3 namespace Drupal\migrate\Plugin\migrate\destination;
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;
13 * Base class for migrate destination classes.
15 * Migrate destination plugins perform the import operation of the migration.
16 * Destination plugins extend this abstract base class. A destination plugin
17 * must implement at least fields(), getIds() and import() methods. Destination
18 * plugins can also support rollback operations. For more
19 * information, refer to \Drupal\migrate\Plugin\MigrateDestinationInterface.
21 * @see \Drupal\migrate\Plugin\MigrateDestinationPluginManager
22 * @see \Drupal\migrate\Annotation\MigrateDestination
27 abstract class DestinationBase extends PluginBase implements MigrateDestinationInterface, RequirementsInterface {
30 * Indicates whether the destination can be rolled back.
34 protected $supportsRollback = FALSE;
37 * The rollback action to be saved for the last imported item.
41 protected $rollbackAction = MigrateIdMapInterface::ROLLBACK_DELETE;
46 * @var \Drupal\migrate\Plugin\MigrationInterface
51 * Constructs an entity destination plugin.
53 * @param array $configuration
54 * A configuration array containing information about the plugin instance.
55 * @param string $plugin_id
56 * The plugin_id for the plugin instance.
57 * @param mixed $plugin_definition
58 * The plugin implementation definition.
59 * @param \Drupal\migrate\Plugin\MigrationInterface $migration
62 public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration) {
63 parent::__construct($configuration, $plugin_id, $plugin_definition);
64 $this->migration = $migration;
70 public function rollbackAction() {
71 return $this->rollbackAction;
77 public function checkRequirements() {
78 if (empty($this->pluginDefinition['requirements_met'])) {
79 throw new RequirementsException();
86 public function rollback(array $destination_identifier) {
87 // By default we do nothing.
93 public function supportsRollback() {
94 return $this->supportsRollback;
98 * For a destination item being updated, set the appropriate rollback action.
100 * @param array $id_map
101 * The map row data for the item.
102 * @param int $update_action
103 * The rollback action to take if we are updating an existing item.
105 protected function setRollbackAction(array $id_map, $update_action = MigrateIdMapInterface::ROLLBACK_PRESERVE) {
106 // If the entity we're updating was previously migrated by us, preserve the
107 // existing rollback action.
108 if (isset($id_map['sourceid1'])) {
109 $this->rollbackAction = $id_map['rollback_action'];
111 // Otherwise, we're updating an entity which already existed on the
112 // destination and want to make sure we do not delete it on rollback.
114 $this->rollbackAction = $update_action;
121 public function getDestinationModule() {
122 if (!empty($this->configuration['destination_module'])) {
123 return $this->configuration['destination_module'];
125 if (!empty($this->pluginDefinition['destination_module'])) {
126 return $this->pluginDefinition['destination_module'];
128 if (is_string($this->migration->provider)) {
129 return $this->migration->provider;
132 return reset($this->migration->provider);