You are here

function gathercontent_update_finished in GatherContent 8.4

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

Finished callback.

@inheritdoc

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

File

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

Code

function gathercontent_update_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/update/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;
}