Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / migrate / src / Plugin / migrate / destination / DestinationBase.php
1 <?php
2
3 namespace Drupal\migrate\Plugin\migrate\destination;
4
5 use Drupal\Core\Plugin\PluginBase;
6 use Drupal\migrate\Plugin\MigrationInterface;
7 use Drupal\migrate\Exception\RequirementsException;
8 use Drupal\migrate\Plugin\MigrateDestinationInterface;
9 use Drupal\migrate\Plugin\MigrateIdMapInterface;
10 use Drupal\migrate\Plugin\RequirementsInterface;
11
12 /**
13  * Base class for migrate destination classes.
14  *
15  * @see \Drupal\migrate\Plugin\MigrateDestinationInterface
16  * @see \Drupal\migrate\Plugin\MigrateDestinationPluginManager
17  * @see \Drupal\migrate\Annotation\MigrateDestination
18  * @see plugin_api
19  *
20  * @ingroup migration
21  */
22 abstract class DestinationBase extends PluginBase implements MigrateDestinationInterface, RequirementsInterface {
23
24   /**
25    * Indicates whether the destination can be rolled back.
26    *
27    * @var bool
28    */
29   protected $supportsRollback = FALSE;
30
31   /**
32    * The rollback action to be saved for the last imported item.
33    *
34    * @var int
35    */
36   protected $rollbackAction = MigrateIdMapInterface::ROLLBACK_DELETE;
37
38   /**
39    * The migration.
40    *
41    * @var \Drupal\migrate\Plugin\MigrationInterface
42    */
43   protected $migration;
44
45   /**
46    * Constructs an entity destination plugin.
47    *
48    * @param array $configuration
49    *   A configuration array containing information about the plugin instance.
50    * @param string $plugin_id
51    *   The plugin_id for the plugin instance.
52    * @param mixed $plugin_definition
53    *   The plugin implementation definition.
54    * @param \Drupal\migrate\Plugin\MigrationInterface $migration
55    *   The migration.
56    */
57   public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration) {
58     parent::__construct($configuration, $plugin_id, $plugin_definition);
59     $this->migration = $migration;
60   }
61
62   /**
63    * {@inheritdoc}
64    */
65   public function rollbackAction() {
66     return $this->rollbackAction;
67   }
68
69   /**
70    * {@inheritdoc}
71    */
72   public function checkRequirements() {
73     if (empty($this->pluginDefinition['requirements_met'])) {
74       throw new RequirementsException();
75     }
76   }
77
78   /**
79    * {@inheritdoc}
80    */
81   public function rollback(array $destination_identifier) {
82     // By default we do nothing.
83   }
84
85   /**
86    * {@inheritdoc}
87    */
88   public function supportsRollback() {
89     return $this->supportsRollback;
90   }
91
92   /**
93    * For a destination item being updated, set the appropriate rollback action.
94    *
95    * @param array $id_map
96    *   The map row data for the item.
97    * @param int $update_action
98    *   The rollback action to take if we are updating an existing item.
99    */
100   protected function setRollbackAction(array $id_map, $update_action = MigrateIdMapInterface::ROLLBACK_PRESERVE) {
101     // If the entity we're updating was previously migrated by us, preserve the
102     // existing rollback action.
103     if (isset($id_map['sourceid1'])) {
104       $this->rollbackAction = $id_map['rollback_action'];
105     }
106     // Otherwise, we're updating an entity which already existed on the
107     // destination and want to make sure we do not delete it on rollback.
108     else {
109       $this->rollbackAction = $update_action;
110     }
111   }
112
113   /**
114    * {@inheritdoc}
115    */
116   public function getDestinationModule() {
117     if (!empty($this->configuration['destination_module'])) {
118       return $this->configuration['destination_module'];
119     }
120     if (!empty($this->pluginDefinition['destination_module'])) {
121       return $this->pluginDefinition['destination_module'];
122     }
123     if (is_string($this->migration->provider)) {
124       return $this->migration->provider;
125     }
126     else {
127       return reset($this->migration->provider);
128     }
129   }
130
131 }