Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/config/src/Form/ConfigSync.php @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | c75dbcec494b |
children | 12f9dff5fda9 |
comparison
equal
deleted
inserted
replaced
3:307d7a7fd348 | 4:a9cd425dd02b |
---|---|
2 | 2 |
3 namespace Drupal\config\Form; | 3 namespace Drupal\config\Form; |
4 | 4 |
5 use Drupal\Core\Config\ConfigImporterException; | 5 use Drupal\Core\Config\ConfigImporterException; |
6 use Drupal\Core\Config\ConfigImporter; | 6 use Drupal\Core\Config\ConfigImporter; |
7 use Drupal\Core\Config\Importer\ConfigImporterBatch; | |
7 use Drupal\Core\Config\TypedConfigManagerInterface; | 8 use Drupal\Core\Config\TypedConfigManagerInterface; |
8 use Drupal\Core\Extension\ModuleHandlerInterface; | 9 use Drupal\Core\Extension\ModuleHandlerInterface; |
9 use Drupal\Core\Extension\ModuleInstallerInterface; | 10 use Drupal\Core\Extension\ModuleInstallerInterface; |
10 use Drupal\Core\Extension\ThemeHandlerInterface; | 11 use Drupal\Core\Extension\ThemeHandlerInterface; |
11 use Drupal\Core\Config\ConfigManagerInterface; | 12 use Drupal\Core\Config\ConfigManagerInterface; |
62 protected $eventDispatcher; | 63 protected $eventDispatcher; |
63 | 64 |
64 /** | 65 /** |
65 * The configuration manager. | 66 * The configuration manager. |
66 * | 67 * |
67 * @var \Drupal\Core\Config\ConfigManagerInterface; | 68 * @var \Drupal\Core\Config\ConfigManagerInterface |
68 */ | 69 */ |
69 protected $configManager; | 70 protected $configManager; |
70 | 71 |
71 /** | 72 /** |
72 * The typed config manager. | 73 * The typed config manager. |
189 ]; | 190 ]; |
190 $form['actions']['#access'] = FALSE; | 191 $form['actions']['#access'] = FALSE; |
191 return $form; | 192 return $form; |
192 } | 193 } |
193 elseif (!$storage_comparer->validateSiteUuid()) { | 194 elseif (!$storage_comparer->validateSiteUuid()) { |
194 drupal_set_message($this->t('The staged configuration cannot be imported, because it originates from a different site than this site. You can only synchronize configuration between cloned instances of this site.'), 'error'); | 195 $this->messenger()->addError($this->t('The staged configuration cannot be imported, because it originates from a different site than this site. You can only synchronize configuration between cloned instances of this site.')); |
195 $form['actions']['#access'] = FALSE; | 196 $form['actions']['#access'] = FALSE; |
196 return $form; | 197 return $form; |
197 } | 198 } |
198 // A list of changes will be displayed, so check if the user should be | 199 // A list of changes will be displayed, so check if the user should be |
199 // warned of potential losses to configuration. | 200 // warned of potential losses to configuration. |
212 } | 213 } |
213 } | 214 } |
214 sort($change_list); | 215 sort($change_list); |
215 $message = [ | 216 $message = [ |
216 [ | 217 [ |
217 '#markup' => $this->t('The following items in your active configuration have changes since the last import that may be lost on the next import.') | 218 '#markup' => $this->t('The following items in your active configuration have changes since the last import that may be lost on the next import.'), |
218 ], | 219 ], |
219 [ | 220 [ |
220 '#theme' => 'item_list', | 221 '#theme' => 'item_list', |
221 '#items' => $change_list, | 222 '#items' => $change_list, |
222 ] | 223 ], |
223 ]; | 224 ]; |
224 drupal_set_message($this->renderer->renderPlain($message), 'warning'); | 225 $this->messenger()->addWarning($this->renderer->renderPlain($message)); |
225 } | 226 } |
226 } | 227 } |
227 | 228 |
228 // Store the comparer for use in the submit. | 229 // Store the comparer for use in the submit. |
229 $form_state->set('storage_comparer', $storage_comparer); | 230 $form_state->set('storage_comparer', $storage_comparer); |
293 'url' => Url::fromRoute($route_name, $route_options), | 294 'url' => Url::fromRoute($route_name, $route_options), |
294 'attributes' => [ | 295 'attributes' => [ |
295 'class' => ['use-ajax'], | 296 'class' => ['use-ajax'], |
296 'data-dialog-type' => 'modal', | 297 'data-dialog-type' => 'modal', |
297 'data-dialog-options' => json_encode([ | 298 'data-dialog-options' => json_encode([ |
298 'width' => 700 | 299 'width' => 700, |
299 ]), | 300 ]), |
300 ], | 301 ], |
301 ]; | 302 ]; |
302 $form[$collection][$config_change_type]['list']['#rows'][] = [ | 303 $form[$collection][$config_change_type]['list']['#rows'][] = [ |
303 'name' => $config_name, | 304 'name' => $config_name, |
328 $this->moduleInstaller, | 329 $this->moduleInstaller, |
329 $this->themeHandler, | 330 $this->themeHandler, |
330 $this->getStringTranslation() | 331 $this->getStringTranslation() |
331 ); | 332 ); |
332 if ($config_importer->alreadyImporting()) { | 333 if ($config_importer->alreadyImporting()) { |
333 drupal_set_message($this->t('Another request may be synchronizing configuration already.')); | 334 $this->messenger()->addStatus($this->t('Another request may be synchronizing configuration already.')); |
334 } | 335 } |
335 else { | 336 else { |
336 try { | 337 try { |
337 $sync_steps = $config_importer->initialize(); | 338 $sync_steps = $config_importer->initialize(); |
338 $batch = [ | 339 $batch = [ |
339 'operations' => [], | 340 'operations' => [], |
340 'finished' => [get_class($this), 'finishBatch'], | 341 'finished' => [ConfigImporterBatch::class, 'finish'], |
341 'title' => t('Synchronizing configuration'), | 342 'title' => t('Synchronizing configuration'), |
342 'init_message' => t('Starting configuration synchronization.'), | 343 'init_message' => t('Starting configuration synchronization.'), |
343 'progress_message' => t('Completed step @current of @total.'), | 344 'progress_message' => t('Completed step @current of @total.'), |
344 'error_message' => t('Configuration synchronization has encountered an error.'), | 345 'error_message' => t('Configuration synchronization has encountered an error.'), |
345 ]; | 346 ]; |
346 foreach ($sync_steps as $sync_step) { | 347 foreach ($sync_steps as $sync_step) { |
347 $batch['operations'][] = [[get_class($this), 'processBatch'], [$config_importer, $sync_step]]; | 348 $batch['operations'][] = [[ConfigImporterBatch::class, 'process'], [$config_importer, $sync_step]]; |
348 } | 349 } |
349 | 350 |
350 batch_set($batch); | 351 batch_set($batch); |
351 } | 352 } |
352 catch (ConfigImporterException $e) { | 353 catch (ConfigImporterException $e) { |
353 // There are validation errors. | 354 // There are validation errors. |
354 drupal_set_message($this->t('The configuration cannot be imported because it failed validation for the following reasons:'), 'error'); | 355 $this->messenger()->addError($this->t('The configuration cannot be imported because it failed validation for the following reasons:')); |
355 foreach ($config_importer->getErrors() as $message) { | 356 foreach ($config_importer->getErrors() as $message) { |
356 drupal_set_message($message, 'error'); | 357 $this->messenger()->addError($message); |
357 } | 358 } |
358 } | 359 } |
359 } | 360 } |
360 } | 361 } |
361 | 362 |
366 * The batch config importer object to persist. | 367 * The batch config importer object to persist. |
367 * @param string $sync_step | 368 * @param string $sync_step |
368 * The synchronization step to do. | 369 * The synchronization step to do. |
369 * @param array $context | 370 * @param array $context |
370 * The batch context. | 371 * The batch context. |
372 * | |
373 * @deprecated in Drupal 8.6.0 and will be removed before 9.0.0. Use | |
374 * \Drupal\Core\Config\Importer\ConfigImporterBatch::process() instead. | |
375 * | |
376 * @see https://www.drupal.org/node/2897299 | |
371 */ | 377 */ |
372 public static function processBatch(ConfigImporter $config_importer, $sync_step, &$context) { | 378 public static function processBatch(ConfigImporter $config_importer, $sync_step, &$context) { |
373 if (!isset($context['sandbox']['config_importer'])) { | 379 @trigger_error('\Drupal\config\Form\ConfigSync::processBatch() deprecated in Drupal 8.6.0 and will be removed before 9.0.0. Use \Drupal\Core\Config\Importer\ConfigImporterBatch::process() instead. See https://www.drupal.org/node/2897299'); |
374 $context['sandbox']['config_importer'] = $config_importer; | 380 ConfigImporterBatch::process($config_importer, $sync_step, $context); |
375 } | |
376 | |
377 $config_importer = $context['sandbox']['config_importer']; | |
378 $config_importer->doSyncStep($sync_step, $context); | |
379 if ($errors = $config_importer->getErrors()) { | |
380 if (!isset($context['results']['errors'])) { | |
381 $context['results']['errors'] = []; | |
382 } | |
383 $context['results']['errors'] += $errors; | |
384 } | |
385 } | 381 } |
386 | 382 |
387 /** | 383 /** |
388 * Finish batch. | 384 * Finish batch. |
389 * | 385 * |
390 * This function is a static function to avoid serializing the ConfigSync | 386 * This function is a static function to avoid serializing the ConfigSync |
391 * object unnecessarily. | 387 * object unnecessarily. |
388 * | |
389 * @deprecated in Drupal 8.6.0 and will be removed before 9.0.0. Use | |
390 * \Drupal\Core\Config\Importer\ConfigImporterBatch::finish() instead. | |
391 * | |
392 * @see https://www.drupal.org/node/2897299 | |
392 */ | 393 */ |
393 public static function finishBatch($success, $results, $operations) { | 394 public static function finishBatch($success, $results, $operations) { |
394 if ($success) { | 395 @trigger_error('\Drupal\config\Form\ConfigSync::finishBatch() deprecated in Drupal 8.6.0 and will be removed before 9.0.0. Use \Drupal\Core\Config\Importer\ConfigImporterBatch::finish() instead. See https://www.drupal.org/node/2897299'); |
395 if (!empty($results['errors'])) { | 396 ConfigImporterBatch::finish($success, $results, $operations); |
396 foreach ($results['errors'] as $error) { | |
397 drupal_set_message($error, 'error'); | |
398 \Drupal::logger('config_sync')->error($error); | |
399 } | |
400 drupal_set_message(\Drupal::translation()->translate('The configuration was imported with errors.'), 'warning'); | |
401 } | |
402 else { | |
403 drupal_set_message(\Drupal::translation()->translate('The configuration was imported successfully.')); | |
404 } | |
405 } | |
406 else { | |
407 // An error occurred. | |
408 // $operations contains the operations that remained unprocessed. | |
409 $error_operation = reset($operations); | |
410 $message = \Drupal::translation()->translate('An error occurred while processing %error_operation with arguments: @arguments', ['%error_operation' => $error_operation[0], '@arguments' => print_r($error_operation[1], TRUE)]); | |
411 drupal_set_message($message, 'error'); | |
412 } | |
413 } | 397 } |
414 | 398 |
415 } | 399 } |