/**
 * 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);
}
/**
 * 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;
    }
}