first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,46 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Privacy Subsystem implementation for tool_dbtransfer.
*
* @package tool_dbtransfer
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_dbtransfer\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for tool_dbtransfer implementing null_provider.
*
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+191
View File
@@ -0,0 +1,191 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This script migrates data from current database to another
*
* This script is not intended for beginners!
* Potential problems:
* - su to apache account or sudo before execution
* - already broken DB scheme or invalid data
*
* @package tool_dbtransfer
* @copyright 2012 Petr Skoda {@link http://skodak.org/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('CLI_SCRIPT', true);
require(__DIR__.'/../../../../config.php');
require_once($CFG->libdir.'/clilib.php');
require_once(__DIR__.'/../locallib.php');
$help =
"Database migration script.
It is strongly recommended to turn off the web server
or enable CLI maintenance mode before starting the migration.
Options:
--dbtype=TYPE Database type.
--dblibrary=TYPE Database library. Defaults to 'native'.
--dbhost=HOST Database host.
--dbname=NAME Database name.
--dbuser=USERNAME Database user.
--dbpass=PASSWORD Database password.
--dbport=NUMBER Database port.
--prefix=STRING Table prefix for above database tables.
--dbsocket=PATH Use database sockets. Available for some databases only.
-h, --help Print out this help.
Example:
\$ sudo -u www-data /usr/bin/php admin/tool/dbtransfer/cli/migrate.php
";
// Now get cli options.
list($options, $unrecognized) = cli_get_params(
array(
'dbtype' => null,
'dblibrary' => 'native',
'dbhost' => null,
'dbname' => null,
'dbuser' => null,
'dbpass' => null,
'dbport' => null,
'prefix' => null,
'dbsocket' => null,
'maintenance' => null,
'list' => false,
'help' => false,
),
array(
'm' => 'maintenance',
'l' => 'list',
'h' => 'help',
)
);
if ($options['help']) {
echo $help;
exit(0);
}
if (empty($CFG->version)) {
cli_error(get_string('missingconfigversion', 'debug'));
}
echo "\n".get_string('cliheading', 'tool_dbtransfer')."\n\n";
$drivers = tool_dbtransfer_get_drivers();
if (!isset($options['dbtype'])) {
$choose = array();
foreach ($drivers as $driver => $name) {
list($dbtype, $dblibrary) = explode('/', $driver);
$choose[$dbtype] = $dbtype;
}
$optionsstr = implode(', ', $choose);
cli_heading(get_string('databasetypehead', 'install')." ($optionsstr)");
$options['dbtype'] = cli_input(get_string('clitypevalue', 'admin'), '', $choose, true);
}
$choose = array();
foreach ($drivers as $driver => $name) {
list($dbtype, $dblibrary) = explode('/', $driver);
if ($dbtype === $options['dbtype']) {
$choose[$dblibrary] = $dblibrary;
}
}
if (!isset($options['dblibrary']) or !isset($choose[$options['dblibrary']])) {
$optionsstr = implode(', ', $choose);
cli_heading('Database library'." ($optionsstr)"); // Note: no need to localise unless we add real PDO drivers.
$options['dblibrary'] = cli_input(get_string('clitypevalue', 'admin'), '', $choose, true);
}
if (!isset($options['dbhost'])) {
cli_heading(get_string('databasehost', 'install'));
$options['dbhost'] = cli_input(get_string('clitypevalue', 'admin'));
}
if (!isset($options['dbname'])) {
cli_heading(get_string('databasename', 'install'));
$options['dbname'] = cli_input(get_string('clitypevalue', 'admin'));
}
if (!isset($options['dbuser'])) {
cli_heading(get_string('databaseuser', 'install'));
$options['dbuser'] = cli_input(get_string('clitypevalue', 'admin'));
}
if (!isset($options['dbpass'])) {
cli_heading(get_string('databasepass', 'install'));
$options['dbpass'] = cli_input(get_string('clitypevalue', 'admin'));
}
if (!isset($options['prefix'])) {
cli_heading(get_string('dbprefix', 'install'));
$options['prefix'] = cli_input(get_string('clitypevalue', 'admin'));
}
if (!isset($options['dbport'])) {
cli_heading(get_string('dbport', 'install'));
$options['dbport'] = cli_input(get_string('clitypevalue', 'admin'));
}
if ($CFG->ostype !== 'WINDOWS') {
if (!isset($options['dbsocket'])) {
cli_heading(get_string('databasesocket', 'install'));
$options['dbsocket'] = cli_input(get_string('clitypevalue', 'admin'));
}
}
$a = (object)array('dbtypefrom' => $CFG->dbtype, 'dbtype' => $options['dbtype'],
'dbname' => $options['dbname'], 'dbhost' => $options['dbhost']);
cli_heading(get_string('transferringdbto', 'tool_dbtransfer', $a));
// Try target DB connection.
$problem = '';
$targetdb = moodle_database::get_driver_instance($options['dbtype'], $options['dblibrary']);
$dboptions = array();
if ($options['dbport']) {
$dboptions['dbport'] = $options['dbport'];
}
if ($options['dbsocket']) {
$dboptions['dbsocket'] = $options['dbsocket'];
}
try {
$targetdb->connect($options['dbhost'], $options['dbuser'], $options['dbpass'], $options['dbname'],
$options['prefix'], $dboptions);
if ($targetdb->get_tables()) {
$problem .= get_string('targetdatabasenotempty', 'tool_dbtransfer');
}
} catch (moodle_exception $e) {
$problem .= $e->debuginfo."\n\n";
$problem .= get_string('notargetconectexception', 'tool_dbtransfer');
}
if ($problem !== '') {
echo $problem."\n\n";
exit(1);
}
$feedback = new text_progress_trace();
tool_dbtransfer_transfer_database($DB, $targetdb, $feedback);
$feedback->finished();
cli_heading(get_string('success'));
exit(0);
@@ -0,0 +1,50 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Transfer form
*
* @package tool_dbtransfer
* @copyright 2008 Petr Skoda {@link http://skodak.org/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once($CFG->libdir.'/formslib.php');
/**
* Definition of db export settings form.
*
* @package tool_dbtransfer
* @copyright 2008 Petr Skoda {@link http://skodak.org/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class database_export_form extends moodleform {
/**
* Define the export form.
*/
public function definition() {
$mform = $this->_form;
$mform->addElement('header', 'database', get_string('dbexport', 'tool_dbtransfer'));
$mform->addElement('textarea', 'description', get_string('description'), array('rows'=>5, 'cols'=>60));
$mform->setType('description', PARAM_TEXT);
$this->add_action_buttons(false, get_string('exportdata', 'tool_dbtransfer'));
}
}
@@ -0,0 +1,116 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Transfer form
*
* @package tool_dbtransfer
* @copyright 2008 Petr Skoda {@link http://skodak.org/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once($CFG->libdir.'/formslib.php');
require_once(__DIR__.'/locallib.php');
/**
* Definition of db transfer settings form.
*
* @copyright 2008 Petr Skoda {@link http://skodak.org/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class database_transfer_form extends moodleform {
/**
* Define transfer form.
*/
protected function definition() {
global $CFG;
$mform = $this->_form;
$mform->addElement('header', 'database', get_string('targetdatabase', 'tool_dbtransfer'));
$drivers = tool_dbtransfer_get_drivers();
$drivers = array_reverse($drivers, true);
$drivers[''] = get_string('choosedots');
$drivers = array_reverse($drivers, true);
$mform->addElement('select', 'driver', get_string('dbtype', 'install'), $drivers);
$mform->setType('driver', PARAM_RAW);
$mform->addElement('text', 'dbhost', get_string('databasehost', 'install'));
$mform->setType('dbhost', PARAM_HOST);
$mform->addElement('text', 'dbname', get_string('databasename', 'install'));
$mform->setType('dbname', PARAM_ALPHANUMEXT);
$mform->addElement('text', 'dbuser', get_string('databaseuser', 'install'));
$mform->setType('dbuser', PARAM_ALPHANUMEXT);
$mform->addElement('passwordunmask', 'dbpass', get_string('databasepass', 'install'));
$mform->setType('dbpass', PARAM_RAW);
$mform->addElement('text', 'prefix', get_string('dbprefix', 'install'));
$mform->setType('prefix', PARAM_ALPHANUMEXT);
$mform->addElement('text', 'dbport', get_string('dbport', 'install'));
$mform->setType('dbport', PARAM_INT);
if ($CFG->ostype !== 'WINDOWS') {
$mform->addElement('text', 'dbsocket', get_string('databasesocket', 'install'));
} else {
$mform->addElement('hidden', 'dbsocket');
}
$mform->setType('dbsocket', PARAM_RAW);
$mform->addRule('driver', get_string('required'), 'required', null);
$mform->addRule('dbhost', get_string('required'), 'required', null);
$mform->addRule('dbname', get_string('required'), 'required', null);
$mform->addRule('dbuser', get_string('required'), 'required', null);
$mform->addRule('dbpass', get_string('required'), 'required', null);
if (!isset($drivers['mysqli/native'])) {
$mform->addRule('prefix', get_string('required'), 'required', null);
}
$mform->addElement('header', 'database', get_string('options', 'tool_dbtransfer'));
$mform->addElement('advcheckbox', 'enablemaintenance', get_string('enablemaintenance', 'tool_dbtransfer'));
$mform->setType('enablemaintenance', PARAM_BOOL);
$mform->addHelpButton('enablemaintenance', 'enablemaintenance', 'tool_dbtransfer');
$this->add_action_buttons(false, get_string('transferdata', 'tool_dbtransfer'));
}
/**
* Validate prefix is present for non-mysql drivers.
* @param array $data
* @param array $files
* @return array
*/
public function validation($data, $files) {
$errors = parent::validation($data, $files);
if ($data['driver'] !== 'mysqli/native') {
// This is a bloody hack, let's pretend we do not need to look at db family...
if ($data['prefix'] === '') {
$errors['prefix'] = get_string('required');
}
}
return $errors;
}
}
+44
View File
@@ -0,0 +1,44 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Export
*
* @package tool_dbtransfer
* @copyright 2008 Petr Skoda {@link http://skodak.org/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('NO_OUTPUT_BUFFERING', true);
require('../../../config.php');
require_once('locallib.php');
require_once('database_export_form.php');
admin_externalpage_setup('tooldbexport');
// Create form.
$form = new database_export_form();
if ($data = $form->get_data()) {
tool_dbtransfer_export_xml_database($data->description, $DB);
die;
}
echo $OUTPUT->header();
// TODO: add some more info here.
$form->display();
echo $OUTPUT->footer();
+108
View File
@@ -0,0 +1,108 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Transfer tool
*
* @package tool_dbtransfer
* @copyright 2008 Petr Skoda {@link http://skodak.org/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('NO_OUTPUT_BUFFERING', true);
require('../../../config.php');
require_once('locallib.php');
require_once('database_transfer_form.php');
admin_externalpage_setup('tooldbtransfer');
// Create the form.
$form = new database_transfer_form();
$problem = '';
// If we have valid input.
if ($data = $form->get_data()) {
// Connect to the other database.
list($dbtype, $dblibrary) = explode('/', $data->driver);
$targetdb = moodle_database::get_driver_instance($dbtype, $dblibrary);
$dboptions = array();
if ($data->dbport) {
$dboptions['dbport'] = $data->dbport;
}
if ($data->dbsocket) {
$dboptions['dbsocket'] = $data->dbsocket;
}
try {
$targetdb->connect($data->dbhost, $data->dbuser, $data->dbpass, $data->dbname, $data->prefix, $dboptions);
if ($targetdb->get_tables()) {
$problem .= get_string('targetdatabasenotempty', 'tool_dbtransfer');
}
} catch (moodle_exception $e) {
$problem .= get_string('notargetconectexception', 'tool_dbtransfer').'<br />'.$e->debuginfo;
}
if ($problem === '') {
// Scroll down to the bottom when finished.
$PAGE->requires->js_init_code("window.scrollTo(0, 5000000);");
// Enable CLI maintenance mode if requested.
if ($data->enablemaintenance) {
$PAGE->set_pagelayout('maintenance');
tool_dbtransfer_create_maintenance_file();
}
// Start output.
echo $OUTPUT->header();
$data->dbtype = $dbtype;
$data->dbtypefrom = $CFG->dbtype;
echo $OUTPUT->heading(get_string('transferringdbto', 'tool_dbtransfer', $data));
// Do the transfer.
$CFG->tool_dbransfer_migration_running = true;
try {
$feedback = new html_list_progress_trace();
tool_dbtransfer_transfer_database($DB, $targetdb, $feedback);
$feedback->finished();
} catch (Exception $e) {
if ($data->enablemaintenance) {
tool_dbtransfer_maintenance_callback();
}
unset($CFG->tool_dbransfer_migration_running);
throw $e;
}
unset($CFG->tool_dbransfer_migration_running);
// Finish up.
echo $OUTPUT->notification(get_string('success'), 'notifysuccess');
echo $OUTPUT->continue_button("$CFG->wwwroot/$CFG->admin/");
echo $OUTPUT->footer();
die;
}
}
// Otherwise display the settings form.
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('transferdbtoserver', 'tool_dbtransfer'));
$info = format_text(get_string('transferdbintro', 'tool_dbtransfer'), FORMAT_MARKDOWN);
echo $OUTPUT->box($info);
$form->display();
if ($problem !== '') {
echo $OUTPUT->box($problem, 'generalbox error');
}
echo $OUTPUT->footer();
@@ -0,0 +1,43 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Strings for component 'tool_generator', language 'en'.
*
* @package tool_dbtransfer
* @copyright 2011 Petr Skoda {@link http://skodak.org/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['clidriverlist'] = 'Available database drivers for migration';
$string['cliheading'] = 'Database migration - make sure nobody is accessing the server during migration!';
$string['climigrationnotice'] = 'Database migration in progress, please wait until the migration completes and server administrator updates configuration and deletes the $CFG->dataroot/climaintenance.html file.';
$string['convertinglogdisplay'] = 'Converting log display actions';
$string['dbexport'] = 'Database export';
$string['dbtransfer'] = 'Database migration';
$string['enablemaintenance'] = 'Enable maintenance mode';
$string['enablemaintenance_help'] = 'This option enables maintanance mode during and after the database migration, it prevents access of all users until the migration is completed. Please note that administrator has to manually delete $CFG->dataroot/climaintenance.html file after updating config.php settings to resume normal operation.';
$string['exportdata'] = 'Export data';
$string['notargetconectexception'] = 'Can not connect target database, sorry.';
$string['options'] = 'Options';
$string['pluginname'] = 'Database transfer';
$string['targetdatabase'] = 'Target database';
$string['targetdatabasenotempty'] = 'Target database must not contain any tables with given prefix!';
$string['transferdata'] = 'Transfer data';
$string['transferdbintro'] = 'This script will transfer the entire contents of this database to another database server. It is often used for migration of data to different database type.';
$string['transferdbtoserver'] = 'Transfer this Moodle database to another server';
$string['transferringdbto'] = 'Transferring this {$a->dbtypefrom} database to {$a->dbtype} database "{$a->dbname}" on "{$a->dbhost}"';
$string['privacy:metadata'] = 'The Database transfer plugin does not store any personal data.';
+208
View File
@@ -0,0 +1,208 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Export db content to file.
*
* @package tool_dbtransfer
* @copyright 2008 Petr Skoda {@link http://skodak.org/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
/*
TODO:
- exporting to server file >2GB fails in 32bit operating systems - needs warning
- we may run out of disk space exporting to server file - we must verify the file is not truncated; read from the end of file?
- when sending file >4GB - FAT32 limit, Apache limit, browser limit - needs warning
- there must be some form of progress bar during export, transfer - new tracking class could be passed around
- command line operation - could work around some 2G/4G limits in PHP; useful for cron full backups
- by default allow exporting into empty database only (no tables with the same prefix yet)
- all dangerous operation (like deleting of all data) should be confirmed by key found in special file in dataroot
(user would need file access to dataroot which might prevent various "accidents")
- implement "Export/import running" notification in lib/setup.php (similar to new upgrade flag in config table)
- gzip compression when storing xml file - the xml is very verbose and full of repeated tags (zip is not suitable here at all)
this could help us keep the files below 2G (expected ratio is > 10:1)
*/
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/dtllib.php');
/**
* Initiate database export.
* @param string $description
* @param moodle_database $mdb
* @return does not return, calls die()
*/
function tool_dbtransfer_export_xml_database($description, $mdb) {
core_php_time_limit::raise();
\core\session\manager::write_close(); // Release session.
header('Content-Type: application/xhtml+xml; charset=utf-8');
header('Content-Disposition: attachment; filename=database.xml');
header('Expires: 0');
header('Cache-Control: must-revalidate,post-check=0,pre-check=0');
header('Pragma: public');
while(@ob_flush());
$var = new file_xml_database_exporter('php://output', $mdb);
$var->export_database($description);
// No more output.
die;
}
/**
* Initiate database transfer.
* @param moodle_database $sourcedb
* @param moodle_database $targetdb
* @param progress_trace $feedback
* @return void
*/
function tool_dbtransfer_transfer_database(moodle_database $sourcedb, moodle_database $targetdb, progress_trace $feedback = null) {
core_php_time_limit::raise();
\core\session\manager::write_close(); // Release session.
$var = new database_mover($sourcedb, $targetdb, true, $feedback);
$var->export_database(null);
tool_dbtransfer_rebuild_target_log_actions($targetdb, $feedback);
}
/**
* Very hacky function for rebuilding of log actions in target database.
* @param moodle_database $target
* @param progress_trace $feedback
* @return void
* @throws Exception on conversion error
*/
function tool_dbtransfer_rebuild_target_log_actions(moodle_database $target, progress_trace $feedback = null) {
global $DB, $CFG;
require_once("$CFG->libdir/upgradelib.php");
$feedback->output(get_string('convertinglogdisplay', 'tool_dbtransfer'));
$olddb = $DB;
$DB = $target;
try {
$DB->delete_records('log_display', array('component'=>'moodle'));
log_update_descriptions('moodle');
$plugintypes = core_component::get_plugin_types();
foreach ($plugintypes as $type => $location) {
$plugs = core_component::get_plugin_list($type);
foreach ($plugs as $plug => $fullplug) {
$component = $type.'_'.$plug;
$DB->delete_records('log_display', array('component'=>$component));
log_update_descriptions($component);
}
}
} catch (Exception $e) {
$DB = $olddb;
throw $e;
}
$DB = $olddb;
$feedback->output(get_string('done', 'core_dbtransfer', null), 1);
}
/**
* Returns list of fully working database drivers present in system.
* @return array
*/
function tool_dbtransfer_get_drivers() {
global $CFG;
$files = new RegexIterator(new DirectoryIterator("$CFG->libdir/dml"), '|^.*_moodle_database\.php$|');
$drivers = array();
foreach ($files as $file) {
$matches = null;
preg_match('|^([a-z0-9]+)_([a-z]+)_moodle_database\.php$|', $file->getFilename(), $matches);
if (!$matches) {
continue;
}
$dbtype = $matches[1];
$dblibrary = $matches[2];
if ($dbtype === 'sqlite3') {
// The sqlite3 driver is not fully working yet and should not be returned.
continue;
}
$targetdb = moodle_database::get_driver_instance($dbtype, $dblibrary, false);
if ($targetdb->driver_installed() !== true) {
continue;
}
$driver = $dbtype.'/'.$dblibrary;
$drivers[$driver] = $targetdb->get_name();
};
return $drivers;
}
/**
* Create CLI maintenance file to prevent all access.
*/
function tool_dbtransfer_create_maintenance_file() {
global $CFG;
core_shutdown_manager::register_function('tool_dbtransfer_maintenance_callback');
$options = new stdClass();
$options->trusted = false;
$options->noclean = false;
$options->filter = false;
$options->para = true;
$options->newlines = false;
$message = format_text(get_string('climigrationnotice', 'tool_dbtransfer'), FORMAT_MARKDOWN, $options);
$message = bootstrap_renderer::early_error_content($message, '', '', array());
$html = <<<OET
<!DOCTYPE html>
<html>
<header><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><header/>
<body>$message</body>
</html>
OET;
file_put_contents("$CFG->dataroot/climaintenance.html", $html);
@chmod("$CFG->dataroot/climaintenance.html", $CFG->filepermissions);
}
/**
* This callback is responsible for unsetting maintenance mode
* if the migration is interrupted.
*/
function tool_dbtransfer_maintenance_callback() {
global $CFG;
if (empty($CFG->tool_dbransfer_migration_running)) {
// Migration was finished properly - keep the maintenance file in place.
return;
}
if (file_exists("$CFG->dataroot/climaintenance.html")) {
// Failed migration, revert to normal site operation.
unlink("$CFG->dataroot/climaintenance.html");
error_log('tool_dbtransfer: Interrupted database migration detected, switching off CLI maintenance mode.');
}
}
+33
View File
@@ -0,0 +1,33 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Add hidden links db transfer tool
*
* @package tool_dbtransfer
* @copyright 2011 Petr Skoda {@link http://skodak.org/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
if ($hassiteconfig) {
$ADMIN->add('experimental', new admin_externalpage('tooldbtransfer', get_string('dbtransfer', 'tool_dbtransfer'),
$CFG->wwwroot.'/'.$CFG->admin.'/tool/dbtransfer/index.php', 'moodle/site:config', false));
// DB export/import is not ready yet - keep it hidden for now.
$ADMIN->add('experimental', new admin_externalpage('tooldbexport', get_string('dbexport', 'tool_dbtransfer'),
$CFG->wwwroot.'/'.$CFG->admin.'/tool/dbtransfer/dbexport.php', 'moodle/site:config', true));
}
+29
View File
@@ -0,0 +1,29 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Version details.
*
* @package tool_dbtransfer
* @copyright 2008 Petr Skoda {@link http://skodak.org/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'tool_dbtransfer'; // Full name of the plugin (used for diagnostics).