Skip to content

Instantly share code, notes, and snippets.

@chx
Last active September 13, 2023 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chx/3a5e9b648f08259bd6bfc8b6c1521ac9 to your computer and use it in GitHub Desktop.
Save chx/3a5e9b648f08259bd6bfc8b6c1521ac9 to your computer and use it in GitHub Desktop.
Media migration
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
<?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