]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10365 grade history can be turned off + lifetime
authorskodak <skodak>
Thu, 8 Nov 2007 08:59:26 +0000 (08:59 +0000)
committerskodak <skodak>
Thu, 8 Nov 2007 08:59:26 +0000 (08:59 +0000)
admin/cron.php
admin/settings/server.php
lang/en_utf8/grades.php
lib/grade/grade_object.php
lib/gradelib.php

index dbb0be0ce3e36b63abc705c05d68c91e8db2acd6..ba149b4cfd6ac5a475dc5bfb4a1e39414a41f1a8 100644 (file)
     }
 
 
-    mtrace('Starting grade job ...', '');
+    mtrace('Starting main gradebook job ...');
     grade_cron();
-    mtrace('Done ...');
+    mtrace('done.');
 
 
 /// Run all core cron jobs, but not every time since they aren't too important.
             }
         }
     }
-    
+
     // run gradebook import/export/report cron
     if ($gradeimports = get_list_of_plugins('grade/import')) {
         foreach ($gradeimports as $gradeimport) {           
-            if (file_exists($CFG->dirroot.'/grade/import/lib.php')) {
-                require_once($CFG->dirroot.'/grade/import/lib.php');
-                $cron_function = 'gradeimport_'.$gradeimport.'_cron';                                    
+            if (file_exists($CFG->dirroot.'/grade/import/'.$gradeimport.'/lib.php')) {
+                require_once($CFG->dirroot.'/grade/import/'.$gradeimport.'/lib.php');
+                $cron_function = 'grade_import_'.$gradeimport.'_cron';                                    
                 if (function_exists($cron_function)) {
                     mtrace("Processing gradebook import function $cron_function ...", '');
                     $cron_function;  
 
     if ($gradeexports = get_list_of_plugins('grade/export')) {
         foreach ($gradeexports as $gradeexport) {           
-            if (file_exists($CFG->dirroot.'/grade/export/lib.php')) {
-                require_once($CFG->dirroot.'/grade/export/lib.php');
-                $cron_function = 'gradeexport_'.$gradeexport.'_cron';                                    
+            if (file_exists($CFG->dirroot.'/grade/export/'.$gradeexport.'/lib.php')) {
+                require_once($CFG->dirroot.'/grade/export/'.$gradeexport.'/lib.php');
+                $cron_function = 'grade_export_'.$gradeexport.'_cron';                                    
                 if (function_exists($cron_function)) {
                     mtrace("Processing gradebook export function $cron_function ...", '');
                     $cron_function;  
             }
         }
     }
-    
+
     if ($gradereports = get_list_of_plugins('grade/report')) {
         foreach ($gradereports as $gradereport) {           
-            if (file_exists($CFG->dirroot.'/grade/report/lib.php')) {
-                require_once($CFG->dirroot.'/grade/report/lib.php');
-                $cron_function = 'gradereport_'.$gradereport.'_cron';                                    
+            if (file_exists($CFG->dirroot.'/grade/report/'.$gradereport.'/lib.php')) {
+                require_once($CFG->dirroot.'/grade/report/'.$gradereport.'/lib.php');
+                $cron_function = 'grade_report_'.$gradereport.'_cron';                                    
                 if (function_exists($cron_function)) {
                     mtrace("Processing gradebook report function $cron_function ...", '');
                     $cron_function;  
index b6cdd8b1bd596869eea9024d24c8837f56a1b76a..8c2d9ebf7bc4b6e2af4b078a442a4a93c1600ceb 100644 (file)
@@ -182,6 +182,21 @@ $temp->add(new admin_setting_configselect('loglifetime', get_string('loglifetime
                                                                                                                                                 60 => get_string('numdays', '', 60),
                                                                                                                                                 30 => get_string('numdays', '', 30))));
 
+
+$temp->add(new admin_setting_configcheckbox('disablegradehistory', get_string('disablegradehistory', 'grades'),
+                                            get_string('configdisablegradehistory', 'grades'), 0, PARAM_INT));
+
+$temp->add(new admin_setting_configselect('gradehistorylifetime', get_string('gradehistorylifetime', 'grades'),
+                                          get_string('configgradehistorylifetime', 'grades'), 0, array(0 => get_string('neverdeletehistory', 'grades'),
+                                                                                                   1000 => get_string('numdays', '', 1000),
+                                                                                                    365 => get_string('numdays', '', 365),
+                                                                                                    180 => get_string('numdays', '', 180),
+                                                                                                    150 => get_string('numdays', '', 150),
+                                                                                                    120 => get_string('numdays', '', 120),
+                                                                                                     90 => get_string('numdays', '', 90),
+                                                                                                     60 => get_string('numdays', '', 60),
+                                                                                                     30 => get_string('numdays', '', 30))));
+
 $ADMIN->add('server', $temp);
 
 
index 1d4b66f2d21a4cadf1b6afadb013978657203d36..ede599f3eede0e27b265ae1352128e4061c3bf11 100644 (file)
@@ -61,6 +61,7 @@ $string['categorytotal'] = 'Category total';
 $string['changereportdefaults'] = 'Change report defaults';
 $string['choosecategory'] = 'Select Category';
 $string['compact'] = 'Compact';
+$string['configdisablegradehistory'] = 'Disable traking of changes in grades related tables. This may speed up the server operation and conserve space in database.';
 $string['configaggregationposition'] = 'The position of the aggregation column in the report, in reference to the real grades.';
 $string['configaggregationview'] = 'Each category can be displayed in three ways: Full mode (aggregated column and grade item columns), the aggregated column only, or the grade items alone.';
 $string['configaveragesdecimalpoints'] = 'The number of decimal points to display for each average (group or whole), below a column of grades.';
@@ -74,6 +75,7 @@ $string['configgradeboundary'] = 'A percentage boundary over which grades will b
 $string['configgradedisplaytype'] = 'Grades can be shown as real grades, as percentages (in reference to the minimum and maximum grades) or as letters (A, B, C etc..)';
 $string['configgradeexportdisplaytype'] = 'Grades can be shown as real grades, as percentages (in reference to the minimum and maximum grades) or as letters (A, B, C etc..) during export. This can be overriden during export.';
 $string['configexportdecimalpoints'] = 'The number of decimal points to display for export. This can be overriden during export.';
+$string['configgradehistorylifetime'] = 'This specifies the length of time you want to keep history of changes in grade related tables. It is recommended to keep it as long as possible. If you experience performance problems or have limited database space, try to set lower value.';
 $string['configgradeletter'] = 'A letter or other symbol used to represent a range of grades.';
 $string['configgradeletterdefault'] = 'A letter or other symbol used to represent a range of grades. Leave this field empty to use the site default (currently $a).';
 $string['configgradepublishing'] = 'Enable publishing in exports and imports: Exported grades can be accessed by accessing a URL, without having to log on to a Moodle site. Grades can be imported by accessing such a URL (which means that a moodle site can import grades published by another site). By default only administrators may use this feature, please educate users before adding required capabilities to other roles (dangers of bookmark sharing and download accelerators, IP restrictions, etc.).';
@@ -115,6 +117,7 @@ $string['decimalpoints'] = 'Overall decimal points';
 $string['default'] = 'Default';
 $string['defaultprev'] = 'Default ($a)';
 $string['deletecategory'] = 'Delete Category';
+$string['disablegradehistory'] = 'Disable grade history';
 $string['displaylettergrade'] = 'Display Letter Grades';
 $string['displaypercent'] = 'Display Percents';
 $string['displaypoints'] = 'Display Points';
@@ -180,6 +183,7 @@ $string['gradeexceptionshelp'] = 'Grade Exceptions Help';
 $string['gradeexportdisplaytype'] = 'Grade export display type';
 $string['gradeexportdecimalpoints'] = 'Grade export decimal points';
 $string['gradehelp'] = 'Grade Help';
+$string['gradehistorylifetime'] = 'Grade history lifetime';
 $string['gradeitem'] = 'Grade item';
 $string['gradeitemislocked'] = 'This activity is locked in the gradebook. Changes that are made to grades in this activity will not be copied to the gradebook until it is unlocked.';
 $string['gradeitemlocked'] = 'Grading locked';
@@ -282,6 +286,7 @@ $string['movingelement'] = 'Moving $a';
 $string['multfactor'] = 'Multiplicator';
 $string['multfactorhelp'] = 'Factor by which all grades for this grade item will be multiplied.';
 $string['myreportpreferences'] = 'My report preferences';
+$string['neverdeletehistory'] = 'Never delete history';
 $string['newcategory'] = 'New category';
 $string['newuserkey'] = 'New user key';
 $string['no'] = 'No';
index 30b8ce39c970b630d2edb618cc588c17869bef9c..b730ee81afe5428f01ff3eaa5d728fb7f21b2e6c 100644 (file)
@@ -193,7 +193,12 @@ class grade_object {
      * @return boolean success
      */
     function update($source=null) {
-        global $USER;
+        global $USER, $CFG;
+
+        if (empty($this->id)) {
+            debugging('Can not update grade object, no id!');
+            return false;
+        }
 
         $data = $this->get_record_data();
 
@@ -201,14 +206,15 @@ class grade_object {
             return false;
         }
 
-        // track history
-        // TODO: add history disable switch
-        unset($data->timecreated);
-        $data->action     = GRADE_HISTORY_UPDATE;
-        $data->oldid      = $this->id;
-        $data->source     = $source;
-        $data->userlogged = $USER->id;
-        insert_record($this->table.'_history', addslashes_recursive($data));
+        if (empty($CFG->disablegradehistory)) {
+            unset($data->timecreated);
+            $data->action       = GRADE_HISTORY_UPDATE;
+            $data->oldid        = $this->id;
+            $data->source       = $source;
+            $data->timemodified = time();
+            $data->userlogged   = $USER->id;
+            insert_record($this->table.'_history', addslashes_recursive($data));
+        }
 
         return true;
     }
@@ -219,22 +225,24 @@ class grade_object {
      * @return boolean success
      */
     function delete($source=null) {
-        global $USER;
+        global $USER, $CFG;
 
-        // track history
-        // TODO: add history disable switch
-        if ($data = get_record($this->table, 'id', $this->id)) {
-            unset($data->id);
-            unset($data->timecreated);
-            $data->action       = GRADE_HISTORY_DELETE;
-            $data->oldid        = $this->id;
-            $data->source       = $source;
-            $data->timemodified = time();
-            $data->userlogged   = $USER->id;
+        if (empty($this->id)) {
+            debugging('Can not delete grade object, no id!');
+            return false;
         }
 
+        $data = $this->get_record_data();
+
         if (delete_records($this->table, 'id', $this->id)) {
-            if ($data) {
+            if (empty($CFG->disablegradehistory)) {
+                unset($data->id);
+                unset($data->timecreated);
+                $data->action       = GRADE_HISTORY_DELETE;
+                $data->oldid        = $this->id;
+                $data->source       = $source;
+                $data->timemodified = time();
+                $data->userlogged   = $USER->id;
                 insert_record($this->table.'_history', addslashes_recursive($data));
             }
             return true;
@@ -270,7 +278,7 @@ class grade_object {
      * @return int PK ID if successful, false otherwise
      */
     function insert($source=null) {
-        global $USER;
+        global $USER, $CFG;
 
         if (!empty($this->id)) {
             debugging("Grade object already exists!");
@@ -287,14 +295,17 @@ class grade_object {
         // set all object properties from real db data
         $this->update_from_db();
 
-        // track history
-        // TODO: add history disable switch
-        unset($data->timecreated);
-        $data->action     = GRADE_HISTORY_INSERT;
-        $data->oldid      = $this->id;
-        $data->source     = $source;
-        $data->userlogged = $USER->id;
-        insert_record($this->table.'_history', addslashes_recursive($data));
+        $data = $this->get_record_data();
+
+        if (empty($CFG->disablegradehistory)) {
+            unset($data->timecreated);
+            $data->action       = GRADE_HISTORY_INSERT;
+            $data->oldid        = $this->id;
+            $data->source       = $source;
+            $data->timemodified = time();
+            $data->userlogged   = $USER->id;
+            insert_record($this->table.'_history', addslashes_recursive($data));
+        }
 
         return $this->id;
     }
@@ -334,6 +345,5 @@ class grade_object {
             }
         }
     }
-
 }
 ?>
index 17469caf35808c2e94cf678b889c5cc793be5bea..45788d644b03e3ae4cdcf71127027869036c0f72 100644 (file)
@@ -1143,6 +1143,20 @@ function grade_cron() {
         rs_close($rs);
     }
 
+    //TODO: do not run this cleanup every cron invocation
+    // cleanup history tables
+        if (!empty($CFG->gradehistorylifetime)) {  // value in days
+            $histlifetime = $now - ($CFG->gradehistorylifetime * 3600 * 24);
+            $tables = array('grade_outcomes_history', 'grade_categories_history', 'grade_items_history', 'grade_grades_history', 'scale_history');
+            foreach ($tables as $table) {
+                if (delete_records_select($table, "timemodified < '$histlifetime'")) {
+                    mtrace("    Deleted old grade history records from '$table'");
+                }
+                
+            }
+        }
+
+
 }
 
 ?>