ConfigImporterBatch.php in Drupal 8
File
core/lib/Drupal/Core/Config/Importer/ConfigImporterBatch.php
View source
<?php
namespace Drupal\Core\Config\Importer;
use Drupal\Core\Config\ConfigImporter;
use Drupal\Core\Installer\InstallerKernel;
class ConfigImporterBatch {
public static function process(ConfigImporter $config_importer, $sync_step, &$context) {
if (!isset($context['sandbox']['config_importer'])) {
$context['sandbox']['config_importer'] = $config_importer;
}
$config_importer = $context['sandbox']['config_importer'];
$config_importer
->doSyncStep($sync_step, $context);
if ($errors = $config_importer
->getErrors()) {
if (!isset($context['results']['errors'])) {
$context['results']['errors'] = [];
}
$context['results']['errors'] = array_merge($errors, $context['results']['errors']);
}
}
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()) {
$messenger
->addStatus(t('The configuration was imported successfully.'));
}
}
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),
]);
$messenger
->addError($message);
}
}
}