You are here

function quicktabs_update_6002 in Quick Tabs 6.2

Same name and namespace in other branches
  1. 6.3 quicktabs.install \quicktabs_update_6002()

Update the tabs to the new format.

File

./quicktabs.install, line 107

Code

function quicktabs_update_6002() {
  $ret = array();
  $result = db_query('SELECT qtid FROM {quicktabs}');
  while ($row = db_fetch_object($result)) {
    $quicktabs = db_fetch_array(db_query('SELECT tabs, ajax FROM {quicktabs} WHERE qtid = %d', $row->qtid));
    $quicktabs['tabs'] = unserialize($quicktabs['tabs']);
    foreach ($quicktabs['tabs'] as $key => $tab) {
      $newtab = array();
      $newtab['type'] = $tab['type'];
      $newtab['weight'] = $tab['weight'];
      $newtab['title'] = $tab['title'];
      switch ($tab['type']) {
        case 'view':
          if (isset($tab['vid'])) {

            // This is in new format already, don't change.
            $newtab['vid'] = $tab['vid'];
          }
          else {
            if ($quicktabs['ajax']) {
              $newtab['vid'] = $tab['bnid'];
            }
            else {
              $newtab['vid'] = $tab['bvid'];
            }
          }
          $newtab['display'] = $tab['display'];
          $newtab['args'] = $tab['args'];
          break;
        case 'block':
          if (isset($tab['bid'])) {

            // This is in new format already, don't change.
            $newtab['bid'] = $tab['bid'];
          }
          else {
            $newtab['bid'] = $tab['bvid'];
          }
          $newtab['hide_title'] = isset($tab['hide_title']) ? $tab['hide_title'] : 0;
          break;
        case 'node':
          if (isset($tab['nid'])) {

            // This is in new format already, don't change.
            $newtab['nid'] = $tab['nid'];
          }
          else {
            $newtab['nid'] = $tab['bnid'];
          }
          break;
      }
      $quicktabs['tabs'][$key] = $newtab;
    }
    $quicktabs['tabs'] = serialize($quicktabs['tabs']);
    db_query("UPDATE {quicktabs} SET tabs = '%s' WHERE qtid = %d", $quicktabs['tabs'], $row->qtid);
  }
  return $ret;
}