I've been working through a Drupal6 to Drupal7 migration and am having issues getting paths to migrate.

So far I've been able to migrate Taxonomies, Nodes and custom fields, node statistics.

But some nodes (possibly all...) don't seem to get the path migrated - they end up with a path like 'node/12345'.

In the old Drupal6 site pathauto automatic aliases are used for most nodes but some have hard coded paths.

Migrate, and Migrate Extras are installed as well.

 Migration                 Drupal-to-Drupal migration (migrate_d2d)                   7.x-2.1-beta1+7-dev 
 Migration                 Migrate (migrate)                                          7.x-2.6-rc1+22-dev  
 Migration                 Migrate Extras (migrate_extras)                            7.x-2.5+4-dev       
 Migration                 Migrate UI (migrate_ui)                                    7.x-2.6-rc1+22-dev  

According to drush migrate-mappings it appears path is handled automatically because of Migrate Extras?

path                                path                        Handled in prepareRow 

But after the migration is ran, nodes end up with paths like 'node/1245'.

There's no errors complaining about paths.

Is there something simple I'm overlooking or some addition steps to get paths migrating?

Thank you.

Comments

internets’s picture

After setting up a prepareRow function and fetching the path from the legacy database, and mapping it to the path field, some node paths are still showing up as 'node/12435' after migration. Even though there are aliases in the legacy database.

public function prepareRow($row) {
    if (parent::prepareRow($row) === FALSE) {
      return FALSE;
    }
    $src_path = 'node/' . $row->nid;
    $node_path = Database::getConnection('default', 'legacy')
      ->select('url_alias', 'ua')
      ->fields('ua', array('src', 'dst'))
      ->condition('src', $src_path)
      ->execute()
      ->fetchAllKeyed();

    // outputs the correct path    
    error_log(print_r($node_path[$src_path], true));

    // setting the path 
    $row->path = $node_path[$src_path];
    // tried setting path to a different variable 
    $row->old_path = $node_path[$src_path];
    return TRUE;
 
 }

And in the field mapping

    $this->addFieldMapping('path', 'old_path');

And I've tried setting up field mapping for 'path', and also tried setting up a new variable and mapping that to path but still no joy. There must be something simple being overlooked or misunderstood?

internets’s picture

I was able to find a solution by using the prepare() migration method.

After digging in further I've found the 'prepareRow' method (in migrate_d2d/node.inc) mentioned next to the 'path' field when running drush migrate-mappings. This prepareRow function calls the getPath() method.

Adding some error logging into getPath() inside migrate_d2d/d6/d6.inc show that correct paths are being found and assigned to the $row for each node.

But for some reason after the migration completes, some of the nodes don't have the path that was returned from getPath()

So using the prepare function, logging / inspecting the $node I found the alias was blank even the the $row->path was getting set correctly.

  ...
    [path] => Array
        (
            [pathauto] => 0
            [alias] => 
        )
...

So setting adding the following prepare method sets the alias.

  public function prepare($node, stdClass $row) {
    $node->path['alias'] = $row->path;
  }

Nodes are no longer migrating with empty / default paths.
I'm not sure if this means something is broken with migrate_d2d or maybe I'm overlooking something simple...

nerdcore’s picture

Indeed the migrate mappings and all of the migrate_d2d/node.inc code regarding paths would seem to indicate that there already exists a D6 -> D7 'path' mapping. `drush mm` tells me that 'path' is mapped to 'path'. No dice.

In addition to the code in #2, I had to retrieve the D6 alias...

  public function prepare($node, $row) {
    // This line was taken from migrate_d2d-7.x-2.0/node.inc, line 136
    $path = $this->version->getPath('node/' . $row->nid);
    if (!empty($path)) {
      $node->path['alias'] = $path;
    }
  }
mikeryan’s picture

Status: Active » Postponed (maintainer needs more info)

I haven't seen this problem with my D6->D7 migrations, but in the work on D6->D8 migration we've had issues with languages. I.e., in my D6 url_alias table the language column is always blank - could you check your url_alias table and see if perhaps the nodes with unimported paths have a different language value from those that succeeded?

mikeryan’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)
hargobind’s picture

I recently had a similar problem where only some paths were not migrating. I checked the language column in the url_aliases table as suggested in #4, but didn't find any problems there.

Eventually I tracked the issue to a fringe case where more than one alias existed in the {url_alias} table for a single node -- sometimes even 2 or 3. Whenever there is more than one alias, the paths are skipped entirely. Luckily this was only about 20-30 aliases, so I was able to just manually delete the old aliases and re-run the migration on those particular nodes.