/** * Hook into the task scheduler to run the rules against new records on the system. */ function data_cleaner_scheduled_task($timestamp, $db, $endtime) { $rules = data_cleaner::get_rules(); data_cleaner_cleanout_old_messages($rules, $db); data_cleaner_run_rules($rules, $db); data_cleaner_update_occurrence_metadata($db, $endtime); data_cleaner_set_cache_fields($db); }
/** * Retrieve the definition of a single rule. * @param string $type Rule type name * @return array Rule definition */ public static function get_rule($type) { $rules = data_cleaner::get_rules(); foreach ($rules as $rule) { if (strcasecmp($rule['testType'], $type) === 0) { if (!array_key_exists('required', $rule)) { $rule['required'] = array(); } if (!array_key_exists('optional', $rule)) { $rule['optional'] = array(); } return $rule; } } // If we got this far then the rule type is not found. throw new exception("Test type {$type} not found"); }
/** * Hook into the task scheduler to run the rules against new records on the system. */ function data_cleaner_scheduled_task() { $db = new Database(); $rules = data_cleaner::get_rules(); $count = data_cleaner_get_occurrence_list($db); try { if ($count > 0) { data_cleaner_cleanout_old_messages($rules, $db); data_cleaner_run_rules($rules, $db); data_cleaner_update_occurrence_metadata($db); data_cleaner_set_cache_fields($db); } $db->query('drop table occlist'); } catch (Exception $e) { $db->query('drop table occlist'); throw $e; } }
/** * Performs the task of running the rules against the temporary */ private function runRules($db) { $rules = data_cleaner::get_rules(); if (!empty($_REQUEST['rule_types'])) { $ruleTypes = json_decode(strtoupper($_REQUEST['rule_types']), true); } $r = array(); foreach ($rules as $rule) { // skip rule types if only running certain ones if (isset($ruleTypes) && !in_array(strtoupper($rule['testType']), $ruleTypes)) { continue; } if (isset($rule['errorMsgField'])) { // rules are able to specify a different field (e.g. from the verification rule data) to provide the error message. $errorField = $rule['errorMsgField']; } else { $errorField = 'error_message'; } foreach ($rule['queries'] as $query) { // queries can override the error message field. $ruleErrorField = isset($query['errorMsgField']) ? $query['errorMsgField'] : $errorField; $errorMsgSuffix = isset($rule['errorMsgSuffix']) ? $rule['errorMsgSuffix'] : ''; $sql = 'select distinct co.taxa_taxon_list_id, ' . $ruleErrorField . $errorMsgSuffix . ' as message from occdelta co'; if (isset($query['joins'])) { $sql .= "\n" . $query['joins']; } $sql .= "\nwhere co.verification_checks_enabled=true"; if (isset($query['where'])) { $sql .= "\nand " . $query['where']; } // we now have the query ready to run which will return a list of the occurrence ids that fail the check. $messages = $db->query($sql)->result_array(false); $r = $r + $messages; } } return $r; }