You are here

function oa_clone_node_insert in Open Atrium Clone 7.2

Implements hook_node_insert().

File

./oa_clone.module, line 567

Code

function oa_clone_node_insert($node) {
  if (in_array($node->type, array(
    'oa_section',
    'oa_space',
    'oa_group',
  )) && !empty($node->clone_from_original_nid) && empty($node->oa_clone_skip)) {
    $original_nid = $node->clone_from_original_nid;
    $batch = array(
      'title' => t('Cloning content...'),
      'operations' => array(),
      'finished' => 'oa_clone_batch_finished',
    );
    switch ($node->type) {
      case 'oa_section':
        $batch['operations'][] = array(
          'oa_clone_batch_clone_section_content',
          array(
            $node,
            $original_nid,
          ),
        );
        break;
      case 'oa_space':
        _oa_clone_batch_space($batch, $node, $original_nid);
        break;
      case 'oa_group':
        $batch['operations'][] = array(
          'oa_clone_batch_clone_group_memberships',
          array(
            $node,
            $original_nid,
          ),
        );
        $batch['operations'][] = array(
          'oa_clone_batch_clone_group_metadata',
          array(
            $node,
            $original_nid,
          ),
        );
        break;
    }
    batch_set($batch);

    // If in a wizard (modal), drupal_process_form will try executing the batch
    // no matter that it's an ajax callback, which will fail.
    // We isntead replace drupal_goto with a function taht remembers where to
    // redirect to for later.
    if (!empty($node->oa_clone_alter_batch)) {
      $batch =& batch_get();
      $batch['redirect_callback'] = 'oa_clone_save_batch_info';
      $batch['source_url'] = (!empty($_GET['sitemap']) ? 'sitemap/' : 'node/') . $node->nid;
    }
  }
}