You are here

function gathercontent_import_finished in GatherContent 8.4

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

Finished callback.

1 string reference to 'gathercontent_import_finished'
ContentImportSelectForm::submitForm in gathercontent_ui/src/Form/ContentImportSelectForm.php
Form submission handler.

File

./gathercontent.module, line 88
Main module file for GatherContent module.

Code

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

    // Select all items with uuid.
    $result = \Drupal::entityQuery('gathercontent_operation_item')
      ->condition('operation_uuid', $results['uuid'])
      ->execute();
    if (!empty($result)) {
      $operation_items = OperationItem::loadMultiple($result);
      $success_counter = 0;
      $nids = [
        'success' => [],
        'failed' => [],
      ];
      foreach ($operation_items as $operation_item) {

        /** @var \Drupal\gathercontent\Entity\OperationItem $operation_item */
        if ($operation_item
          ->getStatus() === 'Success') {
          $success_counter++;
          $nids['success'][] = [
            'nid' => $operation_item
              ->get('nid')->value,
            'gc_id' => $operation_item
              ->get('gc_id')->value,
          ];
        }
        else {
          $nids['failed'][] = [
            'nid' => $operation_item
              ->get('nid')->value,
            'gc_id' => $operation_item
              ->get('gc_id')->value,
          ];
        }
      }
      $unsuccessful = count($result) - $success_counter;
      drupal_set_message(\Drupal::translation()
        ->formatPlural($success_counter, '1 item was imported successfully.', '@count items were imported successfully.'));
      if ($unsuccessful > 0) {
        drupal_set_message(\Drupal::translation()
          ->formatPlural($unsuccessful, '1 item was not imported. Check errors below.', '@count items were not imported. Check errors below.'), 'error');
      }
      \Drupal::service('event_dispatcher')
        ->dispatch(GatherContentEvents::POST_IMPORT, new PostImportEvent($nids['success'], $nids['failed'], $results['uuid']));
    }
    return new RedirectResponse('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', [
      '@operation' => $error_operation[0],
      '@args' => print_r($error_operation[0], TRUE),
    ]), 'error');
  }
  return TRUE;
}