Setting up a local Drupal development environment on Ubuntu 12.10

I’ve recently started developing with the Drupal content management framework.  I did a lot of work with Drupal in the past, but haven’t done much work with the platform since Drupal 6.  While it still feels a bit strange coming from MVC frameworks and more expressive languages, it seems like Drupal and PHP have come a long way in offering a fluid development experience in the last few years.  This is how I set up my development environment in Ubuntu 12.10, though it probably works for newer releases of Ubuntu or other Debian-based Linuxes.

# Add the PHP5 PPA
sudo add-apt-repository ppa:ondrej/php5 
sudo apt-get update

# Install PHP5.  This will also install a recent version of Apache
sudo apt-get install php5

# Install PEAR, this will make it easier to install drush
sudo apt-get install php-pear

# Install drush via PEAR
pear channel-discover pear.drush.org
sudo pear channel-discover pear.drush.org
sudo pear install drush/drush

# HACK: The first time I ran drush it needed to install some dependencies via PEAR, 
# but I ran drush as my user so I didn't have permissions to write to the global PEAR
# directory.  Work around this by running drush with sudo and then chmoding your
# ~/.drush directory back to your own user.  You can probably just install the
# dependencies using PEAR.
sudo drush
sudo chown yourusername:yourgroupname -R ~/.drush

# For local development, I like using SQLite
sudo apt-get install php5-sqlite

# drush dl/en needs crul
sudo apt-get install php5-curl

# Drupal needs GD
sudo apt-get install php5-gd

MoveSmart

Home_MoveSmart_St._Louis_(Dev)_-_2014-01-15_22.41.50

MoveSmart helped users discover new, affordable, neighborhoods based on neighborhood assets like quality public schools, walkability and farmers markets.

Role

Sustaining developer

Description

I didn’t build the original MoveSmart, but I learned a ton maintaining Bec White‘s code. Building on a clever API that leveraged Drupal Views, I created custom  modules to add new datasets to the system and to support neighborhoods in the St. Louis metropolitan area.

In addition to continued development of the system, I performed data cleaning and merging of the datasets used in the neighborhood search.

More information

Dealing with Drupal comment spam

I got word that the Pages to Prisoners website was drowning in comment spam.  I locked down permissions, installed the AntiSpam and reCAPTCHA modules and wrote up some quick docs about my approach to solve it before stumbling on this really helpful how-to post, How to: Take control of your Drupal site back from the comment spammers, which outlines most of the steps that I took.

In the final step of this how-to, the author recommends bulk deleting spam comments in SQL.  The example SQL query in the how-to is pretty intense, deleting all comments.  I found that by looking at the comments, I could identify frequently used phrases in the subject that clearly had nothing to do with content on the site.  I could then compose a SQL query that would blow away these comments in a way that felt safer than deleting everything.  This is the query that I used which took me about 15 minutes to blow away over 3000 comments:

DELETE FROM `comments` WHERE `subject` LIKE "%boot%" OR `subject` LIKE "%jewelry%" OR
`subject` LIKE "%ugg%" OR `subject` LIKE "%watches%"  OR `subject` LIKE "%handbag%" OR 
`subject` LIKE "%cartier%"  OR `subject` LIKE "%jordan%" OR `subject` LIKE "%vuitton%" OR 
`subject` LIKE "%replica%" OR `subject` LIKE "%Louboutin%" OR `subject` LIKE "%MOD%"  OR 
`subject` LIKE "%OEM%" OR `subject` LIKE "%viagra%" OR `subject` LIKE "%coach%" OR 
`subject` LIKE "%chanel%"  OR `subject` LIKE "%tiffany%"  OR `subject` LIKE "%armani%"  OR 
`subject` LIKE "%windows 7%"  OR `subject` LIKE "%bvlgari%" OR `subject` LIKE "%chanel%" OR 
`subject` LIKE  "%The whirlwinds Mens%"  OR `subject` LIKE "%footwear%"  OR 
`subject` LIKE "%gucci%" OR `subject` LIKE "%BALENCIAGA%" OR `subject` LIKE "%jersey%" OR
 `subject` LIKE "%shoe%" OR `subject` LIKE "%jacket%" OR `subject` LIKE "%vibram%" OR 
`subject` LIKE "%mobile phone%" OR `subject` LIKE "%cell phone%" OR `subject` LIKE "%burberry%" OR
`subject` LIKE "%blu ray%" OR `subject` LIKE "%blu-ray%" OR `subject` LIKE "%phone%" OR 
`subject` LIKE "%nike%" OR `subject` LIKE "%abercrombie%" OR `subject` LIKE "%dress%" OR 
`subject` LIKE "%charm%" OR `subject` LIKE "%jewellery%"  OR `subject` LIKE "%london%" OR 
`subject` LIKE "%www.%"  OR `subject` LIKE "%video game%" OR `subject` LIKE "%bag%" OR 
`subject` LIKE "%wedding%" OR `subject` LIKE "%rosetta stone%" 

Node body search and replace Drush command

This is a command for the very useful Drupal Shell (Drush) module that lets you search and replace text in the body of a node using regular expressions. I wrote it when I was fixing broken links for the Center for Research Library’s web siter and got tired of having to visit a URL, click the edit link, replace the text, update the revision log, and click the save button.

Install this command as you would any other contributed command (for instance, you could put this file in your ~/.drush folder)

To learn how to use, check out the help text for the command by running drush help replace at the command line.

Example usage:

$ drush –url=http://www.crl.edu replace jstor-titles/economics-titles “/http:\/\/www.crl.edu\/jstortitles\/” “”

This replaces all instances of http://www.crl.edu/jstortitles with an empty string. Note that the syntax and escaping of the regular expressions are for those of PHP’s preg_replace function.

Download replace.drush

Published
Categorized as Code Tagged

Mailman Subscription Form with Drupal’s Webform

I’m trying to use Drupal’s webform module to make a subscription form to a Mailman mailing list.  Tracking thoughts and problems here.

I like webform because it stores form responses which might be useful.

Webform also lets you send e-mail on form submission and specify the sender/subject.  I was going to use this to send an e-mail from the address that user enters in the form to the -request address of the mailman list.

The problem is that the module lets you set the From: header but not the Sender: header and mailman uses the Sender: header to detect the requestor.

Options

  • Find a way to use tokens to set the subject to be ‘subscribe address=
  • Try to send my own e-mail with PHP code specified in the Additional Processing textarea of the Webform advanced settings fieldset when editing my form.

Drupal and content purgatory

Let’s jut say you’re migrating content from a static site to a Drupal-based site.  Let’s say that you don’t want to migrate the content all at once and want to roll out the new Drupal-based site ASAP and migrate content as you’re able to.  One thing that you could do is to make your old site static.mysite.com and your new Drupal-based site mysite.com.  Then use the Custom Error module and this snippet to automatically redirect to content on the old static site.  If the content isn’t in either place, they’ll get a 404 from the webserver of the static site.