4

I have write a migration class to enter the value in custom table. But I want to know that how to rollback custom table entry.

I used :

public function complete($entity, stdClass $row) {
  // db_insert in my custom table
}

I want to rollback the above changes. For this I tried the completeRollback method below but it is not working.

public function completeRollback($entity_id) {
  dsm($entity_id);
}

2 Answers 2

1

You want to use prepareRollback() because at that point the thing that you are rolling back has not been removed yet.

public function prepareRollback($entity_id) {
  parent::prepareRollback();
  // Code to execute before an entity has been rolled back
}

Take a look at this guide for more info.

2
  • No luck..... :( Nov 18, 2014 at 16:35
  • this is in MigrateDestinationEntity, not Migrate class, fyi
    – troseman
    Nov 8, 2016 at 19:12
1

What I just did for the solutions is, I set the variable in complete function as like :

public function complete($entity, stdClass $row) {
  $migrated_variable = variable_get('migrated_variable', array());
  $migrated_variable[] = $entity->nid;
  variable_set('migrated_variable', $migrated_variable);
}

And used in postRollback function :

  public function postRollback() {
    parent::postRollback();
    $migrated_variable = variable_get('migrated_variable', array());
    foreach ($migrated_variable as $nid) {
      db_delete('custom_table')
        ->condition('nid', $nid)
        ->execute();
    }
    variable_del('migrated_variable');
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.