Developer migrating from Drupal 7 to Drupal 10, with broken and fixed chain links symbolizing the resolution of URL alias issues.

I've been working on a Drupal 7 to Drupal 10 migration for a few months, and I'm very close to the finish line. However, today I noticed a new problem: none of the URL aliases from the Drupal 7 site had transferred during the migration. Despite running the migration multiple times, this never worked. At this point, rolling back the entire migration wasn't feasible—too much of the content had changed.

So, what to do? I needed to fix the URL aliases to preserve links that may have been published previously.

The Problem: Missing URL Aliases

The migration from Drupal 7 to Drupal 10 was mostly successful, but one glaring issue remained: the URL aliases did not migrate. This created a problem because those old aliases might still be in use, and I wanted to make sure any past links to the site wouldn’t break.

The Initial Attempt: Asking ChatGPT

Like many of us, I turned to ChatGPT for help. I fed it my migration YAML file, hoping for insights on what I might have missed:

uuid: f8dfb2ce-e04e-48ef-8bc3-71a8f463efa8
langcode: en
status: true
dependencies: {  }
id: upgrade_d7_url_alias
class: Drupal\migrate\Plugin\Migration
field_plugin_method: null
cck_plugin_method: null
migration_tags:
  - 'Drupal 7'
  - Content
migration_group: migrate_drupal_7
label: 'URL aliases'
source:
  plugin: d7_url_alias
  constants:
    slash: /
process:
  id:
    -
      plugin: get
      source: pid
  _path:
    -
      plugin: concat
      source:
        - constants/slash
        - source
  alias:
    -
      plugin: concat
      source:
        - constants/slash
        - alias
  node_translation:
    -
      plugin: explode
      source: source
      delimiter: /
    -
      plugin: extract
      default: INVALID_NID
      index:
        - 1
    -
      plugin: migration_lookup
      migration:
        - upgrade_d7_node_complete_article
        - upgrade_d7_node_complete_blog
        - upgrade_d7_node_complete_page
        - upgrade_d7_node_complete_poll
        - upgrade_d7_node_complete_show_excerpt
        - upgrade_d7_node_complete_webform
    -
      plugin: node_complete_node_translation_lookup
  langcode:
    -
      plugin: null_coalesce
      source:
        - '@node_translation/1'
        - language
  path:
    -
      plugin: path_set_translated
      source:
        - '@_path'
        - '@node_translation'
destination:
  plugin: 'entity:path_alias'
migration_dependencies:
  required: {  }
  optional:
    - upgrade_d7_node_complete_article
    - upgrade_d7_node_complete_blog
    - upgrade_d7_node_complete_page
    - upgrade_d7_node_complete_poll
    - upgrade_d7_node_complete_show_excerpt
    - upgrade_d7_node_complete_webform
    - upgrade_d7_node_complete_article
    - upgrade_d7_node_complete_blog
    - upgrade_d7_node_complete_page
    - upgrade_d7_node_complete_poll
    - upgrade_d7_node_complete_show_excerpt
    - upgrade_d7_node_complete_webform
 

Unfortunately, ChatGPT only confirmed what I had already done. No new ideas. Time to dive deeper.

Discovery: The Path Alias Import Module

I decided to consult my trusty friend—Google. After some searching, I came across an old, unreleased Drupal module called Path Alias Import. This module allows you to create path aliases from a CSV file. It sounded like exactly what I needed.

This project allows to create path aliases to specific nodes from imported csv files.

how to use:
-activate the extension
- import your csv file at /admin/config/path_alias_import/upload
- The file must contain 4 columns : an entry id (just for the sake of it ) , /path_alias, internal system path target ( ex : /node/2), lang
- check path alias creation at /admin/config/search/path

The Process: Making It Work for Drupal 10

Since the module was designed for Drupal 8, it didn’t work right away in Drupal 10. Step one: convert the .info file to match the new format. Step two: activate the module and brace for potential errors—something I’ve experienced more often when porting modules to Backdrop CMS than Drupal.

Errors predictably followed. In the past, I would have Googled every error message. But this time, I copied them into ChatGPT. After some troubleshooting, I finally got the module to work, and the URL aliases were successfully imported into my Drupal 10 site.

Conclusion: A Problem Solved (With a Little Help)

It might not have been the most elegant solution, but it worked. In the pre-generative AI days, I would have relied on my "librarian Google skills" to track down solutions, but the process would have taken much longer. With a few clicks and prompts, I was able to fix the issue in minutes—and I learned some new things in the process.

The Drupal 10 Version of Path Alias Import is now up and running, solving a tricky problem efficiently.

Then I submitted this blog post to ChatGPT to help write it.