@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 3 | - exit( 'No direct script access allowed' ); |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | + exit('No direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -12,37 +12,37 @@ discard block |
||
| 12 | 12 | * @author Mike Nelson |
| 13 | 13 | * |
| 14 | 14 | */ |
| 15 | -class EE_DMS_4_6_0_payments extends EE_Data_Migration_Script_Stage_Table{ |
|
| 15 | +class EE_DMS_4_6_0_payments extends EE_Data_Migration_Script_Stage_Table { |
|
| 16 | 16 | protected $_payment_method_table; |
| 17 | - function __construct(){ |
|
| 17 | + function __construct() { |
|
| 18 | 18 | global $wpdb; |
| 19 | - $this->_old_table = $wpdb->prefix . 'esp_payment'; |
|
| 20 | - $this->_payment_method_table = $wpdb->prefix . 'esp_payment_method'; |
|
| 19 | + $this->_old_table = $wpdb->prefix.'esp_payment'; |
|
| 20 | + $this->_payment_method_table = $wpdb->prefix.'esp_payment_method'; |
|
| 21 | 21 | $this->_pretty_name = __('Payment-Payment Method Relations', 'event_espresso'); |
| 22 | 22 | parent::__construct(); |
| 23 | 23 | } |
| 24 | - protected function _migrate_old_row( $payment_row ) { |
|
| 24 | + protected function _migrate_old_row($payment_row) { |
|
| 25 | 25 | global $wpdb; |
| 26 | 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 ) ) ); |
|
| 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 | 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' ); |
|
| 38 | - $success = $wpdb->update( $this->_old_table, |
|
| 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($this->_old_table, |
|
| 39 | 39 | $new_values, |
| 40 | 40 | $wheres, |
| 41 | 41 | $new_value_datatypes, |
| 42 | 42 | $where_datatypes |
| 43 | 43 | ); |
| 44 | - if( ! $success ){ |
|
| 45 | - $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 ) ) ); |
|
| 44 | + if ( ! $success) { |
|
| 45 | + $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))); |
|
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | /** |
@@ -60,11 +60,11 @@ discard block |
||
| 60 | 60 | * @param int $id |
| 61 | 61 | * @return string |
| 62 | 62 | */ |
| 63 | - protected function _get_payment_method_id_by_gateway_name( $gateway_name, $old_pay_method_column ){ |
|
| 63 | + protected function _get_payment_method_id_by_gateway_name($gateway_name, $old_pay_method_column) { |
|
| 64 | 64 | global $wpdb; |
| 65 | 65 | //convert from old known PAY_method values to their corresponding |
| 66 | 66 | //PMD_type or default PMD_name |
| 67 | - switch( $old_pay_method_column ) { |
|
| 67 | + switch ($old_pay_method_column) { |
|
| 68 | 68 | case 'PP': |
| 69 | 69 | $pmd_type = 'Paypal_Standard'; |
| 70 | 70 | break; |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | default: |
| 93 | 93 | $pmd_type = $gateway_name; |
| 94 | 94 | } |
| 95 | - $pmd_name = str_replace( "_", " ", $pmd_type ); |
|
| 96 | - 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 ) ); |
|
| 95 | + $pmd_name = str_replace("_", " ", $pmd_type); |
|
| 96 | + 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)); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 3 | - exit( 'No direct script access allowed' ); |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | + exit('No direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -12,38 +12,38 @@ discard block |
||
| 12 | 12 | * @author Mike Nelson |
| 13 | 13 | * |
| 14 | 14 | */ |
| 15 | -class EE_DMS_4_6_0_transactions extends EE_Data_Migration_Script_Stage_Table{ |
|
| 15 | +class EE_DMS_4_6_0_transactions extends EE_Data_Migration_Script_Stage_Table { |
|
| 16 | 16 | protected $_transaction_table; |
| 17 | 17 | protected $_payment_method_table; |
| 18 | - function __construct(){ |
|
| 18 | + function __construct() { |
|
| 19 | 19 | global $wpdb; |
| 20 | - $this->_old_table = $wpdb->prefix . 'esp_extra_meta'; |
|
| 21 | - $this->_transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
| 22 | - $this->_payment_method_table = $wpdb->prefix . 'esp_payment_method'; |
|
| 20 | + $this->_old_table = $wpdb->prefix.'esp_extra_meta'; |
|
| 21 | + $this->_transaction_table = $wpdb->prefix.'esp_transaction'; |
|
| 22 | + $this->_payment_method_table = $wpdb->prefix.'esp_payment_method'; |
|
| 23 | 23 | $this->_pretty_name = __('Transaction Payment Method Relations', 'event_espresso'); |
| 24 | 24 | $this->_extra_where_sql = "WHERE EXM_key = 'gateway' AND EXM_type = 'Transaction'"; |
| 25 | 25 | parent::__construct(); |
| 26 | 26 | } |
| 27 | - protected function _migrate_old_row( $extra_meta_row ) { |
|
| 27 | + protected function _migrate_old_row($extra_meta_row) { |
|
| 28 | 28 | global $wpdb; |
| 29 | 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 ) ) ); |
|
| 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 | 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' ); |
|
| 39 | - $success = $wpdb->update( $this->_transaction_table, |
|
| 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($this->_transaction_table, |
|
| 40 | 40 | $new_values, |
| 41 | 41 | $wheres, |
| 42 | 42 | $new_value_datatypes, |
| 43 | 43 | $where_datatypes |
| 44 | 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->_transaction_table, $this->_json_encode( $wheres ) ) ); |
|
| 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->_transaction_table, $this->_json_encode($wheres))); |
|
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | /** |
@@ -52,9 +52,9 @@ discard block |
||
| 52 | 52 | * @param int $id |
| 53 | 53 | * @return string |
| 54 | 54 | */ |
| 55 | - protected function _get_payment_method_id_by_gateway_name( $gateway_name ){ |
|
| 55 | + protected function _get_payment_method_id_by_gateway_name($gateway_name) { |
|
| 56 | 56 | global $wpdb; |
| 57 | - return $wpdb->get_var( $wpdb->prepare( "SELECT PMD_ID FROM " . $wpdb->prefix . "esp_payment_method WHERE PMD_type = %s", $gateway_name ) ); |
|
| 57 | + return $wpdb->get_var($wpdb->prepare("SELECT PMD_ID FROM ".$wpdb->prefix."esp_payment_method WHERE PMD_type = %s", $gateway_name)); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 3 | - exit( 'No direct script access allowed' ); |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | + exit('No direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -12,20 +12,20 @@ discard block |
||
| 12 | 12 | * @author Brent Christensen |
| 13 | 13 | * |
| 14 | 14 | */ |
| 15 | -class EE_DMS_4_7_0_Add_Taxes_To_REG_Final_Price extends EE_Data_Migration_Script_Stage_Table{ |
|
| 15 | +class EE_DMS_4_7_0_Add_Taxes_To_REG_Final_Price extends EE_Data_Migration_Script_Stage_Table { |
|
| 16 | 16 | |
| 17 | 17 | protected $_ticket_table; |
| 18 | 18 | |
| 19 | 19 | protected $_line_item_table; |
| 20 | 20 | |
| 21 | - function __construct(){ |
|
| 21 | + function __construct() { |
|
| 22 | 22 | /** @type WPDB $wpdb */ |
| 23 | 23 | global $wpdb; |
| 24 | - $this->_pretty_name = __( 'Registration Final Price Tax Calculations', 'event_espresso' ); |
|
| 24 | + $this->_pretty_name = __('Registration Final Price Tax Calculations', 'event_espresso'); |
|
| 25 | 25 | // define tables |
| 26 | - $this->_old_table = $wpdb->prefix . 'esp_registration'; |
|
| 27 | - $this->_ticket_table = $wpdb->prefix . 'esp_ticket'; |
|
| 28 | - $this->_line_item_table = $wpdb->prefix . 'esp_line_item'; |
|
| 26 | + $this->_old_table = $wpdb->prefix.'esp_registration'; |
|
| 27 | + $this->_ticket_table = $wpdb->prefix.'esp_ticket'; |
|
| 28 | + $this->_line_item_table = $wpdb->prefix.'esp_line_item'; |
|
| 29 | 29 | parent::__construct(); |
| 30 | 30 | } |
| 31 | 31 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | global $wpdb; |
| 56 | 56 | $SQL = "SELECT count( reg.REG_ID ) "; |
| 57 | 57 | $SQL .= $this->_get_rest_of_sql_for_query(); |
| 58 | - $count = $wpdb->get_var( $SQL ); |
|
| 58 | + $count = $wpdb->get_var($SQL); |
|
| 59 | 59 | return $count; |
| 60 | 60 | } |
| 61 | 61 | |
@@ -67,13 +67,13 @@ discard block |
||
| 67 | 67 | * @param int $limit |
| 68 | 68 | * @return array of arrays like $wpdb->get_results($sql, ARRAY_A) |
| 69 | 69 | */ |
| 70 | - protected function _get_rows( $limit ) { |
|
| 70 | + protected function _get_rows($limit) { |
|
| 71 | 71 | /** @type WPDB $wpdb */ |
| 72 | 72 | global $wpdb; |
| 73 | 73 | $start_at_record = $this->count_records_migrated(); |
| 74 | 74 | $SQL = "SELECT reg.REG_ID, reg.REG_final_price, line.LIN_ID "; |
| 75 | 75 | $SQL .= $this->_get_rest_of_sql_for_query(); |
| 76 | - $SQL .= $wpdb->prepare( "LIMIT %d, %d", $start_at_record, $limit ); |
|
| 76 | + $SQL .= $wpdb->prepare("LIMIT %d, %d", $start_at_record, $limit); |
|
| 77 | 77 | |
| 78 | 78 | // produces something like: |
| 79 | 79 | /* |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | LIMIT 1, 50 |
| 94 | 94 | */ |
| 95 | 95 | |
| 96 | - return $wpdb->get_results( $SQL, ARRAY_A ); |
|
| 96 | + return $wpdb->get_results($SQL, ARRAY_A); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | |
@@ -102,38 +102,38 @@ discard block |
||
| 102 | 102 | * @param array $row |
| 103 | 103 | * @return void |
| 104 | 104 | */ |
| 105 | - protected function _migrate_old_row( $row ) { |
|
| 105 | + protected function _migrate_old_row($row) { |
|
| 106 | 106 | /** @type WPDB $wpdb */ |
| 107 | 107 | global $wpdb; |
| 108 | 108 | // ensure all required values are present |
| 109 | - if ( ! isset( $row[ 'REG_ID' ], $row[ 'REG_final_price' ], $row[ 'LIN_ID' ] )) { |
|
| 109 | + if ( ! isset($row['REG_ID'], $row['REG_final_price'], $row['LIN_ID'])) { |
|
| 110 | 110 | $this->add_error( |
| 111 | 111 | sprintf( |
| 112 | - __( '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' ), |
|
| 112 | + __('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'), |
|
| 113 | 113 | '<br />', |
| 114 | - isset( $row[ 'REG_ID' ] ) ? $row[ 'REG_ID' ] : '', |
|
| 115 | - isset( $row[ 'REG_final_price' ] ) ? $row[ 'REG_final_price' ] : '', |
|
| 116 | - isset( $row[ 'LIN_ID' ] ) ? $row[ 'LIN_ID' ] : '', |
|
| 114 | + isset($row['REG_ID']) ? $row['REG_ID'] : '', |
|
| 115 | + isset($row['REG_final_price']) ? $row['REG_final_price'] : '', |
|
| 116 | + isset($row['LIN_ID']) ? $row['LIN_ID'] : '', |
|
| 117 | 117 | $wpdb->last_error |
| 118 | 118 | ) |
| 119 | 119 | ); |
| 120 | 120 | return; |
| 121 | 121 | } |
| 122 | 122 | // get tax subtotal |
| 123 | - $tax_subtotal_line_item_ID = $this->_get_line_item_ID_for_tax_subtotal( $row['LIN_ID'] ); |
|
| 124 | - if ( ! $tax_subtotal_line_item_ID ) { |
|
| 123 | + $tax_subtotal_line_item_ID = $this->_get_line_item_ID_for_tax_subtotal($row['LIN_ID']); |
|
| 124 | + if ( ! $tax_subtotal_line_item_ID) { |
|
| 125 | 125 | $this->add_error( |
| 126 | 126 | sprintf( |
| 127 | - __( 'Invalid line item ID returned. Error: "%1$s"', 'event_espresso' ), |
|
| 127 | + __('Invalid line item ID returned. Error: "%1$s"', 'event_espresso'), |
|
| 128 | 128 | $wpdb->last_error |
| 129 | 129 | ) |
| 130 | 130 | ); |
| 131 | 131 | return; |
| 132 | 132 | } |
| 133 | 133 | // now get taxes |
| 134 | - $taxes = $this->_get_tax_amounts( $tax_subtotal_line_item_ID ); |
|
| 134 | + $taxes = $this->_get_tax_amounts($tax_subtotal_line_item_ID); |
|
| 135 | 135 | // apply taxes to registration final price |
| 136 | - $this->_apply_taxes( $row[ 'REG_ID' ], $row[ 'REG_final_price' ], $taxes ); |
|
| 136 | + $this->_apply_taxes($row['REG_ID'], $row['REG_final_price'], $taxes); |
|
| 137 | 137 | |
| 138 | 138 | } |
| 139 | 139 | |
@@ -145,14 +145,14 @@ discard block |
||
| 145 | 145 | * @param int $LIN_ID |
| 146 | 146 | * @return int |
| 147 | 147 | */ |
| 148 | - protected function _get_line_item_ID_for_tax_subtotal( $LIN_ID ) { |
|
| 148 | + protected function _get_line_item_ID_for_tax_subtotal($LIN_ID) { |
|
| 149 | 149 | /** @type WPDB $wpdb */ |
| 150 | 150 | global $wpdb; |
| 151 | 151 | $SQL = "SELECT LIN_ID "; |
| 152 | 152 | $SQL .= "FROM {$this->_line_item_table} "; |
| 153 | 153 | $SQL .= "WHERE LIN_parent = %d "; |
| 154 | 154 | $SQL .= "AND LIN_code = 'taxes'"; |
| 155 | - return $wpdb->get_var( $wpdb->prepare( $SQL, $LIN_ID ) ); |
|
| 155 | + return $wpdb->get_var($wpdb->prepare($SQL, $LIN_ID)); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | |
@@ -163,13 +163,13 @@ discard block |
||
| 163 | 163 | * @param int $LIN_ID |
| 164 | 164 | * @return array |
| 165 | 165 | */ |
| 166 | - protected function _get_tax_amounts( $LIN_ID ) { |
|
| 166 | + protected function _get_tax_amounts($LIN_ID) { |
|
| 167 | 167 | /** @type WPDB $wpdb */ |
| 168 | 168 | global $wpdb; |
| 169 | 169 | $SQL = "SELECT LIN_percent "; |
| 170 | 170 | $SQL .= "FROM {$this->_line_item_table} "; |
| 171 | 171 | $SQL .= "WHERE LIN_parent = %d"; |
| 172 | - return $wpdb->get_results( $wpdb->prepare( $SQL, $LIN_ID ), OBJECT_K ); |
|
| 172 | + return $wpdb->get_results($wpdb->prepare($SQL, $LIN_ID), OBJECT_K); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | |
@@ -182,14 +182,14 @@ discard block |
||
| 182 | 182 | * @param array $taxes |
| 183 | 183 | * @return void |
| 184 | 184 | */ |
| 185 | - protected function _apply_taxes( $REG_ID = 0, $final_price = 0.00, $taxes = array() ) { |
|
| 186 | - if ( is_array( $taxes ) && ! empty( $taxes ) ) { |
|
| 185 | + protected function _apply_taxes($REG_ID = 0, $final_price = 0.00, $taxes = array()) { |
|
| 186 | + if (is_array($taxes) && ! empty($taxes)) { |
|
| 187 | 187 | $total_taxes = 0; |
| 188 | - foreach ( $taxes as $tax ) { |
|
| 189 | - $total_taxes += $final_price * ( $tax->LIN_percent / 100 ); |
|
| 188 | + foreach ($taxes as $tax) { |
|
| 189 | + $total_taxes += $final_price * ($tax->LIN_percent / 100); |
|
| 190 | 190 | } |
| 191 | 191 | $final_price += $total_taxes; |
| 192 | - $this->_update_registration_final_price( $REG_ID, $final_price ); |
|
| 192 | + $this->_update_registration_final_price($REG_ID, $final_price); |
|
| 193 | 193 | } |
| 194 | 194 | } |
| 195 | 195 | |
@@ -202,20 +202,20 @@ discard block |
||
| 202 | 202 | * @param float $REG_final_price |
| 203 | 203 | * @return void |
| 204 | 204 | */ |
| 205 | - protected function _update_registration_final_price( $REG_ID = 0, $REG_final_price = 0.00 ) { |
|
| 205 | + protected function _update_registration_final_price($REG_ID = 0, $REG_final_price = 0.00) { |
|
| 206 | 206 | /** @type WPDB $wpdb */ |
| 207 | 207 | global $wpdb; |
| 208 | 208 | $success = $wpdb->update( |
| 209 | 209 | $this->_old_table, |
| 210 | - array( 'REG_final_price' => $REG_final_price ), // data |
|
| 211 | - array( 'REG_ID' => $REG_ID ), // where |
|
| 212 | - array( '%f' ), // data format |
|
| 213 | - array( '%d' ) // where format |
|
| 210 | + array('REG_final_price' => $REG_final_price), // data |
|
| 211 | + array('REG_ID' => $REG_ID), // where |
|
| 212 | + array('%f'), // data format |
|
| 213 | + array('%d') // where format |
|
| 214 | 214 | ); |
| 215 | - if ( $success === false ) { |
|
| 215 | + if ($success === false) { |
|
| 216 | 216 | $this->add_error( |
| 217 | 217 | sprintf( |
| 218 | - __( 'Could not update registration final price value for registration ID=%1$d because "%2$s"', 'event_espresso' ), |
|
| 218 | + __('Could not update registration final price value for registration ID=%1$d because "%2$s"', 'event_espresso'), |
|
| 219 | 219 | $REG_ID, |
| 220 | 220 | $wpdb->last_error |
| 221 | 221 | ) |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 3 | - exit( 'No direct script access allowed' ); |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | + exit('No direct script access allowed'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | * @author Brent Christensen |
| 13 | 13 | * |
| 14 | 14 | */ |
| 15 | -class EE_DMS_4_7_0_Registration_Payments extends EE_Data_Migration_Script_Stage_Table{ |
|
| 15 | +class EE_DMS_4_7_0_Registration_Payments extends EE_Data_Migration_Script_Stage_Table { |
|
| 16 | 16 | |
| 17 | 17 | protected $_payment_table; |
| 18 | 18 | |
@@ -20,15 +20,15 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | protected $_registration_payment_table; |
| 22 | 22 | |
| 23 | - function __construct(){ |
|
| 23 | + function __construct() { |
|
| 24 | 24 | /** @type WPDB $wpdb */ |
| 25 | 25 | global $wpdb; |
| 26 | - $this->_pretty_name = __( 'Registration Payment Record Generation', 'event_espresso' ); |
|
| 26 | + $this->_pretty_name = __('Registration Payment Record Generation', 'event_espresso'); |
|
| 27 | 27 | // define tables |
| 28 | - $this->_old_table = $wpdb->prefix . 'esp_transaction'; |
|
| 29 | - $this->_payment_table = $wpdb->prefix . 'esp_payment'; |
|
| 30 | - $this->_registration_table = $wpdb->prefix . 'esp_registration'; |
|
| 31 | - $this->_registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
| 28 | + $this->_old_table = $wpdb->prefix.'esp_transaction'; |
|
| 29 | + $this->_payment_table = $wpdb->prefix.'esp_payment'; |
|
| 30 | + $this->_registration_table = $wpdb->prefix.'esp_registration'; |
|
| 31 | + $this->_registration_payment_table = $wpdb->prefix.'esp_registration_payment'; |
|
| 32 | 32 | // build SQL WHERE clauses |
| 33 | 33 | $this->_extra_where_sql = "WHERE STS_ID IN ( 'TIN', 'TCM' ) AND TXN_Total != '0.000'"; |
| 34 | 34 | parent::__construct(); |
@@ -40,14 +40,14 @@ discard block |
||
| 40 | 40 | * @param array $transaction |
| 41 | 41 | * @return void |
| 42 | 42 | */ |
| 43 | - protected function _migrate_old_row( $transaction ) { |
|
| 43 | + protected function _migrate_old_row($transaction) { |
|
| 44 | 44 | /** @type WPDB $wpdb */ |
| 45 | 45 | global $wpdb; |
| 46 | - $TXN_ID = absint( $transaction[ 'TXN_ID' ] ); |
|
| 47 | - if ( ! $TXN_ID ) { |
|
| 46 | + $TXN_ID = absint($transaction['TXN_ID']); |
|
| 47 | + if ( ! $TXN_ID) { |
|
| 48 | 48 | $this->add_error( |
| 49 | 49 | sprintf( |
| 50 | - __( 'Invalid transaction with ID=%1$d. Error: "%2$s"', 'event_espresso' ), |
|
| 50 | + __('Invalid transaction with ID=%1$d. Error: "%2$s"', 'event_espresso'), |
|
| 51 | 51 | $TXN_ID, |
| 52 | 52 | $wpdb->last_error |
| 53 | 53 | ) |
@@ -55,19 +55,19 @@ discard block |
||
| 55 | 55 | return; |
| 56 | 56 | } |
| 57 | 57 | // get all payments for the TXN |
| 58 | - $payments = $this->_get_payments( $TXN_ID ); |
|
| 59 | - if ( empty( $payments ) ) { |
|
| 58 | + $payments = $this->_get_payments($TXN_ID); |
|
| 59 | + if (empty($payments)) { |
|
| 60 | 60 | return; |
| 61 | 61 | } |
| 62 | 62 | // then the registrants |
| 63 | - $registrations = $this->_get_registrations( $TXN_ID ); |
|
| 64 | - if ( empty( $registrations ) ) { |
|
| 63 | + $registrations = $this->_get_registrations($TXN_ID); |
|
| 64 | + if (empty($registrations)) { |
|
| 65 | 65 | return; |
| 66 | 66 | } |
| 67 | 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 ); |
|
| 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 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | } |
@@ -80,11 +80,11 @@ discard block |
||
| 80 | 80 | * @param int $TXN_ID |
| 81 | 81 | * @return array |
| 82 | 82 | */ |
| 83 | - protected function _get_registrations( $TXN_ID ) { |
|
| 83 | + protected function _get_registrations($TXN_ID) { |
|
| 84 | 84 | /** @type WPDB $wpdb */ |
| 85 | 85 | global $wpdb; |
| 86 | 86 | $SQL = "SELECT * FROM {$this->_registration_table} WHERE TXN_ID = %d AND STS_ID IN ( 'RPP', 'RAP' )"; |
| 87 | - return $wpdb->get_results( $wpdb->prepare( $SQL, $TXN_ID ), OBJECT_K ); |
|
| 87 | + return $wpdb->get_results($wpdb->prepare($SQL, $TXN_ID), OBJECT_K); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | |
@@ -95,10 +95,10 @@ discard block |
||
| 95 | 95 | * @param int $TXN_ID |
| 96 | 96 | * @return array |
| 97 | 97 | */ |
| 98 | - protected function _get_payments( $TXN_ID ) { |
|
| 98 | + protected function _get_payments($TXN_ID) { |
|
| 99 | 99 | /** @type WPDB $wpdb */ |
| 100 | 100 | global $wpdb; |
| 101 | - return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$this->_payment_table} WHERE TXN_ID = %d", $TXN_ID ), OBJECT_K ); |
|
| 101 | + return $wpdb->get_results($wpdb->prepare("SELECT * FROM {$this->_payment_table} WHERE TXN_ID = %d", $TXN_ID), OBJECT_K); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | |
@@ -109,10 +109,10 @@ discard block |
||
| 109 | 109 | * @param int $REG_ID |
| 110 | 110 | * @return array |
| 111 | 111 | */ |
| 112 | - protected function _get_possibly_updated_REG_paid( $REG_ID ) { |
|
| 112 | + protected function _get_possibly_updated_REG_paid($REG_ID) { |
|
| 113 | 113 | /** @type WPDB $wpdb */ |
| 114 | 114 | global $wpdb; |
| 115 | - return $wpdb->get_var( $wpdb->prepare( "SELECT REG_paid FROM {$this->_registration_table} WHERE REG_ID = %d", $REG_ID ) ); |
|
| 115 | + return $wpdb->get_var($wpdb->prepare("SELECT REG_paid FROM {$this->_registration_table} WHERE REG_ID = %d", $REG_ID)); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | |
@@ -127,40 +127,40 @@ discard block |
||
| 127 | 127 | * @param array $registrations |
| 128 | 128 | * @return bool |
| 129 | 129 | */ |
| 130 | - protected function _process_registration_payments( $payment, $registrations = array() ){ |
|
| 130 | + protected function _process_registration_payments($payment, $registrations = array()) { |
|
| 131 | 131 | // how much is available to apply to registrations? |
| 132 | 132 | $available_payment_amount = $payment->PAY_amount; |
| 133 | - foreach ( $registrations as $REG_ID => $registration ) { |
|
| 133 | + foreach ($registrations as $REG_ID => $registration) { |
|
| 134 | 134 | // nothing left, then we are done here? |
| 135 | - if ( ! $available_payment_amount > 0 ) { |
|
| 135 | + if ( ! $available_payment_amount > 0) { |
|
| 136 | 136 | break; |
| 137 | 137 | } |
| 138 | 138 | // ensure REG_final_price has a valid value, and skip if it turns out to be zero |
| 139 | - $registration->REG_final_price = ! empty( $registration->REG_final_price ) ? (float)$registration->REG_final_price : 0.00; |
|
| 140 | - if ( ! $registration->REG_final_price > 0 ) { |
|
| 139 | + $registration->REG_final_price = ! empty($registration->REG_final_price) ? (float) $registration->REG_final_price : 0.00; |
|
| 140 | + if ( ! $registration->REG_final_price > 0) { |
|
| 141 | 141 | continue; |
| 142 | 142 | } |
| 143 | 143 | // because REG_paid may have been updated by a previous payment, we need to retrieve the value from the db |
| 144 | - $possibly_updated_REG_paid = $this->_get_possibly_updated_REG_paid( $REG_ID ); |
|
| 145 | - if ( is_float( $possibly_updated_REG_paid ) ) { |
|
| 144 | + $possibly_updated_REG_paid = $this->_get_possibly_updated_REG_paid($REG_ID); |
|
| 145 | + if (is_float($possibly_updated_REG_paid)) { |
|
| 146 | 146 | $registration->REG_paid = $possibly_updated_REG_paid; |
| 147 | 147 | } |
| 148 | 148 | // and ensure REG_paid has a valid value |
| 149 | - $registration->REG_paid = ! empty( $registration->REG_paid ) ? (float)$registration->REG_paid : 0.00; |
|
| 149 | + $registration->REG_paid = ! empty($registration->REG_paid) ? (float) $registration->REG_paid : 0.00; |
|
| 150 | 150 | // calculate amount owing, and skip if it turns out to be zero |
| 151 | 151 | $owing = $registration->REG_final_price - $registration->REG_paid; |
| 152 | - if ( ! $owing > 0 ) { |
|
| 152 | + if ( ! $owing > 0) { |
|
| 153 | 153 | continue; |
| 154 | 154 | } |
| 155 | 155 | // don't allow payment amount to exceed the available payment amount, OR the amount owing |
| 156 | - $payment_amount = min( $available_payment_amount, $owing ); |
|
| 156 | + $payment_amount = min($available_payment_amount, $owing); |
|
| 157 | 157 | // update $available_payment_amount |
| 158 | 158 | $available_payment_amount = $available_payment_amount - $payment_amount; |
| 159 | 159 | // add relation between registration and payment and set amount |
| 160 | - if ( $this->_insert_registration_payment( $registration->REG_ID, $payment->PAY_ID, $payment_amount )) { |
|
| 160 | + if ($this->_insert_registration_payment($registration->REG_ID, $payment->PAY_ID, $payment_amount)) { |
|
| 161 | 161 | //calculate and set new REG_paid |
| 162 | 162 | $registration->REG_paid = $registration->REG_paid + $payment_amount; |
| 163 | - $this->_update_registration_paid( $registration->REG_ID, $registration->REG_paid ); |
|
| 163 | + $this->_update_registration_paid($registration->REG_ID, $registration->REG_paid); |
|
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | } |
@@ -175,18 +175,18 @@ discard block |
||
| 175 | 175 | * @param float $PAY_amount |
| 176 | 176 | * @return bool |
| 177 | 177 | */ |
| 178 | - protected function _insert_registration_payment( $REG_ID = 0, $PAY_ID = 0, $PAY_amount = 0.00 ){ |
|
| 178 | + protected function _insert_registration_payment($REG_ID = 0, $PAY_ID = 0, $PAY_amount = 0.00) { |
|
| 179 | 179 | /** @type WPDB $wpdb */ |
| 180 | 180 | global $wpdb; |
| 181 | 181 | $success = $wpdb->insert( |
| 182 | 182 | $this->_registration_payment_table, |
| 183 | - array( 'REG_ID' => $REG_ID, 'PAY_ID' => $PAY_ID, 'RPY_amount' => $PAY_amount, ), // data |
|
| 184 | - array( '%f' ) // data format |
|
| 183 | + array('REG_ID' => $REG_ID, 'PAY_ID' => $PAY_ID, 'RPY_amount' => $PAY_amount,), // data |
|
| 184 | + array('%f') // data format |
|
| 185 | 185 | ); |
| 186 | - if ( $success === false ) { |
|
| 186 | + if ($success === false) { |
|
| 187 | 187 | $this->add_error( |
| 188 | 188 | sprintf( |
| 189 | - __( 'Could not update registration paid value for registration ID=%1$d because "%2$s"', 'event_espresso' ), |
|
| 189 | + __('Could not update registration paid value for registration ID=%1$d because "%2$s"', 'event_espresso'), |
|
| 190 | 190 | $REG_ID, |
| 191 | 191 | $wpdb->last_error |
| 192 | 192 | ) |
@@ -205,20 +205,20 @@ discard block |
||
| 205 | 205 | * @param float $REG_paid |
| 206 | 206 | * @return bool |
| 207 | 207 | */ |
| 208 | - protected function _update_registration_paid( $REG_ID = 0, $REG_paid = 0.00 ) { |
|
| 208 | + protected function _update_registration_paid($REG_ID = 0, $REG_paid = 0.00) { |
|
| 209 | 209 | /** @type WPDB $wpdb */ |
| 210 | 210 | global $wpdb; |
| 211 | 211 | $success = $wpdb->update( |
| 212 | 212 | $this->_registration_table, |
| 213 | - array( 'REG_paid' => $REG_paid ), // data |
|
| 214 | - array( 'REG_ID' => $REG_ID ), // where |
|
| 215 | - array( '%f' ), // data format |
|
| 216 | - array( '%d' ) // where format |
|
| 213 | + array('REG_paid' => $REG_paid), // data |
|
| 214 | + array('REG_ID' => $REG_ID), // where |
|
| 215 | + array('%f'), // data format |
|
| 216 | + array('%d') // where format |
|
| 217 | 217 | ); |
| 218 | - if ( $success === false ) { |
|
| 218 | + if ($success === false) { |
|
| 219 | 219 | $this->add_error( |
| 220 | 220 | sprintf( |
| 221 | - __( 'Could not update registration paid value for registration ID=%1$d because "%2$s"', 'event_espresso' ), |
|
| 221 | + __('Could not update registration paid value for registration ID=%1$d because "%2$s"', 'event_espresso'), |
|
| 222 | 222 | $REG_ID, |
| 223 | 223 | $wpdb->last_error |
| 224 | 224 | ) |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 3 | 3 | exit('No direct script access allowed'); |
| 4 | 4 | } |
| 5 | 5 | |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | * |
| 14 | 14 | * Migrates line items that used to have LIN_code="tickets" to "pre-tax-total" |
| 15 | 15 | */ |
| 16 | -class EE_DMS_4_8_0_pretax_totals extends EE_Data_Migration_Script_Stage{ |
|
| 16 | +class EE_DMS_4_8_0_pretax_totals extends EE_Data_Migration_Script_Stage { |
|
| 17 | 17 | |
| 18 | 18 | protected $_line_item_table_name; |
| 19 | 19 | |
@@ -53,10 +53,10 @@ discard block |
||
| 53 | 53 | global $wpdb; |
| 54 | 54 | $rows_updated = $wpdb->update( |
| 55 | 55 | $this->_line_item_table_name, |
| 56 | - array( 'LIN_code' => 'pre-tax-subtotal' ), |
|
| 57 | - array( 'LIN_code' => 'tickets' ), |
|
| 58 | - array( '%s' ), |
|
| 59 | - array( '%s' ) ); |
|
| 56 | + array('LIN_code' => 'pre-tax-subtotal'), |
|
| 57 | + array('LIN_code' => 'tickets'), |
|
| 58 | + array('%s'), |
|
| 59 | + array('%s') ); |
|
| 60 | 60 | $this->set_completed(); |
| 61 | 61 | return 1; |
| 62 | 62 | } |
@@ -264,9 +264,9 @@ |
||
| 264 | 264 | /** |
| 265 | 265 | * Same as json_encode, just avoids putting |
| 266 | 266 | * serialized arrays into the http build query, as that would |
| 267 | - * @param array $array_of_data |
|
| 268 | - * @return string |
|
| 269 | - */ |
|
| 267 | + * @param array $array_of_data |
|
| 268 | + * @return string |
|
| 269 | + */ |
|
| 270 | 270 | protected function _json_encode($array_of_data){ |
| 271 | 271 | //we'd rather NOT serialize the transaction details |
| 272 | 272 | $fields_to_include = array(); |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | $errors = $this->get_errors(); |
| 120 | 120 | if($errors){ |
| 121 | 121 | return end($errors); |
| 122 | - }else{ |
|
| 122 | + } else{ |
|
| 123 | 123 | return null; |
| 124 | 124 | } |
| 125 | 125 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | public function add_error($error, $force = FALSE ){ |
| 132 | 132 | if( ! defined( 'EE_DMS_ERROR_LIMIT' ) ){ |
| 133 | 133 | $limit = 50; |
| 134 | - }else{ |
|
| 134 | + } else{ |
|
| 135 | 135 | $limit = EE_DMS_ERROR_LIMIT; |
| 136 | 136 | } |
| 137 | 137 | //make sure errors is an array, see ticket #8261 |
@@ -144,10 +144,10 @@ discard block |
||
| 144 | 144 | $this->_errors = array_slice( $this->_errors, $limit / 2, $limit / 2 ); |
| 145 | 145 | $this->_errors[] = "Limit reached; removed first half of errors to save space"; |
| 146 | 146 | $this->_errors[] = $error; |
| 147 | - }else{ |
|
| 147 | + } else{ |
|
| 148 | 148 | $this->_errors[ $limit ] = 'More, but limit reached...'; |
| 149 | 149 | } |
| 150 | - }else{ |
|
| 150 | + } else{ |
|
| 151 | 151 | $this->_errors[] = $error; |
| 152 | 152 | } |
| 153 | 153 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | |
| 22 | 22 | |
| 23 | -abstract class EE_Data_Migration_Class_Base{ |
|
| 23 | +abstract class EE_Data_Migration_Class_Base { |
|
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * @var $records_to_migrate int count of all that have been migrated |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * @param TableManager $table_manager |
| 73 | 73 | * @param TableAnalysis $table_analysis |
| 74 | 74 | */ |
| 75 | - public function __construct( TableManager $table_manager = null, TableAnalysis $table_analysis = null ){ |
|
| 75 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) { |
|
| 76 | 76 | $this->_table_manager = $table_manager; |
| 77 | 77 | $this->_table_analysis = $table_analysis; |
| 78 | 78 | $this->set_status(EE_Data_Migration_Manager::status_continue); |
@@ -85,9 +85,9 @@ discard block |
||
| 85 | 85 | * @throws EE_Error |
| 86 | 86 | * @return string |
| 87 | 87 | */ |
| 88 | - public function pretty_name(){ |
|
| 89 | - if($this->_pretty_name === null){ |
|
| 90 | - throw new EE_Error(sprintf(__("Please give a pretty name to the migration script stage %s by assigning the property _pretty_name in the constructor", "event_espresso"),get_class($this))); |
|
| 88 | + public function pretty_name() { |
|
| 89 | + if ($this->_pretty_name === null) { |
|
| 90 | + throw new EE_Error(sprintf(__("Please give a pretty name to the migration script stage %s by assigning the property _pretty_name in the constructor", "event_espresso"), get_class($this))); |
|
| 91 | 91 | } |
| 92 | 92 | return $this->_pretty_name; |
| 93 | 93 | } |
@@ -95,8 +95,8 @@ discard block |
||
| 95 | 95 | * |
| 96 | 96 | * @return int |
| 97 | 97 | */ |
| 98 | - public function count_records_to_migrate(){ |
|
| 99 | - if( $this->_records_to_migrate == null){ |
|
| 98 | + public function count_records_to_migrate() { |
|
| 99 | + if ($this->_records_to_migrate == null) { |
|
| 100 | 100 | $this->_records_to_migrate = $this->_count_records_to_migrate(); |
| 101 | 101 | } |
| 102 | 102 | return $this->_records_to_migrate; |
@@ -116,9 +116,9 @@ discard block |
||
| 116 | 116 | * @return string one of EE_Data_Migration_Manager::status_* constants |
| 117 | 117 | * @throws EE_Error |
| 118 | 118 | */ |
| 119 | - public function get_status(){ |
|
| 120 | - if($this->_status === null){ |
|
| 121 | - throw new EE_Error(sprintf(__("Trying to get status of Migration class %s, but it has not been initialized yet. It should be set in the constructor.", "event_espresso"),get_class($this))); |
|
| 119 | + public function get_status() { |
|
| 120 | + if ($this->_status === null) { |
|
| 121 | + throw new EE_Error(sprintf(__("Trying to get status of Migration class %s, but it has not been initialized yet. It should be set in the constructor.", "event_espresso"), get_class($this))); |
|
| 122 | 122 | } |
| 123 | 123 | return $this->_status; |
| 124 | 124 | } |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | * @param string $status |
| 128 | 128 | * @return void |
| 129 | 129 | */ |
| 130 | - protected function set_status($status){ |
|
| 130 | + protected function set_status($status) { |
|
| 131 | 131 | $this->_status = $status; |
| 132 | 132 | } |
| 133 | 133 | /** |
@@ -139,11 +139,11 @@ discard block |
||
| 139 | 139 | * Returns the last error that occurred. If none occurred, returns null |
| 140 | 140 | * @return string |
| 141 | 141 | */ |
| 142 | - public function get_last_error(){ |
|
| 142 | + public function get_last_error() { |
|
| 143 | 143 | $errors = $this->get_errors(); |
| 144 | - if($errors){ |
|
| 144 | + if ($errors) { |
|
| 145 | 145 | return end($errors); |
| 146 | - }else{ |
|
| 146 | + } else { |
|
| 147 | 147 | return null; |
| 148 | 148 | } |
| 149 | 149 | } |
@@ -152,26 +152,26 @@ discard block |
||
| 152 | 152 | * @param string $error a string describing the error that will be useful for debugging. Consider including all the data that led to the error, and a stack trace etc. |
| 153 | 153 | * @param boolean $force force the error to be added (because otherwise we have a limit). If forcing and errors are already at their limit, we will purposefully forget the first half |
| 154 | 154 | */ |
| 155 | - public function add_error($error, $force = FALSE ){ |
|
| 156 | - if( ! defined( 'EE_DMS_ERROR_LIMIT' ) ){ |
|
| 155 | + public function add_error($error, $force = FALSE) { |
|
| 156 | + if ( ! defined('EE_DMS_ERROR_LIMIT')) { |
|
| 157 | 157 | $limit = 50; |
| 158 | - }else{ |
|
| 158 | + } else { |
|
| 159 | 159 | $limit = EE_DMS_ERROR_LIMIT; |
| 160 | 160 | } |
| 161 | 161 | //make sure errors is an array, see ticket #8261 |
| 162 | - if( is_string( $this->_errors ) ){ |
|
| 163 | - $this->_errors = array( $this->_errors ); |
|
| 162 | + if (is_string($this->_errors)) { |
|
| 163 | + $this->_errors = array($this->_errors); |
|
| 164 | 164 | } |
| 165 | - if(count($this->_errors) >= $limit ){ |
|
| 166 | - if( $force ){ |
|
| 165 | + if (count($this->_errors) >= $limit) { |
|
| 166 | + if ($force) { |
|
| 167 | 167 | //get rid of the first half of the errors and any above the limit |
| 168 | - $this->_errors = array_slice( $this->_errors, $limit / 2, $limit / 2 ); |
|
| 168 | + $this->_errors = array_slice($this->_errors, $limit / 2, $limit / 2); |
|
| 169 | 169 | $this->_errors[] = "Limit reached; removed first half of errors to save space"; |
| 170 | 170 | $this->_errors[] = $error; |
| 171 | - }else{ |
|
| 172 | - $this->_errors[ $limit ] = 'More, but limit reached...'; |
|
| 171 | + } else { |
|
| 172 | + $this->_errors[$limit] = 'More, but limit reached...'; |
|
| 173 | 173 | } |
| 174 | - }else{ |
|
| 174 | + } else { |
|
| 175 | 175 | $this->_errors[] = $error; |
| 176 | 176 | } |
| 177 | 177 | } |
@@ -180,57 +180,57 @@ discard block |
||
| 180 | 180 | * Indicates there was a fatal error and the migration cannot possibly continue |
| 181 | 181 | * @return boolean |
| 182 | 182 | */ |
| 183 | - public function is_broken(){ |
|
| 183 | + public function is_broken() { |
|
| 184 | 184 | return $this->get_status() == EE_Data_Migration_Manager::status_fatal_error; |
| 185 | 185 | } |
| 186 | 186 | /** |
| 187 | 187 | * @deprecated since 4.6.12 |
| 188 | 188 | */ |
| 189 | - public function is_borked(){ |
|
| 190 | - EE_Error::doing_it_wrong('is_borked', __( 'The cheeky "is_borked" method had been replaced with the more proper "is_broken"', 'event_espresso' ), '4.6.12'); |
|
| 189 | + public function is_borked() { |
|
| 190 | + EE_Error::doing_it_wrong('is_borked', __('The cheeky "is_borked" method had been replaced with the more proper "is_broken"', 'event_espresso'), '4.6.12'); |
|
| 191 | 191 | return $this->is_broken(); |
| 192 | 192 | } |
| 193 | 193 | /** |
| 194 | 194 | * Sets the status to as having a fatal error |
| 195 | 195 | */ |
| 196 | - public function set_broken(){ |
|
| 196 | + public function set_broken() { |
|
| 197 | 197 | $this->_status = EE_Data_Migration_Manager::status_fatal_error; |
| 198 | 198 | } |
| 199 | 199 | /** |
| 200 | 200 | * |
| 201 | 201 | * @deprecated since 4.6.12 |
| 202 | 202 | */ |
| 203 | - public function set_borked(){ |
|
| 204 | - EE_Error::doing_it_wrong('is_borked', __( 'The cheeky "is_borked" method had been replaced with the more proper "is_broken"', 'event_espresso' ), '4.6.12'); |
|
| 203 | + public function set_borked() { |
|
| 204 | + EE_Error::doing_it_wrong('is_borked', __('The cheeky "is_borked" method had been replaced with the more proper "is_broken"', 'event_espresso'), '4.6.12'); |
|
| 205 | 205 | return $this->set_broken(); |
| 206 | 206 | } |
| 207 | 207 | /** |
| 208 | 208 | * Checks if this thing believes it is completed |
| 209 | 209 | * @return boolean |
| 210 | 210 | */ |
| 211 | - public function is_completed(){ |
|
| 211 | + public function is_completed() { |
|
| 212 | 212 | return $this->get_status() == EE_Data_Migration_Manager::status_completed; |
| 213 | 213 | } |
| 214 | 214 | /** |
| 215 | 215 | * Checks if the current script has more to do or not (ie, if it's status is CONTINUE) |
| 216 | 216 | * @return boolean |
| 217 | 217 | */ |
| 218 | - public function has_more_to_do(){ |
|
| 218 | + public function has_more_to_do() { |
|
| 219 | 219 | return $this->get_status() == EE_Data_Migration_Manager::status_continue; |
| 220 | 220 | } |
| 221 | 221 | /** |
| 222 | 222 | * Marks that we believe this migration thing is completed |
| 223 | 223 | */ |
| 224 | - public function set_completed(){ |
|
| 224 | + public function set_completed() { |
|
| 225 | 225 | $this->_status = EE_Data_Migration_Manager::status_completed; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
| 229 | 229 | * Marks that we think this migration class can continue to migrate |
| 230 | 230 | */ |
| 231 | - public function reattempt(){ |
|
| 231 | + public function reattempt() { |
|
| 232 | 232 | $this->_status = EE_Data_Migration_Manager::status_continue; |
| 233 | - $this->add_error( __( 'Reattempt migration', 'event_espresso' ), TRUE ); |
|
| 233 | + $this->add_error(__('Reattempt migration', 'event_espresso'), TRUE); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -239,8 +239,8 @@ discard block |
||
| 239 | 239 | * possible that this class is defined when it goes to sleep, but NOT available when it |
| 240 | 240 | * awakes (eg, this class is part of an addon that is deactivated at some point). |
| 241 | 241 | */ |
| 242 | - public function properties_as_array(){ |
|
| 243 | - $properties = get_object_vars($this); |
|
| 242 | + public function properties_as_array() { |
|
| 243 | + $properties = get_object_vars($this); |
|
| 244 | 244 | $properties['class'] = get_class($this); |
| 245 | 245 | unset($properties['_migration_script']); |
| 246 | 246 | return $properties; |
@@ -261,22 +261,22 @@ discard block |
||
| 261 | 261 | * @param array $data_types numerically indexed |
| 262 | 262 | * @return string |
| 263 | 263 | */ |
| 264 | - protected function _create_error_message_for_db_insertion($old_table, $old_row_as_array, $new_table, $new_row_as_array, $data_types){ |
|
| 264 | + protected function _create_error_message_for_db_insertion($old_table, $old_row_as_array, $new_table, $new_row_as_array, $data_types) { |
|
| 265 | 265 | global $wpdb; |
| 266 | 266 | $old_columns_and_values_for_string = array(); |
| 267 | - foreach($old_row_as_array as $column => $value){ |
|
| 267 | + foreach ($old_row_as_array as $column => $value) { |
|
| 268 | 268 | $old_columns_and_values_for_string[] = "$column => $value"; |
| 269 | 269 | } |
| 270 | 270 | $new_columns_and_values_for_string = array(); |
| 271 | 271 | $count = 0; |
| 272 | - foreach($new_row_as_array as $column => $value){ |
|
| 272 | + foreach ($new_row_as_array as $column => $value) { |
|
| 273 | 273 | $new_columns_and_values_for_string[] = " $column => $value (".$data_types[$count++].")"; |
| 274 | 274 | } |
| 275 | 275 | return sprintf( |
| 276 | 276 | __('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.', "event_espresso"), |
| 277 | - implode(", ",$new_columns_and_values_for_string), |
|
| 277 | + implode(", ", $new_columns_and_values_for_string), |
|
| 278 | 278 | $new_table, |
| 279 | - implode(", ",$old_columns_and_values_for_string), |
|
| 279 | + implode(", ", $old_columns_and_values_for_string), |
|
| 280 | 280 | $old_table, |
| 281 | 281 | '<br/>', |
| 282 | 282 | $wpdb->last_error |
@@ -291,12 +291,12 @@ discard block |
||
| 291 | 291 | * @param array $array_of_data |
| 292 | 292 | * @return string |
| 293 | 293 | */ |
| 294 | - protected function _json_encode($array_of_data){ |
|
| 294 | + protected function _json_encode($array_of_data) { |
|
| 295 | 295 | //we'd rather NOT serialize the transaction details |
| 296 | 296 | $fields_to_include = array(); |
| 297 | - foreach($array_of_data as $name => $value){ |
|
| 297 | + foreach ($array_of_data as $name => $value) { |
|
| 298 | 298 | $unserialized_data = @unserialize($value); |
| 299 | - if($unserialized_data === FALSE){ |
|
| 299 | + if ($unserialized_data === FALSE) { |
|
| 300 | 300 | $fields_to_include[$name] = $value; |
| 301 | 301 | } |
| 302 | 302 | } |
@@ -309,13 +309,13 @@ discard block |
||
| 309 | 309 | * @throws EE_Error |
| 310 | 310 | */ |
| 311 | 311 | protected function _get_table_manager() { |
| 312 | - if( $this->_table_manager instanceof TableManager ) { |
|
| 312 | + if ($this->_table_manager instanceof TableManager) { |
|
| 313 | 313 | return $this->_table_manager; |
| 314 | 314 | } else { |
| 315 | 315 | throw new EE_Error( |
| 316 | 316 | sprintf( |
| 317 | - __( 'Table manager on migration class %1$s is not set properly.', 'event_espresso'), |
|
| 318 | - get_class( $this ) |
|
| 317 | + __('Table manager on migration class %1$s is not set properly.', 'event_espresso'), |
|
| 318 | + get_class($this) |
|
| 319 | 319 | ) |
| 320 | 320 | ); |
| 321 | 321 | } |
@@ -327,13 +327,13 @@ discard block |
||
| 327 | 327 | * @throws EE_Error |
| 328 | 328 | */ |
| 329 | 329 | protected function _get_table_analysis() { |
| 330 | - if( $this->_table_analysis instanceof TableAnalysis ) { |
|
| 330 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
| 331 | 331 | return $this->_table_analysis; |
| 332 | 332 | } else { |
| 333 | 333 | throw new EE_Error( |
| 334 | 334 | sprintf( |
| 335 | - __( 'Table analysis class on migration class %1$s is not set properly.', 'event_espresso'), |
|
| 336 | - get_class( $this ) |
|
| 335 | + __('Table analysis class on migration class %1$s is not set properly.', 'event_espresso'), |
|
| 336 | + get_class($this) |
|
| 337 | 337 | ) |
| 338 | 338 | ); |
| 339 | 339 | } |
@@ -21,12 +21,12 @@ |
||
| 21 | 21 | protected $_old_table; |
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | - * Set in the constructor to add this sql to both the counting query in |
|
| 25 | - * EE_Data_Migration_Script_Stage_Table::_count_records_to_migrate() and |
|
| 26 | - * EE_Data_Migration_Script_Stage_Table::_get_rows(). |
|
| 27 | - * Eg "where column_name like '%some_value%'" |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 24 | + * Set in the constructor to add this sql to both the counting query in |
|
| 25 | + * EE_Data_Migration_Script_Stage_Table::_count_records_to_migrate() and |
|
| 26 | + * EE_Data_Migration_Script_Stage_Table::_get_rows(). |
|
| 27 | + * Eg "where column_name like '%some_value%'" |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | 30 | protected $_extra_where_sql; |
| 31 | 31 | |
| 32 | 32 | |
@@ -41,14 +41,14 @@ discard block |
||
| 41 | 41 | * @param int $num_items |
| 42 | 42 | * @return int number of items ACTUALLY migrated |
| 43 | 43 | */ |
| 44 | - function _migration_step($num_items=50){ |
|
| 45 | - $rows = $this->_get_rows( $num_items ); |
|
| 44 | + function _migration_step($num_items = 50) { |
|
| 45 | + $rows = $this->_get_rows($num_items); |
|
| 46 | 46 | $items_actually_migrated = 0; |
| 47 | - foreach($rows as $old_row){ |
|
| 47 | + foreach ($rows as $old_row) { |
|
| 48 | 48 | $this->_migrate_old_row($old_row); |
| 49 | 49 | $items_actually_migrated++; |
| 50 | 50 | } |
| 51 | - if($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()){ |
|
| 51 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
| 52 | 52 | $this->set_completed(); |
| 53 | 53 | } |
| 54 | 54 | return $items_actually_migrated; |
@@ -60,11 +60,11 @@ discard block |
||
| 60 | 60 | * @param int $limit |
| 61 | 61 | * @return array of arrays like $wpdb->get_results($sql, ARRAY_A) |
| 62 | 62 | */ |
| 63 | - protected function _get_rows( $limit ){ |
|
| 63 | + protected function _get_rows($limit) { |
|
| 64 | 64 | global $wpdb; |
| 65 | 65 | $start_at_record = $this->count_records_migrated(); |
| 66 | - $query = "SELECT * FROM {$this->_old_table} {$this->_extra_where_sql} " . $wpdb->prepare("LIMIT %d, %d",$start_at_record,$limit); |
|
| 67 | - return $wpdb->get_results($query,ARRAY_A); |
|
| 66 | + $query = "SELECT * FROM {$this->_old_table} {$this->_extra_where_sql} ".$wpdb->prepare("LIMIT %d, %d", $start_at_record, $limit); |
|
| 67 | + return $wpdb->get_results($query, ARRAY_A); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | function _count_records_to_migrate() { |
| 77 | 77 | global $wpdb; |
| 78 | - $query = "SELECT COUNT(*) FROM {$this->_old_table} {$this->_extra_where_sql}"; |
|
| 79 | - $count = $wpdb->get_var( $query ); |
|
| 78 | + $query = "SELECT COUNT(*) FROM {$this->_old_table} {$this->_extra_where_sql}"; |
|
| 79 | + $count = $wpdb->get_var($query); |
|
| 80 | 80 | return $count; |
| 81 | 81 | } |
| 82 | 82 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | -<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 2 | - exit( 'No direct script access allowed' ); |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | /** |
| 5 | 5 | * Event Espresso |
@@ -31,9 +31,9 @@ discard block |
||
| 31 | 31 | * @param array $props_n_values |
| 32 | 32 | * @return EE_Answer |
| 33 | 33 | */ |
| 34 | - public static function new_instance( $props_n_values = array() ) { |
|
| 35 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__ ); |
|
| 36 | - return $has_object ? $has_object : new self( $props_n_values ); |
|
| 34 | + public static function new_instance($props_n_values = array()) { |
|
| 35 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 36 | + return $has_object ? $has_object : new self($props_n_values); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | * @param array $props_n_values |
| 44 | 44 | * @return EE_Answer |
| 45 | 45 | */ |
| 46 | - public static function new_instance_from_db( $props_n_values = array() ) { |
|
| 47 | - return new self( $props_n_values, TRUE ); |
|
| 46 | + public static function new_instance_from_db($props_n_values = array()) { |
|
| 47 | + return new self($props_n_values, TRUE); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | |
@@ -55,8 +55,8 @@ discard block |
||
| 55 | 55 | * @access public |
| 56 | 56 | * @param int $QST_ID |
| 57 | 57 | */ |
| 58 | - public function set_question( $QST_ID = 0 ) { |
|
| 59 | - $this->set( 'QST_ID', $QST_ID ); |
|
| 58 | + public function set_question($QST_ID = 0) { |
|
| 59 | + $this->set('QST_ID', $QST_ID); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | |
@@ -67,8 +67,8 @@ discard block |
||
| 67 | 67 | * @access public |
| 68 | 68 | * @param int $REG_ID |
| 69 | 69 | */ |
| 70 | - public function set_registration( $REG_ID = 0 ) { |
|
| 71 | - $this->set( 'REG_ID', $REG_ID ); |
|
| 70 | + public function set_registration($REG_ID = 0) { |
|
| 71 | + $this->set('REG_ID', $REG_ID); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | |
@@ -79,8 +79,8 @@ discard block |
||
| 79 | 79 | * @access public |
| 80 | 80 | * @param mixed $ANS_value |
| 81 | 81 | */ |
| 82 | - public function set_value( $ANS_value = '' ) { |
|
| 83 | - $this->set( 'ANS_value', $ANS_value ); |
|
| 82 | + public function set_value($ANS_value = '') { |
|
| 83 | + $this->set('ANS_value', $ANS_value); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | * @return int |
| 93 | 93 | */ |
| 94 | 94 | public function registration_ID() { |
| 95 | - return $this->get( 'REG_ID' ); |
|
| 95 | + return $this->get('REG_ID'); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * @return int |
| 105 | 105 | */ |
| 106 | 106 | public function question_ID() { |
| 107 | - return $this->get( 'QST_ID' ); |
|
| 107 | + return $this->get('QST_ID'); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | * @return string |
| 117 | 117 | */ |
| 118 | 118 | public function value() { |
| 119 | - return $this->get( 'ANS_value' ); |
|
| 119 | + return $this->get('ANS_value'); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | |
@@ -126,8 +126,8 @@ discard block |
||
| 126 | 126 | * @param null $schema |
| 127 | 127 | * @return string |
| 128 | 128 | */ |
| 129 | - public function pretty_value( $schema = NULL ) { |
|
| 130 | - return $this->get_pretty( 'ANS_value', $schema ); |
|
| 129 | + public function pretty_value($schema = NULL) { |
|
| 130 | + return $this->get_pretty('ANS_value', $schema); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | |
@@ -136,8 +136,8 @@ discard block |
||
| 136 | 136 | * Echoes out a pretty value (even for multi-choice options) |
| 137 | 137 | * @param string $schema |
| 138 | 138 | */ |
| 139 | - public function e_value( $schema = NULL ) { |
|
| 140 | - $this->e( 'ANS_value', $schema ); |
|
| 139 | + public function e_value($schema = NULL) { |
|
| 140 | + $this->e('ANS_value', $schema); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | * @return EE_Question |
| 148 | 148 | */ |
| 149 | 149 | public function question() { |
| 150 | - return $this->get_first_related( 'Question' ); |
|
| 150 | + return $this->get_first_related('Question'); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * @return EE_Registration |
| 158 | 158 | */ |
| 159 | 159 | public function registration() { |
| 160 | - return $this->get_first_related( 'Registration' ); |
|
| 160 | + return $this->get_first_related('Registration'); |
|
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
| 1 | +<?php if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | +} |
|
| 2 | 4 | /** |
| 3 | 5 | * CSV Import Export class |
| 4 | 6 | * |
@@ -105,8 +107,9 @@ discard block |
||
| 105 | 107 | $fc = $fc . $c; |
| 106 | 108 | } |
| 107 | 109 | } |
| 108 | - if ((ord(substr($fc,0,1)) == 255) && (ord(substr($fc,1,1)) == 254)) |
|
| 109 | - $fc = substr($fc,2); |
|
| 110 | + if ((ord(substr($fc,0,1)) == 255) && (ord(substr($fc,1,1)) == 254)) { |
|
| 111 | + $fc = substr($fc,2); |
|
| 112 | + } |
|
| 110 | 113 | return ($fc); |
| 111 | 114 | } |
| 112 | 115 | |
@@ -144,7 +147,7 @@ discard block |
||
| 144 | 147 | while(($data = fgetcsv($file_handle, 0, ',', '"' )) !== FALSE){ |
| 145 | 148 | $csvarray[]= $data; |
| 146 | 149 | } |
| 147 | - }else{ |
|
| 150 | + } else{ |
|
| 148 | 151 | // loop through each row of the file |
| 149 | 152 | while (( $data = fgetcsv( $file_handle, 0, ',', '"', '\\' )) !== FALSE ) { |
| 150 | 153 | $csvarray[]=$data; |
@@ -153,7 +156,7 @@ discard block |
||
| 153 | 156 | # Close the File. |
| 154 | 157 | fclose($file_handle); |
| 155 | 158 | return $csvarray; |
| 156 | - }else{ |
|
| 159 | + } else{ |
|
| 157 | 160 | EE_Error::add_error( sprintf(__("An error occurred - the file: %s could not opened.", "event_espresso"),$path_to_file), __FILE__, __FUNCTION__, __LINE__ ); |
| 158 | 161 | return false; |
| 159 | 162 | } |
@@ -234,7 +237,7 @@ discard block |
||
| 234 | 237 | $matches = array(); |
| 235 | 238 | if($model_name == EE_CSV::metadata_header){ |
| 236 | 239 | $headers[$i] = $column_name; |
| 237 | - }else{ |
|
| 240 | + } else{ |
|
| 238 | 241 | //now get the db table name from it (the part between square brackets) |
| 239 | 242 | $success = preg_match('~(.*)\[(.*)\]~', $column_name,$matches); |
| 240 | 243 | if (!$success){ |
@@ -244,7 +247,7 @@ discard block |
||
| 244 | 247 | $headers[$i] = $matches[2]; |
| 245 | 248 | } |
| 246 | 249 | |
| 247 | - }else{ |
|
| 250 | + } else{ |
|
| 248 | 251 | // no column names means our final array will just use counters for keys |
| 249 | 252 | $model_entry[$headers[$i]] = $data[$i]; |
| 250 | 253 | $headers[$i] = $i; |
@@ -371,7 +374,7 @@ discard block |
||
| 371 | 374 | echo $this->fputcsv2($filehandle, $data_row); |
| 372 | 375 | } |
| 373 | 376 | return true; |
| 374 | - }else{ |
|
| 377 | + } else{ |
|
| 375 | 378 | //no data TO write... so we can assume that's a success |
| 376 | 379 | return true; |
| 377 | 380 | } |
@@ -438,7 +441,7 @@ discard block |
||
| 438 | 441 | |
| 439 | 442 | if( ! empty($model_instance_arrays) ){ |
| 440 | 443 | $this->write_data_array_to_csv($filehandle, $model_instance_arrays); |
| 441 | - }else{ |
|
| 444 | + } else{ |
|
| 442 | 445 | // echo "no data to write... so just write the headers"; |
| 443 | 446 | //so there's actually NO model objects for that model. |
| 444 | 447 | //probably still want to show the columns |
@@ -315,7 +315,7 @@ |
||
| 315 | 315 | // header("Content-Type: application/download"); |
| 316 | 316 | header('Content-disposition: attachment; filename='.$filename); |
| 317 | 317 | header("Content-Type: text/csv; charset=utf-8"); |
| 318 | - do_action( 'AHEE__EE_CSV__begin_sending_csv__headers' ); |
|
| 318 | + do_action( 'AHEE__EE_CSV__begin_sending_csv__headers' ); |
|
| 319 | 319 | echo apply_filters('FHEE__EE_CSV__begin_sending_csv__start_writing', "\xEF\xBB\xBF" ); // makes excel open it as UTF-8. UTF-8 BOM, see http://stackoverflow.com/a/4440143/2773835 |
| 320 | 320 | $fh = fopen('php://output', 'w'); |
| 321 | 321 | return $fh; |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
| 2 | 2 | /** |
| 3 | 3 | * CSV Import Export class |
| 4 | 4 | * |
@@ -45,31 +45,31 @@ discard block |
||
| 45 | 45 | global $wpdb; |
| 46 | 46 | |
| 47 | 47 | $this->_primary_keys = array( |
| 48 | - $wpdb->prefix . 'esp_answer' => array( 'ANS_ID' ), |
|
| 49 | - $wpdb->prefix . 'esp_attendee' => array( 'ATT_ID' ), |
|
| 50 | - $wpdb->prefix . 'esp_datetime' => array( 'DTT_ID' ), |
|
| 51 | - $wpdb->prefix . 'esp_event_question_group' => array( 'EQG_ID' ), |
|
| 52 | - $wpdb->prefix . 'esp_message_template' => array( 'MTP_ID' ), |
|
| 53 | - $wpdb->prefix . 'esp_payment' => array( 'PAY_ID' ), |
|
| 54 | - $wpdb->prefix . 'esp_price' => array( 'PRC_ID' ), |
|
| 55 | - $wpdb->prefix . 'esp_price_type' => array( 'PRT_ID' ), |
|
| 56 | - $wpdb->prefix . 'esp_question' => array( 'QST_ID' ), |
|
| 57 | - $wpdb->prefix . 'esp_question_group' => array( 'QSG_ID' ), |
|
| 58 | - $wpdb->prefix . 'esp_question_group_question' => array( 'QGQ_ID' ), |
|
| 59 | - $wpdb->prefix . 'esp_question_option' => array( 'QSO_ID' ), |
|
| 60 | - $wpdb->prefix . 'esp_registration' => array( 'REG_ID' ), |
|
| 61 | - $wpdb->prefix . 'esp_status' => array( 'STS_ID' ), |
|
| 62 | - $wpdb->prefix . 'esp_transaction' => array( 'TXN_ID' ), |
|
| 63 | - $wpdb->prefix . 'esp_transaction' => array( 'TXN_ID' ), |
|
| 64 | - $wpdb->prefix . 'events_detail' => array( 'id' ), |
|
| 65 | - $wpdb->prefix . 'events_category_detail' => array( 'id' ), |
|
| 66 | - $wpdb->prefix . 'events_category_rel' => array( 'id' ), |
|
| 67 | - $wpdb->prefix . 'events_venue' => array( 'id' ), |
|
| 68 | - $wpdb->prefix . 'events_venue_rel' => array( 'emeta_id' ), |
|
| 69 | - $wpdb->prefix . 'events_locale' => array( 'id' ), |
|
| 70 | - $wpdb->prefix . 'events_locale_rel' => array( 'id' ), |
|
| 71 | - $wpdb->prefix . 'events_personnel' => array( 'id' ), |
|
| 72 | - $wpdb->prefix . 'events_personnel_rel' => array( 'id' ), |
|
| 48 | + $wpdb->prefix.'esp_answer' => array('ANS_ID'), |
|
| 49 | + $wpdb->prefix.'esp_attendee' => array('ATT_ID'), |
|
| 50 | + $wpdb->prefix.'esp_datetime' => array('DTT_ID'), |
|
| 51 | + $wpdb->prefix.'esp_event_question_group' => array('EQG_ID'), |
|
| 52 | + $wpdb->prefix.'esp_message_template' => array('MTP_ID'), |
|
| 53 | + $wpdb->prefix.'esp_payment' => array('PAY_ID'), |
|
| 54 | + $wpdb->prefix.'esp_price' => array('PRC_ID'), |
|
| 55 | + $wpdb->prefix.'esp_price_type' => array('PRT_ID'), |
|
| 56 | + $wpdb->prefix.'esp_question' => array('QST_ID'), |
|
| 57 | + $wpdb->prefix.'esp_question_group' => array('QSG_ID'), |
|
| 58 | + $wpdb->prefix.'esp_question_group_question' => array('QGQ_ID'), |
|
| 59 | + $wpdb->prefix.'esp_question_option' => array('QSO_ID'), |
|
| 60 | + $wpdb->prefix.'esp_registration' => array('REG_ID'), |
|
| 61 | + $wpdb->prefix.'esp_status' => array('STS_ID'), |
|
| 62 | + $wpdb->prefix.'esp_transaction' => array('TXN_ID'), |
|
| 63 | + $wpdb->prefix.'esp_transaction' => array('TXN_ID'), |
|
| 64 | + $wpdb->prefix.'events_detail' => array('id'), |
|
| 65 | + $wpdb->prefix.'events_category_detail' => array('id'), |
|
| 66 | + $wpdb->prefix.'events_category_rel' => array('id'), |
|
| 67 | + $wpdb->prefix.'events_venue' => array('id'), |
|
| 68 | + $wpdb->prefix.'events_venue_rel' => array('emeta_id'), |
|
| 69 | + $wpdb->prefix.'events_locale' => array('id'), |
|
| 70 | + $wpdb->prefix.'events_locale_rel' => array('id'), |
|
| 71 | + $wpdb->prefix.'events_personnel' => array('id'), |
|
| 72 | + $wpdb->prefix.'events_personnel_rel' => array('id'), |
|
| 73 | 73 | ); |
| 74 | 74 | |
| 75 | 75 | } |
@@ -81,9 +81,9 @@ discard block |
||
| 81 | 81 | * @ access public |
| 82 | 82 | * @return EE_CSV |
| 83 | 83 | */ |
| 84 | - public static function instance ( ) { |
|
| 84 | + public static function instance( ) { |
|
| 85 | 85 | // check if class object is instantiated |
| 86 | - if ( self::$_instance === NULL or ! is_object( self::$_instance ) or ! ( self::$_instance instanceof EE_CSV )) { |
|
| 86 | + if (self::$_instance === NULL or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_CSV)) { |
|
| 87 | 87 | self::$_instance = new self(); |
| 88 | 88 | } |
| 89 | 89 | return self::$_instance; |
@@ -95,22 +95,22 @@ discard block |
||
| 95 | 95 | * @return string |
| 96 | 96 | * @throws EE_Error |
| 97 | 97 | */ |
| 98 | - private function read_unicode_file($file_path){ |
|
| 98 | + private function read_unicode_file($file_path) { |
|
| 99 | 99 | $fc = ""; |
| 100 | - $fh = fopen($file_path,"rb"); |
|
| 101 | - if( ! $fh ){ |
|
| 102 | - throw new EE_Error( sprintf( __("Cannot open file for read: %s<br>\n", 'event_espresso'), $file_path ) ); |
|
| 100 | + $fh = fopen($file_path, "rb"); |
|
| 101 | + if ( ! $fh) { |
|
| 102 | + throw new EE_Error(sprintf(__("Cannot open file for read: %s<br>\n", 'event_espresso'), $file_path)); |
|
| 103 | 103 | } |
| 104 | 104 | $flen = filesize($file_path); |
| 105 | 105 | $bc = fread($fh, $flen); |
| 106 | - for ($i=0; $i<$flen; $i++){ |
|
| 107 | - $c = substr($bc,$i,1); |
|
| 108 | - if ((ord($c) != 0) && (ord($c) != 13)){ |
|
| 109 | - $fc = $fc . $c; |
|
| 106 | + for ($i = 0; $i < $flen; $i++) { |
|
| 107 | + $c = substr($bc, $i, 1); |
|
| 108 | + if ((ord($c) != 0) && (ord($c) != 13)) { |
|
| 109 | + $fc = $fc.$c; |
|
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | - if ((ord(substr($fc,0,1)) == 255) && (ord(substr($fc,1,1)) == 254)) |
|
| 113 | - $fc = substr($fc,2); |
|
| 112 | + if ((ord(substr($fc, 0, 1)) == 255) && (ord(substr($fc, 1, 1)) == 254)) |
|
| 113 | + $fc = substr($fc, 2); |
|
| 114 | 114 | return ($fc); |
| 115 | 115 | } |
| 116 | 116 | |
@@ -122,15 +122,15 @@ discard block |
||
| 122 | 122 | * @param string $path_to_file |
| 123 | 123 | * @return array of arrays. Top-level array has rows, second-level array has each item |
| 124 | 124 | */ |
| 125 | - public function import_csv_to_multi_dimensional_array($path_to_file){ |
|
| 125 | + public function import_csv_to_multi_dimensional_array($path_to_file) { |
|
| 126 | 126 | // needed to deal with Mac line endings |
| 127 | - ini_set('auto_detect_line_endings',TRUE); |
|
| 127 | + ini_set('auto_detect_line_endings', TRUE); |
|
| 128 | 128 | |
| 129 | 129 | // because fgetcsv does not correctly deal with backslashed quotes such as \" |
| 130 | 130 | // we'll read the file into a string |
| 131 | - $file_contents = $this->read_unicode_file( $path_to_file ); |
|
| 131 | + $file_contents = $this->read_unicode_file($path_to_file); |
|
| 132 | 132 | // replace backslashed quotes with CSV enclosures |
| 133 | - $file_contents = str_replace ( '\\"', '"""', $file_contents ); |
|
| 133 | + $file_contents = str_replace('\\"', '"""', $file_contents); |
|
| 134 | 134 | // HEY YOU! PUT THAT FILE BACK!!! |
| 135 | 135 | file_put_contents($path_to_file, $file_contents); |
| 136 | 136 | |
@@ -140,25 +140,25 @@ discard block |
||
| 140 | 140 | $csvarray = array(); |
| 141 | 141 | |
| 142 | 142 | // in PHP 5.3 fgetcsv accepts a 5th parameter, but the pre 5.3 versions of fgetcsv choke if passed more than 4 - is that crazy or what? |
| 143 | - if ( version_compare( PHP_VERSION, '5.3.0' ) < 0 ) { |
|
| 143 | + if (version_compare(PHP_VERSION, '5.3.0') < 0) { |
|
| 144 | 144 | |
| 145 | 145 | // PHP 5.2- version |
| 146 | 146 | |
| 147 | 147 | // loop through each row of the file |
| 148 | - while(($data = fgetcsv($file_handle, 0, ',', '"' )) !== FALSE){ |
|
| 149 | - $csvarray[]= $data; |
|
| 148 | + while (($data = fgetcsv($file_handle, 0, ',', '"')) !== FALSE) { |
|
| 149 | + $csvarray[] = $data; |
|
| 150 | 150 | } |
| 151 | - }else{ |
|
| 151 | + } else { |
|
| 152 | 152 | // loop through each row of the file |
| 153 | - while (( $data = fgetcsv( $file_handle, 0, ',', '"', '\\' )) !== FALSE ) { |
|
| 154 | - $csvarray[]=$data; |
|
| 153 | + while (($data = fgetcsv($file_handle, 0, ',', '"', '\\')) !== FALSE) { |
|
| 154 | + $csvarray[] = $data; |
|
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | 157 | # Close the File. |
| 158 | 158 | fclose($file_handle); |
| 159 | 159 | return $csvarray; |
| 160 | - }else{ |
|
| 161 | - EE_Error::add_error( sprintf(__("An error occurred - the file: %s could not opened.", "event_espresso"),$path_to_file), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 160 | + } else { |
|
| 161 | + EE_Error::add_error(sprintf(__("An error occurred - the file: %s could not opened.", "event_espresso"), $path_to_file), __FILE__, __FUNCTION__, __LINE__); |
|
| 162 | 162 | return false; |
| 163 | 163 | } |
| 164 | 164 | } |
@@ -188,9 +188,9 @@ discard block |
||
| 188 | 188 | * ... |
| 189 | 189 | * ) |
| 190 | 190 | */ |
| 191 | - public function import_csv_to_model_data_array( $path_to_file, $model_name = FALSE, $first_row_is_headers = TRUE ) { |
|
| 191 | + public function import_csv_to_model_data_array($path_to_file, $model_name = FALSE, $first_row_is_headers = TRUE) { |
|
| 192 | 192 | $multi_dimensional_array = $this->import_csv_to_multi_dimensional_array($path_to_file); |
| 193 | - if( ! $multi_dimensional_array ){ |
|
| 193 | + if ( ! $multi_dimensional_array) { |
|
| 194 | 194 | return false; |
| 195 | 195 | } |
| 196 | 196 | // gotta start somewhere |
@@ -199,9 +199,9 @@ discard block |
||
| 199 | 199 | $ee_formatted_data = array(); |
| 200 | 200 | // array to store headers (column names) |
| 201 | 201 | $headers = array(); |
| 202 | - foreach($multi_dimensional_array as $data){ |
|
| 202 | + foreach ($multi_dimensional_array as $data) { |
|
| 203 | 203 | // if first cell is MODEL, then second cell is the MODEL name |
| 204 | - if ( $data[0] == 'MODEL' ) { |
|
| 204 | + if ($data[0] == 'MODEL') { |
|
| 205 | 205 | $model_name = $data[1]; |
| 206 | 206 | //don't bother looking for model data in this row. The rest of this |
| 207 | 207 | //row should be blank |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | $headers = array(); |
| 212 | 212 | continue; |
| 213 | 213 | } |
| 214 | - if( strpos( $data[0], EE_CSV::metadata_header ) !==FALSE ){ |
|
| 214 | + if (strpos($data[0], EE_CSV::metadata_header) !== FALSE) { |
|
| 215 | 215 | $model_name = EE_CSV::metadata_header; |
| 216 | 216 | //store like model data, we just won't try importing it etc. |
| 217 | 217 | $row = 1; |
@@ -224,31 +224,31 @@ discard block |
||
| 224 | 224 | |
| 225 | 225 | $model_entry = array(); |
| 226 | 226 | // loop through each column |
| 227 | - for ( $i=0; $i < $columns; $i++ ) { |
|
| 227 | + for ($i = 0; $i < $columns; $i++) { |
|
| 228 | 228 | |
| 229 | 229 | //replace csv_enclosures with backslashed quotes |
| 230 | - $data[$i] = str_replace ( '"""', '\\"', $data[$i] ); |
|
| 230 | + $data[$i] = str_replace('"""', '\\"', $data[$i]); |
|
| 231 | 231 | // do we need to grab the column names? |
| 232 | - if ( $row === 1){ |
|
| 233 | - if( $first_row_is_headers ) { |
|
| 232 | + if ($row === 1) { |
|
| 233 | + if ($first_row_is_headers) { |
|
| 234 | 234 | // store the column names to use for keys |
| 235 | 235 | $column_name = $data[$i]; |
| 236 | 236 | //check it's not blank... sometimes CSV editign programs adda bunch of empty columns onto the end... |
| 237 | - if(!$column_name){continue;} |
|
| 237 | + if ( ! $column_name) {continue; } |
|
| 238 | 238 | $matches = array(); |
| 239 | - if($model_name == EE_CSV::metadata_header){ |
|
| 239 | + if ($model_name == EE_CSV::metadata_header) { |
|
| 240 | 240 | $headers[$i] = $column_name; |
| 241 | - }else{ |
|
| 241 | + } else { |
|
| 242 | 242 | //now get the db table name from it (the part between square brackets) |
| 243 | - $success = preg_match('~(.*)\[(.*)\]~', $column_name,$matches); |
|
| 244 | - if (!$success){ |
|
| 245 | - EE_Error::add_error( sprintf(__("The column titled %s is invalid for importing. It must be be in the format of 'Nice Name[model_field_name]' in row %s", "event_espresso"),$column_name,implode(",",$data)), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 243 | + $success = preg_match('~(.*)\[(.*)\]~', $column_name, $matches); |
|
| 244 | + if ( ! $success) { |
|
| 245 | + EE_Error::add_error(sprintf(__("The column titled %s is invalid for importing. It must be be in the format of 'Nice Name[model_field_name]' in row %s", "event_espresso"), $column_name, implode(",", $data)), __FILE__, __FUNCTION__, __LINE__); |
|
| 246 | 246 | return false; |
| 247 | 247 | } |
| 248 | 248 | $headers[$i] = $matches[2]; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | - }else{ |
|
| 251 | + } else { |
|
| 252 | 252 | // no column names means our final array will just use counters for keys |
| 253 | 253 | $model_entry[$headers[$i]] = $data[$i]; |
| 254 | 254 | $headers[$i] = $i; |
@@ -256,14 +256,14 @@ discard block |
||
| 256 | 256 | // and we need to store csv data |
| 257 | 257 | } else { |
| 258 | 258 | // this column isn' ta header, store it if there is a header for it |
| 259 | - if(isset($headers[$i])){ |
|
| 259 | + if (isset($headers[$i])) { |
|
| 260 | 260 | $model_entry[$headers[$i]] = $data[$i]; |
| 261 | 261 | } |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | } |
| 265 | 265 | //save the row's data IF it's a non-header-row |
| 266 | - if( ! $first_row_is_headers || ($first_row_is_headers && $row > 1)){ |
|
| 266 | + if ( ! $first_row_is_headers || ($first_row_is_headers && $row > 1)) { |
|
| 267 | 267 | $ee_formatted_data[$model_name][] = $model_entry; |
| 268 | 268 | } |
| 269 | 269 | // advance to next row |
@@ -282,9 +282,9 @@ discard block |
||
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | |
| 285 | - public function save_csv_to_db( $csv_data_array, $model_name = FALSE ) { |
|
| 286 | - EE_Error::doing_it_wrong('save_csv_to_db', __( 'Function moved to EE_Import and renamed to save_csv_data_array_to_db', 'event_espresso' ), '4.6.7' ); |
|
| 287 | - return EE_Import::instance()->save_csv_data_array_to_db( $csv_data_array, $model_name ); |
|
| 285 | + public function save_csv_to_db($csv_data_array, $model_name = FALSE) { |
|
| 286 | + EE_Error::doing_it_wrong('save_csv_to_db', __('Function moved to EE_Import and renamed to save_csv_data_array_to_db', 'event_espresso'), '4.6.7'); |
|
| 287 | + return EE_Import::instance()->save_csv_data_array_to_db($csv_data_array, $model_name); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -294,11 +294,11 @@ discard block |
||
| 294 | 294 | * @param string $new_filename the name of the file that the user will download |
| 295 | 295 | * @return resource, like the results of fopen(), which can be used for fwrite, fputcsv2, etc. |
| 296 | 296 | */ |
| 297 | - public function begin_sending_csv($filename){ |
|
| 297 | + public function begin_sending_csv($filename) { |
|
| 298 | 298 | // grab file extension |
| 299 | 299 | $ext = substr(strrchr($filename, '.'), 1); |
| 300 | - if ( $ext == '.csv' or $ext == '.xls' ) { |
|
| 301 | - str_replace( $ext, '', $filename ); |
|
| 300 | + if ($ext == '.csv' or $ext == '.xls') { |
|
| 301 | + str_replace($ext, '', $filename); |
|
| 302 | 302 | } |
| 303 | 303 | $filename .= '.csv'; |
| 304 | 304 | |
@@ -319,8 +319,8 @@ discard block |
||
| 319 | 319 | // header("Content-Type: application/download"); |
| 320 | 320 | header('Content-disposition: attachment; filename='.$filename); |
| 321 | 321 | header("Content-Type: text/csv; charset=utf-8"); |
| 322 | - do_action( 'AHEE__EE_CSV__begin_sending_csv__headers' ); |
|
| 323 | - echo apply_filters('FHEE__EE_CSV__begin_sending_csv__start_writing', "\xEF\xBB\xBF" ); // makes excel open it as UTF-8. UTF-8 BOM, see http://stackoverflow.com/a/4440143/2773835 |
|
| 322 | + do_action('AHEE__EE_CSV__begin_sending_csv__headers'); |
|
| 323 | + echo apply_filters('FHEE__EE_CSV__begin_sending_csv__start_writing', "\xEF\xBB\xBF"); // makes excel open it as UTF-8. UTF-8 BOM, see http://stackoverflow.com/a/4440143/2773835 |
|
| 324 | 324 | $fh = fopen('php://output', 'w'); |
| 325 | 325 | return $fh; |
| 326 | 326 | } |
@@ -330,10 +330,10 @@ discard block |
||
| 330 | 330 | * mentioning the version and timezone |
| 331 | 331 | * @param resource $filehandle |
| 332 | 332 | */ |
| 333 | - public function write_metadata_to_csv($filehandle){ |
|
| 334 | - $data_row = array(EE_CSV::metadata_header);//do NOT translate because this exact string is used when importing |
|
| 333 | + public function write_metadata_to_csv($filehandle) { |
|
| 334 | + $data_row = array(EE_CSV::metadata_header); //do NOT translate because this exact string is used when importing |
|
| 335 | 335 | $this->fputcsv2($filehandle, $data_row); |
| 336 | - $meta_data = array( 0=> array( |
|
| 336 | + $meta_data = array(0=> array( |
|
| 337 | 337 | 'version'=>espresso_version(), |
| 338 | 338 | 'timezone'=> EEH_DTT_Helper::get_timezone(), |
| 339 | 339 | 'time_of_export'=>current_time('mysql'), |
@@ -351,29 +351,29 @@ discard block |
||
| 351 | 351 | * then the first row we'd write to the CSV would be "EVT_ID,EVT_name,..." |
| 352 | 352 | * @return boolean if we successfully wrote to the CSV or not. If there's no $data, we consider that a success (because we wrote everything there was...nothing) |
| 353 | 353 | */ |
| 354 | - public function write_data_array_to_csv($filehandle, $data){ |
|
| 354 | + public function write_data_array_to_csv($filehandle, $data) { |
|
| 355 | 355 | |
| 356 | 356 | |
| 357 | 357 | //determine if $data is actually a 2d array |
| 358 | - if ( $data && is_array($data) && is_array(EEH_Array::get_one_item_from_array($data))){ |
|
| 358 | + if ($data && is_array($data) && is_array(EEH_Array::get_one_item_from_array($data))) { |
|
| 359 | 359 | //make sure top level is numerically indexed, |
| 360 | 360 | |
| 361 | - if( EEH_Array::is_associative_array($data)){ |
|
| 362 | - throw new EE_Error(sprintf(__("top-level array must be numerically indexed. Does these look like numbers to you? %s","event_espresso"),implode(",",array_keys($data)))); |
|
| 361 | + if (EEH_Array::is_associative_array($data)) { |
|
| 362 | + throw new EE_Error(sprintf(__("top-level array must be numerically indexed. Does these look like numbers to you? %s", "event_espresso"), implode(",", array_keys($data)))); |
|
| 363 | 363 | } |
| 364 | 364 | $item_in_top_level_array = EEH_Array::get_one_item_from_array($data); |
| 365 | 365 | //now, is the last item in the top-level array of $data an associative or numeric array? |
| 366 | - if(EEH_Array::is_associative_array($item_in_top_level_array)){ |
|
| 366 | + if (EEH_Array::is_associative_array($item_in_top_level_array)) { |
|
| 367 | 367 | //its associative, so we want to output its keys as column headers |
| 368 | 368 | $keys = array_keys($item_in_top_level_array); |
| 369 | 369 | echo $this->fputcsv2($filehandle, $keys); |
| 370 | 370 | } |
| 371 | 371 | //start writing data |
| 372 | - foreach($data as $data_row){ |
|
| 372 | + foreach ($data as $data_row) { |
|
| 373 | 373 | echo $this->fputcsv2($filehandle, $data_row); |
| 374 | 374 | } |
| 375 | 375 | return true; |
| 376 | - }else{ |
|
| 376 | + } else { |
|
| 377 | 377 | //no data TO write... so we can assume that's a success |
| 378 | 378 | return true; |
| 379 | 379 | } |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | * Calls exit to prevent polluting the CSV file with other junk |
| 419 | 419 | * @param resource $fh filehandle where we're writing the CSV to |
| 420 | 420 | */ |
| 421 | - public function end_sending_csv($fh){ |
|
| 421 | + public function end_sending_csv($fh) { |
|
| 422 | 422 | fclose($fh); |
| 423 | 423 | exit(0); |
| 424 | 424 | } |
@@ -431,23 +431,23 @@ discard block |
||
| 431 | 431 | * has all the attributes o fthat model object (eg, the event's id, name, etc) |
| 432 | 432 | * @return boolean success |
| 433 | 433 | */ |
| 434 | - public function write_model_data_to_csv($filehandle,$model_data_array){ |
|
| 434 | + public function write_model_data_to_csv($filehandle, $model_data_array) { |
|
| 435 | 435 | $this->write_metadata_to_csv($filehandle); |
| 436 | - foreach($model_data_array as $model_name => $model_instance_arrays){ |
|
| 436 | + foreach ($model_data_array as $model_name => $model_instance_arrays) { |
|
| 437 | 437 | //first: output a special row stating the model |
| 438 | - echo $this->fputcsv2($filehandle,array('MODEL',$model_name)); |
|
| 438 | + echo $this->fputcsv2($filehandle, array('MODEL', $model_name)); |
|
| 439 | 439 | //if we have items to put in the CSV, do it normally |
| 440 | 440 | |
| 441 | - if( ! empty($model_instance_arrays) ){ |
|
| 441 | + if ( ! empty($model_instance_arrays)) { |
|
| 442 | 442 | $this->write_data_array_to_csv($filehandle, $model_instance_arrays); |
| 443 | - }else{ |
|
| 443 | + } else { |
|
| 444 | 444 | // echo "no data to write... so just write the headers"; |
| 445 | 445 | //so there's actually NO model objects for that model. |
| 446 | 446 | //probably still want to show the columns |
| 447 | 447 | $model = EE_Registry::instance()->load_model($model_name); |
| 448 | 448 | $column_names = array(); |
| 449 | - foreach($model->field_settings() as $field){ |
|
| 450 | - $column_names[$field->get_nicename()."[".$field->get_name()."]"] = null ; |
|
| 449 | + foreach ($model->field_settings() as $field) { |
|
| 450 | + $column_names[$field->get_nicename()."[".$field->get_name()."]"] = null; |
|
| 451 | 451 | } |
| 452 | 452 | $this->write_data_array_to_csv($filehandle, array($column_names)); |
| 453 | 453 | } |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | * @param array $model_data_array 3d array, as described in EE_CSV::write_model_data_to_csv() |
| 462 | 462 | * @return bool | void writes CSV file to output and dies |
| 463 | 463 | */ |
| 464 | - public function export_multiple_model_data_to_csv($filename,$model_data_array){ |
|
| 464 | + public function export_multiple_model_data_to_csv($filename, $model_data_array) { |
|
| 465 | 465 | $filehandle = $this->begin_sending_csv($filename); |
| 466 | 466 | $this->write_model_data_to_csv($filehandle, $model_data_array); |
| 467 | 467 | $this->end_sending_csv($filehandle); |
@@ -473,15 +473,15 @@ discard block |
||
| 473 | 473 | * @param string $filename - name for newly created csv file |
| 474 | 474 | * @return TRUE on success, FALSE on fail |
| 475 | 475 | */ |
| 476 | - public function export_array_to_csv( $data = FALSE, $filename = FALSE ) { |
|
| 476 | + public function export_array_to_csv($data = FALSE, $filename = FALSE) { |
|
| 477 | 477 | |
| 478 | 478 | // no data file?? get outta here |
| 479 | - if ( ! $data or ! is_array( $data ) or empty( $data ) ) { |
|
| 479 | + if ( ! $data or ! is_array($data) or empty($data)) { |
|
| 480 | 480 | return FALSE; |
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | // no filename?? get outta here |
| 484 | - if ( ! $filename ) { |
|
| 484 | + if ( ! $filename) { |
|
| 485 | 485 | return FALSE; |
| 486 | 486 | } |
| 487 | 487 | |
@@ -507,11 +507,11 @@ discard block |
||
| 507 | 507 | * @param int $percent_of_max - desired percentage of the max upload_mb |
| 508 | 508 | * @return int KB |
| 509 | 509 | */ |
| 510 | - public function get_max_upload_size ( $percent_of_max = FALSE ) { |
|
| 510 | + public function get_max_upload_size($percent_of_max = FALSE) { |
|
| 511 | 511 | |
| 512 | - $max_upload = (int)(ini_get('upload_max_filesize')); |
|
| 513 | - $max_post = (int)(ini_get('post_max_size')); |
|
| 514 | - $memory_limit = (int)(ini_get('memory_limit')); |
|
| 512 | + $max_upload = (int) (ini_get('upload_max_filesize')); |
|
| 513 | + $max_post = (int) (ini_get('post_max_size')); |
|
| 514 | + $memory_limit = (int) (ini_get('memory_limit')); |
|
| 515 | 515 | |
| 516 | 516 | // determine the smallest of the three values from above |
| 517 | 517 | $upload_mb = min($max_upload, $max_post, $memory_limit); |
@@ -520,9 +520,9 @@ discard block |
||
| 520 | 520 | $upload_mb = $upload_mb * 1024; |
| 521 | 521 | |
| 522 | 522 | // don't want the full monty? then reduce the max uplaod size |
| 523 | - if ( $percent_of_max ) { |
|
| 523 | + if ($percent_of_max) { |
|
| 524 | 524 | // is percent_of_max like this -> 50 or like this -> 0.50 ? |
| 525 | - if ( $percent_of_max > 1 ) { |
|
| 525 | + if ($percent_of_max > 1) { |
|
| 526 | 526 | // chnages 50 to 0.50 |
| 527 | 527 | $percent_of_max = $percent_of_max / 100; |
| 528 | 528 | } |
@@ -544,17 +544,17 @@ discard block |
||
| 544 | 544 | * @param string $mysql_null - allows php NULL to be overridden with MySQl's insertable NULL value |
| 545 | 545 | * @return void |
| 546 | 546 | */ |
| 547 | - private function fputcsv2 ($fh, array $row, $delimiter = ',', $enclosure = '"', $mysql_null = FALSE) { |
|
| 547 | + private function fputcsv2($fh, array $row, $delimiter = ',', $enclosure = '"', $mysql_null = FALSE) { |
|
| 548 | 548 | //Allow user to filter the csv delimiter and enclosure for other countries csv standards |
| 549 | - $delimiter = apply_filters( 'FHEE__EE_CSV__fputcsv2__delimiter', $delimiter ); |
|
| 550 | - $enclosure = apply_filters( 'FHEE__EE_CSV__fputcsv2__enclosure', $enclosure ); |
|
| 549 | + $delimiter = apply_filters('FHEE__EE_CSV__fputcsv2__delimiter', $delimiter); |
|
| 550 | + $enclosure = apply_filters('FHEE__EE_CSV__fputcsv2__enclosure', $enclosure); |
|
| 551 | 551 | |
| 552 | 552 | $delimiter_esc = preg_quote($delimiter, '/'); |
| 553 | 553 | $enclosure_esc = preg_quote($enclosure, '/'); |
| 554 | 554 | |
| 555 | 555 | $output = array(); |
| 556 | 556 | foreach ($row as $field_value) { |
| 557 | - if(is_object($field_value) || is_array($field_value)){ |
|
| 557 | + if (is_object($field_value) || is_array($field_value)) { |
|
| 558 | 558 | $field_value = serialize($field_value); |
| 559 | 559 | } |
| 560 | 560 | if ($field_value === null && $mysql_null) { |
@@ -563,10 +563,10 @@ discard block |
||
| 563 | 563 | } |
| 564 | 564 | |
| 565 | 565 | $output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field_value) ? |
| 566 | - ( $enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure ) : $field_value; |
|
| 566 | + ($enclosure.str_replace($enclosure, $enclosure.$enclosure, $field_value).$enclosure) : $field_value; |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | - fwrite($fh, join($delimiter, $output) . PHP_EOL); |
|
| 569 | + fwrite($fh, join($delimiter, $output).PHP_EOL); |
|
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | |
@@ -604,8 +604,8 @@ discard block |
||
| 604 | 604 | * @param string $current_format |
| 605 | 605 | * @return string |
| 606 | 606 | */ |
| 607 | - public function get_date_format_for_csv( $current_format = null ) { |
|
| 608 | - return apply_filters( 'FHEE__EE_CSV__get_date_format_for_csv__format', 'Y-m-d', $current_format ); |
|
| 607 | + public function get_date_format_for_csv($current_format = null) { |
|
| 608 | + return apply_filters('FHEE__EE_CSV__get_date_format_for_csv__format', 'Y-m-d', $current_format); |
|
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | /** |
@@ -613,8 +613,8 @@ discard block |
||
| 613 | 613 | * @param string $current_format |
| 614 | 614 | * @return string |
| 615 | 615 | */ |
| 616 | - public function get_time_format_for_csv( $current_format = null ) { |
|
| 617 | - return apply_filters( 'FHEE__EE_CSV__get_time_format_for_csv__format', 'H:i:s', $current_format ); |
|
| 616 | + public function get_time_format_for_csv($current_format = null) { |
|
| 617 | + return apply_filters('FHEE__EE_CSV__get_time_format_for_csv__format', 'H:i:s', $current_format); |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | |