diff --git a/core/modules/migrate/src/Annotation/MigrateDestination.php b/core/modules/migrate/src/Annotation/MigrateDestination.php index 1fd51d7..69b2ce6 100644 --- a/core/modules/migrate/src/Annotation/MigrateDestination.php +++ b/core/modules/migrate/src/Annotation/MigrateDestination.php @@ -7,10 +7,10 @@ /** * Defines a migration destination plugin annotation object. * - * Plugin Namespace: Plugin\migrate\destination + * Plugin Namespace: Plugin\migrate\destination. * * For a working example, see - * \Drupal\migrate\Plugin\migrate\destination\UrlAlias + * \Drupal\migrate\Plugin\migrate\destination\UrlAlias. * * @see \Drupal\migrate\Plugin\MigrateDestinationInterface * @see \Drupal\migrate\Plugin\destination\DestinationBase diff --git a/core/modules/migrate/src/Annotation/MigrateProcessPlugin.php b/core/modules/migrate/src/Annotation/MigrateProcessPlugin.php index f08da3b..d731ebb 100644 --- a/core/modules/migrate/src/Annotation/MigrateProcessPlugin.php +++ b/core/modules/migrate/src/Annotation/MigrateProcessPlugin.php @@ -7,7 +7,7 @@ /** * Defines a migration process plugin annotation object. * - * Plugin Namespace: Plugin\migrate\process + * Plugin Namespace: Plugin\migrate\process. * * For a working example, see * \Drupal\migrate\Plugin\migrate\process\DefaultValue diff --git a/core/modules/migrate/src/Annotation/MigrateSource.php b/core/modules/migrate/src/Annotation/MigrateSource.php index a73f7a5..8401810 100644 --- a/core/modules/migrate/src/Annotation/MigrateSource.php +++ b/core/modules/migrate/src/Annotation/MigrateSource.php @@ -7,7 +7,7 @@ /** * Defines a migration source plugin annotation object. * - * Plugin Namespace: Plugin\migrate\source + * Plugin Namespace: Plugin\migrate\source. * * For a working example, check * \Drupal\migrate\Plugin\migrate\source\EmptySource diff --git a/core/modules/migrate/src/Event/MigrateEvents.php b/core/modules/migrate/src/Event/MigrateEvents.php index edc2bec..6f2c484 100644 --- a/core/modules/migrate/src/Event/MigrateEvents.php +++ b/core/modules/migrate/src/Event/MigrateEvents.php @@ -36,7 +36,8 @@ * * This event allows modules to perform an action whenever a row is deleted * from a migration's map table (implying it has been rolled back). The event - * listener method receives a \Drupal\migrate\Event\MigrateMapDeleteEvent instance. + * listener method receives a \Drupal\migrate\Event\MigrateMapDeleteEvent + * instance. * * @Event * diff --git a/core/modules/migrate/src/Event/MigrateIdMapMessageEvent.php b/core/modules/migrate/src/Event/MigrateIdMapMessageEvent.php index 2bf774f..26f886d 100644 --- a/core/modules/migrate/src/Event/MigrateIdMapMessageEvent.php +++ b/core/modules/migrate/src/Event/MigrateIdMapMessageEvent.php @@ -46,7 +46,7 @@ class MigrateIdMapMessageEvent extends Event { * @param array $source_id_values * Values represent the source ID. * @param string $message - * The message + * The message to be logged. * @param int $level * Severity level (one of the MigrationInterface::MESSAGE_* constants). */ @@ -88,8 +88,9 @@ public function getMessage() { } /** - * Gets the severity level of the message (one of the - * MigrationInterface::MESSAGE_* constants). + * Gets the severity level of the message. + * + * This will be one of the MigrationInterface::MESSAGE_* constants. * * @return int * The message level. diff --git a/core/modules/migrate/src/Event/MigrateMapDeleteEvent.php b/core/modules/migrate/src/Event/MigrateMapDeleteEvent.php index 331331c..2b04eb0 100644 --- a/core/modules/migrate/src/Event/MigrateMapDeleteEvent.php +++ b/core/modules/migrate/src/Event/MigrateMapDeleteEvent.php @@ -30,7 +30,8 @@ class MigrateMapDeleteEvent extends Event { * @param \Drupal\migrate\Plugin\MigrateIdMapInterface $map * Map plugin. * @param array $source_id - * Array of source ID fields representing the object being deleted from the map. + * Array of source ID fields representing the object being deleted from the + * map. */ public function __construct(MigrateIdMapInterface $map, array $source_id) { $this->map = $map; diff --git a/core/modules/migrate/src/Exception/RequirementsException.php b/core/modules/migrate/src/Exception/RequirementsException.php index 4c17dd6..bb5b3c6 100644 --- a/core/modules/migrate/src/Exception/RequirementsException.php +++ b/core/modules/migrate/src/Exception/RequirementsException.php @@ -5,7 +5,7 @@ use Exception; /** - * Defines an + * Defines a requirements exception. * * @see \Drupal\migrate\Plugin\RequirementsInterface */ @@ -22,13 +22,14 @@ class RequirementsException extends \RuntimeException { * Constructs a new RequirementsException instance. * * @param string $message - * (optional) The Exception message to throw. + * (optional) The Exception message to throw. Defaults to an empty string. * @param array $requirements - * (optional) The missing requirements. + * (optional) The missing requirements. Defaults to an empty array. * @param int $code - * (optional) The Exception code. + * (optional) The Exception code. Defaults to zero. * @param \Exception $previous * (optional) The previous exception used for the exception chaining. + * Defaults to NULL. */ public function __construct($message = "", array $requirements = [], $code = 0, Exception $previous = NULL) { parent::__construct($message, $code, $previous); @@ -37,7 +38,7 @@ public function __construct($message = "", array $requirements = [], $code = 0, } /** - * Get an array of requirements. + * Gets an array of requirements. * * @return array * The requirements. @@ -47,7 +48,7 @@ public function getRequirements() { } /** - * Get the requirements as a string. + * Gets the requirements as a string. * * @return string * A formatted requirements string. diff --git a/core/modules/migrate/src/MigrateBuildDependencyInterface.php b/core/modules/migrate/src/MigrateBuildDependencyInterface.php index bb02c88..6545c2c 100644 --- a/core/modules/migrate/src/MigrateBuildDependencyInterface.php +++ b/core/modules/migrate/src/MigrateBuildDependencyInterface.php @@ -1,12 +1,19 @@ level = $level; @@ -53,7 +56,9 @@ public function __construct($message = NULL, $code = 0, \Exception $previous = N * Gets the level. * * @return int - * An integer status code. @see Migration::MESSAGE_* + * An integer status code. + * + * @see Migration::MESSAGE_* */ public function getLevel() { return $this->level; @@ -63,7 +68,9 @@ public function getLevel() { * Gets the status of the current item. * * @return int - * An integer status code. @see MigrateMap::STATUS_* + * An integer status code. + * + * @see MigrateMap::STATUS_* */ public function getStatus() { return $this->status; diff --git a/core/modules/migrate/src/MigrateExecutable.php b/core/modules/migrate/src/MigrateExecutable.php index c0b3537..fc2e4e4 100644 --- a/core/modules/migrate/src/MigrateExecutable.php +++ b/core/modules/migrate/src/MigrateExecutable.php @@ -101,8 +101,8 @@ class MigrateExecutable implements MigrateExecutableInterface { * The migration to run. * @param \Drupal\migrate\MigrateMessageInterface $message * The message to record. - * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher - * The event dispatcher. + * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface|null $event_dispatcher + * The event dispatcher. Defaults to NULL. * * @throws \Drupal\migrate\MigrateException */ @@ -111,7 +111,7 @@ public function __construct(MigrationInterface $migration, MigrateMessageInterfa $this->message = $message; $this->migration->getIdMap()->setMessage($message); $this->eventDispatcher = $event_dispatcher; - // Record the memory limit in bytes + // Record the memory limit in bytes. $limit = trim(ini_get('memory_limit')); if ($limit == '-1') { $this->memoryLimit = PHP_INT_MAX; @@ -127,6 +127,7 @@ public function __construct(MigrationInterface $migration, MigrateMessageInterfa case 'k': $limit *= 1024; break; + default: $limit = PHP_INT_MAX; $this->message->display($this->t('Invalid PHP memory_limit @limit, setting to unlimited.', @@ -156,6 +157,7 @@ protected function getSource() { * Gets the event dispatcher. * * @return \Symfony\Component\EventDispatcher\EventDispatcherInterface + * The event dispatcher service. */ protected function getEventDispatcher() { if (!$this->eventDispatcher) { @@ -306,8 +308,8 @@ public function rollback() { // Announce that rollback is about to happen. $this->getEventDispatcher()->dispatch(MigrateEvents::PRE_ROLLBACK, new MigrateRollbackEvent($this->migration)); - // Optimistically assume things are going to work out; if not, $return will be - // updated to some other status. + // Optimistically assume things are going to work out; if not, $return will + // be updated to some other status. $return = MigrationInterface::RESULT_COMPLETED; $this->migration->setStatus(MigrationInterface::STATUS_ROLLING_BACK); @@ -433,7 +435,8 @@ public function saveMessage($message, $level = MigrationInterface::MESSAGE_ERROR * Object representing the exception. * @param bool $save * (optional) Whether to save the message in the migration's mapping table. - * Set to FALSE in contexts where this doesn't make sense. + * Set to FALSE in contexts where this does not make sense. Defaults to + * TRUE. */ protected function handleException(\Exception $exception, $save = TRUE) { $result = Error::decodeException($exception); @@ -455,7 +458,7 @@ protected function checkStatus() { } /** - * Tests whether we've exceeded the desired memory threshold. + * Tests whether we have exceeded the desired memory threshold. * * If so, output a message. * @@ -477,8 +480,8 @@ protected function memoryExceeded() { 'warning'); $usage = $this->attemptMemoryReclaim(); $pct_memory = $usage / $this->memoryLimit; - // Use a lower threshold - we don't want to be in a situation where we keep - // coming back here and trimming a tiny amount + // Use a lower threshold - we do not want to be in a situation where we + // keep coming back here and trimming a tiny amount. if ($pct_memory > (0.90 * $threshold)) { $this->message->display( $this->t('Memory usage is now @usage (@pct% of limit @limit), not enough reclaimed, starting new batch', @@ -530,7 +533,8 @@ protected function attemptMemoryReclaim() { $manager->getStorage($id)->resetCache(); } - // @TODO: explore resetting the container. + // @todo Explore resetting the container. This should be addressed in issue + // https://www.drupal.org/node/2545632. return memory_get_usage(); } diff --git a/core/modules/migrate/src/MigrateExecutableInterface.php b/core/modules/migrate/src/MigrateExecutableInterface.php index 33d5914..57bd553 100644 --- a/core/modules/migrate/src/MigrateExecutableInterface.php +++ b/core/modules/migrate/src/MigrateExecutableInterface.php @@ -4,6 +4,9 @@ use Drupal\migrate\Plugin\MigrationInterface; +/** + * Defines an interface for a migration executable class. + */ interface MigrateExecutableInterface { /** @@ -23,14 +26,14 @@ public function rollback(); * The $row to be processed. * @param array $process * (optional) A process pipeline configuration. If not set, the top level - * process configuration in the migration entity is used. + * process configuration in the migration entity is used. Defaults to NULL. * @param mixed $value * (optional) Initial value of the pipeline for the first destination. * Usually setting this is not necessary as $process typically starts with * a 'get'. This is useful only when the $process contains a single * destination and needs to access a value outside of the source. See * \Drupal\migrate\Plugin\migrate\process\Iterator::transformKey for an - * example. + * example. Defaults to NULL. * * @throws \Drupal\migrate\MigrateException */ @@ -42,7 +45,8 @@ public function processRow(Row $row, array $process = NULL, $value = NULL); * @param string $message * The message to record. * @param int $level - * (optional) Message severity (defaults to MESSAGE_ERROR). + * (optional) Message severity. Defaults to + * MigrationInterface::MESSAGE_ERROR. */ public function saveMessage($message, $level = MigrationInterface::MESSAGE_ERROR); diff --git a/core/modules/migrate/src/MigrateMessageInterface.php b/core/modules/migrate/src/MigrateMessageInterface.php index 628a684..4069547 100644 --- a/core/modules/migrate/src/MigrateMessageInterface.php +++ b/core/modules/migrate/src/MigrateMessageInterface.php @@ -1,8 +1,15 @@ moduleHandler = $module_handler; + $this->directory = $directory; + } + + /** + * {@inheritdoc} + */ + public function findTemplatesByTag($tag) { + $templates = $this->getAllTemplates(); + $matched_templates = []; + foreach ($templates as $template_name => $template) { + if (!empty($template['migration_tags'])) { + if (in_array($tag, $template['migration_tags'])) { + $matched_templates[$template_name] = $template; + } + } + } + return $matched_templates; + } + + /** + * {@inheritdoc} + */ + public function getTemplateByName($name) { + $templates = $this->getAllTemplates(); + return isset($templates[$name]) ? $templates[$name] : NULL; + } + + /** + * {@inheritdoc} + */ + public function getAllTemplates() { + $templates = []; + foreach ($this->moduleHandler->getModuleDirectories() as $directory) { + $full_directory = $directory . '/' . $this->directory; + if (file_exists($full_directory)) { + $files = scandir($full_directory); + foreach ($files as $file) { + if ($file[0] !== '.' && fnmatch('*.yml', $file)) { + $templates[basename($file, '.yml')] = Yaml::decode(file_get_contents("$full_directory/$file")); + } + } + } + } + + return $templates; + } + +} diff --git a/core/modules/migrate/src/MigrateTemplateStorageInterface.php b/core/modules/migrate/src/MigrateTemplateStorageInterface.php new file mode 100644 index 0000000..4e8f1b8 --- /dev/null +++ b/core/modules/migrate/src/MigrateTemplateStorageInterface.php @@ -0,0 +1,45 @@ +getProcess(); if (isset($current_process[$property])) { $this->process = NestedArray::mergeDeepArray([$current_process, $this->getProcessNormalized([$property => $process_of_property])], TRUE); diff --git a/core/modules/migrate/src/Plugin/MigrationInterface.php b/core/modules/migrate/src/Plugin/MigrationInterface.php index 7572760..f6a3aaf 100644 --- a/core/modules/migrate/src/Plugin/MigrationInterface.php +++ b/core/modules/migrate/src/Plugin/MigrationInterface.php @@ -124,8 +124,8 @@ public function getSourcePlugin(); /** * Returns the process plugins. * - * @param array $process - * A process configuration array. + * @param array|null $process + * (optional) A process configuration array. Defaults to NULL. * * @return \Drupal\migrate\Plugin\MigrateProcessInterface[][] * An associative array. The keys are the destination property names. Values @@ -137,7 +137,8 @@ public function getProcessPlugins(array $process = NULL); * Returns the initialized destination plugin. * * @param bool $stub_being_requested - * TRUE to indicate that this destination will be asked to construct a stub. + * (optional) TRUE to indicate that this destination will be asked to + * construct a stub. Defaults to FALSE. * * @return \Drupal\migrate\Plugin\MigrateDestinationInterface * The destination plugin. @@ -153,10 +154,10 @@ public function getDestinationPlugin($stub_being_requested = FALSE); public function getIdMap(); /** - * The current value of the high water mark. + * Returns the current value of the high water mark. * - * The high water mark defines a timestamp stating the time the import was last - * run. If the mark is set, only content with a higher timestamp will be + * The high water mark defines a timestamp stating the time the import was + * last run. If the mark is set, only content with a higher timestamp will be * imported. * * @return int @@ -165,7 +166,7 @@ public function getIdMap(); public function getHighWater(); /** - * Save the new high water mark. + * Saves the new high water mark. * * @param int $high_water * The high water timestamp. @@ -173,7 +174,7 @@ public function getHighWater(); public function saveHighWater($high_water); /** - * Check if all source rows from this migration have been processed. + * Checks if all source rows from this migration have been processed. * * @return bool * TRUE if this migration is complete otherwise FALSE. @@ -181,15 +182,15 @@ public function saveHighWater($high_water); public function allRowsProcessed(); /** - * Set the current migration status. + * Sets the current migration status. * - * @param int $result + * @param int $status * One of the STATUS_* constants. */ public function setStatus($status); /** - * Get the current migration status. + * Gets the current migration status. * * @return int * The current migration status. Defaults to STATUS_IDLE. @@ -197,7 +198,7 @@ public function setStatus($status); public function getStatus(); /** - * Retrieve a label for the current status. + * Retrieves a label for the current status. * * @return string * User-friendly string corresponding to a STATUS_ constant. @@ -205,7 +206,7 @@ public function getStatus(); public function getStatusLabel(); /** - * Get the result to return upon interruption. + * Gets the result to return upon interruption. * * @return int * The current interruption result. Defaults to RESULT_INCOMPLETE. @@ -218,8 +219,9 @@ public function getInterruptionResult(); public function clearInterruptionResult(); /** - * Signal that the migration should be interrupted with the specified result - * code. + * Signals that the migration should be interrupted. + * + * The migration will be interrupted with the specified result code. * * @param int $result * One of the MigrationInterface::RESULT_* constants. @@ -227,8 +229,7 @@ public function clearInterruptionResult(); public function interruptMigration($result); /** - * Get the normalized process pipeline configuration describing the process - * plugins. + * Gets process pipeline configuration describing the process plugins. * * The process configuration is always normalized. All shorthand processing * will be expanded into their full representations. @@ -251,7 +252,7 @@ public function getProcess(); public function setProcess(array $process); /** - * Set the process pipeline configuration for an individual destination field. + * Sets process pipeline configuration for an individual destination field. * * This method allows you to set the process pipeline configuration for a * single property within the full process pipeline configuration. @@ -267,7 +268,7 @@ public function setProcess(array $process); public function setProcessOfProperty($property, $process_of_property); /** - * Merge the process pipeline configuration for a single property. + * Merges the process pipeline configuration for a single property. * * @param string $property * The property of which to merge the passed in process pipeline @@ -277,14 +278,13 @@ public function setProcessOfProperty($property, $process_of_property); * pipeline configuration. * * @return $this - * The migration entity. * * @see Drupal\migrate_drupal\Plugin\migrate\load\LoadEntity::processLinkField() */ public function mergeProcessOfProperty($property, array $process_of_property); /** - * Get the current system of record of the migration. + * Gets the current system of record of the migration. * * @return string * The current system of record of the migration. @@ -292,7 +292,7 @@ public function mergeProcessOfProperty($property, array $process_of_property); public function getSystemOfRecord(); /** - * Set the system of record for the migration. + * Sets the system of record for the migration. * * @param string $system_of_record * The system of record of the migration. @@ -310,7 +310,7 @@ public function setSystemOfRecord($system_of_record); public function isTrackLastImported(); /** - * Set if the migration should track time of last import. + * Sets if the migration should track time of last import. * * @param bool $track_last_imported * Boolean value to indicate if the migration should track last import time. @@ -320,7 +320,7 @@ public function isTrackLastImported(); public function setTrackLastImported($track_last_imported); /** - * Get the dependencies for this migration. + * Gets the dependencies for this migration. * * @return array * The dependencies for this migrations. diff --git a/core/modules/migrate/src/Row.php b/core/modules/migrate/src/Row.php index 94cb8b2..758b3fe 100644 --- a/core/modules/migrate/src/Row.php +++ b/core/modules/migrate/src/Row.php @@ -50,7 +50,7 @@ class Row { /** * Whether the source has been frozen already. * - * Once frozen the source can not be changed any more. + * Once frozen, the source can not be changed any more. * * @var bool */ @@ -60,8 +60,8 @@ class Row { * The raw destination properties. * * Unlike $destination which is set by using - * \Drupal\Component\Utility\NestedArray::setValue() this array contains - * the destination as setDestinationProperty was called. + * \Drupal\Component\Utility\NestedArray::setValue(), this array contains the + * destination as setDestinationProperty was called. * * @var array * The raw destination. @@ -86,7 +86,7 @@ class Row { * An array containing the IDs of the source using the keys as the field * names. * @param bool $is_stub - * TRUE if the row being created is a stub. + * (optional) TRUE if the row being created is a stub. Defaults to FALSE. * * @throws \InvalidArgumentException * Thrown when a source ID property does not exist. @@ -186,6 +186,7 @@ public function freezeSource() { * Clones the row with an empty set of destination values. * * @return static + * The clone of the row with an empty set of destination values. */ public function cloneWithoutDestination() { return (new static($this->getSource(), $this->sourceIds, $this->isStub()))->freezeSource(); @@ -241,7 +242,7 @@ public function getDestination() { /** * Returns the raw destination. Rarely necessary. * - * For example calling setDestination('foo/bar', 'baz') results in + * For example, calling setDestination('foo/bar', 'baz') results in: * @code * $this->destination['foo']['bar'] = 'baz'; * $this->rawDestination['foo/bar'] = 'baz'; @@ -317,7 +318,7 @@ public function needsUpdate() { } /** - * Returns the hash for the source values.. + * Returns the hash for the source values. * * @return mixed * The hash of the source values.