You are here

function gathercontent_import_form_confirm_submit in GatherContent 7.3

Grdg.

@inheritdoc

File

./gathercontent.import.inc, line 536

Code

function gathercontent_import_form_confirm_submit($form, &$form_state) {
  $form_state['object']->status = $form_state['values']['status'];
  $uuid = _gathercontent_uuid_generate();
  $operation = entity_create('gathercontent_operation', array(
    'uuid' => $uuid,
    'type' => 'import',
  ));
  entity_save('gathercontent_operation', $operation);
  $operations = array();
  $stack = array();
  $import_content = $form_state['object']->nodes;
  foreach ($import_content as $k => $value) {
    if (isset($form_state['object']->menu[$value]) && $form_state['object']->menu[$value] != -1 || !isset($form_state['object']->menu[$value])) {
      $parent_menu_item = isset($form_state['object']->menu[$value]) ? $form_state['object']->menu[$value] : NULL;
      $drupalStatus = isset($form_state['object']->drupal_status[$value]) ? $form_state['object']->drupal_status[$value] : 0;
      $operations[] = array(
        'gathercontent_import_process',
        array(
          $value,
          $form_state['object']->status,
          $uuid,
          $drupalStatus,
          $parent_menu_item,
          $form_state['values']['node_update_method'],
        ),
      );
      $stack[] = $value;
      unset($import_content[$k]);
    }
  }

  // If there are any items.
  if (!empty($import_content)) {

    // Load all by project_id.
    $first = reset($import_content);
    $content_obj = new Content();
    $content = $content_obj
      ->getContent($first);
    $contents_source = $content_obj
      ->getContents($content->project_id);
    $content = array();
    foreach ($contents_source as $value) {
      $content[$value->id] = $value;
    }
    while (!empty($import_content)) {
      $current = reset($import_content);
      if (in_array($content[$current]->parent_id, $stack)) {
        $parent_menu_item = 'node:' . $content[$current]->parent_id;
        $drupalStatus = isset($form_state['object']->drupal_status[$current]) ? $form_state['object']->drupal_status[$current] : 0;
        $operations[] = array(
          'gathercontent_import_process',
          array(
            $current,
            $form_state['object']->status,
            $uuid,
            $drupalStatus,
            $parent_menu_item,
            $form_state['values']['node_update_method'],
          ),
        );
        $stack[] = $current;
        array_shift($import_content);
      }
      else {
        array_shift($import_content);
        array_push($import_content, $current);
      }
    }
  }
  $batch = array(
    'title' => t('Importing content ...'),
    'operations' => $operations,
    'finished' => 'gathercontent_import_finished',
    'file' => drupal_get_path('module', 'gathercontent') . '/gathercontent.import.inc',
    'init_message' => t('Import is starting ...'),
    'progress_message' => t('Processed @current out of @total.'),
    'error_message' => t('An error occurred during processing'),
  );
  batch_set($batch);
}