Commit 7797b14b authored by webchick's avatar webchick

Issue #2561697 by phenaproxima, anavarre, Jeremy: Migration should not choke...

Issue #2561697 by phenaproxima, anavarre, Jeremy: Migration should not choke when the content_node_field table isn't available
parent 8095dedc
......@@ -13,7 +13,8 @@
* The field instance per form display source class.
*
* @MigrateSource(
* id = "d6_field_instance_per_form_display"
* id = "d6_field_instance_per_form_display",
* source_provider = "content"
* )
*/
class FieldInstancePerFormDisplay extends DrupalSqlBase {
......
......@@ -24,7 +24,7 @@
* @param array $configuration
* (optional) Additional configuration for the plugin.
*
* @return \Drupal\migrate\Plugin\MigrateSourceInterface
* @return \Drupal\migrate\Plugin\MigrateSourceInterface|\Drupal\migrate\Plugin\RequirementsInterface
* The fully initialized source plugin.
*/
protected function getSourcePlugin($plugin_id, array $configuration = []) {
......
......@@ -8,6 +8,8 @@
namespace Drupal\migrate_drupal\Plugin\migrate\builder\d6;
use Drupal\migrate\Entity\Migration;
use Drupal\migrate\Exception\RequirementsException;
use Drupal\migrate\Plugin\RequirementsInterface;
use Drupal\migrate_drupal\Plugin\migrate\builder\CckBuilder;
/**
......@@ -28,8 +30,20 @@ class CckMigration extends CckBuilder {
public function buildMigrations(array $template) {
$migration = Migration::create($template);
$source_plugin = $migration->getSourcePlugin();
// The source plugin will throw RequirementsException if CCK is not enabled,
// in which case there is nothing else for us to do.
if ($source_plugin instanceof RequirementsInterface) {
try {
$source_plugin->checkRequirements();
}
catch (RequirementsException $e) {
return [$migration];
}
}
// Loop through every field that will be migrated.
foreach ($migration->getSourcePlugin() as $field) {
foreach ($source_plugin as $field) {
$field_type = $field->getSourceProperty('type');
// Each field type should only be processed once.
......
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Tests\d6\CckMigrationBuilderTest.
*/
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\Core\Database\Database;
/**
* @group migrate_drupal
*/
class CckMigrationBuilderTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['field'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$database = Database::getConnection('default', 'migrate');
$database
->update('system')
->fields(array('status' => 0))
->condition('name', 'content')
->condition('type', 'module')
->execute();
$database->schema()->dropTable('content_node_field');
$database->schema()->dropTable('content_node_field_instance');
}
/**
* Tests that the CckMigration builder performs a requirements check on the
* source plugin.
*/
public function testRequirementCheck() {
$template = \Drupal::service('migrate.template_storage')
->getTemplateByName('d6_field');
// Without the requirements check, this will throw a \PDOException because
// the CCK tables do not exist.
\Drupal::service('migrate.migration_builder')->createMigrations([$template]);
}
}
......@@ -8,6 +8,7 @@
namespace Drupal\node\Plugin\migrate\builder\d6;
use Drupal\migrate\Entity\Migration;
use Drupal\migrate\Exception\RequirementsException;
use Drupal\migrate_drupal\Plugin\migrate\builder\CckBuilder;
/**
......@@ -23,9 +24,17 @@ public function buildMigrations(array $template) {
// Read all CCK field instance definitions in the source database.
$fields = array();
foreach ($this->getSourcePlugin('d6_field_instance', $template['source']) as $field) {
$info = $field->getSource();
$fields[$info['type_name']][$info['field_name']] = $info;
$source_plugin = $this->getSourcePlugin('d6_field_instance', $template['source']);
try {
$source_plugin->checkRequirements();
foreach ($source_plugin as $field) {
$info = $field->getSource();
$fields[$info['type_name']][$info['field_name']] = $info;
}
}
catch (RequirementsException $e) {
// Don't do anything; $fields will be empty.
}
foreach ($this->getSourcePlugin('d6_node_type', $template['source']) as $row) {
......
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