uc_store.install 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <?php
  2. /**
  3. * @file
  4. * Install, update, and uninstall functions for the uc_store module.
  5. */
  6. /**
  7. * Implements hook_requirements().
  8. */
  9. function uc_store_requirements($phase) {
  10. $requirements = array();
  11. if ($phase == 'runtime') {
  12. $severities = array(
  13. 'ok' => REQUIREMENT_OK,
  14. 'warning' => REQUIREMENT_WARNING,
  15. 'error' => REQUIREMENT_ERROR,
  16. );
  17. module_load_include('inc', 'uc_store', 'uc_store.admin');
  18. $results = module_invoke_all('uc_store_status');
  19. foreach ($results as $status) {
  20. $requirements[] = array(
  21. 'severity' => isset($severities[$status['status']]) ? $severities[$status['status']] : REQUIREMENT_INFO,
  22. 'title' => $status['title'],
  23. 'value' => $status['desc'],
  24. );
  25. }
  26. }
  27. return $requirements;
  28. }
  29. /**
  30. * Implements hook_schema().
  31. */
  32. function uc_store_schema() {
  33. $schema = array();
  34. $schema['uc_countries'] = array(
  35. 'description' => 'Stores country information.',
  36. 'fields' => array(
  37. 'country_id' => array(
  38. 'description' => 'Primary key: numeric ISO country code.',
  39. 'type' => 'int',
  40. 'unsigned' => TRUE,
  41. 'not null' => TRUE,
  42. ),
  43. 'country_name' => array(
  44. 'description' => 'The country name.',
  45. 'type' => 'varchar',
  46. 'length' => 255,
  47. 'not null' => TRUE,
  48. 'default' => '',
  49. ),
  50. 'country_iso_code_2' => array(
  51. 'description' => 'The two-character ISO country code.',
  52. 'type' => 'char',
  53. 'length' => 2,
  54. 'not null' => TRUE,
  55. 'default' => '',
  56. ),
  57. 'country_iso_code_3' => array(
  58. 'description' => 'The three-character ISO country code.',
  59. 'type' => 'char',
  60. 'length' => 3,
  61. 'not null' => TRUE,
  62. 'default' => '',
  63. ),
  64. 'version' => array(
  65. 'description' => 'The version of the CIF that loaded the country information.',
  66. 'type' => 'int',
  67. 'size' => 'small',
  68. 'not null' => TRUE,
  69. 'default' => 0,
  70. ),
  71. ),
  72. 'indexes' => array(
  73. 'country_name' => array('country_name'),
  74. ),
  75. 'primary key' => array('country_id'),
  76. );
  77. $schema['uc_zones'] = array(
  78. 'description' => 'Stores state/province information within a country.',
  79. 'fields' => array(
  80. 'zone_id' => array(
  81. 'description' => 'Primary key: the unique zone id.',
  82. 'type' => 'serial',
  83. 'unsigned' => TRUE,
  84. 'not null' => TRUE,
  85. ),
  86. 'zone_country_id' => array(
  87. 'description' => 'The {uc_countries}.country_id to which this zone belongs.',
  88. 'type' => 'int',
  89. 'unsigned' => TRUE,
  90. 'not null' => TRUE,
  91. 'default' => 0,
  92. ),
  93. 'zone_code' => array(
  94. 'description' => 'Standard abbreviation of the zone name.',
  95. 'type' => 'varchar',
  96. 'length' => 32,
  97. 'not null' => TRUE,
  98. 'default' => '',
  99. ),
  100. 'zone_name' => array(
  101. 'description' => 'The zone name.',
  102. 'type' => 'varchar',
  103. 'length' => 255,
  104. 'not null' => TRUE,
  105. 'default' => '',
  106. ),
  107. ),
  108. 'indexes' => array(
  109. 'zone_code' => array('zone_code'),
  110. 'zone_country_id' => array('zone_country_id'),
  111. ),
  112. 'primary key' => array('zone_id'),
  113. 'foreign keys' => array(
  114. 'uc_countries' => array(
  115. 'table' => 'uc_countries',
  116. 'columns' => array('zone_country_id' => 'country_id'),
  117. ),
  118. ),
  119. );
  120. return $schema;
  121. }
  122. /**
  123. * Implements hook_install().
  124. */
  125. function uc_store_install() {
  126. // Set mail handler for all Ubercart modules
  127. variable_set('mail_system',
  128. array_merge(
  129. variable_get('mail_system', array('default-system' => 'DefaultMailSystem')),
  130. array(
  131. 'uc_cart' => 'UbercartMailSystem',
  132. 'uc_order' => 'UbercartMailSystem',
  133. 'uc_file' => 'UbercartMailSystem',
  134. 'uc_roles' => 'UbercartMailSystem',
  135. 'uc_stock' => 'UbercartMailSystem',
  136. 'uc_store' => 'UbercartMailSystem',
  137. )
  138. )
  139. );
  140. // Set the default store date format.
  141. variable_set('date_format_uc_store', 'm/d/Y');
  142. // Install United States and Canada by default.
  143. $path = drupal_get_path('module', 'uc_store');
  144. require_once($path . '/countries/united_states_840_1.cif');
  145. require_once($path . '/countries/canada_124_2.cif');
  146. united_states_install();
  147. canada_install();
  148. }
  149. /**
  150. * Implements hook_uninstall().
  151. */
  152. function uc_store_uninstall() {
  153. db_delete('variable')
  154. ->condition(db_or()
  155. ->condition('name', 'uc_address_format_%', 'LIKE')
  156. ->condition('name', 'uc_currency_%', 'LIKE')
  157. ->condition('name', 'uc_store_%', 'LIKE')
  158. ->condition('name', 'uc_weight_%', 'LIKE')
  159. ->condition('name', 'uc_length_%', 'LIKE')
  160. ->condition('name', 'uc_field_%', 'LIKE')
  161. )
  162. ->execute();
  163. variable_del('uc_customer_list_address');
  164. variable_del('uc_sign_after_amount');
  165. variable_del('date_format_uc_store');
  166. variable_del('uc_address_fields');
  167. variable_del('uc_address_fields_required');
  168. variable_del('uc_address_fields_weight');
  169. variable_del('uc_footer_message');
  170. // Unset mail Ubercart hander in variable mail_system
  171. $mail_system = variable_get('mail_system', array('default-system' => 'DefaultMailSystem'));
  172. unset($mail_system['uc_cart']);
  173. unset($mail_system['uc_order']);
  174. unset($mail_system['uc_file']);
  175. unset($mail_system['uc_roles']);
  176. unset($mail_system['uc_stock']);
  177. unset($mail_system['uc_store']);
  178. variable_set('mail_system', $mail_system);
  179. }
  180. /**
  181. * Implements hook_update_last_removed().
  182. */
  183. function uc_store_update_last_removed() {
  184. return 6005;
  185. }
  186. /*
  187. * Removed update 7000.
  188. */
  189. /**
  190. * Removes uc_price cache table.
  191. */
  192. function uc_store_update_7001() {
  193. db_drop_table('cache_uc_price');
  194. }
  195. /**
  196. * Removes unused variable.
  197. */
  198. function uc_store_update_7002() {
  199. variable_del('uc_store_admin_page_display');
  200. }
  201. /**
  202. * Removes store footer message hash table.
  203. */
  204. function uc_store_update_7003() {
  205. db_drop_table('uc_store_footers');
  206. }
  207. /**
  208. * Installs HTML Mail System for Ubercart.
  209. */
  210. function uc_store_update_7004() {
  211. // Set mail handler for all Ubercart modules
  212. variable_set('mail_system',
  213. array_merge(
  214. variable_get('mail_system', array('default-system' => 'DefaultMailSystem')),
  215. array(
  216. 'uc_cart' => 'UbercartMailSystem',
  217. 'uc_order' => 'UbercartMailSystem',
  218. 'uc_file' => 'UbercartMailSystem',
  219. 'uc_roles' => 'UbercartMailSystem',
  220. 'uc_stock' => 'UbercartMailSystem',
  221. 'uc_store' => 'UbercartMailSystem',
  222. )
  223. )
  224. );
  225. }
  226. /**
  227. * Changes date formatting to use D7 API.
  228. */
  229. function uc_store_update_7005() {
  230. variable_set('date_format_uc_store', variable_get('uc_date_format_default', 'm/d/Y'));
  231. variable_del('uc_date_format_default');
  232. }
  233. /**
  234. * Deletes user initials variables.
  235. */
  236. function uc_store_update_7006() {
  237. db_delete('variable')->condition('name', 'user_initials_%', 'LIKE')->execute();
  238. }
  239. /**
  240. * Ensures Rules and Views are installed.
  241. */
  242. function uc_store_update_7007() {
  243. $modules = array('rules', 'views');
  244. module_enable($modules);
  245. foreach ($modules as $module) {
  246. if (!module_exists($module)) {
  247. throw new DrupalUpdateException(t('Rules and Views are now dependencies of Ubercart, but are not currently available. Please download them to sites/all/modules and run update.php again.'));
  248. }
  249. }
  250. }
  251. /**
  252. * Deletes unused address field titles.
  253. */
  254. function uc_store_update_7008() {
  255. variable_del('uc_field_address');
  256. variable_del('uc_field_email');
  257. variable_del('uc_field_street');
  258. }
  259. /**
  260. * Rebuilds theme registry to pick up new location of theme functions.
  261. *
  262. * All theme functions in Ubercart were moved out of the .module files and
  263. * into .theme.inc files to reduce code memory footprint.
  264. */
  265. function uc_store_update_7300() {
  266. drupal_theme_rebuild();
  267. }