Skip to main content


Preserving Role ID (rid) in a Drupal 6 to Drupal 7 Role Migration

I was working on setting up a role migration from Drupal 6 to Drupal 7. After some time, I noticed that the role id's were not being preserved, which was going to cause a problem for me when I went to take the migration to the live server. I initially tried using the addFieldMapping function to link the source rid to the destination rid (similar to preserving the nid for nodes or the uid for users). However, this failed to save any of the roles during migration.

Useful Linux Snippets

Finding failed login attempts from the maillog:

  1. head -n1 /var/log/maillog | awk '{ printf "Failed Login Attempts Since: "$1" "$2": " }' && cat /var/log/maillog | grep "FAILED" | wc -l && cat /var/log/maillog | grep "FAILED" | perl -ne 'print "$&\n" while m#\d+\.\d+\.\d+\.\d+#g' | sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 | uniq -c | awk 'length($1)>2'

Recovering from a failed iMac hard drive

Back in late December the hard drive on my iMac failed... kaput! Disk utility couldn't fix it nor could it erase the drive. It had become a paper weight. Thankfully, I had time machine running for selected files/folders on the iMac (but not the whole system), which allowed me to restore to a new computer in a timely fashion. This week I found myself wanting to reference an article on my blog site and realized it wasn't loading (it was only a local blog at this time). No problem, I went to the time machine backup and pulled the code for the site.

Multiple Drupal virtual hosts with their own syslog files

We have a shared hosting server that handles many Drupal sites within their own Apache virtual hosts. We had a need to track all available log messages for long periods of time, which the core watchdog module wouldn't allow us to do. So, we enabled the syslog module to write the messages to log files on the server.

To get all of the sites into their own log files we had to add the following code to /etc/rsyslog.d/drupal.conf

Drupal: Disabling another module's rule configuration from my own module.

Today I was working on a feature on a site that was using Ubercart's uc_roles module. By default, whenever a customer would buy a product with a role attached to it, an email would be generated stating what role that customer bought. However, in my use case, we did not want these emails generated and we needed to keep our settings in code.

List all DNS Entries for a domain

Today we were in the process of changing the hosting on a domain. The client wanted us to keep their original DNS records but they only gave us access to change their name servers. So, we needed to investigate how to get a list of all of their current DNS records so we could replicate those on our name servers. I came across this post: and the following command:

Responsive Drupal Calendar

Drupal's calendar module is a great tool for building calendars quickly with views. However, the default theme is still using tables, blech! After some searching, I came across a sandbox module to fix this, Like some of the user's in that thread, I did not want to add another module to my site. So, I set off to theme the calendar in a responsive way. Surprisingly, this was much easier than I anticipated. You only need to override two theme files and add roughly 88 lines of css.

Glusterfs: Re-attach a crashed, inaccessible replicated server to the other peers

This morning started off okay, until I checked my email and found an alarm ringing about one of our file servers being offline. Luckily, we have a replicated setup, so no customers were affected, but it is a little worrisome not having the safety net of two replicated servers.

The server didn't technically crash, rather, it was a problem with the EC2 instance being unavailable likely due to some unforeseen problem in the Virginia datacenter. Regardless, the first step I took was to get the server accessible via SSH.

SmarterMail - Clearing the Spool of a compromised email account's spam messages

Recently we had a spammer compromise a weak password on one of our SmarterMail installations. Over the course of a few hours, the spammer had racked up over 15,000 messages in SmarterMail's spool, not to mention the amount of messages that were delivered successfully. To get our server running normally while clearing out the spam messages we followed the following steps:

Create different messages per content type with Drupal's Messaging/Notifications framework.

A recent project required me to create a different notification message per content type. To do this you can use the hook_message_alter() function to override the default message. I borrowed heavily from the code in file_message_alter()

The code I used is below:

Multi-dependent select elements in Drupal 7 using ajax

Recently I needed to modify a Drupal 7 node form to have two drop down select elements populate based upon a third select element's choice. I have altered select elements in the past to have a single dependency, but never have I made one element control the content of two different elements.

To start, I made the first element control the second (the old familiar way):

I need the selection in field_dropdown_1 to dictate what appears in the list for field_dropdown_2 and field_dropdown_3.

Migrating a Drupal 5 site to a Drupal 7 site.

I had to accomplish the task of migrating the content from a Drupal 5 site with 10,000+ nodes to a new Drupal 7 version. The caveat was that all of the node information needed to remain intact due to various links that were entered into the body of posts. My initial thought was to use a .csv file and import directly into the database. After some more research I discovered the migrate and migrate_d2d modules.

How to form alter Ubercart 3 Address Pane Fields

I recently needed to alter the address fields within the Ubercart 3 billing pane. Unfortunately, due to the way Ubercart 3 builds these form elements, the standard hook_form_alter() hook was not going to work. After a few hours of searching I finally discovered this post:

With that information I was able to alter my billing pane's company field into a select list taken from a taxonomy. The code below was entered into my theme's template.php file.

Get the Aegir Platform path when editing a vhost

I was setting up a static mobile website for a Drupal site that was installed within the Aegir hosting environment today. We had been given a static mobile version of the website to load. So, we added the mobile site to a directory within our theme and we needed to setup an alias for this site. To accomplish this we created a new file within the .drush folder and added the following code:

How to: Migrate an EC2 instances to a new availability zone

Recently an EC2 instance we were using in a production environment was scheduled to go down for maintenance. Normally this would be fine and we would let AWS just handle this. However, their scheduled maintenance window was set for 21:00 UTC, which equates to 17:00 EST. In other words, right at the end of the work day. Not cool!

In order to use a maintenance schedule of our choosing, we had to migrate our production instance into a different availability zone prior to Amazon's schedule. So, we setup a test instances and tested migrating. Our successful steps are below: