Skip to content
Snippets Groups Projects
Commit 91f1f33f authored by Matt Petro's avatar Matt Petro
Browse files

UWMOODLE-875: Convert all crons requiring middleware services to task interface

Task-Url: https://jira.doit.wisc.edu/jira/browse/UWMOODLE-875
parent 319337a4
No related branches found
No related tags found
No related merge requests found
...@@ -120,7 +120,7 @@ class block_course_overview_uwmoodle extends block_base { ...@@ -120,7 +120,7 @@ class block_course_overview_uwmoodle extends block_base {
list($courses, $errors) = block_course_overview_uwmoodle_get_sorted_courses(); list($courses, $errors) = block_course_overview_uwmoodle_get_sorted_courses();
$terms = block_course_overview_uwmoodle_group_courses_by_term($courses); $terms = block_course_overview_uwmoodle_group_courses_by_term($courses);
$currentterm = block_course_overview_uwmoodle_get_current_term(); $currentterm = \enrol_wisc\local\chub\timetable_util::get_current_termcode();
$selectedterm = optional_param('term', $currentterm, PARAM_INT); $selectedterm = optional_param('term', $currentterm, PARAM_INT);
if (!isset($terms[$currentterm])) { if (!isset($terms[$currentterm])) {
...@@ -166,64 +166,6 @@ class block_course_overview_uwmoodle extends block_base { ...@@ -166,64 +166,6 @@ class block_course_overview_uwmoodle extends block_base {
return $this->content; return $this->content;
} }
/**
* Get the current term from the datastore, and update user show/hide preferences when it changes.
*
* @return boolean true on success
*/
public function update_current_term() {
global $CFG, $DB;
$oldcurrentterm = get_config('block_course_overview_uwmoodle', 'currentterm');
try {
$currentterm = $this->get_current_term();
} catch (Exception $e) {
// Suppress errors to the log. This can get noisy quickly when CHUB is down.
//mtrace("Error fetching current term: ".$e->getMessage());
return false;
}
if ($currentterm === false) {
mtrace("No current term found");
return false;
}
if ($currentterm && $currentterm != $oldcurrentterm) {
// store new term
mtrace('new current term: '.$currentterm);
set_config('currentterm', $currentterm, 'block_course_overview_uwmoodle');
}
return true;
}
/**
* Fetch current term from CHUB. Throw exception on CHUB error.
*
* @return string|false term_code or false if none found.
*/
public function get_current_term() {
global $CFG;
require_once($CFG->dirroot.'/enrol/wisc/lib/datastore.php');
$datastore = wisc_timetable_datastore::get_timetable_datastore();
$terms = $datastore->getAvailableTerms();
$now = time();
$futureterms = array();
foreach ($terms as $term) {
// check that term hasn't ended and doesn't have an odd termCode
// odd term codes (e.g. Winter) are never considered the current term
if ($term->endDate > $now && ($term->termCode % 2 != 1)) {
$futureterms[] = $term->termCode;
}
}
if (!empty($futureterms)) {
$currentterm = min($futureterms);
} else {
$currentterm = false;
}
return $currentterm;
}
/** /**
* allow the block to have a configuration page * allow the block to have a configuration page
* *
...@@ -242,15 +184,6 @@ class block_course_overview_uwmoodle extends block_base { ...@@ -242,15 +184,6 @@ class block_course_overview_uwmoodle extends block_base {
return array('my-index'=>true); return array('my-index'=>true);
} }
/**
* Block cron to update currentterm
*
* @return boolean true on success
*/
public function cron() {
return $this->update_current_term();
}
/** /**
* Sets block header to be hidden or visible * Sets block header to be hidden or visible
* *
......
...@@ -66,7 +66,7 @@ if(confirm_sesskey()) { ...@@ -66,7 +66,7 @@ if(confirm_sesskey()) {
$terms = block_course_overview_uwmoodle_group_courses_by_term($courses); $terms = block_course_overview_uwmoodle_group_courses_by_term($courses);
$currentterm = block_course_overview_uwmoodle_get_current_term(); $currentterm = \enrol_wisc\local\chub\timetable_util::get_current_termcode();
$selectedterm = optional_param('term', $currentterm, PARAM_INT); $selectedterm = optional_param('term', $currentterm, PARAM_INT);
if (!isset($terms[$currentterm])) { if (!isset($terms[$currentterm])) {
......
...@@ -188,19 +188,6 @@ function block_course_overview_uwmoodle_sort_term_array(&$terms) { ...@@ -188,19 +188,6 @@ function block_course_overview_uwmoodle_sort_term_array(&$terms) {
return uksort($terms, $cmp); return uksort($terms, $cmp);
} }
/**
* Get the current term from our settings
*
* @return string termcode
*/
function block_course_overview_uwmoodle_get_current_term() {
$currentterm = get_config('block_course_overview_uwmoodle', 'currentterm');
if (!$currentterm) {
$currentterm = 1136; // Just set it to something in the past, until cron runs and updates the term.
}
return $currentterm;
}
/** /**
* Return a string representing the term (e.g. "Fall 2010") * Return a string representing the term (e.g. "Fall 2010")
* This function doesn't make any remote calls. * This function doesn't make any remote calls.
......
...@@ -18,11 +18,10 @@ ...@@ -18,11 +18,10 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->component = 'block_course_overview_uwmoodle'; $plugin->component = 'block_course_overview_uwmoodle';
$plugin->version = 2014082600; $plugin->version = 2014082601;
$plugin->release = '2.0'; $plugin->release = '2.0';
$plugin->requires = 2012120300; $plugin->requires = 2012120300;
$plugin->maturity = MATURITY_STABLE; $plugin->maturity = MATURITY_STABLE;
$plugin->cron = 43200; // Set min time between cron executions to 12 hours
$plugin->dependencies = array( $plugin->dependencies = array(
'enrol_wisc' => 2013061701, 'enrol_wisc' => 2013061701,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment