Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/migrate/src/MigrateExecutable.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | a9cd425dd02b |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
103 * @throws \Drupal\migrate\MigrateException | 103 * @throws \Drupal\migrate\MigrateException |
104 */ | 104 */ |
105 public function __construct(MigrationInterface $migration, MigrateMessageInterface $message = NULL, EventDispatcherInterface $event_dispatcher = NULL) { | 105 public function __construct(MigrationInterface $migration, MigrateMessageInterface $message = NULL, EventDispatcherInterface $event_dispatcher = NULL) { |
106 $this->migration = $migration; | 106 $this->migration = $migration; |
107 $this->message = $message ?: new MigrateMessage(); | 107 $this->message = $message ?: new MigrateMessage(); |
108 $this->migration->getIdMap()->setMessage($this->message); | 108 $this->getIdMap()->setMessage($this->message); |
109 $this->eventDispatcher = $event_dispatcher; | 109 $this->eventDispatcher = $event_dispatcher; |
110 // Record the memory limit in bytes | 110 // Record the memory limit in bytes |
111 $limit = trim(ini_get('memory_limit')); | 111 $limit = trim(ini_get('memory_limit')); |
112 if ($limit == '-1') { | 112 if ($limit == '-1') { |
113 $this->memoryLimit = PHP_INT_MAX; | 113 $this->memoryLimit = PHP_INT_MAX; |
180 } | 180 } |
181 | 181 |
182 $this->migration->setStatus(MigrationInterface::STATUS_IMPORTING); | 182 $this->migration->setStatus(MigrationInterface::STATUS_IMPORTING); |
183 $return = MigrationInterface::RESULT_COMPLETED; | 183 $return = MigrationInterface::RESULT_COMPLETED; |
184 $source = $this->getSource(); | 184 $source = $this->getSource(); |
185 $id_map = $this->migration->getIdMap(); | 185 $id_map = $this->getIdMap(); |
186 | 186 |
187 try { | 187 try { |
188 $source->rewind(); | 188 $source->rewind(); |
189 } | 189 } |
190 catch (\Exception $e) { | 190 catch (\Exception $e) { |
202 try { | 202 try { |
203 $this->processRow($row); | 203 $this->processRow($row); |
204 $save = TRUE; | 204 $save = TRUE; |
205 } | 205 } |
206 catch (MigrateException $e) { | 206 catch (MigrateException $e) { |
207 $this->migration->getIdMap()->saveIdMapping($row, [], $e->getStatus()); | 207 $this->getIdMap()->saveIdMapping($row, [], $e->getStatus()); |
208 $this->saveMessage($e->getMessage(), $e->getLevel()); | 208 $this->saveMessage($e->getMessage(), $e->getLevel()); |
209 $save = FALSE; | 209 $save = FALSE; |
210 } | 210 } |
211 catch (MigrateSkipRowException $e) { | 211 catch (MigrateSkipRowException $e) { |
212 if ($e->getSaveToMap()) { | 212 if ($e->getSaveToMap()) { |
239 $this->message->display($message); | 239 $this->message->display($message); |
240 } | 240 } |
241 } | 241 } |
242 } | 242 } |
243 catch (MigrateException $e) { | 243 catch (MigrateException $e) { |
244 $this->migration->getIdMap()->saveIdMapping($row, [], $e->getStatus()); | 244 $this->getIdMap()->saveIdMapping($row, [], $e->getStatus()); |
245 $this->saveMessage($e->getMessage(), $e->getLevel()); | 245 $this->saveMessage($e->getMessage(), $e->getLevel()); |
246 } | 246 } |
247 catch (\Exception $e) { | 247 catch (\Exception $e) { |
248 $this->migration->getIdMap()->saveIdMapping($row, [], MigrateIdMapInterface::STATUS_FAILED); | 248 $this->getIdMap()->saveIdMapping($row, [], MigrateIdMapInterface::STATUS_FAILED); |
249 $this->handleException($e); | 249 $this->handleException($e); |
250 } | 250 } |
251 } | 251 } |
252 | 252 |
253 $this->sourceRowStatus = MigrateIdMapInterface::STATUS_IMPORTED; | 253 $this->sourceRowStatus = MigrateIdMapInterface::STATUS_IMPORTED; |
297 // Optimistically assume things are going to work out; if not, $return will be | 297 // Optimistically assume things are going to work out; if not, $return will be |
298 // updated to some other status. | 298 // updated to some other status. |
299 $return = MigrationInterface::RESULT_COMPLETED; | 299 $return = MigrationInterface::RESULT_COMPLETED; |
300 | 300 |
301 $this->migration->setStatus(MigrationInterface::STATUS_ROLLING_BACK); | 301 $this->migration->setStatus(MigrationInterface::STATUS_ROLLING_BACK); |
302 $id_map = $this->migration->getIdMap(); | 302 $id_map = $this->getIdMap(); |
303 $destination = $this->migration->getDestinationPlugin(); | 303 $destination = $this->migration->getDestinationPlugin(); |
304 | 304 |
305 // Loop through each row in the map, and try to roll it back. | 305 // Loop through each row in the map, and try to roll it back. |
306 foreach ($id_map as $map_row) { | 306 $id_map->rewind(); |
307 while ($id_map->valid()) { | |
307 $destination_key = $id_map->currentDestination(); | 308 $destination_key = $id_map->currentDestination(); |
308 if ($destination_key) { | 309 if ($destination_key) { |
309 $map_row = $id_map->getRowByDestination($destination_key); | 310 $map_row = $id_map->getRowByDestination($destination_key); |
310 if ($map_row['rollback_action'] == MigrateIdMapInterface::ROLLBACK_DELETE) { | 311 if ($map_row['rollback_action'] == MigrateIdMapInterface::ROLLBACK_DELETE) { |
311 $this->getEventDispatcher() | 312 $this->getEventDispatcher() |
321 // If there is no destination key the import probably failed and we can | 322 // If there is no destination key the import probably failed and we can |
322 // remove the row without further action. | 323 // remove the row without further action. |
323 $source_key = $id_map->currentSource(); | 324 $source_key = $id_map->currentSource(); |
324 $id_map->delete($source_key); | 325 $id_map->delete($source_key); |
325 } | 326 } |
327 $id_map->next(); | |
326 | 328 |
327 // Check for memory exhaustion. | 329 // Check for memory exhaustion. |
328 if (($return = $this->checkStatus()) != MigrationInterface::RESULT_COMPLETED) { | 330 if (($return = $this->checkStatus()) != MigrationInterface::RESULT_COMPLETED) { |
329 break; | 331 break; |
330 } | 332 } |
340 // Notify modules that rollback attempt was complete. | 342 // Notify modules that rollback attempt was complete. |
341 $this->getEventDispatcher()->dispatch(MigrateEvents::POST_ROLLBACK, new MigrateRollbackEvent($this->migration)); | 343 $this->getEventDispatcher()->dispatch(MigrateEvents::POST_ROLLBACK, new MigrateRollbackEvent($this->migration)); |
342 $this->migration->setStatus(MigrationInterface::STATUS_IDLE); | 344 $this->migration->setStatus(MigrationInterface::STATUS_IDLE); |
343 | 345 |
344 return $return; | 346 return $return; |
347 } | |
348 | |
349 /** | |
350 * Get the ID map from the current migration. | |
351 * | |
352 * @return \Drupal\migrate\Plugin\MigrateIdMapInterface | |
353 * The ID map. | |
354 */ | |
355 protected function getIdMap() { | |
356 return $this->migration->getIdMap(); | |
345 } | 357 } |
346 | 358 |
347 /** | 359 /** |
348 * {@inheritdoc} | 360 * {@inheritdoc} |
349 */ | 361 */ |
414 | 426 |
415 /** | 427 /** |
416 * {@inheritdoc} | 428 * {@inheritdoc} |
417 */ | 429 */ |
418 public function saveMessage($message, $level = MigrationInterface::MESSAGE_ERROR) { | 430 public function saveMessage($message, $level = MigrationInterface::MESSAGE_ERROR) { |
419 $this->migration->getIdMap()->saveMessage($this->sourceIdValues, $message, $level); | 431 $this->getIdMap()->saveMessage($this->sourceIdValues, $message, $level); |
420 } | 432 } |
421 | 433 |
422 /** | 434 /** |
423 * Takes an Exception object and both saves and displays it. | 435 * Takes an Exception object and both saves and displays it. |
424 * | 436 * |