You are here

function themekey_update_6105 in ThemeKey 6.3

Same name and namespace in other branches
  1. 6.4 themekey.install \themekey_update_6105()
  2. 6.2 themekey.install \themekey_update_6105()
  3. 7.3 themekey.install \themekey_update_6105()
  4. 7 themekey.install \themekey_update_6105()
  5. 7.2 themekey.install \themekey_update_6105()

Implements hook_update_N().

File

./themekey.install, line 151
Database schema of

Code

function themekey_update_6105() {
  global $db_type;
  $return = array();

  // we need to handle upgrade of module ThemeKey UI here because
  // it will fail when triggered at themekey_ui.install after
  // ThemeKey upgrade from 6.x-1.1 to 6.x.2.0
  if (module_exists('themekey_ui')) {
    $schema_version = drupal_get_installed_schema_version('themekey_ui');
    if (6100 > $schema_version) {
      $return = drupal_install_schema('themekey_ui');
      if (!variable_get('themekey_nodeaspath', 0)) {
        $sql = '';
        if (0 === strpos($db_type, 'mysql')) {
          $sql = "SELECT id, value, theme, nid, vid FROM {themekey_properties} JOIN {node_revisions} ON (value = nid) WHERE property = 'node:nid' AND conditions = '%s'";
        }
        elseif (0 === strpos($db_type, 'pqsql')) {
          $sql = "SELECT id, value, theme, nid, vid FROM {themekey_properties} JOIN {node_revisions} ON (value = nid::character varying) WHERE property = 'node:nid' AND conditions = '%s'";
        }
        if ($result = db_query($sql, 'a:0:{}')) {
          $insert_sql = "INSERT INTO {themekey_ui_node_theme} (nid, vid, theme) VALUES (%d, %d, '%s')";
          $delete_sql = "DELETE FROM {themekey_properties} WHERE id = %d";
          while ($row = db_fetch_array($result)) {
            if ($return['INSERT']['success'] = db_query($insert_sql, $row['nid'], $row['vid'], $row['theme'])) {
              if (!($return['DELETE']['success'] = db_query($delete_sql, $row['id']))) {
                break;
              }
            }
            else {
              $return['INSERT']['success'] = FALSE;
              break;
            }
          }
          if (isset($return['INSERT'])) {
            $return['INSERT']['query'] = check_plain($insert_sql);
          }
          if (isset($return['DELETE'])) {
            $return['DELETE']['query'] = check_plain($delete_sql);
          }
        }
        else {
          $return['SELECT'] = array(
            'success' => FALSE,
            'query' => check_plain($sql),
          );
        }
      }
      variable_del('themekey_nodeaspath');
    }
  }
  return $return;
}