X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Fmigrate%2Fsrc%2FPlugin%2Fmigrate%2Fsource%2FSourcePluginBase.php;h=8267bac783541046ee7b7aa63cf3a32f1aee34e8;hb=1c1cb0980bfa6caf0c24cce671b6bb541dc87583;hp=e35585034e585e453d788709558a28f251f364b9;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php b/web/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php index e35585034..8267bac78 100644 --- a/web/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php +++ b/web/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php @@ -13,7 +13,49 @@ use Drupal\migrate\Plugin\MigrateSourceInterface; use Drupal\migrate\Row; /** - * The base class for all source plugins. + * The base class for source plugins. + * + * Available configuration keys: + * - cache_counts: (optional) If set, cache the source count. + * - skip_count: (optional) If set, do not attempt to count the source. + * - track_changes: (optional) If set, track changes to incoming data. + * - high_water_property: (optional) It is an array of name & alias values + * (optional table alias). This high_water_property is typically a timestamp + * or serial id showing what was the last imported record. Only content with a + * higher value will be imported. + * + * The high_water_property and track_changes are mutually exclusive. + * + * Example: + * + * @code + * source: + * plugin: some_source_plugin_name + * cache_counts: true + * track_changes: true + * @endcode + * + * This example uses the plugin "some_source_plugin_name" and caches the count + * of available source records to save calculating it every time count() is + * called. Changes to incoming data are watched (because track_changes is true), + * which can affect the result of prepareRow(). + * + * Example: + * + * @code + * source: + * plugin: some_source_plugin_name + * skip_count: true + * high_water_property: + * name: changed + * alias: n + * @endcode + * + * In this example, skip_count is true which means count() will not attempt to + * count the available source records, but just always return -1 instead. The + * high_water_property defines which field marks the last imported row of the + * migration. This will get converted into a SQL condition that looks like + * 'n.changed' or 'changed' if no alias. * * @see \Drupal\migrate\Plugin\MigratePluginManager * @see \Drupal\migrate\Annotation\MigrateSource @@ -174,10 +216,10 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter /** * Initializes the iterator with the source data. * - * @return array - * An array of the data for this source. + * @return \Iterator + * Returns an iteratable object of data for this source. */ - protected abstract function initializeIterator(); + abstract protected function initializeIterator(); /** * Gets the module handler. @@ -311,7 +353,7 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter $row_data = $this->getIterator()->current() + $this->configuration; $this->fetchNextRow(); - $row = new Row($row_data, $this->migration->getSourcePlugin()->getIds(), $this->migration->getDestinationIds()); + $row = new Row($row_data, $this->getIds()); // Populate the source key for this row. $this->currentSourceIds = $row->getSourceIdValues(); @@ -394,7 +436,10 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter * Returns -1 if the source is not countable. * * @param bool $refresh - * (optional) Whether or not to refresh the count. Defaults to FALSE. + * (optional) Whether or not to refresh the count. Defaults to FALSE. Not + * all implementations support the reset flag. In such instances this + * parameter is ignored and the result of calling the method will always be + * up to date. * * @return int * The count. @@ -541,4 +586,17 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter $this->saveHighWater(NULL); } + /** + * {@inheritdoc} + */ + public function getSourceModule() { + if (!empty($this->configuration['source_module'])) { + return $this->configuration['source_module']; + } + elseif (!empty($this->pluginDefinition['source_module'])) { + return $this->pluginDefinition['source_module']; + } + return NULL; + } + }