Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/tool/qeupgradehelper/lib.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00027 defined('MOODLE_INTERNAL') || die;
00028 
00032 function tool_qeupgradehelper_cron() {
00033     $settings = get_config('tool_qeupgradehelper');
00034     if (empty($settings->cronenabled)) {
00035         return;
00036     }
00037 
00038     mtrace('qeupgradehelper: tool_qeupgradehelper_cron() started at '. date('H:i:s'));
00039     try {
00040         tool_qeupgradehelper_process($settings);
00041     } catch (Exception $e) {
00042         mtrace('qeupgradehelper: tool_qeupgradehelper_cron() failed with an exception:');
00043         mtrace($e->getMessage());
00044     }
00045     mtrace('qeupgradehelper: tool_qeupgradehelper_cron() finished at ' . date('H:i:s'));
00046 }
00047 
00051 function tool_qeupgradehelper_process($settings) {
00052     global $CFG;
00053     require_once(dirname(__FILE__) . '/locallib.php');
00054 
00055     if (!tool_qeupgradehelper_is_upgraded()) {
00056         mtrace('qeupgradehelper: site not yet upgraded. Doing nothing.');
00057         return;
00058     }
00059 
00060     require_once(dirname(__FILE__) . '/afterupgradelib.php');
00061 
00062     $hour = (int) date('H');
00063     if ($hour < $settings->starthour || $hour >= $settings->stophour) {
00064         mtrace('qeupgradehelper: not between starthour and stophour, so doing nothing (hour = ' .
00065                 $hour . ').');
00066         return;
00067     }
00068 
00069     $stoptime = time() + $settings->procesingtime;
00070 
00071     mtrace('qeupgradehelper: processing ...');
00072     while (time() < $stoptime) {
00073 
00074         $quiz = tool_qeupgradehelper_get_quiz_for_upgrade();
00075         if (!$quiz) {
00076             mtrace('qeupgradehelper: No more quizzes to process. You should probably disable the qeupgradehelper cron settings now.');
00077             break; // No more to do;
00078         }
00079 
00080         $quizid = $quiz->id;
00081         $quizsummary = tool_qeupgradehelper_get_quiz($quizid);
00082         if ($quizsummary) {
00083             mtrace('  starting upgrade of attempts at quiz ' . $quizid);
00084             $upgrader = new tool_qeupgradehelper_attempt_upgrader(
00085                     $quizsummary->id, $quizsummary->numtoconvert);
00086             $upgrader->convert_all_quiz_attempts();
00087             mtrace('  upgrade of quiz ' . $quizid . ' complete.');
00088         }
00089     }
00090 
00091     mtrace('qeupgradehelper: Done.');
00092     return;
00093 }
 All Data Structures Namespaces Files Functions Variables Enumerations