You are here

public static function UserImportController::userImportBatchFinished in Simple Node Importer 8

Callback : Called when batch process is finished.

File

src/Controller/UserImportController.php, line 91

Class

UserImportController
Default controller for the simple_node_importer module.

Namespace

Drupal\simple_node_importer\Controller

Code

public static function userImportBatchFinished($success, $results, $operations) {
  if ($success) {
    $rclink = Url::fromRoute('simple_node_importer.node_resolution_center', [], [
      'absolute' => TRUE,
    ]);
    $link = $rclink
      ->toString();
    $created_count = !empty($results['created']) ? $results['created'] : NULL;
    $failed_count = !empty($results['failed']) ? $results['failed'] : NULL;
    if ($created_count && !$failed_count) {
      $import_status = new FormattableMarkup("Users registered successfully: @created_count", [
        '@created_count' => $created_count,
      ]);
    }
    elseif (!$created_count && $failed_count) {
      $import_status = new FormattableMarkup('Users import failed: @failed_count .To view failed records, please visit <a href="@link">Resolution Center</a>', [
        '@failed_count' => $failed_count,
        '@link' => $link,
      ]);
    }
    else {
      $import_status = new FormattableMarkup('Users registered successfully: @created_count<br/>Users import failed: @failed_count<br/>To view failed records, please visit <a href="@link">Resolution Center</a>', [
        '@created_count' => $created_count,
        '@failed_count' => $failed_count,
        '@link' => $link,
      ]);
    }
    if (isset($results['failed']) && !empty($results['failed'])) {

      // Add Failed nodes to Resolution Table.
      NodeImportController::addFailedRecordsInRc($results);
    }
    $statusMessage = t("Users import completed! Import status:<br/>@import_status", [
      '@import_status' => $import_status,
    ]);
    drupal_set_message($statusMessage);
  }
  else {
    $error_operation = reset($operations);
    $message = t('An error occurred while processing %error_operation with arguments: @arguments', [
      '%error_operation' => $error_operation[0],
      '@arguments' => print_r($error_operation[1], TRUE),
    ]);
    drupal_set_message($message, 'error');
  }
  return new RedirectResponse(\Drupal::url('<front>'));
}