作为迁移过程的一部分,将 url 别名从 drupal6 迁移到 drupal7

发布于 2024-12-05 14:21:26 字数 138 浏览 0 评论 0原文

我已经使用迁移模块 v2 迁移了节点。目前我遇到一个问题,以前的网站使用了 url 别名,这些别名尚未迁移到 drupal7 中,从 SEO 角度来看会影响网站排名。

有没有一种方法可以在运行迁移类本身时迁移路径别名?如果没有,最好的方法是什么?

I have migrated nodes using migrate module v2. Currently i am running into a problem that the previous site used url aliases,which have not been migrated into drupal7 and will affect the site rank from SEO perspective.

Is there a way i can migrate the path aliases while running the migration classes itself?If not what would be the best way to do so?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

你的他你的她 2024-12-12 14:21:26

您可以将旧别名直接迁移到 Drupal 7 路径字段中:

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

You can migrate your legacy aliases directly into the Drupal 7 path field:

$this->addFieldMapping('path', 'my_legacy_alias_field');
一江春梦 2024-12-12 14:21:26

这是一个非常精简的迁移类,其中包括一种简单的方法来携带 URL。旨在与 Migrate 模块一起使用。

class MyNodeMigration extends Migration {
  public function __construct(array $arguments) {
    $this->arguments = $arguments;
    parent::__construct();
    $source_fields = array('nid' => t('The node ID of the page'));

    $query = Database::getConnection('default', 'legacy')
      ->select('node', 'n')
      ->fields('n');
    $query->join('url_alias', 'a', "a.src = CONCAT('node/', n.nid)");
    $query->addField('a', 'dst');
    $this->source = new MigrateSourceSQL($query, $source_fields);
    $this->destination = new MigrateDestinationNode('my_node_type');
    $this->map = new MigrateSQLMap($this->machineName,
      array('nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'D6 Unique Node ID',
        'alias' => 'n',
      )),
      MigrateDestinationNode::getKeySchema()
    );

    $this->addSimpleMappings(array('title', 'created', 'changed', 'status'));
    $this->addUnmigratedDestinations(array('sticky', 'log', 'nid'));
    $this->addFieldMapping('path', 'dst');
    $this->addFieldMapping('is_new')->defaultValue(TRUE);
  }
}

Here is a very stripped down migration class that includes an easy method for bringing URLs along for the ride. Intended for use with the Migrate module.

class MyNodeMigration extends Migration {
  public function __construct(array $arguments) {
    $this->arguments = $arguments;
    parent::__construct();
    $source_fields = array('nid' => t('The node ID of the page'));

    $query = Database::getConnection('default', 'legacy')
      ->select('node', 'n')
      ->fields('n');
    $query->join('url_alias', 'a', "a.src = CONCAT('node/', n.nid)");
    $query->addField('a', 'dst');
    $this->source = new MigrateSourceSQL($query, $source_fields);
    $this->destination = new MigrateDestinationNode('my_node_type');
    $this->map = new MigrateSQLMap($this->machineName,
      array('nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'D6 Unique Node ID',
        'alias' => 'n',
      )),
      MigrateDestinationNode::getKeySchema()
    );

    $this->addSimpleMappings(array('title', 'created', 'changed', 'status'));
    $this->addUnmigratedDestinations(array('sticky', 'log', 'nid'));
    $this->addFieldMapping('path', 'dst');
    $this->addFieldMapping('is_new')->defaultValue(TRUE);
  }
}
べ繥欢鉨o。 2024-12-12 14:21:26

正如我所看到的,url_alias表全局相同,期望从src更改为sourcedst的字段名称别名。所以我想你可以轻松地将内容从 Drupal 6 复制到 Drupal 7。

我从未尝试过,但理论上它应该可以工作。

As I can see, the url_aliastable is globally the same, expect the name of fields whom changed from srcto sourceand dst to alias. So I guess you can easily copy the content from your Drupal 6 to your Drupal 7.

I never tried, but in theory it should work.

一腔孤↑勇 2024-12-12 14:21:26

拥有相同 url 别名的最佳方法(根据我的说法)是:

1>安装 url_alias 模块。

2>使用类似于 drupal6 的模式配置节点。现在,这一步可能会给您带来麻烦,以防新的 url 别名附加了 nid。(如我的情况)。

作为一种解决方案,我们可以继续使用代码创建自定义令牌,其中可以根据易于获得的新目标 ID 从迁移映射表中获取源 ID。

现在,我们可以继续批量生成 url 别名。

创建此类自定义令牌的一个示例是:

/**
 * Implements hook_token_info().
 */
function custom_configuration_token_info() {  
  $type = array(
    'node' => array (
      'name' => t('Nodes'), 
      'description' => t('Tokens related to individual nodes.'), 
      'needs-data' => 'node',
     ),

         'term' => array(
           'name' => t('Taxonomy Terms'),
           'description' => t('Tokens related to taxonomy terms.'),
           'needs-data' => 'term',
         )
      );

      // tokens for node legacy nid.
      $tokens['node']['mapid'] = array(
        'name' => t("mapid"), 
        'description' => t("The nid of the node prior to migration."),
      );

      $tokens['term']['mapid'] = array(
        'name' => t('mapid'),
        'description' => t('The tid of taxonomy terms prior to migration.'),
      );

      return array(
        'types' => $type, 
        'tokens' => $tokens,
      );
    }


    now,

    function custom_configuration_tokens($type, $tokens, array $data = array(), array $options = array()) {
      $url_options = array('absolute' => TRUE);
      if (isset($options['language'])) {
        $url_options['language'] = $options['language'];
        $language_code = $options['language']->language;
      }
      else {
        $language_code = NULL;
      }
      $sanitize = !empty($options['sanitize']);

      $replacements = array();

      if ($type == 'node' && !empty($data['node'])) {
        $node = $data['node'];

        foreach ($tokens as $name => $original) {
              switch ($name) {

    <write your custom code for the token conditioned by the name attribute in info function>

        }
      }
    }

在编写自定义代码时,您可能还需要旧表。 Drupal 7 支持多个数据库,因此只需在 settings.php 文件中配置旧表凭据即可。

从不同表中获取数据时使用 drupal_set_active。

谢谢。

The best way (according to me) to have the same url aliases is :

1> install url_alias module.

2> configure the nodes with patterns similar to drupal6. Now, this step may trouble you, in case the new url-aliases have nids attached to them.(as in my case).

As a solution we can go ahead and create custom tokens using code where the source id can be fetched from the migrate map tables based on the new destination ids which are easily available.

Now, we can go ahead and bulk generate url-aliases.

An example for creating such custom token would be:

/**
 * Implements hook_token_info().
 */
function custom_configuration_token_info() {  
  $type = array(
    'node' => array (
      'name' => t('Nodes'), 
      'description' => t('Tokens related to individual nodes.'), 
      'needs-data' => 'node',
     ),

         'term' => array(
           'name' => t('Taxonomy Terms'),
           'description' => t('Tokens related to taxonomy terms.'),
           'needs-data' => 'term',
         )
      );

      // tokens for node legacy nid.
      $tokens['node']['mapid'] = array(
        'name' => t("mapid"), 
        'description' => t("The nid of the node prior to migration."),
      );

      $tokens['term']['mapid'] = array(
        'name' => t('mapid'),
        'description' => t('The tid of taxonomy terms prior to migration.'),
      );

      return array(
        'types' => $type, 
        'tokens' => $tokens,
      );
    }


    now,

    function custom_configuration_tokens($type, $tokens, array $data = array(), array $options = array()) {
      $url_options = array('absolute' => TRUE);
      if (isset($options['language'])) {
        $url_options['language'] = $options['language'];
        $language_code = $options['language']->language;
      }
      else {
        $language_code = NULL;
      }
      $sanitize = !empty($options['sanitize']);

      $replacements = array();

      if ($type == 'node' && !empty($data['node'])) {
        $node = $data['node'];

        foreach ($tokens as $name => $original) {
              switch ($name) {

    <write your custom code for the token conditioned by the name attribute in info function>

        }
      }
    }

While writing your custom code, you mite also be needing the legacy table. Drupal 7 supports multiple databases, so just configure the legacy table credentials in settings.php file.

Use drupal_set_active while fetching data from the different tables.

Thanks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文