function _node_gallery_api_set_publish in Node Gallery 7
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
int $status: The new publish status to set on the node
1 call to _node_gallery_api_set_publish()
- node_gallery_api_node_update in ./
node_gallery_api.module - Implements hook_node_update().
File
- ./
node_gallery_api.inc, line 694 - Node Gallery API function
Code
function _node_gallery_api_set_publish(&$node, $status) {
$ngid = $node->nid;
$imagenids = node_gallery_api_get_item_nids($ngid, 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, function (&$v, $k, $status) {
$v = (object) array(
'nid' => $v,
'status' => $status,
);
}, $status);
foreach ($node_updates as $node_update) {
$operations[] = array(
'node_gallery_api_batch_node_save',
array(
$node_update,
),
);
}
if (!empty($operations)) {
$batch = array(
'operations' => $operations,
'finished' => 'node_gallery_api_item_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_api_clear_gallery_caches($ngid);
}
}