function imagecrop_cron in Image javascript crop 6
Same name and namespace in other branches
- 5 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 113 - 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.presetname 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,
'presetname' => $row->presetname,
'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, presetname 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->presetname,
'reference' => 'node_images',
);
}
}
// Delete the records
if (!empty($records)) {
while (list($key, $val) = each($records)) {
db_query("DELETE FROM {imagecrop} WHERE fid= %d AND presetname = '%s' AND reference = '%s'", $val['fid'], $val['presetname'], $val['reference']);
}
}
/*
* Deleted all records from deleted presets
*/
$presets = return_presets();
if (!isset($presets['tabs'])) {
return;
}
$in = '';
foreach ($presets['tabs'] as $preset) {
$in .= "'" . db_escape_string($preset) . "',";
}
$in = substr($in, 0, -1);
$result = db_query("SELECT presetname FROM {imagecrop} WHERE presetname NOT IN (" . $in . ")");
while ($row = db_fetch_object($result)) {
db_query("DELETE FROM {imagecrop} WHERE presetname = '%s'", $row->presetname);
}
}