MDL-48804 core: do not set current course until login validated
[moodle.git] / lib / dtl / database_mover.php
blob419080e089e143d66e9f666df930e4847c8ca2cc
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * General database mover class
20 * @package core_dtl
21 * @copyright 2008 Andrei Bautu
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') || die();
27 class database_mover extends database_exporter {
28 /** @var database_importer Importer object used to transfer data. */
29 protected $importer;
30 /** @var progress_trace Progress tracing object */
31 protected $feedback;
33 /**
34 * Object constructor.
36 * @param moodle_database $mdb_source Connection to the source database (a
37 * @see moodle_database object).
38 * @param moodle_database $mdb_target Connection to the target database (a
39 * @see moodle_database object).
40 * @param boolean $check_schema - whether or not to check that XML database
41 * schema matches the RDBMS database schema before exporting (used by
42 * @param progress_trace $feedback Progress tracing object
43 * @see export_database).
45 public function __construct(moodle_database $mdb_source, moodle_database $mdb_target,
46 $check_schema = true, progress_trace $feedback = null) {
47 if (empty($feedback)) {
48 $this->feedback = new null_progress_trace();
49 } else {
50 $this->feedback = $feedback;
52 if ($check_schema) {
53 $this->feedback->output(get_string('checkingsourcetables', 'core_dbtransfer'));
55 parent::__construct($mdb_source, $check_schema);
56 $this->feedback->output(get_string('creatingtargettables', 'core_dbtransfer'));
57 $this->importer = new database_importer($mdb_target, $check_schema);
60 /**
61 * How to use transactions during the transfer.
62 * @param string $mode 'pertable', 'allinone' or 'none'.
64 public function set_transaction_mode($mode) {
65 $this->importer->set_transaction_mode($mode);
68 /**
69 * Callback function. Calls importer's begin_database_import callback method.
71 * @param float $version the version of the system which generating the data
72 * @param string $release moodle release info
73 * @param string $timestamp the timestamp of the data (in ISO 8601) format.
74 * @param string $description a user description of the data.
75 * @return void
77 public function begin_database_export($version, $release, $timestamp, $description) {
78 $this->feedback->output(get_string('copyingtables', 'core_dbtransfer'));
79 $this->importer->begin_database_import($version, $timestamp, $description);
82 /**
83 * Callback function. Calls importer's begin_table_import callback method.
85 * @param xmldb_table $table - XMLDB object for the exported table
86 * @return void
88 public function begin_table_export(xmldb_table $table) {
89 $this->feedback->output(get_string('copyingtable', 'core_dbtransfer', $table->getName()), 1);
90 $this->importer->begin_table_import($table->getName(), $table->getHash());
93 /**
94 * Callback function. Calls importer's import_table_data callback method.
96 * @param xmldb_table $table - XMLDB object of the table from which data
97 * was retrieved
98 * @param object $data - data object (fields and values from record)
99 * @return void
101 public function export_table_data(xmldb_table $table, $data) {
102 $this->importer->import_table_data($table->getName(), $data);
106 * Callback function. Calls importer's finish_table_import callback method.
107 * @param xmldb_table $table - XMLDB object for the exported table
108 * @return void
110 public function finish_table_export(xmldb_table $table) {
111 $this->feedback->output(get_string('done', 'core_dbtransfer', $table->getName()), 2);
112 $this->importer->finish_table_import($table->getName());
116 * Callback function. Calls importer's finish_database_import callback method.
117 * @return void
119 public function finish_database_export() {
120 $this->importer->finish_database_import();