function ConfigImporterBatch::finish

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Config/Importer/ConfigImporterBatch.php \Drupal\Core\Config\Importer\ConfigImporterBatch::finish()
  2. 8.9.x core/lib/Drupal/Core/Config/Importer/ConfigImporterBatch.php \Drupal\Core\Config\Importer\ConfigImporterBatch::finish()
  3. 10 core/lib/Drupal/Core/Config/Importer/ConfigImporterBatch.php \Drupal\Core\Config\Importer\ConfigImporterBatch::finish()

Finish batch.

This function is a static function to avoid serializing the ConfigSync object unnecessarily.

Parameters

bool $success: Indicate that the batch API tasks were all completed successfully.

array $results: An array of all the results that were updated in update_do_one().

array $operations: A list of the operations that had not been completed by the batch API.

File

core/lib/Drupal/Core/Config/Importer/ConfigImporterBatch.php, line 53

Class

ConfigImporterBatch
Methods for running the ConfigImporter in a batch.

Namespace

Drupal\Core\Config\Importer

Code

public static function finish($success, $results, $operations) {
    $messenger = \Drupal::messenger();
    if ($success) {
        if (!empty($results['errors'])) {
            $logger = \Drupal::logger('config_sync');
            foreach ($results['errors'] as $error) {
                $messenger->addError($error);
                $logger->error($error);
            }
            $messenger->addWarning(t('The configuration was imported with errors.'));
        }
        elseif (!InstallerKernel::installationAttempted()) {
            // Display a success message when not installing Drupal.
            $messenger->addStatus(t('The configuration was imported successfully.'));
        }
    }
    else {
        // An error occurred.
        // $operations contains the operations that remained unprocessed.
        $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),
        ]);
        $messenger->addError($message);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.