예제 #1
0
/**
 * Upgrade moodle core
 * @param float $version target version
 * @param bool $verbose
 * @return void, may throw exception
 */
function upgrade_core($version, $verbose) {
    global $CFG, $SITE, $DB, $COURSE;

    raise_memory_limit(MEMORY_EXTRA);

    require_once($CFG->libdir.'/db/upgrade.php');    // Defines upgrades

    try {
        // Reset caches before any output.
        cache_helper::purge_all(true);
        purge_all_caches();

        // Upgrade current language pack if we can
        upgrade_language_pack();

        print_upgrade_part_start('moodle', false, $verbose);

        // Pre-upgrade scripts for local hack workarounds.
        $preupgradefile = "$CFG->dirroot/local/preupgrade.php";
        if (file_exists($preupgradefile)) {
            core_php_time_limit::raise();
            require($preupgradefile);
            // Reset upgrade timeout to default.
            upgrade_set_timeout();
        }

        $result = xmldb_main_upgrade($CFG->version);
        if ($version > $CFG->version) {
            // store version if not already there
            upgrade_main_savepoint($result, $version, false);
        }

        // In case structure of 'course' table has been changed and we forgot to update $SITE, re-read it from db.
        $SITE = $DB->get_record('course', array('id' => $SITE->id));
        $COURSE = clone($SITE);

        // perform all other component upgrade routines
        update_capabilities('moodle');
        log_update_descriptions('moodle');
        external_update_descriptions('moodle');
        events_update_definition('moodle');
        \core\task\manager::reset_scheduled_tasks_for_component('moodle');
        message_update_providers('moodle');
        \core\message\inbound\manager::update_handlers_for_component('moodle');
        // Update core definitions.
        cache_helper::update_definitions(true);

        // Purge caches again, just to be sure we arn't holding onto old stuff now.
        cache_helper::purge_all(true);
        purge_all_caches();

        // Clean up contexts - more and more stuff depends on existence of paths and contexts
        context_helper::cleanup_instances();
        context_helper::create_instances(null, false);
        context_helper::build_all_paths(false);
        $syscontext = context_system::instance();
        $syscontext->mark_dirty();

        print_upgrade_part_end('moodle', false, $verbose);
    } catch (Exception $ex) {
        upgrade_handle_exception($ex);
    }
}
 public function test_reset_scheduled_tasks_for_component()
 {
     global $DB;
     $this->resetAfterTest(true);
     // Remember the defaults.
     $defaulttasks = \core\task\manager::load_scheduled_tasks_for_component('moodle');
     $initcount = count($defaulttasks);
     // Customise a task.
     $firsttask = reset($defaulttasks);
     $firsttask->set_minute('1');
     $firsttask->set_hour('2');
     $firsttask->set_month('3');
     $firsttask->set_day_of_week('4');
     $firsttask->set_day('5');
     $firsttask->set_customised('1');
     \core\task\manager::configure_scheduled_task($firsttask);
     $firsttaskrecord = \core\task\manager::record_from_scheduled_task($firsttask);
     // We reset this field, because we do not want to compare it.
     $firsttaskrecord->nextruntime = '0';
     // Delete a task to simulate the fact that its new.
     $secondtask = next($defaulttasks);
     $DB->delete_records('task_scheduled', array('classname' => '\\' . trim(get_class($secondtask), '\\')));
     $this->assertFalse(\core\task\manager::get_scheduled_task(get_class($secondtask)));
     // Edit a task to simulate a change in its definition (as if it was not customised).
     $thirdtask = next($defaulttasks);
     $thirdtask->set_minute('1');
     $thirdtask->set_hour('2');
     $thirdtask->set_month('3');
     $thirdtask->set_day_of_week('4');
     $thirdtask->set_day('5');
     $thirdtaskbefore = \core\task\manager::get_scheduled_task(get_class($thirdtask));
     $thirdtaskbefore->set_next_run_time(null);
     // Ignore this value when comparing.
     \core\task\manager::configure_scheduled_task($thirdtask);
     $thirdtask = \core\task\manager::get_scheduled_task(get_class($thirdtask));
     $thirdtask->set_next_run_time(null);
     // Ignore this value when comparing.
     $this->assertNotEquals($thirdtaskbefore, $thirdtask);
     // Now call reset on all the tasks.
     \core\task\manager::reset_scheduled_tasks_for_component('moodle');
     // Load the tasks again.
     $defaulttasks = \core\task\manager::load_scheduled_tasks_for_component('moodle');
     $finalcount = count($defaulttasks);
     // Compare the first task.
     $newfirsttask = reset($defaulttasks);
     $newfirsttaskrecord = \core\task\manager::record_from_scheduled_task($newfirsttask);
     // We reset this field, because we do not want to compare it.
     $newfirsttaskrecord->nextruntime = '0';
     // Assert a customised task was not altered by reset.
     $this->assertEquals($firsttaskrecord, $newfirsttaskrecord);
     // Assert that the second task was added back.
     $secondtaskafter = \core\task\manager::get_scheduled_task(get_class($secondtask));
     $secondtaskafter->set_next_run_time(null);
     // Do not compare the nextruntime.
     $secondtask->set_next_run_time(null);
     $this->assertEquals($secondtask, $secondtaskafter);
     // Assert that the third task edits were overridden.
     $thirdtaskafter = \core\task\manager::get_scheduled_task(get_class($thirdtask));
     $thirdtaskafter->set_next_run_time(null);
     $this->assertEquals($thirdtaskbefore, $thirdtaskafter);
     // Assert we have the same number of tasks.
     $this->assertEquals($initcount, $finalcount);
 }
    public function test_reset_scheduled_tasks_for_component() {
        global $DB;

        $this->resetAfterTest(true);
        // Remember the defaults.
        $defaulttasks = \core\task\manager::load_scheduled_tasks_for_component('moodle');
        $initcount = count($defaulttasks);
        // Customise a task.
        $firsttask = reset($defaulttasks);
        $firsttask->set_minute('1');
        $firsttask->set_hour('2');
        $firsttask->set_month('3');
        $firsttask->set_day_of_week('4');
        $firsttask->set_day('5');
        $firsttask->set_customised('1');
        \core\task\manager::configure_scheduled_task($firsttask);
        $firsttaskrecord = \core\task\manager::record_from_scheduled_task($firsttask);
        // We reset this field, because we do not want to compare it.
        $firsttaskrecord->nextruntime = '0';

        // Now call reset on all the tasks.
        \core\task\manager::reset_scheduled_tasks_for_component('moodle');

        // Load the tasks again.
        $defaulttasks = \core\task\manager::load_scheduled_tasks_for_component('moodle');
        $finalcount = count($defaulttasks);
        // Compare the first task.
        $newfirsttask = reset($defaulttasks);
        $newfirsttaskrecord = \core\task\manager::record_from_scheduled_task($newfirsttask);
        // We reset this field, because we do not want to compare it.
        $newfirsttaskrecord->nextruntime = '0';

        // Assert a customised task was not altered by reset.
        $this->assertEquals($firsttaskrecord, $newfirsttaskrecord);

        // Assert we have the same number of tasks.
        $this->assertEquals($initcount, $finalcount);
    }
예제 #4
0
 /**
  * Tests that the reset function deletes old tasks.
  */
 public function test_reset_scheduled_tasks_for_component_delete()
 {
     global $DB;
     $this->resetAfterTest(true);
     $count = $DB->count_records('task_scheduled', array('component' => 'moodle'));
     $allcount = $DB->count_records('task_scheduled');
     $task = new \core\task\scheduled_test_task();
     $task->set_component('moodle');
     $record = \core\task\manager::record_from_scheduled_task($task);
     $DB->insert_record('task_scheduled', $record);
     $this->assertTrue($DB->record_exists('task_scheduled', array('classname' => '\\core\\task\\scheduled_test_task', 'component' => 'moodle')));
     $task = new \core\task\scheduled_test2_task();
     $task->set_component('moodle');
     $record = \core\task\manager::record_from_scheduled_task($task);
     $DB->insert_record('task_scheduled', $record);
     $this->assertTrue($DB->record_exists('task_scheduled', array('classname' => '\\core\\task\\scheduled_test2_task', 'component' => 'moodle')));
     $aftercount = $DB->count_records('task_scheduled', array('component' => 'moodle'));
     $afterallcount = $DB->count_records('task_scheduled');
     $this->assertEquals($count + 2, $aftercount);
     $this->assertEquals($allcount + 2, $afterallcount);
     // Now check that the right things were deleted.
     \core\task\manager::reset_scheduled_tasks_for_component('moodle');
     $this->assertEquals($count, $DB->count_records('task_scheduled', array('component' => 'moodle')));
     $this->assertEquals($allcount, $DB->count_records('task_scheduled'));
     $this->assertFalse($DB->record_exists('task_scheduled', array('classname' => '\\core\\task\\scheduled_test2_task', 'component' => 'moodle')));
     $this->assertFalse($DB->record_exists('task_scheduled', array('classname' => '\\core\\task\\scheduled_test_task', 'component' => 'moodle')));
 }