简体   繁体   中英

How to detect a failed transaction in neo4j-php-client

I'm using graphaware/neo4j-php-client 4.5.1 with Neo4j 3.0.4 on PHP 5.6.24.

I don't understand how to find out whether a transaction has failed.

For example, I try to delete a node that still has relationships. If I run the DELETE in this simple query:

$client->run
(
    'MATCH (node { name: {name} }) DELETE node',
    [ 'name' => 'Fred' ]
);

… I get this exception, which is the behaviour I expected:

[GraphAware\Neo4j\Client\Exception\Neo4jException]
  org.neo4j.kernel.api.exceptions.ConstraintViolationTransactionFailureException: 
  Cannot delete node<31>, because it still has relationships. 
  To delete this node, you must first delete its relationships.

But when I wrap that same query inside a transaction:

$transaction = $client->transaction();

$transaction->push
(
    'MATCH (node { name: {name} }) DELETE node',
    [ 'name' => 'Fred' ]
);

$results = $transaction->commit();

foreach ($results as $result)
{
    $summary = $result->summarize();
    $stats = $summary->updateStatistics();
    printf("Nodes deleted: %d\n", $stats->nodesDeleted());
}

printf("Transaction status: %s\n", $transaction->status());

… Neo4j doesn't delete the node, but I see this (suggesting success) instead of an exception:

Nodes deleted: 1
Transaction status: COMMITED

Am I missing anything, or is this a bug? Thanks in advance!

Thanks,

This is actually a bug and I fixed it in https://github.com/graphaware/neo4j-php-client/commit/af8f01475a3cf63549498449574eb9c4bb8e7254

The 4.5.3 version including this fix should be available on packagist in a couple of minutes.

Please test and report back.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM