You are here

function themekey_update_6200 in ThemeKey 6.2

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

Implements hook_update_N().

File

./themekey.install, line 258
Database schema of @author Markus Kalkbrenner | Cocomore AG

Code

function themekey_update_6200() {
  $field = array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => '0',
    'initial' => '1',
  );
  db_add_field($ret, 'themekey_properties', 'enabled', $field);
  db_drop_index($ret, 'themekey_properties', 'property');
  db_add_index($ret, 'themekey_properties', 'enabled', array(
    'enabled',
  ));
  $field = array(
    'type' => 'text',
    'not null' => TRUE,
  );
  db_add_field($ret, 'themekey_properties', 'wildcards', $field);
  $weight = (int) db_result(db_query("SELECT MIN(weight) FROM {themekey_properties}")) - 1;
  $insert_query = "INSERT INTO {themekey_properties} (property, value, weight, conditions, theme, enabled, wildcards) VALUES ('drupal:path', '%s', %d, '%s', '%s', 1, '%s')";
  $result = db_query("SELECT * FROM {themekey_paths} WHERE custom = 1");
  while ($item = db_fetch_array($result)) {
    $conditions = unserialize($item['conditions']);
    if (is_array($conditions) && !empty($conditions)) {
      if (!is_array($conditions[0])) {

        // ThemeKey 6.x-1.1 stored conditions for paths as simple string within an array
        $conditions = _themekey_properties_explode_conditions($conditions[0]);
      }
    }
    $insert_success = db_query($insert_query, $item['path'], $weight, serialize($conditions), $item['theme'], $item['wildcards']);
    $ret[] = array(
      'success' => $insert_success,
      'query' => $insert_query,
    );
    $ret[] = update_sql('DELETE FROM {themekey_paths} WHERE id = ' . $item['id']);
  }
  db_drop_field($ret, 'themekey_paths', 'conditions');
  db_drop_field($ret, 'themekey_paths', 'custom');
  db_drop_field($ret, 'themekey_paths', 'theme');
  return $ret;
}