开发者

Remove rows from the node table

Some nodes are displayed in the content list even if they don't exist anymore.

When I click on them I get an empty page.

I was wondering if I can just delete the rows from the "Node" tabl开发者_如何学编程e or I should clean something else.

thanks


First: on the administer page, go to performance, and click on the clear all caches button. If it doesn't solve your problem, then try disabling every contrib, and see if the problem still exists. If not, try enabling them one-by-one, and you will know which contrib made the problem. Report it to the module's issue queue.

If disabling modules doesn't solve your problem, download drush. Try deleting the node directly with node_delete. Example (if the wrong node's nid is 3):

drush php-eval 'node_delete(3);'

If you are not familiar with the command line, you can do the same with this little PHP file (put it into the Drupal's root):

include './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
node_delete(3);

If it doesn't work then make a backup from your database, delete the node from the node table and go through every node-related table (which has a nid column), and delete the related entries.


This may not be your problem but:

You don't want to delete rows directly from the database. You'll end up with no way of knowing what shape your database is in afterwards. Node IDs exist in many tables and nodes are distributed through more than one table.

Go through the nodeapi and use the Drupal framework because that's what it's meant for! The node api will treat your database schema correctly.

See: http://api.drupal.org/api/function/node_delete/6

So if you know the node ID, you can call node_delete.


Note that (depending on your Drupal permissions) you will likely need to be operating as a user with permissions to delete nodes -- such as user-1 rather than the default anonymous user. You can do this by pre-appending your node_delete() call with,

global $user; 
$user = user_load(1);

You may also experience a timeout if deleting many nodes and invoking the PHP file via a browser. One fix for this is to invoke the PHP file via the command line (if you have shell access). For example,

php -f custom-script.php

Again, if you are deleting many nodes, you may also run out of memory. Increase the PHP memory limit for your script's invocation like this,

php -f custom-script.php -d memory_limit=512M

This works against my tests with Drupal 6. Note that you may also be able to fix the server timeout issue by setting an explicit timeout in the custom-script.php.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜