You are here

function _oa_clone_batch_space in Open Atrium Clone 7.2

Recursively clone a Space while setting up a batch for cloning content.

1 call to _oa_clone_batch_space()
oa_clone_node_insert in ./oa_clone.module
Implements hook_node_insert().

File

./oa_clone.module, line 623

Code

function _oa_clone_batch_space(&$batch, $space, $original_space_nid) {
  $bypass_access_check = !empty($space->oa_clone_bypass_access_check);

  // Clone the OG metadata.
  $batch['operations'][] = array(
    'oa_clone_batch_clone_group_metadata',
    array(
      $space,
      $original_space_nid,
    ),
  );
  $not_orphan = array();

  // Clone all the Sections in this Space.
  foreach (array_keys(oa_core_space_sections($original_space_nid, 1, $bypass_access_check, array(), TRUE)) as $original_section_nid) {
    $not_orphan[$original_section_nid] = $original_section_nid;
    if ($clone_section = oa_clone($original_section_nid, $space->nid, NULL, $bypass_access_check)) {
      $not_orphan = array_merge($not_orphan, oa_clone_get_section_content($original_section_nid, $bypass_access_check));
      $batch['operations'][] = array(
        'oa_clone_batch_clone_section_content',
        array(
          $clone_section,
          $original_section_nid,
        ),
      );
    }
  }
  if (module_exists('oa_subspaces')) {

    // Clone all sub-Spaces in this Space.
    $associated_entities = oa_core_get_groups_by_parent($original_space_nid);
    if (!empty($associated_entities)) {
      foreach ($associated_entities as $original_subspace_nid) {
        $not_orphan[$original_subspace_nid] = $original_subspace_nid;
        if ($original_subspace_nid != $space->nid && ($clone_subspace = oa_clone($original_subspace_nid, $space->nid, NULL, $bypass_access_check))) {
          _oa_clone_batch_space($batch, $clone_subspace, $original_subspace_nid);
        }
      }
    }
  }
  if (module_exists('og_vocab') && ($vocabs = og_vocab_relation_get_by_group('node', $original_space_nid))) {
    foreach ($vocabs as $vocab) {
      $batch['operations'][] = array(
        'oa_clone_batch_og_vocab',
        array(
          $space,
          $vocab->vid,
          $original_space_nid,
        ),
      );
    }
  }
  if ($nids = array_diff(oa_clone_get_orphan_content($original_space_nid, $bypass_access_check), $not_orphan)) {
    $batch['operations'][] = array(
      'oa_clone_batch_clone_orphan_content',
      array(
        $space,
        $nids,
      ),
    );
  }
  $batch['operations'][] = array(
    'oa_clone_batch_og_menu_clone',
    array(
      $space,
      $original_space_nid,
    ),
  );
}