uc_roles.install 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the uc_roles module.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function uc_roles_schema() {
  10. $schema['uc_roles_products'] = array(
  11. 'description' => 'Maps purchasable roles to Ubercart products.',
  12. 'fields' => array(
  13. 'rpid' => array(
  14. 'description' => 'Primary key: the role-product id.',
  15. 'type' => 'serial',
  16. 'unsigned' => TRUE,
  17. 'not null' => TRUE,
  18. ),
  19. 'pfid' => array(
  20. 'description' => 'The {uc_product_features}.pfid of the product feature this is attached to.',
  21. 'type' => 'int',
  22. 'unsigned' => TRUE,
  23. 'not null' => TRUE,
  24. 'default' => 0,
  25. ),
  26. 'nid' => array(
  27. 'description' => 'The {node}.nid of the node this role feature is attached to.',
  28. 'type' => 'int',
  29. 'unsigned' => TRUE,
  30. 'not null' => TRUE,
  31. 'default' => 0,
  32. ),
  33. 'model' => array(
  34. 'description' => 'The product model.',
  35. 'type' => 'varchar',
  36. 'length' => 255,
  37. 'default' => NULL,
  38. ),
  39. 'rid' => array(
  40. 'description' => 'The {role}.rid that is purchased with the attached product.',
  41. 'type' => 'int',
  42. 'unsigned' => TRUE,
  43. 'not null' => TRUE,
  44. 'default' => 0,
  45. ),
  46. // Start of expiration period
  47. // Not actually implemented yet, this is a placeholder.
  48. 'start_override' => array(
  49. 'description' => 'Override the store default start time? 1 => Yes. 0 => No.',
  50. 'type' => 'int',
  51. 'size' => 'tiny',
  52. 'not null' => FALSE,
  53. 'default' => 0,
  54. ),
  55. 'start_time' => array(
  56. 'description' => 'Role expiration start time. 0 signifies to start at product purchase.',
  57. 'type' => 'int',
  58. 'not null' => FALSE,
  59. 'default' => 0,
  60. ),
  61. // End of expiration period
  62. 'end_override' => array(
  63. 'description' => 'Override the default end time? 1 => Yes. 0 => No.',
  64. 'type' => 'int',
  65. 'size' => 'tiny',
  66. 'not null' => FALSE,
  67. 'default' => 0,
  68. ),
  69. 'end_time' => array(
  70. 'description' => 'Role expiration end time. 0 signifies to use a relative expiration.',
  71. 'type' => 'int',
  72. 'not null' => FALSE,
  73. 'default' => 0,
  74. ),
  75. 'duration' => array(
  76. 'description' => 'The duration of the granted role, using the value of granualarity.',
  77. 'type' => 'int',
  78. 'size' => 'small',
  79. ),
  80. 'granularity' => array(
  81. 'description' => 'The units of time of duration.',
  82. 'type' => 'varchar',
  83. 'length' => 32,
  84. ),
  85. 'shippable' => array(
  86. 'description' => 'Is this role feature shippable? 1 => Yes. 0 => No.',
  87. 'type' => 'int',
  88. 'size' => 'tiny',
  89. 'not null' => TRUE,
  90. 'default' => 0,
  91. ),
  92. 'by_quantity' => array(
  93. 'description' => 'Multiply any relative expiration by the quantity purchased? 1 => Yes. 0 => No.',
  94. 'type' => 'int',
  95. 'size' => 'tiny',
  96. 'unsigned' => TRUE,
  97. 'not null' => TRUE,
  98. 'default' => 0,
  99. ),
  100. ),
  101. 'indexes' => array(
  102. 'nid' => array('nid'),
  103. 'model' => array('model'),
  104. 'rid' => array('rid'),
  105. ),
  106. 'primary key' => array('rpid'),
  107. 'foreign keys' => array(
  108. 'uc_product_features' => array(
  109. 'table' => 'uc_product_features',
  110. 'columns' => array('pfid' => 'pfid'),
  111. ),
  112. 'uc_products' => array(
  113. 'table' => 'uc_products',
  114. 'columns' => array('nid' => 'nid'),
  115. ),
  116. 'role' => array(
  117. 'table' => 'role',
  118. 'columns' => array('rid' => 'rid'),
  119. ),
  120. ),
  121. );
  122. $schema['uc_roles_expirations'] = array(
  123. 'description' => 'Store expiration dates of purchased roles.',
  124. 'fields' => array(
  125. 'reid' => array(
  126. 'description' => 'Primary key: the unique expiration id.',
  127. 'type' => 'serial',
  128. 'unsigned' => TRUE,
  129. 'not null' => TRUE,
  130. ),
  131. 'uid' => array(
  132. 'description' => 'The {users}.uid owning the role.',
  133. 'type' => 'int',
  134. 'unsigned' => TRUE,
  135. 'not null' => TRUE,
  136. 'default' => 0,
  137. ),
  138. 'rid' => array(
  139. 'description' => 'The {role}.rid of the purchased role.',
  140. 'type' => 'int',
  141. 'unsigned' => TRUE,
  142. 'not null' => TRUE,
  143. 'default' => 0,
  144. ),
  145. 'expiration' => array(
  146. 'description' => 'The Unix timestamp indicating when the role will be removed from the user account.',
  147. 'type' => 'int',
  148. 'not null' => TRUE,
  149. 'default' => 0,
  150. ),
  151. 'notified' => array(
  152. 'description' => 'A flag indicating that the user was warned that the role will be removed soon.',
  153. 'type' => 'int',
  154. 'size' => 'tiny',
  155. ),
  156. ),
  157. 'indexes' => array(
  158. 'uid' => array('uid'),
  159. 'rid' => array('rid'),
  160. ),
  161. 'primary key' => array('reid'),
  162. 'foreign keys' => array(
  163. 'users' => array(
  164. 'table' => 'users',
  165. 'columns' => array('uid' => 'uid'),
  166. ),
  167. 'role' => array(
  168. 'table' => 'role',
  169. 'columns' => array('rid' => 'rid'),
  170. ),
  171. ),
  172. );
  173. return $schema;
  174. }
  175. /**
  176. * Implements hook_update_last_removed().
  177. */
  178. function uc_roles_update_last_removed() {
  179. // 7.x-3.0-beta2 and earlier were installed with schema version 0,
  180. // which causes update.php to fail.
  181. return drupal_get_installed_schema_version('uc_roles') == 0 ? 0 : 6004;
  182. }
  183. /**
  184. * Implements hook_uninstall().
  185. */
  186. function uc_roles_uninstall() {
  187. db_delete('uc_product_features')
  188. ->condition('fid', 'role')
  189. ->execute();
  190. db_delete('variable')
  191. ->condition('name', 'uc_roles_%', 'LIKE')
  192. ->execute();
  193. }
  194. /**
  195. * Remove unused variables.
  196. */
  197. function uc_roles_update_7300() {
  198. variable_del('uc_roles_default_expiration_header');
  199. variable_del('uc_roles_default_expiration_message');
  200. variable_del('uc_roles_default_expiration_title');
  201. }