Drupal - File Usage MySQL Queries

Here are a few helpful MySQL queries to retrieve file usage in Drupal (perhaps via IMCE or other file management module).

Total File Space Used by a Particular User

select SUM(filesize) as total_space from {files} where uid = 123;

Total File Space Used by a Particular Directory

select sum(filesize) as total_size from {files} where filepath like '%files\/my_sub_dir\/my_other_sub_dir%';

Drupal - How to Make a Backup Copy of MySQL Database

Here is how you can make a backup copy of your Drupal's MySQL database from a terminal:

mysqldump -u my_drupal_mysql_uer_name -p my_drupal_mysql_database_name > ~/my_drupal_sql_dump.sql

I like to clear all of Drupal's caches before running the dump so there isn't a bunch of cache data in the export.

If you'd prefer to use Drush, check out this article instead: Use Drush to Export/Import a Drupal MySQL Database Dump File

Drupal Custom Time Field Select List with 15 Minute Intervals

If you need a custom time field select list with 15 minute interval options in Drupal 7, try this out when adding a new field to your content type (this will work in Drupal 6 as well):

Field: List (text)

Widget: Select list

Allowed values list:

Drupal Views Group by Field with Counts and Links - A Better Way

Alas, I came across a better way to take a bunch of rows from views, group them by a particular field, and provide a count for each.

Here is a basic example for Drupal 6 (probably very similar for Drupal 7).

Basic Settings

Style: HTML List


Node id (exclude from display)

Node title


Node title

Drupal How to Add a CSS ID or Class Name to a Menu Item Link

Do you need to add a unique CSS ID or Class Name to a Drupal menu item link? Then you've come to the right place. Check out this example below...

Menu item link before:

<a href="/my_node_url_path">My Node</a>

Menu item link after:

<a href="/my_node_url_path" id="my_css_id" class="my_css_class">My Node</a>

How to do it...

Drupal 7 Retrieve Node Comments with Database API

My oh my, how times have changed. Here is how you can get all the comments for a node in Drupal 7 (much different from D6):

Drupal Webform Submission Results User Access Control

Have you ever wanted to grant access to a certain list of users so they could access a Drupal Webform's submission results? The default permissions that come with Webform don't provide much granularity in this scenario, so a custom solution needs to be implemented.

Luckily Webform has a few hooks to make our lives easier.

Drupal Convert User Relationships Module to User Reference Field

So I was using the User Relationships module for a while on a project. It worked OK, but I got very tired of not having the flexibility of a user reference field. Since I was already using the Content Profile module for users, I just added a new user reference field to the Profile content type. The user reference field was configured for multiple values.

I then wrote a simple hook_menu item and a call back function that would actually handle the conversion from the User Relationships module to a User Reference field on my Content Profile setup.

Drupal Webform Alter

Once upon a time, on a dark day, December 21st, 2011 to be exact. There was a desire to modify a Drupal webform. Normally, one could use replacement pattern tokens available in the Webform UI to set default values on a component field. But this was a special day, a day where a Webform field had to be prepopulated with a value that was not available via replacement pattern tokens. So if you need to modify a Webform via hook_form_alter, try something like this:

Drupal Location Form Alter

If you need to modify the Location module's form on a node, try something like this:


Subscribe to RSS - Code