我已经使用迁移模块v2迁移了节点。目前我遇到了一个问题,以前的网站使用网址别名,这还没有迁移到drupal7,并将影响网站排名从搜索引擎优化的角度。
有没有一种方法可以在运行迁移类本身的同时迁移路径别名?如果没有,最好的方法是什么?
发布于 2011-10-14 20:07:08
(据我所知)拥有相同url别名的最好方法是:
1>安装url_alias模块。
2>使用类似于drupal6的模式配置节点。现在,这一步可能会给你带来麻烦,以防新的url别名附加了nid(就像我的例子一样)。
作为一种解决方案,我们可以继续使用代码创建自定义令牌,其中源id可以根据新的目标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>
}
}
}
在编写自定义代码时,您可能还需要遗留的表。Drupal7支持多个数据库,所以只需在settings.php文件中配置遗留表凭证即可。
从不同的表取数据时使用drupal_set_active。
谢谢。
发布于 2012-11-14 02:01:39
您可以将遗留别名直接迁移到Drupal 7路径字段中:
$this->addFieldMapping('path', 'my_legacy_alias_field');
发布于 2014-10-01 03:10:47
这是一个非常精简的迁移类,其中包含了一种简单的方法,可以随身携带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);
}
}
https://stackoverflow.com/questions/7481544
复制相似问题