GraphAware\Neo4j\Client\HttpDriver\Session::commitTransaction PHP Method

commitTransaction() public method

public commitTransaction ( integer $transactionId )
$transactionId integer
    public function commitTransaction($transactionId)
    {
        $request = new Request('POST', sprintf('%s/db/data/transaction/%d/commit', $this->uri, $transactionId));
        try {
            $response = $this->httpClient->send($request);
            $data = json_decode((string) $response->getBody(), true);
            if (!empty($data['errors'])) {
                $msg = sprintf('Neo4j Exception with code "%s" and message "%s"', $data['errors'][0]['code'], $data['errors'][0]['message']);
                $exception = new Neo4jException($msg);
                $exception->setNeo4jStatusCode($data['errors'][0]['code']);
                throw $exception;
            }
        } catch (RequestException $e) {
            if ($e->hasResponse()) {
                $body = json_decode($e->getResponse()->getBody(), true);
                if (!isset($body['code'])) {
                    throw $e;
                }
                $msg = sprintf('Neo4j Exception with code "%s" and message "%s"', $body['errors'][0]['code'], $body['errors'][0]['message']);
                $exception = new Neo4jException($msg);
                $exception->setNeo4jStatusCode($body['errors'][0]['code']);
                throw $exception;
            }
            throw $e;
        }
    }

Usage Example

 public function success()
 {
     $this->assertNotClosed();
     $this->assertStarted();
     try {
         $this->session->commitTransaction($this->transactionId);
     } catch (Neo4jException $e) {
         if ($e->effect() === Neo4jExceptionInterface::EFFECT_ROLLBACK) {
             $this->state = self::ROLLED_BACK;
         }
         throw $e;
     }
     $this->state = self::COMMITED;
     $this->closed = true;
     $this->session->transaction = null;
 }