You are here

function node_gallery_delete_image in Node Gallery 6.3

Same name and namespace in other branches
  1. 6.2 node_gallery.inc \node_gallery_delete_image()

Deletes an image from the database, cleans the filesystem of imagecache files.

Parameters

$node: A populated node object that is a node gallery image.

1 call to node_gallery_delete_image()
_node_gallery_delete in ./node_gallery.module
Deletes the child image nodes when deleting a gallery.

File

./node_gallery.inc, line 918
Shared functions for node_gallery

Code

function node_gallery_delete_image($node) {

  // Clean up our tables
  db_query("DELETE FROM {node_gallery_images} WHERE nid = %d", $node->nid);
  $gid = db_result(db_query("SELECT gid FROM {node_gallery_galleries} WHERE cover_image = %d", $node->nid));
  if ($gid !== FALSE) {

    // the image was the cover of an gallery
    $new_cover = db_result(db_query('SELECT nid FROM {node_gallery_images} WHERE gid = %d AND nid <> %d LIMIT 1', $gid, $node->nid));
    if ($new_cover !== FALSE) {
      db_query("UPDATE {node_gallery_galleries} SET cover_image = %d WHERE gid = %d", $new_cover, $gid);
    }
    else {

      // Gallery is now empty, set cover to NULL.
      db_query("UPDATE {node_gallery_galleries} SET cover_image = NULL WHERE gid = %d", $gid);
    }
  }

  // We don't delete the file from the filesystem anymore, because imagefield handles this for us
  // Clean our imagecache - note, this API call leaves empty dirs
  $relationship = node_gallery_get_relationship(NULL, $node->type);
  imagecache_image_flush($node->{$relationship['imagefield_name']}[0]['filepath']);

  // Clean up empty dirs, if they exist
  node_gallery_clean_empty_dirs(dirname($node->field_node_gallery_image[0]['filepath']));
}