pmpro_upgrade_1_8_6_9

Upgrade to 1.8.6.9.

Description

pmpro_upgrade_1_8_6_9(); 

1. Find all orders for stripe gateway with a subscription_transaction_id LIKE cus_% 2. Search for an order for the same user_id and membership_id with a subscription_transaction_id LIKE sub_% 3. Replace subscription_transaction_id field.


Usage

  1. if ( !function_exists( 'pmpro_upgrade_1_8_6_9' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/includes/updates/upgrade_1_8_6_9.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = pmpro_upgrade_1_8_6_9(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/includes/updates/upgrade_1_8_6_9.php  
  1. function pmpro_upgrade_1_8_6_9() { 
  2. global $wpdb; 
  3. $orders = $wpdb->get_results("SELECT id, user_id, membership_id, subscription_transaction_id FROM $wpdb->pmpro_membership_orders WHEREgateway= stripe AND subscription_transaction_id LIKE 'cus_%'"); 
  4.  
  5. if(!empty($orders)) { 
  6. if(count($orders) > 100) { 
  7. //if more than 100 orders, we'll need to do this via AJAX 
  8. pmpro_addUpdate('pmpro_upgrade_1_8_6_9_ajax'); 
  9. } else { 
  10. //less than 100, let's just do them now  
  11. $subids = array(); 
  12.  
  13. foreach($orders as $order) { 
  14. if(!empty($subids[$order->subscription_transaction_id])) { 
  15. $wpdb->query("UPDATE $wpdb->pmpro_membership_ordersSETsubscription_transaction_id = '" . esc_sql($subids[$order->subscription_transaction_id]) . "' WHERE id = '" . $order->id . "' LIMIT 1"); 
  16.  
  17. //echo "Updating subid for #" . $order->id . " " . $order->subscription_transaction_id . ".<br />"; 
  18. elseif(isset($subids[$order->subscription_transaction_id])) { 
  19. //no sub id found, so let it go 
  20.  
  21. //echo "No subid found for #" . $order->id . " " . $order->subscription_transaction_id . " in cache.<br />"; 
  22. else { 
  23. //need to look for a sub id in the database 
  24. $subid = $wpdb->get_var("SELECT subscription_transaction_id FROM $wpdb->pmpro_membership_orders WHERE membership_id = '" . $order->membership_id . "' AND user_id = '" . $order->user_id . "' AND subscription_transaction_id LIKE 'sub_%' LIMIT 1"); 
  25. $subids[$order->subscription_transaction_id] = $subid; 
  26. if(!empty($subid)) { 
  27. $wpdb->query("UPDATE $wpdb->pmpro_membership_ordersSETsubscription_transaction_id = '" . esc_sql($subid) . "' WHERE id = '" . $order->id . "' LIMIT 1"); 
  28.  
  29. //echo "Updating subid for #" . $order->id . " " . $order->subscription_transaction_id . ".<br />";  
  30. else { 
  31. //echo "No subid found for #" . $order->id . " " . $order->subscription_transaction_id . ".<br />"; 
  32.  
  33. pmpro_setOption("db_version", "1.869"); 
  34. return 1.869;