当前位置: 首页>>代码示例>>PHP>>正文


PHP moodle_transaction::allow_commit方法代码示例

本文整理汇总了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;
     }
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:16,代码来源:advanced_testcase.php

示例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);
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:84,代码来源:testdml.php


注:本文中的moodle_transaction::allow_commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。