}
echo str_pad($table->name, 40). " - ";
- $DB->change_database_structure("ALTER TABLE {$table->name} ENGINE = $engine");
+ try {
+ $DB->change_database_structure("ALTER TABLE {$table->name} ENGINE = $engine");
+ } catch (moodle_exception $e) {
+ echo $e->getMessage()."\n";
+ $skipped++;
+ continue;
+ }
echo "DONE\n";
$converted++;
}
$this->add_action_buttons(false, get_string('addhost', 'mnet'));
}
- function validation($data) {
+ function validation($data, $files) {
global $DB;
$wwwroot = $data['wwwroot'];
$this->add_action_buttons(false);
}
- function validation($data) {
+ function validation($data, $files) {
$errors = array();
if ($data['oldpublickey'] == $data['public_key']) {
return;
global $CFG;
$mform =& $this->_form;
+ $mnetprofileimportfields = '';
+ if (isset($CFG->mnetprofileimportfields)) {
+ $mnetprofileimportfields = str_replace(',', ', ', $CFG->mnetprofileimportfields);
+ }
+
+ $mnetprofileexportfields = '';
+ if (isset($CFG->mnetprofileexportfields)) {
+ $mnetprofileexportfields = str_replace(',', ', ', $CFG->mnetprofileexportfields);
+ }
$mform->addElement('hidden', 'hostid', $this->_customdata['hostid']);
$fields = mnet_profile_field_options();
$select = $mform->addElement('select', 'importfields', get_string('importfields', 'mnet'), $fields['optional']);
$select->setMultiple(true);
- $mform->addElement('checkbox', 'importdefault', get_string('leavedefault', 'mnet'), str_replace(',', ', ', $CFG->mnetprofileimportfields));
+ $mform->addElement('checkbox', 'importdefault', get_string('leavedefault', 'mnet'), $mnetprofileimportfields);
// Fields to export ----------------------------------------------------
$mform->addElement('header', 'export', get_string('exportfields', 'mnet'));
$select = $mform->addElement('select', 'exportfields', get_string('exportfields', 'mnet'), $fields['optional']);
$select->setMultiple(true);
- $mform->addElement('checkbox', 'exportdefault', get_string('leavedefault', 'mnet'), str_replace(',', ', ', $CFG->mnetprofileexportfields));
+ $mform->addElement('checkbox', 'exportdefault', get_string('leavedefault', 'mnet'), $mnetprofileexportfields);
$this->add_action_buttons();
}
function definition() {
$mform =& $this->_form;
$mnet_peer =& $this->_customdata['peer'];
- $myservices =& mnet_get_service_info($mnet_peer);
+ $myservices = mnet_get_service_info($mnet_peer);
$mform->addElement('hidden', 'hostid', $mnet_peer->id);
// Add a category for backups
$ADMIN->add('courses', new admin_category('backups', new lang_string('backups','admin')));
- // Create a page for general backup defaults
+ // Create a page for general backups configuration and defaults.
$temp = new admin_settingpage('backupgeneralsettings', new lang_string('generalbackdefaults', 'backup'), 'moodle/backup:backupcourse');
+
+ // General configuration section.
+ $temp->add(new admin_setting_configselect('backup/loglifetime', new lang_string('loglifetime', 'backup'), new lang_string('configloglifetime', 'backup'), 30, array(
+ 1 => new lang_string('numdays', '', 1),
+ 2 => new lang_string('numdays', '', 2),
+ 3 => new lang_string('numdays', '', 3),
+ 5 => new lang_string('numdays', '', 5),
+ 7 => new lang_string('numdays', '', 7),
+ 10 => new lang_string('numdays', '', 10),
+ 14 => new lang_string('numdays', '', 14),
+ 20 => new lang_string('numdays', '', 20),
+ 30 => new lang_string('numdays', '', 30),
+ 60 => new lang_string('numdays', '', 60),
+ 90 => new lang_string('numdays', '', 90),
+ 120 => new lang_string('numdays', '', 120),
+ 180 => new lang_string('numdays', '', 180),
+ 365 => new lang_string('numdays', '', 365)
+ )));
+
+ // General defaults section.
+ $temp->add(new admin_setting_heading('generalsettings', new lang_string('generalsettings', 'backup'), ''));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_users', new lang_string('generalusers','backup'), new lang_string('configgeneralusers','backup'), array('value'=>1, 'locked'=>0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_anonymize', new lang_string('generalanonymize','backup'), new lang_string('configgeneralanonymize','backup'), array('value'=>0, 'locked'=>0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_role_assignments', new lang_string('generalroleassignments','backup'), new lang_string('configgeneralroleassignments','backup'), array('value'=>1, 'locked'=>0)));
$temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_histories', new lang_string('generalhistories','backup'), new lang_string('configgeneralhistories','backup'), array('value'=>0, 'locked'=>0)));
$ADMIN->add('backups', $temp);
-/// "backups" settingpage
+ // Create a page for automated backups configuration and defaults.
$temp = new admin_settingpage('automated', new lang_string('automatedsetup','backup'), 'moodle/backup:backupcourse');
+
+ // Automated configuration section.
$temp->add(new admin_setting_configselect('backup/backup_auto_active', new lang_string('active'), new lang_string('autoactivedescription', 'backup'), 0, array(
0 => new lang_string('autoactivedisabled', 'backup'),
1 => new lang_string('autoactiveenabled', 'backup'),
500 => '500');
$temp->add(new admin_setting_configselect('backup/backup_auto_keep', new lang_string('keep'), new lang_string('backupkeephelp'), 1, $keepoptoins));
-
+ // Automated defaults section.
$temp->add(new admin_setting_heading('automatedsettings', new lang_string('automatedsettings','backup'), ''));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_users', new lang_string('generalusers', 'backup'), new lang_string('configgeneralusers', 'backup'), 1));
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_role_assignments', new lang_string('generalroleassignments','backup'), new lang_string('configgeneralroleassignments','backup'), 1));
echo $OUTPUT->notification('Please be patient and wait for this to complete...', 'notifysuccess');
+ set_time_limit(0);
+
if ($tables = $DB->get_tables()) {
$DB->set_debug(true);
foreach ($tables as $table) {
$fulltable = $DB->get_prefix().$table;
- $DB->change_database_structure("ALTER TABLE $fulltable ENGINE=INNODB");
+ try {
+ $DB->change_database_structure("ALTER TABLE $fulltable ENGINE=INNODB");
+ } catch (moodle_exception $e) {
+ echo $OUTPUT->notification(s($e->getMessage()).'<br />'.s($e->debuginfo));
+ }
}
$DB->set_debug(false);
}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-$string['configintrotimezones'] = 'This page will search for new information about world timezones (including daylight savings time rules) and update your local database with this information. These locations will be checked, in order: {$a} This procedure is generally very safe and can not break normal installations. Do you wish to update your timezones now?';
+$string['configintrotimezones'] = 'This page will search for new information about world timezones (including daylight savings time rules) and update your local database with this information. These locations will be checked, in order: {$a} Do you wish to update your timezones now?';
$string['importtimezones'] = 'Update complete list of timezones';
$string['importtimezonescount'] = '{$a->count} entries imported from {$a->source}';
$string['importtimezonesfailed'] = 'No sources found! (Bad news)';
+++ /dev/null
-<?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/>.
-
-/**
- * Run database functional tests.
- *
- * @package tool
- * @subpackage unittest
- * @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(dirname(__FILE__) . '/../../../config.php');
-require_once($CFG->libdir.'/adminlib.php');
-
-require_once('simpletestlib.php');
-require_once('simpletestcoveragelib.php');
-require_once('ex_simple_test.php');
-require_once('ex_reporter.php');
-
-$showpasses = optional_param('showpasses', false, PARAM_BOOL);
-$codecoverage = optional_param('codecoverage', false, PARAM_BOOL);
-$selected = optional_param_array('selected', array(), PARAM_INT);
-
-// Print the header and check access.
-admin_externalpage_setup('tooldbtest');
-echo $OUTPUT->header();
-
-global $UNITTEST;
-$UNITTEST = new stdClass();
-
-if (!data_submitted()) {
- $selected = array();
- for ($i=0; $i<=10; $i++) {
- $selected[$i] = 1;
- }
-}
-
-
-$dbinfos = array();
-$tests = array();
-
-$dbinfos[0] = array('name'=>"Current database ($CFG->dblibrary/$CFG->dbtype)", 'installed'=>true, 'configured'=>true); // TODO: localise
-if (data_submitted() and !empty($selected[0])) {
- $tests[0] = $DB;
-}
-
-for ($i=1; $i<=10; $i++) {
- $name = 'func_test_db_'.$i;
- if (!isset($CFG->$name)) {
- continue;
- }
- list($library, $driver, $dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions) = $CFG->$name;
- $dbinfos[$i] = array('name'=>"External database $i ($library/$driver/$dbhost/$dbname/$prefix)", 'installed'=>false, 'configured'=>false);
-
- $classname = "{$driver}_{$library}_moodle_database";
- require_once("$CFG->libdir/dml/$classname.php");
- $d = new $classname();
- if (!$d->driver_installed()) {
- continue;
- }
- $dbinfos[$i]['installed'] = true;
-
- try {
- $d->connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions);
- $dbinfos[$i]['configured'] = true;
- if (data_submitted() and !empty($selected[$i])) {
- $tests[$i] = $d;
- } else {
- $d->dispose();
- }
- } catch (dml_connection_exception $e) {
- $dbinfos[$i]['configured'] = false;
- }
-}
-
-if (!empty($tests)) {
- $covreporter = new moodle_coverage_reporter('Functional DB Tests Code Coverage Report', 'dbtest');
- $covrecorder = new moodle_coverage_recorder($covreporter);
-
- foreach ($tests as $i=>$database) {
- $dbinfo = $dbinfos[$i];
-
- $UNITTEST->func_test_db = $database; // pass the db to the tests through global
-
- echo $OUTPUT->heading('Running tests on: '.$dbinfo['name'], 3); // TODO: localise
-
- // Create the group of tests.
- $test = new autogroup_test_coverage(false, true, $codecoverage);
-
-
- $test->addTestFile($CFG->libdir.'/dml/simpletest/testdml.php');
- $test->addTestFile($CFG->libdir.'/ddl/simpletest/testddl.php');
-
- // Make the reporter, which is what displays the results.
- $reporter = new ExHtmlReporter($showpasses);
-
- set_time_limit(300); // 5 mins per DB should be enough
- $test->run_with_external_coverage($reporter, $covrecorder);
-
- unset($UNITTEST->func_test_db);
-
- echo '<hr />';
- }
- if ($codecoverage) {
- $covrecorder->generate_report();
- moodle_coverage_reporter::print_summary_info('dbtest');
- }
-
-}
-
-// Print the form for adjusting options.
-echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter');
-echo '<form method="post" action="dbtest.php">';
-echo '<div>';
-echo $OUTPUT->heading("Run functional database tests"); // TODO: localise
-echo '<p>'.html_writer::checkbox('showpasses', 1, $showpasses, get_string('showpasses', 'tool_unittest')).'</p>';
-if (moodle_coverage_recorder::can_run_codecoverage()) {
- echo '<p>'.html_writer::checkbox('codecoverage', 1, $codecoverage, get_string('codecoverageanalysis', 'tool_unittest')).'</p>';
-} else {
- echo '<p>'; print_string('codecoveragedisabled', 'tool_unittest'); echo '<input type="hidden" name="codecoverage" value="0" /></p>';
-}
-echo '<p><strong>'."Databases:".'</strong></p>';
-echo '<ul>';
-foreach ($dbinfos as $i=>$dbinfo) {
- $name = $dbinfo['name'];
- if ($dbinfo['installed']) {
- if (!$dbinfo['configured']) {
- $name = "$name (misconfigured)"; // TODO: localise
- }
- echo '<li>'.html_writer::checkbox('selected['.$i.']', 1, intval(!empty($selected[$i])), $name).'</li>';
- } else {
- echo '<li>'."$name: driver not installed".'</li>'; // TODO: localise
- }
-}
-echo '</ul>';
-echo '<p>External databases are configured in config.php, add lines:</p>
-<pre>
-$CFG->func_test_db_1 = array("native", "pgsql", "localhost", "moodleuser", "password", "moodle", "test", null);
-$CFG->func_test_db_2 = array("native", "mssql", "localhost", "moodleuser", "password", "moodle", "test", null);
-</pre>
-<p>where order of parameters is: dblibrary, dbtype, dbhost, dbuser, dbpass, dbname, prefix, dboptions</p>';
-echo '<p><input type="submit" value="' . get_string('runtests', 'tool_unittest') . '" /></p>';
-echo '</div>';
-echo '</form>';
-echo $OUTPUT->box_end();
-
-// Print link to latest code coverage for this report type
-if (!data_submitted() || !$codecoverage) {
- moodle_coverage_reporter::print_link_to_latest('dbtest');
-}
-
-// Footer.
-echo $OUTPUT->footer();
echo '</form>';
echo $OUTPUT->box_end();
-$otherpages = array();
-$otherpages['PDF lib test'] = new moodle_url('/admin/tool/unittest/other/pdflibtestpage.php');
-if (debugging('', DEBUG_DEVELOPER)) {
- $otherpages['TODO checker'] = new moodle_url('/admin/tool/unittest/other/todochecker.php');
-}
-
-// print list of extra test pages that are not simpletests,
-// not everything there is good enough to show to our users
-if ($otherpages) {
- echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter');
- echo $OUTPUT->heading(get_string('othertestpages', 'tool_unittest'));
- echo '<ul>';
- foreach ($otherpages as $name=>$url) {
- echo '<li>'.html_writer::link($url, $name).'</li>';
- }
- echo '</ul>';
- echo $OUTPUT->box_end();
-}
-
-
// Print link to latest code coverage for this report type
if (is_null($path) || !$codecoverage) {
moodle_coverage_reporter::print_link_to_latest('unittest');
+++ /dev/null
-<?php
-
-die;die;die;
-/*
- if (empty($CFG->unittestprefix)) {
- die;
- }
-
- $CFG->xmlstrictheaders = false;
-
- // extra security
- session_write_close();
-
- $return_url = "$CFG->wwwroot/$CFG->admin/tool/unittest/test_tables.php";
-
- // Temporarily override $DB and $CFG for a fresh install on the unit test prefix
-
- $real_cfg = $CFG;
-
- $CFG = new stdClass();
- $CFG->dbhost = $real_cfg->dbhost;
- $CFG->dbtype = $real_cfg->dbtype;
- $CFG->dblibrary = $real_cfg->dblibrary;
- $CFG->dbuser = $real_cfg->dbuser;
- $CFG->dbpass = $real_cfg->dbpass;
- $CFG->dbname = $real_cfg->dbname;
- $CFG->unittestprefix = $real_cfg->unittestprefix;
- $CFG->wwwroot = $real_cfg->wwwroot;
- $CFG->dirroot = $real_cfg->dirroot;
- $CFG->libdir = $real_cfg->libdir;
- $CFG->dataroot = $real_cfg->dataroot;
- $CFG->admin = $real_cfg->admin;
- $CFG->release = $real_cfg->release;
- $CFG->version = $real_cfg->version;
- $CFG->config_php_settings = $real_cfg->config_php_settings;
- $CFG->debug = 0;
-
- $DB = moodle_database::get_driver_instance($CFG->dbtype, $CFG->dblibrary);
- $DB->connect($CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->unittestprefix);
-
- $test_tables = $DB->get_tables();
-
- include("$CFG->dirroot/version.php"); // defines $version and $release
-
- /// Check if the main tables have been installed yet or not.
- if ($test_tables = $DB->get_tables() ) { // No tables yet at all.
- //TODO: make sure these are test tables & delte all these tables
- $manager = $DB->get_manager();
- foreach ($test_tables as $table) {
- $xmldbtable = new xmldb_table($table);
- $manager->drop_table($xmldbtable);
- }
- }
-
-/// return to original debugging level
-
- $DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml");
-
-/// set all core default records and default settings
- require_once("$CFG->libdir/db/install.php");
- xmldb_main_install($version);
-
-/// Continue with the instalation
-
- // Install the roles system.
- moodle_install_roles();
-
- // Install core event handlers
- events_update_definition();
-
- // Install core message providers
- message_update_providers();
- message_update_providers('message');
-
- // Write default settings unconditionally (i.e. even if a setting is already set, overwrite it)
- admin_apply_default_settings(NULL, true);
-
-
-/// upgrade all plugins types
- $plugintypes = get_plugin_types();
- foreach ($plugintypes as $type => $location) {
- upgrade_plugins($type);
- }
-
-/// just make sure upgrade logging is properly terminated
- upgrade_finished();
-
-/// make sure admin user is created - this is the last step because we need
-/// session to be working properly in order to edit admin account
- create_admin_user();
-
-
- redirect('index.php');
-*/
\ No newline at end of file
defined('MOODLE_INTERNAL') || die;
-$ADMIN->add('development', new admin_externalpage('toolsimpletest', get_string('pluginname', 'tool_unittest'), "$CFG->wwwroot/$CFG->admin/tool/unittest/index.php", 'tool/unittest:execute'));
-$ADMIN->add('development', new admin_externalpage('tooldbtest', get_string('dbtest', 'tool_unittest'), "$CFG->wwwroot/$CFG->admin/tool/unittest/dbtest.php", 'tool/unittest:execute'));
+$ADMIN->add('development', new admin_externalpage('toolsimpletest', get_string('pluginname', 'tool_unittest'), "$CFG->wwwroot/$CFG->admin/tool/unittest/index.php", 'tool/unittest:execute', true));
<div class="loginbox clearfix">
<div class="loginpanel">
<div>
-<a href="<?php echo $CFG->wwwroot.'/login/index.php?authCAS=CAS';?>"><?php print_string('accesCAS', 'auth_cas');?></a>
+<a href="<?php echo get_login_url() . '?authCAS=CAS';?>"><?php print_string('accesCAS', 'auth_cas');?></a>
</div>
<br/>
<div>
-<a href="<?php echo $CFG->wwwroot.'/login/index.php?authCAS=NOCAS';?>"><?php print_string('accesNOCAS', 'auth_cas');?></a>
+<a href="<?php echo get_login_url() . '?authCAS=NOCAS';?>"><?php print_string('accesNOCAS', 'auth_cas');?></a>
</div>
</div>
</div>
$string['auth_cas_baseuri_key'] = 'Base URI';
$string['auth_cas_broken_password'] = 'You cannot proceed without changing your password, however there is no available page for changing it. Please contact your Moodle Administrator.';
$string['auth_cas_cantconnect'] = 'LDAP part of CAS-module cannot connect to server: {$a}';
-$string['auth_cas_casversion'] = 'Version';
-$string['auth_cas_certificate_check'] = 'Turn this to \'yes\' if you want to validate the server certificate';
+$string['auth_cas_casversion'] = 'CAS protocol version';
+$string['auth_cas_certificate_check'] = 'Select \'yes\' if you want to validate the server certificate';
$string['auth_cas_certificate_path_empty'] = 'If you turn on Server validation, you need to specify a certificate path';
$string['auth_cas_certificate_check_key'] = 'Server validation';
$string['auth_cas_certificate_path'] = 'Path of the CA chain file (PEM Format) to validate the server certificate';
$string['auth_cas_hostname_key'] = 'Hostname';
$string['auth_cas_changepasswordurl'] = 'Password-change URL';
$string['auth_cas_invalidcaslogin'] = 'Sorry, your login has failed - you could not be authorised';
-$string['auth_cas_language'] = 'Selected language';
+$string['auth_cas_language'] = 'Select language for authentication pages';
$string['auth_cas_language_key'] = 'Language';
$string['auth_cas_logincas'] = 'Secure connection access';
-$string['auth_cas_logoutcas'] = 'Turn this to \'yes\' if you want to logout from CAS when you disconnect from Moodle';
-$string['auth_cas_logoutcas_key'] = 'Logout CAS';
-$string['auth_cas_multiauth'] = 'Turn this to \'yes\' if you want to have multi-authentication (CAS + other authentication)';
+$string['auth_cas_logoutcas'] = 'Select \'yes\' if you want to logout from CAS when you disconnect from Moodle';
+$string['auth_cas_logoutcas_key'] = 'CAS logout option';
+$string['auth_cas_multiauth'] = 'Select \'yes\' if you want to have multi-authentication (CAS + other authentication)';
$string['auth_cas_multiauth_key'] = 'Multi-authentication';
$string['auth_casnotinstalled'] = 'Cannot use CAS authentication. The PHP LDAP module is not installed.';
$string['auth_cas_port'] = 'Port of the CAS server';
$string['auth_cas_port_key'] = 'Port';
-$string['auth_cas_proxycas'] = 'Turn this to \'yes\' if you use CASin proxy-mode';
+$string['auth_cas_proxycas'] = 'Select \'yes\' if you use CAS in proxy-mode';
$string['auth_cas_proxycas_key'] = 'Proxy mode';
$string['auth_cas_server_settings'] = 'CAS server configuration';
$string['auth_cas_text'] = 'Secure connection';
$string['auth_cas_use_cas'] = 'Use CAS';
-$string['auth_cas_version'] = 'Version of CAS';
+$string['auth_cas_version'] = 'CAS protocol version to use';
$string['CASform'] = 'Authentication choice';
$string['noldapserver'] = 'No LDAP server configured for CAS! Syncing disabled.';
$string['pluginname'] = 'CAS server (SSO)';
$config->ntlmsso_type = 'ntlm';
}
+ // Try to remove duplicates before storing the contexts (to avoid problems in sync_users()).
+ $config->contexts = explode(';', $config->contexts);
+ $config->contexts = array_map(create_function('$x', 'return textlib::strtolower(trim($x));'),
+ $config->contexts);
+ $config->contexts = implode(';', array_unique($config->contexts));
+
// Save settings
set_config('host_url', trim($config->host_url), $this->pluginconfig);
set_config('ldapencoding', trim($config->ldapencoding), $this->pluginconfig);
- set_config('contexts', trim($config->contexts), $this->pluginconfig);
+ set_config('contexts', $config->contexts, $this->pluginconfig);
set_config('user_type', textlib::strtolower(trim($config->user_type)), $this->pluginconfig);
set_config('user_attribute', textlib::strtolower(trim($config->user_attribute)), $this->pluginconfig);
set_config('search_sub', $config->search_sub, $this->pluginconfig);
}
public function set_status($status) {
+ // Note: never save_controller() with the object info after STATUS_EXECUTING or the whole controller,
+ // containing all the steps will be sent to DB. 100% (monster) useless.
$this->log('setting controller status to', backup::LOG_DEBUG, $status);
- // TODO: Check it's a correct status
+ // TODO: Check it's a correct status.
$this->status = $status;
- // Ensure that, once set to backup::STATUS_AWAITING, controller is stored in DB
- // Note: never save_controller() after STATUS_EXECUTING or the whole controller,
- // containing all the steps will be sent to DB. 100% (monster) useless.
+ // Ensure that, once set to backup::STATUS_AWAITING, controller is stored in DB.
if ($status == backup::STATUS_AWAITING) {
$this->save_controller();
$tbc = self::load_controller($this->backupid);
$this->logger = $tbc->logger; // wakeup loggers
$tbc->destroy(); // Clean temp controller structures
+
+ } else if ($status == backup::STATUS_FINISHED_OK) {
+ // If the operation has ended without error (backup::STATUS_FINISHED_OK)
+ // proceed by cleaning the object from database. MDL-29262.
+ $this->save_controller(false, true);
}
}
backup_helper::log($message, $level, $a, $depth, $display, $this->logger);
}
- public function save_controller() {
+ /**
+ * Save controller information
+ *
+ * @param bool $includeobj to decide if the object itself must be updated (true) or no (false)
+ * @param bool $cleanobj to decide if the object itself must be cleaned (true) or no (false)
+ */
+ public function save_controller($includeobj = true, $cleanobj = false) {
// Going to save controller to persistent storage, calculate checksum for later checks and save it
// TODO: flag the controller as NA. Any operation on it should be forbidden util loaded back
$this->log('saving controller to db', backup::LOG_DEBUG);
- $this->checksum = $this->calculate_checksum();
- backup_controller_dbops::save_controller($this, $this->checksum);
+ if ($includeobj ) { // Only calculate checksum if we are going to include the object.
+ $this->checksum = $this->calculate_checksum();
+ }
+ backup_controller_dbops::save_controller($this, $this->checksum, $includeobj, $cleanobj);
}
public static function load_controller($backupid) {
}
public function set_status($status) {
+ // Note: never save_controller() with the object info after STATUS_EXECUTING or the whole controller,
+ // containing all the steps will be sent to DB. 100% (monster) useless.
$this->log('setting controller status to', backup::LOG_DEBUG, $status);
- // TODO: Check it's a correct status
+ // TODO: Check it's a correct status.
$this->status = $status;
- // Ensure that, once set to backup::STATUS_AWAITING | STATUS_NEED_PRECHECK, controller is stored in DB
- // Note: never save_controller() after STATUS_EXECUTING or the whole controller,
- // containing all the steps will be sent to DB. 100% (monster) useless.
+ // Ensure that, once set to backup::STATUS_AWAITING | STATUS_NEED_PRECHECK, controller is stored in DB.
if ($status == backup::STATUS_AWAITING || $status == backup::STATUS_NEED_PRECHECK) {
$this->save_controller();
$tbc = self::load_controller($this->restoreid);
$this->logger = $tbc->logger; // wakeup loggers
$tbc->destroy(); // Clean temp controller structures
+
+ } else if ($status == backup::STATUS_FINISHED_OK) {
+ // If the operation has ended without error (backup::STATUS_FINISHED_OK)
+ // proceed by cleaning the object from database. MDL-29262.
+ $this->save_controller(false, true);
}
}
backup_helper::log($message, $level, $a, $depth, $display, $this->logger);
}
- public function save_controller() {
+ /**
+ * Save controller information
+ *
+ * @param bool $includeobj to decide if the object itself must be updated (true) or no (false)
+ * @param bool $cleanobj to decide if the object itself must be cleaned (true) or no (false)
+ */
+ public function save_controller($includeobj = true, $cleanobj = false) {
// Going to save controller to persistent storage, calculate checksum for later checks and save it
// TODO: flag the controller as NA. Any operation on it should be forbidden util loaded back
$this->log('saving controller to db', backup::LOG_DEBUG);
- $this->checksum = $this->calculate_checksum();
- restore_controller_dbops::save_controller($this, $this->checksum);
+ if ($includeobj ) { // Only calculate checksum if we are going to include the object.
+ $this->checksum = $this->calculate_checksum();
+ }
+ restore_controller_dbops::save_controller($this, $this->checksum, $includeobj, $cleanobj);
}
public static function load_controller($restoreid) {
+++ /dev/null
-<?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/>.
-
-/**
- * @package moodlecore
- * @subpackage backup-tests
- * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-// Prevent direct access to this file
-if (!defined('MOODLE_INTERNAL')) {
- die('Direct access to this script is forbidden.');
-}
-
-// Include all the needed stuff
-require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
-
-/*
- * controller tests (all)
- */
-class backup_controller_test extends UnitTestCase {
-
- public static $includecoverage = array('backup/controller');
- public static $excludecoverage = array('backup/controller/simpletest');
-
- protected $moduleid; // course_modules id used for testing
- protected $sectionid; // course_sections id used for testing
- protected $courseid; // course id used for testing
- protected $user; // user record used for testing
-
- protected $todelete; // array of records to be deleted after tests
- protected $errorlogloggerlevel; // To store level $CFG->backup_error_log_logger_level
- protected $outputindentedloggerlevel; // To store level $CFG->backup_output_indented_logger_level
- protected $fileloggerlevel; // To store level $CFG->backup_file_logger_level
- protected $databaseloggerlevel; // To store level $CFG->backup_database_logger_level
- protected $fileloggerlevelextra;// To store level $CFG->backup_file_logger_level_extra
-
- function __construct() {
- global $DB, $USER, $CFG;
-
- $this->moduleid = 0;
- $this->sectionid = 0;
- $this->courseid = 0;
- $this->userid = $USER->id;
- $this->todelete = array();
-
- // Check we have (at least) one course_module
- if ($coursemodule = $DB->get_record('course_modules', array(), '*', IGNORE_MULTIPLE)) {
- $this->moduleid = $coursemodule->id;
- $this->sectionid = $coursemodule->section;
- $this->courseid = $coursemodule->course;
- }
-
- // Avoid any logger to be created, we'll restore original settings on tearDown()
- $this->errorlogloggerlevel = isset($CFG->backup_error_log_logger_level) ? $CFG->backup_error_log_logger_level : null;
- $this->outputindentedloggerlevel = isset($CFG->backup_output_indented_logger_level) ? $CFG->backup_output_indented_logger_level : null;
- $this->fileloggerlevel = isset($CFG->backup_file_logger_level) ? $CFG->backup_file_logger_level : null;
- $this->databaseloggerlevel = isset($CFG->backup_database_logger_level) ? $CFG->backup_database_logger_level : null;
- $this->fileloggerlevelextra = isset($CFG->backup_file_logger_level_extra) ? $CFG->backup_file_logger_level_extra : null;
-
- parent::__construct();
- }
-
- function skip() {
- $this->skipIf(empty($this->moduleid), 'backup_controller_test require at least one course module to exist');
- $this->skipIf(empty($this->sectionid),'backup_controller_test require at least one course section to exist');
- $this->skipIf(empty($this->courseid), 'backup_controller_test require at least one course to exist');
- $this->skipIf(empty($this->userid),'backup_controller_test require one valid user to exist');
- }
-
- function setUp() {
- global $CFG;
-
- // Disable all loggers
- $CFG->backup_error_log_logger_level = backup::LOG_NONE;
- $CFG->backup_output_indented_logger_level = backup::LOG_NONE;
- $CFG->backup_file_logger_level = backup::LOG_NONE;
- $CFG->backup_database_logger_level = backup::LOG_NONE;
- $CFG->backup_file_logger_level_extra = backup::LOG_NONE;
- }
-
- function tearDown() {
- global $DB, $CFG;
- // Delete all the records marked to
- foreach ($this->todelete as $todelete) {
- $DB->delete_records($todelete[0], array('id' => $todelete[1]));
- }
- // Restore original file_logger levels
- if ($this->errorlogloggerlevel !== null) {
- $CFG->backup_error_log_logger_level = $this->errorlogloggerlevel;
- } else {
- unset($CFG->backup_error_log_logger_level);
- }
- if ($this->outputindentedloggerlevel !== null) {
- $CFG->backup_output_indented_logger_level = $this->outputindentedloggerlevel;
- } else {
- unset($CFG->backup_output_indented_logger_level);
- }
- if ($this->fileloggerlevel !== null) {
- $CFG->backup_file_logger_level = $this->fileloggerlevel;
- } else {
- unset($CFG->backup_file_logger_level);
- }
- if ($this->databaseloggerlevel !== null) {
- $CFG->backup_database_logger_level = $this->databaseloggerlevel;
- } else {
- unset($CFG->backup_database_logger_level);
- }
- if ($this->fileloggerlevelextra !== null) {
- $CFG->backup_file_logger_level_extra = $this->fileloggerlevelextra;
- } else {
- unset($CFG->backup_file_logger_level_extra);
- }
- }
-
- /*
- * test base_setting class
- */
- function test_backup_controller() {
-
- // Instantiate non interactive backup_controller
- $bc = new mock_backup_controller(backup::TYPE_1ACTIVITY, $this->moduleid, backup::FORMAT_MOODLE,
- backup::INTERACTIVE_NO, backup::MODE_GENERAL, $this->userid);
- $this->assertTrue($bc instanceof backup_controller);
- $this->assertEqual($bc->get_status(), backup::STATUS_AWAITING);
- // Instantiate interactive backup_controller
- $bc = new mock_backup_controller(backup::TYPE_1ACTIVITY, $this->moduleid, backup::FORMAT_MOODLE,
- backup::INTERACTIVE_YES, backup::MODE_GENERAL, $this->userid);
- $this->assertTrue($bc instanceof backup_controller);
- $this->assertEqual($bc->get_status(), backup::STATUS_SETTING_UI);
- $this->assertEqual(strlen($bc->get_backupid()), 32); // is one md5
-
- // Save and load one backup controller to check everything is in place
- $bc = new mock_backup_controller(backup::TYPE_1ACTIVITY, $this->moduleid, backup::FORMAT_MOODLE,
- backup::INTERACTIVE_NO, backup::MODE_GENERAL, $this->userid);
- $recid = $bc->save_controller();
- $newbc = mock_backup_controller::load_controller($bc->get_backupid());
- $this->assertTrue($newbc instanceof backup_controller); // This means checksum and load worked ok
-
- $this->todelete[] = array('backup_controllers', $recid); // mark this record for deletion
- }
-}
-
-/*
- * helper extended @backup_controller class that makes some methods public for testing
- */
-class mock_backup_controller extends backup_controller {
-
- public function save_controller() {
- parent::save_controller();
- }
-}
*/
class mock_backup_controller extends backup_controller {
- public function save_controller() {
- parent::save_controller();
+ public function save_controller($includeobj = true, $cleanobj = false) {
+ parent::save_controller($includeobj, $cleanobj);
}
}
+++ /dev/null
-<?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/>.
-
-/**
- * Unit tests for the moodle1 converter
- *
- * @package core
- * @subpackage backup-convert
- * @copyright 2011 Mark Nielsen <mark@moodlerooms.com>
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-require_once($CFG->dirroot . '/backup/converter/moodle1/lib.php');
-
-class moodle1_converter_test extends UnitTestCase {
-
- public static $includecoverage = array();
-
- /** @var string the name of the directory containing the unpacked Moodle 1.9 backup */
- protected $tempdir;
-
- public function setUp() {
- global $CFG;
-
- $this->tempdir = convert_helper::generate_id('simpletest');
- check_dir_exists("$CFG->tempdir/backup/$this->tempdir/course_files/sub1");
- check_dir_exists("$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/7");
- copy(
- "$CFG->dirroot/backup/converter/moodle1/simpletest/files/moodle.xml",
- "$CFG->tempdir/backup/$this->tempdir/moodle.xml"
- );
- copy(
- "$CFG->dirroot/backup/converter/moodle1/simpletest/files/icon.gif",
- "$CFG->tempdir/backup/$this->tempdir/course_files/file1.gif"
- );
- copy(
- "$CFG->dirroot/backup/converter/moodle1/simpletest/files/icon.gif",
- "$CFG->tempdir/backup/$this->tempdir/course_files/sub1/file2.gif"
- );
- copy(
- "$CFG->dirroot/backup/converter/moodle1/simpletest/files/icon.gif",
- "$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/file1.gif"
- );
- copy(
- "$CFG->dirroot/backup/converter/moodle1/simpletest/files/icon.gif",
- "$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/icon.gif"
- );
- copy(
- "$CFG->dirroot/backup/converter/moodle1/simpletest/files/icon.gif",
- "$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/7/icon.gif"
- );
- }
-
- public function tearDown() {
- global $CFG;
- if (empty($CFG->keeptempdirectoriesonbackup)) {
- fulldelete("$CFG->tempdir/backup/$this->tempdir");
- }
- }
-
- public function test_detect_format() {
- $detected = moodle1_converter::detect_format($this->tempdir);
- $this->assertEqual(backup::FORMAT_MOODLE1, $detected);
- }
-
- public function test_convert_factory() {
- $converter = convert_factory::get_converter('moodle1', $this->tempdir);
- $this->assertIsA($converter, 'moodle1_converter');
- }
-
- public function test_stash_storage_not_created() {
- $converter = convert_factory::get_converter('moodle1', $this->tempdir);
- $this->expectException('moodle1_convert_storage_exception');
- $converter->set_stash('tempinfo', 12);
- }
-
- public function test_stash_requiring_empty_stash() {
- $converter = convert_factory::get_converter('moodle1', $this->tempdir);
- $converter->create_stash_storage();
- $converter->set_stash('tempinfo', 12);
- $this->expectException('moodle1_convert_empty_storage_exception');
- try {
- $converter->get_stash('anothertempinfo');
-
- } catch (moodle1_convert_empty_storage_exception $e) {
- // we must drop the storage here so we are able to re-create it in the next test
- $converter->drop_stash_storage();
- throw new moodle1_convert_empty_storage_exception('rethrowing');
- }
- }
-
- public function test_stash_storage() {
- $converter = convert_factory::get_converter('moodle1', $this->tempdir);
- $converter->create_stash_storage();
-
- // no implicit stashes
- $stashes = $converter->get_stash_names();
- $this->assertIsA($stashes, 'array');
- $this->assertTrue(empty($stashes));
-
- // test stashes without itemid
- $converter->set_stash('tempinfo1', 12);
- $converter->set_stash('tempinfo2', array('a' => 2, 'b' => 3));
- $stashes = $converter->get_stash_names();
- $this->assertIsA($stashes, 'array');
- $this->assertEqual(2, count($stashes));
- $this->assertTrue(in_array('tempinfo1', $stashes));
- $this->assertTrue(in_array('tempinfo2', $stashes));
- $this->assertIdentical(12, $converter->get_stash('tempinfo1'));
- $this->assertIdentical(array('a' => 2, 'b' => 3), $converter->get_stash('tempinfo2'));
-
- // overwriting a stashed value is allowed
- $converter->set_stash('tempinfo1', '13');
- $this->assertNotIdentical(13, $converter->get_stash('tempinfo1'));
- $this->assertIdentical('13', $converter->get_stash('tempinfo1'));
-
- // repeated reading is allowed
- $this->assertIdentical('13', $converter->get_stash('tempinfo1'));
-
- // storing empty array
- $converter->set_stash('empty_array_stash', array());
- $restored = $converter->get_stash('empty_array_stash');
- //$this->assertIsA($restored, 'array'); // todo return null now, this needs MDL-27713 to be fixed, then uncomment
- $this->assertTrue(empty($restored));
-
- // test stashes with itemid
- $converter->set_stash('tempinfo', 'Hello', 1);
- $converter->set_stash('tempinfo', 'World', 2);
- $this->assertIdentical('Hello', $converter->get_stash('tempinfo', 1));
- $this->assertIdentical('World', $converter->get_stash('tempinfo', 2));
-
- // test get_stash_itemids()
- $ids = $converter->get_stash_itemids('course_fileref');
- $this->assertIsA($ids, 'array');
- $this->assertTrue(empty($ids));
-
- $converter->set_stash('course_fileref', null, 34);
- $converter->set_stash('course_fileref', null, 52);
- $ids = $converter->get_stash_itemids('course_fileref');
- $this->assertEqual(2, count($ids));
- $this->assertTrue(in_array(34, $ids));
- $this->assertTrue(in_array(52, $ids));
-
- $converter->drop_stash_storage();
- }
-
- public function test_get_stash_or_default() {
- $converter = convert_factory::get_converter('moodle1', $this->tempdir);
- $converter->create_stash_storage();
-
- $this->assertTrue(is_null($converter->get_stash_or_default('stashname')));
- $this->assertTrue(is_null($converter->get_stash_or_default('stashname', 7)));
- $this->assertTrue('default' === $converter->get_stash_or_default('stashname', 0, 'default'));
- $this->assertTrue(array('foo', 'bar') === $converter->get_stash_or_default('stashname', 42, array('foo', 'bar')));
-
- //$converter->set_stash('stashname', 0);
- //$this->assertFalse(is_null($converter->get_stash_or_default('stashname'))); // todo returns true now, this needs MDL-27713 to be fixed
-
- //$converter->set_stash('stashname', '');
- //$this->assertFalse(is_null($converter->get_stash_or_default('stashname'))); // todo returns true now, this needs MDL-27713 to be fixed
-
- //$converter->set_stash('stashname', array());
- //$this->assertFalse(is_null($converter->get_stash_or_default('stashname'))); // todo returns true now, this needs MDL-27713 to be fixed
-
- $converter->set_stash('stashname', 42);
- $this->assertTrue(42 === $converter->get_stash_or_default('stashname'));
- $this->assertTrue(is_null($converter->get_stash_or_default('stashname', 1)));
- $this->assertTrue(42 === $converter->get_stash_or_default('stashname', 0, 61));
-
- $converter->set_stash('stashname', array(42 => (object)array('id' => 42)), 18);
- $stashed = $converter->get_stash_or_default('stashname', 18, 1984);
- $this->assertIsA($stashed, 'array');
- $this->assertTrue(is_object($stashed[42]));
- $this->assertTrue($stashed[42]->id === 42);
-
- $converter->drop_stash_storage();
- }
-
- public function test_get_contextid() {
- $converter = convert_factory::get_converter('moodle1', $this->tempdir);
-
- // stash storage must be created in advance
- $converter->create_stash_storage();
-
- // ids are generated on the first call
- $id1 = $converter->get_contextid(CONTEXT_BLOCK, 10);
- $id2 = $converter->get_contextid(CONTEXT_BLOCK, 11);
- $id3 = $converter->get_contextid(CONTEXT_MODULE, 10);
-
- $this->assertNotEqual($id1, $id2);
- $this->assertNotEqual($id1, $id3);
- $this->assertNotEqual($id2, $id3);
-
- // and then re-used if called with the same params
- $this->assertEqual($id1, $converter->get_contextid(CONTEXT_BLOCK, 10));
- $this->assertEqual($id2, $converter->get_contextid(CONTEXT_BLOCK, 11));
- $this->assertEqual($id3, $converter->get_contextid(CONTEXT_MODULE, 10));
-
- // for system and course level, the instance is irrelevant
- // as we need only one system and one course
- $id1 = $converter->get_contextid(CONTEXT_COURSE);
- $id2 = $converter->get_contextid(CONTEXT_COURSE, 10);
- $id3 = $converter->get_contextid(CONTEXT_COURSE, 14);
-
- $this->assertEqual($id1, $id2);
- $this->assertEqual($id1, $id3);
-
- $id1 = $converter->get_contextid(CONTEXT_SYSTEM);
- $id2 = $converter->get_contextid(CONTEXT_SYSTEM, 11);
- $id3 = $converter->get_contextid(CONTEXT_SYSTEM, 15);
-
- $this->assertEqual($id1, $id2);
- $this->assertEqual($id1, $id3);
-
- $converter->drop_stash_storage();
- }
-
- public function test_get_nextid() {
- $converter = convert_factory::get_converter('moodle1', $this->tempdir);
-
- $id1 = $converter->get_nextid();
- $id2 = $converter->get_nextid();
- $id3 = $converter->get_nextid();
-
- $this->assertTrue(0 < $id1);
- $this->assertTrue($id1 < $id2);
- $this->assertTrue($id2 < $id3);
- }
-
- public function test_migrate_file() {
- // set-up the file manager
- $converter = convert_factory::get_converter('moodle1', $this->tempdir);
- $converter->create_stash_storage();
- $contextid = $converter->get_contextid(CONTEXT_MODULE, 32);
- $fileman = $converter->get_file_manager($contextid, 'mod_unittest', 'testarea');
- // this fileman has not converted anything yet
- $fileids = $fileman->get_fileids();
- $this->assertIsA($fileids, 'array');
- $this->assertEqual(0, count($fileids));
- // try to migrate a non-existing directory
- $returned = $fileman->migrate_directory('not/existing/directory');
- $this->assertIsA($returned, 'array');
- $this->assertEqual(0, count($returned));
- $fileids = $fileman->get_fileids();
- $this->assertIsA($fileids, 'array');
- $this->assertEqual(0, count($fileids));
- // migrate a single file
- $fileman->itemid = 4;
- $fileman->migrate_file('moddata/unittest/4/icon.gif');
- $this->assertTrue(is_file($converter->get_workdir_path().'/files/4e/4ea114b0558f53e3af8dd9afc0e0810a95c2a724'));
- // get the file id
- $fileids = $fileman->get_fileids();
- $this->assertIsA($fileids, 'array');
- $this->assertEqual(1, count($fileids));
- // migrate another single file into another file area
- $fileman->filearea = 'anotherarea';
- $fileman->itemid = 7;
- $fileman->migrate_file('moddata/unittest/4/7/icon.gif', '/', 'renamed.gif');
- // get the file records
- $filerecordids = $converter->get_stash_itemids('files');
- foreach ($filerecordids as $filerecordid) {
- $filerecord = $converter->get_stash('files', $filerecordid);
- $this->assertEqual('4ea114b0558f53e3af8dd9afc0e0810a95c2a724', $filerecord['contenthash']);
- $this->assertEqual($contextid, $filerecord['contextid']);
- $this->assertEqual('mod_unittest', $filerecord['component']);
- if ($filerecord['filearea'] === 'testarea') {
- $this->assertEqual(4, $filerecord['itemid']);
- $this->assertEqual('icon.gif', $filerecord['filename']);
- }
- }
- // explicitly clear the list of migrated files
- $this->assertTrue(count($fileman->get_fileids()) > 0);
- $fileman->reset_fileids();
- $this->assertTrue(count($fileman->get_fileids()) == 0);
- $converter->drop_stash_storage();
- }
-
- public function test_convert_path() {
- $path = new convert_path('foo_bar', '/ROOT/THINGS/FOO/BAR');
- $this->assertEqual('foo_bar', $path->get_name());
- $this->assertEqual('/ROOT/THINGS/FOO/BAR', $path->get_path());
- $this->assertEqual('process_foo_bar', $path->get_processing_method());
- $this->assertEqual('on_foo_bar_start', $path->get_start_method());
- $this->assertEqual('on_foo_bar_end', $path->get_end_method());
- }
-
- public function test_convert_path_implicit_recipes() {
- $path = new convert_path('foo_bar', '/ROOT/THINGS/FOO/BAR');
- $data = array(
- 'ID' => 76,
- 'ELOY' => 'stronk7',
- 'MARTIN' => 'moodler',
- 'EMPTY' => null,
- );
- // apply default recipes (converting keys to lowercase)
- $data = $path->apply_recipes($data);
- $this->assertEqual(4, count($data));
- $this->assertEqual(76, $data['id']);
- $this->assertEqual('stronk7', $data['eloy']);
- $this->assertEqual('moodler', $data['martin']);
- $this->assertIdentical(null, $data['empty']);
- }
-
- public function test_convert_path_explicit_recipes() {
- $path = new convert_path(
- 'foo_bar', '/ROOT/THINGS/FOO/BAR',
- array(
- 'newfields' => array(
- 'david' => 'mudrd8mz',
- 'petr' => 'skodak',
- ),
- 'renamefields' => array(
- 'empty' => 'nothing',
- ),
- 'dropfields' => array(
- 'id'
- ),
- )
- );
- $data = array(
- 'ID' => 76,
- 'ELOY' => 'stronk7',
- 'MARTIN' => 'moodler',
- 'EMPTY' => null,
- );
- $data = $path->apply_recipes($data);
-
- $this->assertEqual(5, count($data));
- $this->assertFalse(array_key_exists('id', $data));
- $this->assertEqual('stronk7', $data['eloy']);
- $this->assertEqual('moodler', $data['martin']);
- $this->assertEqual('mudrd8mz', $data['david']);
- $this->assertEqual('skodak', $data['petr']);
- $this->assertIdentical(null, $data['nothing']);
- }
-
- public function test_grouped_data_on_nongrouped_convert_path() {
- // prepare some grouped data
- $data = array(
- 'ID' => 77,
- 'NAME' => 'Pale lagers',
- 'BEERS' => array(
- array(
- 'BEER' => array(
- 'ID' => 67,
- 'NAME' => 'Pilsner Urquell',
- )
- ),
- array(
- 'BEER' => array(
- 'ID' => 34,
- 'NAME' => 'Heineken',
- )
- ),
- )
- );
-
- // declare a non-grouped path
- $path = new convert_path('beer_style', '/ROOT/BEER_STYLES/BEER_STYLE');
-
- // an attempt to apply recipes throws exception because we do not expect grouped data
- $this->expectException('convert_path_exception');
- $data = $path->apply_recipes($data);
- }
-
- public function test_grouped_convert_path_with_recipes() {
- // prepare some grouped data
- $data = array(
- 'ID' => 77,
- 'NAME' => 'Pale lagers',
- 'BEERS' => array(
- array(
- 'BEER' => array(
- 'ID' => 67,
- 'NAME' => 'Pilsner Urquell',
- )
- ),
- array(
- 'BEER' => array(
- 'ID' => 34,
- 'NAME' => 'Heineken',
- )
- ),
- )
- );
-
- // implict recipes work for grouped data if the path is declared as grouped
- $path = new convert_path('beer_style', '/ROOT/BEER_STYLES/BEER_STYLE', array(), true);
- $data = $path->apply_recipes($data);
- $this->assertEqual('Heineken', $data['beers'][1]['beer']['name']);
-
- // an attempt to provide explicit recipes on grouped elements throws exception
- $this->expectException('convert_path_exception');
- $path = new convert_path(
- 'beer_style', '/ROOT/BEER_STYLES/BEER_STYLE',
- array(
- 'renamefields' => array(
- 'name' => 'beername', // note this is confusing recipe because the 'name' is used for both
- // beer-style name ('Pale lagers') and beer name ('Pilsner Urquell')
- )
- ), true);
- }
-
- public function test_referenced_course_files() {
-
- $text = 'This is a text containing links to file.php
-as it is parsed from the backup file. <br /><br /><img border="0" width="110" vspace="0" hspace="0" height="92" title="News" alt="News" src="$@FILEPHP@$$@SLASH@$pics$@SLASH@$news.gif" /><a href="$@FILEPHP@$$@SLASH@$pics$@SLASH@$news.gif$@FORCEDOWNLOAD@$">download image</a><br />
- <br /><a href=\'$@FILEPHP@$$@SLASH@$MANUAL.DOC$@FORCEDOWNLOAD@$\'>download manual</a><br />';
-
- $files = moodle1_converter::find_referenced_files($text);
- $this->assertIsA($files, 'array');
- $this->assertEqual(2, count($files));
- $this->assertTrue(in_array('/pics/news.gif', $files));
- $this->assertTrue(in_array('/MANUAL.DOC', $files));
-
- $text = moodle1_converter::rewrite_filephp_usage($text, array('/pics/news.gif', '/another/file/notused.txt'), $files);
- $this->assertEqual($text, 'This is a text containing links to file.php
-as it is parsed from the backup file. <br /><br /><img border="0" width="110" vspace="0" hspace="0" height="92" title="News" alt="News" src="@@PLUGINFILE@@/pics/news.gif" /><a href="@@PLUGINFILE@@/pics/news.gif?forcedownload=1">download image</a><br />
- <br /><a href=\'$@FILEPHP@$$@SLASH@$MANUAL.DOC$@FORCEDOWNLOAD@$\'>download manual</a><br />');
- }
-
- public function test_question_bank_conversion() {
- global $CFG;
-
- copy(
- "$CFG->dirroot/backup/converter/moodle1/simpletest/files/questions.xml",
- "$CFG->tempdir/backup/$this->tempdir/moodle.xml"
- );
- $converter = convert_factory::get_converter('moodle1', $this->tempdir);
- $converter->convert();
- }
-
- public function test_convert_run_convert() {
- $converter = convert_factory::get_converter('moodle1', $this->tempdir);
- $converter->convert();
- }
-
- public function test_inforef_manager() {
- $converter = convert_factory::get_converter('moodle1', $this->tempdir);
- $inforef = $converter->get_inforef_manager('unittest');
- $inforef->add_ref('file', 45);
- $inforef->add_refs('file', array(46, 47));
- // todo test the write_refs() via some dummy xml_writer
- $this->expectException('coding_exception');
- $inforef->add_ref('unknown_referenced_item_name', 76);
- }
-}
protected function setUp() {
global $CFG;
- $this->tempdir = convert_helper::generate_id('simpletest');
+ $this->tempdir = convert_helper::generate_id('unittest');
check_dir_exists("$CFG->tempdir/backup/$this->tempdir/course_files/sub1");
check_dir_exists("$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/7");
copy(
- "$CFG->dirroot/backup/converter/moodle1/simpletest/files/moodle.xml",
+ "$CFG->dirroot/backup/converter/moodle1/tests/fixtures/moodle.xml",
"$CFG->tempdir/backup/$this->tempdir/moodle.xml"
);
copy(
- "$CFG->dirroot/backup/converter/moodle1/simpletest/files/icon.gif",
+ "$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
"$CFG->tempdir/backup/$this->tempdir/course_files/file1.gif"
);
copy(
- "$CFG->dirroot/backup/converter/moodle1/simpletest/files/icon.gif",
+ "$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
"$CFG->tempdir/backup/$this->tempdir/course_files/sub1/file2.gif"
);
copy(
- "$CFG->dirroot/backup/converter/moodle1/simpletest/files/icon.gif",
+ "$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
"$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/file1.gif"
);
copy(
- "$CFG->dirroot/backup/converter/moodle1/simpletest/files/icon.gif",
+ "$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
"$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/icon.gif"
);
copy(
- "$CFG->dirroot/backup/converter/moodle1/simpletest/files/icon.gif",
+ "$CFG->dirroot/backup/converter/moodle1/tests/fixtures/icon.gif",
"$CFG->tempdir/backup/$this->tempdir/moddata/unittest/4/7/icon.gif"
);
}
$this->resetAfterTest(true);
copy(
- "$CFG->dirroot/backup/converter/moodle1/simpletest/files/questions.xml",
+ "$CFG->dirroot/backup/converter/moodle1/tests/fixtures/questions.xml",
"$CFG->tempdir/backup/$this->tempdir/moodle.xml"
);
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
$this->add_step(new restore_gradebook_structure_step('gradebook_step','gradebook.xml'));
}
- // Course completion
- $this->add_step(new restore_course_completion_structure_step('course_completion', 'completion.xml'));
+ // Course completion, executed conditionally if restoring to new course
+ if ($this->get_target() !== backup::TARGET_CURRENT_ADDING &&
+ $this->get_target() !== backup::TARGET_EXISTING_ADDING) {
+ $this->add_step(new restore_course_completion_structure_step('course_completion', 'completion.xml'));
+ }
// Review all the module_availability records in backup_ids in order
// to match them with existing modules / grade items.
+++ /dev/null
-<?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/>.
-
-/**
- * @package moodlecore
- * @subpackage backup-tests
- * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-// Prevent direct access to this file
-if (!defined('MOODLE_INTERNAL')) {
- die('Direct access to this script is forbidden.');
-}
-
-// Include all the needed stuff
-require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
-
-/*
- * check tests (all)
- */
-class backup_check_test extends UnitTestCase {
-
- public static $includecoverage = array('backup/util/checks');
- public static $excludecoverage = array('backup/util/checks/simpletest');
-
- protected $moduleid; // course_modules id used for testing
- protected $sectionid; // course_sections id used for testing
- protected $courseid; // course id used for testing
- protected $userid; // user record id
-
- protected $errorlogloggerlevel; // To store $CFG->backup_error_log_logger_level
- protected $fileloggerlevel; // To store level $CFG->backup_file_logger_level
- protected $databaseloggerlevel; // To store $CFG->backup_database_logger_level
- protected $outputindentedloggerlevel; // To store $CFG->backup_output_indented_logger_level
- protected $fileloggerextra; // To store $CFG->backup_file_logger_extra
- protected $fileloggerlevelextra; // To store level $CFG->backup_file_logger_level_extra
- protected $debugging; // To store $CFG->debug
- protected $debugdisplay; // To store $CFG->debugdisplay
-
- function __construct() {
- global $DB, $USER, $CFG;
-
- $this->moduleid = 0;
- $this->sectionid = 0;
- $this->courseid = 0;
- $this->userid = $USER->id;
-
- // Check we have (at least) one course_module
- if ($coursemodule = $DB->get_record('course_modules', array(), '*', IGNORE_MULTIPLE)) {
- $this->moduleid = $coursemodule->id;
- $this->sectionid = $coursemodule->section;
- $this->courseid = $coursemodule->course;
- }
- parent::__construct();
- }
-
- function skip() {
- $this->skipIf(empty($this->moduleid), 'backup_check_test require at least one course module to exist');
- $this->skipIf(empty($this->sectionid),'backup_check_test require at least one course section to exist');
- $this->skipIf(empty($this->courseid), 'backup_check_test require at least one course to exist');
- $this->skipIf(empty($this->userid),'backup_check_test require one valid user to exist');
- }
-
- function setUp() {
- global $CFG;
- parent::setUp();
- // Avoid any file logger to be created, we'll restore original settings on tearDown()
- // Fetch the rest of CFG variables to be able to restore them after tests
- // and normalize default values
- $this->errorlogloggerlevel = isset($CFG->backup_error_log_logger_level) ? $CFG->backup_error_log_logger_level : null;
- $CFG->backup_error_log_logger_level = backup::LOG_NONE;
-
- $this->outputindentedloggerlevel = isset($CFG->backup_output_indented_logger_level) ? $CFG->backup_output_indented_logger_level : null;
- $CFG->backup_output_indented_logger_level = backup::LOG_NONE;
-
- $this->fileloggerlevel = isset($CFG->backup_file_logger_level) ? $CFG->backup_file_logger_level : null;
- $CFG->backup_file_logger_level = backup::LOG_NONE;
-
- $this->databaseloggerlevel = isset($CFG->backup_database_logger_level) ? $CFG->backup_database_logger_level : null;
- $CFG->backup_database_logger_level = backup::LOG_NONE;
-
- $this->fileloggerextra = isset($CFG->backup_file_logger_extra) ? $CFG->backup_file_logger_extra : null;
- unset($CFG->backup_file_logger_extra);
- $this->fileloggerlevelextra = isset($CFG->backup_file_logger_level_extra) ? $CFG->backup_file_logger_level_extra : null;
- $CFG->backup_file_logger_level_extra = backup::LOG_NONE;
-
- $this->debugging = isset($CFG->debug) ? $CFG->debug : null;
- $this->debugdisplay = isset($CFG->debugdisplay) ? $CFG->debugdisplay : null;
- }
-
- function tearDown() {
- global $CFG;
- // Restore original file_logger levels
- if ($this->errorlogloggerlevel !== null) {
- $CFG->backup_error_log_logger_level = $this->errorlogloggerlevel;
- } else {
- unset($CFG->backup_error_log_logger_level);
- }
-
- if ($this->outputindentedloggerlevel !== null) {
- $CFG->backup_output_indented_logger_level = $this->outputindentedloggerlevel;
- } else {
- unset($CFG->backup_output_indented_logger_level);
- }
-
- if ($this->fileloggerlevel !== null) {
- $CFG->backup_file_logger_level = $this->fileloggerlevel;
- } else {
- unset($CFG->backup_file_logger_level);
- }
-
- if ($this->databaseloggerlevel !== null) {
- $CFG->backup_database_logger_level = $this->databaseloggerlevel;
- } else {
- unset($CFG->backup_database_logger_level);
- }
-
- if ($this->fileloggerextra !== null) {
- $CFG->backup_file_logger_extra = $this->fileloggerextra;
- } else {
- unset($CFG->backup_file_logger_extra);
- }
- if ($this->fileloggerlevelextra !== null) {
- $CFG->backup_file_logger_level_extra = $this->fileloggerlevelextra;
- } else {
- unset($CFG->backup_file_logger_level_extra);
- }
- // Restore the rest of $CFG settings
- if ($this->debugging !== null) {
- $CFG->debug = $this->debugging;
- } else {
- unset($CFG->debug);
- }
- if ($this->debugdisplay !== null) {
- $CFG->debugdisplay = $this->debugdisplay;
- } else {
- unset($CFG->debugdisplay);
- }
- parent::tearDown();
- }
-
- /*
- * test backup_check class
- */
- function test_backup_check() {
-
- // Check against existing course module/section course or fail
- $this->assertTrue(backup_check::check_id(backup::TYPE_1ACTIVITY, $this->moduleid));
- $this->assertTrue(backup_check::check_id(backup::TYPE_1SECTION, $this->sectionid));
- $this->assertTrue(backup_check::check_id(backup::TYPE_1COURSE, $this->courseid));
- $this->assertTrue(backup_check::check_user($this->userid));
-
- // Check agains non-existing course module/section/course (0)
- try {
- backup_check::check_id(backup::TYPE_1ACTIVITY, 0);
- $this->assertTrue(false, 'backup_controller_exception expected');
- } catch (exception $e) {
- $this->assertTrue($e instanceof backup_controller_exception);
- $this->assertEqual($e->errorcode, 'backup_check_module_not_exists');
- }
- try {
- backup_check::check_id(backup::TYPE_1SECTION, 0);
- $this->assertTrue(false, 'backup_controller_exception expected');
- } catch (exception $e) {
- $this->assertTrue($e instanceof backup_controller_exception);
- $this->assertEqual($e->errorcode, 'backup_check_section_not_exists');
- }
- try {
- backup_check::check_id(backup::TYPE_1COURSE, 0);
- $this->assertTrue(false, 'backup_controller_exception expected');
- } catch (exception $e) {
- $this->assertTrue($e instanceof backup_controller_exception);
- $this->assertEqual($e->errorcode, 'backup_check_course_not_exists');
- }
-
- // Try wrong type
- try {
- backup_check::check_id(12345678,0);
- $this->assertTrue(false, 'backup_controller_exception expected');
- } catch (exception $e) {
- $this->assertTrue($e instanceof backup_controller_exception);
- $this->assertEqual($e->errorcode, 'backup_check_incorrect_type');
- }
-
- // Test non-existing user
- $userid = 0;
- try {
- backup_check::check_user($userid);
- $this->assertTrue(false, 'backup_controller_exception expected');
- } catch (exception $e) {
- $this->assertTrue($e instanceof backup_controller_exception);
- $this->assertEqual($e->errorcode, 'backup_check_user_not_exists');
- }
-
- // Security check tests
- // Try to pass wrong controller
- try {
- backup_check::check_security(new stdclass(), true);
- $this->assertTrue(false, 'backup_controller_exception expected');
- } catch (exception $e) {
- $this->assertTrue($e instanceof backup_controller_exception);
- $this->assertEqual($e->errorcode, 'backup_check_security_requires_backup_controller');
- }
-
- // Pass correct controller, check must return true in any case with $apply enabled
- &nbs