@@ -10,20 +10,20 @@ discard block |
||
10 | 10 | * @since 4.6 |
11 | 11 | * |
12 | 12 | */ |
13 | -class EE_Full_HTML_Validation_Strategy extends EE_Validation_Strategy_Base{ |
|
13 | +class EE_Full_HTML_Validation_Strategy extends EE_Validation_Strategy_Base { |
|
14 | 14 | |
15 | 15 | /** |
16 | 16 | * @param null $validation_error_message |
17 | 17 | */ |
18 | - public function __construct( $validation_error_message = NULL ) { |
|
19 | - if ( ! $validation_error_message ) { |
|
18 | + public function __construct($validation_error_message = NULL) { |
|
19 | + if ( ! $validation_error_message) { |
|
20 | 20 | $validation_error_message = sprintf( |
21 | - __( 'Only the following HTML tags are allowed:%1$s%2$s', "event_espresso" ), |
|
21 | + __('Only the following HTML tags are allowed:%1$s%2$s', "event_espresso"), |
|
22 | 22 | '<br />', |
23 | 23 | $this->get_list_of_allowed_tags() |
24 | 24 | ); |
25 | 25 | } |
26 | - parent::__construct( $validation_error_message ); |
|
26 | + parent::__construct($validation_error_message); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function get_list_of_allowed_tags() { |
39 | 39 | global $allowedposttags; |
40 | - ksort( $allowedposttags ); |
|
41 | - return implode( ', ', array_keys( $allowedposttags ) ); |
|
40 | + ksort($allowedposttags); |
|
41 | + return implode(', ', array_keys($allowedposttags)); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | |
@@ -49,10 +49,10 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function validate($normalized_value) { |
51 | 51 | global $allowedposttags; |
52 | - parent::validate( $normalized_value ); |
|
53 | - $normalized_value_sans_tags = wp_kses( "$normalized_value", $allowedposttags ); |
|
54 | - if ( strlen( $normalized_value ) > strlen( $normalized_value_sans_tags ) ) { |
|
55 | - throw new EE_Validation_Error( $this->get_validation_error_message(), 'complex_html_tags' ); |
|
52 | + parent::validate($normalized_value); |
|
53 | + $normalized_value_sans_tags = wp_kses("$normalized_value", $allowedposttags); |
|
54 | + if (strlen($normalized_value) > strlen($normalized_value_sans_tags)) { |
|
55 | + throw new EE_Validation_Error($this->get_validation_error_message(), 'complex_html_tags'); |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 | } |
59 | 59 | \ No newline at end of file |
@@ -31,29 +31,29 @@ discard block |
||
31 | 31 | <tbody> |
32 | 32 | <tr> |
33 | 33 | <td> |
34 | - <h2><?php printf( esc_html__( 'Hello, %s:', 'event_espresso' ), '[PRIMARY_REGISTRANT_FNAME] [PRIMARY_REGISTRANT_LNAME]' ); ?></h2> |
|
35 | - <p class="lead"><?php esc_html_e( "We'd like to remind you that you still owe money for the following transaction:", 'event_espresso' ); ?></p> |
|
36 | - <h3><?php esc_html_e( 'Payment Details:', 'event_espresso' ); ?></h3> |
|
34 | + <h2><?php printf(esc_html__('Hello, %s:', 'event_espresso'), '[PRIMARY_REGISTRANT_FNAME] [PRIMARY_REGISTRANT_LNAME]'); ?></h2> |
|
35 | + <p class="lead"><?php esc_html_e("We'd like to remind you that you still owe money for the following transaction:", 'event_espresso'); ?></p> |
|
36 | + <h3><?php esc_html_e('Payment Details:', 'event_espresso'); ?></h3> |
|
37 | 37 | <ul> |
38 | 38 | <li> |
39 | - <strong><?php esc_html_e( 'Payment Status:', 'event_espresso' ); ?></strong> [PAYMENT_STATUS] |
|
39 | + <strong><?php esc_html_e('Payment Status:', 'event_espresso'); ?></strong> [PAYMENT_STATUS] |
|
40 | 40 | </li> |
41 | 41 | <li> |
42 | - <strong><?php esc_html_e( 'Transaction ID:', 'event_espresso' ); ?></strong> [TXN_ID] |
|
42 | + <strong><?php esc_html_e('Transaction ID:', 'event_espresso'); ?></strong> [TXN_ID] |
|
43 | 43 | </li> |
44 | 44 | <li> |
45 | - <strong><?php esc_html_e( 'Total Cost:', 'event_espresso' ); ?></strong> [TOTAL_COST] |
|
45 | + <strong><?php esc_html_e('Total Cost:', 'event_espresso'); ?></strong> [TOTAL_COST] |
|
46 | 46 | </li> |
47 | 47 | <li> |
48 | - <strong><?php esc_html_e( 'Amount Due:', 'event_espresso' ); ?></strong> [TOTAL_OWING] |
|
48 | + <strong><?php esc_html_e('Amount Due:', 'event_espresso'); ?></strong> [TOTAL_OWING] |
|
49 | 49 | </li> |
50 | 50 | </ul> |
51 | 51 | <p class="callout"> |
52 | - <?php printf( esc_html__( 'Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso' ), '<a href="[PAYMENT_URL]">', '</a>' ); ?> |
|
52 | + <?php printf(esc_html__('Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso'), '<a href="[PAYMENT_URL]">', '</a>'); ?> |
|
53 | 53 | </p> |
54 | 54 | [EVENT_LIST] |
55 | 55 | <p class="callout"> |
56 | - <?php printf( esc_html__( 'Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso' ), '<a href="[PAYMENT_URL]">', '</a>' ); ?> |
|
56 | + <?php printf(esc_html__('Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso'), '<a href="[PAYMENT_URL]">', '</a>'); ?> |
|
57 | 57 | </p> |
58 | 58 | </td> |
59 | 59 | </tr> |
@@ -78,10 +78,10 @@ discard block |
||
78 | 78 | <tbody> |
79 | 79 | <tr> |
80 | 80 | <td> |
81 | - <h3><?php esc_html_e( 'Connect with Us:', 'event_espresso' ); ?></h3> |
|
82 | - <a class="soc-btn fb" href="[CO_FACEBOOK_URL]"><?php esc_html_e( 'Facebook', 'event_espresso' ); ?></a> |
|
83 | - <a class="soc-btn tw" href="[CO_TWITTER_URL]"><?php esc_html_e( 'Twitter', 'event_espresso' ); ?></a> |
|
84 | - <a class="soc-btn gp" href="[CO_GOOGLE_URL]"><?php esc_html_e( 'Google+', 'event_espresso' ); ?></a> |
|
81 | + <h3><?php esc_html_e('Connect with Us:', 'event_espresso'); ?></h3> |
|
82 | + <a class="soc-btn fb" href="[CO_FACEBOOK_URL]"><?php esc_html_e('Facebook', 'event_espresso'); ?></a> |
|
83 | + <a class="soc-btn tw" href="[CO_TWITTER_URL]"><?php esc_html_e('Twitter', 'event_espresso'); ?></a> |
|
84 | + <a class="soc-btn gp" href="[CO_GOOGLE_URL]"><?php esc_html_e('Google+', 'event_espresso'); ?></a> |
|
85 | 85 | </td> |
86 | 86 | </tr> |
87 | 87 | </tbody> |
@@ -91,9 +91,9 @@ discard block |
||
91 | 91 | <tbody> |
92 | 92 | <tr> |
93 | 93 | <td> |
94 | - <h3><?php esc_html_e( 'Contact Info:', 'event_espresso' ); ?></h3> |
|
95 | - <?php esc_html_e( 'Phone:', 'event_espresso' ); ?> <strong>[CO_PHONE]</strong> |
|
96 | - <?php esc_html_e( 'Email:', 'event_espresso' ); ?> |
|
94 | + <h3><?php esc_html_e('Contact Info:', 'event_espresso'); ?></h3> |
|
95 | + <?php esc_html_e('Phone:', 'event_espresso'); ?> <strong>[CO_PHONE]</strong> |
|
96 | + <?php esc_html_e('Email:', 'event_espresso'); ?> |
|
97 | 97 | <strong><a href="mailto:[CO_EMAIL]" target="_blank">[CO_EMAIL]</a></strong> |
98 | 98 | </td> |
99 | 99 | </tr> |
@@ -31,23 +31,23 @@ discard block |
||
31 | 31 | <tbody> |
32 | 32 | <tr> |
33 | 33 | <td> |
34 | - <h1><?php esc_html_e( 'Payment Reminder Notification', 'event_espresso' ); ?></h1> |
|
35 | - <?php esc_html_e( 'The following message was sent to the Primary Registrant of this transaction:', 'event_espresso' ); ?> |
|
36 | - <h3><?php esc_html_e( 'Payment Details:', 'event_espresso' ); ?></h3> |
|
34 | + <h1><?php esc_html_e('Payment Reminder Notification', 'event_espresso'); ?></h1> |
|
35 | + <?php esc_html_e('The following message was sent to the Primary Registrant of this transaction:', 'event_espresso'); ?> |
|
36 | + <h3><?php esc_html_e('Payment Details:', 'event_espresso'); ?></h3> |
|
37 | 37 | <ul> |
38 | 38 | <li> |
39 | - <strong><?php esc_html_e( 'Payment Status:', 'event_espresso' ); ?></strong> [PAYMENT_STATUS] |
|
39 | + <strong><?php esc_html_e('Payment Status:', 'event_espresso'); ?></strong> [PAYMENT_STATUS] |
|
40 | 40 | </li> |
41 | - <li><strong><?php esc_html_e( 'Transaction ID:', 'event_espresso' ); ?></strong> |
|
41 | + <li><strong><?php esc_html_e('Transaction ID:', 'event_espresso'); ?></strong> |
|
42 | 42 | <a href="[TRANSACTION_ADMIN_URL]">[TXN_ID]</a></li> |
43 | 43 | <li> |
44 | - <strong><?php esc_html_e( 'Payment Gateway:', 'event_espresso' ); ?></strong> [PAYMENT_GATEWAY] |
|
44 | + <strong><?php esc_html_e('Payment Gateway:', 'event_espresso'); ?></strong> [PAYMENT_GATEWAY] |
|
45 | 45 | </li> |
46 | 46 | <li> |
47 | - <strong><?php esc_html_e( 'Total Cost:', 'event_espresso' ); ?></strong> [TOTAL_COST] |
|
47 | + <strong><?php esc_html_e('Total Cost:', 'event_espresso'); ?></strong> [TOTAL_COST] |
|
48 | 48 | </li> |
49 | 49 | <li> |
50 | - <strong><?php esc_html_e( 'Amount Due:', 'event_espresso' ); ?></strong> [TOTAL_OWING] |
|
50 | + <strong><?php esc_html_e('Amount Due:', 'event_espresso'); ?></strong> [TOTAL_OWING] |
|
51 | 51 | </li> |
52 | 52 | </ul> |
53 | 53 | </td> |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | </table> |
57 | 57 | </div> |
58 | 58 | <div class="content"> |
59 | - <h2><?php esc_html_e( 'Registrant Details:', 'event_espresso' ); ?></h2> |
|
59 | + <h2><?php esc_html_e('Registrant Details:', 'event_espresso'); ?></h2> |
|
60 | 60 | <p class="callout"><strong>[PRIMARY_REGISTRANT_FNAME] [PRIMARY_REGISTRANT_LNAME]:</strong> |
61 | 61 | <a href="mailto:[PRIMARY_REGISTRANT_EMAIL]">[PRIMARY_REGISTRANT_EMAIL]</a></p> |
62 | 62 | </div> |
@@ -64,14 +64,14 @@ |
||
64 | 64 | //make sure we end up with a copy of the EE_Messages_Addressee object |
65 | 65 | $this->_recipient = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
66 | 66 | $this->_recipient = ! $this->_recipient instanceof EE_Messages_Addressee |
67 | - && is_array( $this->_data ) |
|
68 | - && isset( $this->_data['data'] ) |
|
69 | - && $this->_data['data'] instanceof EE_Messages_Addressee |
|
67 | + && is_array( $this->_data ) |
|
68 | + && isset( $this->_data['data'] ) |
|
69 | + && $this->_data['data'] instanceof EE_Messages_Addressee |
|
70 | 70 | ? $this->_data['data'] : |
71 | 71 | $this->_recipient; |
72 | 72 | $this->_recipient = ! $this->_recipient instanceof EE_Messages_Addressee |
73 | - && ! empty( $this->_extra_data['data'] ) |
|
74 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
73 | + && ! empty( $this->_extra_data['data'] ) |
|
74 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
75 | 75 | ? $this->_extra_data['data'] |
76 | 76 | : $this->_recipient; |
77 | 77 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
4 | 4 | exit('NO direct script access allowed'); |
5 | 5 | |
6 | 6 | /** |
@@ -37,24 +37,24 @@ discard block |
||
37 | 37 | |
38 | 38 | |
39 | 39 | protected function _init_props() { |
40 | - $this->label = esc_html__( 'Recipient Details Shortcodes', 'event_espresso' ); |
|
41 | - $this->description = esc_html__( 'All shortcodes specific to recipient registration data', 'event_espresso' ); |
|
40 | + $this->label = esc_html__('Recipient Details Shortcodes', 'event_espresso'); |
|
41 | + $this->description = esc_html__('All shortcodes specific to recipient registration data', 'event_espresso'); |
|
42 | 42 | $this->_shortcodes = array( |
43 | - '[RECIPIENT_FNAME]' => esc_html__( 'Parses to the first name of the recipient for the message.', 'event_espresso' ), |
|
44 | - '[RECIPIENT_LNAME]' => esc_html__( 'Parses to the last name of the recipient for the message.', 'event_espresso' ), |
|
45 | - '[RECIPIENT_EMAIL]' => esc_html__( 'Parses to the email address of the recipient for the message.', 'event_espresso' ), |
|
46 | - '[RECIPIENT_REGISTRATION_ID]' => esc_html__( 'Parses to the registration ID of the recipient for the message.', 'event_espresso' ), |
|
47 | - '[RECIPIENT_REGISTRATION_CODE]' => esc_html__( 'Parses to the registration code of the recipient for the message.', 'event_espresso' ), |
|
48 | - '[RECIPIENT_EDIT_REGISTRATION_LINK]' => esc_html__( 'Parses to a link for frontend editing of the registration for the recipient.', 'event_espresso' ), |
|
49 | - '[RECIPIENT_PHONE_NUMBER]' => esc_html__( 'The Phone Number for the recipient of the message.', 'event_espresso' ), |
|
50 | - '[RECIPIENT_ADDRESS]' => esc_html__( 'The Address for the recipient of the message.', 'event_espresso' ), |
|
51 | - '[RECIPIENT_ADDRESS2]' => esc_html__( 'Whatever was in the address 2 field for the recipient of the message.', 'event_espresso' ), |
|
52 | - '[RECIPIENT_CITY]' => esc_html__( 'The city for the recipient of the message.', 'event_espresso' ), |
|
53 | - '[RECIPIENT_ZIP_PC]' => esc_html__( 'The ZIP (or Postal) Code for the recipient of the message.', 'event_espresso' ), |
|
54 | - '[RECIPIENT_ADDRESS_STATE]' => esc_html__( 'The state/province for the recipient of the message.', 'event_espresso' ), |
|
55 | - '[RECIPIENT_COUNTRY]' => esc_html__( 'The country for the recipient of the message.', 'event_espresso' ), |
|
56 | - '[RECIPIENT_ANSWER_*]' => esc_html__( 'This is a special dynamic shortcode. After the "*", add the exact text of an existing question, and if there is an answer for that question for this recipient, then it will be output in place of this shortcode.', 'event_espresso' ), |
|
57 | - '[RECIPIENT_TOTAL_AMOUNT_PAID]' => esc_html__( 'If a single registration related to the recipient is available, that is used to retrieve the total amount that has been paid for this recipient. Otherwise the value of 0 is printed.', 'event_espresso' ) |
|
43 | + '[RECIPIENT_FNAME]' => esc_html__('Parses to the first name of the recipient for the message.', 'event_espresso'), |
|
44 | + '[RECIPIENT_LNAME]' => esc_html__('Parses to the last name of the recipient for the message.', 'event_espresso'), |
|
45 | + '[RECIPIENT_EMAIL]' => esc_html__('Parses to the email address of the recipient for the message.', 'event_espresso'), |
|
46 | + '[RECIPIENT_REGISTRATION_ID]' => esc_html__('Parses to the registration ID of the recipient for the message.', 'event_espresso'), |
|
47 | + '[RECIPIENT_REGISTRATION_CODE]' => esc_html__('Parses to the registration code of the recipient for the message.', 'event_espresso'), |
|
48 | + '[RECIPIENT_EDIT_REGISTRATION_LINK]' => esc_html__('Parses to a link for frontend editing of the registration for the recipient.', 'event_espresso'), |
|
49 | + '[RECIPIENT_PHONE_NUMBER]' => esc_html__('The Phone Number for the recipient of the message.', 'event_espresso'), |
|
50 | + '[RECIPIENT_ADDRESS]' => esc_html__('The Address for the recipient of the message.', 'event_espresso'), |
|
51 | + '[RECIPIENT_ADDRESS2]' => esc_html__('Whatever was in the address 2 field for the recipient of the message.', 'event_espresso'), |
|
52 | + '[RECIPIENT_CITY]' => esc_html__('The city for the recipient of the message.', 'event_espresso'), |
|
53 | + '[RECIPIENT_ZIP_PC]' => esc_html__('The ZIP (or Postal) Code for the recipient of the message.', 'event_espresso'), |
|
54 | + '[RECIPIENT_ADDRESS_STATE]' => esc_html__('The state/province for the recipient of the message.', 'event_espresso'), |
|
55 | + '[RECIPIENT_COUNTRY]' => esc_html__('The country for the recipient of the message.', 'event_espresso'), |
|
56 | + '[RECIPIENT_ANSWER_*]' => esc_html__('This is a special dynamic shortcode. After the "*", add the exact text of an existing question, and if there is an answer for that question for this recipient, then it will be output in place of this shortcode.', 'event_espresso'), |
|
57 | + '[RECIPIENT_TOTAL_AMOUNT_PAID]' => esc_html__('If a single registration related to the recipient is available, that is used to retrieve the total amount that has been paid for this recipient. Otherwise the value of 0 is printed.', 'event_espresso') |
|
58 | 58 | ); |
59 | 59 | } |
60 | 60 | |
@@ -65,36 +65,35 @@ discard block |
||
65 | 65 | * @param string $shortcode the shortcode to be parsed. |
66 | 66 | * @return string parsed shortcode |
67 | 67 | */ |
68 | - protected function _parser( $shortcode ) { |
|
68 | + protected function _parser($shortcode) { |
|
69 | 69 | |
70 | 70 | //make sure we end up with a copy of the EE_Messages_Addressee object |
71 | 71 | $this->_recipient = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
72 | 72 | $this->_recipient = ! $this->_recipient instanceof EE_Messages_Addressee |
73 | - && is_array( $this->_data ) |
|
74 | - && isset( $this->_data['data'] ) |
|
73 | + && is_array($this->_data) |
|
74 | + && isset($this->_data['data']) |
|
75 | 75 | && $this->_data['data'] instanceof EE_Messages_Addressee |
76 | - ? $this->_data['data'] : |
|
77 | - $this->_recipient; |
|
76 | + ? $this->_data['data'] : $this->_recipient; |
|
78 | 77 | $this->_recipient = ! $this->_recipient instanceof EE_Messages_Addressee |
79 | - && ! empty( $this->_extra_data['data'] ) |
|
78 | + && ! empty($this->_extra_data['data']) |
|
80 | 79 | && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
81 | 80 | ? $this->_extra_data['data'] |
82 | 81 | : $this->_recipient; |
83 | 82 | |
84 | - if ( ! $this->_recipient instanceof EE_Messages_Addressee ) { |
|
83 | + if ( ! $this->_recipient instanceof EE_Messages_Addressee) { |
|
85 | 84 | return ''; |
86 | 85 | } |
87 | 86 | |
88 | 87 | $attendee = $this->_recipient->att_obj; |
89 | - if ( ! $attendee instanceof EE_Attendee ) { |
|
88 | + if ( ! $attendee instanceof EE_Attendee) { |
|
90 | 89 | return ''; |
91 | 90 | } |
92 | 91 | |
93 | - $this->_registrations_for_recipient = isset( $this->_recipient->attendees[ $attendee->ID() ]['reg_objs'] ) |
|
94 | - ? $this->_recipient->attendees[ $attendee->ID() ]['reg_objs'] |
|
92 | + $this->_registrations_for_recipient = isset($this->_recipient->attendees[$attendee->ID()]['reg_objs']) |
|
93 | + ? $this->_recipient->attendees[$attendee->ID()]['reg_objs'] |
|
95 | 94 | : array(); |
96 | 95 | |
97 | - switch ( $shortcode ) { |
|
96 | + switch ($shortcode) { |
|
98 | 97 | case '[RECIPIENT_FNAME]' : |
99 | 98 | return $attendee->fname(); |
100 | 99 | break; |
@@ -108,21 +107,21 @@ discard block |
||
108 | 107 | break; |
109 | 108 | |
110 | 109 | case '[RECIPIENT_REGISTRATION_ID]' : |
111 | - if ( ! $this->_recipient->reg_obj instanceof EE_Registration ) { |
|
110 | + if ( ! $this->_recipient->reg_obj instanceof EE_Registration) { |
|
112 | 111 | return ''; |
113 | 112 | } |
114 | 113 | return $this->_get_reg_id(); |
115 | 114 | break; |
116 | 115 | |
117 | 116 | case '[RECIPIENT_REGISTRATION_CODE]' : |
118 | - if ( ! $this->_recipient->reg_obj instanceof EE_Registration ) { |
|
117 | + if ( ! $this->_recipient->reg_obj instanceof EE_Registration) { |
|
119 | 118 | return ''; |
120 | 119 | } |
121 | 120 | return $this->_get_reg_code(); |
122 | 121 | break; |
123 | 122 | |
124 | 123 | case '[RECIPIENT_EDIT_REGISTRATION_LINK]' : |
125 | - if ( ! $this->_recipient->reg_obj instanceof EE_Registration ) { |
|
124 | + if ( ! $this->_recipient->reg_obj instanceof EE_Registration) { |
|
126 | 125 | return ''; |
127 | 126 | } |
128 | 127 | return $this->_recipient->reg_obj->edit_attendee_information_url(); |
@@ -164,23 +163,23 @@ discard block |
||
164 | 163 | break; |
165 | 164 | } |
166 | 165 | |
167 | - if ( strpos( $shortcode, '[RECIPIENT_ANSWER_*' ) !== false ) { |
|
168 | - $shortcode = str_replace( '[RECIPIENT_ANSWER_*', '', $shortcode ); |
|
169 | - $shortcode = trim( str_replace( ']', '', $shortcode ) ); |
|
166 | + if (strpos($shortcode, '[RECIPIENT_ANSWER_*') !== false) { |
|
167 | + $shortcode = str_replace('[RECIPIENT_ANSWER_*', '', $shortcode); |
|
168 | + $shortcode = trim(str_replace(']', '', $shortcode)); |
|
170 | 169 | |
171 | 170 | |
172 | 171 | //now let's figure out what question has this text |
173 | - if ( empty( $this->_recipient->questions ) || ! $this->_recipient->reg_obj instanceof EE_Registration ) { |
|
172 | + if (empty($this->_recipient->questions) || ! $this->_recipient->reg_obj instanceof EE_Registration) { |
|
174 | 173 | return ''; |
175 | 174 | } |
176 | 175 | |
177 | - foreach ( $this->_recipient->questions as $ansid => $question ) { |
|
176 | + foreach ($this->_recipient->questions as $ansid => $question) { |
|
178 | 177 | if ( |
179 | 178 | $question instanceof EE_Question |
180 | - && trim( $question->display_text() ) == trim( $shortcode ) |
|
181 | - && isset( $this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ] ) |
|
179 | + && trim($question->display_text()) == trim($shortcode) |
|
180 | + && isset($this->_recipient->registrations[$this->_recipient->reg_obj->ID()]['ans_objs'][$ansid]) |
|
182 | 181 | ) { |
183 | - return $this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ]->get_pretty( 'ANS_value', 'no_wpautop' ); |
|
182 | + return $this->_recipient->registrations[$this->_recipient->reg_obj->ID()]['ans_objs'][$ansid]->get_pretty('ANS_value', 'no_wpautop'); |
|
184 | 183 | } |
185 | 184 | } |
186 | 185 | } |
@@ -211,53 +210,53 @@ discard block |
||
211 | 210 | protected function _get_reg_code() { |
212 | 211 | |
213 | 212 | //if only one related registration for the recipient then just return that reg code. |
214 | - if ( count( $this->_registrations_for_recipient ) <= 1 ) { |
|
213 | + if (count($this->_registrations_for_recipient) <= 1) { |
|
215 | 214 | return $this->_recipient->reg_obj->reg_code(); |
216 | 215 | } |
217 | 216 | |
218 | 217 | //k more than one registration so let's see if we can get specific to context |
219 | 218 | //are we parsing event_list? |
220 | - if ( $this->_data instanceof EE_Event ) { |
|
219 | + if ($this->_data instanceof EE_Event) { |
|
221 | 220 | $reg_code = array(); |
222 | 221 | //loop through registrations for recipient and see if there is a match for this event |
223 | - foreach ( $this->_registrations_for_recipient as $reg ) { |
|
224 | - if ( $reg instanceof EE_Registration && $reg->event_ID() == $this->_data->ID() ) { |
|
222 | + foreach ($this->_registrations_for_recipient as $reg) { |
|
223 | + if ($reg instanceof EE_Registration && $reg->event_ID() == $this->_data->ID()) { |
|
225 | 224 | $reg_code[] = $reg->reg_code(); |
226 | 225 | } |
227 | 226 | } |
228 | - return implode( ', ', $reg_code ); |
|
227 | + return implode(', ', $reg_code); |
|
229 | 228 | } |
230 | 229 | |
231 | 230 | //are we parsing ticket list? |
232 | - if ( $this->_data instanceof EE_Ticket ) { |
|
231 | + if ($this->_data instanceof EE_Ticket) { |
|
233 | 232 | $reg_code = array(); |
234 | 233 | //loop through each registration for recipient and see if there is a match for this ticket |
235 | - foreach ( $this->_registrations_for_recipient as $reg ) { |
|
236 | - if ( $reg instanceof EE_Registration && $reg->ticket_ID() == $this->_data->ID() ) { |
|
234 | + foreach ($this->_registrations_for_recipient as $reg) { |
|
235 | + if ($reg instanceof EE_Registration && $reg->ticket_ID() == $this->_data->ID()) { |
|
237 | 236 | $reg_code = $reg->reg_code(); |
238 | 237 | } |
239 | 238 | } |
240 | - return implode( ', ', $reg_code ); |
|
239 | + return implode(', ', $reg_code); |
|
241 | 240 | } |
242 | 241 | |
243 | 242 | //do we have a specific reg_obj? Let's use it |
244 | - if ( $this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration ) { |
|
243 | + if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) { |
|
245 | 244 | return $this->_data->reg_obj->reg_code(); |
246 | 245 | } |
247 | 246 | |
248 | 247 | //do we have a specific reg_obj? Let's use it |
249 | - if ( $this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration ) { |
|
248 | + if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) { |
|
250 | 249 | return $this->_data->reg_obj->reg_code(); |
251 | 250 | } |
252 | 251 | |
253 | 252 | //not able to determine the single reg code so let's return a comma delimited list of reg codes. |
254 | 253 | $reg_code = array(); |
255 | - foreach ( $this->_registrations_for_recipient as $reg ) { |
|
256 | - if ( $reg instanceof EE_Registration ) { |
|
254 | + foreach ($this->_registrations_for_recipient as $reg) { |
|
255 | + if ($reg instanceof EE_Registration) { |
|
257 | 256 | $reg_code[] = $reg->reg_code(); |
258 | 257 | } |
259 | 258 | } |
260 | - return implode( ', ', $reg_code ); |
|
259 | + return implode(', ', $reg_code); |
|
261 | 260 | } |
262 | 261 | |
263 | 262 | |
@@ -270,48 +269,48 @@ discard block |
||
270 | 269 | protected function _get_reg_id() { |
271 | 270 | |
272 | 271 | //if only one related registration for the recipient then just return that reg code. |
273 | - if ( count( $this->_registrations_for_recipient ) <= 1 ) { |
|
272 | + if (count($this->_registrations_for_recipient) <= 1) { |
|
274 | 273 | return $this->_recipient->reg_obj->ID(); |
275 | 274 | } |
276 | 275 | |
277 | 276 | //k more than one registration so let's see if we can get specific to context |
278 | 277 | //are we parsing event_list? |
279 | - if ( $this->_data instanceof EE_Event ) { |
|
278 | + if ($this->_data instanceof EE_Event) { |
|
280 | 279 | $registration_ids = array(); |
281 | 280 | //loop through registrations for recipient and see if there is a match for this event |
282 | - foreach ( $this->_registrations_for_recipient as $reg ) { |
|
283 | - if ( $reg instanceof EE_Registration && $reg->event_ID() == $this->_data->ID() ) { |
|
281 | + foreach ($this->_registrations_for_recipient as $reg) { |
|
282 | + if ($reg instanceof EE_Registration && $reg->event_ID() == $this->_data->ID()) { |
|
284 | 283 | $registration_ids[] = $reg->ID(); |
285 | 284 | } |
286 | 285 | } |
287 | - return implode( ', ', $registration_ids ); |
|
286 | + return implode(', ', $registration_ids); |
|
288 | 287 | } |
289 | 288 | |
290 | 289 | //are we parsing ticket list? |
291 | - if ( $this->_data instanceof EE_Ticket ) { |
|
290 | + if ($this->_data instanceof EE_Ticket) { |
|
292 | 291 | $registration_ids = array(); |
293 | 292 | //loop through each registration for recipient and see if there is a match for this ticket |
294 | - foreach ( $this->_registrations_for_recipient as $reg ) { |
|
295 | - if ( $reg instanceof EE_Registration && $reg->ticket_ID() == $this->_data->ID() ) { |
|
293 | + foreach ($this->_registrations_for_recipient as $reg) { |
|
294 | + if ($reg instanceof EE_Registration && $reg->ticket_ID() == $this->_data->ID()) { |
|
296 | 295 | $registration_ids = $reg->ID(); |
297 | 296 | } |
298 | 297 | } |
299 | - return implode( ', ', $registration_ids ); |
|
298 | + return implode(', ', $registration_ids); |
|
300 | 299 | } |
301 | 300 | |
302 | 301 | //do we have a specific reg_obj? Let's use it |
303 | - if ( $this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration ) { |
|
302 | + if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) { |
|
304 | 303 | return $this->_data->reg_obj->ID(); |
305 | 304 | } |
306 | 305 | |
307 | 306 | //not able to determine the single reg code so let's return a comma delimited list of reg codes. |
308 | 307 | $registration_ids = array(); |
309 | - foreach ( $this->_registrations_for_recipient as $reg ) { |
|
310 | - if ( $reg instanceof EE_Registration ) { |
|
308 | + foreach ($this->_registrations_for_recipient as $reg) { |
|
309 | + if ($reg instanceof EE_Registration) { |
|
311 | 310 | $registration_ids[] = $reg->ID(); |
312 | 311 | } |
313 | 312 | } |
314 | - return implode( ', ', $registration_ids ); |
|
313 | + return implode(', ', $registration_ids); |
|
315 | 314 | } |
316 | 315 | |
317 | 316 |
@@ -1,6 +1,7 @@ |
||
1 | 1 | <?php |
2 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
2 | +if (!defined('EVENT_ESPRESSO_VERSION') ) { |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | +} |
|
4 | 5 | |
5 | 6 | /** |
6 | 7 | * Event Espresso |
@@ -41,7 +41,7 @@ |
||
41 | 41 | |
42 | 42 | /** |
43 | 43 | * EE_Attendee_Shortcodes constructor. |
44 | - */ |
|
44 | + */ |
|
45 | 45 | public function __construct() { |
46 | 46 | parent::__construct(); |
47 | 47 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
4 | 4 | exit('NO direct script access allowed'); |
5 | 5 | |
6 | 6 | /** |
@@ -49,26 +49,26 @@ discard block |
||
49 | 49 | |
50 | 50 | |
51 | 51 | protected function _init_props() { |
52 | - $this->label = esc_html__( 'Attendee Shortcodes', 'event_espresso' ); |
|
53 | - $this->description = esc_html__( 'All shortcodes specific to attendee related data', 'event_espresso' ); |
|
52 | + $this->label = esc_html__('Attendee Shortcodes', 'event_espresso'); |
|
53 | + $this->description = esc_html__('All shortcodes specific to attendee related data', 'event_espresso'); |
|
54 | 54 | $this->_shortcodes = array( |
55 | - '[FNAME]' => esc_html__( 'First Name of an attendee.', 'event_espresso' ), |
|
56 | - '[LNAME]' => esc_html__( 'Last Name of an attendee.', 'event_espresso' ), |
|
57 | - '[ATTENDEE_EMAIL]' => esc_html__( 'Email address for the attendee.', 'event_espresso' ), |
|
58 | - '[EDIT_ATTENDEE_LINK]' => esc_html__( 'Edit Registration Link (typically you\'d only use this for messages going to event administrators)', 'event_espresso' ), |
|
59 | - '[REGISTRATION_ID]' => esc_html__( 'Unique Registration ID for the registration', 'event_espresso' ), |
|
60 | - '[REGISTRATION_CODE]' => esc_html__( 'Unique Registration Code for the registration', 'event_espresso' ), |
|
61 | - '[REGISTRATION_STATUS_ID]' => esc_html__( 'Parses to the registration status for the attendee', 'event_espresso' ), |
|
62 | - '[REGISTRATION_STATUS_LABEL]' => esc_html__( 'Parses to the status label for the registrant', 'event_espresso' ), |
|
63 | - '[REGISTRATION_TOTAL_AMOUNT_PAID]' => esc_html__( 'Parses to the total amount paid for this registration.', 'event_espresso' ), |
|
64 | - '[FRONTEND_EDIT_REG_LINK]' => esc_html__( 'Generates a link for the given registration to edit this registration details on the frontend.', 'event_espresso' ), |
|
65 | - '[PHONE_NUMBER]' => esc_html__( 'The Phone Number for the Registration.', 'event_espresso' ), |
|
66 | - '[ADDRESS]' => esc_html__( 'The Address for the Registration', 'event_espresso' ), |
|
67 | - '[ADDRESS2]' => esc_html__( 'Whatever was in the address 2 field for the registration.', 'event_espresso' ), |
|
68 | - '[CITY]' => esc_html__( 'The city for the registration.', 'event_espresso' ), |
|
69 | - '[ZIP_PC]' => esc_html__( 'The ZIP (or Postal) Code for the Registration.', 'event_espresso' ), |
|
70 | - '[ADDRESS_STATE]' => esc_html__( 'The state/province for the registration.', 'event_espresso' ), |
|
71 | - '[COUNTRY]' => esc_html__( 'The country for the registration.', 'event_espresso' ) |
|
55 | + '[FNAME]' => esc_html__('First Name of an attendee.', 'event_espresso'), |
|
56 | + '[LNAME]' => esc_html__('Last Name of an attendee.', 'event_espresso'), |
|
57 | + '[ATTENDEE_EMAIL]' => esc_html__('Email address for the attendee.', 'event_espresso'), |
|
58 | + '[EDIT_ATTENDEE_LINK]' => esc_html__('Edit Registration Link (typically you\'d only use this for messages going to event administrators)', 'event_espresso'), |
|
59 | + '[REGISTRATION_ID]' => esc_html__('Unique Registration ID for the registration', 'event_espresso'), |
|
60 | + '[REGISTRATION_CODE]' => esc_html__('Unique Registration Code for the registration', 'event_espresso'), |
|
61 | + '[REGISTRATION_STATUS_ID]' => esc_html__('Parses to the registration status for the attendee', 'event_espresso'), |
|
62 | + '[REGISTRATION_STATUS_LABEL]' => esc_html__('Parses to the status label for the registrant', 'event_espresso'), |
|
63 | + '[REGISTRATION_TOTAL_AMOUNT_PAID]' => esc_html__('Parses to the total amount paid for this registration.', 'event_espresso'), |
|
64 | + '[FRONTEND_EDIT_REG_LINK]' => esc_html__('Generates a link for the given registration to edit this registration details on the frontend.', 'event_espresso'), |
|
65 | + '[PHONE_NUMBER]' => esc_html__('The Phone Number for the Registration.', 'event_espresso'), |
|
66 | + '[ADDRESS]' => esc_html__('The Address for the Registration', 'event_espresso'), |
|
67 | + '[ADDRESS2]' => esc_html__('Whatever was in the address 2 field for the registration.', 'event_espresso'), |
|
68 | + '[CITY]' => esc_html__('The city for the registration.', 'event_espresso'), |
|
69 | + '[ZIP_PC]' => esc_html__('The ZIP (or Postal) Code for the Registration.', 'event_espresso'), |
|
70 | + '[ADDRESS_STATE]' => esc_html__('The state/province for the registration.', 'event_espresso'), |
|
71 | + '[COUNTRY]' => esc_html__('The country for the registration.', 'event_espresso') |
|
72 | 72 | ); |
73 | 73 | } |
74 | 74 | |
@@ -82,10 +82,10 @@ discard block |
||
82 | 82 | * @return string |
83 | 83 | * @throws \EE_Error |
84 | 84 | */ |
85 | - protected function _parser( $shortcode ) { |
|
85 | + protected function _parser($shortcode) { |
|
86 | 86 | |
87 | 87 | |
88 | - $this->_xtra = ! empty( $this->_extra_data ) && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
88 | + $this->_xtra = ! empty($this->_extra_data) && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
89 | 89 | ? $this->_extra_data['data'] |
90 | 90 | : null; |
91 | 91 | |
@@ -94,34 +94,34 @@ discard block |
||
94 | 94 | ? null |
95 | 95 | : $this->_data; |
96 | 96 | |
97 | - if ( ! $registration instanceof EE_Registration ) { |
|
97 | + if ( ! $registration instanceof EE_Registration) { |
|
98 | 98 | //let's attempt to get the txn_id for the error message. |
99 | - $txn_id = isset( $this->_xtra->txn ) && $this->_xtra->txn instanceof EE_Transaction |
|
99 | + $txn_id = isset($this->_xtra->txn) && $this->_xtra->txn instanceof EE_Transaction |
|
100 | 100 | ? $this->_xtra->txn->ID() |
101 | - : esc_html__( 'Unknown', 'event_espresso' ); |
|
102 | - $msg = esc_html__( 'There is no EE_Registration object in the data sent to the EE_Attendee Shortcode Parser for the messages system.', 'event_espresso' ); |
|
101 | + : esc_html__('Unknown', 'event_espresso'); |
|
102 | + $msg = esc_html__('There is no EE_Registration object in the data sent to the EE_Attendee Shortcode Parser for the messages system.', 'event_espresso'); |
|
103 | 103 | $dev_msg = sprintf( |
104 | - esc_html__( 'The transaction ID for this request is: %s', 'event_espresso' ), |
|
104 | + esc_html__('The transaction ID for this request is: %s', 'event_espresso'), |
|
105 | 105 | $txn_id |
106 | 106 | ); |
107 | - throw new EE_Error( "{$msg}||{$msg} {$dev_msg}" ); |
|
107 | + throw new EE_Error("{$msg}||{$msg} {$dev_msg}"); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | //attendee obj for this registration |
111 | - $attendee = isset( $this->_xtra->registrations[ $registration->ID() ]['att_obj'] ) |
|
112 | - ? $this->_xtra->registrations[ $registration->ID() ]['att_obj'] |
|
113 | - : null ; |
|
111 | + $attendee = isset($this->_xtra->registrations[$registration->ID()]['att_obj']) |
|
112 | + ? $this->_xtra->registrations[$registration->ID()]['att_obj'] |
|
113 | + : null; |
|
114 | 114 | |
115 | - if ( ! $attendee instanceof EE_Attendee ) { |
|
116 | - $msg = esc_html__( 'There is no EE_Attendee object in the data sent to the EE_Attendee_Shortcode parser for the messages system.', 'event_espresso' ); |
|
115 | + if ( ! $attendee instanceof EE_Attendee) { |
|
116 | + $msg = esc_html__('There is no EE_Attendee object in the data sent to the EE_Attendee_Shortcode parser for the messages system.', 'event_espresso'); |
|
117 | 117 | $dev_msg = sprintf( |
118 | - esc_html__( 'The registration ID for this request is: %s', 'event_espresso' ), |
|
118 | + esc_html__('The registration ID for this request is: %s', 'event_espresso'), |
|
119 | 119 | $registration->ID() |
120 | 120 | ); |
121 | - throw new EE_Error( "{$msg}||{$msg} {$dev_msg}" ); |
|
121 | + throw new EE_Error("{$msg}||{$msg} {$dev_msg}"); |
|
122 | 122 | } |
123 | 123 | |
124 | - switch ( $shortcode ) { |
|
124 | + switch ($shortcode) { |
|
125 | 125 | |
126 | 126 | case '[FNAME]' : |
127 | 127 | return $attendee->fname(); |
@@ -1,6 +1,7 @@ |
||
1 | 1 | <?php |
2 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
2 | +if (!defined('EVENT_ESPRESSO_VERSION') ) { |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | +} |
|
4 | 5 | |
5 | 6 | /** |
6 | 7 | * Event Espresso |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
3 | - exit( 'NO direct script access allowed' ); |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | + exit('NO direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | * @param array $addressee_data We're expecting an incoming array of data that will be used to fill the properties |
261 | 261 | * for the object. |
262 | 262 | */ |
263 | - public function __construct( $addressee_data ) { |
|
263 | + public function __construct($addressee_data) { |
|
264 | 264 | $this->_data = $addressee_data; |
265 | 265 | $this->_set_properties(); |
266 | 266 | } |
@@ -275,15 +275,15 @@ discard block |
||
275 | 275 | * @return void. |
276 | 276 | */ |
277 | 277 | protected function _set_properties() { |
278 | - foreach ( $this->_data as $prop => $value ) { |
|
279 | - if ( property_exists( $this, $prop ) ) { |
|
278 | + foreach ($this->_data as $prop => $value) { |
|
279 | + if (property_exists($this, $prop)) { |
|
280 | 280 | $this->{$prop} = $value; |
281 | 281 | } |
282 | 282 | } |
283 | 283 | //if user_id present we'll use this to set the fname and lname and admin_email. |
284 | - if ( ! empty( $this->user_id ) ) { |
|
284 | + if ( ! empty($this->user_id)) { |
|
285 | 285 | $this->user_id = (int) $this->user_id; |
286 | - $user = get_userdata( $this->user_id ); |
|
286 | + $user = get_userdata($this->user_id); |
|
287 | 287 | $this->fname = $user->user_firstname; |
288 | 288 | $this->lname = $user->user_lastname; |
289 | 289 | $this->admin_email = $user->user_email; |
@@ -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 | * |
@@ -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 |