}
- 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;
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);
$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.';
$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.).';
$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';
$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';
$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';
* @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();
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;
}
* @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;
* @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!");
// 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;
}
}
}
}
-
}
?>
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'");
+ }
+
+ }
+ }
+
+
}
?>