當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。