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,53 @@
<?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/>.
/**
* Behat step definitions for scheduled task administration.
*
* @package tool_task
* @copyright 2017 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/../../../../../lib/behat/behat_base.php');
/**
* Behat step definitions for scheduled task administration.
*
* @package tool_task
* @copyright 2017 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_tool_task extends behat_base {
/**
* Set a fake fail delay for a scheduled task.
*
* @Given /^the scheduled task "(?P<task_name>[^"]+)" has a fail delay of "(?P<seconds_number>\d+)" seconds$/
* @param string $task Task classname
* @param int $seconds Fail delay time in seconds
*/
public function scheduled_task_has_fail_delay_seconds($task, $seconds) {
global $DB;
$id = $DB->get_field('task_scheduled', 'id', ['classname' => $task], IGNORE_MISSING);
if (!$id) {
throw new Exception('Unknown scheduled task: ' . $task);
}
$DB->set_field('task_scheduled', 'faildelay', $seconds, ['id' => $id]);
}
}
@@ -0,0 +1,32 @@
@tool @tool_task
Feature: Clear scheduled task fail delay
In order to stop failures from delaying a scheduled task run
As an admin
I need to be able to clear the fail delay on a task
Background:
Given the scheduled task "\core\task\send_new_user_passwords_task" has a fail delay of "60" seconds
And I log in as "admin"
And I navigate to "Server > Tasks > Scheduled tasks" in site administration
Scenario: Any fail delay is highlighted
Then I should see "60" in the "Send new user passwords" "table_row"
And I should see "Clear" in the "Send new user passwords" "table_row"
And I should see "60" in the "td.table-danger" "css_element"
Scenario: Clear fail delay
When I click on "Clear" "text" in the "Send new user passwords" "table_row"
And I should see "Are you sure you want to clear the fail delay"
And I press "Clear"
Then I should not see "60" in the "Send new user passwords" "table_row"
And I should not see "Clear" in the "Send new user passwords" "table_row"
And I should see "Send new user passwords" in the "tr.table-primary" "css_element"
Scenario: Cancel clearing the fail delay
When I click on "Clear" "text" in the "Send new user passwords" "table_row"
And I press "Cancel"
Then I should see "60" in the "Send new user passwords" "table_row"
And I should see "Clear" in the "Send new user passwords" "table_row"
And I should see "Send new user passwords" in the "tr.table-primary" "css_element"
@@ -0,0 +1,20 @@
@tool @tool_task
Feature: See warning message if cron is disabled
In order to manage scheduled tasks
As a Moodle Administrator
I need to be able to view a warning message if cron is disabled
Background:
Given I log in as "admin"
Scenario: If cron is disabled, I should see the message
When the following config values are set as admin:
| cron_enabled | 0 |
And I navigate to "Server > Tasks > Scheduled tasks" in site administration
Then I should see "Cron is disabled"
Scenario: If cron is enabled, I should not see the message
When the following config values are set as admin:
| cron_enabled | 1 |
And I navigate to "Server > Tasks > Scheduled tasks" in site administration
Then I should not see "Cron is disabled"
@@ -0,0 +1,73 @@
@tool @tool_task @javascript
Feature: Manage scheduled tasks
In order to configure scheduled tasks
As an admin
I need to be able to disable, enable, edit and reset to default scheduled tasks
Background:
Given I log in as "admin"
And I navigate to "Server > Tasks > Scheduled tasks" in site administration
Scenario: Disable scheduled task
When I click on "Edit task schedule: Log table cleanup" "link" in the "Log table cleanup" "table_row"
Then I should see "Edit task schedule: Log table cleanup"
And I set the following fields to these values:
| disabled | 1 |
And I press "Save changes"
Then I should see "Changes saved"
And I should see "Task disabled" in the "Log table cleanup" "table_row"
And I should see "Log table cleanup" in the "tr.table-primary" "css_element"
Scenario: Enable scheduled task
When I click on "Edit task schedule: Log table cleanup" "link" in the "Log table cleanup" "table_row"
Then I should see "Edit task schedule: Log table cleanup"
And I set the following fields to these values:
| disabled | 0 |
And I press "Save changes"
Then I should see "Changes saved"
And I should not see "Task disabled" in the "Log table cleanup" "table_row"
And I should see "Log table cleanup" in the "tr.table-primary" "css_element"
Scenario: Edit scheduled task
When I click on "Edit task schedule: Log table cleanup" "link" in the "Log table cleanup" "table_row"
Then I should see "Edit task schedule: Log table cleanup"
And I should see "\logstore_standard\task\cleanup_task"
And I should see "From component: Standard log"
And I should see "logstore_standard"
And I should see "Default: R" in the "Minute" "fieldset"
And I should see "Default: *" in the "Day" "fieldset"
And I set the following fields to these values:
| minute | frog |
And I press "Save changes"
And I should see "Data submitted is invalid"
And I set the following fields to these values:
| minute | */5 |
| hour | 1 |
| day | 2 |
| month | 3 |
| dayofweek | 4 |
And I press "Save changes"
And I should see "Changes saved"
And the following should exist in the "admintable" table:
| Component | Minute | Hour | Day | Day of week | Month |
| Standard log logstore_standard | */5 Default: R | 1 Default: 4 | 2 Default: * | 4 Default: * | 3 Default: * |
And I should see "Log table cleanup" in the "tr.table-primary" "css_element"
And I should see "*/5 Default: R" in the "td.table-warning" "css_element"
Scenario: Reset scheduled task to default
When I click on "Edit task schedule: Log table cleanup" "link" in the "Log table cleanup" "table_row"
Then I should see "Edit task schedule: Log table cleanup"
And I set the following fields to these values:
| resettodefaults | 1 |
And I press "Save changes"
Then I should see "Changes saved"
And the following should not exist in the "admintable" table:
| Name | Minute | Hour | Day | Day of week | Month |
| Log table cleanup | */5 | 1 | 2 | 4 | 3 |
And I should see "Log table cleanup" in the "tr.table-primary" "css_element"
Scenario: Disabled plugin's tasks are labelled as disabled too
When "CAS users sync job \auth_cas\task\sync_task" row "Next run" column of "Scheduled tasks" table should contain "Plugin disabled"
Then "CAS users sync job \auth_cas\task\sync_task" row "Component" column of "Scheduled tasks" table should contain "Disabled"
And "Background processing for scheduled allocation \workshopallocation_scheduled\task\cron_task" row "Next run" column of "Scheduled tasks" table should not contain "Plugin disabled"
And "Background processing for scheduled allocation \workshopallocation_scheduled\task\cron_task" row "Component" column of "Scheduled tasks" table should not contain "Disabled"
@@ -0,0 +1,40 @@
@tool @tool_task
Feature: See running scheduled tasks
In order to configure scheduled tasks
As an admin
I need to see if tasks are running
Background:
Given I log in as "admin"
Scenario: If no task is running, I should see the corresponding message
Given I navigate to "Server > Tasks > Tasks running now" in site administration
Then I should see "Nothing to display"
Scenario: If tasks are running, I should see task details
Given the following "tool_task > scheduled tasks" exist:
| classname | seconds | hostname | pid |
| \core\task\automated_backup_task | 121 | c69335460f7f | 1914 |
And the following "tool_task > adhoc tasks" exist:
| classname | seconds | hostname | pid |
| \core\task\asynchronous_backup_task | 7201 | c69335460f7f | 1915 |
| \core\task\asynchronous_restore_task | 172800 | c69335460f7f | 1916 |
And I navigate to "Server > Tasks > Tasks running now" in site administration
# Check the scheduled task details.
Then I should see "Scheduled" in the "\core\task\automated_backup_task" "table_row"
And I should see "2 mins" in the "Automated backups" "table_row"
And I should see "c69335460f7f" in the "Automated backups" "table_row"
And I should see "1914" in the "Automated backups" "table_row"
# Check the "asynchronous_backup_task" adhoc task details.
And I should see "Ad hoc" in the "\core\task\asynchronous_backup_task" "table_row"
And I should see "2 hours" in the "core\task\asynchronous_backup_task" "table_row"
And I should see "c69335460f7f" in the "core\task\asynchronous_backup_task" "table_row"
And I should see "1915" in the "core\task\asynchronous_backup_task" "table_row"
# Check the "asynchronous_restore_task" adhoc task details.
And I should see "Ad hoc" in the "\core\task\asynchronous_restore_task" "table_row"
And I should see "2 days" in the "core\task\asynchronous_restore_task" "table_row"
And I should see "c69335460f7f" in the "core\task\asynchronous_restore_task" "table_row"
And I should see "1916" in the "core\task\asynchronous_restore_task" "table_row"
+280
View File
@@ -0,0 +1,280 @@
<?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/>.
namespace tool_task;
/**
* Test for the task mform class.
*
* @package tool_task
* @copyright 2014 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or late
*/
class form_test extends \advanced_testcase {
/**
* Test validations for minute field.
*/
public function test_validate_fields_minute(): void {
$checker = new \tool_task\scheduled_checker_task();
$checker->set_minute('*');
$this->assertTrue($checker->is_valid($checker::FIELD_MINUTE));
$checker->set_minute('1');
$this->assertTrue($checker->is_valid($checker::FIELD_MINUTE));
$checker->set_minute('20');
$this->assertTrue($checker->is_valid($checker::FIELD_MINUTE));
$checker->set_minute('65');
$this->assertFalse($checker->is_valid($checker::FIELD_MINUTE));
$checker->set_minute('*/');
$this->assertFalse($checker->is_valid($checker::FIELD_MINUTE));
$checker->set_minute('*/1');
$this->assertTrue($checker->is_valid($checker::FIELD_MINUTE));
$checker->set_minute('*/20');
$this->assertTrue($checker->is_valid($checker::FIELD_MINUTE));
$checker->set_minute('*/60');
$this->assertFalse($checker->is_valid($checker::FIELD_MINUTE));
$checker->set_minute('1,2');
$this->assertTrue($checker->is_valid($checker::FIELD_MINUTE));
$checker->set_minute('2,20');
$this->assertTrue($checker->is_valid($checker::FIELD_MINUTE));
$checker->set_minute('20,30,45');
$this->assertTrue($checker->is_valid($checker::FIELD_MINUTE));
$checker->set_minute('65,20,30');
$this->assertFalse($checker->is_valid($checker::FIELD_MINUTE));
$checker->set_minute('25,75');
$this->assertFalse($checker->is_valid($checker::FIELD_MINUTE));
$checker->set_minute('1-2');
$this->assertTrue($checker->is_valid($checker::FIELD_MINUTE));
$checker->set_minute('2-20');
$this->assertTrue($checker->is_valid($checker::FIELD_MINUTE));
$checker->set_minute('20-30');
$this->assertTrue($checker->is_valid($checker::FIELD_MINUTE));
$checker->set_minute('65-20');
$this->assertFalse($checker->is_valid($checker::FIELD_MINUTE));
$checker->set_minute('25-75');
$this->assertFalse($checker->is_valid($checker::FIELD_MINUTE));
}
/**
* Test validations for minute hour.
*/
public function test_validate_fields_hour(): void {
$checker = new \tool_task\scheduled_checker_task();
$checker->set_hour('*');
$this->assertTrue($checker->is_valid($checker::FIELD_HOUR));
$checker->set_hour('1');
$this->assertTrue($checker->is_valid($checker::FIELD_HOUR));
$checker->set_hour('20');
$this->assertTrue($checker->is_valid($checker::FIELD_HOUR));
$checker->set_hour('60');
$this->assertFalse($checker->is_valid($checker::FIELD_HOUR));
$checker->set_hour('65');
$this->assertFalse($checker->is_valid($checker::FIELD_HOUR));
$checker->set_hour('*/');
$this->assertFalse($checker->is_valid($checker::FIELD_HOUR));
$checker->set_hour('*/1');
$this->assertTrue($checker->is_valid($checker::FIELD_HOUR));
$checker->set_hour('*/20');
$this->assertTrue($checker->is_valid($checker::FIELD_HOUR));
$checker->set_hour('*/60');
$this->assertFalse($checker->is_valid($checker::FIELD_HOUR));
$checker->set_hour('*/65');
$this->assertFalse($checker->is_valid($checker::FIELD_HOUR));
$checker->set_hour('1,2');
$this->assertTrue($checker->is_valid($checker::FIELD_HOUR));
$checker->set_hour('2,20');
$this->assertTrue($checker->is_valid($checker::FIELD_HOUR));
$checker->set_hour('20,30,45');
$this->assertFalse($checker->is_valid($checker::FIELD_HOUR));
$checker->set_hour('65,20,30');
$this->assertFalse($checker->is_valid($checker::FIELD_HOUR));
$checker->set_hour('25,75');
$this->assertFalse($checker->is_valid($checker::FIELD_HOUR));
$checker->set_hour('1-2');
$this->assertTrue($checker->is_valid($checker::FIELD_HOUR));
$checker->set_hour('2-20');
$this->assertTrue($checker->is_valid($checker::FIELD_HOUR));
$checker->set_hour('20-30');
$this->assertFalse($checker->is_valid($checker::FIELD_HOUR));
$checker->set_hour('65-20');
$this->assertFalse($checker->is_valid($checker::FIELD_HOUR));
$checker->set_hour('24-75');
$this->assertFalse($checker->is_valid($checker::FIELD_HOUR));
}
/**
* Test validations for day field.
*/
public function test_validate_fields_day(): void {
$checker = new \tool_task\scheduled_checker_task();
$checker->set_day('*');
$this->assertTrue($checker->is_valid($checker::FIELD_DAY));
$checker->set_day('1');
$this->assertTrue($checker->is_valid($checker::FIELD_DAY));
$checker->set_day('20');
$this->assertTrue($checker->is_valid($checker::FIELD_DAY));
$checker->set_day('65');
$this->assertFalse($checker->is_valid($checker::FIELD_DAY));
$checker->set_day('35');
$this->assertFalse($checker->is_valid($checker::FIELD_DAY));
$checker->set_day('*/');
$this->assertFalse($checker->is_valid($checker::FIELD_DAY));
$checker->set_day('*/1');
$this->assertTrue($checker->is_valid($checker::FIELD_DAY));
$checker->set_day('*/20');
$this->assertTrue($checker->is_valid($checker::FIELD_DAY));
$checker->set_day('*/65');
$this->assertFalse($checker->is_valid($checker::FIELD_DAY));
$checker->set_day('*/35');
$this->assertFalse($checker->is_valid($checker::FIELD_DAY));
$checker->set_day('1,2');
$this->assertTrue($checker->is_valid($checker::FIELD_DAY));
$checker->set_day('2,20');
$this->assertTrue($checker->is_valid($checker::FIELD_DAY));
$checker->set_day('20,30,25');
$this->assertTrue($checker->is_valid($checker::FIELD_DAY));
$checker->set_day('65,20,30');
$this->assertFalse($checker->is_valid($checker::FIELD_DAY));
$checker->set_day('25,35');
$this->assertFalse($checker->is_valid($checker::FIELD_DAY));
$checker->set_day('1-2');
$this->assertTrue($checker->is_valid($checker::FIELD_DAY));
$checker->set_day('2-20');
$this->assertTrue($checker->is_valid($checker::FIELD_DAY));
$checker->set_day('20-30');
$this->assertTrue($checker->is_valid($checker::FIELD_DAY));
$checker->set_day('65-20');
$this->assertFalse($checker->is_valid($checker::FIELD_DAY));
$checker->set_day('25-35');
$this->assertFalse($checker->is_valid($checker::FIELD_DAY));
}
/**
* Test validations for month field.
*/
public function test_validate_fields_month(): void {
$checker = new \tool_task\scheduled_checker_task();
$checker->set_month('*');
$this->assertTrue($checker->is_valid($checker::FIELD_MONTH));
$checker->set_month('1');
$this->assertTrue($checker->is_valid($checker::FIELD_MONTH));
$checker->set_month('10');
$this->assertTrue($checker->is_valid($checker::FIELD_MONTH));
$checker->set_month('13');
$this->assertFalse($checker->is_valid($checker::FIELD_MONTH));
$checker->set_month('35');
$this->assertFalse($checker->is_valid($checker::FIELD_MONTH));
$checker->set_month('*/');
$this->assertFalse($checker->is_valid($checker::FIELD_MONTH));
$checker->set_month('*/1');
$this->assertTrue($checker->is_valid($checker::FIELD_MONTH));
$checker->set_month('*/12');
$this->assertTrue($checker->is_valid($checker::FIELD_MONTH));
$checker->set_month('*/13');
$this->assertFalse($checker->is_valid($checker::FIELD_MONTH));
$checker->set_month('*/35');
$this->assertFalse($checker->is_valid($checker::FIELD_MONTH));
$checker->set_month('1,2');
$this->assertTrue($checker->is_valid($checker::FIELD_MONTH));
$checker->set_month('2,11');
$this->assertTrue($checker->is_valid($checker::FIELD_MONTH));
$checker->set_month('2,10,12');
$this->assertTrue($checker->is_valid($checker::FIELD_MONTH));
$checker->set_month('65,2,13');
$this->assertFalse($checker->is_valid($checker::FIELD_MONTH));
$checker->set_month('25,35');
$this->assertFalse($checker->is_valid($checker::FIELD_MONTH));
$checker->set_month('1-2');
$this->assertTrue($checker->is_valid($checker::FIELD_MONTH));
$checker->set_month('2-12');
$this->assertTrue($checker->is_valid($checker::FIELD_MONTH));
$checker->set_month('3-6');
$this->assertTrue($checker->is_valid($checker::FIELD_MONTH));
$checker->set_month('65-2');
$this->assertFalse($checker->is_valid($checker::FIELD_MONTH));
$checker->set_month('25-26');
$this->assertFalse($checker->is_valid($checker::FIELD_MONTH));
}
/**
* Test validations for dayofweek field.
*/
public function test_validate_fields_dayofweek(): void {
$checker = new \tool_task\scheduled_checker_task();
$checker->set_day_of_week('*');
$this->assertTrue($checker->is_valid($checker::FIELD_DAYOFWEEK));
$checker->set_day_of_week('0');
$this->assertTrue($checker->is_valid($checker::FIELD_DAYOFWEEK));
$checker->set_day_of_week('1');
$this->assertTrue($checker->is_valid($checker::FIELD_DAYOFWEEK));
$checker->set_day_of_week('6');
$this->assertTrue($checker->is_valid($checker::FIELD_DAYOFWEEK));
$checker->set_day_of_week('7');
$this->assertTrue($checker->is_valid($checker::FIELD_DAYOFWEEK));
$checker->set_day_of_week('8');
$this->assertFalse($checker->is_valid($checker::FIELD_DAYOFWEEK));
$checker->set_day_of_week('20');
$this->assertFalse($checker->is_valid($checker::FIELD_DAYOFWEEK));
$checker->set_day_of_week('*/');
$this->assertFalse($checker->is_valid($checker::FIELD_DAYOFWEEK));
$checker->set_day_of_week('*/1');
$this->assertTrue($checker->is_valid($checker::FIELD_DAYOFWEEK));
$checker->set_day_of_week('*/6');
$this->assertTrue($checker->is_valid($checker::FIELD_DAYOFWEEK));
$checker->set_day_of_week('*/7');
$this->assertTrue($checker->is_valid($checker::FIELD_DAYOFWEEK));
$checker->set_day_of_week('*/13');
$this->assertFalse($checker->is_valid($checker::FIELD_DAYOFWEEK));
$checker->set_day_of_week('*/35');
$this->assertFalse($checker->is_valid($checker::FIELD_DAYOFWEEK));
$checker->set_day_of_week('1,2');
$this->assertTrue($checker->is_valid($checker::FIELD_DAYOFWEEK));
$checker->set_day_of_week('2,6');
$this->assertTrue($checker->is_valid($checker::FIELD_DAYOFWEEK));
$checker->set_day_of_week('2,6,3');
$this->assertTrue($checker->is_valid($checker::FIELD_DAYOFWEEK));
$checker->set_day_of_week('65,2,13');
$this->assertFalse($checker->is_valid($checker::FIELD_DAYOFWEEK));
$checker->set_day_of_week('25,35');
$this->assertFalse($checker->is_valid($checker::FIELD_DAYOFWEEK));
$checker->set_day_of_week('1-2');
$this->assertTrue($checker->is_valid($checker::FIELD_DAYOFWEEK));
$checker->set_day_of_week('2-6');
$this->assertTrue($checker->is_valid($checker::FIELD_DAYOFWEEK));
$checker->set_day_of_week('65-2');
$this->assertFalse($checker->is_valid($checker::FIELD_DAYOFWEEK));
$checker->set_day_of_week('3-7');
$this->assertTrue($checker->is_valid($checker::FIELD_DAYOFWEEK));
$checker->set_day_of_week('3-8');
$this->assertFalse($checker->is_valid($checker::FIELD_DAYOFWEEK));
}
}
@@ -0,0 +1,57 @@
<?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/>.
/**
* Behat data generator for tool_task.
*
* @package tool_task
* @category test
* @copyright 2020 Mikhail Golenkov <golenkovm@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Behat data generator for tool_task.
*
* @package tool_task
* @category test
* @copyright 2020 Mikhail Golenkov <golenkovm@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_tool_task_generator extends behat_generator_base {
/**
* Get a list of the entities that can be created.
* @return array entity name => information about how to generate.
*/
protected function get_creatable_entities(): array {
return [
'scheduled tasks' => [
'singular' => 'scheduled task',
'datagenerator' => 'scheduled_tasks',
'required' => ['classname', 'seconds', 'hostname', 'pid'],
],
'adhoc tasks' => [
'singular' => 'adhoc task',
'datagenerator' => 'adhoc_tasks',
'required' => ['classname', 'seconds', 'hostname', 'pid'],
],
];
}
}
+69
View File
@@ -0,0 +1,69 @@
<?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/>.
/**
* Tool task test data generator class
*
* @package tool_task
* @copyright 2020 Mikhail Golenkov <golenkovm@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Tool task test data generator class
*
* @package tool_task
* @copyright 2020 Mikhail Golenkov <golenkovm@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_task_generator extends testing_module_generator {
/**
* Mark a scheduled task as running.
*
* @param array $data Scheduled task properties
* @throws dml_exception
*/
public function create_scheduled_tasks($data) {
global $DB;
$conditions = ['classname' => $data['classname']];
$record = $DB->get_record('task_scheduled', $conditions, '*', MUST_EXIST);
$record->timestarted = time() - $data['seconds'];
$record->hostname = $data['hostname'];
$record->pid = $data['pid'];
$DB->update_record('task_scheduled', $record);
}
/**
* Mark an adhoc task as running.
*
* @param array $data Adhoc task properties
* @throws dml_exception
*/
public function create_adhoc_tasks($data) {
global $DB;
$adhoctask = (object)[
'classname' => $data['classname'],
'nextruntime' => 0,
'timestarted' => time() - $data['seconds'],
'hostname' => $data['hostname'],
'pid' => $data['pid'],
];
$DB->insert_record('task_adhoc', $adhoctask);
}
}