Issue #2314289 by benjy: Track result of migrations and use it to properly define migrate_dependencies.
parent
cdab062b60
commit
453a4451b7
|
@ -1,7 +1,7 @@
|
||||||
# Schema for the configuration files of the Migrate module.
|
# Schema for the configuration files of the Migrate module.
|
||||||
|
|
||||||
migrate.migration.*:
|
migrate.migration.*:
|
||||||
type: mapping
|
type: config_entity
|
||||||
label: 'Migration'
|
label: 'Migration'
|
||||||
mapping:
|
mapping:
|
||||||
id:
|
id:
|
||||||
|
|
|
@ -326,15 +326,7 @@ class Migration extends ConfigEntityBase implements MigrationInterface, Requirem
|
||||||
$required_migrations = \Drupal::entityManager()->getStorage('migration')->loadMultiple($this->requirements);
|
$required_migrations = \Drupal::entityManager()->getStorage('migration')->loadMultiple($this->requirements);
|
||||||
// Check if the dependencies are in good shape.
|
// Check if the dependencies are in good shape.
|
||||||
foreach ($required_migrations as $required_migration) {
|
foreach ($required_migrations as $required_migration) {
|
||||||
// If the dependent source migration has no IDs then no mappings can
|
if (!$required_migration->isComplete()) {
|
||||||
// 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()) {
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -346,4 +338,27 @@ class Migration extends ConfigEntityBase implements MigrationInterface, Requirem
|
||||||
return TRUE;
|
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 @@ interface MigrationInterface extends ConfigEntityInterface {
|
||||||
*/
|
*/
|
||||||
public function saveHighwater($highwater);
|
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.
|
* The configuration of the migration to do.
|
||||||
*
|
*
|
||||||
* @var \Drupal\migrate\Entity\MigrationInterface
|
* @var \Drupal\migrate\Entity\Migration
|
||||||
*/
|
*/
|
||||||
protected $migration;
|
protected $migration;
|
||||||
|
|
||||||
|
@ -333,6 +333,7 @@ class MigrateExecutable {
|
||||||
*/
|
*/
|
||||||
#$this->progressMessage($return);
|
#$this->progressMessage($return);
|
||||||
|
|
||||||
|
$this->migration->setMigrationResult($return);
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,6 +116,11 @@ abstract class MigrateTestBase extends WebTestBase implements MigrateMessageInte
|
||||||
$migrations = entity_load_multiple('migration', array_keys($id_mappings));
|
$migrations = entity_load_multiple('migration', array_keys($id_mappings));
|
||||||
foreach ($id_mappings as $migration_id => $data) {
|
foreach ($id_mappings as $migration_id => $data) {
|
||||||
$migration = $migrations[$migration_id];
|
$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 = $migration->getIdMap();
|
||||||
$id_map->setMessage($this);
|
$id_map->setMessage($this);
|
||||||
$source_ids = $migration->getSourcePlugin()->getIds();
|
$source_ids = $migration->getSourcePlugin()->getIds();
|
||||||
|
|
|
@ -84,6 +84,6 @@ process:
|
||||||
destination:
|
destination:
|
||||||
plugin: entity:block
|
plugin: entity:block
|
||||||
migration_dependencies:
|
migration_dependencies:
|
||||||
optional:
|
required:
|
||||||
- d6_menu
|
- d6_menu
|
||||||
- d6_custom_block
|
- d6_custom_block
|
||||||
|
|
|
@ -48,10 +48,9 @@ process:
|
||||||
destination:
|
destination:
|
||||||
plugin: entity:comment
|
plugin: entity:comment
|
||||||
migration_dependencies:
|
migration_dependencies:
|
||||||
optional:
|
|
||||||
- d6_comment_type
|
|
||||||
required:
|
required:
|
||||||
- d6_node
|
- d6_node
|
||||||
|
- d6_comment_type
|
||||||
- d6_user
|
- d6_user
|
||||||
- d6_comment_entity_display
|
- d6_comment_entity_display
|
||||||
- d6_comment_entity_form_display
|
- d6_comment_entity_form_display
|
||||||
|
|
|
@ -33,8 +33,7 @@ destination:
|
||||||
migration_dependencies:
|
migration_dependencies:
|
||||||
required:
|
required:
|
||||||
- d6_node_type
|
- d6_node_type
|
||||||
|
- d6_node_settings
|
||||||
- d6_filter_format
|
- d6_filter_format
|
||||||
optional:
|
|
||||||
- d6_field_instance_widget_settings
|
- d6_field_instance_widget_settings
|
||||||
- d6_field_formatter_settings
|
- d6_field_formatter_settings
|
||||||
- d6_node_settings
|
|
||||||
|
|
|
@ -22,3 +22,6 @@ migration_dependencies:
|
||||||
# migration as an optional dependency to ensure it runs first.
|
# migration as an optional dependency to ensure it runs first.
|
||||||
optional:
|
optional:
|
||||||
- d6_file
|
- d6_file
|
||||||
|
dependencies:
|
||||||
|
module:
|
||||||
|
- file
|
||||||
|
|
|
@ -52,7 +52,10 @@ class MigrateBlockTest extends MigrateDrupalTestBase {
|
||||||
array(array(11), array(2)),
|
array(array(11), array(2)),
|
||||||
array(array(12), array(1)),
|
array(array(12), array(1)),
|
||||||
array(array(13), array(2)),
|
array(array(13), array(2)),
|
||||||
)
|
),
|
||||||
|
'd6_menu' => array(
|
||||||
|
array(array('menu1'), array('menu')),
|
||||||
|
),
|
||||||
));
|
));
|
||||||
|
|
||||||
// Set Bartik and Seven as the default public and admin theme.
|
// Set Bartik and Seven as the default public and admin theme.
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
namespace Drupal\migrate_drupal\Tests\d6;
|
namespace Drupal\migrate_drupal\Tests\d6;
|
||||||
|
|
||||||
use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase;
|
use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase;
|
||||||
|
use Drupal\migrate\Entity\MigrationInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for Node migration tests.
|
* Base class for Node migration tests.
|
||||||
|
@ -33,9 +34,24 @@ abstract class MigrateNodeTestBase extends MigrateDrupalTestBase {
|
||||||
array(array(1), array('filtered_html')),
|
array(array(1), array('filtered_html')),
|
||||||
array(array(2), array('full_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);
|
$this->prepareIdMappings($id_mappings);
|
||||||
|
|
||||||
|
$migration = entity_load('migration', 'd6_node_settings');
|
||||||
|
$migration->setMigrationResult(MigrationInterface::RESULT_COMPLETED);
|
||||||
|
|
||||||
// Create a test node.
|
// Create a test node.
|
||||||
$node = entity_create('node', array(
|
$node = entity_create('node', array(
|
||||||
'type' => 'story',
|
'type' => 'story',
|
||||||
|
|
|
@ -30,7 +30,18 @@ class MigrateDependenciesTest extends MigrateDrupalTestBase {
|
||||||
$migrations = entity_load_multiple('migration', $migration_items);
|
$migrations = entity_load_multiple('migration', $migration_items);
|
||||||
$expected_order = array('d6_filter_format', 'd6_node', 'd6_comment');
|
$expected_order = array('d6_filter_format', 'd6_node', 'd6_comment');
|
||||||
$this->assertEqual(array_keys($migrations), $expected_order);
|
$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 dependencies for comment include dependencies for node
|
||||||
// migration as well.
|
// migration as well.
|
||||||
$actual_requirements = $migrations['d6_comment']->get('requirements');
|
$actual_requirements = $migrations['d6_comment']->get('requirements');
|
||||||
|
|
Loading…
Reference in New Issue