You are here

function node_gallery_api_batch_node_delete in Node Gallery 7

Deletes batches of images for batch API.

Parameters

array $imagenids: Array of nids to delete.

array $context: Array provided by batch API.

1 string reference to 'node_gallery_api_batch_node_delete'
node_gallery_api_manage_items_submit in ./node_gallery_api.pages.inc
Submit handler for Manage Items form.

File

./node_gallery_api.inc, line 406
Node Gallery API function

Code

function node_gallery_api_batch_node_delete($imagenids, &$context) {
  if (!isset($context['sandbox']['progress'])) {
    $context['sandbox']['progress'] = 0;
    $context['sandbox']['max'] = count($imagenids);
  }
  if (!isset($context['sandbox']['imagenids'])) {
    if (is_array($imagenids)) {
      $context['sandbox']['imagenids'] = $imagenids;
    }
    else {
      $context['sandbox']['imagenids'] = array(
        $imagenids,
      );
    }
  }
  $count = 0;
  while (!empty($context['sandbox']['imagenids']) && $count <= NODE_GALLERY_BATCH_CHUNK_SIZE) {
    $count++;
    $nid = array_shift($context['sandbox']['imagenids']);
    node_delete($nid);
    $context['sandbox']['progress']++;
  }

  // Let the batch engine know how close we are to completion.
  if ($context['sandbox']['progress'] == $context['sandbox']['max']) {

    // Done!
    $context['finished'] = 1;
  }
  else {
    $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
  }
}