Export from Git for Drupal site releases

I'm used to how svn export works, and have used this in a number of release scripts.

Git doesn't quite have an equivalent

There is

git archive

Which creates a tarball rather than a set of files, and while you can export a subset of the repository you still get the full path in the tarball.

and

git checkout-index

Which creates a set of files (these can be locate outside the working copy) but requires a local repository.

Read more

Instance parameter for drupal field_create_instance($instance)

The code in chapter 7 of pro Drupal development has a bug.

The $instance array that you need to pass to field_create_instance() needs to be as below.

Note that the display array has the keyword, 'default' for the default display - ie a node on it's own page 'teaser' looks like the right value for teaser. Other view modes are possible too.

Read more

node_save tags by term name with auto addition of new tags

Drupal lets you add a taxonomy term to a node and if you use the GUI you can have a nice auto-complete widget that takes term name - and iof the term doesn't exist yet you get a new term created when you save the node.

I wanted to access the same functionality on node I am generating from external data.

The key is to create the term array with tid = 'autocreate' - this and the vocabulary ID are enough to trigger the taxonomy module to lookup the tid for you - and adda new term is required.

<?php
$node = new stdClass();
$node->type='mytype';
$node-title='foo';

Read more

Drupal files directory permissions for continuous integration

I want the drupal user uploaded files to be manageable by both apache and a non-root user

In my case I'm using hudson to rebuild the site with data and "files" from live periodically.

So I have added the apache group to the hudson user

/usr/sbin/usermod -G hudson,apache hudson
/etc/init.d/hudson restart

and set the umask for apache so that files are created group writebale

For Redhat

echo "umask 002" >> /etc/sysconfig/httpd
/etc/init.d/httpd restart

For Debian/Ubuntu

echo "umask 002" >> /etc/apache2/envvars

Read more

Selenium UI-Elements

While playing around with selenium IDE I discovered a fantatsic tool that makes test (and results) more readable while making the suite of tests easier to adapt to layout changes.

What it does is to allow you to centrally define most of the xpath (and related) statements and give page elements meaningful names.

So instead of testing for some element like

//form[@id='search-block-form']//input[@type='text']

You can test for

ui=allPages::mainSearchField()

Read more

Integrating Selenium and Hudson

Hudson http://hudson-ci.org/ is a continuous integration server - it runs and monitors 'jobs' in a way that is useful to regularly build software and report on any errors.

Selenium http://seleniumhq.org/ is a suite of tools specifically for testing web
applications - it tests the full website by automating the running of one or more browsers (so you can test all that pointy clicky ajaxy stuff)

Read more

Programatically Delete a content type in Drupal

<?php
$result
= db_query("SELECT nid FROM node where type='mytype'");
while (
$row = db_fetch_object($result)) {
   
node_delete($row->nid);
}
node_type_delete('mytype');
?>

Read more

"Backport small changes to stable releases"

I've found the recent thread on distribution support very interesting.

An I'm especially excited by the prospects hinted at here

http://drupal.org/node/933846#comment-3545110

#42
webchick - October 7, 2010 - 21:40

Read more

Drupal upgrades and patches

Reading Greg's post on security upgrades and a few mentions of patches in the following discussion got me thinking about upgrade methods.

The standard Drupal method is to delete existing files and unpack a tarball to replace the old version - I find this method unappealing because: I keep my code in subversion so don't want to delete the .svn subdirectories, and sometimes I have patches applied that I don't want to loose.

Read more

Delete Drupal View programatically

Quick function to delete a view.

This is basically what the UI form submit does.

<?php
function delete_view($name) {

   
$view = views_ui_cache_load($name);
   
$view->delete();
   
views_object_cache_clear('view', $view->name);

}
?>

Read more