/** * Performs the entire scheduled run of the specified task, including emailing * the report export, decrementing remaining runs, updating next scheduled run time, * and cleanup * * @param string $taskname The task name, in the form scheduled_{id}, where id * is the PHP report schedule id * * @return boolean true on success, otherwise false */ function run_schedule($taskname) { global $CFG; $now = gmmktime(); //time(); $report_schedule = php_report_schedule_get_instance($taskname); if ($report_schedule === false) { //error getting the report schedule, so return false return false; } // New report schedule for updating purposes $data = unserialize($report_schedule->config); // Check that we are beyond the startdate before continuing if ($data['startdate'] > $now) { return true; } //perform the export php_report_schedule_export_instance($report_schedule, $now); //decrement the number of remaining runs, if applicable php_report_schedule_decrement_remaining_runs($report_schedule); //set the next run time in the database if appropriate php_report_schedule_set_next_runtime($taskname, $report_schedule); //cleanup php_report_schedule_delete_unmatching_records(); return true; }
require_once '../../../config.php'; require_once $CFG->dirroot . '/blocks/php_report/runschedule.php'; require_once $CFG->dirroot . '/blocks/php_report/sharedlib.php'; //database record id of the schedule to run $scheduleid = required_param('scheduleid', PARAM_INT); //represents the schedule name / label $schedulename = required_param('schedulename', PARAM_ALPHAEXT); //how far we currently are in processing the jobs (1 to n) $current = required_param('current', PARAM_INT); //total number of jobs $total = required_param('total', PARAM_INT); //determine the ELIS scheduled task name from the PHP report schedule id $taskname = block_php_report_get_taskname_from_id($scheduleid); //used to update the UI with errors that have taken place $error_string = ''; //obtain information about the scheduled PHP report task, if possible if ($report_schedule = php_report_schedule_get_instance($taskname)) { //run the export $export_result = php_report_schedule_export_instance($report_schedule); if (!$export_result) { //export failure, so return a helpful error string $error_string = get_string('schedule_user_access_error', 'block_php_report', $schedulename); } } //spit out information regarding the current position $a->current = $current; $a->total = $total; //send back status and error $output = array(get_string('popup_status', 'block_php_report', $a), $error_string); //send back the array as JSON data echo json_encode($output);