uc_credit.install 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the uc_credit module.
  5. *
  6. * This is mostly legacy code now.
  7. */
  8. /**
  9. * Implements hook_uninstall().
  10. */
  11. function uc_credit_uninstall() {
  12. db_delete('variable')
  13. ->condition('name', 'uc_credit_%', 'LIKE')
  14. ->execute();
  15. }
  16. /**
  17. * Implements hook_update_last_removed().
  18. */
  19. function uc_credit_update_last_removed() {
  20. // 7.x-3.0-beta2 and earlier were installed with schema version 0,
  21. // which causes update.php to fail.
  22. return drupal_get_installed_schema_version('uc_credit') == 0 ? 0 : 6000;
  23. }
  24. /**
  25. * Remove credit card debug mode.
  26. */
  27. function uc_credit_update_7000(&$sandbox) {
  28. drupal_load('module', 'uc_credit');
  29. module_load_include('inc', 'uc_store', 'classes/encrypt');
  30. if (!isset($sandbox['progress'])) {
  31. $sandbox['progress'] = 0;
  32. $sandbox['current_order_id'] = 0;
  33. $sandbox['max'] = db_query("SELECT COUNT(order_id) FROM {uc_orders} WHERE data LIKE '%cc_data%'")->fetchField();
  34. }
  35. $t = get_t();
  36. $limit = 100;
  37. $crypt = new UbercartEncryption();
  38. $key = uc_credit_encryption_key();
  39. // Truncate stored data from debug mode.
  40. $result = db_query_range("SELECT order_id, data FROM {uc_orders} WHERE order_id > :current AND data LIKE '%cc_data%' ORDER BY order_id", 0, $limit, array(':current' => $sandbox['current_order_id']));
  41. while ($order = $result->fetchObject()) {
  42. $sandbox['current_order_id'] = $order->order_id;
  43. // Load up the existing data array.
  44. $data = unserialize($order->data);
  45. $cc_data = uc_credit_cache('save', $data['cc_data']);
  46. // Save only some limited, PCI compliant data.
  47. $cc_data['cc_number'] = substr($cc_data['cc_number'], -4);
  48. unset($cc_data['cc_cvv']);
  49. // Stuff the serialized and encrypted CC details into the array.
  50. $data['cc_data'] = $crypt->encrypt($key, base64_encode(serialize($cc_data)));
  51. // Save it again.
  52. db_update('uc_orders')
  53. ->fields(array('data' => serialize($data)))
  54. ->condition('order_id', $order->order_id)
  55. ->execute();
  56. $sandbox['progress']++;
  57. $sandbox['message'] = $t('Scrubbed credit card data from order @order_id', array('@order_id' => $order->order_id));
  58. }
  59. if ($sandbox['progress'] < $sandbox['max']) {
  60. $sandbox['#finished'] = min(0.99, $sandbox['progress'] / $sandbox['max']);
  61. }
  62. else {
  63. $sandbox['#finished'] = 1;
  64. variable_del('uc_credit_checkout_process');
  65. variable_del('uc_credit_debug');
  66. variable_del('uc_credit_clear_status');
  67. variable_del('uc_credit_number_duration');
  68. variable_del('uc_credit_number_unit');
  69. }
  70. }