The Redirect module cleans up it's redirects when an entity is deleted using the following code:

<?php
/**
 * Implements hook_entity_delete().
 */
function redirect_entity_delete($entity, $entity_type) {
  if (redirect_entity_type_supports_redirects($entity_type)) {
    redirect_delete_by_entity_path($entity_type, $entity);
  }
}
?>

However, the Migrate module uses

<?php
node_delete_multiple($nids);
?>

So hook_entity_delete() is never called. Is it possible that Migrate uses hook_entity_delete() as well, so that Redirects are deleted as well on rollbacks?

Comments

mikeryan’s picture

Status: Active » Postponed (maintainer needs more info)

hook_entity_delete() has nothing to do with the contrib Entity API's entity_delete() function, it is a core hook that is invoked when core entities are deleted - in particular in this case, it is invoked by node_delete_multiple(). Are you sure redirect_entity_delete() is not being called? What precisely is the symptom?

marty2081’s picture

Our use case is that we want the old (ugly) paths of entities to redirect to the new path of the migrated entity. We accomplish this by creating redirects using the Redirect module's redirect_save() function in the complete() function of the Migration class. This works fine:

     $redirect = new stdClass();
     redirect_object_prepare($redirect);
     $redirect->source = $row->path;
     $redirect->redirect = $new_path;
     $redirect->language = LANGUAGE_NONE;
     redirect_save($redirect);

Where $new_path is obviously the new path alias for the migrated entity.

When we perform a rollback of a migration however, the redirects are not removed. BarisW thought the issue was with hook_entity_delete() not being called.

mikeryan’s picture

Don't forget to reset the issue status to "active" if you want your response to be reviewed in a timely fashion.

I think you need to dive a little deeper here - first, confirm whether redirect_entity_delete() is actually being called. Note that there is migration support for the redirect module in the issue queue: #1116408: Support migrate module: Destination handler class.

mikeryan’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)