Helper scripts and settings

Events happening in the community are now at Drupal community events on www.drupal.org.
You are viewing a wiki page. You are welcome to join the group and then edit it. Be bold!

If you are creating install profiles and developed some script to help develop it, post it here!

Pathauto settings

Pathauto enabled in installation profile doesn't work unless some variables are set.

Note that I've implemented these in pathauto_install as part of this issue: http://drupal.org/node/113496 So if you use the 5.x--2 version of pathauto then these are no longer necessary (and the version one is outdated). You could still use them as the basis to set your own configuration. --greggles

These are:

<?php
  variable_set
('pathauto_version', array('text' => "2005-9-18", "build" => 5));
 
variable_set('pathauto_indexaliases_bulkupdate', 0);
 
variable_set('pathauto_node_supportsfeeds', 'feed');
 
variable_set('pathauto_taxonomy_supportsfeeds', '0/feed');
 
variable_set('pathauto_user_supportsfeeds', '');
 
variable_set('pathauto_modulelist', array('node', 'taxonomy', 'user'));
 
variable_set('pathauto_verbose', 0);
 
variable_set('pathauto_separator', "-");
 
variable_set('pathauto_quotes', "0");
 
variable_set('pathauto_max_length', "100");
 
variable_set('pathauto_max_component_length', "100");
 
variable_set('pathauto_indexaliases', 0);
 
variable_set('pathauto_update_action', "2");
 
variable_set('pathauto_ignore_words', "a,an,as,at,before,but,by,for,from,is,in,into,like,of,off,on,onto,per,since,than,the,this,that,to,up,via,with");
 
variable_set('pathauto_node_pattern', "[title]");
 
variable_set('pathauto_node_page_pattern', "");
 
variable_set('pathauto_node_story_pattern', "");
 
variable_set('pathauto_node_bulkupdate', 0);
 
variable_set('pathauto_node_applytofeeds', 0);
 
variable_set('pathauto_taxonomy_pattern', "[vocab]/[catpath]");
 
variable_set('pathauto_taxonomy_bulkupdate', 0);
 
variable_set('pathauto_taxonomy_applytofeeds', 0);
 
variable_set('pathauto_user_pattern', "user/[user]");
 
variable_set('pathauto_user_bulkupdate', 0);
?>

The above are the default settings for Pathauto as of today, note that these will change with newer versions. To make sure you give Pathauto the correct list of variables, you can (in a clean Drupal installation) do the following:
  1. Install the Pathauto module and enable it
  2. Go to admin/settings/pathauto and click Save configuration
  3. In your favorite MySQL console (e.g. phpMyAdmin), export all pathauto_* fields in the variable table
  4. Manually decipher the serialized values and write corresponding variable_set() lines for each variable

Configure default aliases

This is a snippet of code to insert aliases into the datatbase that you have preconfigured. Simply change the values of each array element to be 'original_path', 'new_alias'. Do not use a trailing or leading backslash.

<?php
$url_aliases
= array(
 
"'original_path','new_alias'",
 
"'taxonomy/term/3','alias/for/taxonomy/term/3'",
);

foreach (
$url_aliases as $alias) {
 
path_set_alias($alias);
};
?>

Database changes (diff)

This little script helps me determining what changed in database after i done some action on the web. It's far from ideal and i recommend disabling locale module when developing installation profile, but it definitely works. The output is diff. You need to create directory "dbchanges". Please note that this script shouldn't be accessible from browser.

#!/bin/bash

dbname="YOUR DB NAME"
dbuser="YOUR DB USER"
dbpass="YOUR DB PASSWORD"
changesdir="./dbchanges"
mysqldump=which mysqldump

if [ ! -d "$changesdir" ]; then
echo "Directory $changesdir does not exist";
exit 1;
fi

# determine last database dump and prepare next
last=ls &quot;$changesdir&quot; | sort -rn | head -1
if [ -z "$last" ]; then
next="1"
else
next=$(($last + 1))
fi

$mysqldump "$dbname" -u "$dbuser" --password="$dbpass" > "$changesdir/$next"

if [ "$next" -eq 1 ]; then
echo "First dump at all, not diffing";
exit 0;
else
diff -u "$changesdir/$last" "$changesdir/$next" | grep -v "-- Dump completed on" | grep -v "locales_source" | grep -v "locales_target"
fi

Custom welcome message

Update, hopefully this hack won't be necessary with Drupal 6.x 7.x, see http://drupal.org/node/126221

I have a profile for which I wished to change the default "Welcome to your new Drupal site!" message that is displayed when no nodes are published and promoted. This message is unfortunately hard coded in the node module under the function node_page_default. To recreate this functionality with different text, I made a module to include all the additional helper functions for my install profile/distro and put in a menu callback to a copy of that function registered at a different path, such as 'welcome.' The code in the module looks something like this:

(Refer to node_page_default to get the original text if you want. )

<?php
function modulename_menu($may_cache) {
 
$items = array();
  if (
$may_cache) {
   
$items[] = array(
     
'path' => 'welcome',
     
'title' => t('Content'),
     
'callback' => 'modulename_page_default',
     
'access' => user_access('access content'),
     
'type' => MENU_CALLBACK
   
);
  }

  return
$items;
};

function
modulename_page_default() {

 
$result = pager_query(db_rewrite_sql('SELECT n.nid, n.sticky, n.created FROM {node} n WHERE n.promote = 1 AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC'), variable_get('default_nodes_main', 10));

  if (
db_num_rows($result)) {
   
$feed_url = url('rss.xml', NULL, NULL, TRUE);
   
drupal_add_feed($feed_url, variable_get('site_name', 'Drupal') .' '. t('RSS'));

   
$output = '';
    while (
$node = db_fetch_object($result)) {
     
$output .= node_view(node_load($node->nid), 1);
    }
   
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
  }
  else {
   
// Check for existence of admin account.
   
$admin = db_result(db_query('SELECT uid FROM {users} WHERE uid = 1'));

   
$default_message = t('<h1 class="title">Welcome to your new Drupal/install profile!</h1>');
   
$default_message .= '<ol>';

    if (!
$admin) {
     
$default_message .= '<li>'. t('<strong>Create your administrator account</strong> To begin, <a href="@register">create the first account</a>. This account will have full administration rights and will allow you to configure your website.', array('@register' => url('user/register'))) .'</li>';
    }
   
$default_message .= '<li>'. t('Rest of your welcome message goes here.......') .'</li>';
   
$default_message .= '</ol>';

   
$output = '<div id="first-time">'. $default_message .'</div>';
  }
 
drupal_set_title('');

  return
$output;
};
?>

Drop this in profiles/example/modules along with a .info file, enable the module in your profile, and drop variable_set('site_frontpage', 'welcome'); (or whatever you register as the new path) in your .profile and you should be seeing a new custom welcome message upon install!

Configure LoginToboggan

<?php
// Configure LoginToboggan
 
variable_set('login_with_mail', "1");
 
variable_set('email_reg_confirm', "1");
 
variable_set('user_email_verification', 1);
 
variable_set('site_403', "toboggan/denied");
 
variable_set('login_successful', "1");
 
variable_set('toboggan_min_pass_length', "4");
?>

Configure Taxonomy: Vocabularies

This creates an array of values to pass on to taxonomy_save_vocabulary(). The array is keyed to match the vocabulary edit page as well as the vocabulary table, so if you have any questions about the values, please look there. Create as many arrays within $vocabularies as you need. The nodes element does have to contain array for taxonomy_save_vocaulary() to process it correctly, but no value is required.

<?php
$vocabularies
= array(
  array(
// this is the first vocab that we are going to create
   
'name' => 'Vocabulary 1',
   
'description' => 'description goes here',
   
'help' => 'enter help text to go on edit form of content types below',
   
'relations' => '1',
   
'hierarchy' => '0',
   
'multiple' => '1',
   
'required' => '0',
   
'tags' => '0',
   
'module' => 'taxonomy',
   
'weight' => '0',
   
'nodes' => array('blog' => NULL), // add an element for each type of content that you wish to enable the vocabulary
 
),
  array(
// this is the second vocab that we are going to create
   
'name' => 'Vocabulary 2',
   
'description' => 'description goes here',
   
'help' => 'enter help text to go on edit form of content types below',
   
'relations' => '1',
   
'hierarchy' => '0',
   
'multiple' => '1',
   
'required' => '0',
   
'tags' => '1', // this is a free tagging vocabulary
   
'module' => 'taxonomy',
   
'weight' => '0',
   
'nodes' => array(
     
'blog' => NULL, // add an element for each type of content that you wish to enable the vocabulary
     
'story' => NULL,
     
'page' => NULL,
     
'audio' => NULL,
    ),
  ),
);

foreach (
$vocabularies as $vocabulary) {
  switch (
taxonomy_save_vocabulary($vocabulary)) {
    case
SAVED_UPDATED:
     
drupal_set_message(t('Updated vocabulary %name.', array('%name' => $vocabulary['name'])));
      break;
    case
SAVED_NEW:
     
drupal_set_message(t('Created vocabulary %name.', array('%name' => $vocabulary['name'])));
      break;
  }
}
?>

Configure Taxonomy: Terms

In order to configure terms reliably we need a function to return the vid of our newly created vocabularies in order to assure that we have the correct vid to insert in our terms. This is required because some modules may install their own Vocabularies. This function must be placed before the code where it is called in the install profile.

<?php
// Get the vid of our newly created terms
function install_get_vid($name) {
    return
db_result(db_query("SELECT vid FROM {vocabulary} WHERE name = '%s'", $name));
};
?>

To actually create the terms, we will make and array containing all of them. The 'vid' is set to install_get_vid('Vocabulary'), where Vocabulary is the name of the Vocabulary you want to list the term under.

<?php
$term_data
= array(
  array(
   
'vid' => install_get_vid('Vocabulary 1'), // Vocabulary 1 is the Vocabulary we want this term to be listed under
   
'name' => 'Term 1',
   
'description' => 'a description of the term',
   
'weight' => 0,
  ),
  array(
   
'vid' => install_get_vid('Example'), // Example is the Vocabulary we want this term to be listed under
   
'name' => 'Another term',
   
'description' => 'a description of the term',
   
'weight' => 0,
  ),
);

foreach (
$term_data as $term) {
  switch(
taxonomy_save_term($term)) {
    case
SAVED_UPDATED:
     
drupal_set_message(t('Updated term %name.', array('%name' => $term['name'])));
      break;
    case
SAVED_DELETED:
     
drupal_set_message(t('Deleted term %name.', array('%name' => $term['name'])));
      break;
  }
};
?>

Distributions

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: