2
2
3
3
namespace Neo4j \QueryAPI ;
4
4
5
+ use Exception ;
5
6
use GuzzleHttp \Client ;
6
7
use GuzzleHttp \Psr7 \Request ;
7
8
use GuzzleHttp \Psr7 \Utils ;
@@ -90,7 +91,6 @@ public function run(string $cypher, array $parameters = [], string $database = '
90
91
0 ,
91
92
null ,
92
93
$ error
93
-
94
94
);
95
95
}
96
96
@@ -164,17 +164,32 @@ private function handleException(RequestExceptionInterface $e): void
164
164
throw $ e ;
165
165
}
166
166
167
- public function beginTransaction (string $ database = ' neo4j ' ): Transaction
167
+ public function beginTransaction (): array
168
168
{
169
- $ response = $ this ->client ->sendRequest (new Request ('POST ' , '/db/neo4j/query/v2/tx ' ));
169
+ $ request = new Request ('POST ' , '/db/neo4j/tx ' ); // Adjust endpoint as needed
170
+
171
+ // Apply authentication, if provided
172
+ if ($ this ->auth instanceof AuthenticateInterface) {
173
+ $ request = $ this ->auth ->authenticate ($ request );
174
+ }
175
+
176
+ try {
177
+ $ response = $ this ->client ->send ($ request );
178
+ $ responseBody = json_decode ($ response ->getBody ()->getContents (), true );
170
179
171
- $ clusterAffinity = $ response ->getHeaderLine ('neo4j-cluster-affinity ' );
172
- $ responseData = json_decode ($ response ->getBody (), true );
173
- $ transactionId = $ responseData ['transaction ' ]['id ' ];
180
+ // Validate the response for transaction ID
181
+ if (isset ($ responseBody ['commit ' ])) {
182
+ return $ responseBody ; // Successful transaction
183
+ }
174
184
175
- return new Transaction ($ this ->client , $ clusterAffinity , $ transactionId );
185
+ throw new RuntimeException ('Missing transaction ID in the response. ' );
186
+ } catch (Exception $ e ) {
187
+ throw new RuntimeException ("Failed to begin transaction: {$ e ->getMessage ()}" , 0 , $ e );
188
+ }
176
189
}
177
190
191
+
192
+
178
193
private function createProfileData (array $ data ): ProfiledQueryPlan
179
194
{
180
195
$ ogm = new OGM ();
@@ -229,4 +244,4 @@ private function createProfileData(array $data): ProfiledQueryPlan
229
244
230
245
return $ profiledQueryPlan ;
231
246
}
232
- }
247
+ }
0 commit comments