You are here

function oa_clone_batch_clone_section_content in Open Atrium Clone 7.2

Callback for cloning all the content in a section.

Parameters

object $node: Node object representing the Section we are going to popuplate.

int $original_nid: The node ID of the original Section we are cloning data from.

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

2 string references to 'oa_clone_batch_clone_section_content'
oa_clone_node_insert in ./oa_clone.module
Implements hook_node_insert().
_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 870

Code

function oa_clone_batch_clone_section_content($node, $original_nid, &$context) {
  $bypass_access_check = !empty($node->oa_clone_bypass_access_check);

  // The first time through, set up all the variables.
  if (empty($context['sandbox']['max'])) {
    $context['sandbox']['content_ids'] = oa_clone_get_section_content($original_nid, $bypass_access_check);
    $context['sandbox']['max'] = count($context['sandbox']['content_ids']);
    $context['sandbox']['nid'] = $node->nid;
    $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;

  // Clone it, setting to the new Space and Section.
  $clone = oa_clone($original_node, $node->{OA_SPACE_FIELD}[LANGUAGE_NONE][0]['target_id'], $node->nid, $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'];
}