server/src/app/Libraries/Sparql/SparqlClient.php
changeset 109 d22ed5792f8e
parent 28 b0b56e0f8c7f
child 158 366509ae2f37
--- a/server/src/app/Libraries/Sparql/SparqlClient.php	Tue Jan 19 19:16:23 2016 +0100
+++ b/server/src/app/Libraries/Sparql/SparqlClient.php	Tue Jan 19 19:18:34 2016 +0100
@@ -5,6 +5,7 @@
 use CorpusParole\Libraries\CorpusParoleException;
 use Config;
 use Log;
+use GuzzleHttp\Psr7\Request;
 
 /**
  *
@@ -38,7 +39,7 @@
         }
         //Log::debug('http_client base uri: ' . $this->getHttpClient()->getConfig('base_uri'));
         $sesameRepository = config('corpusparole.sesame_repository');
-        $resp = $this->getHttpClient()->post("$sesameRepository/transactions");
+        $resp = $this->getHttpClient()->post("$sesameRepository/transactions", ['query' => ['isolation-level' => 'http://www.openrdf.org/schema/sesame#SNAPSHOT_READ']]);
         //$resp = $this->getHttpClient()->post('transactions');
         //TODO check errors
         if($resp->getStatusCode() != 201) {
@@ -97,28 +98,26 @@
     protected function updateData($operation, Graph $graph)
     {
         $graphUri = $graph->getUri();
-        $query = "$operation DATA {";
+
+        $query = $graph->serialise('ntriples');
         if ($graphUri) {
-            $query .= "GRAPH <$graphUri> {";
+            $query = "GRAPH <$graphUri> { $query }";
         }
-        $query .= $graph->serialise('ntriples');
-        if ($graphUri) {
-            $query .= "}";
-        }
-        $query .= '}';
+        $query = "$operation DATA { $query }";
+
 
+        // doc : http://rdf4j.org/doc/4/articles/REST-API/transaction-operations.docbook?view
+        // cf. bug : https://openrdf.atlassian.net/browse/SES-2295
+        // and PR https://bitbucket.org/openrdf/sesame/commits/62b680d8650caca7bc1673f6aaac48a5b6e85d23?at=2.8.x
+        // The put form has been chosen over the post, because it seems that this is the form choosed in the sesame http client
         $resp = $this->getHttpClient()->put(
             $this->currentTransactionUrl, [
+                'headers' => ["Content-Type" => "application/sparql-update; charset=utf-8"],
                 'query' => ['action' => 'UPDATE'],
-                'form_params'=> ['update' => $query],
+                'body' => $query,
             ]
         );
-        if($resp->getStatusCode() != 204) {
-            throw new CorpusParoleException("Could not update in transaction with operation $operation: "
-                . $resp->getStatusCode() . " - "
-                . $resp->getReasonPhrase() . " : " . $resp->getBody()
-                . " : $query" , 1);
-        }
+
     }
 
     public function add(Graph $graph) {