Last active
April 20, 2017 21:06
-
-
Save brooke-heaton/f5f57d1975f5155d953d74797cf39225 to your computer and use it in GitHub Desktop.
Rollback a subset idlist of a specific Drupal 7 migration
This file contains 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 | |
/** | |
* Rollback only 'articles' type nodes using the idlist option | |
* This is useful if you can't for some reason rollback the whole migration | |
*/ | |
function migration_update_7001() { | |
// Get the 'migrate' database and query for nodes that should not have been | |
// in our migration class - 52 is the term id for 'articles' | |
$results = Database::getConnection('default', 'migrate') | |
->query('SELECT * | |
FROM field_data_field_type fdft | |
WHERE fdft.field_type_tid = 52 | |
ORDER BY fdft.entity_id;'); | |
$article_nids = $results->fetchAllAssoc('entity_id'); | |
echo 'Rolling back ' . count($article_nids) . ' article Pages.'; | |
$idlist = implode(',', array_keys($article_nids)); | |
// rollback only the 'articles' types from the migration using 'idlist' option | |
migrate_static_registration(array('NARPage')); | |
$migration = Migration::getInstance('NARPage'); | |
$result = $migration->processRollback(array('idlist' => $idlist)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment