From: skodak Date: Thu, 8 Nov 2007 08:59:26 +0000 (+0000) Subject: MDL-10365 grade history can be turned off + lifetime X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=1ee0df067faa9353fa9133d28a4f39cc58305837;p=moodle.git MDL-10365 grade history can be turned off + lifetime --- diff --git a/admin/cron.php b/admin/cron.php index dbb0be0ce3..ba149b4cfd 100644 --- a/admin/cron.php +++ b/admin/cron.php @@ -189,9 +189,9 @@ } - 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. @@ -471,13 +471,13 @@ } } } - + // 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; @@ -488,9 +488,9 @@ 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; @@ -498,12 +498,12 @@ } } } - + 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; diff --git a/admin/settings/server.php b/admin/settings/server.php index b6cdd8b1bd..8c2d9ebf7b 100644 --- a/admin/settings/server.php +++ b/admin/settings/server.php @@ -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); diff --git a/lang/en_utf8/grades.php b/lang/en_utf8/grades.php index 1d4b66f2d2..ede599f3ee 100644 --- a/lang/en_utf8/grades.php +++ b/lang/en_utf8/grades.php @@ -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'; diff --git a/lib/grade/grade_object.php b/lib/grade/grade_object.php index 30b8ce39c9..b730ee81af 100644 --- a/lib/grade/grade_object.php +++ b/lib/grade/grade_object.php @@ -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 { } } } - } ?> diff --git a/lib/gradelib.php b/lib/gradelib.php index 17469caf35..45788d644b 100644 --- a/lib/gradelib.php +++ b/lib/gradelib.php @@ -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'"); + } + + } + } + + } ?>