annotate core/modules/migrate/src/Plugin/Migration.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\migrate\Plugin;
Chris@0 4
Chris@0 5 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
Chris@0 6 use Drupal\Core\Plugin\PluginBase;
Chris@0 7 use Drupal\migrate\Exception\RequirementsException;
Chris@0 8 use Drupal\migrate\MigrateException;
Chris@0 9 use Drupal\migrate\MigrateSkipRowException;
Chris@0 10 use Drupal\Component\Utility\NestedArray;
Chris@0 11 use Symfony\Component\DependencyInjection\ContainerInterface;
Chris@0 12
Chris@0 13 /**
Chris@0 14 * Defines the Migration plugin.
Chris@0 15 *
Chris@0 16 * The migration process plugin represents one single migration and acts like a
Chris@0 17 * container for the information about a single migration such as the source,
Chris@0 18 * process and destination plugins.
Chris@0 19 */
Chris@0 20 class Migration extends PluginBase implements MigrationInterface, RequirementsInterface, ContainerFactoryPluginInterface {
Chris@0 21
Chris@0 22 /**
Chris@0 23 * The migration ID (machine name).
Chris@0 24 *
Chris@0 25 * @var string
Chris@0 26 */
Chris@0 27 protected $id;
Chris@0 28
Chris@0 29 /**
Chris@0 30 * The human-readable label for the migration.
Chris@0 31 *
Chris@0 32 * @var string
Chris@0 33 */
Chris@0 34 protected $label;
Chris@0 35
Chris@0 36 /**
Chris@0 37 * The plugin ID for the row.
Chris@0 38 *
Chris@0 39 * @var string
Chris@0 40 */
Chris@0 41 protected $row;
Chris@0 42
Chris@0 43 /**
Chris@0 44 * The source configuration, with at least a 'plugin' key.
Chris@0 45 *
Chris@0 46 * Used to initialize the $sourcePlugin.
Chris@0 47 *
Chris@0 48 * @var array
Chris@0 49 */
Chris@0 50 protected $source;
Chris@0 51
Chris@0 52 /**
Chris@0 53 * The source plugin.
Chris@0 54 *
Chris@0 55 * @var \Drupal\migrate\Plugin\MigrateSourceInterface
Chris@0 56 */
Chris@0 57 protected $sourcePlugin;
Chris@0 58
Chris@0 59 /**
Chris@0 60 * The configuration describing the process plugins.
Chris@0 61 *
Chris@0 62 * This is a strictly internal property and should not returned to calling
Chris@0 63 * code, use getProcess() instead.
Chris@0 64 *
Chris@0 65 * @var array
Chris@0 66 */
Chris@0 67 protected $process = [];
Chris@0 68
Chris@0 69 /**
Chris@0 70 * The cached process plugins.
Chris@0 71 *
Chris@0 72 * @var array
Chris@0 73 */
Chris@0 74 protected $processPlugins = [];
Chris@0 75
Chris@0 76 /**
Chris@0 77 * The destination configuration, with at least a 'plugin' key.
Chris@0 78 *
Chris@0 79 * Used to initialize $destinationPlugin.
Chris@0 80 *
Chris@0 81 * @var array
Chris@0 82 */
Chris@0 83 protected $destination;
Chris@0 84
Chris@0 85 /**
Chris@0 86 * The destination plugin.
Chris@0 87 *
Chris@0 88 * @var \Drupal\migrate\Plugin\MigrateDestinationInterface
Chris@0 89 */
Chris@0 90 protected $destinationPlugin;
Chris@0 91
Chris@0 92 /**
Chris@0 93 * The identifier map data.
Chris@0 94 *
Chris@0 95 * Used to initialize $idMapPlugin.
Chris@0 96 *
Chris@0 97 * @var string
Chris@0 98 */
Chris@0 99 protected $idMap = [];
Chris@0 100
Chris@0 101 /**
Chris@0 102 * The identifier map.
Chris@0 103 *
Chris@0 104 * @var \Drupal\migrate\Plugin\MigrateIdMapInterface
Chris@0 105 */
Chris@0 106 protected $idMapPlugin;
Chris@0 107
Chris@0 108 /**
Chris@0 109 * The source identifiers.
Chris@0 110 *
Chris@0 111 * An array of source identifiers: the keys are the name of the properties,
Chris@0 112 * the values are dependent on the ID map plugin.
Chris@0 113 *
Chris@0 114 * @var array
Chris@0 115 */
Chris@0 116 protected $sourceIds = [];
Chris@0 117
Chris@0 118 /**
Chris@0 119 * The destination identifiers.
Chris@0 120 *
Chris@0 121 * An array of destination identifiers: the keys are the name of the
Chris@0 122 * properties, the values are dependent on the ID map plugin.
Chris@0 123 *
Chris@0 124 * @var array
Chris@0 125 */
Chris@0 126 protected $destinationIds = [];
Chris@0 127
Chris@0 128 /**
Chris@0 129 * Specify value of source_row_status for current map row. Usually set by
Chris@0 130 * MigrateFieldHandler implementations.
Chris@0 131 *
Chris@0 132 * @var int
Chris@0 133 */
Chris@0 134 protected $sourceRowStatus = MigrateIdMapInterface::STATUS_IMPORTED;
Chris@0 135
Chris@0 136 /**
Chris@0 137 * Track time of last import if TRUE.
Chris@0 138 *
Chris@0 139 * @var bool
Chris@0 140 */
Chris@0 141 protected $trackLastImported = FALSE;
Chris@0 142
Chris@0 143 /**
Chris@0 144 * These migrations must be already executed before this migration can run.
Chris@0 145 *
Chris@0 146 * @var array
Chris@0 147 */
Chris@0 148 protected $requirements = [];
Chris@0 149
Chris@0 150 /**
Chris@0 151 * An optional list of tags, used by the plugin manager for filtering.
Chris@0 152 *
Chris@0 153 * @var array
Chris@0 154 */
Chris@0 155 protected $migration_tags = [];
Chris@0 156
Chris@0 157 /**
Chris@14 158 * Whether the migration is auditable.
Chris@14 159 *
Chris@14 160 * If set to TRUE, the migration's IDs will be audited. This means that, if
Chris@14 161 * the highest destination ID is greater than the highest source ID, a warning
Chris@14 162 * will be displayed that entities might be overwritten.
Chris@14 163 *
Chris@14 164 * @var bool
Chris@14 165 */
Chris@14 166 protected $audit = FALSE;
Chris@14 167
Chris@14 168 /**
Chris@0 169 * These migrations, if run, must be executed before this migration.
Chris@0 170 *
Chris@0 171 * These are different from the configuration dependencies. Migration
Chris@0 172 * dependencies are only used to store relationships between migrations.
Chris@0 173 *
Chris@0 174 * The migration_dependencies value is structured like this:
Chris@0 175 * @code
Chris@0 176 * array(
Chris@0 177 * 'required' => array(
Chris@0 178 * // An array of migration IDs that must be run before this migration.
Chris@0 179 * ),
Chris@0 180 * 'optional' => array(
Chris@0 181 * // An array of migration IDs that, if they exist, must be run before
Chris@0 182 * // this migration.
Chris@0 183 * ),
Chris@0 184 * );
Chris@0 185 * @endcode
Chris@0 186 *
Chris@0 187 * @var array
Chris@0 188 */
Chris@0 189 protected $migration_dependencies = [];
Chris@0 190
Chris@0 191 /**
Chris@0 192 * The migration's configuration dependencies.
Chris@0 193 *
Chris@0 194 * These store any dependencies on modules or other configuration (including
Chris@0 195 * other migrations) that must be available before the migration can be
Chris@0 196 * created.
Chris@0 197 *
Chris@0 198 * @see \Drupal\Core\Config\Entity\ConfigDependencyManager
Chris@0 199 *
Chris@0 200 * @var array
Chris@0 201 */
Chris@0 202 protected $dependencies = [];
Chris@0 203
Chris@0 204 /**
Chris@0 205 * The migration plugin manager for loading other migration plugins.
Chris@0 206 *
Chris@0 207 * @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface
Chris@0 208 */
Chris@0 209 protected $migrationPluginManager;
Chris@0 210
Chris@0 211 /**
Chris@0 212 * The source plugin manager.
Chris@0 213 *
Chris@0 214 * @var \Drupal\migrate\Plugin\MigratePluginManager
Chris@0 215 */
Chris@0 216 protected $sourcePluginManager;
Chris@0 217
Chris@0 218 /**
Chris@17 219 * The process plugin manager.
Chris@0 220 *
Chris@0 221 * @var \Drupal\migrate\Plugin\MigratePluginManager
Chris@0 222 */
Chris@0 223 protected $processPluginManager;
Chris@0 224
Chris@0 225 /**
Chris@0 226 * The destination plugin manager.
Chris@0 227 *
Chris@0 228 * @var \Drupal\migrate\Plugin\MigrateDestinationPluginManager
Chris@0 229 */
Chris@0 230 protected $destinationPluginManager;
Chris@0 231
Chris@0 232 /**
Chris@0 233 * The ID map plugin manager.
Chris@0 234 *
Chris@0 235 * @var \Drupal\migrate\Plugin\MigratePluginManager
Chris@0 236 */
Chris@0 237 protected $idMapPluginManager;
Chris@0 238
Chris@0 239 /**
Chris@0 240 * Labels corresponding to each defined status.
Chris@0 241 *
Chris@0 242 * @var array
Chris@0 243 */
Chris@0 244 protected $statusLabels = [
Chris@0 245 self::STATUS_IDLE => 'Idle',
Chris@0 246 self::STATUS_IMPORTING => 'Importing',
Chris@0 247 self::STATUS_ROLLING_BACK => 'Rolling back',
Chris@0 248 self::STATUS_STOPPING => 'Stopping',
Chris@0 249 self::STATUS_DISABLED => 'Disabled',
Chris@0 250 ];
Chris@0 251
Chris@0 252 /**
Chris@0 253 * Constructs a Migration.
Chris@0 254 *
Chris@0 255 * @param array $configuration
Chris@0 256 * Plugin configuration.
Chris@0 257 * @param string $plugin_id
Chris@0 258 * The plugin ID.
Chris@0 259 * @param mixed $plugin_definition
Chris@0 260 * The plugin definition.
Chris@0 261 * @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager
Chris@0 262 * The migration plugin manager.
Chris@0 263 * @param \Drupal\migrate\Plugin\MigratePluginManagerInterface $source_plugin_manager
Chris@0 264 * The source migration plugin manager.
Chris@0 265 * @param \Drupal\migrate\Plugin\MigratePluginManagerInterface $process_plugin_manager
Chris@0 266 * The process migration plugin manager.
Chris@0 267 * @param \Drupal\migrate\Plugin\MigrateDestinationPluginManager $destination_plugin_manager
Chris@0 268 * The destination migration plugin manager.
Chris@0 269 * @param \Drupal\migrate\Plugin\MigratePluginManagerInterface $idmap_plugin_manager
Chris@0 270 * The ID map migration plugin manager.
Chris@0 271 */
Chris@0 272 public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationPluginManagerInterface $migration_plugin_manager, MigratePluginManagerInterface $source_plugin_manager, MigratePluginManagerInterface $process_plugin_manager, MigrateDestinationPluginManager $destination_plugin_manager, MigratePluginManagerInterface $idmap_plugin_manager) {
Chris@0 273 parent::__construct($configuration, $plugin_id, $plugin_definition);
Chris@0 274 $this->migrationPluginManager = $migration_plugin_manager;
Chris@0 275 $this->sourcePluginManager = $source_plugin_manager;
Chris@0 276 $this->processPluginManager = $process_plugin_manager;
Chris@0 277 $this->destinationPluginManager = $destination_plugin_manager;
Chris@0 278 $this->idMapPluginManager = $idmap_plugin_manager;
Chris@0 279
Chris@0 280 foreach (NestedArray::mergeDeep($plugin_definition, $configuration) as $key => $value) {
Chris@0 281 $this->$key = $value;
Chris@0 282 }
Chris@0 283 }
Chris@0 284
Chris@0 285 /**
Chris@0 286 * {@inheritdoc}
Chris@0 287 */
Chris@0 288 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
Chris@0 289 return new static(
Chris@0 290 $configuration,
Chris@0 291 $plugin_id,
Chris@0 292 $plugin_definition,
Chris@0 293 $container->get('plugin.manager.migration'),
Chris@0 294 $container->get('plugin.manager.migrate.source'),
Chris@0 295 $container->get('plugin.manager.migrate.process'),
Chris@0 296 $container->get('plugin.manager.migrate.destination'),
Chris@0 297 $container->get('plugin.manager.migrate.id_map')
Chris@0 298 );
Chris@0 299 }
Chris@0 300
Chris@0 301 /**
Chris@0 302 * {@inheritdoc}
Chris@0 303 */
Chris@0 304 public function id() {
Chris@0 305 return $this->pluginId;
Chris@0 306 }
Chris@0 307
Chris@0 308 /**
Chris@0 309 * {@inheritdoc}
Chris@0 310 */
Chris@0 311 public function label() {
Chris@0 312 return $this->label;
Chris@0 313 }
Chris@0 314
Chris@0 315 /**
Chris@0 316 * Gets any arbitrary property's value.
Chris@0 317 *
Chris@0 318 * @param string $property
Chris@0 319 * The property to retrieve.
Chris@0 320 *
Chris@0 321 * @return mixed
Chris@0 322 * The value for that property, or NULL if the property does not exist.
Chris@0 323 *
Chris@0 324 * @deprecated in Drupal 8.1.x, will be removed before Drupal 9.0.x. Use
Chris@0 325 * more specific getters instead.
Chris@0 326 *
Chris@0 327 * @see https://www.drupal.org/node/2873795
Chris@0 328 */
Chris@0 329 public function get($property) {
Chris@18 330 @trigger_error('\Drupal\migrate\Plugin\Migration::get() is deprecated in Drupal 8.1.x, will be removed before Drupal 9.0.x. Use more specific getters instead. See https://www.drupal.org/node/2873795', E_USER_DEPRECATED);
Chris@0 331 return isset($this->$property) ? $this->$property : NULL;
Chris@0 332 }
Chris@0 333
Chris@0 334 /**
Chris@0 335 * Retrieves the ID map plugin.
Chris@0 336 *
Chris@0 337 * @return \Drupal\migrate\Plugin\MigrateIdMapInterface
Chris@0 338 * The ID map plugin.
Chris@0 339 */
Chris@0 340 public function getIdMapPlugin() {
Chris@0 341 return $this->idMapPlugin;
Chris@0 342 }
Chris@0 343
Chris@0 344 /**
Chris@0 345 * {@inheritdoc}
Chris@0 346 */
Chris@0 347 public function getSourcePlugin() {
Chris@0 348 if (!isset($this->sourcePlugin)) {
Chris@0 349 $this->sourcePlugin = $this->sourcePluginManager->createInstance($this->source['plugin'], $this->source, $this);
Chris@0 350 }
Chris@0 351 return $this->sourcePlugin;
Chris@0 352 }
Chris@0 353
Chris@0 354 /**
Chris@0 355 * {@inheritdoc}
Chris@0 356 */
Chris@0 357 public function getProcessPlugins(array $process = NULL) {
Chris@0 358 if (!isset($process)) {
Chris@0 359 $process = $this->getProcess();
Chris@0 360 }
Chris@0 361 $index = serialize($process);
Chris@0 362 if (!isset($this->processPlugins[$index])) {
Chris@0 363 $this->processPlugins[$index] = [];
Chris@0 364 foreach ($this->getProcessNormalized($process) as $property => $configurations) {
Chris@0 365 $this->processPlugins[$index][$property] = [];
Chris@0 366 foreach ($configurations as $configuration) {
Chris@0 367 if (isset($configuration['source'])) {
Chris@0 368 $this->processPlugins[$index][$property][] = $this->processPluginManager->createInstance('get', $configuration, $this);
Chris@0 369 }
Chris@0 370 // Get is already handled.
Chris@0 371 if ($configuration['plugin'] != 'get') {
Chris@0 372 $this->processPlugins[$index][$property][] = $this->processPluginManager->createInstance($configuration['plugin'], $configuration, $this);
Chris@0 373 }
Chris@0 374 if (!$this->processPlugins[$index][$property]) {
Chris@0 375 throw new MigrateException("Invalid process configuration for $property");
Chris@0 376 }
Chris@0 377 }
Chris@0 378 }
Chris@0 379 }
Chris@0 380 return $this->processPlugins[$index];
Chris@0 381 }
Chris@0 382
Chris@0 383 /**
Chris@0 384 * Resolve shorthands into a list of plugin configurations.
Chris@0 385 *
Chris@0 386 * @param array $process
Chris@0 387 * A process configuration array.
Chris@0 388 *
Chris@0 389 * @return array
Chris@0 390 * The normalized process configuration.
Chris@0 391 */
Chris@0 392 protected function getProcessNormalized(array $process) {
Chris@0 393 $normalized_configurations = [];
Chris@0 394 foreach ($process as $destination => $configuration) {
Chris@0 395 if (is_string($configuration)) {
Chris@0 396 $configuration = [
Chris@0 397 'plugin' => 'get',
Chris@0 398 'source' => $configuration,
Chris@0 399 ];
Chris@0 400 }
Chris@0 401 if (isset($configuration['plugin'])) {
Chris@0 402 $configuration = [$configuration];
Chris@0 403 }
Chris@0 404 $normalized_configurations[$destination] = $configuration;
Chris@0 405 }
Chris@0 406 return $normalized_configurations;
Chris@0 407 }
Chris@0 408
Chris@0 409 /**
Chris@0 410 * {@inheritdoc}
Chris@0 411 */
Chris@0 412 public function getDestinationPlugin($stub_being_requested = FALSE) {
Chris@0 413 if ($stub_being_requested && !empty($this->destination['no_stub'])) {
Chris@17 414 throw new MigrateSkipRowException('Stub requested but not made because no_stub configuration is set.');
Chris@0 415 }
Chris@0 416 if (!isset($this->destinationPlugin)) {
Chris@0 417 $this->destinationPlugin = $this->destinationPluginManager->createInstance($this->destination['plugin'], $this->destination, $this);
Chris@0 418 }
Chris@0 419 return $this->destinationPlugin;
Chris@0 420 }
Chris@0 421
Chris@0 422 /**
Chris@0 423 * {@inheritdoc}
Chris@0 424 */
Chris@0 425 public function getIdMap() {
Chris@0 426 if (!isset($this->idMapPlugin)) {
Chris@0 427 $configuration = $this->idMap;
Chris@0 428 $plugin = isset($configuration['plugin']) ? $configuration['plugin'] : 'sql';
Chris@0 429 $this->idMapPlugin = $this->idMapPluginManager->createInstance($plugin, $configuration, $this);
Chris@0 430 }
Chris@0 431 return $this->idMapPlugin;
Chris@0 432 }
Chris@0 433
Chris@0 434 /**
Chris@0 435 * {@inheritdoc}
Chris@0 436 */
Chris@0 437 public function checkRequirements() {
Chris@0 438 // Check whether the current migration source and destination plugin
Chris@0 439 // requirements are met or not.
Chris@0 440 if ($this->getSourcePlugin() instanceof RequirementsInterface) {
Chris@0 441 $this->getSourcePlugin()->checkRequirements();
Chris@0 442 }
Chris@0 443 if ($this->getDestinationPlugin() instanceof RequirementsInterface) {
Chris@0 444 $this->getDestinationPlugin()->checkRequirements();
Chris@0 445 }
Chris@0 446
Chris@0 447 if (empty($this->requirements)) {
Chris@0 448 // There are no requirements to check.
Chris@0 449 return;
Chris@0 450 }
Chris@0 451 /** @var \Drupal\migrate\Plugin\MigrationInterface[] $required_migrations */
Chris@0 452 $required_migrations = $this->getMigrationPluginManager()->createInstances($this->requirements);
Chris@0 453
Chris@0 454 $missing_migrations = array_diff($this->requirements, array_keys($required_migrations));
Chris@0 455 // Check if the dependencies are in good shape.
Chris@0 456 foreach ($required_migrations as $migration_id => $required_migration) {
Chris@0 457 if (!$required_migration->allRowsProcessed()) {
Chris@0 458 $missing_migrations[] = $migration_id;
Chris@0 459 }
Chris@0 460 }
Chris@0 461 if ($missing_migrations) {
Chris@0 462 throw new RequirementsException('Missing migrations ' . implode(', ', $missing_migrations) . '.', ['requirements' => $missing_migrations]);
Chris@0 463 }
Chris@0 464 }
Chris@0 465
Chris@0 466 /**
Chris@0 467 * Gets the migration plugin manager.
Chris@0 468 *
Chris@0 469 * @return \Drupal\migrate\Plugin\MigratePluginManager
Chris@0 470 * The plugin manager.
Chris@0 471 */
Chris@0 472 protected function getMigrationPluginManager() {
Chris@0 473 return $this->migrationPluginManager;
Chris@0 474 }
Chris@0 475
Chris@0 476 /**
Chris@0 477 * {@inheritdoc}
Chris@0 478 */
Chris@0 479 public function setStatus($status) {
Chris@0 480 \Drupal::keyValue('migrate_status')->set($this->id(), $status);
Chris@0 481 }
Chris@0 482
Chris@0 483 /**
Chris@0 484 * {@inheritdoc}
Chris@0 485 */
Chris@0 486 public function getStatus() {
Chris@0 487 return \Drupal::keyValue('migrate_status')->get($this->id(), static::STATUS_IDLE);
Chris@0 488 }
Chris@0 489
Chris@0 490 /**
Chris@0 491 * {@inheritdoc}
Chris@0 492 */
Chris@0 493 public function getStatusLabel() {
Chris@0 494 $status = $this->getStatus();
Chris@0 495 if (isset($this->statusLabels[$status])) {
Chris@0 496 return $this->statusLabels[$status];
Chris@0 497 }
Chris@0 498 else {
Chris@0 499 return '';
Chris@0 500 }
Chris@0 501 }
Chris@0 502
Chris@0 503 /**
Chris@0 504 * {@inheritdoc}
Chris@0 505 */
Chris@0 506 public function getInterruptionResult() {
Chris@0 507 return \Drupal::keyValue('migrate_interruption_result')->get($this->id(), static::RESULT_INCOMPLETE);
Chris@0 508 }
Chris@0 509
Chris@0 510 /**
Chris@0 511 * {@inheritdoc}
Chris@0 512 */
Chris@0 513 public function clearInterruptionResult() {
Chris@0 514 \Drupal::keyValue('migrate_interruption_result')->delete($this->id());
Chris@0 515 }
Chris@0 516
Chris@0 517 /**
Chris@0 518 * {@inheritdoc}
Chris@0 519 */
Chris@0 520 public function interruptMigration($result) {
Chris@0 521 $this->setStatus(MigrationInterface::STATUS_STOPPING);
Chris@0 522 \Drupal::keyValue('migrate_interruption_result')->set($this->id(), $result);
Chris@0 523 }
Chris@0 524
Chris@0 525 /**
Chris@0 526 * {@inheritdoc}
Chris@0 527 */
Chris@0 528 public function allRowsProcessed() {
Chris@0 529 $source_count = $this->getSourcePlugin()->count();
Chris@0 530 // If the source is uncountable, we have no way of knowing if it's
Chris@0 531 // complete, so stipulate that it is.
Chris@0 532 if ($source_count < 0) {
Chris@0 533 return TRUE;
Chris@0 534 }
Chris@0 535 $processed_count = $this->getIdMap()->processedCount();
Chris@0 536 // We don't use == because in some circumstances (like unresolved stubs
Chris@0 537 // being created), the processed count may be higher than the available
Chris@0 538 // source rows.
Chris@0 539 return $source_count <= $processed_count;
Chris@0 540 }
Chris@0 541
Chris@0 542 /**
Chris@0 543 * {@inheritdoc}
Chris@0 544 */
Chris@0 545 public function set($property_name, $value) {
Chris@0 546 if ($property_name == 'source') {
Chris@0 547 // Invalidate the source plugin.
Chris@0 548 unset($this->sourcePlugin);
Chris@0 549 }
Chris@0 550 elseif ($property_name === 'destination') {
Chris@0 551 // Invalidate the destination plugin.
Chris@0 552 unset($this->destinationPlugin);
Chris@0 553 }
Chris@0 554 $this->{$property_name} = $value;
Chris@0 555 return $this;
Chris@0 556 }
Chris@0 557
Chris@0 558 /**
Chris@0 559 * {@inheritdoc}
Chris@0 560 */
Chris@0 561 public function getProcess() {
Chris@0 562 return $this->getProcessNormalized($this->process);
Chris@0 563 }
Chris@0 564
Chris@0 565 /**
Chris@0 566 * {@inheritdoc}
Chris@0 567 */
Chris@0 568 public function setProcess(array $process) {
Chris@0 569 $this->process = $process;
Chris@0 570 return $this;
Chris@0 571 }
Chris@0 572
Chris@0 573 /**
Chris@0 574 * {@inheritdoc}
Chris@0 575 */
Chris@0 576 public function setProcessOfProperty($property, $process_of_property) {
Chris@0 577 $this->process[$property] = $process_of_property;
Chris@0 578 return $this;
Chris@0 579 }
Chris@0 580
Chris@0 581 /**
Chris@0 582 * {@inheritdoc}
Chris@0 583 */
Chris@0 584 public function mergeProcessOfProperty($property, array $process_of_property) {
Chris@0 585 // If we already have a process value then merge the incoming process array
Chris@0 586 // otherwise simply set it.
Chris@0 587 $current_process = $this->getProcess();
Chris@0 588 if (isset($current_process[$property])) {
Chris@0 589 $this->process = NestedArray::mergeDeepArray([$current_process, $this->getProcessNormalized([$property => $process_of_property])], TRUE);
Chris@0 590 }
Chris@0 591 else {
Chris@0 592 $this->setProcessOfProperty($property, $process_of_property);
Chris@0 593 }
Chris@0 594
Chris@0 595 return $this;
Chris@0 596 }
Chris@0 597
Chris@0 598 /**
Chris@0 599 * {@inheritdoc}
Chris@0 600 */
Chris@0 601 public function isTrackLastImported() {
Chris@0 602 return $this->trackLastImported;
Chris@0 603 }
Chris@0 604
Chris@0 605 /**
Chris@0 606 * {@inheritdoc}
Chris@0 607 */
Chris@0 608 public function setTrackLastImported($track_last_imported) {
Chris@0 609 $this->trackLastImported = (bool) $track_last_imported;
Chris@0 610 return $this;
Chris@0 611 }
Chris@0 612
Chris@0 613 /**
Chris@0 614 * {@inheritdoc}
Chris@0 615 */
Chris@0 616 public function getMigrationDependencies() {
Chris@0 617 $this->migration_dependencies = ($this->migration_dependencies ?: []) + ['required' => [], 'optional' => []];
Chris@0 618 $this->migration_dependencies['optional'] = array_unique(array_merge($this->migration_dependencies['optional'], $this->findMigrationDependencies($this->process)));
Chris@0 619 return $this->migration_dependencies;
Chris@0 620 }
Chris@0 621
Chris@0 622 /**
Chris@16 623 * Find migration dependencies from migration_lookup and sub_process plugins.
Chris@0 624 *
Chris@16 625 * @param array $process
Chris@16 626 * A process configuration array.
Chris@16 627 *
Chris@0 628 * @return array
Chris@16 629 * The migration dependencies.
Chris@0 630 */
Chris@0 631 protected function findMigrationDependencies($process) {
Chris@0 632 $return = [];
Chris@0 633 foreach ($this->getProcessNormalized($process) as $process_pipeline) {
Chris@0 634 foreach ($process_pipeline as $plugin_configuration) {
Chris@16 635 if (in_array($plugin_configuration['plugin'], ['migration', 'migration_lookup'], TRUE)) {
Chris@0 636 $return = array_merge($return, (array) $plugin_configuration['migration']);
Chris@0 637 }
Chris@16 638 if (in_array($plugin_configuration['plugin'], ['iterator', 'sub_process'], TRUE)) {
Chris@0 639 $return = array_merge($return, $this->findMigrationDependencies($plugin_configuration['process']));
Chris@0 640 }
Chris@0 641 }
Chris@0 642 }
Chris@0 643 return $return;
Chris@0 644 }
Chris@0 645
Chris@0 646 /**
Chris@0 647 * {@inheritdoc}
Chris@0 648 */
Chris@0 649 public function getPluginDefinition() {
Chris@0 650 $definition = [];
Chris@0 651 // While normal plugins do not change their definitions on the fly, this
Chris@0 652 // one does so accommodate for that.
Chris@0 653 foreach (parent::getPluginDefinition() as $key => $value) {
Chris@0 654 $definition[$key] = isset($this->$key) ? $this->$key : $value;
Chris@0 655 }
Chris@0 656 return $definition;
Chris@0 657 }
Chris@0 658
Chris@0 659 /**
Chris@0 660 * {@inheritdoc}
Chris@0 661 */
Chris@0 662 public function getDestinationConfiguration() {
Chris@0 663 return $this->destination;
Chris@0 664 }
Chris@0 665
Chris@0 666 /**
Chris@0 667 * {@inheritdoc}
Chris@0 668 */
Chris@0 669 public function getSourceConfiguration() {
Chris@0 670 return $this->source;
Chris@0 671 }
Chris@0 672
Chris@0 673 /**
Chris@0 674 * {@inheritdoc}
Chris@0 675 */
Chris@0 676 public function getTrackLastImported() {
Chris@0 677 return $this->trackLastImported;
Chris@0 678 }
Chris@0 679
Chris@0 680 /**
Chris@0 681 * {@inheritdoc}
Chris@0 682 */
Chris@0 683 public function getDestinationIds() {
Chris@0 684 return $this->destinationIds;
Chris@0 685 }
Chris@0 686
Chris@0 687 /**
Chris@0 688 * {@inheritdoc}
Chris@0 689 */
Chris@0 690 public function getMigrationTags() {
Chris@0 691 return $this->migration_tags;
Chris@0 692 }
Chris@0 693
Chris@14 694 /**
Chris@14 695 * {@inheritdoc}
Chris@14 696 */
Chris@14 697 public function isAuditable() {
Chris@14 698 return (bool) $this->audit;
Chris@14 699 }
Chris@14 700
Chris@0 701 }