function taxonomy_image_delete in Taxonomy Image 6
Same name and namespace in other branches
- 5 taxonomy_image.module \taxonomy_image_delete()
Deletes the Taxonomy Image associated with the given termid.
Parameters
$tid - the id of the term to delete.: return none - the association is broken, the path is removed from the files table, and the image is deleted from the disk, if appropriate.
4 calls to taxonomy_image_delete()
- taxonomy_image_add in ./
taxonomy_image.module - Helper function for adding an image to a term
- taxonomy_image_admin in ./
taxonomy_image.module - taxonomy_image_attach_taxonomy in contributed/
taxonomy_image_attach/ taxonomy_image_attach.module - Implementation of hook_taxonomy. Capture term updates - including submission of the term edit form
- taxonomy_image_taxonomy in ./
taxonomy_image.module - Implementation of hook_taxonomy().
File
- ./
taxonomy_image.module, line 713 - taxonomy_image.module Simple module for providing an association between taxonomy terms and images. Written by Jeremy Andrews <jeremy@kerneltrap.org>, May 2004.
Code
function taxonomy_image_delete($tid) {
$verbose = variable_get('taxonomy_image_verbose_delete', FALSE);
// Is there an image to delete?
$path = _taxonomy_image_exists($tid);
if (!$path) {
// No image, go back now.
return;
}
// See how many terms are using this image.
$count = db_result(db_query("SELECT COUNT(path) FROM {term_image} WHERE path='%s'", $path));
// Get the term's name.
$term = taxonomy_get_term($tid);
$term_name = check_plain(taxonomy_image_tt("taxonomy:term:{$term->tid}:name", $term->name));
// Break the term to image association.
$del_tid = db_query('DELETE FROM {term_image} WHERE tid=%d', $tid);
if ($del_tid) {
if ($verbose) {
drupal_set_message(t('Term image association removed for !name.', array(
'!name' => $term_name,
)), 'status');
}
// Delete the cached version.
cache_clear_all("taxonomy_image:{$tid}", 'cache_tax_image');
}
else {
drupal_set_message(t('Error deleting %path for !name.', array(
'%path' => $path,
'!name' => $term_name,
)), 'error');
// Don't delete anything else either.
return;
}
if ($count > 1) {
// This file is shared, don't remove file.
if ($verbose) {
drupal_set_message(t('%path is used !count other places.', array(
'%path' => $full_path,
'!count' => $count - 1,
)), 'status');
}
return;
}
$taxonomy_image_path = file_directory_path() . '/' . variable_get('taxonomy_image_path', 'category_pictures') . '/';
$full_path = $taxonomy_image_path . $path;
// This is the only term using this file, so it is safe to delete it
// The physical file will be deleted only if also removed from {files} table.
$file_del = db_query("DELETE FROM {files} WHERE filepath='%s'", $full_path);
if ($file_del) {
if ($verbose) {
drupal_set_message(t('%path deleted from database.', array(
'%path' => $full_path,
)), 'status');
}
}
else {
drupal_set_message(t('Error deleting image %path.', array(
'%path' => $full_path,
)), 'error');
// Don't even try to delete from disk.
return;
}
$phys_del = file_delete($full_path);
if ($phys_del) {
if ($verbose) {
drupal_set_message(t('%path deleted from disk.', array(
'%path' => $full_path,
)), 'status');
}
}
else {
drupal_set_message(t('Error deleting image file %path from disk.', array(
'%path' => $full_path,
)), 'warning');
}
}