]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15818 "allow quiz reports to register cron routines" - Quiz reports can now inclu...
authorjamiesensei <jamiesensei>
Thu, 24 Jul 2008 17:36:33 +0000 (17:36 +0000)
committerjamiesensei <jamiesensei>
Thu, 24 Jul 2008 17:36:33 +0000 (17:36 +0000)
admin/cron.php
mod/quiz/db/install.xml
mod/quiz/db/upgrade.php
mod/quiz/version.php

index 9cb16df0faa829aa84a55e4b4c26fb52bdf03ce6..28fa5ff0aa528d36f7c95354a552feccb5eaa9c8 100644 (file)
     }
     mtrace('Finished blocks');
 
+    mtrace("Starting quiz reports");
+    if ($reports = $DB->get_records_select('quiz_report', "cron > 0 AND ((? - lastcron) > cron)", array($timenow))) {
+        foreach ($reports as $report) {
+            $cronfile = "$CFG->dirroot/mod/quiz/report/$report->name/cron.php";
+            if (file_exists($cronfile)) {
+                include_once($cronfile);
+                $cron_function = 'quiz_report_'.$report->name."_cron";
+                if (function_exists($cron_function)) {
+                    mtrace("Processing quiz report cron function $cron_function ...", '');
+                    $pre_dbqueries = null;
+                    $pre_dbqueries = $DB->perf_get_queries();
+                    $pre_time      = microtime(1);
+                    if ($cron_function()) {
+                        if (!$DB->set_field('quiz_report', "lastcron", $timenow, array("id"=>$report->id))) {
+                            mtrace("Error: could not update timestamp for $report->name");
+                        }
+                    }
+                    if (isset($pre_dbqueries)) {
+                        mtrace("... used " . ($DB->perf_get_queries() - $pre_dbqueries) . " dbqueries");
+                        mtrace("... used " . (microtime(1) - $pre_time) . " seconds");
+                    }
+                    mtrace("done.");
+                }
+            }
+        }
+    }
+    mtrace("Finished quiz reports");
+    
     mtrace('Starting admin reports');
     // Admin reports do not have a database table that lists them. Instead a
     // report includes cron.php with function report_reportname_cron() if it wishes
         $cronfile = $CFG->dirroot.'/'.$CFG->admin.'/report/'.$report.'/cron.php';
         if (file_exists($cronfile)) {
             require_once($cronfile);
-            $cronfunction = 'report_'.$report.'_cron';
+            $cronfunction = 'quiz_report_'.$report.'_cron';
             mtrace('Processing cron function for '.$report.'...', '');
             $pre_dbqueries = null;
             $pre_dbqueries = $DB->perf_get_queries();
index 33f9d1b8f81afe8f5cd048f6c4727076acbafca5..e81b4825defb81a10ad882d33b3acc29cdb7bd1c 100755 (executable)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="mod/quiz/db" VERSION="20080620" COMMENT="XMLDB file for Moodle mod/quiz"
+<XMLDB PATH="mod/quiz/db" VERSION="20080725" COMMENT="XMLDB file for Moodle mod/quiz"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
 >
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="name"/>
         <FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" ENUM="false" COMMENT="name of the report, same as the directory name" PREVIOUS="id" NEXT="displayorder"/>
-        <FIELD NAME="displayorder" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="display order for report tabs" PREVIOUS="name"/>
+        <FIELD NAME="displayorder" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" ENUM="false" COMMENT="display order for report tabs" PREVIOUS="name" NEXT="lastcron"/>
+        <FIELD NAME="lastcron" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="displayorder" NEXT="cron"/>
+        <FIELD NAME="cron" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="0 if there is no cron for this report (default) or the time between crons otherwise." PREVIOUS="lastcron"/>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
index 05ac39f7eb0fc7e4e4066c51698398872254da6c..a0ca4967a50e7b7c3e8dcccfba7fffdcccc7fc17 100644 (file)
@@ -86,6 +86,28 @@ function xmldb_quiz_upgrade($oldversion=0) {
         upgrade_mod_savepoint($result, 2008072401, 'quiz');
     }
 
+    if ($result && $oldversion < 2008072402) {
+
+    /// Define field lastcron to be added to quiz_report
+        $table = new xmldb_table('quiz_report');
+        $field = new xmldb_field('lastcron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'displayorder');
+
+    /// Conditionally launch add field lastcron
+        if (!$dbman->field_exists($table, $field)) {
+            $dbman->add_field($table, $field);
+        }
+
+    /// Define field cron to be added to quiz_report
+        $field = new xmldb_field('cron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'lastcron');
+
+    /// Conditionally launch add field cron
+        if (!$dbman->field_exists($table, $field)) {
+            $dbman->add_field($table, $field);
+        }
+
+    /// quiz savepoint reached
+        upgrade_mod_savepoint($result, 2008072402, 'quiz');
+    }
 
 
     return $result;
index 942cfedbe8ffee993e0f88e5ce570328d7b0d59b..676568c21efdd1e0c289aec0ebba17fe94b78b60 100644 (file)
@@ -5,7 +5,7 @@
 //  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2008072401;   // The (date) version of this module
+$module->version  = 2008072402;   // The (date) version of this module
 $module->requires = 2008072401;   // Requires this Moodle version
 $module->cron     = 0;            // How often should cron check this module (seconds)?