uc_payment.install 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the uc_payment module.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function uc_payment_schema() {
  10. $schema = array();
  11. $schema['uc_payment_receipts'] = array(
  12. 'description' => 'Stores completed payments.',
  13. 'fields' => array(
  14. 'receipt_id' => array(
  15. 'description' => 'Primary key: the payment receipt ID.',
  16. 'type' => 'serial',
  17. 'unsigned' => TRUE,
  18. 'not null' => TRUE,
  19. ),
  20. 'order_id' => array(
  21. 'description' => 'The {uc_orders}.order_id.',
  22. 'type' => 'int',
  23. 'unsigned' => TRUE,
  24. 'not null' => TRUE,
  25. 'default' => 0,
  26. ),
  27. 'method' => array(
  28. 'description' => 'The payment method.',
  29. 'type' => 'varchar',
  30. 'length' => 32,
  31. 'not null' => TRUE,
  32. 'default' => '',
  33. ),
  34. 'amount' => array(
  35. 'description' => 'The payment amount in the store default currency.',
  36. 'type' => 'numeric',
  37. 'precision' => 16,
  38. 'scale' => 5,
  39. 'not null' => TRUE,
  40. 'default' => 0,
  41. ),
  42. 'uid' => array(
  43. 'description' => 'The {users}.uid who collected the payment.',
  44. 'type' => 'int',
  45. 'unsigned' => TRUE,
  46. 'not null' => TRUE,
  47. 'default' => 0,
  48. ),
  49. 'data' => array(
  50. 'description' => 'A serialized array of extra payment data.',
  51. 'type' => 'text',
  52. 'serialize' => TRUE,
  53. ),
  54. 'comment' => array(
  55. 'description' => 'A comment made on the payment.',
  56. 'type' => 'text',
  57. ),
  58. 'received' => array(
  59. 'description' => 'The Unix timestamp indicating when the payment was received.',
  60. 'type' => 'int',
  61. 'not null' => TRUE,
  62. 'default' => 0,
  63. ),
  64. ),
  65. 'indexes' => array(
  66. 'order_id' => array('order_id'),
  67. ),
  68. 'primary key' => array('receipt_id'),
  69. 'foreign keys' => array(
  70. 'uc_orders' => array(
  71. 'table' => 'uc_orders',
  72. 'columns' => array('order_id' => 'order_id'),
  73. ),
  74. ),
  75. );
  76. return $schema;
  77. }
  78. /**
  79. * Implements hook_install().
  80. */
  81. function uc_payment_install() {
  82. $t = get_t();
  83. db_merge('uc_order_statuses')
  84. ->key(array('order_status_id' => 'payment_received'))
  85. ->insertFields(array(
  86. 'order_status_id' => 'payment_received',
  87. 'title' => $t('Payment received'),
  88. 'state' => 'payment_received',
  89. 'weight' => 10,
  90. 'locked' => 1,
  91. ))
  92. ->updateFields(array(
  93. 'state' => 'payment_received',
  94. 'locked' => 1,
  95. ))
  96. ->execute();
  97. }
  98. /**
  99. * Implements hook_uninstall().
  100. */
  101. function uc_payment_uninstall() {
  102. db_delete('variable')
  103. ->condition(db_or()
  104. ->condition('name', 'uc_pg_%', 'LIKE')
  105. ->condition('name', 'uc_payment_%', 'LIKE'))
  106. ->execute();
  107. }
  108. /**
  109. * Implements hook_update_last_removed().
  110. */
  111. function uc_payment_update_last_removed() {
  112. // 7.x-3.0-beta2 and earlier were installed with schema version 0,
  113. // which causes update.php to fail.
  114. return drupal_get_installed_schema_version('uc_payment') == 0 ? 0 : 6002;
  115. }
  116. /**
  117. * Remove unused variables.
  118. */
  119. function uc_payment_update_7000() {
  120. variable_del('uc_payment_tracking');
  121. variable_del('uc_payment_deleting');
  122. variable_del('uc_payment_logging');
  123. variable_del('uc_default_payment_msg');
  124. }
  125. /**
  126. * Increase maximum length of comment field.
  127. */
  128. function uc_payment_update_7001() {
  129. db_change_field('uc_payment_receipts', 'comment', 'comment', array(
  130. 'description' => 'A comment made on the payment.',
  131. 'type' => 'text',
  132. ));
  133. }