You are here

function gc_import_finished in GatherContent 8

Finished callback.

@inheritdoc

File

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

Code

function gc_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 = GathercontentOperationItem::loadMultiple($result);
      $success_counter = 0;
      foreach ($operation_items as $operation_item) {

        /** @var $operation_item  \Drupal\gathercontent\Entity\GathercontentOperationItem */
        if ($operation_item
          ->getStatus() === 'Success') {
          $success_counter++;
        }
      }
      $unsuccessful = count($result['gc_operation_item']) - $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\Core\Url::fromUri('admin/config/gc/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');
  }
}