uc_stock.install 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the uc_stock module.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function uc_stock_schema() {
  10. $schema = array();
  11. $schema['uc_product_stock'] = array(
  12. 'description' => 'Stock levels for Ubercart products.',
  13. 'fields' => array(
  14. 'sku' => array(
  15. 'description' => 'SKU (Stock Keeping Unit) of a product.',
  16. 'type' => 'varchar',
  17. 'length' => '255',
  18. 'not null' => TRUE,
  19. 'default' => '',
  20. ),
  21. 'nid' => array(
  22. 'description' => 'Node ID of a product.',
  23. 'type' => 'int',
  24. 'unsigned' => TRUE,
  25. 'not null' => TRUE,
  26. 'default' => 0,
  27. ),
  28. 'active' => array(
  29. 'description' => 'Boolean flag indicating whether stock is being tracked for this product. 1 => Yes. 0 => No.',
  30. 'type' => 'int',
  31. 'size' => 'tiny',
  32. 'unsigned' => TRUE,
  33. 'not null' => TRUE,
  34. 'default' => 0,
  35. ),
  36. 'stock' => array(
  37. 'description' => 'Quantity in stock.',
  38. 'type' => 'int',
  39. 'size' => 'medium',
  40. 'not null' => TRUE,
  41. 'default' => 0,
  42. ),
  43. 'threshold' => array(
  44. 'description' => 'Minimum quantity threshold level.',
  45. 'type' => 'int',
  46. 'size' => 'medium',
  47. 'not null' => TRUE,
  48. 'default' => 0,
  49. ),
  50. ),
  51. 'indexes' => array(
  52. 'nid' => array('nid'),
  53. ),
  54. 'primary key' => array('sku'),
  55. 'foreign keys' => array(
  56. 'uc_products' => array(
  57. 'table' => 'uc_products',
  58. 'columns' => array('nid' => 'nid'),
  59. ),
  60. ),
  61. );
  62. return $schema;
  63. }
  64. /**
  65. * Implements hook_uninstall().
  66. */
  67. function uc_stock_uninstall() {
  68. db_delete('variable')
  69. ->condition('name', 'uc_stock_%', 'LIKE')
  70. ->execute();
  71. variable_del('uc_stock_threshold_notification');
  72. variable_del('uc_stock_threshold_notification_recipients');
  73. variable_del('uc_stock_threshold_notification_subject');
  74. variable_del('uc_stock_threshold_notification_message');
  75. }
  76. /**
  77. * Implements hook_update_last_removed().
  78. */
  79. function uc_stock_update_last_removed() {
  80. return 6000;
  81. }
  82. /**
  83. * Remove unused message format variable.
  84. */
  85. function uc_stock_update_7000() {
  86. variable_del('uc_stock_threshold_notification_format');
  87. }
  88. /**
  89. * Remove unused message format variable.
  90. */
  91. function uc_stock_update_7001() {
  92. variable_del('uc_stock_threshold_notification_message_format');
  93. }