You are here

function gathercontent_import_finished in GatherContent 7.3

Same name and namespace in other branches
  1. 8.3 gathercontent.module \gathercontent_import_finished()
  2. 8.4 gathercontent.module \gathercontent_import_finished()

Finished callback.

@inheritdoc

1 string reference to 'gathercontent_import_finished'
gathercontent_import_form_confirm_submit in ./gathercontent.import.inc
Grdg.

File

./gathercontent.import.inc, line 670

Code

function gathercontent_import_finished($success, $results, $operations) {
  if ($success) {

    // Select all items with uuid.
    $query = new EntityFieldQuery();
    $result = $query
      ->entityCondition('entity_type', 'gathercontent_operation_item')
      ->propertyCondition('operation_uuid', $results['uuid'])
      ->execute();
    if (isset($result['gathercontent_operation_item'])) {
      $operation_items = entity_load('gathercontent_operation_item', array_keys($result['gathercontent_operation_item']));
      $success_counter = 0;
      $nids = array(
        'success' => array(),
        'failed' => array(),
      );
      foreach ($operation_items as $operation_item) {
        if ($operation_item->status === 'Success') {
          $success_counter++;
          $nids['success'][] = array(
            'nid' => $operation_item->nid,
            'gathercontent_id' => $operation_item->gathercontent_id,
          );
        }
        else {
          $nids['failed'][] = array(
            'nid' => $operation_item->nid,
            'gathercontent_id' => $operation_item->gathercontent_id,
          );
        }
      }
      $unsuccessful = count($result['gathercontent_operation_item']) - $success_counter;
      drupal_set_message(format_plural($success_counter, '1 item was imported successfully.', '@count items were imported successfully.'));
      if ($unsuccessful > 0) {
        drupal_set_message(format_plural($unsuccessful, '1 item was not imported. Check errors below.', '@count items were not imported. Check errors below.'), 'error');
      }
      module_invoke_all('gathercontent_post_import', $nids['success'], $nids['failed'], $results['uuid']);
    }
    drupal_goto('admin/config/gathercontent/import/result/' . $results['uuid']);
  }
  else {
    $error_operation = reset($operations);
    drupal_set_message(t('An error occurred while processing @operation with arguments : @args', array(
      '@operation' => $error_operation[0],
      '@args' => print_r($error_operation[0], TRUE),
    )), 'error');
  }
}