You are here

function themekey_update_6105 in ThemeKey 7.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. 6.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 252
Database schema of

Code

function themekey_update_6105() {

  // Coder module complains "global variables should start with a single
  // underscore followed by the module and another underscore". But $db_type is
  // defined by drupal core.
  // @ignore style_global_vars
  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) {
      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 = :property AND conditions = :conditions";
        }
        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 = :property AND conditions = :conditions";
        }
        if ($result = db_query($sql, array(
          ':property' => 'node:nid',
          ':conditions' => 'a:0:{}',
        ))) {
          foreach ($result as $row) {
            $return['INSERT']['success'] = db_insert('themekey_ui_node_theme')
              ->fields(array(
              'nid' => $row->nid,
              'vid' => $row->vid,
              'theme' => $row->theme,
            ))
              ->execute();
            if ($return['INSERT']['success']) {
              $return['DELETE']['success'] = db_delete('themekey_properties')
                ->condition('id', $row->id)
                ->execute();
              if (!$return['DELETE']['success']) {
                break;
              }
            }
            else {
              $return['INSERT']['success'] = FALSE;
              break;
            }
          }
          $return = t('Themekey UI was successfully updated');
        }
        else {
          $return = t('Update of Themekey UI failed.');
        }
      }
      variable_del('themekey_nodeaspath');
    }
  }
  return $return;
}