@@ -146,43 +146,43 @@ discard block |
||
146 | 146 | if ( isset( $_REQUEST['import'] )) { |
147 | 147 | if( isset( $_POST['csv_submitted'] )) { |
148 | 148 | |
149 | - switch ( $_FILES['file']['error'][0] ) { |
|
150 | - case UPLOAD_ERR_OK: |
|
151 | - $error_msg = FALSE; |
|
152 | - break; |
|
153 | - case UPLOAD_ERR_INI_SIZE: |
|
154 | - $error_msg = __("'The uploaded file exceeds the upload_max_filesize directive in php.ini.'", "event_espresso"); |
|
155 | - break; |
|
156 | - case UPLOAD_ERR_FORM_SIZE: |
|
157 | - $error_msg = __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', "event_espresso"); |
|
158 | - break; |
|
159 | - case UPLOAD_ERR_PARTIAL: |
|
160 | - $error_msg = __('The uploaded file was only partially uploaded.', "event_espresso"); |
|
161 | - break; |
|
162 | - case UPLOAD_ERR_NO_FILE: |
|
163 | - $error_msg = __('No file was uploaded.', "event_espresso"); |
|
164 | - break; |
|
165 | - case UPLOAD_ERR_NO_TMP_DIR: |
|
166 | - $error_msg = __('Missing a temporary folder.', "event_espresso"); |
|
167 | - break; |
|
168 | - case UPLOAD_ERR_CANT_WRITE: |
|
169 | - $error_msg = __('Failed to write file to disk.', "event_espresso"); |
|
170 | - break; |
|
171 | - case UPLOAD_ERR_EXTENSION: |
|
172 | - $error_msg = __('File upload stopped by extension.', "event_espresso"); |
|
173 | - break; |
|
174 | - default: |
|
175 | - $error_msg = __('An unknown error occurred and the file could not be uploaded', "event_espresso"); |
|
176 | - break; |
|
177 | - } |
|
149 | + switch ( $_FILES['file']['error'][0] ) { |
|
150 | + case UPLOAD_ERR_OK: |
|
151 | + $error_msg = FALSE; |
|
152 | + break; |
|
153 | + case UPLOAD_ERR_INI_SIZE: |
|
154 | + $error_msg = __("'The uploaded file exceeds the upload_max_filesize directive in php.ini.'", "event_espresso"); |
|
155 | + break; |
|
156 | + case UPLOAD_ERR_FORM_SIZE: |
|
157 | + $error_msg = __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', "event_espresso"); |
|
158 | + break; |
|
159 | + case UPLOAD_ERR_PARTIAL: |
|
160 | + $error_msg = __('The uploaded file was only partially uploaded.', "event_espresso"); |
|
161 | + break; |
|
162 | + case UPLOAD_ERR_NO_FILE: |
|
163 | + $error_msg = __('No file was uploaded.', "event_espresso"); |
|
164 | + break; |
|
165 | + case UPLOAD_ERR_NO_TMP_DIR: |
|
166 | + $error_msg = __('Missing a temporary folder.', "event_espresso"); |
|
167 | + break; |
|
168 | + case UPLOAD_ERR_CANT_WRITE: |
|
169 | + $error_msg = __('Failed to write file to disk.', "event_espresso"); |
|
170 | + break; |
|
171 | + case UPLOAD_ERR_EXTENSION: |
|
172 | + $error_msg = __('File upload stopped by extension.', "event_espresso"); |
|
173 | + break; |
|
174 | + default: |
|
175 | + $error_msg = __('An unknown error occurred and the file could not be uploaded', "event_espresso"); |
|
176 | + break; |
|
177 | + } |
|
178 | 178 | |
179 | 179 | if ( ! $error_msg ) { |
180 | 180 | |
181 | - $filename = $_FILES['file']['name'][0]; |
|
181 | + $filename = $_FILES['file']['name'][0]; |
|
182 | 182 | $file_ext = substr( strrchr( $filename, '.' ), 1 ); |
183 | - //$file_type = $_FILES['file']['type'][0]; |
|
184 | - $temp_file = $_FILES['file']['tmp_name'][0]; |
|
185 | - $filesize = $_FILES['file']['size'][0] / 1024;//convert from bytes to KB |
|
183 | + //$file_type = $_FILES['file']['type'][0]; |
|
184 | + $temp_file = $_FILES['file']['tmp_name'][0]; |
|
185 | + $filesize = $_FILES['file']['size'][0] / 1024;//convert from bytes to KB |
|
186 | 186 | |
187 | 187 | if ( $file_ext=='csv' ) { |
188 | 188 | |
@@ -331,10 +331,10 @@ discard block |
||
331 | 331 | unset($csv_data_array[EE_CSV::metadata_header]); |
332 | 332 | } |
333 | 333 | /** |
334 | - * @var $old_db_to_new_db_mapping 2d array: top level keys being model names, bottom-level keys being the original key, and |
|
335 | - * the value will be the newly-inserted ID. |
|
336 | - * If we have already imported data from the same website via CSV, it should be kept in this wp option |
|
337 | - */ |
|
334 | + * @var $old_db_to_new_db_mapping 2d array: top level keys being model names, bottom-level keys being the original key, and |
|
335 | + * the value will be the newly-inserted ID. |
|
336 | + * If we have already imported data from the same website via CSV, it should be kept in this wp option |
|
337 | + */ |
|
338 | 338 | $old_db_to_new_db_mapping = get_option('ee_id_mapping_from'.sanitize_title($old_site_url),array()); |
339 | 339 | if( $old_db_to_new_db_mapping){ |
340 | 340 | EE_Error::add_attention( |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | foreach($model_object_data as $field){ |
436 | 436 | if($field){ |
437 | 437 | $row_is_completely_empty = false; |
438 | - break; |
|
438 | + break; |
|
439 | 439 | } |
440 | 440 | } |
441 | 441 | if($row_is_completely_empty){ |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | |
454 | 454 | |
455 | 455 | $model_object_data = $this->_replace_temp_ids_with_mappings( $model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b ); |
456 | - $model_object_data = $this->_prepare_data_for_use_in_db( $model_object_data, $model, $export_from_site_a_to_b ); |
|
456 | + $model_object_data = $this->_prepare_data_for_use_in_db( $model_object_data, $model, $export_from_site_a_to_b ); |
|
457 | 457 | //now we need to decide if we're going to add a new model object given the $model_object_data, |
458 | 458 | //or just update. |
459 | 459 | if($export_from_site_a_to_b){ |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
2 | -do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
2 | +do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
3 | 3 | /** |
4 | 4 | * EE_Import class |
5 | 5 | * |
@@ -69,10 +69,10 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public static function instance() { |
71 | 71 | // check if class object is instantiated |
72 | - if ( self::$_instance === NULL or ! is_object( self::$_instance ) or ! ( self::$_instance instanceof EE_Import )) { |
|
72 | + if (self::$_instance === NULL or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Import)) { |
|
73 | 73 | self::$_instance = new self(); |
74 | 74 | } |
75 | - add_filter( 'FHEE__EE_Import___replace_temp_ids_with_mappings__model_object_data__end', array( self::$_instance, 'handle_split_term_ids' ), 10, 2 ); |
|
75 | + add_filter('FHEE__EE_Import___replace_temp_ids_with_mappings__model_object_data__end', array(self::$_instance, 'handle_split_term_ids'), 10, 2); |
|
76 | 76 | return self::$_instance; |
77 | 77 | } |
78 | 78 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * Resets the importer |
81 | 81 | * @return EE_Import |
82 | 82 | */ |
83 | - public static function reset(){ |
|
83 | + public static function reset() { |
|
84 | 84 | self::$_instance = null; |
85 | 85 | return self::instance(); |
86 | 86 | } |
@@ -99,27 +99,27 @@ discard block |
||
99 | 99 | * |
100 | 100 | *@return string |
101 | 101 | */ |
102 | - public function upload_form ( $title, $intro, $form_url, $action, $type ) { |
|
102 | + public function upload_form($title, $intro, $form_url, $action, $type) { |
|
103 | 103 | |
104 | - $form_url = EE_Admin_Page::add_query_args_and_nonce( array( 'action' => $action ), $form_url ); |
|
104 | + $form_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => $action), $form_url); |
|
105 | 105 | |
106 | 106 | ob_start(); |
107 | 107 | ?> |
108 | 108 | <div class="ee-upload-form-dv"> |
109 | - <h3><?php echo $title;?></h3> |
|
110 | - <p><?php echo $intro;?></p> |
|
109 | + <h3><?php echo $title; ?></h3> |
|
110 | + <p><?php echo $intro; ?></p> |
|
111 | 111 | |
112 | 112 | <form action="<?php echo $form_url?>" method="post" enctype="multipart/form-data"> |
113 | - <input type="hidden" name="csv_submitted" value="TRUE" id="<?php echo time();?>"> |
|
114 | - <input name="import" type="hidden" value="<?php echo $type;?>" /> |
|
113 | + <input type="hidden" name="csv_submitted" value="TRUE" id="<?php echo time(); ?>"> |
|
114 | + <input name="import" type="hidden" value="<?php echo $type; ?>" /> |
|
115 | 115 | <input type="file" name="file[]" size="90" > |
116 | - <input class="button-primary" type="submit" value="<?php _e( 'Upload File', 'event_espresso' );?>"> |
|
116 | + <input class="button-primary" type="submit" value="<?php _e('Upload File', 'event_espresso'); ?>"> |
|
117 | 117 | </form> |
118 | 118 | |
119 | 119 | <p class="ee-attention"> |
120 | - <b><?php _e( 'Attention', 'event_espresso' );?></b><br/> |
|
121 | - <?php echo sprintf( __( 'Accepts .%s file types only.', 'event_espresso' ), $type ) ;?> |
|
122 | - <?php echo __( 'Please only import CSV files exported from Event Espresso, or compatible 3rd-party software.', 'event_espresso' );?> |
|
120 | + <b><?php _e('Attention', 'event_espresso'); ?></b><br/> |
|
121 | + <?php echo sprintf(__('Accepts .%s file types only.', 'event_espresso'), $type); ?> |
|
122 | + <?php echo __('Please only import CSV files exported from Event Espresso, or compatible 3rd-party software.', 'event_espresso'); ?> |
|
123 | 123 | </p> |
124 | 124 | |
125 | 125 | </div> |
@@ -140,13 +140,13 @@ discard block |
||
140 | 140 | */ |
141 | 141 | public function import() { |
142 | 142 | |
143 | - require_once( EE_CLASSES . 'EE_CSV.class.php' ); |
|
143 | + require_once(EE_CLASSES.'EE_CSV.class.php'); |
|
144 | 144 | $this->EE_CSV = EE_CSV::instance(); |
145 | 145 | $success = true; |
146 | - if ( isset( $_REQUEST['import'] )) { |
|
147 | - if( isset( $_POST['csv_submitted'] )) { |
|
146 | + if (isset($_REQUEST['import'])) { |
|
147 | + if (isset($_POST['csv_submitted'])) { |
|
148 | 148 | |
149 | - switch ( $_FILES['file']['error'][0] ) { |
|
149 | + switch ($_FILES['file']['error'][0]) { |
|
150 | 150 | case UPLOAD_ERR_OK: |
151 | 151 | $error_msg = FALSE; |
152 | 152 | break; |
@@ -176,29 +176,29 @@ discard block |
||
176 | 176 | break; |
177 | 177 | } |
178 | 178 | |
179 | - if ( ! $error_msg ) { |
|
179 | + if ( ! $error_msg) { |
|
180 | 180 | |
181 | - $filename = $_FILES['file']['name'][0]; |
|
182 | - $file_ext = substr( strrchr( $filename, '.' ), 1 ); |
|
181 | + $filename = $_FILES['file']['name'][0]; |
|
182 | + $file_ext = substr(strrchr($filename, '.'), 1); |
|
183 | 183 | //$file_type = $_FILES['file']['type'][0]; |
184 | - $temp_file = $_FILES['file']['tmp_name'][0]; |
|
185 | - $filesize = $_FILES['file']['size'][0] / 1024;//convert from bytes to KB |
|
184 | + $temp_file = $_FILES['file']['tmp_name'][0]; |
|
185 | + $filesize = $_FILES['file']['size'][0] / 1024; //convert from bytes to KB |
|
186 | 186 | |
187 | - if ( $file_ext=='csv' ) { |
|
187 | + if ($file_ext == 'csv') { |
|
188 | 188 | |
189 | - $max_upload = $this->EE_CSV->get_max_upload_size();//max upload size in KB |
|
190 | - if ( $filesize < $max_upload || true) { |
|
189 | + $max_upload = $this->EE_CSV->get_max_upload_size(); //max upload size in KB |
|
190 | + if ($filesize < $max_upload || true) { |
|
191 | 191 | |
192 | - $wp_upload_dir = str_replace( array( '\\', '/' ), DS, wp_upload_dir()); |
|
193 | - $path_to_file = $wp_upload_dir['basedir'] . DS . 'espresso' . DS . $filename; |
|
192 | + $wp_upload_dir = str_replace(array('\\', '/'), DS, wp_upload_dir()); |
|
193 | + $path_to_file = $wp_upload_dir['basedir'].DS.'espresso'.DS.$filename; |
|
194 | 194 | |
195 | - if( move_uploaded_file( $temp_file, $path_to_file )) { |
|
195 | + if (move_uploaded_file($temp_file, $path_to_file)) { |
|
196 | 196 | // convert csv to array |
197 | - $this->csv_array = $this->EE_CSV->import_csv_to_model_data_array( $path_to_file ); |
|
197 | + $this->csv_array = $this->EE_CSV->import_csv_to_model_data_array($path_to_file); |
|
198 | 198 | // was data successfully stored in an array? |
199 | - if ( is_array( $this->csv_array ) ) { |
|
199 | + if (is_array($this->csv_array)) { |
|
200 | 200 | // save processed codes to db |
201 | - if ( $this->save_csv_data_array_to_db( $this->csv_array, false ) ) { |
|
201 | + if ($this->save_csv_data_array_to_db($this->csv_array, false)) { |
|
202 | 202 | $success = TRUE; |
203 | 203 | } |
204 | 204 | } else { |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | } |
246 | 246 | |
247 | 247 | } else { |
248 | - $this->_add_general_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
248 | + $this->_add_general_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
249 | 249 | $success = FALSE; |
250 | 250 | } |
251 | 251 | |
@@ -288,14 +288,14 @@ discard block |
||
288 | 288 | * @param bool | string $model_name - an array containing the csv column names as keys with the corresponding db table fields they will be saved to |
289 | 289 | * @return TRUE on success, FALSE on fail |
290 | 290 | */ |
291 | - public function save_csv_data_array_to_db( $csv_data_array, $model_name = FALSE ) { |
|
291 | + public function save_csv_data_array_to_db($csv_data_array, $model_name = FALSE) { |
|
292 | 292 | |
293 | 293 | //whether to treat this import as if it's data from a different database or not |
294 | 294 | //ie, if it IS from a different database, ignore foreign keys |
295 | 295 | $export_from_site_a_to_b = true; |
296 | 296 | // first level of array is not table information but a table name was passed to the function |
297 | 297 | // array is only two levels deep, so let's fix that by adding a level, else the next steps will fail |
298 | - if($model_name){ |
|
298 | + if ($model_name) { |
|
299 | 299 | $csv_data_array = array($csv_data_array); |
300 | 300 | } |
301 | 301 | //what models we want to update |
@@ -309,14 +309,14 @@ discard block |
||
309 | 309 | $old_site_url = site_url(); |
310 | 310 | |
311 | 311 | //handle metadata |
312 | - if(isset($csv_data_array[EE_CSV::metadata_header]) ){ |
|
312 | + if (isset($csv_data_array[EE_CSV::metadata_header])) { |
|
313 | 313 | $this->_csv_import_metadata_row = array_shift($csv_data_array[EE_CSV::metadata_header]); |
314 | 314 | //ok so its metadata, dont try to save it to the db obviously... |
315 | - if(isset($this->_csv_import_metadata_row['site_url']) && $this->_csv_import_metadata_row['site_url'] == site_url()){ |
|
316 | - EE_Error::add_attention( __("CSV Data appears to be from the same database, so attempting to update data", "event_espresso") ); |
|
315 | + if (isset($this->_csv_import_metadata_row['site_url']) && $this->_csv_import_metadata_row['site_url'] == site_url()) { |
|
316 | + EE_Error::add_attention(__("CSV Data appears to be from the same database, so attempting to update data", "event_espresso")); |
|
317 | 317 | $export_from_site_a_to_b = false; |
318 | - }else{ |
|
319 | - $old_site_url = isset( $this->_csv_import_metadata_row['site_url']) ? $this->_csv_import_metadata_row['site_url'] : $old_site_url; |
|
318 | + } else { |
|
319 | + $old_site_url = isset($this->_csv_import_metadata_row['site_url']) ? $this->_csv_import_metadata_row['site_url'] : $old_site_url; |
|
320 | 320 | EE_Error::add_attention( |
321 | 321 | sprintf( |
322 | 322 | __('CSV Data appears to be from a different database (%1$s instead of %2$s), so we assume IDs in the CSV data DO NOT correspond to IDs in this database', "event_espresso"), |
@@ -325,8 +325,8 @@ discard block |
||
325 | 325 | ) |
326 | 326 | ); |
327 | 327 | }; |
328 | - if( ! empty( $this->_csv_import_metadata_row['models_to_update'] )){ |
|
329 | - $models_to_update = explode(",", $this->_csv_import_metadata_row['models_to_update' ] ); |
|
328 | + if ( ! empty($this->_csv_import_metadata_row['models_to_update'])) { |
|
329 | + $models_to_update = explode(",", $this->_csv_import_metadata_row['models_to_update']); |
|
330 | 330 | } |
331 | 331 | unset($csv_data_array[EE_CSV::metadata_header]); |
332 | 332 | } |
@@ -335,8 +335,8 @@ discard block |
||
335 | 335 | * the value will be the newly-inserted ID. |
336 | 336 | * If we have already imported data from the same website via CSV, it should be kept in this wp option |
337 | 337 | */ |
338 | - $old_db_to_new_db_mapping = get_option('ee_id_mapping_from'.sanitize_title($old_site_url),array()); |
|
339 | - if( $old_db_to_new_db_mapping){ |
|
338 | + $old_db_to_new_db_mapping = get_option('ee_id_mapping_from'.sanitize_title($old_site_url), array()); |
|
339 | + if ($old_db_to_new_db_mapping) { |
|
340 | 340 | EE_Error::add_attention( |
341 | 341 | sprintf( |
342 | 342 | __('We noticed you have imported data via CSV from %1$s before. Because of this, IDs in your CSV have been mapped to their new IDs in %2$s', "event_espresso"), |
@@ -345,23 +345,23 @@ discard block |
||
345 | 345 | ) |
346 | 346 | ); |
347 | 347 | } |
348 | - $old_db_to_new_db_mapping = $this->save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping, $models_to_update ); |
|
348 | + $old_db_to_new_db_mapping = $this->save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping, $models_to_update); |
|
349 | 349 | |
350 | 350 | //save the mapping from old db to new db in case they try re-importing the same data from the same website again |
351 | - update_option('ee_id_mapping_from'.sanitize_title($old_site_url),$old_db_to_new_db_mapping); |
|
351 | + update_option('ee_id_mapping_from'.sanitize_title($old_site_url), $old_db_to_new_db_mapping); |
|
352 | 352 | |
353 | 353 | |
354 | 354 | //lastly, we need to update the datetime and ticket sold amounts |
355 | 355 | //as those may have been affected by this |
356 | - EEM_Datetime::instance()->update_sold( EEM_Datetime::instance()->get_all() ); |
|
356 | + EEM_Datetime::instance()->update_sold(EEM_Datetime::instance()->get_all()); |
|
357 | 357 | EEM_Ticket::instance()->update_tickets_sold(EEM_Ticket::instance()->get_all()); |
358 | 358 | |
359 | 359 | // if there was at least one success and absolutely no errors |
360 | - if ( ! $this->get_total_general_errors() && |
|
361 | - ! $this->get_total_insert_errors() && |
|
360 | + if ( ! $this->get_total_general_errors() && |
|
361 | + ! $this->get_total_insert_errors() && |
|
362 | 362 | ! $this->get_total_update_errors() && |
363 | 363 | $this->get_total_inserts() && |
364 | - $this->get_total_updates() ) { |
|
364 | + $this->get_total_updates()) { |
|
365 | 365 | return TRUE; |
366 | 366 | } else { |
367 | 367 | return FALSE; |
@@ -401,23 +401,23 @@ discard block |
||
401 | 401 | * @return array updated $old_db_to_new_db_mapping |
402 | 402 | * @throws \EE_Error |
403 | 403 | */ |
404 | - public function save_data_rows_to_db( $csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping, $models_to_update = NULL ) { |
|
405 | - foreach ( $csv_data_array as $model_name_in_csv_data => $model_data_from_import ) { |
|
404 | + public function save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping, $models_to_update = NULL) { |
|
405 | + foreach ($csv_data_array as $model_name_in_csv_data => $model_data_from_import) { |
|
406 | 406 | //now check that assumption was correct. If |
407 | - if ( EE_Registry::instance()->is_model_name($model_name_in_csv_data)) { |
|
407 | + if (EE_Registry::instance()->is_model_name($model_name_in_csv_data)) { |
|
408 | 408 | $model_name = $model_name_in_csv_data; |
409 | - }elseif( empty( $model_name_in_csv_data ) ) { |
|
409 | + }elseif (empty($model_name_in_csv_data)) { |
|
410 | 410 | // no table info in the array and no table name passed to the function?? FAIL |
411 | 411 | $this->_add_general_error( |
412 | - __('No table information was specified and/or found, therefore the import could not be completed','event_espresso'), |
|
412 | + __('No table information was specified and/or found, therefore the import could not be completed', 'event_espresso'), |
|
413 | 413 | __FILE__, __FUNCTION__, __LINE__ |
414 | 414 | ); |
415 | 415 | return FALSE; |
416 | - }else{ |
|
416 | + } else { |
|
417 | 417 | //what is this model name?? |
418 | 418 | $this->_add_general_error( |
419 | 419 | sprintf( |
420 | - __( 'The model "%1$s" is not recognized so its data cannot be imported', 'event_espresso' ), |
|
420 | + __('The model "%1$s" is not recognized so its data cannot be imported', 'event_espresso'), |
|
421 | 421 | $model_name_in_csv_data |
422 | 422 | ), |
423 | 423 | __FILE__, __FUNCTION__, __LINE__ |
@@ -429,77 +429,77 @@ discard block |
||
429 | 429 | $model = EE_Registry::instance()->load_model($model_name); |
430 | 430 | |
431 | 431 | //so without further ado, scanning all the data provided for primary keys and their inital values |
432 | - foreach ( $model_data_from_import as $model_object_data ) { |
|
432 | + foreach ($model_data_from_import as $model_object_data) { |
|
433 | 433 | //before we do ANYTHING, make sure the csv row wasn't just completely blank |
434 | 434 | $row_is_completely_empty = true; |
435 | - foreach($model_object_data as $field){ |
|
436 | - if($field){ |
|
435 | + foreach ($model_object_data as $field) { |
|
436 | + if ($field) { |
|
437 | 437 | $row_is_completely_empty = false; |
438 | 438 | break; |
439 | 439 | } |
440 | 440 | } |
441 | - if($row_is_completely_empty){ |
|
441 | + if ($row_is_completely_empty) { |
|
442 | 442 | continue; |
443 | 443 | } |
444 | 444 | //make sure there is no data for fields we don't recognize |
445 | - $model_object_data = array_intersect_key( $model_object_data, $model->field_settings() ); |
|
445 | + $model_object_data = array_intersect_key($model_object_data, $model->field_settings()); |
|
446 | 446 | //find the PK in the row of data (or a combined key if |
447 | 447 | //there is no primary key) |
448 | - if($model->has_primary_key_field()){ |
|
449 | - $id_in_csv = $model_object_data[$model->primary_key_name()]; |
|
450 | - }else{ |
|
448 | + if ($model->has_primary_key_field()) { |
|
449 | + $id_in_csv = $model_object_data[$model->primary_key_name()]; |
|
450 | + } else { |
|
451 | 451 | $id_in_csv = $model->get_index_primary_key_string($model_object_data); |
452 | 452 | } |
453 | 453 | |
454 | 454 | |
455 | - $model_object_data = $this->_replace_temp_ids_with_mappings( $model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b ); |
|
456 | - $model_object_data = $this->_prepare_data_for_use_in_db( $model_object_data, $model, $export_from_site_a_to_b ); |
|
455 | + $model_object_data = $this->_replace_temp_ids_with_mappings($model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b); |
|
456 | + $model_object_data = $this->_prepare_data_for_use_in_db($model_object_data, $model, $export_from_site_a_to_b); |
|
457 | 457 | //now we need to decide if we're going to add a new model object given the $model_object_data, |
458 | 458 | //or just update. |
459 | - if($export_from_site_a_to_b){ |
|
460 | - $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_other_db( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
|
461 | - }else{//this is just a re-import |
|
462 | - $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db( $id_in_csv, $model_object_data, $model ); |
|
459 | + if ($export_from_site_a_to_b) { |
|
460 | + $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_other_db($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping); |
|
461 | + } else {//this is just a re-import |
|
462 | + $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db($id_in_csv, $model_object_data, $model); |
|
463 | 463 | } |
464 | - if( $what_to_do == self::do_nothing ) { |
|
464 | + if ($what_to_do == self::do_nothing) { |
|
465 | 465 | continue; |
466 | 466 | } |
467 | 467 | |
468 | 468 | //double-check we actually want to insert, if that's what we're planning |
469 | 469 | //based on whether this item would be unique in the DB or not |
470 | - if( $what_to_do == self::do_insert ) { |
|
470 | + if ($what_to_do == self::do_insert) { |
|
471 | 471 | //we're supposed to be inserting. But wait, will this thing |
472 | 472 | //be acceptable if inserted? |
473 | - $conflicting = $model->get_one_conflicting( $model_object_data, false ); |
|
474 | - if($conflicting){ |
|
473 | + $conflicting = $model->get_one_conflicting($model_object_data, false); |
|
474 | + if ($conflicting) { |
|
475 | 475 | //ok, this item would conflict if inserted. Just update the item that it conflicts with. |
476 | 476 | $what_to_do = self::do_update; |
477 | 477 | //and if this model has a primary key, remember its mapping |
478 | - if($model->has_primary_key_field()){ |
|
478 | + if ($model->has_primary_key_field()) { |
|
479 | 479 | $old_db_to_new_db_mapping[$model_name][$id_in_csv] = $conflicting->ID(); |
480 | 480 | $model_object_data[$model->primary_key_name()] = $conflicting->ID(); |
481 | - }else{ |
|
481 | + } else { |
|
482 | 482 | //we want to update this conflicting item, instead of inserting a conflicting item |
483 | 483 | //so we need to make sure they match entirely (its possible that they only conflicted on one field, but we need them to match on other fields |
484 | 484 | //for the WHERE conditions in the update). At the time of this comment, there were no models like this |
485 | - foreach($model->get_combined_primary_key_fields() as $key_field){ |
|
485 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
486 | 486 | $model_object_data[$key_field->get_name()] = $conflicting->get($key_field->get_name()); |
487 | 487 | } |
488 | 488 | } |
489 | 489 | } |
490 | 490 | } |
491 | - if( $what_to_do == self::do_insert ) { |
|
492 | - $old_db_to_new_db_mapping = $this->_insert_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
|
493 | - }elseif( $what_to_do == self::do_update ) { |
|
494 | - if( $models_to_update === null || in_array( $model_name_in_csv_data, $models_to_update ) ){ |
|
495 | - $old_db_to_new_db_mapping = $this->_update_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
|
496 | - }else{ |
|
491 | + if ($what_to_do == self::do_insert) { |
|
492 | + $old_db_to_new_db_mapping = $this->_insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping); |
|
493 | + }elseif ($what_to_do == self::do_update) { |
|
494 | + if ($models_to_update === null || in_array($model_name_in_csv_data, $models_to_update)) { |
|
495 | + $old_db_to_new_db_mapping = $this->_update_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping); |
|
496 | + } else { |
|
497 | 497 | //we would have updated this, but the export data indicated we ought not |
498 | 498 | } |
499 | - }else{ |
|
499 | + } else { |
|
500 | 500 | throw new EE_Error( |
501 | 501 | sprintf( |
502 | - __( 'Programming error. We should be inserting or updating, but instead we are being told to "%1$s", which is invalid', 'event_espresso' ), |
|
502 | + __('Programming error. We should be inserting or updating, but instead we are being told to "%1$s", which is invalid', 'event_espresso'), |
|
503 | 503 | $what_to_do |
504 | 504 | ) |
505 | 505 | ); |
@@ -523,20 +523,20 @@ discard block |
||
523 | 523 | * @param array $old_db_to_new_db_mapping by reference so it can be modified |
524 | 524 | * @return string one of the constants on this class that starts with do_* |
525 | 525 | */ |
526 | - protected function _decide_whether_to_insert_or_update_given_data_from_other_db( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ) { |
|
526 | + protected function _decide_whether_to_insert_or_update_given_data_from_other_db($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) { |
|
527 | 527 | $model_name = $model->get_this_model_name(); |
528 | 528 | //if it's a site-to-site export-and-import, see if this model object's id |
529 | 529 | //in the old data that we know of |
530 | 530 | |
531 | - if( isset($old_db_to_new_db_mapping[$model_name][$id_in_csv]) ){ |
|
532 | - $what_to_do = self::do_update; |
|
533 | - }else{ |
|
534 | - $what_to_do = self::do_insert; |
|
531 | + if (isset($old_db_to_new_db_mapping[$model_name][$id_in_csv])) { |
|
532 | + $what_to_do = self::do_update; |
|
533 | + } else { |
|
534 | + $what_to_do = self::do_insert; |
|
535 | 535 | } |
536 | 536 | //consider any exceptions, usually where there are other uniqueness constraints |
537 | - if( $model instanceof EEM_Question_Group ) { |
|
538 | - if( isset( $model_object_data[ 'QSG_system' ] ) && |
|
539 | - $model_object_data[ 'QSG_system' ] ) { |
|
537 | + if ($model instanceof EEM_Question_Group) { |
|
538 | + if (isset($model_object_data['QSG_system']) && |
|
539 | + $model_object_data['QSG_system']) { |
|
540 | 540 | $what_to_do = self::do_update; |
541 | 541 | } |
542 | 542 | } |
@@ -558,11 +558,11 @@ discard block |
||
558 | 558 | * @throws \EE_Error |
559 | 559 | * @internal param \type $old_db_to_new_db_mapping |
560 | 560 | */ |
561 | - protected function _decide_whether_to_insert_or_update_given_data_from_same_db( $id_in_csv, $model_object_data, $model ) { |
|
561 | + protected function _decide_whether_to_insert_or_update_given_data_from_same_db($id_in_csv, $model_object_data, $model) { |
|
562 | 562 | //in this case, check if this thing ACTUALLY exists in the database |
563 | - if( $model->get_one_conflicting( $model_object_data ) ){ |
|
563 | + if ($model->get_one_conflicting($model_object_data)) { |
|
564 | 564 | return self::do_update; |
565 | - }else{ |
|
565 | + } else { |
|
566 | 566 | return self::do_insert; |
567 | 567 | } |
568 | 568 | } |
@@ -583,32 +583,32 @@ discard block |
||
583 | 583 | * |
584 | 584 | *@return array updated model object data with temp IDs removed |
585 | 585 | */ |
586 | - protected function _replace_temp_ids_with_mappings( $model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b ) { |
|
586 | + protected function _replace_temp_ids_with_mappings($model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b) { |
|
587 | 587 | //if this model object's primary key is in the mapping, replace it |
588 | - if( $model->has_primary_key_field() && |
|
588 | + if ($model->has_primary_key_field() && |
|
589 | 589 | $model->get_primary_key_field()->is_auto_increment() && |
590 | - isset( $old_db_to_new_db_mapping[ $model->get_this_model_name() ] ) && |
|
591 | - isset( $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ] ) ) { |
|
592 | - $model_object_data[ $model->primary_key_name() ] = $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ]; |
|
590 | + isset($old_db_to_new_db_mapping[$model->get_this_model_name()]) && |
|
591 | + isset($old_db_to_new_db_mapping[$model->get_this_model_name()][$model_object_data[$model->primary_key_name()]])) { |
|
592 | + $model_object_data[$model->primary_key_name()] = $old_db_to_new_db_mapping[$model->get_this_model_name()][$model_object_data[$model->primary_key_name()]]; |
|
593 | 593 | } |
594 | 594 | |
595 | - try{ |
|
595 | + try { |
|
596 | 596 | $model_name_field = $model->get_field_containing_related_model_name(); |
597 | 597 | //$models_pointed_to_by_model_name_field = $model_name_field->get_model_names_pointed_to(); |
598 | - }catch( EE_Error $e ){ |
|
598 | + } catch (EE_Error $e) { |
|
599 | 599 | $model_name_field = NULL; |
600 | 600 | //$models_pointed_to_by_model_name_field = array(); |
601 | 601 | } |
602 | - foreach( $model->field_settings( true ) as $field_obj ){ |
|
603 | - if( $field_obj instanceof EE_Foreign_Key_Int_Field ) { |
|
602 | + foreach ($model->field_settings(true) as $field_obj) { |
|
603 | + if ($field_obj instanceof EE_Foreign_Key_Int_Field) { |
|
604 | 604 | $models_pointed_to = $field_obj->get_model_names_pointed_to(); |
605 | - foreach( $models_pointed_to as $model_pointed_to_by_fk ) { |
|
605 | + foreach ($models_pointed_to as $model_pointed_to_by_fk) { |
|
606 | 606 | |
607 | - if( $model_name_field ){ |
|
608 | - $value_of_model_name_field = $model_object_data[ $model_name_field->get_name() ]; |
|
609 | - if( $value_of_model_name_field == $model_pointed_to_by_fk ) { |
|
610 | - $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
611 | - $model_object_data[ $field_obj->get_name() ], |
|
607 | + if ($model_name_field) { |
|
608 | + $value_of_model_name_field = $model_object_data[$model_name_field->get_name()]; |
|
609 | + if ($value_of_model_name_field == $model_pointed_to_by_fk) { |
|
610 | + $model_object_data[$field_obj->get_name()] = $this->_find_mapping_in( |
|
611 | + $model_object_data[$field_obj->get_name()], |
|
612 | 612 | $model_pointed_to_by_fk, |
613 | 613 | $old_db_to_new_db_mapping, |
614 | 614 | $export_from_site_a_to_b |
@@ -616,9 +616,9 @@ discard block |
||
616 | 616 | //once we've found a mapping for this field no need to continue |
617 | 617 | break; |
618 | 618 | } |
619 | - }else{ |
|
620 | - $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
621 | - $model_object_data[ $field_obj->get_name() ], |
|
619 | + } else { |
|
620 | + $model_object_data[$field_obj->get_name()] = $this->_find_mapping_in( |
|
621 | + $model_object_data[$field_obj->get_name()], |
|
622 | 622 | $model_pointed_to_by_fk, |
623 | 623 | $old_db_to_new_db_mapping, |
624 | 624 | $export_from_site_a_to_b |
@@ -627,7 +627,7 @@ discard block |
||
627 | 627 | break; |
628 | 628 | } |
629 | 629 | } |
630 | - }else{ |
|
630 | + } else { |
|
631 | 631 | //it's a string foreign key (which we leave alone, because those are things |
632 | 632 | //like country names, which we'd really rather not make 2 USAs etc (we'd actually |
633 | 633 | //prefer to just update one) |
@@ -635,7 +635,7 @@ discard block |
||
635 | 635 | } |
636 | 636 | } |
637 | 637 | //allow for any other value replacement |
638 | - return apply_filters( 'FHEE__EE_Import___replace_temp_ids_with_mappings__model_object_data__end', $model_object_data, $model ); |
|
638 | + return apply_filters('FHEE__EE_Import___replace_temp_ids_with_mappings__model_object_data__end', $model_object_data, $model); |
|
639 | 639 | } |
640 | 640 | |
641 | 641 | |
@@ -648,13 +648,13 @@ discard block |
||
648 | 648 | * @param boolean $export_from_site_a_to_b |
649 | 649 | * @return mixed|null|void |
650 | 650 | */ |
651 | - protected function _prepare_data_for_use_in_db( $original_data_row, $model, $export_from_site_a_to_b ) { |
|
651 | + protected function _prepare_data_for_use_in_db($original_data_row, $model, $export_from_site_a_to_b) { |
|
652 | 652 | $altered_data_row = $original_data_row; |
653 | - switch ( $model->get_this_model_name() ) { |
|
653 | + switch ($model->get_this_model_name()) { |
|
654 | 654 | case 'Message_Template_Group': |
655 | 655 | if ( |
656 | - isset( $original_data_row[ 'MTP_is_global' ] ) |
|
657 | - && intval( $original_data_row[ 'MTP_is_global' ] ) == 1 |
|
656 | + isset($original_data_row['MTP_is_global']) |
|
657 | + && intval($original_data_row['MTP_is_global']) == 1 |
|
658 | 658 | && apply_filters( |
659 | 659 | 'FHEE__EE_Import___prepare_data_for_use_in_db__tweak_global_message_template_groups', |
660 | 660 | true, |
@@ -664,34 +664,34 @@ discard block |
||
664 | 664 | ) |
665 | 665 | && ! $export_from_site_a_to_b |
666 | 666 | ) { |
667 | - $altered_data_row[ 'MTP_is_global' ] = 0; |
|
668 | - $message_type = isset( $altered_data_row[ 'MTP_message_type' ] ) |
|
669 | - ? $altered_data_row[ 'MTP_message_type' ] |
|
670 | - : __( 'Unknown', 'event_espresso' ); |
|
671 | - $altered_data_row[ 'MTP_name' ] = sprintf( |
|
672 | - __( 'Global %1$s message template from %2$s', 'event_espresso' ), |
|
667 | + $altered_data_row['MTP_is_global'] = 0; |
|
668 | + $message_type = isset($altered_data_row['MTP_message_type']) |
|
669 | + ? $altered_data_row['MTP_message_type'] |
|
670 | + : __('Unknown', 'event_espresso'); |
|
671 | + $altered_data_row['MTP_name'] = sprintf( |
|
672 | + __('Global %1$s message template from %2$s', 'event_espresso'), |
|
673 | 673 | $message_type, |
674 | - $this->_csv_import_metadata_row[ 'site_url' ] |
|
674 | + $this->_csv_import_metadata_row['site_url'] |
|
675 | 675 | ); |
676 | 676 | global $current_user; |
677 | - $altered_data_row[ 'MTP_description' ] = sprintf( |
|
678 | - __( 'Imported at %1$s by user %2$s', 'event_espresso' ), |
|
679 | - current_time( 'mysql' ), |
|
677 | + $altered_data_row['MTP_description'] = sprintf( |
|
678 | + __('Imported at %1$s by user %2$s', 'event_espresso'), |
|
679 | + current_time('mysql'), |
|
680 | 680 | $current_user->user_nicename |
681 | 681 | ); |
682 | 682 | } |
683 | 683 | } |
684 | - foreach ( $model->field_settings() as $field_name => $field_obj ) { |
|
685 | - if ( $field_obj instanceof EE_Datetime_Field ) { |
|
686 | - $altered_data_row[ $field_name ] = $model->convert_datetime_for_query( |
|
684 | + foreach ($model->field_settings() as $field_name => $field_obj) { |
|
685 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
686 | + $altered_data_row[$field_name] = $model->convert_datetime_for_query( |
|
687 | 687 | $field_name, |
688 | - $original_data_row[ $field_name ], |
|
688 | + $original_data_row[$field_name], |
|
689 | 689 | apply_filters( |
690 | 690 | 'FHEE__EE_Import___prepare_data_for_use_in_db__datetime_format_in_csv', |
691 | 691 | 'Y-m-d H:i:s' |
692 | 692 | ), |
693 | - isset( $this->_csv_import_metadata_row[ 'timezone' ] ) |
|
694 | - ? $this->_csv_import_metadata_row[ 'timezone' ] |
|
693 | + isset($this->_csv_import_metadata_row['timezone']) |
|
694 | + ? $this->_csv_import_metadata_row['timezone'] |
|
695 | 695 | : '' |
696 | 696 | ); |
697 | 697 | } |
@@ -713,14 +713,14 @@ discard block |
||
713 | 713 | * @param EEM_Base $model |
714 | 714 | * @return array new model object data |
715 | 715 | */ |
716 | - public function handle_split_term_ids( $model_object_data, $model ){ |
|
717 | - if( $model instanceof EEM_Term_Taxonomy && |
|
718 | - isset( $model_object_data['term_id'] ) && |
|
719 | - isset( $model_object_data[ 'taxonomy' ]) && |
|
720 | - apply_filters( 'FHEE__EE_Import__handle_split_term_ids__function_exists', function_exists( 'wp_get_split_term' ), $model_object_data ) ) { |
|
721 | - $new_term_id = wp_get_split_term( $model_object_data[ 'term_id' ], $model_object_data[ 'taxonomy' ] ); |
|
722 | - if( $new_term_id ){ |
|
723 | - $model_object_data[ 'term_id' ] = $new_term_id; |
|
716 | + public function handle_split_term_ids($model_object_data, $model) { |
|
717 | + if ($model instanceof EEM_Term_Taxonomy && |
|
718 | + isset($model_object_data['term_id']) && |
|
719 | + isset($model_object_data['taxonomy']) && |
|
720 | + apply_filters('FHEE__EE_Import__handle_split_term_ids__function_exists', function_exists('wp_get_split_term'), $model_object_data)) { |
|
721 | + $new_term_id = wp_get_split_term($model_object_data['term_id'], $model_object_data['taxonomy']); |
|
722 | + if ($new_term_id) { |
|
723 | + $model_object_data['term_id'] = $new_term_id; |
|
724 | 724 | } |
725 | 725 | } |
726 | 726 | return $model_object_data; |
@@ -734,17 +734,17 @@ discard block |
||
734 | 734 | * @param bool $export_from_site_a_to_b |
735 | 735 | * @return int |
736 | 736 | */ |
737 | - protected function _find_mapping_in( $object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) { |
|
738 | - if( isset( $old_db_to_new_db_mapping[ $model_name ][ $object_id ] ) ){ |
|
739 | - return $old_db_to_new_db_mapping[ $model_name ][ $object_id ]; |
|
740 | - }elseif( $object_id == '0' || $object_id == '' ) { |
|
737 | + protected function _find_mapping_in($object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) { |
|
738 | + if (isset($old_db_to_new_db_mapping[$model_name][$object_id])) { |
|
739 | + return $old_db_to_new_db_mapping[$model_name][$object_id]; |
|
740 | + }elseif ($object_id == '0' || $object_id == '') { |
|
741 | 741 | //leave as-is |
742 | 742 | return $object_id; |
743 | - }elseif( $export_from_site_a_to_b ){ |
|
743 | + }elseif ($export_from_site_a_to_b) { |
|
744 | 744 | //we couldn't find a mapping for this, and it's from a different site, |
745 | 745 | //so blank it out |
746 | 746 | return null; |
747 | - }elseif( ! $export_from_site_a_to_b ) { |
|
747 | + }elseif ( ! $export_from_site_a_to_b) { |
|
748 | 748 | //we couldn't find a mapping for this, but it's from this DB anyway |
749 | 749 | //so let's just leave it as-is |
750 | 750 | return $object_id; |
@@ -760,19 +760,19 @@ discard block |
||
760 | 760 | * @param array $old_db_to_new_db_mapping |
761 | 761 | * @return array updated $old_db_to_new_db_mapping |
762 | 762 | */ |
763 | - protected function _insert_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ) { |
|
763 | + protected function _insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) { |
|
764 | 764 | //remove the primary key, if there is one (we don't want it for inserts OR updates) |
765 | 765 | //we'll put it back in if we need it |
766 | - if($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()){ |
|
766 | + if ($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()) { |
|
767 | 767 | $effective_id = $model_object_data[$model->primary_key_name()]; |
768 | 768 | unset($model_object_data[$model->primary_key_name()]); |
769 | - }else{ |
|
770 | - $effective_id = $model->get_index_primary_key_string( $model_object_data ); |
|
769 | + } else { |
|
770 | + $effective_id = $model->get_index_primary_key_string($model_object_data); |
|
771 | 771 | } |
772 | 772 | //the model takes care of validating the CSV's input |
773 | - try{ |
|
773 | + try { |
|
774 | 774 | $new_id = $model->insert($model_object_data); |
775 | - if( $new_id ){ |
|
775 | + if ($new_id) { |
|
776 | 776 | $old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_id; |
777 | 777 | $this->_add_insert_success( |
778 | 778 | sprintf( |
@@ -781,15 +781,15 @@ discard block |
||
781 | 781 | $new_id |
782 | 782 | ) |
783 | 783 | ); |
784 | - }else{ |
|
784 | + } else { |
|
785 | 785 | //put the ID used back in there for the error message |
786 | - if($model->has_primary_key_field()){ |
|
786 | + if ($model->has_primary_key_field()) { |
|
787 | 787 | $model_object_data[$model->primary_key_name()] = $effective_id; |
788 | 788 | } |
789 | 789 | global $wpdb; |
790 | 790 | $this->_add_insert_error( |
791 | 791 | sprintf( |
792 | - __('Could not insert new %1$s with ID in file %2$s because %3$s', "event_espresso" ), |
|
792 | + __('Could not insert new %1$s with ID in file %2$s because %3$s', "event_espresso"), |
|
793 | 793 | $model->get_this_model_name(), |
794 | 794 | $id_in_csv, |
795 | 795 | $wpdb->last_error |
@@ -797,8 +797,8 @@ discard block |
||
797 | 797 | __FILE__, __FUNCTION__, __LINE__ |
798 | 798 | ); |
799 | 799 | } |
800 | - }catch(EE_Error $e){ |
|
801 | - if($model->has_primary_key_field()){ |
|
800 | + } catch (EE_Error $e) { |
|
801 | + if ($model->has_primary_key_field()) { |
|
802 | 802 | $model_object_data[$model->primary_key_name()] = $effective_id; |
803 | 803 | } |
804 | 804 | $this->_add_insert_error( |
@@ -822,29 +822,29 @@ discard block |
||
822 | 822 | * @param array $old_db_to_new_db_mapping |
823 | 823 | * @return array updated $old_db_to_new_db_mapping |
824 | 824 | */ |
825 | - protected function _update_from_data_array( $id_in_csv, $original_model_object_data, $model, $old_db_to_new_db_mapping ) { |
|
826 | - try{ |
|
825 | + protected function _update_from_data_array($id_in_csv, $original_model_object_data, $model, $old_db_to_new_db_mapping) { |
|
826 | + try { |
|
827 | 827 | //let's keep two copies of the model object data: |
828 | 828 | //one for performing an update, one for everything else |
829 | 829 | $model_object_data_for_update = $original_model_object_data; |
830 | - if ( $model->has_primary_key_field() ) { |
|
830 | + if ($model->has_primary_key_field()) { |
|
831 | 831 | //wait- will this update cause a conflict with other data? |
832 | - $conflicting = $model->get_one_conflicting( $original_model_object_data, false ); |
|
833 | - if ( $conflicting ) { |
|
832 | + $conflicting = $model->get_one_conflicting($original_model_object_data, false); |
|
833 | + if ($conflicting) { |
|
834 | 834 | //if so, just update the thing it would conflict with, dont cause a conflict |
835 | 835 | $pk_value = $conflicting->ID(); |
836 | 836 | } else { |
837 | - $pk_value = $model_object_data_for_update[ $model->primary_key_name() ]; |
|
837 | + $pk_value = $model_object_data_for_update[$model->primary_key_name()]; |
|
838 | 838 | } |
839 | - $conditions = array( $model->primary_key_name() => $pk_value ); |
|
839 | + $conditions = array($model->primary_key_name() => $pk_value); |
|
840 | 840 | //remove the primary key because we shouldn't use it for updating |
841 | - unset( $model_object_data_for_update[ $model->primary_key_name() ] ); |
|
842 | - } elseif ( $model->get_combined_primary_key_fields() > 1 ) { |
|
841 | + unset($model_object_data_for_update[$model->primary_key_name()]); |
|
842 | + } elseif ($model->get_combined_primary_key_fields() > 1) { |
|
843 | 843 | $conditions = array(); |
844 | - foreach ( $model->get_combined_primary_key_fields() as $key_field ) { |
|
845 | - $conditions[ $key_field->get_name() ] = $model_object_data_for_update[ $key_field->get_name() ]; |
|
844 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
845 | + $conditions[$key_field->get_name()] = $model_object_data_for_update[$key_field->get_name()]; |
|
846 | 846 | } |
847 | - $pk_value = $model->get_index_primary_key_string( $original_model_object_data ); |
|
847 | + $pk_value = $model->get_index_primary_key_string($original_model_object_data); |
|
848 | 848 | } else { |
849 | 849 | //this should just throw an exception, explaining that we dont have a primary key (or a combined key) |
850 | 850 | $model->primary_key_name(); |
@@ -855,8 +855,8 @@ discard block |
||
855 | 855 | $conditions, |
856 | 856 | 'default_where_conditions' => 'minimum' |
857 | 857 | ); |
858 | - $success = $model->update($model_object_data_for_update,$query_params); |
|
859 | - if($success){ |
|
858 | + $success = $model->update($model_object_data_for_update, $query_params); |
|
859 | + if ($success) { |
|
860 | 860 | $this->_add_update_success( |
861 | 861 | sprintf( |
862 | 862 | __('Successfully updated %1$s (with ID %2$s).', "event_espresso"), |
@@ -868,10 +868,10 @@ discard block |
||
868 | 868 | //because if we were going to insert something but it was going to conflict |
869 | 869 | //we would have last-minute decided to update. So we'd like to know what we updated |
870 | 870 | //and so we record what record ended up being updated using the mapping |
871 | - $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $pk_value; |
|
872 | - }else{ |
|
871 | + $old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $pk_value; |
|
872 | + } else { |
|
873 | 873 | $matched_items = $model->get_all($query_params); |
874 | - if( ! $matched_items){ |
|
874 | + if ( ! $matched_items) { |
|
875 | 875 | //no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck? |
876 | 876 | $this->_add_update_error( |
877 | 877 | sprintf( |
@@ -886,15 +886,15 @@ discard block |
||
886 | 886 | //wasn't an error, just didn't need updating |
887 | 887 | } |
888 | 888 | } |
889 | - }catch(EE_Error $e){ |
|
889 | + } catch (EE_Error $e) { |
|
890 | 890 | $basic_message = sprintf( |
891 | 891 | __('Could not update %1$s with ID %2$s because %3$s', "event_espresso"), |
892 | 892 | $model->get_this_model_name(), |
893 | 893 | $pk_value, |
894 | 894 | $e->getMessage() |
895 | 895 | ); |
896 | - $debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString(); |
|
897 | - $this->_add_general_error( "$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__ ); |
|
896 | + $debug_message = $basic_message.' Stack trace: '.$e->getTraceAsString(); |
|
897 | + $this->_add_general_error("$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__); |
|
898 | 898 | } |
899 | 899 | return $old_db_to_new_db_mapping; |
900 | 900 | } |
@@ -903,52 +903,52 @@ discard block |
||
903 | 903 | * Gets the number of inserts performed since importer was instantiated or reset |
904 | 904 | * @return int |
905 | 905 | */ |
906 | - public function get_total_inserts(){ |
|
907 | - return count( $this->_inserts ); |
|
906 | + public function get_total_inserts() { |
|
907 | + return count($this->_inserts); |
|
908 | 908 | } |
909 | 909 | /** |
910 | 910 | * Gets the number of insert errors since importer was instantiated or reset |
911 | 911 | * @return int |
912 | 912 | */ |
913 | - public function get_total_insert_errors(){ |
|
914 | - return count( $this->_insert_errors ); |
|
913 | + public function get_total_insert_errors() { |
|
914 | + return count($this->_insert_errors); |
|
915 | 915 | } |
916 | 916 | /** |
917 | 917 | * Gets the number of updates performed since importer was instantiated or reset |
918 | 918 | * @return int |
919 | 919 | */ |
920 | - public function get_total_updates(){ |
|
921 | - return count( $this->_updates ); |
|
920 | + public function get_total_updates() { |
|
921 | + return count($this->_updates); |
|
922 | 922 | } |
923 | 923 | /** |
924 | 924 | * Gets the number of update errors since importer was instantiated or reset |
925 | 925 | * @return int |
926 | 926 | */ |
927 | - public function get_total_update_errors(){ |
|
928 | - return count( $this->_update_errors ); |
|
927 | + public function get_total_update_errors() { |
|
928 | + return count($this->_update_errors); |
|
929 | 929 | } |
930 | 930 | |
931 | 931 | /** |
932 | 932 | * Gets count of general errors during import |
933 | 933 | * @return int |
934 | 934 | */ |
935 | - public function get_total_general_errors(){ |
|
936 | - return count( $this->_general_errors ); |
|
935 | + public function get_total_general_errors() { |
|
936 | + return count($this->_general_errors); |
|
937 | 937 | } |
938 | - protected function _add_update_success( $message ){ |
|
938 | + protected function _add_update_success($message) { |
|
939 | 939 | $this->_updates[] = $message; |
940 | 940 | } |
941 | - protected function _add_insert_success( $message ){ |
|
941 | + protected function _add_insert_success($message) { |
|
942 | 942 | $this->_inserts[] = $message; |
943 | 943 | } |
944 | - protected function _add_update_error( $message, $file, $function, $line ){ |
|
945 | - $this->_update_errors[] = array( $message, $file, $function, $line ); |
|
944 | + protected function _add_update_error($message, $file, $function, $line) { |
|
945 | + $this->_update_errors[] = array($message, $file, $function, $line); |
|
946 | 946 | } |
947 | - protected function _add_insert_error( $message, $file, $function, $line ){ |
|
948 | - $this->_insert_errors[] = array( $message, $file, $function, $line ); |
|
947 | + protected function _add_insert_error($message, $file, $function, $line) { |
|
948 | + $this->_insert_errors[] = array($message, $file, $function, $line); |
|
949 | 949 | } |
950 | - protected function _add_general_error( $message, $file, $function, $line ){ |
|
951 | - $this->_general_errors[] = array( $message, $file, $function, $line ); |
|
950 | + protected function _add_general_error($message, $file, $function, $line) { |
|
951 | + $this->_general_errors[] = array($message, $file, $function, $line); |
|
952 | 952 | } |
953 | 953 | |
954 | 954 | /** |
@@ -958,7 +958,7 @@ discard block |
||
958 | 958 | * happened. |
959 | 959 | * @return array |
960 | 960 | */ |
961 | - public function get_update_errors(){ |
|
961 | + public function get_update_errors() { |
|
962 | 962 | return $this->_update_errors; |
963 | 963 | } |
964 | 964 | /** |
@@ -968,7 +968,7 @@ discard block |
||
968 | 968 | * happened. |
969 | 969 | * @return array |
970 | 970 | */ |
971 | - public function get_insert_errors(){ |
|
971 | + public function get_insert_errors() { |
|
972 | 972 | return $this->_insert_errors; |
973 | 973 | } |
974 | 974 | /** |
@@ -978,21 +978,21 @@ discard block |
||
978 | 978 | * happened. |
979 | 979 | * @return array |
980 | 980 | */ |
981 | - public function get_general_errors(){ |
|
981 | + public function get_general_errors() { |
|
982 | 982 | return $this->_general_errors; |
983 | 983 | } |
984 | 984 | /** |
985 | 985 | * Gets a simple array where each item in the array is a string describing what was inserted |
986 | 986 | * @return array |
987 | 987 | */ |
988 | - public function get_inserts(){ |
|
988 | + public function get_inserts() { |
|
989 | 989 | return $this->_inserts; |
990 | 990 | } |
991 | 991 | /** |
992 | 992 | * Gets a simple array where each item in the array is a string describing what was updated |
993 | 993 | * @return array |
994 | 994 | */ |
995 | - public function get_updates(){ |
|
995 | + public function get_updates() { |
|
996 | 996 | return $this->_updates; |
997 | 997 | } |
998 | 998 | /** |
@@ -1000,40 +1000,40 @@ discard block |
||
1000 | 1000 | * normal EE_Error success and error messages. |
1001 | 1001 | * @return boolean there were no errors and we successfully did something |
1002 | 1002 | */ |
1003 | - public function report_successes_and_errors(){ |
|
1003 | + public function report_successes_and_errors() { |
|
1004 | 1004 | $success = false; |
1005 | 1005 | $error = false; |
1006 | - if ( $this->get_total_updates() ) { |
|
1007 | - EE_Error::add_success( sprintf(__("%s existing records in the database were updated.", "event_espresso"),$this->get_total_updates())); |
|
1006 | + if ($this->get_total_updates()) { |
|
1007 | + EE_Error::add_success(sprintf(__("%s existing records in the database were updated.", "event_espresso"), $this->get_total_updates())); |
|
1008 | 1008 | $success = true; |
1009 | 1009 | } |
1010 | - if ( $this->get_total_inserts() ) { |
|
1011 | - EE_Error::add_success(sprintf(__("%s new records were added to the database.", "event_espresso"),$this->get_total_inserts())); |
|
1010 | + if ($this->get_total_inserts()) { |
|
1011 | + EE_Error::add_success(sprintf(__("%s new records were added to the database.", "event_espresso"), $this->get_total_inserts())); |
|
1012 | 1012 | $success = true; |
1013 | 1013 | } |
1014 | 1014 | |
1015 | - if ( $this->get_total_update_errors()) { |
|
1016 | - EE_Error::add_error(sprintf(__("'One or more errors occurred, and a total of %s existing records in the database were <strong>not</strong> updated.'", "event_espresso"),$this->get_total_update_errors() ), __FILE__, __FUNCTION__, __LINE__ ); |
|
1015 | + if ($this->get_total_update_errors()) { |
|
1016 | + EE_Error::add_error(sprintf(__("'One or more errors occurred, and a total of %s existing records in the database were <strong>not</strong> updated.'", "event_espresso"), $this->get_total_update_errors()), __FILE__, __FUNCTION__, __LINE__); |
|
1017 | 1017 | $error = true; |
1018 | 1018 | } |
1019 | - if ( $this->get_total_insert_errors() ) { |
|
1020 | - EE_Error::add_error(sprintf(__("One or more errors occurred, and a total of %s new records were <strong>not</strong> added to the database.'", "event_espresso"),$this->get_total_insert_errors() ), __FILE__, __FUNCTION__, __LINE__ ); |
|
1019 | + if ($this->get_total_insert_errors()) { |
|
1020 | + EE_Error::add_error(sprintf(__("One or more errors occurred, and a total of %s new records were <strong>not</strong> added to the database.'", "event_espresso"), $this->get_total_insert_errors()), __FILE__, __FUNCTION__, __LINE__); |
|
1021 | 1021 | $error = true; |
1022 | 1022 | } |
1023 | - foreach( $this->_general_errors as $message_data ){ |
|
1024 | - EE_Error::add_error( $message_data[0], $message_data[1], $message_data[2], $message_data[3]); |
|
1023 | + foreach ($this->_general_errors as $message_data) { |
|
1024 | + EE_Error::add_error($message_data[0], $message_data[1], $message_data[2], $message_data[3]); |
|
1025 | 1025 | } |
1026 | - foreach( $this->_inserts as $insert ){ |
|
1027 | - EE_Error::add_success( $insert ); |
|
1026 | + foreach ($this->_inserts as $insert) { |
|
1027 | + EE_Error::add_success($insert); |
|
1028 | 1028 | } |
1029 | - foreach( $this->_updates as $update ){ |
|
1030 | - EE_Error::add_success( $update ); |
|
1029 | + foreach ($this->_updates as $update) { |
|
1030 | + EE_Error::add_success($update); |
|
1031 | 1031 | } |
1032 | - foreach( $this->_insert_errors as $message_data ){ |
|
1033 | - EE_Error::add_error( $message_data[0], $message_data[1], $message_data[2], $message_data[3]); |
|
1032 | + foreach ($this->_insert_errors as $message_data) { |
|
1033 | + EE_Error::add_error($message_data[0], $message_data[1], $message_data[2], $message_data[3]); |
|
1034 | 1034 | } |
1035 | - foreach( $this->_update_errors as $message_data ){ |
|
1036 | - EE_Error::add_error( $message_data[0], $message_data[1], $message_data[2], $message_data[3]); |
|
1035 | + foreach ($this->_update_errors as $message_data) { |
|
1036 | + EE_Error::add_error($message_data[0], $message_data[1], $message_data[2], $message_data[3]); |
|
1037 | 1037 | } |
1038 | 1038 | return $success && ! $error; |
1039 | 1039 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
2 | -do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
2 | +do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
3 | 3 | /** |
4 | 4 | * EE_Export class |
5 | 5 | * |
@@ -41,11 +41,11 @@ discard block |
||
41 | 41 | * @access private |
42 | 42 | * @param array $request_data |
43 | 43 | */ |
44 | - private function __construct( $request_data = array() ) { |
|
44 | + private function __construct($request_data = array()) { |
|
45 | 45 | $this->_req_data = $request_data; |
46 | - $this->today = date("Y-m-d",time()); |
|
47 | - require_once( EE_CLASSES . 'EE_CSV.class.php' ); |
|
48 | - $this->EE_CSV= EE_CSV::instance(); |
|
46 | + $this->today = date("Y-m-d", time()); |
|
47 | + require_once(EE_CLASSES.'EE_CSV.class.php'); |
|
48 | + $this->EE_CSV = EE_CSV::instance(); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | |
@@ -57,10 +57,10 @@ discard block |
||
57 | 57 | * @param array $request_data |
58 | 58 | * @return \EE_Export |
59 | 59 | */ |
60 | - public static function instance( $request_data = array() ) { |
|
60 | + public static function instance($request_data = array()) { |
|
61 | 61 | // check if class object is instantiated |
62 | - if ( self::$_instance === NULL or ! is_object( self::$_instance ) or ! ( self::$_instance instanceof EE_Export )) { |
|
63 | - self::$_instance = new self( $request_data ); |
|
62 | + if (self::$_instance === NULL or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Export)) { |
|
63 | + self::$_instance = new self($request_data); |
|
64 | 64 | } |
65 | 65 | return self::$_instance; |
66 | 66 | } |
@@ -74,15 +74,15 @@ discard block |
||
74 | 74 | public function export() { |
75 | 75 | |
76 | 76 | // in case of bulk exports, the "actual" action will be in action2, but first check regular action for "export" keyword |
77 | - if ( isset( $this->_req_data['action'] ) && strpos( $this->_req_data['action'], 'export' ) === FALSE ) { |
|
77 | + if (isset($this->_req_data['action']) && strpos($this->_req_data['action'], 'export') === FALSE) { |
|
78 | 78 | // check if action2 has export action |
79 | - if ( isset( $this->_req_data['action2'] ) && strpos( $this->_req_data['action2'], 'export' ) !== FALSE ) { |
|
79 | + if (isset($this->_req_data['action2']) && strpos($this->_req_data['action2'], 'export') !== FALSE) { |
|
80 | 80 | // whoop! there it is! |
81 | 81 | $this->_req_data['action'] = $this->_req_data['action2']; |
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
85 | - $this->_req_data['export'] = isset( $this->_req_data['export'] ) ? $this->_req_data['export'] : ''; |
|
85 | + $this->_req_data['export'] = isset($this->_req_data['export']) ? $this->_req_data['export'] : ''; |
|
86 | 86 | |
87 | 87 | switch ($this->_req_data['export']) { |
88 | 88 | case 'report': |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | break; |
100 | 100 | |
101 | 101 | case 'registrations_report_for_event': |
102 | - $this->report_registrations_for_event( $this->_req_data['EVT_ID'] ); |
|
102 | + $this->report_registrations_for_event($this->_req_data['EVT_ID']); |
|
103 | 103 | break; |
104 | 104 | |
105 | 105 | case 'attendees': |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | break; |
112 | 112 | |
113 | 113 | default: |
114 | - EE_Error::add_error(__('An error occurred! The requested export report could not be found.','event_espresso'), __FILE__, __FUNCTION__, __LINE__ ) ; |
|
114 | + EE_Error::add_error(__('An error occurred! The requested export report could not be found.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
115 | 115 | return FALSE; |
116 | 116 | break; |
117 | 117 | |
@@ -139,12 +139,12 @@ discard block |
||
139 | 139 | |
140 | 140 | $models_to_export = EE_Registry::instance()->non_abstract_db_models; |
141 | 141 | |
142 | - $table_data = $this->_get_export_data_for_models( array_keys( $models_to_export ) ); |
|
142 | + $table_data = $this->_get_export_data_for_models(array_keys($models_to_export)); |
|
143 | 143 | |
144 | - $filename = $this->generate_filename ( 'full-db-export' ); |
|
144 | + $filename = $this->generate_filename('full-db-export'); |
|
145 | 145 | |
146 | - if ( ! $this->EE_CSV->export_multiple_model_data_to_csv( $filename,$table_data )) { |
|
147 | - EE_Error::add_error(__("An error occurred and the Event details could not be exported from the database.", "event_espresso"), __FILE__, __FUNCTION__, __LINE__ ); |
|
146 | + if ( ! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $table_data)) { |
|
147 | + EE_Error::add_error(__("An error occurred and the Event details could not be exported from the database.", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | * Downloads a CSV file with all the columns, but no data. This should be used for importing |
153 | 153 | * @return null kills execution |
154 | 154 | */ |
155 | - function export_sample(){ |
|
155 | + function export_sample() { |
|
156 | 156 | $event = EEM_Event::instance()->get_one(); |
157 | 157 | $this->_req_data['EVT_ID'] = $event->ID(); |
158 | 158 | $this->export_all_event_data(); |
@@ -179,23 +179,23 @@ discard block |
||
179 | 179 | $question_group_query_params = array(); |
180 | 180 | $question_query_params = array(); |
181 | 181 | $related_through_mtg_params = array(); |
182 | - if ( isset( $this->_req_data['EVT_ID'] )) { |
|
182 | + if (isset($this->_req_data['EVT_ID'])) { |
|
183 | 183 | // do we have an array of IDs ? |
184 | 184 | |
185 | - if ( is_array( $this->_req_data['EVT_ID'] )) { |
|
186 | - $EVT_IDs = array_map( 'sanitize_text_field', $this->_req_data['EVT_ID'] ); |
|
187 | - $value_to_equal = array('IN',$EVT_IDs); |
|
185 | + if (is_array($this->_req_data['EVT_ID'])) { |
|
186 | + $EVT_IDs = array_map('sanitize_text_field', $this->_req_data['EVT_ID']); |
|
187 | + $value_to_equal = array('IN', $EVT_IDs); |
|
188 | 188 | $filename = 'events'; |
189 | 189 | } else { |
190 | 190 | // generate regular where = clause |
191 | - $EVT_ID = absint( $this->_req_data['EVT_ID'] ); |
|
191 | + $EVT_ID = absint($this->_req_data['EVT_ID']); |
|
192 | 192 | $value_to_equal = $EVT_ID; |
193 | 193 | $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($EVT_ID); |
194 | 194 | |
195 | - $filename = 'event-' . ( $event instanceof EE_Event ? $event->slug() : __( 'unknown', 'event_espresso' ) ); |
|
195 | + $filename = 'event-'.($event instanceof EE_Event ? $event->slug() : __('unknown', 'event_espresso')); |
|
196 | 196 | |
197 | 197 | } |
198 | - $event_query_params[0]['EVT_ID'] =$value_to_equal; |
|
198 | + $event_query_params[0]['EVT_ID'] = $value_to_equal; |
|
199 | 199 | $related_models_query_params[0]['Event.EVT_ID'] = $value_to_equal; |
200 | 200 | $related_through_reg_query_params[0]['Registration.EVT_ID'] = $value_to_equal; |
201 | 201 | $datetime_ticket_query_params[0]['Datetime.EVT_ID'] = $value_to_equal; |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | $state_country_query_params[0]['Venue.Event.EVT_ID'] = $value_to_equal; |
206 | 206 | $question_group_query_params[0]['Event.EVT_ID'] = $value_to_equal; |
207 | 207 | $question_query_params[0]['Question_Group.Event.EVT_ID'] = $value_to_equal; |
208 | - $related_through_mtg_params[0]['Message_Template_Group.Event.EVT_ID' ] = $value_to_equal; |
|
208 | + $related_through_mtg_params[0]['Message_Template_Group.Event.EVT_ID'] = $value_to_equal; |
|
209 | 209 | |
210 | 210 | } else { |
211 | 211 | $filename = 'all-events'; |
@@ -246,18 +246,18 @@ discard block |
||
246 | 246 | //and we want to specify what things we want to update (because some of that data we'd rather |
247 | 247 | //not update, just insert if it doesn't exist |
248 | 248 | $models_to_update = $models_to_export; |
249 | - unset( $models_to_update['Ticket_Template'] ); |
|
250 | - unset( $models_to_update['Price_Type'] ); |
|
251 | - unset( $models_to_update['Term'] ); |
|
252 | - unset( $models_to_update['Country'] ); |
|
253 | - unset( $models_to_update['State'] ); |
|
254 | - unset( $models_to_update['Question_Group'] ); |
|
255 | - unset( $models_to_update['Event_Question_Group'] ); |
|
256 | - unset( $models_to_update['Question'] ); |
|
257 | - unset( $models_to_update['Question_Group_Question'] ); |
|
258 | - unset( $models_to_update['Message_Template_Group'] ); |
|
259 | - unset( $models_to_update['Message_Template'] ); |
|
260 | - $models_to_update = array_keys( $models_to_update ); |
|
249 | + unset($models_to_update['Ticket_Template']); |
|
250 | + unset($models_to_update['Price_Type']); |
|
251 | + unset($models_to_update['Term']); |
|
252 | + unset($models_to_update['Country']); |
|
253 | + unset($models_to_update['State']); |
|
254 | + unset($models_to_update['Question_Group']); |
|
255 | + unset($models_to_update['Event_Question_Group']); |
|
256 | + unset($models_to_update['Question']); |
|
257 | + unset($models_to_update['Question_Group_Question']); |
|
258 | + unset($models_to_update['Message_Template_Group']); |
|
259 | + unset($models_to_update['Message_Template']); |
|
260 | + $models_to_update = array_keys($models_to_update); |
|
261 | 261 | |
262 | 262 | |
263 | 263 | |
@@ -266,37 +266,37 @@ discard block |
||
266 | 266 | //and won't get any non-events; also |
267 | 267 | //we can forego the default query params |
268 | 268 | |
269 | - $model_data = $this->_get_export_data_for_models( $models_to_export ); |
|
269 | + $model_data = $this->_get_export_data_for_models($models_to_export); |
|
270 | 270 | |
271 | - $filename = $this->generate_filename ( $filename ); |
|
271 | + $filename = $this->generate_filename($filename); |
|
272 | 272 | |
273 | - if ( ! $this->EE_CSV->export_multiple_model_data_to_csv( $filename, $model_data, $models_to_update )) { |
|
274 | - EE_Error::add_error(__("'An error occurred and the Event details could not be exported from the database.'", "event_espresso"), __FILE__, __FUNCTION__, __LINE__ ); |
|
273 | + if ( ! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data, $models_to_update)) { |
|
274 | + EE_Error::add_error(__("'An error occurred and the Event details could not be exported from the database.'", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
275 | 275 | } |
276 | 276 | } |
277 | 277 | |
278 | - function report_attendees(){ |
|
279 | - $attendee_rows = EEM_Attendee::instance()->get_all_wpdb_results( array( 'force_join' => array( 'State', 'Country' ) ) ); |
|
278 | + function report_attendees() { |
|
279 | + $attendee_rows = EEM_Attendee::instance()->get_all_wpdb_results(array('force_join' => array('State', 'Country'))); |
|
280 | 280 | $csv_data = array(); |
281 | - foreach( $attendee_rows as $attendee_row ){ |
|
281 | + foreach ($attendee_rows as $attendee_row) { |
|
282 | 282 | $csv_row = array(); |
283 | - foreach( EEM_Attendee::instance()->field_settings() as $field_name => $field_obj ){ |
|
284 | - if( $field_name == 'STA_ID' ){ |
|
285 | - $state_name_field = EEM_State::instance()->field_settings_for( 'STA_name' ); |
|
286 | - $csv_row[ __( 'State', 'event_espresso' ) ] = $attendee_row[ $state_name_field->get_qualified_column() ]; |
|
287 | - }elseif( $field_name == 'CNT_ISO' ){ |
|
288 | - $country_name_field = EEM_Country::instance()->field_settings_for( 'CNT_name' ); |
|
289 | - $csv_row[ __( 'Country', 'event_espresso' ) ] = $attendee_row[ $country_name_field->get_qualified_column() ]; |
|
290 | - }else{ |
|
291 | - $csv_row[ $field_obj->get_nicename() ] = $attendee_row[ $field_obj->get_qualified_column() ]; |
|
283 | + foreach (EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) { |
|
284 | + if ($field_name == 'STA_ID') { |
|
285 | + $state_name_field = EEM_State::instance()->field_settings_for('STA_name'); |
|
286 | + $csv_row[__('State', 'event_espresso')] = $attendee_row[$state_name_field->get_qualified_column()]; |
|
287 | + }elseif ($field_name == 'CNT_ISO') { |
|
288 | + $country_name_field = EEM_Country::instance()->field_settings_for('CNT_name'); |
|
289 | + $csv_row[__('Country', 'event_espresso')] = $attendee_row[$country_name_field->get_qualified_column()]; |
|
290 | + } else { |
|
291 | + $csv_row[$field_obj->get_nicename()] = $attendee_row[$field_obj->get_qualified_column()]; |
|
292 | 292 | } |
293 | 293 | } |
294 | 294 | $csv_data[] = $csv_row; |
295 | 295 | } |
296 | 296 | |
297 | - $filename = $this->generate_filename ( 'contact-list-report' ); |
|
297 | + $filename = $this->generate_filename('contact-list-report'); |
|
298 | 298 | |
299 | - $handle = $this->EE_CSV->begin_sending_csv( $filename); |
|
299 | + $handle = $this->EE_CSV->begin_sending_csv($filename); |
|
300 | 300 | $this->EE_CSV->write_data_array_to_csv($handle, $csv_data); |
301 | 301 | $this->EE_CSV->end_sending_csv($handle); |
302 | 302 | } |
@@ -313,19 +313,19 @@ discard block |
||
313 | 313 | $countries_that_have_an_attendee = EEM_Country::instance()->get_all(array(0=>array('Attendee.ATT_ID'=>array('IS NOT NULL')))); |
314 | 314 | // $states_to_export_query_params |
315 | 315 | $models_to_export = array( |
316 | - 'Country'=>array(array('CNT_ISO'=>array('IN',array_keys($countries_that_have_an_attendee)))), |
|
317 | - 'State'=>array(array('STA_ID'=>array('IN',array_keys($states_that_have_an_attendee)))), |
|
316 | + 'Country'=>array(array('CNT_ISO'=>array('IN', array_keys($countries_that_have_an_attendee)))), |
|
317 | + 'State'=>array(array('STA_ID'=>array('IN', array_keys($states_that_have_an_attendee)))), |
|
318 | 318 | 'Attendee'=>array(), |
319 | 319 | ); |
320 | - $models_to_update = array( 'Attendee' ); |
|
320 | + $models_to_update = array('Attendee'); |
|
321 | 321 | |
322 | 322 | |
323 | 323 | |
324 | - $model_data = $this->_get_export_data_for_models( $models_to_export ); |
|
325 | - $filename = $this->generate_filename ( 'all-attendees' ); |
|
324 | + $model_data = $this->_get_export_data_for_models($models_to_export); |
|
325 | + $filename = $this->generate_filename('all-attendees'); |
|
326 | 326 | |
327 | - if ( ! $this->EE_CSV->export_multiple_model_data_to_csv( $filename, $model_data, $models_to_update )) { |
|
328 | - EE_Error::add_error(__('An error occurred and the Attendee data could not be exported from the database.','event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
327 | + if ( ! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data, $models_to_update)) { |
|
328 | + EE_Error::add_error(__('An error occurred and the Attendee data could not be exported from the database.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
329 | 329 | } |
330 | 330 | } |
331 | 331 | |
@@ -337,19 +337,19 @@ discard block |
||
337 | 337 | * @param boolean|string $pretty_schema true to display pretty, a string to use a specific "Schema", or false to NOT display pretty |
338 | 338 | * @return string |
339 | 339 | */ |
340 | - protected function _prepare_value_from_db_for_display( $model, $field_name, $raw_db_value, $pretty_schema = true ) { |
|
341 | - $field_obj = $model->field_settings_for( $field_name ); |
|
342 | - $value_on_model_obj = $field_obj->prepare_for_set_from_db( $raw_db_value ); |
|
343 | - if( $field_obj instanceof EE_Datetime_Field ) { |
|
344 | - $field_obj->set_date_format( EE_CSV::instance()->get_date_format_for_csv( $field_obj->get_date_format( $pretty_schema ) ), $pretty_schema ); |
|
345 | - $field_obj->set_time_format( EE_CSV::instance()->get_time_format_for_csv( $field_obj->get_time_format( $pretty_schema ) ), $pretty_schema ); |
|
340 | + protected function _prepare_value_from_db_for_display($model, $field_name, $raw_db_value, $pretty_schema = true) { |
|
341 | + $field_obj = $model->field_settings_for($field_name); |
|
342 | + $value_on_model_obj = $field_obj->prepare_for_set_from_db($raw_db_value); |
|
343 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
344 | + $field_obj->set_date_format(EE_CSV::instance()->get_date_format_for_csv($field_obj->get_date_format($pretty_schema)), $pretty_schema); |
|
345 | + $field_obj->set_time_format(EE_CSV::instance()->get_time_format_for_csv($field_obj->get_time_format($pretty_schema)), $pretty_schema); |
|
346 | 346 | } |
347 | - if( $pretty_schema === true){ |
|
348 | - return $field_obj->prepare_for_pretty_echoing( $value_on_model_obj ); |
|
349 | - }elseif( is_string( $pretty_schema ) ) { |
|
350 | - return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema ); |
|
351 | - }else{ |
|
352 | - return $field_obj->prepare_for_get( $value_on_model_obj ); |
|
347 | + if ($pretty_schema === true) { |
|
348 | + return $field_obj->prepare_for_pretty_echoing($value_on_model_obj); |
|
349 | + }elseif (is_string($pretty_schema)) { |
|
350 | + return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema); |
|
351 | + } else { |
|
352 | + return $field_obj->prepare_for_get($value_on_model_obj); |
|
353 | 353 | } |
354 | 354 | } |
355 | 355 | |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | * and the questions associated with the registrations |
359 | 359 | * @param int $event_id |
360 | 360 | */ |
361 | - function report_registrations_for_event( $event_id = NULL ){ |
|
361 | + function report_registrations_for_event($event_id = NULL) { |
|
362 | 362 | $reg_fields_to_include = array( |
363 | 363 | 'TXN_ID', |
364 | 364 | 'ATT_ID', |
@@ -390,125 +390,125 @@ discard block |
||
390 | 390 | array( |
391 | 391 | 'OR' => array( |
392 | 392 | //don't include registrations from failed or abandoned transactions... |
393 | - 'Transaction.STS_ID' => array( 'NOT IN', array( EEM_Transaction::failed_status_code, EEM_Transaction::abandoned_status_code ) ), |
|
393 | + 'Transaction.STS_ID' => array('NOT IN', array(EEM_Transaction::failed_status_code, EEM_Transaction::abandoned_status_code)), |
|
394 | 394 | //unless the registration is approved, in which case include it regardless of transaction status |
395 | 395 | 'STS_ID' => EEM_Registration::status_id_approved |
396 | 396 | ), |
397 | - 'Ticket.TKT_deleted' => array( 'IN', array( true, false ) ) |
|
397 | + 'Ticket.TKT_deleted' => array('IN', array(true, false)) |
|
398 | 398 | ), |
399 | - 'order_by' => array('Transaction.TXN_ID'=>'asc','REG_count'=>'asc'), |
|
400 | - 'force_join' => array( 'Transaction', 'Ticket', 'Attendee' ) |
|
399 | + 'order_by' => array('Transaction.TXN_ID'=>'asc', 'REG_count'=>'asc'), |
|
400 | + 'force_join' => array('Transaction', 'Ticket', 'Attendee') |
|
401 | 401 | ), |
402 | 402 | $event_id |
403 | 403 | ); |
404 | - if( $event_id ){ |
|
405 | - $query_params[0]['EVT_ID'] = $event_id; |
|
406 | - }else{ |
|
407 | - $query_params[ 'force_join' ][] = 'Event'; |
|
404 | + if ($event_id) { |
|
405 | + $query_params[0]['EVT_ID'] = $event_id; |
|
406 | + } else { |
|
407 | + $query_params['force_join'][] = 'Event'; |
|
408 | 408 | } |
409 | - $registration_rows = $reg_model->get_all_wpdb_results( $query_params ); |
|
409 | + $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
410 | 410 | //get all questions which relate to someone in this group |
411 | 411 | $registration_ids = array(); |
412 | - foreach( $registration_rows as $reg_row ) { |
|
413 | - $registration_ids[] = intval( $reg_row[ 'Registration.REG_ID'] ); |
|
412 | + foreach ($registration_rows as $reg_row) { |
|
413 | + $registration_ids[] = intval($reg_row['Registration.REG_ID']); |
|
414 | 414 | } |
415 | 415 | // EEM_Question::instance()->show_next_x_db_queries(); |
416 | - $questions_for_these_regs_rows = EEM_Question::instance()->get_all_wpdb_results(array(array('Answer.REG_ID'=>array('IN',$registration_ids)))); |
|
417 | - foreach($registration_rows as $reg_row){ |
|
418 | - if ( is_array( $reg_row ) ) { |
|
416 | + $questions_for_these_regs_rows = EEM_Question::instance()->get_all_wpdb_results(array(array('Answer.REG_ID'=>array('IN', $registration_ids)))); |
|
417 | + foreach ($registration_rows as $reg_row) { |
|
418 | + if (is_array($reg_row)) { |
|
419 | 419 | $reg_csv_array = array(); |
420 | - if( ! $event_id ){ |
|
420 | + if ( ! $event_id) { |
|
421 | 421 | //get the event's name and Id |
422 | - $reg_csv_array[ __( 'Event', 'event_espresso' ) ] = sprintf( __( '%1$s (%2$s)', 'event_espresso' ), $this->_prepare_value_from_db_for_display( EEM_Event::instance(), 'EVT_name', $reg_row[ 'Event_CPT.post_title'] ), $reg_row[ 'Event_CPT.ID' ] ); |
|
422 | + $reg_csv_array[__('Event', 'event_espresso')] = sprintf(__('%1$s (%2$s)', 'event_espresso'), $this->_prepare_value_from_db_for_display(EEM_Event::instance(), 'EVT_name', $reg_row['Event_CPT.post_title']), $reg_row['Event_CPT.ID']); |
|
423 | 423 | } |
424 | - $is_primary_reg = $reg_row[ 'Registration.REG_count' ] == '1' ? true : false; |
|
424 | + $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
425 | 425 | /*@var $reg_row EE_Registration */ |
426 | - foreach($reg_fields_to_include as $field_name){ |
|
426 | + foreach ($reg_fields_to_include as $field_name) { |
|
427 | 427 | $field = $reg_model->field_settings_for($field_name); |
428 | - if($field_name == 'REG_final_price'){ |
|
429 | - $value = $this->_prepare_value_from_db_for_display( $reg_model, $field_name, $reg_row[ 'Registration.REG_final_price'], 'localized_float' ); |
|
430 | - }elseif( $field_name == 'REG_count' ){ |
|
431 | - $value = sprintf( __( '%s of %s', 'event_espresso' ), $this->_prepare_value_from_db_for_display( $reg_model, 'REG_count', $reg_row['Registration.REG_count'] ), $this->_prepare_value_from_db_for_display( $reg_model, 'REG_group_size', $reg_row['Registration.REG_group_size' ] ) ); |
|
432 | - }elseif( $field_name == 'REG_date' ) { |
|
433 | - $value = $this->_prepare_value_from_db_for_display( $reg_model, $field_name, $reg_row[ 'Registration.REG_date'], 'no_html' ); |
|
434 | - }else{ |
|
435 | - $value = $this->_prepare_value_from_db_for_display( $reg_model, $field_name, $reg_row[ $field->get_qualified_column() ] ); |
|
428 | + if ($field_name == 'REG_final_price') { |
|
429 | + $value = $this->_prepare_value_from_db_for_display($reg_model, $field_name, $reg_row['Registration.REG_final_price'], 'localized_float'); |
|
430 | + }elseif ($field_name == 'REG_count') { |
|
431 | + $value = sprintf(__('%s of %s', 'event_espresso'), $this->_prepare_value_from_db_for_display($reg_model, 'REG_count', $reg_row['Registration.REG_count']), $this->_prepare_value_from_db_for_display($reg_model, 'REG_group_size', $reg_row['Registration.REG_group_size'])); |
|
432 | + }elseif ($field_name == 'REG_date') { |
|
433 | + $value = $this->_prepare_value_from_db_for_display($reg_model, $field_name, $reg_row['Registration.REG_date'], 'no_html'); |
|
434 | + } else { |
|
435 | + $value = $this->_prepare_value_from_db_for_display($reg_model, $field_name, $reg_row[$field->get_qualified_column()]); |
|
436 | 436 | } |
437 | 437 | $reg_csv_array[$this->_get_column_name_for_field($field)] = $value; |
438 | - if($field_name == 'REG_final_price'){ |
|
438 | + if ($field_name == 'REG_final_price') { |
|
439 | 439 | //add a column named Currency after the final price |
440 | 440 | $reg_csv_array[__("Currency", "event_espresso")] = EE_Config::instance()->currency->code; |
441 | 441 | } |
442 | 442 | } |
443 | 443 | //get pretty status |
444 | - $stati = EEM_Status::instance()->localized_status( array( |
|
445 | - $reg_row[ 'Registration.STS_ID' ] => __( 'unknown', 'event_espresso' ), |
|
446 | - $reg_row[ 'Transaction.STS_ID' ] => __( 'unknown', 'event_espresso' ) ), |
|
444 | + $stati = EEM_Status::instance()->localized_status(array( |
|
445 | + $reg_row['Registration.STS_ID'] => __('unknown', 'event_espresso'), |
|
446 | + $reg_row['Transaction.STS_ID'] => __('unknown', 'event_espresso') ), |
|
447 | 447 | FALSE, |
448 | - 'sentence' ); |
|
449 | - $reg_csv_array[__("Registration Status", 'event_espresso')] = $stati[ $reg_row[ 'Registration.STS_ID' ] ]; |
|
448 | + 'sentence'); |
|
449 | + $reg_csv_array[__("Registration Status", 'event_espresso')] = $stati[$reg_row['Registration.STS_ID']]; |
|
450 | 450 | //get pretty trnasaction status |
451 | - $reg_csv_array[__("Transaction Status", 'event_espresso')] = $stati[ $reg_row[ 'Transaction.STS_ID' ] ]; |
|
452 | - $reg_csv_array[ __( 'Transaction Amount Due', 'event_espresso' ) ] = $is_primary_reg ? $this->_prepare_value_from_db_for_display( EEM_Transaction::instance(), 'TXN_total', $reg_row[ 'Transaction.TXN_total' ], 'localized_float' ) : '0.00'; |
|
453 | - $reg_csv_array[ __( 'Amount Paid', 'event_espresso' )] = $is_primary_reg ? $this->_prepare_value_from_db_for_display( EEM_Transaction::instance(), 'TXN_paid', $reg_row[ 'Transaction.TXN_paid' ], 'localized_float' ) : '0.00'; |
|
451 | + $reg_csv_array[__("Transaction Status", 'event_espresso')] = $stati[$reg_row['Transaction.STS_ID']]; |
|
452 | + $reg_csv_array[__('Transaction Amount Due', 'event_espresso')] = $is_primary_reg ? $this->_prepare_value_from_db_for_display(EEM_Transaction::instance(), 'TXN_total', $reg_row['Transaction.TXN_total'], 'localized_float') : '0.00'; |
|
453 | + $reg_csv_array[__('Amount Paid', 'event_espresso')] = $is_primary_reg ? $this->_prepare_value_from_db_for_display(EEM_Transaction::instance(), 'TXN_paid', $reg_row['Transaction.TXN_paid'], 'localized_float') : '0.00'; |
|
454 | 454 | $payment_methods = array(); |
455 | 455 | $gateway_txn_ids_etc = array(); |
456 | 456 | $payment_times = array(); |
457 | - if( $is_primary_reg && $reg_row[ 'Transaction.TXN_ID' ] ){ |
|
457 | + if ($is_primary_reg && $reg_row['Transaction.TXN_ID']) { |
|
458 | 458 | $payments_info = EEM_Payment::instance()->get_all_wpdb_results( |
459 | 459 | array( |
460 | 460 | array( |
461 | - 'TXN_ID' => $reg_row[ 'Transaction.TXN_ID' ], |
|
461 | + 'TXN_ID' => $reg_row['Transaction.TXN_ID'], |
|
462 | 462 | 'STS_ID' => EEM_Payment::status_id_approved |
463 | 463 | ), |
464 | - 'force_join' => array( 'Payment_Method' ), |
|
464 | + 'force_join' => array('Payment_Method'), |
|
465 | 465 | |
466 | 466 | ), |
467 | 467 | ARRAY_A, |
468 | 468 | 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' ); |
469 | 469 | |
470 | - foreach( $payments_info as $payment_method_and_gateway_txn_id ){ |
|
471 | - $payment_methods[] = isset( $payment_method_and_gateway_txn_id[ 'name' ] ) ? $payment_method_and_gateway_txn_id[ 'name' ] : __( 'Unknown', 'event_espresso' ); |
|
472 | - $gateway_txn_ids_etc[] = isset( $payment_method_and_gateway_txn_id[ 'gateway_txn_id' ] ) ? $payment_method_and_gateway_txn_id[ 'gateway_txn_id' ] : ''; |
|
473 | - $payment_times[] = isset( $payment_method_and_gateway_txn_id[ 'payment_time' ] ) ? $payment_method_and_gateway_txn_id[ 'payment_time' ] : ''; |
|
470 | + foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
471 | + $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso'); |
|
472 | + $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; |
|
473 | + $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
|
474 | 474 | } |
475 | 475 | |
476 | 476 | } |
477 | - $reg_csv_array[ __( 'Payment Date(s)', 'event_espresso' ) ] = implode( ',', $payment_times ); |
|
478 | - $reg_csv_array[ __( 'Payment Method(s)', 'event_espresso' ) ] = implode( ",", $payment_methods ); |
|
479 | - $reg_csv_array[ __( 'Gateway Transaction ID(s)', 'event_espresso' )] = implode( ',', $gateway_txn_ids_etc ); |
|
477 | + $reg_csv_array[__('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times); |
|
478 | + $reg_csv_array[__('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods); |
|
479 | + $reg_csv_array[__('Gateway Transaction ID(s)', 'event_espresso')] = implode(',', $gateway_txn_ids_etc); |
|
480 | 480 | |
481 | 481 | //get whether or not the user has checked in |
482 | - $reg_csv_array[__("Check-Ins", "event_espresso")] = $reg_model->count_related( $reg_row[ 'Registration.REG_ID'] , 'Checkin' ); |
|
482 | + $reg_csv_array[__("Check-Ins", "event_espresso")] = $reg_model->count_related($reg_row['Registration.REG_ID'], 'Checkin'); |
|
483 | 483 | //get ticket of registration and its price |
484 | 484 | $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
485 | - if( $reg_row[ 'Ticket.TKT_ID'] ) { |
|
486 | - $ticket_name = $this->_prepare_value_from_db_for_display( $ticket_model, 'TKT_name', $reg_row[ 'Ticket.TKT_name' ] ); |
|
485 | + if ($reg_row['Ticket.TKT_ID']) { |
|
486 | + $ticket_name = $this->_prepare_value_from_db_for_display($ticket_model, 'TKT_name', $reg_row['Ticket.TKT_name']); |
|
487 | 487 | $datetimes_strings = array(); |
488 | - foreach( EEM_Datetime::instance()->get_all_wpdb_results( array( array( 'Ticket.TKT_ID' => $reg_row[ 'Ticket.TKT_ID' ] ), 'order_by' => array( 'DTT_EVT_start' => 'ASC' ), 'default_where_conditions' => 'none' ) ) as $datetime){ |
|
489 | - $datetimes_strings[] = $this->_prepare_value_from_db_for_display( EEM_Datetime::instance(), 'DTT_EVT_start', $datetime[ 'Datetime.DTT_EVT_start'] ); |
|
488 | + foreach (EEM_Datetime::instance()->get_all_wpdb_results(array(array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), 'order_by' => array('DTT_EVT_start' => 'ASC'), 'default_where_conditions' => 'none')) as $datetime) { |
|
489 | + $datetimes_strings[] = $this->_prepare_value_from_db_for_display(EEM_Datetime::instance(), 'DTT_EVT_start', $datetime['Datetime.DTT_EVT_start']); |
|
490 | 490 | } |
491 | 491 | |
492 | 492 | } else { |
493 | - $ticket_name = __( 'Unknown', 'event_espresso' ); |
|
494 | - $datetimes_strings = array( __( 'Unknown', 'event_espresso' ) ); |
|
493 | + $ticket_name = __('Unknown', 'event_espresso'); |
|
494 | + $datetimes_strings = array(__('Unknown', 'event_espresso')); |
|
495 | 495 | } |
496 | 496 | $reg_csv_array[$ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name; |
497 | 497 | $reg_csv_array[__("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings); |
498 | 498 | //get datetime(s) of registration |
499 | 499 | |
500 | 500 | //add attendee columns |
501 | - foreach($att_fields_to_include as $att_field_name){ |
|
501 | + foreach ($att_fields_to_include as $att_field_name) { |
|
502 | 502 | $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name); |
503 | - if( $reg_row[ 'Attendee_CPT.ID' ]){ |
|
504 | - if($att_field_name == 'STA_ID'){ |
|
505 | - $value = EEM_State::instance()->get_var( array( array( 'STA_ID' => $reg_row[ 'Attendee_Meta.STA_ID' ] ) ), 'STA_name' ); |
|
506 | - }elseif($att_field_name == 'CNT_ISO'){ |
|
507 | - $value = EEM_Country::instance()->get_var( array( array( 'CNT_ISO' => $reg_row[ 'Attendee_Meta.CNT_ISO' ] ) ), 'CNT_name' ); |
|
508 | - }else{ |
|
509 | - $value = $this->_prepare_value_from_db_for_display( EEM_Attendee::instance(), $att_field_name, $reg_row[ $field_obj->get_qualified_column() ] ); |
|
503 | + if ($reg_row['Attendee_CPT.ID']) { |
|
504 | + if ($att_field_name == 'STA_ID') { |
|
505 | + $value = EEM_State::instance()->get_var(array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), 'STA_name'); |
|
506 | + }elseif ($att_field_name == 'CNT_ISO') { |
|
507 | + $value = EEM_Country::instance()->get_var(array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), 'CNT_name'); |
|
508 | + } else { |
|
509 | + $value = $this->_prepare_value_from_db_for_display(EEM_Attendee::instance(), $att_field_name, $reg_row[$field_obj->get_qualified_column()]); |
|
510 | 510 | } |
511 | - }else{ |
|
511 | + } else { |
|
512 | 512 | $value = ''; |
513 | 513 | } |
514 | 514 | |
@@ -516,56 +516,56 @@ discard block |
||
516 | 516 | } |
517 | 517 | |
518 | 518 | //make sure each registration has the same questions in the same order |
519 | - foreach($questions_for_these_regs_rows as $question_row){ |
|
520 | - if( ! isset($reg_csv_array[$question_row[ 'Question.QST_admin_label']])){ |
|
521 | - $reg_csv_array[$question_row[ 'Question.QST_admin_label' ] ] = null; |
|
519 | + foreach ($questions_for_these_regs_rows as $question_row) { |
|
520 | + if ( ! isset($reg_csv_array[$question_row['Question.QST_admin_label']])) { |
|
521 | + $reg_csv_array[$question_row['Question.QST_admin_label']] = null; |
|
522 | 522 | } |
523 | 523 | } |
524 | 524 | //now fill out the questions THEY answered |
525 | - foreach( EEM_Answer::instance()->get_all_wpdb_results( array( array( 'REG_ID' => $reg_row[ 'Registration.REG_ID' ] ), 'force_join' => array( 'Question' ) ) ) as $answer_row){ |
|
525 | + foreach (EEM_Answer::instance()->get_all_wpdb_results(array(array('REG_ID' => $reg_row['Registration.REG_ID']), 'force_join' => array('Question'))) as $answer_row) { |
|
526 | 526 | /* @var $answer EE_Answer */ |
527 | - if( $answer_row[ 'Question.QST_ID' ] ){ |
|
528 | - $question_label = $this->_prepare_value_from_db_for_display( EEM_Question::instance(), 'QST_admin_label', $answer_row[ 'Question.QST_admin_label' ] ); |
|
529 | - }else{ |
|
530 | - $question_label = sprintf( __( 'Question $s', 'event_espresso' ), $answer_row[ 'Answer.QST_ID' ] ); |
|
527 | + if ($answer_row['Question.QST_ID']) { |
|
528 | + $question_label = $this->_prepare_value_from_db_for_display(EEM_Question::instance(), 'QST_admin_label', $answer_row['Question.QST_admin_label']); |
|
529 | + } else { |
|
530 | + $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
531 | 531 | } |
532 | - if( isset( $answer_row[ 'Question.QST_type'] ) && $answer_row[ 'Question.QST_type' ] == EEM_Question::QST_type_state ) { |
|
533 | - $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( $answer_row[ 'Answer.ANS_value' ] ); |
|
532 | + if (isset($answer_row['Question.QST_type']) && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state) { |
|
533 | + $reg_csv_array[$question_label] = EEM_State::instance()->get_state_name_by_ID($answer_row['Answer.ANS_value']); |
|
534 | 534 | } else { |
535 | - $reg_csv_array[ $question_label ] = $this->_prepare_value_from_db_for_display( EEM_Answer::instance(), 'ANS_value', $answer_row[ 'Answer.ANS_value' ] ); |
|
535 | + $reg_csv_array[$question_label] = $this->_prepare_value_from_db_for_display(EEM_Answer::instance(), 'ANS_value', $answer_row['Answer.ANS_value']); |
|
536 | 536 | } |
537 | 537 | } |
538 | - $registrations_csv_ready_array[] = apply_filters( 'FHEE__EE_Export__report_registrations__reg_csv_array', $reg_csv_array, $reg_row ); |
|
538 | + $registrations_csv_ready_array[] = apply_filters('FHEE__EE_Export__report_registrations__reg_csv_array', $reg_csv_array, $reg_row); |
|
539 | 539 | } |
540 | 540 | } |
541 | 541 | |
542 | 542 | //if we couldn't export anything, we want to at least show the column headers |
543 | - if(empty($registrations_csv_ready_array)){ |
|
543 | + if (empty($registrations_csv_ready_array)) { |
|
544 | 544 | $reg_csv_array = array(); |
545 | 545 | $model_and_fields_to_include = array( |
546 | 546 | 'Registration' => $reg_fields_to_include, |
547 | 547 | 'Attendee' => $att_fields_to_include |
548 | 548 | ); |
549 | - foreach($model_and_fields_to_include as $model_name => $field_list){ |
|
549 | + foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
550 | 550 | $model = EE_Registry::instance()->load_model($model_name); |
551 | - foreach($field_list as $field_name){ |
|
551 | + foreach ($field_list as $field_name) { |
|
552 | 552 | $field = $model->field_settings_for($field_name); |
553 | - $reg_csv_array[$this->_get_column_name_for_field($field)] = null;//$registration->get($field->get_name()); |
|
553 | + $reg_csv_array[$this->_get_column_name_for_field($field)] = null; //$registration->get($field->get_name()); |
|
554 | 554 | } |
555 | 555 | } |
556 | 556 | $registrations_csv_ready_array [] = $reg_csv_array; |
557 | 557 | } |
558 | - if( $event_id ){ |
|
559 | - $event_slug = EEM_Event::instance()->get_var( array( array( 'EVT_ID' => $event_id ) ), 'EVT_slug' ); |
|
560 | - if( ! $event_slug ) { |
|
561 | - $event_slug = __( 'unknown', 'event_espresso' ); |
|
558 | + if ($event_id) { |
|
559 | + $event_slug = EEM_Event::instance()->get_var(array(array('EVT_ID' => $event_id)), 'EVT_slug'); |
|
560 | + if ( ! $event_slug) { |
|
561 | + $event_slug = __('unknown', 'event_espresso'); |
|
562 | 562 | } |
563 | - }else{ |
|
564 | - $event_slug = __( 'all', 'event_espresso' ); |
|
563 | + } else { |
|
564 | + $event_slug = __('all', 'event_espresso'); |
|
565 | 565 | } |
566 | - $filename = sprintf( "registrations-for-%s", $event_slug ); |
|
566 | + $filename = sprintf("registrations-for-%s", $event_slug); |
|
567 | 567 | |
568 | - $handle = $this->EE_CSV->begin_sending_csv( $filename); |
|
568 | + $handle = $this->EE_CSV->begin_sending_csv($filename); |
|
569 | 569 | $this->EE_CSV->write_data_array_to_csv($handle, $registrations_csv_ready_array); |
570 | 570 | $this->EE_CSV->end_sending_csv($handle); |
571 | 571 | } |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | * @param EE_Model_Field_Base $field |
576 | 576 | * @return string |
577 | 577 | */ |
578 | - protected function _get_column_name_for_field(EE_Model_Field_Base $field){ |
|
578 | + protected function _get_column_name_for_field(EE_Model_Field_Base $field) { |
|
579 | 579 | return $field->get_nicename()."[".$field->get_name()."]"; |
580 | 580 | } |
581 | 581 | |
@@ -588,17 +588,17 @@ discard block |
||
588 | 588 | function export_categories() { |
589 | 589 | // are any Event IDs set? |
590 | 590 | $query_params = array(); |
591 | - if ( isset( $this->_req_data['EVT_CAT_ID'] )) { |
|
591 | + if (isset($this->_req_data['EVT_CAT_ID'])) { |
|
592 | 592 | // do we have an array of IDs ? |
593 | - if ( is_array( $this->_req_data['EVT_CAT_ID'] )) { |
|
593 | + if (is_array($this->_req_data['EVT_CAT_ID'])) { |
|
594 | 594 | // generate an "IN (CSV)" where clause |
595 | - $EVT_CAT_IDs = array_map( 'sanitize_text_field', $this->_req_data['EVT_CAT_ID'] ); |
|
595 | + $EVT_CAT_IDs = array_map('sanitize_text_field', $this->_req_data['EVT_CAT_ID']); |
|
596 | 596 | $filename = 'event-categories'; |
597 | - $query_params[0]['term_taxonomy_id'] = array('IN',$EVT_CAT_IDs); |
|
597 | + $query_params[0]['term_taxonomy_id'] = array('IN', $EVT_CAT_IDs); |
|
598 | 598 | } else { |
599 | 599 | // generate regular where = clause |
600 | - $EVT_CAT_ID = absint( $this->_req_data['EVT_CAT_ID'] ); |
|
601 | - $filename = 'event-category#' . $EVT_CAT_ID; |
|
600 | + $EVT_CAT_ID = absint($this->_req_data['EVT_CAT_ID']); |
|
601 | + $filename = 'event-category#'.$EVT_CAT_ID; |
|
602 | 602 | $query_params[0]['term_taxonomy_id'] = $EVT_CAT_ID; |
603 | 603 | } |
604 | 604 | } else { |
@@ -610,11 +610,11 @@ discard block |
||
610 | 610 | 'Term_Taxonomy' => $query_params |
611 | 611 | ); |
612 | 612 | |
613 | - $table_data = $this->_get_export_data_for_models( $tables_to_export ); |
|
614 | - $filename = $this->generate_filename ( $filename ); |
|
613 | + $table_data = $this->_get_export_data_for_models($tables_to_export); |
|
614 | + $filename = $this->generate_filename($filename); |
|
615 | 615 | |
616 | - if ( ! $this->EE_CSV->export_multiple_model_data_to_csv( $filename, $table_data )) { |
|
617 | - EE_Error::add_error(__('An error occurred and the Category details could not be exported from the database.','event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
616 | + if ( ! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $table_data)) { |
|
617 | + EE_Error::add_error(__('An error occurred and the Category details could not be exported from the database.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
618 | 618 | } |
619 | 619 | } |
620 | 620 | |
@@ -625,13 +625,13 @@ discard block |
||
625 | 625 | * @param string - export_name |
626 | 626 | * @return string on success, FALSE on fail |
627 | 627 | */ |
628 | - private function generate_filename ( $export_name = '' ) { |
|
629 | - if ( $export_name != '' ) { |
|
630 | - $filename = get_bloginfo('name') . '-' . $export_name; |
|
631 | - $filename = sanitize_key( $filename ) . '-' . $this->today; |
|
628 | + private function generate_filename($export_name = '') { |
|
629 | + if ($export_name != '') { |
|
630 | + $filename = get_bloginfo('name').'-'.$export_name; |
|
631 | + $filename = sanitize_key($filename).'-'.$this->today; |
|
632 | 632 | return $filename; |
633 | - } else { |
|
634 | - EE_Error::add_error(__("No filename was provided", "event_espresso"), __FILE__, __FUNCTION__, __LINE__ ); |
|
633 | + } else { |
|
634 | + EE_Error::add_error(__("No filename was provided", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
635 | 635 | } |
636 | 636 | return false; |
637 | 637 | } |
@@ -644,37 +644,37 @@ discard block |
||
644 | 644 | * @param array $models_to_export keys are model names (eg 'Event', 'Attendee', etc.) and values are arrays of query params like on EEM_Base::get_all |
645 | 645 | * @return array on success, FALSE on fail |
646 | 646 | */ |
647 | - private function _get_export_data_for_models( $models_to_export = array() ) { |
|
647 | + private function _get_export_data_for_models($models_to_export = array()) { |
|
648 | 648 | $table_data = FALSE; |
649 | - if ( is_array( $models_to_export ) ) { |
|
650 | - foreach ( $models_to_export as $model_name => $query_params ) { |
|
649 | + if (is_array($models_to_export)) { |
|
650 | + foreach ($models_to_export as $model_name => $query_params) { |
|
651 | 651 | //check for a numerically-indexed array. in that case, $model_name is the value!! |
652 | - if(is_int($model_name)){ |
|
652 | + if (is_int($model_name)) { |
|
653 | 653 | $model_name = $query_params; |
654 | 654 | $query_params = array(); |
655 | 655 | } |
656 | - if( ! isset( $query_params[ 'default_where_conditions'] ) ) { |
|
657 | - $query_params[ 'default_where_conditions' ] = 'minimum'; |
|
656 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
657 | + $query_params['default_where_conditions'] = 'minimum'; |
|
658 | 658 | } |
659 | 659 | $model = EE_Registry::instance()->load_model($model_name); |
660 | 660 | $model_objects = $model->get_all($query_params); |
661 | 661 | |
662 | 662 | |
663 | 663 | $table_data[$model_name] = array(); |
664 | - foreach($model_objects as $model_object){ |
|
664 | + foreach ($model_objects as $model_object) { |
|
665 | 665 | $model_data_array = array(); |
666 | 666 | $fields = $model->field_settings(); |
667 | - foreach($fields as $field){ |
|
667 | + foreach ($fields as $field) { |
|
668 | 668 | $column_name = $field->get_nicename()."[".$field->get_name()."]"; |
669 | - if($field instanceof EE_Datetime_Field){ |
|
669 | + if ($field instanceof EE_Datetime_Field) { |
|
670 | 670 | // $field->set_date_format('Y-m-d'); |
671 | 671 | // $field->set_time_format('H:i:s'); |
672 | - $model_data_array[$column_name] = $model_object->get_datetime($field->get_name(),'Y-m-d','H:i:s'); |
|
673 | - } elseif( $field instanceof EE_Infinite_Integer_Field && |
|
674 | - $model_object->get( $field->get_name() ) === EE_INF ) { |
|
672 | + $model_data_array[$column_name] = $model_object->get_datetime($field->get_name(), 'Y-m-d', 'H:i:s'); |
|
673 | + } elseif ($field instanceof EE_Infinite_Integer_Field && |
|
674 | + $model_object->get($field->get_name()) === EE_INF) { |
|
675 | 675 | $model_data_array[$column_name] = ""; |
676 | 676 | } |
677 | - else{ |
|
677 | + else { |
|
678 | 678 | $model_data_array[$column_name] = $model_object->get($field->get_name()); |
679 | 679 | } |
680 | 680 | } |
@@ -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 | /* |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * @subpackage core/db_models/strategies/ |
12 | 12 | * @author Michael Nelson |
13 | 13 | */ |
14 | -class EE_CPT_Where_Conditions extends EE_Default_Where_Conditions{ |
|
14 | +class EE_CPT_Where_Conditions extends EE_Default_Where_Conditions { |
|
15 | 15 | |
16 | 16 | protected $_post_type; |
17 | 17 | protected $_meta_field; |
@@ -23,10 +23,10 @@ discard block |
||
23 | 23 | * @param string $meta_field_to_chk |
24 | 24 | * @param array $custom_where_conditions |
25 | 25 | */ |
26 | - function __construct( $post_type, $meta_field_to_chk, $custom_where_conditions = array() ){ |
|
26 | + function __construct($post_type, $meta_field_to_chk, $custom_where_conditions = array()) { |
|
27 | 27 | $this->_post_type = $post_type; |
28 | 28 | $this->_meta_field = $meta_field_to_chk; |
29 | - parent::__construct( $custom_where_conditions ); |
|
29 | + parent::__construct($custom_where_conditions); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | |
@@ -39,16 +39,16 @@ discard block |
||
39 | 39 | * @return \EE_Model_Field_Base |
40 | 40 | * @throws \EE_Error |
41 | 41 | */ |
42 | - protected function _get_field_on_column( $column ){ |
|
43 | - $all_fields = $this->_model->field_settings( true ); |
|
44 | - foreach ( $all_fields as $field_obj ) { |
|
45 | - if ( $column == $field_obj->get_table_column() ) { |
|
42 | + protected function _get_field_on_column($column) { |
|
43 | + $all_fields = $this->_model->field_settings(true); |
|
44 | + foreach ($all_fields as $field_obj) { |
|
45 | + if ($column == $field_obj->get_table_column()) { |
|
46 | 46 | return $field_obj; |
47 | 47 | } |
48 | 48 | } |
49 | 49 | throw new EE_Error( |
50 | 50 | sprintf( |
51 | - __( 'Model EE_CPT_Where_Conditions misconfigured. Looking for a field with column %1$s on model %2$s but none found.', 'event_espresso'), |
|
51 | + __('Model EE_CPT_Where_Conditions misconfigured. Looking for a field with column %1$s on model %2$s but none found.', 'event_espresso'), |
|
52 | 52 | $column, |
53 | 53 | $this->_model->get_this_model_name() |
54 | 54 | ) |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * CPT models, otherwise we could get rows which aren't of this post type |
63 | 63 | * @return array |
64 | 64 | */ |
65 | - function _get_minimum_where_conditions(){ |
|
65 | + function _get_minimum_where_conditions() { |
|
66 | 66 | return array( |
67 | 67 | $this->_get_field_on_column('post_type')->get_name() => $this->_post_type |
68 | 68 | ); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | $status_field = $this->_get_field_on_column('post_status'); |
80 | 80 | return array_replace_recursive( |
81 | 81 | $this->_get_minimum_where_conditions(), |
82 | - array( $status_field->get_name() => array('NOT IN',array('auto-draft','trash'))) |
|
82 | + array($status_field->get_name() => array('NOT IN', array('auto-draft', 'trash'))) |
|
83 | 83 | ); |
84 | 84 | } |
85 | 85 | } |