Mercurial > hg > isophonics-drupal-site
comparison core/modules/migrate/migrate.api.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
8 use Drupal\migrate\Plugin\MigrationInterface; | 8 use Drupal\migrate\Plugin\MigrationInterface; |
9 use Drupal\migrate\Plugin\MigrateSourceInterface; | 9 use Drupal\migrate\Plugin\MigrateSourceInterface; |
10 use Drupal\migrate\Row; | 10 use Drupal\migrate\Row; |
11 | 11 |
12 /** | 12 /** |
13 * @defgroup migration Migration API | 13 * @defgroup migration Migrate API |
14 * @{ | 14 * @{ |
15 * Overview of the Migration API, which migrates data into Drupal. | 15 * Overview of the Migrate API, which migrates data into Drupal. |
16 * | 16 * |
17 * @section overview Overview of migration | 17 * @section overview Overview of a migration |
18 * Migration is an | 18 * Migration is an |
19 * @link http://wikipedia.org/wiki/Extract,_transform,_load Extract, Transform, Load @endlink | 19 * @link http://wikipedia.org/wiki/Extract,_transform,_load Extract, Transform, Load @endlink |
20 * (ETL) process. In the Drupal migration API the extract phase is called | 20 * (ETL) process. In the Drupal Migrate API, the extract phase is called |
21 * "source", the transform phase is called "process", and the load phase is | 21 * 'source', the transform phase is called 'process', and the load phase is |
22 * called "destination". It is important to understand that the "load" in ETL | 22 * called 'destination'. It is important to understand that the term 'load' in |
23 * means to load data into storage, while traditionally Drupal uses "load" to | 23 * ETL refers to loading data into the storage while in a typical Drupal context |
24 * mean load data from storage into memory. | 24 * the term 'load' refers to loading data from storage. |
25 * | 25 * |
26 * In the source phase, a set of data, called the row, is retrieved from the | 26 * In the source phase, a set of data, called the row, is retrieved from the |
27 * data source, typically a database but it can be a CSV, JSON or XML file. The | 27 * data source. The data can be migrated from a database, loaded from a file |
28 * row is sent to the process phase where it is transformed as needed by the | 28 * (for example CSV, JSON or XML) or fetched from a web service (for example RSS |
29 * destination, or marked to be skipped. Processing can also determine that a | 29 * or REST). The row is sent to the process phase where it is transformed as |
30 * stub needs to be created, for example, if a term has a parent term that does | 30 * needed or marked to be skipped. Processing can also determine if a 'stub' |
31 * not yet exist. After processing the transformed row is passed to the | 31 * needs to be created. For example, if a term has a parent term which hasn't |
32 * destination phase where it is loaded (saved) into the Drupal 8 site. | 32 * been migrated yet, a stub term is created so that the parent relation can be |
33 * established, and the stub is updated at a later point. After processing, the | |
34 * transformed row is passed to the destination phase where it is loaded (saved) | |
35 * into the target Drupal site. | |
33 * | 36 * |
34 * The ETL process is configured by the migration plugin. The different phases: | 37 * Migrate API uses the Drupal plugin system for many different purposes. Most |
35 * source, process, and destination are also plugins, and are managed by the | 38 * importantly, the overall ETL process is defined as a migration plugin and the |
36 * Migration plugin. So there are four types of plugins in the migration | 39 * three phases (source, process and destination) have their own plugin types. |
37 * process: migration, source, process and destination. | |
38 * | 40 * |
39 * @section sec_migrations Migration plugins | 41 * @section sec_migrations Migrate API migration plugins |
40 * Migration plugin definitions are stored in a module's 'migrations' directory. | 42 * Migration plugin definitions are stored in a module's 'migrations' directory. |
41 * For backwards compatibility we also scan the 'migration_templates' directory. | 43 * The plugin class is \Drupal\migrate\Plugin\Migration, with interface |
42 * Examples of migration plugin definitions can be found in | |
43 * 'core/modules/action/migration_templates'. The plugin class is | |
44 * \Drupal\migrate\Plugin\Migration, with interface | |
45 * \Drupal\migrate\Plugin\MigrationInterface. Migration plugins are managed by | 44 * \Drupal\migrate\Plugin\MigrationInterface. Migration plugins are managed by |
46 * the \Drupal\migrate\Plugin\MigrationPluginManager class. Migration plugins | 45 * the \Drupal\migrate\Plugin\MigrationPluginManager class. Migration plugins |
47 * are only available if the providers of their source plugins are installed. | 46 * are only available if the providers of their source plugins are installed. |
48 * | 47 * |
49 * @section sec_source Source plugins | 48 * @link https://www.drupal.org/docs/8/api/migrate-api/migrate-destination-plugins-examples Example migrations in Migrate API handbook. @endlink |
50 * Migration source plugins implement | 49 * |
50 * @section sec_source Migrate API source plugins | |
51 * Migrate API source plugins implement | |
51 * \Drupal\migrate\Plugin\MigrateSourceInterface and usually extend | 52 * \Drupal\migrate\Plugin\MigrateSourceInterface and usually extend |
52 * \Drupal\migrate\Plugin\migrate\source\SourcePluginBase. They are annotated | 53 * \Drupal\migrate\Plugin\migrate\source\SourcePluginBase. They are annotated |
53 * with \Drupal\migrate\Annotation\MigrateSource annotation, and must be in | 54 * with \Drupal\migrate\Annotation\MigrateSource annotation and must be in |
54 * namespace subdirectory Plugin\migrate\source under the namespace of the | 55 * namespace subdirectory 'Plugin\migrate\source' under the namespace of the |
55 * module that defines them. Migration source plugins are managed by the | 56 * module that defines them. Migrate API source plugins are managed by the |
56 * \Drupal\migrate\Plugin\MigrateSourcePluginManager class. Source plugin | 57 * \Drupal\migrate\Plugin\MigrateSourcePluginManager class. |
57 * providers are determined by their and their parents namespaces. | |
58 * | 58 * |
59 * @section sec_process Process plugins | 59 * @link https://api.drupal.org/api/drupal/namespace/Drupal!migrate!Plugin!migrate!source List of source plugins provided by the core Migrate module. @endlink |
60 * Migration process plugins implement | 60 * @link https://www.drupal.org/docs/8/api/migrate-api/migrate-source-plugins Core and contributed source plugin usage examples in Migrate API handbook. @endlink |
61 * | |
62 * @section sec_process Migrate API process plugins | |
63 * Migrate API process plugins implement | |
61 * \Drupal\migrate\Plugin\MigrateProcessInterface and usually extend | 64 * \Drupal\migrate\Plugin\MigrateProcessInterface and usually extend |
62 * \Drupal\migrate\ProcessPluginBase. They are annotated | 65 * \Drupal\migrate\ProcessPluginBase. They are annotated with |
63 * with \Drupal\migrate\Annotation\MigrateProcessPlugin annotation, and must be | 66 * \Drupal\migrate\Annotation\MigrateProcessPlugin annotation and must be in |
64 * in namespace subdirectory Plugin\migrate\process under the namespace of the | 67 * namespace subdirectory 'Plugin\migrate\process' under the namespace of the |
65 * module that defines them. Migration process plugins are managed by the | 68 * module that defines them. Migrate API process plugins are managed by the |
66 * \Drupal\migrate\Plugin\MigratePluginManager class. The Migrate module | 69 * \Drupal\migrate\Plugin\MigratePluginManager class. |
67 * provides process plugins for common operations (setting default values, | |
68 * mapping values, etc.). | |
69 * | 70 * |
70 * @section sec_destination Destination plugins | 71 * @link https://api.drupal.org/api/drupal/namespace/Drupal!migrate!Plugin!migrate!process List of process plugins for common operations provided by the core Migrate module. @endlink |
71 * Migration destination plugins implement | 72 * |
73 * @section sec_destination Migrate API destination plugins | |
74 * Migrate API destination plugins implement | |
72 * \Drupal\migrate\Plugin\MigrateDestinationInterface and usually extend | 75 * \Drupal\migrate\Plugin\MigrateDestinationInterface and usually extend |
73 * \Drupal\migrate\Plugin\migrate\destination\DestinationBase. They are | 76 * \Drupal\migrate\Plugin\migrate\destination\DestinationBase. They are |
74 * annotated with \Drupal\migrate\Annotation\MigrateDestination annotation, and | 77 * annotated with \Drupal\migrate\Annotation\MigrateDestination annotation and |
75 * must be in namespace subdirectory Plugin\migrate\destination under the | 78 * must be in namespace subdirectory 'Plugin\migrate\destination' under the |
76 * namespace of the module that defines them. Migration destination plugins | 79 * namespace of the module that defines them. Migrate API destination plugins |
77 * are managed by the \Drupal\migrate\Plugin\MigrateDestinationPluginManager | 80 * are managed by the \Drupal\migrate\Plugin\MigrateDestinationPluginManager |
78 * class. The Migrate module provides destination plugins for Drupal core | 81 * class. |
79 * objects (configuration and entity). | |
80 * | 82 * |
81 * @section sec_more_info More information | 83 * @link https://api.drupal.org/api/drupal/namespace/Drupal!migrate!Plugin!migrate!destination List of destination plugins for Drupal configuration and content entities provided by the core Migrate module. @endlink |
82 * @link https://www.drupal.org/node/2127611 Migration API documentation. @endlink | |
83 * | 84 * |
84 * @see update_api | 85 * @section sec_more_info Documentation handbooks |
86 * @link https://www.drupal.org/docs/8/api/migrate-api Migrate API handbook. @endlink | |
87 * @link https://www.drupal.org/docs/8/upgrade Upgrading to Drupal 8 handbook. @endlink | |
85 * @} | 88 * @} |
86 */ | 89 */ |
87 | 90 |
88 /** | 91 /** |
89 * @addtogroup hooks | 92 * @addtogroup hooks |
97 * variables table which now needs to be inside the filter format config | 100 * variables table which now needs to be inside the filter format config |
98 * file. So, it needs to be added here. | 101 * file. So, it needs to be added here. |
99 * | 102 * |
100 * hook_migrate_MIGRATION_ID_prepare_row() is also available. | 103 * hook_migrate_MIGRATION_ID_prepare_row() is also available. |
101 * | 104 * |
105 * @param \Drupal\migrate\Row $row | |
106 * The row being imported. | |
107 * @param \Drupal\migrate\Plugin\MigrateSourceInterface $source | |
108 * The source migration. | |
109 * @param \Drupal\migrate\Plugin\MigrationInterface $migration | |
110 * The current migration. | |
111 * | |
102 * @ingroup migration | 112 * @ingroup migration |
103 */ | 113 */ |
104 function hook_migrate_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration) { | 114 function hook_migrate_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration) { |
105 if ($migration->id() == 'd6_filter_formats') { | 115 if ($migration->id() == 'd6_filter_formats') { |
106 $value = $source->getDatabase()->query('SELECT value FROM {variable} WHERE name = :name', [':name' => 'mymodule_filter_foo_' . $row->getSourceProperty('format')])->fetchField(); | 116 $value = $source->getDatabase()->query('SELECT value FROM {variable} WHERE name = :name', [':name' => 'mymodule_filter_foo_' . $row->getSourceProperty('format')])->fetchField(); |
107 if ($value) { | 117 if ($value) { |
108 $row->setSourceProperty('settings:mymodule:foo', unserialize($value)); | 118 $row->setSourceProperty('settings:mymodule:foo', unserialize($value)); |
109 } | 119 } |
120 } | |
121 } | |
122 | |
123 /** | |
124 * Allows adding data to a row for a migration with the specified ID. | |
125 * | |
126 * This provides the same functionality as hook_migrate_prepare_row() but | |
127 * removes the need to check the value of $migration->id(). | |
128 * | |
129 * @param \Drupal\migrate\Row $row | |
130 * The row being imported. | |
131 * @param \Drupal\migrate\Plugin\MigrateSourceInterface $source | |
132 * The source migration. | |
133 * @param \Drupal\migrate\Plugin\MigrationInterface $migration | |
134 * The current migration. | |
135 * | |
136 * @ingroup migration | |
137 */ | |
138 function hook_migrate_MIGRATION_ID_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration) { | |
139 $value = $source->getDatabase()->query('SELECT value FROM {variable} WHERE name = :name', [':name' => 'mymodule_filter_foo_' . $row->getSourceProperty('format')])->fetchField(); | |
140 if ($value) { | |
141 $row->setSourceProperty('settings:mymodule:foo', unserialize($value)); | |
110 } | 142 } |
111 } | 143 } |
112 | 144 |
113 /** | 145 /** |
114 * Allows altering the list of discovered migration plugins. | 146 * Allows altering the list of discovered migration plugins. |