Created
July 16, 2018 02:37
-
-
Save Unifex/d73a357992528a44f0f67ff4bdfcb3bc to your computer and use it in GitHub Desktop.
A Drupal 8 Migrate destination plugin that does nothing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\migrate_nbr\Plugin\migrate\destination; | |
use Drupal\migrate\Plugin\MigrationInterface; | |
use Drupal\migrate\Plugin\migrate\destination\DestinationBase; | |
use Drupal\migrate\Row; | |
/** | |
* Provides noop destination plugin. | |
* | |
* Sometimes you want to use the migrate system for more, or less, that it was | |
* designed for and this means not having anything to do in the destination | |
* plugin. e.g. your migration is too far in to back out and you need to 'fix' | |
* something. A quick lightweight migration where the work happens in the | |
* process section could do this. | |
* | |
* This destination plugin is a 'quickfix' to the `null` destination plugin | |
* always throwing false for `requirements_met`. I think this also sounds more | |
* 'correct' in describing what the plugin does. | |
* | |
* @MigrateDestination( | |
* id = "noop" | |
* ) | |
*/ | |
class NoOp extends DestinationBase { | |
/** | |
* {@inheritdoc} | |
*/ | |
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration) { | |
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration); | |
$this->supportsRollback = FALSE; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getIds() { | |
return []; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function fields(MigrationInterface $migration = NULL) { | |
return []; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function import(Row $row, array $old_destination_id_values = []) { | |
// The no-op always succeeds. Returning TRUE here prevents a 'failed' | |
// being thrown. However, it also gives no indication of progress. | |
return TRUE; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function saveIdMapping(Row $row, array $destination_id_values, $source_row_status = MigrateIdMapInterface::STATUS_IMPORTED, $rollback_action = MigrateIdMapInterface::ROLLBACK_DELETE) { | |
// Do nothing. | |
} | |
} |
Hitting this a bit later, but finding the approach useful. To get past @havran's issue from https://gist.github.com/Unifex/d73a357992528a44f0f67ff4bdfcb3bc?permalink_comment_id=2755099#gistcomment-2755099, it's possible to specify an ID field:
/**
* {@inheritdoc}
*/
public function getIds() {
return [
'noop' => [
'type' => 'string',
],
];
}
/**
* {@inheritdoc}
*/
public function fields(MigrationInterface $migration = NULL) {
return [
'noop' => $this->t('Nothing'),
];
}
There should never be any value there, but it appears to satisfy whatever internals that are trying to make use of ID columns.
If already encountering the issue, it may be necessary to:
- drop the related
migrate_map_
table for the no-op migration drush migrate:reset-status
the target migration
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, thanks for plugin. I have one small issue - rollback is failed because mapping table is created without destid1 field. Is this intended?