-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Override the SQL id_map plugin for our migration lookup (#52) - CSV convert to UTF-8 correctly - Switch form field access to readonly field widget (#51)
- Loading branch information
Showing
11 changed files
with
199 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.messages.messages--readonly { | ||
background-color: transparent; | ||
border-color: #ccc; | ||
color: inherit; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Drupal\stanford_migrate\Plugin\migrate\id_map; | ||
|
||
use Drupal\migrate\Plugin\migrate\id_map\Sql; | ||
|
||
/** | ||
* SQL Plugin override to modify the way the methods are used. | ||
*/ | ||
class StanfordSql extends Sql { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getRowByDestination(array $destination_id_values) { | ||
$query = $this->getDatabase()->select($this->mapTableName(), 'map') | ||
->fields('map'); | ||
foreach ($this->destinationIdFields() as $field_name => $destination_id) { | ||
if (!isset($destination_id_values[$field_name])) { | ||
// In the parent class, if the destination id values doesn't include | ||
// every field, we get an empty data. We're overridding it to use | ||
// whatever values & conditions we can. | ||
continue; | ||
} | ||
$query->condition("map.$destination_id", $destination_id_values[$field_name], '='); | ||
} | ||
return count($query->conditions()) > 1 ? | ||
$query->execute()->fetchAssoc() : []; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
name: 'Stanford Migrate' | ||
description: 'Adds more functionality to migrate and migrate plus modules' | ||
type: module | ||
core_version_requirement: ^8.8 || ^9 | ||
core_version_requirement: ^8.8 || ^9 || ^10 | ||
package: 'Stanford' | ||
version: 8.x-1.22 | ||
version: 8.x-1.23 | ||
dependencies: | ||
- drupal:migrate | ||
- migrate_plus:migrate_plus | ||
- migrate_tools:migrate_tools | ||
- readonly_field_widget:readonly_field_widget | ||
- ultimate_cron:ultimate_cron |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* stanford_migrate.install | ||
*/ | ||
|
||
/** | ||
* Install readonly_field_widget module. | ||
*/ | ||
function stanford_migrate_update_8001() { | ||
\Drupal::service('module_installer')->install(['readonly_field_widget']); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
readonly: | ||
css: | ||
component: | ||
css/stanford_migrate.readonly.css: {} | ||
dependencies: | ||
- seven/classy.messages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
tests/src/Kernel/Plugin/migrate/id_map/StanfordSqlTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Drupal\Tests\stanford_migrate\Kernel\Plugin\migrate\id_map; | ||
|
||
use Drupal\Core\Cache\Cache; | ||
use Drupal\migrate\MigrateExecutable; | ||
use Drupal\node\Entity\Node; | ||
use Drupal\stanford_migrate\Plugin\migrate\id_map\StanfordSql; | ||
use Drupal\Tests\stanford_migrate\Kernel\StanfordMigrateKernelTestBase; | ||
|
||
/** | ||
* Class StanfordSqlTest. | ||
* | ||
* @group stanford_migrate | ||
* @coversDefaultClass \Drupal\stanford_migrate\Plugin\migrate\id_map\StanfordSql | ||
*/ | ||
class StanfordSqlTest extends StanfordMigrateKernelTestBase { | ||
|
||
/** | ||
* Ensure the id map returns expected values. | ||
*/ | ||
public function testOverride() { | ||
\Drupal::configFactory() | ||
->getEditable('migrate_plus.migration.stanford_migrate') | ||
->set('destination.plugin', 'entity_reference_revisions:node') | ||
->set('source.urls', [dirname(__FILE__, 4) . '/test.xml']) | ||
->save(); | ||
Cache::invalidateTags(['migration_plugins']); | ||
|
||
$manager = \Drupal::service('plugin.manager.migration'); | ||
/** @var \Drupal\migrate\Plugin\Migration $migration */ | ||
$migration = $manager->createInstance('stanford_migrate'); | ||
$migrate_executable = new MigrateExecutable($migration); | ||
$migrate_executable->import(); | ||
|
||
$nodes = Node::loadMultiple(); | ||
$node = reset($nodes); | ||
|
||
$this->assertInstanceOf(StanfordSql::class, $migration->getIdMap()); | ||
$this->assertNotEmpty($migration->getIdMap() | ||
->getRowByDestination(['nid' => $node->id()])); | ||
$this->assertNotEmpty($migration->getIdMap() | ||
->getRowByDestination(['nid' => $node->id(), 'vid' => $node->getRevisionId()])); | ||
$this->assertEmpty($migration->getIdMap()->getRowByDestination([])); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters