@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | * |
24 | 24 | * ------------------------------------------------------------------------ |
25 | 25 | */ |
26 | -require_once ( EE_MODELS . 'EEM_Base.model.php' ); |
|
27 | -require_once ( EE_CLASSES . 'EE_Checkin.class.php' ); |
|
26 | +require_once (EE_MODELS.'EEM_Base.model.php'); |
|
27 | +require_once (EE_CLASSES.'EE_Checkin.class.php'); |
|
28 | 28 | |
29 | 29 | class EEM_Checkin extends EEM_Base { |
30 | 30 | |
@@ -40,12 +40,12 @@ discard block |
||
40 | 40 | * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
41 | 41 | * @return void |
42 | 42 | */ |
43 | - protected function __construct( $timezone = NULL ) { |
|
44 | - $this->singular_item = __('Check-In','event_espresso'); |
|
45 | - $this->plural_item = __('Check-Ins','event_espresso'); |
|
43 | + protected function __construct($timezone = NULL) { |
|
44 | + $this->singular_item = __('Check-In', 'event_espresso'); |
|
45 | + $this->plural_item = __('Check-Ins', 'event_espresso'); |
|
46 | 46 | |
47 | 47 | $this->_tables = array( |
48 | - 'Checkin'=>new EE_Primary_Table('esp_checkin','CHK_ID') |
|
48 | + 'Checkin'=>new EE_Primary_Table('esp_checkin', 'CHK_ID') |
|
49 | 49 | ); |
50 | 50 | $this->_fields = array( |
51 | 51 | 'Checkin'=> array( |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | 'REG_ID'=>new EE_Foreign_Key_Int_Field('REG_ID', 'Registration Id', false, 0, 'Registration'), |
54 | 54 | 'DTT_ID'=>new EE_Foreign_Key_Int_Field('DTT_ID', 'Datetime Id', false, 0, 'Datetime'), |
55 | 55 | 'CHK_in'=>new EE_Boolean_Field('CHK_in', 'Whether a person has checked in or checked out', false, true), |
56 | - 'CHK_timestamp'=>new EE_Datetime_Field('CHK_timestamp', __('When the row was modified','event_espresso'), false, EE_Datetime_Field::now, $timezone ) |
|
56 | + 'CHK_timestamp'=>new EE_Datetime_Field('CHK_timestamp', __('When the row was modified', 'event_espresso'), false, EE_Datetime_Field::now, $timezone) |
|
57 | 57 | ) |
58 | 58 | ); |
59 | 59 | $this->_model_relations = array( |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | 'Datetime'=>new EE_Belongs_To_Relation() |
62 | 62 | ); |
63 | 63 | $this->_model_chain_to_wp_user = 'Registration.Event'; |
64 | - parent::__construct( $timezone ); |
|
64 | + parent::__construct($timezone); |
|
65 | 65 | |
66 | 66 | } |
67 | 67 |
@@ -1,4 +1,6 @@ |
||
1 | -<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | +} |
|
2 | 4 | /** |
3 | 5 | * Event Espresso |
4 | 6 | * |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * @since $VID:$ |
13 | 13 | * |
14 | 14 | */ |
15 | -class EE_Select2_Display_Strategy extends EE_Select_Display_Strategy{ |
|
15 | +class EE_Select2_Display_Strategy extends EE_Select_Display_Strategy { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Arguments that will be passed into the select2 javascript constructor |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * @param array $select2_js_args pass in the EXACT array of JS arguments you want |
26 | 26 | * to pass into the select2 js/html input. See https://select2.github.io |
27 | 27 | */ |
28 | - public function __construct( $select2_js_args = array() ) { |
|
28 | + public function __construct($select2_js_args = array()) { |
|
29 | 29 | $this->_select2_js_args = $select2_js_args; |
30 | 30 | parent::__construct(); |
31 | 31 | } |
@@ -37,12 +37,12 @@ discard block |
||
37 | 37 | public function enqueue_js() { |
38 | 38 | // need to first deregister the select2 script in case some other plugin **cough cough Toolset Types cough** |
39 | 39 | // is carelessly registering an older version of Select2 on admin pages that don't even belong to them |
40 | - wp_deregister_script( 'select2' ); |
|
41 | - wp_deregister_style( 'select2' ); |
|
42 | - wp_register_script( 'select2', EE_GLOBAL_ASSETS_URL . 'scripts/select2.min.js', array(), '4.0.2', true ); |
|
43 | - wp_register_style( 'select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all' ); |
|
44 | - wp_enqueue_script( 'form_section_select2_init', EE_GLOBAL_ASSETS_URL . 'scripts/form_section_select2_init.js', array( 'select2' ), '1.0.0', true ); |
|
45 | - wp_enqueue_style( 'select2', EE_GLOBAL_ASSETS_URL . 'css/select2.min.css', array(), '4.0.2', 'all' ); |
|
40 | + wp_deregister_script('select2'); |
|
41 | + wp_deregister_style('select2'); |
|
42 | + wp_register_script('select2', EE_GLOBAL_ASSETS_URL.'scripts/select2.min.js', array(), '4.0.2', true); |
|
43 | + wp_register_style('select2', EE_GLOBAL_ASSETS_URL.'css/select2.min.css', array(), '4.0.2', 'all'); |
|
44 | + wp_enqueue_script('form_section_select2_init', EE_GLOBAL_ASSETS_URL.'scripts/form_section_select2_init.js', array('select2'), '1.0.0', true); |
|
45 | + wp_enqueue_style('select2', EE_GLOBAL_ASSETS_URL.'css/select2.min.css', array(), '4.0.2', 'all'); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * Sets the exact js args which will be passed into the select2 js/html input |
58 | 58 | * @param array $js_args |
59 | 59 | */ |
60 | - public function set_js_args( $js_args ) { |
|
60 | + public function set_js_args($js_args) { |
|
61 | 61 | $this->_select2_js_args = $js_args; |
62 | 62 | } |
63 | 63 | |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | * @param array $other_js_data |
67 | 67 | * @return array |
68 | 68 | */ |
69 | - public function get_other_js_data( $other_js_data = array() ) { |
|
70 | - $other_js_data = parent::get_other_js_data( $other_js_data ); |
|
71 | - if( ! isset( $other_js_data[ 'select2s' ] ) ) { |
|
69 | + public function get_other_js_data($other_js_data = array()) { |
|
70 | + $other_js_data = parent::get_other_js_data($other_js_data); |
|
71 | + if ( ! isset($other_js_data['select2s'])) { |
|
72 | 72 | $other_js_data['select2s'] = array(); |
73 | 73 | } |
74 | - $other_js_data[ 'select2s' ][ $this->_input->html_id() ] = $this->get_js_args(); |
|
74 | + $other_js_data['select2s'][$this->_input->html_id()] = $this->get_js_args(); |
|
75 | 75 | return $other_js_data; |
76 | 76 | } |
77 | 77 | } |
78 | 78 | \ No newline at end of file |
@@ -2,7 +2,7 @@ |
||
2 | 2 | namespace EventEspresso\core\services\commands; |
3 | 3 | |
4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 |
@@ -1,6 +1,8 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\interfaces\ResettableInterface; |
2 | 2 | |
3 | -if (!defined( 'EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
3 | +if (!defined( 'EVENT_ESPRESSO_VERSION')) { |
|
4 | + exit('No direct script access allowed'); |
|
5 | +} |
|
4 | 6 | do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
5 | 7 | /** |
6 | 8 | * EE_Import class |
@@ -297,7 +299,7 @@ discard block |
||
297 | 299 | if(isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()){ |
298 | 300 | EE_Error::add_attention(sprintf(__("CSV Data appears to be from the same database, so attempting to update data", "event_espresso"))); |
299 | 301 | $export_from_site_a_to_b = false; |
300 | - }else{ |
|
302 | + } else{ |
|
301 | 303 | $old_site_url = isset( $csv_metadata['site_url']) ? $csv_metadata['site_url'] : $old_site_url; |
302 | 304 | EE_Error::add_attention(sprintf(__("CSV Data appears to be from a different database (%s instead of %s), so we assume IDs in the CSV data DO NOT correspond to IDs in this database", "event_espresso"),$old_site_url,site_url())); |
303 | 305 | }; |
@@ -378,7 +380,7 @@ discard block |
||
378 | 380 | //now check that assumption was correct. If |
379 | 381 | if ( EE_Registry::instance()->is_model_name($model_name_in_csv_data)) { |
380 | 382 | $model_name = $model_name_in_csv_data; |
381 | - }else { |
|
383 | + } else { |
|
382 | 384 | // no table info in the array and no table name passed to the function?? FAIL |
383 | 385 | EE_Error::add_error( __('No table information was specified and/or found, therefore the import could not be completed','event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
384 | 386 | return FALSE; |
@@ -402,7 +404,7 @@ discard block |
||
402 | 404 | //there is no primary key) |
403 | 405 | if($model->has_primary_key_field()){ |
404 | 406 | $id_in_csv = $model_object_data[$model->primary_key_name()]; |
405 | - }else{ |
|
407 | + } else{ |
|
406 | 408 | $id_in_csv = $model->get_index_primary_key_string($model_object_data); |
407 | 409 | } |
408 | 410 | |
@@ -412,7 +414,7 @@ discard block |
||
412 | 414 | //or just update. |
413 | 415 | if($export_from_site_a_to_b){ |
414 | 416 | $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 ); |
415 | - }else{//this is just a re-import |
|
417 | + } else{//this is just a re-import |
|
416 | 418 | $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
417 | 419 | } |
418 | 420 | if( $what_to_do == self::do_nothing ) { |
@@ -432,7 +434,7 @@ discard block |
||
432 | 434 | if($model->has_primary_key_field()){ |
433 | 435 | $old_db_to_new_db_mapping[$model_name][$id_in_csv] = $conflicting->ID(); |
434 | 436 | $model_object_data[$model->primary_key_name()] = $conflicting->ID(); |
435 | - }else{ |
|
437 | + } else{ |
|
436 | 438 | //we want to update this conflicting item, instead of inserting a conflicting item |
437 | 439 | //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 |
438 | 440 | //for the WHERE conditions in the update). At the time of this comment, there were no models like this |
@@ -444,9 +446,9 @@ discard block |
||
444 | 446 | } |
445 | 447 | if( $what_to_do == self::do_insert ) { |
446 | 448 | $old_db_to_new_db_mapping = $this->_insert_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
447 | - }elseif( $what_to_do == self::do_update ) { |
|
449 | + } elseif( $what_to_do == self::do_update ) { |
|
448 | 450 | $old_db_to_new_db_mapping = $this->_update_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
449 | - }else{ |
|
451 | + } else{ |
|
450 | 452 | throw new EE_Error( sprintf( __( 'Programming error. We shoudl be inserting or updating, but instead we are being told to "%s", whifh is invalid', 'event_espresso' ), $what_to_do ) ); |
451 | 453 | } |
452 | 454 | } |
@@ -474,7 +476,7 @@ discard block |
||
474 | 476 | //in the old data that we know of |
475 | 477 | if( isset($old_db_to_new_db_mapping[$model_name][$id_in_csv]) ){ |
476 | 478 | return self::do_update; |
477 | - }else{ |
|
479 | + } else{ |
|
478 | 480 | return self::do_insert; |
479 | 481 | } |
480 | 482 | } |
@@ -493,7 +495,7 @@ discard block |
||
493 | 495 | //in this case, check if this thing ACTUALLY exists in the database |
494 | 496 | if( $model->get_one_conflicting( $model_object_data ) ){ |
495 | 497 | return self::do_update; |
496 | - }else{ |
|
498 | + } else{ |
|
497 | 499 | return self::do_insert; |
498 | 500 | } |
499 | 501 | } |
@@ -524,7 +526,7 @@ discard block |
||
524 | 526 | try{ |
525 | 527 | $model_name_field = $model->get_field_containing_related_model_name(); |
526 | 528 | $models_pointed_to_by_model_name_field = $model_name_field->get_model_names_pointed_to(); |
527 | - }catch( EE_Error $e ){ |
|
529 | + } catch( EE_Error $e ){ |
|
528 | 530 | $model_name_field = NULL; |
529 | 531 | $models_pointed_to_by_model_name_field = array(); |
530 | 532 | } |
@@ -545,7 +547,7 @@ discard block |
||
545 | 547 | $found_a_mapping = true; |
546 | 548 | break; |
547 | 549 | } |
548 | - }else{ |
|
550 | + } else{ |
|
549 | 551 | $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
550 | 552 | $model_object_data[ $field_obj->get_name() ], |
551 | 553 | $model_pointed_to_by_fk, |
@@ -560,7 +562,7 @@ discard block |
||
560 | 562 | |
561 | 563 | |
562 | 564 | } |
563 | - }else{ |
|
565 | + } else{ |
|
564 | 566 | //it's a string foreign key (which we leave alone, because those are things |
565 | 567 | //like country names, which we'd really rather not make 2 USAs etc (we'd actually |
566 | 568 | //prefer to just update one) |
@@ -603,14 +605,14 @@ discard block |
||
603 | 605 | if( isset( $old_db_to_new_db_mapping[ $model_name ][ $object_id ] ) ){ |
604 | 606 | |
605 | 607 | return $old_db_to_new_db_mapping[ $model_name ][ $object_id ]; |
606 | - }elseif( $object_id == '0' || $object_id == '' ) { |
|
608 | + } elseif( $object_id == '0' || $object_id == '' ) { |
|
607 | 609 | //leave as-is |
608 | 610 | return $object_id; |
609 | - }elseif( $export_from_site_a_to_b ){ |
|
611 | + } elseif( $export_from_site_a_to_b ){ |
|
610 | 612 | //we couldn't find a mapping for this, and it's from a different site, |
611 | 613 | //so blank it out |
612 | 614 | return NULL; |
613 | - }elseif( ! $export_from_site_a_to_b ) { |
|
615 | + } elseif( ! $export_from_site_a_to_b ) { |
|
614 | 616 | //we coudln't find a mapping for this, but it's from thsi DB anyway |
615 | 617 | //so let's just leave it as-is |
616 | 618 | return $object_id; |
@@ -631,7 +633,7 @@ discard block |
||
631 | 633 | if($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()){ |
632 | 634 | $effective_id = $model_object_data[$model->primary_key_name()]; |
633 | 635 | unset($model_object_data[$model->primary_key_name()]); |
634 | - }else{ |
|
636 | + } else{ |
|
635 | 637 | $effective_id = $model->get_index_primary_key_string( $model_object_data ); |
636 | 638 | } |
637 | 639 | //the model takes care of validating the CSV's input |
@@ -641,7 +643,7 @@ discard block |
||
641 | 643 | $old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_id; |
642 | 644 | $this->_total_inserts++; |
643 | 645 | EE_Error::add_success( sprintf(__("Successfully added new %s (with id %s) with csv data %s", "event_espresso"),$model->get_this_model_name(),$new_id, implode(",",$model_object_data))); |
644 | - }else{ |
|
646 | + } else{ |
|
645 | 647 | $this->_total_insert_errors++; |
646 | 648 | //put the ID used back in there for the error message |
647 | 649 | if($model->has_primary_key_field()){ |
@@ -649,7 +651,7 @@ discard block |
||
649 | 651 | } |
650 | 652 | EE_Error::add_error( sprintf(__("Could not insert new %s with the csv data: %s", "event_espresso"),$model->get_this_model_name(),http_build_query($model_object_data)), __FILE__, __FUNCTION__, __LINE__ ); |
651 | 653 | } |
652 | - }catch(EE_Error $e){ |
|
654 | + } catch(EE_Error $e){ |
|
653 | 655 | $this->_total_insert_errors++; |
654 | 656 | if($model->has_primary_key_field()){ |
655 | 657 | $model_object_data[$model->primary_key_name()] = $effective_id; |
@@ -676,12 +678,12 @@ discard block |
||
676 | 678 | $conditions = array($model->primary_key_name() => $model_object_data[$model->primary_key_name()]); |
677 | 679 | //remove the primary key because we shouldn't use it for updating |
678 | 680 | unset($model_object_data_for_update[$model->primary_key_name()]); |
679 | - }elseif($model->get_combined_primary_key_fields() > 1 ){ |
|
681 | + } elseif($model->get_combined_primary_key_fields() > 1 ){ |
|
680 | 682 | $conditions = array(); |
681 | 683 | foreach($model->get_combined_primary_key_fields() as $key_field){ |
682 | 684 | $conditions[$key_field->get_name()] = $model_object_data[$key_field->get_name()]; |
683 | 685 | } |
684 | - }else{ |
|
686 | + } else{ |
|
685 | 687 | $model->primary_key_name();//this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey) |
686 | 688 | } |
687 | 689 | |
@@ -695,23 +697,23 @@ discard block |
||
695 | 697 | //and so we record what record ended up being updated using the mapping |
696 | 698 | if( $model->has_primary_key_field() ){ |
697 | 699 | $new_key_for_mapping = $model_object_data[ $model->primary_key_name() ]; |
698 | - }else{ |
|
700 | + } else{ |
|
699 | 701 | //no primary key just a combined key |
700 | 702 | $new_key_for_mapping = $model->get_index_primary_key_string( $model_object_data ); |
701 | 703 | } |
702 | 704 | $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_key_for_mapping; |
703 | - }else{ |
|
705 | + } else{ |
|
704 | 706 | $matched_items = $model->get_all(array($conditions)); |
705 | 707 | if( ! $matched_items){ |
706 | 708 | //no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck? |
707 | 709 | $this->_total_update_errors++; |
708 | 710 | EE_Error::add_error( sprintf(__("Could not update %s with the csv data: '%s' for an unknown reason (using WHERE conditions %s)", "event_espresso"),$model->get_this_model_name(),http_build_query($model_object_data),http_build_query($conditions)), __FILE__, __FUNCTION__, __LINE__ ); |
709 | - }else{ |
|
711 | + } else{ |
|
710 | 712 | $this->_total_updates++; |
711 | 713 | EE_Error::add_success( sprintf(__("%s with csv data '%s' was found in the database and didn't need updating because all the data is identical.", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data))); |
712 | 714 | } |
713 | 715 | } |
714 | - }catch(EE_Error $e){ |
|
716 | + } catch(EE_Error $e){ |
|
715 | 717 | $this->_total_update_errors++; |
716 | 718 | $basic_message = sprintf(__("Could not update %s with the csv data: %s because %s", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data),$e->getMessage()); |
717 | 719 | $debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString(); |
@@ -131,43 +131,43 @@ discard block |
||
131 | 131 | if ( isset( $_REQUEST['import'] )) { |
132 | 132 | if( isset( $_POST['csv_submitted'] )) { |
133 | 133 | |
134 | - switch ( $_FILES['file']['error'][0] ) { |
|
135 | - case UPLOAD_ERR_OK: |
|
136 | - $error_msg = FALSE; |
|
137 | - break; |
|
138 | - case UPLOAD_ERR_INI_SIZE: |
|
139 | - $error_msg = __("'The uploaded file exceeds the upload_max_filesize directive in php.ini.'", "event_espresso"); |
|
140 | - break; |
|
141 | - case UPLOAD_ERR_FORM_SIZE: |
|
142 | - $error_msg = __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', "event_espresso"); |
|
143 | - break; |
|
144 | - case UPLOAD_ERR_PARTIAL: |
|
145 | - $error_msg = __('The uploaded file was only partially uploaded.', "event_espresso"); |
|
146 | - break; |
|
147 | - case UPLOAD_ERR_NO_FILE: |
|
148 | - $error_msg = __('No file was uploaded.', "event_espresso"); |
|
149 | - break; |
|
150 | - case UPLOAD_ERR_NO_TMP_DIR: |
|
151 | - $error_msg = __('Missing a temporary folder.', "event_espresso"); |
|
152 | - break; |
|
153 | - case UPLOAD_ERR_CANT_WRITE: |
|
154 | - $error_msg = __('Failed to write file to disk.', "event_espresso"); |
|
155 | - break; |
|
156 | - case UPLOAD_ERR_EXTENSION: |
|
157 | - $error_msg = __('File upload stopped by extension.', "event_espresso"); |
|
158 | - break; |
|
159 | - default: |
|
160 | - $error_msg = __('An unknown error occurred and the file could not be uploaded', "event_espresso"); |
|
161 | - break; |
|
162 | - } |
|
134 | + switch ( $_FILES['file']['error'][0] ) { |
|
135 | + case UPLOAD_ERR_OK: |
|
136 | + $error_msg = FALSE; |
|
137 | + break; |
|
138 | + case UPLOAD_ERR_INI_SIZE: |
|
139 | + $error_msg = __("'The uploaded file exceeds the upload_max_filesize directive in php.ini.'", "event_espresso"); |
|
140 | + break; |
|
141 | + case UPLOAD_ERR_FORM_SIZE: |
|
142 | + $error_msg = __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', "event_espresso"); |
|
143 | + break; |
|
144 | + case UPLOAD_ERR_PARTIAL: |
|
145 | + $error_msg = __('The uploaded file was only partially uploaded.', "event_espresso"); |
|
146 | + break; |
|
147 | + case UPLOAD_ERR_NO_FILE: |
|
148 | + $error_msg = __('No file was uploaded.', "event_espresso"); |
|
149 | + break; |
|
150 | + case UPLOAD_ERR_NO_TMP_DIR: |
|
151 | + $error_msg = __('Missing a temporary folder.', "event_espresso"); |
|
152 | + break; |
|
153 | + case UPLOAD_ERR_CANT_WRITE: |
|
154 | + $error_msg = __('Failed to write file to disk.', "event_espresso"); |
|
155 | + break; |
|
156 | + case UPLOAD_ERR_EXTENSION: |
|
157 | + $error_msg = __('File upload stopped by extension.', "event_espresso"); |
|
158 | + break; |
|
159 | + default: |
|
160 | + $error_msg = __('An unknown error occurred and the file could not be uploaded', "event_espresso"); |
|
161 | + break; |
|
162 | + } |
|
163 | 163 | |
164 | 164 | if ( ! $error_msg ) { |
165 | 165 | |
166 | - $filename = $_FILES['file']['name'][0]; |
|
166 | + $filename = $_FILES['file']['name'][0]; |
|
167 | 167 | $file_ext = substr( strrchr( $filename, '.' ), 1 ); |
168 | - $file_type = $_FILES['file']['type'][0]; |
|
169 | - $temp_file = $_FILES['file']['tmp_name'][0]; |
|
170 | - $filesize = $_FILES['file']['size'][0] / 1024;//convert from bytes to KB |
|
168 | + $file_type = $_FILES['file']['type'][0]; |
|
169 | + $temp_file = $_FILES['file']['tmp_name'][0]; |
|
170 | + $filesize = $_FILES['file']['size'][0] / 1024;//convert from bytes to KB |
|
171 | 171 | |
172 | 172 | if ( $file_ext=='csv' ) { |
173 | 173 | |
@@ -242,40 +242,40 @@ discard block |
||
242 | 242 | |
243 | 243 | |
244 | 244 | |
245 | - /** |
|
246 | - * Given an array of data (usually from a CSV import) attempts to save that data to the db. |
|
247 | - * If $model_name ISN'T provided, assumes that this is a 3d array, with toplevel keys being model names, |
|
248 | - * next level being numeric indexes adn each value representing a model object, and the last layer down |
|
249 | - * being keys of model fields and their proposed values. |
|
250 | - * If $model_name IS provided, assumes a 2d array of the bottom two layers previously mentioned. |
|
251 | - * If the CSV data says (in the metadata row) that it's from the SAME database, |
|
252 | - * we treat the IDs in the CSV as the normal IDs, and try to update those records. However, if those |
|
253 | - * IDs DON'T exist in the database, they're treated as temporary IDs, |
|
254 | - * which can used elsewhere to refer to the same object. Once an item |
|
255 | - * with a temporary ID gets inserted, we record its mapping from temporary |
|
256 | - * ID to real ID, and use the real ID in place of the temporary ID |
|
257 | - * when that temporary ID was used as a foreign key. |
|
258 | - * If the CSV data says (in the metadata again) that it's from a DIFFERENT database, |
|
259 | - * we treat all the IDs in the CSV as temporary ID- eg, if the CSV specifies an event with |
|
260 | - * ID 1, and the database already has an event with ID 1, we assume that's just a coincidence, |
|
261 | - * and insert a new event, and map it's temporary ID of 1 over to its new real ID. |
|
262 | - * An important exception are non-auto-increment primary keys. If one entry in the |
|
263 | - * CSV file has the same ID as one in the DB, we assume they are meant to be |
|
264 | - * the same item, and instead update the item in the DB with that same ID. |
|
265 | - * Also note, we remember the mappings permanently. So the 2nd, 3rd, and 10000th |
|
266 | - * time you import a CSV from a different site, we remember their mappings, and |
|
267 | - * will try to update the item in the DB instead of inserting another item (eg |
|
268 | - * if we previously imported an event with temporary ID 1, and then it got a |
|
269 | - * real ID of 123, we remember that. So the next time we import an event with |
|
270 | - * temporary ID, from the same site, we know that it's real ID is 123, and will |
|
271 | - * update that event, instead of adding a new event). |
|
272 | - * |
|
273 | - * @access public |
|
274 | - * @param array $csv_data_array - the array containing the csv data produced from EE_CSV::import_csv_to_model_data_array() |
|
275 | - * @param array $fields_to_save - an array containing the csv column names as keys with the corresponding db table fields they will be saved to |
|
276 | - * @return TRUE on success, FALSE on fail |
|
277 | - * @throws \EE_Error |
|
278 | - */ |
|
245 | + /** |
|
246 | + * Given an array of data (usually from a CSV import) attempts to save that data to the db. |
|
247 | + * If $model_name ISN'T provided, assumes that this is a 3d array, with toplevel keys being model names, |
|
248 | + * next level being numeric indexes adn each value representing a model object, and the last layer down |
|
249 | + * being keys of model fields and their proposed values. |
|
250 | + * If $model_name IS provided, assumes a 2d array of the bottom two layers previously mentioned. |
|
251 | + * If the CSV data says (in the metadata row) that it's from the SAME database, |
|
252 | + * we treat the IDs in the CSV as the normal IDs, and try to update those records. However, if those |
|
253 | + * IDs DON'T exist in the database, they're treated as temporary IDs, |
|
254 | + * which can used elsewhere to refer to the same object. Once an item |
|
255 | + * with a temporary ID gets inserted, we record its mapping from temporary |
|
256 | + * ID to real ID, and use the real ID in place of the temporary ID |
|
257 | + * when that temporary ID was used as a foreign key. |
|
258 | + * If the CSV data says (in the metadata again) that it's from a DIFFERENT database, |
|
259 | + * we treat all the IDs in the CSV as temporary ID- eg, if the CSV specifies an event with |
|
260 | + * ID 1, and the database already has an event with ID 1, we assume that's just a coincidence, |
|
261 | + * and insert a new event, and map it's temporary ID of 1 over to its new real ID. |
|
262 | + * An important exception are non-auto-increment primary keys. If one entry in the |
|
263 | + * CSV file has the same ID as one in the DB, we assume they are meant to be |
|
264 | + * the same item, and instead update the item in the DB with that same ID. |
|
265 | + * Also note, we remember the mappings permanently. So the 2nd, 3rd, and 10000th |
|
266 | + * time you import a CSV from a different site, we remember their mappings, and |
|
267 | + * will try to update the item in the DB instead of inserting another item (eg |
|
268 | + * if we previously imported an event with temporary ID 1, and then it got a |
|
269 | + * real ID of 123, we remember that. So the next time we import an event with |
|
270 | + * temporary ID, from the same site, we know that it's real ID is 123, and will |
|
271 | + * update that event, instead of adding a new event). |
|
272 | + * |
|
273 | + * @access public |
|
274 | + * @param array $csv_data_array - the array containing the csv data produced from EE_CSV::import_csv_to_model_data_array() |
|
275 | + * @param array $fields_to_save - an array containing the csv column names as keys with the corresponding db table fields they will be saved to |
|
276 | + * @return TRUE on success, FALSE on fail |
|
277 | + * @throws \EE_Error |
|
278 | + */ |
|
279 | 279 | public function save_csv_data_array_to_db( $csv_data_array, $model_name = FALSE ) { |
280 | 280 | |
281 | 281 | |
@@ -306,10 +306,10 @@ discard block |
||
306 | 306 | unset($csv_data_array[EE_CSV::metadata_header]); |
307 | 307 | } |
308 | 308 | /** |
309 | - * @var $old_db_to_new_db_mapping 2d array: toplevel keys being model names, bottom-level keys being the original key, and |
|
310 | - * the value will be the newly-inserted ID. |
|
311 | - * If we have already imported data from the same website via CSV, it shoudl be kept in this wp option |
|
312 | - */ |
|
309 | + * @var $old_db_to_new_db_mapping 2d array: toplevel keys being model names, bottom-level keys being the original key, and |
|
310 | + * the value will be the newly-inserted ID. |
|
311 | + * If we have already imported data from the same website via CSV, it shoudl be kept in this wp option |
|
312 | + */ |
|
313 | 313 | $old_db_to_new_db_mapping = get_option('ee_id_mapping_from'.sanitize_title($old_site_url),array()); |
314 | 314 | if( $old_db_to_new_db_mapping){ |
315 | 315 | EE_Error::add_attention(sprintf(__("We noticed you have imported data via CSV from %s before. Because of this, IDs in your CSV have been mapped to their new IDs in %s", "event_espresso"),$old_site_url,site_url())); |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\interfaces\ResettableInterface; |
2 | 2 | |
3 | -if (!defined( 'EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
4 | -do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
4 | +do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
5 | 5 | /** |
6 | 6 | * EE_Import class |
7 | 7 | * |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public static function instance() { |
60 | 60 | // check if class object is instantiated |
61 | - if ( self::$_instance === NULL or ! is_object( self::$_instance ) or ! ( self::$_instance instanceof EE_Import )) { |
|
61 | + if (self::$_instance === NULL or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Import)) { |
|
62 | 62 | self::$_instance = new self(); |
63 | 63 | } |
64 | 64 | return self::$_instance; |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * Resets the importer |
69 | 69 | * @return EE_Import |
70 | 70 | */ |
71 | - public static function reset(){ |
|
71 | + public static function reset() { |
|
72 | 72 | self::$_instance = null; |
73 | 73 | return self::instance(); |
74 | 74 | } |
@@ -86,27 +86,27 @@ discard block |
||
86 | 86 | * @param string $type - type of file to import |
87 | 87 | * @ return string |
88 | 88 | */ |
89 | - public function upload_form ( $title, $intro, $form_url, $action, $type ) { |
|
89 | + public function upload_form($title, $intro, $form_url, $action, $type) { |
|
90 | 90 | |
91 | - $form_url = EE_Admin_Page::add_query_args_and_nonce( array( 'action' => $action ), $form_url ); |
|
91 | + $form_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => $action), $form_url); |
|
92 | 92 | |
93 | 93 | ob_start(); |
94 | 94 | ?> |
95 | 95 | <div class="ee-upload-form-dv"> |
96 | - <h3><?php echo $title;?></h3> |
|
97 | - <p><?php echo $intro;?></p> |
|
96 | + <h3><?php echo $title; ?></h3> |
|
97 | + <p><?php echo $intro; ?></p> |
|
98 | 98 | |
99 | 99 | <form action="<?php echo $form_url?>" method="post" enctype="multipart/form-data"> |
100 | - <input type="hidden" name="csv_submitted" value="TRUE" id="<?php echo time();?>"> |
|
101 | - <input name="import" type="hidden" value="<?php echo $type;?>" /> |
|
100 | + <input type="hidden" name="csv_submitted" value="TRUE" id="<?php echo time(); ?>"> |
|
101 | + <input name="import" type="hidden" value="<?php echo $type; ?>" /> |
|
102 | 102 | <input type="file" name="file[]" size="90" > |
103 | - <input class="button-primary" type="submit" value="<?php _e( 'Upload File', 'event_espresso' );?>"> |
|
103 | + <input class="button-primary" type="submit" value="<?php _e('Upload File', 'event_espresso'); ?>"> |
|
104 | 104 | </form> |
105 | 105 | |
106 | 106 | <p class="ee-attention"> |
107 | - <b><?php _e( 'Attention', 'event_espresso' );?></b><br/> |
|
108 | - <?php echo sprintf( __( 'Accepts .%s file types only.', 'event_espresso' ), $type ) ;?> |
|
109 | - <?php echo __( 'Please only import CSV files exported from Event Espresso, or compatible 3rd-party software.', 'event_espresso' );?> |
|
107 | + <b><?php _e('Attention', 'event_espresso'); ?></b><br/> |
|
108 | + <?php echo sprintf(__('Accepts .%s file types only.', 'event_espresso'), $type); ?> |
|
109 | + <?php echo __('Please only import CSV files exported from Event Espresso, or compatible 3rd-party software.', 'event_espresso'); ?> |
|
110 | 110 | </p> |
111 | 111 | |
112 | 112 | </div> |
@@ -127,13 +127,13 @@ discard block |
||
127 | 127 | */ |
128 | 128 | public function import() { |
129 | 129 | |
130 | - require_once( EE_CLASSES . 'EE_CSV.class.php' ); |
|
130 | + require_once(EE_CLASSES.'EE_CSV.class.php'); |
|
131 | 131 | $this->EE_CSV = EE_CSV::instance(); |
132 | 132 | |
133 | - if ( isset( $_REQUEST['import'] )) { |
|
134 | - if( isset( $_POST['csv_submitted'] )) { |
|
133 | + if (isset($_REQUEST['import'])) { |
|
134 | + if (isset($_POST['csv_submitted'])) { |
|
135 | 135 | |
136 | - switch ( $_FILES['file']['error'][0] ) { |
|
136 | + switch ($_FILES['file']['error'][0]) { |
|
137 | 137 | case UPLOAD_ERR_OK: |
138 | 138 | $error_msg = FALSE; |
139 | 139 | break; |
@@ -163,32 +163,32 @@ discard block |
||
163 | 163 | break; |
164 | 164 | } |
165 | 165 | |
166 | - if ( ! $error_msg ) { |
|
166 | + if ( ! $error_msg) { |
|
167 | 167 | |
168 | - $filename = $_FILES['file']['name'][0]; |
|
169 | - $file_ext = substr( strrchr( $filename, '.' ), 1 ); |
|
170 | - $file_type = $_FILES['file']['type'][0]; |
|
171 | - $temp_file = $_FILES['file']['tmp_name'][0]; |
|
172 | - $filesize = $_FILES['file']['size'][0] / 1024;//convert from bytes to KB |
|
168 | + $filename = $_FILES['file']['name'][0]; |
|
169 | + $file_ext = substr(strrchr($filename, '.'), 1); |
|
170 | + $file_type = $_FILES['file']['type'][0]; |
|
171 | + $temp_file = $_FILES['file']['tmp_name'][0]; |
|
172 | + $filesize = $_FILES['file']['size'][0] / 1024; //convert from bytes to KB |
|
173 | 173 | |
174 | - if ( $file_ext=='csv' ) { |
|
174 | + if ($file_ext == 'csv') { |
|
175 | 175 | |
176 | - $max_upload = $this->EE_CSV->get_max_upload_size();//max upload size in KB |
|
177 | - if ( $filesize < $max_upload || true) { |
|
176 | + $max_upload = $this->EE_CSV->get_max_upload_size(); //max upload size in KB |
|
177 | + if ($filesize < $max_upload || true) { |
|
178 | 178 | |
179 | - $wp_upload_dir = str_replace( array( '\\', '/' ), DS, wp_upload_dir()); |
|
180 | - $path_to_file = $wp_upload_dir['basedir'] . DS . 'espresso' . DS . $filename; |
|
179 | + $wp_upload_dir = str_replace(array('\\', '/'), DS, wp_upload_dir()); |
|
180 | + $path_to_file = $wp_upload_dir['basedir'].DS.'espresso'.DS.$filename; |
|
181 | 181 | |
182 | - if( move_uploaded_file( $temp_file, $path_to_file )) { |
|
182 | + if (move_uploaded_file($temp_file, $path_to_file)) { |
|
183 | 183 | |
184 | 184 | // convert csv to array |
185 | - $this->csv_array = $this->EE_CSV->import_csv_to_model_data_array( $path_to_file ); |
|
185 | + $this->csv_array = $this->EE_CSV->import_csv_to_model_data_array($path_to_file); |
|
186 | 186 | |
187 | 187 | // was data successfully stored in an array? |
188 | - if ( is_array( $this->csv_array ) ) { |
|
188 | + if (is_array($this->csv_array)) { |
|
189 | 189 | |
190 | - $import_what = str_replace( 'csv_import_', '', $_REQUEST['action'] ); |
|
191 | - $import_what = str_replace( '_', ' ', ucwords( $import_what )); |
|
190 | + $import_what = str_replace('csv_import_', '', $_REQUEST['action']); |
|
191 | + $import_what = str_replace('_', ' ', ucwords($import_what)); |
|
192 | 192 | $processed_data = $this->csv_array; |
193 | 193 | $this->columns_to_save = FALSE; |
194 | 194 | |
@@ -207,33 +207,33 @@ discard block |
||
207 | 207 | |
208 | 208 | } |
209 | 209 | // save processed codes to db |
210 | - if ( $this->save_csv_data_array_to_db( $processed_data, $this->columns_to_save ) ) { |
|
210 | + if ($this->save_csv_data_array_to_db($processed_data, $this->columns_to_save)) { |
|
211 | 211 | return TRUE; |
212 | 212 | |
213 | 213 | } |
214 | 214 | } else { |
215 | 215 | // no array? must be an error |
216 | - EE_Error::add_error(sprintf(__("No file seems to have been uploaded", "event_espresso")), __FILE__, __FUNCTION__, __LINE__ ); |
|
216 | + EE_Error::add_error(sprintf(__("No file seems to have been uploaded", "event_espresso")), __FILE__, __FUNCTION__, __LINE__); |
|
217 | 217 | return FALSE; |
218 | 218 | } |
219 | 219 | |
220 | 220 | } else { |
221 | - EE_Error::add_error(sprintf(__("%s was not successfully uploaded", "event_espresso"),$filename), __FILE__, __FUNCTION__, __LINE__ ); |
|
221 | + EE_Error::add_error(sprintf(__("%s was not successfully uploaded", "event_espresso"), $filename), __FILE__, __FUNCTION__, __LINE__); |
|
222 | 222 | return FALSE; |
223 | 223 | } |
224 | 224 | |
225 | 225 | } else { |
226 | - EE_Error::add_error( sprintf(__("%s was too large of a file and could not be uploaded. The max filesize is %s' KB.", "event_espresso"),$filename,$max_upload), __FILE__, __FUNCTION__, __LINE__ ); |
|
226 | + EE_Error::add_error(sprintf(__("%s was too large of a file and could not be uploaded. The max filesize is %s' KB.", "event_espresso"), $filename, $max_upload), __FILE__, __FUNCTION__, __LINE__); |
|
227 | 227 | return FALSE; |
228 | 228 | } |
229 | 229 | |
230 | 230 | } else { |
231 | - EE_Error::add_error( sprintf(__("%s had an invalid file extension, not uploaded", "event_espresso"),$filename), __FILE__, __FUNCTION__, __LINE__ ); |
|
231 | + EE_Error::add_error(sprintf(__("%s had an invalid file extension, not uploaded", "event_espresso"), $filename), __FILE__, __FUNCTION__, __LINE__); |
|
232 | 232 | return FALSE; |
233 | 233 | } |
234 | 234 | |
235 | 235 | } else { |
236 | - EE_Error::add_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
236 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
237 | 237 | return FALSE; |
238 | 238 | } |
239 | 239 | |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | * @return TRUE on success, FALSE on fail |
279 | 279 | * @throws \EE_Error |
280 | 280 | */ |
281 | - public function save_csv_data_array_to_db( $csv_data_array, $model_name = FALSE ) { |
|
281 | + public function save_csv_data_array_to_db($csv_data_array, $model_name = FALSE) { |
|
282 | 282 | |
283 | 283 | |
284 | 284 | $success = FALSE; |
@@ -288,22 +288,22 @@ discard block |
||
288 | 288 | $export_from_site_a_to_b = true; |
289 | 289 | // first level of array is not table information but a table name was passed to the function |
290 | 290 | // array is only two levels deep, so let's fix that by adding a level, else the next steps will fail |
291 | - if($model_name){ |
|
291 | + if ($model_name) { |
|
292 | 292 | $csv_data_array = array($csv_data_array); |
293 | 293 | } |
294 | 294 | // begin looking through the $csv_data_array, expecting the toplevel key to be the model's name... |
295 | 295 | $old_site_url = 'none-specified'; |
296 | 296 | |
297 | 297 | //hanlde metadata |
298 | - if(isset($csv_data_array[EE_CSV::metadata_header]) ){ |
|
298 | + if (isset($csv_data_array[EE_CSV::metadata_header])) { |
|
299 | 299 | $csv_metadata = array_shift($csv_data_array[EE_CSV::metadata_header]); |
300 | 300 | //ok so its metadata, dont try to save it to ehte db obviously... |
301 | - if(isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()){ |
|
301 | + if (isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()) { |
|
302 | 302 | EE_Error::add_attention(sprintf(__("CSV Data appears to be from the same database, so attempting to update data", "event_espresso"))); |
303 | 303 | $export_from_site_a_to_b = false; |
304 | - }else{ |
|
305 | - $old_site_url = isset( $csv_metadata['site_url']) ? $csv_metadata['site_url'] : $old_site_url; |
|
306 | - EE_Error::add_attention(sprintf(__("CSV Data appears to be from a different database (%s instead of %s), so we assume IDs in the CSV data DO NOT correspond to IDs in this database", "event_espresso"),$old_site_url,site_url())); |
|
304 | + } else { |
|
305 | + $old_site_url = isset($csv_metadata['site_url']) ? $csv_metadata['site_url'] : $old_site_url; |
|
306 | + EE_Error::add_attention(sprintf(__("CSV Data appears to be from a different database (%s instead of %s), so we assume IDs in the CSV data DO NOT correspond to IDs in this database", "event_espresso"), $old_site_url, site_url())); |
|
307 | 307 | }; |
308 | 308 | unset($csv_data_array[EE_CSV::metadata_header]); |
309 | 309 | } |
@@ -312,30 +312,30 @@ discard block |
||
312 | 312 | * the value will be the newly-inserted ID. |
313 | 313 | * If we have already imported data from the same website via CSV, it shoudl be kept in this wp option |
314 | 314 | */ |
315 | - $old_db_to_new_db_mapping = get_option('ee_id_mapping_from'.sanitize_title($old_site_url),array()); |
|
316 | - if( $old_db_to_new_db_mapping){ |
|
317 | - EE_Error::add_attention(sprintf(__("We noticed you have imported data via CSV from %s before. Because of this, IDs in your CSV have been mapped to their new IDs in %s", "event_espresso"),$old_site_url,site_url())); |
|
315 | + $old_db_to_new_db_mapping = get_option('ee_id_mapping_from'.sanitize_title($old_site_url), array()); |
|
316 | + if ($old_db_to_new_db_mapping) { |
|
317 | + EE_Error::add_attention(sprintf(__("We noticed you have imported data via CSV from %s before. Because of this, IDs in your CSV have been mapped to their new IDs in %s", "event_espresso"), $old_site_url, site_url())); |
|
318 | 318 | } |
319 | 319 | $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); |
320 | 320 | |
321 | 321 | //save the mapping from old db to new db in case they try re-importing the same data from the same website again |
322 | - update_option('ee_id_mapping_from'.sanitize_title($old_site_url),$old_db_to_new_db_mapping); |
|
322 | + update_option('ee_id_mapping_from'.sanitize_title($old_site_url), $old_db_to_new_db_mapping); |
|
323 | 323 | |
324 | - if ( $this->_total_updates > 0 ) { |
|
325 | - EE_Error::add_success( sprintf(__("%s existing records in the database were updated.", "event_espresso"),$this->_total_updates)); |
|
324 | + if ($this->_total_updates > 0) { |
|
325 | + EE_Error::add_success(sprintf(__("%s existing records in the database were updated.", "event_espresso"), $this->_total_updates)); |
|
326 | 326 | $success = true; |
327 | 327 | } |
328 | - if ( $this->_total_inserts > 0 ) { |
|
329 | - EE_Error::add_success(sprintf(__("%s new records were added to the database.", "event_espresso"),$this->_total_inserts)); |
|
328 | + if ($this->_total_inserts > 0) { |
|
329 | + EE_Error::add_success(sprintf(__("%s new records were added to the database.", "event_espresso"), $this->_total_inserts)); |
|
330 | 330 | $success = true; |
331 | 331 | } |
332 | 332 | |
333 | - if ( $this->_total_update_errors > 0 ) { |
|
334 | - 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->_total_update_errors), __FILE__, __FUNCTION__, __LINE__ ); |
|
333 | + if ($this->_total_update_errors > 0) { |
|
334 | + 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->_total_update_errors), __FILE__, __FUNCTION__, __LINE__); |
|
335 | 335 | $error = true; |
336 | 336 | } |
337 | - if ( $this->_total_insert_errors > 0 ) { |
|
338 | - 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->_total_insert_errors), __FILE__, __FUNCTION__, __LINE__ ); |
|
337 | + if ($this->_total_insert_errors > 0) { |
|
338 | + 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->_total_insert_errors), __FILE__, __FUNCTION__, __LINE__); |
|
339 | 339 | $error = true; |
340 | 340 | } |
341 | 341 | |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | EEM_Ticket::instance()->update_tickets_sold(EEM_Ticket::instance()->get_all()); |
345 | 345 | |
346 | 346 | // if there was at least one success and absolutely no errors |
347 | - if ( $success && ! $error ) { |
|
347 | + if ($success && ! $error) { |
|
348 | 348 | return TRUE; |
349 | 349 | } else { |
350 | 350 | return FALSE; |
@@ -376,81 +376,81 @@ discard block |
||
376 | 376 | * @param type $old_db_to_new_db_mapping |
377 | 377 | * @return array updated $old_db_to_new_db_mapping |
378 | 378 | */ |
379 | - public function save_data_rows_to_db( $csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping ) { |
|
380 | - foreach ( $csv_data_array as $model_name_in_csv_data => $model_data_from_import ) { |
|
379 | + public function save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping) { |
|
380 | + foreach ($csv_data_array as $model_name_in_csv_data => $model_data_from_import) { |
|
381 | 381 | //now check that assumption was correct. If |
382 | - if ( EE_Registry::instance()->is_model_name($model_name_in_csv_data)) { |
|
382 | + if (EE_Registry::instance()->is_model_name($model_name_in_csv_data)) { |
|
383 | 383 | $model_name = $model_name_in_csv_data; |
384 | - }else { |
|
384 | + } else { |
|
385 | 385 | // no table info in the array and no table name passed to the function?? FAIL |
386 | - EE_Error::add_error( __('No table information was specified and/or found, therefore the import could not be completed','event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
386 | + EE_Error::add_error(__('No table information was specified and/or found, therefore the import could not be completed', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
387 | 387 | return FALSE; |
388 | 388 | } |
389 | 389 | /* @var $model EEM_Base */ |
390 | 390 | $model = EE_Registry::instance()->load_model($model_name); |
391 | 391 | |
392 | 392 | //so without further ado, scanning all the data provided for primary keys and their inital values |
393 | - foreach ( $model_data_from_import as $model_object_data ) { |
|
393 | + foreach ($model_data_from_import as $model_object_data) { |
|
394 | 394 | //before we do ANYTHING, make sure the csv row wasn't just completely blank |
395 | 395 | $row_is_completely_empty = true; |
396 | - foreach($model_object_data as $field){ |
|
397 | - if($field){ |
|
396 | + foreach ($model_object_data as $field) { |
|
397 | + if ($field) { |
|
398 | 398 | $row_is_completely_empty = false; |
399 | 399 | } |
400 | 400 | } |
401 | - if($row_is_completely_empty){ |
|
401 | + if ($row_is_completely_empty) { |
|
402 | 402 | continue; |
403 | 403 | } |
404 | 404 | //find the PK in the row of data (or a combined key if |
405 | 405 | //there is no primary key) |
406 | - if($model->has_primary_key_field()){ |
|
407 | - $id_in_csv = $model_object_data[$model->primary_key_name()]; |
|
408 | - }else{ |
|
406 | + if ($model->has_primary_key_field()) { |
|
407 | + $id_in_csv = $model_object_data[$model->primary_key_name()]; |
|
408 | + } else { |
|
409 | 409 | $id_in_csv = $model->get_index_primary_key_string($model_object_data); |
410 | 410 | } |
411 | 411 | |
412 | 412 | |
413 | - $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 ); |
|
413 | + $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); |
|
414 | 414 | //now we need to decide if we're going to add a new model object given the $model_object_data, |
415 | 415 | //or just update. |
416 | - if($export_from_site_a_to_b){ |
|
417 | - $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 ); |
|
418 | - }else{//this is just a re-import |
|
419 | - $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
|
416 | + if ($export_from_site_a_to_b) { |
|
417 | + $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); |
|
418 | + } else {//this is just a re-import |
|
419 | + $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping); |
|
420 | 420 | } |
421 | - if( $what_to_do == self::do_nothing ) { |
|
421 | + if ($what_to_do == self::do_nothing) { |
|
422 | 422 | continue; |
423 | 423 | } |
424 | 424 | |
425 | 425 | //double-check we actually want to insert, if that's what we're planning |
426 | 426 | //based on whether this item would be unique in the DB or not |
427 | - if( $what_to_do == self::do_insert ) { |
|
427 | + if ($what_to_do == self::do_insert) { |
|
428 | 428 | //we're supposed to be inserting. But wait, will this thing |
429 | 429 | //be acceptable if inserted? |
430 | - $conflicting = $model->get_one_conflicting( $model_object_data, false ); |
|
431 | - if($conflicting){ |
|
430 | + $conflicting = $model->get_one_conflicting($model_object_data, false); |
|
431 | + if ($conflicting) { |
|
432 | 432 | //ok, this item would conflict if inserted. Just update the item that it conflicts with. |
433 | 433 | $what_to_do = self::do_update; |
434 | 434 | //and if this model has a primary key, remember its mapping |
435 | - if($model->has_primary_key_field()){ |
|
435 | + if ($model->has_primary_key_field()) { |
|
436 | 436 | $old_db_to_new_db_mapping[$model_name][$id_in_csv] = $conflicting->ID(); |
437 | 437 | $model_object_data[$model->primary_key_name()] = $conflicting->ID(); |
438 | - }else{ |
|
438 | + } else { |
|
439 | 439 | //we want to update this conflicting item, instead of inserting a conflicting item |
440 | 440 | //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 |
441 | 441 | //for the WHERE conditions in the update). At the time of this comment, there were no models like this |
442 | - foreach($model->get_combined_primary_key_fields() as $key_field){ |
|
442 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
443 | 443 | $model_object_data[$key_field->get_name()] = $conflicting->get($key_field->get_name()); |
444 | 444 | } |
445 | 445 | } |
446 | 446 | } |
447 | 447 | } |
448 | - if( $what_to_do == self::do_insert ) { |
|
449 | - $old_db_to_new_db_mapping = $this->_insert_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
|
450 | - }elseif( $what_to_do == self::do_update ) { |
|
451 | - $old_db_to_new_db_mapping = $this->_update_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
|
452 | - }else{ |
|
453 | - throw new EE_Error( sprintf( __( 'Programming error. We shoudl be inserting or updating, but instead we are being told to "%s", whifh is invalid', 'event_espresso' ), $what_to_do ) ); |
|
448 | + if ($what_to_do == self::do_insert) { |
|
449 | + $old_db_to_new_db_mapping = $this->_insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping); |
|
450 | + }elseif ($what_to_do == self::do_update) { |
|
451 | + $old_db_to_new_db_mapping = $this->_update_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping); |
|
452 | + } else { |
|
453 | + throw new EE_Error(sprintf(__('Programming error. We shoudl be inserting or updating, but instead we are being told to "%s", whifh is invalid', 'event_espresso'), $what_to_do)); |
|
454 | 454 | } |
455 | 455 | } |
456 | 456 | } |
@@ -471,13 +471,13 @@ discard block |
||
471 | 471 | * @param array $old_db_to_new_db_mapping by reference so it can be modified |
472 | 472 | * @return string one of the consts on this class that starts with do_* |
473 | 473 | */ |
474 | - 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 ) { |
|
474 | + 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) { |
|
475 | 475 | $model_name = $model->get_this_model_name(); |
476 | 476 | //if it's a site-to-site export-and-import, see if this modelobject's id |
477 | 477 | //in the old data that we know of |
478 | - if( isset($old_db_to_new_db_mapping[$model_name][$id_in_csv]) ){ |
|
478 | + if (isset($old_db_to_new_db_mapping[$model_name][$id_in_csv])) { |
|
479 | 479 | return self::do_update; |
480 | - }else{ |
|
480 | + } else { |
|
481 | 481 | return self::do_insert; |
482 | 482 | } |
483 | 483 | } |
@@ -492,11 +492,11 @@ discard block |
||
492 | 492 | * @param type $old_db_to_new_db_mapping |
493 | 493 | * @return |
494 | 494 | */ |
495 | - protected function _decide_whether_to_insert_or_update_given_data_from_same_db( $id_in_csv, $model_object_data, $model ) { |
|
495 | + protected function _decide_whether_to_insert_or_update_given_data_from_same_db($id_in_csv, $model_object_data, $model) { |
|
496 | 496 | //in this case, check if this thing ACTUALLY exists in the database |
497 | - if( $model->get_one_conflicting( $model_object_data ) ){ |
|
497 | + if ($model->get_one_conflicting($model_object_data)) { |
|
498 | 498 | return self::do_update; |
499 | - }else{ |
|
499 | + } else { |
|
500 | 500 | return self::do_insert; |
501 | 501 | } |
502 | 502 | } |
@@ -515,55 +515,55 @@ discard block |
||
515 | 515 | * @param boolean $export_from_site_a_to_b |
516 | 516 | * @return array updated model object data with temp IDs removed |
517 | 517 | */ |
518 | - protected function _replace_temp_ids_with_mappings( $model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b ) { |
|
518 | + protected function _replace_temp_ids_with_mappings($model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b) { |
|
519 | 519 | //if this model object's primary key is in the mapping, replace it |
520 | - if( $model->has_primary_key_field() && |
|
520 | + if ($model->has_primary_key_field() && |
|
521 | 521 | $model->get_primary_key_field()->is_auto_increment() && |
522 | - isset( $old_db_to_new_db_mapping[ $model->get_this_model_name() ] ) && |
|
523 | - isset( $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ] ) ) { |
|
524 | - $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() ] ]; |
|
522 | + isset($old_db_to_new_db_mapping[$model->get_this_model_name()]) && |
|
523 | + isset($old_db_to_new_db_mapping[$model->get_this_model_name()][$model_object_data[$model->primary_key_name()]])) { |
|
524 | + $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()]]; |
|
525 | 525 | } |
526 | 526 | |
527 | - try{ |
|
527 | + try { |
|
528 | 528 | $model_name_field = $model->get_field_containing_related_model_name(); |
529 | 529 | $models_pointed_to_by_model_name_field = $model_name_field->get_model_names_pointed_to(); |
530 | - }catch( EE_Error $e ){ |
|
530 | + } catch (EE_Error $e) { |
|
531 | 531 | $model_name_field = NULL; |
532 | 532 | $models_pointed_to_by_model_name_field = array(); |
533 | 533 | } |
534 | - foreach( $model->field_settings( true ) as $field_obj ){ |
|
535 | - if( $field_obj instanceof EE_Foreign_Key_Int_Field ) { |
|
534 | + foreach ($model->field_settings(true) as $field_obj) { |
|
535 | + if ($field_obj instanceof EE_Foreign_Key_Int_Field) { |
|
536 | 536 | $models_pointed_to = $field_obj->get_model_names_pointed_to(); |
537 | 537 | $found_a_mapping = false; |
538 | - foreach( $models_pointed_to as $model_pointed_to_by_fk ) { |
|
538 | + foreach ($models_pointed_to as $model_pointed_to_by_fk) { |
|
539 | 539 | |
540 | - if( $model_name_field ){ |
|
541 | - $value_of_model_name_field = $model_object_data[ $model_name_field->get_name() ]; |
|
542 | - if( $value_of_model_name_field == $model_pointed_to_by_fk ) { |
|
543 | - $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
544 | - $model_object_data[ $field_obj->get_name() ], |
|
540 | + if ($model_name_field) { |
|
541 | + $value_of_model_name_field = $model_object_data[$model_name_field->get_name()]; |
|
542 | + if ($value_of_model_name_field == $model_pointed_to_by_fk) { |
|
543 | + $model_object_data[$field_obj->get_name()] = $this->_find_mapping_in( |
|
544 | + $model_object_data[$field_obj->get_name()], |
|
545 | 545 | $model_pointed_to_by_fk, |
546 | 546 | $old_db_to_new_db_mapping, |
547 | 547 | $export_from_site_a_to_b ); |
548 | 548 | $found_a_mapping = true; |
549 | 549 | break; |
550 | 550 | } |
551 | - }else{ |
|
552 | - $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
553 | - $model_object_data[ $field_obj->get_name() ], |
|
551 | + } else { |
|
552 | + $model_object_data[$field_obj->get_name()] = $this->_find_mapping_in( |
|
553 | + $model_object_data[$field_obj->get_name()], |
|
554 | 554 | $model_pointed_to_by_fk, |
555 | 555 | $old_db_to_new_db_mapping, |
556 | 556 | $export_from_site_a_to_b ); |
557 | 557 | $found_a_mapping = true; |
558 | 558 | } |
559 | 559 | //once we've found a mapping for this field no need to continue |
560 | - if( $found_a_mapping ) { |
|
560 | + if ($found_a_mapping) { |
|
561 | 561 | break; |
562 | 562 | } |
563 | 563 | |
564 | 564 | |
565 | 565 | } |
566 | - }else{ |
|
566 | + } else { |
|
567 | 567 | //it's a string foreign key (which we leave alone, because those are things |
568 | 568 | //like country names, which we'd really rather not make 2 USAs etc (we'd actually |
569 | 569 | //prefer to just update one) |
@@ -571,8 +571,8 @@ discard block |
||
571 | 571 | } |
572 | 572 | } |
573 | 573 | // |
574 | - if( $model instanceof EEM_Term_Taxonomy ){ |
|
575 | - $model_object_data = $this->_handle_split_term_ids( $model_object_data ); |
|
574 | + if ($model instanceof EEM_Term_Taxonomy) { |
|
575 | + $model_object_data = $this->_handle_split_term_ids($model_object_data); |
|
576 | 576 | } |
577 | 577 | return $model_object_data; |
578 | 578 | } |
@@ -584,11 +584,11 @@ discard block |
||
584 | 584 | * @param type $model_object_data |
585 | 585 | * @return array new model object data |
586 | 586 | */ |
587 | - protected function _handle_split_term_ids( $model_object_data ){ |
|
588 | - if( isset( $model_object_data['term_id'] ) && isset( $model_object_data[ 'taxonomy' ]) && apply_filters( 'FHEE__EE_Import__handle_split_term_ids__function_exists', function_exists( 'wp_get_split_term' ), $model_object_data ) ) { |
|
589 | - $new_term_id = wp_get_split_term( $model_object_data[ 'term_id' ], $model_object_data[ 'taxonomy' ] ); |
|
590 | - if( $new_term_id ){ |
|
591 | - $model_object_data[ 'term_id' ] = $new_term_id; |
|
587 | + protected function _handle_split_term_ids($model_object_data) { |
|
588 | + if (isset($model_object_data['term_id']) && isset($model_object_data['taxonomy']) && apply_filters('FHEE__EE_Import__handle_split_term_ids__function_exists', function_exists('wp_get_split_term'), $model_object_data)) { |
|
589 | + $new_term_id = wp_get_split_term($model_object_data['term_id'], $model_object_data['taxonomy']); |
|
590 | + if ($new_term_id) { |
|
591 | + $model_object_data['term_id'] = $new_term_id; |
|
592 | 592 | } |
593 | 593 | } |
594 | 594 | return $model_object_data; |
@@ -602,18 +602,18 @@ discard block |
||
602 | 602 | * @param type $export_from_site_a_to_b |
603 | 603 | * @return int |
604 | 604 | */ |
605 | - protected function _find_mapping_in( $object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) { |
|
606 | - if( isset( $old_db_to_new_db_mapping[ $model_name ][ $object_id ] ) ){ |
|
605 | + protected function _find_mapping_in($object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) { |
|
606 | + if (isset($old_db_to_new_db_mapping[$model_name][$object_id])) { |
|
607 | 607 | |
608 | - return $old_db_to_new_db_mapping[ $model_name ][ $object_id ]; |
|
609 | - }elseif( $object_id == '0' || $object_id == '' ) { |
|
608 | + return $old_db_to_new_db_mapping[$model_name][$object_id]; |
|
609 | + }elseif ($object_id == '0' || $object_id == '') { |
|
610 | 610 | //leave as-is |
611 | 611 | return $object_id; |
612 | - }elseif( $export_from_site_a_to_b ){ |
|
612 | + }elseif ($export_from_site_a_to_b) { |
|
613 | 613 | //we couldn't find a mapping for this, and it's from a different site, |
614 | 614 | //so blank it out |
615 | 615 | return NULL; |
616 | - }elseif( ! $export_from_site_a_to_b ) { |
|
616 | + }elseif ( ! $export_from_site_a_to_b) { |
|
617 | 617 | //we coudln't find a mapping for this, but it's from thsi DB anyway |
618 | 618 | //so let's just leave it as-is |
619 | 619 | return $object_id; |
@@ -628,36 +628,36 @@ discard block |
||
628 | 628 | * @param type $old_db_to_new_db_mapping |
629 | 629 | * @return array updated $old_db_to_new_db_mapping |
630 | 630 | */ |
631 | - protected function _insert_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ) { |
|
631 | + protected function _insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) { |
|
632 | 632 | //remove the primary key, if there is one (we don't want it for inserts OR updates) |
633 | 633 | //we'll put it back in if we need it |
634 | - if($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()){ |
|
634 | + if ($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()) { |
|
635 | 635 | $effective_id = $model_object_data[$model->primary_key_name()]; |
636 | 636 | unset($model_object_data[$model->primary_key_name()]); |
637 | - }else{ |
|
638 | - $effective_id = $model->get_index_primary_key_string( $model_object_data ); |
|
637 | + } else { |
|
638 | + $effective_id = $model->get_index_primary_key_string($model_object_data); |
|
639 | 639 | } |
640 | 640 | //the model takes care of validating the CSV's input |
641 | - try{ |
|
641 | + try { |
|
642 | 642 | $new_id = $model->insert($model_object_data); |
643 | - if( $new_id ){ |
|
643 | + if ($new_id) { |
|
644 | 644 | $old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_id; |
645 | 645 | $this->_total_inserts++; |
646 | - EE_Error::add_success( sprintf(__("Successfully added new %s (with id %s) with csv data %s", "event_espresso"),$model->get_this_model_name(),$new_id, implode(",",$model_object_data))); |
|
647 | - }else{ |
|
646 | + EE_Error::add_success(sprintf(__("Successfully added new %s (with id %s) with csv data %s", "event_espresso"), $model->get_this_model_name(), $new_id, implode(",", $model_object_data))); |
|
647 | + } else { |
|
648 | 648 | $this->_total_insert_errors++; |
649 | 649 | //put the ID used back in there for the error message |
650 | - if($model->has_primary_key_field()){ |
|
650 | + if ($model->has_primary_key_field()) { |
|
651 | 651 | $model_object_data[$model->primary_key_name()] = $effective_id; |
652 | 652 | } |
653 | - EE_Error::add_error( sprintf(__("Could not insert new %s with the csv data: %s", "event_espresso"),$model->get_this_model_name(),http_build_query($model_object_data)), __FILE__, __FUNCTION__, __LINE__ ); |
|
653 | + EE_Error::add_error(sprintf(__("Could not insert new %s with the csv data: %s", "event_espresso"), $model->get_this_model_name(), http_build_query($model_object_data)), __FILE__, __FUNCTION__, __LINE__); |
|
654 | 654 | } |
655 | - }catch(EE_Error $e){ |
|
655 | + } catch (EE_Error $e) { |
|
656 | 656 | $this->_total_insert_errors++; |
657 | - if($model->has_primary_key_field()){ |
|
657 | + if ($model->has_primary_key_field()) { |
|
658 | 658 | $model_object_data[$model->primary_key_name()] = $effective_id; |
659 | 659 | } |
660 | - EE_Error::add_error( sprintf(__("Could not insert new %s with the csv data: %s because %s", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data),$e->getMessage()), __FILE__, __FUNCTION__, __LINE__ ); |
|
660 | + EE_Error::add_error(sprintf(__("Could not insert new %s with the csv data: %s because %s", "event_espresso"), $model->get_this_model_name(), implode(",", $model_object_data), $e->getMessage()), __FILE__, __FUNCTION__, __LINE__); |
|
661 | 661 | } |
662 | 662 | return $old_db_to_new_db_mapping; |
663 | 663 | } |
@@ -670,55 +670,55 @@ discard block |
||
670 | 670 | * @param array $old_db_to_new_db_mapping |
671 | 671 | * @return array updated $old_db_to_new_db_mapping |
672 | 672 | */ |
673 | - protected function _update_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ) { |
|
674 | - try{ |
|
673 | + protected function _update_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) { |
|
674 | + try { |
|
675 | 675 | //let's keep two copies of the model object data: |
676 | 676 | //one for performing an update, one for everthing else |
677 | 677 | $model_object_data_for_update = $model_object_data; |
678 | - if($model->has_primary_key_field()){ |
|
678 | + if ($model->has_primary_key_field()) { |
|
679 | 679 | $conditions = array($model->primary_key_name() => $model_object_data[$model->primary_key_name()]); |
680 | 680 | //remove the primary key because we shouldn't use it for updating |
681 | 681 | unset($model_object_data_for_update[$model->primary_key_name()]); |
682 | - }elseif($model->get_combined_primary_key_fields() > 1 ){ |
|
682 | + }elseif ($model->get_combined_primary_key_fields() > 1) { |
|
683 | 683 | $conditions = array(); |
684 | - foreach($model->get_combined_primary_key_fields() as $key_field){ |
|
684 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
685 | 685 | $conditions[$key_field->get_name()] = $model_object_data[$key_field->get_name()]; |
686 | 686 | } |
687 | - }else{ |
|
688 | - $model->primary_key_name();//this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey) |
|
687 | + } else { |
|
688 | + $model->primary_key_name(); //this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey) |
|
689 | 689 | } |
690 | 690 | |
691 | - $success = $model->update($model_object_data_for_update,array($conditions)); |
|
692 | - if($success){ |
|
691 | + $success = $model->update($model_object_data_for_update, array($conditions)); |
|
692 | + if ($success) { |
|
693 | 693 | $this->_total_updates++; |
694 | - EE_Error::add_success( sprintf(__("Successfully updated %s with csv data %s", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data_for_update))); |
|
694 | + EE_Error::add_success(sprintf(__("Successfully updated %s with csv data %s", "event_espresso"), $model->get_this_model_name(), implode(",", $model_object_data_for_update))); |
|
695 | 695 | //we should still record the mapping even though it was an update |
696 | 696 | //because if we were going to insert somethign but it was going to conflict |
697 | 697 | //we would have last-minute decided to update. So we'd like to know what we updated |
698 | 698 | //and so we record what record ended up being updated using the mapping |
699 | - if( $model->has_primary_key_field() ){ |
|
700 | - $new_key_for_mapping = $model_object_data[ $model->primary_key_name() ]; |
|
701 | - }else{ |
|
699 | + if ($model->has_primary_key_field()) { |
|
700 | + $new_key_for_mapping = $model_object_data[$model->primary_key_name()]; |
|
701 | + } else { |
|
702 | 702 | //no primary key just a combined key |
703 | - $new_key_for_mapping = $model->get_index_primary_key_string( $model_object_data ); |
|
703 | + $new_key_for_mapping = $model->get_index_primary_key_string($model_object_data); |
|
704 | 704 | } |
705 | - $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_key_for_mapping; |
|
706 | - }else{ |
|
705 | + $old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_key_for_mapping; |
|
706 | + } else { |
|
707 | 707 | $matched_items = $model->get_all(array($conditions)); |
708 | - if( ! $matched_items){ |
|
708 | + if ( ! $matched_items) { |
|
709 | 709 | //no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck? |
710 | 710 | $this->_total_update_errors++; |
711 | - EE_Error::add_error( sprintf(__("Could not update %s with the csv data: '%s' for an unknown reason (using WHERE conditions %s)", "event_espresso"),$model->get_this_model_name(),http_build_query($model_object_data),http_build_query($conditions)), __FILE__, __FUNCTION__, __LINE__ ); |
|
712 | - }else{ |
|
711 | + EE_Error::add_error(sprintf(__("Could not update %s with the csv data: '%s' for an unknown reason (using WHERE conditions %s)", "event_espresso"), $model->get_this_model_name(), http_build_query($model_object_data), http_build_query($conditions)), __FILE__, __FUNCTION__, __LINE__); |
|
712 | + } else { |
|
713 | 713 | $this->_total_updates++; |
714 | - EE_Error::add_success( sprintf(__("%s with csv data '%s' was found in the database and didn't need updating because all the data is identical.", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data))); |
|
714 | + EE_Error::add_success(sprintf(__("%s with csv data '%s' was found in the database and didn't need updating because all the data is identical.", "event_espresso"), $model->get_this_model_name(), implode(",", $model_object_data))); |
|
715 | 715 | } |
716 | 716 | } |
717 | - }catch(EE_Error $e){ |
|
717 | + } catch (EE_Error $e) { |
|
718 | 718 | $this->_total_update_errors++; |
719 | - $basic_message = sprintf(__("Could not update %s with the csv data: %s because %s", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data),$e->getMessage()); |
|
720 | - $debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString(); |
|
721 | - EE_Error::add_error( "$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__ ); |
|
719 | + $basic_message = sprintf(__("Could not update %s with the csv data: %s because %s", "event_espresso"), $model->get_this_model_name(), implode(",", $model_object_data), $e->getMessage()); |
|
720 | + $debug_message = $basic_message.' Stack trace: '.$e->getTraceAsString(); |
|
721 | + EE_Error::add_error("$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__); |
|
722 | 722 | } |
723 | 723 | return $old_db_to_new_db_mapping; |
724 | 724 | } |
@@ -727,28 +727,28 @@ discard block |
||
727 | 727 | * Gets the number of inserts performed since importer was instantiated or reset |
728 | 728 | * @return int |
729 | 729 | */ |
730 | - public function get_total_inserts(){ |
|
730 | + public function get_total_inserts() { |
|
731 | 731 | return $this->_total_inserts; |
732 | 732 | } |
733 | 733 | /** |
734 | 734 | * Gets the number of insert errors since importer was instantiated or reset |
735 | 735 | * @return int |
736 | 736 | */ |
737 | - public function get_total_insert_errors(){ |
|
737 | + public function get_total_insert_errors() { |
|
738 | 738 | return $this->_total_insert_errors; |
739 | 739 | } |
740 | 740 | /** |
741 | 741 | * Gets the number of updates performed since importer was instantiated or reset |
742 | 742 | * @return int |
743 | 743 | */ |
744 | - public function get_total_updates(){ |
|
744 | + public function get_total_updates() { |
|
745 | 745 | return $this->_total_updates; |
746 | 746 | } |
747 | 747 | /** |
748 | 748 | * Gets the number of update errors since importer was instantiated or reset |
749 | 749 | * @return int |
750 | 750 | */ |
751 | - public function get_total_update_errors(){ |
|
751 | + public function get_total_update_errors() { |
|
752 | 752 | return $this->_total_update_errors; |
753 | 753 | } |
754 | 754 |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' )) { exit( 'No direct script access allowed' ); } |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
|
2 | 2 | /** |
3 | 3 | * Class EE_Country_Select_Input |
4 | 4 | * |
@@ -11,23 +11,23 @@ discard block |
||
11 | 11 | * @since $VID:$ |
12 | 12 | * |
13 | 13 | */ |
14 | -class EE_Country_Select_Input extends EE_Select_Input{ |
|
14 | +class EE_Country_Select_Input extends EE_Select_Input { |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * @param array $country_options |
18 | 18 | * @param array $input_settings |
19 | 19 | * @return EE_Country_Select_Input |
20 | 20 | */ |
21 | - public function __construct( $country_options = NULL, $input_settings = array() ){ |
|
21 | + public function __construct($country_options = NULL, $input_settings = array()) { |
|
22 | 22 | $country_options = apply_filters( |
23 | 23 | 'FHEE__EE_Country_Select_Input____construct__country_options', |
24 | - $this->get_country_answer_options( $country_options ), |
|
24 | + $this->get_country_answer_options($country_options), |
|
25 | 25 | $this |
26 | 26 | ); |
27 | - $input_settings['html_class'] = isset( $input_settings['html_class'] ) |
|
28 | - ? $input_settings['html_class'] . ' ee-country-select-js' |
|
27 | + $input_settings['html_class'] = isset($input_settings['html_class']) |
|
28 | + ? $input_settings['html_class'].' ee-country-select-js' |
|
29 | 29 | : 'ee-country-select-js'; |
30 | - parent::__construct( $country_options, $input_settings ); |
|
30 | + parent::__construct($country_options, $input_settings); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | |
@@ -38,16 +38,16 @@ discard block |
||
38 | 38 | * @param array $country_options |
39 | 39 | * @return array |
40 | 40 | */ |
41 | - public function get_country_answer_options( $country_options = NULL ){ |
|
41 | + public function get_country_answer_options($country_options = NULL) { |
|
42 | 42 | // if passed something that is NOT an array |
43 | - if ( ! is_array( $country_options )) { |
|
43 | + if ( ! is_array($country_options)) { |
|
44 | 44 | // get possibly cached list of countries |
45 | 45 | $countries = EEM_Country::instance()->get_all_active_countries(); |
46 | - if ( ! empty( $countries )) { |
|
47 | - $country_options[ '' ] = ''; |
|
48 | - foreach( $countries as $country ){ |
|
49 | - if ( $country instanceof EE_Country ) { |
|
50 | - $country_options[ $country->ID() ] = $country->name(); |
|
46 | + if ( ! empty($countries)) { |
|
47 | + $country_options[''] = ''; |
|
48 | + foreach ($countries as $country) { |
|
49 | + if ($country instanceof EE_Country) { |
|
50 | + $country_options[$country->ID()] = $country->name(); |
|
51 | 51 | } |
52 | 52 | } |
53 | 53 | } else { |
@@ -6,22 +6,22 @@ discard block |
||
6 | 6 | * @subpackage |
7 | 7 | * @author Mike Nelson |
8 | 8 | */ |
9 | -class EE_State_Select_Input extends EE_Select_Input{ |
|
9 | +class EE_State_Select_Input extends EE_Select_Input { |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * @param array $state_options |
13 | 13 | * @param array $input_settings |
14 | 14 | */ |
15 | - function __construct( $state_options, $input_settings = array() ){ |
|
15 | + function __construct($state_options, $input_settings = array()) { |
|
16 | 16 | $state_options = apply_filters( |
17 | 17 | 'FHEE__EE_State_Select_Input____construct__state_options', |
18 | - $this->get_state_answer_options( $state_options ), |
|
18 | + $this->get_state_answer_options($state_options), |
|
19 | 19 | $this |
20 | 20 | ); |
21 | - $input_settings['html_class'] = isset( $input_settings['html_class'] ) |
|
22 | - ? $input_settings['html_class'] . ' ee-state-select-js' |
|
21 | + $input_settings['html_class'] = isset($input_settings['html_class']) |
|
22 | + ? $input_settings['html_class'].' ee-state-select-js' |
|
23 | 23 | : 'ee-state-select-js'; |
24 | - parent::__construct( $state_options, $input_settings ); |
|
24 | + parent::__construct($state_options, $input_settings); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | |
@@ -32,17 +32,17 @@ discard block |
||
32 | 32 | * @param array $state_options |
33 | 33 | * @return array |
34 | 34 | */ |
35 | - public function get_state_answer_options( $state_options = NULL ){ |
|
35 | + public function get_state_answer_options($state_options = NULL) { |
|
36 | 36 | // if passed something that is NOT an array |
37 | - if ( ! is_array( $state_options )) { |
|
37 | + if ( ! is_array($state_options)) { |
|
38 | 38 | // get possibly cached list of states |
39 | 39 | $states = EEM_State::instance()->get_all_active_states(); |
40 | - if ( ! empty( $states )) { |
|
40 | + if ( ! empty($states)) { |
|
41 | 41 | //set the default |
42 | 42 | $state_options[''][''] = ''; |
43 | - foreach( $states as $state ){ |
|
44 | - if ( $state instanceof EE_State ) { |
|
45 | - $state_options[ $state->country()->name() ][ $state->ID() ] = $state->name(); |
|
43 | + foreach ($states as $state) { |
|
44 | + if ($state instanceof EE_State) { |
|
45 | + $state_options[$state->country()->name()][$state->ID()] = $state->name(); |
|
46 | 46 | } |
47 | 47 | } |
48 | 48 | } else { |
@@ -1,5 +1,5 @@ |
||
1 | 1 | <div class="padding"> |
2 | - <p><?php _e( 'We need your help to continue maintaining and providing this plugin for free. You can help by leaving a positive review in the WordPress plugin directory. 5 star ratings bring Event Espresso Decaf to the attention of more users which increases our support and features for this version of Event Espresso.', 'event_espresso' ); ?></p> |
|
3 | - <p><?php _e( 'Rate it five stars today!', 'event_espresso' ); ?></p><span class="ee-wp-blue dashicons dashicons-star-filled"></span><span class="ee-wp-blue dashicons dashicons-star-filled"></span><span class="ee-wp-blue dashicons dashicons-star-filled"></span><span class="ee-wp-blue dashicons dashicons-star-filled"></span><span class="ee-wp-blue dashicons dashicons-star-filled"></span> |
|
4 | - <p><a class="button button-primary" href="https://events.codebasehq.com/redirect?https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Fview%2Fplugin-reviews%2Fevent-espresso-decaf%3Frate%3D5%23postform"><?php _e( 'Rate It!', 'event_espresso' ); ?></a></p> |
|
2 | + <p><?php _e('We need your help to continue maintaining and providing this plugin for free. You can help by leaving a positive review in the WordPress plugin directory. 5 star ratings bring Event Espresso Decaf to the attention of more users which increases our support and features for this version of Event Espresso.', 'event_espresso'); ?></p> |
|
3 | + <p><?php _e('Rate it five stars today!', 'event_espresso'); ?></p><span class="ee-wp-blue dashicons dashicons-star-filled"></span><span class="ee-wp-blue dashicons dashicons-star-filled"></span><span class="ee-wp-blue dashicons dashicons-star-filled"></span><span class="ee-wp-blue dashicons dashicons-star-filled"></span><span class="ee-wp-blue dashicons dashicons-star-filled"></span> |
|
4 | + <p><a class="button button-primary" href="https://events.codebasehq.com/redirect?https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Fview%2Fplugin-reviews%2Fevent-espresso-decaf%3Frate%3D5%23postform"><?php _e('Rate It!', 'event_espresso'); ?></a></p> |
|
5 | 5 | </div> |
6 | 6 | \ No newline at end of file |
@@ -1,1 +1,1 @@ |
||
1 | -<?php printf( __('PayPal Express (Express Checkout) is an off-site payment method for accepting payments via PayPal and is available to event organizers in many countries. A PayPal premier or business account is needed to accept payments. Need a PayPal account? Call 1-855-456-1338 or %1$sclick here to sign up for a merchant account%2$s.', 'event_espresso'), '<a href="https://eventespresso.com/go/paypalexpress/" target="_blank">','</a>' ); ?> |
|
2 | 1 | \ No newline at end of file |
2 | +<?php printf(__('PayPal Express (Express Checkout) is an off-site payment method for accepting payments via PayPal and is available to event organizers in many countries. A PayPal premier or business account is needed to accept payments. Need a PayPal account? Call 1-855-456-1338 or %1$sclick here to sign up for a merchant account%2$s.', 'event_espresso'), '<a href="https://eventespresso.com/go/paypalexpress/" target="_blank">', '</a>'); ?> |
|
3 | 3 | \ No newline at end of file |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { exit('No direct script access allowed'); } ?> |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } ?> |
|
2 | 2 | |
3 | 3 | <div id="ppexpress-sandbox-panel" class="sandbox-panel"> |
4 | 4 | |
@@ -6,13 +6,13 @@ discard block |
||
6 | 6 | |
7 | 7 | <h4><?php _e('How do I test specific error codes?', 'event_espresso'); ?></h4> |
8 | 8 | <p> |
9 | - <?php _e( 'To trigger an error condition on an amount-related field, |
|
9 | + <?php _e('To trigger an error condition on an amount-related field, |
|
10 | 10 | specify a error code value as a number with two digits to the right of the decimal point. |
11 | 11 | For example, specify a value of 107.55 to trigger the 10755 error.', |
12 | - 'event_espresso');?> |
|
12 | + 'event_espresso'); ?> |
|
13 | 13 | </p> |
14 | 14 | <p> |
15 | - <?php printf( __( 'More details can be found here: %1$s Testing Error Conditions %2$s.', 'event_espresso'), '<a href="https://developer.paypal.com/docs/classic/lifecycle/sb_error-conditions">', '</a>');?> |
|
15 | + <?php printf(__('More details can be found here: %1$s Testing Error Conditions %2$s.', 'event_espresso'), '<a href="https://developer.paypal.com/docs/classic/lifecycle/sb_error-conditions">', '</a>'); ?> |
|
16 | 16 | </p> |
17 | 17 | |
18 | 18 | </div> |
19 | 19 | \ No newline at end of file |