@@ -781,7 +781,7 @@ discard block |
||
781 | 781 | * _get_transaction_and_cart_for_previous_visit |
782 | 782 | * |
783 | 783 | * @access private |
784 | - * @return mixed EE_Transaction|NULL |
|
784 | + * @return EE_Transaction|null EE_Transaction|NULL |
|
785 | 785 | */ |
786 | 786 | private function _get_transaction_and_cart_for_previous_visit() |
787 | 787 | { |
@@ -863,7 +863,7 @@ discard block |
||
863 | 863 | * generates a new EE_Transaction object and adds it to the $_transaction property. |
864 | 864 | * |
865 | 865 | * @access private |
866 | - * @return mixed EE_Transaction|NULL |
|
866 | + * @return EE_Transaction|null EE_Transaction|NULL |
|
867 | 867 | */ |
868 | 868 | private function _initialize_transaction() |
869 | 869 | { |
@@ -218,19 +218,19 @@ discard block |
||
218 | 218 | */ |
219 | 219 | public static function set_definitions() |
220 | 220 | { |
221 | - if(defined('SPCO_BASE_PATH')) { |
|
221 | + if (defined('SPCO_BASE_PATH')) { |
|
222 | 222 | return; |
223 | 223 | } |
224 | 224 | define( |
225 | 225 | 'SPCO_BASE_PATH', |
226 | - rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS |
|
226 | + rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS).DS |
|
227 | 227 | ); |
228 | - define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
229 | - define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
230 | - define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
231 | - define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
232 | - define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
233 | - define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
228 | + define('SPCO_CSS_URL', plugin_dir_url(__FILE__).'css'.DS); |
|
229 | + define('SPCO_IMG_URL', plugin_dir_url(__FILE__).'img'.DS); |
|
230 | + define('SPCO_JS_URL', plugin_dir_url(__FILE__).'js'.DS); |
|
231 | + define('SPCO_INC_PATH', SPCO_BASE_PATH.'inc'.DS); |
|
232 | + define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH.'reg_steps'.DS); |
|
233 | + define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH.'templates'.DS); |
|
234 | 234 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
235 | 235 | EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
236 | 236 | __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | '</h4>', |
240 | 240 | '<br />', |
241 | 241 | '<p>', |
242 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
242 | + '<a href="'.get_post_type_archive_link('espresso_events').'" title="', |
|
243 | 243 | '">', |
244 | 244 | '</a>', |
245 | 245 | '</p>' |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | return; |
263 | 263 | } |
264 | 264 | // filter list of reg_steps |
265 | - $reg_steps_to_load = (array)apply_filters( |
|
265 | + $reg_steps_to_load = (array) apply_filters( |
|
266 | 266 | 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
267 | 267 | EED_Single_Page_Checkout::get_reg_steps() |
268 | 268 | ); |
@@ -314,25 +314,25 @@ discard block |
||
314 | 314 | if (empty($reg_steps)) { |
315 | 315 | $reg_steps = array( |
316 | 316 | 10 => array( |
317 | - 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
317 | + 'file_path' => SPCO_REG_STEPS_PATH.'attendee_information', |
|
318 | 318 | 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
319 | 319 | 'slug' => 'attendee_information', |
320 | 320 | 'has_hooks' => false, |
321 | 321 | ), |
322 | 322 | 20 => array( |
323 | - 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
323 | + 'file_path' => SPCO_REG_STEPS_PATH.'registration_confirmation', |
|
324 | 324 | 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
325 | 325 | 'slug' => 'registration_confirmation', |
326 | 326 | 'has_hooks' => false, |
327 | 327 | ), |
328 | 328 | 30 => array( |
329 | - 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
329 | + 'file_path' => SPCO_REG_STEPS_PATH.'payment_options', |
|
330 | 330 | 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
331 | 331 | 'slug' => 'payment_options', |
332 | 332 | 'has_hooks' => true, |
333 | 333 | ), |
334 | 334 | 999 => array( |
335 | - 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
335 | + 'file_path' => SPCO_REG_STEPS_PATH.'finalize_registration', |
|
336 | 336 | 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
337 | 337 | 'slug' => 'finalize_registration', |
338 | 338 | 'has_hooks' => false, |
@@ -516,7 +516,7 @@ discard block |
||
516 | 516 | // DEBUG LOG |
517 | 517 | //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
518 | 518 | // get reg form |
519 | - if( ! $this->_check_form_submission()) { |
|
519 | + if ( ! $this->_check_form_submission()) { |
|
520 | 520 | EED_Single_Page_Checkout::$_initialized = true; |
521 | 521 | return; |
522 | 522 | } |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | ); |
558 | 558 | // is session still valid ? |
559 | 559 | if ($clear_session_requested |
560 | - || ( EE_Registry::instance()->SSN->expired() |
|
560 | + || (EE_Registry::instance()->SSN->expired() |
|
561 | 561 | && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '' |
562 | 562 | ) |
563 | 563 | ) { |
@@ -566,7 +566,7 @@ discard block |
||
566 | 566 | // EE_Registry::instance()->SSN->reset_cart(); |
567 | 567 | // EE_Registry::instance()->SSN->reset_checkout(); |
568 | 568 | // EE_Registry::instance()->SSN->reset_transaction(); |
569 | - if (! $clear_session_requested) { |
|
569 | + if ( ! $clear_session_requested) { |
|
570 | 570 | EE_Error::add_attention( |
571 | 571 | EE_Registry::$i18n_js_strings['registration_expiration_notice'], |
572 | 572 | __FILE__, __FUNCTION__, __LINE__ |
@@ -1121,7 +1121,7 @@ discard block |
||
1121 | 1121 | if ( ! $registration instanceof EE_Registration) { |
1122 | 1122 | throw new InvalidEntityException($registration, 'EE_Registration'); |
1123 | 1123 | } |
1124 | - $registrations[ $registration->ID() ] = $registration; |
|
1124 | + $registrations[$registration->ID()] = $registration; |
|
1125 | 1125 | } |
1126 | 1126 | } |
1127 | 1127 | $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
@@ -1382,7 +1382,7 @@ discard block |
||
1382 | 1382 | ) { |
1383 | 1383 | EE_Error::add_success( |
1384 | 1384 | $this->checkout->current_step->success_message() |
1385 | - . '<br />' . $this->checkout->next_step->_instructions() |
|
1385 | + . '<br />'.$this->checkout->next_step->_instructions() |
|
1386 | 1386 | ); |
1387 | 1387 | } |
1388 | 1388 | // pack it up, pack it in... |
@@ -1507,7 +1507,7 @@ discard block |
||
1507 | 1507 | '</h4>', |
1508 | 1508 | '<br />', |
1509 | 1509 | '<p>', |
1510 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1510 | + '<a href="'.get_post_type_archive_link('espresso_events').'" title="', |
|
1511 | 1511 | '">', |
1512 | 1512 | '</a>', |
1513 | 1513 | '</p>' |
@@ -1539,7 +1539,7 @@ discard block |
||
1539 | 1539 | // load css |
1540 | 1540 | wp_register_style( |
1541 | 1541 | 'single_page_checkout', |
1542 | - SPCO_CSS_URL . 'single_page_checkout.css', |
|
1542 | + SPCO_CSS_URL.'single_page_checkout.css', |
|
1543 | 1543 | array('espresso_default'), |
1544 | 1544 | EVENT_ESPRESSO_VERSION |
1545 | 1545 | ); |
@@ -1547,21 +1547,21 @@ discard block |
||
1547 | 1547 | // load JS |
1548 | 1548 | wp_register_script( |
1549 | 1549 | 'jquery_plugin', |
1550 | - EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', |
|
1550 | + EE_THIRD_PARTY_URL.'jquery .plugin.min.js', |
|
1551 | 1551 | array('jquery'), |
1552 | 1552 | '1.0.1', |
1553 | 1553 | true |
1554 | 1554 | ); |
1555 | 1555 | wp_register_script( |
1556 | 1556 | 'jquery_countdown', |
1557 | - EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', |
|
1557 | + EE_THIRD_PARTY_URL.'jquery .countdown.min.js', |
|
1558 | 1558 | array('jquery_plugin'), |
1559 | 1559 | '2.0.2', |
1560 | 1560 | true |
1561 | 1561 | ); |
1562 | 1562 | wp_register_script( |
1563 | 1563 | 'single_page_checkout', |
1564 | - SPCO_JS_URL . 'single_page_checkout.js', |
|
1564 | + SPCO_JS_URL.'single_page_checkout.js', |
|
1565 | 1565 | array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), |
1566 | 1566 | EVENT_ESPRESSO_VERSION, |
1567 | 1567 | true |
@@ -1584,7 +1584,7 @@ discard block |
||
1584 | 1584 | * AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
1585 | 1585 | */ |
1586 | 1586 | do_action( |
1587 | - 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), |
|
1587 | + 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__'.$this->checkout->current_step->slug(), |
|
1588 | 1588 | $this |
1589 | 1589 | ); |
1590 | 1590 | } |
@@ -1638,7 +1638,7 @@ discard block |
||
1638 | 1638 | 'layout_strategy' => |
1639 | 1639 | new EE_Template_Layout( |
1640 | 1640 | array( |
1641 | - 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
1641 | + 'layout_template_file' => SPCO_TEMPLATES_PATH.'registration_page_wrapper.template.php', |
|
1642 | 1642 | 'template_args' => array( |
1643 | 1643 | 'empty_cart' => $empty_cart, |
1644 | 1644 | 'revisit' => $this->checkout->revisit, |
@@ -1713,7 +1713,7 @@ discard block |
||
1713 | 1713 | ) { |
1714 | 1714 | add_filter( |
1715 | 1715 | 'FHEE__EEH_Template__powered_by_event_espresso__url', |
1716 | - function ($url) { |
|
1716 | + function($url) { |
|
1717 | 1717 | return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
1718 | 1718 | } |
1719 | 1719 | ); |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | use EventEspresso\core\exceptions\InvalidEntityException; |
6 | 6 | |
7 | 7 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
8 | - exit('No direct script access allowed'); |
|
8 | + exit('No direct script access allowed'); |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | |
@@ -20,1865 +20,1865 @@ discard block |
||
20 | 20 | class EED_Single_Page_Checkout extends EED_Module |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * $_initialized - has the SPCO controller already been initialized ? |
|
25 | - * |
|
26 | - * @access private |
|
27 | - * @var bool $_initialized |
|
28 | - */ |
|
29 | - private static $_initialized = false; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * $_checkout_verified - is the EE_Checkout verified as correct for this request ? |
|
34 | - * |
|
35 | - * @access private |
|
36 | - * @var bool $_valid_checkout |
|
37 | - */ |
|
38 | - private static $_checkout_verified = true; |
|
39 | - |
|
40 | - /** |
|
41 | - * $_reg_steps_array - holds initial array of reg steps |
|
42 | - * |
|
43 | - * @access private |
|
44 | - * @var array $_reg_steps_array |
|
45 | - */ |
|
46 | - private static $_reg_steps_array = array(); |
|
47 | - |
|
48 | - /** |
|
49 | - * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
50 | - * |
|
51 | - * @access public |
|
52 | - * @var EE_Checkout $checkout |
|
53 | - */ |
|
54 | - public $checkout; |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * @return EED_Module|EED_Single_Page_Checkout |
|
60 | - */ |
|
61 | - public static function instance() |
|
62 | - { |
|
63 | - add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); |
|
64 | - return parent::get_instance(__CLASS__); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @return EE_CART |
|
71 | - */ |
|
72 | - public function cart() |
|
73 | - { |
|
74 | - return $this->checkout->cart; |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * @return EE_Transaction |
|
81 | - */ |
|
82 | - public function transaction() |
|
83 | - { |
|
84 | - return $this->checkout->transaction; |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
91 | - * |
|
92 | - * @access public |
|
93 | - * @return void |
|
94 | - * @throws EE_Error |
|
95 | - */ |
|
96 | - public static function set_hooks() |
|
97 | - { |
|
98 | - EED_Single_Page_Checkout::set_definitions(); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
105 | - * |
|
106 | - * @access public |
|
107 | - * @return void |
|
108 | - * @throws EE_Error |
|
109 | - */ |
|
110 | - public static function set_hooks_admin() |
|
111 | - { |
|
112 | - EED_Single_Page_Checkout::set_definitions(); |
|
113 | - if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
114 | - return; |
|
115 | - } |
|
116 | - // going to start an output buffer in case anything gets accidentally output |
|
117 | - // that might disrupt our JSON response |
|
118 | - ob_start(); |
|
119 | - EED_Single_Page_Checkout::load_request_handler(); |
|
120 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
121 | - // set ajax hooks |
|
122 | - add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
123 | - add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
124 | - add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
125 | - add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
126 | - add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
127 | - add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * process ajax request |
|
134 | - * |
|
135 | - * @param string $ajax_action |
|
136 | - * @throws EE_Error |
|
137 | - */ |
|
138 | - public static function process_ajax_request($ajax_action) |
|
139 | - { |
|
140 | - EE_Registry::instance()->REQ->set('action', $ajax_action); |
|
141 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * ajax display registration step |
|
148 | - * |
|
149 | - * @throws EE_Error |
|
150 | - */ |
|
151 | - public static function display_reg_step() |
|
152 | - { |
|
153 | - EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * ajax process registration step |
|
160 | - * |
|
161 | - * @throws EE_Error |
|
162 | - */ |
|
163 | - public static function process_reg_step() |
|
164 | - { |
|
165 | - EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * ajax process registration step |
|
172 | - * |
|
173 | - * @throws EE_Error |
|
174 | - */ |
|
175 | - public static function update_reg_step() |
|
176 | - { |
|
177 | - EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * update_checkout |
|
184 | - * |
|
185 | - * @access public |
|
186 | - * @return void |
|
187 | - * @throws EE_Error |
|
188 | - */ |
|
189 | - public static function update_checkout() |
|
190 | - { |
|
191 | - EED_Single_Page_Checkout::process_ajax_request('update_checkout'); |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * load_request_handler |
|
198 | - * |
|
199 | - * @access public |
|
200 | - * @return void |
|
201 | - */ |
|
202 | - public static function load_request_handler() |
|
203 | - { |
|
204 | - // load core Request_Handler class |
|
205 | - if (EE_Registry::instance()->REQ !== null) { |
|
206 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
207 | - } |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * set_definitions |
|
214 | - * |
|
215 | - * @access public |
|
216 | - * @return void |
|
217 | - * @throws EE_Error |
|
218 | - */ |
|
219 | - public static function set_definitions() |
|
220 | - { |
|
221 | - if(defined('SPCO_BASE_PATH')) { |
|
222 | - return; |
|
223 | - } |
|
224 | - define( |
|
225 | - 'SPCO_BASE_PATH', |
|
226 | - rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS |
|
227 | - ); |
|
228 | - define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
229 | - define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
230 | - define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
231 | - define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
232 | - define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
233 | - define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
234 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
|
235 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
236 | - __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
237 | - 'event_espresso'), |
|
238 | - '<h4 class="important-notice">', |
|
239 | - '</h4>', |
|
240 | - '<br />', |
|
241 | - '<p>', |
|
242 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
243 | - '">', |
|
244 | - '</a>', |
|
245 | - '</p>' |
|
246 | - ); |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * load_reg_steps |
|
253 | - * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array |
|
254 | - * |
|
255 | - * @access private |
|
256 | - * @throws EE_Error |
|
257 | - */ |
|
258 | - public static function load_reg_steps() |
|
259 | - { |
|
260 | - static $reg_steps_loaded = false; |
|
261 | - if ($reg_steps_loaded) { |
|
262 | - return; |
|
263 | - } |
|
264 | - // filter list of reg_steps |
|
265 | - $reg_steps_to_load = (array)apply_filters( |
|
266 | - 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
|
267 | - EED_Single_Page_Checkout::get_reg_steps() |
|
268 | - ); |
|
269 | - // sort by key (order) |
|
270 | - ksort($reg_steps_to_load); |
|
271 | - // loop through folders |
|
272 | - foreach ($reg_steps_to_load as $order => $reg_step) { |
|
273 | - // we need a |
|
274 | - if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
275 | - // copy over to the reg_steps_array |
|
276 | - EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step; |
|
277 | - // register custom key route for each reg step |
|
278 | - // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
|
279 | - EE_Config::register_route( |
|
280 | - $reg_step['slug'], |
|
281 | - 'EED_Single_Page_Checkout', |
|
282 | - 'run', |
|
283 | - 'step' |
|
284 | - ); |
|
285 | - // add AJAX or other hooks |
|
286 | - if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
|
287 | - // setup autoloaders if necessary |
|
288 | - if ( ! class_exists($reg_step['class_name'])) { |
|
289 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder( |
|
290 | - $reg_step['file_path'], |
|
291 | - true |
|
292 | - ); |
|
293 | - } |
|
294 | - if (is_callable($reg_step['class_name'], 'set_hooks')) { |
|
295 | - call_user_func(array($reg_step['class_name'], 'set_hooks')); |
|
296 | - } |
|
297 | - } |
|
298 | - } |
|
299 | - } |
|
300 | - $reg_steps_loaded = true; |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * get_reg_steps |
|
307 | - * |
|
308 | - * @access public |
|
309 | - * @return array |
|
310 | - */ |
|
311 | - public static function get_reg_steps() |
|
312 | - { |
|
313 | - $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; |
|
314 | - if (empty($reg_steps)) { |
|
315 | - $reg_steps = array( |
|
316 | - 10 => array( |
|
317 | - 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
318 | - 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
|
319 | - 'slug' => 'attendee_information', |
|
320 | - 'has_hooks' => false, |
|
321 | - ), |
|
322 | - 20 => array( |
|
323 | - 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
324 | - 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
|
325 | - 'slug' => 'registration_confirmation', |
|
326 | - 'has_hooks' => false, |
|
327 | - ), |
|
328 | - 30 => array( |
|
329 | - 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
330 | - 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
|
331 | - 'slug' => 'payment_options', |
|
332 | - 'has_hooks' => true, |
|
333 | - ), |
|
334 | - 999 => array( |
|
335 | - 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
336 | - 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
|
337 | - 'slug' => 'finalize_registration', |
|
338 | - 'has_hooks' => false, |
|
339 | - ), |
|
340 | - ); |
|
341 | - } |
|
342 | - return $reg_steps; |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * registration_checkout_for_admin |
|
349 | - * |
|
350 | - * @access public |
|
351 | - * @return string |
|
352 | - * @throws EE_Error |
|
353 | - */ |
|
354 | - public static function registration_checkout_for_admin() |
|
355 | - { |
|
356 | - EED_Single_Page_Checkout::load_request_handler(); |
|
357 | - EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
358 | - EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); |
|
359 | - EE_Registry::instance()->REQ->set('process_form_submission', false); |
|
360 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
361 | - EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); |
|
362 | - return EE_Registry::instance()->REQ->get_output(); |
|
363 | - } |
|
364 | - |
|
365 | - |
|
366 | - |
|
367 | - /** |
|
368 | - * process_registration_from_admin |
|
369 | - * |
|
370 | - * @access public |
|
371 | - * @return \EE_Transaction |
|
372 | - * @throws EE_Error |
|
373 | - */ |
|
374 | - public static function process_registration_from_admin() |
|
375 | - { |
|
376 | - EED_Single_Page_Checkout::load_request_handler(); |
|
377 | - EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
378 | - EE_Registry::instance()->REQ->set('action', 'process_reg_step'); |
|
379 | - EE_Registry::instance()->REQ->set('process_form_submission', true); |
|
380 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
381 | - if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { |
|
382 | - $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); |
|
383 | - if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
384 | - EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); |
|
385 | - if ($final_reg_step->process_reg_step()) { |
|
386 | - $final_reg_step->set_completed(); |
|
387 | - EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); |
|
388 | - return EED_Single_Page_Checkout::instance()->checkout->transaction; |
|
389 | - } |
|
390 | - } |
|
391 | - } |
|
392 | - return null; |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - |
|
397 | - /** |
|
398 | - * run |
|
399 | - * |
|
400 | - * @access public |
|
401 | - * @param WP_Query $WP_Query |
|
402 | - * @return void |
|
403 | - * @throws EE_Error |
|
404 | - */ |
|
405 | - public function run($WP_Query) |
|
406 | - { |
|
407 | - if ( |
|
408 | - $WP_Query instanceof WP_Query |
|
409 | - && $WP_Query->is_main_query() |
|
410 | - && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) |
|
411 | - && $this->_is_reg_checkout() |
|
412 | - ) { |
|
413 | - $this->_initialize(); |
|
414 | - } |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - |
|
419 | - /** |
|
420 | - * determines whether current url matches reg page url |
|
421 | - * |
|
422 | - * @return bool |
|
423 | - */ |
|
424 | - protected function _is_reg_checkout() |
|
425 | - { |
|
426 | - // get current permalink for reg page without any extra query args |
|
427 | - $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
|
428 | - // get request URI for current request, but without the scheme or host |
|
429 | - $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
430 | - $current_request_uri = html_entity_decode($current_request_uri); |
|
431 | - // get array of query args from the current request URI |
|
432 | - $query_args = \EEH_URL::get_query_string($current_request_uri); |
|
433 | - // grab page id if it is set |
|
434 | - $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; |
|
435 | - // and remove the page id from the query args (we will re-add it later) |
|
436 | - unset($query_args['page_id']); |
|
437 | - // now strip all query args from current request URI |
|
438 | - $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri); |
|
439 | - // and re-add the page id if it was set |
|
440 | - if ($page_id) { |
|
441 | - $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
|
442 | - } |
|
443 | - // remove slashes and ? |
|
444 | - $current_request_uri = trim($current_request_uri, '?/'); |
|
445 | - // is current request URI part of the known full reg page URL ? |
|
446 | - return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false; |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * @param WP_Query $wp_query |
|
453 | - * @return void |
|
454 | - * @throws EE_Error |
|
455 | - */ |
|
456 | - public static function init($wp_query) |
|
457 | - { |
|
458 | - EED_Single_Page_Checkout::instance()->run($wp_query); |
|
459 | - } |
|
460 | - |
|
461 | - |
|
462 | - |
|
463 | - /** |
|
464 | - * _initialize - initial module setup |
|
465 | - * |
|
466 | - * @access private |
|
467 | - * @throws EE_Error |
|
468 | - * @return void |
|
469 | - */ |
|
470 | - private function _initialize() |
|
471 | - { |
|
472 | - // ensure SPCO doesn't run twice |
|
473 | - if (EED_Single_Page_Checkout::$_initialized) { |
|
474 | - return; |
|
475 | - } |
|
476 | - try { |
|
477 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
478 | - $this->_verify_session(); |
|
479 | - // setup the EE_Checkout object |
|
480 | - $this->checkout = $this->_initialize_checkout(); |
|
481 | - // filter checkout |
|
482 | - $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); |
|
483 | - // get the $_GET |
|
484 | - $this->_get_request_vars(); |
|
485 | - if ($this->_block_bots()) { |
|
486 | - return; |
|
487 | - } |
|
488 | - // filter continue_reg |
|
489 | - $this->checkout->continue_reg = apply_filters( |
|
490 | - 'FHEE__EED_Single_Page_Checkout__init___continue_reg', |
|
491 | - true, |
|
492 | - $this->checkout |
|
493 | - ); |
|
494 | - // load the reg steps array |
|
495 | - if ( ! $this->_load_and_instantiate_reg_steps()) { |
|
496 | - EED_Single_Page_Checkout::$_initialized = true; |
|
497 | - return; |
|
498 | - } |
|
499 | - // set the current step |
|
500 | - $this->checkout->set_current_step($this->checkout->step); |
|
501 | - // and the next step |
|
502 | - $this->checkout->set_next_step(); |
|
503 | - // verify that everything has been setup correctly |
|
504 | - if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { |
|
505 | - EED_Single_Page_Checkout::$_initialized = true; |
|
506 | - return; |
|
507 | - } |
|
508 | - // lock the transaction |
|
509 | - $this->checkout->transaction->lock(); |
|
510 | - // make sure all of our cached objects are added to their respective model entity mappers |
|
511 | - $this->checkout->refresh_all_entities(); |
|
512 | - // set amount owing |
|
513 | - $this->checkout->amount_owing = $this->checkout->transaction->remaining(); |
|
514 | - // initialize each reg step, which gives them the chance to potentially alter the process |
|
515 | - $this->_initialize_reg_steps(); |
|
516 | - // DEBUG LOG |
|
517 | - //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
518 | - // get reg form |
|
519 | - if( ! $this->_check_form_submission()) { |
|
520 | - EED_Single_Page_Checkout::$_initialized = true; |
|
521 | - return; |
|
522 | - } |
|
523 | - // checkout the action!!! |
|
524 | - $this->_process_form_action(); |
|
525 | - // add some style and make it dance |
|
526 | - $this->add_styles_and_scripts(); |
|
527 | - // kk... SPCO has successfully run |
|
528 | - EED_Single_Page_Checkout::$_initialized = true; |
|
529 | - // set no cache headers and constants |
|
530 | - EE_System::do_not_cache(); |
|
531 | - // add anchor |
|
532 | - add_action('loop_start', array($this, 'set_checkout_anchor'), 1); |
|
533 | - // remove transaction lock |
|
534 | - add_action('shutdown', array($this, 'unlock_transaction'), 1); |
|
535 | - } catch (Exception $e) { |
|
536 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
537 | - } |
|
538 | - } |
|
539 | - |
|
540 | - |
|
541 | - |
|
542 | - /** |
|
543 | - * _verify_session |
|
544 | - * checks that the session is valid and not expired |
|
545 | - * |
|
546 | - * @access private |
|
547 | - * @throws EE_Error |
|
548 | - */ |
|
549 | - private function _verify_session() |
|
550 | - { |
|
551 | - if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
552 | - throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso')); |
|
553 | - } |
|
554 | - $clear_session_requested = filter_var( |
|
555 | - EE_Registry::instance()->REQ->get('clear_session', false), |
|
556 | - FILTER_VALIDATE_BOOLEAN |
|
557 | - ); |
|
558 | - // is session still valid ? |
|
559 | - if ($clear_session_requested |
|
560 | - || ( EE_Registry::instance()->SSN->expired() |
|
561 | - && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '' |
|
562 | - ) |
|
563 | - ) { |
|
564 | - $this->checkout = new EE_Checkout(); |
|
565 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
566 | - // EE_Registry::instance()->SSN->reset_cart(); |
|
567 | - // EE_Registry::instance()->SSN->reset_checkout(); |
|
568 | - // EE_Registry::instance()->SSN->reset_transaction(); |
|
569 | - if (! $clear_session_requested) { |
|
570 | - EE_Error::add_attention( |
|
571 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'], |
|
572 | - __FILE__, __FUNCTION__, __LINE__ |
|
573 | - ); |
|
574 | - } |
|
575 | - // EE_Registry::instance()->SSN->reset_expired(); |
|
576 | - } |
|
577 | - } |
|
578 | - |
|
579 | - |
|
580 | - |
|
581 | - /** |
|
582 | - * _initialize_checkout |
|
583 | - * loads and instantiates EE_Checkout |
|
584 | - * |
|
585 | - * @access private |
|
586 | - * @throws EE_Error |
|
587 | - * @return EE_Checkout |
|
588 | - */ |
|
589 | - private function _initialize_checkout() |
|
590 | - { |
|
591 | - // look in session for existing checkout |
|
592 | - /** @type EE_Checkout $checkout */ |
|
593 | - $checkout = EE_Registry::instance()->SSN->checkout(); |
|
594 | - // verify |
|
595 | - if ( ! $checkout instanceof EE_Checkout) { |
|
596 | - // instantiate EE_Checkout object for handling the properties of the current checkout process |
|
597 | - $checkout = EE_Registry::instance()->load_file( |
|
598 | - SPCO_INC_PATH, |
|
599 | - 'EE_Checkout', |
|
600 | - 'class', array(), |
|
601 | - false |
|
602 | - ); |
|
603 | - } else { |
|
604 | - if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { |
|
605 | - $this->unlock_transaction(); |
|
606 | - wp_safe_redirect($checkout->redirect_url); |
|
607 | - exit(); |
|
608 | - } |
|
609 | - } |
|
610 | - $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
|
611 | - // verify again |
|
612 | - if ( ! $checkout instanceof EE_Checkout) { |
|
613 | - throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
|
614 | - } |
|
615 | - // reset anything that needs a clean slate for each request |
|
616 | - $checkout->reset_for_current_request(); |
|
617 | - return $checkout; |
|
618 | - } |
|
619 | - |
|
620 | - |
|
621 | - |
|
622 | - /** |
|
623 | - * _get_request_vars |
|
624 | - * |
|
625 | - * @access private |
|
626 | - * @return void |
|
627 | - * @throws EE_Error |
|
628 | - */ |
|
629 | - private function _get_request_vars() |
|
630 | - { |
|
631 | - // load classes |
|
632 | - EED_Single_Page_Checkout::load_request_handler(); |
|
633 | - //make sure this request is marked as belonging to EE |
|
634 | - EE_Registry::instance()->REQ->set_espresso_page(true); |
|
635 | - // which step is being requested ? |
|
636 | - $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); |
|
637 | - // which step is being edited ? |
|
638 | - $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); |
|
639 | - // and what we're doing on the current step |
|
640 | - $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); |
|
641 | - // timestamp |
|
642 | - $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); |
|
643 | - // returning to edit ? |
|
644 | - $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); |
|
645 | - // add reg url link to registration query params |
|
646 | - if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) { |
|
647 | - $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link; |
|
648 | - } |
|
649 | - // or some other kind of revisit ? |
|
650 | - $this->checkout->revisit = filter_var( |
|
651 | - EE_Registry::instance()->REQ->get('revisit', false), |
|
652 | - FILTER_VALIDATE_BOOLEAN |
|
653 | - ); |
|
654 | - // and whether or not to generate a reg form for this request |
|
655 | - $this->checkout->generate_reg_form = filter_var( |
|
656 | - EE_Registry::instance()->REQ->get('generate_reg_form', true), |
|
657 | - FILTER_VALIDATE_BOOLEAN |
|
658 | - ); |
|
659 | - // and whether or not to process a reg form submission for this request |
|
660 | - $this->checkout->process_form_submission = filter_var( |
|
661 | - EE_Registry::instance()->REQ->get( |
|
662 | - 'process_form_submission', |
|
663 | - $this->checkout->action === 'process_reg_step' |
|
664 | - ), |
|
665 | - FILTER_VALIDATE_BOOLEAN |
|
666 | - ); |
|
667 | - $this->checkout->process_form_submission = filter_var( |
|
668 | - $this->checkout->action !== 'display_spco_reg_step' |
|
669 | - ? $this->checkout->process_form_submission |
|
670 | - : false, |
|
671 | - FILTER_VALIDATE_BOOLEAN |
|
672 | - ); |
|
673 | - // $this->_display_request_vars(); |
|
674 | - } |
|
675 | - |
|
676 | - |
|
677 | - |
|
678 | - /** |
|
679 | - * _display_request_vars |
|
680 | - * |
|
681 | - * @access protected |
|
682 | - * @return void |
|
683 | - */ |
|
684 | - protected function _display_request_vars() |
|
685 | - { |
|
686 | - if ( ! WP_DEBUG) { |
|
687 | - return; |
|
688 | - } |
|
689 | - EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
|
690 | - EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); |
|
691 | - EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); |
|
692 | - EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); |
|
693 | - EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); |
|
694 | - EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); |
|
695 | - EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__); |
|
696 | - EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__); |
|
697 | - } |
|
698 | - |
|
699 | - |
|
700 | - |
|
701 | - /** |
|
702 | - * _block_bots |
|
703 | - * checks that the incoming request has either of the following set: |
|
704 | - * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector |
|
705 | - * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
|
706 | - * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
|
707 | - * then where you coming from man? |
|
708 | - * |
|
709 | - * @return boolean |
|
710 | - */ |
|
711 | - private function _block_bots() |
|
712 | - { |
|
713 | - $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
714 | - if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { |
|
715 | - return true; |
|
716 | - } |
|
717 | - return false; |
|
718 | - } |
|
719 | - |
|
720 | - |
|
721 | - |
|
722 | - /** |
|
723 | - * _get_first_step |
|
724 | - * gets slug for first step in $_reg_steps_array |
|
725 | - * |
|
726 | - * @access private |
|
727 | - * @throws EE_Error |
|
728 | - * @return string |
|
729 | - */ |
|
730 | - private function _get_first_step() |
|
731 | - { |
|
732 | - $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); |
|
733 | - return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; |
|
734 | - } |
|
735 | - |
|
736 | - |
|
737 | - |
|
738 | - /** |
|
739 | - * _load_and_instantiate_reg_steps |
|
740 | - * instantiates each reg step based on the loaded reg_steps array |
|
741 | - * |
|
742 | - * @access private |
|
743 | - * @throws EE_Error |
|
744 | - * @return bool |
|
745 | - */ |
|
746 | - private function _load_and_instantiate_reg_steps() |
|
747 | - { |
|
748 | - do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout); |
|
749 | - // have reg_steps already been instantiated ? |
|
750 | - if ( |
|
751 | - empty($this->checkout->reg_steps) |
|
752 | - || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) |
|
753 | - ) { |
|
754 | - // if not, then loop through raw reg steps array |
|
755 | - foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
|
756 | - if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
757 | - return false; |
|
758 | - } |
|
759 | - } |
|
760 | - EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true; |
|
761 | - EE_Registry::instance()->CFG->registration->reg_confirmation_last = true; |
|
762 | - // skip the registration_confirmation page ? |
|
763 | - if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { |
|
764 | - // just remove it from the reg steps array |
|
765 | - $this->checkout->remove_reg_step('registration_confirmation', false); |
|
766 | - } else if ( |
|
767 | - isset($this->checkout->reg_steps['registration_confirmation']) |
|
768 | - && EE_Registry::instance()->CFG->registration->reg_confirmation_last |
|
769 | - ) { |
|
770 | - // set the order to something big like 100 |
|
771 | - $this->checkout->set_reg_step_order('registration_confirmation', 100); |
|
772 | - } |
|
773 | - // filter the array for good luck |
|
774 | - $this->checkout->reg_steps = apply_filters( |
|
775 | - 'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps', |
|
776 | - $this->checkout->reg_steps |
|
777 | - ); |
|
778 | - // finally re-sort based on the reg step class order properties |
|
779 | - $this->checkout->sort_reg_steps(); |
|
780 | - } else { |
|
781 | - foreach ($this->checkout->reg_steps as $reg_step) { |
|
782 | - // set all current step stati to FALSE |
|
783 | - $reg_step->set_is_current_step(false); |
|
784 | - } |
|
785 | - } |
|
786 | - if (empty($this->checkout->reg_steps)) { |
|
787 | - EE_Error::add_error( |
|
788 | - __('No Reg Steps were loaded..', 'event_espresso'), |
|
789 | - __FILE__, __FUNCTION__, __LINE__ |
|
790 | - ); |
|
791 | - return false; |
|
792 | - } |
|
793 | - // make reg step details available to JS |
|
794 | - $this->checkout->set_reg_step_JSON_info(); |
|
795 | - return true; |
|
796 | - } |
|
797 | - |
|
798 | - |
|
799 | - |
|
800 | - /** |
|
801 | - * _load_and_instantiate_reg_step |
|
802 | - * |
|
803 | - * @access private |
|
804 | - * @param array $reg_step |
|
805 | - * @param int $order |
|
806 | - * @return bool |
|
807 | - */ |
|
808 | - private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) |
|
809 | - { |
|
810 | - // we need a file_path, class_name, and slug to add a reg step |
|
811 | - if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
812 | - // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) |
|
813 | - if ( |
|
814 | - $this->checkout->reg_url_link |
|
815 | - && $this->checkout->step !== $reg_step['slug'] |
|
816 | - && $reg_step['slug'] !== 'finalize_registration' |
|
817 | - // normally at this point we would NOT load the reg step, but this filter can change that |
|
818 | - && apply_filters( |
|
819 | - 'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step', |
|
820 | - true, |
|
821 | - $reg_step, |
|
822 | - $this->checkout |
|
823 | - ) |
|
824 | - ) { |
|
825 | - return true; |
|
826 | - } |
|
827 | - // instantiate step class using file path and class name |
|
828 | - $reg_step_obj = EE_Registry::instance()->load_file( |
|
829 | - $reg_step['file_path'], |
|
830 | - $reg_step['class_name'], |
|
831 | - 'class', |
|
832 | - $this->checkout, |
|
833 | - false |
|
834 | - ); |
|
835 | - // did we gets the goods ? |
|
836 | - if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { |
|
837 | - // set reg step order based on config |
|
838 | - $reg_step_obj->set_order($order); |
|
839 | - // add instantiated reg step object to the master reg steps array |
|
840 | - $this->checkout->add_reg_step($reg_step_obj); |
|
841 | - } else { |
|
842 | - EE_Error::add_error( |
|
843 | - __('The current step could not be set.', 'event_espresso'), |
|
844 | - __FILE__, __FUNCTION__, __LINE__ |
|
845 | - ); |
|
846 | - return false; |
|
847 | - } |
|
848 | - } else { |
|
849 | - if (WP_DEBUG) { |
|
850 | - EE_Error::add_error( |
|
851 | - sprintf( |
|
852 | - __( |
|
853 | - 'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', |
|
854 | - 'event_espresso' |
|
855 | - ), |
|
856 | - isset($reg_step['file_path']) ? $reg_step['file_path'] : '', |
|
857 | - isset($reg_step['class_name']) ? $reg_step['class_name'] : '', |
|
858 | - isset($reg_step['slug']) ? $reg_step['slug'] : '', |
|
859 | - '<ul>', |
|
860 | - '<li>', |
|
861 | - '</li>', |
|
862 | - '</ul>' |
|
863 | - ), |
|
864 | - __FILE__, __FUNCTION__, __LINE__ |
|
865 | - ); |
|
866 | - } |
|
867 | - return false; |
|
868 | - } |
|
869 | - return true; |
|
870 | - } |
|
871 | - |
|
872 | - |
|
873 | - /** |
|
874 | - * _verify_transaction_and_get_registrations |
|
875 | - * |
|
876 | - * @access private |
|
877 | - * @return bool |
|
878 | - * @throws InvalidDataTypeException |
|
879 | - * @throws InvalidEntityException |
|
880 | - * @throws EE_Error |
|
881 | - */ |
|
882 | - private function _verify_transaction_and_get_registrations() |
|
883 | - { |
|
884 | - // was there already a valid transaction in the checkout from the session ? |
|
885 | - if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
886 | - // get transaction from db or session |
|
887 | - $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
|
888 | - ? $this->_get_transaction_and_cart_for_previous_visit() |
|
889 | - : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
|
890 | - if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
891 | - EE_Error::add_error( |
|
892 | - __('Your Registration and Transaction information could not be retrieved from the db.', |
|
893 | - 'event_espresso'), |
|
894 | - __FILE__, __FUNCTION__, __LINE__ |
|
895 | - ); |
|
896 | - $this->checkout->transaction = EE_Transaction::new_instance(); |
|
897 | - // add some style and make it dance |
|
898 | - $this->add_styles_and_scripts(); |
|
899 | - EED_Single_Page_Checkout::$_initialized = true; |
|
900 | - return false; |
|
901 | - } |
|
902 | - // and the registrations for the transaction |
|
903 | - $this->_get_registrations($this->checkout->transaction); |
|
904 | - } |
|
905 | - return true; |
|
906 | - } |
|
907 | - |
|
908 | - |
|
909 | - |
|
910 | - /** |
|
911 | - * _get_transaction_and_cart_for_previous_visit |
|
912 | - * |
|
913 | - * @access private |
|
914 | - * @return mixed EE_Transaction|NULL |
|
915 | - */ |
|
916 | - private function _get_transaction_and_cart_for_previous_visit() |
|
917 | - { |
|
918 | - /** @var $TXN_model EEM_Transaction */ |
|
919 | - $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
920 | - // because the reg_url_link is present in the request, |
|
921 | - // this is a return visit to SPCO, so we'll get the transaction data from the db |
|
922 | - $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); |
|
923 | - // verify transaction |
|
924 | - if ($transaction instanceof EE_Transaction) { |
|
925 | - // and get the cart that was used for that transaction |
|
926 | - $this->checkout->cart = $this->_get_cart_for_transaction($transaction); |
|
927 | - return $transaction; |
|
928 | - } |
|
929 | - EE_Error::add_error( |
|
930 | - __('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), |
|
931 | - __FILE__, __FUNCTION__, __LINE__ |
|
932 | - ); |
|
933 | - return null; |
|
934 | - |
|
935 | - } |
|
936 | - |
|
937 | - |
|
938 | - |
|
939 | - /** |
|
940 | - * _get_cart_for_transaction |
|
941 | - * |
|
942 | - * @access private |
|
943 | - * @param EE_Transaction $transaction |
|
944 | - * @return EE_Cart |
|
945 | - */ |
|
946 | - private function _get_cart_for_transaction($transaction) |
|
947 | - { |
|
948 | - return $this->checkout->get_cart_for_transaction($transaction); |
|
949 | - } |
|
950 | - |
|
951 | - |
|
952 | - |
|
953 | - /** |
|
954 | - * get_cart_for_transaction |
|
955 | - * |
|
956 | - * @access public |
|
957 | - * @param EE_Transaction $transaction |
|
958 | - * @return EE_Cart |
|
959 | - */ |
|
960 | - public function get_cart_for_transaction(EE_Transaction $transaction) |
|
961 | - { |
|
962 | - return $this->checkout->get_cart_for_transaction($transaction); |
|
963 | - } |
|
964 | - |
|
965 | - |
|
966 | - |
|
967 | - /** |
|
968 | - * _get_transaction_and_cart_for_current_session |
|
969 | - * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
970 | - * |
|
971 | - * @access private |
|
972 | - * @return EE_Transaction |
|
973 | - * @throws EE_Error |
|
974 | - */ |
|
975 | - private function _get_cart_for_current_session_and_setup_new_transaction() |
|
976 | - { |
|
977 | - // if there's no transaction, then this is the FIRST visit to SPCO |
|
978 | - // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) |
|
979 | - $this->checkout->cart = $this->_get_cart_for_transaction(null); |
|
980 | - // and then create a new transaction |
|
981 | - $transaction = $this->_initialize_transaction(); |
|
982 | - // verify transaction |
|
983 | - if ($transaction instanceof EE_Transaction) { |
|
984 | - // save it so that we have an ID for other objects to use |
|
985 | - $transaction->save(); |
|
986 | - // and save TXN data to the cart |
|
987 | - $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); |
|
988 | - } else { |
|
989 | - EE_Error::add_error( |
|
990 | - __('A Valid Transaction could not be initialized.', 'event_espresso'), |
|
991 | - __FILE__, __FUNCTION__, __LINE__ |
|
992 | - ); |
|
993 | - } |
|
994 | - return $transaction; |
|
995 | - } |
|
996 | - |
|
997 | - |
|
998 | - |
|
999 | - /** |
|
1000 | - * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
1001 | - * |
|
1002 | - * @access private |
|
1003 | - * @return mixed EE_Transaction|NULL |
|
1004 | - */ |
|
1005 | - private function _initialize_transaction() |
|
1006 | - { |
|
1007 | - try { |
|
1008 | - // ensure cart totals have been calculated |
|
1009 | - $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
1010 | - // grab the cart grand total |
|
1011 | - $cart_total = $this->checkout->cart->get_cart_grand_total(); |
|
1012 | - // create new TXN |
|
1013 | - $transaction = EE_Transaction::new_instance( |
|
1014 | - array( |
|
1015 | - 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), |
|
1016 | - 'TXN_total' => $cart_total > 0 ? $cart_total : 0, |
|
1017 | - 'TXN_paid' => 0, |
|
1018 | - 'STS_ID' => EEM_Transaction::failed_status_code, |
|
1019 | - ) |
|
1020 | - ); |
|
1021 | - // save it so that we have an ID for other objects to use |
|
1022 | - $transaction->save(); |
|
1023 | - // set cron job for following up on TXNs after their session has expired |
|
1024 | - EE_Cron_Tasks::schedule_expired_transaction_check( |
|
1025 | - EE_Registry::instance()->SSN->expiration() + 1, |
|
1026 | - $transaction->ID() |
|
1027 | - ); |
|
1028 | - return $transaction; |
|
1029 | - } catch (Exception $e) { |
|
1030 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1031 | - } |
|
1032 | - return null; |
|
1033 | - } |
|
1034 | - |
|
1035 | - |
|
1036 | - /** |
|
1037 | - * _get_registrations |
|
1038 | - * |
|
1039 | - * @access private |
|
1040 | - * @param EE_Transaction $transaction |
|
1041 | - * @return void |
|
1042 | - * @throws InvalidDataTypeException |
|
1043 | - * @throws InvalidEntityException |
|
1044 | - * @throws EE_Error |
|
1045 | - */ |
|
1046 | - private function _get_registrations(EE_Transaction $transaction) |
|
1047 | - { |
|
1048 | - // first step: grab the registrants { : o |
|
1049 | - $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
1050 | - $this->checkout->total_ticket_count = count($registrations); |
|
1051 | - // verify registrations have been set |
|
1052 | - if (empty($registrations)) { |
|
1053 | - // if no cached registrations, then check the db |
|
1054 | - $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
1055 | - // still nothing ? well as long as this isn't a revisit |
|
1056 | - if (empty($registrations) && ! $this->checkout->revisit) { |
|
1057 | - // generate new registrations from scratch |
|
1058 | - $registrations = $this->_initialize_registrations($transaction); |
|
1059 | - } |
|
1060 | - } |
|
1061 | - // sort by their original registration order |
|
1062 | - usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); |
|
1063 | - // then loop thru the array |
|
1064 | - foreach ($registrations as $registration) { |
|
1065 | - // verify each registration |
|
1066 | - if ($registration instanceof EE_Registration) { |
|
1067 | - // we display all attendee info for the primary registrant |
|
1068 | - if ($this->checkout->reg_url_link === $registration->reg_url_link() |
|
1069 | - && $registration->is_primary_registrant() |
|
1070 | - ) { |
|
1071 | - $this->checkout->primary_revisit = true; |
|
1072 | - break; |
|
1073 | - } |
|
1074 | - if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) { |
|
1075 | - // but hide info if it doesn't belong to you |
|
1076 | - $transaction->clear_cache('Registration', $registration->ID()); |
|
1077 | - $this->checkout->total_ticket_count--; |
|
1078 | - } |
|
1079 | - $this->checkout->set_reg_status_updated($registration->ID(), false); |
|
1080 | - } |
|
1081 | - } |
|
1082 | - } |
|
1083 | - |
|
1084 | - |
|
1085 | - /** |
|
1086 | - * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
|
1087 | - * |
|
1088 | - * @access private |
|
1089 | - * @param EE_Transaction $transaction |
|
1090 | - * @return array |
|
1091 | - * @throws InvalidDataTypeException |
|
1092 | - * @throws InvalidEntityException |
|
1093 | - * @throws EE_Error |
|
1094 | - */ |
|
1095 | - private function _initialize_registrations(EE_Transaction $transaction) |
|
1096 | - { |
|
1097 | - $att_nmbr = 0; |
|
1098 | - $registrations = array(); |
|
1099 | - if ($transaction instanceof EE_Transaction) { |
|
1100 | - /** @type EE_Registration_Processor $registration_processor */ |
|
1101 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1102 | - $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); |
|
1103 | - // now let's add the cart items to the $transaction |
|
1104 | - foreach ($this->checkout->cart->get_tickets() as $line_item) { |
|
1105 | - //do the following for each ticket of this type they selected |
|
1106 | - for ($x = 1; $x <= $line_item->quantity(); $x++) { |
|
1107 | - $att_nmbr++; |
|
1108 | - /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
|
1109 | - $CreateRegistrationCommand = EE_Registry::instance()->create( |
|
1110 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
1111 | - array( |
|
1112 | - $transaction, |
|
1113 | - $line_item, |
|
1114 | - $att_nmbr, |
|
1115 | - $this->checkout->total_ticket_count, |
|
1116 | - ) |
|
1117 | - ); |
|
1118 | - // override capabilities for frontend registrations |
|
1119 | - if ( ! is_admin()) { |
|
1120 | - $CreateRegistrationCommand->setCapCheck( |
|
1121 | - new PublicCapabilities('', 'create_new_registration') |
|
1122 | - ); |
|
1123 | - } |
|
1124 | - $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
|
1125 | - if ( ! $registration instanceof EE_Registration) { |
|
1126 | - throw new InvalidEntityException($registration, 'EE_Registration'); |
|
1127 | - } |
|
1128 | - $registrations[ $registration->ID() ] = $registration; |
|
1129 | - } |
|
1130 | - } |
|
1131 | - $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
|
1132 | - } |
|
1133 | - return $registrations; |
|
1134 | - } |
|
1135 | - |
|
1136 | - |
|
1137 | - |
|
1138 | - /** |
|
1139 | - * sorts registrations by REG_count |
|
1140 | - * |
|
1141 | - * @access public |
|
1142 | - * @param EE_Registration $reg_A |
|
1143 | - * @param EE_Registration $reg_B |
|
1144 | - * @return int |
|
1145 | - */ |
|
1146 | - public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) |
|
1147 | - { |
|
1148 | - // this shouldn't ever happen within the same TXN, but oh well |
|
1149 | - if ($reg_A->count() === $reg_B->count()) { |
|
1150 | - return 0; |
|
1151 | - } |
|
1152 | - return ($reg_A->count() > $reg_B->count()) ? 1 : -1; |
|
1153 | - } |
|
1154 | - |
|
1155 | - |
|
1156 | - |
|
1157 | - /** |
|
1158 | - * _final_verifications |
|
1159 | - * just makes sure that everything is set up correctly before proceeding |
|
1160 | - * |
|
1161 | - * @access private |
|
1162 | - * @return bool |
|
1163 | - * @throws EE_Error |
|
1164 | - */ |
|
1165 | - private function _final_verifications() |
|
1166 | - { |
|
1167 | - // filter checkout |
|
1168 | - $this->checkout = apply_filters( |
|
1169 | - 'FHEE__EED_Single_Page_Checkout___final_verifications__checkout', |
|
1170 | - $this->checkout |
|
1171 | - ); |
|
1172 | - //verify that current step is still set correctly |
|
1173 | - if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
1174 | - EE_Error::add_error( |
|
1175 | - __('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1176 | - __FILE__, |
|
1177 | - __FUNCTION__, |
|
1178 | - __LINE__ |
|
1179 | - ); |
|
1180 | - return false; |
|
1181 | - } |
|
1182 | - // if returning to SPCO, then verify that primary registrant is set |
|
1183 | - if ( ! empty($this->checkout->reg_url_link)) { |
|
1184 | - $valid_registrant = $this->checkout->transaction->primary_registration(); |
|
1185 | - if ( ! $valid_registrant instanceof EE_Registration) { |
|
1186 | - EE_Error::add_error( |
|
1187 | - __('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1188 | - __FILE__, |
|
1189 | - __FUNCTION__, |
|
1190 | - __LINE__ |
|
1191 | - ); |
|
1192 | - return false; |
|
1193 | - } |
|
1194 | - $valid_registrant = null; |
|
1195 | - foreach ( |
|
1196 | - $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration |
|
1197 | - ) { |
|
1198 | - if ( |
|
1199 | - $registration instanceof EE_Registration |
|
1200 | - && $registration->reg_url_link() === $this->checkout->reg_url_link |
|
1201 | - ) { |
|
1202 | - $valid_registrant = $registration; |
|
1203 | - } |
|
1204 | - } |
|
1205 | - if ( ! $valid_registrant instanceof EE_Registration) { |
|
1206 | - // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
|
1207 | - if (EED_Single_Page_Checkout::$_checkout_verified) { |
|
1208 | - // clear the session, mark the checkout as unverified, and try again |
|
1209 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
1210 | - EED_Single_Page_Checkout::$_initialized = false; |
|
1211 | - EED_Single_Page_Checkout::$_checkout_verified = false; |
|
1212 | - $this->_initialize(); |
|
1213 | - EE_Error::reset_notices(); |
|
1214 | - return false; |
|
1215 | - } |
|
1216 | - EE_Error::add_error( |
|
1217 | - __( |
|
1218 | - 'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', |
|
1219 | - 'event_espresso' |
|
1220 | - ), |
|
1221 | - __FILE__, |
|
1222 | - __FUNCTION__, |
|
1223 | - __LINE__ |
|
1224 | - ); |
|
1225 | - return false; |
|
1226 | - } |
|
1227 | - } |
|
1228 | - // now that things have been kinda sufficiently verified, |
|
1229 | - // let's add the checkout to the session so that it's available to other systems |
|
1230 | - EE_Registry::instance()->SSN->set_checkout($this->checkout); |
|
1231 | - return true; |
|
1232 | - } |
|
1233 | - |
|
1234 | - |
|
1235 | - |
|
1236 | - /** |
|
1237 | - * _initialize_reg_steps |
|
1238 | - * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required |
|
1239 | - * then loops thru all of the active reg steps and calls the initialize_reg_step() method |
|
1240 | - * |
|
1241 | - * @access private |
|
1242 | - * @param bool $reinitializing |
|
1243 | - * @throws EE_Error |
|
1244 | - */ |
|
1245 | - private function _initialize_reg_steps($reinitializing = false) |
|
1246 | - { |
|
1247 | - $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
|
1248 | - // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
|
1249 | - foreach ($this->checkout->reg_steps as $reg_step) { |
|
1250 | - if ( ! $reg_step->initialize_reg_step()) { |
|
1251 | - // if not initialized then maybe this step is being removed... |
|
1252 | - if ( ! $reinitializing && $reg_step->is_current_step()) { |
|
1253 | - // if it was the current step, then we need to start over here |
|
1254 | - $this->_initialize_reg_steps(true); |
|
1255 | - return; |
|
1256 | - } |
|
1257 | - continue; |
|
1258 | - } |
|
1259 | - // add css and JS for current step |
|
1260 | - $reg_step->enqueue_styles_and_scripts(); |
|
1261 | - // i18n |
|
1262 | - $reg_step->translate_js_strings(); |
|
1263 | - if ($reg_step->is_current_step()) { |
|
1264 | - // the text that appears on the reg step form submit button |
|
1265 | - $reg_step->set_submit_button_text(); |
|
1266 | - } |
|
1267 | - } |
|
1268 | - // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
|
1269 | - do_action( |
|
1270 | - "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", |
|
1271 | - $this->checkout->current_step |
|
1272 | - ); |
|
1273 | - } |
|
1274 | - |
|
1275 | - |
|
1276 | - |
|
1277 | - /** |
|
1278 | - * _check_form_submission |
|
1279 | - * |
|
1280 | - * @access private |
|
1281 | - * @return boolean |
|
1282 | - */ |
|
1283 | - private function _check_form_submission() |
|
1284 | - { |
|
1285 | - //does this request require the reg form to be generated ? |
|
1286 | - if ($this->checkout->generate_reg_form) { |
|
1287 | - // ever heard that song by Blue Rodeo ? |
|
1288 | - try { |
|
1289 | - $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
|
1290 | - // if not displaying a form, then check for form submission |
|
1291 | - if ( |
|
1292 | - $this->checkout->process_form_submission |
|
1293 | - && $this->checkout->current_step->reg_form->was_submitted() |
|
1294 | - ) { |
|
1295 | - // clear out any old data in case this step is being run again |
|
1296 | - $this->checkout->current_step->set_valid_data(array()); |
|
1297 | - // capture submitted form data |
|
1298 | - $this->checkout->current_step->reg_form->receive_form_submission( |
|
1299 | - apply_filters( |
|
1300 | - 'FHEE__Single_Page_Checkout___check_form_submission__request_params', |
|
1301 | - EE_Registry::instance()->REQ->params(), |
|
1302 | - $this->checkout |
|
1303 | - ) |
|
1304 | - ); |
|
1305 | - // validate submitted form data |
|
1306 | - if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { |
|
1307 | - // thou shall not pass !!! |
|
1308 | - $this->checkout->continue_reg = false; |
|
1309 | - // any form validation errors? |
|
1310 | - if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { |
|
1311 | - $submission_error_messages = array(); |
|
1312 | - // bad, bad, bad registrant |
|
1313 | - foreach ( |
|
1314 | - $this->checkout->current_step->reg_form->get_validation_errors_accumulated() |
|
1315 | - as $validation_error |
|
1316 | - ) { |
|
1317 | - if ($validation_error instanceof EE_Validation_Error) { |
|
1318 | - $submission_error_messages[] = sprintf( |
|
1319 | - __('%s : %s', 'event_espresso'), |
|
1320 | - $validation_error->get_form_section()->html_label_text(), |
|
1321 | - $validation_error->getMessage() |
|
1322 | - ); |
|
1323 | - } |
|
1324 | - } |
|
1325 | - EE_Error::add_error( |
|
1326 | - implode('<br />', $submission_error_messages), |
|
1327 | - __FILE__, __FUNCTION__, __LINE__ |
|
1328 | - ); |
|
1329 | - } |
|
1330 | - // well not really... what will happen is |
|
1331 | - // we'll just get redirected back to redo the current step |
|
1332 | - $this->go_to_next_step(); |
|
1333 | - return false; |
|
1334 | - } |
|
1335 | - } |
|
1336 | - } catch (EE_Error $e) { |
|
1337 | - $e->get_error(); |
|
1338 | - } |
|
1339 | - } |
|
1340 | - return true; |
|
1341 | - } |
|
1342 | - |
|
1343 | - |
|
1344 | - |
|
1345 | - /** |
|
1346 | - * _process_action |
|
1347 | - * |
|
1348 | - * @access private |
|
1349 | - * @return void |
|
1350 | - * @throws EE_Error |
|
1351 | - */ |
|
1352 | - private function _process_form_action() |
|
1353 | - { |
|
1354 | - // what cha wanna do? |
|
1355 | - switch ($this->checkout->action) { |
|
1356 | - // AJAX next step reg form |
|
1357 | - case 'display_spco_reg_step' : |
|
1358 | - $this->checkout->redirect = false; |
|
1359 | - if (EE_Registry::instance()->REQ->ajax) { |
|
1360 | - $this->checkout->json_response->set_reg_step_html( |
|
1361 | - $this->checkout->current_step->display_reg_form() |
|
1362 | - ); |
|
1363 | - } |
|
1364 | - break; |
|
1365 | - default : |
|
1366 | - // meh... do one of those other steps first |
|
1367 | - if ( |
|
1368 | - ! empty($this->checkout->action) |
|
1369 | - && is_callable(array($this->checkout->current_step, $this->checkout->action)) |
|
1370 | - ) { |
|
1371 | - // dynamically creates hook point like: |
|
1372 | - // AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
|
1373 | - do_action( |
|
1374 | - "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
1375 | - $this->checkout->current_step |
|
1376 | - ); |
|
1377 | - // call action on current step |
|
1378 | - if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { |
|
1379 | - // good registrant, you get to proceed |
|
1380 | - if ( |
|
1381 | - $this->checkout->current_step->success_message() !== '' |
|
1382 | - && apply_filters( |
|
1383 | - 'FHEE__Single_Page_Checkout___process_form_action__display_success', |
|
1384 | - false |
|
1385 | - ) |
|
1386 | - ) { |
|
1387 | - EE_Error::add_success( |
|
1388 | - $this->checkout->current_step->success_message() |
|
1389 | - . '<br />' . $this->checkout->next_step->_instructions() |
|
1390 | - ); |
|
1391 | - } |
|
1392 | - // pack it up, pack it in... |
|
1393 | - $this->_setup_redirect(); |
|
1394 | - } |
|
1395 | - // dynamically creates hook point like: |
|
1396 | - // AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
|
1397 | - do_action( |
|
1398 | - "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
1399 | - $this->checkout->current_step |
|
1400 | - ); |
|
1401 | - } else { |
|
1402 | - EE_Error::add_error( |
|
1403 | - sprintf( |
|
1404 | - __( |
|
1405 | - 'The requested form action "%s" does not exist for the current "%s" registration step.', |
|
1406 | - 'event_espresso' |
|
1407 | - ), |
|
1408 | - $this->checkout->action, |
|
1409 | - $this->checkout->current_step->name() |
|
1410 | - ), |
|
1411 | - __FILE__, |
|
1412 | - __FUNCTION__, |
|
1413 | - __LINE__ |
|
1414 | - ); |
|
1415 | - } |
|
1416 | - // end default |
|
1417 | - } |
|
1418 | - // store our progress so far |
|
1419 | - $this->checkout->stash_transaction_and_checkout(); |
|
1420 | - // advance to the next step! If you pass GO, collect $200 |
|
1421 | - $this->go_to_next_step(); |
|
1422 | - } |
|
1423 | - |
|
1424 | - |
|
1425 | - |
|
1426 | - /** |
|
1427 | - * add_styles_and_scripts |
|
1428 | - * |
|
1429 | - * @access public |
|
1430 | - * @return void |
|
1431 | - */ |
|
1432 | - public function add_styles_and_scripts() |
|
1433 | - { |
|
1434 | - // i18n |
|
1435 | - $this->translate_js_strings(); |
|
1436 | - if ($this->checkout->admin_request) { |
|
1437 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1438 | - } else { |
|
1439 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1440 | - } |
|
1441 | - } |
|
1442 | - |
|
1443 | - |
|
1444 | - |
|
1445 | - /** |
|
1446 | - * translate_js_strings |
|
1447 | - * |
|
1448 | - * @access public |
|
1449 | - * @return void |
|
1450 | - */ |
|
1451 | - public function translate_js_strings() |
|
1452 | - { |
|
1453 | - EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
|
1454 | - EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
1455 | - EE_Registry::$i18n_js_strings['server_error'] = __( |
|
1456 | - 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
1457 | - 'event_espresso' |
|
1458 | - ); |
|
1459 | - EE_Registry::$i18n_js_strings['invalid_json_response'] = __( |
|
1460 | - 'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
1461 | - 'event_espresso' |
|
1462 | - ); |
|
1463 | - EE_Registry::$i18n_js_strings['validation_error'] = __( |
|
1464 | - 'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', |
|
1465 | - 'event_espresso' |
|
1466 | - ); |
|
1467 | - EE_Registry::$i18n_js_strings['invalid_payment_method'] = __( |
|
1468 | - 'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', |
|
1469 | - 'event_espresso' |
|
1470 | - ); |
|
1471 | - EE_Registry::$i18n_js_strings['reg_step_error'] = __( |
|
1472 | - 'This registration step could not be completed. Please refresh the page and try again.', |
|
1473 | - 'event_espresso' |
|
1474 | - ); |
|
1475 | - EE_Registry::$i18n_js_strings['invalid_coupon'] = __( |
|
1476 | - 'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', |
|
1477 | - 'event_espresso' |
|
1478 | - ); |
|
1479 | - EE_Registry::$i18n_js_strings['process_registration'] = sprintf( |
|
1480 | - __( |
|
1481 | - 'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', |
|
1482 | - 'event_espresso' |
|
1483 | - ), |
|
1484 | - '<br/>', |
|
1485 | - '<br/>' |
|
1486 | - ); |
|
1487 | - EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); |
|
1488 | - EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
|
1489 | - EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
|
1490 | - EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
|
1491 | - EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso'); |
|
1492 | - EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso'); |
|
1493 | - EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso'); |
|
1494 | - EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso'); |
|
1495 | - EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso'); |
|
1496 | - EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso'); |
|
1497 | - EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso'); |
|
1498 | - EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso'); |
|
1499 | - EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso'); |
|
1500 | - EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso'); |
|
1501 | - EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso'); |
|
1502 | - EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso'); |
|
1503 | - EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso'); |
|
1504 | - EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso'); |
|
1505 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
1506 | - __( |
|
1507 | - '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
1508 | - 'event_espresso' |
|
1509 | - ), |
|
1510 | - '<h4 class="important-notice">', |
|
1511 | - '</h4>', |
|
1512 | - '<br />', |
|
1513 | - '<p>', |
|
1514 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1515 | - '">', |
|
1516 | - '</a>', |
|
1517 | - '</p>' |
|
1518 | - ); |
|
1519 | - EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters( |
|
1520 | - 'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', |
|
1521 | - true |
|
1522 | - ); |
|
1523 | - EE_Registry::$i18n_js_strings['session_extension'] = absint( |
|
1524 | - apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS) |
|
1525 | - ); |
|
1526 | - EE_Registry::$i18n_js_strings['session_expiration'] = gmdate( |
|
1527 | - 'M d, Y H:i:s', |
|
1528 | - EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
1529 | - ); |
|
1530 | - } |
|
1531 | - |
|
1532 | - |
|
1533 | - |
|
1534 | - /** |
|
1535 | - * enqueue_styles_and_scripts |
|
1536 | - * |
|
1537 | - * @access public |
|
1538 | - * @return void |
|
1539 | - * @throws EE_Error |
|
1540 | - */ |
|
1541 | - public function enqueue_styles_and_scripts() |
|
1542 | - { |
|
1543 | - // load css |
|
1544 | - wp_register_style( |
|
1545 | - 'single_page_checkout', |
|
1546 | - SPCO_CSS_URL . 'single_page_checkout.css', |
|
1547 | - array('espresso_default'), |
|
1548 | - EVENT_ESPRESSO_VERSION |
|
1549 | - ); |
|
1550 | - wp_enqueue_style('single_page_checkout'); |
|
1551 | - // load JS |
|
1552 | - wp_register_script( |
|
1553 | - 'jquery_plugin', |
|
1554 | - EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', |
|
1555 | - array('jquery'), |
|
1556 | - '1.0.1', |
|
1557 | - true |
|
1558 | - ); |
|
1559 | - wp_register_script( |
|
1560 | - 'jquery_countdown', |
|
1561 | - EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', |
|
1562 | - array('jquery_plugin'), |
|
1563 | - '2.0.2', |
|
1564 | - true |
|
1565 | - ); |
|
1566 | - wp_register_script( |
|
1567 | - 'single_page_checkout', |
|
1568 | - SPCO_JS_URL . 'single_page_checkout.js', |
|
1569 | - array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), |
|
1570 | - EVENT_ESPRESSO_VERSION, |
|
1571 | - true |
|
1572 | - ); |
|
1573 | - if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) { |
|
1574 | - $this->checkout->registration_form->enqueue_js(); |
|
1575 | - } |
|
1576 | - if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) { |
|
1577 | - $this->checkout->current_step->reg_form->enqueue_js(); |
|
1578 | - } |
|
1579 | - wp_enqueue_script('single_page_checkout'); |
|
1580 | - /** |
|
1581 | - * global action hook for enqueueing styles and scripts with |
|
1582 | - * spco calls. |
|
1583 | - */ |
|
1584 | - do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); |
|
1585 | - /** |
|
1586 | - * dynamic action hook for enqueueing styles and scripts with spco calls. |
|
1587 | - * The hook will end up being something like: |
|
1588 | - * AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
|
1589 | - */ |
|
1590 | - do_action( |
|
1591 | - 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), |
|
1592 | - $this |
|
1593 | - ); |
|
1594 | - } |
|
1595 | - |
|
1596 | - |
|
1597 | - |
|
1598 | - /** |
|
1599 | - * display the Registration Single Page Checkout Form |
|
1600 | - * |
|
1601 | - * @access private |
|
1602 | - * @return void |
|
1603 | - * @throws EE_Error |
|
1604 | - */ |
|
1605 | - private function _display_spco_reg_form() |
|
1606 | - { |
|
1607 | - // if registering via the admin, just display the reg form for the current step |
|
1608 | - if ($this->checkout->admin_request) { |
|
1609 | - EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); |
|
1610 | - } else { |
|
1611 | - // add powered by EE msg |
|
1612 | - add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); |
|
1613 | - $empty_cart = count( |
|
1614 | - $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) |
|
1615 | - ) < 1; |
|
1616 | - EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart; |
|
1617 | - $cookies_not_set_msg = ''; |
|
1618 | - if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) { |
|
1619 | - $cookies_not_set_msg = apply_filters( |
|
1620 | - 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', |
|
1621 | - sprintf( |
|
1622 | - __( |
|
1623 | - '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', |
|
1624 | - 'event_espresso' |
|
1625 | - ), |
|
1626 | - '<div class="ee-attention">', |
|
1627 | - '</div>', |
|
1628 | - '<h6 class="important-notice">', |
|
1629 | - '</h6>', |
|
1630 | - '<p>', |
|
1631 | - '</p>', |
|
1632 | - '<br />', |
|
1633 | - '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">', |
|
1634 | - '</a>' |
|
1635 | - ) |
|
1636 | - ); |
|
1637 | - } |
|
1638 | - $this->checkout->registration_form = new EE_Form_Section_Proper( |
|
1639 | - array( |
|
1640 | - 'name' => 'single-page-checkout', |
|
1641 | - 'html_id' => 'ee-single-page-checkout-dv', |
|
1642 | - 'layout_strategy' => |
|
1643 | - new EE_Template_Layout( |
|
1644 | - array( |
|
1645 | - 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
1646 | - 'template_args' => array( |
|
1647 | - 'empty_cart' => $empty_cart, |
|
1648 | - 'revisit' => $this->checkout->revisit, |
|
1649 | - 'reg_steps' => $this->checkout->reg_steps, |
|
1650 | - 'next_step' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
1651 | - ? $this->checkout->next_step->slug() |
|
1652 | - : '', |
|
1653 | - 'cancel_page_url' => $this->checkout->cancel_page_url, |
|
1654 | - 'empty_msg' => apply_filters( |
|
1655 | - 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
|
1656 | - sprintf( |
|
1657 | - __( |
|
1658 | - 'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', |
|
1659 | - 'event_espresso' |
|
1660 | - ), |
|
1661 | - '<a href="' |
|
1662 | - . get_post_type_archive_link('espresso_events') |
|
1663 | - . '" title="', |
|
1664 | - '">', |
|
1665 | - '</a>' |
|
1666 | - ) |
|
1667 | - ), |
|
1668 | - 'cookies_not_set_msg' => $cookies_not_set_msg, |
|
1669 | - 'registration_time_limit' => $this->checkout->get_registration_time_limit(), |
|
1670 | - 'session_expiration' => gmdate( |
|
1671 | - 'M d, Y H:i:s', |
|
1672 | - EE_Registry::instance()->SSN->expiration() |
|
1673 | - + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
1674 | - ), |
|
1675 | - ), |
|
1676 | - ) |
|
1677 | - ), |
|
1678 | - ) |
|
1679 | - ); |
|
1680 | - // load template and add to output sent that gets filtered into the_content() |
|
1681 | - EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); |
|
1682 | - } |
|
1683 | - } |
|
1684 | - |
|
1685 | - |
|
1686 | - |
|
1687 | - /** |
|
1688 | - * add_extra_finalize_registration_inputs |
|
1689 | - * |
|
1690 | - * @access public |
|
1691 | - * @param $next_step |
|
1692 | - * @internal param string $label |
|
1693 | - * @return void |
|
1694 | - */ |
|
1695 | - public function add_extra_finalize_registration_inputs($next_step) |
|
1696 | - { |
|
1697 | - if ($next_step === 'finalize_registration') { |
|
1698 | - echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; |
|
1699 | - } |
|
1700 | - } |
|
1701 | - |
|
1702 | - |
|
1703 | - |
|
1704 | - /** |
|
1705 | - * display_registration_footer |
|
1706 | - * |
|
1707 | - * @access public |
|
1708 | - * @return string |
|
1709 | - */ |
|
1710 | - public static function display_registration_footer() |
|
1711 | - { |
|
1712 | - if ( |
|
1713 | - apply_filters( |
|
1714 | - 'FHEE__EE_Front__Controller__show_reg_footer', |
|
1715 | - EE_Registry::instance()->CFG->admin->show_reg_footer |
|
1716 | - ) |
|
1717 | - ) { |
|
1718 | - add_filter( |
|
1719 | - 'FHEE__EEH_Template__powered_by_event_espresso__url', |
|
1720 | - function ($url) { |
|
1721 | - return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
|
1722 | - } |
|
1723 | - ); |
|
1724 | - echo apply_filters( |
|
1725 | - 'FHEE__EE_Front_Controller__display_registration_footer', |
|
1726 | - \EEH_Template::powered_by_event_espresso( |
|
1727 | - '', |
|
1728 | - 'espresso-registration-footer-dv', |
|
1729 | - array('utm_content' => 'registration_checkout') |
|
1730 | - ) |
|
1731 | - ); |
|
1732 | - } |
|
1733 | - return ''; |
|
1734 | - } |
|
1735 | - |
|
1736 | - |
|
1737 | - |
|
1738 | - /** |
|
1739 | - * unlock_transaction |
|
1740 | - * |
|
1741 | - * @access public |
|
1742 | - * @return void |
|
1743 | - * @throws EE_Error |
|
1744 | - */ |
|
1745 | - public function unlock_transaction() |
|
1746 | - { |
|
1747 | - if ($this->checkout->transaction instanceof EE_Transaction) { |
|
1748 | - $this->checkout->transaction->unlock(); |
|
1749 | - } |
|
1750 | - } |
|
1751 | - |
|
1752 | - |
|
1753 | - |
|
1754 | - /** |
|
1755 | - * _setup_redirect |
|
1756 | - * |
|
1757 | - * @access private |
|
1758 | - * @return void |
|
1759 | - */ |
|
1760 | - private function _setup_redirect() |
|
1761 | - { |
|
1762 | - if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
1763 | - $this->checkout->redirect = true; |
|
1764 | - if (empty($this->checkout->redirect_url)) { |
|
1765 | - $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
|
1766 | - } |
|
1767 | - $this->checkout->redirect_url = apply_filters( |
|
1768 | - 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', |
|
1769 | - $this->checkout->redirect_url, |
|
1770 | - $this->checkout |
|
1771 | - ); |
|
1772 | - } |
|
1773 | - } |
|
1774 | - |
|
1775 | - |
|
1776 | - |
|
1777 | - /** |
|
1778 | - * handle ajax message responses and redirects |
|
1779 | - * |
|
1780 | - * @access public |
|
1781 | - * @return void |
|
1782 | - * @throws EE_Error |
|
1783 | - */ |
|
1784 | - public function go_to_next_step() |
|
1785 | - { |
|
1786 | - if (EE_Registry::instance()->REQ->ajax) { |
|
1787 | - // capture contents of output buffer we started earlier in the request, and insert into JSON response |
|
1788 | - $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); |
|
1789 | - } |
|
1790 | - $this->unlock_transaction(); |
|
1791 | - // just return for these conditions |
|
1792 | - if ( |
|
1793 | - $this->checkout->admin_request |
|
1794 | - || $this->checkout->action === 'redirect_form' |
|
1795 | - || $this->checkout->action === 'update_checkout' |
|
1796 | - ) { |
|
1797 | - return; |
|
1798 | - } |
|
1799 | - // AJAX response |
|
1800 | - $this->_handle_json_response(); |
|
1801 | - // redirect to next step or the Thank You page |
|
1802 | - $this->_handle_html_redirects(); |
|
1803 | - // hmmm... must be something wrong, so let's just display the form again ! |
|
1804 | - $this->_display_spco_reg_form(); |
|
1805 | - } |
|
1806 | - |
|
1807 | - |
|
1808 | - |
|
1809 | - /** |
|
1810 | - * _handle_json_response |
|
1811 | - * |
|
1812 | - * @access protected |
|
1813 | - * @return void |
|
1814 | - */ |
|
1815 | - protected function _handle_json_response() |
|
1816 | - { |
|
1817 | - // if this is an ajax request |
|
1818 | - if (EE_Registry::instance()->REQ->ajax) { |
|
1819 | - // DEBUG LOG |
|
1820 | - //$this->checkout->log( |
|
1821 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
1822 | - // array( |
|
1823 | - // 'json_response_redirect_url' => $this->checkout->json_response->redirect_url(), |
|
1824 | - // 'redirect' => $this->checkout->redirect, |
|
1825 | - // 'continue_reg' => $this->checkout->continue_reg, |
|
1826 | - // ) |
|
1827 | - //); |
|
1828 | - $this->checkout->json_response->set_registration_time_limit( |
|
1829 | - $this->checkout->get_registration_time_limit() |
|
1830 | - ); |
|
1831 | - $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); |
|
1832 | - // just send the ajax ( |
|
1833 | - $json_response = apply_filters( |
|
1834 | - 'FHEE__EE_Single_Page_Checkout__JSON_response', |
|
1835 | - $this->checkout->json_response |
|
1836 | - ); |
|
1837 | - echo $json_response; |
|
1838 | - exit(); |
|
1839 | - } |
|
1840 | - } |
|
1841 | - |
|
1842 | - |
|
1843 | - |
|
1844 | - /** |
|
1845 | - * _handle_redirects |
|
1846 | - * |
|
1847 | - * @access protected |
|
1848 | - * @return void |
|
1849 | - */ |
|
1850 | - protected function _handle_html_redirects() |
|
1851 | - { |
|
1852 | - // going somewhere ? |
|
1853 | - if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { |
|
1854 | - // store notices in a transient |
|
1855 | - EE_Error::get_notices(false, true, true); |
|
1856 | - // DEBUG LOG |
|
1857 | - //$this->checkout->log( |
|
1858 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
1859 | - // array( |
|
1860 | - // 'headers_sent' => headers_sent(), |
|
1861 | - // 'redirect_url' => $this->checkout->redirect_url, |
|
1862 | - // 'headers_list' => headers_list(), |
|
1863 | - // ) |
|
1864 | - //); |
|
1865 | - wp_safe_redirect($this->checkout->redirect_url); |
|
1866 | - exit(); |
|
1867 | - } |
|
1868 | - } |
|
1869 | - |
|
1870 | - |
|
1871 | - |
|
1872 | - /** |
|
1873 | - * set_checkout_anchor |
|
1874 | - * |
|
1875 | - * @access public |
|
1876 | - * @return void |
|
1877 | - */ |
|
1878 | - public function set_checkout_anchor() |
|
1879 | - { |
|
1880 | - echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>'; |
|
1881 | - } |
|
23 | + /** |
|
24 | + * $_initialized - has the SPCO controller already been initialized ? |
|
25 | + * |
|
26 | + * @access private |
|
27 | + * @var bool $_initialized |
|
28 | + */ |
|
29 | + private static $_initialized = false; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * $_checkout_verified - is the EE_Checkout verified as correct for this request ? |
|
34 | + * |
|
35 | + * @access private |
|
36 | + * @var bool $_valid_checkout |
|
37 | + */ |
|
38 | + private static $_checkout_verified = true; |
|
39 | + |
|
40 | + /** |
|
41 | + * $_reg_steps_array - holds initial array of reg steps |
|
42 | + * |
|
43 | + * @access private |
|
44 | + * @var array $_reg_steps_array |
|
45 | + */ |
|
46 | + private static $_reg_steps_array = array(); |
|
47 | + |
|
48 | + /** |
|
49 | + * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
50 | + * |
|
51 | + * @access public |
|
52 | + * @var EE_Checkout $checkout |
|
53 | + */ |
|
54 | + public $checkout; |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * @return EED_Module|EED_Single_Page_Checkout |
|
60 | + */ |
|
61 | + public static function instance() |
|
62 | + { |
|
63 | + add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); |
|
64 | + return parent::get_instance(__CLASS__); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @return EE_CART |
|
71 | + */ |
|
72 | + public function cart() |
|
73 | + { |
|
74 | + return $this->checkout->cart; |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * @return EE_Transaction |
|
81 | + */ |
|
82 | + public function transaction() |
|
83 | + { |
|
84 | + return $this->checkout->transaction; |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
91 | + * |
|
92 | + * @access public |
|
93 | + * @return void |
|
94 | + * @throws EE_Error |
|
95 | + */ |
|
96 | + public static function set_hooks() |
|
97 | + { |
|
98 | + EED_Single_Page_Checkout::set_definitions(); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
105 | + * |
|
106 | + * @access public |
|
107 | + * @return void |
|
108 | + * @throws EE_Error |
|
109 | + */ |
|
110 | + public static function set_hooks_admin() |
|
111 | + { |
|
112 | + EED_Single_Page_Checkout::set_definitions(); |
|
113 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
114 | + return; |
|
115 | + } |
|
116 | + // going to start an output buffer in case anything gets accidentally output |
|
117 | + // that might disrupt our JSON response |
|
118 | + ob_start(); |
|
119 | + EED_Single_Page_Checkout::load_request_handler(); |
|
120 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
121 | + // set ajax hooks |
|
122 | + add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
123 | + add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
124 | + add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
125 | + add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
126 | + add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
127 | + add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * process ajax request |
|
134 | + * |
|
135 | + * @param string $ajax_action |
|
136 | + * @throws EE_Error |
|
137 | + */ |
|
138 | + public static function process_ajax_request($ajax_action) |
|
139 | + { |
|
140 | + EE_Registry::instance()->REQ->set('action', $ajax_action); |
|
141 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * ajax display registration step |
|
148 | + * |
|
149 | + * @throws EE_Error |
|
150 | + */ |
|
151 | + public static function display_reg_step() |
|
152 | + { |
|
153 | + EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * ajax process registration step |
|
160 | + * |
|
161 | + * @throws EE_Error |
|
162 | + */ |
|
163 | + public static function process_reg_step() |
|
164 | + { |
|
165 | + EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * ajax process registration step |
|
172 | + * |
|
173 | + * @throws EE_Error |
|
174 | + */ |
|
175 | + public static function update_reg_step() |
|
176 | + { |
|
177 | + EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * update_checkout |
|
184 | + * |
|
185 | + * @access public |
|
186 | + * @return void |
|
187 | + * @throws EE_Error |
|
188 | + */ |
|
189 | + public static function update_checkout() |
|
190 | + { |
|
191 | + EED_Single_Page_Checkout::process_ajax_request('update_checkout'); |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * load_request_handler |
|
198 | + * |
|
199 | + * @access public |
|
200 | + * @return void |
|
201 | + */ |
|
202 | + public static function load_request_handler() |
|
203 | + { |
|
204 | + // load core Request_Handler class |
|
205 | + if (EE_Registry::instance()->REQ !== null) { |
|
206 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
207 | + } |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * set_definitions |
|
214 | + * |
|
215 | + * @access public |
|
216 | + * @return void |
|
217 | + * @throws EE_Error |
|
218 | + */ |
|
219 | + public static function set_definitions() |
|
220 | + { |
|
221 | + if(defined('SPCO_BASE_PATH')) { |
|
222 | + return; |
|
223 | + } |
|
224 | + define( |
|
225 | + 'SPCO_BASE_PATH', |
|
226 | + rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS |
|
227 | + ); |
|
228 | + define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
229 | + define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
230 | + define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
231 | + define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
232 | + define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
233 | + define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
234 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
|
235 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
236 | + __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
237 | + 'event_espresso'), |
|
238 | + '<h4 class="important-notice">', |
|
239 | + '</h4>', |
|
240 | + '<br />', |
|
241 | + '<p>', |
|
242 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
243 | + '">', |
|
244 | + '</a>', |
|
245 | + '</p>' |
|
246 | + ); |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * load_reg_steps |
|
253 | + * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array |
|
254 | + * |
|
255 | + * @access private |
|
256 | + * @throws EE_Error |
|
257 | + */ |
|
258 | + public static function load_reg_steps() |
|
259 | + { |
|
260 | + static $reg_steps_loaded = false; |
|
261 | + if ($reg_steps_loaded) { |
|
262 | + return; |
|
263 | + } |
|
264 | + // filter list of reg_steps |
|
265 | + $reg_steps_to_load = (array)apply_filters( |
|
266 | + 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
|
267 | + EED_Single_Page_Checkout::get_reg_steps() |
|
268 | + ); |
|
269 | + // sort by key (order) |
|
270 | + ksort($reg_steps_to_load); |
|
271 | + // loop through folders |
|
272 | + foreach ($reg_steps_to_load as $order => $reg_step) { |
|
273 | + // we need a |
|
274 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
275 | + // copy over to the reg_steps_array |
|
276 | + EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step; |
|
277 | + // register custom key route for each reg step |
|
278 | + // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
|
279 | + EE_Config::register_route( |
|
280 | + $reg_step['slug'], |
|
281 | + 'EED_Single_Page_Checkout', |
|
282 | + 'run', |
|
283 | + 'step' |
|
284 | + ); |
|
285 | + // add AJAX or other hooks |
|
286 | + if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
|
287 | + // setup autoloaders if necessary |
|
288 | + if ( ! class_exists($reg_step['class_name'])) { |
|
289 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder( |
|
290 | + $reg_step['file_path'], |
|
291 | + true |
|
292 | + ); |
|
293 | + } |
|
294 | + if (is_callable($reg_step['class_name'], 'set_hooks')) { |
|
295 | + call_user_func(array($reg_step['class_name'], 'set_hooks')); |
|
296 | + } |
|
297 | + } |
|
298 | + } |
|
299 | + } |
|
300 | + $reg_steps_loaded = true; |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * get_reg_steps |
|
307 | + * |
|
308 | + * @access public |
|
309 | + * @return array |
|
310 | + */ |
|
311 | + public static function get_reg_steps() |
|
312 | + { |
|
313 | + $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; |
|
314 | + if (empty($reg_steps)) { |
|
315 | + $reg_steps = array( |
|
316 | + 10 => array( |
|
317 | + 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
318 | + 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
|
319 | + 'slug' => 'attendee_information', |
|
320 | + 'has_hooks' => false, |
|
321 | + ), |
|
322 | + 20 => array( |
|
323 | + 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
324 | + 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
|
325 | + 'slug' => 'registration_confirmation', |
|
326 | + 'has_hooks' => false, |
|
327 | + ), |
|
328 | + 30 => array( |
|
329 | + 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
330 | + 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
|
331 | + 'slug' => 'payment_options', |
|
332 | + 'has_hooks' => true, |
|
333 | + ), |
|
334 | + 999 => array( |
|
335 | + 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
336 | + 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
|
337 | + 'slug' => 'finalize_registration', |
|
338 | + 'has_hooks' => false, |
|
339 | + ), |
|
340 | + ); |
|
341 | + } |
|
342 | + return $reg_steps; |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * registration_checkout_for_admin |
|
349 | + * |
|
350 | + * @access public |
|
351 | + * @return string |
|
352 | + * @throws EE_Error |
|
353 | + */ |
|
354 | + public static function registration_checkout_for_admin() |
|
355 | + { |
|
356 | + EED_Single_Page_Checkout::load_request_handler(); |
|
357 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
358 | + EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); |
|
359 | + EE_Registry::instance()->REQ->set('process_form_submission', false); |
|
360 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
361 | + EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); |
|
362 | + return EE_Registry::instance()->REQ->get_output(); |
|
363 | + } |
|
364 | + |
|
365 | + |
|
366 | + |
|
367 | + /** |
|
368 | + * process_registration_from_admin |
|
369 | + * |
|
370 | + * @access public |
|
371 | + * @return \EE_Transaction |
|
372 | + * @throws EE_Error |
|
373 | + */ |
|
374 | + public static function process_registration_from_admin() |
|
375 | + { |
|
376 | + EED_Single_Page_Checkout::load_request_handler(); |
|
377 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
378 | + EE_Registry::instance()->REQ->set('action', 'process_reg_step'); |
|
379 | + EE_Registry::instance()->REQ->set('process_form_submission', true); |
|
380 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
381 | + if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { |
|
382 | + $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); |
|
383 | + if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
384 | + EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); |
|
385 | + if ($final_reg_step->process_reg_step()) { |
|
386 | + $final_reg_step->set_completed(); |
|
387 | + EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); |
|
388 | + return EED_Single_Page_Checkout::instance()->checkout->transaction; |
|
389 | + } |
|
390 | + } |
|
391 | + } |
|
392 | + return null; |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + |
|
397 | + /** |
|
398 | + * run |
|
399 | + * |
|
400 | + * @access public |
|
401 | + * @param WP_Query $WP_Query |
|
402 | + * @return void |
|
403 | + * @throws EE_Error |
|
404 | + */ |
|
405 | + public function run($WP_Query) |
|
406 | + { |
|
407 | + if ( |
|
408 | + $WP_Query instanceof WP_Query |
|
409 | + && $WP_Query->is_main_query() |
|
410 | + && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) |
|
411 | + && $this->_is_reg_checkout() |
|
412 | + ) { |
|
413 | + $this->_initialize(); |
|
414 | + } |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + |
|
419 | + /** |
|
420 | + * determines whether current url matches reg page url |
|
421 | + * |
|
422 | + * @return bool |
|
423 | + */ |
|
424 | + protected function _is_reg_checkout() |
|
425 | + { |
|
426 | + // get current permalink for reg page without any extra query args |
|
427 | + $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
|
428 | + // get request URI for current request, but without the scheme or host |
|
429 | + $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
430 | + $current_request_uri = html_entity_decode($current_request_uri); |
|
431 | + // get array of query args from the current request URI |
|
432 | + $query_args = \EEH_URL::get_query_string($current_request_uri); |
|
433 | + // grab page id if it is set |
|
434 | + $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; |
|
435 | + // and remove the page id from the query args (we will re-add it later) |
|
436 | + unset($query_args['page_id']); |
|
437 | + // now strip all query args from current request URI |
|
438 | + $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri); |
|
439 | + // and re-add the page id if it was set |
|
440 | + if ($page_id) { |
|
441 | + $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
|
442 | + } |
|
443 | + // remove slashes and ? |
|
444 | + $current_request_uri = trim($current_request_uri, '?/'); |
|
445 | + // is current request URI part of the known full reg page URL ? |
|
446 | + return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false; |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * @param WP_Query $wp_query |
|
453 | + * @return void |
|
454 | + * @throws EE_Error |
|
455 | + */ |
|
456 | + public static function init($wp_query) |
|
457 | + { |
|
458 | + EED_Single_Page_Checkout::instance()->run($wp_query); |
|
459 | + } |
|
460 | + |
|
461 | + |
|
462 | + |
|
463 | + /** |
|
464 | + * _initialize - initial module setup |
|
465 | + * |
|
466 | + * @access private |
|
467 | + * @throws EE_Error |
|
468 | + * @return void |
|
469 | + */ |
|
470 | + private function _initialize() |
|
471 | + { |
|
472 | + // ensure SPCO doesn't run twice |
|
473 | + if (EED_Single_Page_Checkout::$_initialized) { |
|
474 | + return; |
|
475 | + } |
|
476 | + try { |
|
477 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
478 | + $this->_verify_session(); |
|
479 | + // setup the EE_Checkout object |
|
480 | + $this->checkout = $this->_initialize_checkout(); |
|
481 | + // filter checkout |
|
482 | + $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); |
|
483 | + // get the $_GET |
|
484 | + $this->_get_request_vars(); |
|
485 | + if ($this->_block_bots()) { |
|
486 | + return; |
|
487 | + } |
|
488 | + // filter continue_reg |
|
489 | + $this->checkout->continue_reg = apply_filters( |
|
490 | + 'FHEE__EED_Single_Page_Checkout__init___continue_reg', |
|
491 | + true, |
|
492 | + $this->checkout |
|
493 | + ); |
|
494 | + // load the reg steps array |
|
495 | + if ( ! $this->_load_and_instantiate_reg_steps()) { |
|
496 | + EED_Single_Page_Checkout::$_initialized = true; |
|
497 | + return; |
|
498 | + } |
|
499 | + // set the current step |
|
500 | + $this->checkout->set_current_step($this->checkout->step); |
|
501 | + // and the next step |
|
502 | + $this->checkout->set_next_step(); |
|
503 | + // verify that everything has been setup correctly |
|
504 | + if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { |
|
505 | + EED_Single_Page_Checkout::$_initialized = true; |
|
506 | + return; |
|
507 | + } |
|
508 | + // lock the transaction |
|
509 | + $this->checkout->transaction->lock(); |
|
510 | + // make sure all of our cached objects are added to their respective model entity mappers |
|
511 | + $this->checkout->refresh_all_entities(); |
|
512 | + // set amount owing |
|
513 | + $this->checkout->amount_owing = $this->checkout->transaction->remaining(); |
|
514 | + // initialize each reg step, which gives them the chance to potentially alter the process |
|
515 | + $this->_initialize_reg_steps(); |
|
516 | + // DEBUG LOG |
|
517 | + //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
518 | + // get reg form |
|
519 | + if( ! $this->_check_form_submission()) { |
|
520 | + EED_Single_Page_Checkout::$_initialized = true; |
|
521 | + return; |
|
522 | + } |
|
523 | + // checkout the action!!! |
|
524 | + $this->_process_form_action(); |
|
525 | + // add some style and make it dance |
|
526 | + $this->add_styles_and_scripts(); |
|
527 | + // kk... SPCO has successfully run |
|
528 | + EED_Single_Page_Checkout::$_initialized = true; |
|
529 | + // set no cache headers and constants |
|
530 | + EE_System::do_not_cache(); |
|
531 | + // add anchor |
|
532 | + add_action('loop_start', array($this, 'set_checkout_anchor'), 1); |
|
533 | + // remove transaction lock |
|
534 | + add_action('shutdown', array($this, 'unlock_transaction'), 1); |
|
535 | + } catch (Exception $e) { |
|
536 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
537 | + } |
|
538 | + } |
|
539 | + |
|
540 | + |
|
541 | + |
|
542 | + /** |
|
543 | + * _verify_session |
|
544 | + * checks that the session is valid and not expired |
|
545 | + * |
|
546 | + * @access private |
|
547 | + * @throws EE_Error |
|
548 | + */ |
|
549 | + private function _verify_session() |
|
550 | + { |
|
551 | + if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
552 | + throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso')); |
|
553 | + } |
|
554 | + $clear_session_requested = filter_var( |
|
555 | + EE_Registry::instance()->REQ->get('clear_session', false), |
|
556 | + FILTER_VALIDATE_BOOLEAN |
|
557 | + ); |
|
558 | + // is session still valid ? |
|
559 | + if ($clear_session_requested |
|
560 | + || ( EE_Registry::instance()->SSN->expired() |
|
561 | + && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '' |
|
562 | + ) |
|
563 | + ) { |
|
564 | + $this->checkout = new EE_Checkout(); |
|
565 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
566 | + // EE_Registry::instance()->SSN->reset_cart(); |
|
567 | + // EE_Registry::instance()->SSN->reset_checkout(); |
|
568 | + // EE_Registry::instance()->SSN->reset_transaction(); |
|
569 | + if (! $clear_session_requested) { |
|
570 | + EE_Error::add_attention( |
|
571 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'], |
|
572 | + __FILE__, __FUNCTION__, __LINE__ |
|
573 | + ); |
|
574 | + } |
|
575 | + // EE_Registry::instance()->SSN->reset_expired(); |
|
576 | + } |
|
577 | + } |
|
578 | + |
|
579 | + |
|
580 | + |
|
581 | + /** |
|
582 | + * _initialize_checkout |
|
583 | + * loads and instantiates EE_Checkout |
|
584 | + * |
|
585 | + * @access private |
|
586 | + * @throws EE_Error |
|
587 | + * @return EE_Checkout |
|
588 | + */ |
|
589 | + private function _initialize_checkout() |
|
590 | + { |
|
591 | + // look in session for existing checkout |
|
592 | + /** @type EE_Checkout $checkout */ |
|
593 | + $checkout = EE_Registry::instance()->SSN->checkout(); |
|
594 | + // verify |
|
595 | + if ( ! $checkout instanceof EE_Checkout) { |
|
596 | + // instantiate EE_Checkout object for handling the properties of the current checkout process |
|
597 | + $checkout = EE_Registry::instance()->load_file( |
|
598 | + SPCO_INC_PATH, |
|
599 | + 'EE_Checkout', |
|
600 | + 'class', array(), |
|
601 | + false |
|
602 | + ); |
|
603 | + } else { |
|
604 | + if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { |
|
605 | + $this->unlock_transaction(); |
|
606 | + wp_safe_redirect($checkout->redirect_url); |
|
607 | + exit(); |
|
608 | + } |
|
609 | + } |
|
610 | + $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
|
611 | + // verify again |
|
612 | + if ( ! $checkout instanceof EE_Checkout) { |
|
613 | + throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
|
614 | + } |
|
615 | + // reset anything that needs a clean slate for each request |
|
616 | + $checkout->reset_for_current_request(); |
|
617 | + return $checkout; |
|
618 | + } |
|
619 | + |
|
620 | + |
|
621 | + |
|
622 | + /** |
|
623 | + * _get_request_vars |
|
624 | + * |
|
625 | + * @access private |
|
626 | + * @return void |
|
627 | + * @throws EE_Error |
|
628 | + */ |
|
629 | + private function _get_request_vars() |
|
630 | + { |
|
631 | + // load classes |
|
632 | + EED_Single_Page_Checkout::load_request_handler(); |
|
633 | + //make sure this request is marked as belonging to EE |
|
634 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
635 | + // which step is being requested ? |
|
636 | + $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); |
|
637 | + // which step is being edited ? |
|
638 | + $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); |
|
639 | + // and what we're doing on the current step |
|
640 | + $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); |
|
641 | + // timestamp |
|
642 | + $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); |
|
643 | + // returning to edit ? |
|
644 | + $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); |
|
645 | + // add reg url link to registration query params |
|
646 | + if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) { |
|
647 | + $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link; |
|
648 | + } |
|
649 | + // or some other kind of revisit ? |
|
650 | + $this->checkout->revisit = filter_var( |
|
651 | + EE_Registry::instance()->REQ->get('revisit', false), |
|
652 | + FILTER_VALIDATE_BOOLEAN |
|
653 | + ); |
|
654 | + // and whether or not to generate a reg form for this request |
|
655 | + $this->checkout->generate_reg_form = filter_var( |
|
656 | + EE_Registry::instance()->REQ->get('generate_reg_form', true), |
|
657 | + FILTER_VALIDATE_BOOLEAN |
|
658 | + ); |
|
659 | + // and whether or not to process a reg form submission for this request |
|
660 | + $this->checkout->process_form_submission = filter_var( |
|
661 | + EE_Registry::instance()->REQ->get( |
|
662 | + 'process_form_submission', |
|
663 | + $this->checkout->action === 'process_reg_step' |
|
664 | + ), |
|
665 | + FILTER_VALIDATE_BOOLEAN |
|
666 | + ); |
|
667 | + $this->checkout->process_form_submission = filter_var( |
|
668 | + $this->checkout->action !== 'display_spco_reg_step' |
|
669 | + ? $this->checkout->process_form_submission |
|
670 | + : false, |
|
671 | + FILTER_VALIDATE_BOOLEAN |
|
672 | + ); |
|
673 | + // $this->_display_request_vars(); |
|
674 | + } |
|
675 | + |
|
676 | + |
|
677 | + |
|
678 | + /** |
|
679 | + * _display_request_vars |
|
680 | + * |
|
681 | + * @access protected |
|
682 | + * @return void |
|
683 | + */ |
|
684 | + protected function _display_request_vars() |
|
685 | + { |
|
686 | + if ( ! WP_DEBUG) { |
|
687 | + return; |
|
688 | + } |
|
689 | + EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
|
690 | + EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); |
|
691 | + EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); |
|
692 | + EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); |
|
693 | + EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); |
|
694 | + EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); |
|
695 | + EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__); |
|
696 | + EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__); |
|
697 | + } |
|
698 | + |
|
699 | + |
|
700 | + |
|
701 | + /** |
|
702 | + * _block_bots |
|
703 | + * checks that the incoming request has either of the following set: |
|
704 | + * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector |
|
705 | + * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
|
706 | + * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
|
707 | + * then where you coming from man? |
|
708 | + * |
|
709 | + * @return boolean |
|
710 | + */ |
|
711 | + private function _block_bots() |
|
712 | + { |
|
713 | + $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
714 | + if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { |
|
715 | + return true; |
|
716 | + } |
|
717 | + return false; |
|
718 | + } |
|
719 | + |
|
720 | + |
|
721 | + |
|
722 | + /** |
|
723 | + * _get_first_step |
|
724 | + * gets slug for first step in $_reg_steps_array |
|
725 | + * |
|
726 | + * @access private |
|
727 | + * @throws EE_Error |
|
728 | + * @return string |
|
729 | + */ |
|
730 | + private function _get_first_step() |
|
731 | + { |
|
732 | + $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); |
|
733 | + return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; |
|
734 | + } |
|
735 | + |
|
736 | + |
|
737 | + |
|
738 | + /** |
|
739 | + * _load_and_instantiate_reg_steps |
|
740 | + * instantiates each reg step based on the loaded reg_steps array |
|
741 | + * |
|
742 | + * @access private |
|
743 | + * @throws EE_Error |
|
744 | + * @return bool |
|
745 | + */ |
|
746 | + private function _load_and_instantiate_reg_steps() |
|
747 | + { |
|
748 | + do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout); |
|
749 | + // have reg_steps already been instantiated ? |
|
750 | + if ( |
|
751 | + empty($this->checkout->reg_steps) |
|
752 | + || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) |
|
753 | + ) { |
|
754 | + // if not, then loop through raw reg steps array |
|
755 | + foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
|
756 | + if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
757 | + return false; |
|
758 | + } |
|
759 | + } |
|
760 | + EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true; |
|
761 | + EE_Registry::instance()->CFG->registration->reg_confirmation_last = true; |
|
762 | + // skip the registration_confirmation page ? |
|
763 | + if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { |
|
764 | + // just remove it from the reg steps array |
|
765 | + $this->checkout->remove_reg_step('registration_confirmation', false); |
|
766 | + } else if ( |
|
767 | + isset($this->checkout->reg_steps['registration_confirmation']) |
|
768 | + && EE_Registry::instance()->CFG->registration->reg_confirmation_last |
|
769 | + ) { |
|
770 | + // set the order to something big like 100 |
|
771 | + $this->checkout->set_reg_step_order('registration_confirmation', 100); |
|
772 | + } |
|
773 | + // filter the array for good luck |
|
774 | + $this->checkout->reg_steps = apply_filters( |
|
775 | + 'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps', |
|
776 | + $this->checkout->reg_steps |
|
777 | + ); |
|
778 | + // finally re-sort based on the reg step class order properties |
|
779 | + $this->checkout->sort_reg_steps(); |
|
780 | + } else { |
|
781 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
782 | + // set all current step stati to FALSE |
|
783 | + $reg_step->set_is_current_step(false); |
|
784 | + } |
|
785 | + } |
|
786 | + if (empty($this->checkout->reg_steps)) { |
|
787 | + EE_Error::add_error( |
|
788 | + __('No Reg Steps were loaded..', 'event_espresso'), |
|
789 | + __FILE__, __FUNCTION__, __LINE__ |
|
790 | + ); |
|
791 | + return false; |
|
792 | + } |
|
793 | + // make reg step details available to JS |
|
794 | + $this->checkout->set_reg_step_JSON_info(); |
|
795 | + return true; |
|
796 | + } |
|
797 | + |
|
798 | + |
|
799 | + |
|
800 | + /** |
|
801 | + * _load_and_instantiate_reg_step |
|
802 | + * |
|
803 | + * @access private |
|
804 | + * @param array $reg_step |
|
805 | + * @param int $order |
|
806 | + * @return bool |
|
807 | + */ |
|
808 | + private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) |
|
809 | + { |
|
810 | + // we need a file_path, class_name, and slug to add a reg step |
|
811 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
812 | + // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) |
|
813 | + if ( |
|
814 | + $this->checkout->reg_url_link |
|
815 | + && $this->checkout->step !== $reg_step['slug'] |
|
816 | + && $reg_step['slug'] !== 'finalize_registration' |
|
817 | + // normally at this point we would NOT load the reg step, but this filter can change that |
|
818 | + && apply_filters( |
|
819 | + 'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step', |
|
820 | + true, |
|
821 | + $reg_step, |
|
822 | + $this->checkout |
|
823 | + ) |
|
824 | + ) { |
|
825 | + return true; |
|
826 | + } |
|
827 | + // instantiate step class using file path and class name |
|
828 | + $reg_step_obj = EE_Registry::instance()->load_file( |
|
829 | + $reg_step['file_path'], |
|
830 | + $reg_step['class_name'], |
|
831 | + 'class', |
|
832 | + $this->checkout, |
|
833 | + false |
|
834 | + ); |
|
835 | + // did we gets the goods ? |
|
836 | + if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { |
|
837 | + // set reg step order based on config |
|
838 | + $reg_step_obj->set_order($order); |
|
839 | + // add instantiated reg step object to the master reg steps array |
|
840 | + $this->checkout->add_reg_step($reg_step_obj); |
|
841 | + } else { |
|
842 | + EE_Error::add_error( |
|
843 | + __('The current step could not be set.', 'event_espresso'), |
|
844 | + __FILE__, __FUNCTION__, __LINE__ |
|
845 | + ); |
|
846 | + return false; |
|
847 | + } |
|
848 | + } else { |
|
849 | + if (WP_DEBUG) { |
|
850 | + EE_Error::add_error( |
|
851 | + sprintf( |
|
852 | + __( |
|
853 | + 'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', |
|
854 | + 'event_espresso' |
|
855 | + ), |
|
856 | + isset($reg_step['file_path']) ? $reg_step['file_path'] : '', |
|
857 | + isset($reg_step['class_name']) ? $reg_step['class_name'] : '', |
|
858 | + isset($reg_step['slug']) ? $reg_step['slug'] : '', |
|
859 | + '<ul>', |
|
860 | + '<li>', |
|
861 | + '</li>', |
|
862 | + '</ul>' |
|
863 | + ), |
|
864 | + __FILE__, __FUNCTION__, __LINE__ |
|
865 | + ); |
|
866 | + } |
|
867 | + return false; |
|
868 | + } |
|
869 | + return true; |
|
870 | + } |
|
871 | + |
|
872 | + |
|
873 | + /** |
|
874 | + * _verify_transaction_and_get_registrations |
|
875 | + * |
|
876 | + * @access private |
|
877 | + * @return bool |
|
878 | + * @throws InvalidDataTypeException |
|
879 | + * @throws InvalidEntityException |
|
880 | + * @throws EE_Error |
|
881 | + */ |
|
882 | + private function _verify_transaction_and_get_registrations() |
|
883 | + { |
|
884 | + // was there already a valid transaction in the checkout from the session ? |
|
885 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
886 | + // get transaction from db or session |
|
887 | + $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
|
888 | + ? $this->_get_transaction_and_cart_for_previous_visit() |
|
889 | + : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
|
890 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
891 | + EE_Error::add_error( |
|
892 | + __('Your Registration and Transaction information could not be retrieved from the db.', |
|
893 | + 'event_espresso'), |
|
894 | + __FILE__, __FUNCTION__, __LINE__ |
|
895 | + ); |
|
896 | + $this->checkout->transaction = EE_Transaction::new_instance(); |
|
897 | + // add some style and make it dance |
|
898 | + $this->add_styles_and_scripts(); |
|
899 | + EED_Single_Page_Checkout::$_initialized = true; |
|
900 | + return false; |
|
901 | + } |
|
902 | + // and the registrations for the transaction |
|
903 | + $this->_get_registrations($this->checkout->transaction); |
|
904 | + } |
|
905 | + return true; |
|
906 | + } |
|
907 | + |
|
908 | + |
|
909 | + |
|
910 | + /** |
|
911 | + * _get_transaction_and_cart_for_previous_visit |
|
912 | + * |
|
913 | + * @access private |
|
914 | + * @return mixed EE_Transaction|NULL |
|
915 | + */ |
|
916 | + private function _get_transaction_and_cart_for_previous_visit() |
|
917 | + { |
|
918 | + /** @var $TXN_model EEM_Transaction */ |
|
919 | + $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
920 | + // because the reg_url_link is present in the request, |
|
921 | + // this is a return visit to SPCO, so we'll get the transaction data from the db |
|
922 | + $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); |
|
923 | + // verify transaction |
|
924 | + if ($transaction instanceof EE_Transaction) { |
|
925 | + // and get the cart that was used for that transaction |
|
926 | + $this->checkout->cart = $this->_get_cart_for_transaction($transaction); |
|
927 | + return $transaction; |
|
928 | + } |
|
929 | + EE_Error::add_error( |
|
930 | + __('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), |
|
931 | + __FILE__, __FUNCTION__, __LINE__ |
|
932 | + ); |
|
933 | + return null; |
|
934 | + |
|
935 | + } |
|
936 | + |
|
937 | + |
|
938 | + |
|
939 | + /** |
|
940 | + * _get_cart_for_transaction |
|
941 | + * |
|
942 | + * @access private |
|
943 | + * @param EE_Transaction $transaction |
|
944 | + * @return EE_Cart |
|
945 | + */ |
|
946 | + private function _get_cart_for_transaction($transaction) |
|
947 | + { |
|
948 | + return $this->checkout->get_cart_for_transaction($transaction); |
|
949 | + } |
|
950 | + |
|
951 | + |
|
952 | + |
|
953 | + /** |
|
954 | + * get_cart_for_transaction |
|
955 | + * |
|
956 | + * @access public |
|
957 | + * @param EE_Transaction $transaction |
|
958 | + * @return EE_Cart |
|
959 | + */ |
|
960 | + public function get_cart_for_transaction(EE_Transaction $transaction) |
|
961 | + { |
|
962 | + return $this->checkout->get_cart_for_transaction($transaction); |
|
963 | + } |
|
964 | + |
|
965 | + |
|
966 | + |
|
967 | + /** |
|
968 | + * _get_transaction_and_cart_for_current_session |
|
969 | + * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
970 | + * |
|
971 | + * @access private |
|
972 | + * @return EE_Transaction |
|
973 | + * @throws EE_Error |
|
974 | + */ |
|
975 | + private function _get_cart_for_current_session_and_setup_new_transaction() |
|
976 | + { |
|
977 | + // if there's no transaction, then this is the FIRST visit to SPCO |
|
978 | + // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) |
|
979 | + $this->checkout->cart = $this->_get_cart_for_transaction(null); |
|
980 | + // and then create a new transaction |
|
981 | + $transaction = $this->_initialize_transaction(); |
|
982 | + // verify transaction |
|
983 | + if ($transaction instanceof EE_Transaction) { |
|
984 | + // save it so that we have an ID for other objects to use |
|
985 | + $transaction->save(); |
|
986 | + // and save TXN data to the cart |
|
987 | + $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); |
|
988 | + } else { |
|
989 | + EE_Error::add_error( |
|
990 | + __('A Valid Transaction could not be initialized.', 'event_espresso'), |
|
991 | + __FILE__, __FUNCTION__, __LINE__ |
|
992 | + ); |
|
993 | + } |
|
994 | + return $transaction; |
|
995 | + } |
|
996 | + |
|
997 | + |
|
998 | + |
|
999 | + /** |
|
1000 | + * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
1001 | + * |
|
1002 | + * @access private |
|
1003 | + * @return mixed EE_Transaction|NULL |
|
1004 | + */ |
|
1005 | + private function _initialize_transaction() |
|
1006 | + { |
|
1007 | + try { |
|
1008 | + // ensure cart totals have been calculated |
|
1009 | + $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
1010 | + // grab the cart grand total |
|
1011 | + $cart_total = $this->checkout->cart->get_cart_grand_total(); |
|
1012 | + // create new TXN |
|
1013 | + $transaction = EE_Transaction::new_instance( |
|
1014 | + array( |
|
1015 | + 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), |
|
1016 | + 'TXN_total' => $cart_total > 0 ? $cart_total : 0, |
|
1017 | + 'TXN_paid' => 0, |
|
1018 | + 'STS_ID' => EEM_Transaction::failed_status_code, |
|
1019 | + ) |
|
1020 | + ); |
|
1021 | + // save it so that we have an ID for other objects to use |
|
1022 | + $transaction->save(); |
|
1023 | + // set cron job for following up on TXNs after their session has expired |
|
1024 | + EE_Cron_Tasks::schedule_expired_transaction_check( |
|
1025 | + EE_Registry::instance()->SSN->expiration() + 1, |
|
1026 | + $transaction->ID() |
|
1027 | + ); |
|
1028 | + return $transaction; |
|
1029 | + } catch (Exception $e) { |
|
1030 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1031 | + } |
|
1032 | + return null; |
|
1033 | + } |
|
1034 | + |
|
1035 | + |
|
1036 | + /** |
|
1037 | + * _get_registrations |
|
1038 | + * |
|
1039 | + * @access private |
|
1040 | + * @param EE_Transaction $transaction |
|
1041 | + * @return void |
|
1042 | + * @throws InvalidDataTypeException |
|
1043 | + * @throws InvalidEntityException |
|
1044 | + * @throws EE_Error |
|
1045 | + */ |
|
1046 | + private function _get_registrations(EE_Transaction $transaction) |
|
1047 | + { |
|
1048 | + // first step: grab the registrants { : o |
|
1049 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
1050 | + $this->checkout->total_ticket_count = count($registrations); |
|
1051 | + // verify registrations have been set |
|
1052 | + if (empty($registrations)) { |
|
1053 | + // if no cached registrations, then check the db |
|
1054 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
1055 | + // still nothing ? well as long as this isn't a revisit |
|
1056 | + if (empty($registrations) && ! $this->checkout->revisit) { |
|
1057 | + // generate new registrations from scratch |
|
1058 | + $registrations = $this->_initialize_registrations($transaction); |
|
1059 | + } |
|
1060 | + } |
|
1061 | + // sort by their original registration order |
|
1062 | + usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); |
|
1063 | + // then loop thru the array |
|
1064 | + foreach ($registrations as $registration) { |
|
1065 | + // verify each registration |
|
1066 | + if ($registration instanceof EE_Registration) { |
|
1067 | + // we display all attendee info for the primary registrant |
|
1068 | + if ($this->checkout->reg_url_link === $registration->reg_url_link() |
|
1069 | + && $registration->is_primary_registrant() |
|
1070 | + ) { |
|
1071 | + $this->checkout->primary_revisit = true; |
|
1072 | + break; |
|
1073 | + } |
|
1074 | + if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) { |
|
1075 | + // but hide info if it doesn't belong to you |
|
1076 | + $transaction->clear_cache('Registration', $registration->ID()); |
|
1077 | + $this->checkout->total_ticket_count--; |
|
1078 | + } |
|
1079 | + $this->checkout->set_reg_status_updated($registration->ID(), false); |
|
1080 | + } |
|
1081 | + } |
|
1082 | + } |
|
1083 | + |
|
1084 | + |
|
1085 | + /** |
|
1086 | + * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
|
1087 | + * |
|
1088 | + * @access private |
|
1089 | + * @param EE_Transaction $transaction |
|
1090 | + * @return array |
|
1091 | + * @throws InvalidDataTypeException |
|
1092 | + * @throws InvalidEntityException |
|
1093 | + * @throws EE_Error |
|
1094 | + */ |
|
1095 | + private function _initialize_registrations(EE_Transaction $transaction) |
|
1096 | + { |
|
1097 | + $att_nmbr = 0; |
|
1098 | + $registrations = array(); |
|
1099 | + if ($transaction instanceof EE_Transaction) { |
|
1100 | + /** @type EE_Registration_Processor $registration_processor */ |
|
1101 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1102 | + $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); |
|
1103 | + // now let's add the cart items to the $transaction |
|
1104 | + foreach ($this->checkout->cart->get_tickets() as $line_item) { |
|
1105 | + //do the following for each ticket of this type they selected |
|
1106 | + for ($x = 1; $x <= $line_item->quantity(); $x++) { |
|
1107 | + $att_nmbr++; |
|
1108 | + /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
|
1109 | + $CreateRegistrationCommand = EE_Registry::instance()->create( |
|
1110 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
1111 | + array( |
|
1112 | + $transaction, |
|
1113 | + $line_item, |
|
1114 | + $att_nmbr, |
|
1115 | + $this->checkout->total_ticket_count, |
|
1116 | + ) |
|
1117 | + ); |
|
1118 | + // override capabilities for frontend registrations |
|
1119 | + if ( ! is_admin()) { |
|
1120 | + $CreateRegistrationCommand->setCapCheck( |
|
1121 | + new PublicCapabilities('', 'create_new_registration') |
|
1122 | + ); |
|
1123 | + } |
|
1124 | + $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
|
1125 | + if ( ! $registration instanceof EE_Registration) { |
|
1126 | + throw new InvalidEntityException($registration, 'EE_Registration'); |
|
1127 | + } |
|
1128 | + $registrations[ $registration->ID() ] = $registration; |
|
1129 | + } |
|
1130 | + } |
|
1131 | + $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
|
1132 | + } |
|
1133 | + return $registrations; |
|
1134 | + } |
|
1135 | + |
|
1136 | + |
|
1137 | + |
|
1138 | + /** |
|
1139 | + * sorts registrations by REG_count |
|
1140 | + * |
|
1141 | + * @access public |
|
1142 | + * @param EE_Registration $reg_A |
|
1143 | + * @param EE_Registration $reg_B |
|
1144 | + * @return int |
|
1145 | + */ |
|
1146 | + public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) |
|
1147 | + { |
|
1148 | + // this shouldn't ever happen within the same TXN, but oh well |
|
1149 | + if ($reg_A->count() === $reg_B->count()) { |
|
1150 | + return 0; |
|
1151 | + } |
|
1152 | + return ($reg_A->count() > $reg_B->count()) ? 1 : -1; |
|
1153 | + } |
|
1154 | + |
|
1155 | + |
|
1156 | + |
|
1157 | + /** |
|
1158 | + * _final_verifications |
|
1159 | + * just makes sure that everything is set up correctly before proceeding |
|
1160 | + * |
|
1161 | + * @access private |
|
1162 | + * @return bool |
|
1163 | + * @throws EE_Error |
|
1164 | + */ |
|
1165 | + private function _final_verifications() |
|
1166 | + { |
|
1167 | + // filter checkout |
|
1168 | + $this->checkout = apply_filters( |
|
1169 | + 'FHEE__EED_Single_Page_Checkout___final_verifications__checkout', |
|
1170 | + $this->checkout |
|
1171 | + ); |
|
1172 | + //verify that current step is still set correctly |
|
1173 | + if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
1174 | + EE_Error::add_error( |
|
1175 | + __('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1176 | + __FILE__, |
|
1177 | + __FUNCTION__, |
|
1178 | + __LINE__ |
|
1179 | + ); |
|
1180 | + return false; |
|
1181 | + } |
|
1182 | + // if returning to SPCO, then verify that primary registrant is set |
|
1183 | + if ( ! empty($this->checkout->reg_url_link)) { |
|
1184 | + $valid_registrant = $this->checkout->transaction->primary_registration(); |
|
1185 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
1186 | + EE_Error::add_error( |
|
1187 | + __('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1188 | + __FILE__, |
|
1189 | + __FUNCTION__, |
|
1190 | + __LINE__ |
|
1191 | + ); |
|
1192 | + return false; |
|
1193 | + } |
|
1194 | + $valid_registrant = null; |
|
1195 | + foreach ( |
|
1196 | + $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration |
|
1197 | + ) { |
|
1198 | + if ( |
|
1199 | + $registration instanceof EE_Registration |
|
1200 | + && $registration->reg_url_link() === $this->checkout->reg_url_link |
|
1201 | + ) { |
|
1202 | + $valid_registrant = $registration; |
|
1203 | + } |
|
1204 | + } |
|
1205 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
1206 | + // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
|
1207 | + if (EED_Single_Page_Checkout::$_checkout_verified) { |
|
1208 | + // clear the session, mark the checkout as unverified, and try again |
|
1209 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
1210 | + EED_Single_Page_Checkout::$_initialized = false; |
|
1211 | + EED_Single_Page_Checkout::$_checkout_verified = false; |
|
1212 | + $this->_initialize(); |
|
1213 | + EE_Error::reset_notices(); |
|
1214 | + return false; |
|
1215 | + } |
|
1216 | + EE_Error::add_error( |
|
1217 | + __( |
|
1218 | + 'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', |
|
1219 | + 'event_espresso' |
|
1220 | + ), |
|
1221 | + __FILE__, |
|
1222 | + __FUNCTION__, |
|
1223 | + __LINE__ |
|
1224 | + ); |
|
1225 | + return false; |
|
1226 | + } |
|
1227 | + } |
|
1228 | + // now that things have been kinda sufficiently verified, |
|
1229 | + // let's add the checkout to the session so that it's available to other systems |
|
1230 | + EE_Registry::instance()->SSN->set_checkout($this->checkout); |
|
1231 | + return true; |
|
1232 | + } |
|
1233 | + |
|
1234 | + |
|
1235 | + |
|
1236 | + /** |
|
1237 | + * _initialize_reg_steps |
|
1238 | + * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required |
|
1239 | + * then loops thru all of the active reg steps and calls the initialize_reg_step() method |
|
1240 | + * |
|
1241 | + * @access private |
|
1242 | + * @param bool $reinitializing |
|
1243 | + * @throws EE_Error |
|
1244 | + */ |
|
1245 | + private function _initialize_reg_steps($reinitializing = false) |
|
1246 | + { |
|
1247 | + $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
|
1248 | + // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
|
1249 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
1250 | + if ( ! $reg_step->initialize_reg_step()) { |
|
1251 | + // if not initialized then maybe this step is being removed... |
|
1252 | + if ( ! $reinitializing && $reg_step->is_current_step()) { |
|
1253 | + // if it was the current step, then we need to start over here |
|
1254 | + $this->_initialize_reg_steps(true); |
|
1255 | + return; |
|
1256 | + } |
|
1257 | + continue; |
|
1258 | + } |
|
1259 | + // add css and JS for current step |
|
1260 | + $reg_step->enqueue_styles_and_scripts(); |
|
1261 | + // i18n |
|
1262 | + $reg_step->translate_js_strings(); |
|
1263 | + if ($reg_step->is_current_step()) { |
|
1264 | + // the text that appears on the reg step form submit button |
|
1265 | + $reg_step->set_submit_button_text(); |
|
1266 | + } |
|
1267 | + } |
|
1268 | + // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
|
1269 | + do_action( |
|
1270 | + "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", |
|
1271 | + $this->checkout->current_step |
|
1272 | + ); |
|
1273 | + } |
|
1274 | + |
|
1275 | + |
|
1276 | + |
|
1277 | + /** |
|
1278 | + * _check_form_submission |
|
1279 | + * |
|
1280 | + * @access private |
|
1281 | + * @return boolean |
|
1282 | + */ |
|
1283 | + private function _check_form_submission() |
|
1284 | + { |
|
1285 | + //does this request require the reg form to be generated ? |
|
1286 | + if ($this->checkout->generate_reg_form) { |
|
1287 | + // ever heard that song by Blue Rodeo ? |
|
1288 | + try { |
|
1289 | + $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
|
1290 | + // if not displaying a form, then check for form submission |
|
1291 | + if ( |
|
1292 | + $this->checkout->process_form_submission |
|
1293 | + && $this->checkout->current_step->reg_form->was_submitted() |
|
1294 | + ) { |
|
1295 | + // clear out any old data in case this step is being run again |
|
1296 | + $this->checkout->current_step->set_valid_data(array()); |
|
1297 | + // capture submitted form data |
|
1298 | + $this->checkout->current_step->reg_form->receive_form_submission( |
|
1299 | + apply_filters( |
|
1300 | + 'FHEE__Single_Page_Checkout___check_form_submission__request_params', |
|
1301 | + EE_Registry::instance()->REQ->params(), |
|
1302 | + $this->checkout |
|
1303 | + ) |
|
1304 | + ); |
|
1305 | + // validate submitted form data |
|
1306 | + if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { |
|
1307 | + // thou shall not pass !!! |
|
1308 | + $this->checkout->continue_reg = false; |
|
1309 | + // any form validation errors? |
|
1310 | + if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { |
|
1311 | + $submission_error_messages = array(); |
|
1312 | + // bad, bad, bad registrant |
|
1313 | + foreach ( |
|
1314 | + $this->checkout->current_step->reg_form->get_validation_errors_accumulated() |
|
1315 | + as $validation_error |
|
1316 | + ) { |
|
1317 | + if ($validation_error instanceof EE_Validation_Error) { |
|
1318 | + $submission_error_messages[] = sprintf( |
|
1319 | + __('%s : %s', 'event_espresso'), |
|
1320 | + $validation_error->get_form_section()->html_label_text(), |
|
1321 | + $validation_error->getMessage() |
|
1322 | + ); |
|
1323 | + } |
|
1324 | + } |
|
1325 | + EE_Error::add_error( |
|
1326 | + implode('<br />', $submission_error_messages), |
|
1327 | + __FILE__, __FUNCTION__, __LINE__ |
|
1328 | + ); |
|
1329 | + } |
|
1330 | + // well not really... what will happen is |
|
1331 | + // we'll just get redirected back to redo the current step |
|
1332 | + $this->go_to_next_step(); |
|
1333 | + return false; |
|
1334 | + } |
|
1335 | + } |
|
1336 | + } catch (EE_Error $e) { |
|
1337 | + $e->get_error(); |
|
1338 | + } |
|
1339 | + } |
|
1340 | + return true; |
|
1341 | + } |
|
1342 | + |
|
1343 | + |
|
1344 | + |
|
1345 | + /** |
|
1346 | + * _process_action |
|
1347 | + * |
|
1348 | + * @access private |
|
1349 | + * @return void |
|
1350 | + * @throws EE_Error |
|
1351 | + */ |
|
1352 | + private function _process_form_action() |
|
1353 | + { |
|
1354 | + // what cha wanna do? |
|
1355 | + switch ($this->checkout->action) { |
|
1356 | + // AJAX next step reg form |
|
1357 | + case 'display_spco_reg_step' : |
|
1358 | + $this->checkout->redirect = false; |
|
1359 | + if (EE_Registry::instance()->REQ->ajax) { |
|
1360 | + $this->checkout->json_response->set_reg_step_html( |
|
1361 | + $this->checkout->current_step->display_reg_form() |
|
1362 | + ); |
|
1363 | + } |
|
1364 | + break; |
|
1365 | + default : |
|
1366 | + // meh... do one of those other steps first |
|
1367 | + if ( |
|
1368 | + ! empty($this->checkout->action) |
|
1369 | + && is_callable(array($this->checkout->current_step, $this->checkout->action)) |
|
1370 | + ) { |
|
1371 | + // dynamically creates hook point like: |
|
1372 | + // AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
|
1373 | + do_action( |
|
1374 | + "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
1375 | + $this->checkout->current_step |
|
1376 | + ); |
|
1377 | + // call action on current step |
|
1378 | + if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { |
|
1379 | + // good registrant, you get to proceed |
|
1380 | + if ( |
|
1381 | + $this->checkout->current_step->success_message() !== '' |
|
1382 | + && apply_filters( |
|
1383 | + 'FHEE__Single_Page_Checkout___process_form_action__display_success', |
|
1384 | + false |
|
1385 | + ) |
|
1386 | + ) { |
|
1387 | + EE_Error::add_success( |
|
1388 | + $this->checkout->current_step->success_message() |
|
1389 | + . '<br />' . $this->checkout->next_step->_instructions() |
|
1390 | + ); |
|
1391 | + } |
|
1392 | + // pack it up, pack it in... |
|
1393 | + $this->_setup_redirect(); |
|
1394 | + } |
|
1395 | + // dynamically creates hook point like: |
|
1396 | + // AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
|
1397 | + do_action( |
|
1398 | + "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", |
|
1399 | + $this->checkout->current_step |
|
1400 | + ); |
|
1401 | + } else { |
|
1402 | + EE_Error::add_error( |
|
1403 | + sprintf( |
|
1404 | + __( |
|
1405 | + 'The requested form action "%s" does not exist for the current "%s" registration step.', |
|
1406 | + 'event_espresso' |
|
1407 | + ), |
|
1408 | + $this->checkout->action, |
|
1409 | + $this->checkout->current_step->name() |
|
1410 | + ), |
|
1411 | + __FILE__, |
|
1412 | + __FUNCTION__, |
|
1413 | + __LINE__ |
|
1414 | + ); |
|
1415 | + } |
|
1416 | + // end default |
|
1417 | + } |
|
1418 | + // store our progress so far |
|
1419 | + $this->checkout->stash_transaction_and_checkout(); |
|
1420 | + // advance to the next step! If you pass GO, collect $200 |
|
1421 | + $this->go_to_next_step(); |
|
1422 | + } |
|
1423 | + |
|
1424 | + |
|
1425 | + |
|
1426 | + /** |
|
1427 | + * add_styles_and_scripts |
|
1428 | + * |
|
1429 | + * @access public |
|
1430 | + * @return void |
|
1431 | + */ |
|
1432 | + public function add_styles_and_scripts() |
|
1433 | + { |
|
1434 | + // i18n |
|
1435 | + $this->translate_js_strings(); |
|
1436 | + if ($this->checkout->admin_request) { |
|
1437 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1438 | + } else { |
|
1439 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1440 | + } |
|
1441 | + } |
|
1442 | + |
|
1443 | + |
|
1444 | + |
|
1445 | + /** |
|
1446 | + * translate_js_strings |
|
1447 | + * |
|
1448 | + * @access public |
|
1449 | + * @return void |
|
1450 | + */ |
|
1451 | + public function translate_js_strings() |
|
1452 | + { |
|
1453 | + EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
|
1454 | + EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
1455 | + EE_Registry::$i18n_js_strings['server_error'] = __( |
|
1456 | + 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
1457 | + 'event_espresso' |
|
1458 | + ); |
|
1459 | + EE_Registry::$i18n_js_strings['invalid_json_response'] = __( |
|
1460 | + 'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', |
|
1461 | + 'event_espresso' |
|
1462 | + ); |
|
1463 | + EE_Registry::$i18n_js_strings['validation_error'] = __( |
|
1464 | + 'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', |
|
1465 | + 'event_espresso' |
|
1466 | + ); |
|
1467 | + EE_Registry::$i18n_js_strings['invalid_payment_method'] = __( |
|
1468 | + 'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', |
|
1469 | + 'event_espresso' |
|
1470 | + ); |
|
1471 | + EE_Registry::$i18n_js_strings['reg_step_error'] = __( |
|
1472 | + 'This registration step could not be completed. Please refresh the page and try again.', |
|
1473 | + 'event_espresso' |
|
1474 | + ); |
|
1475 | + EE_Registry::$i18n_js_strings['invalid_coupon'] = __( |
|
1476 | + 'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', |
|
1477 | + 'event_espresso' |
|
1478 | + ); |
|
1479 | + EE_Registry::$i18n_js_strings['process_registration'] = sprintf( |
|
1480 | + __( |
|
1481 | + 'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', |
|
1482 | + 'event_espresso' |
|
1483 | + ), |
|
1484 | + '<br/>', |
|
1485 | + '<br/>' |
|
1486 | + ); |
|
1487 | + EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); |
|
1488 | + EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
|
1489 | + EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
|
1490 | + EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
|
1491 | + EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso'); |
|
1492 | + EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso'); |
|
1493 | + EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso'); |
|
1494 | + EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso'); |
|
1495 | + EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso'); |
|
1496 | + EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso'); |
|
1497 | + EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso'); |
|
1498 | + EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso'); |
|
1499 | + EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso'); |
|
1500 | + EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso'); |
|
1501 | + EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso'); |
|
1502 | + EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso'); |
|
1503 | + EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso'); |
|
1504 | + EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso'); |
|
1505 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
1506 | + __( |
|
1507 | + '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
1508 | + 'event_espresso' |
|
1509 | + ), |
|
1510 | + '<h4 class="important-notice">', |
|
1511 | + '</h4>', |
|
1512 | + '<br />', |
|
1513 | + '<p>', |
|
1514 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1515 | + '">', |
|
1516 | + '</a>', |
|
1517 | + '</p>' |
|
1518 | + ); |
|
1519 | + EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters( |
|
1520 | + 'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', |
|
1521 | + true |
|
1522 | + ); |
|
1523 | + EE_Registry::$i18n_js_strings['session_extension'] = absint( |
|
1524 | + apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS) |
|
1525 | + ); |
|
1526 | + EE_Registry::$i18n_js_strings['session_expiration'] = gmdate( |
|
1527 | + 'M d, Y H:i:s', |
|
1528 | + EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
1529 | + ); |
|
1530 | + } |
|
1531 | + |
|
1532 | + |
|
1533 | + |
|
1534 | + /** |
|
1535 | + * enqueue_styles_and_scripts |
|
1536 | + * |
|
1537 | + * @access public |
|
1538 | + * @return void |
|
1539 | + * @throws EE_Error |
|
1540 | + */ |
|
1541 | + public function enqueue_styles_and_scripts() |
|
1542 | + { |
|
1543 | + // load css |
|
1544 | + wp_register_style( |
|
1545 | + 'single_page_checkout', |
|
1546 | + SPCO_CSS_URL . 'single_page_checkout.css', |
|
1547 | + array('espresso_default'), |
|
1548 | + EVENT_ESPRESSO_VERSION |
|
1549 | + ); |
|
1550 | + wp_enqueue_style('single_page_checkout'); |
|
1551 | + // load JS |
|
1552 | + wp_register_script( |
|
1553 | + 'jquery_plugin', |
|
1554 | + EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', |
|
1555 | + array('jquery'), |
|
1556 | + '1.0.1', |
|
1557 | + true |
|
1558 | + ); |
|
1559 | + wp_register_script( |
|
1560 | + 'jquery_countdown', |
|
1561 | + EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', |
|
1562 | + array('jquery_plugin'), |
|
1563 | + '2.0.2', |
|
1564 | + true |
|
1565 | + ); |
|
1566 | + wp_register_script( |
|
1567 | + 'single_page_checkout', |
|
1568 | + SPCO_JS_URL . 'single_page_checkout.js', |
|
1569 | + array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), |
|
1570 | + EVENT_ESPRESSO_VERSION, |
|
1571 | + true |
|
1572 | + ); |
|
1573 | + if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) { |
|
1574 | + $this->checkout->registration_form->enqueue_js(); |
|
1575 | + } |
|
1576 | + if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) { |
|
1577 | + $this->checkout->current_step->reg_form->enqueue_js(); |
|
1578 | + } |
|
1579 | + wp_enqueue_script('single_page_checkout'); |
|
1580 | + /** |
|
1581 | + * global action hook for enqueueing styles and scripts with |
|
1582 | + * spco calls. |
|
1583 | + */ |
|
1584 | + do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); |
|
1585 | + /** |
|
1586 | + * dynamic action hook for enqueueing styles and scripts with spco calls. |
|
1587 | + * The hook will end up being something like: |
|
1588 | + * AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
|
1589 | + */ |
|
1590 | + do_action( |
|
1591 | + 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), |
|
1592 | + $this |
|
1593 | + ); |
|
1594 | + } |
|
1595 | + |
|
1596 | + |
|
1597 | + |
|
1598 | + /** |
|
1599 | + * display the Registration Single Page Checkout Form |
|
1600 | + * |
|
1601 | + * @access private |
|
1602 | + * @return void |
|
1603 | + * @throws EE_Error |
|
1604 | + */ |
|
1605 | + private function _display_spco_reg_form() |
|
1606 | + { |
|
1607 | + // if registering via the admin, just display the reg form for the current step |
|
1608 | + if ($this->checkout->admin_request) { |
|
1609 | + EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); |
|
1610 | + } else { |
|
1611 | + // add powered by EE msg |
|
1612 | + add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); |
|
1613 | + $empty_cart = count( |
|
1614 | + $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) |
|
1615 | + ) < 1; |
|
1616 | + EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart; |
|
1617 | + $cookies_not_set_msg = ''; |
|
1618 | + if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) { |
|
1619 | + $cookies_not_set_msg = apply_filters( |
|
1620 | + 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', |
|
1621 | + sprintf( |
|
1622 | + __( |
|
1623 | + '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', |
|
1624 | + 'event_espresso' |
|
1625 | + ), |
|
1626 | + '<div class="ee-attention">', |
|
1627 | + '</div>', |
|
1628 | + '<h6 class="important-notice">', |
|
1629 | + '</h6>', |
|
1630 | + '<p>', |
|
1631 | + '</p>', |
|
1632 | + '<br />', |
|
1633 | + '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">', |
|
1634 | + '</a>' |
|
1635 | + ) |
|
1636 | + ); |
|
1637 | + } |
|
1638 | + $this->checkout->registration_form = new EE_Form_Section_Proper( |
|
1639 | + array( |
|
1640 | + 'name' => 'single-page-checkout', |
|
1641 | + 'html_id' => 'ee-single-page-checkout-dv', |
|
1642 | + 'layout_strategy' => |
|
1643 | + new EE_Template_Layout( |
|
1644 | + array( |
|
1645 | + 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
1646 | + 'template_args' => array( |
|
1647 | + 'empty_cart' => $empty_cart, |
|
1648 | + 'revisit' => $this->checkout->revisit, |
|
1649 | + 'reg_steps' => $this->checkout->reg_steps, |
|
1650 | + 'next_step' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
1651 | + ? $this->checkout->next_step->slug() |
|
1652 | + : '', |
|
1653 | + 'cancel_page_url' => $this->checkout->cancel_page_url, |
|
1654 | + 'empty_msg' => apply_filters( |
|
1655 | + 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
|
1656 | + sprintf( |
|
1657 | + __( |
|
1658 | + 'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', |
|
1659 | + 'event_espresso' |
|
1660 | + ), |
|
1661 | + '<a href="' |
|
1662 | + . get_post_type_archive_link('espresso_events') |
|
1663 | + . '" title="', |
|
1664 | + '">', |
|
1665 | + '</a>' |
|
1666 | + ) |
|
1667 | + ), |
|
1668 | + 'cookies_not_set_msg' => $cookies_not_set_msg, |
|
1669 | + 'registration_time_limit' => $this->checkout->get_registration_time_limit(), |
|
1670 | + 'session_expiration' => gmdate( |
|
1671 | + 'M d, Y H:i:s', |
|
1672 | + EE_Registry::instance()->SSN->expiration() |
|
1673 | + + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
1674 | + ), |
|
1675 | + ), |
|
1676 | + ) |
|
1677 | + ), |
|
1678 | + ) |
|
1679 | + ); |
|
1680 | + // load template and add to output sent that gets filtered into the_content() |
|
1681 | + EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); |
|
1682 | + } |
|
1683 | + } |
|
1684 | + |
|
1685 | + |
|
1686 | + |
|
1687 | + /** |
|
1688 | + * add_extra_finalize_registration_inputs |
|
1689 | + * |
|
1690 | + * @access public |
|
1691 | + * @param $next_step |
|
1692 | + * @internal param string $label |
|
1693 | + * @return void |
|
1694 | + */ |
|
1695 | + public function add_extra_finalize_registration_inputs($next_step) |
|
1696 | + { |
|
1697 | + if ($next_step === 'finalize_registration') { |
|
1698 | + echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; |
|
1699 | + } |
|
1700 | + } |
|
1701 | + |
|
1702 | + |
|
1703 | + |
|
1704 | + /** |
|
1705 | + * display_registration_footer |
|
1706 | + * |
|
1707 | + * @access public |
|
1708 | + * @return string |
|
1709 | + */ |
|
1710 | + public static function display_registration_footer() |
|
1711 | + { |
|
1712 | + if ( |
|
1713 | + apply_filters( |
|
1714 | + 'FHEE__EE_Front__Controller__show_reg_footer', |
|
1715 | + EE_Registry::instance()->CFG->admin->show_reg_footer |
|
1716 | + ) |
|
1717 | + ) { |
|
1718 | + add_filter( |
|
1719 | + 'FHEE__EEH_Template__powered_by_event_espresso__url', |
|
1720 | + function ($url) { |
|
1721 | + return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
|
1722 | + } |
|
1723 | + ); |
|
1724 | + echo apply_filters( |
|
1725 | + 'FHEE__EE_Front_Controller__display_registration_footer', |
|
1726 | + \EEH_Template::powered_by_event_espresso( |
|
1727 | + '', |
|
1728 | + 'espresso-registration-footer-dv', |
|
1729 | + array('utm_content' => 'registration_checkout') |
|
1730 | + ) |
|
1731 | + ); |
|
1732 | + } |
|
1733 | + return ''; |
|
1734 | + } |
|
1735 | + |
|
1736 | + |
|
1737 | + |
|
1738 | + /** |
|
1739 | + * unlock_transaction |
|
1740 | + * |
|
1741 | + * @access public |
|
1742 | + * @return void |
|
1743 | + * @throws EE_Error |
|
1744 | + */ |
|
1745 | + public function unlock_transaction() |
|
1746 | + { |
|
1747 | + if ($this->checkout->transaction instanceof EE_Transaction) { |
|
1748 | + $this->checkout->transaction->unlock(); |
|
1749 | + } |
|
1750 | + } |
|
1751 | + |
|
1752 | + |
|
1753 | + |
|
1754 | + /** |
|
1755 | + * _setup_redirect |
|
1756 | + * |
|
1757 | + * @access private |
|
1758 | + * @return void |
|
1759 | + */ |
|
1760 | + private function _setup_redirect() |
|
1761 | + { |
|
1762 | + if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
1763 | + $this->checkout->redirect = true; |
|
1764 | + if (empty($this->checkout->redirect_url)) { |
|
1765 | + $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
|
1766 | + } |
|
1767 | + $this->checkout->redirect_url = apply_filters( |
|
1768 | + 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', |
|
1769 | + $this->checkout->redirect_url, |
|
1770 | + $this->checkout |
|
1771 | + ); |
|
1772 | + } |
|
1773 | + } |
|
1774 | + |
|
1775 | + |
|
1776 | + |
|
1777 | + /** |
|
1778 | + * handle ajax message responses and redirects |
|
1779 | + * |
|
1780 | + * @access public |
|
1781 | + * @return void |
|
1782 | + * @throws EE_Error |
|
1783 | + */ |
|
1784 | + public function go_to_next_step() |
|
1785 | + { |
|
1786 | + if (EE_Registry::instance()->REQ->ajax) { |
|
1787 | + // capture contents of output buffer we started earlier in the request, and insert into JSON response |
|
1788 | + $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); |
|
1789 | + } |
|
1790 | + $this->unlock_transaction(); |
|
1791 | + // just return for these conditions |
|
1792 | + if ( |
|
1793 | + $this->checkout->admin_request |
|
1794 | + || $this->checkout->action === 'redirect_form' |
|
1795 | + || $this->checkout->action === 'update_checkout' |
|
1796 | + ) { |
|
1797 | + return; |
|
1798 | + } |
|
1799 | + // AJAX response |
|
1800 | + $this->_handle_json_response(); |
|
1801 | + // redirect to next step or the Thank You page |
|
1802 | + $this->_handle_html_redirects(); |
|
1803 | + // hmmm... must be something wrong, so let's just display the form again ! |
|
1804 | + $this->_display_spco_reg_form(); |
|
1805 | + } |
|
1806 | + |
|
1807 | + |
|
1808 | + |
|
1809 | + /** |
|
1810 | + * _handle_json_response |
|
1811 | + * |
|
1812 | + * @access protected |
|
1813 | + * @return void |
|
1814 | + */ |
|
1815 | + protected function _handle_json_response() |
|
1816 | + { |
|
1817 | + // if this is an ajax request |
|
1818 | + if (EE_Registry::instance()->REQ->ajax) { |
|
1819 | + // DEBUG LOG |
|
1820 | + //$this->checkout->log( |
|
1821 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
1822 | + // array( |
|
1823 | + // 'json_response_redirect_url' => $this->checkout->json_response->redirect_url(), |
|
1824 | + // 'redirect' => $this->checkout->redirect, |
|
1825 | + // 'continue_reg' => $this->checkout->continue_reg, |
|
1826 | + // ) |
|
1827 | + //); |
|
1828 | + $this->checkout->json_response->set_registration_time_limit( |
|
1829 | + $this->checkout->get_registration_time_limit() |
|
1830 | + ); |
|
1831 | + $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); |
|
1832 | + // just send the ajax ( |
|
1833 | + $json_response = apply_filters( |
|
1834 | + 'FHEE__EE_Single_Page_Checkout__JSON_response', |
|
1835 | + $this->checkout->json_response |
|
1836 | + ); |
|
1837 | + echo $json_response; |
|
1838 | + exit(); |
|
1839 | + } |
|
1840 | + } |
|
1841 | + |
|
1842 | + |
|
1843 | + |
|
1844 | + /** |
|
1845 | + * _handle_redirects |
|
1846 | + * |
|
1847 | + * @access protected |
|
1848 | + * @return void |
|
1849 | + */ |
|
1850 | + protected function _handle_html_redirects() |
|
1851 | + { |
|
1852 | + // going somewhere ? |
|
1853 | + if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { |
|
1854 | + // store notices in a transient |
|
1855 | + EE_Error::get_notices(false, true, true); |
|
1856 | + // DEBUG LOG |
|
1857 | + //$this->checkout->log( |
|
1858 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
1859 | + // array( |
|
1860 | + // 'headers_sent' => headers_sent(), |
|
1861 | + // 'redirect_url' => $this->checkout->redirect_url, |
|
1862 | + // 'headers_list' => headers_list(), |
|
1863 | + // ) |
|
1864 | + //); |
|
1865 | + wp_safe_redirect($this->checkout->redirect_url); |
|
1866 | + exit(); |
|
1867 | + } |
|
1868 | + } |
|
1869 | + |
|
1870 | + |
|
1871 | + |
|
1872 | + /** |
|
1873 | + * set_checkout_anchor |
|
1874 | + * |
|
1875 | + * @access public |
|
1876 | + * @return void |
|
1877 | + */ |
|
1878 | + public function set_checkout_anchor() |
|
1879 | + { |
|
1880 | + echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>'; |
|
1881 | + } |
|
1882 | 1882 | |
1883 | 1883 | |
1884 | 1884 |
@@ -68,7 +68,7 @@ |
||
68 | 68 | </div> |
69 | 69 | <p><?php esc_html_e('Don\'t want to keep your old Event Espresso data? Alternatively, you can delete it all and start fresh.', |
70 | 70 | 'event_espresso'); ?> <a |
71 | - href="<?php echo $data_reset_page;?>"><?php esc_html_e('Visit the Maintenance Page and Reset Your Event Espresso Data', |
|
71 | + href="<?php echo $data_reset_page; ?>"><?php esc_html_e('Visit the Maintenance Page and Reset Your Event Espresso Data', |
|
72 | 72 | 'event_espresso'); ?></a></p> |
73 | 73 | <?php do_action('AHEE__ee_migration_page__after_migration_options_table'); ?> |
74 | 74 | </div> |
75 | 75 | \ No newline at end of file |
@@ -25,14 +25,14 @@ discard block |
||
25 | 25 | <tr> |
26 | 26 | <td> |
27 | 27 | <?php |
28 | - echo apply_filters( |
|
29 | - 'FHEE__ee_migration_page__option_1_main', |
|
30 | - esc_html__('Before updating your database, you should first create a database backup', |
|
31 | - "event_espresso"), |
|
32 | - $current_db_state, |
|
33 | - $next_db_state |
|
34 | - ); |
|
35 | - ?> |
|
28 | + echo apply_filters( |
|
29 | + 'FHEE__ee_migration_page__option_1_main', |
|
30 | + esc_html__('Before updating your database, you should first create a database backup', |
|
31 | + "event_espresso"), |
|
32 | + $current_db_state, |
|
33 | + $next_db_state |
|
34 | + ); |
|
35 | + ?> |
|
36 | 36 | <a id="display-migration-details" |
37 | 37 | class="display-the-hidden lt-grey-text smaller-text hide-if-no-js" |
38 | 38 | rel="migration-details"><?php esc_html_e('How Do I Make a Database Backup?', "event_espresso"); ?> |
@@ -41,8 +41,8 @@ discard block |
||
41 | 41 | <td> |
42 | 42 | <a id="db-backed-up" |
43 | 43 | class="toggle-migration-monitor button-primary"><?php echo apply_filters('FHEE__ee_migration_page__option_1_button_text', |
44 | - sprintf(esc_html__("My Database Is Backed Up, Continue", "event_espresso"), $current_db_state, |
|
45 | - $next_db_state), $current_db_state, $next_db_state); ?></a> |
|
44 | + sprintf(esc_html__("My Database Is Backed Up, Continue", "event_espresso"), $current_db_state, |
|
45 | + $next_db_state), $current_db_state, $next_db_state); ?></a> |
|
46 | 46 | </td> |
47 | 47 | </tr> |
48 | 48 | <tr> |
@@ -50,14 +50,14 @@ discard block |
||
50 | 50 | <div id="migration-details-dv" style="display: none; padding: 1em;"> |
51 | 51 | <p> |
52 | 52 | <?php |
53 | - printf( |
|
54 | - esc_html__('%1$sClick Here to Learn How To Backup your Database Yourself%2$s. Or have one of our dedicated support technicians help you by %3$spurchasing a Priority Support Token.%2$s', |
|
55 | - "event_espresso"), |
|
56 | - '<a target="_blank" href="http://eventespresso.com/wiki/how-to-back-up-your-site/">', |
|
57 | - "</a>", |
|
58 | - "<a target=\"_blank\" href='http://eventespresso.com/product/priority-support-tokens/'>" |
|
59 | - ); |
|
60 | - ?> |
|
53 | + printf( |
|
54 | + esc_html__('%1$sClick Here to Learn How To Backup your Database Yourself%2$s. Or have one of our dedicated support technicians help you by %3$spurchasing a Priority Support Token.%2$s', |
|
55 | + "event_espresso"), |
|
56 | + '<a target="_blank" href="http://eventespresso.com/wiki/how-to-back-up-your-site/">', |
|
57 | + "</a>", |
|
58 | + "<a target=\"_blank\" href='http://eventespresso.com/product/priority-support-tokens/'>" |
|
59 | + ); |
|
60 | + ?> |
|
61 | 61 | </p> |
62 | 62 | <?php do_action('AHEE__ee_migration_page__option_1_extra_details'); ?> |
63 | 63 | </div> |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | </table> |
68 | 68 | </div> |
69 | 69 | <p><?php esc_html_e('Don\'t want to keep your old Event Espresso data? Alternatively, you can delete it all and start fresh.', |
70 | - 'event_espresso'); ?> <a |
|
70 | + 'event_espresso'); ?> <a |
|
71 | 71 | href="<?php echo $data_reset_page;?>"><?php esc_html_e('Visit the Maintenance Page and Reset Your Event Espresso Data', |
72 | - 'event_espresso'); ?></a></p> |
|
72 | + 'event_espresso'); ?></a></p> |
|
73 | 73 | <?php do_action('AHEE__ee_migration_page__after_migration_options_table'); ?> |
74 | 74 | </div> |
75 | 75 | \ No newline at end of file |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | * @access public |
261 | 261 | * @param EE_Ticket $ticket |
262 | 262 | * @param int $qty |
263 | - * @return TRUE on success, FALSE on fail |
|
263 | + * @return boolean on success, FALSE on fail |
|
264 | 264 | * @throws \EE_Error |
265 | 265 | */ |
266 | 266 | public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1) |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | * @save cart to session |
386 | 386 | * @access public |
387 | 387 | * @param bool $apply_taxes |
388 | - * @return TRUE on success, FALSE on fail |
|
388 | + * @return boolean on success, FALSE on fail |
|
389 | 389 | * @throws \EE_Error |
390 | 390 | */ |
391 | 391 | public function save_cart($apply_taxes = true) |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | |
420 | 420 | |
421 | 421 | /** |
422 | - * @return array |
|
422 | + * @return string[] |
|
423 | 423 | */ |
424 | 424 | public function __sleep() |
425 | 425 | { |
@@ -203,7 +203,7 @@ |
||
203 | 203 | */ |
204 | 204 | public function get_tickets() |
205 | 205 | { |
206 | - if ($this->_grand_total === null ) { |
|
206 | + if ($this->_grand_total === null) { |
|
207 | 207 | return array(); |
208 | 208 | } |
209 | 209 | return EEH_Line_Item::get_ticket_line_items($this->_grand_total); |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use EventEspresso\core\interfaces\ResettableInterface; |
3 | 3 | |
4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
8 | 8 | |
@@ -23,421 +23,421 @@ discard block |
||
23 | 23 | class EE_Cart implements ResettableInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * instance of the EE_Cart object |
|
28 | - * |
|
29 | - * @access private |
|
30 | - * @var EE_Cart $_instance |
|
31 | - */ |
|
32 | - private static $_instance; |
|
33 | - |
|
34 | - /** |
|
35 | - * instance of the EE_Session object |
|
36 | - * |
|
37 | - * @access protected |
|
38 | - * @var EE_Session $_session |
|
39 | - */ |
|
40 | - protected $_session; |
|
41 | - |
|
42 | - /** |
|
43 | - * The total Line item which comprises all the children line-item subtotals, |
|
44 | - * which in turn each have their line items. |
|
45 | - * Typically, the line item structure will look like: |
|
46 | - * grand total |
|
47 | - * -tickets-sub-total |
|
48 | - * --ticket1 |
|
49 | - * --ticket2 |
|
50 | - * --... |
|
51 | - * -taxes-sub-total |
|
52 | - * --tax1 |
|
53 | - * --tax2 |
|
54 | - * |
|
55 | - * @var EE_Line_Item |
|
56 | - */ |
|
57 | - private $_grand_total; |
|
58 | - |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * @singleton method used to instantiate class object |
|
63 | - * @access public |
|
64 | - * @param EE_Line_Item $grand_total |
|
65 | - * @param EE_Session $session |
|
66 | - * @return \EE_Cart |
|
67 | - * @throws \EE_Error |
|
68 | - */ |
|
69 | - public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
70 | - { |
|
71 | - if ( ! empty($grand_total)) { |
|
72 | - self::$_instance = new self($grand_total, $session); |
|
73 | - } |
|
74 | - // or maybe retrieve an existing one ? |
|
75 | - if ( ! self::$_instance instanceof EE_Cart) { |
|
76 | - // try getting the cart out of the session |
|
77 | - $saved_cart = $session instanceof EE_Session ? $session->cart() : null; |
|
78 | - self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session); |
|
79 | - unset($saved_cart); |
|
80 | - } |
|
81 | - // verify that cart is ok and grand total line item exists |
|
82 | - if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) { |
|
83 | - self::$_instance = new self($grand_total, $session); |
|
84 | - } |
|
85 | - self::$_instance->get_grand_total(); |
|
86 | - // once everything is all said and done, save the cart to the EE_Session |
|
87 | - add_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
88 | - return self::$_instance; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * private constructor to prevent direct creation |
|
95 | - * |
|
96 | - * @Constructor |
|
97 | - * @access private |
|
98 | - * @param EE_Line_Item $grand_total |
|
99 | - * @param EE_Session $session |
|
100 | - */ |
|
101 | - private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
102 | - { |
|
103 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
104 | - $this->set_session($session); |
|
105 | - if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) { |
|
106 | - $this->set_grand_total_line_item($grand_total); |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * Resets the cart completely (whereas empty_cart |
|
114 | - * |
|
115 | - * @param EE_Line_Item $grand_total |
|
116 | - * @param EE_Session $session |
|
117 | - * @return EE_Cart |
|
118 | - * @throws \EE_Error |
|
119 | - */ |
|
120 | - public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
121 | - { |
|
122 | - remove_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
123 | - if ($session instanceof EE_Session) { |
|
124 | - $session->reset_cart(); |
|
125 | - } |
|
126 | - self::$_instance = null; |
|
127 | - return self::instance($grand_total, $session); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @return \EE_Session |
|
134 | - */ |
|
135 | - public function session() |
|
136 | - { |
|
137 | - if ( ! $this->_session instanceof EE_Session) { |
|
138 | - $this->set_session(); |
|
139 | - } |
|
140 | - return $this->_session; |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @param EE_Session $session |
|
147 | - */ |
|
148 | - public function set_session(EE_Session $session = null) |
|
149 | - { |
|
150 | - $this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session'); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * Sets the cart to match the line item. Especially handy for loading an old cart where you |
|
157 | - * know the grand total line item on it |
|
158 | - * |
|
159 | - * @param EE_Line_Item $line_item |
|
160 | - */ |
|
161 | - public function set_grand_total_line_item(EE_Line_Item $line_item) |
|
162 | - { |
|
163 | - $this->_grand_total = $line_item; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * get_cart_from_reg_url_link |
|
170 | - * |
|
171 | - * @access public |
|
172 | - * @param EE_Transaction $transaction |
|
173 | - * @param EE_Session $session |
|
174 | - * @return \EE_Cart |
|
175 | - * @throws \EE_Error |
|
176 | - */ |
|
177 | - public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null) |
|
178 | - { |
|
179 | - $grand_total = $transaction->total_line_item(); |
|
180 | - $grand_total->get_items(); |
|
181 | - $grand_total->tax_descendants(); |
|
182 | - return EE_Cart::instance($grand_total, $session); |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items |
|
189 | - * |
|
190 | - * @return EE_Line_Item |
|
191 | - * @throws \EE_Error |
|
192 | - */ |
|
193 | - private function _create_grand_total() |
|
194 | - { |
|
195 | - $this->_grand_total = EEH_Line_Item::create_total_line_item(); |
|
196 | - return $this->_grand_total; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * Gets all the line items of object type Ticket |
|
203 | - * |
|
204 | - * @access public |
|
205 | - * @return \EE_Line_Item[] |
|
206 | - */ |
|
207 | - public function get_tickets() |
|
208 | - { |
|
209 | - if ($this->_grand_total === null ) { |
|
210 | - return array(); |
|
211 | - } |
|
212 | - return EEH_Line_Item::get_ticket_line_items($this->_grand_total); |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * returns the total quantity of tickets in the cart |
|
219 | - * |
|
220 | - * @access public |
|
221 | - * @return int |
|
222 | - * @throws \EE_Error |
|
223 | - */ |
|
224 | - public function all_ticket_quantity_count() |
|
225 | - { |
|
226 | - $tickets = $this->get_tickets(); |
|
227 | - if (empty($tickets)) { |
|
228 | - return 0; |
|
229 | - } |
|
230 | - $count = 0; |
|
231 | - foreach ($tickets as $ticket) { |
|
232 | - $count += $ticket->get('LIN_quantity'); |
|
233 | - } |
|
234 | - return $count; |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * Gets all the tax line items |
|
241 | - * |
|
242 | - * @return \EE_Line_Item[] |
|
243 | - * @throws \EE_Error |
|
244 | - */ |
|
245 | - public function get_taxes() |
|
246 | - { |
|
247 | - return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children(); |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * Gets the total line item (which is a parent of all other line items) on this cart |
|
254 | - * |
|
255 | - * @return EE_Line_Item |
|
256 | - * @throws \EE_Error |
|
257 | - */ |
|
258 | - public function get_grand_total() |
|
259 | - { |
|
260 | - return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total(); |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @process items for adding to cart |
|
267 | - * @access public |
|
268 | - * @param EE_Ticket $ticket |
|
269 | - * @param int $qty |
|
270 | - * @return TRUE on success, FALSE on fail |
|
271 | - * @throws \EE_Error |
|
272 | - */ |
|
273 | - public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1) |
|
274 | - { |
|
275 | - EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty); |
|
276 | - return $this->save_cart() ? true : false; |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * get_cart_total_before_tax |
|
283 | - * |
|
284 | - * @access public |
|
285 | - * @return float |
|
286 | - * @throws \EE_Error |
|
287 | - */ |
|
288 | - public function get_cart_total_before_tax() |
|
289 | - { |
|
290 | - return $this->get_grand_total()->recalculate_pre_tax_total(); |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * gets the total amount of tax paid for items in this cart |
|
297 | - * |
|
298 | - * @access public |
|
299 | - * @return float |
|
300 | - * @throws \EE_Error |
|
301 | - */ |
|
302 | - public function get_applied_taxes() |
|
303 | - { |
|
304 | - return EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - |
|
309 | - /** |
|
310 | - * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
311 | - * |
|
312 | - * @access public |
|
313 | - * @return float |
|
314 | - * @throws \EE_Error |
|
315 | - */ |
|
316 | - public function get_cart_grand_total() |
|
317 | - { |
|
318 | - EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
319 | - return $this->get_grand_total()->total(); |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
326 | - * |
|
327 | - * @access public |
|
328 | - * @return float |
|
329 | - * @throws \EE_Error |
|
330 | - */ |
|
331 | - public function recalculate_all_cart_totals() |
|
332 | - { |
|
333 | - $pre_tax_total = $this->get_cart_total_before_tax(); |
|
334 | - $taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
335 | - $this->_grand_total->set_total($pre_tax_total + $taxes_total); |
|
336 | - $this->_grand_total->save_this_and_descendants_to_txn(); |
|
337 | - return $this->get_grand_total()->total(); |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * deletes an item from the cart |
|
344 | - * |
|
345 | - * @access public |
|
346 | - * @param array|bool|string $line_item_codes |
|
347 | - * @return int on success, FALSE on fail |
|
348 | - * @throws \EE_Error |
|
349 | - */ |
|
350 | - public function delete_items($line_item_codes = false) |
|
351 | - { |
|
352 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
353 | - return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes); |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - |
|
358 | - /** |
|
359 | - * @remove ALL items from cart and zero ALL totals |
|
360 | - * @access public |
|
361 | - * @return bool |
|
362 | - * @throws \EE_Error |
|
363 | - */ |
|
364 | - public function empty_cart() |
|
365 | - { |
|
366 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
367 | - $this->_grand_total = $this->_create_grand_total(); |
|
368 | - return $this->save_cart(true); |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * @remove ALL items from cart and delete total as well |
|
375 | - * @access public |
|
376 | - * @return bool |
|
377 | - * @throws \EE_Error |
|
378 | - */ |
|
379 | - public function delete_cart() |
|
380 | - { |
|
381 | - if ($this->_grand_total instanceof EE_Line_Item) { |
|
382 | - $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total); |
|
383 | - if ($deleted) { |
|
384 | - $deleted += $this->_grand_total->delete(); |
|
385 | - $this->_grand_total = null; |
|
386 | - return true; |
|
387 | - } |
|
388 | - } |
|
389 | - return false; |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * @save cart to session |
|
396 | - * @access public |
|
397 | - * @param bool $apply_taxes |
|
398 | - * @return TRUE on success, FALSE on fail |
|
399 | - * @throws \EE_Error |
|
400 | - */ |
|
401 | - public function save_cart($apply_taxes = true) |
|
402 | - { |
|
403 | - if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) { |
|
404 | - EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
405 | - //make sure we don't cache the transaction because it can get stale |
|
406 | - if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction |
|
407 | - && $this->_grand_total->get_one_from_cache('Transaction')->ID() |
|
408 | - ) { |
|
409 | - $this->_grand_total->clear_cache('Transaction', null, true); |
|
410 | - } |
|
411 | - } |
|
412 | - if ($this->session() instanceof EE_Session) { |
|
413 | - return $this->session()->set_cart($this); |
|
414 | - } else { |
|
415 | - return false; |
|
416 | - } |
|
417 | - } |
|
418 | - |
|
419 | - |
|
420 | - |
|
421 | - public function __wakeup() |
|
422 | - { |
|
423 | - if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) { |
|
424 | - // $this->_grand_total is actually just an ID, so use it to get the object from the db |
|
425 | - $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total); |
|
426 | - } |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * @return array |
|
433 | - */ |
|
434 | - public function __sleep() |
|
435 | - { |
|
436 | - if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) { |
|
437 | - $this->_grand_total = $this->_grand_total->ID(); |
|
438 | - } |
|
439 | - return array('_grand_total'); |
|
440 | - } |
|
26 | + /** |
|
27 | + * instance of the EE_Cart object |
|
28 | + * |
|
29 | + * @access private |
|
30 | + * @var EE_Cart $_instance |
|
31 | + */ |
|
32 | + private static $_instance; |
|
33 | + |
|
34 | + /** |
|
35 | + * instance of the EE_Session object |
|
36 | + * |
|
37 | + * @access protected |
|
38 | + * @var EE_Session $_session |
|
39 | + */ |
|
40 | + protected $_session; |
|
41 | + |
|
42 | + /** |
|
43 | + * The total Line item which comprises all the children line-item subtotals, |
|
44 | + * which in turn each have their line items. |
|
45 | + * Typically, the line item structure will look like: |
|
46 | + * grand total |
|
47 | + * -tickets-sub-total |
|
48 | + * --ticket1 |
|
49 | + * --ticket2 |
|
50 | + * --... |
|
51 | + * -taxes-sub-total |
|
52 | + * --tax1 |
|
53 | + * --tax2 |
|
54 | + * |
|
55 | + * @var EE_Line_Item |
|
56 | + */ |
|
57 | + private $_grand_total; |
|
58 | + |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * @singleton method used to instantiate class object |
|
63 | + * @access public |
|
64 | + * @param EE_Line_Item $grand_total |
|
65 | + * @param EE_Session $session |
|
66 | + * @return \EE_Cart |
|
67 | + * @throws \EE_Error |
|
68 | + */ |
|
69 | + public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
70 | + { |
|
71 | + if ( ! empty($grand_total)) { |
|
72 | + self::$_instance = new self($grand_total, $session); |
|
73 | + } |
|
74 | + // or maybe retrieve an existing one ? |
|
75 | + if ( ! self::$_instance instanceof EE_Cart) { |
|
76 | + // try getting the cart out of the session |
|
77 | + $saved_cart = $session instanceof EE_Session ? $session->cart() : null; |
|
78 | + self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session); |
|
79 | + unset($saved_cart); |
|
80 | + } |
|
81 | + // verify that cart is ok and grand total line item exists |
|
82 | + if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) { |
|
83 | + self::$_instance = new self($grand_total, $session); |
|
84 | + } |
|
85 | + self::$_instance->get_grand_total(); |
|
86 | + // once everything is all said and done, save the cart to the EE_Session |
|
87 | + add_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
88 | + return self::$_instance; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * private constructor to prevent direct creation |
|
95 | + * |
|
96 | + * @Constructor |
|
97 | + * @access private |
|
98 | + * @param EE_Line_Item $grand_total |
|
99 | + * @param EE_Session $session |
|
100 | + */ |
|
101 | + private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
102 | + { |
|
103 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
104 | + $this->set_session($session); |
|
105 | + if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) { |
|
106 | + $this->set_grand_total_line_item($grand_total); |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * Resets the cart completely (whereas empty_cart |
|
114 | + * |
|
115 | + * @param EE_Line_Item $grand_total |
|
116 | + * @param EE_Session $session |
|
117 | + * @return EE_Cart |
|
118 | + * @throws \EE_Error |
|
119 | + */ |
|
120 | + public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
121 | + { |
|
122 | + remove_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
123 | + if ($session instanceof EE_Session) { |
|
124 | + $session->reset_cart(); |
|
125 | + } |
|
126 | + self::$_instance = null; |
|
127 | + return self::instance($grand_total, $session); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @return \EE_Session |
|
134 | + */ |
|
135 | + public function session() |
|
136 | + { |
|
137 | + if ( ! $this->_session instanceof EE_Session) { |
|
138 | + $this->set_session(); |
|
139 | + } |
|
140 | + return $this->_session; |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @param EE_Session $session |
|
147 | + */ |
|
148 | + public function set_session(EE_Session $session = null) |
|
149 | + { |
|
150 | + $this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session'); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * Sets the cart to match the line item. Especially handy for loading an old cart where you |
|
157 | + * know the grand total line item on it |
|
158 | + * |
|
159 | + * @param EE_Line_Item $line_item |
|
160 | + */ |
|
161 | + public function set_grand_total_line_item(EE_Line_Item $line_item) |
|
162 | + { |
|
163 | + $this->_grand_total = $line_item; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * get_cart_from_reg_url_link |
|
170 | + * |
|
171 | + * @access public |
|
172 | + * @param EE_Transaction $transaction |
|
173 | + * @param EE_Session $session |
|
174 | + * @return \EE_Cart |
|
175 | + * @throws \EE_Error |
|
176 | + */ |
|
177 | + public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null) |
|
178 | + { |
|
179 | + $grand_total = $transaction->total_line_item(); |
|
180 | + $grand_total->get_items(); |
|
181 | + $grand_total->tax_descendants(); |
|
182 | + return EE_Cart::instance($grand_total, $session); |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items |
|
189 | + * |
|
190 | + * @return EE_Line_Item |
|
191 | + * @throws \EE_Error |
|
192 | + */ |
|
193 | + private function _create_grand_total() |
|
194 | + { |
|
195 | + $this->_grand_total = EEH_Line_Item::create_total_line_item(); |
|
196 | + return $this->_grand_total; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * Gets all the line items of object type Ticket |
|
203 | + * |
|
204 | + * @access public |
|
205 | + * @return \EE_Line_Item[] |
|
206 | + */ |
|
207 | + public function get_tickets() |
|
208 | + { |
|
209 | + if ($this->_grand_total === null ) { |
|
210 | + return array(); |
|
211 | + } |
|
212 | + return EEH_Line_Item::get_ticket_line_items($this->_grand_total); |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * returns the total quantity of tickets in the cart |
|
219 | + * |
|
220 | + * @access public |
|
221 | + * @return int |
|
222 | + * @throws \EE_Error |
|
223 | + */ |
|
224 | + public function all_ticket_quantity_count() |
|
225 | + { |
|
226 | + $tickets = $this->get_tickets(); |
|
227 | + if (empty($tickets)) { |
|
228 | + return 0; |
|
229 | + } |
|
230 | + $count = 0; |
|
231 | + foreach ($tickets as $ticket) { |
|
232 | + $count += $ticket->get('LIN_quantity'); |
|
233 | + } |
|
234 | + return $count; |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * Gets all the tax line items |
|
241 | + * |
|
242 | + * @return \EE_Line_Item[] |
|
243 | + * @throws \EE_Error |
|
244 | + */ |
|
245 | + public function get_taxes() |
|
246 | + { |
|
247 | + return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children(); |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * Gets the total line item (which is a parent of all other line items) on this cart |
|
254 | + * |
|
255 | + * @return EE_Line_Item |
|
256 | + * @throws \EE_Error |
|
257 | + */ |
|
258 | + public function get_grand_total() |
|
259 | + { |
|
260 | + return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total(); |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @process items for adding to cart |
|
267 | + * @access public |
|
268 | + * @param EE_Ticket $ticket |
|
269 | + * @param int $qty |
|
270 | + * @return TRUE on success, FALSE on fail |
|
271 | + * @throws \EE_Error |
|
272 | + */ |
|
273 | + public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1) |
|
274 | + { |
|
275 | + EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty); |
|
276 | + return $this->save_cart() ? true : false; |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * get_cart_total_before_tax |
|
283 | + * |
|
284 | + * @access public |
|
285 | + * @return float |
|
286 | + * @throws \EE_Error |
|
287 | + */ |
|
288 | + public function get_cart_total_before_tax() |
|
289 | + { |
|
290 | + return $this->get_grand_total()->recalculate_pre_tax_total(); |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * gets the total amount of tax paid for items in this cart |
|
297 | + * |
|
298 | + * @access public |
|
299 | + * @return float |
|
300 | + * @throws \EE_Error |
|
301 | + */ |
|
302 | + public function get_applied_taxes() |
|
303 | + { |
|
304 | + return EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + |
|
309 | + /** |
|
310 | + * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
311 | + * |
|
312 | + * @access public |
|
313 | + * @return float |
|
314 | + * @throws \EE_Error |
|
315 | + */ |
|
316 | + public function get_cart_grand_total() |
|
317 | + { |
|
318 | + EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
319 | + return $this->get_grand_total()->total(); |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
326 | + * |
|
327 | + * @access public |
|
328 | + * @return float |
|
329 | + * @throws \EE_Error |
|
330 | + */ |
|
331 | + public function recalculate_all_cart_totals() |
|
332 | + { |
|
333 | + $pre_tax_total = $this->get_cart_total_before_tax(); |
|
334 | + $taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
335 | + $this->_grand_total->set_total($pre_tax_total + $taxes_total); |
|
336 | + $this->_grand_total->save_this_and_descendants_to_txn(); |
|
337 | + return $this->get_grand_total()->total(); |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * deletes an item from the cart |
|
344 | + * |
|
345 | + * @access public |
|
346 | + * @param array|bool|string $line_item_codes |
|
347 | + * @return int on success, FALSE on fail |
|
348 | + * @throws \EE_Error |
|
349 | + */ |
|
350 | + public function delete_items($line_item_codes = false) |
|
351 | + { |
|
352 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
353 | + return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes); |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + |
|
358 | + /** |
|
359 | + * @remove ALL items from cart and zero ALL totals |
|
360 | + * @access public |
|
361 | + * @return bool |
|
362 | + * @throws \EE_Error |
|
363 | + */ |
|
364 | + public function empty_cart() |
|
365 | + { |
|
366 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
367 | + $this->_grand_total = $this->_create_grand_total(); |
|
368 | + return $this->save_cart(true); |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * @remove ALL items from cart and delete total as well |
|
375 | + * @access public |
|
376 | + * @return bool |
|
377 | + * @throws \EE_Error |
|
378 | + */ |
|
379 | + public function delete_cart() |
|
380 | + { |
|
381 | + if ($this->_grand_total instanceof EE_Line_Item) { |
|
382 | + $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total); |
|
383 | + if ($deleted) { |
|
384 | + $deleted += $this->_grand_total->delete(); |
|
385 | + $this->_grand_total = null; |
|
386 | + return true; |
|
387 | + } |
|
388 | + } |
|
389 | + return false; |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * @save cart to session |
|
396 | + * @access public |
|
397 | + * @param bool $apply_taxes |
|
398 | + * @return TRUE on success, FALSE on fail |
|
399 | + * @throws \EE_Error |
|
400 | + */ |
|
401 | + public function save_cart($apply_taxes = true) |
|
402 | + { |
|
403 | + if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) { |
|
404 | + EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
405 | + //make sure we don't cache the transaction because it can get stale |
|
406 | + if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction |
|
407 | + && $this->_grand_total->get_one_from_cache('Transaction')->ID() |
|
408 | + ) { |
|
409 | + $this->_grand_total->clear_cache('Transaction', null, true); |
|
410 | + } |
|
411 | + } |
|
412 | + if ($this->session() instanceof EE_Session) { |
|
413 | + return $this->session()->set_cart($this); |
|
414 | + } else { |
|
415 | + return false; |
|
416 | + } |
|
417 | + } |
|
418 | + |
|
419 | + |
|
420 | + |
|
421 | + public function __wakeup() |
|
422 | + { |
|
423 | + if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) { |
|
424 | + // $this->_grand_total is actually just an ID, so use it to get the object from the db |
|
425 | + $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total); |
|
426 | + } |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * @return array |
|
433 | + */ |
|
434 | + public function __sleep() |
|
435 | + { |
|
436 | + if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) { |
|
437 | + $this->_grand_total = $this->_grand_total->ID(); |
|
438 | + } |
|
439 | + return array('_grand_total'); |
|
440 | + } |
|
441 | 441 | |
442 | 442 | |
443 | 443 | } |
@@ -613,7 +613,7 @@ discard block |
||
613 | 613 | * |
614 | 614 | * @since 4.6.0 |
615 | 615 | * @global WPDB $wpdb |
616 | - * @return mixed null|int WP_user ID or NULL |
|
616 | + * @return integer|null null|int WP_user ID or NULL |
|
617 | 617 | */ |
618 | 618 | public static function get_default_creator_id() |
619 | 619 | { |
@@ -774,7 +774,7 @@ discard block |
||
774 | 774 | * @static |
775 | 775 | * @deprecated instead use TableManager::dropTable() |
776 | 776 | * @param string $table_name |
777 | - * @return bool | int |
|
777 | + * @return integer | int |
|
778 | 778 | */ |
779 | 779 | public static function delete_unused_db_table($table_name) |
780 | 780 | { |
@@ -791,7 +791,7 @@ discard block |
||
791 | 791 | * @deprecated instead use TableManager::dropIndex() |
792 | 792 | * @param string $table_name |
793 | 793 | * @param string $index_name |
794 | - * @return bool | int |
|
794 | + * @return integer | int |
|
795 | 795 | */ |
796 | 796 | public static function drop_index($table_name, $index_name) |
797 | 797 | { |
@@ -18,243 +18,243 @@ discard block |
||
18 | 18 | class EEH_Activation implements ResettableInterface |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * constant used to indicate a cron task is no longer in use |
|
23 | - */ |
|
24 | - const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
25 | - |
|
26 | - /** |
|
27 | - * option name that will indicate whether or not we still |
|
28 | - * need to create EE's folders in the uploads directory |
|
29 | - * (because if EE was installed without file system access, |
|
30 | - * we need to request credentials before we can create them) |
|
31 | - */ |
|
32 | - const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete'; |
|
33 | - |
|
34 | - /** |
|
35 | - * WP_User->ID |
|
36 | - * |
|
37 | - * @var int |
|
38 | - */ |
|
39 | - private static $_default_creator_id; |
|
40 | - |
|
41 | - /** |
|
42 | - * indicates whether or not we've already verified core's default data during this request, |
|
43 | - * because after migrations are done, any addons activated while in maintenance mode |
|
44 | - * will want to setup their own default data, and they might hook into core's default data |
|
45 | - * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
46 | - * This prevents doing that for EVERY single addon. |
|
47 | - * |
|
48 | - * @var boolean |
|
49 | - */ |
|
50 | - protected static $_initialized_db_content_already_in_this_request = false; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
54 | - */ |
|
55 | - private static $table_analysis; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
59 | - */ |
|
60 | - private static $table_manager; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * @return \EventEspresso\core\services\database\TableAnalysis |
|
65 | - */ |
|
66 | - public static function getTableAnalysis() |
|
67 | - { |
|
68 | - if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
69 | - self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
70 | - } |
|
71 | - return self::$table_analysis; |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * @return \EventEspresso\core\services\database\TableManager |
|
77 | - */ |
|
78 | - public static function getTableManager() |
|
79 | - { |
|
80 | - if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
81 | - self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
82 | - } |
|
83 | - return self::$table_manager; |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * _ensure_table_name_has_prefix |
|
89 | - * |
|
90 | - * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
91 | - * @access public |
|
92 | - * @static |
|
93 | - * @param $table_name |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - public static function ensure_table_name_has_prefix($table_name) |
|
97 | - { |
|
98 | - return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * system_initialization |
|
104 | - * ensures the EE configuration settings are loaded with at least default options set |
|
105 | - * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
106 | - * |
|
107 | - * @access public |
|
108 | - * @static |
|
109 | - * @return void |
|
110 | - */ |
|
111 | - public static function system_initialization() |
|
112 | - { |
|
113 | - EEH_Activation::reset_and_update_config(); |
|
114 | - //which is fired BEFORE activation of plugin anyways |
|
115 | - EEH_Activation::verify_default_pages_exist(); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * Sets the database schema and creates folders. This should |
|
121 | - * be called on plugin activation and reactivation |
|
122 | - * |
|
123 | - * @return boolean success, whether the database and folders are setup properly |
|
124 | - * @throws \EE_Error |
|
125 | - */ |
|
126 | - public static function initialize_db_and_folders() |
|
127 | - { |
|
128 | - $good_filesystem = EEH_Activation::create_upload_directories(); |
|
129 | - $good_db = EEH_Activation::create_database_tables(); |
|
130 | - return $good_filesystem && $good_db; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * assuming we have an up-to-date database schema, this will populate it |
|
136 | - * with default and initial data. This should be called |
|
137 | - * upon activation of a new plugin, reactivation, and at the end |
|
138 | - * of running migration scripts |
|
139 | - * |
|
140 | - * @throws \EE_Error |
|
141 | - */ |
|
142 | - public static function initialize_db_content() |
|
143 | - { |
|
144 | - //let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
145 | - if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
146 | - return; |
|
147 | - } |
|
148 | - EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
149 | - |
|
150 | - EEH_Activation::initialize_system_questions(); |
|
151 | - EEH_Activation::insert_default_status_codes(); |
|
152 | - EEH_Activation::generate_default_message_templates(); |
|
153 | - EEH_Activation::create_no_ticket_prices_array(); |
|
154 | - |
|
155 | - EEH_Activation::validate_messages_system(); |
|
156 | - EEH_Activation::insert_default_payment_methods(); |
|
157 | - //in case we've |
|
158 | - EEH_Activation::remove_cron_tasks(); |
|
159 | - EEH_Activation::create_cron_tasks(); |
|
160 | - // remove all TXN locks since that is being done via extra meta now |
|
161 | - delete_option('ee_locked_transactions'); |
|
162 | - //also, check for CAF default db content |
|
163 | - do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
164 | - //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
165 | - //which users really won't care about on initial activation |
|
166 | - EE_Error::overwrite_success(); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
172 | - * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
173 | - * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
174 | - * (null) |
|
175 | - * |
|
176 | - * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
177 | - * 'old' (only returns ones that should no longer be used),or 'all', |
|
178 | - * @return array |
|
179 | - * @throws \EE_Error |
|
180 | - */ |
|
181 | - public static function get_cron_tasks($which_to_include) |
|
182 | - { |
|
183 | - $cron_tasks = apply_filters( |
|
184 | - 'FHEE__EEH_Activation__get_cron_tasks', |
|
185 | - array( |
|
186 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
21 | + /** |
|
22 | + * constant used to indicate a cron task is no longer in use |
|
23 | + */ |
|
24 | + const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
25 | + |
|
26 | + /** |
|
27 | + * option name that will indicate whether or not we still |
|
28 | + * need to create EE's folders in the uploads directory |
|
29 | + * (because if EE was installed without file system access, |
|
30 | + * we need to request credentials before we can create them) |
|
31 | + */ |
|
32 | + const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete'; |
|
33 | + |
|
34 | + /** |
|
35 | + * WP_User->ID |
|
36 | + * |
|
37 | + * @var int |
|
38 | + */ |
|
39 | + private static $_default_creator_id; |
|
40 | + |
|
41 | + /** |
|
42 | + * indicates whether or not we've already verified core's default data during this request, |
|
43 | + * because after migrations are done, any addons activated while in maintenance mode |
|
44 | + * will want to setup their own default data, and they might hook into core's default data |
|
45 | + * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
46 | + * This prevents doing that for EVERY single addon. |
|
47 | + * |
|
48 | + * @var boolean |
|
49 | + */ |
|
50 | + protected static $_initialized_db_content_already_in_this_request = false; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
54 | + */ |
|
55 | + private static $table_analysis; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
59 | + */ |
|
60 | + private static $table_manager; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * @return \EventEspresso\core\services\database\TableAnalysis |
|
65 | + */ |
|
66 | + public static function getTableAnalysis() |
|
67 | + { |
|
68 | + if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
69 | + self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
70 | + } |
|
71 | + return self::$table_analysis; |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * @return \EventEspresso\core\services\database\TableManager |
|
77 | + */ |
|
78 | + public static function getTableManager() |
|
79 | + { |
|
80 | + if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
81 | + self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
82 | + } |
|
83 | + return self::$table_manager; |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * _ensure_table_name_has_prefix |
|
89 | + * |
|
90 | + * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
91 | + * @access public |
|
92 | + * @static |
|
93 | + * @param $table_name |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + public static function ensure_table_name_has_prefix($table_name) |
|
97 | + { |
|
98 | + return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * system_initialization |
|
104 | + * ensures the EE configuration settings are loaded with at least default options set |
|
105 | + * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
106 | + * |
|
107 | + * @access public |
|
108 | + * @static |
|
109 | + * @return void |
|
110 | + */ |
|
111 | + public static function system_initialization() |
|
112 | + { |
|
113 | + EEH_Activation::reset_and_update_config(); |
|
114 | + //which is fired BEFORE activation of plugin anyways |
|
115 | + EEH_Activation::verify_default_pages_exist(); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * Sets the database schema and creates folders. This should |
|
121 | + * be called on plugin activation and reactivation |
|
122 | + * |
|
123 | + * @return boolean success, whether the database and folders are setup properly |
|
124 | + * @throws \EE_Error |
|
125 | + */ |
|
126 | + public static function initialize_db_and_folders() |
|
127 | + { |
|
128 | + $good_filesystem = EEH_Activation::create_upload_directories(); |
|
129 | + $good_db = EEH_Activation::create_database_tables(); |
|
130 | + return $good_filesystem && $good_db; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * assuming we have an up-to-date database schema, this will populate it |
|
136 | + * with default and initial data. This should be called |
|
137 | + * upon activation of a new plugin, reactivation, and at the end |
|
138 | + * of running migration scripts |
|
139 | + * |
|
140 | + * @throws \EE_Error |
|
141 | + */ |
|
142 | + public static function initialize_db_content() |
|
143 | + { |
|
144 | + //let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
145 | + if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
146 | + return; |
|
147 | + } |
|
148 | + EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
149 | + |
|
150 | + EEH_Activation::initialize_system_questions(); |
|
151 | + EEH_Activation::insert_default_status_codes(); |
|
152 | + EEH_Activation::generate_default_message_templates(); |
|
153 | + EEH_Activation::create_no_ticket_prices_array(); |
|
154 | + |
|
155 | + EEH_Activation::validate_messages_system(); |
|
156 | + EEH_Activation::insert_default_payment_methods(); |
|
157 | + //in case we've |
|
158 | + EEH_Activation::remove_cron_tasks(); |
|
159 | + EEH_Activation::create_cron_tasks(); |
|
160 | + // remove all TXN locks since that is being done via extra meta now |
|
161 | + delete_option('ee_locked_transactions'); |
|
162 | + //also, check for CAF default db content |
|
163 | + do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
164 | + //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
165 | + //which users really won't care about on initial activation |
|
166 | + EE_Error::overwrite_success(); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
172 | + * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
173 | + * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
174 | + * (null) |
|
175 | + * |
|
176 | + * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
177 | + * 'old' (only returns ones that should no longer be used),or 'all', |
|
178 | + * @return array |
|
179 | + * @throws \EE_Error |
|
180 | + */ |
|
181 | + public static function get_cron_tasks($which_to_include) |
|
182 | + { |
|
183 | + $cron_tasks = apply_filters( |
|
184 | + 'FHEE__EEH_Activation__get_cron_tasks', |
|
185 | + array( |
|
186 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
187 | 187 | // 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use |
188 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
189 | - //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
190 | - 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
191 | - ) |
|
192 | - ); |
|
193 | - if ($which_to_include === 'old') { |
|
194 | - $cron_tasks = array_filter( |
|
195 | - $cron_tasks, |
|
196 | - function ($value) { |
|
197 | - return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
198 | - } |
|
199 | - ); |
|
200 | - } elseif ($which_to_include === 'current') { |
|
201 | - $cron_tasks = array_filter($cron_tasks); |
|
202 | - } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
203 | - throw new EE_Error( |
|
204 | - sprintf( |
|
205 | - __( |
|
206 | - 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
207 | - 'event_espresso' |
|
208 | - ), |
|
209 | - $which_to_include |
|
210 | - ) |
|
211 | - ); |
|
212 | - } |
|
213 | - return $cron_tasks; |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
219 | - * |
|
220 | - * @throws \EE_Error |
|
221 | - */ |
|
222 | - public static function create_cron_tasks() |
|
223 | - { |
|
224 | - |
|
225 | - foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
226 | - if (! wp_next_scheduled($hook_name)) { |
|
227 | - /** |
|
228 | - * This allows client code to define the initial start timestamp for this schedule. |
|
229 | - */ |
|
230 | - if (is_array($frequency) |
|
231 | - && count($frequency) === 2 |
|
232 | - && isset($frequency[0], $frequency[1]) |
|
233 | - ) { |
|
234 | - $start_timestamp = $frequency[0]; |
|
235 | - $frequency = $frequency[1]; |
|
236 | - } else { |
|
237 | - $start_timestamp = time(); |
|
238 | - } |
|
239 | - wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
240 | - } |
|
241 | - } |
|
242 | - |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * Remove the currently-existing and now-removed cron tasks. |
|
248 | - * |
|
249 | - * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
250 | - * @throws \EE_Error |
|
251 | - */ |
|
252 | - public static function remove_cron_tasks($remove_all = true) |
|
253 | - { |
|
254 | - $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
255 | - $crons = _get_cron_array(); |
|
256 | - $crons = is_array($crons) ? $crons : array(); |
|
257 | - /* reminder of what $crons look like: |
|
188 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
189 | + //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
190 | + 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
191 | + ) |
|
192 | + ); |
|
193 | + if ($which_to_include === 'old') { |
|
194 | + $cron_tasks = array_filter( |
|
195 | + $cron_tasks, |
|
196 | + function ($value) { |
|
197 | + return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
198 | + } |
|
199 | + ); |
|
200 | + } elseif ($which_to_include === 'current') { |
|
201 | + $cron_tasks = array_filter($cron_tasks); |
|
202 | + } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
203 | + throw new EE_Error( |
|
204 | + sprintf( |
|
205 | + __( |
|
206 | + 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
207 | + 'event_espresso' |
|
208 | + ), |
|
209 | + $which_to_include |
|
210 | + ) |
|
211 | + ); |
|
212 | + } |
|
213 | + return $cron_tasks; |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
219 | + * |
|
220 | + * @throws \EE_Error |
|
221 | + */ |
|
222 | + public static function create_cron_tasks() |
|
223 | + { |
|
224 | + |
|
225 | + foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
226 | + if (! wp_next_scheduled($hook_name)) { |
|
227 | + /** |
|
228 | + * This allows client code to define the initial start timestamp for this schedule. |
|
229 | + */ |
|
230 | + if (is_array($frequency) |
|
231 | + && count($frequency) === 2 |
|
232 | + && isset($frequency[0], $frequency[1]) |
|
233 | + ) { |
|
234 | + $start_timestamp = $frequency[0]; |
|
235 | + $frequency = $frequency[1]; |
|
236 | + } else { |
|
237 | + $start_timestamp = time(); |
|
238 | + } |
|
239 | + wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
240 | + } |
|
241 | + } |
|
242 | + |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * Remove the currently-existing and now-removed cron tasks. |
|
248 | + * |
|
249 | + * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
250 | + * @throws \EE_Error |
|
251 | + */ |
|
252 | + public static function remove_cron_tasks($remove_all = true) |
|
253 | + { |
|
254 | + $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
255 | + $crons = _get_cron_array(); |
|
256 | + $crons = is_array($crons) ? $crons : array(); |
|
257 | + /* reminder of what $crons look like: |
|
258 | 258 | * Top-level keys are timestamps, and their values are arrays. |
259 | 259 | * The 2nd level arrays have keys with each of the cron task hook names to run at that time |
260 | 260 | * and their values are arrays. |
@@ -271,911 +271,911 @@ discard block |
||
271 | 271 | * ... |
272 | 272 | * ... |
273 | 273 | */ |
274 | - $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
275 | - foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
276 | - if (is_array($hooks_to_fire_at_time)) { |
|
277 | - foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
278 | - if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
279 | - && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
280 | - ) { |
|
281 | - unset($crons[$timestamp][$hook_name]); |
|
282 | - } |
|
283 | - } |
|
284 | - //also take care of any empty cron timestamps. |
|
285 | - if (empty($hooks_to_fire_at_time)) { |
|
286 | - unset($crons[$timestamp]); |
|
287 | - } |
|
288 | - } |
|
289 | - } |
|
290 | - _set_cron_array($crons); |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * CPT_initialization |
|
296 | - * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
297 | - * |
|
298 | - * @access public |
|
299 | - * @static |
|
300 | - * @return void |
|
301 | - */ |
|
302 | - public static function CPT_initialization() |
|
303 | - { |
|
304 | - // register Custom Post Types |
|
305 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
306 | - flush_rewrite_rules(); |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * reset_and_update_config |
|
313 | - * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
314 | - * If there is old calendar config data saved, then it will get converted on activation. |
|
315 | - * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
316 | - * |
|
317 | - * @access public |
|
318 | - * @static |
|
319 | - * @return void |
|
320 | - */ |
|
321 | - public static function reset_and_update_config() |
|
322 | - { |
|
323 | - do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
324 | - add_filter( |
|
325 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
326 | - array('EEH_Activation', 'migrate_old_config_data'), |
|
327 | - 10, |
|
328 | - 3 |
|
329 | - ); |
|
330 | - //EE_Config::reset(); |
|
331 | - if (! EE_Config::logging_enabled()) { |
|
332 | - delete_option(EE_Config::LOG_NAME); |
|
333 | - } |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * load_calendar_config |
|
339 | - * |
|
340 | - * @access public |
|
341 | - * @return void |
|
342 | - */ |
|
343 | - public static function load_calendar_config() |
|
344 | - { |
|
345 | - // grab array of all plugin folders and loop thru it |
|
346 | - $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
347 | - if (empty($plugins)) { |
|
348 | - return; |
|
349 | - } |
|
350 | - foreach ($plugins as $plugin_path) { |
|
351 | - // grab plugin folder name from path |
|
352 | - $plugin = basename($plugin_path); |
|
353 | - // drill down to Espresso plugins |
|
354 | - // then to calendar related plugins |
|
355 | - if ( |
|
356 | - strpos($plugin, 'espresso') !== false |
|
357 | - || strpos($plugin, 'Espresso') !== false |
|
358 | - || strpos($plugin, 'ee4') !== false |
|
359 | - || strpos($plugin, 'EE4') !== false |
|
360 | - || strpos($plugin, 'calendar') !== false |
|
361 | - ) { |
|
362 | - // this is what we are looking for |
|
363 | - $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
364 | - // does it exist in this folder ? |
|
365 | - if (is_readable($calendar_config)) { |
|
366 | - // YEAH! let's load it |
|
367 | - require_once($calendar_config); |
|
368 | - } |
|
369 | - } |
|
370 | - } |
|
371 | - } |
|
372 | - |
|
373 | - |
|
374 | - |
|
375 | - /** |
|
376 | - * _migrate_old_config_data |
|
377 | - * |
|
378 | - * @access public |
|
379 | - * @param array|stdClass $settings |
|
380 | - * @param string $config |
|
381 | - * @param \EE_Config $EE_Config |
|
382 | - * @return \stdClass |
|
383 | - */ |
|
384 | - public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
385 | - { |
|
386 | - $convert_from_array = array('addons'); |
|
387 | - // in case old settings were saved as an array |
|
388 | - if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
389 | - // convert existing settings to an object |
|
390 | - $config_array = $settings; |
|
391 | - $settings = new stdClass(); |
|
392 | - foreach ($config_array as $key => $value) { |
|
393 | - if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
394 | - $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
395 | - } else { |
|
396 | - $settings->{$key} = $value; |
|
397 | - } |
|
398 | - } |
|
399 | - add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
400 | - } |
|
401 | - return $settings; |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * deactivate_event_espresso |
|
407 | - * |
|
408 | - * @access public |
|
409 | - * @static |
|
410 | - * @return void |
|
411 | - */ |
|
412 | - public static function deactivate_event_espresso() |
|
413 | - { |
|
414 | - // check permissions |
|
415 | - if (current_user_can('activate_plugins')) { |
|
416 | - deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
417 | - } |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * verify_default_pages_exist |
|
424 | - * |
|
425 | - * @access public |
|
426 | - * @static |
|
427 | - * @return void |
|
428 | - * @throws InvalidDataTypeException |
|
429 | - */ |
|
430 | - public static function verify_default_pages_exist() |
|
431 | - { |
|
432 | - $critical_page_problem = false; |
|
433 | - $critical_pages = array( |
|
434 | - array( |
|
435 | - 'id' => 'reg_page_id', |
|
436 | - 'name' => __('Registration Checkout', 'event_espresso'), |
|
437 | - 'post' => null, |
|
438 | - 'code' => 'ESPRESSO_CHECKOUT', |
|
439 | - ), |
|
440 | - array( |
|
441 | - 'id' => 'txn_page_id', |
|
442 | - 'name' => __('Transactions', 'event_espresso'), |
|
443 | - 'post' => null, |
|
444 | - 'code' => 'ESPRESSO_TXN_PAGE', |
|
445 | - ), |
|
446 | - array( |
|
447 | - 'id' => 'thank_you_page_id', |
|
448 | - 'name' => __('Thank You', 'event_espresso'), |
|
449 | - 'post' => null, |
|
450 | - 'code' => 'ESPRESSO_THANK_YOU', |
|
451 | - ), |
|
452 | - array( |
|
453 | - 'id' => 'cancel_page_id', |
|
454 | - 'name' => __('Registration Cancelled', 'event_espresso'), |
|
455 | - 'post' => null, |
|
456 | - 'code' => 'ESPRESSO_CANCELLED', |
|
457 | - ), |
|
458 | - ); |
|
459 | - $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
460 | - foreach ($critical_pages as $critical_page) { |
|
461 | - // is critical page ID set in config ? |
|
462 | - if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
463 | - // attempt to find post by ID |
|
464 | - $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
465 | - } |
|
466 | - // no dice? |
|
467 | - if ($critical_page['post'] === null) { |
|
468 | - // attempt to find post by title |
|
469 | - $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
470 | - // still nothing? |
|
471 | - if ($critical_page['post'] === null) { |
|
472 | - $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
473 | - // REALLY? Still nothing ??!?!? |
|
474 | - if ($critical_page['post'] === null) { |
|
475 | - $msg = __( |
|
476 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
477 | - 'event_espresso' |
|
478 | - ); |
|
479 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
480 | - break; |
|
481 | - } |
|
482 | - } |
|
483 | - } |
|
484 | - // check that Post ID matches critical page ID in config |
|
485 | - if ( |
|
486 | - isset($critical_page['post']->ID) |
|
487 | - && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
488 | - ) { |
|
489 | - //update Config with post ID |
|
490 | - $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
491 | - if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
492 | - $msg = __( |
|
493 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
494 | - 'event_espresso' |
|
495 | - ); |
|
496 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
497 | - } |
|
498 | - } |
|
499 | - $critical_page_problem = |
|
500 | - ! isset($critical_page['post']->post_status) |
|
501 | - || $critical_page['post']->post_status !== 'publish' |
|
502 | - || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
503 | - ? true |
|
504 | - : $critical_page_problem; |
|
505 | - } |
|
506 | - if ($critical_page_problem) { |
|
507 | - new PersistentAdminNotice( |
|
508 | - 'critical_page_problem', |
|
509 | - sprintf( |
|
510 | - esc_html__( |
|
511 | - 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
512 | - 'event_espresso' |
|
513 | - ), |
|
514 | - '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' |
|
515 | - . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
516 | - . '</a>' |
|
517 | - ) |
|
518 | - ); |
|
519 | - } |
|
520 | - if (EE_Error::has_notices()) { |
|
521 | - EE_Error::get_notices(false, true, true); |
|
522 | - } |
|
523 | - } |
|
524 | - |
|
525 | - |
|
526 | - |
|
527 | - /** |
|
528 | - * Returns the first post which uses the specified shortcode |
|
529 | - * |
|
530 | - * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
531 | - * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
532 | - * "[ESPRESSO_THANK_YOU" |
|
533 | - * (we don't search for the closing shortcode bracket because they might have added |
|
534 | - * parameter to the shortcode |
|
535 | - * @return WP_Post or NULl |
|
536 | - */ |
|
537 | - public static function get_page_by_ee_shortcode($ee_shortcode) |
|
538 | - { |
|
539 | - global $wpdb; |
|
540 | - $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
541 | - $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
542 | - if ($post_id) { |
|
543 | - return get_post($post_id); |
|
544 | - } else { |
|
545 | - return null; |
|
546 | - } |
|
547 | - } |
|
548 | - |
|
549 | - |
|
550 | - /** |
|
551 | - * This function generates a post for critical espresso pages |
|
552 | - * |
|
553 | - * @access public |
|
554 | - * @static |
|
555 | - * @param array $critical_page |
|
556 | - * @return array |
|
557 | - */ |
|
558 | - public static function create_critical_page($critical_page) |
|
559 | - { |
|
560 | - |
|
561 | - $post_args = array( |
|
562 | - 'post_title' => $critical_page['name'], |
|
563 | - 'post_status' => 'publish', |
|
564 | - 'post_type' => 'page', |
|
565 | - 'comment_status' => 'closed', |
|
566 | - 'post_content' => '[' . $critical_page['code'] . ']', |
|
567 | - ); |
|
568 | - |
|
569 | - $post_id = wp_insert_post($post_args); |
|
570 | - if (! $post_id) { |
|
571 | - $msg = sprintf( |
|
572 | - __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
573 | - $critical_page['name'] |
|
574 | - ); |
|
575 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
576 | - return $critical_page; |
|
577 | - } |
|
578 | - // get newly created post's details |
|
579 | - if (! $critical_page['post'] = get_post($post_id)) { |
|
580 | - $msg = sprintf( |
|
581 | - __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
582 | - $critical_page['name'] |
|
583 | - ); |
|
584 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
585 | - } |
|
586 | - |
|
587 | - return $critical_page; |
|
588 | - |
|
589 | - } |
|
590 | - |
|
591 | - |
|
592 | - |
|
593 | - |
|
594 | - /** |
|
595 | - * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
596 | - * The role being used to check is filterable. |
|
597 | - * |
|
598 | - * @since 4.6.0 |
|
599 | - * @global WPDB $wpdb |
|
600 | - * @return mixed null|int WP_user ID or NULL |
|
601 | - */ |
|
602 | - public static function get_default_creator_id() |
|
603 | - { |
|
604 | - global $wpdb; |
|
605 | - if ( ! empty(self::$_default_creator_id)) { |
|
606 | - return self::$_default_creator_id; |
|
607 | - }/**/ |
|
608 | - $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
609 | - //let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
610 | - $pre_filtered_id = apply_filters( |
|
611 | - 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
612 | - false, |
|
613 | - $role_to_check |
|
614 | - ); |
|
615 | - if ($pre_filtered_id !== false) { |
|
616 | - return (int)$pre_filtered_id; |
|
617 | - } |
|
618 | - $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
619 | - $query = $wpdb->prepare( |
|
620 | - "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
621 | - '%' . $role_to_check . '%' |
|
622 | - ); |
|
623 | - $user_id = $wpdb->get_var($query); |
|
624 | - $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
625 | - if ($user_id && (int)$user_id) { |
|
626 | - self::$_default_creator_id = (int)$user_id; |
|
627 | - return self::$_default_creator_id; |
|
628 | - } else { |
|
629 | - return null; |
|
630 | - } |
|
631 | - } |
|
632 | - |
|
633 | - |
|
634 | - |
|
635 | - /** |
|
636 | - * used by EE and EE addons during plugin activation to create tables. |
|
637 | - * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
638 | - * but includes extra logic regarding activations. |
|
639 | - * |
|
640 | - * @access public |
|
641 | - * @static |
|
642 | - * @param string $table_name without the $wpdb->prefix |
|
643 | - * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
644 | - * table query) |
|
645 | - * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
646 | - * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
647 | - * and new once this function is done (ie, you really do want to CREATE a |
|
648 | - * table, and expect it to be empty once you're done) leave as FALSE when |
|
649 | - * you just want to verify the table exists and matches this definition |
|
650 | - * (and if it HAS data in it you want to leave it be) |
|
651 | - * @return void |
|
652 | - * @throws EE_Error if there are database errors |
|
653 | - */ |
|
654 | - public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
655 | - { |
|
656 | - if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
657 | - return; |
|
658 | - } |
|
659 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
660 | - if ( ! function_exists('dbDelta')) { |
|
661 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
662 | - } |
|
663 | - $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
664 | - $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
665 | - // do we need to first delete an existing version of this table ? |
|
666 | - if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
667 | - // ok, delete the table... but ONLY if it's empty |
|
668 | - $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
669 | - // table is NOT empty, are you SURE you want to delete this table ??? |
|
670 | - if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
671 | - \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
672 | - } else if ( ! $deleted_safely) { |
|
673 | - // so we should be more cautious rather than just dropping tables so easily |
|
674 | - error_log( |
|
675 | - sprintf( |
|
676 | - __( |
|
677 | - 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
678 | - 'event_espresso' |
|
679 | - ), |
|
680 | - $wp_table_name, |
|
681 | - '<br/>', |
|
682 | - 'espresso_db_update' |
|
683 | - ) |
|
684 | - ); |
|
685 | - } |
|
686 | - } |
|
687 | - $engine = str_replace('ENGINE=', '', $engine); |
|
688 | - \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
689 | - } |
|
690 | - |
|
691 | - |
|
692 | - |
|
693 | - /** |
|
694 | - * add_column_if_it_doesn't_exist |
|
695 | - * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
696 | - * |
|
697 | - * @access public |
|
698 | - * @static |
|
699 | - * @deprecated instead use TableManager::addColumn() |
|
700 | - * @param string $table_name (without "wp_", eg "esp_attendee" |
|
701 | - * @param string $column_name |
|
702 | - * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
703 | - * 'VARCHAR(10)' |
|
704 | - * @return bool|int |
|
705 | - */ |
|
706 | - public static function add_column_if_it_doesnt_exist( |
|
707 | - $table_name, |
|
708 | - $column_name, |
|
709 | - $column_info = 'INT UNSIGNED NOT NULL' |
|
710 | - ) { |
|
711 | - return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
712 | - } |
|
713 | - |
|
714 | - |
|
715 | - /** |
|
716 | - * get_fields_on_table |
|
717 | - * Gets all the fields on the database table. |
|
718 | - * |
|
719 | - * @access public |
|
720 | - * @deprecated instead use TableManager::getTableColumns() |
|
721 | - * @static |
|
722 | - * @param string $table_name , without prefixed $wpdb->prefix |
|
723 | - * @return array of database column names |
|
724 | - */ |
|
725 | - public static function get_fields_on_table($table_name = null) |
|
726 | - { |
|
727 | - return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
728 | - } |
|
729 | - |
|
730 | - |
|
731 | - /** |
|
732 | - * db_table_is_empty |
|
733 | - * |
|
734 | - * @access public\ |
|
735 | - * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
736 | - * @static |
|
737 | - * @param string $table_name |
|
738 | - * @return bool |
|
739 | - */ |
|
740 | - public static function db_table_is_empty($table_name) |
|
741 | - { |
|
742 | - return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
743 | - } |
|
744 | - |
|
745 | - |
|
746 | - /** |
|
747 | - * delete_db_table_if_empty |
|
748 | - * |
|
749 | - * @access public |
|
750 | - * @static |
|
751 | - * @param string $table_name |
|
752 | - * @return bool | int |
|
753 | - */ |
|
754 | - public static function delete_db_table_if_empty($table_name) |
|
755 | - { |
|
756 | - if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
757 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
758 | - } |
|
759 | - return false; |
|
760 | - } |
|
761 | - |
|
762 | - |
|
763 | - /** |
|
764 | - * delete_unused_db_table |
|
765 | - * |
|
766 | - * @access public |
|
767 | - * @static |
|
768 | - * @deprecated instead use TableManager::dropTable() |
|
769 | - * @param string $table_name |
|
770 | - * @return bool | int |
|
771 | - */ |
|
772 | - public static function delete_unused_db_table($table_name) |
|
773 | - { |
|
774 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
775 | - } |
|
776 | - |
|
777 | - |
|
778 | - /** |
|
779 | - * drop_index |
|
780 | - * |
|
781 | - * @access public |
|
782 | - * @static |
|
783 | - * @deprecated instead use TableManager::dropIndex() |
|
784 | - * @param string $table_name |
|
785 | - * @param string $index_name |
|
786 | - * @return bool | int |
|
787 | - */ |
|
788 | - public static function drop_index($table_name, $index_name) |
|
789 | - { |
|
790 | - return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
791 | - } |
|
792 | - |
|
793 | - |
|
794 | - |
|
795 | - /** |
|
796 | - * create_database_tables |
|
797 | - * |
|
798 | - * @access public |
|
799 | - * @static |
|
800 | - * @throws EE_Error |
|
801 | - * @return boolean success (whether database is setup properly or not) |
|
802 | - */ |
|
803 | - public static function create_database_tables() |
|
804 | - { |
|
805 | - EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
806 | - //find the migration script that sets the database to be compatible with the code |
|
807 | - $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
808 | - if ($dms_name) { |
|
809 | - $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
810 | - $current_data_migration_script->set_migrating(false); |
|
811 | - $current_data_migration_script->schema_changes_before_migration(); |
|
812 | - $current_data_migration_script->schema_changes_after_migration(); |
|
813 | - if ($current_data_migration_script->get_errors()) { |
|
814 | - if (WP_DEBUG) { |
|
815 | - foreach ($current_data_migration_script->get_errors() as $error) { |
|
816 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
817 | - } |
|
818 | - } else { |
|
819 | - EE_Error::add_error( |
|
820 | - __( |
|
821 | - 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
274 | + $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
275 | + foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
276 | + if (is_array($hooks_to_fire_at_time)) { |
|
277 | + foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
278 | + if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
279 | + && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
280 | + ) { |
|
281 | + unset($crons[$timestamp][$hook_name]); |
|
282 | + } |
|
283 | + } |
|
284 | + //also take care of any empty cron timestamps. |
|
285 | + if (empty($hooks_to_fire_at_time)) { |
|
286 | + unset($crons[$timestamp]); |
|
287 | + } |
|
288 | + } |
|
289 | + } |
|
290 | + _set_cron_array($crons); |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * CPT_initialization |
|
296 | + * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
297 | + * |
|
298 | + * @access public |
|
299 | + * @static |
|
300 | + * @return void |
|
301 | + */ |
|
302 | + public static function CPT_initialization() |
|
303 | + { |
|
304 | + // register Custom Post Types |
|
305 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
306 | + flush_rewrite_rules(); |
|
307 | + } |
|
308 | + |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * reset_and_update_config |
|
313 | + * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
314 | + * If there is old calendar config data saved, then it will get converted on activation. |
|
315 | + * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
316 | + * |
|
317 | + * @access public |
|
318 | + * @static |
|
319 | + * @return void |
|
320 | + */ |
|
321 | + public static function reset_and_update_config() |
|
322 | + { |
|
323 | + do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
324 | + add_filter( |
|
325 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
326 | + array('EEH_Activation', 'migrate_old_config_data'), |
|
327 | + 10, |
|
328 | + 3 |
|
329 | + ); |
|
330 | + //EE_Config::reset(); |
|
331 | + if (! EE_Config::logging_enabled()) { |
|
332 | + delete_option(EE_Config::LOG_NAME); |
|
333 | + } |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * load_calendar_config |
|
339 | + * |
|
340 | + * @access public |
|
341 | + * @return void |
|
342 | + */ |
|
343 | + public static function load_calendar_config() |
|
344 | + { |
|
345 | + // grab array of all plugin folders and loop thru it |
|
346 | + $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
347 | + if (empty($plugins)) { |
|
348 | + return; |
|
349 | + } |
|
350 | + foreach ($plugins as $plugin_path) { |
|
351 | + // grab plugin folder name from path |
|
352 | + $plugin = basename($plugin_path); |
|
353 | + // drill down to Espresso plugins |
|
354 | + // then to calendar related plugins |
|
355 | + if ( |
|
356 | + strpos($plugin, 'espresso') !== false |
|
357 | + || strpos($plugin, 'Espresso') !== false |
|
358 | + || strpos($plugin, 'ee4') !== false |
|
359 | + || strpos($plugin, 'EE4') !== false |
|
360 | + || strpos($plugin, 'calendar') !== false |
|
361 | + ) { |
|
362 | + // this is what we are looking for |
|
363 | + $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
364 | + // does it exist in this folder ? |
|
365 | + if (is_readable($calendar_config)) { |
|
366 | + // YEAH! let's load it |
|
367 | + require_once($calendar_config); |
|
368 | + } |
|
369 | + } |
|
370 | + } |
|
371 | + } |
|
372 | + |
|
373 | + |
|
374 | + |
|
375 | + /** |
|
376 | + * _migrate_old_config_data |
|
377 | + * |
|
378 | + * @access public |
|
379 | + * @param array|stdClass $settings |
|
380 | + * @param string $config |
|
381 | + * @param \EE_Config $EE_Config |
|
382 | + * @return \stdClass |
|
383 | + */ |
|
384 | + public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
385 | + { |
|
386 | + $convert_from_array = array('addons'); |
|
387 | + // in case old settings were saved as an array |
|
388 | + if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
389 | + // convert existing settings to an object |
|
390 | + $config_array = $settings; |
|
391 | + $settings = new stdClass(); |
|
392 | + foreach ($config_array as $key => $value) { |
|
393 | + if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
394 | + $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
395 | + } else { |
|
396 | + $settings->{$key} = $value; |
|
397 | + } |
|
398 | + } |
|
399 | + add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
400 | + } |
|
401 | + return $settings; |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * deactivate_event_espresso |
|
407 | + * |
|
408 | + * @access public |
|
409 | + * @static |
|
410 | + * @return void |
|
411 | + */ |
|
412 | + public static function deactivate_event_espresso() |
|
413 | + { |
|
414 | + // check permissions |
|
415 | + if (current_user_can('activate_plugins')) { |
|
416 | + deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
417 | + } |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * verify_default_pages_exist |
|
424 | + * |
|
425 | + * @access public |
|
426 | + * @static |
|
427 | + * @return void |
|
428 | + * @throws InvalidDataTypeException |
|
429 | + */ |
|
430 | + public static function verify_default_pages_exist() |
|
431 | + { |
|
432 | + $critical_page_problem = false; |
|
433 | + $critical_pages = array( |
|
434 | + array( |
|
435 | + 'id' => 'reg_page_id', |
|
436 | + 'name' => __('Registration Checkout', 'event_espresso'), |
|
437 | + 'post' => null, |
|
438 | + 'code' => 'ESPRESSO_CHECKOUT', |
|
439 | + ), |
|
440 | + array( |
|
441 | + 'id' => 'txn_page_id', |
|
442 | + 'name' => __('Transactions', 'event_espresso'), |
|
443 | + 'post' => null, |
|
444 | + 'code' => 'ESPRESSO_TXN_PAGE', |
|
445 | + ), |
|
446 | + array( |
|
447 | + 'id' => 'thank_you_page_id', |
|
448 | + 'name' => __('Thank You', 'event_espresso'), |
|
449 | + 'post' => null, |
|
450 | + 'code' => 'ESPRESSO_THANK_YOU', |
|
451 | + ), |
|
452 | + array( |
|
453 | + 'id' => 'cancel_page_id', |
|
454 | + 'name' => __('Registration Cancelled', 'event_espresso'), |
|
455 | + 'post' => null, |
|
456 | + 'code' => 'ESPRESSO_CANCELLED', |
|
457 | + ), |
|
458 | + ); |
|
459 | + $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
460 | + foreach ($critical_pages as $critical_page) { |
|
461 | + // is critical page ID set in config ? |
|
462 | + if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
463 | + // attempt to find post by ID |
|
464 | + $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
465 | + } |
|
466 | + // no dice? |
|
467 | + if ($critical_page['post'] === null) { |
|
468 | + // attempt to find post by title |
|
469 | + $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
470 | + // still nothing? |
|
471 | + if ($critical_page['post'] === null) { |
|
472 | + $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
473 | + // REALLY? Still nothing ??!?!? |
|
474 | + if ($critical_page['post'] === null) { |
|
475 | + $msg = __( |
|
476 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
477 | + 'event_espresso' |
|
478 | + ); |
|
479 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
480 | + break; |
|
481 | + } |
|
482 | + } |
|
483 | + } |
|
484 | + // check that Post ID matches critical page ID in config |
|
485 | + if ( |
|
486 | + isset($critical_page['post']->ID) |
|
487 | + && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
488 | + ) { |
|
489 | + //update Config with post ID |
|
490 | + $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
491 | + if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
492 | + $msg = __( |
|
493 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
494 | + 'event_espresso' |
|
495 | + ); |
|
496 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
497 | + } |
|
498 | + } |
|
499 | + $critical_page_problem = |
|
500 | + ! isset($critical_page['post']->post_status) |
|
501 | + || $critical_page['post']->post_status !== 'publish' |
|
502 | + || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
503 | + ? true |
|
504 | + : $critical_page_problem; |
|
505 | + } |
|
506 | + if ($critical_page_problem) { |
|
507 | + new PersistentAdminNotice( |
|
508 | + 'critical_page_problem', |
|
509 | + sprintf( |
|
510 | + esc_html__( |
|
511 | + 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
512 | + 'event_espresso' |
|
513 | + ), |
|
514 | + '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' |
|
515 | + . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
516 | + . '</a>' |
|
517 | + ) |
|
518 | + ); |
|
519 | + } |
|
520 | + if (EE_Error::has_notices()) { |
|
521 | + EE_Error::get_notices(false, true, true); |
|
522 | + } |
|
523 | + } |
|
524 | + |
|
525 | + |
|
526 | + |
|
527 | + /** |
|
528 | + * Returns the first post which uses the specified shortcode |
|
529 | + * |
|
530 | + * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
531 | + * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
532 | + * "[ESPRESSO_THANK_YOU" |
|
533 | + * (we don't search for the closing shortcode bracket because they might have added |
|
534 | + * parameter to the shortcode |
|
535 | + * @return WP_Post or NULl |
|
536 | + */ |
|
537 | + public static function get_page_by_ee_shortcode($ee_shortcode) |
|
538 | + { |
|
539 | + global $wpdb; |
|
540 | + $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
541 | + $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
542 | + if ($post_id) { |
|
543 | + return get_post($post_id); |
|
544 | + } else { |
|
545 | + return null; |
|
546 | + } |
|
547 | + } |
|
548 | + |
|
549 | + |
|
550 | + /** |
|
551 | + * This function generates a post for critical espresso pages |
|
552 | + * |
|
553 | + * @access public |
|
554 | + * @static |
|
555 | + * @param array $critical_page |
|
556 | + * @return array |
|
557 | + */ |
|
558 | + public static function create_critical_page($critical_page) |
|
559 | + { |
|
560 | + |
|
561 | + $post_args = array( |
|
562 | + 'post_title' => $critical_page['name'], |
|
563 | + 'post_status' => 'publish', |
|
564 | + 'post_type' => 'page', |
|
565 | + 'comment_status' => 'closed', |
|
566 | + 'post_content' => '[' . $critical_page['code'] . ']', |
|
567 | + ); |
|
568 | + |
|
569 | + $post_id = wp_insert_post($post_args); |
|
570 | + if (! $post_id) { |
|
571 | + $msg = sprintf( |
|
572 | + __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
573 | + $critical_page['name'] |
|
574 | + ); |
|
575 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
576 | + return $critical_page; |
|
577 | + } |
|
578 | + // get newly created post's details |
|
579 | + if (! $critical_page['post'] = get_post($post_id)) { |
|
580 | + $msg = sprintf( |
|
581 | + __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
582 | + $critical_page['name'] |
|
583 | + ); |
|
584 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
585 | + } |
|
586 | + |
|
587 | + return $critical_page; |
|
588 | + |
|
589 | + } |
|
590 | + |
|
591 | + |
|
592 | + |
|
593 | + |
|
594 | + /** |
|
595 | + * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
596 | + * The role being used to check is filterable. |
|
597 | + * |
|
598 | + * @since 4.6.0 |
|
599 | + * @global WPDB $wpdb |
|
600 | + * @return mixed null|int WP_user ID or NULL |
|
601 | + */ |
|
602 | + public static function get_default_creator_id() |
|
603 | + { |
|
604 | + global $wpdb; |
|
605 | + if ( ! empty(self::$_default_creator_id)) { |
|
606 | + return self::$_default_creator_id; |
|
607 | + }/**/ |
|
608 | + $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
609 | + //let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
610 | + $pre_filtered_id = apply_filters( |
|
611 | + 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
612 | + false, |
|
613 | + $role_to_check |
|
614 | + ); |
|
615 | + if ($pre_filtered_id !== false) { |
|
616 | + return (int)$pre_filtered_id; |
|
617 | + } |
|
618 | + $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
619 | + $query = $wpdb->prepare( |
|
620 | + "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
621 | + '%' . $role_to_check . '%' |
|
622 | + ); |
|
623 | + $user_id = $wpdb->get_var($query); |
|
624 | + $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
625 | + if ($user_id && (int)$user_id) { |
|
626 | + self::$_default_creator_id = (int)$user_id; |
|
627 | + return self::$_default_creator_id; |
|
628 | + } else { |
|
629 | + return null; |
|
630 | + } |
|
631 | + } |
|
632 | + |
|
633 | + |
|
634 | + |
|
635 | + /** |
|
636 | + * used by EE and EE addons during plugin activation to create tables. |
|
637 | + * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
638 | + * but includes extra logic regarding activations. |
|
639 | + * |
|
640 | + * @access public |
|
641 | + * @static |
|
642 | + * @param string $table_name without the $wpdb->prefix |
|
643 | + * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
644 | + * table query) |
|
645 | + * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
646 | + * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
647 | + * and new once this function is done (ie, you really do want to CREATE a |
|
648 | + * table, and expect it to be empty once you're done) leave as FALSE when |
|
649 | + * you just want to verify the table exists and matches this definition |
|
650 | + * (and if it HAS data in it you want to leave it be) |
|
651 | + * @return void |
|
652 | + * @throws EE_Error if there are database errors |
|
653 | + */ |
|
654 | + public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
655 | + { |
|
656 | + if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
657 | + return; |
|
658 | + } |
|
659 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
660 | + if ( ! function_exists('dbDelta')) { |
|
661 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
662 | + } |
|
663 | + $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
664 | + $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
665 | + // do we need to first delete an existing version of this table ? |
|
666 | + if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
667 | + // ok, delete the table... but ONLY if it's empty |
|
668 | + $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
669 | + // table is NOT empty, are you SURE you want to delete this table ??? |
|
670 | + if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
671 | + \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
672 | + } else if ( ! $deleted_safely) { |
|
673 | + // so we should be more cautious rather than just dropping tables so easily |
|
674 | + error_log( |
|
675 | + sprintf( |
|
676 | + __( |
|
677 | + 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
678 | + 'event_espresso' |
|
679 | + ), |
|
680 | + $wp_table_name, |
|
681 | + '<br/>', |
|
682 | + 'espresso_db_update' |
|
683 | + ) |
|
684 | + ); |
|
685 | + } |
|
686 | + } |
|
687 | + $engine = str_replace('ENGINE=', '', $engine); |
|
688 | + \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
689 | + } |
|
690 | + |
|
691 | + |
|
692 | + |
|
693 | + /** |
|
694 | + * add_column_if_it_doesn't_exist |
|
695 | + * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
696 | + * |
|
697 | + * @access public |
|
698 | + * @static |
|
699 | + * @deprecated instead use TableManager::addColumn() |
|
700 | + * @param string $table_name (without "wp_", eg "esp_attendee" |
|
701 | + * @param string $column_name |
|
702 | + * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
703 | + * 'VARCHAR(10)' |
|
704 | + * @return bool|int |
|
705 | + */ |
|
706 | + public static function add_column_if_it_doesnt_exist( |
|
707 | + $table_name, |
|
708 | + $column_name, |
|
709 | + $column_info = 'INT UNSIGNED NOT NULL' |
|
710 | + ) { |
|
711 | + return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
712 | + } |
|
713 | + |
|
714 | + |
|
715 | + /** |
|
716 | + * get_fields_on_table |
|
717 | + * Gets all the fields on the database table. |
|
718 | + * |
|
719 | + * @access public |
|
720 | + * @deprecated instead use TableManager::getTableColumns() |
|
721 | + * @static |
|
722 | + * @param string $table_name , without prefixed $wpdb->prefix |
|
723 | + * @return array of database column names |
|
724 | + */ |
|
725 | + public static function get_fields_on_table($table_name = null) |
|
726 | + { |
|
727 | + return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
728 | + } |
|
729 | + |
|
730 | + |
|
731 | + /** |
|
732 | + * db_table_is_empty |
|
733 | + * |
|
734 | + * @access public\ |
|
735 | + * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
736 | + * @static |
|
737 | + * @param string $table_name |
|
738 | + * @return bool |
|
739 | + */ |
|
740 | + public static function db_table_is_empty($table_name) |
|
741 | + { |
|
742 | + return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
743 | + } |
|
744 | + |
|
745 | + |
|
746 | + /** |
|
747 | + * delete_db_table_if_empty |
|
748 | + * |
|
749 | + * @access public |
|
750 | + * @static |
|
751 | + * @param string $table_name |
|
752 | + * @return bool | int |
|
753 | + */ |
|
754 | + public static function delete_db_table_if_empty($table_name) |
|
755 | + { |
|
756 | + if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
757 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
758 | + } |
|
759 | + return false; |
|
760 | + } |
|
761 | + |
|
762 | + |
|
763 | + /** |
|
764 | + * delete_unused_db_table |
|
765 | + * |
|
766 | + * @access public |
|
767 | + * @static |
|
768 | + * @deprecated instead use TableManager::dropTable() |
|
769 | + * @param string $table_name |
|
770 | + * @return bool | int |
|
771 | + */ |
|
772 | + public static function delete_unused_db_table($table_name) |
|
773 | + { |
|
774 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
775 | + } |
|
776 | + |
|
777 | + |
|
778 | + /** |
|
779 | + * drop_index |
|
780 | + * |
|
781 | + * @access public |
|
782 | + * @static |
|
783 | + * @deprecated instead use TableManager::dropIndex() |
|
784 | + * @param string $table_name |
|
785 | + * @param string $index_name |
|
786 | + * @return bool | int |
|
787 | + */ |
|
788 | + public static function drop_index($table_name, $index_name) |
|
789 | + { |
|
790 | + return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
791 | + } |
|
792 | + |
|
793 | + |
|
794 | + |
|
795 | + /** |
|
796 | + * create_database_tables |
|
797 | + * |
|
798 | + * @access public |
|
799 | + * @static |
|
800 | + * @throws EE_Error |
|
801 | + * @return boolean success (whether database is setup properly or not) |
|
802 | + */ |
|
803 | + public static function create_database_tables() |
|
804 | + { |
|
805 | + EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
806 | + //find the migration script that sets the database to be compatible with the code |
|
807 | + $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
808 | + if ($dms_name) { |
|
809 | + $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
810 | + $current_data_migration_script->set_migrating(false); |
|
811 | + $current_data_migration_script->schema_changes_before_migration(); |
|
812 | + $current_data_migration_script->schema_changes_after_migration(); |
|
813 | + if ($current_data_migration_script->get_errors()) { |
|
814 | + if (WP_DEBUG) { |
|
815 | + foreach ($current_data_migration_script->get_errors() as $error) { |
|
816 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
817 | + } |
|
818 | + } else { |
|
819 | + EE_Error::add_error( |
|
820 | + __( |
|
821 | + 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
822 | 822 | deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.', |
823 | - 'event_espresso' |
|
824 | - ) |
|
825 | - ); |
|
826 | - } |
|
827 | - return false; |
|
828 | - } |
|
829 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
830 | - } else { |
|
831 | - EE_Error::add_error( |
|
832 | - __( |
|
833 | - 'Could not determine most up-to-date data migration script from which to pull database schema |
|
823 | + 'event_espresso' |
|
824 | + ) |
|
825 | + ); |
|
826 | + } |
|
827 | + return false; |
|
828 | + } |
|
829 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
830 | + } else { |
|
831 | + EE_Error::add_error( |
|
832 | + __( |
|
833 | + 'Could not determine most up-to-date data migration script from which to pull database schema |
|
834 | 834 | structure. So database is probably not setup properly', |
835 | - 'event_espresso' |
|
836 | - ), |
|
837 | - __FILE__, |
|
838 | - __FUNCTION__, |
|
839 | - __LINE__ |
|
840 | - ); |
|
841 | - return false; |
|
842 | - } |
|
843 | - return true; |
|
844 | - } |
|
845 | - |
|
846 | - |
|
847 | - |
|
848 | - /** |
|
849 | - * initialize_system_questions |
|
850 | - * |
|
851 | - * @access public |
|
852 | - * @static |
|
853 | - * @return void |
|
854 | - */ |
|
855 | - public static function initialize_system_questions() |
|
856 | - { |
|
857 | - // QUESTION GROUPS |
|
858 | - global $wpdb; |
|
859 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
860 | - $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
861 | - // what we have |
|
862 | - $question_groups = $wpdb->get_col($SQL); |
|
863 | - // check the response |
|
864 | - $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
865 | - // what we should have |
|
866 | - $QSG_systems = array(1, 2); |
|
867 | - // loop thru what we should have and compare to what we have |
|
868 | - foreach ($QSG_systems as $QSG_system) { |
|
869 | - // reset values array |
|
870 | - $QSG_values = array(); |
|
871 | - // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
872 | - if (! in_array("$QSG_system", $question_groups)) { |
|
873 | - // add it |
|
874 | - switch ($QSG_system) { |
|
875 | - case 1: |
|
876 | - $QSG_values = array( |
|
877 | - 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
878 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
879 | - 'QSG_desc' => '', |
|
880 | - 'QSG_order' => 1, |
|
881 | - 'QSG_show_group_name' => 1, |
|
882 | - 'QSG_show_group_desc' => 1, |
|
883 | - 'QSG_system' => EEM_Question_Group::system_personal, |
|
884 | - 'QSG_deleted' => 0, |
|
885 | - ); |
|
886 | - break; |
|
887 | - case 2: |
|
888 | - $QSG_values = array( |
|
889 | - 'QSG_name' => __('Address Information', 'event_espresso'), |
|
890 | - 'QSG_identifier' => 'address-information-' . time(), |
|
891 | - 'QSG_desc' => '', |
|
892 | - 'QSG_order' => 2, |
|
893 | - 'QSG_show_group_name' => 1, |
|
894 | - 'QSG_show_group_desc' => 1, |
|
895 | - 'QSG_system' => EEM_Question_Group::system_address, |
|
896 | - 'QSG_deleted' => 0, |
|
897 | - ); |
|
898 | - break; |
|
899 | - } |
|
900 | - // make sure we have some values before inserting them |
|
901 | - if (! empty($QSG_values)) { |
|
902 | - // insert system question |
|
903 | - $wpdb->insert( |
|
904 | - $table_name, |
|
905 | - $QSG_values, |
|
906 | - array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
907 | - ); |
|
908 | - $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
909 | - } |
|
910 | - } |
|
911 | - } |
|
912 | - // QUESTIONS |
|
913 | - global $wpdb; |
|
914 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
915 | - $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
916 | - // what we have |
|
917 | - $questions = $wpdb->get_col($SQL); |
|
918 | - // what we should have |
|
919 | - $QST_systems = array( |
|
920 | - 'fname', |
|
921 | - 'lname', |
|
922 | - 'email', |
|
923 | - 'address', |
|
924 | - 'address2', |
|
925 | - 'city', |
|
926 | - 'country', |
|
927 | - 'state', |
|
928 | - 'zip', |
|
929 | - 'phone', |
|
930 | - ); |
|
931 | - $order_for_group_1 = 1; |
|
932 | - $order_for_group_2 = 1; |
|
933 | - // loop thru what we should have and compare to what we have |
|
934 | - foreach ($QST_systems as $QST_system) { |
|
935 | - // reset values array |
|
936 | - $QST_values = array(); |
|
937 | - // if we don't have what we should have |
|
938 | - if (! in_array($QST_system, $questions)) { |
|
939 | - // add it |
|
940 | - switch ($QST_system) { |
|
941 | - case 'fname': |
|
942 | - $QST_values = array( |
|
943 | - 'QST_display_text' => __('First Name', 'event_espresso'), |
|
944 | - 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
945 | - 'QST_system' => 'fname', |
|
946 | - 'QST_type' => 'TEXT', |
|
947 | - 'QST_required' => 1, |
|
948 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
949 | - 'QST_order' => 1, |
|
950 | - 'QST_admin_only' => 0, |
|
951 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
952 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
953 | - 'QST_deleted' => 0, |
|
954 | - ); |
|
955 | - break; |
|
956 | - case 'lname': |
|
957 | - $QST_values = array( |
|
958 | - 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
959 | - 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
960 | - 'QST_system' => 'lname', |
|
961 | - 'QST_type' => 'TEXT', |
|
962 | - 'QST_required' => 1, |
|
963 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
964 | - 'QST_order' => 2, |
|
965 | - 'QST_admin_only' => 0, |
|
966 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
967 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
968 | - 'QST_deleted' => 0, |
|
969 | - ); |
|
970 | - break; |
|
971 | - case 'email': |
|
972 | - $QST_values = array( |
|
973 | - 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
974 | - 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
975 | - 'QST_system' => 'email', |
|
976 | - 'QST_type' => 'EMAIL', |
|
977 | - 'QST_required' => 1, |
|
978 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
979 | - 'QST_order' => 3, |
|
980 | - 'QST_admin_only' => 0, |
|
981 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
982 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
983 | - 'QST_deleted' => 0, |
|
984 | - ); |
|
985 | - break; |
|
986 | - case 'address': |
|
987 | - $QST_values = array( |
|
988 | - 'QST_display_text' => __('Address', 'event_espresso'), |
|
989 | - 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
990 | - 'QST_system' => 'address', |
|
991 | - 'QST_type' => 'TEXT', |
|
992 | - 'QST_required' => 0, |
|
993 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
994 | - 'QST_order' => 4, |
|
995 | - 'QST_admin_only' => 0, |
|
996 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
997 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
998 | - 'QST_deleted' => 0, |
|
999 | - ); |
|
1000 | - break; |
|
1001 | - case 'address2': |
|
1002 | - $QST_values = array( |
|
1003 | - 'QST_display_text' => __('Address2', 'event_espresso'), |
|
1004 | - 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
1005 | - 'QST_system' => 'address2', |
|
1006 | - 'QST_type' => 'TEXT', |
|
1007 | - 'QST_required' => 0, |
|
1008 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1009 | - 'QST_order' => 5, |
|
1010 | - 'QST_admin_only' => 0, |
|
1011 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1012 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1013 | - 'QST_deleted' => 0, |
|
1014 | - ); |
|
1015 | - break; |
|
1016 | - case 'city': |
|
1017 | - $QST_values = array( |
|
1018 | - 'QST_display_text' => __('City', 'event_espresso'), |
|
1019 | - 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
1020 | - 'QST_system' => 'city', |
|
1021 | - 'QST_type' => 'TEXT', |
|
1022 | - 'QST_required' => 0, |
|
1023 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1024 | - 'QST_order' => 6, |
|
1025 | - 'QST_admin_only' => 0, |
|
1026 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1027 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1028 | - 'QST_deleted' => 0, |
|
1029 | - ); |
|
1030 | - break; |
|
1031 | - case 'country': |
|
1032 | - $QST_values = array( |
|
1033 | - 'QST_display_text' => __('Country', 'event_espresso'), |
|
1034 | - 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
1035 | - 'QST_system' => 'country', |
|
1036 | - 'QST_type' => 'COUNTRY', |
|
1037 | - 'QST_required' => 0, |
|
1038 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1039 | - 'QST_order' => 7, |
|
1040 | - 'QST_admin_only' => 0, |
|
1041 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1042 | - 'QST_deleted' => 0, |
|
1043 | - ); |
|
1044 | - break; |
|
1045 | - case 'state': |
|
1046 | - $QST_values = array( |
|
1047 | - 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
1048 | - 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
1049 | - 'QST_system' => 'state', |
|
1050 | - 'QST_type' => 'STATE', |
|
1051 | - 'QST_required' => 0, |
|
1052 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1053 | - 'QST_order' => 8, |
|
1054 | - 'QST_admin_only' => 0, |
|
1055 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1056 | - 'QST_deleted' => 0, |
|
1057 | - ); |
|
1058 | - break; |
|
1059 | - case 'zip': |
|
1060 | - $QST_values = array( |
|
1061 | - 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
1062 | - 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
1063 | - 'QST_system' => 'zip', |
|
1064 | - 'QST_type' => 'TEXT', |
|
1065 | - 'QST_required' => 0, |
|
1066 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1067 | - 'QST_order' => 9, |
|
1068 | - 'QST_admin_only' => 0, |
|
1069 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1070 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1071 | - 'QST_deleted' => 0, |
|
1072 | - ); |
|
1073 | - break; |
|
1074 | - case 'phone': |
|
1075 | - $QST_values = array( |
|
1076 | - 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
1077 | - 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
1078 | - 'QST_system' => 'phone', |
|
1079 | - 'QST_type' => 'TEXT', |
|
1080 | - 'QST_required' => 0, |
|
1081 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1082 | - 'QST_order' => 10, |
|
1083 | - 'QST_admin_only' => 0, |
|
1084 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1085 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1086 | - 'QST_deleted' => 0, |
|
1087 | - ); |
|
1088 | - break; |
|
1089 | - } |
|
1090 | - if (! empty($QST_values)) { |
|
1091 | - // insert system question |
|
1092 | - $wpdb->insert( |
|
1093 | - $table_name, |
|
1094 | - $QST_values, |
|
1095 | - array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
1096 | - ); |
|
1097 | - $QST_ID = $wpdb->insert_id; |
|
1098 | - // QUESTION GROUP QUESTIONS |
|
1099 | - if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
1100 | - $system_question_we_want = EEM_Question_Group::system_personal; |
|
1101 | - } else { |
|
1102 | - $system_question_we_want = EEM_Question_Group::system_address; |
|
1103 | - } |
|
1104 | - if (isset($QSG_IDs[$system_question_we_want])) { |
|
1105 | - $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
1106 | - } else { |
|
1107 | - $id_col = EEM_Question_Group::instance() |
|
1108 | - ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
1109 | - if (is_array($id_col)) { |
|
1110 | - $QSG_ID = reset($id_col); |
|
1111 | - } else { |
|
1112 | - //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
1113 | - EE_Log::instance()->log( |
|
1114 | - __FILE__, |
|
1115 | - __FUNCTION__, |
|
1116 | - sprintf( |
|
1117 | - __( |
|
1118 | - 'Could not associate question %1$s to a question group because no system question |
|
835 | + 'event_espresso' |
|
836 | + ), |
|
837 | + __FILE__, |
|
838 | + __FUNCTION__, |
|
839 | + __LINE__ |
|
840 | + ); |
|
841 | + return false; |
|
842 | + } |
|
843 | + return true; |
|
844 | + } |
|
845 | + |
|
846 | + |
|
847 | + |
|
848 | + /** |
|
849 | + * initialize_system_questions |
|
850 | + * |
|
851 | + * @access public |
|
852 | + * @static |
|
853 | + * @return void |
|
854 | + */ |
|
855 | + public static function initialize_system_questions() |
|
856 | + { |
|
857 | + // QUESTION GROUPS |
|
858 | + global $wpdb; |
|
859 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
860 | + $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
861 | + // what we have |
|
862 | + $question_groups = $wpdb->get_col($SQL); |
|
863 | + // check the response |
|
864 | + $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
865 | + // what we should have |
|
866 | + $QSG_systems = array(1, 2); |
|
867 | + // loop thru what we should have and compare to what we have |
|
868 | + foreach ($QSG_systems as $QSG_system) { |
|
869 | + // reset values array |
|
870 | + $QSG_values = array(); |
|
871 | + // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
872 | + if (! in_array("$QSG_system", $question_groups)) { |
|
873 | + // add it |
|
874 | + switch ($QSG_system) { |
|
875 | + case 1: |
|
876 | + $QSG_values = array( |
|
877 | + 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
878 | + 'QSG_identifier' => 'personal-information-' . time(), |
|
879 | + 'QSG_desc' => '', |
|
880 | + 'QSG_order' => 1, |
|
881 | + 'QSG_show_group_name' => 1, |
|
882 | + 'QSG_show_group_desc' => 1, |
|
883 | + 'QSG_system' => EEM_Question_Group::system_personal, |
|
884 | + 'QSG_deleted' => 0, |
|
885 | + ); |
|
886 | + break; |
|
887 | + case 2: |
|
888 | + $QSG_values = array( |
|
889 | + 'QSG_name' => __('Address Information', 'event_espresso'), |
|
890 | + 'QSG_identifier' => 'address-information-' . time(), |
|
891 | + 'QSG_desc' => '', |
|
892 | + 'QSG_order' => 2, |
|
893 | + 'QSG_show_group_name' => 1, |
|
894 | + 'QSG_show_group_desc' => 1, |
|
895 | + 'QSG_system' => EEM_Question_Group::system_address, |
|
896 | + 'QSG_deleted' => 0, |
|
897 | + ); |
|
898 | + break; |
|
899 | + } |
|
900 | + // make sure we have some values before inserting them |
|
901 | + if (! empty($QSG_values)) { |
|
902 | + // insert system question |
|
903 | + $wpdb->insert( |
|
904 | + $table_name, |
|
905 | + $QSG_values, |
|
906 | + array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
907 | + ); |
|
908 | + $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
909 | + } |
|
910 | + } |
|
911 | + } |
|
912 | + // QUESTIONS |
|
913 | + global $wpdb; |
|
914 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
915 | + $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
916 | + // what we have |
|
917 | + $questions = $wpdb->get_col($SQL); |
|
918 | + // what we should have |
|
919 | + $QST_systems = array( |
|
920 | + 'fname', |
|
921 | + 'lname', |
|
922 | + 'email', |
|
923 | + 'address', |
|
924 | + 'address2', |
|
925 | + 'city', |
|
926 | + 'country', |
|
927 | + 'state', |
|
928 | + 'zip', |
|
929 | + 'phone', |
|
930 | + ); |
|
931 | + $order_for_group_1 = 1; |
|
932 | + $order_for_group_2 = 1; |
|
933 | + // loop thru what we should have and compare to what we have |
|
934 | + foreach ($QST_systems as $QST_system) { |
|
935 | + // reset values array |
|
936 | + $QST_values = array(); |
|
937 | + // if we don't have what we should have |
|
938 | + if (! in_array($QST_system, $questions)) { |
|
939 | + // add it |
|
940 | + switch ($QST_system) { |
|
941 | + case 'fname': |
|
942 | + $QST_values = array( |
|
943 | + 'QST_display_text' => __('First Name', 'event_espresso'), |
|
944 | + 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
945 | + 'QST_system' => 'fname', |
|
946 | + 'QST_type' => 'TEXT', |
|
947 | + 'QST_required' => 1, |
|
948 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
949 | + 'QST_order' => 1, |
|
950 | + 'QST_admin_only' => 0, |
|
951 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
952 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
953 | + 'QST_deleted' => 0, |
|
954 | + ); |
|
955 | + break; |
|
956 | + case 'lname': |
|
957 | + $QST_values = array( |
|
958 | + 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
959 | + 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
960 | + 'QST_system' => 'lname', |
|
961 | + 'QST_type' => 'TEXT', |
|
962 | + 'QST_required' => 1, |
|
963 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
964 | + 'QST_order' => 2, |
|
965 | + 'QST_admin_only' => 0, |
|
966 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
967 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
968 | + 'QST_deleted' => 0, |
|
969 | + ); |
|
970 | + break; |
|
971 | + case 'email': |
|
972 | + $QST_values = array( |
|
973 | + 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
974 | + 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
975 | + 'QST_system' => 'email', |
|
976 | + 'QST_type' => 'EMAIL', |
|
977 | + 'QST_required' => 1, |
|
978 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
979 | + 'QST_order' => 3, |
|
980 | + 'QST_admin_only' => 0, |
|
981 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
982 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
983 | + 'QST_deleted' => 0, |
|
984 | + ); |
|
985 | + break; |
|
986 | + case 'address': |
|
987 | + $QST_values = array( |
|
988 | + 'QST_display_text' => __('Address', 'event_espresso'), |
|
989 | + 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
990 | + 'QST_system' => 'address', |
|
991 | + 'QST_type' => 'TEXT', |
|
992 | + 'QST_required' => 0, |
|
993 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
994 | + 'QST_order' => 4, |
|
995 | + 'QST_admin_only' => 0, |
|
996 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
997 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
998 | + 'QST_deleted' => 0, |
|
999 | + ); |
|
1000 | + break; |
|
1001 | + case 'address2': |
|
1002 | + $QST_values = array( |
|
1003 | + 'QST_display_text' => __('Address2', 'event_espresso'), |
|
1004 | + 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
1005 | + 'QST_system' => 'address2', |
|
1006 | + 'QST_type' => 'TEXT', |
|
1007 | + 'QST_required' => 0, |
|
1008 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1009 | + 'QST_order' => 5, |
|
1010 | + 'QST_admin_only' => 0, |
|
1011 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1012 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1013 | + 'QST_deleted' => 0, |
|
1014 | + ); |
|
1015 | + break; |
|
1016 | + case 'city': |
|
1017 | + $QST_values = array( |
|
1018 | + 'QST_display_text' => __('City', 'event_espresso'), |
|
1019 | + 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
1020 | + 'QST_system' => 'city', |
|
1021 | + 'QST_type' => 'TEXT', |
|
1022 | + 'QST_required' => 0, |
|
1023 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1024 | + 'QST_order' => 6, |
|
1025 | + 'QST_admin_only' => 0, |
|
1026 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1027 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1028 | + 'QST_deleted' => 0, |
|
1029 | + ); |
|
1030 | + break; |
|
1031 | + case 'country': |
|
1032 | + $QST_values = array( |
|
1033 | + 'QST_display_text' => __('Country', 'event_espresso'), |
|
1034 | + 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
1035 | + 'QST_system' => 'country', |
|
1036 | + 'QST_type' => 'COUNTRY', |
|
1037 | + 'QST_required' => 0, |
|
1038 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1039 | + 'QST_order' => 7, |
|
1040 | + 'QST_admin_only' => 0, |
|
1041 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1042 | + 'QST_deleted' => 0, |
|
1043 | + ); |
|
1044 | + break; |
|
1045 | + case 'state': |
|
1046 | + $QST_values = array( |
|
1047 | + 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
1048 | + 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
1049 | + 'QST_system' => 'state', |
|
1050 | + 'QST_type' => 'STATE', |
|
1051 | + 'QST_required' => 0, |
|
1052 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1053 | + 'QST_order' => 8, |
|
1054 | + 'QST_admin_only' => 0, |
|
1055 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1056 | + 'QST_deleted' => 0, |
|
1057 | + ); |
|
1058 | + break; |
|
1059 | + case 'zip': |
|
1060 | + $QST_values = array( |
|
1061 | + 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
1062 | + 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
1063 | + 'QST_system' => 'zip', |
|
1064 | + 'QST_type' => 'TEXT', |
|
1065 | + 'QST_required' => 0, |
|
1066 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1067 | + 'QST_order' => 9, |
|
1068 | + 'QST_admin_only' => 0, |
|
1069 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1070 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1071 | + 'QST_deleted' => 0, |
|
1072 | + ); |
|
1073 | + break; |
|
1074 | + case 'phone': |
|
1075 | + $QST_values = array( |
|
1076 | + 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
1077 | + 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
1078 | + 'QST_system' => 'phone', |
|
1079 | + 'QST_type' => 'TEXT', |
|
1080 | + 'QST_required' => 0, |
|
1081 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1082 | + 'QST_order' => 10, |
|
1083 | + 'QST_admin_only' => 0, |
|
1084 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1085 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1086 | + 'QST_deleted' => 0, |
|
1087 | + ); |
|
1088 | + break; |
|
1089 | + } |
|
1090 | + if (! empty($QST_values)) { |
|
1091 | + // insert system question |
|
1092 | + $wpdb->insert( |
|
1093 | + $table_name, |
|
1094 | + $QST_values, |
|
1095 | + array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
1096 | + ); |
|
1097 | + $QST_ID = $wpdb->insert_id; |
|
1098 | + // QUESTION GROUP QUESTIONS |
|
1099 | + if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
1100 | + $system_question_we_want = EEM_Question_Group::system_personal; |
|
1101 | + } else { |
|
1102 | + $system_question_we_want = EEM_Question_Group::system_address; |
|
1103 | + } |
|
1104 | + if (isset($QSG_IDs[$system_question_we_want])) { |
|
1105 | + $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
1106 | + } else { |
|
1107 | + $id_col = EEM_Question_Group::instance() |
|
1108 | + ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
1109 | + if (is_array($id_col)) { |
|
1110 | + $QSG_ID = reset($id_col); |
|
1111 | + } else { |
|
1112 | + //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
1113 | + EE_Log::instance()->log( |
|
1114 | + __FILE__, |
|
1115 | + __FUNCTION__, |
|
1116 | + sprintf( |
|
1117 | + __( |
|
1118 | + 'Could not associate question %1$s to a question group because no system question |
|
1119 | 1119 | group existed', |
1120 | - 'event_espresso' |
|
1121 | - ), |
|
1122 | - $QST_ID), |
|
1123 | - 'error'); |
|
1124 | - continue; |
|
1125 | - } |
|
1126 | - } |
|
1127 | - // add system questions to groups |
|
1128 | - $wpdb->insert( |
|
1129 | - \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
1130 | - array( |
|
1131 | - 'QSG_ID' => $QSG_ID, |
|
1132 | - 'QST_ID' => $QST_ID, |
|
1133 | - 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
1134 | - ), |
|
1135 | - array('%d', '%d', '%d') |
|
1136 | - ); |
|
1137 | - } |
|
1138 | - } |
|
1139 | - } |
|
1140 | - } |
|
1141 | - |
|
1142 | - |
|
1143 | - /** |
|
1144 | - * Makes sure the default payment method (Invoice) is active. |
|
1145 | - * This used to be done automatically as part of constructing the old gateways config |
|
1146 | - * |
|
1147 | - * @throws \EE_Error |
|
1148 | - */ |
|
1149 | - public static function insert_default_payment_methods() |
|
1150 | - { |
|
1151 | - if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1152 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
1153 | - EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
1154 | - } else { |
|
1155 | - EEM_Payment_Method::instance()->verify_button_urls(); |
|
1156 | - } |
|
1157 | - } |
|
1158 | - |
|
1159 | - /** |
|
1160 | - * insert_default_status_codes |
|
1161 | - * |
|
1162 | - * @access public |
|
1163 | - * @static |
|
1164 | - * @return void |
|
1165 | - */ |
|
1166 | - public static function insert_default_status_codes() |
|
1167 | - { |
|
1168 | - |
|
1169 | - global $wpdb; |
|
1170 | - |
|
1171 | - if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
1172 | - |
|
1173 | - $table_name = EEM_Status::instance()->table(); |
|
1174 | - |
|
1175 | - $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
1176 | - $wpdb->query($SQL); |
|
1177 | - |
|
1178 | - $SQL = "INSERT INTO $table_name |
|
1120 | + 'event_espresso' |
|
1121 | + ), |
|
1122 | + $QST_ID), |
|
1123 | + 'error'); |
|
1124 | + continue; |
|
1125 | + } |
|
1126 | + } |
|
1127 | + // add system questions to groups |
|
1128 | + $wpdb->insert( |
|
1129 | + \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
1130 | + array( |
|
1131 | + 'QSG_ID' => $QSG_ID, |
|
1132 | + 'QST_ID' => $QST_ID, |
|
1133 | + 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
1134 | + ), |
|
1135 | + array('%d', '%d', '%d') |
|
1136 | + ); |
|
1137 | + } |
|
1138 | + } |
|
1139 | + } |
|
1140 | + } |
|
1141 | + |
|
1142 | + |
|
1143 | + /** |
|
1144 | + * Makes sure the default payment method (Invoice) is active. |
|
1145 | + * This used to be done automatically as part of constructing the old gateways config |
|
1146 | + * |
|
1147 | + * @throws \EE_Error |
|
1148 | + */ |
|
1149 | + public static function insert_default_payment_methods() |
|
1150 | + { |
|
1151 | + if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1152 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
1153 | + EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
1154 | + } else { |
|
1155 | + EEM_Payment_Method::instance()->verify_button_urls(); |
|
1156 | + } |
|
1157 | + } |
|
1158 | + |
|
1159 | + /** |
|
1160 | + * insert_default_status_codes |
|
1161 | + * |
|
1162 | + * @access public |
|
1163 | + * @static |
|
1164 | + * @return void |
|
1165 | + */ |
|
1166 | + public static function insert_default_status_codes() |
|
1167 | + { |
|
1168 | + |
|
1169 | + global $wpdb; |
|
1170 | + |
|
1171 | + if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
1172 | + |
|
1173 | + $table_name = EEM_Status::instance()->table(); |
|
1174 | + |
|
1175 | + $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
1176 | + $wpdb->query($SQL); |
|
1177 | + |
|
1178 | + $SQL = "INSERT INTO $table_name |
|
1179 | 1179 | (STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES |
1180 | 1180 | ('ACT', 'ACTIVE', 'event', 0, NULL, 1), |
1181 | 1181 | ('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0), |
@@ -1215,521 +1215,521 @@ discard block |
||
1215 | 1215 | ('MID', 'IDLE', 'message', 0, NULL, 1), |
1216 | 1216 | ('MRS', 'RESEND', 'message', 0, NULL, 1), |
1217 | 1217 | ('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);"; |
1218 | - $wpdb->query($SQL); |
|
1219 | - |
|
1220 | - } |
|
1221 | - |
|
1222 | - } |
|
1223 | - |
|
1224 | - |
|
1225 | - /** |
|
1226 | - * create_upload_directories |
|
1227 | - * Creates folders in the uploads directory to facilitate addons and templates |
|
1228 | - * |
|
1229 | - * @access public |
|
1230 | - * @static |
|
1231 | - * @return boolean success of verifying upload directories exist |
|
1232 | - */ |
|
1233 | - public static function create_upload_directories() |
|
1234 | - { |
|
1235 | - // Create the required folders |
|
1236 | - $folders = array( |
|
1237 | - EVENT_ESPRESSO_TEMPLATE_DIR, |
|
1238 | - EVENT_ESPRESSO_GATEWAY_DIR, |
|
1239 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
1240 | - EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
1241 | - EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
1242 | - ); |
|
1243 | - foreach ($folders as $folder) { |
|
1244 | - try { |
|
1245 | - EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
1246 | - @ chmod($folder, 0755); |
|
1247 | - } catch (EE_Error $e) { |
|
1248 | - EE_Error::add_error( |
|
1249 | - sprintf( |
|
1250 | - __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
|
1251 | - $folder, |
|
1252 | - '<br />' . $e->getMessage() |
|
1253 | - ), |
|
1254 | - __FILE__, __FUNCTION__, __LINE__ |
|
1255 | - ); |
|
1256 | - //indicate we'll need to fix this later |
|
1257 | - update_option(EEH_Activation::upload_directories_incomplete_option_name, true); |
|
1258 | - return false; |
|
1259 | - } |
|
1260 | - } |
|
1261 | - //just add the .htaccess file to the logs directory to begin with. Even if logging |
|
1262 | - //is disabled, there might be activation errors recorded in there |
|
1263 | - EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
1264 | - //remember EE's folders are all good |
|
1265 | - delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
|
1266 | - return true; |
|
1267 | - } |
|
1268 | - |
|
1269 | - /** |
|
1270 | - * Whether the upload directories need to be fixed or not. |
|
1271 | - * If EE is installed but filesystem access isn't initially available, |
|
1272 | - * we need to get the user's filesystem credentials and THEN create them, |
|
1273 | - * so there might be period of time when EE is installed but its |
|
1274 | - * upload directories aren't available. This indicates such a state |
|
1275 | - * |
|
1276 | - * @return boolean |
|
1277 | - */ |
|
1278 | - public static function upload_directories_incomplete() |
|
1279 | - { |
|
1280 | - return get_option(EEH_Activation::upload_directories_incomplete_option_name, false); |
|
1281 | - } |
|
1282 | - |
|
1283 | - |
|
1284 | - /** |
|
1285 | - * generate_default_message_templates |
|
1286 | - * |
|
1287 | - * @static |
|
1288 | - * @throws EE_Error |
|
1289 | - * @return bool true means new templates were created. |
|
1290 | - * false means no templates were created. |
|
1291 | - * This is NOT an error flag. To check for errors you will want |
|
1292 | - * to use either EE_Error or a try catch for an EE_Error exception. |
|
1293 | - */ |
|
1294 | - public static function generate_default_message_templates() |
|
1295 | - { |
|
1296 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1297 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1298 | - /* |
|
1218 | + $wpdb->query($SQL); |
|
1219 | + |
|
1220 | + } |
|
1221 | + |
|
1222 | + } |
|
1223 | + |
|
1224 | + |
|
1225 | + /** |
|
1226 | + * create_upload_directories |
|
1227 | + * Creates folders in the uploads directory to facilitate addons and templates |
|
1228 | + * |
|
1229 | + * @access public |
|
1230 | + * @static |
|
1231 | + * @return boolean success of verifying upload directories exist |
|
1232 | + */ |
|
1233 | + public static function create_upload_directories() |
|
1234 | + { |
|
1235 | + // Create the required folders |
|
1236 | + $folders = array( |
|
1237 | + EVENT_ESPRESSO_TEMPLATE_DIR, |
|
1238 | + EVENT_ESPRESSO_GATEWAY_DIR, |
|
1239 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
1240 | + EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
1241 | + EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
1242 | + ); |
|
1243 | + foreach ($folders as $folder) { |
|
1244 | + try { |
|
1245 | + EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
1246 | + @ chmod($folder, 0755); |
|
1247 | + } catch (EE_Error $e) { |
|
1248 | + EE_Error::add_error( |
|
1249 | + sprintf( |
|
1250 | + __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
|
1251 | + $folder, |
|
1252 | + '<br />' . $e->getMessage() |
|
1253 | + ), |
|
1254 | + __FILE__, __FUNCTION__, __LINE__ |
|
1255 | + ); |
|
1256 | + //indicate we'll need to fix this later |
|
1257 | + update_option(EEH_Activation::upload_directories_incomplete_option_name, true); |
|
1258 | + return false; |
|
1259 | + } |
|
1260 | + } |
|
1261 | + //just add the .htaccess file to the logs directory to begin with. Even if logging |
|
1262 | + //is disabled, there might be activation errors recorded in there |
|
1263 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
1264 | + //remember EE's folders are all good |
|
1265 | + delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
|
1266 | + return true; |
|
1267 | + } |
|
1268 | + |
|
1269 | + /** |
|
1270 | + * Whether the upload directories need to be fixed or not. |
|
1271 | + * If EE is installed but filesystem access isn't initially available, |
|
1272 | + * we need to get the user's filesystem credentials and THEN create them, |
|
1273 | + * so there might be period of time when EE is installed but its |
|
1274 | + * upload directories aren't available. This indicates such a state |
|
1275 | + * |
|
1276 | + * @return boolean |
|
1277 | + */ |
|
1278 | + public static function upload_directories_incomplete() |
|
1279 | + { |
|
1280 | + return get_option(EEH_Activation::upload_directories_incomplete_option_name, false); |
|
1281 | + } |
|
1282 | + |
|
1283 | + |
|
1284 | + /** |
|
1285 | + * generate_default_message_templates |
|
1286 | + * |
|
1287 | + * @static |
|
1288 | + * @throws EE_Error |
|
1289 | + * @return bool true means new templates were created. |
|
1290 | + * false means no templates were created. |
|
1291 | + * This is NOT an error flag. To check for errors you will want |
|
1292 | + * to use either EE_Error or a try catch for an EE_Error exception. |
|
1293 | + */ |
|
1294 | + public static function generate_default_message_templates() |
|
1295 | + { |
|
1296 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1297 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1298 | + /* |
|
1299 | 1299 | * This first method is taking care of ensuring any default messengers |
1300 | 1300 | * that should be made active and have templates generated are done. |
1301 | 1301 | */ |
1302 | - $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
1303 | - $message_resource_manager |
|
1304 | - ); |
|
1305 | - /** |
|
1306 | - * This method is verifying there are no NEW default message types |
|
1307 | - * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
1308 | - */ |
|
1309 | - $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1310 | - $message_resource_manager |
|
1311 | - ); |
|
1312 | - //after all is done, let's persist these changes to the db. |
|
1313 | - $message_resource_manager->update_has_activated_messengers_option(); |
|
1314 | - $message_resource_manager->update_active_messengers_option(); |
|
1315 | - // will return true if either of these are true. Otherwise will return false. |
|
1316 | - return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
1317 | - } |
|
1318 | - |
|
1319 | - |
|
1320 | - |
|
1321 | - /** |
|
1322 | - * @param \EE_Message_Resource_Manager $message_resource_manager |
|
1323 | - * @return array|bool |
|
1324 | - * @throws \EE_Error |
|
1325 | - */ |
|
1326 | - protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1327 | - EE_Message_Resource_Manager $message_resource_manager |
|
1328 | - ) { |
|
1329 | - /** @type EE_messenger[] $active_messengers */ |
|
1330 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
1331 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1332 | - $templates_created = false; |
|
1333 | - foreach ($active_messengers as $active_messenger) { |
|
1334 | - $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
1335 | - $default_message_type_names_to_activate = array(); |
|
1336 | - // looping through each default message type reported by the messenger |
|
1337 | - // and setup the actual message types to activate. |
|
1338 | - foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
1339 | - // if already active or has already been activated before we skip |
|
1340 | - // (otherwise we might reactivate something user's intentionally deactivated.) |
|
1341 | - // we also skip if the message type is not installed. |
|
1342 | - if ( |
|
1343 | - $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1344 | - $default_message_type_name_for_messenger, |
|
1345 | - $active_messenger->name |
|
1346 | - ) |
|
1347 | - || $message_resource_manager->is_message_type_active_for_messenger( |
|
1348 | - $active_messenger->name, |
|
1349 | - $default_message_type_name_for_messenger |
|
1350 | - ) |
|
1351 | - || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
1352 | - ) { |
|
1353 | - continue; |
|
1354 | - } |
|
1355 | - $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
1356 | - } |
|
1357 | - //let's activate! |
|
1358 | - $message_resource_manager->ensure_message_types_are_active( |
|
1359 | - $default_message_type_names_to_activate, |
|
1360 | - $active_messenger->name, |
|
1361 | - false |
|
1362 | - ); |
|
1363 | - //activate the templates for these message types |
|
1364 | - if ( ! empty($default_message_type_names_to_activate)) { |
|
1365 | - $templates_created = EEH_MSG_Template::generate_new_templates( |
|
1366 | - $active_messenger->name, |
|
1367 | - $default_message_type_names_for_messenger, |
|
1368 | - '', |
|
1369 | - true |
|
1370 | - ); |
|
1371 | - } |
|
1372 | - } |
|
1373 | - return $templates_created; |
|
1374 | - } |
|
1375 | - |
|
1376 | - |
|
1377 | - |
|
1378 | - /** |
|
1379 | - * This will activate and generate default messengers and default message types for those messengers. |
|
1380 | - * |
|
1381 | - * @param EE_message_Resource_Manager $message_resource_manager |
|
1382 | - * @return array|bool True means there were default messengers and message type templates generated. |
|
1383 | - * False means that there were no templates generated |
|
1384 | - * (which could simply mean there are no default message types for a messenger). |
|
1385 | - * @throws EE_Error |
|
1386 | - */ |
|
1387 | - protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
1388 | - EE_Message_Resource_Manager $message_resource_manager |
|
1389 | - ) { |
|
1390 | - /** @type EE_messenger[] $messengers_to_generate */ |
|
1391 | - $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
1392 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1393 | - $templates_generated = false; |
|
1394 | - foreach ($messengers_to_generate as $messenger_to_generate) { |
|
1395 | - $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
1396 | - //verify the default message types match an installed message type. |
|
1397 | - foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
1398 | - if ( |
|
1399 | - ! isset($installed_message_types[$name]) |
|
1400 | - || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1401 | - $name, |
|
1402 | - $messenger_to_generate->name |
|
1403 | - ) |
|
1404 | - ) { |
|
1405 | - unset($default_message_type_names_for_messenger[$key]); |
|
1406 | - } |
|
1407 | - } |
|
1408 | - // in previous iterations, the active_messengers option in the db |
|
1409 | - // needed updated before calling create templates. however with the changes this may not be necessary. |
|
1410 | - // This comment is left here just in case we discover that we _do_ need to update before |
|
1411 | - // passing off to create templates (after the refactor is done). |
|
1412 | - // @todo remove this comment when determined not necessary. |
|
1413 | - $message_resource_manager->activate_messenger( |
|
1414 | - $messenger_to_generate->name, |
|
1415 | - $default_message_type_names_for_messenger, |
|
1416 | - false |
|
1417 | - ); |
|
1418 | - //create any templates needing created (or will reactivate templates already generated as necessary). |
|
1419 | - if ( ! empty($default_message_type_names_for_messenger)) { |
|
1420 | - $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
1421 | - $messenger_to_generate->name, |
|
1422 | - $default_message_type_names_for_messenger, |
|
1423 | - '', |
|
1424 | - true |
|
1425 | - ); |
|
1426 | - } |
|
1427 | - } |
|
1428 | - return $templates_generated; |
|
1429 | - } |
|
1430 | - |
|
1431 | - |
|
1432 | - /** |
|
1433 | - * This returns the default messengers to generate templates for on activation of EE. |
|
1434 | - * It considers: |
|
1435 | - * - whether a messenger is already active in the db. |
|
1436 | - * - whether a messenger has been made active at any time in the past. |
|
1437 | - * |
|
1438 | - * @static |
|
1439 | - * @param EE_Message_Resource_Manager $message_resource_manager |
|
1440 | - * @return EE_messenger[] |
|
1441 | - */ |
|
1442 | - protected static function _get_default_messengers_to_generate_on_activation( |
|
1443 | - EE_Message_Resource_Manager $message_resource_manager |
|
1444 | - ) { |
|
1445 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
1446 | - $installed_messengers = $message_resource_manager->installed_messengers(); |
|
1447 | - $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
1448 | - |
|
1449 | - $messengers_to_generate = array(); |
|
1450 | - foreach ($installed_messengers as $installed_messenger) { |
|
1451 | - //if installed messenger is a messenger that should be activated on install |
|
1452 | - //and is not already active |
|
1453 | - //and has never been activated |
|
1454 | - if ( |
|
1455 | - ! $installed_messenger->activate_on_install |
|
1456 | - || isset($active_messengers[$installed_messenger->name]) |
|
1457 | - || isset($has_activated[$installed_messenger->name]) |
|
1458 | - ) { |
|
1459 | - continue; |
|
1460 | - } |
|
1461 | - $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
1462 | - } |
|
1463 | - return $messengers_to_generate; |
|
1464 | - } |
|
1465 | - |
|
1466 | - |
|
1467 | - /** |
|
1468 | - * This simply validates active message types to ensure they actually match installed |
|
1469 | - * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
1470 | - * rows are set inactive. |
|
1471 | - * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
1472 | - * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
1473 | - * are still handled in here. |
|
1474 | - * |
|
1475 | - * @since 4.3.1 |
|
1476 | - * @return void |
|
1477 | - */ |
|
1478 | - public static function validate_messages_system() |
|
1479 | - { |
|
1480 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1481 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1482 | - $message_resource_manager->validate_active_message_types_are_installed(); |
|
1483 | - do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
1484 | - } |
|
1485 | - |
|
1486 | - |
|
1487 | - /** |
|
1488 | - * create_no_ticket_prices_array |
|
1489 | - * |
|
1490 | - * @access public |
|
1491 | - * @static |
|
1492 | - * @return void |
|
1493 | - */ |
|
1494 | - public static function create_no_ticket_prices_array() |
|
1495 | - { |
|
1496 | - // this creates an array for tracking events that have no active ticket prices created |
|
1497 | - // this allows us to warn admins of the situation so that it can be corrected |
|
1498 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
1499 | - if (! $espresso_no_ticket_prices) { |
|
1500 | - add_option('ee_no_ticket_prices', array(), '', false); |
|
1501 | - } |
|
1502 | - } |
|
1503 | - |
|
1504 | - |
|
1505 | - /** |
|
1506 | - * plugin_deactivation |
|
1507 | - * |
|
1508 | - * @access public |
|
1509 | - * @static |
|
1510 | - * @return void |
|
1511 | - */ |
|
1512 | - public static function plugin_deactivation() |
|
1513 | - { |
|
1514 | - } |
|
1515 | - |
|
1516 | - |
|
1517 | - /** |
|
1518 | - * Finds all our EE4 custom post types, and deletes them and their associated data |
|
1519 | - * (like post meta or term relations) |
|
1520 | - * |
|
1521 | - * @global wpdb $wpdb |
|
1522 | - * @throws \EE_Error |
|
1523 | - */ |
|
1524 | - public static function delete_all_espresso_cpt_data() |
|
1525 | - { |
|
1526 | - global $wpdb; |
|
1527 | - //get all the CPT post_types |
|
1528 | - $ee_post_types = array(); |
|
1529 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1530 | - if (method_exists($model_name, 'instance')) { |
|
1531 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
1532 | - if ($model_obj instanceof EEM_CPT_Base) { |
|
1533 | - $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
1534 | - } |
|
1535 | - } |
|
1536 | - } |
|
1537 | - //get all our CPTs |
|
1538 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
1539 | - $cpt_ids = $wpdb->get_col($query); |
|
1540 | - //delete each post meta and term relations too |
|
1541 | - foreach ($cpt_ids as $post_id) { |
|
1542 | - wp_delete_post($post_id, true); |
|
1543 | - } |
|
1544 | - } |
|
1545 | - |
|
1546 | - /** |
|
1547 | - * Deletes all EE custom tables |
|
1548 | - * |
|
1549 | - * @return array |
|
1550 | - */ |
|
1551 | - public static function drop_espresso_tables() |
|
1552 | - { |
|
1553 | - $tables = array(); |
|
1554 | - // load registry |
|
1555 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1556 | - if (method_exists($model_name, 'instance')) { |
|
1557 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
1558 | - if ($model_obj instanceof EEM_Base) { |
|
1559 | - foreach ($model_obj->get_tables() as $table) { |
|
1560 | - if (strpos($table->get_table_name(), 'esp_') |
|
1561 | - && |
|
1562 | - ( |
|
1563 | - is_main_site()//main site? nuke them all |
|
1564 | - || ! $table->is_global()//not main site,but not global either. nuke it |
|
1565 | - ) |
|
1566 | - ) { |
|
1567 | - $tables[$table->get_table_name()] = $table->get_table_name(); |
|
1568 | - } |
|
1569 | - } |
|
1570 | - } |
|
1571 | - } |
|
1572 | - } |
|
1573 | - |
|
1574 | - //there are some tables whose models were removed. |
|
1575 | - //they should be removed when removing all EE core's data |
|
1576 | - $tables_without_models = array( |
|
1577 | - 'esp_promotion', |
|
1578 | - 'esp_promotion_applied', |
|
1579 | - 'esp_promotion_object', |
|
1580 | - 'esp_promotion_rule', |
|
1581 | - 'esp_rule', |
|
1582 | - ); |
|
1583 | - foreach ($tables_without_models as $table) { |
|
1584 | - $tables[$table] = $table; |
|
1585 | - } |
|
1586 | - return \EEH_Activation::getTableManager()->dropTables($tables); |
|
1587 | - } |
|
1588 | - |
|
1589 | - |
|
1590 | - |
|
1591 | - /** |
|
1592 | - * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
1593 | - * each table name provided has a wpdb prefix attached, and that it exists. |
|
1594 | - * Returns the list actually deleted |
|
1595 | - * |
|
1596 | - * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
1597 | - * @global WPDB $wpdb |
|
1598 | - * @param array $table_names |
|
1599 | - * @return array of table names which we deleted |
|
1600 | - */ |
|
1601 | - public static function drop_tables($table_names) |
|
1602 | - { |
|
1603 | - return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
1604 | - } |
|
1605 | - |
|
1606 | - |
|
1607 | - |
|
1608 | - /** |
|
1609 | - * plugin_uninstall |
|
1610 | - * |
|
1611 | - * @access public |
|
1612 | - * @static |
|
1613 | - * @param bool $remove_all |
|
1614 | - * @return void |
|
1615 | - */ |
|
1616 | - public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
1617 | - { |
|
1618 | - global $wpdb; |
|
1619 | - self::drop_espresso_tables(); |
|
1620 | - $wp_options_to_delete = array( |
|
1621 | - 'ee_no_ticket_prices' => true, |
|
1622 | - 'ee_active_messengers' => true, |
|
1623 | - 'ee_has_activated_messenger' => true, |
|
1624 | - 'ee_flush_rewrite_rules' => true, |
|
1625 | - 'ee_config' => false, |
|
1626 | - 'ee_data_migration_current_db_state' => true, |
|
1627 | - 'ee_data_migration_mapping_' => false, |
|
1628 | - 'ee_data_migration_script_' => false, |
|
1629 | - 'ee_data_migrations' => true, |
|
1630 | - 'ee_dms_map' => false, |
|
1631 | - 'ee_notices' => true, |
|
1632 | - 'lang_file_check_' => false, |
|
1633 | - 'ee_maintenance_mode' => true, |
|
1634 | - 'ee_ueip_optin' => true, |
|
1635 | - 'ee_ueip_has_notified' => true, |
|
1636 | - 'ee_plugin_activation_errors' => true, |
|
1637 | - 'ee_id_mapping_from' => false, |
|
1638 | - 'espresso_persistent_admin_notices' => true, |
|
1639 | - 'ee_encryption_key' => true, |
|
1640 | - 'pue_force_upgrade_' => false, |
|
1641 | - 'pue_json_error_' => false, |
|
1642 | - 'pue_install_key_' => false, |
|
1643 | - 'pue_verification_error_' => false, |
|
1644 | - 'pu_dismissed_upgrade_' => false, |
|
1645 | - 'external_updates-' => false, |
|
1646 | - 'ee_extra_data' => true, |
|
1647 | - 'ee_ssn_' => false, |
|
1648 | - 'ee_rss_' => false, |
|
1649 | - 'ee_rte_n_tx_' => false, |
|
1650 | - 'ee_pers_admin_notices' => true, |
|
1651 | - 'ee_job_parameters_' => false, |
|
1652 | - 'ee_upload_directories_incomplete' => true, |
|
1653 | - 'ee_verified_db_collations' => true, |
|
1654 | - ); |
|
1655 | - if (is_main_site()) { |
|
1656 | - $wp_options_to_delete['ee_network_config'] = true; |
|
1657 | - } |
|
1658 | - $undeleted_options = array(); |
|
1659 | - foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
1660 | - if ($no_wildcard) { |
|
1661 | - if ( ! delete_option($option_name)) { |
|
1662 | - $undeleted_options[] = $option_name; |
|
1663 | - } |
|
1664 | - } else { |
|
1665 | - $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
1666 | - foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
1667 | - if ( ! delete_option($option_name_from_wildcard)) { |
|
1668 | - $undeleted_options[] = $option_name_from_wildcard; |
|
1669 | - } |
|
1670 | - } |
|
1671 | - } |
|
1672 | - } |
|
1673 | - //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
1674 | - remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
1675 | - if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
1676 | - $db_update_sans_ee4 = array(); |
|
1677 | - foreach ($espresso_db_update as $version => $times_activated) { |
|
1678 | - if ((string)$version[0] === '3') {//if its NON EE4 |
|
1679 | - $db_update_sans_ee4[$version] = $times_activated; |
|
1680 | - } |
|
1681 | - } |
|
1682 | - update_option('espresso_db_update', $db_update_sans_ee4); |
|
1683 | - } |
|
1684 | - $errors = ''; |
|
1685 | - if ( ! empty($undeleted_options)) { |
|
1686 | - $errors .= sprintf( |
|
1687 | - __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
1688 | - '<br/>', |
|
1689 | - implode(',<br/>', $undeleted_options) |
|
1690 | - ); |
|
1691 | - } |
|
1692 | - if ( ! empty($errors)) { |
|
1693 | - EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
1694 | - } |
|
1695 | - } |
|
1696 | - |
|
1697 | - /** |
|
1698 | - * Gets the mysql error code from the last used query by wpdb |
|
1699 | - * |
|
1700 | - * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
1701 | - */ |
|
1702 | - public static function last_wpdb_error_code() |
|
1703 | - { |
|
1704 | - global $wpdb; |
|
1705 | - if ($wpdb->use_mysqli) { |
|
1706 | - return mysqli_errno($wpdb->dbh); |
|
1707 | - } else { |
|
1708 | - return mysql_errno($wpdb->dbh); |
|
1709 | - } |
|
1710 | - } |
|
1711 | - |
|
1712 | - /** |
|
1713 | - * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
1714 | - * |
|
1715 | - * @global wpdb $wpdb |
|
1716 | - * @deprecated instead use TableAnalysis::tableExists() |
|
1717 | - * @param string $table_name with or without $wpdb->prefix |
|
1718 | - * @return boolean |
|
1719 | - */ |
|
1720 | - public static function table_exists($table_name) |
|
1721 | - { |
|
1722 | - return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
1723 | - } |
|
1724 | - |
|
1725 | - /** |
|
1726 | - * Resets the cache on EEH_Activation |
|
1727 | - */ |
|
1728 | - public static function reset() |
|
1729 | - { |
|
1730 | - self::$_default_creator_id = null; |
|
1731 | - self::$_initialized_db_content_already_in_this_request = false; |
|
1732 | - } |
|
1302 | + $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
1303 | + $message_resource_manager |
|
1304 | + ); |
|
1305 | + /** |
|
1306 | + * This method is verifying there are no NEW default message types |
|
1307 | + * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
1308 | + */ |
|
1309 | + $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1310 | + $message_resource_manager |
|
1311 | + ); |
|
1312 | + //after all is done, let's persist these changes to the db. |
|
1313 | + $message_resource_manager->update_has_activated_messengers_option(); |
|
1314 | + $message_resource_manager->update_active_messengers_option(); |
|
1315 | + // will return true if either of these are true. Otherwise will return false. |
|
1316 | + return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
1317 | + } |
|
1318 | + |
|
1319 | + |
|
1320 | + |
|
1321 | + /** |
|
1322 | + * @param \EE_Message_Resource_Manager $message_resource_manager |
|
1323 | + * @return array|bool |
|
1324 | + * @throws \EE_Error |
|
1325 | + */ |
|
1326 | + protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1327 | + EE_Message_Resource_Manager $message_resource_manager |
|
1328 | + ) { |
|
1329 | + /** @type EE_messenger[] $active_messengers */ |
|
1330 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
1331 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1332 | + $templates_created = false; |
|
1333 | + foreach ($active_messengers as $active_messenger) { |
|
1334 | + $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
1335 | + $default_message_type_names_to_activate = array(); |
|
1336 | + // looping through each default message type reported by the messenger |
|
1337 | + // and setup the actual message types to activate. |
|
1338 | + foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
1339 | + // if already active or has already been activated before we skip |
|
1340 | + // (otherwise we might reactivate something user's intentionally deactivated.) |
|
1341 | + // we also skip if the message type is not installed. |
|
1342 | + if ( |
|
1343 | + $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1344 | + $default_message_type_name_for_messenger, |
|
1345 | + $active_messenger->name |
|
1346 | + ) |
|
1347 | + || $message_resource_manager->is_message_type_active_for_messenger( |
|
1348 | + $active_messenger->name, |
|
1349 | + $default_message_type_name_for_messenger |
|
1350 | + ) |
|
1351 | + || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
1352 | + ) { |
|
1353 | + continue; |
|
1354 | + } |
|
1355 | + $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
1356 | + } |
|
1357 | + //let's activate! |
|
1358 | + $message_resource_manager->ensure_message_types_are_active( |
|
1359 | + $default_message_type_names_to_activate, |
|
1360 | + $active_messenger->name, |
|
1361 | + false |
|
1362 | + ); |
|
1363 | + //activate the templates for these message types |
|
1364 | + if ( ! empty($default_message_type_names_to_activate)) { |
|
1365 | + $templates_created = EEH_MSG_Template::generate_new_templates( |
|
1366 | + $active_messenger->name, |
|
1367 | + $default_message_type_names_for_messenger, |
|
1368 | + '', |
|
1369 | + true |
|
1370 | + ); |
|
1371 | + } |
|
1372 | + } |
|
1373 | + return $templates_created; |
|
1374 | + } |
|
1375 | + |
|
1376 | + |
|
1377 | + |
|
1378 | + /** |
|
1379 | + * This will activate and generate default messengers and default message types for those messengers. |
|
1380 | + * |
|
1381 | + * @param EE_message_Resource_Manager $message_resource_manager |
|
1382 | + * @return array|bool True means there were default messengers and message type templates generated. |
|
1383 | + * False means that there were no templates generated |
|
1384 | + * (which could simply mean there are no default message types for a messenger). |
|
1385 | + * @throws EE_Error |
|
1386 | + */ |
|
1387 | + protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
1388 | + EE_Message_Resource_Manager $message_resource_manager |
|
1389 | + ) { |
|
1390 | + /** @type EE_messenger[] $messengers_to_generate */ |
|
1391 | + $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
1392 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1393 | + $templates_generated = false; |
|
1394 | + foreach ($messengers_to_generate as $messenger_to_generate) { |
|
1395 | + $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
1396 | + //verify the default message types match an installed message type. |
|
1397 | + foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
1398 | + if ( |
|
1399 | + ! isset($installed_message_types[$name]) |
|
1400 | + || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1401 | + $name, |
|
1402 | + $messenger_to_generate->name |
|
1403 | + ) |
|
1404 | + ) { |
|
1405 | + unset($default_message_type_names_for_messenger[$key]); |
|
1406 | + } |
|
1407 | + } |
|
1408 | + // in previous iterations, the active_messengers option in the db |
|
1409 | + // needed updated before calling create templates. however with the changes this may not be necessary. |
|
1410 | + // This comment is left here just in case we discover that we _do_ need to update before |
|
1411 | + // passing off to create templates (after the refactor is done). |
|
1412 | + // @todo remove this comment when determined not necessary. |
|
1413 | + $message_resource_manager->activate_messenger( |
|
1414 | + $messenger_to_generate->name, |
|
1415 | + $default_message_type_names_for_messenger, |
|
1416 | + false |
|
1417 | + ); |
|
1418 | + //create any templates needing created (or will reactivate templates already generated as necessary). |
|
1419 | + if ( ! empty($default_message_type_names_for_messenger)) { |
|
1420 | + $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
1421 | + $messenger_to_generate->name, |
|
1422 | + $default_message_type_names_for_messenger, |
|
1423 | + '', |
|
1424 | + true |
|
1425 | + ); |
|
1426 | + } |
|
1427 | + } |
|
1428 | + return $templates_generated; |
|
1429 | + } |
|
1430 | + |
|
1431 | + |
|
1432 | + /** |
|
1433 | + * This returns the default messengers to generate templates for on activation of EE. |
|
1434 | + * It considers: |
|
1435 | + * - whether a messenger is already active in the db. |
|
1436 | + * - whether a messenger has been made active at any time in the past. |
|
1437 | + * |
|
1438 | + * @static |
|
1439 | + * @param EE_Message_Resource_Manager $message_resource_manager |
|
1440 | + * @return EE_messenger[] |
|
1441 | + */ |
|
1442 | + protected static function _get_default_messengers_to_generate_on_activation( |
|
1443 | + EE_Message_Resource_Manager $message_resource_manager |
|
1444 | + ) { |
|
1445 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
1446 | + $installed_messengers = $message_resource_manager->installed_messengers(); |
|
1447 | + $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
1448 | + |
|
1449 | + $messengers_to_generate = array(); |
|
1450 | + foreach ($installed_messengers as $installed_messenger) { |
|
1451 | + //if installed messenger is a messenger that should be activated on install |
|
1452 | + //and is not already active |
|
1453 | + //and has never been activated |
|
1454 | + if ( |
|
1455 | + ! $installed_messenger->activate_on_install |
|
1456 | + || isset($active_messengers[$installed_messenger->name]) |
|
1457 | + || isset($has_activated[$installed_messenger->name]) |
|
1458 | + ) { |
|
1459 | + continue; |
|
1460 | + } |
|
1461 | + $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
1462 | + } |
|
1463 | + return $messengers_to_generate; |
|
1464 | + } |
|
1465 | + |
|
1466 | + |
|
1467 | + /** |
|
1468 | + * This simply validates active message types to ensure they actually match installed |
|
1469 | + * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
1470 | + * rows are set inactive. |
|
1471 | + * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
1472 | + * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
1473 | + * are still handled in here. |
|
1474 | + * |
|
1475 | + * @since 4.3.1 |
|
1476 | + * @return void |
|
1477 | + */ |
|
1478 | + public static function validate_messages_system() |
|
1479 | + { |
|
1480 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1481 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1482 | + $message_resource_manager->validate_active_message_types_are_installed(); |
|
1483 | + do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
1484 | + } |
|
1485 | + |
|
1486 | + |
|
1487 | + /** |
|
1488 | + * create_no_ticket_prices_array |
|
1489 | + * |
|
1490 | + * @access public |
|
1491 | + * @static |
|
1492 | + * @return void |
|
1493 | + */ |
|
1494 | + public static function create_no_ticket_prices_array() |
|
1495 | + { |
|
1496 | + // this creates an array for tracking events that have no active ticket prices created |
|
1497 | + // this allows us to warn admins of the situation so that it can be corrected |
|
1498 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
1499 | + if (! $espresso_no_ticket_prices) { |
|
1500 | + add_option('ee_no_ticket_prices', array(), '', false); |
|
1501 | + } |
|
1502 | + } |
|
1503 | + |
|
1504 | + |
|
1505 | + /** |
|
1506 | + * plugin_deactivation |
|
1507 | + * |
|
1508 | + * @access public |
|
1509 | + * @static |
|
1510 | + * @return void |
|
1511 | + */ |
|
1512 | + public static function plugin_deactivation() |
|
1513 | + { |
|
1514 | + } |
|
1515 | + |
|
1516 | + |
|
1517 | + /** |
|
1518 | + * Finds all our EE4 custom post types, and deletes them and their associated data |
|
1519 | + * (like post meta or term relations) |
|
1520 | + * |
|
1521 | + * @global wpdb $wpdb |
|
1522 | + * @throws \EE_Error |
|
1523 | + */ |
|
1524 | + public static function delete_all_espresso_cpt_data() |
|
1525 | + { |
|
1526 | + global $wpdb; |
|
1527 | + //get all the CPT post_types |
|
1528 | + $ee_post_types = array(); |
|
1529 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1530 | + if (method_exists($model_name, 'instance')) { |
|
1531 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
1532 | + if ($model_obj instanceof EEM_CPT_Base) { |
|
1533 | + $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
1534 | + } |
|
1535 | + } |
|
1536 | + } |
|
1537 | + //get all our CPTs |
|
1538 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
1539 | + $cpt_ids = $wpdb->get_col($query); |
|
1540 | + //delete each post meta and term relations too |
|
1541 | + foreach ($cpt_ids as $post_id) { |
|
1542 | + wp_delete_post($post_id, true); |
|
1543 | + } |
|
1544 | + } |
|
1545 | + |
|
1546 | + /** |
|
1547 | + * Deletes all EE custom tables |
|
1548 | + * |
|
1549 | + * @return array |
|
1550 | + */ |
|
1551 | + public static function drop_espresso_tables() |
|
1552 | + { |
|
1553 | + $tables = array(); |
|
1554 | + // load registry |
|
1555 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1556 | + if (method_exists($model_name, 'instance')) { |
|
1557 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
1558 | + if ($model_obj instanceof EEM_Base) { |
|
1559 | + foreach ($model_obj->get_tables() as $table) { |
|
1560 | + if (strpos($table->get_table_name(), 'esp_') |
|
1561 | + && |
|
1562 | + ( |
|
1563 | + is_main_site()//main site? nuke them all |
|
1564 | + || ! $table->is_global()//not main site,but not global either. nuke it |
|
1565 | + ) |
|
1566 | + ) { |
|
1567 | + $tables[$table->get_table_name()] = $table->get_table_name(); |
|
1568 | + } |
|
1569 | + } |
|
1570 | + } |
|
1571 | + } |
|
1572 | + } |
|
1573 | + |
|
1574 | + //there are some tables whose models were removed. |
|
1575 | + //they should be removed when removing all EE core's data |
|
1576 | + $tables_without_models = array( |
|
1577 | + 'esp_promotion', |
|
1578 | + 'esp_promotion_applied', |
|
1579 | + 'esp_promotion_object', |
|
1580 | + 'esp_promotion_rule', |
|
1581 | + 'esp_rule', |
|
1582 | + ); |
|
1583 | + foreach ($tables_without_models as $table) { |
|
1584 | + $tables[$table] = $table; |
|
1585 | + } |
|
1586 | + return \EEH_Activation::getTableManager()->dropTables($tables); |
|
1587 | + } |
|
1588 | + |
|
1589 | + |
|
1590 | + |
|
1591 | + /** |
|
1592 | + * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
1593 | + * each table name provided has a wpdb prefix attached, and that it exists. |
|
1594 | + * Returns the list actually deleted |
|
1595 | + * |
|
1596 | + * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
1597 | + * @global WPDB $wpdb |
|
1598 | + * @param array $table_names |
|
1599 | + * @return array of table names which we deleted |
|
1600 | + */ |
|
1601 | + public static function drop_tables($table_names) |
|
1602 | + { |
|
1603 | + return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
1604 | + } |
|
1605 | + |
|
1606 | + |
|
1607 | + |
|
1608 | + /** |
|
1609 | + * plugin_uninstall |
|
1610 | + * |
|
1611 | + * @access public |
|
1612 | + * @static |
|
1613 | + * @param bool $remove_all |
|
1614 | + * @return void |
|
1615 | + */ |
|
1616 | + public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
1617 | + { |
|
1618 | + global $wpdb; |
|
1619 | + self::drop_espresso_tables(); |
|
1620 | + $wp_options_to_delete = array( |
|
1621 | + 'ee_no_ticket_prices' => true, |
|
1622 | + 'ee_active_messengers' => true, |
|
1623 | + 'ee_has_activated_messenger' => true, |
|
1624 | + 'ee_flush_rewrite_rules' => true, |
|
1625 | + 'ee_config' => false, |
|
1626 | + 'ee_data_migration_current_db_state' => true, |
|
1627 | + 'ee_data_migration_mapping_' => false, |
|
1628 | + 'ee_data_migration_script_' => false, |
|
1629 | + 'ee_data_migrations' => true, |
|
1630 | + 'ee_dms_map' => false, |
|
1631 | + 'ee_notices' => true, |
|
1632 | + 'lang_file_check_' => false, |
|
1633 | + 'ee_maintenance_mode' => true, |
|
1634 | + 'ee_ueip_optin' => true, |
|
1635 | + 'ee_ueip_has_notified' => true, |
|
1636 | + 'ee_plugin_activation_errors' => true, |
|
1637 | + 'ee_id_mapping_from' => false, |
|
1638 | + 'espresso_persistent_admin_notices' => true, |
|
1639 | + 'ee_encryption_key' => true, |
|
1640 | + 'pue_force_upgrade_' => false, |
|
1641 | + 'pue_json_error_' => false, |
|
1642 | + 'pue_install_key_' => false, |
|
1643 | + 'pue_verification_error_' => false, |
|
1644 | + 'pu_dismissed_upgrade_' => false, |
|
1645 | + 'external_updates-' => false, |
|
1646 | + 'ee_extra_data' => true, |
|
1647 | + 'ee_ssn_' => false, |
|
1648 | + 'ee_rss_' => false, |
|
1649 | + 'ee_rte_n_tx_' => false, |
|
1650 | + 'ee_pers_admin_notices' => true, |
|
1651 | + 'ee_job_parameters_' => false, |
|
1652 | + 'ee_upload_directories_incomplete' => true, |
|
1653 | + 'ee_verified_db_collations' => true, |
|
1654 | + ); |
|
1655 | + if (is_main_site()) { |
|
1656 | + $wp_options_to_delete['ee_network_config'] = true; |
|
1657 | + } |
|
1658 | + $undeleted_options = array(); |
|
1659 | + foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
1660 | + if ($no_wildcard) { |
|
1661 | + if ( ! delete_option($option_name)) { |
|
1662 | + $undeleted_options[] = $option_name; |
|
1663 | + } |
|
1664 | + } else { |
|
1665 | + $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
1666 | + foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
1667 | + if ( ! delete_option($option_name_from_wildcard)) { |
|
1668 | + $undeleted_options[] = $option_name_from_wildcard; |
|
1669 | + } |
|
1670 | + } |
|
1671 | + } |
|
1672 | + } |
|
1673 | + //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
1674 | + remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
1675 | + if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
1676 | + $db_update_sans_ee4 = array(); |
|
1677 | + foreach ($espresso_db_update as $version => $times_activated) { |
|
1678 | + if ((string)$version[0] === '3') {//if its NON EE4 |
|
1679 | + $db_update_sans_ee4[$version] = $times_activated; |
|
1680 | + } |
|
1681 | + } |
|
1682 | + update_option('espresso_db_update', $db_update_sans_ee4); |
|
1683 | + } |
|
1684 | + $errors = ''; |
|
1685 | + if ( ! empty($undeleted_options)) { |
|
1686 | + $errors .= sprintf( |
|
1687 | + __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
1688 | + '<br/>', |
|
1689 | + implode(',<br/>', $undeleted_options) |
|
1690 | + ); |
|
1691 | + } |
|
1692 | + if ( ! empty($errors)) { |
|
1693 | + EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
1694 | + } |
|
1695 | + } |
|
1696 | + |
|
1697 | + /** |
|
1698 | + * Gets the mysql error code from the last used query by wpdb |
|
1699 | + * |
|
1700 | + * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
1701 | + */ |
|
1702 | + public static function last_wpdb_error_code() |
|
1703 | + { |
|
1704 | + global $wpdb; |
|
1705 | + if ($wpdb->use_mysqli) { |
|
1706 | + return mysqli_errno($wpdb->dbh); |
|
1707 | + } else { |
|
1708 | + return mysql_errno($wpdb->dbh); |
|
1709 | + } |
|
1710 | + } |
|
1711 | + |
|
1712 | + /** |
|
1713 | + * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
1714 | + * |
|
1715 | + * @global wpdb $wpdb |
|
1716 | + * @deprecated instead use TableAnalysis::tableExists() |
|
1717 | + * @param string $table_name with or without $wpdb->prefix |
|
1718 | + * @return boolean |
|
1719 | + */ |
|
1720 | + public static function table_exists($table_name) |
|
1721 | + { |
|
1722 | + return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
1723 | + } |
|
1724 | + |
|
1725 | + /** |
|
1726 | + * Resets the cache on EEH_Activation |
|
1727 | + */ |
|
1728 | + public static function reset() |
|
1729 | + { |
|
1730 | + self::$_default_creator_id = null; |
|
1731 | + self::$_initialized_db_content_already_in_this_request = false; |
|
1732 | + } |
|
1733 | 1733 | } |
1734 | 1734 | // End of file EEH_Activation.helper.php |
1735 | 1735 | // Location: /helpers/EEH_Activation.core.php |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public static function getTableAnalysis() |
67 | 67 | { |
68 | - if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
68 | + if ( ! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
69 | 69 | self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
70 | 70 | } |
71 | 71 | return self::$table_analysis; |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | */ |
78 | 78 | public static function getTableManager() |
79 | 79 | { |
80 | - if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
80 | + if ( ! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
81 | 81 | self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
82 | 82 | } |
83 | 83 | return self::$table_manager; |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | if ($which_to_include === 'old') { |
194 | 194 | $cron_tasks = array_filter( |
195 | 195 | $cron_tasks, |
196 | - function ($value) { |
|
196 | + function($value) { |
|
197 | 197 | return $value === EEH_Activation::cron_task_no_longer_in_use; |
198 | 198 | } |
199 | 199 | ); |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | { |
224 | 224 | |
225 | 225 | foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
226 | - if (! wp_next_scheduled($hook_name)) { |
|
226 | + if ( ! wp_next_scheduled($hook_name)) { |
|
227 | 227 | /** |
228 | 228 | * This allows client code to define the initial start timestamp for this schedule. |
229 | 229 | */ |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | 3 |
329 | 329 | ); |
330 | 330 | //EE_Config::reset(); |
331 | - if (! EE_Config::logging_enabled()) { |
|
331 | + if ( ! EE_Config::logging_enabled()) { |
|
332 | 332 | delete_option(EE_Config::LOG_NAME); |
333 | 333 | } |
334 | 334 | } |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | public static function load_calendar_config() |
344 | 344 | { |
345 | 345 | // grab array of all plugin folders and loop thru it |
346 | - $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
346 | + $plugins = glob(WP_PLUGIN_DIR.DS.'*', GLOB_ONLYDIR); |
|
347 | 347 | if (empty($plugins)) { |
348 | 348 | return; |
349 | 349 | } |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | || strpos($plugin, 'calendar') !== false |
361 | 361 | ) { |
362 | 362 | // this is what we are looking for |
363 | - $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
363 | + $calendar_config = $plugin_path.DS.'EE_Calendar_Config.php'; |
|
364 | 364 | // does it exist in this folder ? |
365 | 365 | if (is_readable($calendar_config)) { |
366 | 366 | // YEAH! let's load it |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | ) { |
489 | 489 | //update Config with post ID |
490 | 490 | $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
491 | - if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
491 | + if ( ! EE_Config::instance()->update_espresso_config(false, false)) { |
|
492 | 492 | $msg = __( |
493 | 493 | 'The Event Espresso critical page configuration settings could not be updated.', |
494 | 494 | 'event_espresso' |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
512 | 512 | 'event_espresso' |
513 | 513 | ), |
514 | - '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' |
|
514 | + '<a href="'.admin_url('admin.php?page=espresso_general_settings&action=critical_pages').'">' |
|
515 | 515 | . __('Event Espresso Critical Pages Settings', 'event_espresso') |
516 | 516 | . '</a>' |
517 | 517 | ) |
@@ -537,7 +537,7 @@ discard block |
||
537 | 537 | public static function get_page_by_ee_shortcode($ee_shortcode) |
538 | 538 | { |
539 | 539 | global $wpdb; |
540 | - $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
540 | + $shortcode_and_opening_bracket = '['.$ee_shortcode; |
|
541 | 541 | $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
542 | 542 | if ($post_id) { |
543 | 543 | return get_post($post_id); |
@@ -563,11 +563,11 @@ discard block |
||
563 | 563 | 'post_status' => 'publish', |
564 | 564 | 'post_type' => 'page', |
565 | 565 | 'comment_status' => 'closed', |
566 | - 'post_content' => '[' . $critical_page['code'] . ']', |
|
566 | + 'post_content' => '['.$critical_page['code'].']', |
|
567 | 567 | ); |
568 | 568 | |
569 | 569 | $post_id = wp_insert_post($post_args); |
570 | - if (! $post_id) { |
|
570 | + if ( ! $post_id) { |
|
571 | 571 | $msg = sprintf( |
572 | 572 | __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
573 | 573 | $critical_page['name'] |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | return $critical_page; |
577 | 577 | } |
578 | 578 | // get newly created post's details |
579 | - if (! $critical_page['post'] = get_post($post_id)) { |
|
579 | + if ( ! $critical_page['post'] = get_post($post_id)) { |
|
580 | 580 | $msg = sprintf( |
581 | 581 | __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
582 | 582 | $critical_page['name'] |
@@ -613,17 +613,17 @@ discard block |
||
613 | 613 | $role_to_check |
614 | 614 | ); |
615 | 615 | if ($pre_filtered_id !== false) { |
616 | - return (int)$pre_filtered_id; |
|
616 | + return (int) $pre_filtered_id; |
|
617 | 617 | } |
618 | 618 | $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
619 | 619 | $query = $wpdb->prepare( |
620 | 620 | "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
621 | - '%' . $role_to_check . '%' |
|
621 | + '%'.$role_to_check.'%' |
|
622 | 622 | ); |
623 | 623 | $user_id = $wpdb->get_var($query); |
624 | 624 | $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
625 | - if ($user_id && (int)$user_id) { |
|
626 | - self::$_default_creator_id = (int)$user_id; |
|
625 | + if ($user_id && (int) $user_id) { |
|
626 | + self::$_default_creator_id = (int) $user_id; |
|
627 | 627 | return self::$_default_creator_id; |
628 | 628 | } else { |
629 | 629 | return null; |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | } |
659 | 659 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
660 | 660 | if ( ! function_exists('dbDelta')) { |
661 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
661 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
662 | 662 | } |
663 | 663 | $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
664 | 664 | $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
@@ -869,13 +869,13 @@ discard block |
||
869 | 869 | // reset values array |
870 | 870 | $QSG_values = array(); |
871 | 871 | // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
872 | - if (! in_array("$QSG_system", $question_groups)) { |
|
872 | + if ( ! in_array("$QSG_system", $question_groups)) { |
|
873 | 873 | // add it |
874 | 874 | switch ($QSG_system) { |
875 | 875 | case 1: |
876 | 876 | $QSG_values = array( |
877 | 877 | 'QSG_name' => __('Personal Information', 'event_espresso'), |
878 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
878 | + 'QSG_identifier' => 'personal-information-'.time(), |
|
879 | 879 | 'QSG_desc' => '', |
880 | 880 | 'QSG_order' => 1, |
881 | 881 | 'QSG_show_group_name' => 1, |
@@ -887,7 +887,7 @@ discard block |
||
887 | 887 | case 2: |
888 | 888 | $QSG_values = array( |
889 | 889 | 'QSG_name' => __('Address Information', 'event_espresso'), |
890 | - 'QSG_identifier' => 'address-information-' . time(), |
|
890 | + 'QSG_identifier' => 'address-information-'.time(), |
|
891 | 891 | 'QSG_desc' => '', |
892 | 892 | 'QSG_order' => 2, |
893 | 893 | 'QSG_show_group_name' => 1, |
@@ -898,7 +898,7 @@ discard block |
||
898 | 898 | break; |
899 | 899 | } |
900 | 900 | // make sure we have some values before inserting them |
901 | - if (! empty($QSG_values)) { |
|
901 | + if ( ! empty($QSG_values)) { |
|
902 | 902 | // insert system question |
903 | 903 | $wpdb->insert( |
904 | 904 | $table_name, |
@@ -935,7 +935,7 @@ discard block |
||
935 | 935 | // reset values array |
936 | 936 | $QST_values = array(); |
937 | 937 | // if we don't have what we should have |
938 | - if (! in_array($QST_system, $questions)) { |
|
938 | + if ( ! in_array($QST_system, $questions)) { |
|
939 | 939 | // add it |
940 | 940 | switch ($QST_system) { |
941 | 941 | case 'fname': |
@@ -1087,7 +1087,7 @@ discard block |
||
1087 | 1087 | ); |
1088 | 1088 | break; |
1089 | 1089 | } |
1090 | - if (! empty($QST_values)) { |
|
1090 | + if ( ! empty($QST_values)) { |
|
1091 | 1091 | // insert system question |
1092 | 1092 | $wpdb->insert( |
1093 | 1093 | $table_name, |
@@ -1148,7 +1148,7 @@ discard block |
||
1148 | 1148 | */ |
1149 | 1149 | public static function insert_default_payment_methods() |
1150 | 1150 | { |
1151 | - if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1151 | + if ( ! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1152 | 1152 | EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
1153 | 1153 | EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
1154 | 1154 | } else { |
@@ -1236,9 +1236,9 @@ discard block |
||
1236 | 1236 | $folders = array( |
1237 | 1237 | EVENT_ESPRESSO_TEMPLATE_DIR, |
1238 | 1238 | EVENT_ESPRESSO_GATEWAY_DIR, |
1239 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
1240 | - EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
1241 | - EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
1239 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs/', |
|
1240 | + EVENT_ESPRESSO_UPLOAD_DIR.'css/', |
|
1241 | + EVENT_ESPRESSO_UPLOAD_DIR.'tickets/', |
|
1242 | 1242 | ); |
1243 | 1243 | foreach ($folders as $folder) { |
1244 | 1244 | try { |
@@ -1249,7 +1249,7 @@ discard block |
||
1249 | 1249 | sprintf( |
1250 | 1250 | __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
1251 | 1251 | $folder, |
1252 | - '<br />' . $e->getMessage() |
|
1252 | + '<br />'.$e->getMessage() |
|
1253 | 1253 | ), |
1254 | 1254 | __FILE__, __FUNCTION__, __LINE__ |
1255 | 1255 | ); |
@@ -1260,7 +1260,7 @@ discard block |
||
1260 | 1260 | } |
1261 | 1261 | //just add the .htaccess file to the logs directory to begin with. Even if logging |
1262 | 1262 | //is disabled, there might be activation errors recorded in there |
1263 | - EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
1263 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR.'logs/'); |
|
1264 | 1264 | //remember EE's folders are all good |
1265 | 1265 | delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
1266 | 1266 | return true; |
@@ -1496,7 +1496,7 @@ discard block |
||
1496 | 1496 | // this creates an array for tracking events that have no active ticket prices created |
1497 | 1497 | // this allows us to warn admins of the situation so that it can be corrected |
1498 | 1498 | $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
1499 | - if (! $espresso_no_ticket_prices) { |
|
1499 | + if ( ! $espresso_no_ticket_prices) { |
|
1500 | 1500 | add_option('ee_no_ticket_prices', array(), '', false); |
1501 | 1501 | } |
1502 | 1502 | } |
@@ -1535,7 +1535,7 @@ discard block |
||
1535 | 1535 | } |
1536 | 1536 | } |
1537 | 1537 | //get all our CPTs |
1538 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
1538 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",", $ee_post_types).")"; |
|
1539 | 1539 | $cpt_ids = $wpdb->get_col($query); |
1540 | 1540 | //delete each post meta and term relations too |
1541 | 1541 | foreach ($cpt_ids as $post_id) { |
@@ -1675,7 +1675,7 @@ discard block |
||
1675 | 1675 | if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
1676 | 1676 | $db_update_sans_ee4 = array(); |
1677 | 1677 | foreach ($espresso_db_update as $version => $times_activated) { |
1678 | - if ((string)$version[0] === '3') {//if its NON EE4 |
|
1678 | + if ((string) $version[0] === '3') {//if its NON EE4 |
|
1679 | 1679 | $db_update_sans_ee4[$version] = $times_activated; |
1680 | 1680 | } |
1681 | 1681 | } |
@@ -10,10 +10,10 @@ discard block |
||
10 | 10 | * define and use the hook in a specific caffeinated/whatever class or file. |
11 | 11 | */ |
12 | 12 | // defined some new constants related to caffeinated folder |
13 | -define('EE_CAF_URL', EE_PLUGIN_DIR_URL . 'caffeinated/'); |
|
14 | -define('EE_CAF_CORE', EE_CAFF_PATH . 'core' . DS); |
|
15 | -define('EE_CAF_LIBRARIES', EE_CAF_CORE . 'libraries' . DS); |
|
16 | -define('EE_CAF_PAYMENT_METHODS', EE_CAFF_PATH . 'payment_methods' . DS); |
|
13 | +define('EE_CAF_URL', EE_PLUGIN_DIR_URL.'caffeinated/'); |
|
14 | +define('EE_CAF_CORE', EE_CAFF_PATH.'core'.DS); |
|
15 | +define('EE_CAF_LIBRARIES', EE_CAF_CORE.'libraries'.DS); |
|
16 | +define('EE_CAF_PAYMENT_METHODS', EE_CAFF_PATH.'payment_methods'.DS); |
|
17 | 17 | |
18 | 18 | |
19 | 19 | |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | */ |
77 | 77 | public function caf_helper_paths($paths) |
78 | 78 | { |
79 | - $paths[] = EE_CAF_CORE . 'helpers' . DS; |
|
79 | + $paths[] = EE_CAF_CORE.'helpers'.DS; |
|
80 | 80 | return $paths; |
81 | 81 | } |
82 | 82 | |
@@ -98,10 +98,10 @@ discard block |
||
98 | 98 | global $wpdb; |
99 | 99 | //use same method of getting creator id as the version introducing the change |
100 | 100 | $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
101 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
102 | - $price_table = $wpdb->prefix . "esp_price"; |
|
101 | + $price_type_table = $wpdb->prefix."esp_price_type"; |
|
102 | + $price_table = $wpdb->prefix."esp_price"; |
|
103 | 103 | if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
104 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types |
|
104 | + $SQL = 'SELECT COUNT(PRT_ID) FROM '.$price_type_table.' WHERE PBT_ID=4'; //include trashed price types |
|
105 | 105 | $tax_price_type_count = $wpdb->get_var($SQL); |
106 | 106 | if ($tax_price_type_count <= 1) { |
107 | 107 | $wpdb->insert( |
@@ -115,11 +115,11 @@ discard block |
||
115 | 115 | 'PRT_wp_user' => $default_creator_id, |
116 | 116 | ), |
117 | 117 | array( |
118 | - '%s',//PRT_name |
|
119 | - '%d',//PBT_id |
|
120 | - '%d',//PRT_is_percent |
|
121 | - '%d',//PRT_order |
|
122 | - '%d',//PRT_deleted |
|
118 | + '%s', //PRT_name |
|
119 | + '%d', //PBT_id |
|
120 | + '%d', //PRT_is_percent |
|
121 | + '%d', //PRT_order |
|
122 | + '%d', //PRT_deleted |
|
123 | 123 | '%d', //PRT_wp_user |
124 | 124 | ) |
125 | 125 | ); |
@@ -135,11 +135,11 @@ discard block |
||
135 | 135 | 'PRT_wp_user' => $default_creator_id, |
136 | 136 | ), |
137 | 137 | array( |
138 | - '%s',//PRT_name |
|
139 | - '%d',//PBT_id |
|
140 | - '%d',//PRT_is_percent |
|
141 | - '%d',//PRT_order |
|
142 | - '%d',//PRT_deleted |
|
138 | + '%s', //PRT_name |
|
139 | + '%d', //PBT_id |
|
140 | + '%d', //PRT_is_percent |
|
141 | + '%d', //PRT_order |
|
142 | + '%d', //PRT_deleted |
|
143 | 143 | '%d' //PRT_wp_user |
144 | 144 | ) |
145 | 145 | ); |
@@ -159,15 +159,15 @@ discard block |
||
159 | 159 | 'PRC_wp_user' => $default_creator_id, |
160 | 160 | ), |
161 | 161 | array( |
162 | - '%d',//PRT_id |
|
163 | - '%f',//PRC_amount |
|
164 | - '%s',//PRC_name |
|
165 | - '%s',//PRC_desc |
|
166 | - '%d',//PRC_is_default |
|
167 | - '%d',//PRC_overrides |
|
168 | - '%d',//PRC_deleted |
|
169 | - '%d',//PRC_order |
|
170 | - '%d',//PRC_parent |
|
162 | + '%d', //PRT_id |
|
163 | + '%f', //PRC_amount |
|
164 | + '%s', //PRC_name |
|
165 | + '%s', //PRC_desc |
|
166 | + '%d', //PRC_is_default |
|
167 | + '%d', //PRC_overrides |
|
168 | + '%d', //PRC_deleted |
|
169 | + '%d', //PRC_order |
|
170 | + '%d', //PRC_parent |
|
171 | 171 | '%d' //PRC_wp_user |
172 | 172 | ) |
173 | 173 | ); |
@@ -187,8 +187,8 @@ discard block |
||
187 | 187 | */ |
188 | 188 | public function caffeinated_modules_to_register($modules_to_register = array()) |
189 | 189 | { |
190 | - if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
191 | - $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR); |
|
190 | + if (is_readable(EE_CAFF_PATH.'modules')) { |
|
191 | + $caffeinated_modules_to_register = glob(EE_CAFF_PATH.'modules'.DS.'*', GLOB_ONLYDIR); |
|
192 | 192 | if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
193 | 193 | $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
194 | 194 | } |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | */ |
269 | 269 | public function caf_payment_methods($payment_method_paths) |
270 | 270 | { |
271 | - $caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
271 | + $caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS.'*', GLOB_ONLYDIR); |
|
272 | 272 | $payment_method_paths = array_merge($payment_method_paths, $caf_payment_methods_paths); |
273 | 273 | return $payment_method_paths; |
274 | 274 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\services\database\TableAnalysis; |
5 | 5 | |
6 | 6 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
7 | - exit('No direct script access allowed'); |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | /** |
10 | 10 | * the purpose of this file is to simply contain any action/filter hook callbacks etc for specific aspects of EE |
@@ -29,277 +29,277 @@ discard block |
||
29 | 29 | class EE_Brewing_Regular extends EE_BASE implements InterminableInterface |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
34 | - */ |
|
35 | - protected $_table_analysis; |
|
36 | - |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * EE_Brewing_Regular constructor. |
|
41 | - */ |
|
42 | - public function __construct(TableAnalysis $table_analysis) |
|
43 | - { |
|
44 | - $this->_table_analysis = $table_analysis; |
|
45 | - if (defined('EE_CAFF_PATH')) { |
|
46 | - // activation |
|
47 | - add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content')); |
|
48 | - // load caff init |
|
49 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init')); |
|
50 | - // remove the "powered by" credit link from receipts and invoices |
|
51 | - add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false'); |
|
52 | - // add caffeinated modules |
|
53 | - add_filter( |
|
54 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
55 | - array($this, 'caffeinated_modules_to_register') |
|
56 | - ); |
|
57 | - // load caff scripts |
|
58 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10); |
|
59 | - add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10); |
|
60 | - add_filter( |
|
61 | - 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
62 | - array($this, 'caf_payment_methods') |
|
63 | - ); |
|
64 | - // caffeinated constructed |
|
65 | - do_action('AHEE__EE_Brewing_Regular__construct__complete'); |
|
66 | - //seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer |
|
67 | - add_filter('FHEE__ee_show_affiliate_links', '__return_false'); |
|
68 | - } |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths |
|
75 | - * |
|
76 | - * @param array $paths original helper paths array |
|
77 | - * @return array new array of paths |
|
78 | - */ |
|
79 | - public function caf_helper_paths($paths) |
|
80 | - { |
|
81 | - $paths[] = EE_CAF_CORE . 'helpers' . DS; |
|
82 | - return $paths; |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * Upon brand-new activation, if this is a new activation of CAF, we want to add |
|
89 | - * some global prices that will show off EE4's capabilities. However, if they're upgrading |
|
90 | - * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices. |
|
91 | - * This action should only be called when EE 4.x.0.P is initially activated. |
|
92 | - * Right now the only CAF content are these global prices. If there's more in the future, then |
|
93 | - * we should probably create a caf file to contain it all instead just a function like this. |
|
94 | - * Right now, we ASSUME the only price types in the system are default ones |
|
95 | - * |
|
96 | - * @global wpdb $wpdb |
|
97 | - */ |
|
98 | - public function initialize_caf_db_content() |
|
99 | - { |
|
100 | - global $wpdb; |
|
101 | - //use same method of getting creator id as the version introducing the change |
|
102 | - $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
|
103 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
104 | - $price_table = $wpdb->prefix . "esp_price"; |
|
105 | - if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
106 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types |
|
107 | - $tax_price_type_count = $wpdb->get_var($SQL); |
|
108 | - if ($tax_price_type_count <= 1) { |
|
109 | - $wpdb->insert( |
|
110 | - $price_type_table, |
|
111 | - array( |
|
112 | - 'PRT_name' => __("Regional Tax", "event_espresso"), |
|
113 | - 'PBT_ID' => 4, |
|
114 | - 'PRT_is_percent' => true, |
|
115 | - 'PRT_order' => 60, |
|
116 | - 'PRT_deleted' => false, |
|
117 | - 'PRT_wp_user' => $default_creator_id, |
|
118 | - ), |
|
119 | - array( |
|
120 | - '%s',//PRT_name |
|
121 | - '%d',//PBT_id |
|
122 | - '%d',//PRT_is_percent |
|
123 | - '%d',//PRT_order |
|
124 | - '%d',//PRT_deleted |
|
125 | - '%d', //PRT_wp_user |
|
126 | - ) |
|
127 | - ); |
|
128 | - //federal tax |
|
129 | - $result = $wpdb->insert( |
|
130 | - $price_type_table, |
|
131 | - array( |
|
132 | - 'PRT_name' => __("Federal Tax", "event_espresso"), |
|
133 | - 'PBT_ID' => 4, |
|
134 | - 'PRT_is_percent' => true, |
|
135 | - 'PRT_order' => 70, |
|
136 | - 'PRT_deleted' => false, |
|
137 | - 'PRT_wp_user' => $default_creator_id, |
|
138 | - ), |
|
139 | - array( |
|
140 | - '%s',//PRT_name |
|
141 | - '%d',//PBT_id |
|
142 | - '%d',//PRT_is_percent |
|
143 | - '%d',//PRT_order |
|
144 | - '%d',//PRT_deleted |
|
145 | - '%d' //PRT_wp_user |
|
146 | - ) |
|
147 | - ); |
|
148 | - if ($result) { |
|
149 | - $wpdb->insert( |
|
150 | - $price_table, |
|
151 | - array( |
|
152 | - 'PRT_ID' => $wpdb->insert_id, |
|
153 | - 'PRC_amount' => 15.00, |
|
154 | - 'PRC_name' => __("Sales Tax", "event_espresso"), |
|
155 | - 'PRC_desc' => '', |
|
156 | - 'PRC_is_default' => true, |
|
157 | - 'PRC_overrides' => null, |
|
158 | - 'PRC_deleted' => false, |
|
159 | - 'PRC_order' => 50, |
|
160 | - 'PRC_parent' => null, |
|
161 | - 'PRC_wp_user' => $default_creator_id, |
|
162 | - ), |
|
163 | - array( |
|
164 | - '%d',//PRT_id |
|
165 | - '%f',//PRC_amount |
|
166 | - '%s',//PRC_name |
|
167 | - '%s',//PRC_desc |
|
168 | - '%d',//PRC_is_default |
|
169 | - '%d',//PRC_overrides |
|
170 | - '%d',//PRC_deleted |
|
171 | - '%d',//PRC_order |
|
172 | - '%d',//PRC_parent |
|
173 | - '%d' //PRC_wp_user |
|
174 | - ) |
|
175 | - ); |
|
176 | - } |
|
177 | - } |
|
178 | - } |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * caffeinated_modules_to_register |
|
185 | - * |
|
186 | - * @access public |
|
187 | - * @param array $modules_to_register |
|
188 | - * @return array |
|
189 | - */ |
|
190 | - public function caffeinated_modules_to_register($modules_to_register = array()) |
|
191 | - { |
|
192 | - if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
193 | - $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR); |
|
194 | - if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
|
195 | - $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
|
196 | - } |
|
197 | - } |
|
198 | - return $modules_to_register; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - |
|
203 | - public function caffeinated_init() |
|
204 | - { |
|
205 | - // EE_Register_CPTs hooks |
|
206 | - add_filter('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array($this, 'filter_taxonomies'), 10); |
|
207 | - add_filter('FHEE__EE_Register_CPTs__get_CPTs__cpts', array($this, 'filter_cpts'), 10); |
|
208 | - add_filter('FHEE__EE_Admin__get_extra_nav_menu_pages_items', array($this, 'nav_metabox_items'), 10); |
|
209 | - EE_Registry::instance()->load_file(EE_CAFF_PATH, 'EE_Caf_Messages', 'class', array(), false); |
|
210 | - // caffeinated_init__complete hook |
|
211 | - do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete'); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - |
|
216 | - public function enqueue_caffeinated_scripts() |
|
217 | - { |
|
218 | - // sound of crickets... |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - |
|
223 | - /** |
|
224 | - * callbacks below here |
|
225 | - * |
|
226 | - * @param array $taxonomy_array |
|
227 | - * @return array |
|
228 | - */ |
|
229 | - public function filter_taxonomies(array $taxonomy_array) |
|
230 | - { |
|
231 | - $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true; |
|
232 | - return $taxonomy_array; |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * @param array $cpt_array |
|
239 | - * @return mixed |
|
240 | - */ |
|
241 | - public function filter_cpts(array $cpt_array) |
|
242 | - { |
|
243 | - $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true; |
|
244 | - return $cpt_array; |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * @param array $menuitems |
|
251 | - * @return array |
|
252 | - */ |
|
253 | - public function nav_metabox_items(array $menuitems) |
|
254 | - { |
|
255 | - $menuitems[] = array( |
|
256 | - 'title' => __('Venue List', 'event_espresso'), |
|
257 | - 'url' => get_post_type_archive_link('espresso_venues'), |
|
258 | - 'description' => __('Archive page for all venues.', 'event_espresso'), |
|
259 | - ); |
|
260 | - return $menuitems; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * Adds the payment methods in {event-espresso-core}/caffeinated/payment_methods |
|
267 | - * |
|
268 | - * @param array $payment_method_paths |
|
269 | - * @return array values are folder paths to payment method folders |
|
270 | - */ |
|
271 | - public function caf_payment_methods($payment_method_paths) |
|
272 | - { |
|
273 | - $caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
274 | - $payment_method_paths = array_merge($payment_method_paths, $caf_payment_methods_paths); |
|
275 | - return $payment_method_paths; |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * Gets the injected table analyzer, or throws an exception |
|
282 | - * |
|
283 | - * @return TableAnalysis |
|
284 | - * @throws \EE_Error |
|
285 | - */ |
|
286 | - protected function _get_table_analysis() |
|
287 | - { |
|
288 | - if ($this->_table_analysis instanceof TableAnalysis) { |
|
289 | - return $this->_table_analysis; |
|
290 | - } else { |
|
291 | - throw new \EE_Error( |
|
292 | - sprintf( |
|
293 | - __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
294 | - get_class($this) |
|
295 | - ) |
|
296 | - ); |
|
297 | - } |
|
298 | - } |
|
32 | + /** |
|
33 | + * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
34 | + */ |
|
35 | + protected $_table_analysis; |
|
36 | + |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * EE_Brewing_Regular constructor. |
|
41 | + */ |
|
42 | + public function __construct(TableAnalysis $table_analysis) |
|
43 | + { |
|
44 | + $this->_table_analysis = $table_analysis; |
|
45 | + if (defined('EE_CAFF_PATH')) { |
|
46 | + // activation |
|
47 | + add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content')); |
|
48 | + // load caff init |
|
49 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init')); |
|
50 | + // remove the "powered by" credit link from receipts and invoices |
|
51 | + add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false'); |
|
52 | + // add caffeinated modules |
|
53 | + add_filter( |
|
54 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
55 | + array($this, 'caffeinated_modules_to_register') |
|
56 | + ); |
|
57 | + // load caff scripts |
|
58 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10); |
|
59 | + add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10); |
|
60 | + add_filter( |
|
61 | + 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
62 | + array($this, 'caf_payment_methods') |
|
63 | + ); |
|
64 | + // caffeinated constructed |
|
65 | + do_action('AHEE__EE_Brewing_Regular__construct__complete'); |
|
66 | + //seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer |
|
67 | + add_filter('FHEE__ee_show_affiliate_links', '__return_false'); |
|
68 | + } |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths |
|
75 | + * |
|
76 | + * @param array $paths original helper paths array |
|
77 | + * @return array new array of paths |
|
78 | + */ |
|
79 | + public function caf_helper_paths($paths) |
|
80 | + { |
|
81 | + $paths[] = EE_CAF_CORE . 'helpers' . DS; |
|
82 | + return $paths; |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * Upon brand-new activation, if this is a new activation of CAF, we want to add |
|
89 | + * some global prices that will show off EE4's capabilities. However, if they're upgrading |
|
90 | + * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices. |
|
91 | + * This action should only be called when EE 4.x.0.P is initially activated. |
|
92 | + * Right now the only CAF content are these global prices. If there's more in the future, then |
|
93 | + * we should probably create a caf file to contain it all instead just a function like this. |
|
94 | + * Right now, we ASSUME the only price types in the system are default ones |
|
95 | + * |
|
96 | + * @global wpdb $wpdb |
|
97 | + */ |
|
98 | + public function initialize_caf_db_content() |
|
99 | + { |
|
100 | + global $wpdb; |
|
101 | + //use same method of getting creator id as the version introducing the change |
|
102 | + $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
|
103 | + $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
104 | + $price_table = $wpdb->prefix . "esp_price"; |
|
105 | + if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
106 | + $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types |
|
107 | + $tax_price_type_count = $wpdb->get_var($SQL); |
|
108 | + if ($tax_price_type_count <= 1) { |
|
109 | + $wpdb->insert( |
|
110 | + $price_type_table, |
|
111 | + array( |
|
112 | + 'PRT_name' => __("Regional Tax", "event_espresso"), |
|
113 | + 'PBT_ID' => 4, |
|
114 | + 'PRT_is_percent' => true, |
|
115 | + 'PRT_order' => 60, |
|
116 | + 'PRT_deleted' => false, |
|
117 | + 'PRT_wp_user' => $default_creator_id, |
|
118 | + ), |
|
119 | + array( |
|
120 | + '%s',//PRT_name |
|
121 | + '%d',//PBT_id |
|
122 | + '%d',//PRT_is_percent |
|
123 | + '%d',//PRT_order |
|
124 | + '%d',//PRT_deleted |
|
125 | + '%d', //PRT_wp_user |
|
126 | + ) |
|
127 | + ); |
|
128 | + //federal tax |
|
129 | + $result = $wpdb->insert( |
|
130 | + $price_type_table, |
|
131 | + array( |
|
132 | + 'PRT_name' => __("Federal Tax", "event_espresso"), |
|
133 | + 'PBT_ID' => 4, |
|
134 | + 'PRT_is_percent' => true, |
|
135 | + 'PRT_order' => 70, |
|
136 | + 'PRT_deleted' => false, |
|
137 | + 'PRT_wp_user' => $default_creator_id, |
|
138 | + ), |
|
139 | + array( |
|
140 | + '%s',//PRT_name |
|
141 | + '%d',//PBT_id |
|
142 | + '%d',//PRT_is_percent |
|
143 | + '%d',//PRT_order |
|
144 | + '%d',//PRT_deleted |
|
145 | + '%d' //PRT_wp_user |
|
146 | + ) |
|
147 | + ); |
|
148 | + if ($result) { |
|
149 | + $wpdb->insert( |
|
150 | + $price_table, |
|
151 | + array( |
|
152 | + 'PRT_ID' => $wpdb->insert_id, |
|
153 | + 'PRC_amount' => 15.00, |
|
154 | + 'PRC_name' => __("Sales Tax", "event_espresso"), |
|
155 | + 'PRC_desc' => '', |
|
156 | + 'PRC_is_default' => true, |
|
157 | + 'PRC_overrides' => null, |
|
158 | + 'PRC_deleted' => false, |
|
159 | + 'PRC_order' => 50, |
|
160 | + 'PRC_parent' => null, |
|
161 | + 'PRC_wp_user' => $default_creator_id, |
|
162 | + ), |
|
163 | + array( |
|
164 | + '%d',//PRT_id |
|
165 | + '%f',//PRC_amount |
|
166 | + '%s',//PRC_name |
|
167 | + '%s',//PRC_desc |
|
168 | + '%d',//PRC_is_default |
|
169 | + '%d',//PRC_overrides |
|
170 | + '%d',//PRC_deleted |
|
171 | + '%d',//PRC_order |
|
172 | + '%d',//PRC_parent |
|
173 | + '%d' //PRC_wp_user |
|
174 | + ) |
|
175 | + ); |
|
176 | + } |
|
177 | + } |
|
178 | + } |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * caffeinated_modules_to_register |
|
185 | + * |
|
186 | + * @access public |
|
187 | + * @param array $modules_to_register |
|
188 | + * @return array |
|
189 | + */ |
|
190 | + public function caffeinated_modules_to_register($modules_to_register = array()) |
|
191 | + { |
|
192 | + if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
193 | + $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR); |
|
194 | + if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
|
195 | + $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
|
196 | + } |
|
197 | + } |
|
198 | + return $modules_to_register; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + |
|
203 | + public function caffeinated_init() |
|
204 | + { |
|
205 | + // EE_Register_CPTs hooks |
|
206 | + add_filter('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array($this, 'filter_taxonomies'), 10); |
|
207 | + add_filter('FHEE__EE_Register_CPTs__get_CPTs__cpts', array($this, 'filter_cpts'), 10); |
|
208 | + add_filter('FHEE__EE_Admin__get_extra_nav_menu_pages_items', array($this, 'nav_metabox_items'), 10); |
|
209 | + EE_Registry::instance()->load_file(EE_CAFF_PATH, 'EE_Caf_Messages', 'class', array(), false); |
|
210 | + // caffeinated_init__complete hook |
|
211 | + do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete'); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + |
|
216 | + public function enqueue_caffeinated_scripts() |
|
217 | + { |
|
218 | + // sound of crickets... |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + |
|
223 | + /** |
|
224 | + * callbacks below here |
|
225 | + * |
|
226 | + * @param array $taxonomy_array |
|
227 | + * @return array |
|
228 | + */ |
|
229 | + public function filter_taxonomies(array $taxonomy_array) |
|
230 | + { |
|
231 | + $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true; |
|
232 | + return $taxonomy_array; |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * @param array $cpt_array |
|
239 | + * @return mixed |
|
240 | + */ |
|
241 | + public function filter_cpts(array $cpt_array) |
|
242 | + { |
|
243 | + $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true; |
|
244 | + return $cpt_array; |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * @param array $menuitems |
|
251 | + * @return array |
|
252 | + */ |
|
253 | + public function nav_metabox_items(array $menuitems) |
|
254 | + { |
|
255 | + $menuitems[] = array( |
|
256 | + 'title' => __('Venue List', 'event_espresso'), |
|
257 | + 'url' => get_post_type_archive_link('espresso_venues'), |
|
258 | + 'description' => __('Archive page for all venues.', 'event_espresso'), |
|
259 | + ); |
|
260 | + return $menuitems; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * Adds the payment methods in {event-espresso-core}/caffeinated/payment_methods |
|
267 | + * |
|
268 | + * @param array $payment_method_paths |
|
269 | + * @return array values are folder paths to payment method folders |
|
270 | + */ |
|
271 | + public function caf_payment_methods($payment_method_paths) |
|
272 | + { |
|
273 | + $caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
274 | + $payment_method_paths = array_merge($payment_method_paths, $caf_payment_methods_paths); |
|
275 | + return $payment_method_paths; |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * Gets the injected table analyzer, or throws an exception |
|
282 | + * |
|
283 | + * @return TableAnalysis |
|
284 | + * @throws \EE_Error |
|
285 | + */ |
|
286 | + protected function _get_table_analysis() |
|
287 | + { |
|
288 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
289 | + return $this->_table_analysis; |
|
290 | + } else { |
|
291 | + throw new \EE_Error( |
|
292 | + sprintf( |
|
293 | + __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
294 | + get_class($this) |
|
295 | + ) |
|
296 | + ); |
|
297 | + } |
|
298 | + } |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | |
302 | 302 | |
303 | 303 | $brewing = new EE_Brewing_Regular( |
304 | - EE_Registry::instance()->create('TableAnalysis', array(), true) |
|
304 | + EE_Registry::instance()->create('TableAnalysis', array(), true) |
|
305 | 305 | ); |
306 | 306 | \ No newline at end of file |
@@ -1,3 +1,3 @@ |
||
1 | 1 | <h2><?php esc_html_e('What is the Event Espresso Messages System?', 'event_espresso'); ?></h2> |
2 | -<p><?php printf( esc_html__('The Event Espresso Messages system is a powerful framework that Event Espresso uses to prepare %1$smessages%2$s for different types of use (message types) and delivered by different %1$smessengers%2$s.', 'event_espresso'), '<strong>', '</strong>' ); ?></p> |
|
2 | +<p><?php printf(esc_html__('The Event Espresso Messages system is a powerful framework that Event Espresso uses to prepare %1$smessages%2$s for different types of use (message types) and delivered by different %1$smessengers%2$s.', 'event_espresso'), '<strong>', '</strong>'); ?></p> |
|
3 | 3 | <p><?php esc_html_e('We\'ve intentionally created this framework so that we have as much flexibility as possible for future ideas that we think of (or customers think of) for the kinds of messages that get sent out related to your events.', 'event_espresso'); ?></p> |
4 | 4 | \ No newline at end of file |
@@ -31,35 +31,35 @@ discard block |
||
31 | 31 | <tbody> |
32 | 32 | <tr> |
33 | 33 | <td> |
34 | - <h2><?php printf( esc_html__( 'Hello, %s:', 'event_espresso' ), '[PRIMARY_REGISTRANT_FNAME] [PRIMARY_REGISTRANT_LNAME]' ); ?></h2> |
|
35 | - <p class="lead"><?php printf( esc_html__( 'Your payment was %1$sCANCELLED%2$s for the following transaction and ticket purchases:', 'event_espresso' ), '<strong>', '</strong>'); ?></p> |
|
36 | - <h3><?php esc_html_e( 'Payment Details:', 'event_espresso' ); ?></h3> |
|
34 | + <h2><?php printf(esc_html__('Hello, %s:', 'event_espresso'), '[PRIMARY_REGISTRANT_FNAME] [PRIMARY_REGISTRANT_LNAME]'); ?></h2> |
|
35 | + <p class="lead"><?php printf(esc_html__('Your payment was %1$sCANCELLED%2$s for the following transaction and ticket purchases:', 'event_espresso'), '<strong>', '</strong>'); ?></p> |
|
36 | + <h3><?php esc_html_e('Payment Details:', 'event_espresso'); ?></h3> |
|
37 | 37 | <ul> |
38 | 38 | <li> |
39 | - <strong><?php esc_html_e( 'Payment Status:', 'event_espresso' ); ?></strong> [PAYMENT_STATUS] |
|
39 | + <strong><?php esc_html_e('Payment Status:', 'event_espresso'); ?></strong> [PAYMENT_STATUS] |
|
40 | 40 | </li> |
41 | 41 | <li> |
42 | - <strong><?php esc_html_e( 'Transaction ID:', 'event_espresso' ); ?></strong> [TXN_ID] |
|
42 | + <strong><?php esc_html_e('Transaction ID:', 'event_espresso'); ?></strong> [TXN_ID] |
|
43 | 43 | </li> |
44 | 44 | <li> |
45 | - <strong><?php esc_html_e( 'Total Cost:', 'event_espresso' ); ?></strong> [TOTAL_COST] |
|
45 | + <strong><?php esc_html_e('Total Cost:', 'event_espresso'); ?></strong> [TOTAL_COST] |
|
46 | 46 | </li> |
47 | 47 | <li> |
48 | - <strong><?php esc_html_e( 'Payment Method:', 'event_espresso' ); ?></strong> [PAYMENT_GATEWAY] |
|
48 | + <strong><?php esc_html_e('Payment Method:', 'event_espresso'); ?></strong> [PAYMENT_GATEWAY] |
|
49 | 49 | </li> |
50 | 50 | <li> |
51 | - <strong><?php esc_html_e( 'Payment Amount:', 'event_espresso' ); ?></strong> [AMOUNT_PAID] |
|
51 | + <strong><?php esc_html_e('Payment Amount:', 'event_espresso'); ?></strong> [AMOUNT_PAID] |
|
52 | 52 | </li> |
53 | 53 | <li> |
54 | - <strong><?php esc_html_e( 'Amount Due:', 'event_espresso' ); ?></strong> [TOTAL_OWING] |
|
54 | + <strong><?php esc_html_e('Amount Due:', 'event_espresso'); ?></strong> [TOTAL_OWING] |
|
55 | 55 | </li> |
56 | 56 | </ul> |
57 | 57 | <p class="callout"> |
58 | - <?php printf( esc_html__( 'Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso' ), '<a href="[PAYMENT_URL]">', '</a>' ); ?> |
|
58 | + <?php printf(esc_html__('Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso'), '<a href="[PAYMENT_URL]">', '</a>'); ?> |
|
59 | 59 | </p> |
60 | 60 | [EVENT_LIST] |
61 | 61 | <p class="callout"> |
62 | - <?php printf( esc_html__( 'Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso' ), '<a href="[PAYMENT_URL]">', '</a>' ); ?> |
|
62 | + <?php printf(esc_html__('Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso'), '<a href="[PAYMENT_URL]">', '</a>'); ?> |
|
63 | 63 | </p> |
64 | 64 | </td> |
65 | 65 | </tr> |
@@ -84,10 +84,10 @@ discard block |
||
84 | 84 | <tbody> |
85 | 85 | <tr> |
86 | 86 | <td> |
87 | - <h3><?php esc_html_e( 'Connect with Us:', 'event_espresso' ); ?></h3> |
|
88 | - <a class="soc-btn fb" href="[CO_FACEBOOK_URL]"><?php esc_html_e( 'Facebook', 'event_espresso' ); ?></a> |
|
89 | - <a class="soc-btn tw" href="[CO_TWITTER_URL]"><?php esc_html_e( 'Twitter', 'event_espresso' ); ?></a> |
|
90 | - <a class="soc-btn gp" href="[CO_GOOGLE_URL]"><?php esc_html_e( 'Google+', 'event_espresso' ); ?></a> |
|
87 | + <h3><?php esc_html_e('Connect with Us:', 'event_espresso'); ?></h3> |
|
88 | + <a class="soc-btn fb" href="[CO_FACEBOOK_URL]"><?php esc_html_e('Facebook', 'event_espresso'); ?></a> |
|
89 | + <a class="soc-btn tw" href="[CO_TWITTER_URL]"><?php esc_html_e('Twitter', 'event_espresso'); ?></a> |
|
90 | + <a class="soc-btn gp" href="[CO_GOOGLE_URL]"><?php esc_html_e('Google+', 'event_espresso'); ?></a> |
|
91 | 91 | </td> |
92 | 92 | </tr> |
93 | 93 | </tbody> |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | <tbody> |
98 | 98 | <tr> |
99 | 99 | <td> |
100 | - <h3><?php esc_html_e( 'Contact Info:', 'event_espresso' ); ?></h3> |
|
101 | - <?php esc_html_e( 'Phone:', 'event_espresso' ); ?> <strong>[CO_PHONE]</strong> |
|
102 | - <?php esc_html_e( 'Email:', 'event_espresso' ); ?> <strong><a href="mailto:[CO_EMAIL]" target="_blank">[CO_EMAIL]</a></strong> |
|
100 | + <h3><?php esc_html_e('Contact Info:', 'event_espresso'); ?></h3> |
|
101 | + <?php esc_html_e('Phone:', 'event_espresso'); ?> <strong>[CO_PHONE]</strong> |
|
102 | + <?php esc_html_e('Email:', 'event_espresso'); ?> <strong><a href="mailto:[CO_EMAIL]" target="_blank">[CO_EMAIL]</a></strong> |
|
103 | 103 | </td> |
104 | 104 | </tr> |
105 | 105 | </tbody> |
@@ -31,35 +31,35 @@ discard block |
||
31 | 31 | <tbody> |
32 | 32 | <tr> |
33 | 33 | <td> |
34 | - <h2><?php printf( esc_html__( 'Hello, %s:', 'event_espresso' ), '[PRIMARY_REGISTRANT_FNAME] [PRIMARY_REGISTRANT_LNAME]' ); ?></h2> |
|
35 | - <p class="lead"><?php printf( esc_html__( 'Your payment was %1$sDECLINED%2$s for the following transaction and ticket purchases:', 'event_espresso' ), '<strong>', '</strong>') ?></p> |
|
36 | - <h3><?php esc_html_e( 'Payment Details:', 'event_espresso' ); ?></h3> |
|
34 | + <h2><?php printf(esc_html__('Hello, %s:', 'event_espresso'), '[PRIMARY_REGISTRANT_FNAME] [PRIMARY_REGISTRANT_LNAME]'); ?></h2> |
|
35 | + <p class="lead"><?php printf(esc_html__('Your payment was %1$sDECLINED%2$s for the following transaction and ticket purchases:', 'event_espresso'), '<strong>', '</strong>') ?></p> |
|
36 | + <h3><?php esc_html_e('Payment Details:', 'event_espresso'); ?></h3> |
|
37 | 37 | <ul> |
38 | 38 | <li> |
39 | - <strong><?php esc_html_e( 'Payment Status:', 'event_espresso' ); ?></strong> [PAYMENT_STATUS] |
|
39 | + <strong><?php esc_html_e('Payment Status:', 'event_espresso'); ?></strong> [PAYMENT_STATUS] |
|
40 | 40 | </li> |
41 | 41 | <li> |
42 | - <strong><?php esc_html_e( 'Transaction ID:', 'event_espresso' ); ?></strong> [TXN_ID] |
|
42 | + <strong><?php esc_html_e('Transaction ID:', 'event_espresso'); ?></strong> [TXN_ID] |
|
43 | 43 | </li> |
44 | 44 | <li> |
45 | - <strong><?php esc_html_e( 'Total Cost:', 'event_espresso' ); ?></strong> [TOTAL_COST] |
|
45 | + <strong><?php esc_html_e('Total Cost:', 'event_espresso'); ?></strong> [TOTAL_COST] |
|
46 | 46 | </li> |
47 | 47 | <li> |
48 | - <strong><?php esc_html_e( 'Payment Method:', 'event_espresso' ); ?></strong> [PAYMENT_GATEWAY] |
|
48 | + <strong><?php esc_html_e('Payment Method:', 'event_espresso'); ?></strong> [PAYMENT_GATEWAY] |
|
49 | 49 | </li> |
50 | 50 | <li> |
51 | - <strong><?php esc_html_e( 'Payment Amount:', 'event_espresso' ); ?></strong> [AMOUNT_PAID] |
|
51 | + <strong><?php esc_html_e('Payment Amount:', 'event_espresso'); ?></strong> [AMOUNT_PAID] |
|
52 | 52 | </li> |
53 | 53 | <li> |
54 | - <strong><?php esc_html_e( 'Amount Due:', 'event_espresso' ); ?></strong> [TOTAL_OWING] |
|
54 | + <strong><?php esc_html_e('Amount Due:', 'event_espresso'); ?></strong> [TOTAL_OWING] |
|
55 | 55 | </li> |
56 | 56 | </ul> |
57 | 57 | <p class="callout"> |
58 | - <?php printf( esc_html__( 'Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso' ), '<a href="[PAYMENT_URL]">', '</a>' ); ?> |
|
58 | + <?php printf(esc_html__('Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso'), '<a href="[PAYMENT_URL]">', '</a>'); ?> |
|
59 | 59 | </p> |
60 | 60 | [EVENT_LIST] |
61 | 61 | <p class="callout"> |
62 | - <?php printf( esc_html__( 'Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso' ), '<a href="[PAYMENT_URL]">', '</a>' ); ?> |
|
62 | + <?php printf(esc_html__('Please %sretry your payment%s, or choose an alternate payment method to reserve your space.', 'event_espresso'), '<a href="[PAYMENT_URL]">', '</a>'); ?> |
|
63 | 63 | </p> |
64 | 64 | </td> |
65 | 65 | </tr> |
@@ -84,10 +84,10 @@ discard block |
||
84 | 84 | <tbody> |
85 | 85 | <tr> |
86 | 86 | <td> |
87 | - <h3><?php esc_html_e( 'Connect with Us:', 'event_espresso' ); ?></h3> |
|
88 | - <a class="soc-btn fb" href="[CO_FACEBOOK_URL]"><?php esc_html_e( 'Facebook', 'event_espresso' ); ?></a> |
|
89 | - <a class="soc-btn tw" href="[CO_TWITTER_URL]"><?php esc_html_e( 'Twitter', 'event_espresso' ); ?></a> |
|
90 | - <a class="soc-btn gp" href="[CO_GOOGLE_URL]"><?php esc_html_e( 'Google+', 'event_espresso' ); ?></a> |
|
87 | + <h3><?php esc_html_e('Connect with Us:', 'event_espresso'); ?></h3> |
|
88 | + <a class="soc-btn fb" href="[CO_FACEBOOK_URL]"><?php esc_html_e('Facebook', 'event_espresso'); ?></a> |
|
89 | + <a class="soc-btn tw" href="[CO_TWITTER_URL]"><?php esc_html_e('Twitter', 'event_espresso'); ?></a> |
|
90 | + <a class="soc-btn gp" href="[CO_GOOGLE_URL]"><?php esc_html_e('Google+', 'event_espresso'); ?></a> |
|
91 | 91 | </td> |
92 | 92 | </tr> |
93 | 93 | </tbody> |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | <tbody> |
98 | 98 | <tr> |
99 | 99 | <td> |
100 | - <h3><?php esc_html_e( 'Contact Info:', 'event_espresso' ); ?></h3> |
|
101 | - <?php esc_html_e( 'Phone:', 'event_espresso' ); ?> <strong>[CO_PHONE]</strong> |
|
102 | - <?php esc_html_e( 'Email:', 'event_espresso' ); ?> <strong><a href="mailto:[CO_EMAIL]" target="_blank">[CO_EMAIL]</a></strong> |
|
100 | + <h3><?php esc_html_e('Contact Info:', 'event_espresso'); ?></h3> |
|
101 | + <?php esc_html_e('Phone:', 'event_espresso'); ?> <strong>[CO_PHONE]</strong> |
|
102 | + <?php esc_html_e('Email:', 'event_espresso'); ?> <strong><a href="mailto:[CO_EMAIL]" target="_blank">[CO_EMAIL]</a></strong> |
|
103 | 103 | </td> |
104 | 104 | </tr> |
105 | 105 | </tbody> |
@@ -1,6 +1,5 @@ |
||
1 | 1 | <?php |
2 | 2 | use EventEspresso\core\interfaces\ResettableInterface; |
3 | - |
|
4 | 3 | use EventEspresso\core\services\database\TableManager; |
5 | 4 | use EventEspresso\core\services\database\TableAnalysis; |
6 | 5 |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | protected $_table_analysis; |
128 | 128 | |
129 | 129 | /** |
130 | - * @var EE_Data_Migration_Manager $_instance |
|
130 | + * @var EE_Data_Migration_Manager $_instance |
|
131 | 131 | * @access private |
132 | - */ |
|
132 | + */ |
|
133 | 133 | private static $_instance = NULL; |
134 | 134 | |
135 | 135 | |
@@ -720,18 +720,18 @@ discard block |
||
720 | 720 | |
721 | 721 | |
722 | 722 | |
723 | - /** |
|
724 | - * Gets all the data migration scripts available in the core folder and folders |
|
725 | - * in addons. Has the side effect of adding them for autoloading |
|
726 | - * |
|
727 | - * @return array keys are expected classnames, values are their filepaths |
|
728 | - * @throws \EE_Error |
|
729 | - */ |
|
723 | + /** |
|
724 | + * Gets all the data migration scripts available in the core folder and folders |
|
725 | + * in addons. Has the side effect of adding them for autoloading |
|
726 | + * |
|
727 | + * @return array keys are expected classnames, values are their filepaths |
|
728 | + * @throws \EE_Error |
|
729 | + */ |
|
730 | 730 | public function get_all_data_migration_scripts_available(){ |
731 | 731 | if( ! $this->_data_migration_class_to_filepath_map){ |
732 | 732 | $this->_data_migration_class_to_filepath_map = array(); |
733 | 733 | foreach($this->get_data_migration_script_folders() as $folder_path){ |
734 | - $folder_path = EEH_File::end_with_directory_separator($folder_path); |
|
734 | + $folder_path = EEH_File::end_with_directory_separator($folder_path); |
|
735 | 735 | $files = glob( $folder_path. '*.dms.php' ); |
736 | 736 | |
737 | 737 | if ( empty( $files ) ) { |
@@ -748,15 +748,15 @@ discard block |
||
748 | 748 | if( $slug !== 'Core' ){ |
749 | 749 | if( ! EE_Registry::instance()->get_addon_by_name( $slug ) ) { |
750 | 750 | EE_Error::doing_it_wrong( |
751 | - __FUNCTION__, |
|
752 | - sprintf( |
|
753 | - __( 'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', 'event_espresso' ), |
|
754 | - $classname, |
|
755 | - $slug, |
|
756 | - implode(', ', array_keys( EE_Registry::instance()->get_addons_by_name() ) ) |
|
757 | - ), |
|
758 | - '4.3.0.alpha.019' |
|
759 | - ); |
|
751 | + __FUNCTION__, |
|
752 | + sprintf( |
|
753 | + __( 'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', 'event_espresso' ), |
|
754 | + $classname, |
|
755 | + $slug, |
|
756 | + implode(', ', array_keys( EE_Registry::instance()->get_addons_by_name() ) ) |
|
757 | + ), |
|
758 | + '4.3.0.alpha.019' |
|
759 | + ); |
|
760 | 760 | } |
761 | 761 | } |
762 | 762 | $this->_data_migration_class_to_filepath_map[$classname] = $file; |
@@ -939,12 +939,12 @@ discard block |
||
939 | 939 | } |
940 | 940 | |
941 | 941 | /** |
942 | - * Resets the borked data migration scripts so they're no longer borked |
|
943 | - * so we can again attempt to migrate |
|
944 | - * |
|
945 | - * @return bool |
|
946 | - * @throws \EE_Error |
|
947 | - */ |
|
942 | + * Resets the borked data migration scripts so they're no longer borked |
|
943 | + * so we can again attempt to migrate |
|
944 | + * |
|
945 | + * @return bool |
|
946 | + * @throws \EE_Error |
|
947 | + */ |
|
948 | 948 | public function reattempt(){ |
949 | 949 | //find if the last-ran script was borked |
950 | 950 | //set it as being non-borked (we shouldn't ever get DMSs that we don't recognize) |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | //it's 4.2-style.eg Core.4.1.0 |
209 | 209 | $plugin_slug = $parts[0];//eg Core |
210 | 210 | $version_string = $parts[1].".".$parts[2].".".$parts[3]; //eg 4.1.0 |
211 | - }else{ |
|
211 | + } else{ |
|
212 | 212 | //it's 4.1-style: eg 4.1.0 |
213 | 213 | $plugin_slug = 'Core'; |
214 | 214 | $version_string = $plugin_slug_and_version_string;//eg 4.1.0 |
@@ -231,12 +231,12 @@ discard block |
||
231 | 231 | if($class instanceof EE_Data_Migration_Script_Base){ |
232 | 232 | $class->instantiate_from_array_of_properties($data_migration_data); |
233 | 233 | return $class; |
234 | - }else{ |
|
234 | + } else{ |
|
235 | 235 | //huh, so its an object but not a data migration script?? that shouldn't happen |
236 | 236 | //just leave it as an array (which will probably just get ignored) |
237 | 237 | throw new EE_Error(sprintf(__("Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists", 'event_espresso'),$data_migration_data['class'])); |
238 | 238 | } |
239 | - }else{ |
|
239 | + } else{ |
|
240 | 240 | //so the data doesn't specify a class. So it must either be a legacy array of info or some array (which we'll probably just ignore), or a class that no longer exists |
241 | 241 | throw new EE_Error(sprintf(__("The wp option with key '%s' does not represent a DMS", 'event_espresso'),$dms_option_name)); |
242 | 242 | } |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | //sometimes we also like to know which was the last incomplete script (or if there are any at all) |
267 | 267 | $this->_last_ran_incomplete_script = $class; |
268 | 268 | } |
269 | - }catch(EE_Error $e){ |
|
269 | + } catch(EE_Error $e){ |
|
270 | 270 | //ok so its not a DMS. We'll just keep it, although other code will need to expect non-DMSs |
271 | 271 | $data_migrations_ran[$plugin_slug][$version_string] = maybe_unserialize($data_migration_option['option_value']); |
272 | 272 | } |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | //so we want the data migrations to happen. SO, we're going to say the DB is at that state |
368 | 368 | // echo "4.1.0 is greater than $previous_version_installed! update the option"; |
369 | 369 | $db_state = array('Core'=>$previous_version_installed); |
370 | - }else{ |
|
370 | + } else{ |
|
371 | 371 | // echo "4.1.0 is SMALLER than $previous_version_installed"; |
372 | 372 | $db_state = array('Core'=>EVENT_ESPRESSO_VERSION); |
373 | 373 | } |
@@ -435,10 +435,10 @@ discard block |
||
435 | 435 | $migrates_to_version = $script->migrates_to_version(); |
436 | 436 | $next_database_state_to_consider[ $migrates_to_version[ 'slug' ] ] = $migrates_to_version[ 'version' ]; |
437 | 437 | unset($script_class_and_filepaths_available[$classname]); |
438 | - }else{ |
|
438 | + } else{ |
|
439 | 439 | //it must have a status that indicates it has finished, so we don't want to try and run it again |
440 | 440 | } |
441 | - }else{ |
|
441 | + } else{ |
|
442 | 442 | //it exists but it's not a proper data migration script |
443 | 443 | //maybe the script got renamed? or was simply removed from EE? |
444 | 444 | //either way, its certainly not runnable! |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | } |
479 | 479 | if($include_completed_scripts){ |
480 | 480 | return $this->_last_ran_script; |
481 | - }else{ |
|
481 | + } else{ |
|
482 | 482 | return $this->_last_ran_incomplete_script; |
483 | 483 | } |
484 | 484 | } |
@@ -539,7 +539,7 @@ discard block |
||
539 | 539 | $this->_data_migrations_ran[$plugin_slug][$version] = $currently_executing_script; |
540 | 540 | } |
541 | 541 | $current_script_name = get_class($currently_executing_script); |
542 | - }catch(Exception $e){ |
|
542 | + } catch(Exception $e){ |
|
543 | 543 | //an exception occurred while trying to get migration scripts |
544 | 544 | |
545 | 545 | $message = sprintf( __("Error Message: %sStack Trace:%s", "event_espresso"), $e->getMessage() . '<br>', $e->getTraceAsString() ); |
@@ -604,14 +604,14 @@ discard block |
||
604 | 604 | ); |
605 | 605 | break; |
606 | 606 | } |
607 | - }catch(Exception $e){ |
|
607 | + } catch(Exception $e){ |
|
608 | 608 | //ok so some exception was thrown which killed the data migration script |
609 | 609 | //double-check we have a real script |
610 | 610 | if($currently_executing_script instanceof EE_Data_Migration_Script_Base){ |
611 | 611 | $script_name = $currently_executing_script->pretty_name(); |
612 | 612 | $currently_executing_script->set_broken(); |
613 | 613 | $currently_executing_script->add_error($e->getMessage()); |
614 | - }else{ |
|
614 | + } else{ |
|
615 | 615 | $script_name = __("Error getting Migration Script", "event_espresso"); |
616 | 616 | } |
617 | 617 | $response_array = array( |
@@ -654,7 +654,7 @@ discard block |
||
654 | 654 | ob_start(); |
655 | 655 | try{ |
656 | 656 | $response = $this->migration_step(); |
657 | - }catch(Exception $e){ |
|
657 | + } catch(Exception $e){ |
|
658 | 658 | $response = array( |
659 | 659 | 'records_to_migrate'=>0, |
660 | 660 | 'records_migrated'=>0, |
@@ -703,7 +703,7 @@ discard block |
||
703 | 703 | $current_database_state = get_option(self::current_database_state); |
704 | 704 | if( ! isset( $current_database_state[ $slug ] ) ) { |
705 | 705 | return true; |
706 | - }else{ |
|
706 | + } else{ |
|
707 | 707 | //just compare the first 3 parts of version string, eg "4.7.1", not "4.7.1.dev.032" because DBs shouldn't change on nano version changes |
708 | 708 | $version_parts_current_db_state = array_slice( explode('.', $current_database_state[ $slug ] ), 0, 3); |
709 | 709 | $version_parts_of_provided_db_state = array_slice( explode( '.', $version ), 0, 3 ); |
@@ -803,7 +803,7 @@ discard block |
||
803 | 803 | //ok then just add this error to its list of errors |
804 | 804 | $last_ran_migration_script_properties['_errors'][] = $error_message; |
805 | 805 | $last_ran_migration_script_properties['_status'] = self::status_fatal_error; |
806 | - }else{ |
|
806 | + } else{ |
|
807 | 807 | //so we don't even know which script was last running |
808 | 808 | //use the data migration error stub, which is designed specifically for this type of thing |
809 | 809 | $general_migration_error = new EE_DMS_Unknown_1_0_0(); |
@@ -839,7 +839,7 @@ discard block |
||
839 | 839 | if( $old_option_value != $script_array_for_saving){ |
840 | 840 | $successful_updates = update_option($option_name,$script_array_for_saving); |
841 | 841 | } |
842 | - }else{//we don't know what this array-thing is. So just save it as-is |
|
842 | + } else{//we don't know what this array-thing is. So just save it as-is |
|
843 | 843 | // $array_of_migrations[$version_string] = $array_or_migration_obj; |
844 | 844 | if($old_option_value != $array_or_migration_obj){ |
845 | 845 | $successful_updates = update_option($option_name,$array_or_migration_obj); |
@@ -906,7 +906,7 @@ discard block |
||
906 | 906 | } |
907 | 907 | //if it wasn't for core, we must keep searching for one that is! |
908 | 908 | continue; |
909 | - }else{ |
|
909 | + } else{ |
|
910 | 910 | $champion_migrates_to= $this->script_migrates_to_version($most_up_to_date_dms_classname); |
911 | 911 | $contender_migrates_to = $this->script_migrates_to_version($classname); |
912 | 912 | if($contender_migrates_to[ 'slug' ] == $plugin_slug && version_compare($champion_migrates_to[ 'version' ], $contender_migrates_to[ 'version' ], '<')){ |
@@ -933,7 +933,7 @@ discard block |
||
933 | 933 | $migrations_ran = $this->get_data_migrations_ran(); |
934 | 934 | if( isset( $migrations_ran[ $plugin_slug ] ) && isset( $migrations_ran[ $plugin_slug ][ $version ] ) ){ |
935 | 935 | return $migrations_ran[ $plugin_slug ][ $version ]; |
936 | - }else{ |
|
936 | + } else{ |
|
937 | 937 | return NULL; |
938 | 938 | } |
939 | 939 | } |
@@ -955,9 +955,9 @@ discard block |
||
955 | 955 | if( $last_ran_script instanceof EE_DMS_Unknown_1_0_0 ){ |
956 | 956 | //if it was an error DMS, just mark it as complete (if another error occurs it will overwrite it) |
957 | 957 | $last_ran_script->set_completed(); |
958 | - }elseif( $last_ran_script instanceof EE_Data_Migration_Script_Base ) { |
|
958 | + } elseif( $last_ran_script instanceof EE_Data_Migration_Script_Base ) { |
|
959 | 959 | $last_ran_script->reattempt(); |
960 | - }else{ |
|
960 | + } else{ |
|
961 | 961 | throw new EE_Error( sprintf( __( 'Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s', 'event_espresso' ), print_r( $last_ran_script, true ) ) ); |
962 | 962 | } |
963 | 963 | return $this->_save_migrations_ran(); |
@@ -995,7 +995,7 @@ discard block |
||
995 | 995 | if( ! $most_up_to_date_dms ) { |
996 | 996 | //if there is NO DMS for this plugin, obviously there's no schema to verify anyways |
997 | 997 | $verify_db = false; |
998 | - }else{ |
|
998 | + } else{ |
|
999 | 999 | $most_up_to_date_dms_migrates_to = $this->script_migrates_to_version( $most_up_to_date_dms ); |
1000 | 1000 | $verify_db = $this->database_needs_updating_to( $most_up_to_date_dms_migrates_to ); |
1001 | 1001 | } |
@@ -1004,7 +1004,7 @@ discard block |
||
1004 | 1004 | false, |
1005 | 1005 | $verify_db |
1006 | 1006 | ); |
1007 | - }else{ |
|
1007 | + } else{ |
|
1008 | 1008 | //just loop through the addons to make sure their database is setup |
1009 | 1009 | foreach( EE_Registry::instance()->addons as $addon ) { |
1010 | 1010 | if( $addon->name() == $plugin_slug ) { |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * of this EE installation. Keys should be the name of the version the script upgraded to |
83 | 83 | * @var EE_Data_Migration_Script_Base[] |
84 | 84 | */ |
85 | - private $_data_migrations_ran =null; |
|
85 | + private $_data_migrations_ran = null; |
|
86 | 86 | /** |
87 | 87 | * The last ran script. It's nice to store this somewhere accessible, as its easiest |
88 | 88 | * to know which was the last run by which is the newest wp option; but in most of the code |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | */ |
143 | 143 | public static function instance() { |
144 | 144 | // check if class object is instantiated |
145 | - if ( ! self::$_instance instanceof EE_Data_Migration_Manager ) { |
|
145 | + if ( ! self::$_instance instanceof EE_Data_Migration_Manager) { |
|
146 | 146 | self::$_instance = new self(); |
147 | 147 | } |
148 | 148 | return self::$_instance; |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | * all new usages of the singleton should be made with Classname::instance()) and returns it |
153 | 153 | * @return EE_Data_Migration_Manager |
154 | 154 | */ |
155 | - public static function reset(){ |
|
155 | + public static function reset() { |
|
156 | 156 | self::$_instance = NULL; |
157 | 157 | return self::instance(); |
158 | 158 | } |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | /** |
163 | 163 | * constructor |
164 | 164 | */ |
165 | - private function __construct(){ |
|
165 | + private function __construct() { |
|
166 | 166 | $this->stati_that_indicate_to_continue_migrations = array( |
167 | 167 | self::status_continue, |
168 | 168 | self::status_completed |
@@ -181,13 +181,13 @@ discard block |
||
181 | 181 | ); |
182 | 182 | //make sure we've included the base migration script, because we may need the EE_DMS_Unknown_1_0_0 class |
183 | 183 | //to be defined, because right now it doesn't get autoloaded on its own |
184 | - EE_Registry::instance()->load_core( 'Data_Migration_Class_Base', array(), TRUE ); |
|
185 | - EE_Registry::instance()->load_core( 'Data_Migration_Script_Base', array(), TRUE ); |
|
186 | - EE_Registry::instance()->load_core( 'DMS_Unknown_1_0_0', array(), TRUE ); |
|
187 | - EE_Registry::instance()->load_core( 'Data_Migration_Script_Stage', array(), TRUE ); |
|
188 | - EE_Registry::instance()->load_core( 'Data_Migration_Script_Stage_Table', array(), TRUE ); |
|
189 | - $this->_table_manager = EE_Registry::instance()->create( 'TableManager', array(), true ); |
|
190 | - $this->_table_analysis = EE_Registry::instance()->create( 'TableAnalysis', array(), true ); |
|
184 | + EE_Registry::instance()->load_core('Data_Migration_Class_Base', array(), TRUE); |
|
185 | + EE_Registry::instance()->load_core('Data_Migration_Script_Base', array(), TRUE); |
|
186 | + EE_Registry::instance()->load_core('DMS_Unknown_1_0_0', array(), TRUE); |
|
187 | + EE_Registry::instance()->load_core('Data_Migration_Script_Stage', array(), TRUE); |
|
188 | + EE_Registry::instance()->load_core('Data_Migration_Script_Stage_Table', array(), TRUE); |
|
189 | + $this->_table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
190 | + $this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | |
@@ -200,21 +200,21 @@ discard block |
||
200 | 200 | * @param string $option_name (see EE_Data_Migration_Manage::_save_migrations_ran() where the option name is set) |
201 | 201 | * @return array where the first item is the plugin slug (eg 'Core','Calendar',etc) and the 2nd is the version of that plugin (eg '4.1.0') |
202 | 202 | */ |
203 | - private function _get_plugin_slug_and_version_string_from_dms_option_name($option_name){ |
|
203 | + private function _get_plugin_slug_and_version_string_from_dms_option_name($option_name) { |
|
204 | 204 | $plugin_slug_and_version_string = str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_name); |
205 | 205 | //check if $plugin_slug_and_version_string is like '4.1.0' (4.1-style) or 'Core.4.1.0' (4.2-style) |
206 | - $parts = explode(".",$plugin_slug_and_version_string); |
|
206 | + $parts = explode(".", $plugin_slug_and_version_string); |
|
207 | 207 | |
208 | - if(count($parts) == 4){ |
|
208 | + if (count($parts) == 4) { |
|
209 | 209 | //it's 4.2-style.eg Core.4.1.0 |
210 | - $plugin_slug = $parts[0];//eg Core |
|
210 | + $plugin_slug = $parts[0]; //eg Core |
|
211 | 211 | $version_string = $parts[1].".".$parts[2].".".$parts[3]; //eg 4.1.0 |
212 | - }else{ |
|
212 | + } else { |
|
213 | 213 | //it's 4.1-style: eg 4.1.0 |
214 | 214 | $plugin_slug = 'Core'; |
215 | - $version_string = $plugin_slug_and_version_string;//eg 4.1.0 |
|
215 | + $version_string = $plugin_slug_and_version_string; //eg 4.1.0 |
|
216 | 216 | } |
217 | - return array($plugin_slug,$version_string); |
|
217 | + return array($plugin_slug, $version_string); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -225,21 +225,21 @@ discard block |
||
225 | 225 | * @return EE_Data_Migration_Script_Base |
226 | 226 | * @throws EE_Error |
227 | 227 | */ |
228 | - private function _get_dms_class_from_wp_option($dms_option_name,$dms_option_value){ |
|
228 | + private function _get_dms_class_from_wp_option($dms_option_name, $dms_option_value) { |
|
229 | 229 | $data_migration_data = maybe_unserialize($dms_option_value); |
230 | - if(isset($data_migration_data['class']) && class_exists($data_migration_data['class'])){ |
|
230 | + if (isset($data_migration_data['class']) && class_exists($data_migration_data['class'])) { |
|
231 | 231 | $class = new $data_migration_data['class']; |
232 | - if($class instanceof EE_Data_Migration_Script_Base){ |
|
232 | + if ($class instanceof EE_Data_Migration_Script_Base) { |
|
233 | 233 | $class->instantiate_from_array_of_properties($data_migration_data); |
234 | 234 | return $class; |
235 | - }else{ |
|
235 | + } else { |
|
236 | 236 | //huh, so its an object but not a data migration script?? that shouldn't happen |
237 | 237 | //just leave it as an array (which will probably just get ignored) |
238 | - throw new EE_Error(sprintf(__("Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists", 'event_espresso'),$data_migration_data['class'])); |
|
238 | + throw new EE_Error(sprintf(__("Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists", 'event_espresso'), $data_migration_data['class'])); |
|
239 | 239 | } |
240 | - }else{ |
|
240 | + } else { |
|
241 | 241 | //so the data doesn't specify a class. So it must either be a legacy array of info or some array (which we'll probably just ignore), or a class that no longer exists |
242 | - throw new EE_Error(sprintf(__("The wp option with key '%s' does not represent a DMS", 'event_espresso'),$dms_option_name)); |
|
242 | + throw new EE_Error(sprintf(__("The wp option with key '%s' does not represent a DMS", 'event_espresso'), $dms_option_name)); |
|
243 | 243 | } |
244 | 244 | } |
245 | 245 | /** |
@@ -247,34 +247,34 @@ discard block |
||
247 | 247 | * the last ran which hasn't finished yet |
248 | 248 | * @return array where each element should be an array of EE_Data_Migration_Script_Base (but also has a few legacy arrays in there - which should probably be ignored) |
249 | 249 | */ |
250 | - public function get_data_migrations_ran(){ |
|
251 | - if( ! $this->_data_migrations_ran ){ |
|
250 | + public function get_data_migrations_ran() { |
|
251 | + if ( ! $this->_data_migrations_ran) { |
|
252 | 252 | //setup autoloaders for each of the scripts in there |
253 | 253 | $this->get_all_data_migration_scripts_available(); |
254 | - $data_migrations_options = $this->get_all_migration_script_options();//get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
254 | + $data_migrations_options = $this->get_all_migration_script_options(); //get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
255 | 255 | |
256 | 256 | $data_migrations_ran = array(); |
257 | 257 | //convert into data migration script classes where possible |
258 | - foreach($data_migrations_options as $data_migration_option){ |
|
259 | - list($plugin_slug,$version_string) = $this->_get_plugin_slug_and_version_string_from_dms_option_name($data_migration_option['option_name']); |
|
258 | + foreach ($data_migrations_options as $data_migration_option) { |
|
259 | + list($plugin_slug, $version_string) = $this->_get_plugin_slug_and_version_string_from_dms_option_name($data_migration_option['option_name']); |
|
260 | 260 | |
261 | - try{ |
|
262 | - $class = $this->_get_dms_class_from_wp_option($data_migration_option['option_name'],$data_migration_option['option_value']); |
|
261 | + try { |
|
262 | + $class = $this->_get_dms_class_from_wp_option($data_migration_option['option_name'], $data_migration_option['option_value']); |
|
263 | 263 | $data_migrations_ran[$plugin_slug][$version_string] = $class; |
264 | 264 | //ok so far THIS is the 'last-ran-script'... unless we find another on next iteration |
265 | 265 | $this->_last_ran_script = $class; |
266 | - if( ! $class->is_completed()){ |
|
266 | + if ( ! $class->is_completed()) { |
|
267 | 267 | //sometimes we also like to know which was the last incomplete script (or if there are any at all) |
268 | 268 | $this->_last_ran_incomplete_script = $class; |
269 | 269 | } |
270 | - }catch(EE_Error $e){ |
|
270 | + } catch (EE_Error $e) { |
|
271 | 271 | //ok so its not a DMS. We'll just keep it, although other code will need to expect non-DMSs |
272 | 272 | $data_migrations_ran[$plugin_slug][$version_string] = maybe_unserialize($data_migration_option['option_value']); |
273 | 273 | } |
274 | 274 | } |
275 | 275 | //so here the array of $data_migrations_ran is actually a mix of classes and a few legacy arrays |
276 | 276 | $this->_data_migrations_ran = $data_migrations_ran; |
277 | - if ( ! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran) ){ |
|
277 | + if ( ! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran)) { |
|
278 | 278 | $this->_data_migrations_ran = array(); |
279 | 279 | } |
280 | 280 | } |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | * @param $new_table |
292 | 292 | * @return mixed string or int |
293 | 293 | */ |
294 | - public function get_mapping_new_pk( $script_name, $old_table, $old_pk, $new_table){ |
|
294 | + public function get_mapping_new_pk($script_name, $old_table, $old_pk, $new_table) { |
|
295 | 295 | $script = EE_Registry::instance()->load_dms($script_name); |
296 | 296 | $mapping = $script->get_mapping_new_pk($old_table, $old_pk, $new_table); |
297 | 297 | return $mapping; |
@@ -302,9 +302,9 @@ discard block |
||
302 | 302 | * option returned in this array is the most-recently ran DMS option |
303 | 303 | * @return array |
304 | 304 | */ |
305 | - public function get_all_migration_script_options(){ |
|
305 | + public function get_all_migration_script_options() { |
|
306 | 306 | global $wpdb; |
307 | - return $wpdb->get_results("SELECT * FROM {$wpdb->options} WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id ASC",ARRAY_A); |
|
307 | + return $wpdb->get_results("SELECT * FROM {$wpdb->options} WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id ASC", ARRAY_A); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
@@ -312,8 +312,8 @@ discard block |
||
312 | 312 | * @return array where each value is the full folder path of a folder containing data migration scripts, WITH slashes at the end of the |
313 | 313 | * folder name. |
314 | 314 | */ |
315 | - public function get_data_migration_script_folders(){ |
|
316 | - return apply_filters( 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders',array(EE_CORE.'data_migration_scripts') ); |
|
315 | + public function get_data_migration_script_folders() { |
|
316 | + return apply_filters('FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', array(EE_CORE.'data_migration_scripts')); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -325,11 +325,11 @@ discard block |
||
325 | 325 | * } |
326 | 326 | * @throws EE_Error |
327 | 327 | */ |
328 | - public function script_migrates_to_version($migration_script_name){ |
|
328 | + public function script_migrates_to_version($migration_script_name) { |
|
329 | 329 | $dms_info = $this->parse_dms_classname($migration_script_name); |
330 | 330 | return array( |
331 | - 'slug'=> $dms_info[ 'slug' ], |
|
332 | - 'version'=> $dms_info[ 'major_version' ] . "." . $dms_info[ 'minor_version' ] . "." . $dms_info[ 'micro_version' ] ); |
|
331 | + 'slug'=> $dms_info['slug'], |
|
332 | + 'version'=> $dms_info['major_version'].".".$dms_info['minor_version'].".".$dms_info['micro_version'] ); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
@@ -338,13 +338,13 @@ discard block |
||
338 | 338 | * @return array with keys 'slug','major_version','minor_version', and 'micro_version' (the last 3 are ints) |
339 | 339 | * @throws EE_Error |
340 | 340 | */ |
341 | - public function parse_dms_classname($classname){ |
|
341 | + public function parse_dms_classname($classname) { |
|
342 | 342 | $matches = array(); |
343 | - preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~',$classname,$matches); |
|
344 | - if( ! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))){ |
|
345 | - throw new EE_Error(sprintf(__("%s is not a valid Data Migration Script. The classname should be like EE_DMS_w_x_y_z, where w is either 'Core' or the slug of an addon and x, y and z are numbers, ", "event_espresso"),$classname)); |
|
343 | + preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~', $classname, $matches); |
|
344 | + if ( ! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))) { |
|
345 | + throw new EE_Error(sprintf(__("%s is not a valid Data Migration Script. The classname should be like EE_DMS_w_x_y_z, where w is either 'Core' or the slug of an addon and x, y and z are numbers, ", "event_espresso"), $classname)); |
|
346 | 346 | } |
347 | - return array('slug'=>$matches[1],'major_version'=>intval($matches[2]),'minor_version'=>intval($matches[3]),'micro_version'=>intval($matches[4])); |
|
347 | + return array('slug'=>$matches[1], 'major_version'=>intval($matches[2]), 'minor_version'=>intval($matches[3]), 'micro_version'=>intval($matches[4])); |
|
348 | 348 | } |
349 | 349 | /** |
350 | 350 | * Ensures that the option indicating the current DB version is set. This should only be |
@@ -353,33 +353,33 @@ discard block |
||
353 | 353 | * to 4.1.x. |
354 | 354 | * @return string of current db state |
355 | 355 | */ |
356 | - public function ensure_current_database_state_is_set(){ |
|
357 | - $espresso_db_core_updates = get_option( 'espresso_db_update', array() ); |
|
356 | + public function ensure_current_database_state_is_set() { |
|
357 | + $espresso_db_core_updates = get_option('espresso_db_update', array()); |
|
358 | 358 | $db_state = get_option(EE_Data_Migration_Manager::current_database_state); |
359 | - if( ! $db_state ){ |
|
359 | + if ( ! $db_state) { |
|
360 | 360 | //mark the DB as being in the state as the last version in there. |
361 | 361 | //this is done to trigger maintenance mode and do data migration scripts |
362 | 362 | //if the admin installed this version of EE over 3.1.x or 4.0.x |
363 | 363 | //otherwise, the normal maintenance mode code is fine |
364 | 364 | $previous_versions_installed = array_keys($espresso_db_core_updates); |
365 | 365 | $previous_version_installed = end($previous_versions_installed); |
366 | - if(version_compare('4.1.0', $previous_version_installed)){ |
|
366 | + if (version_compare('4.1.0', $previous_version_installed)) { |
|
367 | 367 | //last installed version was less than 4.1 |
368 | 368 | //so we want the data migrations to happen. SO, we're going to say the DB is at that state |
369 | 369 | // echo "4.1.0 is greater than $previous_version_installed! update the option"; |
370 | 370 | $db_state = array('Core'=>$previous_version_installed); |
371 | - }else{ |
|
371 | + } else { |
|
372 | 372 | // echo "4.1.0 is SMALLER than $previous_version_installed"; |
373 | 373 | $db_state = array('Core'=>EVENT_ESPRESSO_VERSION); |
374 | 374 | } |
375 | - update_option(EE_Data_Migration_Manager::current_database_state,$db_state); |
|
375 | + update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
376 | 376 | } |
377 | 377 | //in 4.1, $db_state would have only been a simple string like '4.1.0', |
378 | 378 | //but in 4.2+ it should be an array with at least key 'Core' and the value of that plugin's |
379 | 379 | //db, and possibly other keys for other addons like 'Calendar','Permissions',etc |
380 | - if( ! is_array($db_state)){ |
|
380 | + if ( ! is_array($db_state)) { |
|
381 | 381 | $db_state = array('Core'=>$db_state); |
382 | - update_option(EE_Data_Migration_Manager::current_database_state,$db_state); |
|
382 | + update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
383 | 383 | } |
384 | 384 | return $db_state; |
385 | 385 | } |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | * or they don't apply), returns an empty array |
391 | 391 | * @return EE_Data_Migration_Script_Base[] |
392 | 392 | */ |
393 | - public function check_for_applicable_data_migration_scripts(){ |
|
393 | + public function check_for_applicable_data_migration_scripts() { |
|
394 | 394 | //get the option describing what options have already run |
395 | 395 | $scripts_ran = $this->get_data_migrations_ran(); |
396 | 396 | //$scripts_ran = array('4.1.0.core'=>array('monkey'=>null)); |
@@ -403,62 +403,62 @@ discard block |
||
403 | 403 | $iteration = 0; |
404 | 404 | $next_database_state_to_consider = $current_database_state; |
405 | 405 | $theoretical_database_state = NULL; |
406 | - do{ |
|
406 | + do { |
|
407 | 407 | //the next state after the currently-considered one will start off looking the same as the current, but we may make additions... |
408 | 408 | $theoretical_database_state = $next_database_state_to_consider; |
409 | 409 | //the next db state to consider is "what would the DB be like had we run all the scripts we found that applied last time?) |
410 | - foreach($script_class_and_filepaths_available as $classname => $filepath){ |
|
410 | + foreach ($script_class_and_filepaths_available as $classname => $filepath) { |
|
411 | 411 | |
412 | 412 | $migrates_to_version = $this->script_migrates_to_version($classname); |
413 | - $script_converts_plugin_slug = $migrates_to_version[ 'slug' ]; |
|
414 | - $script_converts_to_version = $migrates_to_version[ 'version' ]; |
|
413 | + $script_converts_plugin_slug = $migrates_to_version['slug']; |
|
414 | + $script_converts_to_version = $migrates_to_version['version']; |
|
415 | 415 | //check if this version script is DONE or not; or if it's never been ran |
416 | - if( ! $scripts_ran || |
|
416 | + if ( ! $scripts_ran || |
|
417 | 417 | ! isset($scripts_ran[$script_converts_plugin_slug]) || |
418 | - ! isset($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version])){ |
|
418 | + ! isset($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version])) { |
|
419 | 419 | //we haven't ran this conversion script before |
420 | 420 | //now check if it applies... note that we've added an autoloader for it on get_all_data_migration_scripts_available |
421 | - $script = new $classname( $this->_get_table_manager(), $this->_get_table_analysis() ); |
|
421 | + $script = new $classname($this->_get_table_manager(), $this->_get_table_analysis()); |
|
422 | 422 | /* @var $script EE_Data_Migration_Script_Base */ |
423 | 423 | $can_migrate = $script->can_migrate_from_version($theoretical_database_state); |
424 | - if($can_migrate){ |
|
424 | + if ($can_migrate) { |
|
425 | 425 | $script_classes_that_should_run_per_iteration[$iteration][$script->priority()][] = $script; |
426 | 426 | $migrates_to_version = $script->migrates_to_version(); |
427 | - $next_database_state_to_consider[ $migrates_to_version[ 'slug' ] ] = $migrates_to_version[ 'version' ]; |
|
427 | + $next_database_state_to_consider[$migrates_to_version['slug']] = $migrates_to_version['version']; |
|
428 | 428 | unset($script_class_and_filepaths_available[$classname]); |
429 | 429 | } |
430 | - } elseif($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version] instanceof EE_Data_Migration_Script_Base){ |
|
430 | + } elseif ($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version] instanceof EE_Data_Migration_Script_Base) { |
|
431 | 431 | //this script has been ran, or at least started |
432 | 432 | $script = $scripts_ran[$script_converts_plugin_slug][$script_converts_to_version]; |
433 | - if( $script->get_status() != self::status_completed){ |
|
433 | + if ($script->get_status() != self::status_completed) { |
|
434 | 434 | //this script is already underway... keep going with it |
435 | 435 | $script_classes_that_should_run_per_iteration[$iteration][$script->priority()][] = $script; |
436 | 436 | $migrates_to_version = $script->migrates_to_version(); |
437 | - $next_database_state_to_consider[ $migrates_to_version[ 'slug' ] ] = $migrates_to_version[ 'version' ]; |
|
437 | + $next_database_state_to_consider[$migrates_to_version['slug']] = $migrates_to_version['version']; |
|
438 | 438 | unset($script_class_and_filepaths_available[$classname]); |
439 | - }else{ |
|
439 | + } else { |
|
440 | 440 | //it must have a status that indicates it has finished, so we don't want to try and run it again |
441 | 441 | } |
442 | - }else{ |
|
442 | + } else { |
|
443 | 443 | //it exists but it's not a proper data migration script |
444 | 444 | //maybe the script got renamed? or was simply removed from EE? |
445 | 445 | //either way, its certainly not runnable! |
446 | 446 | } |
447 | 447 | } |
448 | 448 | $iteration++; |
449 | - }while( $next_database_state_to_consider != $theoretical_database_state && $iteration<6); |
|
449 | + }while ($next_database_state_to_consider != $theoretical_database_state && $iteration < 6); |
|
450 | 450 | //ok we have all the scripts that should run, now let's make them into flat array |
451 | 451 | $scripts_that_should_run = array(); |
452 | - foreach($script_classes_that_should_run_per_iteration as $scripts_at_priority){ |
|
452 | + foreach ($script_classes_that_should_run_per_iteration as $scripts_at_priority) { |
|
453 | 453 | ksort($scripts_at_priority); |
454 | - foreach($scripts_at_priority as $scripts){ |
|
455 | - foreach($scripts as $script){ |
|
454 | + foreach ($scripts_at_priority as $scripts) { |
|
455 | + foreach ($scripts as $script) { |
|
456 | 456 | $scripts_that_should_run[get_class($script)] = $script; |
457 | 457 | } |
458 | 458 | } |
459 | 459 | } |
460 | 460 | |
461 | - do_action( 'AHEE__EE_Data_Migration_Manager__check_for_applicable_data_migration_scripts__scripts_that_should_run', $scripts_that_should_run ); |
|
461 | + do_action('AHEE__EE_Data_Migration_Manager__check_for_applicable_data_migration_scripts__scripts_that_should_run', $scripts_that_should_run); |
|
462 | 462 | return $scripts_that_should_run; |
463 | 463 | } |
464 | 464 | |
@@ -472,14 +472,14 @@ discard block |
||
472 | 472 | * @param bool $include_completed_scripts |
473 | 473 | * @return EE_Data_Migration_Script_Base |
474 | 474 | */ |
475 | - public function get_last_ran_script($include_completed_scripts = false){ |
|
475 | + public function get_last_ran_script($include_completed_scripts = false) { |
|
476 | 476 | //make sure we've setup the class properties _last_ran_script and _last_ran_incomplete_script |
477 | - if( ! $this->_data_migrations_ran){ |
|
477 | + if ( ! $this->_data_migrations_ran) { |
|
478 | 478 | $this->get_data_migrations_ran(); |
479 | 479 | } |
480 | - if($include_completed_scripts){ |
|
480 | + if ($include_completed_scripts) { |
|
481 | 481 | return $this->_last_ran_script; |
482 | - }else{ |
|
482 | + } else { |
|
483 | 483 | return $this->_last_ran_incomplete_script; |
484 | 484 | } |
485 | 485 | } |
@@ -502,19 +502,19 @@ discard block |
||
502 | 502 | * @type string $message string describing what was done during this step |
503 | 503 | * } |
504 | 504 | */ |
505 | - public function migration_step( $step_size = 0 ){ |
|
505 | + public function migration_step($step_size = 0) { |
|
506 | 506 | |
507 | 507 | //bandaid fix for issue https://events.codebasehq.com/projects/event-espresso/tickets/7535 |
508 | - if ( class_exists( 'EE_CPT_Strategy' ) ) { |
|
509 | - remove_action( 'pre_get_posts', array( EE_CPT_Strategy::instance(), 'pre_get_posts' ), 5 ); |
|
508 | + if (class_exists('EE_CPT_Strategy')) { |
|
509 | + remove_action('pre_get_posts', array(EE_CPT_Strategy::instance(), 'pre_get_posts'), 5); |
|
510 | 510 | } |
511 | 511 | |
512 | - try{ |
|
512 | + try { |
|
513 | 513 | $currently_executing_script = $this->get_last_ran_script(); |
514 | - if( ! $currently_executing_script){ |
|
514 | + if ( ! $currently_executing_script) { |
|
515 | 515 | //Find the next script that needs to execute |
516 | 516 | $scripts = $this->check_for_applicable_data_migration_scripts(); |
517 | - if( ! $scripts ){ |
|
517 | + if ( ! $scripts) { |
|
518 | 518 | //huh, no more scripts to run... apparently we're done! |
519 | 519 | //but dont forget to make sure initial data is there |
520 | 520 | //we should be good to allow them to exit maintenance mode now |
@@ -535,18 +535,18 @@ discard block |
||
535 | 535 | //and add to the array/wp option showing the scripts ran |
536 | 536 | // $this->_data_migrations_ran[$this->script_migrates_to_version(get_class($currently_executing_script))] = $currently_executing_script; |
537 | 537 | $migrates_to = $this->script_migrates_to_version(get_class($currently_executing_script)); |
538 | - $plugin_slug = $migrates_to[ 'slug' ]; |
|
539 | - $version = $migrates_to[ 'version' ]; |
|
538 | + $plugin_slug = $migrates_to['slug']; |
|
539 | + $version = $migrates_to['version']; |
|
540 | 540 | $this->_data_migrations_ran[$plugin_slug][$version] = $currently_executing_script; |
541 | 541 | } |
542 | 542 | $current_script_name = get_class($currently_executing_script); |
543 | - }catch(Exception $e){ |
|
543 | + } catch (Exception $e) { |
|
544 | 544 | //an exception occurred while trying to get migration scripts |
545 | 545 | |
546 | - $message = sprintf( __("Error Message: %sStack Trace:%s", "event_espresso"), $e->getMessage() . '<br>', $e->getTraceAsString() ); |
|
546 | + $message = sprintf(__("Error Message: %sStack Trace:%s", "event_espresso"), $e->getMessage().'<br>', $e->getTraceAsString()); |
|
547 | 547 | //record it on the array of data migration scripts ran. This will be overwritten next time we try and try to run data migrations |
548 | 548 | //but that's ok-- it's just an FYI to support that we couldn't even run any data migrations |
549 | - $this->add_error_to_migrations_ran(sprintf(__("Could not run data migrations because: %s", "event_espresso"),$message)); |
|
549 | + $this->add_error_to_migrations_ran(sprintf(__("Could not run data migrations because: %s", "event_espresso"), $message)); |
|
550 | 550 | return array( |
551 | 551 | 'records_to_migrate'=>1, |
552 | 552 | 'records_migrated'=>0, |
@@ -556,16 +556,16 @@ discard block |
||
556 | 556 | ); |
557 | 557 | } |
558 | 558 | //ok so we definitely have a data migration script |
559 | - try{ |
|
559 | + try { |
|
560 | 560 | //how big of a bite do we want to take? Allow users to easily override via their wp-config |
561 | - if( ! absint( $step_size ) > 0 ){ |
|
562 | - $step_size = defined( 'EE_MIGRATION_STEP_SIZE' ) && absint( EE_MIGRATION_STEP_SIZE ) ? EE_MIGRATION_STEP_SIZE : EE_Data_Migration_Manager::step_size; |
|
561 | + if ( ! absint($step_size) > 0) { |
|
562 | + $step_size = defined('EE_MIGRATION_STEP_SIZE') && absint(EE_MIGRATION_STEP_SIZE) ? EE_MIGRATION_STEP_SIZE : EE_Data_Migration_Manager::step_size; |
|
563 | 563 | } |
564 | 564 | //do what we came to do! |
565 | 565 | $currently_executing_script->migration_step($step_size); |
566 | 566 | //can we wrap it up and verify default data? |
567 | 567 | $init_dbs = false; |
568 | - switch($currently_executing_script->get_status()){ |
|
568 | + switch ($currently_executing_script->get_status()) { |
|
569 | 569 | case EE_Data_Migration_Manager::status_continue: |
570 | 570 | $response_array = array( |
571 | 571 | 'records_to_migrate'=>$currently_executing_script->count_records_to_migrate(), |
@@ -577,16 +577,16 @@ discard block |
||
577 | 577 | case EE_Data_Migration_Manager::status_completed: |
578 | 578 | //ok so THAT script has completed |
579 | 579 | $this->update_current_database_state_to($this->script_migrates_to_version($current_script_name)); |
580 | - $response_array = array( |
|
580 | + $response_array = array( |
|
581 | 581 | 'records_to_migrate'=>$currently_executing_script->count_records_to_migrate(), |
582 | 582 | 'records_migrated'=>$currently_executing_script->count_records_migrated(), |
583 | 583 | 'status'=> EE_Data_Migration_Manager::status_completed, |
584 | 584 | 'message'=>$currently_executing_script->get_feedback_message(), |
585 | - 'script'=> sprintf(__("%s Completed",'event_espresso'),$currently_executing_script->pretty_name()) |
|
585 | + 'script'=> sprintf(__("%s Completed", 'event_espresso'), $currently_executing_script->pretty_name()) |
|
586 | 586 | ); |
587 | 587 | //check if there are any more after this one. |
588 | 588 | $scripts_remaining = $this->check_for_applicable_data_migration_scripts(); |
589 | - if( ! $scripts_remaining ){ |
|
589 | + if ( ! $scripts_remaining) { |
|
590 | 590 | //we should be good to allow them to exit maintenance mode now |
591 | 591 | EE_Maintenance_Mode::instance()->set_maintenance_level(intval(EE_Maintenance_Mode::level_0_not_in_maintenance)); |
592 | 592 | ////huh, no more scripts to run... apparently we're done! |
@@ -600,39 +600,39 @@ discard block |
||
600 | 600 | 'records_to_migrate'=>$currently_executing_script->count_records_to_migrate(), |
601 | 601 | 'records_migrated'=>$currently_executing_script->count_records_migrated(), |
602 | 602 | 'status'=> $currently_executing_script->get_status(), |
603 | - 'message'=> sprintf(__("Minor errors occurred during %s: %s", "event_espresso"), $currently_executing_script->pretty_name(), implode(", ",$currently_executing_script->get_errors())), |
|
603 | + 'message'=> sprintf(__("Minor errors occurred during %s: %s", "event_espresso"), $currently_executing_script->pretty_name(), implode(", ", $currently_executing_script->get_errors())), |
|
604 | 604 | 'script'=>$currently_executing_script->pretty_name() |
605 | 605 | ); |
606 | 606 | break; |
607 | 607 | } |
608 | - }catch(Exception $e){ |
|
608 | + } catch (Exception $e) { |
|
609 | 609 | //ok so some exception was thrown which killed the data migration script |
610 | 610 | //double-check we have a real script |
611 | - if($currently_executing_script instanceof EE_Data_Migration_Script_Base){ |
|
611 | + if ($currently_executing_script instanceof EE_Data_Migration_Script_Base) { |
|
612 | 612 | $script_name = $currently_executing_script->pretty_name(); |
613 | 613 | $currently_executing_script->set_broken(); |
614 | 614 | $currently_executing_script->add_error($e->getMessage()); |
615 | - }else{ |
|
615 | + } else { |
|
616 | 616 | $script_name = __("Error getting Migration Script", "event_espresso"); |
617 | 617 | } |
618 | 618 | $response_array = array( |
619 | 619 | 'records_to_migrate'=>1, |
620 | 620 | 'records_migrated'=>0, |
621 | 621 | 'status'=>self::status_fatal_error, |
622 | - 'message'=> sprintf(__("A fatal error occurred during the migration: %s", "event_espresso"),$e->getMessage()), |
|
622 | + 'message'=> sprintf(__("A fatal error occurred during the migration: %s", "event_espresso"), $e->getMessage()), |
|
623 | 623 | 'script'=>$script_name |
624 | 624 | ); |
625 | 625 | } |
626 | 626 | $successful_save = $this->_save_migrations_ran(); |
627 | - if($successful_save !== TRUE){ |
|
627 | + if ($successful_save !== TRUE) { |
|
628 | 628 | //ok so the current wp option didn't save. that's tricky, because we'd like to update it |
629 | 629 | //and mark it as having a fatal error, but remember- WE CAN'T SAVE THIS WP OPTION! |
630 | 630 | //however, if we throw an exception, and return that, then the next request |
631 | 631 | //won't have as much info in it, and it may be able to save |
632 | - throw new EE_Error(sprintf(__("The error '%s' occurred updating the status of the migration. This is a FATAL ERROR, but the error is preventing the system from remembering that. Please contact event espresso support.", "event_espresso"),$successful_save)); |
|
632 | + throw new EE_Error(sprintf(__("The error '%s' occurred updating the status of the migration. This is a FATAL ERROR, but the error is preventing the system from remembering that. Please contact event espresso support.", "event_espresso"), $successful_save)); |
|
633 | 633 | } |
634 | 634 | //if we're all done, initialize EE plugins' default data etc. |
635 | - if( $init_dbs ) { |
|
635 | + if ($init_dbs) { |
|
636 | 636 | $this->initialize_db_for_enqueued_ee_plugins(); |
637 | 637 | } |
638 | 638 | return $response_array; |
@@ -650,23 +650,23 @@ discard block |
||
650 | 650 | * 'message'=>a string, containing any message you want to show to the user. We may decide to split this up into errors, notifications, and successes |
651 | 651 | * 'script'=>a pretty name of the script currently running |
652 | 652 | */ |
653 | - public function response_to_migration_ajax_request(){ |
|
653 | + public function response_to_migration_ajax_request() { |
|
654 | 654 | // //start output buffer just to make sure we don't mess up the json |
655 | 655 | ob_start(); |
656 | - try{ |
|
656 | + try { |
|
657 | 657 | $response = $this->migration_step(); |
658 | - }catch(Exception $e){ |
|
658 | + } catch (Exception $e) { |
|
659 | 659 | $response = array( |
660 | 660 | 'records_to_migrate'=>0, |
661 | 661 | 'records_migrated'=>0, |
662 | 662 | 'status'=> EE_Data_Migration_Manager::status_fatal_error, |
663 | - 'message'=> sprintf(__("Unknown fatal error occurred: %s", "event_espresso"),$e->getMessage()), |
|
663 | + 'message'=> sprintf(__("Unknown fatal error occurred: %s", "event_espresso"), $e->getMessage()), |
|
664 | 664 | 'script'=>'Unknown'); |
665 | 665 | $this->add_error_to_migrations_ran($e->getMessage()."; Stack trace:".$e->getTraceAsString()); |
666 | 666 | } |
667 | 667 | $warnings_etc = @ob_get_contents(); |
668 | 668 | ob_end_clean(); |
669 | - $response['message'] .=$warnings_etc; |
|
669 | + $response['message'] .= $warnings_etc; |
|
670 | 670 | return $response; |
671 | 671 | } |
672 | 672 | |
@@ -679,14 +679,14 @@ discard block |
||
679 | 679 | * } |
680 | 680 | * @return void |
681 | 681 | */ |
682 | - public function update_current_database_state_to($slug_and_version = null){ |
|
683 | - if( ! $slug_and_version ){ |
|
682 | + public function update_current_database_state_to($slug_and_version = null) { |
|
683 | + if ( ! $slug_and_version) { |
|
684 | 684 | //no version was provided, assume it should be at the current code version |
685 | 685 | $slug_and_version = array('slug' => 'Core', 'version' => espresso_version()); |
686 | 686 | } |
687 | 687 | $current_database_state = get_option(self::current_database_state); |
688 | - $current_database_state[ $slug_and_version[ 'slug' ] ]=$slug_and_version[ 'version' ]; |
|
689 | - update_option(self::current_database_state,$current_database_state); |
|
688 | + $current_database_state[$slug_and_version['slug']] = $slug_and_version['version']; |
|
689 | + update_option(self::current_database_state, $current_database_state); |
|
690 | 690 | } |
691 | 691 | |
692 | 692 | /** |
@@ -697,20 +697,20 @@ discard block |
||
697 | 697 | * } |
698 | 698 | * @return boolean |
699 | 699 | */ |
700 | - public function database_needs_updating_to( $slug_and_version ) { |
|
700 | + public function database_needs_updating_to($slug_and_version) { |
|
701 | 701 | |
702 | - $slug = $slug_and_version[ 'slug' ]; |
|
703 | - $version = $slug_and_version[ 'version' ]; |
|
702 | + $slug = $slug_and_version['slug']; |
|
703 | + $version = $slug_and_version['version']; |
|
704 | 704 | $current_database_state = get_option(self::current_database_state); |
705 | - if( ! isset( $current_database_state[ $slug ] ) ) { |
|
705 | + if ( ! isset($current_database_state[$slug])) { |
|
706 | 706 | return true; |
707 | - }else{ |
|
707 | + } else { |
|
708 | 708 | //just compare the first 3 parts of version string, eg "4.7.1", not "4.7.1.dev.032" because DBs shouldn't change on nano version changes |
709 | - $version_parts_current_db_state = array_slice( explode('.', $current_database_state[ $slug ] ), 0, 3); |
|
710 | - $version_parts_of_provided_db_state = array_slice( explode( '.', $version ), 0, 3 ); |
|
709 | + $version_parts_current_db_state = array_slice(explode('.', $current_database_state[$slug]), 0, 3); |
|
710 | + $version_parts_of_provided_db_state = array_slice(explode('.', $version), 0, 3); |
|
711 | 711 | $needs_updating = false; |
712 | - foreach($version_parts_current_db_state as $offset => $version_part_in_current_db_state ) { |
|
713 | - if( $version_part_in_current_db_state < $version_parts_of_provided_db_state[ $offset ] ) { |
|
712 | + foreach ($version_parts_current_db_state as $offset => $version_part_in_current_db_state) { |
|
713 | + if ($version_part_in_current_db_state < $version_parts_of_provided_db_state[$offset]) { |
|
714 | 714 | $needs_updating = true; |
715 | 715 | break; |
716 | 716 | } |
@@ -728,33 +728,33 @@ discard block |
||
728 | 728 | * @return array keys are expected classnames, values are their filepaths |
729 | 729 | * @throws \EE_Error |
730 | 730 | */ |
731 | - public function get_all_data_migration_scripts_available(){ |
|
732 | - if( ! $this->_data_migration_class_to_filepath_map){ |
|
731 | + public function get_all_data_migration_scripts_available() { |
|
732 | + if ( ! $this->_data_migration_class_to_filepath_map) { |
|
733 | 733 | $this->_data_migration_class_to_filepath_map = array(); |
734 | - foreach($this->get_data_migration_script_folders() as $folder_path){ |
|
734 | + foreach ($this->get_data_migration_script_folders() as $folder_path) { |
|
735 | 735 | $folder_path = EEH_File::end_with_directory_separator($folder_path); |
736 | - $files = glob( $folder_path. '*.dms.php' ); |
|
736 | + $files = glob($folder_path.'*.dms.php'); |
|
737 | 737 | |
738 | - if ( empty( $files ) ) { |
|
738 | + if (empty($files)) { |
|
739 | 739 | continue; |
740 | 740 | } |
741 | 741 | |
742 | - foreach($files as $file){ |
|
743 | - $pos_of_last_slash = strrpos($file,DS); |
|
742 | + foreach ($files as $file) { |
|
743 | + $pos_of_last_slash = strrpos($file, DS); |
|
744 | 744 | $classname = str_replace('.dms.php', '', substr($file, $pos_of_last_slash + 1)); |
745 | - $migrates_to = $this->script_migrates_to_version( $classname ); |
|
746 | - $slug = $migrates_to[ 'slug' ]; |
|
745 | + $migrates_to = $this->script_migrates_to_version($classname); |
|
746 | + $slug = $migrates_to['slug']; |
|
747 | 747 | //check that the slug as contained in the DMS is associated with |
748 | 748 | //the slug of an addon or core |
749 | - if( $slug !== 'Core' ){ |
|
750 | - if( ! EE_Registry::instance()->get_addon_by_name( $slug ) ) { |
|
749 | + if ($slug !== 'Core') { |
|
750 | + if ( ! EE_Registry::instance()->get_addon_by_name($slug)) { |
|
751 | 751 | EE_Error::doing_it_wrong( |
752 | 752 | __FUNCTION__, |
753 | 753 | sprintf( |
754 | - __( 'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', 'event_espresso' ), |
|
754 | + __('The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', 'event_espresso'), |
|
755 | 755 | $classname, |
756 | 756 | $slug, |
757 | - implode(', ', array_keys( EE_Registry::instance()->get_addons_by_name() ) ) |
|
757 | + implode(', ', array_keys(EE_Registry::instance()->get_addons_by_name())) |
|
758 | 758 | ), |
759 | 759 | '4.3.0.alpha.019' |
760 | 760 | ); |
@@ -777,7 +777,7 @@ discard block |
||
777 | 777 | * from each addon, and check if they need updating, |
778 | 778 | * @return boolean |
779 | 779 | */ |
780 | - public function addons_need_updating(){ |
|
780 | + public function addons_need_updating() { |
|
781 | 781 | return false; |
782 | 782 | } |
783 | 783 | /** |
@@ -786,25 +786,25 @@ discard block |
||
786 | 786 | * @param string $error_message |
787 | 787 | * @throws EE_Error |
788 | 788 | */ |
789 | - public function add_error_to_migrations_ran($error_message){ |
|
789 | + public function add_error_to_migrations_ran($error_message) { |
|
790 | 790 | //get last-ran migration script |
791 | 791 | global $wpdb; |
792 | - $last_migration_script_option = $wpdb->get_row("SELECT * FROM $wpdb->options WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id DESC LIMIT 1",ARRAY_A); |
|
792 | + $last_migration_script_option = $wpdb->get_row("SELECT * FROM $wpdb->options WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id DESC LIMIT 1", ARRAY_A); |
|
793 | 793 | |
794 | 794 | $last_ran_migration_script_properties = isset($last_migration_script_option['option_value']) ? maybe_unserialize($last_migration_script_option['option_value']) : null; |
795 | 795 | //now, tread lightly because we're here because a FATAL non-catchable error |
796 | 796 | //was thrown last time when we were trying to run a data migration script |
797 | 797 | //so the fatal error could have happened while getting the migration script |
798 | 798 | //or doing running it... |
799 | - $versions_migrated_to = isset($last_migration_script_option['option_name']) ? str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix,"",$last_migration_script_option['option_name']) : null; |
|
799 | + $versions_migrated_to = isset($last_migration_script_option['option_name']) ? str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $last_migration_script_option['option_name']) : null; |
|
800 | 800 | |
801 | 801 | //check if it THINKS its a data migration script and especially if it's one that HASN'T finished yet |
802 | 802 | //because if it has finished, then it obviously couldn't be the cause of this error, right? (because its all done) |
803 | - if(isset($last_ran_migration_script_properties['class']) && isset($last_ran_migration_script_properties['_status']) && $last_ran_migration_script_properties['_status'] != self::status_completed){ |
|
803 | + if (isset($last_ran_migration_script_properties['class']) && isset($last_ran_migration_script_properties['_status']) && $last_ran_migration_script_properties['_status'] != self::status_completed) { |
|
804 | 804 | //ok then just add this error to its list of errors |
805 | 805 | $last_ran_migration_script_properties['_errors'][] = $error_message; |
806 | 806 | $last_ran_migration_script_properties['_status'] = self::status_fatal_error; |
807 | - }else{ |
|
807 | + } else { |
|
808 | 808 | //so we don't even know which script was last running |
809 | 809 | //use the data migration error stub, which is designed specifically for this type of thing |
810 | 810 | $general_migration_error = new EE_DMS_Unknown_1_0_0(); |
@@ -814,39 +814,39 @@ discard block |
||
814 | 814 | $versions_migrated_to = 'Unknown.1.0.0'; |
815 | 815 | //now just to make sure appears as last (in case the were previously a fatal error like this) |
816 | 816 | //delete the old one |
817 | - delete_option( self::data_migration_script_option_prefix . $versions_migrated_to ); |
|
817 | + delete_option(self::data_migration_script_option_prefix.$versions_migrated_to); |
|
818 | 818 | } |
819 | - update_option(self::data_migration_script_option_prefix.$versions_migrated_to,$last_ran_migration_script_properties); |
|
819 | + update_option(self::data_migration_script_option_prefix.$versions_migrated_to, $last_ran_migration_script_properties); |
|
820 | 820 | |
821 | 821 | } |
822 | 822 | /** |
823 | 823 | * saves what data migrations have ran to the database |
824 | 824 | * @return mixed TRUE if successfully saved migrations ran, string if an error occurred |
825 | 825 | */ |
826 | - protected function _save_migrations_ran(){ |
|
827 | - if($this->_data_migrations_ran == null){ |
|
826 | + protected function _save_migrations_ran() { |
|
827 | + if ($this->_data_migrations_ran == null) { |
|
828 | 828 | $this->get_data_migrations_ran(); |
829 | 829 | } |
830 | 830 | //now, we don't want to save actual classes to the DB because that's messy |
831 | 831 | $successful_updates = true; |
832 | - foreach($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin){ |
|
833 | - foreach($migrations_ran_for_plugin as $version_string => $array_or_migration_obj){ |
|
832 | + foreach ($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin) { |
|
833 | + foreach ($migrations_ran_for_plugin as $version_string => $array_or_migration_obj) { |
|
834 | 834 | // echo "saving migration script to $version_string<br>"; |
835 | 835 | $plugin_slug_for_use_in_option_name = $plugin_slug."."; |
836 | 836 | $option_name = self::data_migration_script_option_prefix.$plugin_slug_for_use_in_option_name.$version_string; |
837 | 837 | $old_option_value = get_option($option_name); |
838 | - if($array_or_migration_obj instanceof EE_Data_Migration_Script_Base){ |
|
838 | + if ($array_or_migration_obj instanceof EE_Data_Migration_Script_Base) { |
|
839 | 839 | $script_array_for_saving = $array_or_migration_obj->properties_as_array(); |
840 | - if( $old_option_value != $script_array_for_saving){ |
|
841 | - $successful_updates = update_option($option_name,$script_array_for_saving); |
|
840 | + if ($old_option_value != $script_array_for_saving) { |
|
841 | + $successful_updates = update_option($option_name, $script_array_for_saving); |
|
842 | 842 | } |
843 | - }else{//we don't know what this array-thing is. So just save it as-is |
|
843 | + } else {//we don't know what this array-thing is. So just save it as-is |
|
844 | 844 | // $array_of_migrations[$version_string] = $array_or_migration_obj; |
845 | - if($old_option_value != $array_or_migration_obj){ |
|
846 | - $successful_updates = update_option($option_name,$array_or_migration_obj); |
|
845 | + if ($old_option_value != $array_or_migration_obj) { |
|
846 | + $successful_updates = update_option($option_name, $array_or_migration_obj); |
|
847 | 847 | } |
848 | 848 | } |
849 | - if( ! $successful_updates ){ |
|
849 | + if ( ! $successful_updates) { |
|
850 | 850 | global $wpdb; |
851 | 851 | return $wpdb->last_error; |
852 | 852 | } |
@@ -870,17 +870,17 @@ discard block |
||
870 | 870 | * @return EE_Data_Migration_Script_Base |
871 | 871 | * @throws EE_Error |
872 | 872 | */ |
873 | - function _instantiate_script_from_properties_array($properties_array){ |
|
874 | - if( ! isset($properties_array['class'])){ |
|
875 | - throw new EE_Error(sprintf(__("Properties array has no 'class' properties. Here's what it has: %s", "event_espresso"),implode(",",$properties_array))); |
|
873 | + function _instantiate_script_from_properties_array($properties_array) { |
|
874 | + if ( ! isset($properties_array['class'])) { |
|
875 | + throw new EE_Error(sprintf(__("Properties array has no 'class' properties. Here's what it has: %s", "event_espresso"), implode(",", $properties_array))); |
|
876 | 876 | } |
877 | 877 | $class_name = $properties_array['class']; |
878 | - if( ! class_exists($class_name)){ |
|
879 | - throw new EE_Error(sprintf(__("There is no migration script named %s", "event_espresso"),$class_name)); |
|
878 | + if ( ! class_exists($class_name)) { |
|
879 | + throw new EE_Error(sprintf(__("There is no migration script named %s", "event_espresso"), $class_name)); |
|
880 | 880 | } |
881 | 881 | $class = new $class_name; |
882 | - if( ! $class instanceof EE_Data_Migration_Script_Base){ |
|
883 | - throw new EE_Error(sprintf(__("Class '%s' is supposed to be a migration script. Its not, its a '%s'", "event_espresso"),$class_name,get_class($class))); |
|
882 | + if ( ! $class instanceof EE_Data_Migration_Script_Base) { |
|
883 | + throw new EE_Error(sprintf(__("Class '%s' is supposed to be a migration script. Its not, its a '%s'", "event_espresso"), $class_name, get_class($class))); |
|
884 | 884 | } |
885 | 885 | $class->instantiate_from_array_of_properties($properties_array); |
886 | 886 | return $class; |
@@ -892,25 +892,25 @@ discard block |
||
892 | 892 | * @param string $plugin_slug the slug for the ee plugin we are searching for. Default is 'Core' |
893 | 893 | * @return string |
894 | 894 | */ |
895 | - public function get_most_up_to_date_dms($plugin_slug = 'Core'){ |
|
895 | + public function get_most_up_to_date_dms($plugin_slug = 'Core') { |
|
896 | 896 | $class_to_filepath_map = $this->get_all_data_migration_scripts_available(); |
897 | 897 | $most_up_to_date_dms_classname = NULL; |
898 | - foreach($class_to_filepath_map as $classname => $filepath){ |
|
899 | - if($most_up_to_date_dms_classname === NULL){ |
|
898 | + foreach ($class_to_filepath_map as $classname => $filepath) { |
|
899 | + if ($most_up_to_date_dms_classname === NULL) { |
|
900 | 900 | $migrates_to = $this->script_migrates_to_version($classname); |
901 | - $this_plugin_slug = $migrates_to[ 'slug' ]; |
|
901 | + $this_plugin_slug = $migrates_to['slug']; |
|
902 | 902 | // $version_string = $migrates_to[ 'version' ]; |
903 | 903 | // $details = $this->parse_dms_classname($classname); |
904 | - if($this_plugin_slug == $plugin_slug){ |
|
904 | + if ($this_plugin_slug == $plugin_slug) { |
|
905 | 905 | //if it's for core, it wins |
906 | 906 | $most_up_to_date_dms_classname = $classname; |
907 | 907 | } |
908 | 908 | //if it wasn't for core, we must keep searching for one that is! |
909 | 909 | continue; |
910 | - }else{ |
|
911 | - $champion_migrates_to= $this->script_migrates_to_version($most_up_to_date_dms_classname); |
|
910 | + } else { |
|
911 | + $champion_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms_classname); |
|
912 | 912 | $contender_migrates_to = $this->script_migrates_to_version($classname); |
913 | - if($contender_migrates_to[ 'slug' ] == $plugin_slug && version_compare($champion_migrates_to[ 'version' ], $contender_migrates_to[ 'version' ], '<')){ |
|
913 | + if ($contender_migrates_to['slug'] == $plugin_slug && version_compare($champion_migrates_to['version'], $contender_migrates_to['version'], '<')) { |
|
914 | 914 | //so the contenders version is higher and its for Core |
915 | 915 | $most_up_to_date_dms_classname = $classname; |
916 | 916 | } |
@@ -930,11 +930,11 @@ discard block |
||
930 | 930 | * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
931 | 931 | * @return EE_Data_Migration_Script_Base |
932 | 932 | */ |
933 | - public function get_migration_ran( $version, $plugin_slug = 'Core' ) { |
|
933 | + public function get_migration_ran($version, $plugin_slug = 'Core') { |
|
934 | 934 | $migrations_ran = $this->get_data_migrations_ran(); |
935 | - if( isset( $migrations_ran[ $plugin_slug ] ) && isset( $migrations_ran[ $plugin_slug ][ $version ] ) ){ |
|
936 | - return $migrations_ran[ $plugin_slug ][ $version ]; |
|
937 | - }else{ |
|
935 | + if (isset($migrations_ran[$plugin_slug]) && isset($migrations_ran[$plugin_slug][$version])) { |
|
936 | + return $migrations_ran[$plugin_slug][$version]; |
|
937 | + } else { |
|
938 | 938 | return NULL; |
939 | 939 | } |
940 | 940 | } |
@@ -946,20 +946,20 @@ discard block |
||
946 | 946 | * @return bool |
947 | 947 | * @throws \EE_Error |
948 | 948 | */ |
949 | - public function reattempt(){ |
|
949 | + public function reattempt() { |
|
950 | 950 | //find if the last-ran script was borked |
951 | 951 | //set it as being non-borked (we shouldn't ever get DMSs that we don't recognize) |
952 | 952 | //add an 'error' saying that we attempted to reset |
953 | 953 | //does it have a stage that was borked too? if so make it no longer borked |
954 | 954 | //add an 'error' saying we attempted to reset |
955 | 955 | $last_ran_script = $this->get_last_ran_script(); |
956 | - if( $last_ran_script instanceof EE_DMS_Unknown_1_0_0 ){ |
|
956 | + if ($last_ran_script instanceof EE_DMS_Unknown_1_0_0) { |
|
957 | 957 | //if it was an error DMS, just mark it as complete (if another error occurs it will overwrite it) |
958 | 958 | $last_ran_script->set_completed(); |
959 | - }elseif( $last_ran_script instanceof EE_Data_Migration_Script_Base ) { |
|
959 | + }elseif ($last_ran_script instanceof EE_Data_Migration_Script_Base) { |
|
960 | 960 | $last_ran_script->reattempt(); |
961 | - }else{ |
|
962 | - throw new EE_Error( sprintf( __( 'Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s', 'event_espresso' ), print_r( $last_ran_script, true ) ) ); |
|
961 | + } else { |
|
962 | + throw new EE_Error(sprintf(__('Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s', 'event_espresso'), print_r($last_ran_script, true))); |
|
963 | 963 | } |
964 | 964 | return $this->_save_migrations_ran(); |
965 | 965 | } |
@@ -969,19 +969,19 @@ discard block |
||
969 | 969 | * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
970 | 970 | * @return boolean |
971 | 971 | */ |
972 | - public function migration_has_ran( $version, $plugin_slug = 'Core' ) { |
|
973 | - return $this->get_migration_ran( $version, $plugin_slug ) !== NULL; |
|
972 | + public function migration_has_ran($version, $plugin_slug = 'Core') { |
|
973 | + return $this->get_migration_ran($version, $plugin_slug) !== NULL; |
|
974 | 974 | } |
975 | 975 | /** |
976 | 976 | * Enqueues this ee plugin to have its data initialized |
977 | 977 | * @param string $plugin_slug either 'Core' or EE_Addon::name()'s return value |
978 | 978 | */ |
979 | - public function enqueue_db_initialization_for( $plugin_slug ) { |
|
979 | + public function enqueue_db_initialization_for($plugin_slug) { |
|
980 | 980 | $queue = $this->get_db_initialization_queue(); |
981 | - if( ! in_array( $plugin_slug, $queue ) ) { |
|
981 | + if ( ! in_array($plugin_slug, $queue)) { |
|
982 | 982 | $queue[] = $plugin_slug; |
983 | 983 | } |
984 | - update_option( self::db_init_queue_option_name, $queue ); |
|
984 | + update_option(self::db_init_queue_option_name, $queue); |
|
985 | 985 | } |
986 | 986 | /** |
987 | 987 | * Calls EE_Addon::initialize_db_if_no_migrations_required() on each addon |
@@ -991,26 +991,26 @@ discard block |
||
991 | 991 | public function initialize_db_for_enqueued_ee_plugins() { |
992 | 992 | // EEH_Debug_Tools::instance()->start_timer( 'initialize_db_for_enqueued_ee_plugins' ); |
993 | 993 | $queue = $this->get_db_initialization_queue(); |
994 | - foreach( $queue as $plugin_slug ) { |
|
995 | - $most_up_to_date_dms = $this->get_most_up_to_date_dms( $plugin_slug ); |
|
996 | - if( ! $most_up_to_date_dms ) { |
|
994 | + foreach ($queue as $plugin_slug) { |
|
995 | + $most_up_to_date_dms = $this->get_most_up_to_date_dms($plugin_slug); |
|
996 | + if ( ! $most_up_to_date_dms) { |
|
997 | 997 | //if there is NO DMS for this plugin, obviously there's no schema to verify anyways |
998 | 998 | $verify_db = false; |
999 | - }else{ |
|
1000 | - $most_up_to_date_dms_migrates_to = $this->script_migrates_to_version( $most_up_to_date_dms ); |
|
1001 | - $verify_db = $this->database_needs_updating_to( $most_up_to_date_dms_migrates_to ); |
|
999 | + } else { |
|
1000 | + $most_up_to_date_dms_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms); |
|
1001 | + $verify_db = $this->database_needs_updating_to($most_up_to_date_dms_migrates_to); |
|
1002 | 1002 | } |
1003 | - if( $plugin_slug == 'Core' ){ |
|
1003 | + if ($plugin_slug == 'Core') { |
|
1004 | 1004 | EE_System::instance()->initialize_db_if_no_migrations_required( |
1005 | 1005 | false, |
1006 | 1006 | $verify_db |
1007 | 1007 | ); |
1008 | - }else{ |
|
1008 | + } else { |
|
1009 | 1009 | //just loop through the addons to make sure their database is setup |
1010 | - foreach( EE_Registry::instance()->addons as $addon ) { |
|
1011 | - if( $addon->name() == $plugin_slug ) { |
|
1010 | + foreach (EE_Registry::instance()->addons as $addon) { |
|
1011 | + if ($addon->name() == $plugin_slug) { |
|
1012 | 1012 | |
1013 | - $addon->initialize_db_if_no_migrations_required( $verify_db ); |
|
1013 | + $addon->initialize_db_if_no_migrations_required($verify_db); |
|
1014 | 1014 | break; |
1015 | 1015 | } |
1016 | 1016 | } |
@@ -1020,7 +1020,7 @@ discard block |
||
1020 | 1020 | // EEH_Debug_Tools::instance()->show_times(); |
1021 | 1021 | //because we just initialized the DBs for the enqueued ee plugins |
1022 | 1022 | //we don't need to keep remembering which ones needed to be initialized |
1023 | - delete_option( self::db_init_queue_option_name ); |
|
1023 | + delete_option(self::db_init_queue_option_name); |
|
1024 | 1024 | } |
1025 | 1025 | |
1026 | 1026 | /** |
@@ -1029,8 +1029,8 @@ discard block |
||
1029 | 1029 | * 'Core', or the return value of EE_Addon::name() for an addon |
1030 | 1030 | * @return array |
1031 | 1031 | */ |
1032 | - public function get_db_initialization_queue(){ |
|
1033 | - return get_option ( self::db_init_queue_option_name, array() ); |
|
1032 | + public function get_db_initialization_queue() { |
|
1033 | + return get_option(self::db_init_queue_option_name, array()); |
|
1034 | 1034 | } |
1035 | 1035 | |
1036 | 1036 | /** |
@@ -1039,13 +1039,13 @@ discard block |
||
1039 | 1039 | * @throws \EE_Error |
1040 | 1040 | */ |
1041 | 1041 | protected function _get_table_analysis() { |
1042 | - if( $this->_table_analysis instanceof TableAnalysis ) { |
|
1042 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
1043 | 1043 | return $this->_table_analysis; |
1044 | 1044 | } else { |
1045 | 1045 | throw new \EE_Error( |
1046 | 1046 | sprintf( |
1047 | - __( 'Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
1048 | - get_class( $this ) |
|
1047 | + __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
1048 | + get_class($this) |
|
1049 | 1049 | ) |
1050 | 1050 | ); |
1051 | 1051 | } |
@@ -1057,13 +1057,13 @@ discard block |
||
1057 | 1057 | * @throws \EE_Error |
1058 | 1058 | */ |
1059 | 1059 | protected function _get_table_manager() { |
1060 | - if( $this->_table_manager instanceof TableManager ) { |
|
1060 | + if ($this->_table_manager instanceof TableManager) { |
|
1061 | 1061 | return $this->_table_manager; |
1062 | 1062 | } else { |
1063 | 1063 | throw new \EE_Error( |
1064 | 1064 | sprintf( |
1065 | - __( 'Table manager class on class %1$s is not set properly.', 'event_espresso'), |
|
1066 | - get_class( $this ) |
|
1065 | + __('Table manager class on class %1$s is not set properly.', 'event_espresso'), |
|
1066 | + get_class($this) |
|
1067 | 1067 | ) |
1068 | 1068 | ); |
1069 | 1069 | } |