Module: user.module, node.module
Drupal Version: 4.6.6
Oh sad day. Without thinking, I've deleted a user from a client's site and into the ether vanished a couple hours' work of static content..
Not against my better knowledge, I confess. When working with Drupal, always unpublish content, and block users.
Administer > Content > Edit (the relevant node) > Uncheck "Published" > Submit
Administer > Users > Edit (relevant user) > Set Role to "Blocked"
*update* Oh, happy day! All my content is salvaged. If you have ssh access to your webserver, here's how you can too:
Step 1: Find out what the user's uid (or user id) was
Access your Drupal database from your secure shell terminal, eg:
mysql -u <username> -p <database>
where <username> = The drupal database user and <database> = the drupal database name
After entering the drupal database password, you will be taken to a mysql prompt.
Run the following database query:
select nid, uid from node where nid = <broken>;
where <broken> = A node id of a post that's no longer accessable.
This returns a table showing the user id of a broken node and should resemble something like this:
mysql> select nid, uid from node where nid = 13; +-----+-----+ | nid | uid | +-----+-----+ | 13 | 2 | +-----+-----+ 1 row in set (0.00 sec)
Step 2: Replace the user id with an existing user id
From the mysql prompt, execute the following:
update node set uid = <existing> where uid = <missing>;
where <existing> = The user id of an existing user, or a new user created to replace the deleted one and <missing> = the user id established from the above, eg:
mysql> update node set uid = 10 where uid = 2; Query OK, 19 rows affected (0.43 sec) Rows matched: 19 Changed: 19 Warnings: 0
Voila! Your content has been restored!