1

我正在使用提要模块将我现有的数据导入 Drupal 7,它运行良好,但我对它生成的 nid 有一个问题。

我希望这些与我现有的站点 id 相匹配,然后我可以在旧的和新的之间有一个很好的干净过渡,即使是相同的 url。

这里有两种方法;1.不知何故将这些nid分配为导入的一部分。2. 导入后重新编号nid。

我在谷歌中找不到任何模块或其他代码,所以看起来我必须自己一起破解一些东西......以前有人做过吗?

-

能像更新所有这些一样简单吗?

SELECT table_name FROM INFORMATION_SCHEMA.COLUMNS WHERE column_name = 'nid'

comment
history
location_instance
node
node_access
node_comment_statistics
node_counter
node_revision
search_node_links
taxonomy_index

编辑:这些...

SELECT table_name FROM INFORMATION_SCHEMA.COLUMNS WHERE column_name = 'entity_id'

feeds_item
field_data_body
field_data_comment_body
field_data_field_address
field_data_field_image
field_data_field_state
field_data_field_tags
field_data_field_type
field_data_field_website
field_revision_body
field_revision_comment_body
field_revision_field_address
field_revision_field_image
field_revision_field_state
field_revision_field_tags
field_revision_field_type
field_revision_field_website
4

2 回答 2

0

如果您的源包含原始 nid,您只需在 feed 导入器中设置一个映射来分配 nid。这种方式应该没有理由在导入过程之后操作数据库,因为每个节点都将被简单地分配相同的 nid。

显然,如果您的站点中有具有相同 nid 的现有节点,这可能会中断。

于 2015-03-27T14:16:50.990 回答
0

这就是我最后所做的......

似乎一切正常,但在做这样的事情之前请非常小心并进行备份(就像我所做的那样)。

header('Content-type: text/plain');

global $database, $tables, $prefix;
$database = // your database

$prefix = 'drupal_';

$tables = array (
'comment'                 => 'nid',
'history'                 => 'nid',
'location_instance'       => 'nid',
'node'                    => 'nid',
'node_access'             => 'nid',
'node_comment_statistics' => 'nid',
'node_counter'            => 'nid',
'node_revision'           => 'nid',
'search_node_links'       => 'nid',
'taxonomy_index'          => 'nid',
'feeds_item'                   => 'entity_id',
'field_data_body'              => 'entity_id',
'field_data_comment_body'      => 'entity_id',
'field_data_field_address'     => 'entity_id',
'field_data_field_image'       => 'entity_id',
'field_data_field_state'       => 'entity_id',
'field_data_field_tags'        => 'entity_id',
'field_data_field_type'        => 'entity_id',
'field_data_field_website'     => 'entity_id',
'field_revision_body'          => 'entity_id',
'field_revision_comment_body'  => 'entity_id',
'field_revision_field_address' => 'entity_id',
'field_revision_field_image'   => 'entity_id',
'field_revision_field_state'   => 'entity_id',
'field_revision_field_tags'    => 'entity_id',
'field_revision_field_type'    => 'entity_id',
'field_revision_field_website' => 'entity_id'
    );

// Move all nids +10000 (out of the way)

$query = "SELECT nid FROM {$prefix}node WHERE nid < 10000 ORDER BY nid";
echo "$query\n";
$result = $database->query($query);
while($data = $result->fetchRow()) {
    echo "Processing nid: {$data['nid']}\n";
    changeNodeId($data['nid'], $data['nid'] + 10000);
}

// Move all nids to match guids
// (I originally imported through the feeds module, so used the guids to reorder here, but you can use your own logic as required...)

$query = "SELECT guid, entity_id FROM {$prefix}feeds_item WHERE guid <> entity_id ORDER BY ABS(guid)";
echo "$query\n";
$result = $database->query($query);
while($data = $result->fetchRow()) {
    echo "Processing guid: {$data['guid']} (nid: {$data['entity_id']})\n";
    changeNodeId($data['entity_id'], $data['guid']);
}

function changeNodeId($old, $new)
{
    global $database, $tables, $prefix;

    echo "Updating nid: {$old} -> {$new}\n";

    // Check new doesn't already exist
    $query = "SELECT * FROM {$prefix}node WHERE nid={$new}";
    $result = $database->query($query);
    if ($result->fetchRow()) {
        echo "Error nid: {$new} already exists!\n"; 
        return;
    }

    foreach ($tables as $table => $column)
    {
        $query = "UPDATE {$prefix}{$table} SET {$column} = {$new} WHERE {$column} = {$old}";
        echo "$query\n";
        $database->query($query);
    }
}

笔记。

  1. 上面列出的表格对我有用,根据您安装的模块,它几乎肯定会有所不同。

  2. 这将破坏您的菜单和您设置的任何 URL 别名,因此您必须在之后手动完成并修复它们,虽然不是主要的。

  3. 在节点表上重置您的自动增量 ID 也是一个好主意。ALTER TABLE node AUTO_INCREMENT = X其中 X 比最高 nid 大 1。

于 2013-07-13T05:46:57.347 回答