I had an issue with Apache that was driving me nuts. I've got a Drupal site with a page that uses the path /new. Simple enough. However, I also have a static HTML page in the root of the site at the path /new.html. Every time I'd click a link to /new it would render the static HTML page, though not via a redirect. The browser address bar would still show /new, but it would show me the new.html file.
Drush PHP Memory Limit
Thu, 01/26/2012 - 15:34 | by nathanI was banging my head against the wall this morning because Drush kept telling me that I was exhausting PHP's memory at 128MB. I finally figured out the problem and thought I'd share for others searching the internet for a solution.
The first thing I did was check my php.ini file. Sometimes PHP on the command line will use a different php.ini file than the Apache version. In my case, the php.ini file is shared for both.
Render a Single Field in Drupal 7
Thu, 09/01/2011 - 18:33 | by nathanI needed a simple method to render a single field from a node object in Drupal 7, but couldn't find any good answers by searching the web.
Here is the solution I finally came to by searching the documentation:
// Render the field named "field_image" $field = field_view_value('node', $node, 'field_image', $node->field_image[$node->language][0]); print render($field);
Command line bookmarks / shortcut script
Wed, 07/27/2011 - 18:08 | by nathanI grew tired of typing some of the same long commands into my terminal; especially ssh commands to log into a myriad of remote machines. I needed a way to create bookmarks or shortcuts to these long commands that I use on a regular basis. So several month ago I decided solving this problem would be a good opportunity to dabble into some Ruby (which I'd been meaning to do for a long time).
The script is freely available on Github.com: https://github.com/nrambeck/Go
I was able to find a ruby command-line template as a starting point (I can't recall where I got the template from).
Copying objects in PHP 5 using clone
Thu, 03/17/2011 - 11:35 | by nathanIn PHP 4 object variables were simple. Assigning one object to another worked exactly as you'd expect.
$object1->title = "Title One"; $object2 = $object1; $object2->title = "Title Two"; print $object1->title; // returns "Title One"
You could make a copy of the original, and modify your copy with full assurance that your original would remain untouched.
That changed in PHP 5. Now when you assign an object to a new variable.
Views Index Hint module
Wed, 09/29/2010 - 16:11 | by nathanOn one of my projects, I cam across a certain performance edge case on a site with a large volume of data. For whatever reason, the MySQL optimizer refused to use the fastest index in a handful of views queries, causing these queries to be painfully slow.
Here is a simplified example of a query generated by views:
SELECT nid, title FROM node WHERE status <> 0 AND type IN ("story") ORDER BY created DESC;
When viewing the explain plan for this query, it shows my that MySQL is choosing to use the node_type index instead of node_created.
Drush command to close comments
Wed, 09/22/2010 - 13:34 | by nathanThere is a great module called Comment Closer that allows you to automatically close comments on certain nodes after a certain time period.
On a recent project, needed to come up with a solution to close comments apart from a cron job and without adding yet another module to the site.
I decided to make use of drush and created my first drush command.
With the drush file properly installed, I can now execute the following command from the site root directory:
drush comment-close --days=7 --types=story,blog
This command will close comments on all story and blog nodes that are older than 7 days.
Drupal Camp Indy
Mon, 09/20/2010 - 23:59 | by nathanThe folks over in Indiana are organizing a Drupal Camp on October 23. Hope you can make it.
DROP all MySQL tables from the command line
Fri, 09/10/2010 - 16:40 | by nathanI had a situation today where I wanted to drop all the tables in a database, but didn't have access to a UI like phpMyAdmin. The easiest thing to do would have been to drop the entire database then re-create it, but I didn't have permissions to drop an entire database.
After searching around online, this is the best solution I found:
Export a single row from a mysql table
Wed, 09/08/2010 - 16:19 | by nathanWhile it doesn't happen that often, occasionally I'll need to export a certain subset of data from a MySQL table instead of the entire dataset. You can do this with mysqldump using the --where option which allows you to apply a WHERE clause that filters the data in your tables based on a certain condition.
Let's say in Drupal, you'd like to copy a single comment from one table into another.


