3 namespace Drupal\migrate\Plugin;
5 use Drupal\Component\Plugin\PluginInspectionInterface;
6 use Drupal\migrate\MigrateMessageInterface;
7 use Drupal\migrate\Row;
10 * Defines an interface for migrate ID mappings.
12 * Migrate ID mappings maintain a relation between source ID and destination ID
13 * for audit and rollback purposes.
15 interface MigrateIdMapInterface extends \Iterator, PluginInspectionInterface {
18 * Codes reflecting the current status of a map row.
20 const STATUS_IMPORTED = 0;
21 const STATUS_NEEDS_UPDATE = 1;
22 const STATUS_IGNORED = 2;
23 const STATUS_FAILED = 3;
26 * Codes reflecting how to handle the destination item on rollback.
28 const ROLLBACK_DELETE = 0;
29 const ROLLBACK_PRESERVE = 1;
32 * Saves a mapping from the source identifiers to the destination identifiers.
34 * Called upon import of one row, we record a mapping from the source ID to
35 * the destination ID. Also may be called, setting the third parameter to
36 * NEEDS_UPDATE, to signal an existing record should be re-migrated.
38 * @param \Drupal\migrate\Row $row
39 * The raw source data. We use the ID map derived from the source object
40 * to get the source identifier values.
41 * @param array $destination_id_values
42 * An array of destination identifier values.
44 * (optional) Status of the source row in the map. Defaults to
45 * self::STATUS_IMPORTED.
46 * @param int $rollback_action
47 * (optional) How to handle the destination object on rollback. Defaults to
48 * self::ROLLBACK_DELETE.
50 public function saveIdMapping(Row $row, array $destination_id_values, $status = self::STATUS_IMPORTED, $rollback_action = self::ROLLBACK_DELETE);
53 * Saves a message related to a source record in the migration message table.
55 * @param array $source_id_values
56 * The source identifier keyed values of the record, e.g. ['nid' => 5].
57 * @param string $message
58 * The message to record.
60 * (optional) The message severity. Defaults to
61 * MigrationInterface::MESSAGE_ERROR.
63 public function saveMessage(array $source_id_values, $message, $level = MigrationInterface::MESSAGE_ERROR);
66 * Retrieves an iterator over messages relate to source records.
68 * @param array $source_id_values
69 * (optional) The source identifier keyed values of the record, e.g.
70 * ['nid' => 5]. If empty (the default), all messages are retrieved.
72 * (optional) Message severity. If NULL (the default), retrieve messages of
76 * Retrieves an iterator over the message rows.
78 public function getMessageIterator(array $source_id_values = [], $level = NULL);
81 * Prepares to run a full update.
83 * Prepares this migration to run as an update - that is, in addition to
84 * unmigrated content (source records not in the map table) being imported,
85 * previously-migrated content will also be updated in place by marking all
86 * previously-imported content as ready to be re-imported.
88 public function prepareUpdate();
91 * Returns the number of processed items in the map.
94 * The count of records in the map table.
96 public function processedCount();
99 * Returns the number of imported items in the map.
102 * The number of imported items.
104 public function importedCount();
107 * Returns a count of items which are marked as needing update.
110 * The number of items which need updating.
112 public function updateCount();
115 * Returns the number of items that failed to import.
118 * The number of items that errored out.
120 public function errorCount();
123 * Returns the number of messages saved.
126 * The number of messages.
128 public function messageCount();
131 * Deletes the map and message entries for a given source record.
133 * @param array $source_id_values
134 * The source identifier keyed values of the record, e.g. ['nid' => 5].
135 * @param bool $messages_only
136 * (optional) TRUE to only delete the migrate messages. Defaults to FALSE.
138 public function delete(array $source_id_values, $messages_only = FALSE);
141 * Deletes the map and message table entries for a given destination row.
143 * @param array $destination_id_values
144 * The destination identifier key value pairs we should do the deletes for.
146 public function deleteDestination(array $destination_id_values);
149 * Clears all messages from the map.
151 public function clearMessages();
154 * Retrieves a row from the map table based on source identifier values.
156 * @param array $source_id_values
157 * The source identifier keyed values of the record, e.g. ['nid' => 5].
160 * The raw row data as an associative array.
162 public function getRowBySource(array $source_id_values);
165 * Retrieves a row by the destination identifiers.
167 * @param array $destination_id_values
168 * The destination identifier keyed values of the record, e.g. ['nid' => 5].
171 * The row(s) of data.
173 public function getRowByDestination(array $destination_id_values);
176 * Retrieves an array of map rows marked as needing update.
179 * The maximum number of rows to return.
182 * Array of map row objects that need updating.
184 public function getRowsNeedingUpdate($count);
187 * Looks up the source identifier.
189 * Given a (possibly multi-field) destination identifier value, return the
190 * (possibly multi-field) source identifier value mapped to it.
192 * @param array $destination_id_values
193 * The destination identifier keyed values of the record, e.g. ['nid' => 5].
196 * The source identifier keyed values of the record, e.g. ['nid' => 5], or
197 * an empty array on failure.
199 public function lookupSourceId(array $destination_id_values);
202 * Looks up the destination identifier corresponding to a source key.
204 * Given a (possibly multi-field) source identifier value, return the
205 * (possibly multi-field) destination identifier value it is mapped to.
207 * @param array $source_id_values
208 * The source identifier keyed values of the record, e.g. ['nid' => 5].
211 * The destination identifier values of the record, or empty on failure.
213 * @deprecated in Drupal 8.1.x, will be removed before Drupal 9.0.x. Use
214 * lookupDestinationIds() instead.
216 * @see https://www.drupal.org/node/2725809
218 public function lookupDestinationId(array $source_id_values);
221 * Looks up the destination identifiers corresponding to a source key.
223 * This can look up a subset of source keys if only some are provided, and
224 * will return all destination keys that match.
226 * @param array $source_id_values
227 * The source identifier keyed values of the records, e.g. ['nid' => 5].
228 * If unkeyed, the first count($source_id_values) keys will be assumed.
231 * An array of arrays of destination identifier values.
233 * @throws \Drupal\migrate\MigrateException
234 * Thrown when $source_id_values contains unknown keys, or is the wrong
237 public function lookupDestinationIds(array $source_id_values);
240 * Looks up the destination identifier currently being iterated.
243 * The destination identifier values of the record, or NULL on failure.
245 public function currentDestination();
248 * Looks up the source identifier(s) currently being iterated.
251 * The source identifier values of the record, or NULL on failure.
253 public function currentSource();
256 * Removes any persistent storage used by this map.
258 * For example, remove the map and message tables.
260 public function destroy();
263 * Gets the qualified map table.
265 * @todo Remove this as this is SQL only and so doesn't belong to the interface.
267 public function getQualifiedMapTableName();
270 * Sets the migrate message service.
272 * @param \Drupal\migrate\MigrateMessageInterface $message
273 * The migrate message service.
275 public function setMessage(MigrateMessageInterface $message);
278 * Sets a specified record to be updated, if it exists.
280 * @param array $source_id_values
281 * The source identifier values of the record.
283 public function setUpdate(array $source_id_values);