uc_file.install 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the uc_file module.
  5. */
  6. // -1 is the UC_FILE_LIMIT_SENTINEL constant in uc_file.module, but
  7. // it might not be available (like when upgrading from 5 -> 6.
  8. /**
  9. * Implements hook_schema().
  10. */
  11. function uc_file_schema() {
  12. $schema = array();
  13. $schema['uc_files'] = array(
  14. 'description' => 'Stores information on purchasable files.',
  15. 'fields' => array(
  16. 'fid' => array(
  17. 'description' => 'Primary key: the file ID.',
  18. 'type' => 'serial',
  19. 'unsigned' => TRUE,
  20. 'not null' => TRUE,
  21. ),
  22. 'filename' => array(
  23. 'description' => 'The name of the file.',
  24. 'type' => 'varchar',
  25. 'length' => 255,
  26. 'not null' => TRUE,
  27. 'default' => '',
  28. ),
  29. ),
  30. 'primary key' => array('fid'),
  31. 'indexes' => array(
  32. 'filename' => array('filename'),
  33. ),
  34. );
  35. $schema['uc_file_products'] = array(
  36. 'description' => 'Maps file product features to files.',
  37. 'fields' => array(
  38. 'fpid' => array(
  39. 'description' => 'Primary key: the ID for the file-product combination.',
  40. 'type' => 'serial',
  41. 'unsigned' => TRUE,
  42. 'not null' => TRUE,
  43. ),
  44. 'pfid' => array(
  45. 'description' => 'The {uc_product_features}.pfid.',
  46. 'type' => 'int',
  47. 'unsigned' => TRUE,
  48. 'not null' => TRUE,
  49. 'default' => 0,
  50. ),
  51. 'fid' => array(
  52. 'description' => 'The {uc_files}.fid of the purchasable file.',
  53. 'type' => 'int',
  54. 'unsigned' => TRUE,
  55. 'not null' => TRUE,
  56. 'default' => 0,
  57. ),
  58. 'model' => array(
  59. 'description' => 'The product model.',
  60. 'type' => 'varchar',
  61. 'length' => 255,
  62. 'not null' => FALSE,
  63. ),
  64. 'description' => array(
  65. 'description' => 'The description of the file.',
  66. 'type' => 'varchar',
  67. 'length' => 255,
  68. 'not null' => FALSE,
  69. ),
  70. 'shippable' => array(
  71. 'description' => 'Is this file feature shippable? 1 => Yes. 0 => No.',
  72. 'type' => 'int',
  73. 'size' => 'tiny',
  74. 'not null' => TRUE,
  75. 'default' => 0,
  76. ),
  77. 'download_limit' => array(
  78. 'description' => 'The number of times the file may be downloaded by a user. -1 indicates the store default will be used.',
  79. 'type' => 'int',
  80. 'not null' => FALSE,
  81. 'default' => -1, // UC_FILE_LIMIT_SENTINEL
  82. ),
  83. 'address_limit' => array(
  84. 'description' => 'The number of different IP addresses from which the file may be downloaded. -1 indicates the store default will be used.',
  85. 'type' => 'int',
  86. 'not null' => FALSE,
  87. 'default' => -1, // UC_FILE_LIMIT_SENTINEL
  88. ),
  89. 'time_granularity' => array(
  90. 'description' => 'The units of time for time_quantity. -1 indicates the store default will be used.',
  91. 'type' => 'varchar',
  92. 'length' => 16,
  93. 'not null' => TRUE,
  94. 'default' => '-1', // UC_FILE_LIMIT_SENTINEL
  95. ),
  96. 'time_quantity' => array(
  97. 'description' => 'With time_granularity, the amount of time the file will be available for download. -1 indicates the store default will be used.',
  98. 'type' => 'int',
  99. 'not null' => TRUE,
  100. 'default' => -1, // UC_FILE_LIMIT_SENTINEL
  101. ),
  102. ),
  103. 'indexes' => array(
  104. 'pfid' => array('pfid'),
  105. 'fid' => array('fid'),
  106. ),
  107. 'primary key' => array('fpid'),
  108. 'foreign keys' => array(
  109. 'uc_product_features' => array(
  110. 'table' => 'uc_product_features',
  111. 'columns' => array('pfid' => 'pfid'),
  112. ),
  113. 'uc_files' => array(
  114. 'table' => 'uc_files',
  115. 'columns' => array('fid' => 'fid'),
  116. ),
  117. ),
  118. );
  119. $schema['uc_file_users'] = array(
  120. 'description' => 'The customers and the files they have purchased.',
  121. 'fields' => array(
  122. 'fuid' => array(
  123. 'description' => 'Primary key: the ID of the file-user combination.',
  124. 'type' => 'serial',
  125. 'unsigned' => TRUE,
  126. 'not null' => TRUE,
  127. ),
  128. 'fid' => array(
  129. 'description' => 'The {uc_files}.fid that was purchased.',
  130. 'type' => 'int',
  131. 'unsigned' => TRUE,
  132. 'not null' => TRUE,
  133. 'default' => 0,
  134. ),
  135. 'uid' => array(
  136. 'description' => 'The {users}.uid of the user who purchased the file.',
  137. 'type' => 'int',
  138. 'unsigned' => TRUE,
  139. 'not null' => TRUE,
  140. 'default' => 0,
  141. ),
  142. 'pfid' => array(
  143. 'description' => 'The product feature ID of the product that was ordered, from {uc_file_products}.pfid.',
  144. 'type' => 'int',
  145. 'unsigned' => TRUE,
  146. 'not null' => FALSE,
  147. ),
  148. 'file_key' => array(
  149. 'description' => 'A hash of the data in this row.',
  150. 'type' => 'varchar',
  151. 'length' => 64,
  152. 'not null' => TRUE,
  153. 'default' => '',
  154. ),
  155. 'granted' => array(
  156. 'description' => 'The Unix timestamp indicating when the file was made available for download.',
  157. 'type' => 'int',
  158. 'not null' => TRUE,
  159. 'default' => 0,
  160. ),
  161. 'expiration' => array(
  162. 'description' => 'The Unix timestamp indicating when the file will no longer be available for download.',
  163. 'type' => 'int',
  164. 'not null' => FALSE,
  165. 'default' => 0,
  166. ),
  167. 'accessed' => array(
  168. 'description' => 'The number of times the file has been downloaded by the user.',
  169. 'type' => 'int',
  170. 'size' => 'small',
  171. 'unsigned' => TRUE,
  172. 'not null' => TRUE,
  173. 'default' => 0,
  174. ),
  175. 'addresses' => array(
  176. 'description' => 'The number of different IP addresses the user has used to download the file.',
  177. 'type' => 'text',
  178. 'serialize' => TRUE,
  179. 'not null' => FALSE,
  180. ),
  181. 'download_limit' => array(
  182. 'description' => 'The number of times the user may download the file.',
  183. 'type' => 'int',
  184. 'not null' => FALSE,
  185. 'default' => NULL,
  186. ),
  187. 'address_limit' => array(
  188. 'description' => 'The number of different IP addresses the user may use to download the file.',
  189. 'type' => 'int',
  190. 'not null' => FALSE,
  191. 'default' => NULL,
  192. ),
  193. ),
  194. 'indexes' => array(
  195. 'fid_uid' => array('fid', 'uid'),
  196. 'uid' => array('uid'),
  197. ),
  198. 'primary key' => array('fuid'),
  199. 'foreign keys' => array(
  200. 'uc_product_features' => array(
  201. 'table' => 'uc_product_features',
  202. 'columns' => array('pfid' => 'pfid'),
  203. ),
  204. 'uc_files' => array(
  205. 'table' => 'uc_files',
  206. 'columns' => array('fid' => 'fid'),
  207. ),
  208. 'users' => array(
  209. 'table' => 'users',
  210. 'columns' => array('uid' => 'uid'),
  211. ),
  212. ),
  213. );
  214. return $schema;
  215. }
  216. /**
  217. * Implements hook_uninstall().
  218. */
  219. function uc_file_uninstall() {
  220. db_delete('uc_product_features')
  221. ->condition('fid', 'file')
  222. ->execute();
  223. db_delete('variable')
  224. ->condition('name', 'uc_file_%', 'LIKE')
  225. ->execute();
  226. }
  227. /**
  228. * Implements hook_update_last_removed().
  229. */
  230. function uc_file_update_last_removed() {
  231. return 6006;
  232. }
  233. /**
  234. * Change 'uc_file_file_mask' variable to a preg regular expression.
  235. */
  236. function uc_file_update_7000() {
  237. $mask = '/' . variable_get('uc_file_file_mask', '.*') . '/';
  238. variable_set('uc_file_file_mask', $mask);
  239. return t("Variable 'uc_file_file_mask' changed to @mask.", array('@mask' => $mask));
  240. }
  241. /**
  242. * Increase the length of {uc_file_users}.file_key.
  243. */
  244. function uc_file_update_7001() {
  245. db_change_field('uc_file_users', 'file_key', 'file_key', array(
  246. 'type' => 'varchar',
  247. 'length' => 64,
  248. 'not null' => TRUE,
  249. 'default' => '',
  250. ));
  251. }
  252. /**
  253. * Add a index on filename since we query on it fairly frequently.
  254. */
  255. function uc_file_update_7002() {
  256. // Index may have been added by uc_file_update_6007() in 6.x-2.x.
  257. if (!db_index_exists('uc_files', 'filename')) {
  258. db_add_index('uc_files', 'filename', array('filename'));
  259. }
  260. }
  261. /**
  262. * Change index on uc_file_users.fid to be over fid and uid.
  263. */
  264. function uc_file_update_7003() {
  265. // Index may have been changed in 6.x-2.x.
  266. if (!db_index_exists('uc_file_users', 'fid_uid')) {
  267. db_add_index('uc_file_users', 'fid_uid', array('fid', 'uid'));
  268. db_drop_index('uc_file_users', 'fid');
  269. }
  270. }