]> git.mjollnir.org Git - moodle.git/commitdiff
admin dbtransfer: MDL-18225 also, let the caller control how transactions are used.
authortjhunt <tjhunt>
Fri, 13 Feb 2009 02:49:25 +0000 (02:49 +0000)
committertjhunt <tjhunt>
Fri, 13 Feb 2009 02:49:25 +0000 (02:49 +0000)
lib/dtl/database_importer.php
lib/dtl/database_mover.php

index 45a9dcb5029abd38e6e438664863bd786b237103..7d1b8bf4dc8aa2017a84610915eb7bcb7b73ccdc 100644 (file)
@@ -35,6 +35,10 @@ class database_importer {
      * @see begin_database_import).
      */
     protected $check_schema;
+    /**
+     * How to use transactions.
+     */
+    protected $transactionmode = 'allinone';
 
     /**
      * Object constructor.
@@ -52,6 +56,17 @@ class database_importer {
         $this->check_schema = $check_schema;
     }
 
+    /**
+     * How to use transactions during the import.
+     * @param string $mode 'pertable', 'allinone' or 'none'.
+     */
+    public function set_transaction_mode($mode) {
+        if (!in_array($mode, array('pertable', 'allinone', 'none'))) {
+            throw new coding_exception('Unknown transaction mode', $mode);
+        }
+        $this->transactionmode = $mode;
+    }
+
     /**
      * Callback function. Should be called only once database per import
      * operation, before any database changes are made. It will check the database
@@ -89,7 +104,9 @@ class database_importer {
             }
             throw new dbtransfer_exception('importschemaexception', $details);
         }
-        $this->mdb->begin_sql();
+        if ($this->transactionmode == 'allinone') {
+            $this->mdb->begin_sql();
+        }
     }
 
     /**
@@ -104,6 +121,9 @@ class database_importer {
      * @return void
      */
     public function begin_table_import($tablename, $schemaHash) {
+        if ($this->transactionmode == 'pertable') {
+            $this->mdb->begin_sql();
+        }
         if (!$table = $this->schema->getTable($tablename)) {
             throw new dbtransfer_exception('unknowntableexception', $tablename);
         }
@@ -132,6 +152,9 @@ class database_importer {
                 return;
             }
         }
+        if ($this->transactionmode == 'pertable') {
+            $this->mdb->commit_sql();
+        }
     }
 
     /**
@@ -140,7 +163,9 @@ class database_importer {
      * @return void
      */
     public function finish_database_import() {
-        $this->mdb->commit_sql();
+        if ($this->transactionmode == 'allinone') {
+            $this->mdb->commit_sql();
+        }
     }
 
     /**
index 6236a881815e8fc1f7c279f324df97e28b768994..3856a520fdc522df47bbd0f557ab1088ed909bd4 100644 (file)
@@ -31,6 +31,14 @@ class database_mover extends database_exporter {
         $this->importer = new database_importer($mdb_target, $check_schema);
     }
 
+    /**
+     * How to use transactions during the transfer.
+     * @param string $mode 'pertable', 'allinone' or 'none'.
+     */
+    public function set_transaction_mode($mode) {
+        $this->importer->set_transaction_mode($mode);
+    }
+
     /**
      * Callback function. Calls importer's begin_database_import callback method.
      *