这就是我最后所做的......
它似乎一切正常,但在做这样的事情之前请非常小心并进行备份(就像我所做的那样)。
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);
}
}
笔记。
上面列出的表格对我有用,根据您安装的模块,它几乎肯定会有所不同。
这将破坏您的菜单和您设置的任何 URL 别名,因此您必须在之后手动完成并修复它们,虽然不是主要的。
在节点表上重置您的自动增量 ID 也是一个好主意。ALTER TABLE node AUTO_INCREMENT = X
其中 X 比最高 nid 大 1。