[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/masquerade/ -> masquerade.install (source)

   1  <?php
   2  // $Id: masquerade.install,v 1.4.2.7 2010/05/31 23:14:20 deviantintegral Exp $
   3  
   4  /**
   5   * @file masquerade.install
   6   *
   7   * Install, uninstall and update hooks for the Masquarade module.
   8   */
   9  
  10  /**
  11   * Implementation of hook_schema().
  12   *
  13   * @return array
  14   */
  15  function masquerade_schema() {
  16    return array(
  17      'masquerade' => array(
  18        'description' => "Each masquerading user has their session recorded into the masquerade table. Each record represents a masquerading user.",
  19        'fields' => array(
  20          'sid' => array(
  21            'description' => "The current session for this masquerading user corresponding to their {sessions}.sid.",
  22            'type' => 'varchar',
  23            'length' => '64',
  24            'not null' => TRUE,
  25            'default' => ''),
  26          'uid_from' => array(
  27            'description' => 'The {users}.uid corresponding to a session.',
  28            'type' => 'int',
  29            'not null' => TRUE,
  30            'default' => 0,
  31            'disp-width' => '10'),
  32          'uid_as' => array(
  33            'description' => 'The {users}.uid this session is masquerading as.',
  34            'type' => 'int',
  35            'not null' => TRUE,
  36            'default' => 0,
  37            'disp-width' => '10')
  38        ),
  39        'indexes' => array(
  40          'sid' => array('sid', 'uid_from'),
  41          'sid_2' => array('sid', 'uid_as')
  42        )
  43      ),
  44      'masquerade_users' => array(
  45        'description' => 'Per-user permission table granting permissions to switch as a specific user.',
  46        'fields' => array(
  47          'uid_from' => array(
  48            'description' => 'The {users}.uid that can masquerade as {masquerade_users}.uid_to.',
  49            'type' => 'int',
  50            'not null' => true,
  51            'default' => 0,
  52            'disp-width' => 10,
  53          ),
  54          'uid_to' => array(
  55            'description' => 'The {users}.uid that {masquerade_users}.uid_from can masquerade as.',
  56            'type' => 'int',
  57            'not null' => true,
  58            'default' => 0,
  59            'disp-width' => 10,
  60          ),
  61        ),
  62        'primary key' => array('uid_from', 'uid_to'),
  63      ),
  64    );
  65  }
  66  
  67  /**
  68   * Implementation of hook_install().
  69   */
  70  function masquerade_install() {
  71    drupal_install_schema('masquerade');
  72    db_query("UPDATE {system} SET weight = -10 WHERE name = 'masquerade'");
  73  }
  74  
  75  /**
  76   * Implementation of hook_uninstall().
  77   */
  78  function masquerade_uninstall() {
  79    drupal_uninstall_schema('masquerade');
  80    variable_del('masquerade_test_user');
  81    variable_del('masquerade_admin_roles');
  82    variable_del('masquerade_quick_switches');
  83  }
  84  
  85  /**
  86   * Implementation of hook_update_N().
  87   *
  88   * Update for http://drupal.org/node/281468
  89   * Adding support for multiple quick links in the Masquerade block.
  90   */
  91  function masquerade_update_5000() {
  92    // If test user was previously configured, add that as the first quick switch user.
  93    $masquerade_test_user = variable_get('masquerade_test_user', '');
  94    $masquerade_test_uid = db_result(db_query("SELECT uid FROM {users} WHERE name = '%s'", $masquerade_test_user));
  95    if ($masquerade_test_uid) {
  96      variable_set('masquerade_quick_switches', array($masquerade_test_uid => $masquerade_test_uid));
  97    }
  98    return array();
  99  }
 100  
 101  /**
 102   * Implementation of hook_update_N().
 103   */
 104  function masquerade_update_6001() {
 105    variable_set('masquerade_quick_switches', implode(',', variable_get('masquerade_quick_switches', array())));
 106    return array();
 107  }
 108  
 109  /**
 110   * Make the sid column match the length of the core sessions table (64 characters).
 111   */
 112  function masquerade_update_6002() {
 113    $ret = array();
 114    db_drop_index($ret, 'masquerade', 'sid');
 115    db_drop_index($ret, 'masquerade', 'sid_2');
 116    db_change_field($ret, 'masquerade', 'sid', 'sid', array(
 117      'type' => 'varchar',
 118      'length' => '64',
 119      'not null' => TRUE,
 120      'default' => '')
 121    );
 122    db_add_index($ret, 'masquerade', 'sid', array('sid', 'uid_from'));
 123    db_add_index($ret, 'masquerade', 'sid_2', array('sid', 'uid_as'));
 124    return $ret;
 125  }
 126  
 127  /**
 128   * Change masquerade_quick_switches variable to store a serialized array of
 129   * user ID's. Reverts update 6001.
 130   */
 131  function masquerade_update_6003() {
 132    $users = variable_get('masquerade_quick_switches', NULL);
 133    if (!empty($users)) {
 134      $user_ids = drupal_explode_tags($users);
 135      if (!empty($user_ids)) {
 136        variable_set('masquerade_quick_switches', $user_ids);
 137      }
 138    }
 139    else {
 140      variable_del('masquerade_quick_switches');
 141    }
 142    return array();
 143  }
 144  
 145  /**
 146   * Set the weight of the masquerade module to -10, but only if it hasn't
 147   * previously been changed.
 148   */
 149  function masquerade_update_6004() {
 150    $ret = array();
 151    $ret[] = update_sql("UPDATE {system} SET weight = -10 WHERE name = 'masquerade' AND weight = 0");
 152    return $ret;
 153  }
 154  
 155  /**
 156   * Add a table storing specific user pairings a user can masquerade as.
 157   */
 158  function masquerade_update_6005() {
 159    $ret = array();
 160    $schema = array(
 161      'masquerade_users' => array(
 162        'fields' => array(
 163          'uid_from' => array(
 164            'type' => 'int',
 165            'not null' => true,
 166            'default' => 0,
 167            'disp-width' => 10,
 168          ),
 169          'uid_to' => array(
 170            'type' => 'int',
 171            'not null' => true,
 172            'default' => 0,
 173            'disp-width' => 10,
 174          ),
 175        ),
 176        'primary key' => array('uid_from', 'uid_to'),
 177      )
 178    );
 179    db_create_table($ret, 'masquerade_users', $schema['masquerade_users']);
 180    return $ret;
 181  }
 182  


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7