You are here

function node_recur_node_batch_create_node in Node recur 7.2

Same name and namespace in other branches
  1. 7 node_recur.batch.inc \node_recur_node_batch_create_node()

Create the recurring nodes

1 string reference to 'node_recur_node_batch_create_node'
node_recur_node_batch_start in ./node_recur.module
Start the batch to generate recurring nodes

File

./node_recur.module, line 171

Code

function node_recur_node_batch_create_node($node, $date, &$context) {
  $field_name = node_recur_get_date_field_name($node->type);
  $view = field_view_value('node', $node, $field_name, $date);

  // Set the progress message
  $context['message'] = t('Date: !date', array(
    '!date' => $view['#markup'],
  ));

  // Clone the node
  $clone = node_load($node->nid, $node->vid, TRUE);

  // Inject the new dates
  unset($clone->{$field_name}[LANGUAGE_NONE]);
  $clone->{$field_name}[LANGUAGE_NONE][] = $date;

  // Store the start dates
  $context['results'][] = $date;

  // Save the new node
  if (module_exists('clone')) {
    $context = [
      'method' => 'node_recur',
      'prefix_title' => FALSE,
      'original_node' => $node,
    ];
    clone_action_clone($clone, $context);
  }
  else {
    $clone->clone_from_original_nid = $node->nid;
    unset($clone->nid);
    unset($clone->created);
    unset($clone->changed);
    unset($clone->vid);
    node_save($clone);
  }
}