Yaffs site version 1.1
[yaffs-website] / web / modules / contrib / migrate_plus / migrate_example / src / Plugin / migrate / source / BeerTerm.php
1 <?php
2
3 namespace Drupal\migrate_example\Plugin\migrate\source;
4
5 use Drupal\migrate\Plugin\migrate\source\SqlBase;
6
7 /**
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.
13  *
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.
17  *
18  * @MigrateSource(
19  *   id = "beer_term"
20  * )
21  */
22 class BeerTerm extends SqlBase {
23
24   /**
25    * {@inheritdoc}
26    */
27   public function query() {
28     /**
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
34      * source plugin.
35      */
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');
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   public function fields() {
46     /**
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
51      */
52     $fields = [
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
57       // don't need.
58       'region' => $this->t('Region the style is associated with'),
59       'hoppiness' => $this->t('Hoppiness of the style'),
60     ];
61
62     return $fields;
63   }
64
65   /**
66    * {@inheritdoc}
67    */
68   public function getIds() {
69     /**
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.
76      */
77     return [
78       'style' => [
79         'type' => 'string',
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.
83         'alias' => 'met',
84       ],
85     ];
86   }
87
88 }