You are here

function finishContentBatch in Content Synchronization 8

Finish batch.

Provide information about the Content Batch results.

2 string references to 'finishContentBatch'
ContentSingleImportForm::submitForm in src/Form/ContentSingleImportForm.php
Form submission handler.
ContentSync::submitForm in src/Form/ContentSync.php
Form submission handler.

File

./content_sync.batch.inc, line 418

Code

function finishContentBatch($success, $results, $operations) {
  if ($success) {
    if (isset($results['errors'])) {
      $errors = $results['errors'];
      unset($results['errors']);
    }

    //kint($results);

    //$results = array_unique($results);

    //kint($results);

    // Log all the items processed
    foreach ($results as $key => $result) {
      if ($key != 'errors') {

        //drupal_set_message(t('Processed UUID @title.', array('@title' => $result)));
        \Drupal::logger('content_sync')
          ->notice('Processed UUID @title.', [
          '@title' => $result,
          'link' => 'Import',
        ]);
      }
    }
    if (!empty($errors)) {

      // Log the errors
      $errors = array_unique($errors);
      foreach ($errors as $error) {

        //  drupal_set_message($error, 'error');
        \Drupal::logger('content_sync')
          ->error($error, [
          'link' => 'Import',
        ]);

        // \Drupal::logger('content_sync')->error($error);
      }
      drupal_set_message(\Drupal::translation()
        ->translate('The content was imported with errors. <a href=":content-overview">Logs</a>', [
        ':content-overview' => \Drupal::url('content.overview'),
      ]), 'warning');
      \Drupal::logger('content_sync')
        ->warning('The content was imported with errors.', [
        'link' => 'Import',
      ]);
    }
    else {
      drupal_set_message(\Drupal::translation()
        ->translate('The content was imported successfully. <a href=":content-overview">Logs</a>', [
        ':content-overview' => \Drupal::url('content.overview'),
      ]));
      \Drupal::logger('content_sync')
        ->notice('The content was imported successfully.', [
        'link' => 'Import',
      ]);
    }
  }
  else {

    // Log if there was an error.
    $message = t('Finished with an error. <a href=":content-overview">Logs</a>', [
      ':content-overview' => \Drupal::url('content.overview'),
    ]);
    drupal_set_message($message);
    \Drupal::logger('content_sync')
      ->error('Finished with an error.', [
      'link' => 'Import',
    ]);
  }
  drupal_flush_all_caches();
}