@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -17,407 +17,407 @@ discard block |
||
17 | 17 | class EE_Payment_Method_Manager |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * instance of the EE_Payment_Method_Manager object |
|
22 | - * |
|
23 | - * @var $_instance |
|
24 | - * @access private |
|
25 | - */ |
|
26 | - private static $_instance; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var array keys are classnames without 'EE_PMT_', values are their filepaths |
|
30 | - */ |
|
31 | - protected $_payment_method_types = array(); |
|
32 | - |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @singleton method used to instantiate class object |
|
37 | - * @access public |
|
38 | - * @return EE_Payment_Method_Manager instance |
|
39 | - */ |
|
40 | - public static function instance() |
|
41 | - { |
|
42 | - // check if class object is instantiated, and instantiated properly |
|
43 | - if ( ! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
44 | - self::$_instance = new self(); |
|
45 | - } |
|
46 | - EE_Registry::instance()->load_lib('PMT_Base'); |
|
47 | - return self::$_instance; |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * Resets the instance and returns a new one |
|
54 | - * |
|
55 | - * @return EE_Payment_Method_Manager |
|
56 | - */ |
|
57 | - public static function reset() |
|
58 | - { |
|
59 | - self::$_instance = null; |
|
60 | - return self::instance(); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * If necessary, re-register payment methods |
|
67 | - * |
|
68 | - * @param boolean $force_recheck whether to recheck for payment method types, |
|
69 | - * or just re-use the PMTs we found last time we checked during this request (if |
|
70 | - * we have not yet checked during this request, then we need to check anyways) |
|
71 | - */ |
|
72 | - public function maybe_register_payment_methods($force_recheck = false) |
|
73 | - { |
|
74 | - if ( ! $this->_payment_method_types || $force_recheck) { |
|
75 | - $this->_register_payment_methods(); |
|
76 | - //if in admin lets ensure caps are set. |
|
77 | - if (is_admin()) { |
|
78 | - add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array($this, 'add_payment_method_caps')); |
|
79 | - EE_Registry::instance()->CAP->init_caps(); |
|
80 | - } |
|
81 | - } |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * register_payment_methods |
|
88 | - * |
|
89 | - * @return array |
|
90 | - */ |
|
91 | - protected function _register_payment_methods() |
|
92 | - { |
|
93 | - // grab list of installed modules |
|
94 | - $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
95 | - // filter list of modules to register |
|
96 | - $pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
97 | - $pm_to_register); |
|
98 | - // loop through folders |
|
99 | - foreach ($pm_to_register as $pm_path) { |
|
100 | - $this->register_payment_method($pm_path); |
|
101 | - } |
|
102 | - do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods'); |
|
103 | - // filter list of installed modules |
|
104 | - //keep them organized alphabetically by the payment method type's name |
|
105 | - ksort($this->_payment_method_types); |
|
106 | - return apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', |
|
107 | - $this->_payment_method_types); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * register_payment_method- makes core aware of this payment method |
|
114 | - * |
|
115 | - * @access public |
|
116 | - * @param string $payment_method_path - full path up to and including payment method folder |
|
117 | - * @return boolean |
|
118 | - */ |
|
119 | - public function register_payment_method($payment_method_path = '') |
|
120 | - { |
|
121 | - do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path); |
|
122 | - $module_ext = '.pm.php'; |
|
123 | - // make all separators match |
|
124 | - $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS); |
|
125 | - // grab and sanitize module name |
|
126 | - $module_dir = basename($payment_method_path); |
|
127 | - // create classname from module directory name |
|
128 | - $module = str_replace(' ', '_', str_replace('_', ' ', $module_dir)); |
|
129 | - // add class prefix |
|
130 | - $module_class = 'EE_PMT_' . $module; |
|
131 | - // does the module exist ? |
|
132 | - if ( ! is_readable($payment_method_path . DS . $module_class . $module_ext)) { |
|
133 | - $msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.', |
|
134 | - 'event_espresso'), $module); |
|
135 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
136 | - return false; |
|
137 | - } |
|
138 | - if (WP_DEBUG === true) { |
|
139 | - EEH_Debug_Tools::instance()->start_timer(); |
|
140 | - } |
|
141 | - // load the module class file |
|
142 | - require_once($payment_method_path . DS . $module_class . $module_ext); |
|
143 | - if (WP_DEBUG === true) { |
|
144 | - EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class"); |
|
145 | - } |
|
146 | - // verify that class exists |
|
147 | - if ( ! class_exists($module_class)) { |
|
148 | - $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
149 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
150 | - return false; |
|
151 | - } |
|
152 | - // add to array of registered modules |
|
153 | - $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext; |
|
154 | - return true; |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * Checks if a payment method has been registered, and if so includes it |
|
161 | - * |
|
162 | - * @param string $payment_method_name like 'Paypal_Pro', (ie classname without the prefix 'EEPM_') |
|
163 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
164 | - * @return boolean |
|
165 | - */ |
|
166 | - public function payment_method_type_exists($payment_method_name, $force_recheck = false) |
|
167 | - { |
|
168 | - if ( |
|
169 | - $force_recheck |
|
170 | - || ! is_array($this->_payment_method_types) |
|
171 | - || ! isset($this->_payment_method_types[$payment_method_name]) |
|
172 | - ) { |
|
173 | - $this->maybe_register_payment_methods($force_recheck); |
|
174 | - } |
|
175 | - if (isset($this->_payment_method_types[$payment_method_name])) { |
|
176 | - require_once($this->_payment_method_types[$payment_method_name]); |
|
177 | - return true; |
|
178 | - } else { |
|
179 | - return false; |
|
180 | - } |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * Returns all the classnames of the various payment method types |
|
187 | - * |
|
188 | - * @param boolean $with_prefixes TRUE: get payment method type classnames; false just their 'names' |
|
189 | - * (what you'd find in wp_esp_payment_method.PMD_type) |
|
190 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
191 | - * @return array |
|
192 | - */ |
|
193 | - public function payment_method_type_names($with_prefixes = false, $force_recheck = false) |
|
194 | - { |
|
195 | - $this->maybe_register_payment_methods($force_recheck); |
|
196 | - if ($with_prefixes) { |
|
197 | - $classnames = array_keys($this->_payment_method_types); |
|
198 | - $payment_methods = array(); |
|
199 | - foreach ($classnames as $classname) { |
|
200 | - $payment_methods[] = $this->payment_method_class_from_type($classname); |
|
201 | - } |
|
202 | - return $payment_methods; |
|
203 | - } else { |
|
204 | - return array_keys($this->_payment_method_types); |
|
205 | - } |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * Gets an object of each payment method type, none of which are bound to a |
|
212 | - * payment method instance |
|
213 | - * |
|
214 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
215 | - * @return EE_PMT_Base[] |
|
216 | - */ |
|
217 | - public function payment_method_types($force_recheck = false) |
|
218 | - { |
|
219 | - $this->maybe_register_payment_methods($force_recheck); |
|
220 | - $pmt_objs = array(); |
|
221 | - foreach ($this->payment_method_type_names(true) as $classname) { |
|
222 | - $pmt_objs[] = new $classname; |
|
223 | - } |
|
224 | - return $pmt_objs; |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * Changes the payment method's classname into the payment method type's name |
|
231 | - * (as used on the payment method's table's PMD_type field) |
|
232 | - * |
|
233 | - * @param string $classname |
|
234 | - * @return string |
|
235 | - */ |
|
236 | - public function payment_method_type_sans_class_prefix($classname) |
|
237 | - { |
|
238 | - return str_replace("EE_PMT_", "", $classname); |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * Does the opposite of payment-method_type_sans_prefix |
|
245 | - * |
|
246 | - * @param string $type |
|
247 | - * @return string |
|
248 | - */ |
|
249 | - public function payment_method_class_from_type($type) |
|
250 | - { |
|
251 | - $this->maybe_register_payment_methods(); |
|
252 | - return "EE_PMT_" . $type; |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * Activates a payment method of the given type. |
|
259 | - * |
|
260 | - * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice' |
|
261 | - * @return \EE_Payment_Method |
|
262 | - * @throws \EE_Error |
|
263 | - */ |
|
264 | - public function activate_a_payment_method_of_type($payment_method_type) |
|
265 | - { |
|
266 | - $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); |
|
267 | - if ( ! $payment_method instanceof EE_Payment_Method) { |
|
268 | - $pm_type_class = $this->payment_method_class_from_type($payment_method_type); |
|
269 | - if (class_exists($pm_type_class)) { |
|
270 | - /** @var $pm_type_obj EE_PMT_Base */ |
|
271 | - $pm_type_obj = new $pm_type_class; |
|
272 | - $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); |
|
273 | - if ( ! $payment_method) { |
|
274 | - $payment_method = $this->create_payment_method_of_type($pm_type_obj); |
|
275 | - } |
|
276 | - $payment_method->set_type($payment_method_type); |
|
277 | - $this->initialize_payment_method($payment_method); |
|
278 | - } else { |
|
279 | - throw new EE_Error( |
|
280 | - sprintf( |
|
281 | - __('There is no payment method of type %1$s, so it could not be activated', 'event_espresso'), |
|
282 | - $pm_type_class) |
|
283 | - ); |
|
284 | - } |
|
285 | - } |
|
286 | - $payment_method->set_active(); |
|
287 | - $payment_method->save(); |
|
288 | - if ($payment_method->type() === 'Invoice') { |
|
289 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
290 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
291 | - $message_resource_manager->ensure_message_type_is_active('invoice', 'html'); |
|
292 | - $message_resource_manager->ensure_messenger_is_active('pdf'); |
|
293 | - EE_Error::add_persistent_admin_notice( |
|
294 | - 'invoice_pm_requirements_notice', |
|
295 | - sprintf( |
|
296 | - __('The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.', |
|
297 | - 'event_espresso'), |
|
298 | - '<a href="' . admin_url('admin.php?page=espresso_messages') . '">', |
|
299 | - '</a>' |
|
300 | - ), |
|
301 | - true |
|
302 | - ); |
|
303 | - } |
|
304 | - return $payment_method; |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - |
|
309 | - /** |
|
310 | - * Creates a payment method of the specified type. Does not save it. |
|
311 | - * |
|
312 | - * @global WP_User $current_user |
|
313 | - * @param EE_PMT_Base $pm_type_obj |
|
314 | - * @return EE_Payment_Method |
|
315 | - * @throws \EE_Error |
|
316 | - */ |
|
317 | - public function create_payment_method_of_type($pm_type_obj) |
|
318 | - { |
|
319 | - global $current_user; |
|
320 | - $payment_method = EE_Payment_Method::new_instance( |
|
321 | - array( |
|
322 | - 'PMD_type' => $pm_type_obj->system_name(), |
|
323 | - 'PMD_name' => $pm_type_obj->pretty_name(), |
|
324 | - 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
|
325 | - 'PMD_slug' => $pm_type_obj->system_name(),//automatically converted to slug |
|
326 | - 'PMD_wp_user' => $current_user->ID, |
|
327 | - 'PMD_order' => EEM_Payment_Method::instance()->count( |
|
328 | - array(array('PMD_type' => array('!=', 'Admin_Only'))) |
|
329 | - ) * 10, |
|
330 | - ) |
|
331 | - ); |
|
332 | - return $payment_method; |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * Sets the initial payment method properties (including extra meta) |
|
339 | - * |
|
340 | - * @param EE_Payment_Method $payment_method |
|
341 | - * @return EE_Payment_Method |
|
342 | - * @throws \EE_Error |
|
343 | - */ |
|
344 | - public function initialize_payment_method($payment_method) |
|
345 | - { |
|
346 | - $pm_type_obj = $payment_method->type_obj(); |
|
347 | - $payment_method->set_description($pm_type_obj->default_description()); |
|
348 | - if ( ! $payment_method->button_url()) { |
|
349 | - $payment_method->set_button_url($pm_type_obj->default_button_url()); |
|
350 | - } |
|
351 | - //now add setup its default extra meta properties |
|
352 | - $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs(); |
|
353 | - if ( ! empty($extra_metas)) { |
|
354 | - //verify the payment method has an ID before adding extra meta |
|
355 | - if ( ! $payment_method->ID()) { |
|
356 | - $payment_method->save(); |
|
357 | - } |
|
358 | - foreach ($extra_metas as $meta_name => $input) { |
|
359 | - $payment_method->update_extra_meta($meta_name, $input->raw_value()); |
|
360 | - } |
|
361 | - } |
|
362 | - return $payment_method; |
|
363 | - } |
|
364 | - |
|
365 | - |
|
366 | - |
|
367 | - /** |
|
368 | - * Makes sure the payment method is related to the specified payment method |
|
369 | - * @deprecated in 4.9.40 because the currency payment method table is being deprecated |
|
370 | - * @param EE_Payment_Method $payment_method |
|
371 | - * @return EE_Payment_Method |
|
372 | - * @throws \EE_Error |
|
373 | - */ |
|
374 | - public function set_usable_currencies_on_payment_method($payment_method) |
|
375 | - { |
|
376 | - EE_Error::doing_it_wrong( |
|
377 | - 'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method', |
|
378 | - esc_html__('We no longer define what currencies are usable by payment methods. Its not used nor efficient.', 'event_espresso'), |
|
379 | - '4.9.40'); |
|
380 | - return $payment_method; |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * Deactivates a payment method of the given payment method slug. |
|
387 | - * |
|
388 | - * @param string $payment_method_slug The slug for the payment method to deactivate. |
|
389 | - * @return int count of rows updated. |
|
390 | - */ |
|
391 | - public function deactivate_payment_method($payment_method_slug) |
|
392 | - { |
|
393 | - EE_Log::instance()->log( |
|
394 | - __FILE__, |
|
395 | - __FUNCTION__, |
|
396 | - sprintf( |
|
397 | - __('Payment method with slug %1$s is being deactivated by site admin', 'event_espresso'), |
|
398 | - $payment_method_slug |
|
399 | - ), |
|
400 | - 'payment_method_change' |
|
401 | - ); |
|
402 | - $count_updated = EEM_Payment_Method::instance()->update( |
|
403 | - array('PMD_scope' => array()), |
|
404 | - array(array('PMD_slug' => $payment_method_slug)) |
|
405 | - ); |
|
406 | - return $count_updated; |
|
407 | - } |
|
408 | - |
|
409 | - |
|
410 | - |
|
411 | - /** |
|
412 | - * callback for FHEE__EE_Capabilities__init_caps_map__caps filter to add dynamic payment method |
|
413 | - * access caps. |
|
414 | - * |
|
415 | - * @param array $caps capabilities being filtered |
|
416 | - * @return array |
|
417 | - */ |
|
418 | - public function add_payment_method_caps($caps) |
|
419 | - { |
|
420 | - /* add dynamic caps from payment methods |
|
20 | + /** |
|
21 | + * instance of the EE_Payment_Method_Manager object |
|
22 | + * |
|
23 | + * @var $_instance |
|
24 | + * @access private |
|
25 | + */ |
|
26 | + private static $_instance; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var array keys are classnames without 'EE_PMT_', values are their filepaths |
|
30 | + */ |
|
31 | + protected $_payment_method_types = array(); |
|
32 | + |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @singleton method used to instantiate class object |
|
37 | + * @access public |
|
38 | + * @return EE_Payment_Method_Manager instance |
|
39 | + */ |
|
40 | + public static function instance() |
|
41 | + { |
|
42 | + // check if class object is instantiated, and instantiated properly |
|
43 | + if ( ! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
44 | + self::$_instance = new self(); |
|
45 | + } |
|
46 | + EE_Registry::instance()->load_lib('PMT_Base'); |
|
47 | + return self::$_instance; |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * Resets the instance and returns a new one |
|
54 | + * |
|
55 | + * @return EE_Payment_Method_Manager |
|
56 | + */ |
|
57 | + public static function reset() |
|
58 | + { |
|
59 | + self::$_instance = null; |
|
60 | + return self::instance(); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * If necessary, re-register payment methods |
|
67 | + * |
|
68 | + * @param boolean $force_recheck whether to recheck for payment method types, |
|
69 | + * or just re-use the PMTs we found last time we checked during this request (if |
|
70 | + * we have not yet checked during this request, then we need to check anyways) |
|
71 | + */ |
|
72 | + public function maybe_register_payment_methods($force_recheck = false) |
|
73 | + { |
|
74 | + if ( ! $this->_payment_method_types || $force_recheck) { |
|
75 | + $this->_register_payment_methods(); |
|
76 | + //if in admin lets ensure caps are set. |
|
77 | + if (is_admin()) { |
|
78 | + add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array($this, 'add_payment_method_caps')); |
|
79 | + EE_Registry::instance()->CAP->init_caps(); |
|
80 | + } |
|
81 | + } |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * register_payment_methods |
|
88 | + * |
|
89 | + * @return array |
|
90 | + */ |
|
91 | + protected function _register_payment_methods() |
|
92 | + { |
|
93 | + // grab list of installed modules |
|
94 | + $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
95 | + // filter list of modules to register |
|
96 | + $pm_to_register = apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
97 | + $pm_to_register); |
|
98 | + // loop through folders |
|
99 | + foreach ($pm_to_register as $pm_path) { |
|
100 | + $this->register_payment_method($pm_path); |
|
101 | + } |
|
102 | + do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods'); |
|
103 | + // filter list of installed modules |
|
104 | + //keep them organized alphabetically by the payment method type's name |
|
105 | + ksort($this->_payment_method_types); |
|
106 | + return apply_filters('FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', |
|
107 | + $this->_payment_method_types); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * register_payment_method- makes core aware of this payment method |
|
114 | + * |
|
115 | + * @access public |
|
116 | + * @param string $payment_method_path - full path up to and including payment method folder |
|
117 | + * @return boolean |
|
118 | + */ |
|
119 | + public function register_payment_method($payment_method_path = '') |
|
120 | + { |
|
121 | + do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path); |
|
122 | + $module_ext = '.pm.php'; |
|
123 | + // make all separators match |
|
124 | + $payment_method_path = rtrim(str_replace('/\\', DS, $payment_method_path), DS); |
|
125 | + // grab and sanitize module name |
|
126 | + $module_dir = basename($payment_method_path); |
|
127 | + // create classname from module directory name |
|
128 | + $module = str_replace(' ', '_', str_replace('_', ' ', $module_dir)); |
|
129 | + // add class prefix |
|
130 | + $module_class = 'EE_PMT_' . $module; |
|
131 | + // does the module exist ? |
|
132 | + if ( ! is_readable($payment_method_path . DS . $module_class . $module_ext)) { |
|
133 | + $msg = sprintf(__('The requested %s payment method file could not be found or is not readable due to file permissions.', |
|
134 | + 'event_espresso'), $module); |
|
135 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
136 | + return false; |
|
137 | + } |
|
138 | + if (WP_DEBUG === true) { |
|
139 | + EEH_Debug_Tools::instance()->start_timer(); |
|
140 | + } |
|
141 | + // load the module class file |
|
142 | + require_once($payment_method_path . DS . $module_class . $module_ext); |
|
143 | + if (WP_DEBUG === true) { |
|
144 | + EEH_Debug_Tools::instance()->stop_timer("Requiring payment method $module_class"); |
|
145 | + } |
|
146 | + // verify that class exists |
|
147 | + if ( ! class_exists($module_class)) { |
|
148 | + $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
149 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
150 | + return false; |
|
151 | + } |
|
152 | + // add to array of registered modules |
|
153 | + $this->_payment_method_types[$module] = $payment_method_path . DS . $module_class . $module_ext; |
|
154 | + return true; |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * Checks if a payment method has been registered, and if so includes it |
|
161 | + * |
|
162 | + * @param string $payment_method_name like 'Paypal_Pro', (ie classname without the prefix 'EEPM_') |
|
163 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
164 | + * @return boolean |
|
165 | + */ |
|
166 | + public function payment_method_type_exists($payment_method_name, $force_recheck = false) |
|
167 | + { |
|
168 | + if ( |
|
169 | + $force_recheck |
|
170 | + || ! is_array($this->_payment_method_types) |
|
171 | + || ! isset($this->_payment_method_types[$payment_method_name]) |
|
172 | + ) { |
|
173 | + $this->maybe_register_payment_methods($force_recheck); |
|
174 | + } |
|
175 | + if (isset($this->_payment_method_types[$payment_method_name])) { |
|
176 | + require_once($this->_payment_method_types[$payment_method_name]); |
|
177 | + return true; |
|
178 | + } else { |
|
179 | + return false; |
|
180 | + } |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * Returns all the classnames of the various payment method types |
|
187 | + * |
|
188 | + * @param boolean $with_prefixes TRUE: get payment method type classnames; false just their 'names' |
|
189 | + * (what you'd find in wp_esp_payment_method.PMD_type) |
|
190 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
191 | + * @return array |
|
192 | + */ |
|
193 | + public function payment_method_type_names($with_prefixes = false, $force_recheck = false) |
|
194 | + { |
|
195 | + $this->maybe_register_payment_methods($force_recheck); |
|
196 | + if ($with_prefixes) { |
|
197 | + $classnames = array_keys($this->_payment_method_types); |
|
198 | + $payment_methods = array(); |
|
199 | + foreach ($classnames as $classname) { |
|
200 | + $payment_methods[] = $this->payment_method_class_from_type($classname); |
|
201 | + } |
|
202 | + return $payment_methods; |
|
203 | + } else { |
|
204 | + return array_keys($this->_payment_method_types); |
|
205 | + } |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * Gets an object of each payment method type, none of which are bound to a |
|
212 | + * payment method instance |
|
213 | + * |
|
214 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
215 | + * @return EE_PMT_Base[] |
|
216 | + */ |
|
217 | + public function payment_method_types($force_recheck = false) |
|
218 | + { |
|
219 | + $this->maybe_register_payment_methods($force_recheck); |
|
220 | + $pmt_objs = array(); |
|
221 | + foreach ($this->payment_method_type_names(true) as $classname) { |
|
222 | + $pmt_objs[] = new $classname; |
|
223 | + } |
|
224 | + return $pmt_objs; |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * Changes the payment method's classname into the payment method type's name |
|
231 | + * (as used on the payment method's table's PMD_type field) |
|
232 | + * |
|
233 | + * @param string $classname |
|
234 | + * @return string |
|
235 | + */ |
|
236 | + public function payment_method_type_sans_class_prefix($classname) |
|
237 | + { |
|
238 | + return str_replace("EE_PMT_", "", $classname); |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * Does the opposite of payment-method_type_sans_prefix |
|
245 | + * |
|
246 | + * @param string $type |
|
247 | + * @return string |
|
248 | + */ |
|
249 | + public function payment_method_class_from_type($type) |
|
250 | + { |
|
251 | + $this->maybe_register_payment_methods(); |
|
252 | + return "EE_PMT_" . $type; |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * Activates a payment method of the given type. |
|
259 | + * |
|
260 | + * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice' |
|
261 | + * @return \EE_Payment_Method |
|
262 | + * @throws \EE_Error |
|
263 | + */ |
|
264 | + public function activate_a_payment_method_of_type($payment_method_type) |
|
265 | + { |
|
266 | + $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); |
|
267 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
268 | + $pm_type_class = $this->payment_method_class_from_type($payment_method_type); |
|
269 | + if (class_exists($pm_type_class)) { |
|
270 | + /** @var $pm_type_obj EE_PMT_Base */ |
|
271 | + $pm_type_obj = new $pm_type_class; |
|
272 | + $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); |
|
273 | + if ( ! $payment_method) { |
|
274 | + $payment_method = $this->create_payment_method_of_type($pm_type_obj); |
|
275 | + } |
|
276 | + $payment_method->set_type($payment_method_type); |
|
277 | + $this->initialize_payment_method($payment_method); |
|
278 | + } else { |
|
279 | + throw new EE_Error( |
|
280 | + sprintf( |
|
281 | + __('There is no payment method of type %1$s, so it could not be activated', 'event_espresso'), |
|
282 | + $pm_type_class) |
|
283 | + ); |
|
284 | + } |
|
285 | + } |
|
286 | + $payment_method->set_active(); |
|
287 | + $payment_method->save(); |
|
288 | + if ($payment_method->type() === 'Invoice') { |
|
289 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
290 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
291 | + $message_resource_manager->ensure_message_type_is_active('invoice', 'html'); |
|
292 | + $message_resource_manager->ensure_messenger_is_active('pdf'); |
|
293 | + EE_Error::add_persistent_admin_notice( |
|
294 | + 'invoice_pm_requirements_notice', |
|
295 | + sprintf( |
|
296 | + __('The Invoice payment method has been activated. It requires the invoice message type, html messenger, and pdf messenger be activated as well for the %1$smessages system%2$s, so it has been automatically verified that they are also active.', |
|
297 | + 'event_espresso'), |
|
298 | + '<a href="' . admin_url('admin.php?page=espresso_messages') . '">', |
|
299 | + '</a>' |
|
300 | + ), |
|
301 | + true |
|
302 | + ); |
|
303 | + } |
|
304 | + return $payment_method; |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + |
|
309 | + /** |
|
310 | + * Creates a payment method of the specified type. Does not save it. |
|
311 | + * |
|
312 | + * @global WP_User $current_user |
|
313 | + * @param EE_PMT_Base $pm_type_obj |
|
314 | + * @return EE_Payment_Method |
|
315 | + * @throws \EE_Error |
|
316 | + */ |
|
317 | + public function create_payment_method_of_type($pm_type_obj) |
|
318 | + { |
|
319 | + global $current_user; |
|
320 | + $payment_method = EE_Payment_Method::new_instance( |
|
321 | + array( |
|
322 | + 'PMD_type' => $pm_type_obj->system_name(), |
|
323 | + 'PMD_name' => $pm_type_obj->pretty_name(), |
|
324 | + 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
|
325 | + 'PMD_slug' => $pm_type_obj->system_name(),//automatically converted to slug |
|
326 | + 'PMD_wp_user' => $current_user->ID, |
|
327 | + 'PMD_order' => EEM_Payment_Method::instance()->count( |
|
328 | + array(array('PMD_type' => array('!=', 'Admin_Only'))) |
|
329 | + ) * 10, |
|
330 | + ) |
|
331 | + ); |
|
332 | + return $payment_method; |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * Sets the initial payment method properties (including extra meta) |
|
339 | + * |
|
340 | + * @param EE_Payment_Method $payment_method |
|
341 | + * @return EE_Payment_Method |
|
342 | + * @throws \EE_Error |
|
343 | + */ |
|
344 | + public function initialize_payment_method($payment_method) |
|
345 | + { |
|
346 | + $pm_type_obj = $payment_method->type_obj(); |
|
347 | + $payment_method->set_description($pm_type_obj->default_description()); |
|
348 | + if ( ! $payment_method->button_url()) { |
|
349 | + $payment_method->set_button_url($pm_type_obj->default_button_url()); |
|
350 | + } |
|
351 | + //now add setup its default extra meta properties |
|
352 | + $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs(); |
|
353 | + if ( ! empty($extra_metas)) { |
|
354 | + //verify the payment method has an ID before adding extra meta |
|
355 | + if ( ! $payment_method->ID()) { |
|
356 | + $payment_method->save(); |
|
357 | + } |
|
358 | + foreach ($extra_metas as $meta_name => $input) { |
|
359 | + $payment_method->update_extra_meta($meta_name, $input->raw_value()); |
|
360 | + } |
|
361 | + } |
|
362 | + return $payment_method; |
|
363 | + } |
|
364 | + |
|
365 | + |
|
366 | + |
|
367 | + /** |
|
368 | + * Makes sure the payment method is related to the specified payment method |
|
369 | + * @deprecated in 4.9.40 because the currency payment method table is being deprecated |
|
370 | + * @param EE_Payment_Method $payment_method |
|
371 | + * @return EE_Payment_Method |
|
372 | + * @throws \EE_Error |
|
373 | + */ |
|
374 | + public function set_usable_currencies_on_payment_method($payment_method) |
|
375 | + { |
|
376 | + EE_Error::doing_it_wrong( |
|
377 | + 'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method', |
|
378 | + esc_html__('We no longer define what currencies are usable by payment methods. Its not used nor efficient.', 'event_espresso'), |
|
379 | + '4.9.40'); |
|
380 | + return $payment_method; |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * Deactivates a payment method of the given payment method slug. |
|
387 | + * |
|
388 | + * @param string $payment_method_slug The slug for the payment method to deactivate. |
|
389 | + * @return int count of rows updated. |
|
390 | + */ |
|
391 | + public function deactivate_payment_method($payment_method_slug) |
|
392 | + { |
|
393 | + EE_Log::instance()->log( |
|
394 | + __FILE__, |
|
395 | + __FUNCTION__, |
|
396 | + sprintf( |
|
397 | + __('Payment method with slug %1$s is being deactivated by site admin', 'event_espresso'), |
|
398 | + $payment_method_slug |
|
399 | + ), |
|
400 | + 'payment_method_change' |
|
401 | + ); |
|
402 | + $count_updated = EEM_Payment_Method::instance()->update( |
|
403 | + array('PMD_scope' => array()), |
|
404 | + array(array('PMD_slug' => $payment_method_slug)) |
|
405 | + ); |
|
406 | + return $count_updated; |
|
407 | + } |
|
408 | + |
|
409 | + |
|
410 | + |
|
411 | + /** |
|
412 | + * callback for FHEE__EE_Capabilities__init_caps_map__caps filter to add dynamic payment method |
|
413 | + * access caps. |
|
414 | + * |
|
415 | + * @param array $caps capabilities being filtered |
|
416 | + * @return array |
|
417 | + */ |
|
418 | + public function add_payment_method_caps($caps) |
|
419 | + { |
|
420 | + /* add dynamic caps from payment methods |
|
421 | 421 | * at the time of writing, october 20 2014, these are the caps added: |
422 | 422 | * ee_payment_method_admin_only |
423 | 423 | * ee_payment_method_aim |
@@ -431,10 +431,10 @@ discard block |
||
431 | 431 | * their related capability automatically added too, so long as they are |
432 | 432 | * registered properly using EE_Register_Payment_Method::register() |
433 | 433 | */ |
434 | - foreach ($this->payment_method_types() as $payment_method_type_obj) { |
|
435 | - $caps['administrator'][] = $payment_method_type_obj->cap_name(); |
|
436 | - } |
|
437 | - return $caps; |
|
438 | - } |
|
434 | + foreach ($this->payment_method_types() as $payment_method_type_obj) { |
|
435 | + $caps['administrator'][] = $payment_method_type_obj->cap_name(); |
|
436 | + } |
|
437 | + return $caps; |
|
438 | + } |
|
439 | 439 | |
440 | 440 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | } |
6 | 6 | |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | * @deprecated in 4.9.40 because the currency payment method table has been deprecated |
15 | 15 | * |
16 | 16 | */ |
17 | -class EE_DMS_4_6_0_payment_method_currencies extends EE_Data_Migration_Script_Stage{ |
|
17 | +class EE_DMS_4_6_0_payment_method_currencies extends EE_Data_Migration_Script_Stage { |
|
18 | 18 | protected $_currency_table_name; |
19 | 19 | protected $_currency_payment_method_table_name; |
20 | 20 | protected $_payment_method_table_name; |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | ); |
91 | 91 | public function __construct() { |
92 | 92 | global $wpdb; |
93 | - $this->_pretty_name = __( 'Payment Method Currencies', 'event_espresso' ); |
|
93 | + $this->_pretty_name = __('Payment Method Currencies', 'event_espresso'); |
|
94 | 94 | $this->_payment_method_table_name = $wpdb->prefix.'esp_payment_method'; |
95 | 95 | $this->_currency_payment_method_table_name = $wpdb->prefix.'esp_currency_payment_method'; |
96 | 96 | $this->_currency_table_name = $wpdb->prefix.'esp_currency'; |
@@ -99,8 +99,8 @@ discard block |
||
99 | 99 | |
100 | 100 | protected function _count_records_to_migrate() { |
101 | 101 | $count = 0; |
102 | - foreach($this->_gateway_currencies as $currencies){ |
|
103 | - if( $currencies == 'all'){ |
|
102 | + foreach ($this->_gateway_currencies as $currencies) { |
|
103 | + if ($currencies == 'all') { |
|
104 | 104 | $currencies = $this->_get_all_currencies(); |
105 | 105 | } |
106 | 106 | $count += count($currencies); |
@@ -110,20 +110,20 @@ discard block |
||
110 | 110 | |
111 | 111 | |
112 | 112 | |
113 | - protected function _migration_step( $num_items_to_migrate = 50 ) { |
|
113 | + protected function _migration_step($num_items_to_migrate = 50) { |
|
114 | 114 | $items_actually_migrated = 0; |
115 | 115 | $relations_to_add_this_step = $this->_gather_relations_to_add($num_items_to_migrate); |
116 | - foreach($relations_to_add_this_step as $pm_slug => $currencies){ |
|
116 | + foreach ($relations_to_add_this_step as $pm_slug => $currencies) { |
|
117 | 117 | |
118 | - $id = $this->get_migration_script()->get_mapping_new_pk( 'EE_Gateway_Config', $pm_slug, $this->_payment_method_table_name ); |
|
119 | - foreach( $currencies as $currency ){ |
|
120 | - if( $id ){ |
|
121 | - $this->_add_currency_relations( $id, $currency ); |
|
118 | + $id = $this->get_migration_script()->get_mapping_new_pk('EE_Gateway_Config', $pm_slug, $this->_payment_method_table_name); |
|
119 | + foreach ($currencies as $currency) { |
|
120 | + if ($id) { |
|
121 | + $this->_add_currency_relations($id, $currency); |
|
122 | 122 | } |
123 | 123 | $items_actually_migrated++; |
124 | 124 | } |
125 | 125 | } |
126 | - if($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()){ |
|
126 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
127 | 127 | $this->set_completed(); |
128 | 128 | } |
129 | 129 | return $items_actually_migrated; |
@@ -133,14 +133,14 @@ discard block |
||
133 | 133 | $relations_to_add_this_step = array(); |
134 | 134 | $migrate_up_to_count = $this->count_records_migrated() + $num_items_to_migrate; |
135 | 135 | $iterator = 0; |
136 | - foreach($this->_gateway_currencies as $pm_slug => $currencies){ |
|
137 | - if( $currencies == 'all' ){ |
|
136 | + foreach ($this->_gateway_currencies as $pm_slug => $currencies) { |
|
137 | + if ($currencies == 'all') { |
|
138 | 138 | $currencies = $this->_get_all_currencies(); |
139 | 139 | } |
140 | - foreach($currencies as $currency_code){ |
|
141 | - if( $this->count_records_migrated() <= $iterator && |
|
142 | - $iterator < $migrate_up_to_count ){ |
|
143 | - $relations_to_add_this_step[ $pm_slug ] [] = $currency_code; |
|
140 | + foreach ($currencies as $currency_code) { |
|
141 | + if ($this->count_records_migrated() <= $iterator && |
|
142 | + $iterator < $migrate_up_to_count) { |
|
143 | + $relations_to_add_this_step[$pm_slug] [] = $currency_code; |
|
144 | 144 | } |
145 | 145 | $iterator++; |
146 | 146 | } |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * Gets all the currency codes in the database |
152 | 152 | * @return array |
153 | 153 | */ |
154 | - private function _get_all_currencies(){ |
|
154 | + private function _get_all_currencies() { |
|
155 | 155 | global $wpdb; |
156 | 156 | $currencies = $wpdb->get_col("SELECT CUR_code FROM {$this->_currency_table_name}"); |
157 | 157 | return $currencies; |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * @param int $id |
163 | 163 | * @param string $gateway_slug |
164 | 164 | */ |
165 | - private function _add_currency_relations($pm_id,$currency_code){ |
|
165 | + private function _add_currency_relations($pm_id, $currency_code) { |
|
166 | 166 | global $wpdb; |
167 | 167 | $cur_pm_relation = array( |
168 | 168 | 'CUR_code'=>$currency_code, |
@@ -171,11 +171,11 @@ discard block |
||
171 | 171 | $success = $wpdb->insert($this->_currency_payment_method_table_name, |
172 | 172 | $cur_pm_relation, |
173 | 173 | array( |
174 | - '%s',//CUR_code |
|
175 | - '%d',//PMD_ID |
|
174 | + '%s', //CUR_code |
|
175 | + '%d', //PMD_ID |
|
176 | 176 | )); |
177 | - if( ! $success ){ |
|
178 | - $this->add_error( sprintf( __( 'Could not add currency relation %s because %s', "event_espresso" ), wp_json_encode( $cur_pm_relation ), $wpdb->last_error ) ); |
|
177 | + if ( ! $success) { |
|
178 | + $this->add_error(sprintf(__('Could not add currency relation %s because %s', "event_espresso"), wp_json_encode($cur_pm_relation), $wpdb->last_error)); |
|
179 | 179 | } |
180 | 180 | } |
181 | 181 | } |
@@ -12,9 +12,9 @@ discard block |
||
12 | 12 | $stages = glob(EE_CORE . 'data_migration_scripts/4_9_0_stages/*'); |
13 | 13 | $class_to_filepath = array(); |
14 | 14 | foreach ($stages as $filepath) { |
15 | - $matches = array(); |
|
16 | - preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
17 | - $class_to_filepath[$matches[1]] = $filepath; |
|
15 | + $matches = array(); |
|
16 | + preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
17 | + $class_to_filepath[$matches[1]] = $filepath; |
|
18 | 18 | } |
19 | 19 | //give addons a chance to autoload their stages too |
20 | 20 | $class_to_filepath = apply_filters('FHEE__EE_DMS_4_9_0__autoloaded_stages', $class_to_filepath); |
@@ -33,68 +33,68 @@ discard block |
||
33 | 33 | class EE_DMS_Core_4_9_0 extends EE_Data_Migration_Script_Base |
34 | 34 | { |
35 | 35 | |
36 | - /** |
|
37 | - * return EE_DMS_Core_4_9_0 |
|
38 | - * |
|
39 | - * @param TableManager $table_manager |
|
40 | - * @param TableAnalysis $table_analysis |
|
41 | - */ |
|
42 | - public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
43 | - { |
|
44 | - $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso"); |
|
45 | - $this->_priority = 10; |
|
46 | - $this->_migration_stages = array( |
|
47 | - new EE_DMS_4_9_0_Email_System_Question(), |
|
48 | - new EE_DMS_4_9_0_Answers_With_No_Registration(), |
|
49 | - ); |
|
50 | - parent::__construct($table_manager, $table_analysis); |
|
51 | - } |
|
36 | + /** |
|
37 | + * return EE_DMS_Core_4_9_0 |
|
38 | + * |
|
39 | + * @param TableManager $table_manager |
|
40 | + * @param TableAnalysis $table_analysis |
|
41 | + */ |
|
42 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
43 | + { |
|
44 | + $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso"); |
|
45 | + $this->_priority = 10; |
|
46 | + $this->_migration_stages = array( |
|
47 | + new EE_DMS_4_9_0_Email_System_Question(), |
|
48 | + new EE_DMS_4_9_0_Answers_With_No_Registration(), |
|
49 | + ); |
|
50 | + parent::__construct($table_manager, $table_analysis); |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * Whether to migrate or not. |
|
57 | - * |
|
58 | - * @param array $version_array |
|
59 | - * @return bool |
|
60 | - */ |
|
61 | - public function can_migrate_from_version($version_array) |
|
62 | - { |
|
63 | - $version_string = $version_array['Core']; |
|
64 | - if (version_compare($version_string, '4.9.0', '<=') && version_compare($version_string, '4.8.0', '>=')) { |
|
65 | - // echo "$version_string can be migrated from"; |
|
66 | - return true; |
|
67 | - } elseif ( ! $version_string) { |
|
68 | - // echo "no version string provided: $version_string"; |
|
69 | - //no version string provided... this must be pre 4.3 |
|
70 | - return false;//changed mind. dont want people thinking they should migrate yet because they cant |
|
71 | - } else { |
|
72 | - // echo "$version_string doesnt apply"; |
|
73 | - return false; |
|
74 | - } |
|
75 | - } |
|
55 | + /** |
|
56 | + * Whether to migrate or not. |
|
57 | + * |
|
58 | + * @param array $version_array |
|
59 | + * @return bool |
|
60 | + */ |
|
61 | + public function can_migrate_from_version($version_array) |
|
62 | + { |
|
63 | + $version_string = $version_array['Core']; |
|
64 | + if (version_compare($version_string, '4.9.0', '<=') && version_compare($version_string, '4.8.0', '>=')) { |
|
65 | + // echo "$version_string can be migrated from"; |
|
66 | + return true; |
|
67 | + } elseif ( ! $version_string) { |
|
68 | + // echo "no version string provided: $version_string"; |
|
69 | + //no version string provided... this must be pre 4.3 |
|
70 | + return false;//changed mind. dont want people thinking they should migrate yet because they cant |
|
71 | + } else { |
|
72 | + // echo "$version_string doesnt apply"; |
|
73 | + return false; |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * @return bool |
|
81 | - */ |
|
82 | - public function schema_changes_before_migration() |
|
83 | - { |
|
84 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
85 | - $now_in_mysql = current_time('mysql', true); |
|
86 | - $table_name = 'esp_answer'; |
|
87 | - $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
79 | + /** |
|
80 | + * @return bool |
|
81 | + */ |
|
82 | + public function schema_changes_before_migration() |
|
83 | + { |
|
84 | + require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
85 | + $now_in_mysql = current_time('mysql', true); |
|
86 | + $table_name = 'esp_answer'; |
|
87 | + $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
88 | 88 | REG_ID int(10) unsigned NOT NULL, |
89 | 89 | QST_ID int(10) unsigned NOT NULL, |
90 | 90 | ANS_value text NOT NULL, |
91 | 91 | PRIMARY KEY (ANS_ID), |
92 | 92 | KEY REG_ID (REG_ID), |
93 | 93 | KEY QST_ID (QST_ID)"; |
94 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
95 | - $table_name = 'esp_attendee_meta'; |
|
96 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email'); |
|
97 | - $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
94 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
95 | + $table_name = 'esp_attendee_meta'; |
|
96 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email'); |
|
97 | + $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
98 | 98 | ATT_ID bigint(20) unsigned NOT NULL, |
99 | 99 | ATT_fname varchar(45) NOT NULL, |
100 | 100 | ATT_lname varchar(45) NOT NULL, |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | KEY ATT_email (ATT_email(191)), |
112 | 112 | KEY ATT_lname (ATT_lname), |
113 | 113 | KEY ATT_fname (ATT_fname)"; |
114 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
115 | - $table_name = 'esp_checkin'; |
|
116 | - $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
114 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
115 | + $table_name = 'esp_checkin'; |
|
116 | + $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
117 | 117 | REG_ID int(10) unsigned NOT NULL, |
118 | 118 | DTT_ID int(10) unsigned NOT NULL, |
119 | 119 | CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | PRIMARY KEY (CHK_ID), |
122 | 122 | KEY REG_ID (REG_ID), |
123 | 123 | KEY DTT_ID (DTT_ID)"; |
124 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
125 | - $table_name = 'esp_country'; |
|
126 | - $sql = "CNT_ISO varchar(2) NOT NULL, |
|
124 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
125 | + $table_name = 'esp_country'; |
|
126 | + $sql = "CNT_ISO varchar(2) NOT NULL, |
|
127 | 127 | CNT_ISO3 varchar(3) NOT NULL, |
128 | 128 | RGN_ID tinyint(3) unsigned DEFAULT NULL, |
129 | 129 | CNT_name varchar(45) NOT NULL, |
@@ -139,29 +139,29 @@ discard block |
||
139 | 139 | CNT_is_EU tinyint(1) DEFAULT '0', |
140 | 140 | CNT_active tinyint(1) DEFAULT '0', |
141 | 141 | PRIMARY KEY (CNT_ISO)"; |
142 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
143 | - $table_name = 'esp_currency'; |
|
144 | - $sql = "CUR_code varchar(6) NOT NULL, |
|
142 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
143 | + $table_name = 'esp_currency'; |
|
144 | + $sql = "CUR_code varchar(6) NOT NULL, |
|
145 | 145 | CUR_single varchar(45) DEFAULT 'dollar', |
146 | 146 | CUR_plural varchar(45) DEFAULT 'dollars', |
147 | 147 | CUR_sign varchar(45) DEFAULT '$', |
148 | 148 | CUR_dec_plc varchar(1) NOT NULL DEFAULT '2', |
149 | 149 | CUR_active tinyint(1) DEFAULT '0', |
150 | 150 | PRIMARY KEY (CUR_code)"; |
151 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
152 | - //note: although this table is no longer in use, |
|
153 | - //it hasn't been removed because then queries to the model will have errors. |
|
154 | - //but you should expect this table and its corresponding model to be removed in |
|
155 | - //the next few months |
|
156 | - $table_name = 'esp_currency_payment_method'; |
|
157 | - $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
151 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
152 | + //note: although this table is no longer in use, |
|
153 | + //it hasn't been removed because then queries to the model will have errors. |
|
154 | + //but you should expect this table and its corresponding model to be removed in |
|
155 | + //the next few months |
|
156 | + $table_name = 'esp_currency_payment_method'; |
|
157 | + $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
158 | 158 | CUR_code varchar(6) NOT NULL, |
159 | 159 | PMD_ID int(11) NOT NULL, |
160 | 160 | PRIMARY KEY (CPM_ID), |
161 | 161 | KEY PMD_ID (PMD_ID)"; |
162 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
163 | - $table_name = 'esp_datetime'; |
|
164 | - $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
162 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
163 | + $table_name = 'esp_datetime'; |
|
164 | + $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
165 | 165 | EVT_ID bigint(20) unsigned NOT NULL, |
166 | 166 | DTT_name varchar(255) NOT NULL DEFAULT '', |
167 | 167 | DTT_description text NOT NULL, |
@@ -178,25 +178,25 @@ discard block |
||
178 | 178 | KEY DTT_EVT_start (DTT_EVT_start), |
179 | 179 | KEY EVT_ID (EVT_ID), |
180 | 180 | KEY DTT_is_primary (DTT_is_primary)"; |
181 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
182 | - $table_name = "esp_datetime_ticket"; |
|
183 | - $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
181 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
182 | + $table_name = "esp_datetime_ticket"; |
|
183 | + $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
184 | 184 | DTT_ID int(10) unsigned NOT NULL, |
185 | 185 | TKT_ID int(10) unsigned NOT NULL, |
186 | 186 | PRIMARY KEY (DTK_ID), |
187 | 187 | KEY DTT_ID (DTT_ID), |
188 | 188 | KEY TKT_ID (TKT_ID)"; |
189 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
190 | - $table_name = 'esp_event_message_template'; |
|
191 | - $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
189 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
190 | + $table_name = 'esp_event_message_template'; |
|
191 | + $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
192 | 192 | EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
193 | 193 | GRP_ID int(10) unsigned NOT NULL DEFAULT 0, |
194 | 194 | PRIMARY KEY (EMT_ID), |
195 | 195 | KEY EVT_ID (EVT_ID), |
196 | 196 | KEY GRP_ID (GRP_ID)"; |
197 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
198 | - $table_name = 'esp_event_meta'; |
|
199 | - $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
197 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
198 | + $table_name = 'esp_event_meta'; |
|
199 | + $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
200 | 200 | EVT_ID bigint(20) unsigned NOT NULL, |
201 | 201 | EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1, |
202 | 202 | EVT_display_ticket_selector tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -211,34 +211,34 @@ discard block |
||
211 | 211 | EVT_donations tinyint(1) NULL, |
212 | 212 | PRIMARY KEY (EVTM_ID), |
213 | 213 | KEY EVT_ID (EVT_ID)"; |
214 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
215 | - $table_name = 'esp_event_question_group'; |
|
216 | - $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
214 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
215 | + $table_name = 'esp_event_question_group'; |
|
216 | + $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
217 | 217 | EVT_ID bigint(20) unsigned NOT NULL, |
218 | 218 | QSG_ID int(10) unsigned NOT NULL, |
219 | 219 | EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
220 | 220 | PRIMARY KEY (EQG_ID), |
221 | 221 | KEY EVT_ID (EVT_ID), |
222 | 222 | KEY QSG_ID (QSG_ID)"; |
223 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
224 | - $table_name = 'esp_event_venue'; |
|
225 | - $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
223 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
224 | + $table_name = 'esp_event_venue'; |
|
225 | + $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
226 | 226 | EVT_ID bigint(20) unsigned NOT NULL, |
227 | 227 | VNU_ID bigint(20) unsigned NOT NULL, |
228 | 228 | EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
229 | 229 | PRIMARY KEY (EVV_ID)"; |
230 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
231 | - $table_name = 'esp_extra_meta'; |
|
232 | - $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
230 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
231 | + $table_name = 'esp_extra_meta'; |
|
232 | + $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
233 | 233 | OBJ_ID int(11) DEFAULT NULL, |
234 | 234 | EXM_type varchar(45) DEFAULT NULL, |
235 | 235 | EXM_key varchar(45) DEFAULT NULL, |
236 | 236 | EXM_value text, |
237 | 237 | PRIMARY KEY (EXM_ID), |
238 | 238 | KEY EXM_type (EXM_type,OBJ_ID,EXM_key)"; |
239 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
240 | - $table_name = 'esp_extra_join'; |
|
241 | - $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
239 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
240 | + $table_name = 'esp_extra_join'; |
|
241 | + $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
242 | 242 | EXJ_first_model_id varchar(6) NOT NULL, |
243 | 243 | EXJ_first_model_name varchar(20) NOT NULL, |
244 | 244 | EXJ_second_model_id varchar(6) NOT NULL, |
@@ -246,9 +246,9 @@ discard block |
||
246 | 246 | PRIMARY KEY (EXJ_ID), |
247 | 247 | KEY first_model (EXJ_first_model_name,EXJ_first_model_id), |
248 | 248 | KEY second_model (EXJ_second_model_name,EXJ_second_model_id)"; |
249 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
250 | - $table_name = 'esp_line_item'; |
|
251 | - $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
249 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
250 | + $table_name = 'esp_line_item'; |
|
251 | + $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
252 | 252 | LIN_code varchar(245) NOT NULL DEFAULT '', |
253 | 253 | TXN_ID int(11) DEFAULT NULL, |
254 | 254 | LIN_name varchar(245) NOT NULL DEFAULT '', |
@@ -267,9 +267,9 @@ discard block |
||
267 | 267 | PRIMARY KEY (LIN_ID), |
268 | 268 | KEY LIN_code (LIN_code(191)), |
269 | 269 | KEY TXN_ID (TXN_ID)"; |
270 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
271 | - $table_name = 'esp_log'; |
|
272 | - $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
270 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
271 | + $table_name = 'esp_log'; |
|
272 | + $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
273 | 273 | LOG_time datetime DEFAULT NULL, |
274 | 274 | OBJ_ID varchar(45) DEFAULT NULL, |
275 | 275 | OBJ_type varchar(45) DEFAULT NULL, |
@@ -280,12 +280,12 @@ discard block |
||
280 | 280 | KEY LOG_time (LOG_time), |
281 | 281 | KEY OBJ (OBJ_type,OBJ_ID), |
282 | 282 | KEY LOG_type (LOG_type)"; |
283 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
284 | - $table_name = 'esp_message'; |
|
285 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to'); |
|
286 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from'); |
|
287 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject'); |
|
288 | - $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
283 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
284 | + $table_name = 'esp_message'; |
|
285 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to'); |
|
286 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from'); |
|
287 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject'); |
|
288 | + $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
289 | 289 | GRP_ID int(10) unsigned NULL, |
290 | 290 | MSG_token varchar(255) NULL, |
291 | 291 | TXN_ID int(10) unsigned NULL, |
@@ -317,18 +317,18 @@ discard block |
||
317 | 317 | KEY STS_ID (STS_ID), |
318 | 318 | KEY MSG_created (MSG_created), |
319 | 319 | KEY MSG_modified (MSG_modified)"; |
320 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
321 | - $table_name = 'esp_message_template'; |
|
322 | - $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
320 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
321 | + $table_name = 'esp_message_template'; |
|
322 | + $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
323 | 323 | GRP_ID int(10) unsigned NOT NULL, |
324 | 324 | MTP_context varchar(50) NOT NULL, |
325 | 325 | MTP_template_field varchar(30) NOT NULL, |
326 | 326 | MTP_content text NOT NULL, |
327 | 327 | PRIMARY KEY (MTP_ID), |
328 | 328 | KEY GRP_ID (GRP_ID)"; |
329 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
330 | - $table_name = 'esp_message_template_group'; |
|
331 | - $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
329 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
330 | + $table_name = 'esp_message_template_group'; |
|
331 | + $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
332 | 332 | MTP_user_id int(10) NOT NULL DEFAULT '1', |
333 | 333 | MTP_name varchar(245) NOT NULL DEFAULT '', |
334 | 334 | MTP_description varchar(245) NOT NULL DEFAULT '', |
@@ -340,9 +340,9 @@ discard block |
||
340 | 340 | MTP_is_active tinyint(1) NOT NULL DEFAULT '1', |
341 | 341 | PRIMARY KEY (GRP_ID), |
342 | 342 | KEY MTP_user_id (MTP_user_id)"; |
343 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
344 | - $table_name = 'esp_payment'; |
|
345 | - $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
343 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
344 | + $table_name = 'esp_payment'; |
|
345 | + $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
346 | 346 | TXN_ID int(10) unsigned DEFAULT NULL, |
347 | 347 | STS_ID varchar(3) DEFAULT NULL, |
348 | 348 | PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -359,9 +359,9 @@ discard block |
||
359 | 359 | PRIMARY KEY (PAY_ID), |
360 | 360 | KEY PAY_timestamp (PAY_timestamp), |
361 | 361 | KEY TXN_ID (TXN_ID)"; |
362 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
363 | - $table_name = 'esp_payment_method'; |
|
364 | - $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
362 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
363 | + $table_name = 'esp_payment_method'; |
|
364 | + $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
365 | 365 | PMD_type varchar(124) DEFAULT NULL, |
366 | 366 | PMD_name varchar(255) DEFAULT NULL, |
367 | 367 | PMD_desc text, |
@@ -377,24 +377,24 @@ discard block |
||
377 | 377 | PRIMARY KEY (PMD_ID), |
378 | 378 | UNIQUE KEY PMD_slug_UNIQUE (PMD_slug), |
379 | 379 | KEY PMD_type (PMD_type)"; |
380 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
381 | - $table_name = "esp_ticket_price"; |
|
382 | - $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
380 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
381 | + $table_name = "esp_ticket_price"; |
|
382 | + $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
383 | 383 | TKT_ID int(10) unsigned NOT NULL, |
384 | 384 | PRC_ID int(10) unsigned NOT NULL, |
385 | 385 | PRIMARY KEY (TKP_ID), |
386 | 386 | KEY TKT_ID (TKT_ID), |
387 | 387 | KEY PRC_ID (PRC_ID)"; |
388 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
389 | - $table_name = "esp_ticket_template"; |
|
390 | - $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
388 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
389 | + $table_name = "esp_ticket_template"; |
|
390 | + $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
391 | 391 | TTM_name varchar(45) NOT NULL, |
392 | 392 | TTM_description text, |
393 | 393 | TTM_file varchar(45), |
394 | 394 | PRIMARY KEY (TTM_ID)"; |
395 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
396 | - $table_name = 'esp_question'; |
|
397 | - $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
395 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
396 | + $table_name = 'esp_question'; |
|
397 | + $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
398 | 398 | QST_display_text text NOT NULL, |
399 | 399 | QST_admin_label varchar(255) NOT NULL, |
400 | 400 | QST_system varchar(25) DEFAULT NULL, |
@@ -408,18 +408,18 @@ discard block |
||
408 | 408 | QST_deleted tinyint(2) unsigned NOT NULL DEFAULT 0, |
409 | 409 | PRIMARY KEY (QST_ID), |
410 | 410 | KEY QST_order (QST_order)'; |
411 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
412 | - $table_name = 'esp_question_group_question'; |
|
413 | - $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
411 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
412 | + $table_name = 'esp_question_group_question'; |
|
413 | + $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
414 | 414 | QSG_ID int(10) unsigned NOT NULL, |
415 | 415 | QST_ID int(10) unsigned NOT NULL, |
416 | 416 | QGQ_order int(10) unsigned NOT NULL DEFAULT 0, |
417 | 417 | PRIMARY KEY (QGQ_ID), |
418 | 418 | KEY QST_ID (QST_ID), |
419 | 419 | KEY QSG_ID_order (QSG_ID,QGQ_order)"; |
420 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
421 | - $table_name = 'esp_question_option'; |
|
422 | - $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
420 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
421 | + $table_name = 'esp_question_option'; |
|
422 | + $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
423 | 423 | QSO_value varchar(255) NOT NULL, |
424 | 424 | QSO_desc text NOT NULL, |
425 | 425 | QST_ID int(10) unsigned NOT NULL, |
@@ -429,9 +429,9 @@ discard block |
||
429 | 429 | PRIMARY KEY (QSO_ID), |
430 | 430 | KEY QST_ID (QST_ID), |
431 | 431 | KEY QSO_order (QSO_order)"; |
432 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
433 | - $table_name = 'esp_registration'; |
|
434 | - $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
432 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
433 | + $table_name = 'esp_registration'; |
|
434 | + $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
435 | 435 | EVT_ID bigint(20) unsigned NOT NULL, |
436 | 436 | ATT_ID bigint(20) unsigned NOT NULL, |
437 | 437 | TXN_ID int(10) unsigned NOT NULL, |
@@ -455,18 +455,18 @@ discard block |
||
455 | 455 | KEY TKT_ID (TKT_ID), |
456 | 456 | KEY EVT_ID (EVT_ID), |
457 | 457 | KEY STS_ID (STS_ID)"; |
458 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
459 | - $table_name = 'esp_registration_payment'; |
|
460 | - $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
458 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
459 | + $table_name = 'esp_registration_payment'; |
|
460 | + $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
461 | 461 | REG_ID int(10) unsigned NOT NULL, |
462 | 462 | PAY_ID int(10) unsigned NULL, |
463 | 463 | RPY_amount decimal(12,3) NOT NULL DEFAULT '0.00', |
464 | 464 | PRIMARY KEY (RPY_ID), |
465 | 465 | KEY REG_ID (REG_ID), |
466 | 466 | KEY PAY_ID (PAY_ID)"; |
467 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
468 | - $table_name = 'esp_state'; |
|
469 | - $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
467 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
468 | + $table_name = 'esp_state'; |
|
469 | + $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
470 | 470 | CNT_ISO varchar(2) NOT NULL, |
471 | 471 | STA_abbrev varchar(24) NOT NULL, |
472 | 472 | STA_name varchar(100) NOT NULL, |
@@ -474,9 +474,9 @@ discard block |
||
474 | 474 | PRIMARY KEY (STA_ID), |
475 | 475 | KEY STA_abbrev (STA_abbrev), |
476 | 476 | KEY CNT_ISO (CNT_ISO)"; |
477 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
478 | - $table_name = 'esp_status'; |
|
479 | - $sql = "STS_ID varchar(3) NOT NULL, |
|
477 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
478 | + $table_name = 'esp_status'; |
|
479 | + $sql = "STS_ID varchar(3) NOT NULL, |
|
480 | 480 | STS_code varchar(45) NOT NULL, |
481 | 481 | STS_type varchar(45) NOT NULL, |
482 | 482 | STS_can_edit tinyint(1) NOT NULL DEFAULT 0, |
@@ -484,9 +484,9 @@ discard block |
||
484 | 484 | STS_open tinyint(1) NOT NULL DEFAULT 1, |
485 | 485 | UNIQUE KEY STS_ID_UNIQUE (STS_ID), |
486 | 486 | KEY STS_type (STS_type)"; |
487 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
488 | - $table_name = 'esp_transaction'; |
|
489 | - $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
487 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
488 | + $table_name = 'esp_transaction'; |
|
489 | + $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
490 | 490 | TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
491 | 491 | TXN_total decimal(12,3) DEFAULT '0.00', |
492 | 492 | TXN_paid decimal(12,3) NOT NULL DEFAULT '0.00', |
@@ -498,9 +498,9 @@ discard block |
||
498 | 498 | PRIMARY KEY (TXN_ID), |
499 | 499 | KEY TXN_timestamp (TXN_timestamp), |
500 | 500 | KEY STS_ID (STS_ID)"; |
501 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
502 | - $table_name = 'esp_venue_meta'; |
|
503 | - $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
501 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
502 | + $table_name = 'esp_venue_meta'; |
|
503 | + $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
504 | 504 | VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
505 | 505 | VNU_address varchar(255) DEFAULT NULL, |
506 | 506 | VNU_address2 varchar(255) DEFAULT NULL, |
@@ -519,10 +519,10 @@ discard block |
||
519 | 519 | KEY VNU_ID (VNU_ID), |
520 | 520 | KEY STA_ID (STA_ID), |
521 | 521 | KEY CNT_ISO (CNT_ISO)"; |
522 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
523 | - //modified tables |
|
524 | - $table_name = "esp_price"; |
|
525 | - $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
522 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
523 | + //modified tables |
|
524 | + $table_name = "esp_price"; |
|
525 | + $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
526 | 526 | PRT_ID tinyint(3) unsigned NOT NULL, |
527 | 527 | PRC_amount decimal(12,3) NOT NULL DEFAULT '0.00', |
528 | 528 | PRC_name varchar(245) NOT NULL, |
@@ -535,9 +535,9 @@ discard block |
||
535 | 535 | PRC_parent int(10) unsigned DEFAULT 0, |
536 | 536 | PRIMARY KEY (PRC_ID), |
537 | 537 | KEY PRT_ID (PRT_ID)"; |
538 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
539 | - $table_name = "esp_price_type"; |
|
540 | - $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
538 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
539 | + $table_name = "esp_price_type"; |
|
540 | + $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
541 | 541 | PRT_name varchar(45) NOT NULL, |
542 | 542 | PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1', |
543 | 543 | PRT_is_percent tinyint(1) NOT NULL DEFAULT '0', |
@@ -546,9 +546,9 @@ discard block |
||
546 | 546 | PRT_deleted tinyint(1) NOT NULL DEFAULT '0', |
547 | 547 | UNIQUE KEY PRT_name_UNIQUE (PRT_name), |
548 | 548 | PRIMARY KEY (PRT_ID)"; |
549 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
550 | - $table_name = "esp_ticket"; |
|
551 | - $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
549 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
550 | + $table_name = "esp_ticket"; |
|
551 | + $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
552 | 552 | TTM_ID int(10) unsigned NOT NULL, |
553 | 553 | TKT_name varchar(245) NOT NULL DEFAULT '', |
554 | 554 | TKT_description text NOT NULL, |
@@ -571,9 +571,9 @@ discard block |
||
571 | 571 | TKT_deleted tinyint(1) NOT NULL DEFAULT '0', |
572 | 572 | PRIMARY KEY (TKT_ID), |
573 | 573 | KEY TKT_start_date (TKT_start_date)"; |
574 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
575 | - $table_name = 'esp_question_group'; |
|
576 | - $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
574 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
575 | + $table_name = 'esp_question_group'; |
|
576 | + $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
577 | 577 | QSG_name varchar(255) NOT NULL, |
578 | 578 | QSG_identifier varchar(100) NOT NULL, |
579 | 579 | QSG_desc text NULL, |
@@ -586,138 +586,138 @@ discard block |
||
586 | 586 | PRIMARY KEY (QSG_ID), |
587 | 587 | UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier), |
588 | 588 | KEY QSG_order (QSG_order)'; |
589 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
590 | - /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */ |
|
591 | - $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0'); |
|
592 | - //(because many need to convert old string states to foreign keys into the states table) |
|
593 | - $script_4_1_defaults->insert_default_states(); |
|
594 | - $script_4_1_defaults->insert_default_countries(); |
|
595 | - /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */ |
|
596 | - $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0'); |
|
597 | - $script_4_5_defaults->insert_default_price_types(); |
|
598 | - $script_4_5_defaults->insert_default_prices(); |
|
599 | - $script_4_5_defaults->insert_default_tickets(); |
|
600 | - /** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */ |
|
601 | - $script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0'); |
|
602 | - $script_4_6_defaults->add_default_admin_only_payments(); |
|
603 | - $script_4_6_defaults->insert_default_currencies(); |
|
604 | - /** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */ |
|
605 | - $script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0'); |
|
606 | - $script_4_8_defaults->verify_new_countries(); |
|
607 | - $script_4_8_defaults->verify_new_currencies(); |
|
608 | - $this->verify_db_collations(); |
|
609 | - $this->verify_db_collations_again(); |
|
610 | - return true; |
|
611 | - } |
|
589 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
590 | + /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */ |
|
591 | + $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0'); |
|
592 | + //(because many need to convert old string states to foreign keys into the states table) |
|
593 | + $script_4_1_defaults->insert_default_states(); |
|
594 | + $script_4_1_defaults->insert_default_countries(); |
|
595 | + /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */ |
|
596 | + $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0'); |
|
597 | + $script_4_5_defaults->insert_default_price_types(); |
|
598 | + $script_4_5_defaults->insert_default_prices(); |
|
599 | + $script_4_5_defaults->insert_default_tickets(); |
|
600 | + /** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */ |
|
601 | + $script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0'); |
|
602 | + $script_4_6_defaults->add_default_admin_only_payments(); |
|
603 | + $script_4_6_defaults->insert_default_currencies(); |
|
604 | + /** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */ |
|
605 | + $script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0'); |
|
606 | + $script_4_8_defaults->verify_new_countries(); |
|
607 | + $script_4_8_defaults->verify_new_currencies(); |
|
608 | + $this->verify_db_collations(); |
|
609 | + $this->verify_db_collations_again(); |
|
610 | + return true; |
|
611 | + } |
|
612 | 612 | |
613 | 613 | |
614 | 614 | |
615 | - /** |
|
616 | - * @return boolean |
|
617 | - */ |
|
618 | - public function schema_changes_after_migration() |
|
619 | - { |
|
620 | - return true; |
|
621 | - } |
|
615 | + /** |
|
616 | + * @return boolean |
|
617 | + */ |
|
618 | + public function schema_changes_after_migration() |
|
619 | + { |
|
620 | + return true; |
|
621 | + } |
|
622 | 622 | |
623 | 623 | |
624 | 624 | |
625 | - public function migration_page_hooks() |
|
626 | - { |
|
627 | - } |
|
625 | + public function migration_page_hooks() |
|
626 | + { |
|
627 | + } |
|
628 | 628 | |
629 | 629 | |
630 | 630 | |
631 | - /** |
|
632 | - * Verify all EE4 models' tables use utf8mb4 collation |
|
633 | - * |
|
634 | - * @return void |
|
635 | - */ |
|
636 | - public function verify_db_collations() |
|
637 | - { |
|
638 | - if (get_option('ee_verified_db_collations', false)) { |
|
639 | - return; |
|
640 | - } |
|
641 | - // grab tables from each model |
|
642 | - $tables_to_check = array(); |
|
643 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
644 | - if (method_exists($model_name, 'instance')) { |
|
645 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
646 | - if ($model_obj instanceof EEM_Base) { |
|
647 | - foreach ($model_obj->get_tables() as $table) { |
|
648 | - if ( |
|
649 | - strpos($table->get_table_name(), 'esp_') |
|
650 | - && (is_main_site()//for main tables, verify global tables |
|
651 | - || ! $table->is_global()//if not the main site, then only verify non-global tables (avoid doubling up) |
|
652 | - ) |
|
653 | - && function_exists('maybe_convert_table_to_utf8mb4') |
|
654 | - ) { |
|
655 | - $tables_to_check[] = $table->get_table_name(); |
|
656 | - } |
|
657 | - } |
|
658 | - } |
|
659 | - } |
|
660 | - } |
|
661 | - //and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active |
|
662 | - //when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead |
|
663 | - //of hard-coding this |
|
664 | - $addon_tables = array( |
|
665 | - //mailchimp |
|
666 | - 'esp_event_mailchimp_list_group', |
|
667 | - 'esp_event_question_mailchimp_field', |
|
668 | - //multisite |
|
669 | - 'esp_blog_meta', |
|
670 | - //people |
|
671 | - 'esp_people_to_post', |
|
672 | - //promotions |
|
673 | - 'esp_promotion', |
|
674 | - 'esp_promotion_object', |
|
675 | - ); |
|
676 | - foreach ($addon_tables as $table_name) { |
|
677 | - $tables_to_check[] = $table_name; |
|
678 | - } |
|
679 | - $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
680 | - //ok and now let's remember this was done (without needing to check the db schemas all over again) |
|
681 | - add_option('ee_verified_db_collations', true, null, 'no'); |
|
682 | - //seeing how this ran with the fix from 10435, no need to check again |
|
683 | - add_option('ee_verified_db_collations_again',true,null,'no'); |
|
684 | - } |
|
631 | + /** |
|
632 | + * Verify all EE4 models' tables use utf8mb4 collation |
|
633 | + * |
|
634 | + * @return void |
|
635 | + */ |
|
636 | + public function verify_db_collations() |
|
637 | + { |
|
638 | + if (get_option('ee_verified_db_collations', false)) { |
|
639 | + return; |
|
640 | + } |
|
641 | + // grab tables from each model |
|
642 | + $tables_to_check = array(); |
|
643 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
644 | + if (method_exists($model_name, 'instance')) { |
|
645 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
646 | + if ($model_obj instanceof EEM_Base) { |
|
647 | + foreach ($model_obj->get_tables() as $table) { |
|
648 | + if ( |
|
649 | + strpos($table->get_table_name(), 'esp_') |
|
650 | + && (is_main_site()//for main tables, verify global tables |
|
651 | + || ! $table->is_global()//if not the main site, then only verify non-global tables (avoid doubling up) |
|
652 | + ) |
|
653 | + && function_exists('maybe_convert_table_to_utf8mb4') |
|
654 | + ) { |
|
655 | + $tables_to_check[] = $table->get_table_name(); |
|
656 | + } |
|
657 | + } |
|
658 | + } |
|
659 | + } |
|
660 | + } |
|
661 | + //and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active |
|
662 | + //when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead |
|
663 | + //of hard-coding this |
|
664 | + $addon_tables = array( |
|
665 | + //mailchimp |
|
666 | + 'esp_event_mailchimp_list_group', |
|
667 | + 'esp_event_question_mailchimp_field', |
|
668 | + //multisite |
|
669 | + 'esp_blog_meta', |
|
670 | + //people |
|
671 | + 'esp_people_to_post', |
|
672 | + //promotions |
|
673 | + 'esp_promotion', |
|
674 | + 'esp_promotion_object', |
|
675 | + ); |
|
676 | + foreach ($addon_tables as $table_name) { |
|
677 | + $tables_to_check[] = $table_name; |
|
678 | + } |
|
679 | + $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
680 | + //ok and now let's remember this was done (without needing to check the db schemas all over again) |
|
681 | + add_option('ee_verified_db_collations', true, null, 'no'); |
|
682 | + //seeing how this ran with the fix from 10435, no need to check again |
|
683 | + add_option('ee_verified_db_collations_again',true,null,'no'); |
|
684 | + } |
|
685 | 685 | |
686 | 686 | |
687 | 687 | |
688 | - /** |
|
689 | - * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435 |
|
690 | - * which meant some DB collations might not have been updated |
|
691 | - * @return void |
|
692 | - */ |
|
693 | - public function verify_db_collations_again(){ |
|
694 | - if (get_option('ee_verified_db_collations_again', false)) { |
|
695 | - return; |
|
696 | - } |
|
697 | - $tables_to_check = array( |
|
698 | - 'esp_attendee_meta', |
|
699 | - 'esp_message' |
|
700 | - ); |
|
701 | - $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
702 | - add_option('ee_verified_db_collations_again',true,null,'no'); |
|
703 | - } |
|
688 | + /** |
|
689 | + * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435 |
|
690 | + * which meant some DB collations might not have been updated |
|
691 | + * @return void |
|
692 | + */ |
|
693 | + public function verify_db_collations_again(){ |
|
694 | + if (get_option('ee_verified_db_collations_again', false)) { |
|
695 | + return; |
|
696 | + } |
|
697 | + $tables_to_check = array( |
|
698 | + 'esp_attendee_meta', |
|
699 | + 'esp_message' |
|
700 | + ); |
|
701 | + $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
702 | + add_option('ee_verified_db_collations_again',true,null,'no'); |
|
703 | + } |
|
704 | 704 | |
705 | 705 | |
706 | 706 | |
707 | - /** |
|
708 | - * Runs maybe_convert_table_to_utf8mb4 on the specified tables |
|
709 | - * @param $tables_to_check |
|
710 | - * @return boolean true if logic ran, false if it didn't |
|
711 | - */ |
|
712 | - protected function _verify_db_collations_for_tables($tables_to_check) |
|
713 | - { |
|
714 | - foreach ($tables_to_check as $table_name) { |
|
715 | - $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name); |
|
716 | - if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name ) |
|
717 | - && $this->_get_table_analysis()->tableExists($table_name) |
|
718 | - ) { |
|
719 | - maybe_convert_table_to_utf8mb4($table_name); |
|
720 | - } |
|
721 | - } |
|
722 | - } |
|
707 | + /** |
|
708 | + * Runs maybe_convert_table_to_utf8mb4 on the specified tables |
|
709 | + * @param $tables_to_check |
|
710 | + * @return boolean true if logic ran, false if it didn't |
|
711 | + */ |
|
712 | + protected function _verify_db_collations_for_tables($tables_to_check) |
|
713 | + { |
|
714 | + foreach ($tables_to_check as $table_name) { |
|
715 | + $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name); |
|
716 | + if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name ) |
|
717 | + && $this->_get_table_analysis()->tableExists($table_name) |
|
718 | + ) { |
|
719 | + maybe_convert_table_to_utf8mb4($table_name); |
|
720 | + } |
|
721 | + } |
|
722 | + } |
|
723 | 723 | } |
724 | 724 | \ No newline at end of file |
@@ -14,9 +14,9 @@ discard block |
||
14 | 14 | $stages = glob(EE_CORE . 'data_migration_scripts/4_6_0_stages/*'); |
15 | 15 | $class_to_filepath = array(); |
16 | 16 | foreach ($stages as $filepath) { |
17 | - $matches = array(); |
|
18 | - preg_match('~4_6_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
19 | - $class_to_filepath[$matches[1]] = $filepath; |
|
17 | + $matches = array(); |
|
18 | + preg_match('~4_6_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
19 | + $class_to_filepath[$matches[1]] = $filepath; |
|
20 | 20 | } |
21 | 21 | //give addons a chance to autoload their stages too |
22 | 22 | $class_to_filepath = apply_filters('FHEE__EE_DMS_4_6_0__autoloaded_stages', $class_to_filepath); |
@@ -35,69 +35,69 @@ discard block |
||
35 | 35 | class EE_DMS_Core_4_6_0 extends EE_Data_Migration_Script_Base |
36 | 36 | { |
37 | 37 | |
38 | - /** |
|
39 | - * return EE_DMS_Core_4_6_0 |
|
40 | - * |
|
41 | - * @param TableManager $table_manager |
|
42 | - * @param TableAnalysis $table_analysis |
|
43 | - */ |
|
44 | - public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
45 | - { |
|
46 | - $this->_pretty_name = __("Data Update to Event Espresso 4.6.0", "event_espresso"); |
|
47 | - $this->_priority = 10; |
|
48 | - $this->_migration_stages = array( |
|
49 | - new EE_DMS_4_6_0_gateways(), |
|
50 | - new EE_DMS_4_6_0_question_types(), |
|
51 | - new EE_DMS_4_6_0_country_system_question(), |
|
52 | - new EE_DMS_4_6_0_state_system_question(), |
|
53 | - new EE_DMS_4_6_0_billing_info(), |
|
54 | - new EE_DMS_4_6_0_transactions(), |
|
55 | - new EE_DMS_4_6_0_payments(), |
|
56 | - new EE_DMS_4_6_0_invoice_settings(), |
|
57 | - ); |
|
58 | - parent::__construct($table_manager, $table_analysis); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * @param array $version_array |
|
65 | - * @return bool |
|
66 | - */ |
|
67 | - public function can_migrate_from_version($version_array) |
|
68 | - { |
|
69 | - $version_string = $version_array['Core']; |
|
70 | - if (version_compare($version_string, '4.6.0', '<=') && version_compare($version_string, '4.5.0', '>=')) { |
|
38 | + /** |
|
39 | + * return EE_DMS_Core_4_6_0 |
|
40 | + * |
|
41 | + * @param TableManager $table_manager |
|
42 | + * @param TableAnalysis $table_analysis |
|
43 | + */ |
|
44 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
45 | + { |
|
46 | + $this->_pretty_name = __("Data Update to Event Espresso 4.6.0", "event_espresso"); |
|
47 | + $this->_priority = 10; |
|
48 | + $this->_migration_stages = array( |
|
49 | + new EE_DMS_4_6_0_gateways(), |
|
50 | + new EE_DMS_4_6_0_question_types(), |
|
51 | + new EE_DMS_4_6_0_country_system_question(), |
|
52 | + new EE_DMS_4_6_0_state_system_question(), |
|
53 | + new EE_DMS_4_6_0_billing_info(), |
|
54 | + new EE_DMS_4_6_0_transactions(), |
|
55 | + new EE_DMS_4_6_0_payments(), |
|
56 | + new EE_DMS_4_6_0_invoice_settings(), |
|
57 | + ); |
|
58 | + parent::__construct($table_manager, $table_analysis); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * @param array $version_array |
|
65 | + * @return bool |
|
66 | + */ |
|
67 | + public function can_migrate_from_version($version_array) |
|
68 | + { |
|
69 | + $version_string = $version_array['Core']; |
|
70 | + if (version_compare($version_string, '4.6.0', '<=') && version_compare($version_string, '4.5.0', '>=')) { |
|
71 | 71 | // echo "$version_string can be migrated from"; |
72 | - return true; |
|
73 | - } elseif ( ! $version_string) { |
|
72 | + return true; |
|
73 | + } elseif ( ! $version_string) { |
|
74 | 74 | // echo "no version string provided: $version_string"; |
75 | - //no version string provided... this must be pre 4.3 |
|
76 | - return false;//changed mind. dont want people thinking they should migrate yet because they cant |
|
77 | - } else { |
|
75 | + //no version string provided... this must be pre 4.3 |
|
76 | + return false;//changed mind. dont want people thinking they should migrate yet because they cant |
|
77 | + } else { |
|
78 | 78 | // echo "$version_string doesnt apply"; |
79 | - return false; |
|
80 | - } |
|
81 | - } |
|
79 | + return false; |
|
80 | + } |
|
81 | + } |
|
82 | 82 | |
83 | 83 | |
84 | 84 | |
85 | - /** |
|
86 | - * @return bool |
|
87 | - */ |
|
88 | - public function schema_changes_before_migration() |
|
89 | - { |
|
90 | - //relies on 4.1's EEH_Activation::create_table |
|
91 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
92 | - $table_name = 'esp_answer'; |
|
93 | - $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
85 | + /** |
|
86 | + * @return bool |
|
87 | + */ |
|
88 | + public function schema_changes_before_migration() |
|
89 | + { |
|
90 | + //relies on 4.1's EEH_Activation::create_table |
|
91 | + require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
92 | + $table_name = 'esp_answer'; |
|
93 | + $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
94 | 94 | REG_ID INT UNSIGNED NOT NULL, |
95 | 95 | QST_ID INT UNSIGNED NOT NULL, |
96 | 96 | ANS_value TEXT NOT NULL, |
97 | 97 | PRIMARY KEY (ANS_ID)"; |
98 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
99 | - $table_name = 'esp_attendee_meta'; |
|
100 | - $sql = "ATTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
98 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
99 | + $table_name = 'esp_attendee_meta'; |
|
100 | + $sql = "ATTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
101 | 101 | ATT_ID BIGINT(20) UNSIGNED NOT NULL, |
102 | 102 | ATT_fname VARCHAR(45) NOT NULL, |
103 | 103 | ATT_lname VARCHAR(45) NOT NULL, |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | KEY ATT_fname (ATT_fname), |
114 | 114 | KEY ATT_lname (ATT_lname), |
115 | 115 | KEY ATT_email (ATT_email)"; |
116 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
117 | - $table_name = 'esp_country'; |
|
118 | - $sql = "CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL, |
|
116 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
117 | + $table_name = 'esp_country'; |
|
118 | + $sql = "CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL, |
|
119 | 119 | CNT_ISO3 VARCHAR(3) COLLATE utf8_bin NOT NULL, |
120 | 120 | RGN_ID TINYINT(3) UNSIGNED DEFAULT NULL, |
121 | 121 | CNT_name VARCHAR(45) COLLATE utf8_bin NOT NULL, |
@@ -131,24 +131,24 @@ discard block |
||
131 | 131 | CNT_is_EU TINYINT(1) DEFAULT '0', |
132 | 132 | CNT_active TINYINT(1) DEFAULT '0', |
133 | 133 | PRIMARY KEY (CNT_ISO)"; |
134 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
135 | - $table_name = 'esp_currency'; |
|
136 | - $sql = "CUR_code VARCHAR(6) COLLATE utf8_bin NOT NULL, |
|
134 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
135 | + $table_name = 'esp_currency'; |
|
136 | + $sql = "CUR_code VARCHAR(6) COLLATE utf8_bin NOT NULL, |
|
137 | 137 | CUR_single VARCHAR(45) COLLATE utf8_bin DEFAULT 'dollar', |
138 | 138 | CUR_plural VARCHAR(45) COLLATE utf8_bin DEFAULT 'dollars', |
139 | 139 | CUR_sign VARCHAR(45) COLLATE utf8_bin DEFAULT '$', |
140 | 140 | CUR_dec_plc VARCHAR(1) COLLATE utf8_bin NOT NULL DEFAULT '2', |
141 | 141 | CUR_active TINYINT(1) DEFAULT '0', |
142 | 142 | PRIMARY KEY (CUR_code)"; |
143 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
144 | - $table_name = 'esp_currency_payment_method'; |
|
145 | - $sql = "CPM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
143 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
144 | + $table_name = 'esp_currency_payment_method'; |
|
145 | + $sql = "CPM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
146 | 146 | CUR_code VARCHAR(6) COLLATE utf8_bin NOT NULL, |
147 | 147 | PMD_ID INT(11) NOT NULL, |
148 | 148 | PRIMARY KEY (CPM_ID)"; |
149 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
150 | - $table_name = 'esp_datetime'; |
|
151 | - $sql = "DTT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
149 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
150 | + $table_name = 'esp_datetime'; |
|
151 | + $sql = "DTT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
152 | 152 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
153 | 153 | DTT_name VARCHAR(255) NOT NULL DEFAULT '', |
154 | 154 | DTT_description TEXT NOT NULL, |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | PRIMARY KEY (DTT_ID), |
164 | 164 | KEY EVT_ID (EVT_ID), |
165 | 165 | KEY DTT_is_primary (DTT_is_primary)"; |
166 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
167 | - $table_name = 'esp_event_meta'; |
|
168 | - $sql = " |
|
166 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
167 | + $table_name = 'esp_event_meta'; |
|
168 | + $sql = " |
|
169 | 169 | EVTM_ID INT NOT NULL AUTO_INCREMENT, |
170 | 170 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
171 | 171 | EVT_display_desc TINYINT(1) UNSIGNED NOT NULL DEFAULT 1, |
@@ -180,31 +180,31 @@ discard block |
||
180 | 180 | EVT_external_URL VARCHAR(200) NULL, |
181 | 181 | EVT_donations TINYINT(1) NULL, |
182 | 182 | PRIMARY KEY (EVTM_ID)"; |
183 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
184 | - $table_name = 'esp_event_question_group'; |
|
185 | - $sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
183 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
184 | + $table_name = 'esp_event_question_group'; |
|
185 | + $sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
186 | 186 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
187 | 187 | QSG_ID INT UNSIGNED NOT NULL, |
188 | 188 | EQG_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
189 | 189 | PRIMARY KEY (EQG_ID)"; |
190 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
191 | - $table_name = 'esp_event_venue'; |
|
192 | - $sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
190 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
191 | + $table_name = 'esp_event_venue'; |
|
192 | + $sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
193 | 193 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
194 | 194 | VNU_ID BIGINT(20) UNSIGNED NOT NULL, |
195 | 195 | EVV_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
196 | 196 | PRIMARY KEY (EVV_ID)"; |
197 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
198 | - $table_name = 'esp_extra_meta'; |
|
199 | - $sql = "EXM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
197 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
198 | + $table_name = 'esp_extra_meta'; |
|
199 | + $sql = "EXM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
200 | 200 | OBJ_ID INT(11) DEFAULT NULL, |
201 | 201 | EXM_type VARCHAR(45) DEFAULT NULL, |
202 | 202 | EXM_key VARCHAR(45) DEFAULT NULL, |
203 | 203 | EXM_value TEXT, |
204 | 204 | PRIMARY KEY (EXM_ID)"; |
205 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
206 | - $table_name = 'esp_line_item'; |
|
207 | - $sql = "LIN_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
205 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
206 | + $table_name = 'esp_line_item'; |
|
207 | + $sql = "LIN_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
208 | 208 | LIN_code VARCHAR(245) NOT NULL DEFAULT '', |
209 | 209 | TXN_ID INT(11) DEFAULT NULL, |
210 | 210 | LIN_name VARCHAR(245) NOT NULL DEFAULT '', |
@@ -220,9 +220,9 @@ discard block |
||
220 | 220 | OBJ_ID INT(11) DEFAULT NULL, |
221 | 221 | OBJ_type VARCHAR(45)DEFAULT NULL, |
222 | 222 | PRIMARY KEY (LIN_ID)"; |
223 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
224 | - $table_name = 'esp_log'; |
|
225 | - $sql = "LOG_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
223 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
224 | + $table_name = 'esp_log'; |
|
225 | + $sql = "LOG_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
226 | 226 | LOG_time DATETIME DEFAULT NULL, |
227 | 227 | OBJ_ID VARCHAR(45) DEFAULT NULL, |
228 | 228 | OBJ_type VARCHAR(45) DEFAULT NULL, |
@@ -230,19 +230,19 @@ discard block |
||
230 | 230 | LOG_message TEXT, |
231 | 231 | LOG_wp_user INT(11) DEFAULT NULL, |
232 | 232 | PRIMARY KEY (LOG_ID)"; |
233 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
234 | - $table_name = 'esp_message_template'; |
|
235 | - $sql = "MTP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
233 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
234 | + $table_name = 'esp_message_template'; |
|
235 | + $sql = "MTP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
236 | 236 | GRP_ID INT(10) UNSIGNED NOT NULL, |
237 | 237 | MTP_context VARCHAR(50) NOT NULL, |
238 | 238 | MTP_template_field VARCHAR(30) NOT NULL, |
239 | 239 | MTP_content TEXT NOT NULL, |
240 | 240 | PRIMARY KEY (MTP_ID), |
241 | 241 | KEY GRP_ID (GRP_ID)"; |
242 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
243 | - $this->_get_table_manager()->dropIndex('esp_message_template_group', 'EVT_ID'); |
|
244 | - $table_name = 'esp_message_template_group'; |
|
245 | - $sql = "GRP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
242 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
243 | + $this->_get_table_manager()->dropIndex('esp_message_template_group', 'EVT_ID'); |
|
244 | + $table_name = 'esp_message_template_group'; |
|
245 | + $sql = "GRP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
246 | 246 | MTP_user_id INT(10) NOT NULL DEFAULT '1', |
247 | 247 | MTP_name VARCHAR(245) NOT NULL DEFAULT '', |
248 | 248 | MTP_description VARCHAR(245) NOT NULL DEFAULT '', |
@@ -254,17 +254,17 @@ discard block |
||
254 | 254 | MTP_is_active TINYINT(1) NOT NULL DEFAULT '1', |
255 | 255 | PRIMARY KEY (GRP_ID), |
256 | 256 | KEY MTP_user_id (MTP_user_id)"; |
257 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
258 | - $table_name = 'esp_event_message_template'; |
|
259 | - $sql = "EMT_ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
257 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
258 | + $table_name = 'esp_event_message_template'; |
|
259 | + $sql = "EMT_ID BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
260 | 260 | EVT_ID BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, |
261 | 261 | GRP_ID INT(10) UNSIGNED NOT NULL DEFAULT 0, |
262 | 262 | PRIMARY KEY (EMT_ID), |
263 | 263 | KEY EVT_ID (EVT_ID), |
264 | 264 | KEY GRP_ID (GRP_ID)"; |
265 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
266 | - $table_name = 'esp_payment'; |
|
267 | - $sql = "PAY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
265 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
266 | + $table_name = 'esp_payment'; |
|
267 | + $sql = "PAY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
268 | 268 | TXN_ID INT(10) UNSIGNED DEFAULT NULL, |
269 | 269 | STS_ID VARCHAR(3) COLLATE utf8_bin DEFAULT NULL, |
270 | 270 | PAY_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -281,9 +281,9 @@ discard block |
||
281 | 281 | PRIMARY KEY (PAY_ID), |
282 | 282 | KEY TXN_ID (TXN_ID), |
283 | 283 | KEY PAY_timestamp (PAY_timestamp)"; |
284 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
285 | - $table_name = 'esp_payment_method'; |
|
286 | - $sql = "PMD_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
284 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
285 | + $table_name = 'esp_payment_method'; |
|
286 | + $sql = "PMD_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
287 | 287 | PMD_type VARCHAR(124) DEFAULT NULL, |
288 | 288 | PMD_name VARCHAR(255) DEFAULT NULL, |
289 | 289 | PMD_desc TEXT, |
@@ -298,28 +298,28 @@ discard block |
||
298 | 298 | PMD_scope VARCHAR(255) NULL DEFAULT 'frontend', |
299 | 299 | PRIMARY KEY (PMD_ID), |
300 | 300 | UNIQUE KEY PMD_slug_UNIQUE (PMD_slug)"; |
301 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
302 | - $table_name = "esp_ticket_price"; |
|
303 | - $sql = "TKP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
301 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
302 | + $table_name = "esp_ticket_price"; |
|
303 | + $sql = "TKP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
304 | 304 | TKT_ID INT(10) UNSIGNED NOT NULL, |
305 | 305 | PRC_ID INT(10) UNSIGNED NOT NULL, |
306 | 306 | PRIMARY KEY (TKP_ID)"; |
307 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
308 | - $table_name = "esp_datetime_ticket"; |
|
309 | - $sql = "DTK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
307 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
308 | + $table_name = "esp_datetime_ticket"; |
|
309 | + $sql = "DTK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
310 | 310 | DTT_ID INT(10) UNSIGNED NOT NULL, |
311 | 311 | TKT_ID INT(10) UNSIGNED NOT NULL, |
312 | 312 | PRIMARY KEY (DTK_ID)"; |
313 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
314 | - $table_name = "esp_ticket_template"; |
|
315 | - $sql = "TTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
313 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
314 | + $table_name = "esp_ticket_template"; |
|
315 | + $sql = "TTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
316 | 316 | TTM_name VARCHAR(45) NOT NULL, |
317 | 317 | TTM_description TEXT, |
318 | 318 | TTM_file VARCHAR(45), |
319 | 319 | PRIMARY KEY (TTM_ID)"; |
320 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
321 | - $table_name = 'esp_question'; |
|
322 | - $sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
320 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
321 | + $table_name = 'esp_question'; |
|
322 | + $sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
323 | 323 | QST_display_text TEXT NOT NULL, |
324 | 324 | QST_admin_label VARCHAR(255) NOT NULL, |
325 | 325 | QST_system VARCHAR(25) DEFAULT NULL, |
@@ -331,25 +331,25 @@ discard block |
||
331 | 331 | QST_wp_user BIGINT UNSIGNED NULL, |
332 | 332 | QST_deleted TINYINT UNSIGNED NOT NULL DEFAULT 0, |
333 | 333 | PRIMARY KEY (QST_ID)'; |
334 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
335 | - $table_name = 'esp_question_group_question'; |
|
336 | - $sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
334 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
335 | + $table_name = 'esp_question_group_question'; |
|
336 | + $sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
337 | 337 | QSG_ID INT UNSIGNED NOT NULL, |
338 | 338 | QST_ID INT UNSIGNED NOT NULL, |
339 | 339 | QGQ_order INT UNSIGNED NOT NULL DEFAULT 0, |
340 | 340 | PRIMARY KEY (QGQ_ID) "; |
341 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
342 | - $table_name = 'esp_question_option'; |
|
343 | - $sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
341 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
342 | + $table_name = 'esp_question_option'; |
|
343 | + $sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
344 | 344 | QSO_value VARCHAR(255) NOT NULL, |
345 | 345 | QSO_desc TEXT NOT NULL, |
346 | 346 | QST_ID INT UNSIGNED NOT NULL, |
347 | 347 | QSO_order INT UNSIGNED NOT NULL DEFAULT 0, |
348 | 348 | QSO_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
349 | 349 | PRIMARY KEY (QSO_ID)"; |
350 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
351 | - $table_name = 'esp_registration'; |
|
352 | - $sql = "REG_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
350 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
351 | + $table_name = 'esp_registration'; |
|
352 | + $sql = "REG_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
353 | 353 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
354 | 354 | ATT_ID BIGINT(20) UNSIGNED NOT NULL, |
355 | 355 | TXN_ID INT(10) UNSIGNED NOT NULL, |
@@ -372,25 +372,25 @@ discard block |
||
372 | 372 | KEY STS_ID (STS_ID), |
373 | 373 | KEY REG_url_link (REG_url_link), |
374 | 374 | KEY REG_code (REG_code)"; |
375 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
376 | - $table_name = 'esp_checkin'; |
|
377 | - $sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
375 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
376 | + $table_name = 'esp_checkin'; |
|
377 | + $sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
378 | 378 | REG_ID INT(10) UNSIGNED NOT NULL, |
379 | 379 | DTT_ID INT(10) UNSIGNED NOT NULL, |
380 | 380 | CHK_in TINYINT(1) UNSIGNED NOT NULL DEFAULT 1, |
381 | 381 | CHK_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
382 | 382 | PRIMARY KEY (CHK_ID)"; |
383 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
384 | - $table_name = 'esp_state'; |
|
385 | - $sql = "STA_ID smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
383 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
384 | + $table_name = 'esp_state'; |
|
385 | + $sql = "STA_ID smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
386 | 386 | CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL, |
387 | 387 | STA_abbrev VARCHAR(24) COLLATE utf8_bin NOT NULL, |
388 | 388 | STA_name VARCHAR(100) COLLATE utf8_bin NOT NULL, |
389 | 389 | STA_active TINYINT(1) DEFAULT '1', |
390 | 390 | PRIMARY KEY (STA_ID)"; |
391 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
392 | - $table_name = 'esp_status'; |
|
393 | - $sql = "STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL, |
|
391 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
392 | + $table_name = 'esp_status'; |
|
393 | + $sql = "STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL, |
|
394 | 394 | STS_code VARCHAR(45) COLLATE utf8_bin NOT NULL, |
395 | 395 | STS_type set('event','registration','transaction','payment','email') COLLATE utf8_bin NOT NULL, |
396 | 396 | STS_can_edit TINYINT(1) NOT NULL DEFAULT 0, |
@@ -398,9 +398,9 @@ discard block |
||
398 | 398 | STS_open TINYINT(1) NOT NULL DEFAULT 1, |
399 | 399 | UNIQUE KEY STS_ID_UNIQUE (STS_ID), |
400 | 400 | KEY STS_type (STS_type)"; |
401 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
402 | - $table_name = 'esp_transaction'; |
|
403 | - $sql = "TXN_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
401 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
402 | + $table_name = 'esp_transaction'; |
|
403 | + $sql = "TXN_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
404 | 404 | TXN_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
405 | 405 | TXN_total DECIMAL(10,3) DEFAULT '0.00', |
406 | 406 | TXN_paid DECIMAL(10,3) NOT NULL DEFAULT '0.00', |
@@ -412,9 +412,9 @@ discard block |
||
412 | 412 | PRIMARY KEY (TXN_ID), |
413 | 413 | KEY TXN_timestamp (TXN_timestamp), |
414 | 414 | KEY STS_ID (STS_ID)"; |
415 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
416 | - $table_name = 'esp_venue_meta'; |
|
417 | - $sql = "VNUM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
415 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
416 | + $table_name = 'esp_venue_meta'; |
|
417 | + $sql = "VNUM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
418 | 418 | VNU_ID BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, |
419 | 419 | VNU_address VARCHAR(255) DEFAULT NULL, |
420 | 420 | VNU_address2 VARCHAR(255) DEFAULT NULL, |
@@ -432,10 +432,10 @@ discard block |
||
432 | 432 | PRIMARY KEY (VNUM_ID), |
433 | 433 | KEY STA_ID (STA_ID), |
434 | 434 | KEY CNT_ISO (CNT_ISO)"; |
435 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
436 | - //modified tables |
|
437 | - $table_name = "esp_price"; |
|
438 | - $sql = "PRC_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
435 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
436 | + //modified tables |
|
437 | + $table_name = "esp_price"; |
|
438 | + $sql = "PRC_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
439 | 439 | PRT_ID TINYINT(3) UNSIGNED NOT NULL, |
440 | 440 | PRC_amount DECIMAL(10,3) NOT NULL DEFAULT '0.00', |
441 | 441 | PRC_name VARCHAR(245) NOT NULL, |
@@ -447,9 +447,9 @@ discard block |
||
447 | 447 | PRC_wp_user BIGINT UNSIGNED NULL, |
448 | 448 | PRC_parent INT(10) UNSIGNED DEFAULT 0, |
449 | 449 | PRIMARY KEY (PRC_ID)"; |
450 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
451 | - $table_name = "esp_price_type"; |
|
452 | - $sql = "PRT_ID TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
450 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
451 | + $table_name = "esp_price_type"; |
|
452 | + $sql = "PRT_ID TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
453 | 453 | PRT_name VARCHAR(45) NOT NULL, |
454 | 454 | PBT_ID TINYINT(3) UNSIGNED NOT NULL DEFAULT '1', |
455 | 455 | PRT_is_percent TINYINT(1) NOT NULL DEFAULT '0', |
@@ -458,9 +458,9 @@ discard block |
||
458 | 458 | PRT_deleted TINYINT(1) NOT NULL DEFAULT '0', |
459 | 459 | UNIQUE KEY PRT_name_UNIQUE (PRT_name), |
460 | 460 | PRIMARY KEY (PRT_ID)"; |
461 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
462 | - $table_name = "esp_ticket"; |
|
463 | - $sql = "TKT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
461 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB '); |
|
462 | + $table_name = "esp_ticket"; |
|
463 | + $sql = "TKT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
464 | 464 | TTM_ID INT(10) UNSIGNED NOT NULL, |
465 | 465 | TKT_name VARCHAR(245) NOT NULL DEFAULT '', |
466 | 466 | TKT_description TEXT NOT NULL, |
@@ -481,10 +481,10 @@ discard block |
||
481 | 481 | TKT_parent INT(10) UNSIGNED DEFAULT '0', |
482 | 482 | TKT_deleted TINYINT(1) NOT NULL DEFAULT '0', |
483 | 483 | PRIMARY KEY (TKT_ID)"; |
484 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
485 | - $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE'); |
|
486 | - $table_name = 'esp_question_group'; |
|
487 | - $sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
484 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
485 | + $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE'); |
|
486 | + $table_name = 'esp_question_group'; |
|
487 | + $sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
488 | 488 | QSG_name VARCHAR(255) NOT NULL, |
489 | 489 | QSG_identifier VARCHAR(100) NOT NULL, |
490 | 490 | QSG_desc TEXT NULL, |
@@ -496,119 +496,119 @@ discard block |
||
496 | 496 | QSG_wp_user BIGINT UNSIGNED NULL, |
497 | 497 | PRIMARY KEY (QSG_ID), |
498 | 498 | UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier ASC)'; |
499 | - $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
500 | - /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */ |
|
501 | - $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0'); |
|
502 | - //(because many need to convert old string states to foreign keys into the states table) |
|
503 | - $script_4_1_defaults->insert_default_states(); |
|
504 | - $script_4_1_defaults->insert_default_countries(); |
|
505 | - /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */ |
|
506 | - $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0'); |
|
507 | - $script_4_5_defaults->insert_default_price_types(); |
|
508 | - $script_4_5_defaults->insert_default_prices(); |
|
509 | - $script_4_5_defaults->insert_default_tickets(); |
|
510 | - //setting up the config wp option pretty well counts as a 'schema change', or at least should happen here |
|
511 | - EE_Config::instance()->update_espresso_config(false, true); |
|
512 | - $this->add_default_admin_only_payments(); |
|
513 | - $this->insert_default_currencies(); |
|
514 | - return true; |
|
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - |
|
519 | - /** |
|
520 | - * @return boolean |
|
521 | - */ |
|
522 | - public function schema_changes_after_migration() |
|
523 | - { |
|
524 | - return true; |
|
525 | - } |
|
526 | - |
|
527 | - |
|
528 | - |
|
529 | - public function migration_page_hooks() |
|
530 | - { |
|
531 | - } |
|
532 | - |
|
533 | - |
|
534 | - |
|
535 | - public function add_default_admin_only_payments() |
|
536 | - { |
|
537 | - global $wpdb; |
|
538 | - $table_name = $wpdb->prefix . "esp_payment_method"; |
|
539 | - $user_id = EEH_Activation::get_default_creator_id(); |
|
540 | - if ($this->_get_table_analysis()->tableExists($table_name)) { |
|
541 | - $SQL = "SELECT COUNT( * ) FROM $table_name"; |
|
542 | - $existing_payment_methods = $wpdb->get_var($SQL); |
|
543 | - $default_admin_only_payment_methods = apply_filters( |
|
544 | - 'FHEE__EEH_Activation__add_default_admin_only_payments__default_admin_only_payment_methods', |
|
545 | - array( |
|
546 | - __("Bank", 'event_espresso') => __("Bank Draft", 'event_espresso'), |
|
547 | - __("Cash", 'event_espresso') => __("Cash Delivered Physically", 'event_espresso'), |
|
548 | - __("Check", 'event_espresso') => __("Paper Check", 'event_espresso'), |
|
549 | - __("Credit Card", 'event_espresso') => __("Offline Credit Card Payment", 'event_espresso'), |
|
550 | - __("Debit Card", 'event_espresso') => __("Offline Debit Payment", 'event_espresso'), |
|
551 | - __("Invoice", 'event_espresso') => __("Invoice received with monies included", |
|
552 | - 'event_espresso'), |
|
553 | - __("Money Order", 'event_espresso') => '', |
|
554 | - __("Paypal", 'event_espresso') => __("Paypal eCheck, Invoice, etc", 'event_espresso'), |
|
555 | - __('Other', 'event_espresso') => __('Other method of payment', 'event_espresso'), |
|
556 | - )); |
|
557 | - //make sure we hae payment method records for the following |
|
558 | - //so admins can record payments for them from the admin page |
|
559 | - foreach ($default_admin_only_payment_methods as $nicename => $description) { |
|
560 | - $slug = sanitize_key($nicename); |
|
561 | - //check that such a payment method exists |
|
562 | - $exists = $wpdb->get_var($wpdb->prepare("SELECT count(*) FROM $table_name WHERE PMD_slug = %s", $slug)); |
|
563 | - if ( ! $exists) { |
|
564 | - $values = array( |
|
565 | - 'PMD_type' => 'Admin_Only', |
|
566 | - 'PMD_name' => $nicename, |
|
567 | - 'PMD_admin_name' => $nicename, |
|
568 | - 'PMD_admin_desc' => $description, |
|
569 | - 'PMD_slug' => $slug, |
|
570 | - 'PMD_wp_user' => $user_id, |
|
571 | - 'PMD_scope' => serialize(array('ADMIN')), |
|
572 | - ); |
|
573 | - $success = $wpdb->insert( |
|
574 | - $table_name, |
|
575 | - $values, |
|
576 | - array( |
|
577 | - '%s',//PMD_type |
|
578 | - '%s',//PMD_name |
|
579 | - '%s',//PMD_admin_name |
|
580 | - '%s',//PMD_admin_desc |
|
581 | - '%s',//PMD_slug |
|
582 | - '%d',//PMD_wp_user |
|
583 | - '%s',//PMD_scope |
|
584 | - ) |
|
585 | - ); |
|
586 | - if ( ! $success) { |
|
587 | - $this->add_error(sprintf(__("Could not insert new admin-only payment method with values %s during migration", |
|
588 | - "event_espresso"), $this->_json_encode($values))); |
|
589 | - } |
|
590 | - } |
|
591 | - } |
|
592 | - } |
|
593 | - } |
|
594 | - |
|
595 | - |
|
596 | - |
|
597 | - /** |
|
598 | - * insert_default_countries |
|
599 | - * |
|
600 | - * @static |
|
601 | - * @return void |
|
602 | - */ |
|
603 | - public function insert_default_currencies() |
|
604 | - { |
|
605 | - global $wpdb; |
|
606 | - $currency_table = $wpdb->prefix . "esp_currency"; |
|
607 | - if ($this->_get_table_analysis()->tableExists($currency_table)) { |
|
608 | - $SQL = "SELECT COUNT('CUR_code') FROM $currency_table"; |
|
609 | - $countries = $wpdb->get_var($SQL); |
|
610 | - if ( ! $countries) { |
|
611 | - $SQL = "INSERT INTO $currency_table |
|
499 | + $this->_table_should_exist_previously($table_name, $sql, 'ENGINE=InnoDB'); |
|
500 | + /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */ |
|
501 | + $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0'); |
|
502 | + //(because many need to convert old string states to foreign keys into the states table) |
|
503 | + $script_4_1_defaults->insert_default_states(); |
|
504 | + $script_4_1_defaults->insert_default_countries(); |
|
505 | + /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */ |
|
506 | + $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0'); |
|
507 | + $script_4_5_defaults->insert_default_price_types(); |
|
508 | + $script_4_5_defaults->insert_default_prices(); |
|
509 | + $script_4_5_defaults->insert_default_tickets(); |
|
510 | + //setting up the config wp option pretty well counts as a 'schema change', or at least should happen here |
|
511 | + EE_Config::instance()->update_espresso_config(false, true); |
|
512 | + $this->add_default_admin_only_payments(); |
|
513 | + $this->insert_default_currencies(); |
|
514 | + return true; |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + |
|
519 | + /** |
|
520 | + * @return boolean |
|
521 | + */ |
|
522 | + public function schema_changes_after_migration() |
|
523 | + { |
|
524 | + return true; |
|
525 | + } |
|
526 | + |
|
527 | + |
|
528 | + |
|
529 | + public function migration_page_hooks() |
|
530 | + { |
|
531 | + } |
|
532 | + |
|
533 | + |
|
534 | + |
|
535 | + public function add_default_admin_only_payments() |
|
536 | + { |
|
537 | + global $wpdb; |
|
538 | + $table_name = $wpdb->prefix . "esp_payment_method"; |
|
539 | + $user_id = EEH_Activation::get_default_creator_id(); |
|
540 | + if ($this->_get_table_analysis()->tableExists($table_name)) { |
|
541 | + $SQL = "SELECT COUNT( * ) FROM $table_name"; |
|
542 | + $existing_payment_methods = $wpdb->get_var($SQL); |
|
543 | + $default_admin_only_payment_methods = apply_filters( |
|
544 | + 'FHEE__EEH_Activation__add_default_admin_only_payments__default_admin_only_payment_methods', |
|
545 | + array( |
|
546 | + __("Bank", 'event_espresso') => __("Bank Draft", 'event_espresso'), |
|
547 | + __("Cash", 'event_espresso') => __("Cash Delivered Physically", 'event_espresso'), |
|
548 | + __("Check", 'event_espresso') => __("Paper Check", 'event_espresso'), |
|
549 | + __("Credit Card", 'event_espresso') => __("Offline Credit Card Payment", 'event_espresso'), |
|
550 | + __("Debit Card", 'event_espresso') => __("Offline Debit Payment", 'event_espresso'), |
|
551 | + __("Invoice", 'event_espresso') => __("Invoice received with monies included", |
|
552 | + 'event_espresso'), |
|
553 | + __("Money Order", 'event_espresso') => '', |
|
554 | + __("Paypal", 'event_espresso') => __("Paypal eCheck, Invoice, etc", 'event_espresso'), |
|
555 | + __('Other', 'event_espresso') => __('Other method of payment', 'event_espresso'), |
|
556 | + )); |
|
557 | + //make sure we hae payment method records for the following |
|
558 | + //so admins can record payments for them from the admin page |
|
559 | + foreach ($default_admin_only_payment_methods as $nicename => $description) { |
|
560 | + $slug = sanitize_key($nicename); |
|
561 | + //check that such a payment method exists |
|
562 | + $exists = $wpdb->get_var($wpdb->prepare("SELECT count(*) FROM $table_name WHERE PMD_slug = %s", $slug)); |
|
563 | + if ( ! $exists) { |
|
564 | + $values = array( |
|
565 | + 'PMD_type' => 'Admin_Only', |
|
566 | + 'PMD_name' => $nicename, |
|
567 | + 'PMD_admin_name' => $nicename, |
|
568 | + 'PMD_admin_desc' => $description, |
|
569 | + 'PMD_slug' => $slug, |
|
570 | + 'PMD_wp_user' => $user_id, |
|
571 | + 'PMD_scope' => serialize(array('ADMIN')), |
|
572 | + ); |
|
573 | + $success = $wpdb->insert( |
|
574 | + $table_name, |
|
575 | + $values, |
|
576 | + array( |
|
577 | + '%s',//PMD_type |
|
578 | + '%s',//PMD_name |
|
579 | + '%s',//PMD_admin_name |
|
580 | + '%s',//PMD_admin_desc |
|
581 | + '%s',//PMD_slug |
|
582 | + '%d',//PMD_wp_user |
|
583 | + '%s',//PMD_scope |
|
584 | + ) |
|
585 | + ); |
|
586 | + if ( ! $success) { |
|
587 | + $this->add_error(sprintf(__("Could not insert new admin-only payment method with values %s during migration", |
|
588 | + "event_espresso"), $this->_json_encode($values))); |
|
589 | + } |
|
590 | + } |
|
591 | + } |
|
592 | + } |
|
593 | + } |
|
594 | + |
|
595 | + |
|
596 | + |
|
597 | + /** |
|
598 | + * insert_default_countries |
|
599 | + * |
|
600 | + * @static |
|
601 | + * @return void |
|
602 | + */ |
|
603 | + public function insert_default_currencies() |
|
604 | + { |
|
605 | + global $wpdb; |
|
606 | + $currency_table = $wpdb->prefix . "esp_currency"; |
|
607 | + if ($this->_get_table_analysis()->tableExists($currency_table)) { |
|
608 | + $SQL = "SELECT COUNT('CUR_code') FROM $currency_table"; |
|
609 | + $countries = $wpdb->get_var($SQL); |
|
610 | + if ( ! $countries) { |
|
611 | + $SQL = "INSERT INTO $currency_table |
|
612 | 612 | ( CUR_code, CUR_single, CUR_plural, CUR_sign, CUR_dec_plc, CUR_active) VALUES |
613 | 613 | ( 'EUR', 'Euro', 'Euros', '€', 2,1), |
614 | 614 | ( 'AED', 'Dirham', 'Dirhams', 'د.إ',2,1), |
@@ -762,10 +762,10 @@ discard block |
||
762 | 762 | ( 'ZAR', 'Rand', 'Rands', 'R', 2,1), |
763 | 763 | ( 'ZMK', 'Kwacha', 'Kwachas', '', 2,1), |
764 | 764 | ( 'ZWD', 'Dollar', 'Dollars', 'Z$', 2,1);"; |
765 | - $wpdb->query($SQL); |
|
766 | - } |
|
767 | - } |
|
768 | - } |
|
765 | + $wpdb->query($SQL); |
|
766 | + } |
|
767 | + } |
|
768 | + } |
|
769 | 769 | |
770 | 770 | } |
771 | 771 |
@@ -33,211 +33,211 @@ |
||
33 | 33 | class ShortcodesManager |
34 | 34 | { |
35 | 35 | |
36 | - /** |
|
37 | - * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
38 | - */ |
|
39 | - private $legacy_shortcodes_manager; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var ShortcodeInterface[] $shortcodes |
|
43 | - */ |
|
44 | - private $shortcodes; |
|
45 | - |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * ShortcodesManager constructor |
|
50 | - * |
|
51 | - * @param LegacyShortcodesManager $legacy_shortcodes_manager |
|
52 | - */ |
|
53 | - public function __construct(LegacyShortcodesManager $legacy_shortcodes_manager) { |
|
54 | - $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
55 | - // assemble a list of installed and active shortcodes |
|
56 | - add_action( |
|
57 | - 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
58 | - array($this, 'registerShortcodes'), |
|
59 | - 999 |
|
60 | - ); |
|
61 | - // call add_shortcode() for all installed shortcodes |
|
62 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'addShortcodes')); |
|
63 | - // check content for shortcodes the old way |
|
64 | - add_action('parse_query', array($this->legacy_shortcodes_manager, 'initializeShortcodes'), 5); |
|
65 | - // check content for shortcodes the NEW more efficient way |
|
66 | - add_action('wp_head', array($this, 'wpHead'), 0); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @return CollectionInterface|ShortcodeInterface[] |
|
73 | - * @throws InvalidIdentifierException |
|
74 | - * @throws InvalidInterfaceException |
|
75 | - * @throws InvalidFilePathException |
|
76 | - * @throws InvalidEntityException |
|
77 | - * @throws InvalidDataTypeException |
|
78 | - * @throws InvalidClassException |
|
79 | - */ |
|
80 | - public function getShortcodes() |
|
81 | - { |
|
82 | - if ( ! $this->shortcodes instanceof CollectionInterface) { |
|
83 | - $this->shortcodes = $this->loadShortcodesCollection(); |
|
84 | - } |
|
85 | - return $this->shortcodes; |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * @return CollectionInterface|ShortcodeInterface[] |
|
92 | - * @throws InvalidIdentifierException |
|
93 | - * @throws InvalidInterfaceException |
|
94 | - * @throws InvalidFilePathException |
|
95 | - * @throws InvalidEntityException |
|
96 | - * @throws InvalidDataTypeException |
|
97 | - * @throws InvalidClassException |
|
98 | - */ |
|
99 | - protected function loadShortcodesCollection() |
|
100 | - { |
|
101 | - $loader = new CollectionLoader( |
|
102 | - new CollectionDetails( |
|
103 | - // collection name |
|
104 | - 'shortcodes', |
|
105 | - // collection interface |
|
106 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
107 | - // FQCNs for classes to add (all classes within that namespace will be loaded) |
|
108 | - array('EventEspresso\core\domain\entities\shortcodes'), |
|
109 | - // filepaths to classes to add |
|
110 | - array(), |
|
111 | - // filemask to use if parsing folder for files to add |
|
112 | - '', |
|
113 | - // what to use as identifier for collection entities |
|
114 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
115 | - CollectionDetails::ID_CLASS_NAME |
|
116 | - ) |
|
117 | - ); |
|
118 | - return $loader->getCollection(); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @return void |
|
125 | - * @throws DomainException |
|
126 | - * @throws InvalidInterfaceException |
|
127 | - * @throws InvalidIdentifierException |
|
128 | - * @throws InvalidFilePathException |
|
129 | - * @throws InvalidEntityException |
|
130 | - * @throws InvalidDataTypeException |
|
131 | - * @throws InvalidClassException |
|
132 | - */ |
|
133 | - public function registerShortcodes() |
|
134 | - { |
|
135 | - try { |
|
136 | - $this->shortcodes = apply_filters( |
|
137 | - 'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection', |
|
138 | - $this->getShortcodes() |
|
139 | - ); |
|
140 | - if (! $this->shortcodes instanceof CollectionInterface) { |
|
141 | - throw new InvalidEntityException( |
|
142 | - $this->shortcodes, |
|
143 | - 'CollectionInterface', |
|
144 | - sprintf( |
|
145 | - esc_html__( |
|
146 | - 'The "FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection" filter must return a Collection of EspressoShortcode objects. "%1$s" was received instead.', |
|
147 | - 'event_espresso' |
|
148 | - ), |
|
149 | - is_object($this->shortcodes) ? get_class($this->shortcodes) : gettype($this->shortcodes) |
|
150 | - ) |
|
151 | - ); |
|
152 | - } |
|
153 | - $this->legacy_shortcodes_manager->registerShortcodes(); |
|
154 | - } catch (Exception $exception) { |
|
155 | - new ExceptionStackTraceDisplay($exception); |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @return void |
|
163 | - */ |
|
164 | - public function addShortcodes() |
|
165 | - { |
|
166 | - try { |
|
167 | - // cycle thru shortcode folders |
|
168 | - foreach ($this->shortcodes as $shortcode) { |
|
169 | - /** @var ShortcodeInterface $shortcode */ |
|
170 | - if ( $shortcode instanceof EnqueueAssetsInterface) { |
|
171 | - add_action('wp_enqueue_scripts', array($shortcode, 'registerScriptsAndStylesheets'), 10); |
|
172 | - add_action('wp_enqueue_scripts', array($shortcode, 'enqueueStylesheets'), 11); |
|
173 | - } |
|
174 | - // add_shortcode() if it has not already been added |
|
175 | - if ( ! shortcode_exists($shortcode->getTag())) { |
|
176 | - add_shortcode($shortcode->getTag(), array($shortcode, 'processShortcodeCallback')); |
|
177 | - } |
|
178 | - } |
|
179 | - $this->legacy_shortcodes_manager->addShortcodes(); |
|
180 | - } catch (Exception $exception) { |
|
181 | - new ExceptionStackTraceDisplay($exception); |
|
182 | - } |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * callback for the "wp_head" hook point |
|
189 | - * checks posts for EE shortcodes, and initializes them, |
|
190 | - * then toggles filter switch that loads core default assets |
|
191 | - * |
|
192 | - * @return void |
|
193 | - */ |
|
194 | - public function wpHead() |
|
195 | - { |
|
196 | - global $wp_query; |
|
197 | - if (empty($wp_query->posts)) { |
|
198 | - return; |
|
199 | - } |
|
200 | - $load_assets = false; |
|
201 | - // array of posts displayed in current request |
|
202 | - $posts = is_array($wp_query->posts) ? $wp_query->posts : array($wp_query->posts); |
|
203 | - foreach ($posts as $post) { |
|
204 | - // now check post content and excerpt for EE shortcodes |
|
205 | - $load_assets = $this->parseContentForShortcodes($post->post_content) |
|
206 | - ? true |
|
207 | - : $load_assets; |
|
208 | - } |
|
209 | - if ($load_assets) { |
|
210 | - $this->legacy_shortcodes_manager->registry()->REQ->set_espresso_page(true); |
|
211 | - add_filter('FHEE_load_css', '__return_true'); |
|
212 | - add_filter('FHEE_load_js', '__return_true'); |
|
213 | - } |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * checks supplied content against list of shortcodes, |
|
220 | - * then initializes any found shortcodes, and returns true. |
|
221 | - * returns false if no shortcodes found. |
|
222 | - * |
|
223 | - * @param string $content |
|
224 | - * @return bool |
|
225 | - */ |
|
226 | - public function parseContentForShortcodes($content) |
|
227 | - { |
|
228 | - $has_shortcode = false; |
|
229 | - if(empty($this->shortcodes)){ |
|
230 | - return $has_shortcode; |
|
231 | - } |
|
232 | - foreach ($this->shortcodes as $shortcode) { |
|
233 | - /** @var ShortcodeInterface $shortcode */ |
|
234 | - if (has_shortcode($content, $shortcode->getTag())) { |
|
235 | - $shortcode->initializeShortcode(); |
|
236 | - $has_shortcode = true; |
|
237 | - } |
|
238 | - } |
|
239 | - return $has_shortcode; |
|
240 | - } |
|
36 | + /** |
|
37 | + * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
38 | + */ |
|
39 | + private $legacy_shortcodes_manager; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var ShortcodeInterface[] $shortcodes |
|
43 | + */ |
|
44 | + private $shortcodes; |
|
45 | + |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * ShortcodesManager constructor |
|
50 | + * |
|
51 | + * @param LegacyShortcodesManager $legacy_shortcodes_manager |
|
52 | + */ |
|
53 | + public function __construct(LegacyShortcodesManager $legacy_shortcodes_manager) { |
|
54 | + $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
55 | + // assemble a list of installed and active shortcodes |
|
56 | + add_action( |
|
57 | + 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
58 | + array($this, 'registerShortcodes'), |
|
59 | + 999 |
|
60 | + ); |
|
61 | + // call add_shortcode() for all installed shortcodes |
|
62 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'addShortcodes')); |
|
63 | + // check content for shortcodes the old way |
|
64 | + add_action('parse_query', array($this->legacy_shortcodes_manager, 'initializeShortcodes'), 5); |
|
65 | + // check content for shortcodes the NEW more efficient way |
|
66 | + add_action('wp_head', array($this, 'wpHead'), 0); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @return CollectionInterface|ShortcodeInterface[] |
|
73 | + * @throws InvalidIdentifierException |
|
74 | + * @throws InvalidInterfaceException |
|
75 | + * @throws InvalidFilePathException |
|
76 | + * @throws InvalidEntityException |
|
77 | + * @throws InvalidDataTypeException |
|
78 | + * @throws InvalidClassException |
|
79 | + */ |
|
80 | + public function getShortcodes() |
|
81 | + { |
|
82 | + if ( ! $this->shortcodes instanceof CollectionInterface) { |
|
83 | + $this->shortcodes = $this->loadShortcodesCollection(); |
|
84 | + } |
|
85 | + return $this->shortcodes; |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * @return CollectionInterface|ShortcodeInterface[] |
|
92 | + * @throws InvalidIdentifierException |
|
93 | + * @throws InvalidInterfaceException |
|
94 | + * @throws InvalidFilePathException |
|
95 | + * @throws InvalidEntityException |
|
96 | + * @throws InvalidDataTypeException |
|
97 | + * @throws InvalidClassException |
|
98 | + */ |
|
99 | + protected function loadShortcodesCollection() |
|
100 | + { |
|
101 | + $loader = new CollectionLoader( |
|
102 | + new CollectionDetails( |
|
103 | + // collection name |
|
104 | + 'shortcodes', |
|
105 | + // collection interface |
|
106 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
107 | + // FQCNs for classes to add (all classes within that namespace will be loaded) |
|
108 | + array('EventEspresso\core\domain\entities\shortcodes'), |
|
109 | + // filepaths to classes to add |
|
110 | + array(), |
|
111 | + // filemask to use if parsing folder for files to add |
|
112 | + '', |
|
113 | + // what to use as identifier for collection entities |
|
114 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
115 | + CollectionDetails::ID_CLASS_NAME |
|
116 | + ) |
|
117 | + ); |
|
118 | + return $loader->getCollection(); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @return void |
|
125 | + * @throws DomainException |
|
126 | + * @throws InvalidInterfaceException |
|
127 | + * @throws InvalidIdentifierException |
|
128 | + * @throws InvalidFilePathException |
|
129 | + * @throws InvalidEntityException |
|
130 | + * @throws InvalidDataTypeException |
|
131 | + * @throws InvalidClassException |
|
132 | + */ |
|
133 | + public function registerShortcodes() |
|
134 | + { |
|
135 | + try { |
|
136 | + $this->shortcodes = apply_filters( |
|
137 | + 'FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection', |
|
138 | + $this->getShortcodes() |
|
139 | + ); |
|
140 | + if (! $this->shortcodes instanceof CollectionInterface) { |
|
141 | + throw new InvalidEntityException( |
|
142 | + $this->shortcodes, |
|
143 | + 'CollectionInterface', |
|
144 | + sprintf( |
|
145 | + esc_html__( |
|
146 | + 'The "FHEE__EventEspresso_core_services_shortcodes_ShortcodesManager__registerShortcodes__shortcode_collection" filter must return a Collection of EspressoShortcode objects. "%1$s" was received instead.', |
|
147 | + 'event_espresso' |
|
148 | + ), |
|
149 | + is_object($this->shortcodes) ? get_class($this->shortcodes) : gettype($this->shortcodes) |
|
150 | + ) |
|
151 | + ); |
|
152 | + } |
|
153 | + $this->legacy_shortcodes_manager->registerShortcodes(); |
|
154 | + } catch (Exception $exception) { |
|
155 | + new ExceptionStackTraceDisplay($exception); |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @return void |
|
163 | + */ |
|
164 | + public function addShortcodes() |
|
165 | + { |
|
166 | + try { |
|
167 | + // cycle thru shortcode folders |
|
168 | + foreach ($this->shortcodes as $shortcode) { |
|
169 | + /** @var ShortcodeInterface $shortcode */ |
|
170 | + if ( $shortcode instanceof EnqueueAssetsInterface) { |
|
171 | + add_action('wp_enqueue_scripts', array($shortcode, 'registerScriptsAndStylesheets'), 10); |
|
172 | + add_action('wp_enqueue_scripts', array($shortcode, 'enqueueStylesheets'), 11); |
|
173 | + } |
|
174 | + // add_shortcode() if it has not already been added |
|
175 | + if ( ! shortcode_exists($shortcode->getTag())) { |
|
176 | + add_shortcode($shortcode->getTag(), array($shortcode, 'processShortcodeCallback')); |
|
177 | + } |
|
178 | + } |
|
179 | + $this->legacy_shortcodes_manager->addShortcodes(); |
|
180 | + } catch (Exception $exception) { |
|
181 | + new ExceptionStackTraceDisplay($exception); |
|
182 | + } |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * callback for the "wp_head" hook point |
|
189 | + * checks posts for EE shortcodes, and initializes them, |
|
190 | + * then toggles filter switch that loads core default assets |
|
191 | + * |
|
192 | + * @return void |
|
193 | + */ |
|
194 | + public function wpHead() |
|
195 | + { |
|
196 | + global $wp_query; |
|
197 | + if (empty($wp_query->posts)) { |
|
198 | + return; |
|
199 | + } |
|
200 | + $load_assets = false; |
|
201 | + // array of posts displayed in current request |
|
202 | + $posts = is_array($wp_query->posts) ? $wp_query->posts : array($wp_query->posts); |
|
203 | + foreach ($posts as $post) { |
|
204 | + // now check post content and excerpt for EE shortcodes |
|
205 | + $load_assets = $this->parseContentForShortcodes($post->post_content) |
|
206 | + ? true |
|
207 | + : $load_assets; |
|
208 | + } |
|
209 | + if ($load_assets) { |
|
210 | + $this->legacy_shortcodes_manager->registry()->REQ->set_espresso_page(true); |
|
211 | + add_filter('FHEE_load_css', '__return_true'); |
|
212 | + add_filter('FHEE_load_js', '__return_true'); |
|
213 | + } |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * checks supplied content against list of shortcodes, |
|
220 | + * then initializes any found shortcodes, and returns true. |
|
221 | + * returns false if no shortcodes found. |
|
222 | + * |
|
223 | + * @param string $content |
|
224 | + * @return bool |
|
225 | + */ |
|
226 | + public function parseContentForShortcodes($content) |
|
227 | + { |
|
228 | + $has_shortcode = false; |
|
229 | + if(empty($this->shortcodes)){ |
|
230 | + return $has_shortcode; |
|
231 | + } |
|
232 | + foreach ($this->shortcodes as $shortcode) { |
|
233 | + /** @var ShortcodeInterface $shortcode */ |
|
234 | + if (has_shortcode($content, $shortcode->getTag())) { |
|
235 | + $shortcode->initializeShortcode(); |
|
236 | + $has_shortcode = true; |
|
237 | + } |
|
238 | + } |
|
239 | + return $has_shortcode; |
|
240 | + } |
|
241 | 241 | |
242 | 242 | } |
243 | 243 | // End of file ShortcodesManager.php |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | /** |
@@ -14,740 +14,740 @@ discard block |
||
14 | 14 | { |
15 | 15 | |
16 | 16 | |
17 | - /** |
|
18 | - * @type EE_Messages_Data_Handler_Collection |
|
19 | - */ |
|
20 | - protected $_data_handler_collection; |
|
21 | - |
|
22 | - /** |
|
23 | - * @type EE_Message_Template_Group_Collection |
|
24 | - */ |
|
25 | - protected $_template_collection; |
|
26 | - |
|
27 | - /** |
|
28 | - * This will hold the data handler for the current EE_Message being generated. |
|
29 | - * |
|
30 | - * @type EE_Messages_incoming_data |
|
31 | - */ |
|
32 | - protected $_current_data_handler; |
|
33 | - |
|
34 | - /** |
|
35 | - * This holds the EE_Messages_Queue that contains the messages to generate. |
|
36 | - * |
|
37 | - * @type EE_Messages_Queue |
|
38 | - */ |
|
39 | - protected $_generation_queue; |
|
40 | - |
|
41 | - /** |
|
42 | - * This holds the EE_Messages_Queue that will store the generated EE_Message objects. |
|
43 | - * |
|
44 | - * @type EE_Messages_Queue |
|
45 | - */ |
|
46 | - protected $_ready_queue; |
|
47 | - |
|
48 | - /** |
|
49 | - * This is a container for any error messages that get created through the generation |
|
50 | - * process. |
|
51 | - * |
|
52 | - * @type array |
|
53 | - */ |
|
54 | - protected $_error_msg = array(); |
|
55 | - |
|
56 | - /** |
|
57 | - * Flag used to set when the current EE_Message in the generation queue has been verified. |
|
58 | - * |
|
59 | - * @type bool |
|
60 | - */ |
|
61 | - protected $_verified = false; |
|
62 | - |
|
63 | - /** |
|
64 | - * This will hold the current messenger object corresponding with the current EE_Message in the generation queue. |
|
65 | - * |
|
66 | - * @type EE_messenger |
|
67 | - */ |
|
68 | - protected $_current_messenger; |
|
69 | - |
|
70 | - /** |
|
71 | - * This will hold the current message type object corresponding with the current EE_Message in the generation queue. |
|
72 | - * |
|
73 | - * @type EE_message_type |
|
74 | - */ |
|
75 | - protected $_current_message_type; |
|
76 | - |
|
77 | - /** |
|
78 | - * @type EEH_Parse_Shortcodes |
|
79 | - */ |
|
80 | - protected $_shortcode_parser; |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * @param EE_Messages_Queue $generation_queue |
|
85 | - * @param \EE_Messages_Queue $ready_queue |
|
86 | - * @param \EE_Messages_Data_Handler_Collection $data_handler_collection |
|
87 | - * @param \EE_Message_Template_Group_Collection $template_collection |
|
88 | - * @param \EEH_Parse_Shortcodes $shortcode_parser |
|
89 | - */ |
|
90 | - public function __construct( |
|
91 | - EE_Messages_Queue $generation_queue, |
|
92 | - EE_Messages_Queue $ready_queue, |
|
93 | - EE_Messages_Data_Handler_Collection $data_handler_collection, |
|
94 | - EE_Message_Template_Group_Collection $template_collection, |
|
95 | - EEH_Parse_Shortcodes $shortcode_parser |
|
96 | - ) { |
|
97 | - $this->_generation_queue = $generation_queue; |
|
98 | - $this->_ready_queue = $ready_queue; |
|
99 | - $this->_data_handler_collection = $data_handler_collection; |
|
100 | - $this->_template_collection = $template_collection; |
|
101 | - $this->_shortcode_parser = $shortcode_parser; |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @return EE_Messages_Queue |
|
107 | - */ |
|
108 | - public function generation_queue() |
|
109 | - { |
|
110 | - return $this->_generation_queue; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * This iterates through the provided queue and generates the EE_Message objects. |
|
116 | - * When iterating through the queue, the queued item that served as the base for generating other EE_Message |
|
117 | - * objects gets removed and the new EE_Message objects get added to a NEW queue. The NEW queue is then returned |
|
118 | - * for the caller to decide what to do with it. |
|
119 | - * |
|
120 | - * @param bool $save Whether to save the EE_Message objects in the new queue or just return. |
|
121 | - * @return EE_Messages_Queue The new queue for holding generated EE_Message objects. |
|
122 | - */ |
|
123 | - public function generate($save = true) |
|
124 | - { |
|
125 | - //iterate through the messages in the queue, generate, and add to new queue. |
|
126 | - $this->_generation_queue->get_message_repository()->rewind(); |
|
127 | - while ($this->_generation_queue->get_message_repository()->valid()) { |
|
128 | - //reset "current" properties |
|
129 | - $this->_reset_current_properties(); |
|
130 | - |
|
131 | - /** @type EE_Message $msg */ |
|
132 | - $msg = $this->_generation_queue->get_message_repository()->current(); |
|
133 | - |
|
134 | - /** |
|
135 | - * need to get the next object and capture it for setting manually after deletes. The reason is that when |
|
136 | - * an object is removed from the repo then valid for the next object will fail. |
|
137 | - */ |
|
138 | - $this->_generation_queue->get_message_repository()->next(); |
|
139 | - $next_msg = $this->_generation_queue->get_message_repository()->current(); |
|
140 | - //restore pointer to current item |
|
141 | - $this->_generation_queue->get_message_repository()->set_current($msg); |
|
142 | - |
|
143 | - //skip and delete if the current $msg is NOT incomplete (queued for generation) |
|
144 | - if ($msg->STS_ID() !== EEM_Message::status_incomplete) { |
|
145 | - //we keep this item in the db just remove from the repo. |
|
146 | - $this->_generation_queue->get_message_repository()->remove($msg); |
|
147 | - //next item |
|
148 | - $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
149 | - continue; |
|
150 | - } |
|
151 | - |
|
152 | - if ($this->_verify()) { |
|
153 | - //let's get generating! |
|
154 | - $this->_generate(); |
|
155 | - } |
|
156 | - |
|
157 | - //don't persist debug_only messages if the messages system is not in debug mode. |
|
158 | - if ( |
|
159 | - $msg->STS_ID() === EEM_Message::status_debug_only |
|
160 | - && ! EEM_Message::debug() |
|
161 | - ) { |
|
162 | - do_action('AHEE__EE_Messages_Generator__generate__before_debug_delete', $msg, $this->_error_msg, |
|
163 | - $this->_current_messenger, $this->_current_message_type, $this->_current_data_handler); |
|
164 | - $this->_generation_queue->get_message_repository()->delete(); |
|
165 | - $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
166 | - continue; |
|
167 | - } |
|
168 | - |
|
169 | - //if there are error messages then let's set the status and the error message. |
|
170 | - if ($this->_error_msg) { |
|
171 | - //if the status is already debug only, then let's leave it at that. |
|
172 | - if ($msg->STS_ID() !== EEM_Message::status_debug_only) { |
|
173 | - $msg->set_STS_ID(EEM_Message::status_failed); |
|
174 | - } |
|
175 | - do_action('AHEE__EE_Messages_Generator__generate__processing_failed_message', $msg, $this->_error_msg, |
|
176 | - $this->_current_messenger, $this->_current_message_type, $this->_current_data_handler); |
|
177 | - $msg->set_error_message( |
|
178 | - __('Message failed to generate for the following reasons: ') |
|
179 | - . "\n" |
|
180 | - . implode("\n", $this->_error_msg) |
|
181 | - ); |
|
182 | - $msg->set_modified(time()); |
|
183 | - } else { |
|
184 | - do_action('AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete', $msg, |
|
185 | - $this->_error_msg, $this->_current_messenger, $this->_current_message_type, |
|
186 | - $this->_current_data_handler); |
|
187 | - //remove from db |
|
188 | - $this->_generation_queue->get_message_repository()->delete(); |
|
189 | - } |
|
190 | - //next item |
|
191 | - $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
192 | - } |
|
193 | - |
|
194 | - //generation queue is ALWAYS saved to record any errors in the generation process. |
|
195 | - $this->_generation_queue->save(); |
|
196 | - |
|
197 | - /** |
|
198 | - * save _ready_queue if flag set. |
|
199 | - * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method. This |
|
200 | - * means if a field was added that is not a valid database column. The EE_Message was already saved to the db |
|
201 | - * so a EE_Extra_Meta entry could be created and attached to the EE_Message. In those cases the save flag is |
|
202 | - * irrelevant. |
|
203 | - */ |
|
204 | - if ($save) { |
|
205 | - $this->_ready_queue->save(); |
|
206 | - } |
|
207 | - |
|
208 | - //final reset of properties |
|
209 | - $this->_reset_current_properties(); |
|
210 | - |
|
211 | - return $this->_ready_queue; |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * This resets all the properties used for holding "current" values corresponding to the current EE_Message object |
|
217 | - * in the generation queue. |
|
218 | - */ |
|
219 | - protected function _reset_current_properties() |
|
220 | - { |
|
221 | - $this->_verified = false; |
|
222 | - //make sure any _data value in the current message type is reset |
|
223 | - if ($this->_current_message_type instanceof EE_message_type) { |
|
224 | - $this->_current_message_type->reset_data(); |
|
225 | - } |
|
226 | - $this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null; |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * This proceeds with the actual generation of a message. By the time this is called, there should already be a |
|
232 | - * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the |
|
233 | - * _generating_queue. |
|
234 | - * |
|
235 | - * @return bool Whether the message was successfully generated or not. |
|
236 | - */ |
|
237 | - protected function _generate() |
|
238 | - { |
|
239 | - //double check verification has run and that everything is ready to work with (saves us having to validate everything again). |
|
240 | - if (! $this->_verified) { |
|
241 | - return false; //get out because we don't have a valid setup to work with. |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - try { |
|
246 | - $addressees = $this->_current_message_type->get_addressees( |
|
247 | - $this->_current_data_handler, |
|
248 | - $this->_generation_queue->get_message_repository()->current()->context() |
|
249 | - ); |
|
250 | - } catch (EE_Error $e) { |
|
251 | - $this->_error_msg[] = $e->getMessage(); |
|
252 | - return false; |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - //if no addressees then get out because there is nothing to generation (possible bad data). |
|
257 | - if (! $this->_valid_addressees($addressees)) { |
|
258 | - do_action('AHEE__EE_Messages_Generator___generate__invalid_addressees', |
|
259 | - $this->_generation_queue->get_message_repository()->current(), $addressees, $this->_current_messenger, |
|
260 | - $this->_current_message_type, $this->_current_data_handler); |
|
261 | - $this->_generation_queue->get_message_repository()->current()->set_STS_ID(EEM_Message::status_debug_only); |
|
262 | - $this->_error_msg[] = __('This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects. There were no attendees prepared by the data handler. |
|
17 | + /** |
|
18 | + * @type EE_Messages_Data_Handler_Collection |
|
19 | + */ |
|
20 | + protected $_data_handler_collection; |
|
21 | + |
|
22 | + /** |
|
23 | + * @type EE_Message_Template_Group_Collection |
|
24 | + */ |
|
25 | + protected $_template_collection; |
|
26 | + |
|
27 | + /** |
|
28 | + * This will hold the data handler for the current EE_Message being generated. |
|
29 | + * |
|
30 | + * @type EE_Messages_incoming_data |
|
31 | + */ |
|
32 | + protected $_current_data_handler; |
|
33 | + |
|
34 | + /** |
|
35 | + * This holds the EE_Messages_Queue that contains the messages to generate. |
|
36 | + * |
|
37 | + * @type EE_Messages_Queue |
|
38 | + */ |
|
39 | + protected $_generation_queue; |
|
40 | + |
|
41 | + /** |
|
42 | + * This holds the EE_Messages_Queue that will store the generated EE_Message objects. |
|
43 | + * |
|
44 | + * @type EE_Messages_Queue |
|
45 | + */ |
|
46 | + protected $_ready_queue; |
|
47 | + |
|
48 | + /** |
|
49 | + * This is a container for any error messages that get created through the generation |
|
50 | + * process. |
|
51 | + * |
|
52 | + * @type array |
|
53 | + */ |
|
54 | + protected $_error_msg = array(); |
|
55 | + |
|
56 | + /** |
|
57 | + * Flag used to set when the current EE_Message in the generation queue has been verified. |
|
58 | + * |
|
59 | + * @type bool |
|
60 | + */ |
|
61 | + protected $_verified = false; |
|
62 | + |
|
63 | + /** |
|
64 | + * This will hold the current messenger object corresponding with the current EE_Message in the generation queue. |
|
65 | + * |
|
66 | + * @type EE_messenger |
|
67 | + */ |
|
68 | + protected $_current_messenger; |
|
69 | + |
|
70 | + /** |
|
71 | + * This will hold the current message type object corresponding with the current EE_Message in the generation queue. |
|
72 | + * |
|
73 | + * @type EE_message_type |
|
74 | + */ |
|
75 | + protected $_current_message_type; |
|
76 | + |
|
77 | + /** |
|
78 | + * @type EEH_Parse_Shortcodes |
|
79 | + */ |
|
80 | + protected $_shortcode_parser; |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * @param EE_Messages_Queue $generation_queue |
|
85 | + * @param \EE_Messages_Queue $ready_queue |
|
86 | + * @param \EE_Messages_Data_Handler_Collection $data_handler_collection |
|
87 | + * @param \EE_Message_Template_Group_Collection $template_collection |
|
88 | + * @param \EEH_Parse_Shortcodes $shortcode_parser |
|
89 | + */ |
|
90 | + public function __construct( |
|
91 | + EE_Messages_Queue $generation_queue, |
|
92 | + EE_Messages_Queue $ready_queue, |
|
93 | + EE_Messages_Data_Handler_Collection $data_handler_collection, |
|
94 | + EE_Message_Template_Group_Collection $template_collection, |
|
95 | + EEH_Parse_Shortcodes $shortcode_parser |
|
96 | + ) { |
|
97 | + $this->_generation_queue = $generation_queue; |
|
98 | + $this->_ready_queue = $ready_queue; |
|
99 | + $this->_data_handler_collection = $data_handler_collection; |
|
100 | + $this->_template_collection = $template_collection; |
|
101 | + $this->_shortcode_parser = $shortcode_parser; |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @return EE_Messages_Queue |
|
107 | + */ |
|
108 | + public function generation_queue() |
|
109 | + { |
|
110 | + return $this->_generation_queue; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * This iterates through the provided queue and generates the EE_Message objects. |
|
116 | + * When iterating through the queue, the queued item that served as the base for generating other EE_Message |
|
117 | + * objects gets removed and the new EE_Message objects get added to a NEW queue. The NEW queue is then returned |
|
118 | + * for the caller to decide what to do with it. |
|
119 | + * |
|
120 | + * @param bool $save Whether to save the EE_Message objects in the new queue or just return. |
|
121 | + * @return EE_Messages_Queue The new queue for holding generated EE_Message objects. |
|
122 | + */ |
|
123 | + public function generate($save = true) |
|
124 | + { |
|
125 | + //iterate through the messages in the queue, generate, and add to new queue. |
|
126 | + $this->_generation_queue->get_message_repository()->rewind(); |
|
127 | + while ($this->_generation_queue->get_message_repository()->valid()) { |
|
128 | + //reset "current" properties |
|
129 | + $this->_reset_current_properties(); |
|
130 | + |
|
131 | + /** @type EE_Message $msg */ |
|
132 | + $msg = $this->_generation_queue->get_message_repository()->current(); |
|
133 | + |
|
134 | + /** |
|
135 | + * need to get the next object and capture it for setting manually after deletes. The reason is that when |
|
136 | + * an object is removed from the repo then valid for the next object will fail. |
|
137 | + */ |
|
138 | + $this->_generation_queue->get_message_repository()->next(); |
|
139 | + $next_msg = $this->_generation_queue->get_message_repository()->current(); |
|
140 | + //restore pointer to current item |
|
141 | + $this->_generation_queue->get_message_repository()->set_current($msg); |
|
142 | + |
|
143 | + //skip and delete if the current $msg is NOT incomplete (queued for generation) |
|
144 | + if ($msg->STS_ID() !== EEM_Message::status_incomplete) { |
|
145 | + //we keep this item in the db just remove from the repo. |
|
146 | + $this->_generation_queue->get_message_repository()->remove($msg); |
|
147 | + //next item |
|
148 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
149 | + continue; |
|
150 | + } |
|
151 | + |
|
152 | + if ($this->_verify()) { |
|
153 | + //let's get generating! |
|
154 | + $this->_generate(); |
|
155 | + } |
|
156 | + |
|
157 | + //don't persist debug_only messages if the messages system is not in debug mode. |
|
158 | + if ( |
|
159 | + $msg->STS_ID() === EEM_Message::status_debug_only |
|
160 | + && ! EEM_Message::debug() |
|
161 | + ) { |
|
162 | + do_action('AHEE__EE_Messages_Generator__generate__before_debug_delete', $msg, $this->_error_msg, |
|
163 | + $this->_current_messenger, $this->_current_message_type, $this->_current_data_handler); |
|
164 | + $this->_generation_queue->get_message_repository()->delete(); |
|
165 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
166 | + continue; |
|
167 | + } |
|
168 | + |
|
169 | + //if there are error messages then let's set the status and the error message. |
|
170 | + if ($this->_error_msg) { |
|
171 | + //if the status is already debug only, then let's leave it at that. |
|
172 | + if ($msg->STS_ID() !== EEM_Message::status_debug_only) { |
|
173 | + $msg->set_STS_ID(EEM_Message::status_failed); |
|
174 | + } |
|
175 | + do_action('AHEE__EE_Messages_Generator__generate__processing_failed_message', $msg, $this->_error_msg, |
|
176 | + $this->_current_messenger, $this->_current_message_type, $this->_current_data_handler); |
|
177 | + $msg->set_error_message( |
|
178 | + __('Message failed to generate for the following reasons: ') |
|
179 | + . "\n" |
|
180 | + . implode("\n", $this->_error_msg) |
|
181 | + ); |
|
182 | + $msg->set_modified(time()); |
|
183 | + } else { |
|
184 | + do_action('AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete', $msg, |
|
185 | + $this->_error_msg, $this->_current_messenger, $this->_current_message_type, |
|
186 | + $this->_current_data_handler); |
|
187 | + //remove from db |
|
188 | + $this->_generation_queue->get_message_repository()->delete(); |
|
189 | + } |
|
190 | + //next item |
|
191 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
192 | + } |
|
193 | + |
|
194 | + //generation queue is ALWAYS saved to record any errors in the generation process. |
|
195 | + $this->_generation_queue->save(); |
|
196 | + |
|
197 | + /** |
|
198 | + * save _ready_queue if flag set. |
|
199 | + * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method. This |
|
200 | + * means if a field was added that is not a valid database column. The EE_Message was already saved to the db |
|
201 | + * so a EE_Extra_Meta entry could be created and attached to the EE_Message. In those cases the save flag is |
|
202 | + * irrelevant. |
|
203 | + */ |
|
204 | + if ($save) { |
|
205 | + $this->_ready_queue->save(); |
|
206 | + } |
|
207 | + |
|
208 | + //final reset of properties |
|
209 | + $this->_reset_current_properties(); |
|
210 | + |
|
211 | + return $this->_ready_queue; |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * This resets all the properties used for holding "current" values corresponding to the current EE_Message object |
|
217 | + * in the generation queue. |
|
218 | + */ |
|
219 | + protected function _reset_current_properties() |
|
220 | + { |
|
221 | + $this->_verified = false; |
|
222 | + //make sure any _data value in the current message type is reset |
|
223 | + if ($this->_current_message_type instanceof EE_message_type) { |
|
224 | + $this->_current_message_type->reset_data(); |
|
225 | + } |
|
226 | + $this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null; |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * This proceeds with the actual generation of a message. By the time this is called, there should already be a |
|
232 | + * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the |
|
233 | + * _generating_queue. |
|
234 | + * |
|
235 | + * @return bool Whether the message was successfully generated or not. |
|
236 | + */ |
|
237 | + protected function _generate() |
|
238 | + { |
|
239 | + //double check verification has run and that everything is ready to work with (saves us having to validate everything again). |
|
240 | + if (! $this->_verified) { |
|
241 | + return false; //get out because we don't have a valid setup to work with. |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + try { |
|
246 | + $addressees = $this->_current_message_type->get_addressees( |
|
247 | + $this->_current_data_handler, |
|
248 | + $this->_generation_queue->get_message_repository()->current()->context() |
|
249 | + ); |
|
250 | + } catch (EE_Error $e) { |
|
251 | + $this->_error_msg[] = $e->getMessage(); |
|
252 | + return false; |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + //if no addressees then get out because there is nothing to generation (possible bad data). |
|
257 | + if (! $this->_valid_addressees($addressees)) { |
|
258 | + do_action('AHEE__EE_Messages_Generator___generate__invalid_addressees', |
|
259 | + $this->_generation_queue->get_message_repository()->current(), $addressees, $this->_current_messenger, |
|
260 | + $this->_current_message_type, $this->_current_data_handler); |
|
261 | + $this->_generation_queue->get_message_repository()->current()->set_STS_ID(EEM_Message::status_debug_only); |
|
262 | + $this->_error_msg[] = __('This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects. There were no attendees prepared by the data handler. |
|
263 | 263 | Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.', |
264 | - 'event_espresso'); |
|
265 | - return false; |
|
266 | - } |
|
267 | - |
|
268 | - $message_template_group = $this->_get_message_template_group(); |
|
269 | - |
|
270 | - //in the unlikely event there is no EE_Message_Template_Group available, get out! |
|
271 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
272 | - $this->_error_msg[] = __('Unable to get the Message Templates for the Message being generated. No message template group accessible.', |
|
273 | - 'event_espresso'); |
|
274 | - return false; |
|
275 | - } |
|
276 | - |
|
277 | - //get formatted templates for using to parse and setup EE_Message objects. |
|
278 | - $templates = $this->_get_templates($message_template_group); |
|
279 | - |
|
280 | - |
|
281 | - //setup new EE_Message objects (and add to _ready_queue) |
|
282 | - return $this->_assemble_messages($addressees, $templates, $message_template_group); |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * Retrieves the message template group being used for generating messages. |
|
288 | - * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times. |
|
289 | - * |
|
290 | - * @return EE_Message_Template_Group | null |
|
291 | - */ |
|
292 | - protected function _get_message_template_group() |
|
293 | - { |
|
294 | - //is there a GRP_ID already on the EE_Message object? If there is, then a specific template has been requested |
|
295 | - //so let's use that. |
|
296 | - $GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID(); |
|
297 | - |
|
298 | - if ($GRP_ID) { |
|
299 | - //attempt to retrieve from repo first |
|
300 | - $GRP = $this->_template_collection->get_by_ID($GRP_ID); |
|
301 | - if ($GRP instanceof EE_Message_Template_Group) { |
|
302 | - return $GRP; //got it! |
|
303 | - } |
|
304 | - |
|
305 | - //nope don't have it yet. Get from DB then add to repo if its not here, then that means the current GRP_ID |
|
306 | - //is not valid, so we'll continue on in the code assuming there's NO GRP_ID. |
|
307 | - $GRP = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
308 | - if ($GRP instanceof EE_Message_Template_Group) { |
|
309 | - $this->_template_collection->add($GRP); |
|
310 | - return $GRP; |
|
311 | - } |
|
312 | - } |
|
313 | - |
|
314 | - //whatcha still doing here? Oh, no Message Template Group yet I see. Okay let's see if we can get it for you. |
|
315 | - |
|
316 | - //defaults |
|
317 | - $EVT_ID = 0; |
|
318 | - |
|
319 | - $template_qa = array( |
|
320 | - 'MTP_is_active' => true, |
|
321 | - 'MTP_messenger' => $this->_current_messenger->name, |
|
322 | - 'MTP_message_type' => $this->_current_message_type->name, |
|
323 | - ); |
|
324 | - |
|
325 | - //in vanilla EE we're assuming there's only one event. |
|
326 | - //However, if there are multiple events then we'll just use the default templates instead of different |
|
327 | - // templates per event (which could create problems). |
|
328 | - if (count($this->_current_data_handler->events) === 1) { |
|
329 | - foreach ($this->_current_data_handler->events as $event) { |
|
330 | - $EVT_ID = $event['ID']; |
|
331 | - } |
|
332 | - } |
|
333 | - |
|
334 | - //before going any further, let's see if its in the queue |
|
335 | - $GRP = $this->_template_collection->get_by_key($this->_template_collection->get_key($this->_current_messenger->name, |
|
336 | - $this->_current_message_type->name, $EVT_ID)); |
|
337 | - |
|
338 | - if ($GRP instanceof EE_Message_Template_Group) { |
|
339 | - return $GRP; |
|
340 | - } |
|
341 | - |
|
342 | - //nope still no GRP? |
|
343 | - //first we get the global template in case it has an override set. |
|
344 | - $global_template_qa = array_merge(array('MTP_is_global' => true), $template_qa); |
|
345 | - $global_GRP = EEM_Message_Template_Group::instance()->get_one(array($global_template_qa)); |
|
346 | - |
|
347 | - //if this is an override, then we just return it. |
|
348 | - if ($global_GRP instanceof EE_Message_Template_Group && $global_GRP->get('MTP_is_override')) { |
|
349 | - $this->_template_collection->add($global_GRP, $EVT_ID); |
|
350 | - return $global_GRP; |
|
351 | - } |
|
352 | - |
|
353 | - //STILL here? Okay that means we want to see if there is event specific group and if there is we return it, |
|
354 | - //otherwise we return the global group we retrieved. |
|
355 | - if ($EVT_ID) { |
|
356 | - $template_qa['Event.EVT_ID'] = $EVT_ID; |
|
357 | - } |
|
358 | - |
|
359 | - $GRP = EEM_Message_Template_Group::instance()->get_one(array($template_qa)); |
|
360 | - $GRP = $GRP instanceof EE_Message_Template_Group ? $GRP : $global_GRP; |
|
361 | - |
|
362 | - if ($GRP instanceof EE_Message_Template_Group) { |
|
363 | - $this->_template_collection->add($GRP, $EVT_ID); |
|
364 | - return $GRP; |
|
365 | - } |
|
366 | - |
|
367 | - //nothing, nada, there ain't no group from what you fed the machine. (Getting here is a very hard thing to do). |
|
368 | - return null; |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * Retrieves formatted array of template information for each context specific to the given |
|
374 | - * EE_Message_Template_Group |
|
375 | - * |
|
376 | - * @param EE_Message_Template_Group |
|
377 | - * @return array The returned array is in this structure: |
|
378 | - * array( |
|
379 | - * 'field_name' => array( |
|
380 | - * 'context' => 'content' |
|
381 | - * ) |
|
382 | - * ) |
|
383 | - */ |
|
384 | - protected function _get_templates(EE_Message_Template_Group $message_template_group) |
|
385 | - { |
|
386 | - $templates = array(); |
|
387 | - $context_templates = $message_template_group->context_templates(); |
|
388 | - foreach ($context_templates as $context => $template_fields) { |
|
389 | - foreach ($template_fields as $template_field => $template_obj) { |
|
390 | - if (! $template_obj instanceof EE_Message_Template) { |
|
391 | - continue; |
|
392 | - } |
|
393 | - $templates[$template_field][$context] = $template_obj->get('MTP_content'); |
|
394 | - } |
|
395 | - } |
|
396 | - return $templates; |
|
397 | - } |
|
398 | - |
|
399 | - |
|
400 | - /** |
|
401 | - * Assembles new fully generated EE_Message objects and adds to _ready_queue |
|
402 | - * |
|
403 | - * @param array $addressees Array of EE_Messages_Addressee objects indexed by message type |
|
404 | - * context. |
|
405 | - * @param array $templates formatted array of templates used for parsing data. |
|
406 | - * @param EE_Message_Template_Group $message_template_group |
|
407 | - * @return bool true if message generation went a-ok. false if some sort of exception occurred. Note: The |
|
408 | - * method will attempt to generate ALL EE_Message objects and add to the _ready_queue. Successfully |
|
409 | - * generated messages get added to the queue with EEM_Message::status_idle, unsuccessfully generated |
|
410 | - * messages will get added to the queue as EEM_Message::status_failed. Very rarely should "false" |
|
411 | - * be returned from this method. |
|
412 | - */ |
|
413 | - protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group) |
|
414 | - { |
|
415 | - |
|
416 | - //if templates are empty then get out because we can't generate anything. |
|
417 | - if (! $templates) { |
|
418 | - $this->_error_msg[] = __('Unable to assemble messages because there are no templates retrieved for generating the messages with', |
|
419 | - 'event_espresso'); |
|
420 | - return false; |
|
421 | - } |
|
422 | - |
|
423 | - //We use this as the counter for generated messages because don't forget we may be executing this inside of a |
|
424 | - //generation_queue. So _ready_queue may have generated EE_Message objects already. |
|
425 | - $generated_count = 0; |
|
426 | - foreach ($addressees as $context => $recipients) { |
|
427 | - foreach ($recipients as $recipient) { |
|
428 | - $message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group); |
|
429 | - if ($message instanceof EE_Message) { |
|
430 | - $this->_ready_queue->add( |
|
431 | - $message, |
|
432 | - array(), |
|
433 | - $this->_generation_queue->get_message_repository()->is_preview(), |
|
434 | - $this->_generation_queue->get_message_repository()->is_test_send() |
|
435 | - ); |
|
436 | - $generated_count++; |
|
437 | - } |
|
438 | - |
|
439 | - //if the current MSG being generated is for a test send then we'll only use ONE message in the generation. |
|
440 | - if ($this->_generation_queue->get_message_repository()->is_test_send()) { |
|
441 | - break 2; |
|
442 | - } |
|
443 | - } |
|
444 | - } |
|
445 | - |
|
446 | - //if there are no generated messages then something else fatal went wrong. |
|
447 | - return $generated_count > 0; |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * @param string $context The context for the generated message. |
|
453 | - * @param EE_Messages_Addressee $recipient |
|
454 | - * @param array $templates formatted array of templates used for parsing data. |
|
455 | - * @param EE_Message_Template_Group $message_template_group |
|
456 | - * @return EE_Message | bool (false is used when no EE_Message is generated) |
|
457 | - */ |
|
458 | - protected function _setup_message_object( |
|
459 | - $context, |
|
460 | - EE_Messages_Addressee $recipient, |
|
461 | - $templates, |
|
462 | - EE_Message_Template_Group $message_template_group |
|
463 | - ) { |
|
464 | - //stuff we already know |
|
465 | - $transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0; |
|
466 | - $transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction |
|
467 | - ? $this->_current_data_handler->txn->ID() |
|
468 | - : $transaction_id; |
|
469 | - $message_fields = array( |
|
470 | - 'GRP_ID' => $message_template_group->ID(), |
|
471 | - 'TXN_ID' => $transaction_id, |
|
472 | - 'MSG_messenger' => $this->_current_messenger->name, |
|
473 | - 'MSG_message_type' => $this->_current_message_type->name, |
|
474 | - 'MSG_context' => $context, |
|
475 | - ); |
|
476 | - |
|
477 | - //recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab the |
|
478 | - //info from the att_obj found in the EE_Messages_Addressee object. |
|
479 | - if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) { |
|
480 | - $message_fields['MSG_recipient_ID'] = $recipient->att_obj instanceof EE_Attendee |
|
481 | - ? $recipient->att_obj->ID() |
|
482 | - : 0; |
|
483 | - $message_fields['MSG_recipient_type'] = 'Attendee'; |
|
484 | - } else { |
|
485 | - $message_fields['MSG_recipient_ID'] = $recipient->recipient_id; |
|
486 | - $message_fields['MSG_recipient_type'] = $recipient->recipient_type; |
|
487 | - } |
|
488 | - $message = EE_Message_Factory::create($message_fields); |
|
489 | - |
|
490 | - //grab valid shortcodes for shortcode parser |
|
491 | - $mt_shortcodes = $this->_current_message_type->get_valid_shortcodes(); |
|
492 | - $m_shortcodes = $this->_current_messenger->get_valid_shortcodes(); |
|
493 | - |
|
494 | - //if the 'to' field is empty (messages will ALWAYS have a "to" field, then we get out because that means this |
|
495 | - //context is turned off) EXCEPT if we're previewing |
|
496 | - if (empty($templates['to'][$context]) |
|
497 | - && ! $this->_generation_queue->get_message_repository()->is_preview() |
|
498 | - && ! $this->_current_messenger->allow_empty_to_field() |
|
499 | - ) { |
|
500 | - //we silently exit here and do NOT record a fail because the message is "turned off" by having no "to" field. |
|
501 | - return false; |
|
502 | - } |
|
503 | - $error_msg = array(); |
|
504 | - foreach ($templates as $field => $field_context) { |
|
505 | - $error_msg = array(); |
|
506 | - //let's setup the valid shortcodes for the incoming context. |
|
507 | - $valid_shortcodes = $mt_shortcodes[$context]; |
|
508 | - //merge in valid shortcodes for the field. |
|
509 | - $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes; |
|
510 | - if (isset($templates[$field][$context])) { |
|
511 | - //prefix field. |
|
512 | - $column_name = 'MSG_' . $field; |
|
513 | - try { |
|
514 | - $content = $this->_shortcode_parser->parse_message_template( |
|
515 | - $templates[$field][$context], |
|
516 | - $recipient, |
|
517 | - $shortcodes, |
|
518 | - $this->_current_message_type, |
|
519 | - $this->_current_messenger, |
|
520 | - $message); |
|
521 | - $message->set_field_or_extra_meta($column_name, $content); |
|
522 | - } catch (EE_Error $e) { |
|
523 | - $error_msg[] = sprintf(__('There was a problem generating the content for the field %s: %s', |
|
524 | - 'event_espresso'), $field, $e->getMessage()); |
|
525 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
526 | - } |
|
527 | - } |
|
528 | - } |
|
529 | - |
|
530 | - if ($message->STS_ID() === EEM_Message::status_failed) { |
|
531 | - $error_msg = __('There were problems generating this message:', 'event_espresso') . "\n" . implode("\n", |
|
532 | - $error_msg); |
|
533 | - $message->set_error_message($error_msg); |
|
534 | - } else { |
|
535 | - $message->set_STS_ID(EEM_Message::status_idle); |
|
536 | - } |
|
537 | - return $message; |
|
538 | - } |
|
539 | - |
|
540 | - |
|
541 | - /** |
|
542 | - * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate |
|
543 | - * error message if either is missing. |
|
544 | - * |
|
545 | - * @return bool true means there were no errors, false means there were errors. |
|
546 | - */ |
|
547 | - protected function _verify() |
|
548 | - { |
|
549 | - //reset error message to an empty array. |
|
550 | - $this->_error_msg = array(); |
|
551 | - $valid = true; |
|
552 | - $valid = $valid ? $this->_validate_messenger_and_message_type() : $valid; |
|
553 | - $valid = $valid ? $this->_validate_and_setup_data() : $valid; |
|
554 | - |
|
555 | - //set the verified flag so we know everything has been validated. |
|
556 | - $this->_verified = $valid; |
|
557 | - |
|
558 | - return $valid; |
|
559 | - } |
|
560 | - |
|
561 | - |
|
562 | - /** |
|
563 | - * This accepts an array and validates that it is an array indexed by context with each value being an array of |
|
564 | - * EE_Messages_Addressee objects. |
|
565 | - * |
|
566 | - * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[] |
|
567 | - * @return bool |
|
568 | - */ |
|
569 | - protected function _valid_addressees($addressees) |
|
570 | - { |
|
571 | - if (! $addressees || ! is_array($addressees)) { |
|
572 | - return false; |
|
573 | - } |
|
574 | - |
|
575 | - foreach ($addressees as $addressee_array) { |
|
576 | - foreach ($addressee_array as $addressee) { |
|
577 | - if (! $addressee instanceof EE_Messages_Addressee) { |
|
578 | - return false; |
|
579 | - } |
|
580 | - } |
|
581 | - } |
|
582 | - return true; |
|
583 | - } |
|
584 | - |
|
585 | - |
|
586 | - /** |
|
587 | - * This validates the messenger, message type, and presences of generation data for the current EE_Message in the |
|
588 | - * queue. This process sets error messages if something is wrong. |
|
589 | - * |
|
590 | - * @return bool true is if there are no errors. false is if there is. |
|
591 | - */ |
|
592 | - protected function _validate_messenger_and_message_type() |
|
593 | - { |
|
594 | - |
|
595 | - //first are there any existing error messages? If so then return. |
|
596 | - if ($this->_error_msg) { |
|
597 | - return false; |
|
598 | - } |
|
599 | - /** @type EE_Message $message */ |
|
600 | - $message = $this->_generation_queue->get_message_repository()->current(); |
|
601 | - try { |
|
602 | - $this->_current_messenger = $message->valid_messenger(true) ? $message->messenger_object() : null; |
|
603 | - } catch (Exception $e) { |
|
604 | - $this->_error_msg[] = $e->getMessage(); |
|
605 | - } |
|
606 | - try { |
|
607 | - $this->_current_message_type = $message->valid_message_type(true) ? $message->message_type_object() : null; |
|
608 | - } catch (Exception $e) { |
|
609 | - $this->_error_msg[] = $e->getMessage(); |
|
610 | - } |
|
611 | - |
|
612 | - /** |
|
613 | - * Check if there is any generation data, but only if this is not for a preview. |
|
614 | - */ |
|
615 | - if (! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
616 | - && ( |
|
617 | - ! $this->_generation_queue->get_message_repository()->is_preview() |
|
618 | - && $this->_generation_queue->get_message_repository()->get_data_handler() !== 'EE_Messages_Preview_incoming_data') |
|
619 | - ) { |
|
620 | - $this->_error_msg[] = __('There is no generation data for this message. Unable to generate.'); |
|
621 | - } |
|
622 | - |
|
623 | - return empty($this->_error_msg); |
|
624 | - } |
|
625 | - |
|
626 | - |
|
627 | - /** |
|
628 | - * This method retrieves the expected data handler for the message type and validates the generation data for that |
|
629 | - * data handler. |
|
630 | - * |
|
631 | - * @return bool true means there are no errors. false means there were errors (and handler did not get setup). |
|
632 | - */ |
|
633 | - protected function _validate_and_setup_data() |
|
634 | - { |
|
635 | - |
|
636 | - //First, are there any existing error messages? If so, return because if there were errors elsewhere this can't |
|
637 | - //be used anyways. |
|
638 | - if ($this->_error_msg) { |
|
639 | - return false; |
|
640 | - } |
|
641 | - |
|
642 | - $generation_data = $this->_generation_queue->get_message_repository()->get_generation_data(); |
|
643 | - |
|
644 | - /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually */ |
|
645 | - $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
|
646 | - ? $this->_generation_queue->get_message_repository()->get_data_handler() |
|
647 | - : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data'; |
|
648 | - |
|
649 | - //If this EE_Message is for a preview, then let's switch out to the preview data handler. |
|
650 | - if ($this->_generation_queue->get_message_repository()->is_preview()) { |
|
651 | - $data_handler_class_name = 'EE_Messages_Preview_incoming_data'; |
|
652 | - } |
|
653 | - |
|
654 | - //First get the class name for the data handler (and also verifies it exists. |
|
655 | - if (! class_exists($data_handler_class_name)) { |
|
656 | - $this->_error_msg[] = sprintf( |
|
657 | - __('The included data handler class name does not match any valid, accessible, "EE_Messages_incoming_data" classes. Looking for %s.', |
|
658 | - 'event_espresso'), |
|
659 | - $data_handler_class_name |
|
660 | - ); |
|
661 | - return false; |
|
662 | - } |
|
663 | - |
|
664 | - //convert generation_data for data_handler_instantiation. |
|
665 | - $generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data); |
|
666 | - |
|
667 | - //note, this may set error messages as well. |
|
668 | - $this->_set_data_handler($generation_data, $data_handler_class_name); |
|
669 | - |
|
670 | - return empty($this->_error_msg); |
|
671 | - } |
|
672 | - |
|
673 | - |
|
674 | - /** |
|
675 | - * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and |
|
676 | - * adds it to the _data repository. |
|
677 | - * |
|
678 | - * @param mixed $generating_data This is data expected by the instantiated data handler. |
|
679 | - * @param string $data_handler_class_name This is the reference string indicating what data handler is being |
|
680 | - * instantiated. |
|
681 | - * @return void. |
|
682 | - */ |
|
683 | - protected function _set_data_handler($generating_data, $data_handler_class_name) |
|
684 | - { |
|
685 | - //valid classname for the data handler. Now let's setup the key for the data handler repository to see if there |
|
686 | - //is already a ready data handler in the repository. |
|
687 | - $this->_current_data_handler = $this->_data_handler_collection->get_by_key($this->_data_handler_collection->get_key($data_handler_class_name, |
|
688 | - $generating_data)); |
|
689 | - if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
690 | - //no saved data_handler in the repo so let's set one up and add it to the repo. |
|
691 | - try { |
|
692 | - $this->_current_data_handler = new $data_handler_class_name($generating_data); |
|
693 | - $this->_data_handler_collection->add($this->_current_data_handler, $generating_data); |
|
694 | - } catch (EE_Error $e) { |
|
695 | - $this->_error_msg[] = $e->get_error(); |
|
696 | - } |
|
697 | - } |
|
698 | - } |
|
699 | - |
|
700 | - |
|
701 | - /** |
|
702 | - * The queued EE_Message for generation does not save the data used for generation as objects |
|
703 | - * because serialization of those objects could be problematic if the data is saved to the db. |
|
704 | - * So this method calls the static method on the associated data_handler for the given message_type |
|
705 | - * and that preps the data for later instantiation when generating. |
|
706 | - * |
|
707 | - * @param EE_Message_To_Generate $message_to_generate |
|
708 | - * @param bool $preview Indicate whether this is being used for a preview or not. |
|
709 | - * @return mixed Prepped data for persisting to the queue. false is returned if unable to prep data. |
|
710 | - */ |
|
711 | - protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview) |
|
712 | - { |
|
713 | - /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
|
714 | - $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
|
715 | - if (! $message_to_generate->valid()) { |
|
716 | - return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
|
717 | - } |
|
718 | - return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
|
719 | - } |
|
720 | - |
|
721 | - |
|
722 | - /** |
|
723 | - * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue. |
|
724 | - * |
|
725 | - * @param EE_Message_To_Generate $message_to_generate |
|
726 | - * @param bool $test_send Whether this is just a test send or not. Typically used for previews. |
|
727 | - */ |
|
728 | - public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
729 | - { |
|
730 | - //prep data |
|
731 | - $data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview()); |
|
732 | - |
|
733 | - $message = $message_to_generate->get_EE_Message(); |
|
734 | - |
|
735 | - //is there a GRP_ID in the request? |
|
736 | - if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) { |
|
737 | - $message->set_GRP_ID($GRP_ID); |
|
738 | - } |
|
739 | - |
|
740 | - if ($data === false) { |
|
741 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
742 | - $message->set_error_message(__('Unable to prepare data for persistence to the database.', |
|
743 | - 'event_espresso')); |
|
744 | - } else { |
|
745 | - //make sure that the data handler is cached on the message as well |
|
746 | - $data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name(); |
|
747 | - } |
|
748 | - |
|
749 | - $this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send); |
|
750 | - } |
|
264 | + 'event_espresso'); |
|
265 | + return false; |
|
266 | + } |
|
267 | + |
|
268 | + $message_template_group = $this->_get_message_template_group(); |
|
269 | + |
|
270 | + //in the unlikely event there is no EE_Message_Template_Group available, get out! |
|
271 | + if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
272 | + $this->_error_msg[] = __('Unable to get the Message Templates for the Message being generated. No message template group accessible.', |
|
273 | + 'event_espresso'); |
|
274 | + return false; |
|
275 | + } |
|
276 | + |
|
277 | + //get formatted templates for using to parse and setup EE_Message objects. |
|
278 | + $templates = $this->_get_templates($message_template_group); |
|
279 | + |
|
280 | + |
|
281 | + //setup new EE_Message objects (and add to _ready_queue) |
|
282 | + return $this->_assemble_messages($addressees, $templates, $message_template_group); |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * Retrieves the message template group being used for generating messages. |
|
288 | + * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times. |
|
289 | + * |
|
290 | + * @return EE_Message_Template_Group | null |
|
291 | + */ |
|
292 | + protected function _get_message_template_group() |
|
293 | + { |
|
294 | + //is there a GRP_ID already on the EE_Message object? If there is, then a specific template has been requested |
|
295 | + //so let's use that. |
|
296 | + $GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID(); |
|
297 | + |
|
298 | + if ($GRP_ID) { |
|
299 | + //attempt to retrieve from repo first |
|
300 | + $GRP = $this->_template_collection->get_by_ID($GRP_ID); |
|
301 | + if ($GRP instanceof EE_Message_Template_Group) { |
|
302 | + return $GRP; //got it! |
|
303 | + } |
|
304 | + |
|
305 | + //nope don't have it yet. Get from DB then add to repo if its not here, then that means the current GRP_ID |
|
306 | + //is not valid, so we'll continue on in the code assuming there's NO GRP_ID. |
|
307 | + $GRP = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
308 | + if ($GRP instanceof EE_Message_Template_Group) { |
|
309 | + $this->_template_collection->add($GRP); |
|
310 | + return $GRP; |
|
311 | + } |
|
312 | + } |
|
313 | + |
|
314 | + //whatcha still doing here? Oh, no Message Template Group yet I see. Okay let's see if we can get it for you. |
|
315 | + |
|
316 | + //defaults |
|
317 | + $EVT_ID = 0; |
|
318 | + |
|
319 | + $template_qa = array( |
|
320 | + 'MTP_is_active' => true, |
|
321 | + 'MTP_messenger' => $this->_current_messenger->name, |
|
322 | + 'MTP_message_type' => $this->_current_message_type->name, |
|
323 | + ); |
|
324 | + |
|
325 | + //in vanilla EE we're assuming there's only one event. |
|
326 | + //However, if there are multiple events then we'll just use the default templates instead of different |
|
327 | + // templates per event (which could create problems). |
|
328 | + if (count($this->_current_data_handler->events) === 1) { |
|
329 | + foreach ($this->_current_data_handler->events as $event) { |
|
330 | + $EVT_ID = $event['ID']; |
|
331 | + } |
|
332 | + } |
|
333 | + |
|
334 | + //before going any further, let's see if its in the queue |
|
335 | + $GRP = $this->_template_collection->get_by_key($this->_template_collection->get_key($this->_current_messenger->name, |
|
336 | + $this->_current_message_type->name, $EVT_ID)); |
|
337 | + |
|
338 | + if ($GRP instanceof EE_Message_Template_Group) { |
|
339 | + return $GRP; |
|
340 | + } |
|
341 | + |
|
342 | + //nope still no GRP? |
|
343 | + //first we get the global template in case it has an override set. |
|
344 | + $global_template_qa = array_merge(array('MTP_is_global' => true), $template_qa); |
|
345 | + $global_GRP = EEM_Message_Template_Group::instance()->get_one(array($global_template_qa)); |
|
346 | + |
|
347 | + //if this is an override, then we just return it. |
|
348 | + if ($global_GRP instanceof EE_Message_Template_Group && $global_GRP->get('MTP_is_override')) { |
|
349 | + $this->_template_collection->add($global_GRP, $EVT_ID); |
|
350 | + return $global_GRP; |
|
351 | + } |
|
352 | + |
|
353 | + //STILL here? Okay that means we want to see if there is event specific group and if there is we return it, |
|
354 | + //otherwise we return the global group we retrieved. |
|
355 | + if ($EVT_ID) { |
|
356 | + $template_qa['Event.EVT_ID'] = $EVT_ID; |
|
357 | + } |
|
358 | + |
|
359 | + $GRP = EEM_Message_Template_Group::instance()->get_one(array($template_qa)); |
|
360 | + $GRP = $GRP instanceof EE_Message_Template_Group ? $GRP : $global_GRP; |
|
361 | + |
|
362 | + if ($GRP instanceof EE_Message_Template_Group) { |
|
363 | + $this->_template_collection->add($GRP, $EVT_ID); |
|
364 | + return $GRP; |
|
365 | + } |
|
366 | + |
|
367 | + //nothing, nada, there ain't no group from what you fed the machine. (Getting here is a very hard thing to do). |
|
368 | + return null; |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * Retrieves formatted array of template information for each context specific to the given |
|
374 | + * EE_Message_Template_Group |
|
375 | + * |
|
376 | + * @param EE_Message_Template_Group |
|
377 | + * @return array The returned array is in this structure: |
|
378 | + * array( |
|
379 | + * 'field_name' => array( |
|
380 | + * 'context' => 'content' |
|
381 | + * ) |
|
382 | + * ) |
|
383 | + */ |
|
384 | + protected function _get_templates(EE_Message_Template_Group $message_template_group) |
|
385 | + { |
|
386 | + $templates = array(); |
|
387 | + $context_templates = $message_template_group->context_templates(); |
|
388 | + foreach ($context_templates as $context => $template_fields) { |
|
389 | + foreach ($template_fields as $template_field => $template_obj) { |
|
390 | + if (! $template_obj instanceof EE_Message_Template) { |
|
391 | + continue; |
|
392 | + } |
|
393 | + $templates[$template_field][$context] = $template_obj->get('MTP_content'); |
|
394 | + } |
|
395 | + } |
|
396 | + return $templates; |
|
397 | + } |
|
398 | + |
|
399 | + |
|
400 | + /** |
|
401 | + * Assembles new fully generated EE_Message objects and adds to _ready_queue |
|
402 | + * |
|
403 | + * @param array $addressees Array of EE_Messages_Addressee objects indexed by message type |
|
404 | + * context. |
|
405 | + * @param array $templates formatted array of templates used for parsing data. |
|
406 | + * @param EE_Message_Template_Group $message_template_group |
|
407 | + * @return bool true if message generation went a-ok. false if some sort of exception occurred. Note: The |
|
408 | + * method will attempt to generate ALL EE_Message objects and add to the _ready_queue. Successfully |
|
409 | + * generated messages get added to the queue with EEM_Message::status_idle, unsuccessfully generated |
|
410 | + * messages will get added to the queue as EEM_Message::status_failed. Very rarely should "false" |
|
411 | + * be returned from this method. |
|
412 | + */ |
|
413 | + protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group) |
|
414 | + { |
|
415 | + |
|
416 | + //if templates are empty then get out because we can't generate anything. |
|
417 | + if (! $templates) { |
|
418 | + $this->_error_msg[] = __('Unable to assemble messages because there are no templates retrieved for generating the messages with', |
|
419 | + 'event_espresso'); |
|
420 | + return false; |
|
421 | + } |
|
422 | + |
|
423 | + //We use this as the counter for generated messages because don't forget we may be executing this inside of a |
|
424 | + //generation_queue. So _ready_queue may have generated EE_Message objects already. |
|
425 | + $generated_count = 0; |
|
426 | + foreach ($addressees as $context => $recipients) { |
|
427 | + foreach ($recipients as $recipient) { |
|
428 | + $message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group); |
|
429 | + if ($message instanceof EE_Message) { |
|
430 | + $this->_ready_queue->add( |
|
431 | + $message, |
|
432 | + array(), |
|
433 | + $this->_generation_queue->get_message_repository()->is_preview(), |
|
434 | + $this->_generation_queue->get_message_repository()->is_test_send() |
|
435 | + ); |
|
436 | + $generated_count++; |
|
437 | + } |
|
438 | + |
|
439 | + //if the current MSG being generated is for a test send then we'll only use ONE message in the generation. |
|
440 | + if ($this->_generation_queue->get_message_repository()->is_test_send()) { |
|
441 | + break 2; |
|
442 | + } |
|
443 | + } |
|
444 | + } |
|
445 | + |
|
446 | + //if there are no generated messages then something else fatal went wrong. |
|
447 | + return $generated_count > 0; |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * @param string $context The context for the generated message. |
|
453 | + * @param EE_Messages_Addressee $recipient |
|
454 | + * @param array $templates formatted array of templates used for parsing data. |
|
455 | + * @param EE_Message_Template_Group $message_template_group |
|
456 | + * @return EE_Message | bool (false is used when no EE_Message is generated) |
|
457 | + */ |
|
458 | + protected function _setup_message_object( |
|
459 | + $context, |
|
460 | + EE_Messages_Addressee $recipient, |
|
461 | + $templates, |
|
462 | + EE_Message_Template_Group $message_template_group |
|
463 | + ) { |
|
464 | + //stuff we already know |
|
465 | + $transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0; |
|
466 | + $transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction |
|
467 | + ? $this->_current_data_handler->txn->ID() |
|
468 | + : $transaction_id; |
|
469 | + $message_fields = array( |
|
470 | + 'GRP_ID' => $message_template_group->ID(), |
|
471 | + 'TXN_ID' => $transaction_id, |
|
472 | + 'MSG_messenger' => $this->_current_messenger->name, |
|
473 | + 'MSG_message_type' => $this->_current_message_type->name, |
|
474 | + 'MSG_context' => $context, |
|
475 | + ); |
|
476 | + |
|
477 | + //recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab the |
|
478 | + //info from the att_obj found in the EE_Messages_Addressee object. |
|
479 | + if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) { |
|
480 | + $message_fields['MSG_recipient_ID'] = $recipient->att_obj instanceof EE_Attendee |
|
481 | + ? $recipient->att_obj->ID() |
|
482 | + : 0; |
|
483 | + $message_fields['MSG_recipient_type'] = 'Attendee'; |
|
484 | + } else { |
|
485 | + $message_fields['MSG_recipient_ID'] = $recipient->recipient_id; |
|
486 | + $message_fields['MSG_recipient_type'] = $recipient->recipient_type; |
|
487 | + } |
|
488 | + $message = EE_Message_Factory::create($message_fields); |
|
489 | + |
|
490 | + //grab valid shortcodes for shortcode parser |
|
491 | + $mt_shortcodes = $this->_current_message_type->get_valid_shortcodes(); |
|
492 | + $m_shortcodes = $this->_current_messenger->get_valid_shortcodes(); |
|
493 | + |
|
494 | + //if the 'to' field is empty (messages will ALWAYS have a "to" field, then we get out because that means this |
|
495 | + //context is turned off) EXCEPT if we're previewing |
|
496 | + if (empty($templates['to'][$context]) |
|
497 | + && ! $this->_generation_queue->get_message_repository()->is_preview() |
|
498 | + && ! $this->_current_messenger->allow_empty_to_field() |
|
499 | + ) { |
|
500 | + //we silently exit here and do NOT record a fail because the message is "turned off" by having no "to" field. |
|
501 | + return false; |
|
502 | + } |
|
503 | + $error_msg = array(); |
|
504 | + foreach ($templates as $field => $field_context) { |
|
505 | + $error_msg = array(); |
|
506 | + //let's setup the valid shortcodes for the incoming context. |
|
507 | + $valid_shortcodes = $mt_shortcodes[$context]; |
|
508 | + //merge in valid shortcodes for the field. |
|
509 | + $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes; |
|
510 | + if (isset($templates[$field][$context])) { |
|
511 | + //prefix field. |
|
512 | + $column_name = 'MSG_' . $field; |
|
513 | + try { |
|
514 | + $content = $this->_shortcode_parser->parse_message_template( |
|
515 | + $templates[$field][$context], |
|
516 | + $recipient, |
|
517 | + $shortcodes, |
|
518 | + $this->_current_message_type, |
|
519 | + $this->_current_messenger, |
|
520 | + $message); |
|
521 | + $message->set_field_or_extra_meta($column_name, $content); |
|
522 | + } catch (EE_Error $e) { |
|
523 | + $error_msg[] = sprintf(__('There was a problem generating the content for the field %s: %s', |
|
524 | + 'event_espresso'), $field, $e->getMessage()); |
|
525 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
526 | + } |
|
527 | + } |
|
528 | + } |
|
529 | + |
|
530 | + if ($message->STS_ID() === EEM_Message::status_failed) { |
|
531 | + $error_msg = __('There were problems generating this message:', 'event_espresso') . "\n" . implode("\n", |
|
532 | + $error_msg); |
|
533 | + $message->set_error_message($error_msg); |
|
534 | + } else { |
|
535 | + $message->set_STS_ID(EEM_Message::status_idle); |
|
536 | + } |
|
537 | + return $message; |
|
538 | + } |
|
539 | + |
|
540 | + |
|
541 | + /** |
|
542 | + * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate |
|
543 | + * error message if either is missing. |
|
544 | + * |
|
545 | + * @return bool true means there were no errors, false means there were errors. |
|
546 | + */ |
|
547 | + protected function _verify() |
|
548 | + { |
|
549 | + //reset error message to an empty array. |
|
550 | + $this->_error_msg = array(); |
|
551 | + $valid = true; |
|
552 | + $valid = $valid ? $this->_validate_messenger_and_message_type() : $valid; |
|
553 | + $valid = $valid ? $this->_validate_and_setup_data() : $valid; |
|
554 | + |
|
555 | + //set the verified flag so we know everything has been validated. |
|
556 | + $this->_verified = $valid; |
|
557 | + |
|
558 | + return $valid; |
|
559 | + } |
|
560 | + |
|
561 | + |
|
562 | + /** |
|
563 | + * This accepts an array and validates that it is an array indexed by context with each value being an array of |
|
564 | + * EE_Messages_Addressee objects. |
|
565 | + * |
|
566 | + * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[] |
|
567 | + * @return bool |
|
568 | + */ |
|
569 | + protected function _valid_addressees($addressees) |
|
570 | + { |
|
571 | + if (! $addressees || ! is_array($addressees)) { |
|
572 | + return false; |
|
573 | + } |
|
574 | + |
|
575 | + foreach ($addressees as $addressee_array) { |
|
576 | + foreach ($addressee_array as $addressee) { |
|
577 | + if (! $addressee instanceof EE_Messages_Addressee) { |
|
578 | + return false; |
|
579 | + } |
|
580 | + } |
|
581 | + } |
|
582 | + return true; |
|
583 | + } |
|
584 | + |
|
585 | + |
|
586 | + /** |
|
587 | + * This validates the messenger, message type, and presences of generation data for the current EE_Message in the |
|
588 | + * queue. This process sets error messages if something is wrong. |
|
589 | + * |
|
590 | + * @return bool true is if there are no errors. false is if there is. |
|
591 | + */ |
|
592 | + protected function _validate_messenger_and_message_type() |
|
593 | + { |
|
594 | + |
|
595 | + //first are there any existing error messages? If so then return. |
|
596 | + if ($this->_error_msg) { |
|
597 | + return false; |
|
598 | + } |
|
599 | + /** @type EE_Message $message */ |
|
600 | + $message = $this->_generation_queue->get_message_repository()->current(); |
|
601 | + try { |
|
602 | + $this->_current_messenger = $message->valid_messenger(true) ? $message->messenger_object() : null; |
|
603 | + } catch (Exception $e) { |
|
604 | + $this->_error_msg[] = $e->getMessage(); |
|
605 | + } |
|
606 | + try { |
|
607 | + $this->_current_message_type = $message->valid_message_type(true) ? $message->message_type_object() : null; |
|
608 | + } catch (Exception $e) { |
|
609 | + $this->_error_msg[] = $e->getMessage(); |
|
610 | + } |
|
611 | + |
|
612 | + /** |
|
613 | + * Check if there is any generation data, but only if this is not for a preview. |
|
614 | + */ |
|
615 | + if (! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
616 | + && ( |
|
617 | + ! $this->_generation_queue->get_message_repository()->is_preview() |
|
618 | + && $this->_generation_queue->get_message_repository()->get_data_handler() !== 'EE_Messages_Preview_incoming_data') |
|
619 | + ) { |
|
620 | + $this->_error_msg[] = __('There is no generation data for this message. Unable to generate.'); |
|
621 | + } |
|
622 | + |
|
623 | + return empty($this->_error_msg); |
|
624 | + } |
|
625 | + |
|
626 | + |
|
627 | + /** |
|
628 | + * This method retrieves the expected data handler for the message type and validates the generation data for that |
|
629 | + * data handler. |
|
630 | + * |
|
631 | + * @return bool true means there are no errors. false means there were errors (and handler did not get setup). |
|
632 | + */ |
|
633 | + protected function _validate_and_setup_data() |
|
634 | + { |
|
635 | + |
|
636 | + //First, are there any existing error messages? If so, return because if there were errors elsewhere this can't |
|
637 | + //be used anyways. |
|
638 | + if ($this->_error_msg) { |
|
639 | + return false; |
|
640 | + } |
|
641 | + |
|
642 | + $generation_data = $this->_generation_queue->get_message_repository()->get_generation_data(); |
|
643 | + |
|
644 | + /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually */ |
|
645 | + $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
|
646 | + ? $this->_generation_queue->get_message_repository()->get_data_handler() |
|
647 | + : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data'; |
|
648 | + |
|
649 | + //If this EE_Message is for a preview, then let's switch out to the preview data handler. |
|
650 | + if ($this->_generation_queue->get_message_repository()->is_preview()) { |
|
651 | + $data_handler_class_name = 'EE_Messages_Preview_incoming_data'; |
|
652 | + } |
|
653 | + |
|
654 | + //First get the class name for the data handler (and also verifies it exists. |
|
655 | + if (! class_exists($data_handler_class_name)) { |
|
656 | + $this->_error_msg[] = sprintf( |
|
657 | + __('The included data handler class name does not match any valid, accessible, "EE_Messages_incoming_data" classes. Looking for %s.', |
|
658 | + 'event_espresso'), |
|
659 | + $data_handler_class_name |
|
660 | + ); |
|
661 | + return false; |
|
662 | + } |
|
663 | + |
|
664 | + //convert generation_data for data_handler_instantiation. |
|
665 | + $generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data); |
|
666 | + |
|
667 | + //note, this may set error messages as well. |
|
668 | + $this->_set_data_handler($generation_data, $data_handler_class_name); |
|
669 | + |
|
670 | + return empty($this->_error_msg); |
|
671 | + } |
|
672 | + |
|
673 | + |
|
674 | + /** |
|
675 | + * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and |
|
676 | + * adds it to the _data repository. |
|
677 | + * |
|
678 | + * @param mixed $generating_data This is data expected by the instantiated data handler. |
|
679 | + * @param string $data_handler_class_name This is the reference string indicating what data handler is being |
|
680 | + * instantiated. |
|
681 | + * @return void. |
|
682 | + */ |
|
683 | + protected function _set_data_handler($generating_data, $data_handler_class_name) |
|
684 | + { |
|
685 | + //valid classname for the data handler. Now let's setup the key for the data handler repository to see if there |
|
686 | + //is already a ready data handler in the repository. |
|
687 | + $this->_current_data_handler = $this->_data_handler_collection->get_by_key($this->_data_handler_collection->get_key($data_handler_class_name, |
|
688 | + $generating_data)); |
|
689 | + if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
690 | + //no saved data_handler in the repo so let's set one up and add it to the repo. |
|
691 | + try { |
|
692 | + $this->_current_data_handler = new $data_handler_class_name($generating_data); |
|
693 | + $this->_data_handler_collection->add($this->_current_data_handler, $generating_data); |
|
694 | + } catch (EE_Error $e) { |
|
695 | + $this->_error_msg[] = $e->get_error(); |
|
696 | + } |
|
697 | + } |
|
698 | + } |
|
699 | + |
|
700 | + |
|
701 | + /** |
|
702 | + * The queued EE_Message for generation does not save the data used for generation as objects |
|
703 | + * because serialization of those objects could be problematic if the data is saved to the db. |
|
704 | + * So this method calls the static method on the associated data_handler for the given message_type |
|
705 | + * and that preps the data for later instantiation when generating. |
|
706 | + * |
|
707 | + * @param EE_Message_To_Generate $message_to_generate |
|
708 | + * @param bool $preview Indicate whether this is being used for a preview or not. |
|
709 | + * @return mixed Prepped data for persisting to the queue. false is returned if unable to prep data. |
|
710 | + */ |
|
711 | + protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview) |
|
712 | + { |
|
713 | + /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
|
714 | + $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
|
715 | + if (! $message_to_generate->valid()) { |
|
716 | + return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
|
717 | + } |
|
718 | + return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
|
719 | + } |
|
720 | + |
|
721 | + |
|
722 | + /** |
|
723 | + * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue. |
|
724 | + * |
|
725 | + * @param EE_Message_To_Generate $message_to_generate |
|
726 | + * @param bool $test_send Whether this is just a test send or not. Typically used for previews. |
|
727 | + */ |
|
728 | + public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
729 | + { |
|
730 | + //prep data |
|
731 | + $data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview()); |
|
732 | + |
|
733 | + $message = $message_to_generate->get_EE_Message(); |
|
734 | + |
|
735 | + //is there a GRP_ID in the request? |
|
736 | + if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) { |
|
737 | + $message->set_GRP_ID($GRP_ID); |
|
738 | + } |
|
739 | + |
|
740 | + if ($data === false) { |
|
741 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
742 | + $message->set_error_message(__('Unable to prepare data for persistence to the database.', |
|
743 | + 'event_espresso')); |
|
744 | + } else { |
|
745 | + //make sure that the data handler is cached on the message as well |
|
746 | + $data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name(); |
|
747 | + } |
|
748 | + |
|
749 | + $this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send); |
|
750 | + } |
|
751 | 751 | |
752 | 752 | |
753 | 753 | } //end EE_Messages_Generator |
754 | 754 | \ No newline at end of file |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | protected function _generate() |
238 | 238 | { |
239 | 239 | //double check verification has run and that everything is ready to work with (saves us having to validate everything again). |
240 | - if (! $this->_verified) { |
|
240 | + if ( ! $this->_verified) { |
|
241 | 241 | return false; //get out because we don't have a valid setup to work with. |
242 | 242 | } |
243 | 243 | |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | |
255 | 255 | |
256 | 256 | //if no addressees then get out because there is nothing to generation (possible bad data). |
257 | - if (! $this->_valid_addressees($addressees)) { |
|
257 | + if ( ! $this->_valid_addressees($addressees)) { |
|
258 | 258 | do_action('AHEE__EE_Messages_Generator___generate__invalid_addressees', |
259 | 259 | $this->_generation_queue->get_message_repository()->current(), $addressees, $this->_current_messenger, |
260 | 260 | $this->_current_message_type, $this->_current_data_handler); |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | $message_template_group = $this->_get_message_template_group(); |
269 | 269 | |
270 | 270 | //in the unlikely event there is no EE_Message_Template_Group available, get out! |
271 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
271 | + if ( ! $message_template_group instanceof EE_Message_Template_Group) { |
|
272 | 272 | $this->_error_msg[] = __('Unable to get the Message Templates for the Message being generated. No message template group accessible.', |
273 | 273 | 'event_espresso'); |
274 | 274 | return false; |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | //attempt to retrieve from repo first |
300 | 300 | $GRP = $this->_template_collection->get_by_ID($GRP_ID); |
301 | 301 | if ($GRP instanceof EE_Message_Template_Group) { |
302 | - return $GRP; //got it! |
|
302 | + return $GRP; //got it! |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | //nope don't have it yet. Get from DB then add to repo if its not here, then that means the current GRP_ID |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | $context_templates = $message_template_group->context_templates(); |
388 | 388 | foreach ($context_templates as $context => $template_fields) { |
389 | 389 | foreach ($template_fields as $template_field => $template_obj) { |
390 | - if (! $template_obj instanceof EE_Message_Template) { |
|
390 | + if ( ! $template_obj instanceof EE_Message_Template) { |
|
391 | 391 | continue; |
392 | 392 | } |
393 | 393 | $templates[$template_field][$context] = $template_obj->get('MTP_content'); |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | { |
415 | 415 | |
416 | 416 | //if templates are empty then get out because we can't generate anything. |
417 | - if (! $templates) { |
|
417 | + if ( ! $templates) { |
|
418 | 418 | $this->_error_msg[] = __('Unable to assemble messages because there are no templates retrieved for generating the messages with', |
419 | 419 | 'event_espresso'); |
420 | 420 | return false; |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes; |
510 | 510 | if (isset($templates[$field][$context])) { |
511 | 511 | //prefix field. |
512 | - $column_name = 'MSG_' . $field; |
|
512 | + $column_name = 'MSG_'.$field; |
|
513 | 513 | try { |
514 | 514 | $content = $this->_shortcode_parser->parse_message_template( |
515 | 515 | $templates[$field][$context], |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | } |
529 | 529 | |
530 | 530 | if ($message->STS_ID() === EEM_Message::status_failed) { |
531 | - $error_msg = __('There were problems generating this message:', 'event_espresso') . "\n" . implode("\n", |
|
531 | + $error_msg = __('There were problems generating this message:', 'event_espresso')."\n".implode("\n", |
|
532 | 532 | $error_msg); |
533 | 533 | $message->set_error_message($error_msg); |
534 | 534 | } else { |
@@ -568,13 +568,13 @@ discard block |
||
568 | 568 | */ |
569 | 569 | protected function _valid_addressees($addressees) |
570 | 570 | { |
571 | - if (! $addressees || ! is_array($addressees)) { |
|
571 | + if ( ! $addressees || ! is_array($addressees)) { |
|
572 | 572 | return false; |
573 | 573 | } |
574 | 574 | |
575 | 575 | foreach ($addressees as $addressee_array) { |
576 | 576 | foreach ($addressee_array as $addressee) { |
577 | - if (! $addressee instanceof EE_Messages_Addressee) { |
|
577 | + if ( ! $addressee instanceof EE_Messages_Addressee) { |
|
578 | 578 | return false; |
579 | 579 | } |
580 | 580 | } |
@@ -612,7 +612,7 @@ discard block |
||
612 | 612 | /** |
613 | 613 | * Check if there is any generation data, but only if this is not for a preview. |
614 | 614 | */ |
615 | - if (! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
615 | + if ( ! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
616 | 616 | && ( |
617 | 617 | ! $this->_generation_queue->get_message_repository()->is_preview() |
618 | 618 | && $this->_generation_queue->get_message_repository()->get_data_handler() !== 'EE_Messages_Preview_incoming_data') |
@@ -644,7 +644,7 @@ discard block |
||
644 | 644 | /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually */ |
645 | 645 | $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
646 | 646 | ? $this->_generation_queue->get_message_repository()->get_data_handler() |
647 | - : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data'; |
|
647 | + : 'EE_Messages_'.$this->_current_message_type->get_data_handler($generation_data).'_incoming_data'; |
|
648 | 648 | |
649 | 649 | //If this EE_Message is for a preview, then let's switch out to the preview data handler. |
650 | 650 | if ($this->_generation_queue->get_message_repository()->is_preview()) { |
@@ -652,7 +652,7 @@ discard block |
||
652 | 652 | } |
653 | 653 | |
654 | 654 | //First get the class name for the data handler (and also verifies it exists. |
655 | - if (! class_exists($data_handler_class_name)) { |
|
655 | + if ( ! class_exists($data_handler_class_name)) { |
|
656 | 656 | $this->_error_msg[] = sprintf( |
657 | 657 | __('The included data handler class name does not match any valid, accessible, "EE_Messages_incoming_data" classes. Looking for %s.', |
658 | 658 | 'event_espresso'), |
@@ -686,7 +686,7 @@ discard block |
||
686 | 686 | //is already a ready data handler in the repository. |
687 | 687 | $this->_current_data_handler = $this->_data_handler_collection->get_by_key($this->_data_handler_collection->get_key($data_handler_class_name, |
688 | 688 | $generating_data)); |
689 | - if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
689 | + if ( ! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
690 | 690 | //no saved data_handler in the repo so let's set one up and add it to the repo. |
691 | 691 | try { |
692 | 692 | $this->_current_data_handler = new $data_handler_class_name($generating_data); |
@@ -712,7 +712,7 @@ discard block |
||
712 | 712 | { |
713 | 713 | /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
714 | 714 | $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
715 | - if (! $message_to_generate->valid()) { |
|
715 | + if ( ! $message_to_generate->valid()) { |
|
716 | 716 | return false; //unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
717 | 717 | } |
718 | 718 | return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
@@ -47,7 +47,7 @@ |
||
47 | 47 | /** |
48 | 48 | * This retrieves any EE_Message_Template_Group in the repo by its ID. |
49 | 49 | * |
50 | - * @param $GRP_ID |
|
50 | + * @param integer $GRP_ID |
|
51 | 51 | * @return EE_Message_Template_Group | null |
52 | 52 | */ |
53 | 53 | public function get_by_ID($GRP_ID) |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('No direct script access allowed'); |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -16,89 +16,89 @@ discard block |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - public function __construct() |
|
20 | - { |
|
21 | - $this->interface = 'EE_Message_Template_Group'; |
|
22 | - } |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + $this->interface = 'EE_Message_Template_Group'; |
|
22 | + } |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * Adds the Message Template Group object to the repository. |
|
27 | - * |
|
28 | - * @param $message_template_group |
|
29 | - * @param int $EVT_ID Some templates are specific to EVT, so this is provided as a way of |
|
30 | - * indexing the template by key. |
|
31 | - * @return bool |
|
32 | - */ |
|
33 | - public function add($message_template_group, $EVT_ID = null) |
|
34 | - { |
|
35 | - if ($message_template_group instanceof $this->interface) { |
|
36 | - $data['key'] = $this->get_key( |
|
37 | - $message_template_group->messenger(), |
|
38 | - $message_template_group->message_type(), |
|
39 | - $EVT_ID |
|
40 | - ); |
|
41 | - return parent::add($message_template_group, $data); |
|
42 | - } |
|
43 | - return false; |
|
44 | - } |
|
25 | + /** |
|
26 | + * Adds the Message Template Group object to the repository. |
|
27 | + * |
|
28 | + * @param $message_template_group |
|
29 | + * @param int $EVT_ID Some templates are specific to EVT, so this is provided as a way of |
|
30 | + * indexing the template by key. |
|
31 | + * @return bool |
|
32 | + */ |
|
33 | + public function add($message_template_group, $EVT_ID = null) |
|
34 | + { |
|
35 | + if ($message_template_group instanceof $this->interface) { |
|
36 | + $data['key'] = $this->get_key( |
|
37 | + $message_template_group->messenger(), |
|
38 | + $message_template_group->message_type(), |
|
39 | + $EVT_ID |
|
40 | + ); |
|
41 | + return parent::add($message_template_group, $data); |
|
42 | + } |
|
43 | + return false; |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * This retrieves any EE_Message_Template_Group in the repo by its ID. |
|
49 | - * |
|
50 | - * @param $GRP_ID |
|
51 | - * @return EE_Message_Template_Group | null |
|
52 | - */ |
|
53 | - public function get_by_ID($GRP_ID) |
|
54 | - { |
|
55 | - $this->rewind(); |
|
56 | - while ($this->valid()) { |
|
57 | - if ($this->current()->ID() === $GRP_ID) { |
|
58 | - $grp = $this->current(); |
|
59 | - $this->rewind(); |
|
60 | - return $grp; |
|
61 | - } |
|
62 | - $this->next(); |
|
63 | - } |
|
64 | - return null; |
|
65 | - } |
|
47 | + /** |
|
48 | + * This retrieves any EE_Message_Template_Group in the repo by its ID. |
|
49 | + * |
|
50 | + * @param $GRP_ID |
|
51 | + * @return EE_Message_Template_Group | null |
|
52 | + */ |
|
53 | + public function get_by_ID($GRP_ID) |
|
54 | + { |
|
55 | + $this->rewind(); |
|
56 | + while ($this->valid()) { |
|
57 | + if ($this->current()->ID() === $GRP_ID) { |
|
58 | + $grp = $this->current(); |
|
59 | + $this->rewind(); |
|
60 | + return $grp; |
|
61 | + } |
|
62 | + $this->next(); |
|
63 | + } |
|
64 | + return null; |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * Generates a hash used to identify a given Message Template Group. |
|
70 | - * |
|
71 | - * @param string $messenger The EE_messenger->name |
|
72 | - * @param string $message_type The EE_message_type->name |
|
73 | - * @param int $EVT_ID Optional. If the template is for a specific EVT then that should be included. |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - public function get_key($messenger, $message_type, $EVT_ID = 0) |
|
77 | - { |
|
78 | - return md5($messenger . $message_type . $EVT_ID); |
|
79 | - } |
|
68 | + /** |
|
69 | + * Generates a hash used to identify a given Message Template Group. |
|
70 | + * |
|
71 | + * @param string $messenger The EE_messenger->name |
|
72 | + * @param string $message_type The EE_message_type->name |
|
73 | + * @param int $EVT_ID Optional. If the template is for a specific EVT then that should be included. |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + public function get_key($messenger, $message_type, $EVT_ID = 0) |
|
77 | + { |
|
78 | + return md5($messenger . $message_type . $EVT_ID); |
|
79 | + } |
|
80 | 80 | |
81 | 81 | |
82 | - /** |
|
83 | - * This returns a saved EE_Message_Template_Group object if there is one in the repository indexed by a key matching |
|
84 | - * the given string. |
|
85 | - * |
|
86 | - * @param string $key @see EE_Message_Template_Group::get_key() to setup a key formatted for searching. |
|
87 | - * @return null|EE_Message_Template_Group |
|
88 | - */ |
|
89 | - public function get_by_key($key) |
|
90 | - { |
|
91 | - $this->rewind(); |
|
92 | - while ($this->valid()) { |
|
93 | - $data = $this->getInfo(); |
|
94 | - if (isset($data['key']) && $data['key'] === $key) { |
|
95 | - $handler = $this->current(); |
|
96 | - $this->rewind(); |
|
97 | - return $handler; |
|
98 | - } |
|
99 | - $this->next(); |
|
100 | - } |
|
101 | - return null; |
|
102 | - } |
|
82 | + /** |
|
83 | + * This returns a saved EE_Message_Template_Group object if there is one in the repository indexed by a key matching |
|
84 | + * the given string. |
|
85 | + * |
|
86 | + * @param string $key @see EE_Message_Template_Group::get_key() to setup a key formatted for searching. |
|
87 | + * @return null|EE_Message_Template_Group |
|
88 | + */ |
|
89 | + public function get_by_key($key) |
|
90 | + { |
|
91 | + $this->rewind(); |
|
92 | + while ($this->valid()) { |
|
93 | + $data = $this->getInfo(); |
|
94 | + if (isset($data['key']) && $data['key'] === $key) { |
|
95 | + $handler = $this->current(); |
|
96 | + $this->rewind(); |
|
97 | + return $handler; |
|
98 | + } |
|
99 | + $this->next(); |
|
100 | + } |
|
101 | + return null; |
|
102 | + } |
|
103 | 103 | |
104 | 104 | } //end EE_Message_Template_Group_Collection |
105 | 105 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('No direct script access allowed'); |
4 | 4 | } |
5 | 5 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | */ |
76 | 76 | public function get_key($messenger, $message_type, $EVT_ID = 0) |
77 | 77 | { |
78 | - return md5($messenger . $message_type . $EVT_ID); |
|
78 | + return md5($messenger.$message_type.$EVT_ID); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 |
@@ -21,63 +21,63 @@ |
||
21 | 21 | |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * the actual shortcode tag that gets registered with WordPress |
|
26 | - * |
|
27 | - * @return string |
|
28 | - */ |
|
29 | - public function getTag() |
|
30 | - { |
|
31 | - return 'ESPRESSO_TICKET_SELECTOR'; |
|
32 | - } |
|
33 | - |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * the time in seconds to cache the results of the processShortcode() method |
|
38 | - * 0 means the processShortcode() results will NOT be cached at all |
|
39 | - * |
|
40 | - * @return int |
|
41 | - */ |
|
42 | - public function cacheExpiration() |
|
43 | - { |
|
44 | - return 0; |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * a place for adding any initialization code that needs to run prior to wp_header(). |
|
50 | - * this may be required for shortcodes that utilize a corresponding module, |
|
51 | - * and need to enqueue assets for that module |
|
52 | - * |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - public function initializeShortcode() |
|
56 | - { |
|
57 | - add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
58 | - $this->shortcodeHasBeenInitialized(); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * callback that runs when the shortcode is encountered in post content. |
|
65 | - * IMPORTANT !!! |
|
66 | - * remember that shortcode content should be RETURNED and NOT echoed out |
|
67 | - * |
|
68 | - * @param array $attributes |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function processShortcode($attributes = array()) |
|
72 | - { |
|
73 | - extract($attributes, EXTR_OVERWRITE); |
|
74 | - $event_id = isset($event_id) ? $event_id : 0; |
|
75 | - $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id); |
|
76 | - ob_start(); |
|
77 | - do_action('AHEE_event_details_before_post', $event_id); |
|
78 | - espresso_ticket_selector($event); |
|
79 | - do_action('AHEE_event_details_after_post'); |
|
80 | - return ob_get_clean(); } |
|
24 | + /** |
|
25 | + * the actual shortcode tag that gets registered with WordPress |
|
26 | + * |
|
27 | + * @return string |
|
28 | + */ |
|
29 | + public function getTag() |
|
30 | + { |
|
31 | + return 'ESPRESSO_TICKET_SELECTOR'; |
|
32 | + } |
|
33 | + |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * the time in seconds to cache the results of the processShortcode() method |
|
38 | + * 0 means the processShortcode() results will NOT be cached at all |
|
39 | + * |
|
40 | + * @return int |
|
41 | + */ |
|
42 | + public function cacheExpiration() |
|
43 | + { |
|
44 | + return 0; |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * a place for adding any initialization code that needs to run prior to wp_header(). |
|
50 | + * this may be required for shortcodes that utilize a corresponding module, |
|
51 | + * and need to enqueue assets for that module |
|
52 | + * |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + public function initializeShortcode() |
|
56 | + { |
|
57 | + add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
58 | + $this->shortcodeHasBeenInitialized(); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * callback that runs when the shortcode is encountered in post content. |
|
65 | + * IMPORTANT !!! |
|
66 | + * remember that shortcode content should be RETURNED and NOT echoed out |
|
67 | + * |
|
68 | + * @param array $attributes |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function processShortcode($attributes = array()) |
|
72 | + { |
|
73 | + extract($attributes, EXTR_OVERWRITE); |
|
74 | + $event_id = isset($event_id) ? $event_id : 0; |
|
75 | + $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id); |
|
76 | + ob_start(); |
|
77 | + do_action('AHEE_event_details_before_post', $event_id); |
|
78 | + espresso_ticket_selector($event); |
|
79 | + do_action('AHEE_event_details_after_post'); |
|
80 | + return ob_get_clean(); } |
|
81 | 81 | } |
82 | 82 | // End of file EspressoTicketSelector.php |
83 | 83 | // Location: EventEspresso\core\domain\entities\shortcodes/EspressoTicketSelector.php |
84 | 84 | \ No newline at end of file |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\widgets\EspressoWidget; |
4 | 4 | |
5 | 5 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
6 | - exit('No direct script access allowed'); |
|
6 | + exit('No direct script access allowed'); |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | /** |
@@ -26,379 +26,379 @@ discard block |
||
26 | 26 | final class EE_Front_Controller |
27 | 27 | { |
28 | 28 | |
29 | - /** |
|
30 | - * @var string $_template_path |
|
31 | - */ |
|
32 | - private $_template_path; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var string $_template |
|
36 | - */ |
|
37 | - private $_template; |
|
38 | - |
|
39 | - /** |
|
40 | - * @type EE_Registry $Registry |
|
41 | - */ |
|
42 | - protected $Registry; |
|
43 | - |
|
44 | - /** |
|
45 | - * @type EE_Request_Handler $Request_Handler |
|
46 | - */ |
|
47 | - protected $Request_Handler; |
|
48 | - |
|
49 | - /** |
|
50 | - * @type EE_Module_Request_Router $Module_Request_Router |
|
51 | - */ |
|
52 | - protected $Module_Request_Router; |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * class constructor |
|
57 | - * should fire after shortcode, module, addon, or other plugin's default priority init phases have run |
|
58 | - * |
|
59 | - * @access public |
|
60 | - * @param \EE_Registry $Registry |
|
61 | - * @param \EE_Request_Handler $Request_Handler |
|
62 | - * @param \EE_Module_Request_Router $Module_Request_Router |
|
63 | - */ |
|
64 | - public function __construct( |
|
65 | - EE_Registry $Registry, |
|
66 | - EE_Request_Handler $Request_Handler, |
|
67 | - EE_Module_Request_Router $Module_Request_Router |
|
68 | - ) { |
|
69 | - $this->Registry = $Registry; |
|
70 | - $this->Request_Handler = $Request_Handler; |
|
71 | - $this->Module_Request_Router = $Module_Request_Router; |
|
72 | - // determine how to integrate WP_Query with the EE models |
|
73 | - add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy')); |
|
74 | - // load other resources and begin to actually run shortcodes and modules |
|
75 | - add_action('wp_loaded', array($this, 'wp_loaded'), 5); |
|
76 | - // analyse the incoming WP request |
|
77 | - add_action('parse_request', array($this, 'get_request'), 1, 1); |
|
78 | - // process request with module factory |
|
79 | - add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1); |
|
80 | - // before headers sent |
|
81 | - add_action('wp', array($this, 'wp'), 5); |
|
82 | - // after headers sent but before any markup is output, |
|
83 | - // primarily used to process any content shortcodes |
|
84 | - add_action('wp_head', array($this, 'wpHead'), 0); |
|
85 | - // header |
|
86 | - add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
87 | - add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10); |
|
88 | - add_filter('template_include', array($this, 'template_include'), 1); |
|
89 | - // display errors |
|
90 | - add_action('loop_start', array($this, 'display_errors'), 2); |
|
91 | - // the content |
|
92 | - // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
93 | - //exclude our private cpt comments |
|
94 | - add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
95 | - //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
|
96 | - add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
97 | - // action hook EE |
|
98 | - do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
99 | - // for checking that browser cookies are enabled |
|
100 | - if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
|
101 | - setcookie('ee_cookie_test', uniqid('ect',true), time() + DAY_IN_SECONDS, '/'); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @return EE_Request_Handler |
|
108 | - */ |
|
109 | - public function Request_Handler() |
|
110 | - { |
|
111 | - return $this->Request_Handler; |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @return EE_Module_Request_Router |
|
117 | - */ |
|
118 | - public function Module_Request_Router() |
|
119 | - { |
|
120 | - return $this->Module_Request_Router; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @return LegacyShortcodesManager |
|
127 | - */ |
|
128 | - public function getLegacyShortcodesManager() |
|
129 | - { |
|
130 | - return EE_Config::getLegacyShortcodesManager(); |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - |
|
135 | - |
|
136 | - |
|
137 | - /*********************************************** INIT ACTION HOOK ***********************************************/ |
|
138 | - |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * filter_wp_comments |
|
143 | - * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
|
144 | - * widgets/queries done on frontend |
|
145 | - * |
|
146 | - * @param array $clauses array of comment clauses setup by WP_Comment_Query |
|
147 | - * @return array array of comment clauses with modifications. |
|
148 | - */ |
|
149 | - public function filter_wp_comments($clauses) |
|
150 | - { |
|
151 | - global $wpdb; |
|
152 | - if (strpos($clauses['join'], $wpdb->posts) !== false) { |
|
153 | - $cpts = EE_Register_CPTs::get_private_CPTs(); |
|
154 | - foreach ($cpts as $cpt => $details) { |
|
155 | - $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
156 | - } |
|
157 | - } |
|
158 | - return $clauses; |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * employ_CPT_Strategy |
|
164 | - * |
|
165 | - * @access public |
|
166 | - * @return void |
|
167 | - */ |
|
168 | - public function employ_CPT_Strategy() |
|
169 | - { |
|
170 | - if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) { |
|
171 | - $this->Registry->load_core('CPT_Strategy'); |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
|
178 | - * |
|
179 | - * @param string $url incoming url |
|
180 | - * @return string final assembled url |
|
181 | - */ |
|
182 | - public function maybe_force_admin_ajax_ssl($url) |
|
183 | - { |
|
184 | - if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
185 | - $url = str_replace('http://', 'https://', $url); |
|
186 | - } |
|
187 | - return $url; |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - |
|
192 | - |
|
193 | - |
|
194 | - |
|
195 | - /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
|
200 | - * default priority init phases have run |
|
201 | - * |
|
202 | - * @access public |
|
203 | - * @return void |
|
204 | - */ |
|
205 | - public function wp_loaded() |
|
206 | - { |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - |
|
211 | - |
|
212 | - |
|
213 | - /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
|
214 | - /** |
|
215 | - * _get_request |
|
216 | - * |
|
217 | - * @access public |
|
218 | - * @param WP $WP |
|
219 | - * @return void |
|
220 | - */ |
|
221 | - public function get_request(WP $WP) |
|
222 | - { |
|
223 | - do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
224 | - $this->Request_Handler->parse_request($WP); |
|
225 | - do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
|
232 | - * |
|
233 | - * @access public |
|
234 | - * @param WP_Query $WP_Query |
|
235 | - * @return void |
|
236 | - */ |
|
237 | - public function pre_get_posts($WP_Query) |
|
238 | - { |
|
239 | - // only load Module_Request_Router if this is the main query |
|
240 | - if ( |
|
241 | - $this->Module_Request_Router instanceof EE_Module_Request_Router |
|
242 | - && $WP_Query->is_main_query() |
|
243 | - ) { |
|
244 | - // cycle thru module routes |
|
245 | - while ($route = $this->Module_Request_Router->get_route($WP_Query)) { |
|
246 | - // determine module and method for route |
|
247 | - $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]); |
|
248 | - if ($module instanceof EED_Module) { |
|
249 | - // get registered view for route |
|
250 | - $this->_template_path = $this->Module_Request_Router->get_view($route); |
|
251 | - // grab module name |
|
252 | - $module_name = $module->module_name(); |
|
253 | - // map the module to the module objects |
|
254 | - $this->Registry->modules->{$module_name} = $module; |
|
255 | - } |
|
256 | - } |
|
257 | - } |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - |
|
262 | - |
|
263 | - |
|
264 | - /*********************************************** WP HOOK ***********************************************/ |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * wp - basically last chance to do stuff before headers sent |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @return void |
|
272 | - */ |
|
273 | - public function wp() |
|
274 | - { |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - |
|
279 | - /*********************** GET_HEADER && WP_HEAD HOOK ***********************/ |
|
280 | - |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * callback for the "wp_head" hook point |
|
285 | - * checks sidebars for EE widgets |
|
286 | - * loads resources and assets accordingly |
|
287 | - * |
|
288 | - * @return void |
|
289 | - */ |
|
290 | - public function wpHead() |
|
291 | - { |
|
292 | - global $wp_query; |
|
293 | - if (empty($wp_query->posts)){ |
|
294 | - return; |
|
295 | - } |
|
296 | - // if we already know this is an espresso page, then load assets |
|
297 | - $load_assets = $this->Request_Handler->is_espresso_page(); |
|
298 | - // if we are already loading assets then just move along, otherwise check for widgets |
|
299 | - $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
|
300 | - if ( $load_assets){ |
|
301 | - wp_enqueue_style('espresso_default'); |
|
302 | - wp_enqueue_style('espresso_custom_css'); |
|
303 | - wp_enqueue_script('espresso_core'); |
|
304 | - } |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - |
|
309 | - /** |
|
310 | - * builds list of active widgets then scans active sidebars looking for them |
|
311 | - * returns true is an EE widget is found in an active sidebar |
|
312 | - * Please Note: this does NOT mean that the sidebar or widget |
|
313 | - * is actually in use in a given template, as that is unfortunately not known |
|
314 | - * until a sidebar and it's widgets are actually loaded |
|
315 | - * |
|
316 | - * @return boolean |
|
317 | - */ |
|
318 | - private function espresso_widgets_in_active_sidebars() |
|
319 | - { |
|
320 | - $espresso_widgets = array(); |
|
321 | - foreach ($this->Registry->widgets as $widget_class => $widget) { |
|
322 | - $id_base = EspressoWidget::getIdBase($widget_class); |
|
323 | - if (is_active_widget(false, false, $id_base)) { |
|
324 | - $espresso_widgets[] = $id_base; |
|
325 | - } |
|
326 | - } |
|
327 | - $all_sidebar_widgets = wp_get_sidebars_widgets(); |
|
328 | - foreach ($all_sidebar_widgets as $sidebar_name => $sidebar_widgets) { |
|
329 | - if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) { |
|
330 | - foreach ($sidebar_widgets as $sidebar_widget) { |
|
331 | - foreach ($espresso_widgets as $espresso_widget) { |
|
332 | - if (strpos($sidebar_widget, $espresso_widget) !== false) { |
|
333 | - return true; |
|
334 | - } |
|
335 | - } |
|
336 | - } |
|
337 | - } |
|
338 | - } |
|
339 | - return false; |
|
340 | - } |
|
341 | - |
|
342 | - |
|
343 | - |
|
344 | - |
|
345 | - /** |
|
346 | - * header_meta_tag |
|
347 | - * |
|
348 | - * @access public |
|
349 | - * @return void |
|
350 | - */ |
|
351 | - public function header_meta_tag() |
|
352 | - { |
|
353 | - print( |
|
354 | - apply_filters( |
|
355 | - 'FHEE__EE_Front_Controller__header_meta_tag', |
|
356 | - '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
357 | - ); |
|
358 | - |
|
359 | - //let's exclude all event type taxonomy term archive pages from search engine indexing |
|
360 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
|
361 | - //also exclude all critical pages from indexing |
|
362 | - if ( |
|
363 | - ( |
|
364 | - is_tax('espresso_event_type') |
|
365 | - && get_option( 'blog_public' ) !== '0' |
|
366 | - ) |
|
367 | - || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
|
368 | - ) { |
|
369 | - print( |
|
370 | - apply_filters( |
|
371 | - 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
|
372 | - '<meta name="robots" content="noindex,follow" />' . "\n" |
|
373 | - ) |
|
374 | - ); |
|
375 | - } |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * wp_print_scripts |
|
382 | - * |
|
383 | - * @return void |
|
384 | - */ |
|
385 | - public function wp_print_scripts() |
|
386 | - { |
|
387 | - global $post; |
|
388 | - if ( |
|
389 | - isset($post->EE_Event) |
|
390 | - && $post->EE_Event instanceof EE_Event |
|
391 | - && get_post_type() === 'espresso_events' |
|
392 | - && is_singular() |
|
393 | - ) { |
|
394 | - \EEH_Schema::add_json_linked_data_for_event($post->EE_Event); |
|
395 | - } |
|
396 | - } |
|
397 | - |
|
398 | - |
|
399 | - |
|
400 | - |
|
401 | - /*********************************************** THE_CONTENT FILTER HOOK ********************************************** |
|
29 | + /** |
|
30 | + * @var string $_template_path |
|
31 | + */ |
|
32 | + private $_template_path; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var string $_template |
|
36 | + */ |
|
37 | + private $_template; |
|
38 | + |
|
39 | + /** |
|
40 | + * @type EE_Registry $Registry |
|
41 | + */ |
|
42 | + protected $Registry; |
|
43 | + |
|
44 | + /** |
|
45 | + * @type EE_Request_Handler $Request_Handler |
|
46 | + */ |
|
47 | + protected $Request_Handler; |
|
48 | + |
|
49 | + /** |
|
50 | + * @type EE_Module_Request_Router $Module_Request_Router |
|
51 | + */ |
|
52 | + protected $Module_Request_Router; |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * class constructor |
|
57 | + * should fire after shortcode, module, addon, or other plugin's default priority init phases have run |
|
58 | + * |
|
59 | + * @access public |
|
60 | + * @param \EE_Registry $Registry |
|
61 | + * @param \EE_Request_Handler $Request_Handler |
|
62 | + * @param \EE_Module_Request_Router $Module_Request_Router |
|
63 | + */ |
|
64 | + public function __construct( |
|
65 | + EE_Registry $Registry, |
|
66 | + EE_Request_Handler $Request_Handler, |
|
67 | + EE_Module_Request_Router $Module_Request_Router |
|
68 | + ) { |
|
69 | + $this->Registry = $Registry; |
|
70 | + $this->Request_Handler = $Request_Handler; |
|
71 | + $this->Module_Request_Router = $Module_Request_Router; |
|
72 | + // determine how to integrate WP_Query with the EE models |
|
73 | + add_action('AHEE__EE_System__initialize', array($this, 'employ_CPT_Strategy')); |
|
74 | + // load other resources and begin to actually run shortcodes and modules |
|
75 | + add_action('wp_loaded', array($this, 'wp_loaded'), 5); |
|
76 | + // analyse the incoming WP request |
|
77 | + add_action('parse_request', array($this, 'get_request'), 1, 1); |
|
78 | + // process request with module factory |
|
79 | + add_action('pre_get_posts', array($this, 'pre_get_posts'), 10, 1); |
|
80 | + // before headers sent |
|
81 | + add_action('wp', array($this, 'wp'), 5); |
|
82 | + // after headers sent but before any markup is output, |
|
83 | + // primarily used to process any content shortcodes |
|
84 | + add_action('wp_head', array($this, 'wpHead'), 0); |
|
85 | + // header |
|
86 | + add_action('wp_head', array($this, 'header_meta_tag'), 5); |
|
87 | + add_action('wp_print_scripts', array($this, 'wp_print_scripts'), 10); |
|
88 | + add_filter('template_include', array($this, 'template_include'), 1); |
|
89 | + // display errors |
|
90 | + add_action('loop_start', array($this, 'display_errors'), 2); |
|
91 | + // the content |
|
92 | + // add_filter( 'the_content', array( $this, 'the_content' ), 5, 1 ); |
|
93 | + //exclude our private cpt comments |
|
94 | + add_filter('comments_clauses', array($this, 'filter_wp_comments'), 10, 1); |
|
95 | + //make sure any ajax requests will respect the url schema when requests are made against admin-ajax.php (http:// or https://) |
|
96 | + add_filter('admin_url', array($this, 'maybe_force_admin_ajax_ssl'), 200, 1); |
|
97 | + // action hook EE |
|
98 | + do_action('AHEE__EE_Front_Controller__construct__done', $this); |
|
99 | + // for checking that browser cookies are enabled |
|
100 | + if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
|
101 | + setcookie('ee_cookie_test', uniqid('ect',true), time() + DAY_IN_SECONDS, '/'); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @return EE_Request_Handler |
|
108 | + */ |
|
109 | + public function Request_Handler() |
|
110 | + { |
|
111 | + return $this->Request_Handler; |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @return EE_Module_Request_Router |
|
117 | + */ |
|
118 | + public function Module_Request_Router() |
|
119 | + { |
|
120 | + return $this->Module_Request_Router; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @return LegacyShortcodesManager |
|
127 | + */ |
|
128 | + public function getLegacyShortcodesManager() |
|
129 | + { |
|
130 | + return EE_Config::getLegacyShortcodesManager(); |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + |
|
135 | + |
|
136 | + |
|
137 | + /*********************************************** INIT ACTION HOOK ***********************************************/ |
|
138 | + |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * filter_wp_comments |
|
143 | + * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
|
144 | + * widgets/queries done on frontend |
|
145 | + * |
|
146 | + * @param array $clauses array of comment clauses setup by WP_Comment_Query |
|
147 | + * @return array array of comment clauses with modifications. |
|
148 | + */ |
|
149 | + public function filter_wp_comments($clauses) |
|
150 | + { |
|
151 | + global $wpdb; |
|
152 | + if (strpos($clauses['join'], $wpdb->posts) !== false) { |
|
153 | + $cpts = EE_Register_CPTs::get_private_CPTs(); |
|
154 | + foreach ($cpts as $cpt => $details) { |
|
155 | + $clauses['where'] .= $wpdb->prepare(" AND $wpdb->posts.post_type != %s", $cpt); |
|
156 | + } |
|
157 | + } |
|
158 | + return $clauses; |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * employ_CPT_Strategy |
|
164 | + * |
|
165 | + * @access public |
|
166 | + * @return void |
|
167 | + */ |
|
168 | + public function employ_CPT_Strategy() |
|
169 | + { |
|
170 | + if (apply_filters('FHEE__EE_Front_Controller__employ_CPT_Strategy', true)) { |
|
171 | + $this->Registry->load_core('CPT_Strategy'); |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
|
178 | + * |
|
179 | + * @param string $url incoming url |
|
180 | + * @return string final assembled url |
|
181 | + */ |
|
182 | + public function maybe_force_admin_ajax_ssl($url) |
|
183 | + { |
|
184 | + if (is_ssl() && preg_match('/admin-ajax.php/', $url)) { |
|
185 | + $url = str_replace('http://', 'https://', $url); |
|
186 | + } |
|
187 | + return $url; |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + |
|
192 | + |
|
193 | + |
|
194 | + |
|
195 | + /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
|
200 | + * default priority init phases have run |
|
201 | + * |
|
202 | + * @access public |
|
203 | + * @return void |
|
204 | + */ |
|
205 | + public function wp_loaded() |
|
206 | + { |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + |
|
211 | + |
|
212 | + |
|
213 | + /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
|
214 | + /** |
|
215 | + * _get_request |
|
216 | + * |
|
217 | + * @access public |
|
218 | + * @param WP $WP |
|
219 | + * @return void |
|
220 | + */ |
|
221 | + public function get_request(WP $WP) |
|
222 | + { |
|
223 | + do_action('AHEE__EE_Front_Controller__get_request__start'); |
|
224 | + $this->Request_Handler->parse_request($WP); |
|
225 | + do_action('AHEE__EE_Front_Controller__get_request__complete'); |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
|
232 | + * |
|
233 | + * @access public |
|
234 | + * @param WP_Query $WP_Query |
|
235 | + * @return void |
|
236 | + */ |
|
237 | + public function pre_get_posts($WP_Query) |
|
238 | + { |
|
239 | + // only load Module_Request_Router if this is the main query |
|
240 | + if ( |
|
241 | + $this->Module_Request_Router instanceof EE_Module_Request_Router |
|
242 | + && $WP_Query->is_main_query() |
|
243 | + ) { |
|
244 | + // cycle thru module routes |
|
245 | + while ($route = $this->Module_Request_Router->get_route($WP_Query)) { |
|
246 | + // determine module and method for route |
|
247 | + $module = $this->Module_Request_Router->resolve_route($route[0], $route[1]); |
|
248 | + if ($module instanceof EED_Module) { |
|
249 | + // get registered view for route |
|
250 | + $this->_template_path = $this->Module_Request_Router->get_view($route); |
|
251 | + // grab module name |
|
252 | + $module_name = $module->module_name(); |
|
253 | + // map the module to the module objects |
|
254 | + $this->Registry->modules->{$module_name} = $module; |
|
255 | + } |
|
256 | + } |
|
257 | + } |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + |
|
262 | + |
|
263 | + |
|
264 | + /*********************************************** WP HOOK ***********************************************/ |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * wp - basically last chance to do stuff before headers sent |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @return void |
|
272 | + */ |
|
273 | + public function wp() |
|
274 | + { |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + |
|
279 | + /*********************** GET_HEADER && WP_HEAD HOOK ***********************/ |
|
280 | + |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * callback for the "wp_head" hook point |
|
285 | + * checks sidebars for EE widgets |
|
286 | + * loads resources and assets accordingly |
|
287 | + * |
|
288 | + * @return void |
|
289 | + */ |
|
290 | + public function wpHead() |
|
291 | + { |
|
292 | + global $wp_query; |
|
293 | + if (empty($wp_query->posts)){ |
|
294 | + return; |
|
295 | + } |
|
296 | + // if we already know this is an espresso page, then load assets |
|
297 | + $load_assets = $this->Request_Handler->is_espresso_page(); |
|
298 | + // if we are already loading assets then just move along, otherwise check for widgets |
|
299 | + $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
|
300 | + if ( $load_assets){ |
|
301 | + wp_enqueue_style('espresso_default'); |
|
302 | + wp_enqueue_style('espresso_custom_css'); |
|
303 | + wp_enqueue_script('espresso_core'); |
|
304 | + } |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + |
|
309 | + /** |
|
310 | + * builds list of active widgets then scans active sidebars looking for them |
|
311 | + * returns true is an EE widget is found in an active sidebar |
|
312 | + * Please Note: this does NOT mean that the sidebar or widget |
|
313 | + * is actually in use in a given template, as that is unfortunately not known |
|
314 | + * until a sidebar and it's widgets are actually loaded |
|
315 | + * |
|
316 | + * @return boolean |
|
317 | + */ |
|
318 | + private function espresso_widgets_in_active_sidebars() |
|
319 | + { |
|
320 | + $espresso_widgets = array(); |
|
321 | + foreach ($this->Registry->widgets as $widget_class => $widget) { |
|
322 | + $id_base = EspressoWidget::getIdBase($widget_class); |
|
323 | + if (is_active_widget(false, false, $id_base)) { |
|
324 | + $espresso_widgets[] = $id_base; |
|
325 | + } |
|
326 | + } |
|
327 | + $all_sidebar_widgets = wp_get_sidebars_widgets(); |
|
328 | + foreach ($all_sidebar_widgets as $sidebar_name => $sidebar_widgets) { |
|
329 | + if (is_array($sidebar_widgets) && ! empty($sidebar_widgets)) { |
|
330 | + foreach ($sidebar_widgets as $sidebar_widget) { |
|
331 | + foreach ($espresso_widgets as $espresso_widget) { |
|
332 | + if (strpos($sidebar_widget, $espresso_widget) !== false) { |
|
333 | + return true; |
|
334 | + } |
|
335 | + } |
|
336 | + } |
|
337 | + } |
|
338 | + } |
|
339 | + return false; |
|
340 | + } |
|
341 | + |
|
342 | + |
|
343 | + |
|
344 | + |
|
345 | + /** |
|
346 | + * header_meta_tag |
|
347 | + * |
|
348 | + * @access public |
|
349 | + * @return void |
|
350 | + */ |
|
351 | + public function header_meta_tag() |
|
352 | + { |
|
353 | + print( |
|
354 | + apply_filters( |
|
355 | + 'FHEE__EE_Front_Controller__header_meta_tag', |
|
356 | + '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
357 | + ); |
|
358 | + |
|
359 | + //let's exclude all event type taxonomy term archive pages from search engine indexing |
|
360 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/10249 |
|
361 | + //also exclude all critical pages from indexing |
|
362 | + if ( |
|
363 | + ( |
|
364 | + is_tax('espresso_event_type') |
|
365 | + && get_option( 'blog_public' ) !== '0' |
|
366 | + ) |
|
367 | + || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
|
368 | + ) { |
|
369 | + print( |
|
370 | + apply_filters( |
|
371 | + 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
|
372 | + '<meta name="robots" content="noindex,follow" />' . "\n" |
|
373 | + ) |
|
374 | + ); |
|
375 | + } |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * wp_print_scripts |
|
382 | + * |
|
383 | + * @return void |
|
384 | + */ |
|
385 | + public function wp_print_scripts() |
|
386 | + { |
|
387 | + global $post; |
|
388 | + if ( |
|
389 | + isset($post->EE_Event) |
|
390 | + && $post->EE_Event instanceof EE_Event |
|
391 | + && get_post_type() === 'espresso_events' |
|
392 | + && is_singular() |
|
393 | + ) { |
|
394 | + \EEH_Schema::add_json_linked_data_for_event($post->EE_Event); |
|
395 | + } |
|
396 | + } |
|
397 | + |
|
398 | + |
|
399 | + |
|
400 | + |
|
401 | + /*********************************************** THE_CONTENT FILTER HOOK ********************************************** |
|
402 | 402 | |
403 | 403 | |
404 | 404 | |
@@ -409,99 +409,99 @@ discard block |
||
409 | 409 | // * @param $the_content |
410 | 410 | // * @return string |
411 | 411 | // */ |
412 | - // public function the_content( $the_content ) { |
|
413 | - // // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
|
414 | - // if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
|
415 | - // } |
|
416 | - // return $the_content; |
|
417 | - // } |
|
418 | - |
|
419 | - |
|
420 | - |
|
421 | - /*********************************************** WP_FOOTER ***********************************************/ |
|
422 | - |
|
423 | - |
|
424 | - /** |
|
425 | - * display_errors |
|
426 | - * |
|
427 | - * @access public |
|
428 | - * @return void |
|
429 | - */ |
|
430 | - public function display_errors() |
|
431 | - { |
|
432 | - static $shown_already = false; |
|
433 | - do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
434 | - if ( |
|
435 | - ! $shown_already |
|
436 | - && apply_filters('FHEE__EE_Front_Controller__display_errors', true) |
|
437 | - && is_main_query() |
|
438 | - && ! is_feed() |
|
439 | - && in_the_loop() |
|
440 | - && $this->Request_Handler->is_espresso_page() |
|
441 | - ) { |
|
442 | - echo EE_Error::get_notices(); |
|
443 | - $shown_already = true; |
|
444 | - EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
445 | - } |
|
446 | - do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - |
|
451 | - |
|
452 | - |
|
453 | - /*********************************************** UTILITIES ***********************************************/ |
|
454 | - /** |
|
455 | - * template_include |
|
456 | - * |
|
457 | - * @access public |
|
458 | - * @param string $template_include_path |
|
459 | - * @return string |
|
460 | - */ |
|
461 | - public function template_include($template_include_path = null) |
|
462 | - { |
|
463 | - if ($this->Request_Handler->is_espresso_page()) { |
|
464 | - $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path); |
|
465 | - $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
466 | - $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
467 | - $this->_template = basename($this->_template_path); |
|
468 | - return $this->_template_path; |
|
469 | - } |
|
470 | - return $template_include_path; |
|
471 | - } |
|
472 | - |
|
473 | - |
|
474 | - /** |
|
475 | - * get_selected_template |
|
476 | - * |
|
477 | - * @access public |
|
478 | - * @param bool $with_path |
|
479 | - * @return string |
|
480 | - */ |
|
481 | - public function get_selected_template($with_path = false) |
|
482 | - { |
|
483 | - return $with_path ? $this->_template_path : $this->_template; |
|
484 | - } |
|
485 | - |
|
486 | - |
|
487 | - |
|
488 | - /** |
|
489 | - * @deprecated 4.9.26 |
|
490 | - * @param string $shortcode_class |
|
491 | - * @param \WP $wp |
|
492 | - */ |
|
493 | - public function initialize_shortcode($shortcode_class = '', WP $wp = null) |
|
494 | - { |
|
495 | - \EE_Error::doing_it_wrong( |
|
496 | - __METHOD__, |
|
497 | - __( |
|
498 | - 'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.', |
|
499 | - 'event_espresso' |
|
500 | - ), |
|
501 | - '4.9.26' |
|
502 | - ); |
|
503 | - $this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp); |
|
504 | - } |
|
412 | + // public function the_content( $the_content ) { |
|
413 | + // // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
|
414 | + // if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
|
415 | + // } |
|
416 | + // return $the_content; |
|
417 | + // } |
|
418 | + |
|
419 | + |
|
420 | + |
|
421 | + /*********************************************** WP_FOOTER ***********************************************/ |
|
422 | + |
|
423 | + |
|
424 | + /** |
|
425 | + * display_errors |
|
426 | + * |
|
427 | + * @access public |
|
428 | + * @return void |
|
429 | + */ |
|
430 | + public function display_errors() |
|
431 | + { |
|
432 | + static $shown_already = false; |
|
433 | + do_action('AHEE__EE_Front_Controller__display_errors__begin'); |
|
434 | + if ( |
|
435 | + ! $shown_already |
|
436 | + && apply_filters('FHEE__EE_Front_Controller__display_errors', true) |
|
437 | + && is_main_query() |
|
438 | + && ! is_feed() |
|
439 | + && in_the_loop() |
|
440 | + && $this->Request_Handler->is_espresso_page() |
|
441 | + ) { |
|
442 | + echo EE_Error::get_notices(); |
|
443 | + $shown_already = true; |
|
444 | + EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
445 | + } |
|
446 | + do_action('AHEE__EE_Front_Controller__display_errors__end'); |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + |
|
451 | + |
|
452 | + |
|
453 | + /*********************************************** UTILITIES ***********************************************/ |
|
454 | + /** |
|
455 | + * template_include |
|
456 | + * |
|
457 | + * @access public |
|
458 | + * @param string $template_include_path |
|
459 | + * @return string |
|
460 | + */ |
|
461 | + public function template_include($template_include_path = null) |
|
462 | + { |
|
463 | + if ($this->Request_Handler->is_espresso_page()) { |
|
464 | + $this->_template_path = ! empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path); |
|
465 | + $template_path = EEH_Template::locate_template($this->_template_path, array(), false); |
|
466 | + $this->_template_path = ! empty($template_path) ? $template_path : $template_include_path; |
|
467 | + $this->_template = basename($this->_template_path); |
|
468 | + return $this->_template_path; |
|
469 | + } |
|
470 | + return $template_include_path; |
|
471 | + } |
|
472 | + |
|
473 | + |
|
474 | + /** |
|
475 | + * get_selected_template |
|
476 | + * |
|
477 | + * @access public |
|
478 | + * @param bool $with_path |
|
479 | + * @return string |
|
480 | + */ |
|
481 | + public function get_selected_template($with_path = false) |
|
482 | + { |
|
483 | + return $with_path ? $this->_template_path : $this->_template; |
|
484 | + } |
|
485 | + |
|
486 | + |
|
487 | + |
|
488 | + /** |
|
489 | + * @deprecated 4.9.26 |
|
490 | + * @param string $shortcode_class |
|
491 | + * @param \WP $wp |
|
492 | + */ |
|
493 | + public function initialize_shortcode($shortcode_class = '', WP $wp = null) |
|
494 | + { |
|
495 | + \EE_Error::doing_it_wrong( |
|
496 | + __METHOD__, |
|
497 | + __( |
|
498 | + 'Usage is deprecated. Please use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::initializeShortcode() instead.', |
|
499 | + 'event_espresso' |
|
500 | + ), |
|
501 | + '4.9.26' |
|
502 | + ); |
|
503 | + $this->getLegacyShortcodesManager()->initializeShortcode($shortcode_class, $wp); |
|
504 | + } |
|
505 | 505 | |
506 | 506 | } |
507 | 507 | // End of file EE_Front_Controller.core.php |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | do_action('AHEE__EE_Front_Controller__construct__done', $this); |
99 | 99 | // for checking that browser cookies are enabled |
100 | 100 | if (apply_filters('FHEE__EE_Front_Controller____construct__set_test_cookie', true)) { |
101 | - setcookie('ee_cookie_test', uniqid('ect',true), time() + DAY_IN_SECONDS, '/'); |
|
101 | + setcookie('ee_cookie_test', uniqid('ect', true), time() + DAY_IN_SECONDS, '/'); |
|
102 | 102 | } |
103 | 103 | } |
104 | 104 | |
@@ -290,14 +290,14 @@ discard block |
||
290 | 290 | public function wpHead() |
291 | 291 | { |
292 | 292 | global $wp_query; |
293 | - if (empty($wp_query->posts)){ |
|
293 | + if (empty($wp_query->posts)) { |
|
294 | 294 | return; |
295 | 295 | } |
296 | 296 | // if we already know this is an espresso page, then load assets |
297 | 297 | $load_assets = $this->Request_Handler->is_espresso_page(); |
298 | 298 | // if we are already loading assets then just move along, otherwise check for widgets |
299 | 299 | $load_assets = $load_assets ? $load_assets : $this->espresso_widgets_in_active_sidebars(); |
300 | - if ( $load_assets){ |
|
300 | + if ($load_assets) { |
|
301 | 301 | wp_enqueue_style('espresso_default'); |
302 | 302 | wp_enqueue_style('espresso_custom_css'); |
303 | 303 | wp_enqueue_script('espresso_core'); |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | print( |
354 | 354 | apply_filters( |
355 | 355 | 'FHEE__EE_Front_Controller__header_meta_tag', |
356 | - '<meta name="generator" content="Event Espresso Version ' . EVENT_ESPRESSO_VERSION . "\" />\n") |
|
356 | + '<meta name="generator" content="Event Espresso Version '.EVENT_ESPRESSO_VERSION."\" />\n") |
|
357 | 357 | ); |
358 | 358 | |
359 | 359 | //let's exclude all event type taxonomy term archive pages from search engine indexing |
@@ -362,14 +362,14 @@ discard block |
||
362 | 362 | if ( |
363 | 363 | ( |
364 | 364 | is_tax('espresso_event_type') |
365 | - && get_option( 'blog_public' ) !== '0' |
|
365 | + && get_option('blog_public') !== '0' |
|
366 | 366 | ) |
367 | 367 | || is_page(EE_Registry::instance()->CFG->core->get_critical_pages_array()) |
368 | 368 | ) { |
369 | 369 | print( |
370 | 370 | apply_filters( |
371 | 371 | 'FHEE__EE_Front_Controller__header_meta_tag__noindex_for_event_type', |
372 | - '<meta name="robots" content="noindex,follow" />' . "\n" |
|
372 | + '<meta name="robots" content="noindex,follow" />'."\n" |
|
373 | 373 | ) |
374 | 374 | ); |
375 | 375 | } |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | ) { |
442 | 442 | echo EE_Error::get_notices(); |
443 | 443 | $shown_already = true; |
444 | - EEH_Template::display_template(EE_TEMPLATES . 'espresso-ajax-notices.template.php'); |
|
444 | + EEH_Template::display_template(EE_TEMPLATES.'espresso-ajax-notices.template.php'); |
|
445 | 445 | } |
446 | 446 | do_action('AHEE__EE_Front_Controller__display_errors__end'); |
447 | 447 | } |