You are here

function oa_clone_batch_clone_orphan_content in Open Atrium Clone 7.2

Callback for cloning all the content in a section.

Parameters

object $space: Cloned space object

$nids: Array of nids to clone.

array &$context: A place where we can store values that need to b passed from one iteration of this batch operation to the next.

1 string reference to 'oa_clone_batch_clone_orphan_content'
_oa_clone_batch_space in ./oa_clone.module
Recursively clone a Space while setting up a batch for cloning content.

File

./oa_clone.module, line 742

Code

function oa_clone_batch_clone_orphan_content($space, $nids, &$context) {

  // The first time through, set up all the variables.
  if (empty($context['sandbox']['max'])) {
    $context['sandbox']['content_ids'] = $nids;
    $context['sandbox']['max'] = count($context['sandbox']['content_ids']);
    $context['sandbox']['progress'] = 0;
    $context['results']['total'] = (!empty($context['results']['total']) ? $context['results']['total'] : 0) + $context['sandbox']['max'];
  }

  // Get the next node.
  $next_id = array_shift($context['sandbox']['content_ids']);
  if (!$next_id) {
    $context['sandbox']['finished'] = TRUE;
    return;
  }

  // Get the original node and mark it so that it doesn't get cloned again.
  $original_node = node_load($next_id);
  $original_node->oa_clone_skip = TRUE;
  $bypass_access_check = !empty($space->oa_clone_bypass_access_check);

  // Clone it, setting to the new Space.
  $clone = oa_clone($original_node, $space->nid, NULL, $bypass_access_check);

  // Remeber: $clone can be NULL, if the user doesn't have permission to clone this node!
  // Bump the progress indicator.
  $context['sandbox']['progress']++;

  // Report progress if not finished and run again.
  $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
}