首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >作为迁移过程的一部分,将url别名从drupal6迁移到drupal7

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

Stack Overflow用户
提问于 2011-09-20 15:27:26
回答 4查看 1.9K关注 0票数 0

我已经使用迁移模块v2迁移了节点。目前我遇到了一个问题,以前的网站使用网址别名,这还没有迁移到drupal7,并将影响网站排名从搜索引擎优化的角度。

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

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2011-10-14 20:07:08

(据我所知)拥有相同url别名的最好方法是:

1>安装url_alias模块。

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

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

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

创建这样的自定义令牌的示例如下:

代码语言:javascript
运行
复制
/**
 * 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>

        }
      }
    }

在编写自定义代码时,您可能还需要遗留的表。Drupal7支持多个数据库,所以只需在settings.php文件中配置遗留表凭证即可。

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

谢谢。

票数 0
EN

Stack Overflow用户

发布于 2012-11-14 02:01:39

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

代码语言:javascript
运行
复制
$this->addFieldMapping('path', 'my_legacy_alias_field');
票数 5
EN

Stack Overflow用户

发布于 2014-10-01 03:10:47

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

代码语言:javascript
运行
复制
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);
  }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7481544

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档