-
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.
Provide basic set of migration including examples.
Signed-off-by: Stefan Borchert <[email protected]>
- Loading branch information
Stefan Borchert
committed
Jul 1, 2017
1 parent
fae2891
commit 221c3f7
Showing
13 changed files
with
787 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace Drupal\up_migrate\Plugin\Derivative; | ||
|
||
use Drupal\Component\Plugin\Derivative\DeriverBase; | ||
use Drupal\Core\Config\Entity\ConfigEntityStorageInterface; | ||
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
/** | ||
* Provides menu links for migration groups. | ||
*/ | ||
class MigrationGroupMenuLink extends DeriverBase implements ContainerDeriverInterface { | ||
|
||
/** | ||
* The config storage. | ||
* | ||
* @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface | ||
*/ | ||
protected $configStorage; | ||
|
||
/** | ||
* Constructs a MigrationGroupMenuLink instance. | ||
* | ||
* @param \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $config_storage | ||
* The config storage. | ||
*/ | ||
public function __construct(ConfigEntityStorageInterface $config_storage) { | ||
$this->configStorage = $config_storage; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function create(ContainerInterface $container, $base_plugin_id) { | ||
return new static( | ||
$container->get('entity.manager')->getStorage('migration_group') | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getDerivativeDefinitions($base_plugin_definition) { | ||
$links = []; | ||
|
||
$groups = $this->configStorage->loadMultiple(); | ||
/* @var $group \Drupal\migrate_plus\Entity\MigrationGroupInterface */ | ||
foreach ($groups as $group) { | ||
$menu_link_id = "migration_group.{$group->id()}"; | ||
$links[$menu_link_id] = [ | ||
'id' => $menu_link_id, | ||
'title' => $group->label(), | ||
'description' => $group->get('description'), | ||
'route_name' => 'entity.migration.list', | ||
'route_parameters' => [ | ||
'migration_group' => $group->id(), | ||
], | ||
] + $base_plugin_definition; | ||
} | ||
|
||
return $links; | ||
} | ||
|
||
} |
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,45 @@ | ||
<?php | ||
|
||
namespace Drupal\up_migrate\Plugin\migrate\id_map; | ||
|
||
use Drupal\migrate\Plugin\migrate\id_map\Sql; | ||
|
||
/** | ||
* Defines a faster SQL based ID map implementation. | ||
* | ||
* Creates unique keys over source columns so joins and lookups are much faster. | ||
* | ||
* @PluginID("fastsql") | ||
*/ | ||
class FastSql extends Sql { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function ensureTables() { | ||
parent::ensureTables(); | ||
|
||
if ($this->getDatabase()->schema()->indexExists($this->mapTableName, 'source')) { | ||
return; | ||
} | ||
// Add unique index over all source columns. | ||
$count = 1; | ||
$string_fields = 0; | ||
$unique_fields = []; | ||
foreach ($this->migration->getSourcePlugin()->getIds() as $id_definition) { | ||
$unique_fields[] = 'sourceid' . $count++; | ||
if (isset($id_definition['type']) && ('string' === $id_definition['type'])) { | ||
$string_fields++; | ||
} | ||
} | ||
|
||
if ($string_fields > 2) { | ||
// Do not create unique index over more than 2 string fields. Otherwise | ||
// there is a great chance the key is too long (>767 bytes). | ||
return; | ||
} | ||
|
||
$this->getDatabase()->schema()->addUniqueKey($this->mapTableName, 'source', $unique_fields); | ||
} | ||
|
||
} |
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,40 @@ | ||
<?php | ||
|
||
namespace Drupal\up_migrate\Plugin\migrate\process; | ||
|
||
use Drupal\migrate\MigrateExecutableInterface; | ||
use Drupal\migrate\ProcessPluginBase; | ||
use Drupal\migrate\Row; | ||
|
||
/** | ||
* This plugin allows string replacements in the source value. | ||
* | ||
* Example: | ||
* <code> | ||
* process: | ||
* file_destination: | ||
* plugin: up_string_replace | ||
* # Remove unused parts in path. | ||
* 'field/image': '' | ||
* # Move all files into sub-directory. | ||
* 'public:https://': 'public:https://imported' | ||
* </code> | ||
* | ||
* @MigrateProcessPlugin( | ||
* id = "up_string_replace" | ||
* ) | ||
*/ | ||
class StringReplace extends ProcessPluginBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { | ||
$replacements = $this->configuration['replacements'] ?: []; | ||
if (!is_array($replacements)) { | ||
$replacements = [$replacements]; | ||
} | ||
return strtr($value, $replacements); | ||
} | ||
|
||
} |
Oops, something went wrong.