File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,8 @@ class PDOConnector implements IStorageConnector {
39
39
private $ pdo = null ;
40
40
/** @var \PDOStatement $statement */
41
41
private $ statement = null ;
42
+ /** @var bool $transactionExists */
43
+ private $ transactionExists = false ;
42
44
43
45
/**
44
46
* sets the credentials used to connect against the database
@@ -54,23 +56,38 @@ public function setCredentials(array $credentials) {
54
56
* @return bool
55
57
*/
56
58
public function startTransaction (): bool {
57
- return $ this ->pdo ->beginTransaction ();
59
+ if ($ this ->transactionExists ) {
60
+ return false ;
61
+ }
62
+ $ started = $ this ->pdo ->beginTransaction ();
63
+ $ this ->transactionExists = $ started ;
64
+ return $ started ;
58
65
}
59
66
60
67
/**
61
68
* commits a started database transaction
62
69
* @return bool
63
70
*/
64
71
public function commit (): bool {
65
- return $ this ->pdo ->commit ();
72
+ if ($ this ->transactionExists ) {
73
+ $ commited = $ this ->pdo ->commit ();
74
+ $ this ->transactionExists = !$ commited ;
75
+ return $ commited ;
76
+ }
77
+ return false ;
66
78
}
67
79
68
80
/**
69
81
* rolls a started transaction back
70
82
* @return bool
71
83
*/
72
84
public function rollback (): bool {
73
- return $ this ->pdo ->rollBack ();
85
+ if ($ this ->transactionExists ) {
86
+ $ rolledBack = $ this ->pdo ->rollBack ();
87
+ $ this ->transactionExists = !$ rolledBack ;
88
+ return $ rolledBack ;
89
+ }
90
+ return false ;
74
91
}
75
92
76
93
/**
You can’t perform that action at this time.
0 commit comments