Milliner/src/Service/MillinerService.php
protected function updateNode(
        $jsonld_url,
        $fedora_url,
        $token = null
    ) {
        // Get the RDF from Fedora.
        $headers = empty($token) ? [] : ['Authorization' => $token];
        $headers['Accept'] = 'application/ld+json';
        $fedora_response = $this->fedora->getResource(
            $fedora_url,
            $headers
        );

        $status = $fedora_response->getStatusCode();
        if ($status != 200) {
            $reason = $fedora_response->getReasonPhrase();
            throw new \RuntimeException(
                "Client error: `GET $fedora_url` resulted in a `$status $reason` response: " .
                    $fedora_response->getBody(),
                $status
            );
        }

        // Strip off the W/ prefix to make the ETag strong.
        $etags = $fedora_response->getHeader("ETag");
        $etag = ltrim(reset($etags), "W/");

        // Get the modified date from the RDF.
        $fedora_jsonld = json_decode(
            $fedora_response->getBody(),
            true
        );

        // Account for the fact that new media haven't got a modified date
        // pushed to it from Drupal yet.
        try {
            $fedora_modified = $this->getModifiedTimestamp(
                $fedora_jsonld
            );
        } catch (\RuntimeException $e) {
            $fedora_modified = 0;
        }

        // Get the jsonld from Drupal.
        $headers = empty($token) ? [] : ['Authorization' => $token];
        $drupal_response = $this->drupal->get(
            $jsonld_url,
            ['headers' => $headers]
        );
        $drupal_jsonld = json_decode(
            $drupal_response->getBody(),
            true
        );

        // Mash it into the shape Fedora accepts.
        $drupal_jsonld = $this->processJsonld(
            $drupal_jsonld,
            $jsonld_url,
            $fedora_url
        );

        // Get the modified date from the RDF.
        $drupal_modified = $this->getModifiedTimestamp(
            $drupal_jsonld
        );

        // Abort with 412 if the Drupal RDF is stale.
        if ($drupal_modified <= $fedora_modified) {
            throw new \RuntimeException(
                "Not updating $fedora_url because RDF at $jsonld_url is not newer",
                412
            );
        }

        // Conditionally save it in Fedora.
        $headers['Content-Type'] = 'application/ld+json';
        $headers['Prefer'] = 'return=minimal; handling=lenient';
        $headers['If-Match'] = $etag;
        $response = $this->fedora->saveResource(
            $fedora_url,
            json_encode($drupal_jsonld),
            $headers
        );

        $status = $response->getStatusCode();
        if (!in_array($status, [201, 204])) {
            $reason = $response->getReasonPhrase();
            throw new \RuntimeException(
                "Client error: `PUT $fedora_url` resulted in a `$status $reason` response: " . $response->getBody(),
                $status
            );
        }

        // Return the response from Fedora.
        return $response;
    }
protected function updateNode(
        $jsonld_url,
        $fedora_url,
        $token = null
    ) {
        // Get the RDF from Fedora.
        $headers = empty($token) ? [] : ['Authorization' => $token];
        $headers['Accept'] = 'application/ld+json';
        $fedora_response = $this->fedora->getResource(
            $fedora_url,
            $headers
        );

        $status = $fedora_response->getStatusCode();
        if ($status != 200) {
            $reason = $fedora_response->getReasonPhrase();
            throw new \RuntimeException(
                "Client error: `GET $fedora_url` resulted in a `$status $reason` response: " .
                    $fedora_response->getBody(),
                $status
            );
        }

        // Strip off the W/ prefix to make the ETag strong.
        $etags = $fedora_response->getHeader("ETag");
        $etag = ltrim(reset($etags), "W/");

        // Get the modified date from the RDF.
        $fedora_jsonld = json_decode(
            $fedora_response->getBody(),
            true
        );

        // Account for the fact that new media haven't got a modified date
        // pushed to it from Drupal yet.
        try {
            $fedora_modified = $this->getModifiedTimestamp(
                $fedora_jsonld
            );
        } catch (\RuntimeException $e) {
            $fedora_modified = 0;
        }

        // Get the jsonld from Drupal.
        $headers = empty($token) ? [] : ['Authorization' => $token];
        $drupal_response = $this->drupal->get(
            $jsonld_url,
            ['headers' => $headers]
        );
        $drupal_jsonld = json_decode(
            $drupal_response->getBody(),
            true
        );

        // Mash it into the shape Fedora accepts.
        $drupal_jsonld = $this->processJsonld(
            $drupal_jsonld,
            $jsonld_url,
            $fedora_url
        );

        // Get the modified date from the RDF.
        $drupal_modified = $this->getModifiedTimestamp(
            $drupal_jsonld
        );

        // Abort with 412 if the Drupal RDF is stale.
        if ($drupal_modified <= $fedora_modified) {
            throw new \RuntimeException(
                "Not updating $fedora_url because RDF at $jsonld_url is not newer",
                412
            );
        }

        // Conditionally save it in Fedora.
        $headers['Content-Type'] = 'application/ld+json';
        $headers['Prefer'] = 'return=minimal; handling=lenient';
        $headers['If-Match'] = $etag;
        $response = $this->fedora->saveResource(
            $fedora_url,
            json_encode($drupal_jsonld),
            $headers
        );

        $status = $response->getStatusCode();
        if (!in_array($status, [201, 204])) {
            $reason = $response->getReasonPhrase();
            throw new \RuntimeException(
                "Client error: `PUT $fedora_url` resulted in a `$status $reason` response: " . $response->getBody(),
                $status
            );
        }

        // Return the response from Fedora.
        return $response;
    }
protected function updateNode ( $ jsonld_url , $ fedora_url , $ token = null ) { // Get the RDF from Fedora. $ headers = empty ( $ token ) ? [ ] : [ 'Authorization' => $ token ] ; $ headers [ 'Accept' ] = 'application/ld+json' ; $ fedora_response = $ this -> fedora -> getResource ( $ fedora_url , $ headers ) ; $ status = $ fedora_response -> getStatusCode ( ) ; if ( $ status != 200 ) { $ reason = $ fedora_response -> getReasonPhrase ( ) ; throw new \ RuntimeException ( "Client error: `GET $fedora_url` resulted in a `$status $reason` response: " . $ fedora_response -> getBody ( ) , $ status ) ; } // Strip off the W/ prefix to make the ETag strong. $ etags = $ fedora_response -> getHeader ( "ETag" ) ; $ etag = ltrim ( reset ( $ etags ) , "W/" ) ; // Get the modified date from the RDF. $ fedora_jsonld = json_decode ( $ fedora_response -> getBody ( ) , true ) ; // Account for the fact that new media haven't got a modified date // pushed to it from Drupal yet. try { $ fedora_modified = $ this -> getModifiedTimestamp ( $ fedora_jsonld ) ; } catch ( \ RuntimeException $ e ) { $ fedora_modified = 0 ; } // Get the jsonld from Drupal. $ headers = empty ( $ token ) ? [ ] : [ 'Authorization' => $ token ] ; $ drupal_response = $ this -> drupal -> get ( $ jsonld_url , [ 'headers' => $ headers ] ) ; $ drupal_jsonld = json_decode ( $ drupal_response -> getBody ( ) , true ) ; // Mash it into the shape Fedora accepts. $ drupal_jsonld = $ this -> processJsonld ( $ drupal_jsonld , $ jsonld_url , $ fedora_url ) ; // Get the modified date from the RDF. $ drupal_modified = $ this -> getModifiedTimestamp ( $ drupal_jsonld ) ; // Abort with 412 if the Drupal RDF is stale. if ( $ drupal_modified <= $ fedora_modified ) { throw new \ RuntimeException ( "Not updating $fedora_url because RDF at $jsonld_url is not newer" , 412 ) ; } // Conditionally save it in Fedora. $ headers [ 'Content-Type' ] = 'application/ld+json' ; $ headers [ 'Prefer' ] = 'return=minimal; handling=lenient' ; $ headers [ 'If-Match' ] = $ etag ; $ response = $ this -> fedora -> saveResource ( $ fedora_url , json_encode ( $ drupal_jsonld ) , $ headers ) ; $ status = $ response -> getStatusCode ( ) ; if ( ! in_array ( $ status , [ 201 , 204 ] ) ) { $ reason = $ response -> getReasonPhrase ( ) ; throw new \ RuntimeException ( "Client error: `PUT $fedora_url` resulted in a `$status $reason` response: " . $ response -> getBody ( ) , $ status ) ; } // Return the response from Fedora. return $ response ; }
Updates an existing LDP-RS in Fedora from a Node.

@param string $uuid
@param string $jsonld_url
@param string $fedora_url
@param string $token

@return \GuzzleHttp\Psr7\Response

@throws \RuntimeException
@throws \GuzzleHttp\Exception\RequestException
Updates an existing LDP - RS in Fedora from a Node .