本文整理匯總了PHP中core\task\manager::record_from_scheduled_task方法的典型用法代碼示例。如果您正苦於以下問題:PHP manager::record_from_scheduled_task方法的具體用法?PHP manager::record_from_scheduled_task怎麽用?PHP manager::record_from_scheduled_task使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類core\task\manager
的用法示例。
在下文中一共展示了manager::record_from_scheduled_task方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: definition
public function definition()
{
$mform = $this->_form;
/** @var \core\task\scheduled_task $task */
$task = $this->_customdata;
$lastrun = $task->get_last_run_time() ? userdate($task->get_last_run_time()) : get_string('never');
$nextrun = $task->get_next_run_time();
if ($task->get_disabled()) {
$nextrun = get_string('disabled', 'tool_task');
} else {
if ($nextrun > time()) {
$nextrun = userdate($nextrun);
} else {
$nextrun = get_string('asap', 'tool_task');
}
}
$mform->addElement('static', 'lastrun', get_string('lastruntime', 'tool_task'), $lastrun);
$mform->addElement('static', 'nextrun', get_string('nextruntime', 'tool_task'), $nextrun);
$mform->addElement('text', 'minute', get_string('taskscheduleminute', 'tool_task'));
$mform->setType('minute', PARAM_RAW);
$mform->addHelpButton('minute', 'taskscheduleminute', 'tool_task');
$mform->addElement('text', 'hour', get_string('taskschedulehour', 'tool_task'));
$mform->setType('hour', PARAM_RAW);
$mform->addHelpButton('hour', 'taskschedulehour', 'tool_task');
$mform->addElement('text', 'day', get_string('taskscheduleday', 'tool_task'));
$mform->setType('day', PARAM_RAW);
$mform->addHelpButton('day', 'taskscheduleday', 'tool_task');
$mform->addElement('text', 'month', get_string('taskschedulemonth', 'tool_task'));
$mform->setType('month', PARAM_RAW);
$mform->addHelpButton('month', 'taskschedulemonth', 'tool_task');
$mform->addElement('text', 'dayofweek', get_string('taskscheduledayofweek', 'tool_task'));
$mform->setType('dayofweek', PARAM_RAW);
$mform->addHelpButton('dayofweek', 'taskscheduledayofweek', 'tool_task');
$mform->addElement('advcheckbox', 'disabled', get_string('disabled', 'tool_task'));
$mform->addHelpButton('disabled', 'disabled', 'tool_task');
$mform->addElement('advcheckbox', 'resettodefaults', get_string('resettasktodefaults', 'tool_task'));
$mform->addHelpButton('resettodefaults', 'resettasktodefaults', 'tool_task');
$mform->disabledIf('minute', 'resettodefaults', 'checked');
$mform->disabledIf('hour', 'resettodefaults', 'checked');
$mform->disabledIf('day', 'resettodefaults', 'checked');
$mform->disabledIf('dayofweek', 'resettodefaults', 'checked');
$mform->disabledIf('month', 'resettodefaults', 'checked');
$mform->disabledIf('disabled', 'resettodefaults', 'checked');
$mform->addElement('hidden', 'task', get_class($task));
$mform->setType('task', PARAM_RAW);
$mform->addElement('hidden', 'action', 'edit');
$mform->setType('action', PARAM_ALPHANUMEXT);
$this->add_action_buttons(true, get_string('savechanges'));
// Do not use defaults for existing values, the set_data() is the correct way.
$this->set_data(\core\task\manager::record_from_scheduled_task($task));
}
示例2: test_reset_scheduled_tasks_for_component
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);
}
示例3: test_reset_scheduled_tasks_for_component
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);
}
示例4: test_reset_scheduled_tasks_for_component_delete
/**
* 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')));
}