Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\migrate_plus\Entity;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\Cache\Cache;
|
Chris@0
|
6 use Drupal\Core\Config\Entity\ConfigEntityBase;
|
Chris@0
|
7 use Drupal\Core\Entity\EntityTypeInterface;
|
Chris@0
|
8
|
Chris@0
|
9 /**
|
Chris@0
|
10 * Defines the Migration entity.
|
Chris@0
|
11 *
|
Chris@0
|
12 * The migration entity stores the information about a single migration, like
|
Chris@0
|
13 * the source, process and destination plugins.
|
Chris@0
|
14 *
|
Chris@0
|
15 * @ConfigEntityType(
|
Chris@0
|
16 * id = "migration",
|
Chris@0
|
17 * label = @Translation("Migration"),
|
Chris@0
|
18 * entity_keys = {
|
Chris@0
|
19 * "id" = "id",
|
Chris@0
|
20 * "label" = "label",
|
Chris@0
|
21 * "weight" = "weight"
|
Chris@0
|
22 * }
|
Chris@0
|
23 * )
|
Chris@0
|
24 */
|
Chris@0
|
25 class Migration extends ConfigEntityBase implements MigrationInterface {
|
Chris@0
|
26
|
Chris@0
|
27 /**
|
Chris@0
|
28 * The migration ID (machine name).
|
Chris@0
|
29 *
|
Chris@0
|
30 * @var string
|
Chris@0
|
31 */
|
Chris@0
|
32 protected $id;
|
Chris@0
|
33
|
Chris@0
|
34 /**
|
Chris@0
|
35 * The human-readable label for the migration.
|
Chris@0
|
36 *
|
Chris@0
|
37 * @var string
|
Chris@0
|
38 */
|
Chris@0
|
39 protected $label;
|
Chris@0
|
40
|
Chris@0
|
41 /**
|
Chris@0
|
42 * {@inheritdoc}
|
Chris@0
|
43 */
|
Chris@0
|
44 protected function invalidateTagsOnSave($update) {
|
Chris@0
|
45 parent::invalidateTagsOnSave($update);
|
Chris@0
|
46 Cache::invalidateTags(['migration_plugins']);
|
Chris@0
|
47 }
|
Chris@0
|
48
|
Chris@0
|
49 /**
|
Chris@0
|
50 * {@inheritdoc}
|
Chris@0
|
51 */
|
Chris@0
|
52 protected static function invalidateTagsOnDelete(EntityTypeInterface $entity_type, array $entities) {
|
Chris@0
|
53 parent::invalidateTagsOnDelete($entity_type, $entities);
|
Chris@0
|
54 Cache::invalidateTags(['migration_plugins']);
|
Chris@0
|
55 }
|
Chris@0
|
56
|
Chris@0
|
57 /**
|
Chris@0
|
58 * Create a configuration entity from a core migration plugin's configuration.
|
Chris@0
|
59 *
|
Chris@0
|
60 * @param string $plugin_id
|
Chris@0
|
61 * ID of a migration plugin managed by MigrationPluginManager.
|
Chris@0
|
62 * @param string $new_plugin_id
|
Chris@0
|
63 * ID to use for the new configuration entity.
|
Chris@0
|
64 *
|
Chris@0
|
65 * @return \Drupal\migrate_plus\Entity\MigrationInterface
|
Chris@0
|
66 * A Migration configuration entity (not saved to persistent storage).
|
Chris@0
|
67 */
|
Chris@0
|
68 public static function createEntityFromPlugin($plugin_id, $new_plugin_id) {
|
Chris@0
|
69 /** @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface $plugin_manager */
|
Chris@0
|
70 $plugin_manager = \Drupal::service('plugin.manager.migration');
|
Chris@0
|
71 $migration_plugin = $plugin_manager->createInstance($plugin_id);
|
Chris@0
|
72 $entity_array['id'] = $new_plugin_id;
|
Chris@0
|
73 $entity_array['migration_tags'] = $migration_plugin->get('migration_tags');
|
Chris@0
|
74 $entity_array['label'] = $migration_plugin->label();
|
Chris@0
|
75 $entity_array['source'] = $migration_plugin->getSourceConfiguration();
|
Chris@0
|
76 $entity_array['destination'] = $migration_plugin->getDestinationConfiguration();
|
Chris@0
|
77 $entity_array['process'] = $migration_plugin->getProcess();
|
Chris@0
|
78 $entity_array['migration_dependencies'] = $migration_plugin->getMigrationDependencies();
|
Chris@0
|
79 $migration_entity = static::create($entity_array);
|
Chris@0
|
80 return $migration_entity;
|
Chris@0
|
81 }
|
Chris@0
|
82
|
Chris@0
|
83 }
|