masquerade.install 4.8 KB

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