planet

Views random seed

Guilty as charged: I didn't really do much work on PM during the conference, but I ended up releasing a new version of Nodes in block and a new module called Views random seed for views 2. The module adds a random order handler with seed. If a constant integer argument N is specified in the sql RAND() function, it is used as the seed value, which produces a repeatable sequence of column values. This makes it possible to have paging and not having items show up twice.

See http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html#funct... for more info about RAND() and the optional integer argument.

Anyway, it was a cool week in DC and we're off to New York tomorrow, Turn on the Bright Lights!

Enabling boost on a production site

This is not going to be a tutorial on how to install and configure boost on a Drupal installation. No, I'm here to tell you a funny story and to remind myself a frustrating debugging session we had this friday trying to install the module. For those who don't know boost yet: when enabled, the module will create html files for every page on your site and with a little help of some htaccess rules, you can bypass a complete Drupal bootstrap for anonymous users. So far, so good. We really needed to speed up a project, so we told a client to test this on an acceptance version of their site and after the green light, we enabled it too on the production site. Few minutes later, the phone rang, nobody was able to edit the site anymore, boost was serving cached pages to authenticated users, panic all over the place. It took us a few hours to realize we were so stupid not seeing a very obvious and logical boost behavior, so for myself and every one else, remember this:

  • A cookie called DRUPAL_UID is set or deleted whenever a user is authenticating or logging out from the site.
  • If this cookie ain't found, the access rule will try to match a cached version of the incoming page request.
  • After enabling boost and turning on static page caching on the performance page, there is no check to see if current users are authenticated, so DRUPAL_UID does not exist for their session.
  • Therefore, the htaccess rules will serve up any existing cached pages to everyone, authenticated or not.

This is all very logical, but on a friday morning and with a fairly upset client, trying to find a fast solution for a very strange problem can be mindboggling. After skimming the access and the boost code, we finally understood what was happening so we simply truncated the session table and told the client they should go to the login page and everything would be solved. You can even tell your client to go to /logout and /user.

So if you ever experience this too: Don't panic, truncate session table, sit back and relax :)

Topics 

drupal, cache, boost, planet

Having fun with Schema API

Everyone who works with Drupal probably knows CCK. For several reasons - which I'm not going to explain here - we decided to ditch CCK for a project we are currenly working on and write a custom module that adds field to a node type. We need a couple of node types, but instead of using CCK to add new fields, we use the Schema API to define database tables and fields. Besides the known keys from the API, we defined a couple of our own which we use to build node forms. A quick example:

<?php
function hook_schema() {
 
$schema['example'] = array(
   
'fields' => array(
     
'example_field' => array(
       
'type' => 'varchar',
       
'description' => 'Example description',
       
'not null' => TRUE, // Used to set #required or not
       
'#title' => 'Example title',
       
'#widget' => 'textfield',
       
'#widget_validate' => 'validation function',
       
// Other keys like #widget_options, #widget_save etc ...
     
), 
    ),
   
// ...
 
);

  return

$schema;
}
?>

When a node edit form is displayed and we can confirm the node type supports our form functions (with a simple hook), the schema is analyzed and it will render a textfield. All default FAPI elements in Drupal are supported of course and if we need something else, we can either use hook_elements to expose new form element types or install other API's out there which expose useful form elements (eg Date API). CRUD operations and loading data into the node object is handled by our code, so we are now able to easily create multiple node types with extra fields thanks to the extra keys we define in the install files. Basic support for multiple values (only one table!) and exposing fields to views is already done too, so we have a pretty solid API to play with.

Right now, we aren't sure if we're going public with the code because:

  • Only D6 is interesting since D5 core doesn't come with Schema API and D7 now has fields in core.
  • CCK is the de-facto standard for creating new node types with extra fields
  • CCK is more supported and widely used
  • our tool is really more of a developers tool

What I really wanted to tell with this post is that Drupal comes with a strong API and that with a bit of imagination you are able to achieve really cool things. If you want some more details, feel free to bug me at the next DrupalCon in DC, I'd be happy to show you some code and a quick demo.

Topics 

drupal, schema api, planet

Mobile uploads on your drupal site

I'm a proud owner of an iPhone since a week now and I'm completely hooked on it. Being able to read my mail, check my facebook status or lookup a street on google maps is simply amazing and handy too. I'm also a fan of taking pictures with a mobile phone. In the past, I had to download the pictures and upload them manually on my site which is stupid right ? With the facebook application on your iPhone, it's possible to upload pictures to your facebook account, but I really don't want to maintain 2 galleries or abandon my own site. Luckily, I'm a Drupal addict and 2 very cool modules called Mailhandler and Mailsave come to the rescue. Mailhandler enables you to connect to a mailbox and retrieve messages and submit them as nodes on your site. Mailsave has a submodule called 'Mail to image' which connects with Image. So from now on, all new images in my Random photos gallery will be mailed via my iPhone to a special e-mail address and processed thanks to mailhandler - and Drupal of course!

Note, although the mailsave project page tells you to download the project from HEAD, you can safely download the latest D6 release which works perfectly with image alpha4.

Performance: Block Cache Alter

I just submitted Block Cache Alter for Drupal 6 which lets you alter cache settings per block on the configuration screen. Cache settings per block are now set in code, but if you don't like the default - usually none, you can now easily change this. Install this to speed up block rendering for authenticated users.

There are also two patches in the D7 queue now that might interest you:

  • Currently block caching support in views 2 is disabled, probably until 235673 gets in and backported.
  • I submitted this module as a patch (imagine how small it is) as a feature request for D7, review it on #347350.

Off-topic, I'm still looking for another maintainer for PicLens. File an issue and I'd be happy to move it over.

Topics 

drupal, cache, planet, blocks

Pages

Subscribe to RSS - planet

You are here