Tuesday, June 5

Troubleshooting Drupal Cron

 Faced a couple of Problems in cron.
1. Cron Job Failed, May be other cron running prior to our user cron is failing
Solution to check:
Go into module.inc and in the function module_invoke_all
add this extra line:
foreach (module_implements($hook) as $module) {
$function = $module .'_'. $hook;

if ($hook == 'cron') watchdog('cron', "hit $module cron"); // add this line
You should be able to check out your watchdog log and see which module is killing cron.
You ll get additional info of which modules cron is failing.
2. Cron run exceeded the time limit and was aborted.
Solution to check:
Set max_exection_time in php.ini to 0
3. Attempting to re-run cron while it is already running.
Solution to check:
select * FROM variable WHERE name='cron_semaphore';
delete FROM variable WHERE name='cron_semaphore';
So it ll delete the cron lock which is running for long time and got stuck


500 internal server error in Drupal





This happens at time when you commit your files from local to DEV or Production environment.
This may happen because of missing to (Add & Commit) any particular module or files. So make sure you commit everything. :)


Sunday, June 3

Theming Hierarchical select !!!




Theming Hierarchical select Element which you have added to your FAPI or CCK.

function <<themename>>_hierarchical_select_form_element($element, $value) {
  $output = '<div class="form-item hierarchical-select-wrapper-wrapper"';
  if (!empty($element['#id'])) {
    $output .= ' id="'. $element['#id'] .'-wrapper"';
  }
  $output .= ">\n";
  $required = !empty($element['#required']) ? '<span class="form-required" title="'. t('This field is required.') .'">*</span>' : '';

  if (!empty($element['#title'])) {
    $title = $element['#title'];
    if (!empty($element['#id'])) {
      $output .= ' <label for="'. $element['#id'] .'">'. t('!required !title', array('!title' => filter_xss_admin($title), '!required' => $required)) ."</label>\n";
    }
    else {
      $output .= ' <label>'. t('!title: !required', array('!title' => filter_xss_admin($title), '!required' => $required)) ."</label>\n";
     //  $output .= ' <label for="'. $element['#id'] .'">'. t('!required !title', array('!title' => filter_xss_admin($title), '!required' => $required)) ."</label>\n";
    }
  }

  $output .= " $value\n";

  if (!empty($element['#description'])) {
    $output .= ' <div class="description">'. $element['#description'] ."</div>\n";
  }

  $output .= "</div>\n";

  return $output;
}


Copy the above code to your template.php and tweak it !!!!


Hierarchical Select Doesn't Support label for second drop down which coming out on your select.
To have one.. try this code


Else part will add Label to second Drop Down


function <<themename>>_hierarchical_select_select($element) {
  $select = '';
  $size = $element['#size'] ? ' size="'. $element['#size'] .'"' : '';
  $class = array('form-select');
  if (form_get_error($element) === '') {
    $class = array_merge($class, array('error'));
  }
  _form_set_class($element, $class);
  $multiple = isset($element['#multiple']) && $element['#multiple'];
   if ($element['#id']=='<<Parent Hierarchical Element ID>>') {
     $label = '';
   }
   else
   {
     $label = '<label for="hierarchical-select-16-wrapper"><span title="This field is required." class="form-required">*</span> States</label>';
   }

  return $label.'<select name="'. $element['#name'] .''. ($multiple ? '[]' : '') .'"'. ($multiple ? ' multiple="multiple" ' : '') . drupal_attributes($element['#attributes']) .' id="'. $element['#id'] .'" '. $size .'>'. _hierarchical_select_options($element) .'</select>';
}



If you find an easier way to do this..pls do comment.. Thanks :)


Sowmi


Friday, June 1

Drupal: Importing Country States list to Hierarchical Taxonomy

Download Country and States complete list from any web Service
Install Taxonomy Csv Module
Make csv format as
country,state
ex: India,Chennai
Import it with  http://drupal.org/project/taxonomy_csv
Get it Started !!!