[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Scheduled task class. 19 * 20 * @package core 21 * @copyright 2013 onwards Martin Dougiamas http://dougiamas.com 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 namespace core\task; 25 26 /** 27 * Simple task to run cron for all plugins. 28 * Note - this is only for plugins using the legacy cron method, 29 * plugins can also now just add their own scheduled tasks which is the preferred method. 30 */ 31 class legacy_plugin_cron_task extends scheduled_task { 32 33 /** 34 * Get a descriptive name for this task (shown to admins). 35 * 36 * @return string 37 */ 38 public function get_name() { 39 return get_string('tasklegacycron', 'admin'); 40 } 41 42 /** 43 * Do the job. 44 * Throw exceptions on errors (the job will be retried). 45 */ 46 public function execute() { 47 global $CFG, $DB; 48 49 $timenow = time(); 50 // Run the auth cron, if any before enrolments 51 // because it might add users that will be needed in enrol plugins. 52 $auths = get_enabled_auth_plugins(); 53 mtrace("Running auth crons if required..."); 54 foreach ($auths as $auth) { 55 $authplugin = get_auth_plugin($auth); 56 if (method_exists($authplugin, 'cron')) { 57 mtrace("Running cron for auth/$auth..."); 58 $authplugin->cron(); 59 if (!empty($authplugin->log)) { 60 mtrace($authplugin->log); 61 } 62 } 63 unset($authplugin); 64 } 65 66 // It is very important to run enrol early 67 // because other plugins depend on correct enrolment info. 68 mtrace("Running enrol crons if required..."); 69 $enrols = enrol_get_plugins(true); 70 foreach ($enrols as $ename => $enrol) { 71 // Do this for all plugins, disabled plugins might want to cleanup stuff such as roles. 72 if (!$enrol->is_cron_required()) { 73 continue; 74 } 75 mtrace("Running cron for enrol_$ename..."); 76 $enrol->cron(); 77 $enrol->set_config('lastcron', time()); 78 } 79 80 // Run all cron jobs for each module. 81 mtrace("Starting activity modules"); 82 get_mailer('buffer'); 83 if ($mods = $DB->get_records_select("modules", "cron > 0 AND ((? - lastcron) > cron) AND visible = 1", array($timenow))) { 84 foreach ($mods as $mod) { 85 $libfile = "$CFG->dirroot/mod/$mod->name/lib.php"; 86 if (file_exists($libfile)) { 87 include_once($libfile); 88 $cronfunction = $mod->name."_cron"; 89 if (function_exists($cronfunction)) { 90 mtrace("Processing module function $cronfunction ...\n", ''); 91 $predbqueries = null; 92 $predbqueries = $DB->perf_get_queries(); 93 $pretime = microtime(1); 94 if ($cronfunction()) { 95 $DB->set_field("modules", "lastcron", $timenow, array("id" => $mod->id)); 96 } 97 if (isset($predbqueries)) { 98 mtrace("... used " . ($DB->perf_get_queries() - $predbqueries) . " dbqueries"); 99 mtrace("... used " . (microtime(1) - $pretime) . " seconds"); 100 } 101 // Reset possible changes by modules to time_limit. MDL-11597. 102 \core_php_time_limit::raise(); 103 mtrace("done."); 104 } 105 } 106 } 107 } 108 get_mailer('close'); 109 mtrace("Finished activity modules"); 110 111 mtrace("Starting blocks"); 112 if ($blocks = $DB->get_records_select("block", "cron > 0 AND ((? - lastcron) > cron) AND visible = 1", array($timenow))) { 113 // We will need the base class. 114 require_once($CFG->dirroot.'/blocks/moodleblock.class.php'); 115 foreach ($blocks as $block) { 116 $blockfile = $CFG->dirroot.'/blocks/'.$block->name.'/block_'.$block->name.'.php'; 117 if (file_exists($blockfile)) { 118 require_once($blockfile); 119 $classname = '\\block_'.$block->name; 120 $blockobj = new $classname; 121 if (method_exists($blockobj, 'cron')) { 122 mtrace("Processing cron function for ".$block->name.'....', ''); 123 if ($blockobj->cron()) { 124 $DB->set_field('block', 'lastcron', $timenow, array('id' => $block->id)); 125 } 126 // Reset possible changes by blocks to time_limit. MDL-11597. 127 \core_php_time_limit::raise(); 128 mtrace('done.'); 129 } 130 } 131 132 } 133 } 134 mtrace('Finished blocks'); 135 136 mtrace('Starting admin reports'); 137 cron_execute_plugin_type('report'); 138 mtrace('Finished admin reports'); 139 140 mtrace('Starting course reports'); 141 cron_execute_plugin_type('coursereport'); 142 mtrace('Finished course reports'); 143 144 // Run gradebook import/export/report cron. 145 mtrace('Starting gradebook plugins'); 146 cron_execute_plugin_type('gradeimport'); 147 cron_execute_plugin_type('gradeexport'); 148 cron_execute_plugin_type('gradereport'); 149 mtrace('Finished gradebook plugins'); 150 151 // All other plugins. 152 cron_execute_plugin_type('message', 'message plugins'); 153 cron_execute_plugin_type('filter', 'filters'); 154 cron_execute_plugin_type('editor', 'editors'); 155 cron_execute_plugin_type('format', 'course formats'); 156 cron_execute_plugin_type('profilefield', 'profile fields'); 157 cron_execute_plugin_type('webservice', 'webservices'); 158 cron_execute_plugin_type('repository', 'repository plugins'); 159 cron_execute_plugin_type('qbehaviour', 'question behaviours'); 160 cron_execute_plugin_type('qformat', 'question import/export formats'); 161 cron_execute_plugin_type('qtype', 'question types'); 162 cron_execute_plugin_type('plagiarism', 'plagiarism plugins'); 163 cron_execute_plugin_type('theme', 'themes'); 164 cron_execute_plugin_type('tool', 'admin tools'); 165 cron_execute_plugin_type('local', 'local plugins'); 166 } 167 168 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |