diff --git a/CHANGELOG.txt b/CHANGELOG.txt index f0de944b0486f399d0d14e567244859c193d6b77..3e87c4d9c330d259935af69ca0d8a9e802343dfc 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -12,7 +12,7 @@ Features and enhancements machine name rather than class name. MigrationBase::getInstance now takes a machine name rather than a class name. Migration class names are no longer required to end in 'Migration'. - +- #992898 - Pass options to source and destination constructors as arrays. Allow migration of comment enable/disable. Check max_execution_time as well as memory_limit, for graceful exit when max_execution_time is in play. diff --git a/plugins/destinations/comment.inc b/plugins/destinations/comment.inc index 397a8e9e081d3ef6daad7b9082cb31190109f082..22df162b7e2d7e0cfa28eadd90b379e80aa13a51 100644 --- a/plugins/destinations/comment.inc +++ b/plugins/destinations/comment.inc @@ -30,18 +30,28 @@ class MigrateDestinationComment extends MigrateDestinationEntity { */ protected $maintainNodeStatistics; + /** + * Return an options array for comment destinations. + * + * @param string $language + * Default language for comments created via this destination class. + * @param string $text_format + * Default text format for comments created via this destination class. + */ + static public function options($language, $text_format) { + return compact('language', 'text_format'); + } + /** * Basic initialization * * @param string $bundle * A.k.a. the content type (page, article, etc.) of the ... comment?. - * @param string $language - * Language of the node content. - * @param string $text_format - * Default text format for fields on this comment. Can be overridden. + * @param array $options + * Options applied to comments. */ - public function __construct($bundle, $language = NULL, $text_format = NULL) { - parent::__construct('comment', $bundle, $language, $text_format); + public function __construct($bundle, array $options = array()) { + parent::__construct('comment', $bundle, $options); } /** diff --git a/plugins/destinations/entity.inc b/plugins/destinations/entity.inc index c754050edb51897db37506ad34f51ccad89b7579..d6ddbf75ce645356f9e5056a040249a577f98cce 100644 --- a/plugins/destinations/entity.inc +++ b/plugins/destinations/entity.inc @@ -56,13 +56,12 @@ abstract class MigrateDestinationEntity extends MigrateDestination { * * @param array $key_schema */ - public function __construct($entity_type, $bundle, - $language = NULL, $text_format = NULL) { + public function __construct($entity_type, $bundle, array $options = array()) { parent::__construct(); $this->entityType = $entity_type; $this->bundle = $bundle; - $this->language = isset($language) ? $language : LANGUAGE_NONE; - $this->textFormat = isset($text_format) ? $text_format : filter_fallback_format(); + $this->language = isset($options['language']) ? $options['language'] : LANGUAGE_NONE; + $this->textFormat = isset($options['text_format']) ? $options['text_format'] : filter_fallback_format(); } public function __toString() { diff --git a/plugins/destinations/node.inc b/plugins/destinations/node.inc index ef25d821b00220f34f30c8c2be5f7d865327cdc9..abb6f7e42250a7476a541cad7441d3c01c92a474 100644 --- a/plugins/destinations/node.inc +++ b/plugins/destinations/node.inc @@ -24,16 +24,28 @@ class MigrateDestinationNode extends MigrateDestinationEntity { ); } + /** + * Return an options array for node destinations. + * + * @param string $language + * Default language for nodes created via this destination class. + * @param string $text_format + * Default text format for nodes created via this destination class. + */ + static public function options($language, $text_format) { + return compact('language', 'text_format'); + } + /** * Basic initialization * * @param string $bundle * A.k.a. the content type (page, article, etc.) of the node. - * @param string $language - * Default language for nodes created via this destination class. + * @param array $options ++ * Options applied to nodes. */ - public function __construct($bundle, $language = NULL, $text_format = NULL) { - parent::__construct('node', $bundle, $language, $text_format); + public function __construct($bundle, array $options = array()) { + parent::__construct('node', $bundle, $options); } /** diff --git a/plugins/destinations/term.inc b/plugins/destinations/term.inc index 7db7f28e93abd72086837d41956ba6f42fe3e70f..9fc239f6e4c93ac16e2b5b6209208ff2e4f76f5d 100644 --- a/plugins/destinations/term.inc +++ b/plugins/destinations/term.inc @@ -25,11 +25,26 @@ class MigrateDestinationTerm extends MigrateDestinationEntity { ); } + /** + * Return an options array for term destinations. + * + * @param string $language + * Default language for terms created via this destination class. + * @param string $text_format + * Default text format for terms created via this destination class. + */ + static public function options($language, $text_format) { + return compact('language', 'text_format'); + } + /** * Basic initialization + * + * @param array $options + * Options applied to terms. */ - public function __construct($bundle, $language = NULL, $text_format = NULL) { - parent::__construct('taxonomy_term', $bundle, $language, $text_format); + public function __construct($bundle, array $options = array()) { + parent::__construct('taxonomy_term', $bundle, $options); } /** diff --git a/plugins/destinations/user.inc b/plugins/destinations/user.inc index 9b11a574a3bc59f36ea7b01f01cbdecb4df5926b..ae794e2f502f9c30fb3e12a7843d60e4bc2755c1 100644 --- a/plugins/destinations/user.inc +++ b/plugins/destinations/user.inc @@ -25,11 +25,26 @@ class MigrateDestinationUser extends MigrateDestinationEntity { ); } + /** + * Return an options array for user destinations. + * + * @param string $language + * Default language for usrs created via this destination class. + * @param string $text_format + * Default text format for users created via this destination class. + */ + static public function options($language, $text_format) { + return compact('language', 'text_format'); + } + /** * Basic initialization + * + * @param array $options + * Options applied to comments. */ - public function __construct($language = NULL, $text_format = NULL) { - parent::__construct('user', 'user', $language, $text_format); + public function __construct(array $options = array()) { + parent::__construct('user', 'user', $options); } /** diff --git a/plugins/sources/mssql.inc b/plugins/sources/mssql.inc index f2d58cdd1f7bd04a410826efb283d3d139748ac6..a72409e8d6617cd667588041a55805ef07dba47d 100644 --- a/plugins/sources/mssql.inc +++ b/plugins/sources/mssql.inc @@ -59,17 +59,27 @@ class MigrateSourceMSSQL extends MigrateSource { */ protected $batchSize; + /** + * Return an options array for MS SQL sources. + * + * @param int $batch_size + * Number of rows to pull at once (defaults to 500). + */ + static public function options($batch_size) { + return compact('batch_size'); + } + /** * Simple initialization. */ public function __construct(array $configuration, $query, $count_query, - array $fields, $batch_size = 500) { + array $fields, array $options = array()) { parent::__construct(); $this->query = $query; $this->countQuery = $count_query; $this->configuration = $configuration; $this->fields = $fields; - $this->batchSize = $batch_size; + $this->batchSize = isset($options['batch_size']) ? $options['batch_size'] : 500; } /** diff --git a/plugins/sources/sql.inc b/plugins/sources/sql.inc index 7a725a1fdaca3cf3f2873842280cbef17197a60c..173c26e785a8565eb367fcc90eb0e58c96cce303 100644 --- a/plugins/sources/sql.inc +++ b/plugins/sources/sql.inc @@ -61,6 +61,16 @@ class MigrateSourceSQL extends MigrateSource { */ protected $usingHighwater = FALSE; + /** + * Return an options array for PDO sources. + * + * @param boolean $map_joinable + * Indicates whether the map table can be joined directly to the source query. + */ + static public function options($map_joinable) { + return compact('map_joinable'); + } + /** * Simple initialization. * @@ -73,11 +83,11 @@ class MigrateSourceSQL extends MigrateSource { * @param SelectQuery $count_query * Optional - an explicit count query, primarily used when counting the * primary query is slow. - * @param boolean $map_joinable - * Indicates whether the map table can be joined directly to the source query. + * @param boolean $options + * Options applied to this source. */ - public function __construct(SelectQuery $query, - array $fields = array(), SelectQuery $count_query = NULL, $map_joinable = NULL) { + public function __construct(SelectQuery $query, array $fields = array(), + SelectQuery $count_query = NULL, array $options = array()) { parent::__construct(); $this->originalQuery = $query; $this->query = clone $query; @@ -89,8 +99,8 @@ class MigrateSourceSQL extends MigrateSource { $this->countQuery = $count_query; } - if (!is_null($map_joinable)) { - $this->mapJoinable = $map_joinable; + if (isset($options['map_joinable'])) { + $this->mapJoinable = $options['map_joinable']; } else { // TODO: We want to automatically determine if the map table can be joined