annotate core/modules/migrate/src/Plugin/Migration.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 7a779792577d
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@0 158 * These migrations, if run, must be executed before this migration.
Chris@0 159 *
Chris@0 160 * These are different from the configuration dependencies. Migration
Chris@0 161 * dependencies are only used to store relationships between migrations.
Chris@0 162 *
Chris@0 163 * The migration_dependencies value is structured like this:
Chris@0 164 * @code
Chris@0 165 * array(
Chris@0 166 * 'required' => array(
Chris@0 167 * // An array of migration IDs that must be run before this migration.
Chris@0 168 * ),
Chris@0 169 * 'optional' => array(
Chris@0 170 * // An array of migration IDs that, if they exist, must be run before
Chris@0 171 * // this migration.
Chris@0 172 * ),
Chris@0 173 * );
Chris@0 174 * @endcode
Chris@0 175 *
Chris@0 176 * @var array
Chris@0 177 */
Chris@0 178 protected $migration_dependencies = [];
Chris@0 179
Chris@0 180 /**
Chris@0 181 * The migration's configuration dependencies.
Chris@0 182 *
Chris@0 183 * These store any dependencies on modules or other configuration (including
Chris@0 184 * other migrations) that must be available before the migration can be
Chris@0 185 * created.
Chris@0 186 *
Chris@0 187 * @see \Drupal\Core\Config\Entity\ConfigDependencyManager
Chris@0 188 *
Chris@0 189 * @var array
Chris@0 190 */
Chris@0 191 protected $dependencies = [];
Chris@0 192
Chris@0 193 /**
Chris@0 194 * The migration plugin manager for loading other migration plugins.
Chris@0 195 *
Chris@0 196 * @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface
Chris@0 197 */
Chris@0 198 protected $migrationPluginManager;
Chris@0 199
Chris@0 200 /**
Chris@0 201 * The source plugin manager.
Chris@0 202 *
Chris@0 203 * @var \Drupal\migrate\Plugin\MigratePluginManager
Chris@0 204 */
Chris@0 205 protected $sourcePluginManager;
Chris@0 206
Chris@0 207 /**
Chris@0 208 * Thep process plugin manager.
Chris@0 209 *
Chris@0 210 * @var \Drupal\migrate\Plugin\MigratePluginManager
Chris@0 211 */
Chris@0 212 protected $processPluginManager;
Chris@0 213
Chris@0 214 /**
Chris@0 215 * The destination plugin manager.
Chris@0 216 *
Chris@0 217 * @var \Drupal\migrate\Plugin\MigrateDestinationPluginManager
Chris@0 218 */
Chris@0 219 protected $destinationPluginManager;
Chris@0 220
Chris@0 221 /**
Chris@0 222 * The ID map plugin manager.
Chris@0 223 *
Chris@0 224 * @var \Drupal\migrate\Plugin\MigratePluginManager
Chris@0 225 */
Chris@0 226 protected $idMapPluginManager;
Chris@0 227
Chris@0 228 /**
Chris@0 229 * Labels corresponding to each defined status.
Chris@0 230 *
Chris@0 231 * @var array
Chris@0 232 */
Chris@0 233 protected $statusLabels = [
Chris@0 234 self::STATUS_IDLE => 'Idle',
Chris@0 235 self::STATUS_IMPORTING => 'Importing',
Chris@0 236 self::STATUS_ROLLING_BACK => 'Rolling back',
Chris@0 237 self::STATUS_STOPPING => 'Stopping',
Chris@0 238 self::STATUS_DISABLED => 'Disabled',
Chris@0 239 ];
Chris@0 240
Chris@0 241 /**
Chris@0 242 * Constructs a Migration.
Chris@0 243 *
Chris@0 244 * @param array $configuration
Chris@0 245 * Plugin configuration.
Chris@0 246 * @param string $plugin_id
Chris@0 247 * The plugin ID.
Chris@0 248 * @param mixed $plugin_definition
Chris@0 249 * The plugin definition.
Chris@0 250 * @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager
Chris@0 251 * The migration plugin manager.
Chris@0 252 * @param \Drupal\migrate\Plugin\MigratePluginManagerInterface $source_plugin_manager
Chris@0 253 * The source migration plugin manager.
Chris@0 254 * @param \Drupal\migrate\Plugin\MigratePluginManagerInterface $process_plugin_manager
Chris@0 255 * The process migration plugin manager.
Chris@0 256 * @param \Drupal\migrate\Plugin\MigrateDestinationPluginManager $destination_plugin_manager
Chris@0 257 * The destination migration plugin manager.
Chris@0 258 * @param \Drupal\migrate\Plugin\MigratePluginManagerInterface $idmap_plugin_manager
Chris@0 259 * The ID map migration plugin manager.
Chris@0 260 */
Chris@0 261 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 262 parent::__construct($configuration, $plugin_id, $plugin_definition);
Chris@0 263 $this->migrationPluginManager = $migration_plugin_manager;
Chris@0 264 $this->sourcePluginManager = $source_plugin_manager;
Chris@0 265 $this->processPluginManager = $process_plugin_manager;
Chris@0 266 $this->destinationPluginManager = $destination_plugin_manager;
Chris@0 267 $this->idMapPluginManager = $idmap_plugin_manager;
Chris@0 268
Chris@0 269 foreach (NestedArray::mergeDeep($plugin_definition, $configuration) as $key => $value) {
Chris@0 270 $this->$key = $value;
Chris@0 271 }
Chris@0 272 }
Chris@0 273
Chris@0 274 /**
Chris@0 275 * {@inheritdoc}
Chris@0 276 */
Chris@0 277 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
Chris@0 278 return new static(
Chris@0 279 $configuration,
Chris@0 280 $plugin_id,
Chris@0 281 $plugin_definition,
Chris@0 282 $container->get('plugin.manager.migration'),
Chris@0 283 $container->get('plugin.manager.migrate.source'),
Chris@0 284 $container->get('plugin.manager.migrate.process'),
Chris@0 285 $container->get('plugin.manager.migrate.destination'),
Chris@0 286 $container->get('plugin.manager.migrate.id_map')
Chris@0 287 );
Chris@0 288 }
Chris@0 289
Chris@0 290 /**
Chris@0 291 * {@inheritdoc}
Chris@0 292 */
Chris@0 293 public function id() {
Chris@0 294 return $this->pluginId;
Chris@0 295 }
Chris@0 296
Chris@0 297 /**
Chris@0 298 * {@inheritdoc}
Chris@0 299 */
Chris@0 300 public function label() {
Chris@0 301 return $this->label;
Chris@0 302 }
Chris@0 303
Chris@0 304 /**
Chris@0 305 * Gets any arbitrary property's value.
Chris@0 306 *
Chris@0 307 * @param string $property
Chris@0 308 * The property to retrieve.
Chris@0 309 *
Chris@0 310 * @return mixed
Chris@0 311 * The value for that property, or NULL if the property does not exist.
Chris@0 312 *
Chris@0 313 * @deprecated in Drupal 8.1.x, will be removed before Drupal 9.0.x. Use
Chris@0 314 * more specific getters instead.
Chris@0 315 *
Chris@0 316 * @see https://www.drupal.org/node/2873795
Chris@0 317 */
Chris@0 318 public function get($property) {
Chris@0 319 return isset($this->$property) ? $this->$property : NULL;
Chris@0 320 }
Chris@0 321
Chris@0 322 /**
Chris@0 323 * Retrieves the ID map plugin.
Chris@0 324 *
Chris@0 325 * @return \Drupal\migrate\Plugin\MigrateIdMapInterface
Chris@0 326 * The ID map plugin.
Chris@0 327 */
Chris@0 328 public function getIdMapPlugin() {
Chris@0 329 return $this->idMapPlugin;
Chris@0 330 }
Chris@0 331
Chris@0 332 /**
Chris@0 333 * {@inheritdoc}
Chris@0 334 */
Chris@0 335 public function getSourcePlugin() {
Chris@0 336 if (!isset($this->sourcePlugin)) {
Chris@0 337 $this->sourcePlugin = $this->sourcePluginManager->createInstance($this->source['plugin'], $this->source, $this);
Chris@0 338 }
Chris@0 339 return $this->sourcePlugin;
Chris@0 340 }
Chris@0 341
Chris@0 342 /**
Chris@0 343 * {@inheritdoc}
Chris@0 344 */
Chris@0 345 public function getProcessPlugins(array $process = NULL) {
Chris@0 346 if (!isset($process)) {
Chris@0 347 $process = $this->getProcess();
Chris@0 348 }
Chris@0 349 $index = serialize($process);
Chris@0 350 if (!isset($this->processPlugins[$index])) {
Chris@0 351 $this->processPlugins[$index] = [];
Chris@0 352 foreach ($this->getProcessNormalized($process) as $property => $configurations) {
Chris@0 353 $this->processPlugins[$index][$property] = [];
Chris@0 354 foreach ($configurations as $configuration) {
Chris@0 355 if (isset($configuration['source'])) {
Chris@0 356 $this->processPlugins[$index][$property][] = $this->processPluginManager->createInstance('get', $configuration, $this);
Chris@0 357 }
Chris@0 358 // Get is already handled.
Chris@0 359 if ($configuration['plugin'] != 'get') {
Chris@0 360 $this->processPlugins[$index][$property][] = $this->processPluginManager->createInstance($configuration['plugin'], $configuration, $this);
Chris@0 361 }
Chris@0 362 if (!$this->processPlugins[$index][$property]) {
Chris@0 363 throw new MigrateException("Invalid process configuration for $property");
Chris@0 364 }
Chris@0 365 }
Chris@0 366 }
Chris@0 367 }
Chris@0 368 return $this->processPlugins[$index];
Chris@0 369 }
Chris@0 370
Chris@0 371 /**
Chris@0 372 * Resolve shorthands into a list of plugin configurations.
Chris@0 373 *
Chris@0 374 * @param array $process
Chris@0 375 * A process configuration array.
Chris@0 376 *
Chris@0 377 * @return array
Chris@0 378 * The normalized process configuration.
Chris@0 379 */
Chris@0 380 protected function getProcessNormalized(array $process) {
Chris@0 381 $normalized_configurations = [];
Chris@0 382 foreach ($process as $destination => $configuration) {
Chris@0 383 if (is_string($configuration)) {
Chris@0 384 $configuration = [
Chris@0 385 'plugin' => 'get',
Chris@0 386 'source' => $configuration,
Chris@0 387 ];
Chris@0 388 }
Chris@0 389 if (isset($configuration['plugin'])) {
Chris@0 390 $configuration = [$configuration];
Chris@0 391 }
Chris@0 392 $normalized_configurations[$destination] = $configuration;
Chris@0 393 }
Chris@0 394 return $normalized_configurations;
Chris@0 395 }
Chris@0 396
Chris@0 397 /**
Chris@0 398 * {@inheritdoc}
Chris@0 399 */
Chris@0 400 public function getDestinationPlugin($stub_being_requested = FALSE) {
Chris@0 401 if ($stub_being_requested && !empty($this->destination['no_stub'])) {
Chris@0 402 throw new MigrateSkipRowException();
Chris@0 403 }
Chris@0 404 if (!isset($this->destinationPlugin)) {
Chris@0 405 $this->destinationPlugin = $this->destinationPluginManager->createInstance($this->destination['plugin'], $this->destination, $this);
Chris@0 406 }
Chris@0 407 return $this->destinationPlugin;
Chris@0 408 }
Chris@0 409
Chris@0 410 /**
Chris@0 411 * {@inheritdoc}
Chris@0 412 */
Chris@0 413 public function getIdMap() {
Chris@0 414 if (!isset($this->idMapPlugin)) {
Chris@0 415 $configuration = $this->idMap;
Chris@0 416 $plugin = isset($configuration['plugin']) ? $configuration['plugin'] : 'sql';
Chris@0 417 $this->idMapPlugin = $this->idMapPluginManager->createInstance($plugin, $configuration, $this);
Chris@0 418 }
Chris@0 419 return $this->idMapPlugin;
Chris@0 420 }
Chris@0 421
Chris@0 422 /**
Chris@0 423 * {@inheritdoc}
Chris@0 424 */
Chris@0 425 public function checkRequirements() {
Chris@0 426 // Check whether the current migration source and destination plugin
Chris@0 427 // requirements are met or not.
Chris@0 428 if ($this->getSourcePlugin() instanceof RequirementsInterface) {
Chris@0 429 $this->getSourcePlugin()->checkRequirements();
Chris@0 430 }
Chris@0 431 if ($this->getDestinationPlugin() instanceof RequirementsInterface) {
Chris@0 432 $this->getDestinationPlugin()->checkRequirements();
Chris@0 433 }
Chris@0 434
Chris@0 435 if (empty($this->requirements)) {
Chris@0 436 // There are no requirements to check.
Chris@0 437 return;
Chris@0 438 }
Chris@0 439 /** @var \Drupal\migrate\Plugin\MigrationInterface[] $required_migrations */
Chris@0 440 $required_migrations = $this->getMigrationPluginManager()->createInstances($this->requirements);
Chris@0 441
Chris@0 442 $missing_migrations = array_diff($this->requirements, array_keys($required_migrations));
Chris@0 443 // Check if the dependencies are in good shape.
Chris@0 444 foreach ($required_migrations as $migration_id => $required_migration) {
Chris@0 445 if (!$required_migration->allRowsProcessed()) {
Chris@0 446 $missing_migrations[] = $migration_id;
Chris@0 447 }
Chris@0 448 }
Chris@0 449 if ($missing_migrations) {
Chris@0 450 throw new RequirementsException('Missing migrations ' . implode(', ', $missing_migrations) . '.', ['requirements' => $missing_migrations]);
Chris@0 451 }
Chris@0 452 }
Chris@0 453
Chris@0 454 /**
Chris@0 455 * Gets the migration plugin manager.
Chris@0 456 *
Chris@0 457 * @return \Drupal\migrate\Plugin\MigratePluginManager
Chris@0 458 * The plugin manager.
Chris@0 459 */
Chris@0 460 protected function getMigrationPluginManager() {
Chris@0 461 return $this->migrationPluginManager;
Chris@0 462 }
Chris@0 463
Chris@0 464 /**
Chris@0 465 * {@inheritdoc}
Chris@0 466 */
Chris@0 467 public function setStatus($status) {
Chris@0 468 \Drupal::keyValue('migrate_status')->set($this->id(), $status);
Chris@0 469 }
Chris@0 470
Chris@0 471 /**
Chris@0 472 * {@inheritdoc}
Chris@0 473 */
Chris@0 474 public function getStatus() {
Chris@0 475 return \Drupal::keyValue('migrate_status')->get($this->id(), static::STATUS_IDLE);
Chris@0 476 }
Chris@0 477
Chris@0 478 /**
Chris@0 479 * {@inheritdoc}
Chris@0 480 */
Chris@0 481 public function getStatusLabel() {
Chris@0 482 $status = $this->getStatus();
Chris@0 483 if (isset($this->statusLabels[$status])) {
Chris@0 484 return $this->statusLabels[$status];
Chris@0 485 }
Chris@0 486 else {
Chris@0 487 return '';
Chris@0 488 }
Chris@0 489 }
Chris@0 490
Chris@0 491 /**
Chris@0 492 * {@inheritdoc}
Chris@0 493 */
Chris@0 494 public function getInterruptionResult() {
Chris@0 495 return \Drupal::keyValue('migrate_interruption_result')->get($this->id(), static::RESULT_INCOMPLETE);
Chris@0 496 }
Chris@0 497
Chris@0 498 /**
Chris@0 499 * {@inheritdoc}
Chris@0 500 */
Chris@0 501 public function clearInterruptionResult() {
Chris@0 502 \Drupal::keyValue('migrate_interruption_result')->delete($this->id());
Chris@0 503 }
Chris@0 504
Chris@0 505 /**
Chris@0 506 * {@inheritdoc}
Chris@0 507 */
Chris@0 508 public function interruptMigration($result) {
Chris@0 509 $this->setStatus(MigrationInterface::STATUS_STOPPING);
Chris@0 510 \Drupal::keyValue('migrate_interruption_result')->set($this->id(), $result);
Chris@0 511 }
Chris@0 512
Chris@0 513 /**
Chris@0 514 * {@inheritdoc}
Chris@0 515 */
Chris@0 516 public function allRowsProcessed() {
Chris@0 517 $source_count = $this->getSourcePlugin()->count();
Chris@0 518 // If the source is uncountable, we have no way of knowing if it's
Chris@0 519 // complete, so stipulate that it is.
Chris@0 520 if ($source_count < 0) {
Chris@0 521 return TRUE;
Chris@0 522 }
Chris@0 523 $processed_count = $this->getIdMap()->processedCount();
Chris@0 524 // We don't use == because in some circumstances (like unresolved stubs
Chris@0 525 // being created), the processed count may be higher than the available
Chris@0 526 // source rows.
Chris@0 527 return $source_count <= $processed_count;
Chris@0 528 }
Chris@0 529
Chris@0 530 /**
Chris@0 531 * {@inheritdoc}
Chris@0 532 */
Chris@0 533 public function set($property_name, $value) {
Chris@0 534 if ($property_name == 'source') {
Chris@0 535 // Invalidate the source plugin.
Chris@0 536 unset($this->sourcePlugin);
Chris@0 537 }
Chris@0 538 elseif ($property_name === 'destination') {
Chris@0 539 // Invalidate the destination plugin.
Chris@0 540 unset($this->destinationPlugin);
Chris@0 541 }
Chris@0 542 $this->{$property_name} = $value;
Chris@0 543 return $this;
Chris@0 544 }
Chris@0 545
Chris@0 546
Chris@0 547 /**
Chris@0 548 * {@inheritdoc}
Chris@0 549 */
Chris@0 550 public function getProcess() {
Chris@0 551 return $this->getProcessNormalized($this->process);
Chris@0 552 }
Chris@0 553
Chris@0 554 /**
Chris@0 555 * {@inheritdoc}
Chris@0 556 */
Chris@0 557 public function setProcess(array $process) {
Chris@0 558 $this->process = $process;
Chris@0 559 return $this;
Chris@0 560 }
Chris@0 561
Chris@0 562 /**
Chris@0 563 * {@inheritdoc}
Chris@0 564 */
Chris@0 565 public function setProcessOfProperty($property, $process_of_property) {
Chris@0 566 $this->process[$property] = $process_of_property;
Chris@0 567 return $this;
Chris@0 568 }
Chris@0 569
Chris@0 570 /**
Chris@0 571 * {@inheritdoc}
Chris@0 572 */
Chris@0 573 public function mergeProcessOfProperty($property, array $process_of_property) {
Chris@0 574 // If we already have a process value then merge the incoming process array
Chris@0 575 // otherwise simply set it.
Chris@0 576 $current_process = $this->getProcess();
Chris@0 577 if (isset($current_process[$property])) {
Chris@0 578 $this->process = NestedArray::mergeDeepArray([$current_process, $this->getProcessNormalized([$property => $process_of_property])], TRUE);
Chris@0 579 }
Chris@0 580 else {
Chris@0 581 $this->setProcessOfProperty($property, $process_of_property);
Chris@0 582 }
Chris@0 583
Chris@0 584 return $this;
Chris@0 585 }
Chris@0 586
Chris@0 587 /**
Chris@0 588 * {@inheritdoc}
Chris@0 589 */
Chris@0 590 public function isTrackLastImported() {
Chris@0 591 return $this->trackLastImported;
Chris@0 592 }
Chris@0 593
Chris@0 594 /**
Chris@0 595 * {@inheritdoc}
Chris@0 596 */
Chris@0 597 public function setTrackLastImported($track_last_imported) {
Chris@0 598 $this->trackLastImported = (bool) $track_last_imported;
Chris@0 599 return $this;
Chris@0 600 }
Chris@0 601
Chris@0 602 /**
Chris@0 603 * {@inheritdoc}
Chris@0 604 */
Chris@0 605 public function getMigrationDependencies() {
Chris@0 606 $this->migration_dependencies = ($this->migration_dependencies ?: []) + ['required' => [], 'optional' => []];
Chris@0 607 $this->migration_dependencies['optional'] = array_unique(array_merge($this->migration_dependencies['optional'], $this->findMigrationDependencies($this->process)));
Chris@0 608 return $this->migration_dependencies;
Chris@0 609 }
Chris@0 610
Chris@0 611 /**
Chris@0 612 * Find migration dependencies from the migration and the iterator plugins.
Chris@0 613 *
Chris@0 614 * @param $process
Chris@0 615 * @return array
Chris@0 616 */
Chris@0 617 protected function findMigrationDependencies($process) {
Chris@0 618 $return = [];
Chris@0 619 foreach ($this->getProcessNormalized($process) as $process_pipeline) {
Chris@0 620 foreach ($process_pipeline as $plugin_configuration) {
Chris@0 621 if ($plugin_configuration['plugin'] == 'migration') {
Chris@0 622 $return = array_merge($return, (array) $plugin_configuration['migration']);
Chris@0 623 }
Chris@0 624 if ($plugin_configuration['plugin'] == 'iterator') {
Chris@0 625 $return = array_merge($return, $this->findMigrationDependencies($plugin_configuration['process']));
Chris@0 626 }
Chris@0 627 }
Chris@0 628 }
Chris@0 629 return $return;
Chris@0 630 }
Chris@0 631
Chris@0 632 /**
Chris@0 633 * {@inheritdoc}
Chris@0 634 */
Chris@0 635 public function getPluginDefinition() {
Chris@0 636 $definition = [];
Chris@0 637 // While normal plugins do not change their definitions on the fly, this
Chris@0 638 // one does so accommodate for that.
Chris@0 639 foreach (parent::getPluginDefinition() as $key => $value) {
Chris@0 640 $definition[$key] = isset($this->$key) ? $this->$key : $value;
Chris@0 641 }
Chris@0 642 return $definition;
Chris@0 643 }
Chris@0 644
Chris@0 645 /**
Chris@0 646 * {@inheritdoc}
Chris@0 647 */
Chris@0 648 public function getDestinationConfiguration() {
Chris@0 649 return $this->destination;
Chris@0 650 }
Chris@0 651
Chris@0 652 /**
Chris@0 653 * {@inheritdoc}
Chris@0 654 */
Chris@0 655 public function getSourceConfiguration() {
Chris@0 656 return $this->source;
Chris@0 657 }
Chris@0 658
Chris@0 659 /**
Chris@0 660 * {@inheritdoc}
Chris@0 661 */
Chris@0 662 public function getTrackLastImported() {
Chris@0 663 return $this->trackLastImported;
Chris@0 664 }
Chris@0 665
Chris@0 666 /**
Chris@0 667 * {@inheritdoc}
Chris@0 668 */
Chris@0 669 public function getDestinationIds() {
Chris@0 670 return $this->destinationIds;
Chris@0 671 }
Chris@0 672
Chris@0 673 /**
Chris@0 674 * {@inheritdoc}
Chris@0 675 */
Chris@0 676 public function getMigrationTags() {
Chris@0 677 return $this->migration_tags;
Chris@0 678 }
Chris@0 679
Chris@0 680 }