reverted: --- b/core/modules/migrate/lib/Drupal/migrate/DrupalMessage.php +++ /dev/null @@ -1,15 +0,0 @@ -level; } diff -u b/core/modules/migrate/lib/Drupal/migrate/MigrateExecutable.php b/core/modules/migrate/lib/Drupal/migrate/MigrateExecutable.php --- b/core/modules/migrate/lib/Drupal/migrate/MigrateExecutable.php +++ b/core/modules/migrate/lib/Drupal/migrate/MigrateExecutable.php @@ -59,8 +59,18 @@ * @var array */ protected $sourceIdValues; + + /** + * @var int + */ protected $processed_since_feedback = 0; + /** + * @param MigrationInterface $migration + * @param MigrateMessageInterface $message + * + * @throws \Drupal\migrate\MigrateException + */ public function __construct(MigrationInterface $migration, MigrateMessageInterface $message) { $this->migration = $migration; $this->message = $message; @@ -82,7 +92,7 @@ $limit *= 1024; break; default: - throw new \Exception(t('Invalid PHP memory_limit !limit', + throw new MigrateException(t('Invalid PHP memory_limit !limit', array('!limit' => $limit))); } } @@ -95,7 +105,7 @@ */ public function getSource() { if (!isset($this->source)) { - $this->source = new Source($this->migration); + $this->source = new Source($this->migration, $this); } return $this->source; } @@ -165,12 +175,12 @@ try { $destination_id_values = $destination->import($row); if ($destination_id_values) { - $id_map->saveIDMapping($row, $destination_id_values, $this->needsUpdate, $this->rollbackAction); + $id_map->saveIdMapping($row, $destination_id_values, $this->needsUpdate, $this->rollbackAction); $this->successes_since_feedback++; $this->total_successes++; } else { - $id_map->saveIDMapping($row, array(), MigrateIdMapInterface::STATUS_FAILED, $this->rollbackAction); + $id_map->saveIdMapping($row, array(), MigrateIdMapInterface::STATUS_FAILED, $this->rollbackAction); if ($id_map->messageCount() == 0) { $message = t('New object was not saved, no error provided'); $this->saveMessage($message); @@ -178,13 +188,13 @@ } } } - catch (\MigrateException $e) { - $this->migration->getIdMap()->saveIDMapping($row, array(), $e->getStatus(), $this->rollbackAction); + catch (MigrateException $e) { + $this->migration->getIdMap()->saveIdMapping($row, array(), $e->getStatus(), $this->rollbackAction); $this->saveMessage($e->getMessage(), $e->getLevel()); $this->message->display($e->getMessage()); } catch (\Exception $e) { - $this->migration->getIdMap()->saveIDMapping($row, array(), MigrateIdMapInterface::STATUS_FAILED, $this->rollbackAction); + $this->migration->getIdMap()->saveIdMapping($row, array(), MigrateIdMapInterface::STATUS_FAILED, $this->rollbackAction); $this->handleException($e); } $this->total_processed++; diff -u b/core/modules/migrate/lib/Drupal/migrate/MigrateMessageInterface.php b/core/modules/migrate/lib/Drupal/migrate/MigrateMessageInterface.php --- b/core/modules/migrate/lib/Drupal/migrate/MigrateMessageInterface.php +++ b/core/modules/migrate/lib/Drupal/migrate/MigrateMessageInterface.php @@ -10,4 +10,10 @@ interface MigrateMessageInterface { + /** + * @param $message + * @param string $type + * + * @return mixed + */ function display($message, $type = 'status'); } diff -u b/core/modules/migrate/lib/Drupal/migrate/Plugin/MigrateIdMapInterface.php b/core/modules/migrate/lib/Drupal/migrate/Plugin/MigrateIdMapInterface.php --- b/core/modules/migrate/lib/Drupal/migrate/Plugin/MigrateIdMapInterface.php +++ b/core/modules/migrate/lib/Drupal/migrate/Plugin/MigrateIdMapInterface.php @@ -45,7 +45,7 @@ * @param $status * @param $rollback_action */ - public function saveIDMapping(Row $row, array $destination_id_values, $status = self::STATUS_IMPORTED, $rollback_action = self::ROLLBACK_DELETE); + public function saveIdMapping(Row $row, array $destination_id_values, $status = self::STATUS_IMPORTED, $rollback_action = self::ROLLBACK_DELETE); /** * Record a message related to a source record @@ -89,6 +89,7 @@ * Delete the map and message entries for a given source record * * @param array $source_key + * @param bool $messages_only */ public function delete(array $source_key, $messages_only = FALSE); @@ -115,7 +116,16 @@ * Retrieve map data for a given source or destination item */ public function getRowBySource(array $source_id); - public function getRowByDestination(array $destination_id); + + + /** + * Retrieve a row by the destination identifiers. + * + * @param array $destination_id + * + * @return array + */ + public function getRowByDestination(array $destination_id_values); /** * Retrieve an array of map rows marked as needing update. diff -u b/core/modules/migrate/lib/Drupal/migrate/Plugin/MigrateProcessBag.php b/core/modules/migrate/lib/Drupal/migrate/Plugin/MigrateProcessBag.php --- b/core/modules/migrate/lib/Drupal/migrate/Plugin/MigrateProcessBag.php +++ b/core/modules/migrate/lib/Drupal/migrate/Plugin/MigrateProcessBag.php @@ -21,6 +21,11 @@ protected $pluginKey = 'plugin'; + /** + * @param PluginManagerInterface $manager + * @param array $configurations + * @param MigrationInterface $migration + */ public function __construct(PluginManagerInterface $manager, array $configurations = array(), MigrationInterface $migration) { parent::__construct($manager, $configurations); $this->migration = $migration; diff -u b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/destination/Config.php b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/destination/Config.php --- b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/destination/Config.php +++ b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/destination/Config.php @@ -10,6 +10,7 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\migrate\Entity\Migration; use Drupal\migrate\Entity\MigrationInterface; +use Drupal\migrate\MigrateException; use Drupal\migrate\Row; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Config\Config as ConfigObject; @@ -28,6 +29,12 @@ */ protected $config; + /** + * @param array $configuration + * @param string $plugin_id + * @param array $plugin_definition + * @param ConfigObject $config + */ public function __construct(array $configuration, $plugin_id, array $plugin_definition, ConfigObject $config) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->config = $config; @@ -51,10 +58,27 @@ ->save(); } + /** + * @param array $destination_keys + * + * @throws \Drupal\migrate\MigrateException + */ public function rollbackMultiple(array $destination_keys) { - throw new \MigrateException('Configuration can not be rolled back'); + throw new MigrateException('Configuration can not be rolled back'); } + /** + * Derived classes must implement fields(), returning a list of available + * destination fields. + * + * @todo Review the cases where we need the Migration parameter, can we avoid that? + * + * @param Migration $migration + * Optionally, the migration containing this destination. + * @return array + * - Keys: machine names of the fields + * - Values: Human-friendly descriptions of the fields. + */ public function fields(Migration $migration = NULL) { // @todo Dynamically fetch fields using Config Schema API. } diff -u b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/id_map/Sql.php b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/id_map/Sql.php --- b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/id_map/Sql.php +++ b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/id_map/Sql.php @@ -54,6 +54,15 @@ */ protected $migration; + /** + * @var array + */ + protected $sourceIdFields; + + /** + * @var array + */ + protected $destinationIdFields; /** * Qualifying the map table name with the database name makes cross-db joins @@ -98,15 +107,15 @@ $this->destinationIds = $migration->get('destinationIds'); // Build the source and destination key maps - $this->sourceKeyMap = array(); + $this->sourceIdFields = array(); $count = 1; foreach ($this->sourceIds as $field => $schema) { - $this->sourceKeyMap[$field] = 'sourceid' . $count++; + $this->sourceIdFields[$field] = 'sourceid' . $count++; } - $this->destinationKeyMap = array(); + $this->destinationIdFields = array(); $count = 1; foreach ($this->destinationIds as $field => $schema) { - $this->destinationKeyMap[$field] = 'destid' . $count++; + $this->destinationIdFields[$field] = 'destid' . $count++; } $this->ensureTables(); } @@ -250,7 +259,7 @@ public function getRowBySource(array $source_id) { $query = $this->getDatabase()->select($this->mapTable, 'map') ->fields('map'); - foreach ($this->sourceKeyMap as $key_name) { + foreach ($this->sourceIdFields as $key_name) { $query = $query->condition("map.$key_name", array_shift($source_id), '='); } $result = $query->execute(); @@ -260,12 +269,15 @@ /** * Retrieve a row from the map table, given a destination ID * - * @param array $source_id + * @param array $destination_id + * + * @return mixed + * The row(s) of data */ public function getRowByDestination(array $destination_id) { $query = $this->getDatabase()->select($this->mapTable, 'map') ->fields('map'); - foreach ($this->destinationKeyMap as $key_name) { + foreach ($this->destinationIdFields as $key_name) { $query = $query->condition("map.$key_name", array_shift($destination_id), '='); } $result = $query->execute(); @@ -304,8 +316,8 @@ */ public function lookupSourceID(array $destination_id) { $query = $this->getDatabase()->select($this->mapTable, 'map') - ->fields('map', $this->sourceKeyMap); - foreach ($this->destinationKeyMap as $key_name) { + ->fields('map', $this->sourceIdFields); + foreach ($this->destinationIdFields as $key_name) { $query = $query->condition("map.$key_name", array_shift($destination_id), '='); } $result = $query->execute(); @@ -324,8 +336,8 @@ */ public function lookupDestinationID(array $source_id) { $query = $this->getDatabase()->select($this->mapTable, 'map') - ->fields('map', $this->destinationKeyMap); - foreach ($this->sourceKeyMap as $key_name) { + ->fields('map', $this->destinationIdFields); + foreach ($this->sourceIdFields as $key_name) { $query = $query->condition("map.$key_name", array_shift($source_id), '='); } $result = $query->execute(); @@ -338,7 +350,7 @@ * to the destination key. Also may be called, setting the third parameter to * NEEDS_UPDATE, to signal an existing record should be remigrated. * - * @param stdClass $row + * @param Row $row * The raw source data. We use the key map derived from the source object * to get the source key values. * @param array $dest_ids @@ -351,11 +363,11 @@ * $param string $hash * If hashing is enabled, the hash of the raw source row. */ - public function saveIDMapping(Row $row, array $destination_id_values, $needs_update = MigrateIdMapInterface::STATUS_IMPORTED, $rollback_action = MigrateIdMapInterface::ROLLBACK_DELETE) { + public function saveIdMapping(Row $row, array $destination_id_values, $needs_update = MigrateIdMapInterface::STATUS_IMPORTED, $rollback_action = MigrateIdMapInterface::ROLLBACK_DELETE) { // Construct the source key $keys = array(); $destination = $row->getDestination(); - foreach ($this->sourceKeyMap as $field_name => $key_name) { + foreach ($this->sourceIdFields as $field_name => $key_name) { // A NULL key value will fail. if (!isset($destination[$field_name])) { $this->message->display(t( @@ -619,10 +631,10 @@ public function rewind() { $this->currentRow = NULL; $fields = array(); - foreach ($this->sourceKeyMap as $field) { + foreach ($this->sourceIdFields as $field) { $fields[] = $field; } - foreach ($this->destinationKeyMap as $field) { + foreach ($this->destinationIdFields as $field) { $fields[] = $field; } @@ -665,7 +677,7 @@ $this->currentRow = NULL; } else { - foreach ($this->sourceKeyMap as $map_field) { + foreach ($this->sourceIdFields as $map_field) { $this->currentKey[$map_field] = $this->currentRow->$map_field; // Leave only destination fields unset($this->currentRow->$map_field); diff -u b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/source/D6Variable.php b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/source/D6Variable.php --- b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/source/D6Variable.php +++ b/core/modules/migrate/lib/Drupal/migrate/Plugin/migrate/source/D6Variable.php @@ -24,6 +24,9 @@ */ protected $variables; + /** + * {@inheritdoc} + */ function __construct(array $configuration, $plugin_id, array $plugin_definition, MigrationInterface $migration) { parent::__construct($configuration, $plugin_id, $plugin_definition, $migration); $this->variables = $this->configuration['variables']; diff -u b/core/modules/migrate/lib/Drupal/migrate/Source.php b/core/modules/migrate/lib/Drupal/migrate/Source.php --- b/core/modules/migrate/lib/Drupal/migrate/Source.php +++ b/core/modules/migrate/lib/Drupal/migrate/Source.php @@ -8,6 +8,7 @@ namespace Drupal\migrate; use Drupal\migrate\Entity\MigrationInterface; +use Drupal\migrate\Plugin\MigrateIdMapInterface; /** * A base class for migrate sources. @@ -182,8 +183,9 @@ * * @param \Drupal\migrate\Entity\MigrationInterface $migration */ - function __construct(MigrationInterface $migration) { + function __construct(MigrationInterface $migration, MigrateExecutable $migrate_executable) { $this->migration = $migration; + $this->migrateExecutable = $migrate_executable; $configuration = $migration->get('source'); if (!empty($configuration['cache_counts'])) { $this->cacheCounts = TRUE; @@ -385,10 +387,10 @@ if ($this->migration->getSource()->prepareRow($row) === FALSE) { // Make sure we replace any previous messages for this item with any // new ones. - $this->migration->getIdMap()->delete($this->currentIds, TRUE); - $this->migration->saveQueuedMessages(); - $this->migration->getIdMap()->saveIDMapping($row, array(), - \MigrateMap::STATUS_IGNORED, $this->migration->rollbackAction); + $id_map = $this->migration->getIdMap(); + $id_map->delete($this->currentIds, TRUE); + $this->migrateExecutable->saveQueuedMessages(); + $id_map->saveIdMapping($row, array(), MigrateIdMapInterface::STATUS_IGNORED, $this->migrateExecutable->rollbackAction); $this->numIgnored++; $this->currentRow = NULL; $this->currentIds = NULL; diff -u b/core/modules/migrate/lib/Drupal/migrate/Tests/Dump/Drupal6SystemSite.php b/core/modules/migrate/lib/Drupal/migrate/Tests/Dump/Drupal6SystemSite.php --- b/core/modules/migrate/lib/Drupal/migrate/Tests/Dump/Drupal6SystemSite.php +++ b/core/modules/migrate/lib/Drupal/migrate/Tests/Dump/Drupal6SystemSite.php @@ -4,8 +4,14 @@ use Drupal\Core\Database\Connection; +/** + * Database dump for testing system.site.yml migration. + */ class Drupal6SystemSite { + /** + * @param \Drupal\Core\Database\Connection $database + */ public static function load(Connection $database) { $database->schema()->createTable('variable', array( 'fields' => array( diff -u b/core/modules/migrate/lib/Drupal/migrate/Tests/MigrateSystemConfigsTest.php b/core/modules/migrate/lib/Drupal/migrate/Tests/MigrateSystemConfigsTest.php --- b/core/modules/migrate/lib/Drupal/migrate/Tests/MigrateSystemConfigsTest.php +++ b/core/modules/migrate/lib/Drupal/migrate/Tests/MigrateSystemConfigsTest.php @@ -7,11 +7,14 @@ namespace Drupal\migrate\Tests; -use Drupal\migrate\DrupalMessage; +use Drupal\migrate\MigrateMessage; use Drupal\migrate\MigrateExecutable; class MigrateSystemConfigsTest extends MigrateTestBase { + /** + * {@inheritdoc} + */ public static function getInfo() { return array( 'name' => 'Migrate variables to system.site.yml', @@ -26,7 +29,7 @@ drupal_get_path('module', 'migrate') . '/ib/Drupal/migrate/Tests/Dump/Drupal6SystemSite.php', ); $this->prepare($migration, $dumps); - $executable = new MigrateExecutable($migration, new DrupalMessage); + $executable = new MigrateExecutable($migration, new MigrateMessage); $executable->import(); $config = \Drupal::config('system.site'); $this->assertIdentical($config->get('name'), 'drupal'); diff -u b/core/modules/migrate/lib/Drupal/migrate/Tests/MigrateTestBase.php b/core/modules/migrate/lib/Drupal/migrate/Tests/MigrateTestBase.php --- b/core/modules/migrate/lib/Drupal/migrate/Tests/MigrateTestBase.php +++ b/core/modules/migrate/lib/Drupal/migrate/Tests/MigrateTestBase.php @@ -23,6 +23,12 @@ public static $modules = array('migrate'); + /** + * @param MigrationInterface $migration + * @param array $files + * + * @return \Drupal\Core\Database\Connection + */ protected function prepare(MigrationInterface $migration, array $files = array()) { $databasePrefix = 'simpletest_m_' . mt_rand(1000, 1000000); $connection_info = Database::getConnectionInfo('default'); diff -u b/core/modules/migrate/tests/Drupal/migrate/Tests/FakeDatabaseSchema.php b/core/modules/migrate/tests/Drupal/migrate/Tests/FakeDatabaseSchema.php --- b/core/modules/migrate/tests/Drupal/migrate/Tests/FakeDatabaseSchema.php +++ b/core/modules/migrate/tests/Drupal/migrate/Tests/FakeDatabaseSchema.php @@ -142,7 +142,7 @@ } /** - * Provide meta information about this battery of tests. + * {@inheritdoc} */ public static function getInfo() { return array( diff -u b/core/modules/migrate/tests/Drupal/migrate/Tests/FakeSelect.php b/core/modules/migrate/tests/Drupal/migrate/Tests/FakeSelect.php --- b/core/modules/migrate/tests/Drupal/migrate/Tests/FakeSelect.php +++ b/core/modules/migrate/tests/Drupal/migrate/Tests/FakeSelect.php @@ -289,6 +289,9 @@ * * @return bool * TRUE if the condition matches. + * + * @throws \Exception + * */ protected function matchSingle(array $row, array $condition) { $field_info = $this->getFieldInfo($condition['field']); @@ -527,7 +530,7 @@ } /** - * Provide meta information about this battery of tests. + * {@inheritdoc} */ public static function getInfo() { return array( diff -u b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateSqlSourceTestCase.php b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateSqlSourceTestCase.php --- b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateSqlSourceTestCase.php +++ b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateSqlSourceTestCase.php @@ -60,7 +60,10 @@ $migration->expects($this->any()) ->method('getSource') ->will($this->returnValue($plugin)); - $this->source = new Source($migration); + $migrateExecutable = $this->getMockBuilder('Drupal\migrate\MigrateExecutable') + ->disableOriginalConstructor() + ->getMock(); + $this->source = new Source($migration, $migrateExecutable); $cache = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); $this->writeAttribute($this->source, 'cache', $cache); diff -u b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateTestCase.php b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateTestCase.php --- b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateTestCase.php +++ b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateTestCase.php @@ -26,7 +26,7 @@ /** * Retrieve a mocked migration. * - * @return \PHPUnit_Framework_MockObject_MockObject + * @return \Drupal\migrate\Entity\MigrationInterface * The mocked migration. */ protected function getMigration() {