本文整理汇总了PHP中moodle_transaction::allow_commit方法的典型用法代码示例。如果您正苦于以下问题:PHP moodle_transaction::allow_commit方法的具体用法?PHP moodle_transaction::allow_commit怎么用?PHP moodle_transaction::allow_commit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类moodle_transaction
的用法示例。
在下文中一共展示了moodle_transaction::allow_commit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preventResetByRollback
/**
* Call this method from test if you want to make sure that
* the resetting of database is done the slow way without transaction
* rollback.
*
* This is useful especially when testing stuff that is not compatible with transactions.
*
* @return void
*/
public function preventResetByRollback()
{
if ($this->testdbtransaction and !$this->testdbtransaction->is_disposed()) {
$this->testdbtransaction->allow_commit();
$this->testdbtransaction = null;
}
}
示例2: array
function test_wrong_transactions()
{
$DB = $this->tdb;
$dbman = $DB->get_manager();
$table = $this->get_test_table();
$tablename = $table->getName();
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$dbman->create_table($table);
// wrong order of nested commits
$transaction1 = $DB->start_delegated_transaction();
$data = (object) array('course' => 3);
$DB->insert_record($tablename, $data);
$transaction2 = $DB->start_delegated_transaction();
$data = (object) array('course' => 4);
$DB->insert_record($tablename, $data);
try {
$transaction1->allow_commit();
$this->fail('wrong order of commits must throw exception');
} catch (Exception $e) {
$this->assertEqual(get_class($e), 'dml_transaction_exception');
}
try {
$transaction2->allow_commit();
$this->fail('first wrong commit forces rollback');
} catch (Exception $e) {
$this->assertEqual(get_class($e), 'dml_transaction_exception');
}
// this is done in default exception handler usually
$this->assertTrue($DB->is_transaction_started());
$this->assertEqual(2, $DB->count_records($tablename));
// not rolled back yet
$DB->force_transaction_rollback();
$this->assertEqual(0, $DB->count_records($tablename));
$DB->delete_records($tablename);
// wrong order of nested rollbacks
$transaction1 = $DB->start_delegated_transaction();
$data = (object) array('course' => 3);
$DB->insert_record($tablename, $data);
$transaction2 = $DB->start_delegated_transaction();
$data = (object) array('course' => 4);
$DB->insert_record($tablename, $data);
try {
// this first rollback should prevent all other rollbacks
$transaction1->rollback(new Exception('test'));
} catch (Exception $e) {
$this->assertEqual(get_class($e), 'Exception');
}
try {
$transaction2->rollback(new Exception('test'));
} catch (Exception $e) {
$this->assertEqual(get_class($e), 'Exception');
}
try {
$transaction1->rollback(new Exception('test'));
} catch (Exception $e) {
// the rollback was used already once, no way to use it again
$this->assertEqual(get_class($e), 'dml_transaction_exception');
}
// this is done in default exception handler usually
$this->assertTrue($DB->is_transaction_started());
$DB->force_transaction_rollback();
$DB->delete_records($tablename);
// unknown transaction object
$transaction1 = $DB->start_delegated_transaction();
$data = (object) array('course' => 3);
$DB->insert_record($tablename, $data);
$transaction2 = new moodle_transaction($DB);
try {
$transaction2->allow_commit();
$this->fail('foreign transaction must fail');
} catch (Exception $e) {
$this->assertEqual(get_class($e), 'dml_transaction_exception');
}
try {
$transaction1->allow_commit();
$this->fail('first wrong commit forces rollback');
} catch (Exception $e) {
$this->assertEqual(get_class($e), 'dml_transaction_exception');
}
$DB->force_transaction_rollback();
$DB->delete_records($tablename);
}