2011-09-20 57 views

回答

0

的最佳方式(根據我)有相同的URL別名是:

1>安裝url_alias模塊。

2>使用類似於drupal6的模式配置節點。現在,這個步驟可能會給你帶來麻煩,以防萬一新的url-aliases有nid連接到它們(就像我的情況一樣)。

作爲一種解決方案,我們可以繼續使用代碼創建自定義令牌,其中源代碼可以基於新的目標ID從遷移映射表中獲取,這些目標ID很容易獲得。

現在,我們可以繼續批量生成url-aliases。

創建這樣的自定義標記將是一個例子:

/** 
* 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。

謝謝。

0

正如我所看到的,url_alias表是全球一樣的,希望從誰改變srcsourcedstalias字段的名稱。所以我猜你可以很容易地將你的Drupal 6中的內容複製到Drupal 7.

我從來沒有嘗試過,但理論上它應該工作。

5

您可以直接遷移遺留別名到Drupal 7的路徑字段:

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

Drupal 6中沒有將字段保存在節點上的字段?我相信你需要通過查詢url_aliase表將map映射到prepareRow()的「path」字段[select * from url_alias where src ='node/123';] - 或者我誤解了這個? – Andre

+1

我的原始答案是一般情況 - 對於Drupal-to-Drupal遷移,是的,您需要查詢url_alias表以獲取舊版別名。請注意,在原始答案後不久,我發佈了migrate_d2d(Drupal-to-Drupal遷移)模塊,它具有此內置功能。 –

1

這裏是一個非常精簡移民類包括用於將網址湊湊熱鬧的簡單方法。用於與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); 
    } 
}