Commit 453a4451 authored by alexpott's avatar alexpott

Issue #2314289 by benjy: Track result of migrations and use it to properly...

Issue #2314289 by benjy: Track result of migrations and use it to properly define migrate_dependencies.
parent cdab062b
# Schema for the configuration files of the Migrate module.
migrate.migration.*:
type: mapping
type: config_entity
label: 'Migration'
mapping:
id:
......
......@@ -326,15 +326,7 @@ public function checkRequirements() {
$required_migrations = \Drupal::entityManager()->getStorage('migration')->loadMultiple($this->requirements);
// Check if the dependencies are in good shape.
foreach ($required_migrations as $required_migration) {
// If the dependent source migration has no IDs then no mappings can
// be recorded thus it is impossible to see whether the migration ran.
if (!$required_migration->getSourcePlugin()->getIds()) {
return FALSE;
}
// If the dependent migration has not processed any record, it means the
// dependency requirements are not met.
if (!$required_migration->getIdMap()->processedCount()) {
if (!$required_migration->isComplete()) {
return FALSE;
}
}
......@@ -346,4 +338,27 @@ public function checkRequirements() {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function setMigrationResult($result) {
$migrate_result_store = \Drupal::keyValue('migrate_result');
$migrate_result_store->set($this->id(), $result);
}
/**
* {@inheritdoc}
*/
public function getMigrationResult() {
$migrate_result_store = \Drupal::keyValue('migrate_result');
return $migrate_result_store->get($this->id(), static::RESULT_INCOMPLETE);
}
/**
* {@inheritdoc}
*/
public function isComplete() {
return $this->getMigrationResult() === static::RESULT_COMPLETED;
}
}
......@@ -102,4 +102,28 @@ public function getHighwater();
*/
public function saveHighwater($highwater);
/**
* Check if this migration is complete.
*
* @return bool
* TRUE if this migration is complete otherwise FALSE.
*/
public function isComplete();
/**
* Set the migration result.
*
* @param int $result
* One of the RESULT_* constants.
*/
public function setMigrationResult($result);
/**
* Get the current migration result.
*
* @return int
* The current migration result. Defaults to RESULT_INCOMPLETE.
*/
public function getMigrationResult();
}
......@@ -21,7 +21,7 @@ class MigrateExecutable {
/**
* The configuration of the migration to do.
*
* @var \Drupal\migrate\Entity\MigrationInterface
* @var \Drupal\migrate\Entity\Migration
*/
protected $migration;
......@@ -333,6 +333,7 @@ public function import() {
*/
#$this->progressMessage($return);
$this->migration->setMigrationResult($return);
return $return;
}
......
......@@ -116,6 +116,11 @@ protected function prepareIdMappings(array $id_mappings) {
$migrations = entity_load_multiple('migration', array_keys($id_mappings));
foreach ($id_mappings as $migration_id => $data) {
$migration = $migrations[$migration_id];
// @TODO, rename prepareIdMappings() in https://drupal.org/node/2315489
// which will make the position of this more appropriate.
$migration->setMigrationResult(MigrationInterface::RESULT_COMPLETED);
$id_map = $migration->getIdMap();
$id_map->setMessage($this);
$source_ids = $migration->getSourcePlugin()->getIds();
......
......@@ -84,6 +84,6 @@ process:
destination:
plugin: entity:block
migration_dependencies:
optional:
required:
- d6_menu
- d6_custom_block
......@@ -48,10 +48,9 @@ process:
destination:
plugin: entity:comment
migration_dependencies:
optional:
- d6_comment_type
required:
- d6_node
- d6_comment_type
- d6_user
- d6_comment_entity_display
- d6_comment_entity_form_display
......
......@@ -33,8 +33,7 @@ destination:
migration_dependencies:
required:
- d6_node_type
- d6_node_settings
- d6_filter_format
optional:
- d6_field_instance_widget_settings
- d6_field_formatter_settings
- d6_node_settings
......@@ -22,3 +22,6 @@ migration_dependencies:
# migration as an optional dependency to ensure it runs first.
optional:
- d6_file
dependencies:
module:
- file
......@@ -52,7 +52,10 @@ public function setUp() {
array(array(11), array(2)),
array(array(12), array(1)),
array(array(13), array(2)),
)
),
'd6_menu' => array(
array(array('menu1'), array('menu')),
),
));
// Set Bartik and Seven as the default public and admin theme.
......
......@@ -8,6 +8,7 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase;
use Drupal\migrate\Entity\MigrationInterface;
/**
* Base class for Node migration tests.
......@@ -33,9 +34,24 @@ protected function setUp() {
array(array(1), array('filtered_html')),
array(array(2), array('full_html')),
),
'd6_field_instance_widget_settings' => array(
array(
array('page', 'field_test'),
array('node', 'page', 'default', 'test'),
),
),
'd6_field_formatter_settings' => array(
array(
array('page', 'default', 'node', 'field_test'),
array('node', 'page', 'default', 'field_test'),
),
),
);
$this->prepareIdMappings($id_mappings);
$migration = entity_load('migration', 'd6_node_settings');
$migration->setMigrationResult(MigrationInterface::RESULT_COMPLETED);
// Create a test node.
$node = entity_create('node', array(
'type' => 'story',
......
......@@ -30,7 +30,18 @@ public function testMigrateDependenciesOrder() {
$migrations = entity_load_multiple('migration', $migration_items);
$expected_order = array('d6_filter_format', 'd6_node', 'd6_comment');
$this->assertEqual(array_keys($migrations), $expected_order);
$expected_requirements = array('d6_node', 'd6_node_type', 'd6_filter_format', 'd6_user', 'd6_comment_entity_display', 'd6_comment_entity_form_display');
$expected_requirements = array(
'd6_node',
'd6_node_type',
'd6_node_settings',
'd6_field_instance_widget_settings',
'd6_field_formatter_settings',
'd6_filter_format',
'd6_user',
'd6_comment_type',
'd6_comment_entity_display',
'd6_comment_entity_form_display',
);
// Migration dependencies for comment include dependencies for node
// migration as well.
$actual_requirements = $migrations['d6_comment']->get('requirements');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment