Web design, programming, graphics, and pretty much anything else I care about.

Drupal Camp NJ 2013

DrupalCampNJ 2013 (http://www.drupalcampnj.org/) is February 2nd. I will be presenting a session on System Tips and Tricks (http://www.drupalcampnj.org/content/system-tips-and-tricks).

Joins can't be chained using Drupal 7 dynamic queries

I had a problem with a query I was building for a site migration from Drupal 6 to 7. I'm building the query dynamically as an object in Drupal 7. (The details aren't important.)

= db_select('users_roles', 'r')
fields('r', array('uid', 'rid'))
condition('r.uid', $source_id, '=');
$results = $query->execute();

Clearing DNS caches on Mac OS X

When making DNS changes, sometimes it is difficult to see the results from your own computer, because there are many caches involved that hold on to the last queried IP for the given host name. On Mac OS X dscacheutil can flush the DNS cache.

dscacheutil -flushcache

Sometimes, however, this isn't enough. In extreme cases you may have to kill the DNS responder.

sudo killall -HUP mDNSResponder

Using rsync

Rsync can be tricky, but it is the best way to synchronize the contents of directories. It is used when you don't want to simply delete one directory and replace it with another. For example, when replacing the contents of a directory under SVN version control you don't want the .svn directory to get removed or modified.

rsync -arvz [source] [destination]

-a "archive mode" which preserves links, permissions, etc.
-r recursive
-v verbose, multiple Vs increase the amount of data displayed. -vv, -vvv -vvvv.
-z compress
-n Do a dry-run, to see what would happen.

Apache redirect, with cookie support

This will redirect visitors that come from various mobile devices to another website (a mobile site.) It has added support for a cookie, so that mobile users can still opt to visit the full site.

The first block checks to see if it is a mobile device and there is neither a cookie nor a url parameter set. If those conditions are met, redirect the visitor to the mobile site. The second block looks to see if the url parameter is set and there is no cookie. If those conditions are met, set a cookie for the user.

Bootstrapping Drupal from an external sript

There are occasions where connecting to Drupal from an external script comes in handy. Connecting from a non-Drupal system, performing simple maintenance tasks, or just quick and dirty one time operations where you don't feel like making a module. I do this often when creating import scripts to bring data into a new site.

DrupalCamp NJ 2012 and sprint

DrupalCampNJ 2012 is this weekend. http://www.drupalcampnj.org/ . I'm helping organize and sponsor the event. The Sunday after (I know, Super Bowl Sunday :-() we are having a code sprint, and I'm helping organize a "How to Contribute" sprint to show new people how to contribute back to Drupal. I'll be going over documentation, patching, testing, providing support, etc. If you are interested, let me know. The sprint will go from ~10am - 5pm, and you can come and go as you please, so there is plenty of time to get home for the Super Bowl.

Discover CCK field table and column information

When retrieving information from the database for CCK fields, you can't assume the schema. Fields may be added to the content table, but if they are included on more than one content type, they get moved to their own table. Because things might move around, you can't make assumptions about where they will be. CCK api has functions you can use to determine where things are located.

Creating date repeat rules

Because Date doesn't play well with drupal_execute(), you have to use node_save() to insert/update nodes. If those nodes have a date field that uses repeats, you have to manually create the date array and repeat rule. ugh!

Programmatically inserting nodes

Inserting nodes, programmatically, is not always the easiest thing. The "drupally" way of doing it is to build the node form array and then submit it to drupal_execute(). (http://api.drupal.org/api/drupal/includes--form.inc/function/drupal_exec...) This follows the same procedure that the node/add form follows. This method will make sure that all the same validations occur, permission checks, etc. The problem is this is a slow process, and some modules don't work well with drupal_execute; namely, Date. To insert modules that have date fields, use node_save().