Expose methods to allow users of the database class to control when transactions occur.
This commit is contained in:
parent
6bc9315955
commit
2ca74a3b33
@ -279,6 +279,12 @@ class Database {
|
|||||||
*/
|
*/
|
||||||
public $cache = null;
|
public $cache = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A boolean flag to track if we already have an active transaction.
|
||||||
|
* (ie: True if beginTransaction() already called)
|
||||||
|
*/
|
||||||
|
public $transaction = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For now, only connect to the cache, as we will pretty much certainly
|
* For now, only connect to the cache, as we will pretty much certainly
|
||||||
* need it. There are some pages where all the data is in cache, so the
|
* need it. There are some pages where all the data is in cache, so the
|
||||||
@ -327,7 +333,7 @@ class Database {
|
|||||||
$this->engine->init($this->db);
|
$this->engine->init($this->db);
|
||||||
|
|
||||||
// FIXME: this causes problems with running via the PHP CLI
|
// FIXME: this causes problems with running via the PHP CLI
|
||||||
$this->db->beginTransaction();
|
$this->beginTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function connect_engine() {
|
private function connect_engine() {
|
||||||
@ -348,12 +354,23 @@ class Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function beginTransaction() {
|
||||||
|
if ($this->transaction === false) {
|
||||||
|
$this->db->beginTransaction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function commit() {
|
public function commit() {
|
||||||
if(!is_null($this->db)) return $this->db->commit();
|
if(!is_null($this->db) && $this->transaction === true) {
|
||||||
|
$this->transaction = false;
|
||||||
|
return $this->db->commit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function rollback() {
|
public function rollback() {
|
||||||
if(!is_null($this->db)) return $this->db->rollback();
|
if(!is_null($this->db) && $this->transaction === true) {
|
||||||
|
$this->transaction = false;
|
||||||
|
return $this->db->rollback();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function escape($input) {
|
public function escape($input) {
|
||||||
|
@ -54,10 +54,14 @@ send_event(new InitExtEvent());
|
|||||||
send_event(new UserCreationEvent("demo", "demo", ""));
|
send_event(new UserCreationEvent("demo", "demo", ""));
|
||||||
$database->commit(); // Need to commit the new user to the database.
|
$database->commit(); // Need to commit the new user to the database.
|
||||||
|
|
||||||
|
$database->beginTransaction();
|
||||||
|
|
||||||
send_event(new UserCreationEvent("test", "test", ""));
|
send_event(new UserCreationEvent("test", "test", ""));
|
||||||
$database->commit(); // Need to commit the new user to the database.
|
$database->commit(); // Need to commit the new user to the database.
|
||||||
|
|
||||||
|
|
||||||
|
$database->beginTransaction();
|
||||||
|
|
||||||
// Now we can run all the tests.
|
// Now we can run all the tests.
|
||||||
$all = new TestFinder("");
|
$all = new TestFinder("");
|
||||||
$results = $all->run(new TextReporter());
|
$results = $all->run(new TextReporter());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user