You are here

public static function NodeImportController::nodeImportBatchFinished in Simple Node Importer 8

Callback : Called when batch process is finished.

File

src/Controller/NodeImportController.php, line 133

Class

NodeImportController
Default controller for the simple_node_importer module.

Namespace

Drupal\simple_node_importer\Controller

Code

public static function nodeImportBatchFinished($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("Nodes successfully created: @created_count", [
        '@created_count' => $created_count,
      ]);
    }
    elseif (!$created_count && $failed_count) {
      $import_status = new FormattableMarkup('Nodes 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('Nodes successfully created: @created_count<br/>Nodes 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 = ;.
    drupal_set_message(t('Node import completed! Import status:<br/> @import_status', [
      '@import_status' => $import_status,
    ]));
  }
  else {
    $error_operation = reset($operations);
    $message = new FormattableMarkup('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>'));
}