@@ -72,6 +72,6 @@ |
||
72 | 72 | } |
73 | 73 | $this->template_args['ticket_description'] = $ticket_selector_row->getTicketDescription(); |
74 | 74 | $this->template_args['template_path'] = |
75 | - TICKET_SELECTOR_TEMPLATES_PATH . 'simple_ticket_selector.template.php'; |
|
75 | + TICKET_SELECTOR_TEMPLATES_PATH.'simple_ticket_selector.template.php'; |
|
76 | 76 | } |
77 | 77 | } |
@@ -19,59 +19,59 @@ |
||
19 | 19 | */ |
20 | 20 | class TicketSelectorSimple extends TicketSelector |
21 | 21 | { |
22 | - /** |
|
23 | - * @var EE_Ticket $ticket |
|
24 | - */ |
|
25 | - protected $ticket; |
|
22 | + /** |
|
23 | + * @var EE_Ticket $ticket |
|
24 | + */ |
|
25 | + protected $ticket; |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * TicketSelectorSimple constructor. |
|
30 | - * |
|
31 | - * @param EE_Event $event |
|
32 | - * @param EE_Ticket $ticket |
|
33 | - * @param int $max_attendees |
|
34 | - * @param array $template_args |
|
35 | - * @throws EE_Error |
|
36 | - */ |
|
37 | - public function __construct(EE_Event $event, EE_Ticket $ticket, $max_attendees, array $template_args) |
|
38 | - { |
|
39 | - $this->ticket = $ticket; |
|
40 | - parent::__construct( |
|
41 | - $event, |
|
42 | - [$this->ticket], |
|
43 | - $max_attendees, |
|
44 | - $template_args |
|
45 | - ); |
|
46 | - } |
|
28 | + /** |
|
29 | + * TicketSelectorSimple constructor. |
|
30 | + * |
|
31 | + * @param EE_Event $event |
|
32 | + * @param EE_Ticket $ticket |
|
33 | + * @param int $max_attendees |
|
34 | + * @param array $template_args |
|
35 | + * @throws EE_Error |
|
36 | + */ |
|
37 | + public function __construct(EE_Event $event, EE_Ticket $ticket, $max_attendees, array $template_args) |
|
38 | + { |
|
39 | + $this->ticket = $ticket; |
|
40 | + parent::__construct( |
|
41 | + $event, |
|
42 | + [$this->ticket], |
|
43 | + $max_attendees, |
|
44 | + $template_args |
|
45 | + ); |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * sets any and all template args that are required for this Ticket Selector |
|
51 | - * |
|
52 | - * @return void |
|
53 | - * @throws UnexpectedEntityException |
|
54 | - * @throws EE_Error |
|
55 | - */ |
|
56 | - protected function addTemplateArgs() |
|
57 | - { |
|
58 | - $this->ticket_rows = 1; |
|
59 | - unset($this->template_args['tickets']); |
|
60 | - $this->template_args['ticket'] = $this->ticket; |
|
61 | - $ticket_selector_row = new TicketSelectorRowSimple( |
|
62 | - $this->ticket, |
|
63 | - $this->max_attendees, |
|
64 | - $this->template_args['date_format'], |
|
65 | - $this->template_args['event_status'] |
|
66 | - ); |
|
67 | - $this->template_args['TKT_ID'] = $this->ticket->ID(); |
|
68 | - $ticket_selector_row->setupTicketStatusDisplay(); |
|
69 | - $this->template_args['ticket_status_display'] = $ticket_selector_row->getTicketStatusDisplay(); |
|
70 | - if (empty($this->template_args['ticket_status_display'])) { |
|
71 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
72 | - } |
|
73 | - $this->template_args['ticket_description'] = $ticket_selector_row->getTicketDescription(); |
|
74 | - $this->template_args['template_path'] = |
|
75 | - TICKET_SELECTOR_TEMPLATES_PATH . 'simple_ticket_selector.template.php'; |
|
76 | - } |
|
49 | + /** |
|
50 | + * sets any and all template args that are required for this Ticket Selector |
|
51 | + * |
|
52 | + * @return void |
|
53 | + * @throws UnexpectedEntityException |
|
54 | + * @throws EE_Error |
|
55 | + */ |
|
56 | + protected function addTemplateArgs() |
|
57 | + { |
|
58 | + $this->ticket_rows = 1; |
|
59 | + unset($this->template_args['tickets']); |
|
60 | + $this->template_args['ticket'] = $this->ticket; |
|
61 | + $ticket_selector_row = new TicketSelectorRowSimple( |
|
62 | + $this->ticket, |
|
63 | + $this->max_attendees, |
|
64 | + $this->template_args['date_format'], |
|
65 | + $this->template_args['event_status'] |
|
66 | + ); |
|
67 | + $this->template_args['TKT_ID'] = $this->ticket->ID(); |
|
68 | + $ticket_selector_row->setupTicketStatusDisplay(); |
|
69 | + $this->template_args['ticket_status_display'] = $ticket_selector_row->getTicketStatusDisplay(); |
|
70 | + if (empty($this->template_args['ticket_status_display'])) { |
|
71 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
72 | + } |
|
73 | + $this->template_args['ticket_description'] = $ticket_selector_row->getTicketDescription(); |
|
74 | + $this->template_args['template_path'] = |
|
75 | + TICKET_SELECTOR_TEMPLATES_PATH . 'simple_ticket_selector.template.php'; |
|
76 | + } |
|
77 | 77 | } |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | */ |
229 | 229 | public function set_submit_button_text($submit_button_text = '') |
230 | 230 | { |
231 | - if (! empty($submit_button_text)) { |
|
231 | + if ( ! empty($submit_button_text)) { |
|
232 | 232 | $this->_submit_button_text = $submit_button_text; |
233 | 233 | } elseif ($this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
234 | 234 | if ($this->checkout->revisit) { |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | public function reg_form_name() |
389 | 389 | { |
390 | 390 | if (empty($this->_reg_form_name)) { |
391 | - $this->set_reg_form_name('ee-spco-' . $this->slug() . '-reg-step-form'); |
|
391 | + $this->set_reg_form_name('ee-spco-'.$this->slug().'-reg-step-form'); |
|
392 | 392 | } |
393 | 393 | return $this->_reg_form_name; |
394 | 394 | } |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | public function reg_step_url($action = '') |
413 | 413 | { |
414 | 414 | $query_args = ['step' => $this->slug()]; |
415 | - if (! empty($action)) { |
|
415 | + if ( ! empty($action)) { |
|
416 | 416 | $query_args['action'] = $action; |
417 | 417 | } |
418 | 418 | // final step has no display |
@@ -442,12 +442,12 @@ discard block |
||
442 | 442 | return new EE_Form_Section_Proper( |
443 | 443 | [ |
444 | 444 | 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
445 | - 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
445 | + 'html_id' => 'ee-'.$this->slug().'-hidden-inputs', |
|
446 | 446 | 'subsections' => [ |
447 | 447 | 'next_step' => new EE_Fixed_Hidden_Input( |
448 | 448 | [ |
449 | 449 | 'html_name' => 'next_step', |
450 | - 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
450 | + 'html_id' => 'spco-'.$this->slug().'-next-step', |
|
451 | 451 | 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
452 | 452 | ? $this->checkout->next_step->slug() |
453 | 453 | : '', |
@@ -461,12 +461,12 @@ discard block |
||
461 | 461 | return new EE_Form_Section_Proper( |
462 | 462 | [ |
463 | 463 | 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
464 | - 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
464 | + 'html_id' => 'ee-'.$this->slug().'-hidden-inputs', |
|
465 | 465 | 'subsections' => [ |
466 | 466 | 'action' => new EE_Fixed_Hidden_Input( |
467 | 467 | [ |
468 | 468 | 'html_name' => 'action', |
469 | - 'html_id' => 'spco-' . $this->slug() . '-action', |
|
469 | + 'html_id' => 'spco-'.$this->slug().'-action', |
|
470 | 470 | 'default' => apply_filters( |
471 | 471 | 'FHEE__EE_SPCO_Reg_Step__reg_step_hidden_inputs__default_form_action', |
472 | 472 | empty($this->checkout->reg_url_link) |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | 'next_step' => new EE_Fixed_Hidden_Input( |
480 | 480 | [ |
481 | 481 | 'html_name' => 'next_step', |
482 | - 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
482 | + 'html_id' => 'spco-'.$this->slug().'-next-step', |
|
483 | 483 | 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
484 | 484 | ? $this->checkout->next_step->slug() |
485 | 485 | : '', |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | */ |
514 | 514 | public function generate_reg_form_for_actions($actions = []) |
515 | 515 | { |
516 | - $actions = array_merge( |
|
516 | + $actions = array_merge( |
|
517 | 517 | [ |
518 | 518 | 'generate_reg_form', |
519 | 519 | 'display_spco_reg_step', |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | */ |
557 | 557 | public function reg_step_submit_button() |
558 | 558 | { |
559 | - if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
559 | + if ( ! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
560 | 560 | return ''; |
561 | 561 | } |
562 | 562 | ob_start(); |
@@ -570,18 +570,18 @@ discard block |
||
570 | 570 | // generate submit button |
571 | 571 | $submit_btn = new EE_Submit_Input( |
572 | 572 | [ |
573 | - 'html_name' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
574 | - 'html_id' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
573 | + 'html_name' => 'spco-go-to-step-'.$this->checkout->next_step->slug(), |
|
574 | + 'html_id' => 'spco-go-to-step-'.$this->checkout->next_step->slug(), |
|
575 | 575 | 'html_class' => 'spco-next-step-btn', |
576 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
576 | + 'other_html_attributes' => ' rel="'.$this->slug().'"', |
|
577 | 577 | 'default' => $this->submit_button_text(), |
578 | 578 | ] |
579 | 579 | ); |
580 | 580 | $submit_btn->set_button_css_attributes(true, 'large'); |
581 | 581 | $submit_btn_html = $submit_btn->get_html_for_input(); |
582 | - $html .= EEH_HTML::div( |
|
582 | + $html .= EEH_HTML::div( |
|
583 | 583 | apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $submit_btn_html, $this), |
584 | - 'spco-' . $this->slug() . '-whats-next-buttons-dv', |
|
584 | + 'spco-'.$this->slug().'-whats-next-buttons-dv', |
|
585 | 585 | 'spco-whats-next-buttons' |
586 | 586 | ); |
587 | 587 | return $html; |
@@ -13,657 +13,657 @@ |
||
13 | 13 | */ |
14 | 14 | abstract class EE_SPCO_Reg_Step |
15 | 15 | { |
16 | - /** |
|
17 | - * $_completed - TRUE if this step has fully completed it's duties |
|
18 | - * |
|
19 | - * @access protected |
|
20 | - * @type bool $_completed |
|
21 | - */ |
|
22 | - protected $_completed = false; |
|
23 | - |
|
24 | - /** |
|
25 | - * $_is_current_step - TRUE if this is the current step |
|
26 | - * |
|
27 | - * @access protected |
|
28 | - * @type bool $_is_current_step |
|
29 | - */ |
|
30 | - protected $_is_current_step = false; |
|
31 | - |
|
32 | - /** |
|
33 | - * $_order - when the reg step should be run relative to other steps |
|
34 | - * |
|
35 | - * @access protected |
|
36 | - * @type int $_template |
|
37 | - */ |
|
38 | - protected $_order = 0; |
|
39 | - |
|
40 | - /** |
|
41 | - * $_slug - URL param for this step |
|
42 | - * |
|
43 | - * @access protected |
|
44 | - * @type string $_slug |
|
45 | - */ |
|
46 | - protected $_slug; |
|
47 | - |
|
48 | - /** |
|
49 | - * $_name - Step Name - translatable string |
|
50 | - * |
|
51 | - * @access protected |
|
52 | - * @type string $_slug |
|
53 | - */ |
|
54 | - protected $_name; |
|
55 | - |
|
56 | - /** |
|
57 | - * $_submit_button_text - translatable string that appears on this step's submit button |
|
58 | - * |
|
59 | - * @access protected |
|
60 | - * @type string $_slug |
|
61 | - */ |
|
62 | - protected $_submit_button_text; |
|
63 | - |
|
64 | - /** |
|
65 | - * $_template - template name |
|
66 | - * |
|
67 | - * @access protected |
|
68 | - * @type string $_template |
|
69 | - */ |
|
70 | - protected $_template; |
|
71 | - |
|
72 | - /** |
|
73 | - * $_reg_form_name - the form input name and id attribute |
|
74 | - * |
|
75 | - * @access protected |
|
76 | - * @var string $_reg_form_name |
|
77 | - */ |
|
78 | - protected $_reg_form_name; |
|
79 | - |
|
80 | - /** |
|
81 | - * $_success_message - text to display upon successful form submission |
|
82 | - * |
|
83 | - * @access private |
|
84 | - * @var string $_success_message |
|
85 | - */ |
|
86 | - protected $_success_message; |
|
87 | - |
|
88 | - /** |
|
89 | - * $_instructions - a brief description of how to complete the reg step. |
|
90 | - * Usually displayed in conjunction with the previous step's success message. |
|
91 | - * |
|
92 | - * @access private |
|
93 | - * @var string $_instructions |
|
94 | - */ |
|
95 | - protected $_instructions; |
|
96 | - |
|
97 | - /** |
|
98 | - * $_valid_data - the normalized and validated data for this step |
|
99 | - * |
|
100 | - * @access public |
|
101 | - * @var array $_valid_data |
|
102 | - */ |
|
103 | - protected $_valid_data = []; |
|
104 | - |
|
105 | - /** |
|
106 | - * $reg_form - the registration form for this step |
|
107 | - * |
|
108 | - * @access public |
|
109 | - * @var EE_Form_Section_Proper $reg_form |
|
110 | - */ |
|
111 | - public $reg_form; |
|
112 | - |
|
113 | - /** |
|
114 | - * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
115 | - * |
|
116 | - * @access public |
|
117 | - * @var EE_Checkout $checkout |
|
118 | - */ |
|
119 | - public $checkout; |
|
120 | - |
|
121 | - /** |
|
122 | - * @var RequestInterface $request |
|
123 | - */ |
|
124 | - protected $request; |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @return void |
|
129 | - */ |
|
130 | - abstract public function translate_js_strings(); |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * @return void |
|
135 | - */ |
|
136 | - abstract public function enqueue_styles_and_scripts(); |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @return boolean |
|
141 | - */ |
|
142 | - abstract public function initialize_reg_step(); |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @return EE_Form_Section_Proper |
|
147 | - */ |
|
148 | - abstract public function generate_reg_form(); |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @return boolean |
|
153 | - */ |
|
154 | - abstract public function process_reg_step(); |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * @return boolean |
|
159 | - */ |
|
160 | - abstract public function update_reg_step(); |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * @return boolean |
|
165 | - */ |
|
166 | - public function completed() |
|
167 | - { |
|
168 | - return $this->_completed; |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * set_completed - toggles $_completed to TRUE |
|
174 | - */ |
|
175 | - public function set_completed() |
|
176 | - { |
|
177 | - // DEBUG LOG |
|
178 | - // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
179 | - $this->_completed = apply_filters('FHEE__EE_SPCO_Reg_Step__set_completed___completed', true, $this); |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * set_completed - toggles $_completed to FALSE |
|
185 | - */ |
|
186 | - public function set_not_completed() |
|
187 | - { |
|
188 | - $this->_completed = false; |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * @return string |
|
194 | - */ |
|
195 | - public function name() |
|
196 | - { |
|
197 | - return $this->_name; |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * @return string |
|
203 | - */ |
|
204 | - public function slug() |
|
205 | - { |
|
206 | - return $this->_slug; |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * submit_button_text |
|
212 | - * the text that appears on the reg step form submit button |
|
213 | - * |
|
214 | - * @return string |
|
215 | - */ |
|
216 | - public function submit_button_text() |
|
217 | - { |
|
218 | - return $this->_submit_button_text; |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * set_submit_button_text |
|
224 | - * sets the text that appears on the reg step form submit button |
|
225 | - * |
|
226 | - * @param string $submit_button_text |
|
227 | - */ |
|
228 | - public function set_submit_button_text($submit_button_text = '') |
|
229 | - { |
|
230 | - if (! empty($submit_button_text)) { |
|
231 | - $this->_submit_button_text = $submit_button_text; |
|
232 | - } elseif ($this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
233 | - if ($this->checkout->revisit) { |
|
234 | - $this->_submit_button_text = sprintf( |
|
235 | - esc_html__('Update %s', 'event_espresso'), |
|
236 | - $this->checkout->current_step->name() |
|
237 | - ); |
|
238 | - } else { |
|
239 | - $this->_submit_button_text = sprintf( |
|
240 | - esc_html__('Proceed to %s', 'event_espresso'), |
|
241 | - $this->checkout->next_step->name() |
|
242 | - ); |
|
243 | - } |
|
244 | - } |
|
245 | - // filters the submit button text |
|
246 | - $this->_submit_button_text = apply_filters( |
|
247 | - 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', |
|
248 | - $this->_submit_button_text, |
|
249 | - $this->checkout |
|
250 | - ); |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * @param boolean $is_current_step |
|
256 | - */ |
|
257 | - public function set_is_current_step($is_current_step) |
|
258 | - { |
|
259 | - $this->_is_current_step = $is_current_step; |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * @return boolean |
|
265 | - */ |
|
266 | - public function is_current_step() |
|
267 | - { |
|
268 | - return $this->_is_current_step; |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * @return boolean |
|
274 | - */ |
|
275 | - public function is_final_step() |
|
276 | - { |
|
277 | - return $this instanceof EE_SPCO_Reg_Step_Finalize_Registration; |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * @param int $order |
|
283 | - */ |
|
284 | - public function set_order($order) |
|
285 | - { |
|
286 | - $this->_order = $order; |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * @return int |
|
292 | - */ |
|
293 | - public function order() |
|
294 | - { |
|
295 | - return $this->_order; |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * @return string |
|
301 | - */ |
|
302 | - public function template(): string |
|
303 | - { |
|
304 | - return $this->_template; |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * @param string $template |
|
310 | - */ |
|
311 | - public function setTemplate(string $template): void |
|
312 | - { |
|
313 | - $this->_template = $template; |
|
314 | - } |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * @return string |
|
319 | - */ |
|
320 | - public function success_message() |
|
321 | - { |
|
322 | - return $this->_success_message; |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * _set_success_message |
|
328 | - * |
|
329 | - * @param string $success_message |
|
330 | - */ |
|
331 | - protected function _set_success_message($success_message) |
|
332 | - { |
|
333 | - $this->_success_message = $success_message; |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * _reset_success_message |
|
339 | - * |
|
340 | - * @return void |
|
341 | - */ |
|
342 | - protected function _reset_success_message() |
|
343 | - { |
|
344 | - $this->_success_message = ''; |
|
345 | - } |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * @return string |
|
350 | - */ |
|
351 | - public function _instructions() |
|
352 | - { |
|
353 | - return $this->_instructions; |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - /** |
|
358 | - * @param string $instructions |
|
359 | - */ |
|
360 | - public function set_instructions($instructions) |
|
361 | - { |
|
362 | - $this->_instructions = apply_filters( |
|
363 | - 'FHEE__EE_SPCO_Reg_Step__set_instructions__instructions', |
|
364 | - $instructions, |
|
365 | - $this |
|
366 | - ); |
|
367 | - } |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * @param array $valid_data |
|
372 | - */ |
|
373 | - public function set_valid_data($valid_data) |
|
374 | - { |
|
375 | - $this->_valid_data = $valid_data; |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * @return array |
|
381 | - * @throws EE_Error |
|
382 | - * @throws EE_Error |
|
383 | - */ |
|
384 | - public function valid_data() |
|
385 | - { |
|
386 | - if (empty($this->_valid_data)) { |
|
387 | - $this->_valid_data = $this->reg_form->valid_data(); |
|
388 | - } |
|
389 | - return $this->_valid_data; |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - /** |
|
394 | - * @return string |
|
395 | - */ |
|
396 | - public function reg_form_name() |
|
397 | - { |
|
398 | - if (empty($this->_reg_form_name)) { |
|
399 | - $this->set_reg_form_name('ee-spco-' . $this->slug() . '-reg-step-form'); |
|
400 | - } |
|
401 | - return $this->_reg_form_name; |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * @param string $reg_form_name |
|
407 | - */ |
|
408 | - protected function set_reg_form_name($reg_form_name) |
|
409 | - { |
|
410 | - $this->_reg_form_name = $reg_form_name; |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * reg_step_url |
|
416 | - * |
|
417 | - * @param string $action |
|
418 | - * @return string |
|
419 | - */ |
|
420 | - public function reg_step_url($action = '') |
|
421 | - { |
|
422 | - $query_args = ['step' => $this->slug()]; |
|
423 | - if (! empty($action)) { |
|
424 | - $query_args['action'] = $action; |
|
425 | - } |
|
426 | - // final step has no display |
|
427 | - if ($this instanceof EE_SPCO_Reg_Step_Finalize_Registration && $action === 'display_spco_reg_step') { |
|
428 | - $query_args['action'] = 'process_reg_step'; |
|
429 | - } |
|
430 | - if ($this->checkout->revisit) { |
|
431 | - $query_args['revisit'] = true; |
|
432 | - } |
|
433 | - if ($this->checkout->reg_url_link) { |
|
434 | - $query_args['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
435 | - } |
|
436 | - return add_query_arg($query_args, $this->checkout->reg_page_base_url); |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - /** |
|
441 | - * creates the default hidden inputs section |
|
442 | - * |
|
443 | - * @return EE_Form_Section_Proper |
|
444 | - * @throws EE_Error |
|
445 | - */ |
|
446 | - public function reg_step_hidden_inputs() |
|
447 | - { |
|
448 | - // hidden inputs for admin registrations |
|
449 | - if ($this->checkout->admin_request) { |
|
450 | - return new EE_Form_Section_Proper( |
|
451 | - [ |
|
452 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
453 | - 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
454 | - 'subsections' => [ |
|
455 | - 'next_step' => new EE_Fixed_Hidden_Input( |
|
456 | - [ |
|
457 | - 'html_name' => 'next_step', |
|
458 | - 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
459 | - 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
460 | - ? $this->checkout->next_step->slug() |
|
461 | - : '', |
|
462 | - ] |
|
463 | - ), |
|
464 | - ], |
|
465 | - ] |
|
466 | - ); |
|
467 | - } |
|
468 | - // hidden inputs for frontend registrations |
|
469 | - return new EE_Form_Section_Proper( |
|
470 | - [ |
|
471 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
472 | - 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
473 | - 'subsections' => [ |
|
474 | - 'action' => new EE_Fixed_Hidden_Input( |
|
475 | - [ |
|
476 | - 'html_name' => 'action', |
|
477 | - 'html_id' => 'spco-' . $this->slug() . '-action', |
|
478 | - 'default' => apply_filters( |
|
479 | - 'FHEE__EE_SPCO_Reg_Step__reg_step_hidden_inputs__default_form_action', |
|
480 | - empty($this->checkout->reg_url_link) |
|
481 | - ? 'process_reg_step' |
|
482 | - : 'update_reg_step', |
|
483 | - $this |
|
484 | - ), |
|
485 | - ] |
|
486 | - ), |
|
487 | - 'next_step' => new EE_Fixed_Hidden_Input( |
|
488 | - [ |
|
489 | - 'html_name' => 'next_step', |
|
490 | - 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
491 | - 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
492 | - ? $this->checkout->next_step->slug() |
|
493 | - : '', |
|
494 | - ] |
|
495 | - ), |
|
496 | - 'e_reg_url_link' => new EE_Fixed_Hidden_Input( |
|
497 | - [ |
|
498 | - 'html_name' => 'e_reg_url_link', |
|
499 | - 'html_id' => 'spco-reg_url_link', |
|
500 | - 'default' => $this->checkout->reg_url_link, |
|
501 | - ] |
|
502 | - ), |
|
503 | - 'revisit' => new EE_Fixed_Hidden_Input( |
|
504 | - [ |
|
505 | - 'html_name' => 'revisit', |
|
506 | - 'html_id' => 'spco-revisit', |
|
507 | - 'default' => $this->checkout->revisit, |
|
508 | - ] |
|
509 | - ), |
|
510 | - ], |
|
511 | - ] |
|
512 | - ); |
|
513 | - } |
|
514 | - |
|
515 | - |
|
516 | - /** |
|
517 | - * generate_reg_form_for_actions |
|
518 | - * |
|
519 | - * @param array $actions |
|
520 | - * @return void |
|
521 | - */ |
|
522 | - public function generate_reg_form_for_actions($actions = []) |
|
523 | - { |
|
524 | - $actions = array_merge( |
|
525 | - [ |
|
526 | - 'generate_reg_form', |
|
527 | - 'display_spco_reg_step', |
|
528 | - 'process_reg_step', |
|
529 | - 'update_reg_step', |
|
530 | - ], |
|
531 | - $actions |
|
532 | - ); |
|
533 | - $this->checkout->generate_reg_form = in_array($this->checkout->action, $actions, true); |
|
534 | - } |
|
535 | - |
|
536 | - |
|
537 | - /** |
|
538 | - * @return string |
|
539 | - * @throws EE_Error |
|
540 | - */ |
|
541 | - public function display_reg_form() |
|
542 | - { |
|
543 | - $html = ''; |
|
544 | - if ($this->reg_form instanceof EE_Form_Section_Proper) { |
|
545 | - do_action('AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', $this->reg_form, $this); |
|
546 | - $html .= ! $this->checkout->admin_request ? $this->reg_form->form_open($this->reg_step_url()) : ''; |
|
547 | - if ($this->request->isAjax()) { |
|
548 | - $this->reg_form->localize_validation_rules(); |
|
549 | - $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
550 | - } |
|
551 | - $html .= $this->reg_form->get_html(); |
|
552 | - $html .= ! $this->checkout->admin_request ? $this->reg_step_submit_button() : ''; |
|
553 | - $html .= ! $this->checkout->admin_request ? $this->reg_form->form_close() : ''; |
|
554 | - } |
|
555 | - return $html; |
|
556 | - } |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * div_class - returns nothing for current step, but a css class of "hidden" for others |
|
561 | - * |
|
562 | - * @return string |
|
563 | - * @throws EE_Error |
|
564 | - */ |
|
565 | - public function reg_step_submit_button() |
|
566 | - { |
|
567 | - if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
568 | - return ''; |
|
569 | - } |
|
570 | - ob_start(); |
|
571 | - do_action( |
|
572 | - 'AHEE__before_spco_whats_next_buttons', |
|
573 | - $this->slug(), |
|
574 | - $this->checkout->next_step->slug(), |
|
575 | - $this->checkout |
|
576 | - ); |
|
577 | - $html = ob_get_clean(); |
|
578 | - // generate submit button |
|
579 | - $submit_btn = new EE_Submit_Input( |
|
580 | - [ |
|
581 | - 'html_name' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
582 | - 'html_id' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
583 | - 'html_class' => 'spco-next-step-btn', |
|
584 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
585 | - 'default' => $this->submit_button_text(), |
|
586 | - ] |
|
587 | - ); |
|
588 | - $submit_btn->set_button_css_attributes(true, 'large'); |
|
589 | - $submit_btn_html = $submit_btn->get_html_for_input(); |
|
590 | - $html .= EEH_HTML::div( |
|
591 | - apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $submit_btn_html, $this), |
|
592 | - 'spco-' . $this->slug() . '-whats-next-buttons-dv', |
|
593 | - 'spco-whats-next-buttons' |
|
594 | - ); |
|
595 | - return $html; |
|
596 | - } |
|
597 | - |
|
598 | - |
|
599 | - /** |
|
600 | - * div_class - returns nothing for current step, but a css class of "hidden" for others |
|
601 | - * |
|
602 | - * @return string |
|
603 | - */ |
|
604 | - public function div_class() |
|
605 | - { |
|
606 | - return $this->is_current_step() ? '' : ' hidden'; |
|
607 | - } |
|
608 | - |
|
609 | - |
|
610 | - /** |
|
611 | - * div_class - returns a css class of "hidden" for current step, but nothing for others |
|
612 | - * |
|
613 | - * @return string |
|
614 | - */ |
|
615 | - public function edit_lnk_url() |
|
616 | - { |
|
617 | - return add_query_arg(['step' => $this->slug()], $this->checkout->reg_page_base_url); |
|
618 | - } |
|
619 | - |
|
620 | - |
|
621 | - /** |
|
622 | - * div_class - returns a css class of "hidden" for current step, but nothing for others |
|
623 | - * |
|
624 | - * @return string |
|
625 | - */ |
|
626 | - public function edit_link_class() |
|
627 | - { |
|
628 | - return $this->is_current_step() ? ' hidden' : ''; |
|
629 | - } |
|
630 | - |
|
631 | - |
|
632 | - /** |
|
633 | - * update_checkout with changes that have been made to the cart |
|
634 | - * |
|
635 | - * @return void |
|
636 | - * @throws EE_Error |
|
637 | - * @throws ReflectionException |
|
638 | - */ |
|
639 | - public function update_checkout() |
|
640 | - { |
|
641 | - // grab the cart grand total and reset TXN total |
|
642 | - $this->checkout->transaction->set_total($this->checkout->cart->get_cart_grand_total()); |
|
643 | - $this->checkout->stash_transaction_and_checkout(); |
|
644 | - } |
|
645 | - |
|
646 | - |
|
647 | - /** |
|
648 | - * __sleep |
|
649 | - * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
650 | - * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
651 | - * reg form, because if needed, it will be regenerated anyways |
|
652 | - * |
|
653 | - * @return array |
|
654 | - */ |
|
655 | - public function __sleep() |
|
656 | - { |
|
657 | - // remove the reg form and the checkout |
|
658 | - return array_diff(array_keys(get_object_vars($this)), ['reg_form', 'checkout']); |
|
659 | - } |
|
660 | - |
|
661 | - |
|
662 | - /** |
|
663 | - * @param RequestInterface $request |
|
664 | - */ |
|
665 | - public function setRequest(RequestInterface $request) |
|
666 | - { |
|
667 | - $this->request = $request; |
|
668 | - } |
|
16 | + /** |
|
17 | + * $_completed - TRUE if this step has fully completed it's duties |
|
18 | + * |
|
19 | + * @access protected |
|
20 | + * @type bool $_completed |
|
21 | + */ |
|
22 | + protected $_completed = false; |
|
23 | + |
|
24 | + /** |
|
25 | + * $_is_current_step - TRUE if this is the current step |
|
26 | + * |
|
27 | + * @access protected |
|
28 | + * @type bool $_is_current_step |
|
29 | + */ |
|
30 | + protected $_is_current_step = false; |
|
31 | + |
|
32 | + /** |
|
33 | + * $_order - when the reg step should be run relative to other steps |
|
34 | + * |
|
35 | + * @access protected |
|
36 | + * @type int $_template |
|
37 | + */ |
|
38 | + protected $_order = 0; |
|
39 | + |
|
40 | + /** |
|
41 | + * $_slug - URL param for this step |
|
42 | + * |
|
43 | + * @access protected |
|
44 | + * @type string $_slug |
|
45 | + */ |
|
46 | + protected $_slug; |
|
47 | + |
|
48 | + /** |
|
49 | + * $_name - Step Name - translatable string |
|
50 | + * |
|
51 | + * @access protected |
|
52 | + * @type string $_slug |
|
53 | + */ |
|
54 | + protected $_name; |
|
55 | + |
|
56 | + /** |
|
57 | + * $_submit_button_text - translatable string that appears on this step's submit button |
|
58 | + * |
|
59 | + * @access protected |
|
60 | + * @type string $_slug |
|
61 | + */ |
|
62 | + protected $_submit_button_text; |
|
63 | + |
|
64 | + /** |
|
65 | + * $_template - template name |
|
66 | + * |
|
67 | + * @access protected |
|
68 | + * @type string $_template |
|
69 | + */ |
|
70 | + protected $_template; |
|
71 | + |
|
72 | + /** |
|
73 | + * $_reg_form_name - the form input name and id attribute |
|
74 | + * |
|
75 | + * @access protected |
|
76 | + * @var string $_reg_form_name |
|
77 | + */ |
|
78 | + protected $_reg_form_name; |
|
79 | + |
|
80 | + /** |
|
81 | + * $_success_message - text to display upon successful form submission |
|
82 | + * |
|
83 | + * @access private |
|
84 | + * @var string $_success_message |
|
85 | + */ |
|
86 | + protected $_success_message; |
|
87 | + |
|
88 | + /** |
|
89 | + * $_instructions - a brief description of how to complete the reg step. |
|
90 | + * Usually displayed in conjunction with the previous step's success message. |
|
91 | + * |
|
92 | + * @access private |
|
93 | + * @var string $_instructions |
|
94 | + */ |
|
95 | + protected $_instructions; |
|
96 | + |
|
97 | + /** |
|
98 | + * $_valid_data - the normalized and validated data for this step |
|
99 | + * |
|
100 | + * @access public |
|
101 | + * @var array $_valid_data |
|
102 | + */ |
|
103 | + protected $_valid_data = []; |
|
104 | + |
|
105 | + /** |
|
106 | + * $reg_form - the registration form for this step |
|
107 | + * |
|
108 | + * @access public |
|
109 | + * @var EE_Form_Section_Proper $reg_form |
|
110 | + */ |
|
111 | + public $reg_form; |
|
112 | + |
|
113 | + /** |
|
114 | + * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
115 | + * |
|
116 | + * @access public |
|
117 | + * @var EE_Checkout $checkout |
|
118 | + */ |
|
119 | + public $checkout; |
|
120 | + |
|
121 | + /** |
|
122 | + * @var RequestInterface $request |
|
123 | + */ |
|
124 | + protected $request; |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @return void |
|
129 | + */ |
|
130 | + abstract public function translate_js_strings(); |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * @return void |
|
135 | + */ |
|
136 | + abstract public function enqueue_styles_and_scripts(); |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @return boolean |
|
141 | + */ |
|
142 | + abstract public function initialize_reg_step(); |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @return EE_Form_Section_Proper |
|
147 | + */ |
|
148 | + abstract public function generate_reg_form(); |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @return boolean |
|
153 | + */ |
|
154 | + abstract public function process_reg_step(); |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * @return boolean |
|
159 | + */ |
|
160 | + abstract public function update_reg_step(); |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * @return boolean |
|
165 | + */ |
|
166 | + public function completed() |
|
167 | + { |
|
168 | + return $this->_completed; |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * set_completed - toggles $_completed to TRUE |
|
174 | + */ |
|
175 | + public function set_completed() |
|
176 | + { |
|
177 | + // DEBUG LOG |
|
178 | + // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
179 | + $this->_completed = apply_filters('FHEE__EE_SPCO_Reg_Step__set_completed___completed', true, $this); |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * set_completed - toggles $_completed to FALSE |
|
185 | + */ |
|
186 | + public function set_not_completed() |
|
187 | + { |
|
188 | + $this->_completed = false; |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * @return string |
|
194 | + */ |
|
195 | + public function name() |
|
196 | + { |
|
197 | + return $this->_name; |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * @return string |
|
203 | + */ |
|
204 | + public function slug() |
|
205 | + { |
|
206 | + return $this->_slug; |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * submit_button_text |
|
212 | + * the text that appears on the reg step form submit button |
|
213 | + * |
|
214 | + * @return string |
|
215 | + */ |
|
216 | + public function submit_button_text() |
|
217 | + { |
|
218 | + return $this->_submit_button_text; |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * set_submit_button_text |
|
224 | + * sets the text that appears on the reg step form submit button |
|
225 | + * |
|
226 | + * @param string $submit_button_text |
|
227 | + */ |
|
228 | + public function set_submit_button_text($submit_button_text = '') |
|
229 | + { |
|
230 | + if (! empty($submit_button_text)) { |
|
231 | + $this->_submit_button_text = $submit_button_text; |
|
232 | + } elseif ($this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
233 | + if ($this->checkout->revisit) { |
|
234 | + $this->_submit_button_text = sprintf( |
|
235 | + esc_html__('Update %s', 'event_espresso'), |
|
236 | + $this->checkout->current_step->name() |
|
237 | + ); |
|
238 | + } else { |
|
239 | + $this->_submit_button_text = sprintf( |
|
240 | + esc_html__('Proceed to %s', 'event_espresso'), |
|
241 | + $this->checkout->next_step->name() |
|
242 | + ); |
|
243 | + } |
|
244 | + } |
|
245 | + // filters the submit button text |
|
246 | + $this->_submit_button_text = apply_filters( |
|
247 | + 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', |
|
248 | + $this->_submit_button_text, |
|
249 | + $this->checkout |
|
250 | + ); |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * @param boolean $is_current_step |
|
256 | + */ |
|
257 | + public function set_is_current_step($is_current_step) |
|
258 | + { |
|
259 | + $this->_is_current_step = $is_current_step; |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * @return boolean |
|
265 | + */ |
|
266 | + public function is_current_step() |
|
267 | + { |
|
268 | + return $this->_is_current_step; |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * @return boolean |
|
274 | + */ |
|
275 | + public function is_final_step() |
|
276 | + { |
|
277 | + return $this instanceof EE_SPCO_Reg_Step_Finalize_Registration; |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * @param int $order |
|
283 | + */ |
|
284 | + public function set_order($order) |
|
285 | + { |
|
286 | + $this->_order = $order; |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * @return int |
|
292 | + */ |
|
293 | + public function order() |
|
294 | + { |
|
295 | + return $this->_order; |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * @return string |
|
301 | + */ |
|
302 | + public function template(): string |
|
303 | + { |
|
304 | + return $this->_template; |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * @param string $template |
|
310 | + */ |
|
311 | + public function setTemplate(string $template): void |
|
312 | + { |
|
313 | + $this->_template = $template; |
|
314 | + } |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * @return string |
|
319 | + */ |
|
320 | + public function success_message() |
|
321 | + { |
|
322 | + return $this->_success_message; |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * _set_success_message |
|
328 | + * |
|
329 | + * @param string $success_message |
|
330 | + */ |
|
331 | + protected function _set_success_message($success_message) |
|
332 | + { |
|
333 | + $this->_success_message = $success_message; |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * _reset_success_message |
|
339 | + * |
|
340 | + * @return void |
|
341 | + */ |
|
342 | + protected function _reset_success_message() |
|
343 | + { |
|
344 | + $this->_success_message = ''; |
|
345 | + } |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * @return string |
|
350 | + */ |
|
351 | + public function _instructions() |
|
352 | + { |
|
353 | + return $this->_instructions; |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + /** |
|
358 | + * @param string $instructions |
|
359 | + */ |
|
360 | + public function set_instructions($instructions) |
|
361 | + { |
|
362 | + $this->_instructions = apply_filters( |
|
363 | + 'FHEE__EE_SPCO_Reg_Step__set_instructions__instructions', |
|
364 | + $instructions, |
|
365 | + $this |
|
366 | + ); |
|
367 | + } |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * @param array $valid_data |
|
372 | + */ |
|
373 | + public function set_valid_data($valid_data) |
|
374 | + { |
|
375 | + $this->_valid_data = $valid_data; |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * @return array |
|
381 | + * @throws EE_Error |
|
382 | + * @throws EE_Error |
|
383 | + */ |
|
384 | + public function valid_data() |
|
385 | + { |
|
386 | + if (empty($this->_valid_data)) { |
|
387 | + $this->_valid_data = $this->reg_form->valid_data(); |
|
388 | + } |
|
389 | + return $this->_valid_data; |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + /** |
|
394 | + * @return string |
|
395 | + */ |
|
396 | + public function reg_form_name() |
|
397 | + { |
|
398 | + if (empty($this->_reg_form_name)) { |
|
399 | + $this->set_reg_form_name('ee-spco-' . $this->slug() . '-reg-step-form'); |
|
400 | + } |
|
401 | + return $this->_reg_form_name; |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * @param string $reg_form_name |
|
407 | + */ |
|
408 | + protected function set_reg_form_name($reg_form_name) |
|
409 | + { |
|
410 | + $this->_reg_form_name = $reg_form_name; |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * reg_step_url |
|
416 | + * |
|
417 | + * @param string $action |
|
418 | + * @return string |
|
419 | + */ |
|
420 | + public function reg_step_url($action = '') |
|
421 | + { |
|
422 | + $query_args = ['step' => $this->slug()]; |
|
423 | + if (! empty($action)) { |
|
424 | + $query_args['action'] = $action; |
|
425 | + } |
|
426 | + // final step has no display |
|
427 | + if ($this instanceof EE_SPCO_Reg_Step_Finalize_Registration && $action === 'display_spco_reg_step') { |
|
428 | + $query_args['action'] = 'process_reg_step'; |
|
429 | + } |
|
430 | + if ($this->checkout->revisit) { |
|
431 | + $query_args['revisit'] = true; |
|
432 | + } |
|
433 | + if ($this->checkout->reg_url_link) { |
|
434 | + $query_args['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
435 | + } |
|
436 | + return add_query_arg($query_args, $this->checkout->reg_page_base_url); |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + /** |
|
441 | + * creates the default hidden inputs section |
|
442 | + * |
|
443 | + * @return EE_Form_Section_Proper |
|
444 | + * @throws EE_Error |
|
445 | + */ |
|
446 | + public function reg_step_hidden_inputs() |
|
447 | + { |
|
448 | + // hidden inputs for admin registrations |
|
449 | + if ($this->checkout->admin_request) { |
|
450 | + return new EE_Form_Section_Proper( |
|
451 | + [ |
|
452 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
453 | + 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
454 | + 'subsections' => [ |
|
455 | + 'next_step' => new EE_Fixed_Hidden_Input( |
|
456 | + [ |
|
457 | + 'html_name' => 'next_step', |
|
458 | + 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
459 | + 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
460 | + ? $this->checkout->next_step->slug() |
|
461 | + : '', |
|
462 | + ] |
|
463 | + ), |
|
464 | + ], |
|
465 | + ] |
|
466 | + ); |
|
467 | + } |
|
468 | + // hidden inputs for frontend registrations |
|
469 | + return new EE_Form_Section_Proper( |
|
470 | + [ |
|
471 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
472 | + 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
473 | + 'subsections' => [ |
|
474 | + 'action' => new EE_Fixed_Hidden_Input( |
|
475 | + [ |
|
476 | + 'html_name' => 'action', |
|
477 | + 'html_id' => 'spco-' . $this->slug() . '-action', |
|
478 | + 'default' => apply_filters( |
|
479 | + 'FHEE__EE_SPCO_Reg_Step__reg_step_hidden_inputs__default_form_action', |
|
480 | + empty($this->checkout->reg_url_link) |
|
481 | + ? 'process_reg_step' |
|
482 | + : 'update_reg_step', |
|
483 | + $this |
|
484 | + ), |
|
485 | + ] |
|
486 | + ), |
|
487 | + 'next_step' => new EE_Fixed_Hidden_Input( |
|
488 | + [ |
|
489 | + 'html_name' => 'next_step', |
|
490 | + 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
491 | + 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
492 | + ? $this->checkout->next_step->slug() |
|
493 | + : '', |
|
494 | + ] |
|
495 | + ), |
|
496 | + 'e_reg_url_link' => new EE_Fixed_Hidden_Input( |
|
497 | + [ |
|
498 | + 'html_name' => 'e_reg_url_link', |
|
499 | + 'html_id' => 'spco-reg_url_link', |
|
500 | + 'default' => $this->checkout->reg_url_link, |
|
501 | + ] |
|
502 | + ), |
|
503 | + 'revisit' => new EE_Fixed_Hidden_Input( |
|
504 | + [ |
|
505 | + 'html_name' => 'revisit', |
|
506 | + 'html_id' => 'spco-revisit', |
|
507 | + 'default' => $this->checkout->revisit, |
|
508 | + ] |
|
509 | + ), |
|
510 | + ], |
|
511 | + ] |
|
512 | + ); |
|
513 | + } |
|
514 | + |
|
515 | + |
|
516 | + /** |
|
517 | + * generate_reg_form_for_actions |
|
518 | + * |
|
519 | + * @param array $actions |
|
520 | + * @return void |
|
521 | + */ |
|
522 | + public function generate_reg_form_for_actions($actions = []) |
|
523 | + { |
|
524 | + $actions = array_merge( |
|
525 | + [ |
|
526 | + 'generate_reg_form', |
|
527 | + 'display_spco_reg_step', |
|
528 | + 'process_reg_step', |
|
529 | + 'update_reg_step', |
|
530 | + ], |
|
531 | + $actions |
|
532 | + ); |
|
533 | + $this->checkout->generate_reg_form = in_array($this->checkout->action, $actions, true); |
|
534 | + } |
|
535 | + |
|
536 | + |
|
537 | + /** |
|
538 | + * @return string |
|
539 | + * @throws EE_Error |
|
540 | + */ |
|
541 | + public function display_reg_form() |
|
542 | + { |
|
543 | + $html = ''; |
|
544 | + if ($this->reg_form instanceof EE_Form_Section_Proper) { |
|
545 | + do_action('AHEE__EE_SPCO_Reg_Step__display_reg_form__reg_form', $this->reg_form, $this); |
|
546 | + $html .= ! $this->checkout->admin_request ? $this->reg_form->form_open($this->reg_step_url()) : ''; |
|
547 | + if ($this->request->isAjax()) { |
|
548 | + $this->reg_form->localize_validation_rules(); |
|
549 | + $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
550 | + } |
|
551 | + $html .= $this->reg_form->get_html(); |
|
552 | + $html .= ! $this->checkout->admin_request ? $this->reg_step_submit_button() : ''; |
|
553 | + $html .= ! $this->checkout->admin_request ? $this->reg_form->form_close() : ''; |
|
554 | + } |
|
555 | + return $html; |
|
556 | + } |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * div_class - returns nothing for current step, but a css class of "hidden" for others |
|
561 | + * |
|
562 | + * @return string |
|
563 | + * @throws EE_Error |
|
564 | + */ |
|
565 | + public function reg_step_submit_button() |
|
566 | + { |
|
567 | + if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
568 | + return ''; |
|
569 | + } |
|
570 | + ob_start(); |
|
571 | + do_action( |
|
572 | + 'AHEE__before_spco_whats_next_buttons', |
|
573 | + $this->slug(), |
|
574 | + $this->checkout->next_step->slug(), |
|
575 | + $this->checkout |
|
576 | + ); |
|
577 | + $html = ob_get_clean(); |
|
578 | + // generate submit button |
|
579 | + $submit_btn = new EE_Submit_Input( |
|
580 | + [ |
|
581 | + 'html_name' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
582 | + 'html_id' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
583 | + 'html_class' => 'spco-next-step-btn', |
|
584 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
585 | + 'default' => $this->submit_button_text(), |
|
586 | + ] |
|
587 | + ); |
|
588 | + $submit_btn->set_button_css_attributes(true, 'large'); |
|
589 | + $submit_btn_html = $submit_btn->get_html_for_input(); |
|
590 | + $html .= EEH_HTML::div( |
|
591 | + apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $submit_btn_html, $this), |
|
592 | + 'spco-' . $this->slug() . '-whats-next-buttons-dv', |
|
593 | + 'spco-whats-next-buttons' |
|
594 | + ); |
|
595 | + return $html; |
|
596 | + } |
|
597 | + |
|
598 | + |
|
599 | + /** |
|
600 | + * div_class - returns nothing for current step, but a css class of "hidden" for others |
|
601 | + * |
|
602 | + * @return string |
|
603 | + */ |
|
604 | + public function div_class() |
|
605 | + { |
|
606 | + return $this->is_current_step() ? '' : ' hidden'; |
|
607 | + } |
|
608 | + |
|
609 | + |
|
610 | + /** |
|
611 | + * div_class - returns a css class of "hidden" for current step, but nothing for others |
|
612 | + * |
|
613 | + * @return string |
|
614 | + */ |
|
615 | + public function edit_lnk_url() |
|
616 | + { |
|
617 | + return add_query_arg(['step' => $this->slug()], $this->checkout->reg_page_base_url); |
|
618 | + } |
|
619 | + |
|
620 | + |
|
621 | + /** |
|
622 | + * div_class - returns a css class of "hidden" for current step, but nothing for others |
|
623 | + * |
|
624 | + * @return string |
|
625 | + */ |
|
626 | + public function edit_link_class() |
|
627 | + { |
|
628 | + return $this->is_current_step() ? ' hidden' : ''; |
|
629 | + } |
|
630 | + |
|
631 | + |
|
632 | + /** |
|
633 | + * update_checkout with changes that have been made to the cart |
|
634 | + * |
|
635 | + * @return void |
|
636 | + * @throws EE_Error |
|
637 | + * @throws ReflectionException |
|
638 | + */ |
|
639 | + public function update_checkout() |
|
640 | + { |
|
641 | + // grab the cart grand total and reset TXN total |
|
642 | + $this->checkout->transaction->set_total($this->checkout->cart->get_cart_grand_total()); |
|
643 | + $this->checkout->stash_transaction_and_checkout(); |
|
644 | + } |
|
645 | + |
|
646 | + |
|
647 | + /** |
|
648 | + * __sleep |
|
649 | + * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
650 | + * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
651 | + * reg form, because if needed, it will be regenerated anyways |
|
652 | + * |
|
653 | + * @return array |
|
654 | + */ |
|
655 | + public function __sleep() |
|
656 | + { |
|
657 | + // remove the reg form and the checkout |
|
658 | + return array_diff(array_keys(get_object_vars($this)), ['reg_form', 'checkout']); |
|
659 | + } |
|
660 | + |
|
661 | + |
|
662 | + /** |
|
663 | + * @param RequestInterface $request |
|
664 | + */ |
|
665 | + public function setRequest(RequestInterface $request) |
|
666 | + { |
|
667 | + $this->request = $request; |
|
668 | + } |
|
669 | 669 | } |
@@ -40,279 +40,279 @@ |
||
40 | 40 | */ |
41 | 41 | class FilesDataHandler |
42 | 42 | { |
43 | - /** |
|
44 | - * @var Request |
|
45 | - */ |
|
46 | - protected $request; |
|
43 | + /** |
|
44 | + * @var Request |
|
45 | + */ |
|
46 | + protected $request; |
|
47 | 47 | |
48 | - /** |
|
49 | - * @var CollectionInterface | FileSubmissionInterface[] |
|
50 | - */ |
|
51 | - protected $file_objects; |
|
48 | + /** |
|
49 | + * @var CollectionInterface | FileSubmissionInterface[] |
|
50 | + */ |
|
51 | + protected $file_objects; |
|
52 | 52 | |
53 | - /** |
|
54 | - * @var bool |
|
55 | - */ |
|
56 | - protected $initialized = false; |
|
53 | + /** |
|
54 | + * @var bool |
|
55 | + */ |
|
56 | + protected $initialized = false; |
|
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * FilesDataHandler constructor. |
|
61 | - * |
|
62 | - * @param Request $request |
|
63 | - */ |
|
64 | - public function __construct(Request $request) |
|
65 | - { |
|
66 | - $this->request = $request; |
|
67 | - } |
|
59 | + /** |
|
60 | + * FilesDataHandler constructor. |
|
61 | + * |
|
62 | + * @param Request $request |
|
63 | + */ |
|
64 | + public function __construct(Request $request) |
|
65 | + { |
|
66 | + $this->request = $request; |
|
67 | + } |
|
68 | 68 | |
69 | 69 | |
70 | - /** |
|
71 | - * @return CollectionInterface | FileSubmissionInterface[] |
|
72 | - * @throws UnexpectedValueException |
|
73 | - * @throws InvalidArgumentException |
|
74 | - * @since 4.9.80.p |
|
75 | - */ |
|
76 | - protected function getFileObjects() |
|
77 | - { |
|
78 | - $this->initialize(); |
|
79 | - return $this->file_objects; |
|
80 | - } |
|
70 | + /** |
|
71 | + * @return CollectionInterface | FileSubmissionInterface[] |
|
72 | + * @throws UnexpectedValueException |
|
73 | + * @throws InvalidArgumentException |
|
74 | + * @since 4.9.80.p |
|
75 | + */ |
|
76 | + protected function getFileObjects() |
|
77 | + { |
|
78 | + $this->initialize(); |
|
79 | + return $this->file_objects; |
|
80 | + } |
|
81 | 81 | |
82 | 82 | |
83 | - /** |
|
84 | - * Sets up the file objects from the request's $_FILES data. |
|
85 | - * |
|
86 | - * @throws UnexpectedValueException |
|
87 | - * @throws InvalidArgumentException |
|
88 | - * @throws InvalidInterfaceException |
|
89 | - * @since 4.9.80.p |
|
90 | - */ |
|
91 | - protected function initialize() |
|
92 | - { |
|
93 | - if ($this->initialized) { |
|
94 | - return; |
|
95 | - } |
|
96 | - $this->file_objects = new Collection( |
|
97 | - // collection interface |
|
98 | - 'EventEspresso\core\services\request\files\FileSubmissionInterface', |
|
99 | - // collection name |
|
100 | - 'submitted_files' |
|
101 | - ); |
|
102 | - $files_raw_data = $this->request->filesParams(); |
|
103 | - if (empty($files_raw_data)) { |
|
104 | - return; |
|
105 | - } |
|
106 | - if ($this->isStrangeFilesArray($files_raw_data)) { |
|
107 | - $data = $this->fixFilesDataArray($files_raw_data); |
|
108 | - } else { |
|
109 | - $data = $files_raw_data; |
|
110 | - } |
|
111 | - $this->createFileObjects($data); |
|
112 | - $this->initialized = true; |
|
113 | - } |
|
83 | + /** |
|
84 | + * Sets up the file objects from the request's $_FILES data. |
|
85 | + * |
|
86 | + * @throws UnexpectedValueException |
|
87 | + * @throws InvalidArgumentException |
|
88 | + * @throws InvalidInterfaceException |
|
89 | + * @since 4.9.80.p |
|
90 | + */ |
|
91 | + protected function initialize() |
|
92 | + { |
|
93 | + if ($this->initialized) { |
|
94 | + return; |
|
95 | + } |
|
96 | + $this->file_objects = new Collection( |
|
97 | + // collection interface |
|
98 | + 'EventEspresso\core\services\request\files\FileSubmissionInterface', |
|
99 | + // collection name |
|
100 | + 'submitted_files' |
|
101 | + ); |
|
102 | + $files_raw_data = $this->request->filesParams(); |
|
103 | + if (empty($files_raw_data)) { |
|
104 | + return; |
|
105 | + } |
|
106 | + if ($this->isStrangeFilesArray($files_raw_data)) { |
|
107 | + $data = $this->fixFilesDataArray($files_raw_data); |
|
108 | + } else { |
|
109 | + $data = $files_raw_data; |
|
110 | + } |
|
111 | + $this->createFileObjects($data); |
|
112 | + $this->initialized = true; |
|
113 | + } |
|
114 | 114 | |
115 | 115 | |
116 | - /** |
|
117 | - * Detects if $_FILES is a weird multi-dimensional array that needs fixing or not. |
|
118 | - * |
|
119 | - * @param $files_data |
|
120 | - * @return bool |
|
121 | - * @throws UnexpectedValueException |
|
122 | - * @since 4.9.80.p |
|
123 | - */ |
|
124 | - protected function isStrangeFilesArray($files_data) |
|
125 | - { |
|
126 | - if (! is_array($files_data)) { |
|
127 | - throw new UnexpectedValueException( |
|
128 | - sprintf( |
|
129 | - esc_html__( |
|
130 | - 'Unexpected PHP $_FILES data format. "%1$s" was expected to be an array.', |
|
131 | - 'event_espresso' |
|
132 | - ), |
|
133 | - (string) $files_data |
|
134 | - ) |
|
135 | - ); |
|
136 | - } |
|
137 | - $first_value = reset($files_data); |
|
138 | - if (! is_array($first_value)) { |
|
139 | - throw new UnexpectedValueException( |
|
140 | - sprintf( |
|
141 | - esc_html__( |
|
142 | - 'Unexpected PHP $_FILES data format. "%1$s" was expected to be an array.', |
|
143 | - 'event_espresso' |
|
144 | - ), |
|
145 | - (string) $first_value |
|
146 | - ) |
|
147 | - ); |
|
148 | - } |
|
149 | - $first_sub_array_item = reset($first_value); |
|
150 | - if (is_array($first_sub_array_item)) { |
|
151 | - // not just a 2d array |
|
152 | - return true; |
|
153 | - } |
|
154 | - // yep, just 2d array |
|
155 | - return false; |
|
156 | - } |
|
116 | + /** |
|
117 | + * Detects if $_FILES is a weird multi-dimensional array that needs fixing or not. |
|
118 | + * |
|
119 | + * @param $files_data |
|
120 | + * @return bool |
|
121 | + * @throws UnexpectedValueException |
|
122 | + * @since 4.9.80.p |
|
123 | + */ |
|
124 | + protected function isStrangeFilesArray($files_data) |
|
125 | + { |
|
126 | + if (! is_array($files_data)) { |
|
127 | + throw new UnexpectedValueException( |
|
128 | + sprintf( |
|
129 | + esc_html__( |
|
130 | + 'Unexpected PHP $_FILES data format. "%1$s" was expected to be an array.', |
|
131 | + 'event_espresso' |
|
132 | + ), |
|
133 | + (string) $files_data |
|
134 | + ) |
|
135 | + ); |
|
136 | + } |
|
137 | + $first_value = reset($files_data); |
|
138 | + if (! is_array($first_value)) { |
|
139 | + throw new UnexpectedValueException( |
|
140 | + sprintf( |
|
141 | + esc_html__( |
|
142 | + 'Unexpected PHP $_FILES data format. "%1$s" was expected to be an array.', |
|
143 | + 'event_espresso' |
|
144 | + ), |
|
145 | + (string) $first_value |
|
146 | + ) |
|
147 | + ); |
|
148 | + } |
|
149 | + $first_sub_array_item = reset($first_value); |
|
150 | + if (is_array($first_sub_array_item)) { |
|
151 | + // not just a 2d array |
|
152 | + return true; |
|
153 | + } |
|
154 | + // yep, just 2d array |
|
155 | + return false; |
|
156 | + } |
|
157 | 157 | |
158 | 158 | |
159 | - /** |
|
160 | - * Takes into account that $_FILES does a weird thing when you have hierarchical form names (eg `<input type="file" |
|
161 | - * name="my[hierarchical][form]">`): it leaves the top-level form part alone, but replaces the SECOND part with |
|
162 | - * "name", "size", "tmp_name", etc. So that file's data is located at "my[name][hierarchical][form]", |
|
163 | - * "my[size][hierarchical][form]", "my[tmp_name][hierarchical][form]", etc. It's really weird. |
|
164 | - * |
|
165 | - * @param $files_data |
|
166 | - * @return array |
|
167 | - * @since 4.9.80.p |
|
168 | - */ |
|
169 | - protected function fixFilesDataArray($files_data) |
|
170 | - { |
|
171 | - $sane_files_array = []; |
|
172 | - foreach ($files_data as $top_level_name => $top_level_children) { |
|
173 | - $sub_array = []; |
|
174 | - $sane_files_array[ $top_level_name ] = []; |
|
175 | - foreach ($top_level_children as $file_data_part => $second_level_children) { |
|
176 | - foreach ($second_level_children as $next_level_name => $sub_values) { |
|
177 | - $sub_array[ $next_level_name ] = $this->organizeFilesData($sub_values, $file_data_part); |
|
178 | - } |
|
179 | - $sane_files_array[ $top_level_name ] = array_replace_recursive( |
|
180 | - $sub_array, |
|
181 | - $sane_files_array[ $top_level_name ] |
|
182 | - ); |
|
183 | - } |
|
184 | - } |
|
185 | - return $sane_files_array; |
|
186 | - } |
|
159 | + /** |
|
160 | + * Takes into account that $_FILES does a weird thing when you have hierarchical form names (eg `<input type="file" |
|
161 | + * name="my[hierarchical][form]">`): it leaves the top-level form part alone, but replaces the SECOND part with |
|
162 | + * "name", "size", "tmp_name", etc. So that file's data is located at "my[name][hierarchical][form]", |
|
163 | + * "my[size][hierarchical][form]", "my[tmp_name][hierarchical][form]", etc. It's really weird. |
|
164 | + * |
|
165 | + * @param $files_data |
|
166 | + * @return array |
|
167 | + * @since 4.9.80.p |
|
168 | + */ |
|
169 | + protected function fixFilesDataArray($files_data) |
|
170 | + { |
|
171 | + $sane_files_array = []; |
|
172 | + foreach ($files_data as $top_level_name => $top_level_children) { |
|
173 | + $sub_array = []; |
|
174 | + $sane_files_array[ $top_level_name ] = []; |
|
175 | + foreach ($top_level_children as $file_data_part => $second_level_children) { |
|
176 | + foreach ($second_level_children as $next_level_name => $sub_values) { |
|
177 | + $sub_array[ $next_level_name ] = $this->organizeFilesData($sub_values, $file_data_part); |
|
178 | + } |
|
179 | + $sane_files_array[ $top_level_name ] = array_replace_recursive( |
|
180 | + $sub_array, |
|
181 | + $sane_files_array[ $top_level_name ] |
|
182 | + ); |
|
183 | + } |
|
184 | + } |
|
185 | + return $sane_files_array; |
|
186 | + } |
|
187 | 187 | |
188 | 188 | |
189 | - /** |
|
190 | - * Recursively explores the array until it finds a leaf node, and tacks `$type` as a final index in front of it. |
|
191 | - * |
|
192 | - * @param $data array|string |
|
193 | - * @param $type 'name', 'tmp_name', 'size', or 'error' |
|
194 | - * @return array |
|
195 | - * @since 4.9.80.p |
|
196 | - */ |
|
197 | - protected function organizeFilesData($data, $type) |
|
198 | - { |
|
199 | - if (! is_array($data)) { |
|
200 | - return [ |
|
201 | - $type => $data, |
|
202 | - ]; |
|
203 | - } |
|
204 | - $organized_data = []; |
|
205 | - foreach ($data as $input_name_part => $sub_inputs_or_value) { |
|
206 | - if (is_array($sub_inputs_or_value)) { |
|
207 | - $organized_data[ $input_name_part ] = $this->organizeFilesData($sub_inputs_or_value, $type); |
|
208 | - } else { |
|
209 | - $organized_data[ $input_name_part ][ $type ] = $sub_inputs_or_value; |
|
210 | - } |
|
211 | - } |
|
212 | - return $organized_data; |
|
213 | - } |
|
189 | + /** |
|
190 | + * Recursively explores the array until it finds a leaf node, and tacks `$type` as a final index in front of it. |
|
191 | + * |
|
192 | + * @param $data array|string |
|
193 | + * @param $type 'name', 'tmp_name', 'size', or 'error' |
|
194 | + * @return array |
|
195 | + * @since 4.9.80.p |
|
196 | + */ |
|
197 | + protected function organizeFilesData($data, $type) |
|
198 | + { |
|
199 | + if (! is_array($data)) { |
|
200 | + return [ |
|
201 | + $type => $data, |
|
202 | + ]; |
|
203 | + } |
|
204 | + $organized_data = []; |
|
205 | + foreach ($data as $input_name_part => $sub_inputs_or_value) { |
|
206 | + if (is_array($sub_inputs_or_value)) { |
|
207 | + $organized_data[ $input_name_part ] = $this->organizeFilesData($sub_inputs_or_value, $type); |
|
208 | + } else { |
|
209 | + $organized_data[ $input_name_part ][ $type ] = $sub_inputs_or_value; |
|
210 | + } |
|
211 | + } |
|
212 | + return $organized_data; |
|
213 | + } |
|
214 | 214 | |
215 | 215 | |
216 | - /** |
|
217 | - * Takes the organized $_FILES array (where all file info is located at the same spot as you'd expect an input |
|
218 | - * to be in post data, with all the file's data located side-by-side in an array) and creates a |
|
219 | - * multi-dimensional array of FileSubmissionInterface objects. Stores it in `$this->file_objects`. |
|
220 | - * |
|
221 | - * @param array $organized_files $_FILES but organized like $_POST |
|
222 | - * @param array $name_parts_so_far for multidimensional HTML form names, |
|
223 | - * @throws UnexpectedValueException |
|
224 | - * @throws InvalidArgumentException |
|
225 | - * @since 4.9.80.p |
|
226 | - */ |
|
227 | - protected function createFileObjects($organized_files, $name_parts_so_far = []) |
|
228 | - { |
|
229 | - if (! is_array($organized_files)) { |
|
230 | - throw new UnexpectedValueException( |
|
231 | - sprintf( |
|
232 | - esc_html__( |
|
233 | - 'Unexpected PHP $organized_files data format. "%1$s" was expected to be an array.', |
|
234 | - 'event_espresso' |
|
235 | - ), |
|
236 | - (string) $organized_files |
|
237 | - ) |
|
238 | - ); |
|
239 | - } |
|
240 | - foreach ($organized_files as $key => $value) { |
|
241 | - $this_input_name_parts = $name_parts_so_far; |
|
242 | - array_push( |
|
243 | - $this_input_name_parts, |
|
244 | - $key |
|
245 | - ); |
|
246 | - if (isset($value['name'], $value['tmp_name'], $value['size'])) { |
|
247 | - $html_name = $this->inputNameFromParts($this_input_name_parts); |
|
248 | - $this->file_objects->add( |
|
249 | - new FileSubmission( |
|
250 | - $value['name'], |
|
251 | - $value['tmp_name'], |
|
252 | - $value['size'], |
|
253 | - $value['error'] |
|
254 | - ), |
|
255 | - $html_name |
|
256 | - ); |
|
257 | - } else { |
|
258 | - $this->createFileObjects($value, $this_input_name_parts); |
|
259 | - } |
|
260 | - } |
|
261 | - } |
|
216 | + /** |
|
217 | + * Takes the organized $_FILES array (where all file info is located at the same spot as you'd expect an input |
|
218 | + * to be in post data, with all the file's data located side-by-side in an array) and creates a |
|
219 | + * multi-dimensional array of FileSubmissionInterface objects. Stores it in `$this->file_objects`. |
|
220 | + * |
|
221 | + * @param array $organized_files $_FILES but organized like $_POST |
|
222 | + * @param array $name_parts_so_far for multidimensional HTML form names, |
|
223 | + * @throws UnexpectedValueException |
|
224 | + * @throws InvalidArgumentException |
|
225 | + * @since 4.9.80.p |
|
226 | + */ |
|
227 | + protected function createFileObjects($organized_files, $name_parts_so_far = []) |
|
228 | + { |
|
229 | + if (! is_array($organized_files)) { |
|
230 | + throw new UnexpectedValueException( |
|
231 | + sprintf( |
|
232 | + esc_html__( |
|
233 | + 'Unexpected PHP $organized_files data format. "%1$s" was expected to be an array.', |
|
234 | + 'event_espresso' |
|
235 | + ), |
|
236 | + (string) $organized_files |
|
237 | + ) |
|
238 | + ); |
|
239 | + } |
|
240 | + foreach ($organized_files as $key => $value) { |
|
241 | + $this_input_name_parts = $name_parts_so_far; |
|
242 | + array_push( |
|
243 | + $this_input_name_parts, |
|
244 | + $key |
|
245 | + ); |
|
246 | + if (isset($value['name'], $value['tmp_name'], $value['size'])) { |
|
247 | + $html_name = $this->inputNameFromParts($this_input_name_parts); |
|
248 | + $this->file_objects->add( |
|
249 | + new FileSubmission( |
|
250 | + $value['name'], |
|
251 | + $value['tmp_name'], |
|
252 | + $value['size'], |
|
253 | + $value['error'] |
|
254 | + ), |
|
255 | + $html_name |
|
256 | + ); |
|
257 | + } else { |
|
258 | + $this->createFileObjects($value, $this_input_name_parts); |
|
259 | + } |
|
260 | + } |
|
261 | + } |
|
262 | 262 | |
263 | 263 | |
264 | - /** |
|
265 | - * Takes the input name parts, like `['my', 'great', 'file', 'input1']` |
|
266 | - * and returns the HTML name for it, "my[great][file][input1]" |
|
267 | - * |
|
268 | - * @throws UnexpectedValueException |
|
269 | - * @since 4.9.80.p |
|
270 | - */ |
|
271 | - protected function inputNameFromParts($parts) |
|
272 | - { |
|
273 | - if (! is_array($parts)) { |
|
274 | - throw new UnexpectedValueException(esc_html__('Name parts should be an array.', 'event_espresso')); |
|
275 | - } |
|
276 | - $generated_string = ''; |
|
277 | - foreach ($parts as $part) { |
|
278 | - $part = (string) $part; |
|
279 | - // wrap all but the first part in [] |
|
280 | - $generated_string .= $generated_string === '' ? $part : '[' . $part . ']'; |
|
281 | - } |
|
282 | - return $generated_string; |
|
283 | - } |
|
264 | + /** |
|
265 | + * Takes the input name parts, like `['my', 'great', 'file', 'input1']` |
|
266 | + * and returns the HTML name for it, "my[great][file][input1]" |
|
267 | + * |
|
268 | + * @throws UnexpectedValueException |
|
269 | + * @since 4.9.80.p |
|
270 | + */ |
|
271 | + protected function inputNameFromParts($parts) |
|
272 | + { |
|
273 | + if (! is_array($parts)) { |
|
274 | + throw new UnexpectedValueException(esc_html__('Name parts should be an array.', 'event_espresso')); |
|
275 | + } |
|
276 | + $generated_string = ''; |
|
277 | + foreach ($parts as $part) { |
|
278 | + $part = (string) $part; |
|
279 | + // wrap all but the first part in [] |
|
280 | + $generated_string .= $generated_string === '' ? $part : '[' . $part . ']'; |
|
281 | + } |
|
282 | + return $generated_string; |
|
283 | + } |
|
284 | 284 | |
285 | 285 | |
286 | - /** |
|
287 | - * Gets the input by the indicated $name_parts. |
|
288 | - * Eg if you're looking for an input named "my[great][file][input1]", $name_parts |
|
289 | - * should be `['my', 'great', 'file', 'input1']`. |
|
290 | - * Alternatively, you could use `FileDataHandler::getFileObject('my[great][file][input1]');` |
|
291 | - * |
|
292 | - * @param $name_parts |
|
293 | - * @return FileSubmissionInterface |
|
294 | - * @throws UnexpectedValueException |
|
295 | - * @since 4.9.80.p |
|
296 | - */ |
|
297 | - public function getFileObjectFromNameParts($name_parts) |
|
298 | - { |
|
299 | - return $this->getFileObjects()->get($this->inputNameFromParts($name_parts)); |
|
300 | - } |
|
286 | + /** |
|
287 | + * Gets the input by the indicated $name_parts. |
|
288 | + * Eg if you're looking for an input named "my[great][file][input1]", $name_parts |
|
289 | + * should be `['my', 'great', 'file', 'input1']`. |
|
290 | + * Alternatively, you could use `FileDataHandler::getFileObject('my[great][file][input1]');` |
|
291 | + * |
|
292 | + * @param $name_parts |
|
293 | + * @return FileSubmissionInterface |
|
294 | + * @throws UnexpectedValueException |
|
295 | + * @since 4.9.80.p |
|
296 | + */ |
|
297 | + public function getFileObjectFromNameParts($name_parts) |
|
298 | + { |
|
299 | + return $this->getFileObjects()->get($this->inputNameFromParts($name_parts)); |
|
300 | + } |
|
301 | 301 | |
302 | 302 | |
303 | - /** |
|
304 | - * Gets the FileSubmissionInterface corresponding to the HTML name provided. |
|
305 | - * |
|
306 | - * @param $html_name |
|
307 | - * @return mixed |
|
308 | - * @throws InvalidArgumentException |
|
309 | - * @throws UnexpectedValueException |
|
310 | - * @since 4.9.80.p |
|
311 | - */ |
|
312 | - public function getFileObject($html_name) |
|
313 | - { |
|
314 | - return $this->getFileObjects()->get($html_name); |
|
315 | - } |
|
303 | + /** |
|
304 | + * Gets the FileSubmissionInterface corresponding to the HTML name provided. |
|
305 | + * |
|
306 | + * @param $html_name |
|
307 | + * @return mixed |
|
308 | + * @throws InvalidArgumentException |
|
309 | + * @throws UnexpectedValueException |
|
310 | + * @since 4.9.80.p |
|
311 | + */ |
|
312 | + public function getFileObject($html_name) |
|
313 | + { |
|
314 | + return $this->getFileObjects()->get($html_name); |
|
315 | + } |
|
316 | 316 | } |
317 | 317 | // End of file FilesDataHandler.php |
318 | 318 | // Location: EventEspresso\core\services\request\files/FilesDataHandler.php |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | // collection name |
100 | 100 | 'submitted_files' |
101 | 101 | ); |
102 | - $files_raw_data = $this->request->filesParams(); |
|
102 | + $files_raw_data = $this->request->filesParams(); |
|
103 | 103 | if (empty($files_raw_data)) { |
104 | 104 | return; |
105 | 105 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | */ |
124 | 124 | protected function isStrangeFilesArray($files_data) |
125 | 125 | { |
126 | - if (! is_array($files_data)) { |
|
126 | + if ( ! is_array($files_data)) { |
|
127 | 127 | throw new UnexpectedValueException( |
128 | 128 | sprintf( |
129 | 129 | esc_html__( |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | ); |
136 | 136 | } |
137 | 137 | $first_value = reset($files_data); |
138 | - if (! is_array($first_value)) { |
|
138 | + if ( ! is_array($first_value)) { |
|
139 | 139 | throw new UnexpectedValueException( |
140 | 140 | sprintf( |
141 | 141 | esc_html__( |
@@ -171,14 +171,14 @@ discard block |
||
171 | 171 | $sane_files_array = []; |
172 | 172 | foreach ($files_data as $top_level_name => $top_level_children) { |
173 | 173 | $sub_array = []; |
174 | - $sane_files_array[ $top_level_name ] = []; |
|
174 | + $sane_files_array[$top_level_name] = []; |
|
175 | 175 | foreach ($top_level_children as $file_data_part => $second_level_children) { |
176 | 176 | foreach ($second_level_children as $next_level_name => $sub_values) { |
177 | - $sub_array[ $next_level_name ] = $this->organizeFilesData($sub_values, $file_data_part); |
|
177 | + $sub_array[$next_level_name] = $this->organizeFilesData($sub_values, $file_data_part); |
|
178 | 178 | } |
179 | - $sane_files_array[ $top_level_name ] = array_replace_recursive( |
|
179 | + $sane_files_array[$top_level_name] = array_replace_recursive( |
|
180 | 180 | $sub_array, |
181 | - $sane_files_array[ $top_level_name ] |
|
181 | + $sane_files_array[$top_level_name] |
|
182 | 182 | ); |
183 | 183 | } |
184 | 184 | } |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | */ |
197 | 197 | protected function organizeFilesData($data, $type) |
198 | 198 | { |
199 | - if (! is_array($data)) { |
|
199 | + if ( ! is_array($data)) { |
|
200 | 200 | return [ |
201 | 201 | $type => $data, |
202 | 202 | ]; |
@@ -204,9 +204,9 @@ discard block |
||
204 | 204 | $organized_data = []; |
205 | 205 | foreach ($data as $input_name_part => $sub_inputs_or_value) { |
206 | 206 | if (is_array($sub_inputs_or_value)) { |
207 | - $organized_data[ $input_name_part ] = $this->organizeFilesData($sub_inputs_or_value, $type); |
|
207 | + $organized_data[$input_name_part] = $this->organizeFilesData($sub_inputs_or_value, $type); |
|
208 | 208 | } else { |
209 | - $organized_data[ $input_name_part ][ $type ] = $sub_inputs_or_value; |
|
209 | + $organized_data[$input_name_part][$type] = $sub_inputs_or_value; |
|
210 | 210 | } |
211 | 211 | } |
212 | 212 | return $organized_data; |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | */ |
227 | 227 | protected function createFileObjects($organized_files, $name_parts_so_far = []) |
228 | 228 | { |
229 | - if (! is_array($organized_files)) { |
|
229 | + if ( ! is_array($organized_files)) { |
|
230 | 230 | throw new UnexpectedValueException( |
231 | 231 | sprintf( |
232 | 232 | esc_html__( |
@@ -270,14 +270,14 @@ discard block |
||
270 | 270 | */ |
271 | 271 | protected function inputNameFromParts($parts) |
272 | 272 | { |
273 | - if (! is_array($parts)) { |
|
273 | + if ( ! is_array($parts)) { |
|
274 | 274 | throw new UnexpectedValueException(esc_html__('Name parts should be an array.', 'event_espresso')); |
275 | 275 | } |
276 | 276 | $generated_string = ''; |
277 | 277 | foreach ($parts as $part) { |
278 | 278 | $part = (string) $part; |
279 | 279 | // wrap all but the first part in [] |
280 | - $generated_string .= $generated_string === '' ? $part : '[' . $part . ']'; |
|
280 | + $generated_string .= $generated_string === '' ? $part : '['.$part.']'; |
|
281 | 281 | } |
282 | 282 | return $generated_string; |
283 | 283 | } |
@@ -7,16 +7,16 @@ discard block |
||
7 | 7 | define('EE_SUPPORT_EMAIL', '[email protected]'); |
8 | 8 | // used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
9 | 9 | if (! defined('DS')) { |
10 | - define('DS', '/'); |
|
10 | + define('DS', '/'); |
|
11 | 11 | } |
12 | 12 | if (! defined('PS')) { |
13 | - define('PS', PATH_SEPARATOR); |
|
13 | + define('PS', PATH_SEPARATOR); |
|
14 | 14 | } |
15 | 15 | if (! defined('SP')) { |
16 | - define('SP', ' '); |
|
16 | + define('SP', ' '); |
|
17 | 17 | } |
18 | 18 | if (! defined('EENL')) { |
19 | - define('EENL', "\n"); |
|
19 | + define('EENL', "\n"); |
|
20 | 20 | } |
21 | 21 | // define the plugin directory and URL |
22 | 22 | define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages/'); |
71 | 71 | // check for DOMPDF fonts in uploads |
72 | 72 | if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/')) { |
73 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/'); |
|
73 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/'); |
|
74 | 74 | } |
75 | 75 | // just a handy constant occasionally needed for finding values representing infinity in the DB |
76 | 76 | // you're better to use this than its straight value (currently -1) in case you ever |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | define('EE_INF_IN_DB', -1); |
79 | 79 | define('EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX); |
80 | 80 | if (! defined('EE_DEBUG')) { |
81 | - define('EE_DEBUG', false); |
|
81 | + define('EE_DEBUG', false); |
|
82 | 82 | } |
83 | 83 | // for older WP versions |
84 | 84 | if (! defined('MONTH_IN_SECONDS')) { |
85 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
85 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
86 | 86 | } |
@@ -7,78 +7,78 @@ |
||
7 | 7 | define('EE_MIN_PHP_VER_RECOMMENDED', '7.4'); |
8 | 8 | define('EE_SUPPORT_EMAIL', '[email protected]'); |
9 | 9 | // used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
10 | -if (! defined('DS')) { |
|
10 | +if ( ! defined('DS')) { |
|
11 | 11 | define('DS', '/'); |
12 | 12 | } |
13 | -if (! defined('PS')) { |
|
13 | +if ( ! defined('PS')) { |
|
14 | 14 | define('PS', PATH_SEPARATOR); |
15 | 15 | } |
16 | -if (! defined('SP')) { |
|
16 | +if ( ! defined('SP')) { |
|
17 | 17 | define('SP', ' '); |
18 | 18 | } |
19 | -if (! defined('EENL')) { |
|
19 | +if ( ! defined('EENL')) { |
|
20 | 20 | define('EENL', "\n"); |
21 | 21 | } |
22 | 22 | // define the plugin directory and URL |
23 | 23 | define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
24 | -define('EE_PLUGIN_DIR_PATH', dirname(EVENT_ESPRESSO_MAIN_FILE) . '/'); |
|
24 | +define('EE_PLUGIN_DIR_PATH', dirname(EVENT_ESPRESSO_MAIN_FILE).'/'); |
|
25 | 25 | define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
26 | 26 | // main root folder paths |
27 | -define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages/'); |
|
28 | -define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core/'); |
|
29 | -define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules/'); |
|
30 | -define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public/'); |
|
31 | -define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes/'); |
|
32 | -define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets/'); |
|
33 | -define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods/'); |
|
34 | -define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated/'); |
|
27 | +define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH.'admin_pages/'); |
|
28 | +define('EE_CORE', EE_PLUGIN_DIR_PATH.'core/'); |
|
29 | +define('EE_MODULES', EE_PLUGIN_DIR_PATH.'modules/'); |
|
30 | +define('EE_PUBLIC', EE_PLUGIN_DIR_PATH.'public/'); |
|
31 | +define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH.'shortcodes/'); |
|
32 | +define('EE_WIDGETS', EE_PLUGIN_DIR_PATH.'widgets/'); |
|
33 | +define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH.'payment_methods/'); |
|
34 | +define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH.'caffeinated/'); |
|
35 | 35 | // core system paths |
36 | -define('EE_ADMIN', EE_CORE . 'admin/'); |
|
37 | -define('EE_CPTS', EE_CORE . 'CPTs/'); |
|
38 | -define('EE_CLASSES', EE_CORE . 'db_classes/'); |
|
39 | -define('EE_INTERFACES', EE_CORE . 'interfaces/'); |
|
40 | -define('EE_BUSINESS', EE_CORE . 'business/'); |
|
41 | -define('EE_MODELS', EE_CORE . 'db_models/'); |
|
42 | -define('EE_HELPERS', EE_CORE . 'helpers/'); |
|
43 | -define('EE_LIBRARIES', EE_CORE . 'libraries/'); |
|
44 | -define('EE_TEMPLATES', EE_CORE . 'templates/'); |
|
45 | -define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs/'); |
|
46 | -define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets/'); |
|
47 | -define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections/'); |
|
36 | +define('EE_ADMIN', EE_CORE.'admin/'); |
|
37 | +define('EE_CPTS', EE_CORE.'CPTs/'); |
|
38 | +define('EE_CLASSES', EE_CORE.'db_classes/'); |
|
39 | +define('EE_INTERFACES', EE_CORE.'interfaces/'); |
|
40 | +define('EE_BUSINESS', EE_CORE.'business/'); |
|
41 | +define('EE_MODELS', EE_CORE.'db_models/'); |
|
42 | +define('EE_HELPERS', EE_CORE.'helpers/'); |
|
43 | +define('EE_LIBRARIES', EE_CORE.'libraries/'); |
|
44 | +define('EE_TEMPLATES', EE_CORE.'templates/'); |
|
45 | +define('EE_THIRD_PARTY', EE_CORE.'third_party_libs/'); |
|
46 | +define('EE_GLOBAL_ASSETS', EE_TEMPLATES.'global_assets/'); |
|
47 | +define('EE_FORM_SECTIONS', EE_LIBRARIES.'form_sections/'); |
|
48 | 48 | // gateways |
49 | -define('EE_GATEWAYS', EE_MODULES . 'gateways/'); |
|
50 | -define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules/gateways/'); |
|
49 | +define('EE_GATEWAYS', EE_MODULES.'gateways/'); |
|
50 | +define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL.'modules/gateways/'); |
|
51 | 51 | // asset URL paths |
52 | -define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core/templates/'); |
|
53 | -define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets/'); |
|
54 | -define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images/'); |
|
55 | -define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core/third_party_libs/'); |
|
56 | -define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
57 | -define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
52 | +define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL.'core/templates/'); |
|
53 | +define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL.'global_assets/'); |
|
54 | +define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL.'images/'); |
|
55 | +define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL.'core/third_party_libs/'); |
|
56 | +define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL.'core/helpers/assets/'); |
|
57 | +define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL.'core/libraries/'); |
|
58 | 58 | // define upload paths |
59 | 59 | $uploads = wp_upload_dir(); |
60 | 60 | // define the uploads directory and URL |
61 | -define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . '/espresso/'); |
|
62 | -define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . '/espresso/'); |
|
61 | +define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'].'/espresso/'); |
|
62 | +define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'].'/espresso/'); |
|
63 | 63 | // define the templates directory and URL |
64 | -define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . '/espresso/templates/'); |
|
65 | -define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . '/espresso/templates/'); |
|
64 | +define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'].'/espresso/templates/'); |
|
65 | +define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'].'/espresso/templates/'); |
|
66 | 66 | // languages folder/path |
67 | -define('EE_LANGUAGES_SAFE_LOC', '../' . 'uploads/' . 'espresso/languages/'); |
|
68 | -define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages/'); |
|
67 | +define('EE_LANGUAGES_SAFE_LOC', '../'.'uploads/'.'espresso/languages/'); |
|
68 | +define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'languages/'); |
|
69 | 69 | // check for DOMPDF fonts in uploads |
70 | -if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/')) { |
|
71 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts/'); |
|
70 | +if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR.'fonts/')) { |
|
71 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'fonts/'); |
|
72 | 72 | } |
73 | 73 | // just a handy constant occasionally needed for finding values representing infinity in the DB |
74 | 74 | // you're better to use this than its straight value (currently -1) in case you ever |
75 | 75 | // want to change its default value! or find when -1 means infinity |
76 | 76 | define('EE_INF_IN_DB', -1); |
77 | 77 | define('EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX); |
78 | -if (! defined('EE_DEBUG')) { |
|
78 | +if ( ! defined('EE_DEBUG')) { |
|
79 | 79 | define('EE_DEBUG', false); |
80 | 80 | } |
81 | 81 | // for older WP versions |
82 | -if (! defined('MONTH_IN_SECONDS')) { |
|
82 | +if ( ! defined('MONTH_IN_SECONDS')) { |
|
83 | 83 | define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
84 | 84 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public static function instance() |
50 | 50 | { |
51 | - if (! self::$_instance instanceof EE_Log) { |
|
51 | + if ( ! self::$_instance instanceof EE_Log) { |
|
52 | 52 | self::$_instance = new self(); |
53 | 53 | } |
54 | 54 | return self::$_instance; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | private function __construct() |
62 | 62 | { |
63 | 63 | |
64 | - if (! EE_Registry::instance()->CFG->admin->use_remote_logging) { |
|
64 | + if ( ! EE_Registry::instance()->CFG->admin->use_remote_logging) { |
|
65 | 65 | return; |
66 | 66 | } |
67 | 67 | |
@@ -105,14 +105,14 @@ discard block |
||
105 | 105 | */ |
106 | 106 | private function _format_message($file = '', $function = '', $message = '', $type = '') |
107 | 107 | { |
108 | - $msg = '----------------------------------------------------------------------------------------' . PHP_EOL; |
|
109 | - $msg .= '[' . current_time('mysql') . '] '; |
|
108 | + $msg = '----------------------------------------------------------------------------------------'.PHP_EOL; |
|
109 | + $msg .= '['.current_time('mysql').'] '; |
|
110 | 110 | $msg .= ! empty($file) ? basename($file) : ''; |
111 | 111 | $msg .= ! empty($file) && ! empty($function) ? ' -> ' : ''; |
112 | - $msg .= ! empty($function) ? $function . '()' : ''; |
|
112 | + $msg .= ! empty($function) ? $function.'()' : ''; |
|
113 | 113 | $msg .= PHP_EOL; |
114 | 114 | $type = ! empty($type) ? $type : 'log message'; |
115 | - $msg .= ! empty($message) ? "\t" . '[' . $type . '] ' . $message . PHP_EOL : ''; |
|
115 | + $msg .= ! empty($message) ? "\t".'['.$type.'] '.$message.PHP_EOL : ''; |
|
116 | 116 | return $msg; |
117 | 117 | } |
118 | 118 | |
@@ -164,18 +164,18 @@ discard block |
||
164 | 164 | |
165 | 165 | /** @var RequestInterface $request */ |
166 | 166 | $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
167 | - $data = 'domain=' . $request->getServerParam('HTTP_HOST'); |
|
168 | - $data .= '&ip=' . $request->getServerParam('SERVER_ADDR'); |
|
169 | - $data .= '&server_type=' . $request->getServerParam('SERVER_SOFTWARE'); |
|
170 | - $data .= '&time=' . time(); |
|
171 | - $data .= '&remote_log=' . $this->_log; |
|
167 | + $data = 'domain='.$request->getServerParam('HTTP_HOST'); |
|
168 | + $data .= '&ip='.$request->getServerParam('SERVER_ADDR'); |
|
169 | + $data .= '&server_type='.$request->getServerParam('SERVER_SOFTWARE'); |
|
170 | + $data .= '&time='.time(); |
|
171 | + $data .= '&remote_log='.$this->_log; |
|
172 | 172 | $data .= '&action=save'; |
173 | 173 | |
174 | 174 | if (defined('EELOGGING_PASS')) { |
175 | - $data .= '&pass=' . EELOGGING_PASS; |
|
175 | + $data .= '&pass='.EELOGGING_PASS; |
|
176 | 176 | } |
177 | 177 | if (defined('EELOGGING_KEY')) { |
178 | - $data .= '&key=' . EELOGGING_KEY; |
|
178 | + $data .= '&key='.EELOGGING_KEY; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | $c = curl_init($this->_remote_logging_url); |
@@ -19,197 +19,197 @@ |
||
19 | 19 | */ |
20 | 20 | class EE_Log |
21 | 21 | { |
22 | - /** |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - private $_log = ''; |
|
26 | - |
|
27 | - /** |
|
28 | - * Used for remote logging |
|
29 | - * |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - private $_remote_logging_url = ''; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - private $_remote_log = ''; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var EE_Log |
|
41 | - */ |
|
42 | - private static $_instance; |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @return EE_Log |
|
47 | - */ |
|
48 | - public static function instance() |
|
49 | - { |
|
50 | - if (! self::$_instance instanceof EE_Log) { |
|
51 | - self::$_instance = new self(); |
|
52 | - } |
|
53 | - return self::$_instance; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @access private |
|
58 | - * @return EE_Log |
|
59 | - */ |
|
60 | - private function __construct() |
|
61 | - { |
|
62 | - |
|
63 | - if (! EE_Registry::instance()->CFG->admin->use_remote_logging) { |
|
64 | - return; |
|
65 | - } |
|
66 | - |
|
67 | - $this->_remote_logging_url = EE_Registry::instance()->CFG->admin->remote_logging_url; |
|
68 | - $this->_remote_log = ''; |
|
69 | - |
|
70 | - if (EE_Registry::instance()->CFG->admin->use_remote_logging) { |
|
71 | - add_action('shutdown', array($this, 'send_log'), 9999); |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * verify_filesystem |
|
78 | - * tests that the required files and folders exist and are writable |
|
79 | - * |
|
80 | - */ |
|
81 | - public function verify_filesystem() |
|
82 | - { |
|
83 | - $msg = esc_html__( |
|
84 | - 'The Local File Logging functionality was removed permanently. Remote Logging is recommended instead.', |
|
85 | - 'event_espresso' |
|
86 | - ); |
|
87 | - EE_Error::doing_it_wrong( |
|
88 | - __METHOD__, |
|
89 | - $msg, |
|
90 | - '4.10.1.p' |
|
91 | - ); |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * _format_message |
|
97 | - * makes yer log entries look all purdy |
|
98 | - * |
|
99 | - * @param string $file |
|
100 | - * @param string $function |
|
101 | - * @param string $message |
|
102 | - * @param string $type |
|
103 | - * @return string |
|
104 | - */ |
|
105 | - private function _format_message($file = '', $function = '', $message = '', $type = '') |
|
106 | - { |
|
107 | - $msg = '----------------------------------------------------------------------------------------' . PHP_EOL; |
|
108 | - $msg .= '[' . current_time('mysql') . '] '; |
|
109 | - $msg .= ! empty($file) ? basename($file) : ''; |
|
110 | - $msg .= ! empty($file) && ! empty($function) ? ' -> ' : ''; |
|
111 | - $msg .= ! empty($function) ? $function . '()' : ''; |
|
112 | - $msg .= PHP_EOL; |
|
113 | - $type = ! empty($type) ? $type : 'log message'; |
|
114 | - $msg .= ! empty($message) ? "\t" . '[' . $type . '] ' . $message . PHP_EOL : ''; |
|
115 | - return $msg; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * log |
|
121 | - * adds content to the EE_Log->_log property which gets written to file during the WP 'shutdown' hookpoint via the |
|
122 | - * EE_Log::write_log() callback |
|
123 | - * |
|
124 | - * @param string $file |
|
125 | - * @param string $function |
|
126 | - * @param string $message |
|
127 | - * @param string $type |
|
128 | - */ |
|
129 | - public function log($file = '', $function = '', $message = '', $type = '') |
|
130 | - { |
|
131 | - $this->_log .= $this->_format_message($file, $function, $message, $type); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * write_log |
|
137 | - * appends the results of the 'AHEE_log' filter to the espresso log file |
|
138 | - */ |
|
139 | - public function write_log() |
|
140 | - { |
|
141 | - $msg = esc_html__( |
|
142 | - 'The Local File Logging functionality was removed permanently. Remote Logging is recommended instead.', |
|
143 | - 'event_espresso' |
|
144 | - ); |
|
145 | - EE_Error::doing_it_wrong( |
|
146 | - __METHOD__, |
|
147 | - $msg, |
|
148 | - '4.10.1.p' |
|
149 | - ); |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * send_log |
|
155 | - * sends the espresso log to a remote URL via a PHP cURL request |
|
156 | - */ |
|
157 | - public function send_log() |
|
158 | - { |
|
159 | - |
|
160 | - if (empty($this->_remote_logging_url)) { |
|
161 | - return; |
|
162 | - } |
|
163 | - |
|
164 | - /** @var RequestInterface $request */ |
|
165 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
166 | - $data = 'domain=' . $request->getServerParam('HTTP_HOST'); |
|
167 | - $data .= '&ip=' . $request->getServerParam('SERVER_ADDR'); |
|
168 | - $data .= '&server_type=' . $request->getServerParam('SERVER_SOFTWARE'); |
|
169 | - $data .= '&time=' . time(); |
|
170 | - $data .= '&remote_log=' . $this->_log; |
|
171 | - $data .= '&action=save'; |
|
172 | - |
|
173 | - if (defined('EELOGGING_PASS')) { |
|
174 | - $data .= '&pass=' . EELOGGING_PASS; |
|
175 | - } |
|
176 | - if (defined('EELOGGING_KEY')) { |
|
177 | - $data .= '&key=' . EELOGGING_KEY; |
|
178 | - } |
|
179 | - |
|
180 | - $c = curl_init($this->_remote_logging_url); |
|
181 | - curl_setopt($c, CURLOPT_POST, true); |
|
182 | - curl_setopt($c, CURLOPT_POSTFIELDS, $data); |
|
183 | - curl_setopt($c, CURLOPT_RETURNTRANSFER, true); |
|
184 | - curl_exec($c); |
|
185 | - curl_close($c); |
|
186 | - } |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * write_debug |
|
191 | - * writes the contents of the current request's data to a log file. |
|
192 | - * previous entries are overwritten |
|
193 | - */ |
|
194 | - public function write_debug() |
|
195 | - { |
|
196 | - $msg = esc_html__( |
|
197 | - 'The Local File Logging functionality was removed permanently. Remote Logging is recommended instead.', |
|
198 | - 'event_espresso' |
|
199 | - ); |
|
200 | - EE_Error::doing_it_wrong( |
|
201 | - __METHOD__, |
|
202 | - $msg, |
|
203 | - '4.10.1.p' |
|
204 | - ); |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * __clone |
|
210 | - */ |
|
211 | - public function __clone() |
|
212 | - { |
|
213 | - trigger_error(esc_html__('Clone is not allowed.', 'event_espresso'), E_USER_ERROR); |
|
214 | - } |
|
22 | + /** |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + private $_log = ''; |
|
26 | + |
|
27 | + /** |
|
28 | + * Used for remote logging |
|
29 | + * |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + private $_remote_logging_url = ''; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + private $_remote_log = ''; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var EE_Log |
|
41 | + */ |
|
42 | + private static $_instance; |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @return EE_Log |
|
47 | + */ |
|
48 | + public static function instance() |
|
49 | + { |
|
50 | + if (! self::$_instance instanceof EE_Log) { |
|
51 | + self::$_instance = new self(); |
|
52 | + } |
|
53 | + return self::$_instance; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @access private |
|
58 | + * @return EE_Log |
|
59 | + */ |
|
60 | + private function __construct() |
|
61 | + { |
|
62 | + |
|
63 | + if (! EE_Registry::instance()->CFG->admin->use_remote_logging) { |
|
64 | + return; |
|
65 | + } |
|
66 | + |
|
67 | + $this->_remote_logging_url = EE_Registry::instance()->CFG->admin->remote_logging_url; |
|
68 | + $this->_remote_log = ''; |
|
69 | + |
|
70 | + if (EE_Registry::instance()->CFG->admin->use_remote_logging) { |
|
71 | + add_action('shutdown', array($this, 'send_log'), 9999); |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * verify_filesystem |
|
78 | + * tests that the required files and folders exist and are writable |
|
79 | + * |
|
80 | + */ |
|
81 | + public function verify_filesystem() |
|
82 | + { |
|
83 | + $msg = esc_html__( |
|
84 | + 'The Local File Logging functionality was removed permanently. Remote Logging is recommended instead.', |
|
85 | + 'event_espresso' |
|
86 | + ); |
|
87 | + EE_Error::doing_it_wrong( |
|
88 | + __METHOD__, |
|
89 | + $msg, |
|
90 | + '4.10.1.p' |
|
91 | + ); |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * _format_message |
|
97 | + * makes yer log entries look all purdy |
|
98 | + * |
|
99 | + * @param string $file |
|
100 | + * @param string $function |
|
101 | + * @param string $message |
|
102 | + * @param string $type |
|
103 | + * @return string |
|
104 | + */ |
|
105 | + private function _format_message($file = '', $function = '', $message = '', $type = '') |
|
106 | + { |
|
107 | + $msg = '----------------------------------------------------------------------------------------' . PHP_EOL; |
|
108 | + $msg .= '[' . current_time('mysql') . '] '; |
|
109 | + $msg .= ! empty($file) ? basename($file) : ''; |
|
110 | + $msg .= ! empty($file) && ! empty($function) ? ' -> ' : ''; |
|
111 | + $msg .= ! empty($function) ? $function . '()' : ''; |
|
112 | + $msg .= PHP_EOL; |
|
113 | + $type = ! empty($type) ? $type : 'log message'; |
|
114 | + $msg .= ! empty($message) ? "\t" . '[' . $type . '] ' . $message . PHP_EOL : ''; |
|
115 | + return $msg; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * log |
|
121 | + * adds content to the EE_Log->_log property which gets written to file during the WP 'shutdown' hookpoint via the |
|
122 | + * EE_Log::write_log() callback |
|
123 | + * |
|
124 | + * @param string $file |
|
125 | + * @param string $function |
|
126 | + * @param string $message |
|
127 | + * @param string $type |
|
128 | + */ |
|
129 | + public function log($file = '', $function = '', $message = '', $type = '') |
|
130 | + { |
|
131 | + $this->_log .= $this->_format_message($file, $function, $message, $type); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * write_log |
|
137 | + * appends the results of the 'AHEE_log' filter to the espresso log file |
|
138 | + */ |
|
139 | + public function write_log() |
|
140 | + { |
|
141 | + $msg = esc_html__( |
|
142 | + 'The Local File Logging functionality was removed permanently. Remote Logging is recommended instead.', |
|
143 | + 'event_espresso' |
|
144 | + ); |
|
145 | + EE_Error::doing_it_wrong( |
|
146 | + __METHOD__, |
|
147 | + $msg, |
|
148 | + '4.10.1.p' |
|
149 | + ); |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * send_log |
|
155 | + * sends the espresso log to a remote URL via a PHP cURL request |
|
156 | + */ |
|
157 | + public function send_log() |
|
158 | + { |
|
159 | + |
|
160 | + if (empty($this->_remote_logging_url)) { |
|
161 | + return; |
|
162 | + } |
|
163 | + |
|
164 | + /** @var RequestInterface $request */ |
|
165 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
166 | + $data = 'domain=' . $request->getServerParam('HTTP_HOST'); |
|
167 | + $data .= '&ip=' . $request->getServerParam('SERVER_ADDR'); |
|
168 | + $data .= '&server_type=' . $request->getServerParam('SERVER_SOFTWARE'); |
|
169 | + $data .= '&time=' . time(); |
|
170 | + $data .= '&remote_log=' . $this->_log; |
|
171 | + $data .= '&action=save'; |
|
172 | + |
|
173 | + if (defined('EELOGGING_PASS')) { |
|
174 | + $data .= '&pass=' . EELOGGING_PASS; |
|
175 | + } |
|
176 | + if (defined('EELOGGING_KEY')) { |
|
177 | + $data .= '&key=' . EELOGGING_KEY; |
|
178 | + } |
|
179 | + |
|
180 | + $c = curl_init($this->_remote_logging_url); |
|
181 | + curl_setopt($c, CURLOPT_POST, true); |
|
182 | + curl_setopt($c, CURLOPT_POSTFIELDS, $data); |
|
183 | + curl_setopt($c, CURLOPT_RETURNTRANSFER, true); |
|
184 | + curl_exec($c); |
|
185 | + curl_close($c); |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * write_debug |
|
191 | + * writes the contents of the current request's data to a log file. |
|
192 | + * previous entries are overwritten |
|
193 | + */ |
|
194 | + public function write_debug() |
|
195 | + { |
|
196 | + $msg = esc_html__( |
|
197 | + 'The Local File Logging functionality was removed permanently. Remote Logging is recommended instead.', |
|
198 | + 'event_espresso' |
|
199 | + ); |
|
200 | + EE_Error::doing_it_wrong( |
|
201 | + __METHOD__, |
|
202 | + $msg, |
|
203 | + '4.10.1.p' |
|
204 | + ); |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * __clone |
|
210 | + */ |
|
211 | + public function __clone() |
|
212 | + { |
|
213 | + trigger_error(esc_html__('Clone is not allowed.', 'event_espresso'), E_USER_ERROR); |
|
214 | + } |
|
215 | 215 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | public function import() |
142 | 142 | { |
143 | 143 | |
144 | - require_once(EE_CLASSES . 'EE_CSV.class.php'); |
|
144 | + require_once(EE_CLASSES.'EE_CSV.class.php'); |
|
145 | 145 | $this->EE_CSV = EE_CSV::instance(); |
146 | 146 | |
147 | 147 | /** @var RequestInterface $request */ |
@@ -188,18 +188,18 @@ discard block |
||
188 | 188 | break; |
189 | 189 | } |
190 | 190 | |
191 | - if (! $error_msg) { |
|
191 | + if ( ! $error_msg) { |
|
192 | 192 | $filename = $files['file']['name'][0]; |
193 | 193 | $file_ext = substr(strrchr($filename, '.'), 1); |
194 | 194 | $file_type = $files['file']['type'][0]; |
195 | 195 | $temp_file = $files['file']['tmp_name'][0]; |
196 | - $filesize = $files['file']['size'][0] / 1024;// convert from bytes to KB |
|
196 | + $filesize = $files['file']['size'][0] / 1024; // convert from bytes to KB |
|
197 | 197 | |
198 | 198 | if ($file_ext == 'csv') { |
199 | - $max_upload = $this->EE_CSV->get_max_upload_size();// max upload size in KB |
|
199 | + $max_upload = $this->EE_CSV->get_max_upload_size(); // max upload size in KB |
|
200 | 200 | if ($filesize < $max_upload || true) { |
201 | 201 | $wp_upload_dir = str_replace(array('\\', '/'), '/', wp_upload_dir()); |
202 | - $path_to_file = $wp_upload_dir['basedir'] . '/espresso/' . $filename; |
|
202 | + $path_to_file = $wp_upload_dir['basedir'].'/espresso/'.$filename; |
|
203 | 203 | |
204 | 204 | if (move_uploaded_file($temp_file, $path_to_file)) { |
205 | 205 | // convert csv to array |
@@ -334,8 +334,8 @@ discard block |
||
334 | 334 | // begin looking through the $csv_data_array, expecting the toplevel key to be the model's name... |
335 | 335 | $old_site_url = 'none-specified'; |
336 | 336 | // hanlde metadata |
337 | - if (isset($csv_data_array[ EE_CSV::metadata_header ])) { |
|
338 | - $csv_metadata = array_shift($csv_data_array[ EE_CSV::metadata_header ]); |
|
337 | + if (isset($csv_data_array[EE_CSV::metadata_header])) { |
|
338 | + $csv_metadata = array_shift($csv_data_array[EE_CSV::metadata_header]); |
|
339 | 339 | // ok so its metadata, dont try to save it to ehte db obviously... |
340 | 340 | if (isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()) { |
341 | 341 | EE_Error::add_attention( |
@@ -360,14 +360,14 @@ discard block |
||
360 | 360 | ) |
361 | 361 | ); |
362 | 362 | }; |
363 | - unset($csv_data_array[ EE_CSV::metadata_header ]); |
|
363 | + unset($csv_data_array[EE_CSV::metadata_header]); |
|
364 | 364 | } |
365 | 365 | /** |
366 | 366 | * @var $old_db_to_new_db_mapping 2d array: toplevel keys being model names, bottom-level keys being the original key, and |
367 | 367 | * the value will be the newly-inserted ID. |
368 | 368 | * If we have already imported data from the same website via CSV, it shoudl be kept in this wp option |
369 | 369 | */ |
370 | - $old_db_to_new_db_mapping = get_option('ee_id_mapping_from' . sanitize_title($old_site_url), array()); |
|
370 | + $old_db_to_new_db_mapping = get_option('ee_id_mapping_from'.sanitize_title($old_site_url), array()); |
|
371 | 371 | if ($old_db_to_new_db_mapping) { |
372 | 372 | EE_Error::add_attention( |
373 | 373 | sprintf( |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | ); |
388 | 388 | |
389 | 389 | // save the mapping from old db to new db in case they try re-importing the same data from the same website again |
390 | - update_option('ee_id_mapping_from' . sanitize_title($old_site_url), $old_db_to_new_db_mapping); |
|
390 | + update_option('ee_id_mapping_from'.sanitize_title($old_site_url), $old_db_to_new_db_mapping); |
|
391 | 391 | |
392 | 392 | if ($this->_total_updates > 0) { |
393 | 393 | EE_Error::add_success( |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | // find the PK in the row of data (or a combined key if |
511 | 511 | // there is no primary key) |
512 | 512 | if ($model->has_primary_key_field()) { |
513 | - $id_in_csv = $model_object_data[ $model->primary_key_name() ]; |
|
513 | + $id_in_csv = $model_object_data[$model->primary_key_name()]; |
|
514 | 514 | } else { |
515 | 515 | $id_in_csv = $model->get_index_primary_key_string($model_object_data); |
516 | 516 | } |
@@ -554,14 +554,14 @@ discard block |
||
554 | 554 | $what_to_do = self::do_update; |
555 | 555 | // and if this model has a primary key, remember its mapping |
556 | 556 | if ($model->has_primary_key_field()) { |
557 | - $old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ] = $conflicting->ID(); |
|
558 | - $model_object_data[ $model->primary_key_name() ] = $conflicting->ID(); |
|
557 | + $old_db_to_new_db_mapping[$model_name][$id_in_csv] = $conflicting->ID(); |
|
558 | + $model_object_data[$model->primary_key_name()] = $conflicting->ID(); |
|
559 | 559 | } else { |
560 | 560 | // we want to update this conflicting item, instead of inserting a conflicting item |
561 | 561 | // 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 |
562 | 562 | // for the WHERE conditions in the update). At the time of this comment, there were no models like this |
563 | 563 | foreach ($model->get_combined_primary_key_fields() as $key_field) { |
564 | - $model_object_data[ $key_field->get_name() ] = $conflicting->get( |
|
564 | + $model_object_data[$key_field->get_name()] = $conflicting->get( |
|
565 | 565 | $key_field->get_name() |
566 | 566 | ); |
567 | 567 | } |
@@ -621,7 +621,7 @@ discard block |
||
621 | 621 | $model_name = $model->get_this_model_name(); |
622 | 622 | // if it's a site-to-site export-and-import, see if this modelobject's id |
623 | 623 | // in the old data that we know of |
624 | - if (isset($old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ])) { |
|
624 | + if (isset($old_db_to_new_db_mapping[$model_name][$id_in_csv])) { |
|
625 | 625 | return self::do_update; |
626 | 626 | } else { |
627 | 627 | return self::do_insert; |
@@ -677,13 +677,13 @@ discard block |
||
677 | 677 | if ( |
678 | 678 | $model->has_primary_key_field() && |
679 | 679 | $model->get_primary_key_field()->is_auto_increment() && |
680 | - isset($old_db_to_new_db_mapping[ $model->get_this_model_name() ]) && |
|
680 | + isset($old_db_to_new_db_mapping[$model->get_this_model_name()]) && |
|
681 | 681 | isset( |
682 | - $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ] |
|
682 | + $old_db_to_new_db_mapping[$model->get_this_model_name()][$model_object_data[$model->primary_key_name()]] |
|
683 | 683 | ) |
684 | 684 | ) { |
685 | - $model_object_data[ $model->primary_key_name() ] = $old_db_to_new_db_mapping[ $model->get_this_model_name( |
|
686 | - ) ][ $model_object_data[ $model->primary_key_name() ] ]; |
|
685 | + $model_object_data[$model->primary_key_name()] = $old_db_to_new_db_mapping[$model->get_this_model_name( |
|
686 | + )][$model_object_data[$model->primary_key_name()]]; |
|
687 | 687 | } |
688 | 688 | |
689 | 689 | try { |
@@ -699,10 +699,10 @@ discard block |
||
699 | 699 | $found_a_mapping = false; |
700 | 700 | foreach ($models_pointed_to as $model_pointed_to_by_fk) { |
701 | 701 | if ($model_name_field) { |
702 | - $value_of_model_name_field = $model_object_data[ $model_name_field->get_name() ]; |
|
702 | + $value_of_model_name_field = $model_object_data[$model_name_field->get_name()]; |
|
703 | 703 | if ($value_of_model_name_field == $model_pointed_to_by_fk) { |
704 | - $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
705 | - $model_object_data[ $field_obj->get_name() ], |
|
704 | + $model_object_data[$field_obj->get_name()] = $this->_find_mapping_in( |
|
705 | + $model_object_data[$field_obj->get_name()], |
|
706 | 706 | $model_pointed_to_by_fk, |
707 | 707 | $old_db_to_new_db_mapping, |
708 | 708 | $export_from_site_a_to_b |
@@ -711,8 +711,8 @@ discard block |
||
711 | 711 | break; |
712 | 712 | } |
713 | 713 | } else { |
714 | - $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
715 | - $model_object_data[ $field_obj->get_name() ], |
|
714 | + $model_object_data[$field_obj->get_name()] = $this->_find_mapping_in( |
|
715 | + $model_object_data[$field_obj->get_name()], |
|
716 | 716 | $model_pointed_to_by_fk, |
717 | 717 | $old_db_to_new_db_mapping, |
718 | 718 | $export_from_site_a_to_b |
@@ -777,8 +777,8 @@ discard block |
||
777 | 777 | */ |
778 | 778 | protected function _find_mapping_in($object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) |
779 | 779 | { |
780 | - if (isset($old_db_to_new_db_mapping[ $model_name ][ $object_id ])) { |
|
781 | - return $old_db_to_new_db_mapping[ $model_name ][ $object_id ]; |
|
780 | + if (isset($old_db_to_new_db_mapping[$model_name][$object_id])) { |
|
781 | + return $old_db_to_new_db_mapping[$model_name][$object_id]; |
|
782 | 782 | } elseif ($object_id == '0' || $object_id == '') { |
783 | 783 | // leave as-is |
784 | 784 | return $object_id; |
@@ -786,7 +786,7 @@ discard block |
||
786 | 786 | // we couldn't find a mapping for this, and it's from a different site, |
787 | 787 | // so blank it out |
788 | 788 | return null; |
789 | - } elseif (! $export_from_site_a_to_b) { |
|
789 | + } elseif ( ! $export_from_site_a_to_b) { |
|
790 | 790 | // we coudln't find a mapping for this, but it's from thsi DB anyway |
791 | 791 | // so let's just leave it as-is |
792 | 792 | return $object_id; |
@@ -806,8 +806,8 @@ discard block |
||
806 | 806 | // remove the primary key, if there is one (we don't want it for inserts OR updates) |
807 | 807 | // we'll put it back in if we need it |
808 | 808 | if ($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()) { |
809 | - $effective_id = $model_object_data[ $model->primary_key_name() ]; |
|
810 | - unset($model_object_data[ $model->primary_key_name() ]); |
|
809 | + $effective_id = $model_object_data[$model->primary_key_name()]; |
|
810 | + unset($model_object_data[$model->primary_key_name()]); |
|
811 | 811 | } else { |
812 | 812 | $effective_id = $model->get_index_primary_key_string($model_object_data); |
813 | 813 | } |
@@ -815,7 +815,7 @@ discard block |
||
815 | 815 | try { |
816 | 816 | $new_id = $model->insert($model_object_data); |
817 | 817 | if ($new_id) { |
818 | - $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_id; |
|
818 | + $old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_id; |
|
819 | 819 | $this->_total_inserts++; |
820 | 820 | EE_Error::add_success( |
821 | 821 | sprintf( |
@@ -829,7 +829,7 @@ discard block |
||
829 | 829 | $this->_total_insert_errors++; |
830 | 830 | // put the ID used back in there for the error message |
831 | 831 | if ($model->has_primary_key_field()) { |
832 | - $model_object_data[ $model->primary_key_name() ] = $effective_id; |
|
832 | + $model_object_data[$model->primary_key_name()] = $effective_id; |
|
833 | 833 | } |
834 | 834 | EE_Error::add_error( |
835 | 835 | sprintf( |
@@ -845,7 +845,7 @@ discard block |
||
845 | 845 | } catch (EE_Error $e) { |
846 | 846 | $this->_total_insert_errors++; |
847 | 847 | if ($model->has_primary_key_field()) { |
848 | - $model_object_data[ $model->primary_key_name() ] = $effective_id; |
|
848 | + $model_object_data[$model->primary_key_name()] = $effective_id; |
|
849 | 849 | } |
850 | 850 | EE_Error::add_error( |
851 | 851 | sprintf( |
@@ -878,17 +878,17 @@ discard block |
||
878 | 878 | // one for performing an update, one for everthing else |
879 | 879 | $model_object_data_for_update = $model_object_data; |
880 | 880 | if ($model->has_primary_key_field()) { |
881 | - $conditions = array($model->primary_key_name() => $model_object_data[ $model->primary_key_name() ]); |
|
881 | + $conditions = array($model->primary_key_name() => $model_object_data[$model->primary_key_name()]); |
|
882 | 882 | // remove the primary key because we shouldn't use it for updating |
883 | - unset($model_object_data_for_update[ $model->primary_key_name() ]); |
|
883 | + unset($model_object_data_for_update[$model->primary_key_name()]); |
|
884 | 884 | } elseif ($model->get_combined_primary_key_fields() > 1) { |
885 | 885 | $conditions = array(); |
886 | 886 | foreach ($model->get_combined_primary_key_fields() as $key_field) { |
887 | - $conditions[ $key_field->get_name() ] = $model_object_data[ $key_field->get_name() ]; |
|
887 | + $conditions[$key_field->get_name()] = $model_object_data[$key_field->get_name()]; |
|
888 | 888 | } |
889 | 889 | } else { |
890 | 890 | $model->primary_key_name( |
891 | - );// this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey) |
|
891 | + ); // this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey) |
|
892 | 892 | } |
893 | 893 | |
894 | 894 | $success = $model->update($model_object_data_for_update, array($conditions)); |
@@ -906,15 +906,15 @@ discard block |
||
906 | 906 | // we would have last-minute decided to update. So we'd like to know what we updated |
907 | 907 | // and so we record what record ended up being updated using the mapping |
908 | 908 | if ($model->has_primary_key_field()) { |
909 | - $new_key_for_mapping = $model_object_data[ $model->primary_key_name() ]; |
|
909 | + $new_key_for_mapping = $model_object_data[$model->primary_key_name()]; |
|
910 | 910 | } else { |
911 | 911 | // no primary key just a combined key |
912 | 912 | $new_key_for_mapping = $model->get_index_primary_key_string($model_object_data); |
913 | 913 | } |
914 | - $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_key_for_mapping; |
|
914 | + $old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_key_for_mapping; |
|
915 | 915 | } else { |
916 | 916 | $matched_items = $model->get_all(array($conditions)); |
917 | - if (! $matched_items) { |
|
917 | + if ( ! $matched_items) { |
|
918 | 918 | // no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck? |
919 | 919 | $this->_total_update_errors++; |
920 | 920 | EE_Error::add_error( |
@@ -953,7 +953,7 @@ discard block |
||
953 | 953 | implode(",", $model_object_data), |
954 | 954 | $e->getMessage() |
955 | 955 | ); |
956 | - $debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString(); |
|
956 | + $debug_message = $basic_message.' Stack trace: '.$e->getTraceAsString(); |
|
957 | 957 | EE_Error::add_error("$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__); |
958 | 958 | } |
959 | 959 | return $old_db_to_new_db_mapping; |
@@ -13,97 +13,97 @@ discard block |
||
13 | 13 | */ |
14 | 14 | class EE_Import implements ResettableInterface |
15 | 15 | { |
16 | - const do_insert = 'insert'; |
|
17 | - const do_update = 'update'; |
|
18 | - const do_nothing = 'nothing'; |
|
19 | - |
|
20 | - |
|
21 | - // instance of the EE_Import object |
|
22 | - private static $_instance; |
|
23 | - |
|
24 | - private static $_csv_array = array(); |
|
25 | - |
|
26 | - /** |
|
27 | - * |
|
28 | - * @var array of model names |
|
29 | - */ |
|
30 | - private static $_model_list = array(); |
|
31 | - |
|
32 | - private static $_columns_to_save = array(); |
|
33 | - |
|
34 | - protected $_total_inserts = 0; |
|
35 | - protected $_total_updates = 0; |
|
36 | - protected $_total_insert_errors = 0; |
|
37 | - protected $_total_update_errors = 0; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var EE_CSV |
|
41 | - * @since 4.10.14.p |
|
42 | - */ |
|
43 | - private $EE_CSV; |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * private constructor to prevent direct creation |
|
48 | - * |
|
49 | - * @Constructor |
|
50 | - * @access private |
|
51 | - * @return void |
|
52 | - */ |
|
53 | - private function __construct() |
|
54 | - { |
|
55 | - $this->_total_inserts = 0; |
|
56 | - $this->_total_updates = 0; |
|
57 | - $this->_total_insert_errors = 0; |
|
58 | - $this->_total_update_errors = 0; |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @ singleton method used to instantiate class object |
|
64 | - * @ access public |
|
65 | - * |
|
66 | - * @return EE_Import |
|
67 | - */ |
|
68 | - public static function instance() |
|
69 | - { |
|
70 | - // check if class object is instantiated |
|
71 | - if (self::$_instance === null or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Import)) { |
|
72 | - self::$_instance = new self(); |
|
73 | - } |
|
74 | - return self::$_instance; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Resets the importer |
|
79 | - * |
|
80 | - * @return EE_Import |
|
81 | - */ |
|
82 | - public static function reset() |
|
83 | - { |
|
84 | - self::$_instance = null; |
|
85 | - return self::instance(); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * @ generates HTML for a file upload input and form |
|
91 | - * @ access public |
|
92 | - * |
|
93 | - * @param string $title - heading for the form |
|
94 | - * @param string $intro - additional text explaing what to do |
|
95 | - * @param string $page - EE Admin page to direct form to - in the form "espresso_{pageslug}" |
|
96 | - * @param string $action - EE Admin page route array "action" that form will direct to |
|
97 | - * @param string $type - type of file to import |
|
98 | - * @ return string |
|
99 | - */ |
|
100 | - public function upload_form($title, $intro, $form_url, $action, $type) |
|
101 | - { |
|
102 | - |
|
103 | - $form_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => $action), $form_url); |
|
104 | - |
|
105 | - ob_start(); |
|
106 | - ?> |
|
16 | + const do_insert = 'insert'; |
|
17 | + const do_update = 'update'; |
|
18 | + const do_nothing = 'nothing'; |
|
19 | + |
|
20 | + |
|
21 | + // instance of the EE_Import object |
|
22 | + private static $_instance; |
|
23 | + |
|
24 | + private static $_csv_array = array(); |
|
25 | + |
|
26 | + /** |
|
27 | + * |
|
28 | + * @var array of model names |
|
29 | + */ |
|
30 | + private static $_model_list = array(); |
|
31 | + |
|
32 | + private static $_columns_to_save = array(); |
|
33 | + |
|
34 | + protected $_total_inserts = 0; |
|
35 | + protected $_total_updates = 0; |
|
36 | + protected $_total_insert_errors = 0; |
|
37 | + protected $_total_update_errors = 0; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var EE_CSV |
|
41 | + * @since 4.10.14.p |
|
42 | + */ |
|
43 | + private $EE_CSV; |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * private constructor to prevent direct creation |
|
48 | + * |
|
49 | + * @Constructor |
|
50 | + * @access private |
|
51 | + * @return void |
|
52 | + */ |
|
53 | + private function __construct() |
|
54 | + { |
|
55 | + $this->_total_inserts = 0; |
|
56 | + $this->_total_updates = 0; |
|
57 | + $this->_total_insert_errors = 0; |
|
58 | + $this->_total_update_errors = 0; |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @ singleton method used to instantiate class object |
|
64 | + * @ access public |
|
65 | + * |
|
66 | + * @return EE_Import |
|
67 | + */ |
|
68 | + public static function instance() |
|
69 | + { |
|
70 | + // check if class object is instantiated |
|
71 | + if (self::$_instance === null or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Import)) { |
|
72 | + self::$_instance = new self(); |
|
73 | + } |
|
74 | + return self::$_instance; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Resets the importer |
|
79 | + * |
|
80 | + * @return EE_Import |
|
81 | + */ |
|
82 | + public static function reset() |
|
83 | + { |
|
84 | + self::$_instance = null; |
|
85 | + return self::instance(); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * @ generates HTML for a file upload input and form |
|
91 | + * @ access public |
|
92 | + * |
|
93 | + * @param string $title - heading for the form |
|
94 | + * @param string $intro - additional text explaing what to do |
|
95 | + * @param string $page - EE Admin page to direct form to - in the form "espresso_{pageslug}" |
|
96 | + * @param string $action - EE Admin page route array "action" that form will direct to |
|
97 | + * @param string $type - type of file to import |
|
98 | + * @ return string |
|
99 | + */ |
|
100 | + public function upload_form($title, $intro, $form_url, $action, $type) |
|
101 | + { |
|
102 | + |
|
103 | + $form_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => $action), $form_url); |
|
104 | + |
|
105 | + ob_start(); |
|
106 | + ?> |
|
107 | 107 | <div class="ee-upload-form-dv"> |
108 | 108 | <h3><?php echo esc_html($title); ?></h3> |
109 | 109 | <p><?php echo esc_html($intro); ?></p> |
@@ -119,882 +119,882 @@ discard block |
||
119 | 119 | <b><?php esc_html_e('Attention', 'event_espresso'); ?></b><br/> |
120 | 120 | <?php echo sprintf(esc_html__('Accepts .%s file types only.', 'event_espresso'), $type); ?> |
121 | 121 | <?php echo esc_html__( |
122 | - 'Please only import CSV files exported from Event Espresso, or compatible 3rd-party software.', |
|
123 | - 'event_espresso' |
|
124 | - ); ?> |
|
122 | + 'Please only import CSV files exported from Event Espresso, or compatible 3rd-party software.', |
|
123 | + 'event_espresso' |
|
124 | + ); ?> |
|
125 | 125 | </p> |
126 | 126 | |
127 | 127 | </div> |
128 | 128 | |
129 | 129 | <?php |
130 | - $uploader = ob_get_clean(); |
|
131 | - return $uploader; |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * @Import Event Espresso data - some code "borrowed" from event espresso csv_import.php |
|
137 | - * @access public |
|
138 | - * @return boolean success |
|
139 | - */ |
|
140 | - public function import() |
|
141 | - { |
|
142 | - |
|
143 | - require_once(EE_CLASSES . 'EE_CSV.class.php'); |
|
144 | - $this->EE_CSV = EE_CSV::instance(); |
|
145 | - |
|
146 | - /** @var RequestInterface $request */ |
|
147 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
148 | - |
|
149 | - if ($request->requestParamIsSet('import') && $request->requestParamIsSet('csv_submitted')) { |
|
150 | - $files = $request->filesParams(); |
|
151 | - switch ($files['file']['error'][0]) { |
|
152 | - case UPLOAD_ERR_OK: |
|
153 | - $error_msg = false; |
|
154 | - break; |
|
155 | - case UPLOAD_ERR_INI_SIZE: |
|
156 | - $error_msg = esc_html__( |
|
157 | - "'The uploaded file exceeds the upload_max_filesize directive in php.ini.'", |
|
158 | - "event_espresso" |
|
159 | - ); |
|
160 | - break; |
|
161 | - case UPLOAD_ERR_FORM_SIZE: |
|
162 | - $error_msg = esc_html__( |
|
163 | - 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', |
|
164 | - "event_espresso" |
|
165 | - ); |
|
166 | - break; |
|
167 | - case UPLOAD_ERR_PARTIAL: |
|
168 | - $error_msg = esc_html__('The uploaded file was only partially uploaded.', "event_espresso"); |
|
169 | - break; |
|
170 | - case UPLOAD_ERR_NO_FILE: |
|
171 | - $error_msg = esc_html__('No file was uploaded.', "event_espresso"); |
|
172 | - break; |
|
173 | - case UPLOAD_ERR_NO_TMP_DIR: |
|
174 | - $error_msg = esc_html__('Missing a temporary folder.', "event_espresso"); |
|
175 | - break; |
|
176 | - case UPLOAD_ERR_CANT_WRITE: |
|
177 | - $error_msg = esc_html__('Failed to write file to disk.', "event_espresso"); |
|
178 | - break; |
|
179 | - case UPLOAD_ERR_EXTENSION: |
|
180 | - $error_msg = esc_html__('File upload stopped by extension.', "event_espresso"); |
|
181 | - break; |
|
182 | - default: |
|
183 | - $error_msg = esc_html__( |
|
184 | - 'An unknown error occurred and the file could not be uploaded', |
|
185 | - "event_espresso" |
|
186 | - ); |
|
187 | - break; |
|
188 | - } |
|
189 | - |
|
190 | - if (! $error_msg) { |
|
191 | - $filename = $files['file']['name'][0]; |
|
192 | - $file_ext = substr(strrchr($filename, '.'), 1); |
|
193 | - $file_type = $files['file']['type'][0]; |
|
194 | - $temp_file = $files['file']['tmp_name'][0]; |
|
195 | - $filesize = $files['file']['size'][0] / 1024;// convert from bytes to KB |
|
196 | - |
|
197 | - if ($file_ext == 'csv') { |
|
198 | - $max_upload = $this->EE_CSV->get_max_upload_size();// max upload size in KB |
|
199 | - if ($filesize < $max_upload || true) { |
|
200 | - $wp_upload_dir = str_replace(array('\\', '/'), '/', wp_upload_dir()); |
|
201 | - $path_to_file = $wp_upload_dir['basedir'] . '/espresso/' . $filename; |
|
202 | - |
|
203 | - if (move_uploaded_file($temp_file, $path_to_file)) { |
|
204 | - // convert csv to array |
|
205 | - $this->csv_array = $this->EE_CSV->import_csv_to_model_data_array($path_to_file); |
|
206 | - |
|
207 | - $action = $request->getRequestParam('action'); |
|
208 | - |
|
209 | - // was data successfully stored in an array? |
|
210 | - if (is_array($this->csv_array)) { |
|
211 | - $import_what = str_replace('csv_import_', '', $action); |
|
212 | - $import_what = str_replace('_', ' ', ucwords($import_what)); |
|
213 | - $processed_data = $this->csv_array; |
|
214 | - $this->columns_to_save = false; |
|
215 | - |
|
216 | - // if any imports require funky processing, we'll catch them in the switch |
|
217 | - switch ($action) { |
|
218 | - case "import_events": |
|
219 | - case "event_list": |
|
220 | - $import_what = 'Event Details'; |
|
221 | - break; |
|
222 | - |
|
223 | - case 'groupon_import_csv': |
|
224 | - $import_what = 'Groupon Codes'; |
|
225 | - $processed_data = $this->process_groupon_codes(); |
|
226 | - break; |
|
227 | - } |
|
228 | - // save processed codes to db |
|
229 | - if ($this->save_csv_data_array_to_db($processed_data, $this->columns_to_save)) { |
|
230 | - return true; |
|
231 | - } |
|
232 | - } else { |
|
233 | - // no array? must be an error |
|
234 | - EE_Error::add_error( |
|
235 | - sprintf(esc_html__("No file seems to have been uploaded", "event_espresso")), |
|
236 | - __FILE__, |
|
237 | - __FUNCTION__, |
|
238 | - __LINE__ |
|
239 | - ); |
|
240 | - return false; |
|
241 | - } |
|
242 | - } else { |
|
243 | - EE_Error::add_error( |
|
244 | - sprintf(esc_html__("%s was not successfully uploaded", "event_espresso"), $filename), |
|
245 | - __FILE__, |
|
246 | - __FUNCTION__, |
|
247 | - __LINE__ |
|
248 | - ); |
|
249 | - return false; |
|
250 | - } |
|
251 | - } else { |
|
252 | - EE_Error::add_error( |
|
253 | - sprintf( |
|
254 | - esc_html__( |
|
255 | - "%s was too large of a file and could not be uploaded. The max filesize is %s' KB.", |
|
256 | - "event_espresso" |
|
257 | - ), |
|
258 | - $filename, |
|
259 | - $max_upload |
|
260 | - ), |
|
261 | - __FILE__, |
|
262 | - __FUNCTION__, |
|
263 | - __LINE__ |
|
264 | - ); |
|
265 | - return false; |
|
266 | - } |
|
267 | - } else { |
|
268 | - EE_Error::add_error( |
|
269 | - sprintf(esc_html__("%s had an invalid file extension, not uploaded", "event_espresso"), $filename), |
|
270 | - __FILE__, |
|
271 | - __FUNCTION__, |
|
272 | - __LINE__ |
|
273 | - ); |
|
274 | - return false; |
|
275 | - } |
|
276 | - } else { |
|
277 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
278 | - return false; |
|
279 | - } |
|
280 | - } |
|
281 | - return false; |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * Given an array of data (usually from a CSV import) attempts to save that data to the db. |
|
287 | - * If $model_name ISN'T provided, assumes that this is a 3d array, with toplevel keys being model names, |
|
288 | - * next level being numeric indexes adn each value representing a model object, and the last layer down |
|
289 | - * being keys of model fields and their proposed values. |
|
290 | - * If $model_name IS provided, assumes a 2d array of the bottom two layers previously mentioned. |
|
291 | - * If the CSV data says (in the metadata row) that it's from the SAME database, |
|
292 | - * we treat the IDs in the CSV as the normal IDs, and try to update those records. However, if those |
|
293 | - * IDs DON'T exist in the database, they're treated as temporary IDs, |
|
294 | - * which can used elsewhere to refer to the same object. Once an item |
|
295 | - * with a temporary ID gets inserted, we record its mapping from temporary |
|
296 | - * ID to real ID, and use the real ID in place of the temporary ID |
|
297 | - * when that temporary ID was used as a foreign key. |
|
298 | - * If the CSV data says (in the metadata again) that it's from a DIFFERENT database, |
|
299 | - * we treat all the IDs in the CSV as temporary ID- eg, if the CSV specifies an event with |
|
300 | - * ID 1, and the database already has an event with ID 1, we assume that's just a coincidence, |
|
301 | - * and insert a new event, and map it's temporary ID of 1 over to its new real ID. |
|
302 | - * An important exception are non-auto-increment primary keys. If one entry in the |
|
303 | - * CSV file has the same ID as one in the DB, we assume they are meant to be |
|
304 | - * the same item, and instead update the item in the DB with that same ID. |
|
305 | - * Also note, we remember the mappings permanently. So the 2nd, 3rd, and 10000th |
|
306 | - * time you import a CSV from a different site, we remember their mappings, and |
|
307 | - * will try to update the item in the DB instead of inserting another item (eg |
|
308 | - * if we previously imported an event with temporary ID 1, and then it got a |
|
309 | - * real ID of 123, we remember that. So the next time we import an event with |
|
310 | - * temporary ID, from the same site, we know that it's real ID is 123, and will |
|
311 | - * update that event, instead of adding a new event). |
|
312 | - * |
|
313 | - * @access public |
|
314 | - * @param array $csv_data_array - the array containing the csv data produced from |
|
315 | - * EE_CSV::import_csv_to_model_data_array() |
|
316 | - * @param array $fields_to_save - an array containing the csv column names as keys with the corresponding db table |
|
317 | - * fields they will be saved to |
|
318 | - * @return TRUE on success, FALSE on fail |
|
319 | - * @throws \EE_Error |
|
320 | - */ |
|
321 | - public function save_csv_data_array_to_db($csv_data_array, $model_name = false) |
|
322 | - { |
|
323 | - $success = false; |
|
324 | - $error = false; |
|
325 | - // whther to treat this import as if it's data froma different database or not |
|
326 | - // ie, if it IS from a different database, ignore foreign keys whihf |
|
327 | - $export_from_site_a_to_b = true; |
|
328 | - // first level of array is not table information but a table name was passed to the function |
|
329 | - // array is only two levels deep, so let's fix that by adding a level, else the next steps will fail |
|
330 | - if ($model_name) { |
|
331 | - $csv_data_array = array($csv_data_array); |
|
332 | - } |
|
333 | - // begin looking through the $csv_data_array, expecting the toplevel key to be the model's name... |
|
334 | - $old_site_url = 'none-specified'; |
|
335 | - // hanlde metadata |
|
336 | - if (isset($csv_data_array[ EE_CSV::metadata_header ])) { |
|
337 | - $csv_metadata = array_shift($csv_data_array[ EE_CSV::metadata_header ]); |
|
338 | - // ok so its metadata, dont try to save it to ehte db obviously... |
|
339 | - if (isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()) { |
|
340 | - EE_Error::add_attention( |
|
341 | - sprintf( |
|
342 | - esc_html__( |
|
343 | - "CSV Data appears to be from the same database, so attempting to update data", |
|
344 | - "event_espresso" |
|
345 | - ) |
|
346 | - ) |
|
347 | - ); |
|
348 | - $export_from_site_a_to_b = false; |
|
349 | - } else { |
|
350 | - $old_site_url = isset($csv_metadata['site_url']) ? $csv_metadata['site_url'] : $old_site_url; |
|
351 | - EE_Error::add_attention( |
|
352 | - sprintf( |
|
353 | - esc_html__( |
|
354 | - "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", |
|
355 | - "event_espresso" |
|
356 | - ), |
|
357 | - $old_site_url, |
|
358 | - site_url() |
|
359 | - ) |
|
360 | - ); |
|
361 | - }; |
|
362 | - unset($csv_data_array[ EE_CSV::metadata_header ]); |
|
363 | - } |
|
364 | - /** |
|
365 | - * @var $old_db_to_new_db_mapping 2d array: toplevel keys being model names, bottom-level keys being the original key, and |
|
366 | - * the value will be the newly-inserted ID. |
|
367 | - * If we have already imported data from the same website via CSV, it shoudl be kept in this wp option |
|
368 | - */ |
|
369 | - $old_db_to_new_db_mapping = get_option('ee_id_mapping_from' . sanitize_title($old_site_url), array()); |
|
370 | - if ($old_db_to_new_db_mapping) { |
|
371 | - EE_Error::add_attention( |
|
372 | - sprintf( |
|
373 | - esc_html__( |
|
374 | - "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", |
|
375 | - "event_espresso" |
|
376 | - ), |
|
377 | - $old_site_url, |
|
378 | - site_url() |
|
379 | - ) |
|
380 | - ); |
|
381 | - } |
|
382 | - $old_db_to_new_db_mapping = $this->save_data_rows_to_db( |
|
383 | - $csv_data_array, |
|
384 | - $export_from_site_a_to_b, |
|
385 | - $old_db_to_new_db_mapping |
|
386 | - ); |
|
387 | - |
|
388 | - // save the mapping from old db to new db in case they try re-importing the same data from the same website again |
|
389 | - update_option('ee_id_mapping_from' . sanitize_title($old_site_url), $old_db_to_new_db_mapping); |
|
390 | - |
|
391 | - if ($this->_total_updates > 0) { |
|
392 | - EE_Error::add_success( |
|
393 | - sprintf( |
|
394 | - esc_html__("%s existing records in the database were updated.", "event_espresso"), |
|
395 | - $this->_total_updates |
|
396 | - ) |
|
397 | - ); |
|
398 | - $success = true; |
|
399 | - } |
|
400 | - if ($this->_total_inserts > 0) { |
|
401 | - EE_Error::add_success( |
|
402 | - sprintf(esc_html__("%s new records were added to the database.", "event_espresso"), $this->_total_inserts) |
|
403 | - ); |
|
404 | - $success = true; |
|
405 | - } |
|
406 | - |
|
407 | - if ($this->_total_update_errors > 0) { |
|
408 | - EE_Error::add_error( |
|
409 | - sprintf( |
|
410 | - esc_html__( |
|
411 | - "'One or more errors occurred, and a total of %s existing records in the database were <strong>not</strong> updated.'", |
|
412 | - "event_espresso" |
|
413 | - ), |
|
414 | - $this->_total_update_errors |
|
415 | - ), |
|
416 | - __FILE__, |
|
417 | - __FUNCTION__, |
|
418 | - __LINE__ |
|
419 | - ); |
|
420 | - $error = true; |
|
421 | - } |
|
422 | - if ($this->_total_insert_errors > 0) { |
|
423 | - EE_Error::add_error( |
|
424 | - sprintf( |
|
425 | - esc_html__( |
|
426 | - "One or more errors occurred, and a total of %s new records were <strong>not</strong> added to the database.'", |
|
427 | - "event_espresso" |
|
428 | - ), |
|
429 | - $this->_total_insert_errors |
|
430 | - ), |
|
431 | - __FILE__, |
|
432 | - __FUNCTION__, |
|
433 | - __LINE__ |
|
434 | - ); |
|
435 | - $error = true; |
|
436 | - } |
|
437 | - |
|
438 | - // lastly, we need to update the datetime and ticket sold amounts |
|
439 | - // as those may have been affected by this |
|
440 | - EEM_Ticket::instance()->update_tickets_sold(EEM_Ticket::instance()->get_all()); |
|
441 | - |
|
442 | - // if there was at least one success and absolutely no errors |
|
443 | - if ($success && ! $error) { |
|
444 | - return true; |
|
445 | - } else { |
|
446 | - return false; |
|
447 | - } |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * Processes the array of data, given the knowledge that it's from the same database or a different one, |
|
453 | - * and the mapping from temporary IDs to real IDs. |
|
454 | - * If the data is from a different database, we treat the primary keys and their corresponding |
|
455 | - * foreign keys as "temp Ids", basically identifiers that get mapped to real primary keys |
|
456 | - * in the real target database. As items are inserted, their temporary primary keys |
|
457 | - * are mapped to the real IDs in the target database. Also, before doing any update or |
|
458 | - * insert, we replace all the temp ID which are foreign keys with their mapped real IDs. |
|
459 | - * An exception: string primary keys are treated as real IDs, or else we'd need to |
|
460 | - * dynamically generate new string primary keys which would be very awkard for the country table etc. |
|
461 | - * Also, models with no primary key are strange too. We combine use their primar key INDEX (a |
|
462 | - * combination of fields) to create a unique string identifying the row and store |
|
463 | - * those in the mapping. |
|
464 | - * |
|
465 | - * If the data is from the same database, we usually treat primary keys as real IDs. |
|
466 | - * An exception is if there is nothing in the database for that ID. If that's the case, |
|
467 | - * we need to insert a new row for that ID, and then map from the non-existent ID |
|
468 | - * to the newly-inserted real ID. |
|
469 | - * |
|
470 | - * @param type $csv_data_array |
|
471 | - * @param type $export_from_site_a_to_b |
|
472 | - * @param type $old_db_to_new_db_mapping |
|
473 | - * @return array updated $old_db_to_new_db_mapping |
|
474 | - */ |
|
475 | - public function save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping) |
|
476 | - { |
|
477 | - foreach ($csv_data_array as $model_name_in_csv_data => $model_data_from_import) { |
|
478 | - // now check that assumption was correct. If |
|
479 | - if (EE_Registry::instance()->is_model_name($model_name_in_csv_data)) { |
|
480 | - $model_name = $model_name_in_csv_data; |
|
481 | - } else { |
|
482 | - // no table info in the array and no table name passed to the function?? FAIL |
|
483 | - EE_Error::add_error( |
|
484 | - esc_html__( |
|
485 | - 'No table information was specified and/or found, therefore the import could not be completed', |
|
486 | - 'event_espresso' |
|
487 | - ), |
|
488 | - __FILE__, |
|
489 | - __FUNCTION__, |
|
490 | - __LINE__ |
|
491 | - ); |
|
492 | - return false; |
|
493 | - } |
|
494 | - /* @var $model EEM_Base */ |
|
495 | - $model = EE_Registry::instance()->load_model($model_name); |
|
496 | - |
|
497 | - // so without further ado, scanning all the data provided for primary keys and their inital values |
|
498 | - foreach ($model_data_from_import as $model_object_data) { |
|
499 | - // before we do ANYTHING, make sure the csv row wasn't just completely blank |
|
500 | - $row_is_completely_empty = true; |
|
501 | - foreach ($model_object_data as $field) { |
|
502 | - if ($field) { |
|
503 | - $row_is_completely_empty = false; |
|
504 | - } |
|
505 | - } |
|
506 | - if ($row_is_completely_empty) { |
|
507 | - continue; |
|
508 | - } |
|
509 | - // find the PK in the row of data (or a combined key if |
|
510 | - // there is no primary key) |
|
511 | - if ($model->has_primary_key_field()) { |
|
512 | - $id_in_csv = $model_object_data[ $model->primary_key_name() ]; |
|
513 | - } else { |
|
514 | - $id_in_csv = $model->get_index_primary_key_string($model_object_data); |
|
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - $model_object_data = $this->_replace_temp_ids_with_mappings( |
|
519 | - $model_object_data, |
|
520 | - $model, |
|
521 | - $old_db_to_new_db_mapping, |
|
522 | - $export_from_site_a_to_b |
|
523 | - ); |
|
524 | - // now we need to decide if we're going to add a new model object given the $model_object_data, |
|
525 | - // or just update. |
|
526 | - if ($export_from_site_a_to_b) { |
|
527 | - $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_other_db( |
|
528 | - $id_in_csv, |
|
529 | - $model_object_data, |
|
530 | - $model, |
|
531 | - $old_db_to_new_db_mapping |
|
532 | - ); |
|
533 | - } else {// this is just a re-import |
|
534 | - $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db( |
|
535 | - $id_in_csv, |
|
536 | - $model_object_data, |
|
537 | - $model, |
|
538 | - $old_db_to_new_db_mapping |
|
539 | - ); |
|
540 | - } |
|
541 | - if ($what_to_do == self::do_nothing) { |
|
542 | - continue; |
|
543 | - } |
|
544 | - |
|
545 | - // double-check we actually want to insert, if that's what we're planning |
|
546 | - // based on whether this item would be unique in the DB or not |
|
547 | - if ($what_to_do == self::do_insert) { |
|
548 | - // we're supposed to be inserting. But wait, will this thing |
|
549 | - // be acceptable if inserted? |
|
550 | - $conflicting = $model->get_one_conflicting($model_object_data, false); |
|
551 | - if ($conflicting) { |
|
552 | - // ok, this item would conflict if inserted. Just update the item that it conflicts with. |
|
553 | - $what_to_do = self::do_update; |
|
554 | - // and if this model has a primary key, remember its mapping |
|
555 | - if ($model->has_primary_key_field()) { |
|
556 | - $old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ] = $conflicting->ID(); |
|
557 | - $model_object_data[ $model->primary_key_name() ] = $conflicting->ID(); |
|
558 | - } else { |
|
559 | - // we want to update this conflicting item, instead of inserting a conflicting item |
|
560 | - // 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 |
|
561 | - // for the WHERE conditions in the update). At the time of this comment, there were no models like this |
|
562 | - foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
563 | - $model_object_data[ $key_field->get_name() ] = $conflicting->get( |
|
564 | - $key_field->get_name() |
|
565 | - ); |
|
566 | - } |
|
567 | - } |
|
568 | - } |
|
569 | - } |
|
570 | - if ($what_to_do == self::do_insert) { |
|
571 | - $old_db_to_new_db_mapping = $this->_insert_from_data_array( |
|
572 | - $id_in_csv, |
|
573 | - $model_object_data, |
|
574 | - $model, |
|
575 | - $old_db_to_new_db_mapping |
|
576 | - ); |
|
577 | - } elseif ($what_to_do == self::do_update) { |
|
578 | - $old_db_to_new_db_mapping = $this->_update_from_data_array( |
|
579 | - $id_in_csv, |
|
580 | - $model_object_data, |
|
581 | - $model, |
|
582 | - $old_db_to_new_db_mapping |
|
583 | - ); |
|
584 | - } else { |
|
585 | - throw new EE_Error( |
|
586 | - sprintf( |
|
587 | - esc_html__( |
|
588 | - 'Programming error. We shoudl be inserting or updating, but instead we are being told to "%s", whifh is invalid', |
|
589 | - 'event_espresso' |
|
590 | - ), |
|
591 | - $what_to_do |
|
592 | - ) |
|
593 | - ); |
|
594 | - } |
|
595 | - } |
|
596 | - } |
|
597 | - return $old_db_to_new_db_mapping; |
|
598 | - } |
|
599 | - |
|
600 | - |
|
601 | - /** |
|
602 | - * Decides whether or not to insert, given that this data is from another database. |
|
603 | - * So, if the primary key of this $model_object_data already exists in the database, |
|
604 | - * it's just a coincidence and we should still insert. The only time we should |
|
605 | - * update is when we know what it maps to, or there's something that would |
|
606 | - * conflict (and we should instead just update that conflicting thing) |
|
607 | - * |
|
608 | - * @param string $id_in_csv |
|
609 | - * @param array $model_object_data by reference so it can be modified |
|
610 | - * @param EEM_Base $model |
|
611 | - * @param array $old_db_to_new_db_mapping by reference so it can be modified |
|
612 | - * @return string one of the consts on this class that starts with do_* |
|
613 | - */ |
|
614 | - protected function _decide_whether_to_insert_or_update_given_data_from_other_db( |
|
615 | - $id_in_csv, |
|
616 | - $model_object_data, |
|
617 | - $model, |
|
618 | - $old_db_to_new_db_mapping |
|
619 | - ) { |
|
620 | - $model_name = $model->get_this_model_name(); |
|
621 | - // if it's a site-to-site export-and-import, see if this modelobject's id |
|
622 | - // in the old data that we know of |
|
623 | - if (isset($old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ])) { |
|
624 | - return self::do_update; |
|
625 | - } else { |
|
626 | - return self::do_insert; |
|
627 | - } |
|
628 | - } |
|
629 | - |
|
630 | - /** |
|
631 | - * If this thing basically already exists in the database, we want to update it; |
|
632 | - * otherwise insert it (ie, someone tweaked the CSV file, or the item was |
|
633 | - * deleted in the database so it should be re-inserted) |
|
634 | - * |
|
635 | - * @param type $id_in_csv |
|
636 | - * @param type $model_object_data |
|
637 | - * @param EEM_Base $model |
|
638 | - * @param type $old_db_to_new_db_mapping |
|
639 | - * @return |
|
640 | - */ |
|
641 | - protected function _decide_whether_to_insert_or_update_given_data_from_same_db( |
|
642 | - $id_in_csv, |
|
643 | - $model_object_data, |
|
644 | - $model |
|
645 | - ) { |
|
646 | - // in this case, check if this thing ACTUALLY exists in the database |
|
647 | - if ($model->get_one_conflicting($model_object_data)) { |
|
648 | - return self::do_update; |
|
649 | - } else { |
|
650 | - return self::do_insert; |
|
651 | - } |
|
652 | - } |
|
653 | - |
|
654 | - /** |
|
655 | - * Using the $old_db_to_new_db_mapping array, replaces all the temporary IDs |
|
656 | - * with their mapped real IDs. Eg, if importing from site A to B, the mapping |
|
657 | - * file may indicate that the ID "my_event_id" maps to an actual event ID of 123. |
|
658 | - * So this function searches for any event temp Ids called "my_event_id" and |
|
659 | - * replaces them with 123. |
|
660 | - * Also, if there is no temp ID for the INT foreign keys from another database, |
|
661 | - * replaces them with 0 or the field's default. |
|
662 | - * |
|
663 | - * @param type $model_object_data |
|
664 | - * @param EEM_Base $model |
|
665 | - * @param type $old_db_to_new_db_mapping |
|
666 | - * @param boolean $export_from_site_a_to_b |
|
667 | - * @return array updated model object data with temp IDs removed |
|
668 | - */ |
|
669 | - protected function _replace_temp_ids_with_mappings( |
|
670 | - $model_object_data, |
|
671 | - $model, |
|
672 | - $old_db_to_new_db_mapping, |
|
673 | - $export_from_site_a_to_b |
|
674 | - ) { |
|
675 | - // if this model object's primary key is in the mapping, replace it |
|
676 | - if ( |
|
677 | - $model->has_primary_key_field() && |
|
678 | - $model->get_primary_key_field()->is_auto_increment() && |
|
679 | - isset($old_db_to_new_db_mapping[ $model->get_this_model_name() ]) && |
|
680 | - isset( |
|
681 | - $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ] |
|
682 | - ) |
|
683 | - ) { |
|
684 | - $model_object_data[ $model->primary_key_name() ] = $old_db_to_new_db_mapping[ $model->get_this_model_name( |
|
685 | - ) ][ $model_object_data[ $model->primary_key_name() ] ]; |
|
686 | - } |
|
687 | - |
|
688 | - try { |
|
689 | - $model_name_field = $model->get_field_containing_related_model_name(); |
|
690 | - $models_pointed_to_by_model_name_field = $model_name_field->get_model_names_pointed_to(); |
|
691 | - } catch (EE_Error $e) { |
|
692 | - $model_name_field = null; |
|
693 | - $models_pointed_to_by_model_name_field = array(); |
|
694 | - } |
|
695 | - foreach ($model->field_settings(true) as $field_obj) { |
|
696 | - if ($field_obj instanceof EE_Foreign_Key_Int_Field) { |
|
697 | - $models_pointed_to = $field_obj->get_model_names_pointed_to(); |
|
698 | - $found_a_mapping = false; |
|
699 | - foreach ($models_pointed_to as $model_pointed_to_by_fk) { |
|
700 | - if ($model_name_field) { |
|
701 | - $value_of_model_name_field = $model_object_data[ $model_name_field->get_name() ]; |
|
702 | - if ($value_of_model_name_field == $model_pointed_to_by_fk) { |
|
703 | - $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
704 | - $model_object_data[ $field_obj->get_name() ], |
|
705 | - $model_pointed_to_by_fk, |
|
706 | - $old_db_to_new_db_mapping, |
|
707 | - $export_from_site_a_to_b |
|
708 | - ); |
|
709 | - $found_a_mapping = true; |
|
710 | - break; |
|
711 | - } |
|
712 | - } else { |
|
713 | - $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
714 | - $model_object_data[ $field_obj->get_name() ], |
|
715 | - $model_pointed_to_by_fk, |
|
716 | - $old_db_to_new_db_mapping, |
|
717 | - $export_from_site_a_to_b |
|
718 | - ); |
|
719 | - $found_a_mapping = true; |
|
720 | - } |
|
721 | - // once we've found a mapping for this field no need to continue |
|
722 | - if ($found_a_mapping) { |
|
723 | - break; |
|
724 | - } |
|
725 | - } |
|
726 | - } else { |
|
727 | - // it's a string foreign key (which we leave alone, because those are things |
|
728 | - // like country names, which we'd really rather not make 2 USAs etc (we'd actually |
|
729 | - // prefer to just update one) |
|
730 | - // or it's just a regular value that ought to be replaced |
|
731 | - } |
|
732 | - } |
|
733 | - // |
|
734 | - if ($model instanceof EEM_Term_Taxonomy) { |
|
735 | - $model_object_data = $this->_handle_split_term_ids($model_object_data); |
|
736 | - } |
|
737 | - return $model_object_data; |
|
738 | - } |
|
739 | - |
|
740 | - /** |
|
741 | - * If the data was exported PRE-4.2, but then imported POST-4.2, then the term_id |
|
742 | - * this term-taxonomy refers to may be out-of-date so we need to update it. |
|
743 | - * see https://make.wordpress.org/core/2015/02/16/taxonomy-term-splitting-in-4-2-a-developer-guide/ |
|
744 | - * |
|
745 | - * @param type $model_object_data |
|
746 | - * @return array new model object data |
|
747 | - */ |
|
748 | - protected function _handle_split_term_ids($model_object_data) |
|
749 | - { |
|
750 | - if ( |
|
751 | - isset($model_object_data['term_id']) |
|
752 | - && isset($model_object_data['taxonomy']) |
|
753 | - && apply_filters( |
|
754 | - 'FHEE__EE_Import__handle_split_term_ids__function_exists', |
|
755 | - function_exists('wp_get_split_term'), |
|
756 | - $model_object_data |
|
757 | - ) |
|
758 | - ) { |
|
759 | - $new_term_id = wp_get_split_term($model_object_data['term_id'], $model_object_data['taxonomy']); |
|
760 | - if ($new_term_id) { |
|
761 | - $model_object_data['term_id'] = $new_term_id; |
|
762 | - } |
|
763 | - } |
|
764 | - return $model_object_data; |
|
765 | - } |
|
766 | - |
|
767 | - /** |
|
768 | - * Given the object's ID and its model's name, find it int he mapping data, |
|
769 | - * bearing in mind where it came from |
|
770 | - * |
|
771 | - * @param type $object_id |
|
772 | - * @param string $model_name |
|
773 | - * @param array $old_db_to_new_db_mapping |
|
774 | - * @param type $export_from_site_a_to_b |
|
775 | - * @return int |
|
776 | - */ |
|
777 | - protected function _find_mapping_in($object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) |
|
778 | - { |
|
779 | - if (isset($old_db_to_new_db_mapping[ $model_name ][ $object_id ])) { |
|
780 | - return $old_db_to_new_db_mapping[ $model_name ][ $object_id ]; |
|
781 | - } elseif ($object_id == '0' || $object_id == '') { |
|
782 | - // leave as-is |
|
783 | - return $object_id; |
|
784 | - } elseif ($export_from_site_a_to_b) { |
|
785 | - // we couldn't find a mapping for this, and it's from a different site, |
|
786 | - // so blank it out |
|
787 | - return null; |
|
788 | - } elseif (! $export_from_site_a_to_b) { |
|
789 | - // we coudln't find a mapping for this, but it's from thsi DB anyway |
|
790 | - // so let's just leave it as-is |
|
791 | - return $object_id; |
|
792 | - } |
|
793 | - } |
|
794 | - |
|
795 | - /** |
|
796 | - * |
|
797 | - * @param type $id_in_csv |
|
798 | - * @param type $model_object_data |
|
799 | - * @param EEM_Base $model |
|
800 | - * @param type $old_db_to_new_db_mapping |
|
801 | - * @return array updated $old_db_to_new_db_mapping |
|
802 | - */ |
|
803 | - protected function _insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) |
|
804 | - { |
|
805 | - // remove the primary key, if there is one (we don't want it for inserts OR updates) |
|
806 | - // we'll put it back in if we need it |
|
807 | - if ($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()) { |
|
808 | - $effective_id = $model_object_data[ $model->primary_key_name() ]; |
|
809 | - unset($model_object_data[ $model->primary_key_name() ]); |
|
810 | - } else { |
|
811 | - $effective_id = $model->get_index_primary_key_string($model_object_data); |
|
812 | - } |
|
813 | - // the model takes care of validating the CSV's input |
|
814 | - try { |
|
815 | - $new_id = $model->insert($model_object_data); |
|
816 | - if ($new_id) { |
|
817 | - $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_id; |
|
818 | - $this->_total_inserts++; |
|
819 | - EE_Error::add_success( |
|
820 | - sprintf( |
|
821 | - esc_html__("Successfully added new %s (with id %s) with csv data %s", "event_espresso"), |
|
822 | - $model->get_this_model_name(), |
|
823 | - $new_id, |
|
824 | - implode(",", $model_object_data) |
|
825 | - ) |
|
826 | - ); |
|
827 | - } else { |
|
828 | - $this->_total_insert_errors++; |
|
829 | - // put the ID used back in there for the error message |
|
830 | - if ($model->has_primary_key_field()) { |
|
831 | - $model_object_data[ $model->primary_key_name() ] = $effective_id; |
|
832 | - } |
|
833 | - EE_Error::add_error( |
|
834 | - sprintf( |
|
835 | - esc_html__("Could not insert new %s with the csv data: %s", "event_espresso"), |
|
836 | - $model->get_this_model_name(), |
|
837 | - http_build_query($model_object_data) |
|
838 | - ), |
|
839 | - __FILE__, |
|
840 | - __FUNCTION__, |
|
841 | - __LINE__ |
|
842 | - ); |
|
843 | - } |
|
844 | - } catch (EE_Error $e) { |
|
845 | - $this->_total_insert_errors++; |
|
846 | - if ($model->has_primary_key_field()) { |
|
847 | - $model_object_data[ $model->primary_key_name() ] = $effective_id; |
|
848 | - } |
|
849 | - EE_Error::add_error( |
|
850 | - sprintf( |
|
851 | - esc_html__("Could not insert new %s with the csv data: %s because %s", "event_espresso"), |
|
852 | - $model->get_this_model_name(), |
|
853 | - implode(",", $model_object_data), |
|
854 | - $e->getMessage() |
|
855 | - ), |
|
856 | - __FILE__, |
|
857 | - __FUNCTION__, |
|
858 | - __LINE__ |
|
859 | - ); |
|
860 | - } |
|
861 | - return $old_db_to_new_db_mapping; |
|
862 | - } |
|
863 | - |
|
864 | - /** |
|
865 | - * Given the model object data, finds the row to update and updates it |
|
866 | - * |
|
867 | - * @param string|int $id_in_csv |
|
868 | - * @param array $model_object_data |
|
869 | - * @param EEM_Base $model |
|
870 | - * @param array $old_db_to_new_db_mapping |
|
871 | - * @return array updated $old_db_to_new_db_mapping |
|
872 | - */ |
|
873 | - protected function _update_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) |
|
874 | - { |
|
875 | - try { |
|
876 | - // let's keep two copies of the model object data: |
|
877 | - // one for performing an update, one for everthing else |
|
878 | - $model_object_data_for_update = $model_object_data; |
|
879 | - if ($model->has_primary_key_field()) { |
|
880 | - $conditions = array($model->primary_key_name() => $model_object_data[ $model->primary_key_name() ]); |
|
881 | - // remove the primary key because we shouldn't use it for updating |
|
882 | - unset($model_object_data_for_update[ $model->primary_key_name() ]); |
|
883 | - } elseif ($model->get_combined_primary_key_fields() > 1) { |
|
884 | - $conditions = array(); |
|
885 | - foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
886 | - $conditions[ $key_field->get_name() ] = $model_object_data[ $key_field->get_name() ]; |
|
887 | - } |
|
888 | - } else { |
|
889 | - $model->primary_key_name( |
|
890 | - );// this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey) |
|
891 | - } |
|
892 | - |
|
893 | - $success = $model->update($model_object_data_for_update, array($conditions)); |
|
894 | - if ($success) { |
|
895 | - $this->_total_updates++; |
|
896 | - EE_Error::add_success( |
|
897 | - sprintf( |
|
898 | - esc_html__("Successfully updated %s with csv data %s", "event_espresso"), |
|
899 | - $model->get_this_model_name(), |
|
900 | - implode(",", $model_object_data_for_update) |
|
901 | - ) |
|
902 | - ); |
|
903 | - // we should still record the mapping even though it was an update |
|
904 | - // because if we were going to insert somethign but it was going to conflict |
|
905 | - // we would have last-minute decided to update. So we'd like to know what we updated |
|
906 | - // and so we record what record ended up being updated using the mapping |
|
907 | - if ($model->has_primary_key_field()) { |
|
908 | - $new_key_for_mapping = $model_object_data[ $model->primary_key_name() ]; |
|
909 | - } else { |
|
910 | - // no primary key just a combined key |
|
911 | - $new_key_for_mapping = $model->get_index_primary_key_string($model_object_data); |
|
912 | - } |
|
913 | - $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_key_for_mapping; |
|
914 | - } else { |
|
915 | - $matched_items = $model->get_all(array($conditions)); |
|
916 | - if (! $matched_items) { |
|
917 | - // no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck? |
|
918 | - $this->_total_update_errors++; |
|
919 | - EE_Error::add_error( |
|
920 | - sprintf( |
|
921 | - esc_html__( |
|
922 | - "Could not update %s with the csv data: '%s' for an unknown reason (using WHERE conditions %s)", |
|
923 | - "event_espresso" |
|
924 | - ), |
|
925 | - $model->get_this_model_name(), |
|
926 | - http_build_query($model_object_data), |
|
927 | - http_build_query($conditions) |
|
928 | - ), |
|
929 | - __FILE__, |
|
930 | - __FUNCTION__, |
|
931 | - __LINE__ |
|
932 | - ); |
|
933 | - } else { |
|
934 | - $this->_total_updates++; |
|
935 | - EE_Error::add_success( |
|
936 | - sprintf( |
|
937 | - esc_html__( |
|
938 | - "%s with csv data '%s' was found in the database and didn't need updating because all the data is identical.", |
|
939 | - "event_espresso" |
|
940 | - ), |
|
941 | - $model->get_this_model_name(), |
|
942 | - implode(",", $model_object_data) |
|
943 | - ) |
|
944 | - ); |
|
945 | - } |
|
946 | - } |
|
947 | - } catch (EE_Error $e) { |
|
948 | - $this->_total_update_errors++; |
|
949 | - $basic_message = sprintf( |
|
950 | - esc_html__("Could not update %s with the csv data: %s because %s", "event_espresso"), |
|
951 | - $model->get_this_model_name(), |
|
952 | - implode(",", $model_object_data), |
|
953 | - $e->getMessage() |
|
954 | - ); |
|
955 | - $debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString(); |
|
956 | - EE_Error::add_error("$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__); |
|
957 | - } |
|
958 | - return $old_db_to_new_db_mapping; |
|
959 | - } |
|
960 | - |
|
961 | - /** |
|
962 | - * Gets the number of inserts performed since importer was instantiated or reset |
|
963 | - * |
|
964 | - * @return int |
|
965 | - */ |
|
966 | - public function get_total_inserts() |
|
967 | - { |
|
968 | - return $this->_total_inserts; |
|
969 | - } |
|
970 | - |
|
971 | - /** |
|
972 | - * Gets the number of insert errors since importer was instantiated or reset |
|
973 | - * |
|
974 | - * @return int |
|
975 | - */ |
|
976 | - public function get_total_insert_errors() |
|
977 | - { |
|
978 | - return $this->_total_insert_errors; |
|
979 | - } |
|
980 | - |
|
981 | - /** |
|
982 | - * Gets the number of updates performed since importer was instantiated or reset |
|
983 | - * |
|
984 | - * @return int |
|
985 | - */ |
|
986 | - public function get_total_updates() |
|
987 | - { |
|
988 | - return $this->_total_updates; |
|
989 | - } |
|
990 | - |
|
991 | - /** |
|
992 | - * Gets the number of update errors since importer was instantiated or reset |
|
993 | - * |
|
994 | - * @return int |
|
995 | - */ |
|
996 | - public function get_total_update_errors() |
|
997 | - { |
|
998 | - return $this->_total_update_errors; |
|
999 | - } |
|
130 | + $uploader = ob_get_clean(); |
|
131 | + return $uploader; |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * @Import Event Espresso data - some code "borrowed" from event espresso csv_import.php |
|
137 | + * @access public |
|
138 | + * @return boolean success |
|
139 | + */ |
|
140 | + public function import() |
|
141 | + { |
|
142 | + |
|
143 | + require_once(EE_CLASSES . 'EE_CSV.class.php'); |
|
144 | + $this->EE_CSV = EE_CSV::instance(); |
|
145 | + |
|
146 | + /** @var RequestInterface $request */ |
|
147 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
148 | + |
|
149 | + if ($request->requestParamIsSet('import') && $request->requestParamIsSet('csv_submitted')) { |
|
150 | + $files = $request->filesParams(); |
|
151 | + switch ($files['file']['error'][0]) { |
|
152 | + case UPLOAD_ERR_OK: |
|
153 | + $error_msg = false; |
|
154 | + break; |
|
155 | + case UPLOAD_ERR_INI_SIZE: |
|
156 | + $error_msg = esc_html__( |
|
157 | + "'The uploaded file exceeds the upload_max_filesize directive in php.ini.'", |
|
158 | + "event_espresso" |
|
159 | + ); |
|
160 | + break; |
|
161 | + case UPLOAD_ERR_FORM_SIZE: |
|
162 | + $error_msg = esc_html__( |
|
163 | + 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', |
|
164 | + "event_espresso" |
|
165 | + ); |
|
166 | + break; |
|
167 | + case UPLOAD_ERR_PARTIAL: |
|
168 | + $error_msg = esc_html__('The uploaded file was only partially uploaded.', "event_espresso"); |
|
169 | + break; |
|
170 | + case UPLOAD_ERR_NO_FILE: |
|
171 | + $error_msg = esc_html__('No file was uploaded.', "event_espresso"); |
|
172 | + break; |
|
173 | + case UPLOAD_ERR_NO_TMP_DIR: |
|
174 | + $error_msg = esc_html__('Missing a temporary folder.', "event_espresso"); |
|
175 | + break; |
|
176 | + case UPLOAD_ERR_CANT_WRITE: |
|
177 | + $error_msg = esc_html__('Failed to write file to disk.', "event_espresso"); |
|
178 | + break; |
|
179 | + case UPLOAD_ERR_EXTENSION: |
|
180 | + $error_msg = esc_html__('File upload stopped by extension.', "event_espresso"); |
|
181 | + break; |
|
182 | + default: |
|
183 | + $error_msg = esc_html__( |
|
184 | + 'An unknown error occurred and the file could not be uploaded', |
|
185 | + "event_espresso" |
|
186 | + ); |
|
187 | + break; |
|
188 | + } |
|
189 | + |
|
190 | + if (! $error_msg) { |
|
191 | + $filename = $files['file']['name'][0]; |
|
192 | + $file_ext = substr(strrchr($filename, '.'), 1); |
|
193 | + $file_type = $files['file']['type'][0]; |
|
194 | + $temp_file = $files['file']['tmp_name'][0]; |
|
195 | + $filesize = $files['file']['size'][0] / 1024;// convert from bytes to KB |
|
196 | + |
|
197 | + if ($file_ext == 'csv') { |
|
198 | + $max_upload = $this->EE_CSV->get_max_upload_size();// max upload size in KB |
|
199 | + if ($filesize < $max_upload || true) { |
|
200 | + $wp_upload_dir = str_replace(array('\\', '/'), '/', wp_upload_dir()); |
|
201 | + $path_to_file = $wp_upload_dir['basedir'] . '/espresso/' . $filename; |
|
202 | + |
|
203 | + if (move_uploaded_file($temp_file, $path_to_file)) { |
|
204 | + // convert csv to array |
|
205 | + $this->csv_array = $this->EE_CSV->import_csv_to_model_data_array($path_to_file); |
|
206 | + |
|
207 | + $action = $request->getRequestParam('action'); |
|
208 | + |
|
209 | + // was data successfully stored in an array? |
|
210 | + if (is_array($this->csv_array)) { |
|
211 | + $import_what = str_replace('csv_import_', '', $action); |
|
212 | + $import_what = str_replace('_', ' ', ucwords($import_what)); |
|
213 | + $processed_data = $this->csv_array; |
|
214 | + $this->columns_to_save = false; |
|
215 | + |
|
216 | + // if any imports require funky processing, we'll catch them in the switch |
|
217 | + switch ($action) { |
|
218 | + case "import_events": |
|
219 | + case "event_list": |
|
220 | + $import_what = 'Event Details'; |
|
221 | + break; |
|
222 | + |
|
223 | + case 'groupon_import_csv': |
|
224 | + $import_what = 'Groupon Codes'; |
|
225 | + $processed_data = $this->process_groupon_codes(); |
|
226 | + break; |
|
227 | + } |
|
228 | + // save processed codes to db |
|
229 | + if ($this->save_csv_data_array_to_db($processed_data, $this->columns_to_save)) { |
|
230 | + return true; |
|
231 | + } |
|
232 | + } else { |
|
233 | + // no array? must be an error |
|
234 | + EE_Error::add_error( |
|
235 | + sprintf(esc_html__("No file seems to have been uploaded", "event_espresso")), |
|
236 | + __FILE__, |
|
237 | + __FUNCTION__, |
|
238 | + __LINE__ |
|
239 | + ); |
|
240 | + return false; |
|
241 | + } |
|
242 | + } else { |
|
243 | + EE_Error::add_error( |
|
244 | + sprintf(esc_html__("%s was not successfully uploaded", "event_espresso"), $filename), |
|
245 | + __FILE__, |
|
246 | + __FUNCTION__, |
|
247 | + __LINE__ |
|
248 | + ); |
|
249 | + return false; |
|
250 | + } |
|
251 | + } else { |
|
252 | + EE_Error::add_error( |
|
253 | + sprintf( |
|
254 | + esc_html__( |
|
255 | + "%s was too large of a file and could not be uploaded. The max filesize is %s' KB.", |
|
256 | + "event_espresso" |
|
257 | + ), |
|
258 | + $filename, |
|
259 | + $max_upload |
|
260 | + ), |
|
261 | + __FILE__, |
|
262 | + __FUNCTION__, |
|
263 | + __LINE__ |
|
264 | + ); |
|
265 | + return false; |
|
266 | + } |
|
267 | + } else { |
|
268 | + EE_Error::add_error( |
|
269 | + sprintf(esc_html__("%s had an invalid file extension, not uploaded", "event_espresso"), $filename), |
|
270 | + __FILE__, |
|
271 | + __FUNCTION__, |
|
272 | + __LINE__ |
|
273 | + ); |
|
274 | + return false; |
|
275 | + } |
|
276 | + } else { |
|
277 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
278 | + return false; |
|
279 | + } |
|
280 | + } |
|
281 | + return false; |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * Given an array of data (usually from a CSV import) attempts to save that data to the db. |
|
287 | + * If $model_name ISN'T provided, assumes that this is a 3d array, with toplevel keys being model names, |
|
288 | + * next level being numeric indexes adn each value representing a model object, and the last layer down |
|
289 | + * being keys of model fields and their proposed values. |
|
290 | + * If $model_name IS provided, assumes a 2d array of the bottom two layers previously mentioned. |
|
291 | + * If the CSV data says (in the metadata row) that it's from the SAME database, |
|
292 | + * we treat the IDs in the CSV as the normal IDs, and try to update those records. However, if those |
|
293 | + * IDs DON'T exist in the database, they're treated as temporary IDs, |
|
294 | + * which can used elsewhere to refer to the same object. Once an item |
|
295 | + * with a temporary ID gets inserted, we record its mapping from temporary |
|
296 | + * ID to real ID, and use the real ID in place of the temporary ID |
|
297 | + * when that temporary ID was used as a foreign key. |
|
298 | + * If the CSV data says (in the metadata again) that it's from a DIFFERENT database, |
|
299 | + * we treat all the IDs in the CSV as temporary ID- eg, if the CSV specifies an event with |
|
300 | + * ID 1, and the database already has an event with ID 1, we assume that's just a coincidence, |
|
301 | + * and insert a new event, and map it's temporary ID of 1 over to its new real ID. |
|
302 | + * An important exception are non-auto-increment primary keys. If one entry in the |
|
303 | + * CSV file has the same ID as one in the DB, we assume they are meant to be |
|
304 | + * the same item, and instead update the item in the DB with that same ID. |
|
305 | + * Also note, we remember the mappings permanently. So the 2nd, 3rd, and 10000th |
|
306 | + * time you import a CSV from a different site, we remember their mappings, and |
|
307 | + * will try to update the item in the DB instead of inserting another item (eg |
|
308 | + * if we previously imported an event with temporary ID 1, and then it got a |
|
309 | + * real ID of 123, we remember that. So the next time we import an event with |
|
310 | + * temporary ID, from the same site, we know that it's real ID is 123, and will |
|
311 | + * update that event, instead of adding a new event). |
|
312 | + * |
|
313 | + * @access public |
|
314 | + * @param array $csv_data_array - the array containing the csv data produced from |
|
315 | + * EE_CSV::import_csv_to_model_data_array() |
|
316 | + * @param array $fields_to_save - an array containing the csv column names as keys with the corresponding db table |
|
317 | + * fields they will be saved to |
|
318 | + * @return TRUE on success, FALSE on fail |
|
319 | + * @throws \EE_Error |
|
320 | + */ |
|
321 | + public function save_csv_data_array_to_db($csv_data_array, $model_name = false) |
|
322 | + { |
|
323 | + $success = false; |
|
324 | + $error = false; |
|
325 | + // whther to treat this import as if it's data froma different database or not |
|
326 | + // ie, if it IS from a different database, ignore foreign keys whihf |
|
327 | + $export_from_site_a_to_b = true; |
|
328 | + // first level of array is not table information but a table name was passed to the function |
|
329 | + // array is only two levels deep, so let's fix that by adding a level, else the next steps will fail |
|
330 | + if ($model_name) { |
|
331 | + $csv_data_array = array($csv_data_array); |
|
332 | + } |
|
333 | + // begin looking through the $csv_data_array, expecting the toplevel key to be the model's name... |
|
334 | + $old_site_url = 'none-specified'; |
|
335 | + // hanlde metadata |
|
336 | + if (isset($csv_data_array[ EE_CSV::metadata_header ])) { |
|
337 | + $csv_metadata = array_shift($csv_data_array[ EE_CSV::metadata_header ]); |
|
338 | + // ok so its metadata, dont try to save it to ehte db obviously... |
|
339 | + if (isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()) { |
|
340 | + EE_Error::add_attention( |
|
341 | + sprintf( |
|
342 | + esc_html__( |
|
343 | + "CSV Data appears to be from the same database, so attempting to update data", |
|
344 | + "event_espresso" |
|
345 | + ) |
|
346 | + ) |
|
347 | + ); |
|
348 | + $export_from_site_a_to_b = false; |
|
349 | + } else { |
|
350 | + $old_site_url = isset($csv_metadata['site_url']) ? $csv_metadata['site_url'] : $old_site_url; |
|
351 | + EE_Error::add_attention( |
|
352 | + sprintf( |
|
353 | + esc_html__( |
|
354 | + "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", |
|
355 | + "event_espresso" |
|
356 | + ), |
|
357 | + $old_site_url, |
|
358 | + site_url() |
|
359 | + ) |
|
360 | + ); |
|
361 | + }; |
|
362 | + unset($csv_data_array[ EE_CSV::metadata_header ]); |
|
363 | + } |
|
364 | + /** |
|
365 | + * @var $old_db_to_new_db_mapping 2d array: toplevel keys being model names, bottom-level keys being the original key, and |
|
366 | + * the value will be the newly-inserted ID. |
|
367 | + * If we have already imported data from the same website via CSV, it shoudl be kept in this wp option |
|
368 | + */ |
|
369 | + $old_db_to_new_db_mapping = get_option('ee_id_mapping_from' . sanitize_title($old_site_url), array()); |
|
370 | + if ($old_db_to_new_db_mapping) { |
|
371 | + EE_Error::add_attention( |
|
372 | + sprintf( |
|
373 | + esc_html__( |
|
374 | + "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", |
|
375 | + "event_espresso" |
|
376 | + ), |
|
377 | + $old_site_url, |
|
378 | + site_url() |
|
379 | + ) |
|
380 | + ); |
|
381 | + } |
|
382 | + $old_db_to_new_db_mapping = $this->save_data_rows_to_db( |
|
383 | + $csv_data_array, |
|
384 | + $export_from_site_a_to_b, |
|
385 | + $old_db_to_new_db_mapping |
|
386 | + ); |
|
387 | + |
|
388 | + // save the mapping from old db to new db in case they try re-importing the same data from the same website again |
|
389 | + update_option('ee_id_mapping_from' . sanitize_title($old_site_url), $old_db_to_new_db_mapping); |
|
390 | + |
|
391 | + if ($this->_total_updates > 0) { |
|
392 | + EE_Error::add_success( |
|
393 | + sprintf( |
|
394 | + esc_html__("%s existing records in the database were updated.", "event_espresso"), |
|
395 | + $this->_total_updates |
|
396 | + ) |
|
397 | + ); |
|
398 | + $success = true; |
|
399 | + } |
|
400 | + if ($this->_total_inserts > 0) { |
|
401 | + EE_Error::add_success( |
|
402 | + sprintf(esc_html__("%s new records were added to the database.", "event_espresso"), $this->_total_inserts) |
|
403 | + ); |
|
404 | + $success = true; |
|
405 | + } |
|
406 | + |
|
407 | + if ($this->_total_update_errors > 0) { |
|
408 | + EE_Error::add_error( |
|
409 | + sprintf( |
|
410 | + esc_html__( |
|
411 | + "'One or more errors occurred, and a total of %s existing records in the database were <strong>not</strong> updated.'", |
|
412 | + "event_espresso" |
|
413 | + ), |
|
414 | + $this->_total_update_errors |
|
415 | + ), |
|
416 | + __FILE__, |
|
417 | + __FUNCTION__, |
|
418 | + __LINE__ |
|
419 | + ); |
|
420 | + $error = true; |
|
421 | + } |
|
422 | + if ($this->_total_insert_errors > 0) { |
|
423 | + EE_Error::add_error( |
|
424 | + sprintf( |
|
425 | + esc_html__( |
|
426 | + "One or more errors occurred, and a total of %s new records were <strong>not</strong> added to the database.'", |
|
427 | + "event_espresso" |
|
428 | + ), |
|
429 | + $this->_total_insert_errors |
|
430 | + ), |
|
431 | + __FILE__, |
|
432 | + __FUNCTION__, |
|
433 | + __LINE__ |
|
434 | + ); |
|
435 | + $error = true; |
|
436 | + } |
|
437 | + |
|
438 | + // lastly, we need to update the datetime and ticket sold amounts |
|
439 | + // as those may have been affected by this |
|
440 | + EEM_Ticket::instance()->update_tickets_sold(EEM_Ticket::instance()->get_all()); |
|
441 | + |
|
442 | + // if there was at least one success and absolutely no errors |
|
443 | + if ($success && ! $error) { |
|
444 | + return true; |
|
445 | + } else { |
|
446 | + return false; |
|
447 | + } |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * Processes the array of data, given the knowledge that it's from the same database or a different one, |
|
453 | + * and the mapping from temporary IDs to real IDs. |
|
454 | + * If the data is from a different database, we treat the primary keys and their corresponding |
|
455 | + * foreign keys as "temp Ids", basically identifiers that get mapped to real primary keys |
|
456 | + * in the real target database. As items are inserted, their temporary primary keys |
|
457 | + * are mapped to the real IDs in the target database. Also, before doing any update or |
|
458 | + * insert, we replace all the temp ID which are foreign keys with their mapped real IDs. |
|
459 | + * An exception: string primary keys are treated as real IDs, or else we'd need to |
|
460 | + * dynamically generate new string primary keys which would be very awkard for the country table etc. |
|
461 | + * Also, models with no primary key are strange too. We combine use their primar key INDEX (a |
|
462 | + * combination of fields) to create a unique string identifying the row and store |
|
463 | + * those in the mapping. |
|
464 | + * |
|
465 | + * If the data is from the same database, we usually treat primary keys as real IDs. |
|
466 | + * An exception is if there is nothing in the database for that ID. If that's the case, |
|
467 | + * we need to insert a new row for that ID, and then map from the non-existent ID |
|
468 | + * to the newly-inserted real ID. |
|
469 | + * |
|
470 | + * @param type $csv_data_array |
|
471 | + * @param type $export_from_site_a_to_b |
|
472 | + * @param type $old_db_to_new_db_mapping |
|
473 | + * @return array updated $old_db_to_new_db_mapping |
|
474 | + */ |
|
475 | + public function save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping) |
|
476 | + { |
|
477 | + foreach ($csv_data_array as $model_name_in_csv_data => $model_data_from_import) { |
|
478 | + // now check that assumption was correct. If |
|
479 | + if (EE_Registry::instance()->is_model_name($model_name_in_csv_data)) { |
|
480 | + $model_name = $model_name_in_csv_data; |
|
481 | + } else { |
|
482 | + // no table info in the array and no table name passed to the function?? FAIL |
|
483 | + EE_Error::add_error( |
|
484 | + esc_html__( |
|
485 | + 'No table information was specified and/or found, therefore the import could not be completed', |
|
486 | + 'event_espresso' |
|
487 | + ), |
|
488 | + __FILE__, |
|
489 | + __FUNCTION__, |
|
490 | + __LINE__ |
|
491 | + ); |
|
492 | + return false; |
|
493 | + } |
|
494 | + /* @var $model EEM_Base */ |
|
495 | + $model = EE_Registry::instance()->load_model($model_name); |
|
496 | + |
|
497 | + // so without further ado, scanning all the data provided for primary keys and their inital values |
|
498 | + foreach ($model_data_from_import as $model_object_data) { |
|
499 | + // before we do ANYTHING, make sure the csv row wasn't just completely blank |
|
500 | + $row_is_completely_empty = true; |
|
501 | + foreach ($model_object_data as $field) { |
|
502 | + if ($field) { |
|
503 | + $row_is_completely_empty = false; |
|
504 | + } |
|
505 | + } |
|
506 | + if ($row_is_completely_empty) { |
|
507 | + continue; |
|
508 | + } |
|
509 | + // find the PK in the row of data (or a combined key if |
|
510 | + // there is no primary key) |
|
511 | + if ($model->has_primary_key_field()) { |
|
512 | + $id_in_csv = $model_object_data[ $model->primary_key_name() ]; |
|
513 | + } else { |
|
514 | + $id_in_csv = $model->get_index_primary_key_string($model_object_data); |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + $model_object_data = $this->_replace_temp_ids_with_mappings( |
|
519 | + $model_object_data, |
|
520 | + $model, |
|
521 | + $old_db_to_new_db_mapping, |
|
522 | + $export_from_site_a_to_b |
|
523 | + ); |
|
524 | + // now we need to decide if we're going to add a new model object given the $model_object_data, |
|
525 | + // or just update. |
|
526 | + if ($export_from_site_a_to_b) { |
|
527 | + $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_other_db( |
|
528 | + $id_in_csv, |
|
529 | + $model_object_data, |
|
530 | + $model, |
|
531 | + $old_db_to_new_db_mapping |
|
532 | + ); |
|
533 | + } else {// this is just a re-import |
|
534 | + $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db( |
|
535 | + $id_in_csv, |
|
536 | + $model_object_data, |
|
537 | + $model, |
|
538 | + $old_db_to_new_db_mapping |
|
539 | + ); |
|
540 | + } |
|
541 | + if ($what_to_do == self::do_nothing) { |
|
542 | + continue; |
|
543 | + } |
|
544 | + |
|
545 | + // double-check we actually want to insert, if that's what we're planning |
|
546 | + // based on whether this item would be unique in the DB or not |
|
547 | + if ($what_to_do == self::do_insert) { |
|
548 | + // we're supposed to be inserting. But wait, will this thing |
|
549 | + // be acceptable if inserted? |
|
550 | + $conflicting = $model->get_one_conflicting($model_object_data, false); |
|
551 | + if ($conflicting) { |
|
552 | + // ok, this item would conflict if inserted. Just update the item that it conflicts with. |
|
553 | + $what_to_do = self::do_update; |
|
554 | + // and if this model has a primary key, remember its mapping |
|
555 | + if ($model->has_primary_key_field()) { |
|
556 | + $old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ] = $conflicting->ID(); |
|
557 | + $model_object_data[ $model->primary_key_name() ] = $conflicting->ID(); |
|
558 | + } else { |
|
559 | + // we want to update this conflicting item, instead of inserting a conflicting item |
|
560 | + // 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 |
|
561 | + // for the WHERE conditions in the update). At the time of this comment, there were no models like this |
|
562 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
563 | + $model_object_data[ $key_field->get_name() ] = $conflicting->get( |
|
564 | + $key_field->get_name() |
|
565 | + ); |
|
566 | + } |
|
567 | + } |
|
568 | + } |
|
569 | + } |
|
570 | + if ($what_to_do == self::do_insert) { |
|
571 | + $old_db_to_new_db_mapping = $this->_insert_from_data_array( |
|
572 | + $id_in_csv, |
|
573 | + $model_object_data, |
|
574 | + $model, |
|
575 | + $old_db_to_new_db_mapping |
|
576 | + ); |
|
577 | + } elseif ($what_to_do == self::do_update) { |
|
578 | + $old_db_to_new_db_mapping = $this->_update_from_data_array( |
|
579 | + $id_in_csv, |
|
580 | + $model_object_data, |
|
581 | + $model, |
|
582 | + $old_db_to_new_db_mapping |
|
583 | + ); |
|
584 | + } else { |
|
585 | + throw new EE_Error( |
|
586 | + sprintf( |
|
587 | + esc_html__( |
|
588 | + 'Programming error. We shoudl be inserting or updating, but instead we are being told to "%s", whifh is invalid', |
|
589 | + 'event_espresso' |
|
590 | + ), |
|
591 | + $what_to_do |
|
592 | + ) |
|
593 | + ); |
|
594 | + } |
|
595 | + } |
|
596 | + } |
|
597 | + return $old_db_to_new_db_mapping; |
|
598 | + } |
|
599 | + |
|
600 | + |
|
601 | + /** |
|
602 | + * Decides whether or not to insert, given that this data is from another database. |
|
603 | + * So, if the primary key of this $model_object_data already exists in the database, |
|
604 | + * it's just a coincidence and we should still insert. The only time we should |
|
605 | + * update is when we know what it maps to, or there's something that would |
|
606 | + * conflict (and we should instead just update that conflicting thing) |
|
607 | + * |
|
608 | + * @param string $id_in_csv |
|
609 | + * @param array $model_object_data by reference so it can be modified |
|
610 | + * @param EEM_Base $model |
|
611 | + * @param array $old_db_to_new_db_mapping by reference so it can be modified |
|
612 | + * @return string one of the consts on this class that starts with do_* |
|
613 | + */ |
|
614 | + protected function _decide_whether_to_insert_or_update_given_data_from_other_db( |
|
615 | + $id_in_csv, |
|
616 | + $model_object_data, |
|
617 | + $model, |
|
618 | + $old_db_to_new_db_mapping |
|
619 | + ) { |
|
620 | + $model_name = $model->get_this_model_name(); |
|
621 | + // if it's a site-to-site export-and-import, see if this modelobject's id |
|
622 | + // in the old data that we know of |
|
623 | + if (isset($old_db_to_new_db_mapping[ $model_name ][ $id_in_csv ])) { |
|
624 | + return self::do_update; |
|
625 | + } else { |
|
626 | + return self::do_insert; |
|
627 | + } |
|
628 | + } |
|
629 | + |
|
630 | + /** |
|
631 | + * If this thing basically already exists in the database, we want to update it; |
|
632 | + * otherwise insert it (ie, someone tweaked the CSV file, or the item was |
|
633 | + * deleted in the database so it should be re-inserted) |
|
634 | + * |
|
635 | + * @param type $id_in_csv |
|
636 | + * @param type $model_object_data |
|
637 | + * @param EEM_Base $model |
|
638 | + * @param type $old_db_to_new_db_mapping |
|
639 | + * @return |
|
640 | + */ |
|
641 | + protected function _decide_whether_to_insert_or_update_given_data_from_same_db( |
|
642 | + $id_in_csv, |
|
643 | + $model_object_data, |
|
644 | + $model |
|
645 | + ) { |
|
646 | + // in this case, check if this thing ACTUALLY exists in the database |
|
647 | + if ($model->get_one_conflicting($model_object_data)) { |
|
648 | + return self::do_update; |
|
649 | + } else { |
|
650 | + return self::do_insert; |
|
651 | + } |
|
652 | + } |
|
653 | + |
|
654 | + /** |
|
655 | + * Using the $old_db_to_new_db_mapping array, replaces all the temporary IDs |
|
656 | + * with their mapped real IDs. Eg, if importing from site A to B, the mapping |
|
657 | + * file may indicate that the ID "my_event_id" maps to an actual event ID of 123. |
|
658 | + * So this function searches for any event temp Ids called "my_event_id" and |
|
659 | + * replaces them with 123. |
|
660 | + * Also, if there is no temp ID for the INT foreign keys from another database, |
|
661 | + * replaces them with 0 or the field's default. |
|
662 | + * |
|
663 | + * @param type $model_object_data |
|
664 | + * @param EEM_Base $model |
|
665 | + * @param type $old_db_to_new_db_mapping |
|
666 | + * @param boolean $export_from_site_a_to_b |
|
667 | + * @return array updated model object data with temp IDs removed |
|
668 | + */ |
|
669 | + protected function _replace_temp_ids_with_mappings( |
|
670 | + $model_object_data, |
|
671 | + $model, |
|
672 | + $old_db_to_new_db_mapping, |
|
673 | + $export_from_site_a_to_b |
|
674 | + ) { |
|
675 | + // if this model object's primary key is in the mapping, replace it |
|
676 | + if ( |
|
677 | + $model->has_primary_key_field() && |
|
678 | + $model->get_primary_key_field()->is_auto_increment() && |
|
679 | + isset($old_db_to_new_db_mapping[ $model->get_this_model_name() ]) && |
|
680 | + isset( |
|
681 | + $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ] |
|
682 | + ) |
|
683 | + ) { |
|
684 | + $model_object_data[ $model->primary_key_name() ] = $old_db_to_new_db_mapping[ $model->get_this_model_name( |
|
685 | + ) ][ $model_object_data[ $model->primary_key_name() ] ]; |
|
686 | + } |
|
687 | + |
|
688 | + try { |
|
689 | + $model_name_field = $model->get_field_containing_related_model_name(); |
|
690 | + $models_pointed_to_by_model_name_field = $model_name_field->get_model_names_pointed_to(); |
|
691 | + } catch (EE_Error $e) { |
|
692 | + $model_name_field = null; |
|
693 | + $models_pointed_to_by_model_name_field = array(); |
|
694 | + } |
|
695 | + foreach ($model->field_settings(true) as $field_obj) { |
|
696 | + if ($field_obj instanceof EE_Foreign_Key_Int_Field) { |
|
697 | + $models_pointed_to = $field_obj->get_model_names_pointed_to(); |
|
698 | + $found_a_mapping = false; |
|
699 | + foreach ($models_pointed_to as $model_pointed_to_by_fk) { |
|
700 | + if ($model_name_field) { |
|
701 | + $value_of_model_name_field = $model_object_data[ $model_name_field->get_name() ]; |
|
702 | + if ($value_of_model_name_field == $model_pointed_to_by_fk) { |
|
703 | + $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
704 | + $model_object_data[ $field_obj->get_name() ], |
|
705 | + $model_pointed_to_by_fk, |
|
706 | + $old_db_to_new_db_mapping, |
|
707 | + $export_from_site_a_to_b |
|
708 | + ); |
|
709 | + $found_a_mapping = true; |
|
710 | + break; |
|
711 | + } |
|
712 | + } else { |
|
713 | + $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
714 | + $model_object_data[ $field_obj->get_name() ], |
|
715 | + $model_pointed_to_by_fk, |
|
716 | + $old_db_to_new_db_mapping, |
|
717 | + $export_from_site_a_to_b |
|
718 | + ); |
|
719 | + $found_a_mapping = true; |
|
720 | + } |
|
721 | + // once we've found a mapping for this field no need to continue |
|
722 | + if ($found_a_mapping) { |
|
723 | + break; |
|
724 | + } |
|
725 | + } |
|
726 | + } else { |
|
727 | + // it's a string foreign key (which we leave alone, because those are things |
|
728 | + // like country names, which we'd really rather not make 2 USAs etc (we'd actually |
|
729 | + // prefer to just update one) |
|
730 | + // or it's just a regular value that ought to be replaced |
|
731 | + } |
|
732 | + } |
|
733 | + // |
|
734 | + if ($model instanceof EEM_Term_Taxonomy) { |
|
735 | + $model_object_data = $this->_handle_split_term_ids($model_object_data); |
|
736 | + } |
|
737 | + return $model_object_data; |
|
738 | + } |
|
739 | + |
|
740 | + /** |
|
741 | + * If the data was exported PRE-4.2, but then imported POST-4.2, then the term_id |
|
742 | + * this term-taxonomy refers to may be out-of-date so we need to update it. |
|
743 | + * see https://make.wordpress.org/core/2015/02/16/taxonomy-term-splitting-in-4-2-a-developer-guide/ |
|
744 | + * |
|
745 | + * @param type $model_object_data |
|
746 | + * @return array new model object data |
|
747 | + */ |
|
748 | + protected function _handle_split_term_ids($model_object_data) |
|
749 | + { |
|
750 | + if ( |
|
751 | + isset($model_object_data['term_id']) |
|
752 | + && isset($model_object_data['taxonomy']) |
|
753 | + && apply_filters( |
|
754 | + 'FHEE__EE_Import__handle_split_term_ids__function_exists', |
|
755 | + function_exists('wp_get_split_term'), |
|
756 | + $model_object_data |
|
757 | + ) |
|
758 | + ) { |
|
759 | + $new_term_id = wp_get_split_term($model_object_data['term_id'], $model_object_data['taxonomy']); |
|
760 | + if ($new_term_id) { |
|
761 | + $model_object_data['term_id'] = $new_term_id; |
|
762 | + } |
|
763 | + } |
|
764 | + return $model_object_data; |
|
765 | + } |
|
766 | + |
|
767 | + /** |
|
768 | + * Given the object's ID and its model's name, find it int he mapping data, |
|
769 | + * bearing in mind where it came from |
|
770 | + * |
|
771 | + * @param type $object_id |
|
772 | + * @param string $model_name |
|
773 | + * @param array $old_db_to_new_db_mapping |
|
774 | + * @param type $export_from_site_a_to_b |
|
775 | + * @return int |
|
776 | + */ |
|
777 | + protected function _find_mapping_in($object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) |
|
778 | + { |
|
779 | + if (isset($old_db_to_new_db_mapping[ $model_name ][ $object_id ])) { |
|
780 | + return $old_db_to_new_db_mapping[ $model_name ][ $object_id ]; |
|
781 | + } elseif ($object_id == '0' || $object_id == '') { |
|
782 | + // leave as-is |
|
783 | + return $object_id; |
|
784 | + } elseif ($export_from_site_a_to_b) { |
|
785 | + // we couldn't find a mapping for this, and it's from a different site, |
|
786 | + // so blank it out |
|
787 | + return null; |
|
788 | + } elseif (! $export_from_site_a_to_b) { |
|
789 | + // we coudln't find a mapping for this, but it's from thsi DB anyway |
|
790 | + // so let's just leave it as-is |
|
791 | + return $object_id; |
|
792 | + } |
|
793 | + } |
|
794 | + |
|
795 | + /** |
|
796 | + * |
|
797 | + * @param type $id_in_csv |
|
798 | + * @param type $model_object_data |
|
799 | + * @param EEM_Base $model |
|
800 | + * @param type $old_db_to_new_db_mapping |
|
801 | + * @return array updated $old_db_to_new_db_mapping |
|
802 | + */ |
|
803 | + protected function _insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) |
|
804 | + { |
|
805 | + // remove the primary key, if there is one (we don't want it for inserts OR updates) |
|
806 | + // we'll put it back in if we need it |
|
807 | + if ($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()) { |
|
808 | + $effective_id = $model_object_data[ $model->primary_key_name() ]; |
|
809 | + unset($model_object_data[ $model->primary_key_name() ]); |
|
810 | + } else { |
|
811 | + $effective_id = $model->get_index_primary_key_string($model_object_data); |
|
812 | + } |
|
813 | + // the model takes care of validating the CSV's input |
|
814 | + try { |
|
815 | + $new_id = $model->insert($model_object_data); |
|
816 | + if ($new_id) { |
|
817 | + $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_id; |
|
818 | + $this->_total_inserts++; |
|
819 | + EE_Error::add_success( |
|
820 | + sprintf( |
|
821 | + esc_html__("Successfully added new %s (with id %s) with csv data %s", "event_espresso"), |
|
822 | + $model->get_this_model_name(), |
|
823 | + $new_id, |
|
824 | + implode(",", $model_object_data) |
|
825 | + ) |
|
826 | + ); |
|
827 | + } else { |
|
828 | + $this->_total_insert_errors++; |
|
829 | + // put the ID used back in there for the error message |
|
830 | + if ($model->has_primary_key_field()) { |
|
831 | + $model_object_data[ $model->primary_key_name() ] = $effective_id; |
|
832 | + } |
|
833 | + EE_Error::add_error( |
|
834 | + sprintf( |
|
835 | + esc_html__("Could not insert new %s with the csv data: %s", "event_espresso"), |
|
836 | + $model->get_this_model_name(), |
|
837 | + http_build_query($model_object_data) |
|
838 | + ), |
|
839 | + __FILE__, |
|
840 | + __FUNCTION__, |
|
841 | + __LINE__ |
|
842 | + ); |
|
843 | + } |
|
844 | + } catch (EE_Error $e) { |
|
845 | + $this->_total_insert_errors++; |
|
846 | + if ($model->has_primary_key_field()) { |
|
847 | + $model_object_data[ $model->primary_key_name() ] = $effective_id; |
|
848 | + } |
|
849 | + EE_Error::add_error( |
|
850 | + sprintf( |
|
851 | + esc_html__("Could not insert new %s with the csv data: %s because %s", "event_espresso"), |
|
852 | + $model->get_this_model_name(), |
|
853 | + implode(",", $model_object_data), |
|
854 | + $e->getMessage() |
|
855 | + ), |
|
856 | + __FILE__, |
|
857 | + __FUNCTION__, |
|
858 | + __LINE__ |
|
859 | + ); |
|
860 | + } |
|
861 | + return $old_db_to_new_db_mapping; |
|
862 | + } |
|
863 | + |
|
864 | + /** |
|
865 | + * Given the model object data, finds the row to update and updates it |
|
866 | + * |
|
867 | + * @param string|int $id_in_csv |
|
868 | + * @param array $model_object_data |
|
869 | + * @param EEM_Base $model |
|
870 | + * @param array $old_db_to_new_db_mapping |
|
871 | + * @return array updated $old_db_to_new_db_mapping |
|
872 | + */ |
|
873 | + protected function _update_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) |
|
874 | + { |
|
875 | + try { |
|
876 | + // let's keep two copies of the model object data: |
|
877 | + // one for performing an update, one for everthing else |
|
878 | + $model_object_data_for_update = $model_object_data; |
|
879 | + if ($model->has_primary_key_field()) { |
|
880 | + $conditions = array($model->primary_key_name() => $model_object_data[ $model->primary_key_name() ]); |
|
881 | + // remove the primary key because we shouldn't use it for updating |
|
882 | + unset($model_object_data_for_update[ $model->primary_key_name() ]); |
|
883 | + } elseif ($model->get_combined_primary_key_fields() > 1) { |
|
884 | + $conditions = array(); |
|
885 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
886 | + $conditions[ $key_field->get_name() ] = $model_object_data[ $key_field->get_name() ]; |
|
887 | + } |
|
888 | + } else { |
|
889 | + $model->primary_key_name( |
|
890 | + );// this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey) |
|
891 | + } |
|
892 | + |
|
893 | + $success = $model->update($model_object_data_for_update, array($conditions)); |
|
894 | + if ($success) { |
|
895 | + $this->_total_updates++; |
|
896 | + EE_Error::add_success( |
|
897 | + sprintf( |
|
898 | + esc_html__("Successfully updated %s with csv data %s", "event_espresso"), |
|
899 | + $model->get_this_model_name(), |
|
900 | + implode(",", $model_object_data_for_update) |
|
901 | + ) |
|
902 | + ); |
|
903 | + // we should still record the mapping even though it was an update |
|
904 | + // because if we were going to insert somethign but it was going to conflict |
|
905 | + // we would have last-minute decided to update. So we'd like to know what we updated |
|
906 | + // and so we record what record ended up being updated using the mapping |
|
907 | + if ($model->has_primary_key_field()) { |
|
908 | + $new_key_for_mapping = $model_object_data[ $model->primary_key_name() ]; |
|
909 | + } else { |
|
910 | + // no primary key just a combined key |
|
911 | + $new_key_for_mapping = $model->get_index_primary_key_string($model_object_data); |
|
912 | + } |
|
913 | + $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_key_for_mapping; |
|
914 | + } else { |
|
915 | + $matched_items = $model->get_all(array($conditions)); |
|
916 | + if (! $matched_items) { |
|
917 | + // no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck? |
|
918 | + $this->_total_update_errors++; |
|
919 | + EE_Error::add_error( |
|
920 | + sprintf( |
|
921 | + esc_html__( |
|
922 | + "Could not update %s with the csv data: '%s' for an unknown reason (using WHERE conditions %s)", |
|
923 | + "event_espresso" |
|
924 | + ), |
|
925 | + $model->get_this_model_name(), |
|
926 | + http_build_query($model_object_data), |
|
927 | + http_build_query($conditions) |
|
928 | + ), |
|
929 | + __FILE__, |
|
930 | + __FUNCTION__, |
|
931 | + __LINE__ |
|
932 | + ); |
|
933 | + } else { |
|
934 | + $this->_total_updates++; |
|
935 | + EE_Error::add_success( |
|
936 | + sprintf( |
|
937 | + esc_html__( |
|
938 | + "%s with csv data '%s' was found in the database and didn't need updating because all the data is identical.", |
|
939 | + "event_espresso" |
|
940 | + ), |
|
941 | + $model->get_this_model_name(), |
|
942 | + implode(",", $model_object_data) |
|
943 | + ) |
|
944 | + ); |
|
945 | + } |
|
946 | + } |
|
947 | + } catch (EE_Error $e) { |
|
948 | + $this->_total_update_errors++; |
|
949 | + $basic_message = sprintf( |
|
950 | + esc_html__("Could not update %s with the csv data: %s because %s", "event_espresso"), |
|
951 | + $model->get_this_model_name(), |
|
952 | + implode(",", $model_object_data), |
|
953 | + $e->getMessage() |
|
954 | + ); |
|
955 | + $debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString(); |
|
956 | + EE_Error::add_error("$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__); |
|
957 | + } |
|
958 | + return $old_db_to_new_db_mapping; |
|
959 | + } |
|
960 | + |
|
961 | + /** |
|
962 | + * Gets the number of inserts performed since importer was instantiated or reset |
|
963 | + * |
|
964 | + * @return int |
|
965 | + */ |
|
966 | + public function get_total_inserts() |
|
967 | + { |
|
968 | + return $this->_total_inserts; |
|
969 | + } |
|
970 | + |
|
971 | + /** |
|
972 | + * Gets the number of insert errors since importer was instantiated or reset |
|
973 | + * |
|
974 | + * @return int |
|
975 | + */ |
|
976 | + public function get_total_insert_errors() |
|
977 | + { |
|
978 | + return $this->_total_insert_errors; |
|
979 | + } |
|
980 | + |
|
981 | + /** |
|
982 | + * Gets the number of updates performed since importer was instantiated or reset |
|
983 | + * |
|
984 | + * @return int |
|
985 | + */ |
|
986 | + public function get_total_updates() |
|
987 | + { |
|
988 | + return $this->_total_updates; |
|
989 | + } |
|
990 | + |
|
991 | + /** |
|
992 | + * Gets the number of update errors since importer was instantiated or reset |
|
993 | + * |
|
994 | + * @return int |
|
995 | + */ |
|
996 | + public function get_total_update_errors() |
|
997 | + { |
|
998 | + return $this->_total_update_errors; |
|
999 | + } |
|
1000 | 1000 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | continue; |
70 | 70 | } |
71 | 71 | if ($relation instanceof EE_Has_Many_Relation) { |
72 | - $this->nodes[ $relationName ] = new RelationNode( |
|
72 | + $this->nodes[$relationName] = new RelationNode( |
|
73 | 73 | $this->id, |
74 | 74 | $this->model, |
75 | 75 | $relation->get_other_model(), |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $this->dont_traverse_models |
83 | 83 | ) |
84 | 84 | ) { |
85 | - $this->nodes[ $relation->get_join_model()->get_this_model_name() ] = new RelationNode( |
|
85 | + $this->nodes[$relation->get_join_model()->get_this_model_name()] = new RelationNode( |
|
86 | 86 | $this->id, |
87 | 87 | $this->model, |
88 | 88 | $relation->get_join_model(), |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | // To save on space when serializing, only bother keeping a record of relation nodes that actually found |
131 | 131 | // related model objects. |
132 | 132 | if ($relation_node->isComplete() && $relation_node->countSubNodes() === 0) { |
133 | - unset($this->nodes[ $model_name ]); |
|
133 | + unset($this->nodes[$model_name]); |
|
134 | 134 | } |
135 | 135 | if ($num_identified >= $model_objects_to_identify) { |
136 | 136 | // ...but admit we're wrong if the work exceeded the budget. |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | $tree['rels'] = null; |
162 | 162 | } else { |
163 | 163 | foreach ($this->nodes as $relation_name => $relation_node) { |
164 | - $tree['rels'][ $relation_name ] = $relation_node->toArray(); |
|
164 | + $tree['rels'][$relation_name] = $relation_node->toArray(); |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | return $tree; |
@@ -23,218 +23,218 @@ |
||
23 | 23 | */ |
24 | 24 | class ModelObjNode extends BaseNode |
25 | 25 | { |
26 | - /** |
|
27 | - * @var int|string |
|
28 | - */ |
|
29 | - protected $id; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var EEM_Base |
|
33 | - */ |
|
34 | - protected $model; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var RelationNode[] |
|
38 | - */ |
|
39 | - protected $nodes; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * We don't pass the model objects because this needs to serialize to something tiny for effiency. |
|
44 | - * |
|
45 | - * @param $model_obj_id |
|
46 | - * @param EEM_Base $model |
|
47 | - * @param array $dont_traverse_models array of model names we DON'T want to traverse. |
|
48 | - */ |
|
49 | - public function __construct($model_obj_id, EEM_Base $model, array $dont_traverse_models = []) |
|
50 | - { |
|
51 | - $this->id = $model_obj_id; |
|
52 | - $this->model = $model; |
|
53 | - $this->dont_traverse_models = $dont_traverse_models; |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Creates a relation node for each relation of this model's relations. |
|
59 | - * Does NOT call `discover` on them yet though. |
|
60 | - * |
|
61 | - * @throws EE_Error |
|
62 | - * @throws InvalidDataTypeException |
|
63 | - * @throws InvalidInterfaceException |
|
64 | - * @throws InvalidArgumentException |
|
65 | - * @throws ReflectionException |
|
66 | - * @since 4.10.12.p |
|
67 | - */ |
|
68 | - protected function discover() |
|
69 | - { |
|
70 | - $this->nodes = []; |
|
71 | - foreach ($this->model->relation_settings() as $relationName => $relation) { |
|
72 | - // Make sure this isn't one of the models we were told to not traverse into. |
|
73 | - if (in_array($relationName, $this->dont_traverse_models)) { |
|
74 | - continue; |
|
75 | - } |
|
76 | - if ($relation instanceof EE_Has_Many_Relation) { |
|
77 | - $this->nodes[ $relationName ] = new RelationNode( |
|
78 | - $this->id, |
|
79 | - $this->model, |
|
80 | - $relation->get_other_model(), |
|
81 | - $this->dont_traverse_models |
|
82 | - ); |
|
83 | - } elseif ( |
|
84 | - $relation instanceof EE_HABTM_Relation && |
|
85 | - ! in_array( |
|
86 | - $relation->get_join_model()->get_this_model_name(), |
|
87 | - $this->dont_traverse_models |
|
88 | - ) |
|
89 | - ) { |
|
90 | - $this->nodes[ $relation->get_join_model()->get_this_model_name() ] = new RelationNode( |
|
91 | - $this->id, |
|
92 | - $this->model, |
|
93 | - $relation->get_join_model(), |
|
94 | - $this->dont_traverse_models |
|
95 | - ); |
|
96 | - } |
|
97 | - } |
|
98 | - ksort($this->nodes); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * Whether this item has already been initialized |
|
104 | - */ |
|
105 | - protected function isDiscovered() |
|
106 | - { |
|
107 | - return $this->nodes !== null && is_array($this->nodes); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * @since 4.10.12.p |
|
112 | - * @return boolean |
|
113 | - */ |
|
114 | - public function isComplete() |
|
115 | - { |
|
116 | - if ($this->complete === null) { |
|
117 | - $this->complete = false; |
|
118 | - } |
|
119 | - return $this->complete; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * Triggers working on each child relation node that has work to do. |
|
125 | - * |
|
126 | - * @param $model_objects_to_identify |
|
127 | - * @return int units of work done |
|
128 | - * @since 4.10.12.p |
|
129 | - */ |
|
130 | - protected function work($model_objects_to_identify) |
|
131 | - { |
|
132 | - $num_identified = 0; |
|
133 | - // Begin assuming we'll finish all the work on this node and its children... |
|
134 | - $this->complete = true; |
|
135 | - foreach ($this->nodes as $model_name => $relation_node) { |
|
136 | - $num_identified += $relation_node->visit($model_objects_to_identify - $num_identified); |
|
137 | - // To save on space when serializing, only bother keeping a record of relation nodes that actually found |
|
138 | - // related model objects. |
|
139 | - if ($relation_node->isComplete() && $relation_node->countSubNodes() === 0) { |
|
140 | - unset($this->nodes[ $model_name ]); |
|
141 | - } |
|
142 | - if ($num_identified >= $model_objects_to_identify) { |
|
143 | - // ...but admit we're wrong if the work exceeded the budget. |
|
144 | - $this->complete = false; |
|
145 | - break; |
|
146 | - } |
|
147 | - } |
|
148 | - return $num_identified; |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * @return array |
|
154 | - * @throws EE_Error |
|
155 | - * @throws InvalidDataTypeException |
|
156 | - * @throws InvalidInterfaceException |
|
157 | - * @throws InvalidArgumentException |
|
158 | - * @throws ReflectionException |
|
159 | - * @since 4.10.12.p |
|
160 | - */ |
|
161 | - public function toArray() |
|
162 | - { |
|
163 | - $tree = [ |
|
164 | - 'id' => $this->id, |
|
165 | - 'complete' => $this->isComplete(), |
|
166 | - 'rels' => [], |
|
167 | - ]; |
|
168 | - if ($this->nodes === null) { |
|
169 | - $tree['rels'] = null; |
|
170 | - } else { |
|
171 | - foreach ($this->nodes as $relation_name => $relation_node) { |
|
172 | - $tree['rels'][ $relation_name ] = $relation_node->toArray(); |
|
173 | - } |
|
174 | - } |
|
175 | - return $tree; |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * @return array|mixed |
|
181 | - * @throws InvalidArgumentException |
|
182 | - * @throws InvalidDataTypeException |
|
183 | - * @throws InvalidInterfaceException |
|
184 | - * @throws ReflectionException |
|
185 | - * @throws EE_Error |
|
186 | - * @since 4.10.12.p |
|
187 | - */ |
|
188 | - public function getIds() |
|
189 | - { |
|
190 | - $ids = [ |
|
191 | - $this->model->get_this_model_name() => [ |
|
192 | - $this->id => $this->id, |
|
193 | - ], |
|
194 | - ]; |
|
195 | - if ($this->nodes && is_array($this->nodes)) { |
|
196 | - foreach ($this->nodes as $relation_node) { |
|
197 | - $ids = array_replace_recursive($ids, $relation_node->getIds()); |
|
198 | - } |
|
199 | - } |
|
200 | - return $ids; |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * Don't serialize the models. Just record their names on some dynamic properties. |
|
206 | - * |
|
207 | - * @since 4.10.12.p |
|
208 | - */ |
|
209 | - public function __sleep() |
|
210 | - { |
|
211 | - $this->m = $this->model->get_this_model_name(); |
|
212 | - return array_merge( |
|
213 | - [ |
|
214 | - 'm', |
|
215 | - 'id', |
|
216 | - 'nodes', |
|
217 | - ], |
|
218 | - parent::__sleep() |
|
219 | - ); |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - /** |
|
224 | - * Use the dynamic properties to instantiate the models we use. |
|
225 | - * |
|
226 | - * @throws EE_Error |
|
227 | - * @throws InvalidArgumentException |
|
228 | - * @throws InvalidDataTypeException |
|
229 | - * @throws InvalidInterfaceException |
|
230 | - * @throws ReflectionException |
|
231 | - * @since 4.10.12.p |
|
232 | - */ |
|
233 | - public function __wakeup() |
|
234 | - { |
|
235 | - $this->model = EE_Registry::instance()->load_model($this->m); |
|
236 | - parent::__wakeup(); |
|
237 | - } |
|
26 | + /** |
|
27 | + * @var int|string |
|
28 | + */ |
|
29 | + protected $id; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var EEM_Base |
|
33 | + */ |
|
34 | + protected $model; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var RelationNode[] |
|
38 | + */ |
|
39 | + protected $nodes; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * We don't pass the model objects because this needs to serialize to something tiny for effiency. |
|
44 | + * |
|
45 | + * @param $model_obj_id |
|
46 | + * @param EEM_Base $model |
|
47 | + * @param array $dont_traverse_models array of model names we DON'T want to traverse. |
|
48 | + */ |
|
49 | + public function __construct($model_obj_id, EEM_Base $model, array $dont_traverse_models = []) |
|
50 | + { |
|
51 | + $this->id = $model_obj_id; |
|
52 | + $this->model = $model; |
|
53 | + $this->dont_traverse_models = $dont_traverse_models; |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Creates a relation node for each relation of this model's relations. |
|
59 | + * Does NOT call `discover` on them yet though. |
|
60 | + * |
|
61 | + * @throws EE_Error |
|
62 | + * @throws InvalidDataTypeException |
|
63 | + * @throws InvalidInterfaceException |
|
64 | + * @throws InvalidArgumentException |
|
65 | + * @throws ReflectionException |
|
66 | + * @since 4.10.12.p |
|
67 | + */ |
|
68 | + protected function discover() |
|
69 | + { |
|
70 | + $this->nodes = []; |
|
71 | + foreach ($this->model->relation_settings() as $relationName => $relation) { |
|
72 | + // Make sure this isn't one of the models we were told to not traverse into. |
|
73 | + if (in_array($relationName, $this->dont_traverse_models)) { |
|
74 | + continue; |
|
75 | + } |
|
76 | + if ($relation instanceof EE_Has_Many_Relation) { |
|
77 | + $this->nodes[ $relationName ] = new RelationNode( |
|
78 | + $this->id, |
|
79 | + $this->model, |
|
80 | + $relation->get_other_model(), |
|
81 | + $this->dont_traverse_models |
|
82 | + ); |
|
83 | + } elseif ( |
|
84 | + $relation instanceof EE_HABTM_Relation && |
|
85 | + ! in_array( |
|
86 | + $relation->get_join_model()->get_this_model_name(), |
|
87 | + $this->dont_traverse_models |
|
88 | + ) |
|
89 | + ) { |
|
90 | + $this->nodes[ $relation->get_join_model()->get_this_model_name() ] = new RelationNode( |
|
91 | + $this->id, |
|
92 | + $this->model, |
|
93 | + $relation->get_join_model(), |
|
94 | + $this->dont_traverse_models |
|
95 | + ); |
|
96 | + } |
|
97 | + } |
|
98 | + ksort($this->nodes); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * Whether this item has already been initialized |
|
104 | + */ |
|
105 | + protected function isDiscovered() |
|
106 | + { |
|
107 | + return $this->nodes !== null && is_array($this->nodes); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * @since 4.10.12.p |
|
112 | + * @return boolean |
|
113 | + */ |
|
114 | + public function isComplete() |
|
115 | + { |
|
116 | + if ($this->complete === null) { |
|
117 | + $this->complete = false; |
|
118 | + } |
|
119 | + return $this->complete; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * Triggers working on each child relation node that has work to do. |
|
125 | + * |
|
126 | + * @param $model_objects_to_identify |
|
127 | + * @return int units of work done |
|
128 | + * @since 4.10.12.p |
|
129 | + */ |
|
130 | + protected function work($model_objects_to_identify) |
|
131 | + { |
|
132 | + $num_identified = 0; |
|
133 | + // Begin assuming we'll finish all the work on this node and its children... |
|
134 | + $this->complete = true; |
|
135 | + foreach ($this->nodes as $model_name => $relation_node) { |
|
136 | + $num_identified += $relation_node->visit($model_objects_to_identify - $num_identified); |
|
137 | + // To save on space when serializing, only bother keeping a record of relation nodes that actually found |
|
138 | + // related model objects. |
|
139 | + if ($relation_node->isComplete() && $relation_node->countSubNodes() === 0) { |
|
140 | + unset($this->nodes[ $model_name ]); |
|
141 | + } |
|
142 | + if ($num_identified >= $model_objects_to_identify) { |
|
143 | + // ...but admit we're wrong if the work exceeded the budget. |
|
144 | + $this->complete = false; |
|
145 | + break; |
|
146 | + } |
|
147 | + } |
|
148 | + return $num_identified; |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * @return array |
|
154 | + * @throws EE_Error |
|
155 | + * @throws InvalidDataTypeException |
|
156 | + * @throws InvalidInterfaceException |
|
157 | + * @throws InvalidArgumentException |
|
158 | + * @throws ReflectionException |
|
159 | + * @since 4.10.12.p |
|
160 | + */ |
|
161 | + public function toArray() |
|
162 | + { |
|
163 | + $tree = [ |
|
164 | + 'id' => $this->id, |
|
165 | + 'complete' => $this->isComplete(), |
|
166 | + 'rels' => [], |
|
167 | + ]; |
|
168 | + if ($this->nodes === null) { |
|
169 | + $tree['rels'] = null; |
|
170 | + } else { |
|
171 | + foreach ($this->nodes as $relation_name => $relation_node) { |
|
172 | + $tree['rels'][ $relation_name ] = $relation_node->toArray(); |
|
173 | + } |
|
174 | + } |
|
175 | + return $tree; |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * @return array|mixed |
|
181 | + * @throws InvalidArgumentException |
|
182 | + * @throws InvalidDataTypeException |
|
183 | + * @throws InvalidInterfaceException |
|
184 | + * @throws ReflectionException |
|
185 | + * @throws EE_Error |
|
186 | + * @since 4.10.12.p |
|
187 | + */ |
|
188 | + public function getIds() |
|
189 | + { |
|
190 | + $ids = [ |
|
191 | + $this->model->get_this_model_name() => [ |
|
192 | + $this->id => $this->id, |
|
193 | + ], |
|
194 | + ]; |
|
195 | + if ($this->nodes && is_array($this->nodes)) { |
|
196 | + foreach ($this->nodes as $relation_node) { |
|
197 | + $ids = array_replace_recursive($ids, $relation_node->getIds()); |
|
198 | + } |
|
199 | + } |
|
200 | + return $ids; |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * Don't serialize the models. Just record their names on some dynamic properties. |
|
206 | + * |
|
207 | + * @since 4.10.12.p |
|
208 | + */ |
|
209 | + public function __sleep() |
|
210 | + { |
|
211 | + $this->m = $this->model->get_this_model_name(); |
|
212 | + return array_merge( |
|
213 | + [ |
|
214 | + 'm', |
|
215 | + 'id', |
|
216 | + 'nodes', |
|
217 | + ], |
|
218 | + parent::__sleep() |
|
219 | + ); |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + /** |
|
224 | + * Use the dynamic properties to instantiate the models we use. |
|
225 | + * |
|
226 | + * @throws EE_Error |
|
227 | + * @throws InvalidArgumentException |
|
228 | + * @throws InvalidDataTypeException |
|
229 | + * @throws InvalidInterfaceException |
|
230 | + * @throws ReflectionException |
|
231 | + * @since 4.10.12.p |
|
232 | + */ |
|
233 | + public function __wakeup() |
|
234 | + { |
|
235 | + $this->model = EE_Registry::instance()->load_model($this->m); |
|
236 | + parent::__wakeup(); |
|
237 | + } |
|
238 | 238 | } |
239 | 239 | // End of file Visitor.php |
240 | 240 | // Location: EventEspresso\core\services\orm\tree_traversal/Visitor.php |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | protected static function getRequest() |
134 | 134 | { |
135 | 135 | static $request; |
136 | - if (! $request instanceof RequestInterface) { |
|
136 | + if ( ! $request instanceof RequestInterface) { |
|
137 | 137 | $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
138 | 138 | } |
139 | 139 | return $request; |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | protected static function getResponse() |
148 | 148 | { |
149 | 149 | static $response; |
150 | - if (! $response instanceof RequestInterface) { |
|
150 | + if ( ! $response instanceof RequestInterface) { |
|
151 | 151 | $response = LoaderFactory::getLoader()->getShared(ResponseInterface::class); |
152 | 152 | } |
153 | 153 | return $response; |
@@ -14,141 +14,141 @@ |
||
14 | 14 | */ |
15 | 15 | abstract class EED_Module extends EE_Configurable implements ResettableInterface |
16 | 16 | { |
17 | - /** |
|
18 | - * rendered output to be returned to WP |
|
19 | - * |
|
20 | - * @var string $output |
|
21 | - */ |
|
22 | - protected $output = ''; |
|
23 | - |
|
24 | - /** |
|
25 | - * the current active espresso template theme |
|
26 | - * |
|
27 | - * @var string $theme |
|
28 | - */ |
|
29 | - protected $theme = ''; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @return void |
|
34 | - */ |
|
35 | - public static function reset() |
|
36 | - { |
|
37 | - $module_name = get_called_class(); |
|
38 | - new $module_name(); |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
44 | - * |
|
45 | - * @access public |
|
46 | - * @return void |
|
47 | - */ |
|
48 | - public static function set_hooks() |
|
49 | - { |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
55 | - * |
|
56 | - * @access public |
|
57 | - * @return void |
|
58 | - */ |
|
59 | - public static function set_hooks_admin() |
|
60 | - { |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * run - initial module setup |
|
66 | - * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters |
|
67 | - * |
|
68 | - * @access public |
|
69 | - * @var WP $WP |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - abstract public function run($WP); |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * EED_Module constructor. |
|
77 | - */ |
|
78 | - final public function __construct() |
|
79 | - { |
|
80 | - $this->theme = EE_Config::get_current_theme(); |
|
81 | - $module_name = $this->module_name(); |
|
82 | - EE_Registry::instance()->modules->{$module_name} = $this; |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * @param string $module_name |
|
88 | - * @return EED_Module|mixed |
|
89 | - * @throws EE_Error |
|
90 | - * @throws ReflectionException |
|
91 | - */ |
|
92 | - protected static function get_instance($module_name = '') |
|
93 | - { |
|
94 | - $module_name = ! empty($module_name) |
|
95 | - ? $module_name |
|
96 | - : get_called_class(); |
|
97 | - if ( |
|
98 | - ! isset(EE_Registry::instance()->modules->{$module_name}) |
|
99 | - || ! EE_Registry::instance()->modules->{$module_name} instanceof EED_Module |
|
100 | - ) { |
|
101 | - EE_Registry::instance()->add_module($module_name); |
|
102 | - } |
|
103 | - return EE_Registry::instance()->get_module($module_name); |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * module_name |
|
109 | - * |
|
110 | - * @access public |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function module_name() |
|
114 | - { |
|
115 | - return get_class($this); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @return string |
|
121 | - */ |
|
122 | - public function theme() |
|
123 | - { |
|
124 | - return $this->theme; |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * @return RequestInterface |
|
130 | - * @since 4.10.14.p |
|
131 | - */ |
|
132 | - protected static function getRequest() |
|
133 | - { |
|
134 | - static $request; |
|
135 | - if (! $request instanceof RequestInterface) { |
|
136 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
137 | - } |
|
138 | - return $request; |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @return ResponseInterface |
|
144 | - * @since 4.10.14.p |
|
145 | - */ |
|
146 | - protected static function getResponse() |
|
147 | - { |
|
148 | - static $response; |
|
149 | - if (! $response instanceof RequestInterface) { |
|
150 | - $response = LoaderFactory::getLoader()->getShared(ResponseInterface::class); |
|
151 | - } |
|
152 | - return $response; |
|
153 | - } |
|
17 | + /** |
|
18 | + * rendered output to be returned to WP |
|
19 | + * |
|
20 | + * @var string $output |
|
21 | + */ |
|
22 | + protected $output = ''; |
|
23 | + |
|
24 | + /** |
|
25 | + * the current active espresso template theme |
|
26 | + * |
|
27 | + * @var string $theme |
|
28 | + */ |
|
29 | + protected $theme = ''; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @return void |
|
34 | + */ |
|
35 | + public static function reset() |
|
36 | + { |
|
37 | + $module_name = get_called_class(); |
|
38 | + new $module_name(); |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
44 | + * |
|
45 | + * @access public |
|
46 | + * @return void |
|
47 | + */ |
|
48 | + public static function set_hooks() |
|
49 | + { |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
55 | + * |
|
56 | + * @access public |
|
57 | + * @return void |
|
58 | + */ |
|
59 | + public static function set_hooks_admin() |
|
60 | + { |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * run - initial module setup |
|
66 | + * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters |
|
67 | + * |
|
68 | + * @access public |
|
69 | + * @var WP $WP |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + abstract public function run($WP); |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * EED_Module constructor. |
|
77 | + */ |
|
78 | + final public function __construct() |
|
79 | + { |
|
80 | + $this->theme = EE_Config::get_current_theme(); |
|
81 | + $module_name = $this->module_name(); |
|
82 | + EE_Registry::instance()->modules->{$module_name} = $this; |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * @param string $module_name |
|
88 | + * @return EED_Module|mixed |
|
89 | + * @throws EE_Error |
|
90 | + * @throws ReflectionException |
|
91 | + */ |
|
92 | + protected static function get_instance($module_name = '') |
|
93 | + { |
|
94 | + $module_name = ! empty($module_name) |
|
95 | + ? $module_name |
|
96 | + : get_called_class(); |
|
97 | + if ( |
|
98 | + ! isset(EE_Registry::instance()->modules->{$module_name}) |
|
99 | + || ! EE_Registry::instance()->modules->{$module_name} instanceof EED_Module |
|
100 | + ) { |
|
101 | + EE_Registry::instance()->add_module($module_name); |
|
102 | + } |
|
103 | + return EE_Registry::instance()->get_module($module_name); |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * module_name |
|
109 | + * |
|
110 | + * @access public |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function module_name() |
|
114 | + { |
|
115 | + return get_class($this); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @return string |
|
121 | + */ |
|
122 | + public function theme() |
|
123 | + { |
|
124 | + return $this->theme; |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * @return RequestInterface |
|
130 | + * @since 4.10.14.p |
|
131 | + */ |
|
132 | + protected static function getRequest() |
|
133 | + { |
|
134 | + static $request; |
|
135 | + if (! $request instanceof RequestInterface) { |
|
136 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
137 | + } |
|
138 | + return $request; |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @return ResponseInterface |
|
144 | + * @since 4.10.14.p |
|
145 | + */ |
|
146 | + protected static function getResponse() |
|
147 | + { |
|
148 | + static $response; |
|
149 | + if (! $response instanceof RequestInterface) { |
|
150 | + $response = LoaderFactory::getLoader()->getShared(ResponseInterface::class); |
|
151 | + } |
|
152 | + return $response; |
|
153 | + } |
|
154 | 154 | } |
@@ -94,16 +94,16 @@ |
||
94 | 94 | ? $this->_extra_data['template']['question_list'] |
95 | 95 | : $template; |
96 | 96 | $ans_result = ''; |
97 | - $answers = ! empty($this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs']) |
|
98 | - ? $this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs'] |
|
97 | + $answers = ! empty($this->_extra_data['data']->registrations[$reg_obj->ID()]['ans_objs']) |
|
98 | + ? $this->_extra_data['data']->registrations[$reg_obj->ID()]['ans_objs'] |
|
99 | 99 | : []; |
100 | 100 | $questions = ! empty($this->_extra_data['data']->questions) |
101 | 101 | ? $this->_extra_data['data']->questions |
102 | 102 | : []; |
103 | 103 | foreach ($answers as $answer) { |
104 | 104 | // first see if the question is in our $questions array. If not then try to get from answer object |
105 | - $question = isset($questions[ $answer->ID() ]) |
|
106 | - ? $questions[ $answer->ID() ] |
|
105 | + $question = isset($questions[$answer->ID()]) |
|
106 | + ? $questions[$answer->ID()] |
|
107 | 107 | : null; |
108 | 108 | $question = ! $question instanceof EE_Question |
109 | 109 | ? $answer->question() |
@@ -15,113 +15,113 @@ |
||
15 | 15 | */ |
16 | 16 | class EE_Question_List_Shortcodes extends EE_Shortcodes |
17 | 17 | { |
18 | - public function __construct() |
|
19 | - { |
|
20 | - parent::__construct(); |
|
21 | - } |
|
18 | + public function __construct() |
|
19 | + { |
|
20 | + parent::__construct(); |
|
21 | + } |
|
22 | 22 | |
23 | 23 | |
24 | - protected function _init_props() |
|
25 | - { |
|
26 | - $this->label = esc_html__('Questions and Answers Shortcodes', 'event_espresso'); |
|
27 | - $this->description = esc_html__('All shortcodes related to custom questions and answers', 'event_espresso'); |
|
28 | - $this->_shortcodes = [ |
|
29 | - '[QUESTION_LIST]' => esc_html__( |
|
30 | - 'This is used to indicate where you want the list of questions and answers to show for the registrant. You place this within the "[attendee_list]" field.', |
|
31 | - 'event_espresso' |
|
32 | - ), |
|
33 | - ]; |
|
34 | - } |
|
24 | + protected function _init_props() |
|
25 | + { |
|
26 | + $this->label = esc_html__('Questions and Answers Shortcodes', 'event_espresso'); |
|
27 | + $this->description = esc_html__('All shortcodes related to custom questions and answers', 'event_espresso'); |
|
28 | + $this->_shortcodes = [ |
|
29 | + '[QUESTION_LIST]' => esc_html__( |
|
30 | + 'This is used to indicate where you want the list of questions and answers to show for the registrant. You place this within the "[attendee_list]" field.', |
|
31 | + 'event_espresso' |
|
32 | + ), |
|
33 | + ]; |
|
34 | + } |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * @param string $shortcode |
|
39 | - * @return string |
|
40 | - * @throws EE_Error |
|
41 | - * @throws ReflectionException |
|
42 | - */ |
|
43 | - protected function _parser($shortcode) |
|
44 | - { |
|
45 | - switch ($shortcode) { |
|
46 | - case '[QUESTION_LIST]': |
|
47 | - return $this->_get_question_list(); |
|
48 | - } |
|
49 | - return ''; |
|
50 | - } |
|
37 | + /** |
|
38 | + * @param string $shortcode |
|
39 | + * @return string |
|
40 | + * @throws EE_Error |
|
41 | + * @throws ReflectionException |
|
42 | + */ |
|
43 | + protected function _parser($shortcode) |
|
44 | + { |
|
45 | + switch ($shortcode) { |
|
46 | + case '[QUESTION_LIST]': |
|
47 | + return $this->_get_question_list(); |
|
48 | + } |
|
49 | + return ''; |
|
50 | + } |
|
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * @return string |
|
55 | - * @throws EE_Error |
|
56 | - * @throws ReflectionException |
|
57 | - */ |
|
58 | - protected function _get_question_list() |
|
59 | - { |
|
60 | - $this->_validate_list_requirements(); |
|
53 | + /** |
|
54 | + * @return string |
|
55 | + * @throws EE_Error |
|
56 | + * @throws ReflectionException |
|
57 | + */ |
|
58 | + protected function _get_question_list() |
|
59 | + { |
|
60 | + $this->_validate_list_requirements(); |
|
61 | 61 | |
62 | - // for when [QUESTION_LIST] is used in the [attendee_list] field. |
|
63 | - if ($this->_data['data'] instanceof EE_Registration) { |
|
64 | - return $this->_get_question_answer_list_for_attendee(); |
|
65 | - } |
|
62 | + // for when [QUESTION_LIST] is used in the [attendee_list] field. |
|
63 | + if ($this->_data['data'] instanceof EE_Registration) { |
|
64 | + return $this->_get_question_answer_list_for_attendee(); |
|
65 | + } |
|
66 | 66 | |
67 | - // for when [QUESTION_LIST] is used in the main content field. |
|
68 | - if ( |
|
69 | - $this->_data['data'] instanceof EE_Messages_Addressee |
|
70 | - && $this->_data['data']->reg_obj instanceof EE_Registration |
|
71 | - ) { |
|
72 | - return $this->_get_question_answer_list_for_attendee($this->_data['data']->reg_obj); |
|
73 | - } |
|
74 | - return ''; |
|
75 | - } |
|
67 | + // for when [QUESTION_LIST] is used in the main content field. |
|
68 | + if ( |
|
69 | + $this->_data['data'] instanceof EE_Messages_Addressee |
|
70 | + && $this->_data['data']->reg_obj instanceof EE_Registration |
|
71 | + ) { |
|
72 | + return $this->_get_question_answer_list_for_attendee($this->_data['data']->reg_obj); |
|
73 | + } |
|
74 | + return ''; |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | - /** |
|
79 | - * Note when we parse the "[question_list]" shortcode for attendees we're actually going to retrieve the list of |
|
80 | - * answers for that attendee since that is what we really need (we can derive the questions from the answers); |
|
81 | - * |
|
82 | - * @param null $reg_obj |
|
83 | - * @return string parsed template. |
|
84 | - * @throws EE_Error |
|
85 | - * @throws ReflectionException |
|
86 | - */ |
|
87 | - private function _get_question_answer_list_for_attendee($reg_obj = null) |
|
88 | - { |
|
89 | - $valid_shortcodes = ['question']; |
|
90 | - $reg_obj = $reg_obj instanceof EE_Registration |
|
91 | - ? $reg_obj |
|
92 | - : $this->_data['data']; |
|
93 | - $template = is_array($this->_data['template']) && isset($this->_data['template']['question_list']) |
|
94 | - ? $this->_data['template']['question_list'] |
|
95 | - : ''; |
|
96 | - $template = empty($template) && isset($this->_extra_data['template']['question_list']) |
|
97 | - ? $this->_extra_data['template']['question_list'] |
|
98 | - : $template; |
|
99 | - $ans_result = ''; |
|
100 | - $answers = ! empty($this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs']) |
|
101 | - ? $this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs'] |
|
102 | - : []; |
|
103 | - $questions = ! empty($this->_extra_data['data']->questions) |
|
104 | - ? $this->_extra_data['data']->questions |
|
105 | - : []; |
|
106 | - foreach ($answers as $answer) { |
|
107 | - // first see if the question is in our $questions array. If not then try to get from answer object |
|
108 | - $question = isset($questions[ $answer->ID() ]) |
|
109 | - ? $questions[ $answer->ID() ] |
|
110 | - : null; |
|
111 | - $question = ! $question instanceof EE_Question |
|
112 | - ? $answer->question() |
|
113 | - : $question; |
|
114 | - if ($question instanceof EE_Question and $question->admin_only()) { |
|
115 | - continue; |
|
116 | - } |
|
117 | - $ans_result .= $this->_shortcode_helper->parse_question_list_template( |
|
118 | - $template, |
|
119 | - $answer, |
|
120 | - $valid_shortcodes, |
|
121 | - $this->_extra_data |
|
122 | - ); |
|
123 | - } |
|
78 | + /** |
|
79 | + * Note when we parse the "[question_list]" shortcode for attendees we're actually going to retrieve the list of |
|
80 | + * answers for that attendee since that is what we really need (we can derive the questions from the answers); |
|
81 | + * |
|
82 | + * @param null $reg_obj |
|
83 | + * @return string parsed template. |
|
84 | + * @throws EE_Error |
|
85 | + * @throws ReflectionException |
|
86 | + */ |
|
87 | + private function _get_question_answer_list_for_attendee($reg_obj = null) |
|
88 | + { |
|
89 | + $valid_shortcodes = ['question']; |
|
90 | + $reg_obj = $reg_obj instanceof EE_Registration |
|
91 | + ? $reg_obj |
|
92 | + : $this->_data['data']; |
|
93 | + $template = is_array($this->_data['template']) && isset($this->_data['template']['question_list']) |
|
94 | + ? $this->_data['template']['question_list'] |
|
95 | + : ''; |
|
96 | + $template = empty($template) && isset($this->_extra_data['template']['question_list']) |
|
97 | + ? $this->_extra_data['template']['question_list'] |
|
98 | + : $template; |
|
99 | + $ans_result = ''; |
|
100 | + $answers = ! empty($this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs']) |
|
101 | + ? $this->_extra_data['data']->registrations[ $reg_obj->ID() ]['ans_objs'] |
|
102 | + : []; |
|
103 | + $questions = ! empty($this->_extra_data['data']->questions) |
|
104 | + ? $this->_extra_data['data']->questions |
|
105 | + : []; |
|
106 | + foreach ($answers as $answer) { |
|
107 | + // first see if the question is in our $questions array. If not then try to get from answer object |
|
108 | + $question = isset($questions[ $answer->ID() ]) |
|
109 | + ? $questions[ $answer->ID() ] |
|
110 | + : null; |
|
111 | + $question = ! $question instanceof EE_Question |
|
112 | + ? $answer->question() |
|
113 | + : $question; |
|
114 | + if ($question instanceof EE_Question and $question->admin_only()) { |
|
115 | + continue; |
|
116 | + } |
|
117 | + $ans_result .= $this->_shortcode_helper->parse_question_list_template( |
|
118 | + $template, |
|
119 | + $answer, |
|
120 | + $valid_shortcodes, |
|
121 | + $this->_extra_data |
|
122 | + ); |
|
123 | + } |
|
124 | 124 | |
125 | - return $ans_result; |
|
126 | - } |
|
125 | + return $ans_result; |
|
126 | + } |
|
127 | 127 | } |