You are here

spaces.install in Spaces 5.2

File

spaces.install
View source
<?php

/**
 * Implementaton of hook_install().
 */
function spaces_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      db_query("CREATE TABLE {spaces} (\n        sid int(10) NOT NULL default '0',\n        type varchar(64) NOT NULL,\n        preset varchar(64) NOT NULL,\n        customizer longtext NOT NULL,\n        KEY (sid)\n        ) /*!40100 DEFAULT CHARACTER SET UTF8 */");
      db_query("CREATE TABLE {spaces_presets} (\n        type varchar(64) NOT NULL,\n        id varchar(64) NOT NULL,\n        name varchar(255) NOT NULL,\n        description longtext NOT NULL,\n        value longtext NOT NULL,\n        KEY (type)\n        ) /*!40100 DEFAULT CHARACTER SET UTF8 */");
      db_query("CREATE TABLE {spaces_settings} (\n        sid int(10) NOT NULL default '0',\n        type varchar(64) NOT NULL,\n        id longtext NOT NULL,\n        value longtext NOT NULL,\n        KEY (sid)\n        ) /*!40100 DEFAULT CHARACTER SET UTF8 */");
      db_query("CREATE TABLE {spaces_features} (\n        sid int(10) NOT NULL default '0',\n        type varchar(64) NOT NULL,\n        id longtext NOT NULL,\n        value longtext NOT NULL,\n        KEY (sid)\n        ) /*!40100 DEFAULT CHARACTER SET UTF8 */");
  }
}

/**
 * Implementation of hook_uninstall()
 */
function spaces_uninstall() {

  // Drop database table
  db_query('DROP TABLE {spaces_settings}');
  db_query('DROP TABLE {spaces_features}');
  db_query('DROP TABLE {spaces_features_custom}');

  // Delete variables
  $variables = array();
  foreach ($variables as $variable) {
    variable_del($variable);
  }
}
function spaces_update_1() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':

      // Unweight spaces
      db_query("UPDATE {system} SET weight = 0 WHERE name = 'spaces'");

      // Rename gid to sid in spaces_features
      $ret[] = update_sql("ALTER TABLE {spaces_features} CHANGE COLUMN gid sid int(10) NOT NULL default '0'");
      $ret[] = update_sql("ALTER TABLE {spaces_features} ADD KEY(sid)");

      // Drop deprecated spaces_features_custom table
      $ret[] = update_sql("DROP TABLE {spaces_features_custom}");

      // Add spaces table
      db_query("CREATE TABLE {spaces} (\n        sid int(10) NOT NULL default '0',\n        type varchar(64) NOT NULL,\n        preset varchar(64) NOT NULL,\n        customizer longtext NOT NULL,\n        KEY (sid)\n        ) /*!40100 DEFAULT CHARACTER SET UTF8 */");

      // Add spaces_presets table
      db_query("CREATE TABLE {spaces_presets} (\n        type varchar(64) NOT NULL,\n        id varchar(64) NOT NULL,\n        name varchar(255) NOT NULL,\n        description longtext NOT NULL,\n        value longtext NOT NULL,\n        KEY (type)\n        ) /*!40100 DEFAULT CHARACTER SET UTF8 */");

      // Add spaces_settings table
      db_query("CREATE TABLE {spaces_settings} (\n        sid int(10) NOT NULL default '0',                \n        type varchar(64) NOT NULL,\n        id longtext NOT NULL,\n        value longtext NOT NULL,\n        KEY (sid)\n        ) /*!40100 DEFAULT CHARACTER SET UTF8 */");

      // Convert all previous spaces context prefixes to use spaces_og
      // Set preset types based on the deprecated spaces_groupmask
      $result = db_query("SELECT cp.*, og.* FROM {context_prefix} cp JOIN {og} og ON cp.id = og.nid WHERE cp.provider = 'spaces'");
      while ($row = db_fetch_object($result)) {
        $og = array(
          'og_selective' => $row->selective,
          'og_directory' => $row->directory,
          'og_register' => $row->register,
          'og_private' => $row->private,
        );
        $preset = _spaces_groupmask('check', $og) ? _spaces_groupmask('check', $og) : 'private';
        db_query("UPDATE {context_prefix} SET provider = '%s' WHERE provider = 'spaces' AND prefix = '%s'", 'spaces_og', $row->prefix);
        db_query("INSERT INTO {spaces} (sid, type, preset, customizer) VALUES(%d, '%s', '%s', '%s')", $row->id, 'og', $preset, '');
      }

      // Move settings into the spaces_settings table
      $result = db_query("SELECT * FROM {spaces_features} WHERE type = %d", 1);
      while ($setting = db_fetch_object($result)) {
        if ($setting->id == 'spaces_home') {
          $values = array(
            $setting->sid,
            'og',
            'home',
            serialize($setting->value),
          );
          db_query("INSERT INTO {spaces_settings} (sid, type, id, value) VALUES(%d, '%s', '%s', '%s')", $values);
          db_query("DELETE FROM {spaces_features} WHERE sid = %d AND id = '%s' AND type = %d", $setting->sid, 'spaces_home', 1);
        }
        else {
          if ($setting->id != 'shoutbox') {
            $values = array(
              $setting->sid,
              'og',
              $setting->id,
              serialize($setting->value),
            );
            db_query("INSERT INTO {spaces_settings} (sid, type, id, value) VALUES(%d, '%s', '%s', '%s')", $values);
            db_query("DELETE FROM {spaces_features} WHERE sid = %d AND id = '%s' AND type = %d", $setting->sid, $setting->id, 1);
          }
        }
      }

      // Switch type from int to string
      $ret[] = update_sql("ALTER TABLE {spaces_features} CHANGE COLUMN type type varchar(64) NOT NULL");

      // Assume all features were provided for og spaces
      db_query("UPDATE {spaces_features} SET type = '%s'", 'og');
      break;
  }
  return $ret;
}

/**
 * Legacy function. Included in order to migrate from older previous
 * versions of spaces.
 */
function _spaces_groupmask($op = 'mask', $og_settings = array()) {
  static $spacetype_mask;
  if (!$spacetype_mask) {
    $spacetype_mask = array(
      'private' => array(
        'label' => t('Private'),
        'limit options' => array(
          SPACES_PRIVATE,
        ),
        'mask' => array(
          'og_selective' => OG_CLOSED,
          'og_directory' => OG_DIRECTORY_NEVER,
          'og_register' => OG_REGISTRATION_ALWAYS,
          'og_private' => defined(OG_PRIVATE_GROUPS_ALWAYS) ? OG_PRIVATE_GROUPS_ALWAYS : 1,
        ),
      ),
      'controlled' => array(
        'label' => t('Controlled'),
        'mask' => array(
          'og_selective' => variable_get('spaces_controlled_selective', OG_CLOSED),
          'og_directory' => OG_DIRECTORY_ALWAYS,
          'og_register' => OG_REGISTRATION_ALWAYS,
          'og_private' => defined(OG_PRIVATE_GROUPS_NEVER) ? OG_PRIVATE_GROUPS_NEVER : 0,
        ),
      ),
      'public' => array(
        'label' => t('Public'),
        'limit options' => array(
          SPACES_PUBLIC,
        ),
        'mask' => array(
          'og_selective' => OG_OPEN,
          'og_directory' => OG_DIRECTORY_ALWAYS,
          'og_register' => OG_REGISTRATION_ALWAYS,
          'og_private' => defined(OG_PRIVATE_GROUPS_NEVER) ? OG_PRIVATE_GROUPS_NEVER : 0,
        ),
      ),
    );
  }
  switch ($op) {
    case 'mask':
      return $spacetype_mask;
    case 'check':
      foreach ($spacetype_mask as $key => $type) {
        if ($og_settings == $type['mask']) {
          return $key;
        }
      }
      return false;
    case 'labels':
      $labels = array();
      foreach ($spacetype_mask as $key => $type) {
        $labels[$key] = $type['label'];
      }
      return $labels;
  }
}

Functions

Namesort descending Description
spaces_install Implementaton of hook_install().
spaces_uninstall Implementation of hook_uninstall()
spaces_update_1
_spaces_groupmask Legacy function. Included in order to migrate from older previous versions of spaces.