function imagecrop_cron in Image javascript crop 5
Same name and namespace in other branches
- 6 imagecrop.module \imagecrop_cron()
Implementation of hook_cron(). Delete all references in imagecrop table when a) file doesn't exist anymore. b) when preset has been deleted. c) when javascrip_crop action is removed from a preset.
File
- ./
imagecrop.module, line 117 - Provides a javascript toolbox through an imagecache action.
Code
function imagecrop_cron() {
// get all files which do not exist anymore from the files table
$result = db_query("SELECT ic.fid,ic.presetid FROM {imagecrop} ic WHERE NOT EXISTS (SELECT fid FROM {files} f WHERE ic.fid = f.fid) AND ic.reference = 'files'");
while ($row = db_fetch_object($result)) {
$records[] = array(
'fid' => $row->fid,
'presetid' => $row->presetid,
'reference' => 'files',
);
}
// get all files which do not exist anymore from the node_images table
if (module_exists('node_images')) {
$result = db_query("SELECT ic.fid,presetid FROM {imagecrop} ic WHERE NOT EXISTS (SELECT id FROM {node_images} ni WHERE ic.fid = ni.id) AND ic.reference = 'node_images'");
while ($row = db_fetch_object($result)) {
$records[] = array(
'fid' => $row->fid,
'presetid' => $row->presetid,
'reference' => 'node_images',
);
}
}
/*
* Get all records
* a) from presets which do not exist anymore.
* b) and/or from presets with no imagecrop_javascript action anymore.
*/
// files table
$result = db_query("SELECT ic.fid,ic.presetid FROM {imagecrop} ic WHERE NOT EXISTS (SELECT presetid FROM {imagecache_action} ia where ic.presetid = ia.presetid AND ia.action = 'imagecrop_javascript') AND ic.reference = 'files'");
while ($row = db_fetch_object($result)) {
$records[] = array(
'fid' => $row->fid,
'presetid' => $row->presetid,
'reference' => 'files',
);
}
// node_images table
if (module_exists('node_images')) {
$result = db_query("SELECT ic.fid,ic.presetid FROM {imagecrop} ic WHERE NOT EXISTS (SELECT presetid FROM {imagecache_action} ia where ic.presetid = ia.presetid AND ia.action = 'imagecrop_javascript') AND ic.reference = 'node_images'");
while ($row = db_fetch_object($result)) {
$records[] = array(
'fid' => $row->fid,
'presetid' => $row->presetid,
'reference' => 'node_images',
);
}
}
if (!empty($records)) {
while (list($key, $val) = each($records)) {
db_query("DELETE FROM {imagecrop} WHERE fid=%d AND presetid=%d AND reference = '%s'", $val['fid'], $val['presetid'], $val['reference']);
}
}
}