@@ -11,44 +11,44 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class EE_DMS_4_6_0_payments extends EE_Data_Migration_Script_Stage_Table |
13 | 13 | { |
14 | - protected $_payment_method_table; |
|
15 | - public function __construct() |
|
16 | - { |
|
17 | - global $wpdb; |
|
18 | - $this->_old_table = $wpdb->prefix . 'esp_payment'; |
|
19 | - $this->_payment_method_table = $wpdb->prefix . 'esp_payment_method'; |
|
20 | - $this->_pretty_name = __('Payment-Payment Method Relations', 'event_espresso'); |
|
21 | - parent::__construct(); |
|
22 | - } |
|
23 | - protected function _migrate_old_row($payment_row) |
|
24 | - { |
|
25 | - global $wpdb; |
|
26 | - // get the payment method's ID |
|
27 | - $PMD_ID = apply_filters('FHEE__EE_DMS_4_6_0_payments__migrate_old_row__PMD_ID', $this->_get_payment_method_id_by_gateway_name($payment_row['PAY_gateway'], $payment_row['PAY_method'])); |
|
28 | - if (! $PMD_ID) { |
|
29 | - $this->add_error(sprintf(__('Could not find payment method with PMD_type = \'%1$s\' when migrating payment row %2$s so just assigned it an unknown payment method', 'event_espresso'), $payment_row['PAY_gateway'], $this->_json_encode($payment_row))); |
|
30 | - $PMD_ID = 0; |
|
31 | - } |
|
32 | - $new_values = array( |
|
33 | - 'PMD_ID' => $PMD_ID, |
|
34 | - 'PAY_source' => ( $payment_row['PAY_via_admin'] ? 'ADMIN' : 'CART' ) ); |
|
35 | - $wheres = array( 'PAY_ID' => $payment_row['PAY_ID'] ); |
|
36 | - $new_value_datatypes = array( '%d', '%s' ); |
|
37 | - $where_datatypes = array( '%d' ); |
|
38 | - $success = $wpdb->update( |
|
39 | - $this->_old_table, |
|
40 | - $new_values, |
|
41 | - $wheres, |
|
42 | - $new_value_datatypes, |
|
43 | - $where_datatypes |
|
44 | - ); |
|
45 | - if (! $success) { |
|
46 | - $this->add_error(sprintf(__('Couldnt set %1$s row in table %2$s where %3$s', 'event_espresso'), $this->_json_encode($new_values), $this->_old_table, $this->_json_encode($wheres))); |
|
47 | - } |
|
48 | - } |
|
49 | - /** |
|
50 | - * |
|
51 | - * array( |
|
14 | + protected $_payment_method_table; |
|
15 | + public function __construct() |
|
16 | + { |
|
17 | + global $wpdb; |
|
18 | + $this->_old_table = $wpdb->prefix . 'esp_payment'; |
|
19 | + $this->_payment_method_table = $wpdb->prefix . 'esp_payment_method'; |
|
20 | + $this->_pretty_name = __('Payment-Payment Method Relations', 'event_espresso'); |
|
21 | + parent::__construct(); |
|
22 | + } |
|
23 | + protected function _migrate_old_row($payment_row) |
|
24 | + { |
|
25 | + global $wpdb; |
|
26 | + // get the payment method's ID |
|
27 | + $PMD_ID = apply_filters('FHEE__EE_DMS_4_6_0_payments__migrate_old_row__PMD_ID', $this->_get_payment_method_id_by_gateway_name($payment_row['PAY_gateway'], $payment_row['PAY_method'])); |
|
28 | + if (! $PMD_ID) { |
|
29 | + $this->add_error(sprintf(__('Could not find payment method with PMD_type = \'%1$s\' when migrating payment row %2$s so just assigned it an unknown payment method', 'event_espresso'), $payment_row['PAY_gateway'], $this->_json_encode($payment_row))); |
|
30 | + $PMD_ID = 0; |
|
31 | + } |
|
32 | + $new_values = array( |
|
33 | + 'PMD_ID' => $PMD_ID, |
|
34 | + 'PAY_source' => ( $payment_row['PAY_via_admin'] ? 'ADMIN' : 'CART' ) ); |
|
35 | + $wheres = array( 'PAY_ID' => $payment_row['PAY_ID'] ); |
|
36 | + $new_value_datatypes = array( '%d', '%s' ); |
|
37 | + $where_datatypes = array( '%d' ); |
|
38 | + $success = $wpdb->update( |
|
39 | + $this->_old_table, |
|
40 | + $new_values, |
|
41 | + $wheres, |
|
42 | + $new_value_datatypes, |
|
43 | + $where_datatypes |
|
44 | + ); |
|
45 | + if (! $success) { |
|
46 | + $this->add_error(sprintf(__('Couldnt set %1$s row in table %2$s where %3$s', 'event_espresso'), $this->_json_encode($new_values), $this->_old_table, $this->_json_encode($wheres))); |
|
47 | + } |
|
48 | + } |
|
49 | + /** |
|
50 | + * |
|
51 | + * array( |
|
52 | 52 | 'PP' => __( 'PayPal', 'event_espresso' ), |
53 | 53 | 'CC' => __( 'Credit Card', 'event_espresso' ), |
54 | 54 | 'DB'=> __("Debit Card", 'event_espresso'), |
@@ -57,44 +57,44 @@ discard block |
||
57 | 57 | 'BK'=> __("Bank", 'event_espresso'), |
58 | 58 | 'IV'=> __("Invoice", 'event_espresso'), |
59 | 59 | 'MO'=> __("Money Order", 'event_espresso'), |
60 | - * @global type $wpdb |
|
61 | - * @param int $id |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - protected function _get_payment_method_id_by_gateway_name($gateway_name, $old_pay_method_column) |
|
65 | - { |
|
66 | - global $wpdb; |
|
67 | - // convert from old known PAY_method values to their corresponding |
|
68 | - // PMD_type or default PMD_name |
|
69 | - switch ($old_pay_method_column) { |
|
70 | - case 'PP': |
|
71 | - $pmd_type = 'Paypal_Standard'; |
|
72 | - break; |
|
73 | - case 'CC': |
|
74 | - $pmd_type = 'Credit_Card'; |
|
75 | - break; |
|
76 | - case 'DB': |
|
77 | - $pmd_type = 'Debit_Card'; |
|
78 | - break; |
|
79 | - case 'CHQ': |
|
80 | - $pmd_type = 'Check'; |
|
81 | - break; |
|
82 | - case 'CSH': |
|
83 | - $pmd_type = 'Cash'; |
|
84 | - break; |
|
85 | - case 'BK': |
|
86 | - $pmd_type = 'Bank'; |
|
87 | - break; |
|
88 | - case 'IV': |
|
89 | - $pmd_type = 'Invoice'; |
|
90 | - break; |
|
91 | - case 'MO': |
|
92 | - $pmd_type = 'Money_Order'; |
|
93 | - break; |
|
94 | - default: |
|
95 | - $pmd_type = $gateway_name; |
|
96 | - } |
|
97 | - $pmd_name = str_replace("_", " ", $pmd_type); |
|
98 | - return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s OR PMD_name = %s", $pmd_type, $pmd_name)); |
|
99 | - } |
|
60 | + * @global type $wpdb |
|
61 | + * @param int $id |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + protected function _get_payment_method_id_by_gateway_name($gateway_name, $old_pay_method_column) |
|
65 | + { |
|
66 | + global $wpdb; |
|
67 | + // convert from old known PAY_method values to their corresponding |
|
68 | + // PMD_type or default PMD_name |
|
69 | + switch ($old_pay_method_column) { |
|
70 | + case 'PP': |
|
71 | + $pmd_type = 'Paypal_Standard'; |
|
72 | + break; |
|
73 | + case 'CC': |
|
74 | + $pmd_type = 'Credit_Card'; |
|
75 | + break; |
|
76 | + case 'DB': |
|
77 | + $pmd_type = 'Debit_Card'; |
|
78 | + break; |
|
79 | + case 'CHQ': |
|
80 | + $pmd_type = 'Check'; |
|
81 | + break; |
|
82 | + case 'CSH': |
|
83 | + $pmd_type = 'Cash'; |
|
84 | + break; |
|
85 | + case 'BK': |
|
86 | + $pmd_type = 'Bank'; |
|
87 | + break; |
|
88 | + case 'IV': |
|
89 | + $pmd_type = 'Invoice'; |
|
90 | + break; |
|
91 | + case 'MO': |
|
92 | + $pmd_type = 'Money_Order'; |
|
93 | + break; |
|
94 | + default: |
|
95 | + $pmd_type = $gateway_name; |
|
96 | + } |
|
97 | + $pmd_name = str_replace("_", " ", $pmd_type); |
|
98 | + return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s OR PMD_name = %s", $pmd_type, $pmd_name)); |
|
99 | + } |
|
100 | 100 | } |
@@ -15,8 +15,8 @@ discard block |
||
15 | 15 | public function __construct() |
16 | 16 | { |
17 | 17 | global $wpdb; |
18 | - $this->_old_table = $wpdb->prefix . 'esp_payment'; |
|
19 | - $this->_payment_method_table = $wpdb->prefix . 'esp_payment_method'; |
|
18 | + $this->_old_table = $wpdb->prefix.'esp_payment'; |
|
19 | + $this->_payment_method_table = $wpdb->prefix.'esp_payment_method'; |
|
20 | 20 | $this->_pretty_name = __('Payment-Payment Method Relations', 'event_espresso'); |
21 | 21 | parent::__construct(); |
22 | 22 | } |
@@ -25,16 +25,16 @@ discard block |
||
25 | 25 | global $wpdb; |
26 | 26 | // get the payment method's ID |
27 | 27 | $PMD_ID = apply_filters('FHEE__EE_DMS_4_6_0_payments__migrate_old_row__PMD_ID', $this->_get_payment_method_id_by_gateway_name($payment_row['PAY_gateway'], $payment_row['PAY_method'])); |
28 | - if (! $PMD_ID) { |
|
28 | + if ( ! $PMD_ID) { |
|
29 | 29 | $this->add_error(sprintf(__('Could not find payment method with PMD_type = \'%1$s\' when migrating payment row %2$s so just assigned it an unknown payment method', 'event_espresso'), $payment_row['PAY_gateway'], $this->_json_encode($payment_row))); |
30 | 30 | $PMD_ID = 0; |
31 | 31 | } |
32 | 32 | $new_values = array( |
33 | 33 | 'PMD_ID' => $PMD_ID, |
34 | - 'PAY_source' => ( $payment_row['PAY_via_admin'] ? 'ADMIN' : 'CART' ) ); |
|
35 | - $wheres = array( 'PAY_ID' => $payment_row['PAY_ID'] ); |
|
36 | - $new_value_datatypes = array( '%d', '%s' ); |
|
37 | - $where_datatypes = array( '%d' ); |
|
34 | + 'PAY_source' => ($payment_row['PAY_via_admin'] ? 'ADMIN' : 'CART') ); |
|
35 | + $wheres = array('PAY_ID' => $payment_row['PAY_ID']); |
|
36 | + $new_value_datatypes = array('%d', '%s'); |
|
37 | + $where_datatypes = array('%d'); |
|
38 | 38 | $success = $wpdb->update( |
39 | 39 | $this->_old_table, |
40 | 40 | $new_values, |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $new_value_datatypes, |
43 | 43 | $where_datatypes |
44 | 44 | ); |
45 | - if (! $success) { |
|
45 | + if ( ! $success) { |
|
46 | 46 | $this->add_error(sprintf(__('Couldnt set %1$s row in table %2$s where %3$s', 'event_espresso'), $this->_json_encode($new_values), $this->_old_table, $this->_json_encode($wheres))); |
47 | 47 | } |
48 | 48 | } |
@@ -95,6 +95,6 @@ discard block |
||
95 | 95 | $pmd_type = $gateway_name; |
96 | 96 | } |
97 | 97 | $pmd_name = str_replace("_", " ", $pmd_type); |
98 | - return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s OR PMD_name = %s", $pmd_type, $pmd_name)); |
|
98 | + return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM ".$wpdb->prefix."esp_payment_method WHERE PMD_type = %s OR PMD_name = %s", $pmd_type, $pmd_name)); |
|
99 | 99 | } |
100 | 100 | } |
@@ -11,51 +11,51 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_DMS_4_6_0_transactions extends EE_Data_Migration_Script_Stage_Table |
13 | 13 | { |
14 | - protected $_transaction_table; |
|
15 | - protected $_payment_method_table; |
|
16 | - public function __construct() |
|
17 | - { |
|
18 | - global $wpdb; |
|
19 | - $this->_old_table = $wpdb->prefix . 'esp_extra_meta'; |
|
20 | - $this->_transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
21 | - $this->_payment_method_table = $wpdb->prefix . 'esp_payment_method'; |
|
22 | - $this->_pretty_name = __('Transaction Payment Method Relations', 'event_espresso'); |
|
23 | - $this->_extra_where_sql = "WHERE EXM_key = 'gateway' AND EXM_type = 'Transaction'"; |
|
24 | - parent::__construct(); |
|
25 | - } |
|
26 | - protected function _migrate_old_row($extra_meta_row) |
|
27 | - { |
|
28 | - global $wpdb; |
|
29 | - // get the payment method's ID |
|
30 | - $PMD_ID = $this->_get_payment_method_id_by_gateway_name($extra_meta_row['EXM_value']); |
|
31 | - if (! $PMD_ID) { |
|
32 | - $this->add_error(sprintf(__('Could not find payment method with PMD_type = \'%1$s\' when migrating extra meta row %2$s', 'event_espresso'), $extra_meta_row['EXM_value'], $this->_json_encode($extra_meta_row))); |
|
33 | - return; |
|
34 | - } |
|
35 | - $new_values = array( 'PMD_ID' => $PMD_ID ); |
|
36 | - $wheres = array( 'TXN_ID' => $extra_meta_row['OBJ_ID'] ); |
|
37 | - $new_value_datatypes = array( '%d' ); |
|
38 | - $where_datatypes = array( '%d' ); |
|
39 | - $success = $wpdb->update( |
|
40 | - $this->_transaction_table, |
|
41 | - $new_values, |
|
42 | - $wheres, |
|
43 | - $new_value_datatypes, |
|
44 | - $where_datatypes |
|
45 | - ); |
|
46 | - if (! $success) { |
|
47 | - $this->add_error(sprintf(__('Couldnt set %1$s row in table %2$s where %3$s', 'event_espresso'), $this->_json_encode($new_values), $this->_transaction_table, $this->_json_encode($wheres))); |
|
48 | - } |
|
49 | - } |
|
50 | - /** |
|
51 | - * |
|
52 | - * @global type $wpdb |
|
53 | - * @param int $id |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - protected function _get_payment_method_id_by_gateway_name($gateway_name) |
|
57 | - { |
|
58 | - global $wpdb; |
|
59 | - return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s", $gateway_name)); |
|
60 | - } |
|
14 | + protected $_transaction_table; |
|
15 | + protected $_payment_method_table; |
|
16 | + public function __construct() |
|
17 | + { |
|
18 | + global $wpdb; |
|
19 | + $this->_old_table = $wpdb->prefix . 'esp_extra_meta'; |
|
20 | + $this->_transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
21 | + $this->_payment_method_table = $wpdb->prefix . 'esp_payment_method'; |
|
22 | + $this->_pretty_name = __('Transaction Payment Method Relations', 'event_espresso'); |
|
23 | + $this->_extra_where_sql = "WHERE EXM_key = 'gateway' AND EXM_type = 'Transaction'"; |
|
24 | + parent::__construct(); |
|
25 | + } |
|
26 | + protected function _migrate_old_row($extra_meta_row) |
|
27 | + { |
|
28 | + global $wpdb; |
|
29 | + // get the payment method's ID |
|
30 | + $PMD_ID = $this->_get_payment_method_id_by_gateway_name($extra_meta_row['EXM_value']); |
|
31 | + if (! $PMD_ID) { |
|
32 | + $this->add_error(sprintf(__('Could not find payment method with PMD_type = \'%1$s\' when migrating extra meta row %2$s', 'event_espresso'), $extra_meta_row['EXM_value'], $this->_json_encode($extra_meta_row))); |
|
33 | + return; |
|
34 | + } |
|
35 | + $new_values = array( 'PMD_ID' => $PMD_ID ); |
|
36 | + $wheres = array( 'TXN_ID' => $extra_meta_row['OBJ_ID'] ); |
|
37 | + $new_value_datatypes = array( '%d' ); |
|
38 | + $where_datatypes = array( '%d' ); |
|
39 | + $success = $wpdb->update( |
|
40 | + $this->_transaction_table, |
|
41 | + $new_values, |
|
42 | + $wheres, |
|
43 | + $new_value_datatypes, |
|
44 | + $where_datatypes |
|
45 | + ); |
|
46 | + if (! $success) { |
|
47 | + $this->add_error(sprintf(__('Couldnt set %1$s row in table %2$s where %3$s', 'event_espresso'), $this->_json_encode($new_values), $this->_transaction_table, $this->_json_encode($wheres))); |
|
48 | + } |
|
49 | + } |
|
50 | + /** |
|
51 | + * |
|
52 | + * @global type $wpdb |
|
53 | + * @param int $id |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + protected function _get_payment_method_id_by_gateway_name($gateway_name) |
|
57 | + { |
|
58 | + global $wpdb; |
|
59 | + return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s", $gateway_name)); |
|
60 | + } |
|
61 | 61 | } |
@@ -16,9 +16,9 @@ discard block |
||
16 | 16 | public function __construct() |
17 | 17 | { |
18 | 18 | global $wpdb; |
19 | - $this->_old_table = $wpdb->prefix . 'esp_extra_meta'; |
|
20 | - $this->_transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
21 | - $this->_payment_method_table = $wpdb->prefix . 'esp_payment_method'; |
|
19 | + $this->_old_table = $wpdb->prefix.'esp_extra_meta'; |
|
20 | + $this->_transaction_table = $wpdb->prefix.'esp_transaction'; |
|
21 | + $this->_payment_method_table = $wpdb->prefix.'esp_payment_method'; |
|
22 | 22 | $this->_pretty_name = __('Transaction Payment Method Relations', 'event_espresso'); |
23 | 23 | $this->_extra_where_sql = "WHERE EXM_key = 'gateway' AND EXM_type = 'Transaction'"; |
24 | 24 | parent::__construct(); |
@@ -28,14 +28,14 @@ discard block |
||
28 | 28 | global $wpdb; |
29 | 29 | // get the payment method's ID |
30 | 30 | $PMD_ID = $this->_get_payment_method_id_by_gateway_name($extra_meta_row['EXM_value']); |
31 | - if (! $PMD_ID) { |
|
31 | + if ( ! $PMD_ID) { |
|
32 | 32 | $this->add_error(sprintf(__('Could not find payment method with PMD_type = \'%1$s\' when migrating extra meta row %2$s', 'event_espresso'), $extra_meta_row['EXM_value'], $this->_json_encode($extra_meta_row))); |
33 | 33 | return; |
34 | 34 | } |
35 | - $new_values = array( 'PMD_ID' => $PMD_ID ); |
|
36 | - $wheres = array( 'TXN_ID' => $extra_meta_row['OBJ_ID'] ); |
|
37 | - $new_value_datatypes = array( '%d' ); |
|
38 | - $where_datatypes = array( '%d' ); |
|
35 | + $new_values = array('PMD_ID' => $PMD_ID); |
|
36 | + $wheres = array('TXN_ID' => $extra_meta_row['OBJ_ID']); |
|
37 | + $new_value_datatypes = array('%d'); |
|
38 | + $where_datatypes = array('%d'); |
|
39 | 39 | $success = $wpdb->update( |
40 | 40 | $this->_transaction_table, |
41 | 41 | $new_values, |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $new_value_datatypes, |
44 | 44 | $where_datatypes |
45 | 45 | ); |
46 | - if (! $success) { |
|
46 | + if ( ! $success) { |
|
47 | 47 | $this->add_error(sprintf(__('Couldnt set %1$s row in table %2$s where %3$s', 'event_espresso'), $this->_json_encode($new_values), $this->_transaction_table, $this->_json_encode($wheres))); |
48 | 48 | } |
49 | 49 | } |
@@ -56,6 +56,6 @@ discard block |
||
56 | 56 | protected function _get_payment_method_id_by_gateway_name($gateway_name) |
57 | 57 | { |
58 | 58 | global $wpdb; |
59 | - return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s", $gateway_name)); |
|
59 | + return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM ".$wpdb->prefix."esp_payment_method WHERE PMD_type = %s", $gateway_name)); |
|
60 | 60 | } |
61 | 61 | } |
@@ -11,69 +11,69 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_DMS_4_6_0_billing_info extends EE_Data_Migration_Script_Stage_Table |
13 | 13 | { |
14 | - public function __construct() |
|
15 | - { |
|
16 | - global $wpdb; |
|
17 | - $this->_old_table = $wpdb->postmeta; |
|
18 | - $this->_pretty_name = __('Billing Info', 'event_espresso'); |
|
19 | - $this->_extra_where_sql = "WHERE meta_key LIKE 'billing_info_%'"; |
|
20 | - parent::__construct(); |
|
21 | - } |
|
22 | - protected function _migrate_old_row($old_row) |
|
23 | - { |
|
24 | - $new_billing_info = array(); |
|
25 | - $old_billing_info = maybe_unserialize($old_row['meta_value']); |
|
26 | - $gateway_name = str_replace("billing_info_", '', $old_row['meta_key']); |
|
27 | - $repetitive_prefix = '_reg-page-billing-'; |
|
28 | - $repetitive_suffix = "-" . $gateway_name; |
|
29 | - foreach ($old_billing_info as $old_input_name => $input_value) { |
|
30 | - $old_input_name_important_part = str_replace(array( $repetitive_prefix, $repetitive_suffix ), array( '', ''), $old_input_name); |
|
14 | + public function __construct() |
|
15 | + { |
|
16 | + global $wpdb; |
|
17 | + $this->_old_table = $wpdb->postmeta; |
|
18 | + $this->_pretty_name = __('Billing Info', 'event_espresso'); |
|
19 | + $this->_extra_where_sql = "WHERE meta_key LIKE 'billing_info_%'"; |
|
20 | + parent::__construct(); |
|
21 | + } |
|
22 | + protected function _migrate_old_row($old_row) |
|
23 | + { |
|
24 | + $new_billing_info = array(); |
|
25 | + $old_billing_info = maybe_unserialize($old_row['meta_value']); |
|
26 | + $gateway_name = str_replace("billing_info_", '', $old_row['meta_key']); |
|
27 | + $repetitive_prefix = '_reg-page-billing-'; |
|
28 | + $repetitive_suffix = "-" . $gateway_name; |
|
29 | + foreach ($old_billing_info as $old_input_name => $input_value) { |
|
30 | + $old_input_name_important_part = str_replace(array( $repetitive_prefix, $repetitive_suffix ), array( '', ''), $old_input_name); |
|
31 | 31 | |
32 | - switch ($old_input_name_important_part) { |
|
33 | - case 'fname': |
|
34 | - $new_input_name = 'first_name'; |
|
35 | - break; |
|
36 | - case 'lname': |
|
37 | - $new_input_name = 'last_name'; |
|
38 | - break; |
|
39 | - case 'state': |
|
40 | - // we used to store the state's id ,but now we just store the name |
|
41 | - $new_input_name = $old_input_name_important_part; |
|
42 | - $input_value = $this->_get_state_name_by_ID($input_value); |
|
43 | - break; |
|
44 | - case 'card-nmbr': |
|
45 | - $new_input_name = 'credit_card'; |
|
46 | - break; |
|
47 | - case 'card-type':// paypal pro only |
|
48 | - $new_input_name = 'credit_card_type'; |
|
49 | - break; |
|
50 | - case 'card-exp-date-mnth': |
|
51 | - $new_input_name = 'exp_month'; |
|
52 | - $input_value = ''; |
|
53 | - break; |
|
54 | - case 'card-exp-date-year': |
|
55 | - $new_input_name = 'exp_year'; |
|
56 | - $input_value = 0; |
|
57 | - break; |
|
58 | - case 'ccv-code': |
|
59 | - $new_input_name = 'cvv'; |
|
60 | - break; |
|
61 | - default: |
|
62 | - $new_input_name = $old_input_name_important_part; |
|
63 | - } |
|
64 | - $new_billing_info[ $new_input_name ] = $input_value; |
|
65 | - } |
|
66 | - update_post_meta($old_row['post_id'], $old_row['meta_key'], $new_billing_info); |
|
67 | - } |
|
68 | - /** |
|
69 | - * |
|
70 | - * @global type $wpdb |
|
71 | - * @param int $id |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - protected function _get_state_name_by_ID($id) |
|
75 | - { |
|
76 | - global $wpdb; |
|
77 | - return $wpdb->get_var($wpdb->prepare("SELECT STA_name FROM " . $wpdb->prefix . "esp_state WHERE STA_ID = %d", $id)); |
|
78 | - } |
|
32 | + switch ($old_input_name_important_part) { |
|
33 | + case 'fname': |
|
34 | + $new_input_name = 'first_name'; |
|
35 | + break; |
|
36 | + case 'lname': |
|
37 | + $new_input_name = 'last_name'; |
|
38 | + break; |
|
39 | + case 'state': |
|
40 | + // we used to store the state's id ,but now we just store the name |
|
41 | + $new_input_name = $old_input_name_important_part; |
|
42 | + $input_value = $this->_get_state_name_by_ID($input_value); |
|
43 | + break; |
|
44 | + case 'card-nmbr': |
|
45 | + $new_input_name = 'credit_card'; |
|
46 | + break; |
|
47 | + case 'card-type':// paypal pro only |
|
48 | + $new_input_name = 'credit_card_type'; |
|
49 | + break; |
|
50 | + case 'card-exp-date-mnth': |
|
51 | + $new_input_name = 'exp_month'; |
|
52 | + $input_value = ''; |
|
53 | + break; |
|
54 | + case 'card-exp-date-year': |
|
55 | + $new_input_name = 'exp_year'; |
|
56 | + $input_value = 0; |
|
57 | + break; |
|
58 | + case 'ccv-code': |
|
59 | + $new_input_name = 'cvv'; |
|
60 | + break; |
|
61 | + default: |
|
62 | + $new_input_name = $old_input_name_important_part; |
|
63 | + } |
|
64 | + $new_billing_info[ $new_input_name ] = $input_value; |
|
65 | + } |
|
66 | + update_post_meta($old_row['post_id'], $old_row['meta_key'], $new_billing_info); |
|
67 | + } |
|
68 | + /** |
|
69 | + * |
|
70 | + * @global type $wpdb |
|
71 | + * @param int $id |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + protected function _get_state_name_by_ID($id) |
|
75 | + { |
|
76 | + global $wpdb; |
|
77 | + return $wpdb->get_var($wpdb->prepare("SELECT STA_name FROM " . $wpdb->prefix . "esp_state WHERE STA_ID = %d", $id)); |
|
78 | + } |
|
79 | 79 | } |
@@ -25,9 +25,9 @@ discard block |
||
25 | 25 | $old_billing_info = maybe_unserialize($old_row['meta_value']); |
26 | 26 | $gateway_name = str_replace("billing_info_", '', $old_row['meta_key']); |
27 | 27 | $repetitive_prefix = '_reg-page-billing-'; |
28 | - $repetitive_suffix = "-" . $gateway_name; |
|
28 | + $repetitive_suffix = "-".$gateway_name; |
|
29 | 29 | foreach ($old_billing_info as $old_input_name => $input_value) { |
30 | - $old_input_name_important_part = str_replace(array( $repetitive_prefix, $repetitive_suffix ), array( '', ''), $old_input_name); |
|
30 | + $old_input_name_important_part = str_replace(array($repetitive_prefix, $repetitive_suffix), array('', ''), $old_input_name); |
|
31 | 31 | |
32 | 32 | switch ($old_input_name_important_part) { |
33 | 33 | case 'fname': |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | default: |
62 | 62 | $new_input_name = $old_input_name_important_part; |
63 | 63 | } |
64 | - $new_billing_info[ $new_input_name ] = $input_value; |
|
64 | + $new_billing_info[$new_input_name] = $input_value; |
|
65 | 65 | } |
66 | 66 | update_post_meta($old_row['post_id'], $old_row['meta_key'], $new_billing_info); |
67 | 67 | } |
@@ -74,6 +74,6 @@ discard block |
||
74 | 74 | protected function _get_state_name_by_ID($id) |
75 | 75 | { |
76 | 76 | global $wpdb; |
77 | - return $wpdb->get_var($wpdb->prepare("SELECT STA_name FROM " . $wpdb->prefix . "esp_state WHERE STA_ID = %d", $id)); |
|
77 | + return $wpdb->get_var($wpdb->prepare("SELECT STA_name FROM ".$wpdb->prefix."esp_state WHERE STA_ID = %d", $id)); |
|
78 | 78 | } |
79 | 79 | } |
@@ -12,225 +12,225 @@ |
||
12 | 12 | class EE_DMS_4_7_0_Registration_Payments extends EE_Data_Migration_Script_Stage_Table |
13 | 13 | { |
14 | 14 | |
15 | - protected $_payment_table; |
|
16 | - |
|
17 | - protected $_registration_table; |
|
18 | - |
|
19 | - protected $_registration_payment_table; |
|
20 | - |
|
21 | - public function __construct() |
|
22 | - { |
|
23 | - /** @type WPDB $wpdb */ |
|
24 | - global $wpdb; |
|
25 | - $this->_pretty_name = __('Registration Payment Record Generation', 'event_espresso'); |
|
26 | - // define tables |
|
27 | - $this->_old_table = $wpdb->prefix . 'esp_transaction'; |
|
28 | - $this->_payment_table = $wpdb->prefix . 'esp_payment'; |
|
29 | - $this->_registration_table = $wpdb->prefix . 'esp_registration'; |
|
30 | - $this->_registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
31 | - // build SQL WHERE clauses |
|
32 | - $this->_extra_where_sql = "WHERE STS_ID IN ( 'TIN', 'TCM' ) AND TXN_Total != '0.000'"; |
|
33 | - parent::__construct(); |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * @param array $transaction |
|
40 | - * @return void |
|
41 | - */ |
|
42 | - protected function _migrate_old_row($transaction) |
|
43 | - { |
|
44 | - /** @type WPDB $wpdb */ |
|
45 | - global $wpdb; |
|
46 | - $TXN_ID = absint($transaction['TXN_ID']); |
|
47 | - if (! $TXN_ID) { |
|
48 | - $this->add_error( |
|
49 | - sprintf( |
|
50 | - __('Invalid transaction with ID=%1$d. Error: "%2$s"', 'event_espresso'), |
|
51 | - $TXN_ID, |
|
52 | - $wpdb->last_error |
|
53 | - ) |
|
54 | - ); |
|
55 | - return; |
|
56 | - } |
|
57 | - // get all payments for the TXN |
|
58 | - $payments = $this->_get_payments($TXN_ID); |
|
59 | - if (empty($payments)) { |
|
60 | - return; |
|
61 | - } |
|
62 | - // then the registrants |
|
63 | - $registrations = $this->_get_registrations($TXN_ID); |
|
64 | - if (empty($registrations)) { |
|
65 | - return; |
|
66 | - } |
|
67 | - // now loop thru each payment and apply it to each of the registrations |
|
68 | - foreach ($payments as $PAY_ID => $payment) { |
|
69 | - if ($payment->STS_ID === 'PAP' && $payment->PAY_amount > 0) { |
|
70 | - $this->_process_registration_payments($payment, $registrations); |
|
71 | - } |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * _get_registrations |
|
79 | - * |
|
80 | - * @param int $TXN_ID |
|
81 | - * @return array |
|
82 | - */ |
|
83 | - protected function _get_registrations($TXN_ID) |
|
84 | - { |
|
85 | - /** @type WPDB $wpdb */ |
|
86 | - global $wpdb; |
|
87 | - $SQL = "SELECT * FROM {$this->_registration_table} WHERE TXN_ID = %d AND STS_ID IN ( 'RPP', 'RAP' )"; |
|
88 | - return $wpdb->get_results($wpdb->prepare($SQL, $TXN_ID), OBJECT_K); |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * _get_payments |
|
95 | - * |
|
96 | - * @param int $TXN_ID |
|
97 | - * @return array |
|
98 | - */ |
|
99 | - protected function _get_payments($TXN_ID) |
|
100 | - { |
|
101 | - /** @type WPDB $wpdb */ |
|
102 | - global $wpdb; |
|
103 | - return $wpdb->get_results($wpdb->prepare("SELECT * FROM {$this->_payment_table} WHERE TXN_ID = %d", $TXN_ID), OBJECT_K); |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * _get_possibly_updated_REG_paid |
|
110 | - * |
|
111 | - * @param int $REG_ID |
|
112 | - * @return array |
|
113 | - */ |
|
114 | - protected function _get_possibly_updated_REG_paid($REG_ID) |
|
115 | - { |
|
116 | - /** @type WPDB $wpdb */ |
|
117 | - global $wpdb; |
|
118 | - return $wpdb->get_var($wpdb->prepare("SELECT REG_paid FROM {$this->_registration_table} WHERE REG_ID = %d", $REG_ID)); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * _process_registration_payments |
|
125 | - * |
|
126 | - * basically a copy of the "Sequential Registration Payment Application Strategy" logic |
|
127 | - * currently in EE_Payment_Processor::process_registration_payments() |
|
128 | - * |
|
129 | - * @param stdClass $payment |
|
130 | - * @param array $registrations |
|
131 | - * @return bool |
|
132 | - */ |
|
133 | - protected function _process_registration_payments($payment, $registrations = array()) |
|
134 | - { |
|
135 | - // how much is available to apply to registrations? |
|
136 | - $available_payment_amount = $payment->PAY_amount; |
|
137 | - foreach ($registrations as $REG_ID => $registration) { |
|
138 | - // nothing left, then we are done here? |
|
139 | - if (! $available_payment_amount > 0) { |
|
140 | - break; |
|
141 | - } |
|
142 | - // ensure REG_final_price has a valid value, and skip if it turns out to be zero |
|
143 | - $registration->REG_final_price = ! empty($registration->REG_final_price) ? (float) $registration->REG_final_price : 0.00; |
|
144 | - if (! $registration->REG_final_price > 0) { |
|
145 | - continue; |
|
146 | - } |
|
147 | - // because REG_paid may have been updated by a previous payment, we need to retrieve the value from the db |
|
148 | - $possibly_updated_REG_paid = $this->_get_possibly_updated_REG_paid($REG_ID); |
|
149 | - if (is_float($possibly_updated_REG_paid)) { |
|
150 | - $registration->REG_paid = $possibly_updated_REG_paid; |
|
151 | - } |
|
152 | - // and ensure REG_paid has a valid value |
|
153 | - $registration->REG_paid = ! empty($registration->REG_paid) ? (float) $registration->REG_paid : 0.00; |
|
154 | - // calculate amount owing, and skip if it turns out to be zero |
|
155 | - $owing = $registration->REG_final_price - $registration->REG_paid; |
|
156 | - if (! $owing > 0) { |
|
157 | - continue; |
|
158 | - } |
|
159 | - // don't allow payment amount to exceed the available payment amount, OR the amount owing |
|
160 | - $payment_amount = min($available_payment_amount, $owing); |
|
161 | - // update $available_payment_amount |
|
162 | - $available_payment_amount = $available_payment_amount - $payment_amount; |
|
163 | - // add relation between registration and payment and set amount |
|
164 | - if ($this->_insert_registration_payment($registration->REG_ID, $payment->PAY_ID, $payment_amount)) { |
|
165 | - // calculate and set new REG_paid |
|
166 | - $registration->REG_paid = $registration->REG_paid + $payment_amount; |
|
167 | - $this->_update_registration_paid($registration->REG_ID, $registration->REG_paid); |
|
168 | - } |
|
169 | - } |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * _insert_registration_payment |
|
176 | - * |
|
177 | - * @param int $REG_ID |
|
178 | - * @param int $PAY_ID |
|
179 | - * @param float $PAY_amount |
|
180 | - * @return bool |
|
181 | - */ |
|
182 | - protected function _insert_registration_payment($REG_ID = 0, $PAY_ID = 0, $PAY_amount = 0.00) |
|
183 | - { |
|
184 | - /** @type WPDB $wpdb */ |
|
185 | - global $wpdb; |
|
186 | - $success = $wpdb->insert( |
|
187 | - $this->_registration_payment_table, |
|
188 | - array( 'REG_ID' => $REG_ID, 'PAY_ID' => $PAY_ID, 'RPY_amount' => $PAY_amount, ), // data |
|
189 | - array( '%f' ) // data format |
|
190 | - ); |
|
191 | - if ($success === false) { |
|
192 | - $this->add_error( |
|
193 | - sprintf( |
|
194 | - __('Could not update registration paid value for registration ID=%1$d because "%2$s"', 'event_espresso'), |
|
195 | - $REG_ID, |
|
196 | - $wpdb->last_error |
|
197 | - ) |
|
198 | - ); |
|
199 | - return false; |
|
200 | - } |
|
201 | - return true; |
|
202 | - } |
|
203 | - |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * _update_registration_paid |
|
208 | - * |
|
209 | - * @param int $REG_ID |
|
210 | - * @param float $REG_paid |
|
211 | - * @return bool |
|
212 | - */ |
|
213 | - protected function _update_registration_paid($REG_ID = 0, $REG_paid = 0.00) |
|
214 | - { |
|
215 | - /** @type WPDB $wpdb */ |
|
216 | - global $wpdb; |
|
217 | - $success = $wpdb->update( |
|
218 | - $this->_registration_table, |
|
219 | - array( 'REG_paid' => $REG_paid ), // data |
|
220 | - array( 'REG_ID' => $REG_ID ), // where |
|
221 | - array( '%f' ), // data format |
|
222 | - array( '%d' ) // where format |
|
223 | - ); |
|
224 | - if ($success === false) { |
|
225 | - $this->add_error( |
|
226 | - sprintf( |
|
227 | - __('Could not update registration paid value for registration ID=%1$d because "%2$s"', 'event_espresso'), |
|
228 | - $REG_ID, |
|
229 | - $wpdb->last_error |
|
230 | - ) |
|
231 | - ); |
|
232 | - return false; |
|
233 | - } |
|
234 | - return true; |
|
235 | - } |
|
15 | + protected $_payment_table; |
|
16 | + |
|
17 | + protected $_registration_table; |
|
18 | + |
|
19 | + protected $_registration_payment_table; |
|
20 | + |
|
21 | + public function __construct() |
|
22 | + { |
|
23 | + /** @type WPDB $wpdb */ |
|
24 | + global $wpdb; |
|
25 | + $this->_pretty_name = __('Registration Payment Record Generation', 'event_espresso'); |
|
26 | + // define tables |
|
27 | + $this->_old_table = $wpdb->prefix . 'esp_transaction'; |
|
28 | + $this->_payment_table = $wpdb->prefix . 'esp_payment'; |
|
29 | + $this->_registration_table = $wpdb->prefix . 'esp_registration'; |
|
30 | + $this->_registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
31 | + // build SQL WHERE clauses |
|
32 | + $this->_extra_where_sql = "WHERE STS_ID IN ( 'TIN', 'TCM' ) AND TXN_Total != '0.000'"; |
|
33 | + parent::__construct(); |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * @param array $transaction |
|
40 | + * @return void |
|
41 | + */ |
|
42 | + protected function _migrate_old_row($transaction) |
|
43 | + { |
|
44 | + /** @type WPDB $wpdb */ |
|
45 | + global $wpdb; |
|
46 | + $TXN_ID = absint($transaction['TXN_ID']); |
|
47 | + if (! $TXN_ID) { |
|
48 | + $this->add_error( |
|
49 | + sprintf( |
|
50 | + __('Invalid transaction with ID=%1$d. Error: "%2$s"', 'event_espresso'), |
|
51 | + $TXN_ID, |
|
52 | + $wpdb->last_error |
|
53 | + ) |
|
54 | + ); |
|
55 | + return; |
|
56 | + } |
|
57 | + // get all payments for the TXN |
|
58 | + $payments = $this->_get_payments($TXN_ID); |
|
59 | + if (empty($payments)) { |
|
60 | + return; |
|
61 | + } |
|
62 | + // then the registrants |
|
63 | + $registrations = $this->_get_registrations($TXN_ID); |
|
64 | + if (empty($registrations)) { |
|
65 | + return; |
|
66 | + } |
|
67 | + // now loop thru each payment and apply it to each of the registrations |
|
68 | + foreach ($payments as $PAY_ID => $payment) { |
|
69 | + if ($payment->STS_ID === 'PAP' && $payment->PAY_amount > 0) { |
|
70 | + $this->_process_registration_payments($payment, $registrations); |
|
71 | + } |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * _get_registrations |
|
79 | + * |
|
80 | + * @param int $TXN_ID |
|
81 | + * @return array |
|
82 | + */ |
|
83 | + protected function _get_registrations($TXN_ID) |
|
84 | + { |
|
85 | + /** @type WPDB $wpdb */ |
|
86 | + global $wpdb; |
|
87 | + $SQL = "SELECT * FROM {$this->_registration_table} WHERE TXN_ID = %d AND STS_ID IN ( 'RPP', 'RAP' )"; |
|
88 | + return $wpdb->get_results($wpdb->prepare($SQL, $TXN_ID), OBJECT_K); |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * _get_payments |
|
95 | + * |
|
96 | + * @param int $TXN_ID |
|
97 | + * @return array |
|
98 | + */ |
|
99 | + protected function _get_payments($TXN_ID) |
|
100 | + { |
|
101 | + /** @type WPDB $wpdb */ |
|
102 | + global $wpdb; |
|
103 | + return $wpdb->get_results($wpdb->prepare("SELECT * FROM {$this->_payment_table} WHERE TXN_ID = %d", $TXN_ID), OBJECT_K); |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * _get_possibly_updated_REG_paid |
|
110 | + * |
|
111 | + * @param int $REG_ID |
|
112 | + * @return array |
|
113 | + */ |
|
114 | + protected function _get_possibly_updated_REG_paid($REG_ID) |
|
115 | + { |
|
116 | + /** @type WPDB $wpdb */ |
|
117 | + global $wpdb; |
|
118 | + return $wpdb->get_var($wpdb->prepare("SELECT REG_paid FROM {$this->_registration_table} WHERE REG_ID = %d", $REG_ID)); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * _process_registration_payments |
|
125 | + * |
|
126 | + * basically a copy of the "Sequential Registration Payment Application Strategy" logic |
|
127 | + * currently in EE_Payment_Processor::process_registration_payments() |
|
128 | + * |
|
129 | + * @param stdClass $payment |
|
130 | + * @param array $registrations |
|
131 | + * @return bool |
|
132 | + */ |
|
133 | + protected function _process_registration_payments($payment, $registrations = array()) |
|
134 | + { |
|
135 | + // how much is available to apply to registrations? |
|
136 | + $available_payment_amount = $payment->PAY_amount; |
|
137 | + foreach ($registrations as $REG_ID => $registration) { |
|
138 | + // nothing left, then we are done here? |
|
139 | + if (! $available_payment_amount > 0) { |
|
140 | + break; |
|
141 | + } |
|
142 | + // ensure REG_final_price has a valid value, and skip if it turns out to be zero |
|
143 | + $registration->REG_final_price = ! empty($registration->REG_final_price) ? (float) $registration->REG_final_price : 0.00; |
|
144 | + if (! $registration->REG_final_price > 0) { |
|
145 | + continue; |
|
146 | + } |
|
147 | + // because REG_paid may have been updated by a previous payment, we need to retrieve the value from the db |
|
148 | + $possibly_updated_REG_paid = $this->_get_possibly_updated_REG_paid($REG_ID); |
|
149 | + if (is_float($possibly_updated_REG_paid)) { |
|
150 | + $registration->REG_paid = $possibly_updated_REG_paid; |
|
151 | + } |
|
152 | + // and ensure REG_paid has a valid value |
|
153 | + $registration->REG_paid = ! empty($registration->REG_paid) ? (float) $registration->REG_paid : 0.00; |
|
154 | + // calculate amount owing, and skip if it turns out to be zero |
|
155 | + $owing = $registration->REG_final_price - $registration->REG_paid; |
|
156 | + if (! $owing > 0) { |
|
157 | + continue; |
|
158 | + } |
|
159 | + // don't allow payment amount to exceed the available payment amount, OR the amount owing |
|
160 | + $payment_amount = min($available_payment_amount, $owing); |
|
161 | + // update $available_payment_amount |
|
162 | + $available_payment_amount = $available_payment_amount - $payment_amount; |
|
163 | + // add relation between registration and payment and set amount |
|
164 | + if ($this->_insert_registration_payment($registration->REG_ID, $payment->PAY_ID, $payment_amount)) { |
|
165 | + // calculate and set new REG_paid |
|
166 | + $registration->REG_paid = $registration->REG_paid + $payment_amount; |
|
167 | + $this->_update_registration_paid($registration->REG_ID, $registration->REG_paid); |
|
168 | + } |
|
169 | + } |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * _insert_registration_payment |
|
176 | + * |
|
177 | + * @param int $REG_ID |
|
178 | + * @param int $PAY_ID |
|
179 | + * @param float $PAY_amount |
|
180 | + * @return bool |
|
181 | + */ |
|
182 | + protected function _insert_registration_payment($REG_ID = 0, $PAY_ID = 0, $PAY_amount = 0.00) |
|
183 | + { |
|
184 | + /** @type WPDB $wpdb */ |
|
185 | + global $wpdb; |
|
186 | + $success = $wpdb->insert( |
|
187 | + $this->_registration_payment_table, |
|
188 | + array( 'REG_ID' => $REG_ID, 'PAY_ID' => $PAY_ID, 'RPY_amount' => $PAY_amount, ), // data |
|
189 | + array( '%f' ) // data format |
|
190 | + ); |
|
191 | + if ($success === false) { |
|
192 | + $this->add_error( |
|
193 | + sprintf( |
|
194 | + __('Could not update registration paid value for registration ID=%1$d because "%2$s"', 'event_espresso'), |
|
195 | + $REG_ID, |
|
196 | + $wpdb->last_error |
|
197 | + ) |
|
198 | + ); |
|
199 | + return false; |
|
200 | + } |
|
201 | + return true; |
|
202 | + } |
|
203 | + |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * _update_registration_paid |
|
208 | + * |
|
209 | + * @param int $REG_ID |
|
210 | + * @param float $REG_paid |
|
211 | + * @return bool |
|
212 | + */ |
|
213 | + protected function _update_registration_paid($REG_ID = 0, $REG_paid = 0.00) |
|
214 | + { |
|
215 | + /** @type WPDB $wpdb */ |
|
216 | + global $wpdb; |
|
217 | + $success = $wpdb->update( |
|
218 | + $this->_registration_table, |
|
219 | + array( 'REG_paid' => $REG_paid ), // data |
|
220 | + array( 'REG_ID' => $REG_ID ), // where |
|
221 | + array( '%f' ), // data format |
|
222 | + array( '%d' ) // where format |
|
223 | + ); |
|
224 | + if ($success === false) { |
|
225 | + $this->add_error( |
|
226 | + sprintf( |
|
227 | + __('Could not update registration paid value for registration ID=%1$d because "%2$s"', 'event_espresso'), |
|
228 | + $REG_ID, |
|
229 | + $wpdb->last_error |
|
230 | + ) |
|
231 | + ); |
|
232 | + return false; |
|
233 | + } |
|
234 | + return true; |
|
235 | + } |
|
236 | 236 | } |
@@ -24,10 +24,10 @@ discard block |
||
24 | 24 | global $wpdb; |
25 | 25 | $this->_pretty_name = __('Registration Payment Record Generation', 'event_espresso'); |
26 | 26 | // define tables |
27 | - $this->_old_table = $wpdb->prefix . 'esp_transaction'; |
|
28 | - $this->_payment_table = $wpdb->prefix . 'esp_payment'; |
|
29 | - $this->_registration_table = $wpdb->prefix . 'esp_registration'; |
|
30 | - $this->_registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
27 | + $this->_old_table = $wpdb->prefix.'esp_transaction'; |
|
28 | + $this->_payment_table = $wpdb->prefix.'esp_payment'; |
|
29 | + $this->_registration_table = $wpdb->prefix.'esp_registration'; |
|
30 | + $this->_registration_payment_table = $wpdb->prefix.'esp_registration_payment'; |
|
31 | 31 | // build SQL WHERE clauses |
32 | 32 | $this->_extra_where_sql = "WHERE STS_ID IN ( 'TIN', 'TCM' ) AND TXN_Total != '0.000'"; |
33 | 33 | parent::__construct(); |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | /** @type WPDB $wpdb */ |
45 | 45 | global $wpdb; |
46 | 46 | $TXN_ID = absint($transaction['TXN_ID']); |
47 | - if (! $TXN_ID) { |
|
47 | + if ( ! $TXN_ID) { |
|
48 | 48 | $this->add_error( |
49 | 49 | sprintf( |
50 | 50 | __('Invalid transaction with ID=%1$d. Error: "%2$s"', 'event_espresso'), |
@@ -136,12 +136,12 @@ discard block |
||
136 | 136 | $available_payment_amount = $payment->PAY_amount; |
137 | 137 | foreach ($registrations as $REG_ID => $registration) { |
138 | 138 | // nothing left, then we are done here? |
139 | - if (! $available_payment_amount > 0) { |
|
139 | + if ( ! $available_payment_amount > 0) { |
|
140 | 140 | break; |
141 | 141 | } |
142 | 142 | // ensure REG_final_price has a valid value, and skip if it turns out to be zero |
143 | 143 | $registration->REG_final_price = ! empty($registration->REG_final_price) ? (float) $registration->REG_final_price : 0.00; |
144 | - if (! $registration->REG_final_price > 0) { |
|
144 | + if ( ! $registration->REG_final_price > 0) { |
|
145 | 145 | continue; |
146 | 146 | } |
147 | 147 | // because REG_paid may have been updated by a previous payment, we need to retrieve the value from the db |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | $registration->REG_paid = ! empty($registration->REG_paid) ? (float) $registration->REG_paid : 0.00; |
154 | 154 | // calculate amount owing, and skip if it turns out to be zero |
155 | 155 | $owing = $registration->REG_final_price - $registration->REG_paid; |
156 | - if (! $owing > 0) { |
|
156 | + if ( ! $owing > 0) { |
|
157 | 157 | continue; |
158 | 158 | } |
159 | 159 | // don't allow payment amount to exceed the available payment amount, OR the amount owing |
@@ -185,8 +185,8 @@ discard block |
||
185 | 185 | global $wpdb; |
186 | 186 | $success = $wpdb->insert( |
187 | 187 | $this->_registration_payment_table, |
188 | - array( 'REG_ID' => $REG_ID, 'PAY_ID' => $PAY_ID, 'RPY_amount' => $PAY_amount, ), // data |
|
189 | - array( '%f' ) // data format |
|
188 | + array('REG_ID' => $REG_ID, 'PAY_ID' => $PAY_ID, 'RPY_amount' => $PAY_amount,), // data |
|
189 | + array('%f') // data format |
|
190 | 190 | ); |
191 | 191 | if ($success === false) { |
192 | 192 | $this->add_error( |
@@ -216,10 +216,10 @@ discard block |
||
216 | 216 | global $wpdb; |
217 | 217 | $success = $wpdb->update( |
218 | 218 | $this->_registration_table, |
219 | - array( 'REG_paid' => $REG_paid ), // data |
|
220 | - array( 'REG_ID' => $REG_ID ), // where |
|
221 | - array( '%f' ), // data format |
|
222 | - array( '%d' ) // where format |
|
219 | + array('REG_paid' => $REG_paid), // data |
|
220 | + array('REG_ID' => $REG_ID), // where |
|
221 | + array('%f'), // data format |
|
222 | + array('%d') // where format |
|
223 | 223 | ); |
224 | 224 | if ($success === false) { |
225 | 225 | $this->add_error( |
@@ -12,73 +12,73 @@ discard block |
||
12 | 12 | class EE_DMS_4_7_0_Add_Taxes_To_REG_Final_Price extends EE_Data_Migration_Script_Stage_Table |
13 | 13 | { |
14 | 14 | |
15 | - protected $_ticket_table; |
|
16 | - |
|
17 | - protected $_line_item_table; |
|
18 | - |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - /** @type WPDB $wpdb */ |
|
22 | - global $wpdb; |
|
23 | - $this->_pretty_name = __('Registration Final Price Tax Calculations', 'event_espresso'); |
|
24 | - // define tables |
|
25 | - $this->_old_table = $wpdb->prefix . 'esp_registration'; |
|
26 | - $this->_ticket_table = $wpdb->prefix . 'esp_ticket'; |
|
27 | - $this->_line_item_table = $wpdb->prefix . 'esp_line_item'; |
|
28 | - parent::__construct(); |
|
29 | - } |
|
30 | - |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * @return string |
|
35 | - */ |
|
36 | - protected function _get_rest_of_sql_for_query() |
|
37 | - { |
|
38 | - $SQL = "FROM {$this->_old_table} AS reg "; |
|
39 | - $SQL .= "JOIN {$this->_ticket_table} as tkt ON reg.TKT_ID = tkt.TKT_ID "; |
|
40 | - $SQL .= "JOIN {$this->_line_item_table} as line ON reg.TXN_ID = line.TXN_ID "; |
|
41 | - $SQL .= "WHERE tkt.TKT_taxable = 1 "; |
|
42 | - $SQL .= "AND line.LIN_code = 'total' "; |
|
43 | - $SQL .= "AND reg.REG_final_price > 0 "; |
|
44 | - return $SQL; |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * Counts the records to migrate; the public version may cache it |
|
51 | - * @return int |
|
52 | - */ |
|
53 | - public function _count_records_to_migrate() |
|
54 | - { |
|
55 | - /** @type WPDB $wpdb */ |
|
56 | - global $wpdb; |
|
57 | - $SQL = "SELECT count( reg.REG_ID ) "; |
|
58 | - $SQL .= $this->_get_rest_of_sql_for_query(); |
|
59 | - $count = $wpdb->get_var($SQL); |
|
60 | - return $count; |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * Gets data for all registrations with taxable tickets in the esp_line_item table |
|
67 | - * @global wpdb $wpdb |
|
68 | - * @param int $limit |
|
69 | - * @return array of arrays like $wpdb->get_results($sql, ARRAY_A) |
|
70 | - */ |
|
71 | - protected function _get_rows($limit) |
|
72 | - { |
|
73 | - /** @type WPDB $wpdb */ |
|
74 | - global $wpdb; |
|
75 | - $start_at_record = $this->count_records_migrated(); |
|
76 | - $SQL = "SELECT reg.REG_ID, reg.REG_final_price, line.LIN_ID "; |
|
77 | - $SQL .= $this->_get_rest_of_sql_for_query(); |
|
78 | - $SQL .= $wpdb->prepare("LIMIT %d, %d", $start_at_record, $limit); |
|
79 | - |
|
80 | - // produces something like: |
|
81 | - /* |
|
15 | + protected $_ticket_table; |
|
16 | + |
|
17 | + protected $_line_item_table; |
|
18 | + |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + /** @type WPDB $wpdb */ |
|
22 | + global $wpdb; |
|
23 | + $this->_pretty_name = __('Registration Final Price Tax Calculations', 'event_espresso'); |
|
24 | + // define tables |
|
25 | + $this->_old_table = $wpdb->prefix . 'esp_registration'; |
|
26 | + $this->_ticket_table = $wpdb->prefix . 'esp_ticket'; |
|
27 | + $this->_line_item_table = $wpdb->prefix . 'esp_line_item'; |
|
28 | + parent::__construct(); |
|
29 | + } |
|
30 | + |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * @return string |
|
35 | + */ |
|
36 | + protected function _get_rest_of_sql_for_query() |
|
37 | + { |
|
38 | + $SQL = "FROM {$this->_old_table} AS reg "; |
|
39 | + $SQL .= "JOIN {$this->_ticket_table} as tkt ON reg.TKT_ID = tkt.TKT_ID "; |
|
40 | + $SQL .= "JOIN {$this->_line_item_table} as line ON reg.TXN_ID = line.TXN_ID "; |
|
41 | + $SQL .= "WHERE tkt.TKT_taxable = 1 "; |
|
42 | + $SQL .= "AND line.LIN_code = 'total' "; |
|
43 | + $SQL .= "AND reg.REG_final_price > 0 "; |
|
44 | + return $SQL; |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * Counts the records to migrate; the public version may cache it |
|
51 | + * @return int |
|
52 | + */ |
|
53 | + public function _count_records_to_migrate() |
|
54 | + { |
|
55 | + /** @type WPDB $wpdb */ |
|
56 | + global $wpdb; |
|
57 | + $SQL = "SELECT count( reg.REG_ID ) "; |
|
58 | + $SQL .= $this->_get_rest_of_sql_for_query(); |
|
59 | + $count = $wpdb->get_var($SQL); |
|
60 | + return $count; |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * Gets data for all registrations with taxable tickets in the esp_line_item table |
|
67 | + * @global wpdb $wpdb |
|
68 | + * @param int $limit |
|
69 | + * @return array of arrays like $wpdb->get_results($sql, ARRAY_A) |
|
70 | + */ |
|
71 | + protected function _get_rows($limit) |
|
72 | + { |
|
73 | + /** @type WPDB $wpdb */ |
|
74 | + global $wpdb; |
|
75 | + $start_at_record = $this->count_records_migrated(); |
|
76 | + $SQL = "SELECT reg.REG_ID, reg.REG_final_price, line.LIN_ID "; |
|
77 | + $SQL .= $this->_get_rest_of_sql_for_query(); |
|
78 | + $SQL .= $wpdb->prepare("LIMIT %d, %d", $start_at_record, $limit); |
|
79 | + |
|
80 | + // produces something like: |
|
81 | + /* |
|
82 | 82 | SELECT |
83 | 83 | reg.REG_ID, |
84 | 84 | reg.REG_final_price, |
@@ -95,137 +95,137 @@ discard block |
||
95 | 95 | LIMIT 1, 50 |
96 | 96 | */ |
97 | 97 | |
98 | - return $wpdb->get_results($SQL, ARRAY_A); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * @param array $row |
|
105 | - * @return void |
|
106 | - */ |
|
107 | - protected function _migrate_old_row($row) |
|
108 | - { |
|
109 | - /** @type WPDB $wpdb */ |
|
110 | - global $wpdb; |
|
111 | - // ensure all required values are present |
|
112 | - if (! isset($row['REG_ID'], $row['REG_final_price'], $row['LIN_ID'])) { |
|
113 | - $this->add_error( |
|
114 | - sprintf( |
|
115 | - __('Invalid query results returned with the following data:%1$s REG_ID=%2$d, REG_final_price=%3$d, LIN_ID=%4$f. Error: "%5$s"', 'event_espresso'), |
|
116 | - '<br />', |
|
117 | - isset($row['REG_ID']) ? $row['REG_ID'] : '', |
|
118 | - isset($row['REG_final_price']) ? $row['REG_final_price'] : '', |
|
119 | - isset($row['LIN_ID']) ? $row['LIN_ID'] : '', |
|
120 | - $wpdb->last_error |
|
121 | - ) |
|
122 | - ); |
|
123 | - return; |
|
124 | - } |
|
125 | - // get tax subtotal |
|
126 | - $tax_subtotal_line_item_ID = $this->_get_line_item_ID_for_tax_subtotal($row['LIN_ID']); |
|
127 | - if (! $tax_subtotal_line_item_ID) { |
|
128 | - $this->add_error( |
|
129 | - sprintf( |
|
130 | - __('Invalid line item ID returned. Error: "%1$s"', 'event_espresso'), |
|
131 | - $wpdb->last_error |
|
132 | - ) |
|
133 | - ); |
|
134 | - return; |
|
135 | - } |
|
136 | - // now get taxes |
|
137 | - $taxes = $this->_get_tax_amounts($tax_subtotal_line_item_ID); |
|
138 | - // apply taxes to registration final price |
|
139 | - $this->_apply_taxes($row['REG_ID'], $row['REG_final_price'], $taxes); |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * _get_tax_subtotal |
|
146 | - * |
|
147 | - * @param int $LIN_ID |
|
148 | - * @return int |
|
149 | - */ |
|
150 | - protected function _get_line_item_ID_for_tax_subtotal($LIN_ID) |
|
151 | - { |
|
152 | - /** @type WPDB $wpdb */ |
|
153 | - global $wpdb; |
|
154 | - $SQL = "SELECT LIN_ID "; |
|
155 | - $SQL .= "FROM {$this->_line_item_table} "; |
|
156 | - $SQL .= "WHERE LIN_parent = %d "; |
|
157 | - $SQL .= "AND LIN_code = 'taxes'"; |
|
158 | - return $wpdb->get_var($wpdb->prepare($SQL, $LIN_ID)); |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * _get_tax_subtotal |
|
165 | - * |
|
166 | - * @param int $LIN_ID |
|
167 | - * @return array |
|
168 | - */ |
|
169 | - protected function _get_tax_amounts($LIN_ID) |
|
170 | - { |
|
171 | - /** @type WPDB $wpdb */ |
|
172 | - global $wpdb; |
|
173 | - $SQL = "SELECT LIN_percent "; |
|
174 | - $SQL .= "FROM {$this->_line_item_table} "; |
|
175 | - $SQL .= "WHERE LIN_parent = %d"; |
|
176 | - return $wpdb->get_results($wpdb->prepare($SQL, $LIN_ID), OBJECT_K); |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * _apply_taxes |
|
183 | - * |
|
184 | - * @param int $REG_ID |
|
185 | - * @param float $final_price |
|
186 | - * @param array $taxes |
|
187 | - * @return void |
|
188 | - */ |
|
189 | - protected function _apply_taxes($REG_ID = 0, $final_price = 0.00, $taxes = array()) |
|
190 | - { |
|
191 | - if (is_array($taxes) && ! empty($taxes)) { |
|
192 | - $total_taxes = 0; |
|
193 | - foreach ($taxes as $tax) { |
|
194 | - $total_taxes += $final_price * ( $tax->LIN_percent / 100 ); |
|
195 | - } |
|
196 | - $final_price += $total_taxes; |
|
197 | - $this->_update_registration_final_price($REG_ID, $final_price); |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * _update_registration_final_price |
|
205 | - * |
|
206 | - * @param int $REG_ID |
|
207 | - * @param float $REG_final_price |
|
208 | - * @return void |
|
209 | - */ |
|
210 | - protected function _update_registration_final_price($REG_ID = 0, $REG_final_price = 0.00) |
|
211 | - { |
|
212 | - /** @type WPDB $wpdb */ |
|
213 | - global $wpdb; |
|
214 | - $success = $wpdb->update( |
|
215 | - $this->_old_table, |
|
216 | - array( 'REG_final_price' => $REG_final_price ), // data |
|
217 | - array( 'REG_ID' => $REG_ID ), // where |
|
218 | - array( '%f' ), // data format |
|
219 | - array( '%d' ) // where format |
|
220 | - ); |
|
221 | - if ($success === false) { |
|
222 | - $this->add_error( |
|
223 | - sprintf( |
|
224 | - __('Could not update registration final price value for registration ID=%1$d because "%2$s"', 'event_espresso'), |
|
225 | - $REG_ID, |
|
226 | - $wpdb->last_error |
|
227 | - ) |
|
228 | - ); |
|
229 | - } |
|
230 | - } |
|
98 | + return $wpdb->get_results($SQL, ARRAY_A); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * @param array $row |
|
105 | + * @return void |
|
106 | + */ |
|
107 | + protected function _migrate_old_row($row) |
|
108 | + { |
|
109 | + /** @type WPDB $wpdb */ |
|
110 | + global $wpdb; |
|
111 | + // ensure all required values are present |
|
112 | + if (! isset($row['REG_ID'], $row['REG_final_price'], $row['LIN_ID'])) { |
|
113 | + $this->add_error( |
|
114 | + sprintf( |
|
115 | + __('Invalid query results returned with the following data:%1$s REG_ID=%2$d, REG_final_price=%3$d, LIN_ID=%4$f. Error: "%5$s"', 'event_espresso'), |
|
116 | + '<br />', |
|
117 | + isset($row['REG_ID']) ? $row['REG_ID'] : '', |
|
118 | + isset($row['REG_final_price']) ? $row['REG_final_price'] : '', |
|
119 | + isset($row['LIN_ID']) ? $row['LIN_ID'] : '', |
|
120 | + $wpdb->last_error |
|
121 | + ) |
|
122 | + ); |
|
123 | + return; |
|
124 | + } |
|
125 | + // get tax subtotal |
|
126 | + $tax_subtotal_line_item_ID = $this->_get_line_item_ID_for_tax_subtotal($row['LIN_ID']); |
|
127 | + if (! $tax_subtotal_line_item_ID) { |
|
128 | + $this->add_error( |
|
129 | + sprintf( |
|
130 | + __('Invalid line item ID returned. Error: "%1$s"', 'event_espresso'), |
|
131 | + $wpdb->last_error |
|
132 | + ) |
|
133 | + ); |
|
134 | + return; |
|
135 | + } |
|
136 | + // now get taxes |
|
137 | + $taxes = $this->_get_tax_amounts($tax_subtotal_line_item_ID); |
|
138 | + // apply taxes to registration final price |
|
139 | + $this->_apply_taxes($row['REG_ID'], $row['REG_final_price'], $taxes); |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * _get_tax_subtotal |
|
146 | + * |
|
147 | + * @param int $LIN_ID |
|
148 | + * @return int |
|
149 | + */ |
|
150 | + protected function _get_line_item_ID_for_tax_subtotal($LIN_ID) |
|
151 | + { |
|
152 | + /** @type WPDB $wpdb */ |
|
153 | + global $wpdb; |
|
154 | + $SQL = "SELECT LIN_ID "; |
|
155 | + $SQL .= "FROM {$this->_line_item_table} "; |
|
156 | + $SQL .= "WHERE LIN_parent = %d "; |
|
157 | + $SQL .= "AND LIN_code = 'taxes'"; |
|
158 | + return $wpdb->get_var($wpdb->prepare($SQL, $LIN_ID)); |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * _get_tax_subtotal |
|
165 | + * |
|
166 | + * @param int $LIN_ID |
|
167 | + * @return array |
|
168 | + */ |
|
169 | + protected function _get_tax_amounts($LIN_ID) |
|
170 | + { |
|
171 | + /** @type WPDB $wpdb */ |
|
172 | + global $wpdb; |
|
173 | + $SQL = "SELECT LIN_percent "; |
|
174 | + $SQL .= "FROM {$this->_line_item_table} "; |
|
175 | + $SQL .= "WHERE LIN_parent = %d"; |
|
176 | + return $wpdb->get_results($wpdb->prepare($SQL, $LIN_ID), OBJECT_K); |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * _apply_taxes |
|
183 | + * |
|
184 | + * @param int $REG_ID |
|
185 | + * @param float $final_price |
|
186 | + * @param array $taxes |
|
187 | + * @return void |
|
188 | + */ |
|
189 | + protected function _apply_taxes($REG_ID = 0, $final_price = 0.00, $taxes = array()) |
|
190 | + { |
|
191 | + if (is_array($taxes) && ! empty($taxes)) { |
|
192 | + $total_taxes = 0; |
|
193 | + foreach ($taxes as $tax) { |
|
194 | + $total_taxes += $final_price * ( $tax->LIN_percent / 100 ); |
|
195 | + } |
|
196 | + $final_price += $total_taxes; |
|
197 | + $this->_update_registration_final_price($REG_ID, $final_price); |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * _update_registration_final_price |
|
205 | + * |
|
206 | + * @param int $REG_ID |
|
207 | + * @param float $REG_final_price |
|
208 | + * @return void |
|
209 | + */ |
|
210 | + protected function _update_registration_final_price($REG_ID = 0, $REG_final_price = 0.00) |
|
211 | + { |
|
212 | + /** @type WPDB $wpdb */ |
|
213 | + global $wpdb; |
|
214 | + $success = $wpdb->update( |
|
215 | + $this->_old_table, |
|
216 | + array( 'REG_final_price' => $REG_final_price ), // data |
|
217 | + array( 'REG_ID' => $REG_ID ), // where |
|
218 | + array( '%f' ), // data format |
|
219 | + array( '%d' ) // where format |
|
220 | + ); |
|
221 | + if ($success === false) { |
|
222 | + $this->add_error( |
|
223 | + sprintf( |
|
224 | + __('Could not update registration final price value for registration ID=%1$d because "%2$s"', 'event_espresso'), |
|
225 | + $REG_ID, |
|
226 | + $wpdb->last_error |
|
227 | + ) |
|
228 | + ); |
|
229 | + } |
|
230 | + } |
|
231 | 231 | } |
@@ -22,9 +22,9 @@ discard block |
||
22 | 22 | global $wpdb; |
23 | 23 | $this->_pretty_name = __('Registration Final Price Tax Calculations', 'event_espresso'); |
24 | 24 | // define tables |
25 | - $this->_old_table = $wpdb->prefix . 'esp_registration'; |
|
26 | - $this->_ticket_table = $wpdb->prefix . 'esp_ticket'; |
|
27 | - $this->_line_item_table = $wpdb->prefix . 'esp_line_item'; |
|
25 | + $this->_old_table = $wpdb->prefix.'esp_registration'; |
|
26 | + $this->_ticket_table = $wpdb->prefix.'esp_ticket'; |
|
27 | + $this->_line_item_table = $wpdb->prefix.'esp_line_item'; |
|
28 | 28 | parent::__construct(); |
29 | 29 | } |
30 | 30 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | /** @type WPDB $wpdb */ |
110 | 110 | global $wpdb; |
111 | 111 | // ensure all required values are present |
112 | - if (! isset($row['REG_ID'], $row['REG_final_price'], $row['LIN_ID'])) { |
|
112 | + if ( ! isset($row['REG_ID'], $row['REG_final_price'], $row['LIN_ID'])) { |
|
113 | 113 | $this->add_error( |
114 | 114 | sprintf( |
115 | 115 | __('Invalid query results returned with the following data:%1$s REG_ID=%2$d, REG_final_price=%3$d, LIN_ID=%4$f. Error: "%5$s"', 'event_espresso'), |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | } |
125 | 125 | // get tax subtotal |
126 | 126 | $tax_subtotal_line_item_ID = $this->_get_line_item_ID_for_tax_subtotal($row['LIN_ID']); |
127 | - if (! $tax_subtotal_line_item_ID) { |
|
127 | + if ( ! $tax_subtotal_line_item_ID) { |
|
128 | 128 | $this->add_error( |
129 | 129 | sprintf( |
130 | 130 | __('Invalid line item ID returned. Error: "%1$s"', 'event_espresso'), |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | if (is_array($taxes) && ! empty($taxes)) { |
192 | 192 | $total_taxes = 0; |
193 | 193 | foreach ($taxes as $tax) { |
194 | - $total_taxes += $final_price * ( $tax->LIN_percent / 100 ); |
|
194 | + $total_taxes += $final_price * ($tax->LIN_percent / 100); |
|
195 | 195 | } |
196 | 196 | $final_price += $total_taxes; |
197 | 197 | $this->_update_registration_final_price($REG_ID, $final_price); |
@@ -213,10 +213,10 @@ discard block |
||
213 | 213 | global $wpdb; |
214 | 214 | $success = $wpdb->update( |
215 | 215 | $this->_old_table, |
216 | - array( 'REG_final_price' => $REG_final_price ), // data |
|
217 | - array( 'REG_ID' => $REG_ID ), // where |
|
218 | - array( '%f' ), // data format |
|
219 | - array( '%d' ) // where format |
|
216 | + array('REG_final_price' => $REG_final_price), // data |
|
217 | + array('REG_ID' => $REG_ID), // where |
|
218 | + array('%f'), // data format |
|
219 | + array('%d') // where format |
|
220 | 220 | ); |
221 | 221 | if ($success === false) { |
222 | 222 | $this->add_error( |
@@ -18,44 +18,44 @@ |
||
18 | 18 | class EE_DMS_Unknown_1_0_0 extends EE_Data_Migration_Script_Base |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * Returns whether or not this data migration script can operate on the given version of the database. |
|
23 | - * Eg, if this migration script can migrate from 3.1.26 or higher (but not anything after 4.0.0), and |
|
24 | - * it's passed a string like '3.1.38B', it should return true |
|
25 | - * |
|
26 | - * @param string $version_string |
|
27 | - * @return boolean |
|
28 | - */ |
|
29 | - public function can_migrate_from_version($version_string) |
|
30 | - { |
|
31 | - return false; |
|
32 | - } |
|
33 | - |
|
34 | - public function schema_changes_after_migration() |
|
35 | - { |
|
36 | - return; |
|
37 | - } |
|
38 | - |
|
39 | - public function schema_changes_before_migration() |
|
40 | - { |
|
41 | - return; |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * All children of this must call parent::__construct() at the end of their constructor or suffer the consequences! |
|
47 | - * |
|
48 | - * @param TableManager $table_manager |
|
49 | - * @param TableAnalysis $table_analysis |
|
50 | - */ |
|
51 | - public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
52 | - { |
|
53 | - $this->_migration_stages = array(); |
|
54 | - $this->_pretty_name = __("Fatal Uncatchable Error Occurred", "event_espresso"); |
|
55 | - parent::__construct($table_manager, $table_analysis); |
|
56 | - } |
|
57 | - |
|
58 | - public function migration_page_hooks() |
|
59 | - { |
|
60 | - } |
|
21 | + /** |
|
22 | + * Returns whether or not this data migration script can operate on the given version of the database. |
|
23 | + * Eg, if this migration script can migrate from 3.1.26 or higher (but not anything after 4.0.0), and |
|
24 | + * it's passed a string like '3.1.38B', it should return true |
|
25 | + * |
|
26 | + * @param string $version_string |
|
27 | + * @return boolean |
|
28 | + */ |
|
29 | + public function can_migrate_from_version($version_string) |
|
30 | + { |
|
31 | + return false; |
|
32 | + } |
|
33 | + |
|
34 | + public function schema_changes_after_migration() |
|
35 | + { |
|
36 | + return; |
|
37 | + } |
|
38 | + |
|
39 | + public function schema_changes_before_migration() |
|
40 | + { |
|
41 | + return; |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * All children of this must call parent::__construct() at the end of their constructor or suffer the consequences! |
|
47 | + * |
|
48 | + * @param TableManager $table_manager |
|
49 | + * @param TableAnalysis $table_analysis |
|
50 | + */ |
|
51 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
52 | + { |
|
53 | + $this->_migration_stages = array(); |
|
54 | + $this->_pretty_name = __("Fatal Uncatchable Error Occurred", "event_espresso"); |
|
55 | + parent::__construct($table_manager, $table_analysis); |
|
56 | + } |
|
57 | + |
|
58 | + public function migration_page_hooks() |
|
59 | + { |
|
60 | + } |
|
61 | 61 | } |
@@ -15,44 +15,44 @@ |
||
15 | 15 | |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * Just initializes the status of the migration |
|
20 | - * |
|
21 | - * @return EE_DMS_4_9_0_Answers_With_No_Registration |
|
22 | - */ |
|
23 | - public function __construct() |
|
24 | - { |
|
25 | - $this->_pretty_name = __('Answer Cleanup', 'event_espresso'); |
|
26 | - parent::__construct(); |
|
27 | - } |
|
18 | + /** |
|
19 | + * Just initializes the status of the migration |
|
20 | + * |
|
21 | + * @return EE_DMS_4_9_0_Answers_With_No_Registration |
|
22 | + */ |
|
23 | + public function __construct() |
|
24 | + { |
|
25 | + $this->_pretty_name = __('Answer Cleanup', 'event_espresso'); |
|
26 | + parent::__construct(); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Counts the records to migrate; the public version may cache it |
|
31 | - * @return int |
|
32 | - */ |
|
33 | - protected function _count_records_to_migrate() |
|
34 | - { |
|
35 | - return 1; |
|
36 | - } |
|
29 | + /** |
|
30 | + * Counts the records to migrate; the public version may cache it |
|
31 | + * @return int |
|
32 | + */ |
|
33 | + protected function _count_records_to_migrate() |
|
34 | + { |
|
35 | + return 1; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property accordingly. |
|
40 | - * Note: it should not alter the count of items migrated. That is done in the public function that calls this. |
|
41 | - * IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the last migration step, otherwise it |
|
42 | - * should always return $num_items_to_migrate. (Eg, if we're migrating attendees rows from the database, and $num_items_to_migrate is set to 50, |
|
43 | - * then we SHOULD actually migrate 50 rows,but at very least we MUST report/return 50 items migrated) |
|
44 | - * @param int $num_items_to_migrate |
|
45 | - * @return int number of items ACTUALLY migrated |
|
46 | - */ |
|
47 | - protected function _migration_step($num_items_to_migrate = 50) |
|
48 | - { |
|
49 | - global $wpdb; |
|
50 | - $wpdb->delete( |
|
51 | - $wpdb->prefix . 'esp_answer', |
|
52 | - array( 'REG_ID' => 0 ), |
|
53 | - array( '%d' ) |
|
54 | - ); |
|
55 | - $this->set_completed(); |
|
56 | - return 1; |
|
57 | - } |
|
38 | + /** |
|
39 | + * IMPORTANT: if an error is encountered, or everything is finished, this stage should update its status property accordingly. |
|
40 | + * Note: it should not alter the count of items migrated. That is done in the public function that calls this. |
|
41 | + * IMPORTANT: The count of items migrated should ONLY be less than $num_items_to_migrate when it's the last migration step, otherwise it |
|
42 | + * should always return $num_items_to_migrate. (Eg, if we're migrating attendees rows from the database, and $num_items_to_migrate is set to 50, |
|
43 | + * then we SHOULD actually migrate 50 rows,but at very least we MUST report/return 50 items migrated) |
|
44 | + * @param int $num_items_to_migrate |
|
45 | + * @return int number of items ACTUALLY migrated |
|
46 | + */ |
|
47 | + protected function _migration_step($num_items_to_migrate = 50) |
|
48 | + { |
|
49 | + global $wpdb; |
|
50 | + $wpdb->delete( |
|
51 | + $wpdb->prefix . 'esp_answer', |
|
52 | + array( 'REG_ID' => 0 ), |
|
53 | + array( '%d' ) |
|
54 | + ); |
|
55 | + $this->set_completed(); |
|
56 | + return 1; |
|
57 | + } |
|
58 | 58 | } |
@@ -48,9 +48,9 @@ |
||
48 | 48 | { |
49 | 49 | global $wpdb; |
50 | 50 | $wpdb->delete( |
51 | - $wpdb->prefix . 'esp_answer', |
|
52 | - array( 'REG_ID' => 0 ), |
|
53 | - array( '%d' ) |
|
51 | + $wpdb->prefix.'esp_answer', |
|
52 | + array('REG_ID' => 0), |
|
53 | + array('%d') |
|
54 | 54 | ); |
55 | 55 | $this->set_completed(); |
56 | 56 | return 1; |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | */ |
186 | 186 | public function add_error($error, $force = false) |
187 | 187 | { |
188 | - if (! defined('EE_DMS_ERROR_LIMIT')) { |
|
188 | + if ( ! defined('EE_DMS_ERROR_LIMIT')) { |
|
189 | 189 | $limit = 50; |
190 | 190 | } else { |
191 | 191 | $limit = EE_DMS_ERROR_LIMIT; |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | $this->_errors[] = "Limit reached; removed first half of errors to save space"; |
202 | 202 | $this->_errors[] = $error; |
203 | 203 | } else { |
204 | - $this->_errors[ $limit ] = 'More, but limit reached...'; |
|
204 | + $this->_errors[$limit] = 'More, but limit reached...'; |
|
205 | 205 | } |
206 | 206 | } else { |
207 | 207 | $this->_errors[] = $error; |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | $new_columns_and_values_for_string = array(); |
344 | 344 | $count = 0; |
345 | 345 | foreach ($new_row_as_array as $column => $value) { |
346 | - $new_columns_and_values_for_string[] = " $column => $value (" . $data_types[ $count++ ] . ")"; |
|
346 | + $new_columns_and_values_for_string[] = " $column => $value (".$data_types[$count++].")"; |
|
347 | 347 | } |
348 | 348 | return sprintf( |
349 | 349 | __( |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | foreach ($array_of_data as $name => $value) { |
375 | 375 | $unserialized_data = @unserialize($value); |
376 | 376 | if ($unserialized_data === false) { |
377 | - $fields_to_include[ $name ] = $value; |
|
377 | + $fields_to_include[$name] = $value; |
|
378 | 378 | } |
379 | 379 | } |
380 | 380 | return wp_json_encode($fields_to_include); |
@@ -17,408 +17,408 @@ |
||
17 | 17 | abstract class EE_Data_Migration_Class_Base |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var $records_to_migrate int count of all that have been migrated |
|
22 | - */ |
|
23 | - protected $_records_to_migrate = 0; |
|
24 | - |
|
25 | - /** |
|
26 | - * |
|
27 | - * @var $records_migrated int |
|
28 | - */ |
|
29 | - protected $_records_migrated = 0; |
|
30 | - |
|
31 | - /** |
|
32 | - * Whether this migration script is done or not. This COULD be deduced by |
|
33 | - * _records_to_migrate and _records_migrated, but that might nto be accurate |
|
34 | - * |
|
35 | - * @var string one of EE_Data_migration_Manager::status_* constants |
|
36 | - */ |
|
37 | - protected $_status = null; |
|
38 | - |
|
39 | - /** |
|
40 | - * internationalized name of this class. Convention is to NOT restate that |
|
41 | - * this class if a migration script or a migration script stage |
|
42 | - * |
|
43 | - * @var string (i18ned) |
|
44 | - */ |
|
45 | - protected $_pretty_name = null; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var array |
|
49 | - */ |
|
50 | - protected $_errors = array(); |
|
51 | - |
|
52 | - /** |
|
53 | - * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
54 | - */ |
|
55 | - protected $_table_manager; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
59 | - */ |
|
60 | - protected $_table_analysis; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * Just initializes the status of the migration |
|
65 | - * |
|
66 | - * @param TableManager $table_manager |
|
67 | - * @param TableAnalysis $table_analysis |
|
68 | - */ |
|
69 | - public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
70 | - { |
|
71 | - $this->_table_manager = $table_manager; |
|
72 | - $this->_table_analysis = $table_analysis; |
|
73 | - $this->set_status(EE_Data_Migration_Manager::status_continue); |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * Just gets the pretty name for this migration script or stage |
|
79 | - * |
|
80 | - * @throws EE_Error |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public function pretty_name() |
|
84 | - { |
|
85 | - if ($this->_pretty_name === null) { |
|
86 | - throw new EE_Error( |
|
87 | - sprintf( |
|
88 | - __( |
|
89 | - "Please give a pretty name to the migration script stage %s by assigning the property _pretty_name in the constructor", |
|
90 | - "event_espresso" |
|
91 | - ), |
|
92 | - get_class($this) |
|
93 | - ) |
|
94 | - ); |
|
95 | - } |
|
96 | - return $this->_pretty_name; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * |
|
101 | - * @return int |
|
102 | - */ |
|
103 | - public function count_records_to_migrate() |
|
104 | - { |
|
105 | - if ($this->_records_to_migrate == null) { |
|
106 | - $this->_records_to_migrate = $this->_count_records_to_migrate(); |
|
107 | - } |
|
108 | - return $this->_records_to_migrate; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Counts records already migrated. This should only be implemented by EE_Data_Migration_Script_base and |
|
113 | - * EE_Data_migration_Script_Stage |
|
114 | - * |
|
115 | - * @return int |
|
116 | - */ |
|
117 | - abstract public function count_records_migrated(); |
|
118 | - |
|
119 | - /** |
|
120 | - * Counts the records to migrate; the public version may cache it |
|
121 | - * |
|
122 | - * @return int |
|
123 | - */ |
|
124 | - abstract protected function _count_records_to_migrate(); |
|
125 | - |
|
126 | - /** |
|
127 | - * Returns a string indicating the migration script's status. |
|
128 | - * |
|
129 | - * @return string one of EE_Data_Migration_Manager::status_* constants |
|
130 | - * @throws EE_Error |
|
131 | - */ |
|
132 | - public function get_status() |
|
133 | - { |
|
134 | - if ($this->_status === null) { |
|
135 | - throw new EE_Error( |
|
136 | - sprintf( |
|
137 | - __( |
|
138 | - "Trying to get status of Migration class %s, but it has not been initialized yet. It should be set in the constructor.", |
|
139 | - "event_espresso" |
|
140 | - ), |
|
141 | - get_class($this) |
|
142 | - ) |
|
143 | - ); |
|
144 | - } |
|
145 | - return $this->_status; |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * |
|
150 | - * @param string $status |
|
151 | - * @return void |
|
152 | - */ |
|
153 | - protected function set_status($status) |
|
154 | - { |
|
155 | - $this->_status = $status; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @return array of strings |
|
160 | - */ |
|
161 | - abstract public function get_errors(); |
|
162 | - |
|
163 | - /** |
|
164 | - * Returns the last error that occurred. If none occurred, returns null |
|
165 | - * |
|
166 | - * @return string |
|
167 | - */ |
|
168 | - public function get_last_error() |
|
169 | - { |
|
170 | - $errors = $this->get_errors(); |
|
171 | - if ($errors) { |
|
172 | - return end($errors); |
|
173 | - } else { |
|
174 | - return null; |
|
175 | - } |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Adds an error to the array of errors on this class. |
|
180 | - * |
|
181 | - * @param string $error a string describing the error that will be useful for debugging. Consider including all |
|
182 | - * the data that led to the error, and a stack trace etc. |
|
183 | - * @param boolean $force force the error to be added (because otherwise we have a limit). If forcing and errors are |
|
184 | - * already at their limit, we will purposefully forget the first half |
|
185 | - */ |
|
186 | - public function add_error($error, $force = false) |
|
187 | - { |
|
188 | - if (! defined('EE_DMS_ERROR_LIMIT')) { |
|
189 | - $limit = 50; |
|
190 | - } else { |
|
191 | - $limit = EE_DMS_ERROR_LIMIT; |
|
192 | - } |
|
193 | - // make sure errors is an array, see ticket #8261 |
|
194 | - if (is_string($this->_errors)) { |
|
195 | - $this->_errors = array($this->_errors); |
|
196 | - } |
|
197 | - if (count($this->_errors) >= $limit) { |
|
198 | - if ($force) { |
|
199 | - // get rid of the first half of the errors and any above the limit |
|
200 | - $this->_errors = array_slice($this->_errors, $limit / 2, $limit / 2); |
|
201 | - $this->_errors[] = "Limit reached; removed first half of errors to save space"; |
|
202 | - $this->_errors[] = $error; |
|
203 | - } else { |
|
204 | - $this->_errors[ $limit ] = 'More, but limit reached...'; |
|
205 | - } |
|
206 | - } else { |
|
207 | - $this->_errors[] = $error; |
|
208 | - } |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * Indicates there was a fatal error and the migration cannot possibly continue |
|
213 | - * |
|
214 | - * @return boolean |
|
215 | - */ |
|
216 | - public function is_broken() |
|
217 | - { |
|
218 | - return $this->get_status() == EE_Data_Migration_Manager::status_fatal_error; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * @deprecated since 4.6.12 |
|
223 | - */ |
|
224 | - public function is_borked() |
|
225 | - { |
|
226 | - EE_Error::doing_it_wrong( |
|
227 | - 'is_borked', |
|
228 | - __( |
|
229 | - 'The cheeky "is_borked" method had been replaced with the more proper "is_broken"', |
|
230 | - 'event_espresso' |
|
231 | - ), |
|
232 | - '4.6.12' |
|
233 | - ); |
|
234 | - return $this->is_broken(); |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * Sets the status to as having a fatal error |
|
239 | - */ |
|
240 | - public function set_broken() |
|
241 | - { |
|
242 | - $this->_status = EE_Data_Migration_Manager::status_fatal_error; |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * |
|
247 | - * @deprecated since 4.6.12 |
|
248 | - */ |
|
249 | - public function set_borked() |
|
250 | - { |
|
251 | - EE_Error::doing_it_wrong( |
|
252 | - 'is_borked', |
|
253 | - __( |
|
254 | - 'The cheeky "is_borked" method had been replaced with the more proper "is_broken"', |
|
255 | - 'event_espresso' |
|
256 | - ), |
|
257 | - '4.6.12' |
|
258 | - ); |
|
259 | - return $this->set_broken(); |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Checks if this thing believes it is completed |
|
264 | - * |
|
265 | - * @return boolean |
|
266 | - */ |
|
267 | - public function is_completed() |
|
268 | - { |
|
269 | - return $this->get_status() == EE_Data_Migration_Manager::status_completed; |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Checks if the current script has more to do or not (ie, if it's status is CONTINUE) |
|
274 | - * |
|
275 | - * @return boolean |
|
276 | - */ |
|
277 | - public function has_more_to_do() |
|
278 | - { |
|
279 | - return $this->get_status() == EE_Data_Migration_Manager::status_continue; |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * Marks that we believe this migration thing is completed |
|
284 | - */ |
|
285 | - public function set_completed() |
|
286 | - { |
|
287 | - $this->_status = EE_Data_Migration_Manager::status_completed; |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Marks that we think this migration class can continue to migrate |
|
292 | - */ |
|
293 | - public function reattempt() |
|
294 | - { |
|
295 | - $this->_status = EE_Data_Migration_Manager::status_continue; |
|
296 | - $this->add_error(__('Reattempt migration', 'event_espresso'), true); |
|
297 | - } |
|
298 | - |
|
299 | - /** |
|
300 | - * A lot like "__sleep()" magic method in purpose, this is meant for persisting this class' |
|
301 | - * properties to the DB. However, we don't want to use __sleep() because its quite |
|
302 | - * possible that this class is defined when it goes to sleep, but NOT available when it |
|
303 | - * awakes (eg, this class is part of an addon that is deactivated at some point). |
|
304 | - */ |
|
305 | - public function properties_as_array() |
|
306 | - { |
|
307 | - $properties = get_object_vars($this); |
|
308 | - $properties['class'] = get_class($this); |
|
309 | - unset($properties['_migration_script']); |
|
310 | - unset($properties['_table_manager']); |
|
311 | - unset($properties['_table_analysis']); |
|
312 | - return $properties; |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * Sets all of the properties of this script stage to match what's in the array, which is assumed |
|
317 | - * to have been made from the properties_as_array() function. |
|
318 | - * |
|
319 | - * @param array $array_of_properties like what's produced from properties_as_array() method |
|
320 | - */ |
|
321 | - abstract public function instantiate_from_array_of_properties($array_of_properties); |
|
322 | - |
|
323 | - /** |
|
324 | - * Convenience method for showing a database insertion error |
|
325 | - * |
|
326 | - * @param string $old_table |
|
327 | - * @param array $old_row_as_array |
|
328 | - * @param string $new_table |
|
329 | - * @param array $new_row_as_array columns=>values like used in wpdb->insert |
|
330 | - * @param array $data_types numerically indexed |
|
331 | - * @return string |
|
332 | - */ |
|
333 | - protected function _create_error_message_for_db_insertion( |
|
334 | - $old_table, |
|
335 | - $old_row_as_array, |
|
336 | - $new_table, |
|
337 | - $new_row_as_array, |
|
338 | - $data_types |
|
339 | - ) { |
|
340 | - global $wpdb; |
|
341 | - $old_columns_and_values_for_string = array(); |
|
342 | - foreach ($old_row_as_array as $column => $value) { |
|
343 | - $old_columns_and_values_for_string[] = "$column => $value"; |
|
344 | - } |
|
345 | - $new_columns_and_values_for_string = array(); |
|
346 | - $count = 0; |
|
347 | - foreach ($new_row_as_array as $column => $value) { |
|
348 | - $new_columns_and_values_for_string[] = " $column => $value (" . $data_types[ $count++ ] . ")"; |
|
349 | - } |
|
350 | - return sprintf( |
|
351 | - __( |
|
352 | - 'Received error "%6$s" inserting row %5$s %1$s %5$s into table %2$s.%5$s Data used was %5$s %3$s %5$s from table %4$s.', |
|
353 | - 'event_espresso' |
|
354 | - ), |
|
355 | - implode(", ", $new_columns_and_values_for_string), |
|
356 | - $new_table, |
|
357 | - implode(", ", $old_columns_and_values_for_string), |
|
358 | - $old_table, |
|
359 | - '<br/>', |
|
360 | - $wpdb->last_error |
|
361 | - ); |
|
362 | - } |
|
363 | - |
|
364 | - |
|
365 | - /** |
|
366 | - * Same as json_encode, just avoids putting |
|
367 | - * serialized arrays into the http build query, as that would |
|
368 | - * |
|
369 | - * @param array $array_of_data |
|
370 | - * @return string |
|
371 | - */ |
|
372 | - protected function _json_encode($array_of_data) |
|
373 | - { |
|
374 | - // we'd rather NOT serialize the transaction details |
|
375 | - $fields_to_include = array(); |
|
376 | - foreach ($array_of_data as $name => $value) { |
|
377 | - $unserialized_data = @unserialize($value); |
|
378 | - if ($unserialized_data === false) { |
|
379 | - $fields_to_include[ $name ] = $value; |
|
380 | - } |
|
381 | - } |
|
382 | - return wp_json_encode($fields_to_include); |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * Gets the table manager (or throws an exception if it cannot be retrieved) |
|
387 | - * |
|
388 | - * @return TableManager |
|
389 | - * @throws EE_Error |
|
390 | - */ |
|
391 | - protected function _get_table_manager() |
|
392 | - { |
|
393 | - if ($this->_table_manager instanceof TableManager) { |
|
394 | - return $this->_table_manager; |
|
395 | - } else { |
|
396 | - throw new EE_Error( |
|
397 | - sprintf( |
|
398 | - __('Table manager on migration class %1$s is not set properly.', 'event_espresso'), |
|
399 | - get_class($this) |
|
400 | - ) |
|
401 | - ); |
|
402 | - } |
|
403 | - } |
|
404 | - |
|
405 | - /** |
|
406 | - * Gets the injected table analyzer, or throws an exception |
|
407 | - * |
|
408 | - * @return TableAnalysis |
|
409 | - * @throws EE_Error |
|
410 | - */ |
|
411 | - protected function _get_table_analysis() |
|
412 | - { |
|
413 | - if ($this->_table_analysis instanceof TableAnalysis) { |
|
414 | - return $this->_table_analysis; |
|
415 | - } else { |
|
416 | - throw new EE_Error( |
|
417 | - sprintf( |
|
418 | - __('Table analysis class on migration class %1$s is not set properly.', 'event_espresso'), |
|
419 | - get_class($this) |
|
420 | - ) |
|
421 | - ); |
|
422 | - } |
|
423 | - } |
|
20 | + /** |
|
21 | + * @var $records_to_migrate int count of all that have been migrated |
|
22 | + */ |
|
23 | + protected $_records_to_migrate = 0; |
|
24 | + |
|
25 | + /** |
|
26 | + * |
|
27 | + * @var $records_migrated int |
|
28 | + */ |
|
29 | + protected $_records_migrated = 0; |
|
30 | + |
|
31 | + /** |
|
32 | + * Whether this migration script is done or not. This COULD be deduced by |
|
33 | + * _records_to_migrate and _records_migrated, but that might nto be accurate |
|
34 | + * |
|
35 | + * @var string one of EE_Data_migration_Manager::status_* constants |
|
36 | + */ |
|
37 | + protected $_status = null; |
|
38 | + |
|
39 | + /** |
|
40 | + * internationalized name of this class. Convention is to NOT restate that |
|
41 | + * this class if a migration script or a migration script stage |
|
42 | + * |
|
43 | + * @var string (i18ned) |
|
44 | + */ |
|
45 | + protected $_pretty_name = null; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var array |
|
49 | + */ |
|
50 | + protected $_errors = array(); |
|
51 | + |
|
52 | + /** |
|
53 | + * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
54 | + */ |
|
55 | + protected $_table_manager; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
59 | + */ |
|
60 | + protected $_table_analysis; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * Just initializes the status of the migration |
|
65 | + * |
|
66 | + * @param TableManager $table_manager |
|
67 | + * @param TableAnalysis $table_analysis |
|
68 | + */ |
|
69 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
70 | + { |
|
71 | + $this->_table_manager = $table_manager; |
|
72 | + $this->_table_analysis = $table_analysis; |
|
73 | + $this->set_status(EE_Data_Migration_Manager::status_continue); |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * Just gets the pretty name for this migration script or stage |
|
79 | + * |
|
80 | + * @throws EE_Error |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public function pretty_name() |
|
84 | + { |
|
85 | + if ($this->_pretty_name === null) { |
|
86 | + throw new EE_Error( |
|
87 | + sprintf( |
|
88 | + __( |
|
89 | + "Please give a pretty name to the migration script stage %s by assigning the property _pretty_name in the constructor", |
|
90 | + "event_espresso" |
|
91 | + ), |
|
92 | + get_class($this) |
|
93 | + ) |
|
94 | + ); |
|
95 | + } |
|
96 | + return $this->_pretty_name; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * |
|
101 | + * @return int |
|
102 | + */ |
|
103 | + public function count_records_to_migrate() |
|
104 | + { |
|
105 | + if ($this->_records_to_migrate == null) { |
|
106 | + $this->_records_to_migrate = $this->_count_records_to_migrate(); |
|
107 | + } |
|
108 | + return $this->_records_to_migrate; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Counts records already migrated. This should only be implemented by EE_Data_Migration_Script_base and |
|
113 | + * EE_Data_migration_Script_Stage |
|
114 | + * |
|
115 | + * @return int |
|
116 | + */ |
|
117 | + abstract public function count_records_migrated(); |
|
118 | + |
|
119 | + /** |
|
120 | + * Counts the records to migrate; the public version may cache it |
|
121 | + * |
|
122 | + * @return int |
|
123 | + */ |
|
124 | + abstract protected function _count_records_to_migrate(); |
|
125 | + |
|
126 | + /** |
|
127 | + * Returns a string indicating the migration script's status. |
|
128 | + * |
|
129 | + * @return string one of EE_Data_Migration_Manager::status_* constants |
|
130 | + * @throws EE_Error |
|
131 | + */ |
|
132 | + public function get_status() |
|
133 | + { |
|
134 | + if ($this->_status === null) { |
|
135 | + throw new EE_Error( |
|
136 | + sprintf( |
|
137 | + __( |
|
138 | + "Trying to get status of Migration class %s, but it has not been initialized yet. It should be set in the constructor.", |
|
139 | + "event_espresso" |
|
140 | + ), |
|
141 | + get_class($this) |
|
142 | + ) |
|
143 | + ); |
|
144 | + } |
|
145 | + return $this->_status; |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * |
|
150 | + * @param string $status |
|
151 | + * @return void |
|
152 | + */ |
|
153 | + protected function set_status($status) |
|
154 | + { |
|
155 | + $this->_status = $status; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @return array of strings |
|
160 | + */ |
|
161 | + abstract public function get_errors(); |
|
162 | + |
|
163 | + /** |
|
164 | + * Returns the last error that occurred. If none occurred, returns null |
|
165 | + * |
|
166 | + * @return string |
|
167 | + */ |
|
168 | + public function get_last_error() |
|
169 | + { |
|
170 | + $errors = $this->get_errors(); |
|
171 | + if ($errors) { |
|
172 | + return end($errors); |
|
173 | + } else { |
|
174 | + return null; |
|
175 | + } |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Adds an error to the array of errors on this class. |
|
180 | + * |
|
181 | + * @param string $error a string describing the error that will be useful for debugging. Consider including all |
|
182 | + * the data that led to the error, and a stack trace etc. |
|
183 | + * @param boolean $force force the error to be added (because otherwise we have a limit). If forcing and errors are |
|
184 | + * already at their limit, we will purposefully forget the first half |
|
185 | + */ |
|
186 | + public function add_error($error, $force = false) |
|
187 | + { |
|
188 | + if (! defined('EE_DMS_ERROR_LIMIT')) { |
|
189 | + $limit = 50; |
|
190 | + } else { |
|
191 | + $limit = EE_DMS_ERROR_LIMIT; |
|
192 | + } |
|
193 | + // make sure errors is an array, see ticket #8261 |
|
194 | + if (is_string($this->_errors)) { |
|
195 | + $this->_errors = array($this->_errors); |
|
196 | + } |
|
197 | + if (count($this->_errors) >= $limit) { |
|
198 | + if ($force) { |
|
199 | + // get rid of the first half of the errors and any above the limit |
|
200 | + $this->_errors = array_slice($this->_errors, $limit / 2, $limit / 2); |
|
201 | + $this->_errors[] = "Limit reached; removed first half of errors to save space"; |
|
202 | + $this->_errors[] = $error; |
|
203 | + } else { |
|
204 | + $this->_errors[ $limit ] = 'More, but limit reached...'; |
|
205 | + } |
|
206 | + } else { |
|
207 | + $this->_errors[] = $error; |
|
208 | + } |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * Indicates there was a fatal error and the migration cannot possibly continue |
|
213 | + * |
|
214 | + * @return boolean |
|
215 | + */ |
|
216 | + public function is_broken() |
|
217 | + { |
|
218 | + return $this->get_status() == EE_Data_Migration_Manager::status_fatal_error; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * @deprecated since 4.6.12 |
|
223 | + */ |
|
224 | + public function is_borked() |
|
225 | + { |
|
226 | + EE_Error::doing_it_wrong( |
|
227 | + 'is_borked', |
|
228 | + __( |
|
229 | + 'The cheeky "is_borked" method had been replaced with the more proper "is_broken"', |
|
230 | + 'event_espresso' |
|
231 | + ), |
|
232 | + '4.6.12' |
|
233 | + ); |
|
234 | + return $this->is_broken(); |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Sets the status to as having a fatal error |
|
239 | + */ |
|
240 | + public function set_broken() |
|
241 | + { |
|
242 | + $this->_status = EE_Data_Migration_Manager::status_fatal_error; |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * |
|
247 | + * @deprecated since 4.6.12 |
|
248 | + */ |
|
249 | + public function set_borked() |
|
250 | + { |
|
251 | + EE_Error::doing_it_wrong( |
|
252 | + 'is_borked', |
|
253 | + __( |
|
254 | + 'The cheeky "is_borked" method had been replaced with the more proper "is_broken"', |
|
255 | + 'event_espresso' |
|
256 | + ), |
|
257 | + '4.6.12' |
|
258 | + ); |
|
259 | + return $this->set_broken(); |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Checks if this thing believes it is completed |
|
264 | + * |
|
265 | + * @return boolean |
|
266 | + */ |
|
267 | + public function is_completed() |
|
268 | + { |
|
269 | + return $this->get_status() == EE_Data_Migration_Manager::status_completed; |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Checks if the current script has more to do or not (ie, if it's status is CONTINUE) |
|
274 | + * |
|
275 | + * @return boolean |
|
276 | + */ |
|
277 | + public function has_more_to_do() |
|
278 | + { |
|
279 | + return $this->get_status() == EE_Data_Migration_Manager::status_continue; |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * Marks that we believe this migration thing is completed |
|
284 | + */ |
|
285 | + public function set_completed() |
|
286 | + { |
|
287 | + $this->_status = EE_Data_Migration_Manager::status_completed; |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Marks that we think this migration class can continue to migrate |
|
292 | + */ |
|
293 | + public function reattempt() |
|
294 | + { |
|
295 | + $this->_status = EE_Data_Migration_Manager::status_continue; |
|
296 | + $this->add_error(__('Reattempt migration', 'event_espresso'), true); |
|
297 | + } |
|
298 | + |
|
299 | + /** |
|
300 | + * A lot like "__sleep()" magic method in purpose, this is meant for persisting this class' |
|
301 | + * properties to the DB. However, we don't want to use __sleep() because its quite |
|
302 | + * possible that this class is defined when it goes to sleep, but NOT available when it |
|
303 | + * awakes (eg, this class is part of an addon that is deactivated at some point). |
|
304 | + */ |
|
305 | + public function properties_as_array() |
|
306 | + { |
|
307 | + $properties = get_object_vars($this); |
|
308 | + $properties['class'] = get_class($this); |
|
309 | + unset($properties['_migration_script']); |
|
310 | + unset($properties['_table_manager']); |
|
311 | + unset($properties['_table_analysis']); |
|
312 | + return $properties; |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * Sets all of the properties of this script stage to match what's in the array, which is assumed |
|
317 | + * to have been made from the properties_as_array() function. |
|
318 | + * |
|
319 | + * @param array $array_of_properties like what's produced from properties_as_array() method |
|
320 | + */ |
|
321 | + abstract public function instantiate_from_array_of_properties($array_of_properties); |
|
322 | + |
|
323 | + /** |
|
324 | + * Convenience method for showing a database insertion error |
|
325 | + * |
|
326 | + * @param string $old_table |
|
327 | + * @param array $old_row_as_array |
|
328 | + * @param string $new_table |
|
329 | + * @param array $new_row_as_array columns=>values like used in wpdb->insert |
|
330 | + * @param array $data_types numerically indexed |
|
331 | + * @return string |
|
332 | + */ |
|
333 | + protected function _create_error_message_for_db_insertion( |
|
334 | + $old_table, |
|
335 | + $old_row_as_array, |
|
336 | + $new_table, |
|
337 | + $new_row_as_array, |
|
338 | + $data_types |
|
339 | + ) { |
|
340 | + global $wpdb; |
|
341 | + $old_columns_and_values_for_string = array(); |
|
342 | + foreach ($old_row_as_array as $column => $value) { |
|
343 | + $old_columns_and_values_for_string[] = "$column => $value"; |
|
344 | + } |
|
345 | + $new_columns_and_values_for_string = array(); |
|
346 | + $count = 0; |
|
347 | + foreach ($new_row_as_array as $column => $value) { |
|
348 | + $new_columns_and_values_for_string[] = " $column => $value (" . $data_types[ $count++ ] . ")"; |
|
349 | + } |
|
350 | + return sprintf( |
|
351 | + __( |
|
352 | + 'Received error "%6$s" inserting row %5$s %1$s %5$s into table %2$s.%5$s Data used was %5$s %3$s %5$s from table %4$s.', |
|
353 | + 'event_espresso' |
|
354 | + ), |
|
355 | + implode(", ", $new_columns_and_values_for_string), |
|
356 | + $new_table, |
|
357 | + implode(", ", $old_columns_and_values_for_string), |
|
358 | + $old_table, |
|
359 | + '<br/>', |
|
360 | + $wpdb->last_error |
|
361 | + ); |
|
362 | + } |
|
363 | + |
|
364 | + |
|
365 | + /** |
|
366 | + * Same as json_encode, just avoids putting |
|
367 | + * serialized arrays into the http build query, as that would |
|
368 | + * |
|
369 | + * @param array $array_of_data |
|
370 | + * @return string |
|
371 | + */ |
|
372 | + protected function _json_encode($array_of_data) |
|
373 | + { |
|
374 | + // we'd rather NOT serialize the transaction details |
|
375 | + $fields_to_include = array(); |
|
376 | + foreach ($array_of_data as $name => $value) { |
|
377 | + $unserialized_data = @unserialize($value); |
|
378 | + if ($unserialized_data === false) { |
|
379 | + $fields_to_include[ $name ] = $value; |
|
380 | + } |
|
381 | + } |
|
382 | + return wp_json_encode($fields_to_include); |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * Gets the table manager (or throws an exception if it cannot be retrieved) |
|
387 | + * |
|
388 | + * @return TableManager |
|
389 | + * @throws EE_Error |
|
390 | + */ |
|
391 | + protected function _get_table_manager() |
|
392 | + { |
|
393 | + if ($this->_table_manager instanceof TableManager) { |
|
394 | + return $this->_table_manager; |
|
395 | + } else { |
|
396 | + throw new EE_Error( |
|
397 | + sprintf( |
|
398 | + __('Table manager on migration class %1$s is not set properly.', 'event_espresso'), |
|
399 | + get_class($this) |
|
400 | + ) |
|
401 | + ); |
|
402 | + } |
|
403 | + } |
|
404 | + |
|
405 | + /** |
|
406 | + * Gets the injected table analyzer, or throws an exception |
|
407 | + * |
|
408 | + * @return TableAnalysis |
|
409 | + * @throws EE_Error |
|
410 | + */ |
|
411 | + protected function _get_table_analysis() |
|
412 | + { |
|
413 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
414 | + return $this->_table_analysis; |
|
415 | + } else { |
|
416 | + throw new EE_Error( |
|
417 | + sprintf( |
|
418 | + __('Table analysis class on migration class %1$s is not set properly.', 'event_espresso'), |
|
419 | + get_class($this) |
|
420 | + ) |
|
421 | + ); |
|
422 | + } |
|
423 | + } |
|
424 | 424 | } |
@@ -11,77 +11,77 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_DMS_4_8_0_event_subtotals extends EE_Data_Migration_Script_Stage_Table |
13 | 13 | { |
14 | - public function __construct() |
|
15 | - { |
|
16 | - global $wpdb; |
|
17 | - $this->_old_table = $wpdb->prefix . 'esp_line_item'; |
|
18 | - $this->_extra_where_sql = ' WHERE LIN_type="sub-total" AND LIN_code="pre-tax-subtotal"'; |
|
19 | - $this->_pretty_name = __('Event Sub-total line items', 'event_espresso'); |
|
20 | - parent::__construct(); |
|
21 | - } |
|
22 | - protected function _migrate_old_row($line_item_row) |
|
23 | - { |
|
24 | - global $wpdb; |
|
25 | - // what event is this line item for? this can be found by looking at its transaction's registration's EVT_ID |
|
26 | - $event_id = $wpdb->get_var($wpdb->prepare('SELECT EVT_ID FROM ' . $wpdb->prefix . 'esp_registration WHERE TXN_ID=%d LIMIT 1', $line_item_row['TXN_ID'])); |
|
27 | - $new_line_item_data = array( |
|
28 | - 'LIN_code' => 'event-' . $event_id, |
|
29 | - 'TXN_ID' => $line_item_row['TXN_ID'], |
|
30 | - 'LIN_name' => __('Event', 'event_espresso'), |
|
31 | - 'LIN_desc' => $line_item_row['LIN_desc'], |
|
32 | - 'LIN_unit_price' => $line_item_row['LIN_unit_price'], |
|
33 | - 'LIN_percent' => $line_item_row['LIN_percent'], |
|
34 | - 'LIN_is_taxable' => $line_item_row['LIN_is_taxable'], |
|
35 | - 'LIN_order' => $line_item_row['LIN_order'], |
|
36 | - 'LIN_total' => $line_item_row['LIN_total'], |
|
37 | - 'LIN_quantity' => $line_item_row['LIN_quantity'], |
|
38 | - 'LIN_parent' => $line_item_row['LIN_ID'], |
|
39 | - 'LIN_type' => 'sub-total', |
|
40 | - 'OBJ_type' => 'Event', |
|
41 | - 'OBJ_ID' => $event_id, |
|
42 | - ); |
|
43 | - $new_line_item_datatypes = array( |
|
44 | - '%s',// LIN_code |
|
45 | - '%d',// TXN_ID |
|
46 | - '%s',// LIN_name |
|
47 | - '%s',// LIN_desc |
|
48 | - '%f',// LIN_unit_price |
|
49 | - '%f',// LIN_percent |
|
50 | - '%d',// LIN_is_taxable |
|
51 | - '%d',// LIN_order |
|
52 | - '%f',// LIN_total |
|
53 | - '%d',// LIN_quantity |
|
54 | - '%d',// LIN_parent |
|
55 | - '%s',// LIN_type |
|
56 | - '%s',// OBJ_type |
|
57 | - '%d',// OBJ_ID |
|
58 | - ); |
|
59 | - // insert the new event subtotal line item, pointing to this line item |
|
60 | - $success = $wpdb->insert($this->_old_table, $new_line_item_data, $new_line_item_datatypes); |
|
61 | - if (! $success) { |
|
62 | - $this->add_error($this->_create_error_message_for_db_insertion($this->_old_table, $line_item_row, $this->_old_table, $new_line_item_data, $new_line_item_datatypes)); |
|
63 | - } |
|
64 | - $new_line_item_id = $wpdb->insert_id; |
|
65 | - $this->get_migration_script()->set_mapping($this->_old_table, $line_item_row['LIN_ID'], $this->_old_table, $new_line_item_id); |
|
66 | - $query = $wpdb->prepare( |
|
67 | - "UPDATE {$this->_old_table} SET LIN_parent=%d WHERE LIN_parent = %d AND LIN_ID != %d LIMIT 100", |
|
68 | - $new_line_item_id, |
|
69 | - $line_item_row['LIN_ID'], |
|
70 | - $new_line_item_id |
|
71 | - ); |
|
72 | - $success = $wpdb->query($query); |
|
73 | - if ($success === false) { |
|
74 | - $this->add_error( |
|
75 | - sprintf( |
|
76 | - __('Error updating rows to new event subtotal %1$s from %2$s. Error was: %3$s, while using query %4$s which had a result of %5$s', 'event_espresso'), |
|
77 | - $new_line_item_id, |
|
78 | - $line_item_row['LIN_ID'], |
|
79 | - $wpdb->last_error, |
|
80 | - $query, |
|
81 | - $success |
|
82 | - ) |
|
83 | - ); |
|
84 | - } |
|
85 | - return 1; |
|
86 | - } |
|
14 | + public function __construct() |
|
15 | + { |
|
16 | + global $wpdb; |
|
17 | + $this->_old_table = $wpdb->prefix . 'esp_line_item'; |
|
18 | + $this->_extra_where_sql = ' WHERE LIN_type="sub-total" AND LIN_code="pre-tax-subtotal"'; |
|
19 | + $this->_pretty_name = __('Event Sub-total line items', 'event_espresso'); |
|
20 | + parent::__construct(); |
|
21 | + } |
|
22 | + protected function _migrate_old_row($line_item_row) |
|
23 | + { |
|
24 | + global $wpdb; |
|
25 | + // what event is this line item for? this can be found by looking at its transaction's registration's EVT_ID |
|
26 | + $event_id = $wpdb->get_var($wpdb->prepare('SELECT EVT_ID FROM ' . $wpdb->prefix . 'esp_registration WHERE TXN_ID=%d LIMIT 1', $line_item_row['TXN_ID'])); |
|
27 | + $new_line_item_data = array( |
|
28 | + 'LIN_code' => 'event-' . $event_id, |
|
29 | + 'TXN_ID' => $line_item_row['TXN_ID'], |
|
30 | + 'LIN_name' => __('Event', 'event_espresso'), |
|
31 | + 'LIN_desc' => $line_item_row['LIN_desc'], |
|
32 | + 'LIN_unit_price' => $line_item_row['LIN_unit_price'], |
|
33 | + 'LIN_percent' => $line_item_row['LIN_percent'], |
|
34 | + 'LIN_is_taxable' => $line_item_row['LIN_is_taxable'], |
|
35 | + 'LIN_order' => $line_item_row['LIN_order'], |
|
36 | + 'LIN_total' => $line_item_row['LIN_total'], |
|
37 | + 'LIN_quantity' => $line_item_row['LIN_quantity'], |
|
38 | + 'LIN_parent' => $line_item_row['LIN_ID'], |
|
39 | + 'LIN_type' => 'sub-total', |
|
40 | + 'OBJ_type' => 'Event', |
|
41 | + 'OBJ_ID' => $event_id, |
|
42 | + ); |
|
43 | + $new_line_item_datatypes = array( |
|
44 | + '%s',// LIN_code |
|
45 | + '%d',// TXN_ID |
|
46 | + '%s',// LIN_name |
|
47 | + '%s',// LIN_desc |
|
48 | + '%f',// LIN_unit_price |
|
49 | + '%f',// LIN_percent |
|
50 | + '%d',// LIN_is_taxable |
|
51 | + '%d',// LIN_order |
|
52 | + '%f',// LIN_total |
|
53 | + '%d',// LIN_quantity |
|
54 | + '%d',// LIN_parent |
|
55 | + '%s',// LIN_type |
|
56 | + '%s',// OBJ_type |
|
57 | + '%d',// OBJ_ID |
|
58 | + ); |
|
59 | + // insert the new event subtotal line item, pointing to this line item |
|
60 | + $success = $wpdb->insert($this->_old_table, $new_line_item_data, $new_line_item_datatypes); |
|
61 | + if (! $success) { |
|
62 | + $this->add_error($this->_create_error_message_for_db_insertion($this->_old_table, $line_item_row, $this->_old_table, $new_line_item_data, $new_line_item_datatypes)); |
|
63 | + } |
|
64 | + $new_line_item_id = $wpdb->insert_id; |
|
65 | + $this->get_migration_script()->set_mapping($this->_old_table, $line_item_row['LIN_ID'], $this->_old_table, $new_line_item_id); |
|
66 | + $query = $wpdb->prepare( |
|
67 | + "UPDATE {$this->_old_table} SET LIN_parent=%d WHERE LIN_parent = %d AND LIN_ID != %d LIMIT 100", |
|
68 | + $new_line_item_id, |
|
69 | + $line_item_row['LIN_ID'], |
|
70 | + $new_line_item_id |
|
71 | + ); |
|
72 | + $success = $wpdb->query($query); |
|
73 | + if ($success === false) { |
|
74 | + $this->add_error( |
|
75 | + sprintf( |
|
76 | + __('Error updating rows to new event subtotal %1$s from %2$s. Error was: %3$s, while using query %4$s which had a result of %5$s', 'event_espresso'), |
|
77 | + $new_line_item_id, |
|
78 | + $line_item_row['LIN_ID'], |
|
79 | + $wpdb->last_error, |
|
80 | + $query, |
|
81 | + $success |
|
82 | + ) |
|
83 | + ); |
|
84 | + } |
|
85 | + return 1; |
|
86 | + } |
|
87 | 87 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | public function __construct() |
15 | 15 | { |
16 | 16 | global $wpdb; |
17 | - $this->_old_table = $wpdb->prefix . 'esp_line_item'; |
|
17 | + $this->_old_table = $wpdb->prefix.'esp_line_item'; |
|
18 | 18 | $this->_extra_where_sql = ' WHERE LIN_type="sub-total" AND LIN_code="pre-tax-subtotal"'; |
19 | 19 | $this->_pretty_name = __('Event Sub-total line items', 'event_espresso'); |
20 | 20 | parent::__construct(); |
@@ -23,9 +23,9 @@ discard block |
||
23 | 23 | { |
24 | 24 | global $wpdb; |
25 | 25 | // what event is this line item for? this can be found by looking at its transaction's registration's EVT_ID |
26 | - $event_id = $wpdb->get_var($wpdb->prepare('SELECT EVT_ID FROM ' . $wpdb->prefix . 'esp_registration WHERE TXN_ID=%d LIMIT 1', $line_item_row['TXN_ID'])); |
|
26 | + $event_id = $wpdb->get_var($wpdb->prepare('SELECT EVT_ID FROM '.$wpdb->prefix.'esp_registration WHERE TXN_ID=%d LIMIT 1', $line_item_row['TXN_ID'])); |
|
27 | 27 | $new_line_item_data = array( |
28 | - 'LIN_code' => 'event-' . $event_id, |
|
28 | + 'LIN_code' => 'event-'.$event_id, |
|
29 | 29 | 'TXN_ID' => $line_item_row['TXN_ID'], |
30 | 30 | 'LIN_name' => __('Event', 'event_espresso'), |
31 | 31 | 'LIN_desc' => $line_item_row['LIN_desc'], |
@@ -41,24 +41,24 @@ discard block |
||
41 | 41 | 'OBJ_ID' => $event_id, |
42 | 42 | ); |
43 | 43 | $new_line_item_datatypes = array( |
44 | - '%s',// LIN_code |
|
45 | - '%d',// TXN_ID |
|
46 | - '%s',// LIN_name |
|
47 | - '%s',// LIN_desc |
|
48 | - '%f',// LIN_unit_price |
|
49 | - '%f',// LIN_percent |
|
50 | - '%d',// LIN_is_taxable |
|
51 | - '%d',// LIN_order |
|
52 | - '%f',// LIN_total |
|
53 | - '%d',// LIN_quantity |
|
54 | - '%d',// LIN_parent |
|
55 | - '%s',// LIN_type |
|
56 | - '%s',// OBJ_type |
|
57 | - '%d',// OBJ_ID |
|
44 | + '%s', // LIN_code |
|
45 | + '%d', // TXN_ID |
|
46 | + '%s', // LIN_name |
|
47 | + '%s', // LIN_desc |
|
48 | + '%f', // LIN_unit_price |
|
49 | + '%f', // LIN_percent |
|
50 | + '%d', // LIN_is_taxable |
|
51 | + '%d', // LIN_order |
|
52 | + '%f', // LIN_total |
|
53 | + '%d', // LIN_quantity |
|
54 | + '%d', // LIN_parent |
|
55 | + '%s', // LIN_type |
|
56 | + '%s', // OBJ_type |
|
57 | + '%d', // OBJ_ID |
|
58 | 58 | ); |
59 | 59 | // insert the new event subtotal line item, pointing to this line item |
60 | 60 | $success = $wpdb->insert($this->_old_table, $new_line_item_data, $new_line_item_datatypes); |
61 | - if (! $success) { |
|
61 | + if ( ! $success) { |
|
62 | 62 | $this->add_error($this->_create_error_message_for_db_insertion($this->_old_table, $line_item_row, $this->_old_table, $new_line_item_data, $new_line_item_datatypes)); |
63 | 63 | } |
64 | 64 | $new_line_item_id = $wpdb->insert_id; |