Last active
September 13, 2023 09:52
-
-
Save chx/3a5e9b648f08259bd6bfc8b6c1521ac9 to your computer and use it in GitHub Desktop.
Media migration
This file contains hidden or 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
id: foo_media | |
label: Foo media | |
source: | |
plugin: sd8_table | |
table: migrate_map_foo_file | |
ids: | |
sourceid1: | |
type: integer | |
# The table plugin sets the alias to t and this must be specified | |
# otherwise SqlBase::initializeIterator() dies with a SQL error when it | |
# joins the map table for this migration which also contains fields called | |
# sourceid1 and sourceid2. | |
alias: t | |
sourceid2: | |
type: string | |
alias: t | |
process: | |
field_media_image: destid1 | |
destination: | |
plugin: entity:media | |
default_bundle: image | |
migration_dependencies: | |
required: | |
- migrate_map_foo |
This file contains hidden or 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
<?php | |
namespace Drupal\sd8_import\Plugin\migrate\source; | |
use Drupal\migrate\Plugin\migrate\source\SqlBase; | |
/** | |
* Table source from database. | |
* | |
* @MigrateSource( | |
* id = "sd8_table", | |
* source_module = "sd8" | |
* ) | |
*/ | |
class Table extends SqlBase { | |
/** | |
* @return \Drupal\Core\Database\Query\SelectInterface | |
*/ | |
public function query() { | |
$query = $this->select($this->configuration['table'], 't') | |
->fields('t'); | |
foreach (array_keys($this->getIds()) as $id) { | |
$query->orderBy($id); | |
} | |
return $query; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getIds() { | |
return $this->configuration['ids']; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function fields() { | |
return []; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment