function watchdog_prune_cron in Watchdog Prune 7
Same name and namespace in other branches
- 8.2 watchdog_prune.module \watchdog_prune_cron()
- 8 watchdog_prune.module \watchdog_prune_cron()
Implements hook_cron
File
- ./
watchdog_prune.module, line 156 - This is the main module file for watchdog_prune.
Code
function watchdog_prune_cron() {
$prune_type = variable_get('watchdog_prune_age_type', '');
if (!empty($prune_type)) {
$prune_type = explode("\n", $prune_type);
$prune_type_list = array();
if (is_array($prune_type)) {
foreach ($prune_type as $key => $value) {
$watchdog_prune_settings = explode("|", $value);
$prune_query = db_delete('watchdog');
//Check if the user has entered the correct squence of settings to prune watchdog messages by type
//Starting with the watchdog type
if (isset($watchdog_prune_settings[0]) || !empty($watchdog_prune_settings[0])) {
$prune_query
->condition('type', trim($watchdog_prune_settings[0]), '=');
$prune_type_list[] = $watchdog_prune_settings[0];
//Check if age is entered as we cannot delete wathdog entries if the age limit entered is incorrect.
if (isset($watchdog_prune_settings[1]) || !empty($watchdog_prune_settings[1])) {
$ts = strtotime($watchdog_prune_settings[1], time());
$prune_query
->condition('timestamp', $ts, '<');
//Execute the SQL query to Delete.
$prune_query
->execute();
}
}
}
}
}
// Should we delete from the watchdog table based on age?. After deleting all the entries by type let us delete other remaining watchdog entries by excluding the type of entries which were deleted above.
$prune_age = variable_get('watchdog_prune_age', '-18 MONTHS');
if ($prune_age != "") {
$ts = strtotime($prune_age, time());
// Now, simply delete anything from watchdog which is *less than* than our $ts value (meaning, the entry is OLDER than our age limit).
$prune_age = db_delete('watchdog');
$prune_age
->condition('timestamp', $ts, '<');
if (count($prune_type_list) > 0) {
$prune_age
->condition('type', $prune_type_list, 'NOT IN');
}
$prune_age
->execute();
}
}