0

When I last went to update the URL redirect module from 8.x-1.4 to its latest version I saw this note:

After 8.x-1.4 version URL Redirect changed as config entity. If you are using before 8.x-1.4 version, it's strongly recommended to not upgrade module as it deletes all existing redirects in your system.

Since I didn't want to lose all my redirects, I just left the module as it was. Unfortunately, as of yesterday, v8.x-1.4 is no longer supported.

What is the best fix for updating this module?
Is it just a matter of updating to v8.x-2.3 and redoing the redirects (fortunately I do not have a lot of redirects) or is there an easier way of doing it?

1

You can update module to v8.x-2.3 and run drush updb or update.php. In 8.x-2.3 version all existing redirects get converted to an entity in an update hook.

/**
 * Migrate old redirect data.
 */
function url_redirect_update_8103() {

  $db_connection = \Drupal::database();

  if ($db_connection->schema()->tableExists('url_redirect')) {
    $query = $db_connection->select('url_redirect', 'ur');
    $query->fields('ur');
    $all_data = $query->execute()->fetchAll();

    foreach ($all_data as $key => $data) {
      $values = array(
          'label' => 'Migrated Redirect',
          'id' => 'migrated_' . $key . '_' . time(),
          'path' => $data->path,
          'redirect_path' => $data->redirect_path,
          'roles' => Drupal\Component\Serialization\Json::decode($data->roles),
          'users' => Drupal\Component\Serialization\Json::decode($data->users),
          'status' => $data->status,
          'message' => $data->message,
          'checked_for' => $data->check_for,
      );
      $url_redirect_entity = \Drupal\url_redirect\Entity\UrlRedirect::create($values);
      $url_redirect_entity->save();
    }

    // We can drop 'url_redirect' table once we confirm everything is migrated properly.
    // $db_connection->schema()->dropTable('url_redirect');
  }
}
  • What does this mean, handled it in an install file? – Kevin Oct 31 '17 at 17:21
  • The redirects are now handled within the url_redirect.install file located in the url_redirect folder. I've edited the original answer to reflect these changes – Nathan Melen Nov 1 '17 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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