3 namespace Drupal\migrate_example\Plugin\migrate\source;
5 use Drupal\migrate\Plugin\migrate\source\SqlBase;
8 * This is an example of a simple SQL-based source plugin. Source plugins are
9 * classes which deliver source data to the processing pipeline. For SQL
10 * sources, the SqlBase class provides most of the functionality needed - for
11 * a specific migration, you are required to implement the three simple public
12 * methods you see below.
14 * This annotation tells Drupal that the name of the MigrateSource plugin
15 * implemented by this class is "beer_term". This is the name that the migration
16 * configuration references with the source "plugin" key.
22 class BeerTerm extends SqlBase {
27 public function query() {
29 * The most important part of a SQL source plugin is the SQL query to
30 * retrieve the data to be imported. Note that the query is not executed
31 * here - the migration process will control execution of the query. Also
32 * note that it is constructed from a $this->select() call - this ensures
33 * that the query is executed against the database configured for this
36 return $this->select('migrate_example_beer_topic', 'met')
37 ->fields('met', ['style', 'details', 'style_parent', 'region', 'hoppiness'])
38 // We sort this way to ensure parent terms are imported first.
39 ->orderBy('style_parent', 'ASC');
45 public function fields() {
47 * This method simply documents the available source fields provided by
48 * the source plugin, for use by front-end tools. It returns an array keyed
49 * by field/column name, with the value being a translated string explaining
50 * to humans what the field represents. You should always
53 'style' => $this->t('Account ID'),
54 'details' => $this->t('Blocked/Allowed'),
55 'style_parent' => $this->t('Registered date'),
56 // These values are not currently migrated - it's OK to skip fields you
58 'region' => $this->t('Region the style is associated with'),
59 'hoppiness' => $this->t('Hoppiness of the style'),
68 public function getIds() {
70 * This method indicates what field(s) from the source row uniquely identify
71 * that source row, and what their types are. This is critical information
72 * for managing the migration. The keys of the returned array are the field
73 * names from the query which comprise the unique identifier. The values are
74 * arrays indicating the type of the field, used for creating compatible
75 * columns in the map tables that track processed items.
80 // 'alias' is the alias for the table containing 'style' in the query
81 // defined above. Optional in this case, but necessary if the same
82 // column may occur in multiple tables in a join.