diff --git a/admin/registration/lib.php b/admin/registration/lib.php index 6aed4376f30..5a521e18fc9 100644 --- a/admin/registration/lib.php +++ b/admin/registration/lib.php @@ -53,32 +53,30 @@ class registration_manager { public function cron() { global $CFG; if (extension_loaded('xmlrpc')) { - //check if the last registration cron update was less than a week ago - $lastcron = get_config('registration', 'crontime'); - if ($lastcron === false or $lastcron < strtotime("-7 day")) { //set to a week, see MDL-23704 - $function = 'hub_update_site_info'; - require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php"); + $function = 'hub_update_site_info'; + require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php"); - //update all hub where the site is registered on - $hubs = $this->get_registered_on_hubs(); - foreach ($hubs as $hub) { - //update the registration - $siteinfo = $this->get_site_info($hub->huburl); - $params = array('siteinfo' => $siteinfo); - $serverurl = $hub->huburl . "/local/hub/webservice/webservices.php"; - $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hub->token); - try { - $result = $xmlrpcclient->call($function, $params); - $this->update_registeredhub($hub); // To update timemodified. - mtrace(get_string('siteupdatedcron', 'hub', $hub->hubname)); - } catch (Exception $e) { - $errorparam = new stdClass(); - $errorparam->errormessage = $e->getMessage(); - $errorparam->hubname = $hub->hubname; - mtrace(get_string('errorcron', 'hub', $errorparam)); - } + // Update all hubs where the site is registered. + $hubs = $this->get_registered_on_hubs(); + if (empty($hubs)) { + mtrace(get_string('registrationwarning', 'admin')); + } + foreach ($hubs as $hub) { + // Update the registration. + $siteinfo = $this->get_site_info($hub->huburl); + $params = array('siteinfo' => $siteinfo); + $serverurl = $hub->huburl . "/local/hub/webservice/webservices.php"; + $xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hub->token); + try { + $result = $xmlrpcclient->call($function, $params); + $this->update_registeredhub($hub); // To update timemodified. + mtrace(get_string('siteupdatedcron', 'hub', $hub->hubname)); + } catch (Exception $e) { + $errorparam = new stdClass(); + $errorparam->errormessage = $e->getMessage(); + $errorparam->hubname = $hub->hubname; + mtrace(get_string('errorcron', 'hub', $errorparam)); } - set_config('crontime', time(), 'registration'); } } else { mtrace(get_string('errorcronnoxmlrpc', 'hub')); diff --git a/lib/classes/task/scheduled_task.php b/lib/classes/task/scheduled_task.php index 9c525e5860d..aedfcebe5ac 100644 --- a/lib/classes/task/scheduled_task.php +++ b/lib/classes/task/scheduled_task.php @@ -35,11 +35,17 @@ abstract class scheduled_task extends task_base { const MINUTEMIN = 0; /** Maximum minute value. */ const MINUTEMAX = 59; + /** Minimum hour value. */ const HOURMIN = 0; /** Maximum hour value. */ const HOURMAX = 23; + /** Minimum dayofweek value. */ + const DAYOFWEEKMIN = 0; + /** Maximum dayofweek value. */ + const DAYOFWEEKMAX = 6; + /** @var string $hour - Pattern to work out the valid hours */ private $hour = '*'; @@ -173,6 +179,9 @@ abstract class scheduled_task extends task_base { * @param string $dayofweek */ public function set_day_of_week($dayofweek) { + if ($dayofweek === 'R') { + $dayofweek = mt_rand(self::DAYOFWEEKMIN, self::DAYOFWEEKMAX); + } $this->dayofweek = $dayofweek; } diff --git a/lib/db/tasks.php b/lib/db/tasks.php index 8dc4f4e1cf0..6c4d7d203da 100644 --- a/lib/db/tasks.php +++ b/lib/db/tasks.php @@ -215,10 +215,10 @@ $tasks = array( array( 'classname' => 'core\task\registration_cron_task', 'blocking' => 0, - 'minute' => '0', - 'hour' => '3', + 'minute' => 'R', + 'hour' => 'R', 'day' => '*', - 'dayofweek' => '*', + 'dayofweek' => 'R', 'month' => '*' ), array( diff --git a/lib/tests/scheduled_task_test.php b/lib/tests/scheduled_task_test.php index 2d5e2058860..95a5a0dc3a6 100644 --- a/lib/tests/scheduled_task_test.php +++ b/lib/tests/scheduled_task_test.php @@ -329,6 +329,7 @@ class core_scheduled_task_testcase extends advanced_testcase { // Set a random value. $testclass->set_minute('R'); $testclass->set_hour('R'); + $testclass->set_day_of_week('R'); // Verify the minute has changed within allowed bounds. $minute = $testclass->get_minute(); @@ -341,6 +342,12 @@ class core_scheduled_task_testcase extends advanced_testcase { $this->assertInternalType('int', $hour); $this->assertGreaterThanOrEqual(0, $hour); $this->assertLessThanOrEqual(23, $hour); + + // Verify the dayofweek has changed within allowed bounds. + $dayofweek = $testclass->get_day_of_week(); + $this->assertInternalType('int', $dayofweek); + $this->assertGreaterThanOrEqual(0, $dayofweek); + $this->assertLessThanOrEqual(6, $dayofweek); } /**