Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace Drupal\Core\Config\Importer;
use Drupal\Core\Config\ConfigImporter;
/**
* Methods for running the ConfigImporter in a batch.
*
* @see \Drupal\Core\Config\ConfigImporter
*/
class ConfigImporterBatch {
/**
* Processes the config import batch and persists the importer.
*
* @param \Drupal\Core\Config\ConfigImporter $config_importer
* The batch config importer object to persist.
* @param string $sync_step
* The synchronization step to do.
* @param array $context
* The batch context.
*/
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']);
}
}
/**
* Finish batch.
*
* This function is a static function to avoid serializing the ConfigSync
* object unnecessarily.
*
* @param bool $success
* Indicate that the batch API tasks were all completed successfully.
* @param array $results
* An array of all the results that were updated in update_do_one().
* @param array $operations
* A list of the operations that had not been completed by the batch API.
*/
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 (!drupal_installation_attempted()) {
// 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);
}
}
}