You are here

function webform_update_6328 in Webform 6.3

Convert the Date component start and end year options to start and end date.

File

./webform.install, line 1426
Webform module install/schema hooks.

Code

function webform_update_6328() {
  $ret = array();
  $result = db_query("SELECT * FROM {webform_component} WHERE type = 'date'");
  while ($component = db_fetch_array($result)) {
    $component['extra'] = unserialize($component['extra']);
    if (!isset($component['extra']['start_date']) && !isset($component['end_date'])) {
      foreach (array(
        'year_start' => 'start_date',
        'year_end' => 'end_date',
      ) as $key => $replacement) {
        $value = isset($component['extra'][$key]) ? trim($component['extra'][$key]) : '';

        // Relative years.
        if (preg_match('/[-+][ ]*[0-9]+/', $value)) {
          $component['extra'][$replacement] = $value == 1 ? $value . ' year' : $value . ' years';
        }
        elseif (is_numeric($value)) {
          $component['extra'][$replacement] = 'Dec 31 ' . $value;
        }
        unset($component['extra'][$key]);
      }
      $component['extra'] = serialize($component['extra']);
      drupal_write_record('webform_component', $component, array(
        'nid',
        'cid',
      ));
    }
  }
  return $ret;
}