4.6

Version 4.6 of Drupal

Drupal Tip #2: Unpublish and Block

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.

Unpublish:
Administer > Content > Edit (the relevant node) > Uncheck "Published" > Submit

Block:
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:

This tutorial brought to you courtesy of Adrian, my good friend and coder extraordinaire!

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.

Note: If you do not know the drupal database username, password or databasename, check in the settings file you can locate here: {webroot}/sites/uberellis.com/settings.php or {webroot}/sites/{yourdomain}/settings.php

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!

Drupal Tip #1: Node Privacy by Role defaults

Module: node_privacy_byrole.module
Drupal Version: 4.6.6

Many of my clients rely on some form of privacy to allow additional content to registered users, more often than not, to varying degrees. Normal drupal permissions helps out in cases where one could differentiate between content types for different permissions - more complex role divisions doesn't always allow that.

Node privacy by Role allows a lot more flexibility and I've been using it for months. The only reason I haven't been including it in every installation was the somewhat frustrating permission of setting permissions. It appeared to me that only the first admin user can set permissions, limiting other users to rely on defaults.

Much to my surprise, the module allows one to set permissions as well as defaults per node type from the content configuration pages (aka default workflow)

administer > content > configure (tab) > content types (sub-tab) > configure (for each content type)

*glee*
An application of this includes introducing a new user to drupal by including helpful howto's only visible to their various content providers.