Getting PHP + GD + PostgreSQL working on OSX 10.5 (aka recompiling everything)
Finding myself in need of a PostgreSQL server to test some patches for Drupal core, I've decided to do a follow up to my guide to getting PHP + GD + MySQL installed on OS X.
Fortunately for me John VanDyk wrote up Beginning with Drupal 6 and PostgreSQL on OS X 10.5 Leopard which covers the nitty gritty of getting PostgreSQL server installed. He doesn't address recompiling PHP so I'll pick up the story there.
Last Updated: June 1, 2009
HOWTO: Views 2 Relationships
After getting sick of closing issues in various module's issue queues that boiled down to people not knowing how to use Views 2's relationship feature I decided to make a screencast explaining it:
http://drewish.blip.tv/file/1593750/
I think I need to get a microphone, and figure out all the features of the tool I was using but I'm excited to do more of these.
Update: The GotDrupal folks have a much more detailed—and more understandable—screencast on this topic: http://gotdrupal.com/videos/drupal-views-relationships
Media sprinting
So back in April I started talking to Keiran at about doing a media and files sprint... well it's finally happening. aaronwinborn in in Portland and dopry is going to be helping remotely. Aaron posted a great writeup on what we're hoping to accomplish so I'll blockquote at length:
Andrew Morton (drewish), Darrel O'Pry (dopry, remotely), and I are heading up a Media Code Sprint in Portland this week! Come help, in person or remotely, if you're interested in multimedia and Drupal! It has now officially started, and as I've volunteered to help keep folks updated, here goes...
First the reasons.
Number One: Better Media Handling in Core
Dries conducted a survey prior to his State of Drupal presentation at Boston Drupalcon 2008, and number one on the top ten (or 11) list of what would make THE KILLER DRUPAL 7 Release was "Better media handling".
Let me repeat that. Better media handling.
People have done really amazing stuff in contrib, but it is difficult (if not impossible in many cases) for developers to coordinate the use of files, as there is no good means for file handling in the core of Drupal. Thus, we have several dozen (or more) media modules doing some small part, or even duplicating functionality, sometimes out of necessity.
Migrating from D6 upload.module to filefield.module
So building on my last post for creating CCK fields, here's some code I whipped up to migrate from the D6's core upload.module to the filefield.module. This isn't general purpose code but might help someone else out. The catch is I'd built a video node with and was using the upload module to attach exactly two files, an image and a video. The new node will have separate thumbnail and video fields. If you'll be moving to a multi-value field this code won't work for you.
The gist is the same as before, setup your field for video and your field for images then export using:
<?php
var_export(content_fields('field_web_video', 'video'), 1);
?><?php
var_export(content_fields('field_video_thumb', 'video'), 1);
?>Then roll that into an update function that also moves the file data around in the database. Code is after the jump.
Programatically creating a CCK field in Drupal 6
I spent some time today trying to figure out how to create a CCK field as part of an hook_update_N function. Unlike previous versions of CCK, in 6 it's very easy to manipulate the fields from code.
The first step is to create the field using CCK's UI. Once you've got the field setup the way you'd like it use PHP's var_export() to dump the contents of the node's field as an array:
var_export(content_fields('field_translator_note', 'feature'));Prefilling the ImageCache cache with wget
Today I needed to get Drupal's ImageCache module to regenerate a bunch of resized images. ImageCache doesn't create the images until a browser requests them and at that point the new image is saved to the disk for future use.
One way to generate the images would have been to just click my way through every page on the site but I'm way to lazy for that. So I used wget:
wget -r -nd --delete-after http://example.comBy using the recursive (-r) and --delete-after switches I was able to have it crawl the site and get all the images generated. Bonus points for running in on the server so that the transfers were via the loopback interface so the transfer didn't count against the monthly bandwidth limit.
DrupalCampPDX
I took a break today from my work at Sticky building a website for a major sports apparel company that cannot be named, for DrupalCampPDX. Ben Kaplan and I did the keynote presentation this morning which was definitely an honor. I followed that up with a panel on best development practices which was a bit unplanned but went really well. This afternoon I'm doing a presentation on Views2 and Panels2, I'm a little freaked out on that since I've done zero preparation at this point.
Drupal6: Display block for one node type
This is a little snippet I came up with to get a block to show up on a single node type:
<?php
$menu = menu_get_item();
if ($menu['path'] == 'node/%' && isset($menu['page_arguments'][0]->type)) {
return $menu['page_arguments'][0]->type == 'story';
}
?>It uses the node type stored in the menu system so you don't have to match
arg(0) etc.
Getting PHP + GD + pdo_mysql working on OSX 10.5 (aka recompiling everything)
This guide walks through the steps necessary to setup PHP on Leopard in order to run the HEAD version of Drupal. The basic steps are installing several prerequisites then recompiling Apache and PHP from source. It could totally bork your system, I'm just writing it down so the next time I need to do this I can remember what I did. I wish I could give credit to all the places I stole bits from but I didn't do a good job of keeping notes early on.
Every time Apple releases a security update it seems to end up overwriting PHP or Apache and I end up revisiting these instructions. Since it's my personal guide I'm continually modifying it to match my current needs. For example, the last big change was adding in old mysql extension and the new PDO-mysql extension. The upside for you, kind reader, is that this keeps the instructions up-to-date. The down side is that when you come back in two months and try to repeat one part of this it may not work because I've changed some of the earlier steps.
Last Updated: August 26, 2009
DrupalCon Day 1
Made it out to Boston last night. I'd gotten upgraded to business class on the flight from Portland to NYC which was a nice treat. NYC to Boston in coach was a bit of a blow to my ego but the scenery made up for it. The highlight of the flight was looking out the window and seeing a white speck fly by, it was three white balloons. As the sun set we were flying through a beautify pink mist.
I'm staying with a friend of my brother's friends. Great place but it's an hour away from the conference center by train/bus so I was up early this morning. I've got a nice tickle in my throat so I hope I don't end up sick.
Here's the presentations I'm hoping to hit today:
Sorting numeric values stored in character fields with views.module
I spent a good chunk of time this morning trying to figure out how to get the views module to sort a character field with numeric data correctly. The audio module has a normalized table of meta-data meaning that there's one column for the tag name and one for the value. The value is stored as a character string which causes problem when sorting numeric data like the track numbers or years. If you've got a SELECT value FROM audio_metadata ORDER BY value that returns the range of numbers 1...13 it ends up sorted as 1,10,11,12,13,2,3...9. The trick as I discovered is to add zero to the field to coerce it to a numeric value: SELECT value + 0 AS v FROM audio_metadata ORDER BY v.
The problem then is to figure out how to get the views module to generate this bit SQL to get the sorting right. The solution I came upon is when defining the field set 'notafield' to TRUE and provide a 'query_handler' to generate the correct SQL. I've included the relevant parts of the audio module below to demonstrate how it works. You can see the complete code here.
Technical writing
After installing a new hard drive I decided it was time to re-install Windows and clean everything up. I firmly believe that the best time to document something is when you're doing it. So I took the opportunity to write some instructions for setting up a Windows based Drupal development machine. I hope it's of use to someone.
Installing PHP 5 on Windows
This page provides instructions for a Drupal developer who'd like to install PHP 5 on their desktop computer. The instructions assume that you're running a recent version of Windows (NT, 2000, XP, or 2003). Older version like Windows 95, 98 and Me will not be addressed.
Installing MySQL Server on Windows
Download
The first step is to download the MySQL Server "Windows Essentials" binaries from the MySQL website at http://dev.mysql.com/downloads/mysql/. At the time this was written last updated, 5.1.46 was the latest, stable release. The file was named: mysql-essential-5.1.46-win32.msi. Make sure you save the file to a location on your hard drive where you can locate it.
Running multiple versions of Drupal on Windows
Once you've been developing Drupal modules for any length of time you find that you need to test code on multiple versions of Drupal. The easiest way to do this is have separate Drupal releases running as virtual hosts. In this guide I'll walk though setting up Apache virtual hosts for Drupal 5 and Drupal HEAD. I'm assuming you're running Windows 2000 or greater and that you've already gotten Apache, MySQL and PHP setup and running on your local machine.