function hosting_task_gc_queue in Hosting 7.3
Same name and namespace in other branches
- 7.4 task_gc/hosting_task_gc.module \hosting_task_gc_queue()
The main queue callback task_gc.
File
- task_gc/
hosting_task_gc.module, line 35 - Module code for Hosting task garbage collection
Code
function hosting_task_gc_queue() {
global $user;
$old_user = $user;
$user = user_load(1);
$result = hosting_task_gc_list_sites();
while ($site = $result
->fetchObject()) {
$query = "SELECT nid FROM {hosting_task} WHERE rid = :nid";
$tasks_to_remove = db_query($query, array(
':nid' => $site->nid,
));
while ($row = $tasks_to_remove
->fetchObject()) {
node_delete($row->nid);
watchdog('hosting_task_gc', 'Deleted task node with nid @nid.', array(
'@nid' => $row->nid,
));
}
}
$user = $old_user;
// Look for orphaned task log entries.
$query = "SELECT DISTINCT h.vid\n FROM {hosting_task_log} h\n LEFT OUTER JOIN {node_revision} n ON h.vid = n.vid\n WHERE n.vid IS NULL LIMIT 100";
$result = db_query($query);
while ($revision = $result
->fetchObject()) {
$num = db_delete('hosting_task_log')
->condition('vid', $revision->vid)
->execute();
watchdog('hosting_task_gc', 'Deleted @num orphaned task log entries with vid @vid.', array(
'@num' => $num,
'@vid' => $revision->vid,
));
}
}