You are here

function _node_gallery_delete in Node Gallery 6.3

Same name and namespace in other branches
  1. 6 node_gallery.module \_node_gallery_delete()
  2. 6.2 node_gallery.module \_node_gallery_delete()

Deletes the child image nodes when deleting a gallery.

When deleting a gallery, we delete the image nodes within that gallery, as well as remove the imagecache files from the filesystem. We use batch api to allow for deletion of galleries with a large amount of images.

Parameters

object $node: A reference to the gallery node object

1 call to _node_gallery_delete()
node_gallery_nodeapi in ./node_gallery.module
Implements hook_nodeapi().

File

./node_gallery.module, line 782
Node gallery module file.

Code

function _node_gallery_delete(&$node) {
  $gid = NULL;
  if (in_array($node->type, (array) node_gallery_get_types('gallery'))) {
    $gid = $node->nid;
    $imagenids = node_gallery_get_image_nids($gid, FALSE, FALSE, TRUE);
    $total = count($imagenids);

    // Split our operations into X deletes at a time
    while (count($imagenids) > 0) {
      if (count($imagenids) >= NODE_GALLERY_BATCH_DELETE) {
        $nids = array_splice($imagenids, 0, 10);
      }
      else {
        $nids = $imagenids;
        unset($imagenids);
      }
      $operations[] = array(
        'node_gallery_image_delete_process',
        array(
          $nids,
        ),
      );
    }
    if (!empty($operations)) {
      $batch = array(
        'operations' => $operations,
        'finished' => 'node_gallery_image_process_finished',
        'title' => t('Processing Gallery Delete.'),
        'init_message' => t('Gallery deletion is cascading to images.'),
        'progress_message' => t('Processing image deletions.'),
        'error_message' => t('Gallery deletion has encountered an error.'),
      );
      batch_set($batch);
      if (module_exists('og')) {
        $group = og_get_group_context();
        if (isset($group->nid)) {
          batch_process('node/' . $group->nid);
        }
      }
    }
    node_gallery_delete_gallery($node);
  }
  if (in_array($node->type, (array) node_gallery_get_types('image'))) {
    $gid = $node->gid;
    node_gallery_delete_image($node);
  }
  node_gallery_clear_gallery_caches($gid);
}