You are here

public function DrupalMenuLinks6Migration::prepareRow in Drupal-to-Drupal data migration 7.2

Review a data row after fetch, returning FALSE to skip it.

Parameters

$row:

Overrides Migration::prepareRow

File

d6/menu_links.inc, line 74
Implementation of DrupalMenuLinksMigration for Drupal 6 sources.

Class

DrupalMenuLinks6Migration

Code

public function prepareRow($row) {
  if (parent::prepareRow($row) === FALSE) {
    return FALSE;
  }
  if (!($row->menu_name == 'primary-links' || $row->menu_name == 'secondary-links' || substr($row->menu_name, 0, 5) == 'menu-')) {
    return FALSE;
  }
  if ($row->menu_name == 'primary-links') {
    $row->menu_name = 'main-menu';
  }

  /*
   * Fun with link_path!
   *
   * check for nids
   *   if pattern 'node/nid', replace nid with handleSourceMigration($node_migrations, $nid)
   * check for tids
   *   if pattern 'term/tid', replace tid with handleSourceMigration($term_migrations, $tid)
   * check for potential alias (after basepath, I believe)
   *   if (handleSourceMigration($path_migration, $potentialalias), replace potentialalias with result
   */
  $matches = array();
  $value = '';

  // NIDs first
  if (!empty($this->node_migrations)) {

    // Grabs numbers preceded by 'node/', followed by end of string or '/'
    // eg: 'node/63' -> '63', 'node/17/edit' -> '17', 'node/53ea' -> NULL
    //
    // @todo: extend the lookbehind so it returns NULL for inputs like 'awetnode/34'
    $regex_nid = "/(?<=node\\/)[\\d]+(?=\$|\\/)/";
    if (preg_match($regex_nid, $row->link_path, $matches)) {
      if ($value = $this
        ->handleSourceMigration($this->node_migrations, $matches[0])) {
        $new_path = preg_replace('/' . $matches[0] . '/', $value, $row->link_path);
        if ($new_path) {
          $row->link_path = $new_path;
        }
        else {
        }
      }
      else {
      }
    }
  }

  // @todo: handle tid and url_alias
}