You are here

function _node_gallery_set_publish in Node Gallery 6.3

Publishes the child image nodes when publishing a gallery.

When publishing a gallery, we publish the image nodes within that gallery. We use batch api to provide for galleries with a large amount of images.

Parameters

object $node: A reference to a gallery node object

$status: The new publish status to set on the node

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

File

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

Code

function _node_gallery_set_publish(&$node, $status) {
  $gid = $node->nid;
  $imagenids = node_gallery_get_image_nids($gid, FALSE, FALSE);

  // Split our operations into NODE_GALLERY_BATCH_CHUNK_SIZE a time
  $node_updates = array_chunk($imagenids, NODE_GALLERY_BATCH_CHUNK_SIZE);
  array_walk_recursive($node_updates, create_function('&$v,$k,$status', '$v = (object)array(\'nid\' => $v, \'status\' => $status);'), $status);
  foreach ($node_updates as $node_update) {
    $operations[] = array(
      'node_gallery_batch_node_save',
      array(
        $node_update,
      ),
    );
  }
  if (!empty($operations)) {
    $batch = array(
      'operations' => $operations,
      'finished' => 'node_gallery_image_process_finished',
      'title' => t('Processing gallery publish status update.'),
      'init_message' => t('Gallery publish status is cascading to images.'),
      'progress_message' => t('Processing publishing of images.'),
      'error_message' => t('Image publish status change has encountered an error.'),
    );
    batch_set($batch);
    node_gallery_clear_gallery_caches($gid);
  }
}