@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | * @access public |
261 | 261 | * @param EE_Ticket $ticket |
262 | 262 | * @param int $qty |
263 | - * @return TRUE on success, FALSE on fail |
|
263 | + * @return boolean on success, FALSE on fail |
|
264 | 264 | * @throws \EE_Error |
265 | 265 | */ |
266 | 266 | public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1) |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | * @save cart to session |
386 | 386 | * @access public |
387 | 387 | * @param bool $apply_taxes |
388 | - * @return TRUE on success, FALSE on fail |
|
388 | + * @return boolean on success, FALSE on fail |
|
389 | 389 | * @throws \EE_Error |
390 | 390 | */ |
391 | 391 | public function save_cart($apply_taxes = true) |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | |
420 | 420 | |
421 | 421 | /** |
422 | - * @return array |
|
422 | + * @return string[] |
|
423 | 423 | */ |
424 | 424 | public function __sleep() |
425 | 425 | { |
@@ -17,396 +17,396 @@ |
||
17 | 17 | class EE_Cart implements ResettableInterface |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * instance of the EE_Cart object |
|
22 | - * |
|
23 | - * @access private |
|
24 | - * @var EE_Cart $_instance |
|
25 | - */ |
|
26 | - private static $_instance; |
|
27 | - |
|
28 | - /** |
|
29 | - * instance of the EE_Session object |
|
30 | - * |
|
31 | - * @access protected |
|
32 | - * @var EE_Session $_session |
|
33 | - */ |
|
34 | - protected $_session; |
|
35 | - |
|
36 | - /** |
|
37 | - * The total Line item which comprises all the children line-item subtotals, |
|
38 | - * which in turn each have their line items. |
|
39 | - * Typically, the line item structure will look like: |
|
40 | - * grand total |
|
41 | - * -tickets-sub-total |
|
42 | - * --ticket1 |
|
43 | - * --ticket2 |
|
44 | - * --... |
|
45 | - * -taxes-sub-total |
|
46 | - * --tax1 |
|
47 | - * --tax2 |
|
48 | - * |
|
49 | - * @var EE_Line_Item |
|
50 | - */ |
|
51 | - private $_grand_total; |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * @singleton method used to instantiate class object |
|
56 | - * @access public |
|
57 | - * @param EE_Line_Item $grand_total |
|
58 | - * @param EE_Session $session |
|
59 | - * @return \EE_Cart |
|
60 | - * @throws \EE_Error |
|
61 | - */ |
|
62 | - public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
63 | - { |
|
64 | - if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) { |
|
65 | - self::$_instance = new self($grand_total, $session); |
|
66 | - } |
|
67 | - // or maybe retrieve an existing one ? |
|
68 | - if (! self::$_instance instanceof EE_Cart) { |
|
69 | - // try getting the cart out of the session |
|
70 | - $saved_cart = $session instanceof EE_Session ? $session->cart() : null; |
|
71 | - self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session); |
|
72 | - unset($saved_cart); |
|
73 | - } |
|
74 | - // verify that cart is ok and grand total line item exists |
|
75 | - if (! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) { |
|
76 | - self::$_instance = new self($grand_total, $session); |
|
77 | - } |
|
78 | - self::$_instance->get_grand_total(); |
|
79 | - // once everything is all said and done, save the cart to the EE_Session |
|
80 | - add_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
81 | - return self::$_instance; |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * private constructor to prevent direct creation |
|
87 | - * |
|
88 | - * @Constructor |
|
89 | - * @access private |
|
90 | - * @param EE_Line_Item $grand_total |
|
91 | - * @param EE_Session $session |
|
92 | - */ |
|
93 | - private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
94 | - { |
|
95 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
96 | - $this->set_session($session); |
|
97 | - if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) { |
|
98 | - $this->set_grand_total_line_item($grand_total); |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * Resets the cart completely (whereas empty_cart |
|
105 | - * |
|
106 | - * @param EE_Line_Item $grand_total |
|
107 | - * @param EE_Session $session |
|
108 | - * @return EE_Cart |
|
109 | - * @throws \EE_Error |
|
110 | - */ |
|
111 | - public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
112 | - { |
|
113 | - remove_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
114 | - if ($session instanceof EE_Session) { |
|
115 | - $session->reset_cart(); |
|
116 | - } |
|
117 | - self::$_instance = null; |
|
118 | - return self::instance($grand_total, $session); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @return \EE_Session |
|
124 | - */ |
|
125 | - public function session() |
|
126 | - { |
|
127 | - if (! $this->_session instanceof EE_Session) { |
|
128 | - $this->set_session(); |
|
129 | - } |
|
130 | - return $this->_session; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * @param EE_Session $session |
|
136 | - */ |
|
137 | - public function set_session(EE_Session $session = null) |
|
138 | - { |
|
139 | - $this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session'); |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * Sets the cart to match the line item. Especially handy for loading an old cart where you |
|
145 | - * know the grand total line item on it |
|
146 | - * |
|
147 | - * @param EE_Line_Item $line_item |
|
148 | - */ |
|
149 | - public function set_grand_total_line_item(EE_Line_Item $line_item) |
|
150 | - { |
|
151 | - $this->_grand_total = $line_item; |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * get_cart_from_reg_url_link |
|
157 | - * |
|
158 | - * @access public |
|
159 | - * @param EE_Transaction $transaction |
|
160 | - * @param EE_Session $session |
|
161 | - * @return \EE_Cart |
|
162 | - * @throws \EE_Error |
|
163 | - */ |
|
164 | - public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null) |
|
165 | - { |
|
166 | - $grand_total = $transaction->total_line_item(); |
|
167 | - $grand_total->get_items(); |
|
168 | - $grand_total->tax_descendants(); |
|
169 | - return EE_Cart::instance($grand_total, $session); |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items |
|
175 | - * |
|
176 | - * @return EE_Line_Item |
|
177 | - * @throws \EE_Error |
|
178 | - */ |
|
179 | - private function _create_grand_total() |
|
180 | - { |
|
181 | - $this->_grand_total = EEH_Line_Item::create_total_line_item(); |
|
182 | - return $this->_grand_total; |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * Gets all the line items of object type Ticket |
|
188 | - * |
|
189 | - * @access public |
|
190 | - * @return \EE_Line_Item[] |
|
191 | - */ |
|
192 | - public function get_tickets() |
|
193 | - { |
|
194 | - if ($this->_grand_total === null) { |
|
195 | - return array(); |
|
196 | - } |
|
197 | - return EEH_Line_Item::get_ticket_line_items($this->_grand_total); |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * returns the total quantity of tickets in the cart |
|
203 | - * |
|
204 | - * @access public |
|
205 | - * @return int |
|
206 | - * @throws \EE_Error |
|
207 | - */ |
|
208 | - public function all_ticket_quantity_count() |
|
209 | - { |
|
210 | - $tickets = $this->get_tickets(); |
|
211 | - if (empty($tickets)) { |
|
212 | - return 0; |
|
213 | - } |
|
214 | - $count = 0; |
|
215 | - foreach ($tickets as $ticket) { |
|
216 | - $count += $ticket->get('LIN_quantity'); |
|
217 | - } |
|
218 | - return $count; |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * Gets all the tax line items |
|
224 | - * |
|
225 | - * @return \EE_Line_Item[] |
|
226 | - * @throws \EE_Error |
|
227 | - */ |
|
228 | - public function get_taxes() |
|
229 | - { |
|
230 | - return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children(); |
|
231 | - } |
|
232 | - |
|
233 | - |
|
234 | - /** |
|
235 | - * Gets the total line item (which is a parent of all other line items) on this cart |
|
236 | - * |
|
237 | - * @return EE_Line_Item |
|
238 | - * @throws \EE_Error |
|
239 | - */ |
|
240 | - public function get_grand_total() |
|
241 | - { |
|
242 | - return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total(); |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * @process items for adding to cart |
|
248 | - * @access public |
|
249 | - * @param EE_Ticket $ticket |
|
250 | - * @param int $qty |
|
251 | - * @return TRUE on success, FALSE on fail |
|
252 | - * @throws \EE_Error |
|
253 | - */ |
|
254 | - public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1) |
|
255 | - { |
|
256 | - EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty); |
|
257 | - return $this->save_cart() ? true : false; |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - /** |
|
262 | - * get_cart_total_before_tax |
|
263 | - * |
|
264 | - * @access public |
|
265 | - * @return float |
|
266 | - * @throws \EE_Error |
|
267 | - */ |
|
268 | - public function get_cart_total_before_tax() |
|
269 | - { |
|
270 | - return $this->get_grand_total()->recalculate_pre_tax_total(); |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * gets the total amount of tax paid for items in this cart |
|
276 | - * |
|
277 | - * @access public |
|
278 | - * @return float |
|
279 | - * @throws \EE_Error |
|
280 | - */ |
|
281 | - public function get_applied_taxes() |
|
282 | - { |
|
283 | - return EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
289 | - * |
|
290 | - * @access public |
|
291 | - * @return float |
|
292 | - * @throws \EE_Error |
|
293 | - */ |
|
294 | - public function get_cart_grand_total() |
|
295 | - { |
|
296 | - EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
297 | - return $this->get_grand_total()->total(); |
|
298 | - } |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
303 | - * |
|
304 | - * @access public |
|
305 | - * @return float |
|
306 | - * @throws \EE_Error |
|
307 | - */ |
|
308 | - public function recalculate_all_cart_totals() |
|
309 | - { |
|
310 | - $pre_tax_total = $this->get_cart_total_before_tax(); |
|
311 | - $taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
312 | - $this->_grand_total->set_total($pre_tax_total + $taxes_total); |
|
313 | - $this->_grand_total->save_this_and_descendants_to_txn(); |
|
314 | - return $this->get_grand_total()->total(); |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * deletes an item from the cart |
|
320 | - * |
|
321 | - * @access public |
|
322 | - * @param array|bool|string $line_item_codes |
|
323 | - * @return int on success, FALSE on fail |
|
324 | - * @throws \EE_Error |
|
325 | - */ |
|
326 | - public function delete_items($line_item_codes = false) |
|
327 | - { |
|
328 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
329 | - return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes); |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - /** |
|
334 | - * @remove ALL items from cart and zero ALL totals |
|
335 | - * @access public |
|
336 | - * @return bool |
|
337 | - * @throws \EE_Error |
|
338 | - */ |
|
339 | - public function empty_cart() |
|
340 | - { |
|
341 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
342 | - $this->_grand_total = $this->_create_grand_total(); |
|
343 | - return $this->save_cart(true); |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * @remove ALL items from cart and delete total as well |
|
349 | - * @access public |
|
350 | - * @return bool |
|
351 | - * @throws \EE_Error |
|
352 | - */ |
|
353 | - public function delete_cart() |
|
354 | - { |
|
355 | - if ($this->_grand_total instanceof EE_Line_Item) { |
|
356 | - $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total); |
|
357 | - if ($deleted) { |
|
358 | - $deleted += $this->_grand_total->delete(); |
|
359 | - $this->_grand_total = null; |
|
360 | - return true; |
|
361 | - } |
|
362 | - } |
|
363 | - return false; |
|
364 | - } |
|
365 | - |
|
366 | - |
|
367 | - /** |
|
368 | - * @save cart to session |
|
369 | - * @access public |
|
370 | - * @param bool $apply_taxes |
|
371 | - * @return TRUE on success, FALSE on fail |
|
372 | - * @throws \EE_Error |
|
373 | - */ |
|
374 | - public function save_cart($apply_taxes = true) |
|
375 | - { |
|
376 | - if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) { |
|
377 | - EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
378 | - // make sure we don't cache the transaction because it can get stale |
|
379 | - if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction |
|
380 | - && $this->_grand_total->get_one_from_cache('Transaction')->ID() |
|
381 | - ) { |
|
382 | - $this->_grand_total->clear_cache('Transaction', null, true); |
|
383 | - } |
|
384 | - } |
|
385 | - if ($this->session() instanceof EE_Session) { |
|
386 | - return $this->session()->set_cart($this); |
|
387 | - } else { |
|
388 | - return false; |
|
389 | - } |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - public function __wakeup() |
|
394 | - { |
|
395 | - if (! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) { |
|
396 | - // $this->_grand_total is actually just an ID, so use it to get the object from the db |
|
397 | - $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total); |
|
398 | - } |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - /** |
|
403 | - * @return array |
|
404 | - */ |
|
405 | - public function __sleep() |
|
406 | - { |
|
407 | - if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) { |
|
408 | - $this->_grand_total = $this->_grand_total->ID(); |
|
409 | - } |
|
410 | - return array('_grand_total'); |
|
411 | - } |
|
20 | + /** |
|
21 | + * instance of the EE_Cart object |
|
22 | + * |
|
23 | + * @access private |
|
24 | + * @var EE_Cart $_instance |
|
25 | + */ |
|
26 | + private static $_instance; |
|
27 | + |
|
28 | + /** |
|
29 | + * instance of the EE_Session object |
|
30 | + * |
|
31 | + * @access protected |
|
32 | + * @var EE_Session $_session |
|
33 | + */ |
|
34 | + protected $_session; |
|
35 | + |
|
36 | + /** |
|
37 | + * The total Line item which comprises all the children line-item subtotals, |
|
38 | + * which in turn each have their line items. |
|
39 | + * Typically, the line item structure will look like: |
|
40 | + * grand total |
|
41 | + * -tickets-sub-total |
|
42 | + * --ticket1 |
|
43 | + * --ticket2 |
|
44 | + * --... |
|
45 | + * -taxes-sub-total |
|
46 | + * --tax1 |
|
47 | + * --tax2 |
|
48 | + * |
|
49 | + * @var EE_Line_Item |
|
50 | + */ |
|
51 | + private $_grand_total; |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * @singleton method used to instantiate class object |
|
56 | + * @access public |
|
57 | + * @param EE_Line_Item $grand_total |
|
58 | + * @param EE_Session $session |
|
59 | + * @return \EE_Cart |
|
60 | + * @throws \EE_Error |
|
61 | + */ |
|
62 | + public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
63 | + { |
|
64 | + if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) { |
|
65 | + self::$_instance = new self($grand_total, $session); |
|
66 | + } |
|
67 | + // or maybe retrieve an existing one ? |
|
68 | + if (! self::$_instance instanceof EE_Cart) { |
|
69 | + // try getting the cart out of the session |
|
70 | + $saved_cart = $session instanceof EE_Session ? $session->cart() : null; |
|
71 | + self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session); |
|
72 | + unset($saved_cart); |
|
73 | + } |
|
74 | + // verify that cart is ok and grand total line item exists |
|
75 | + if (! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) { |
|
76 | + self::$_instance = new self($grand_total, $session); |
|
77 | + } |
|
78 | + self::$_instance->get_grand_total(); |
|
79 | + // once everything is all said and done, save the cart to the EE_Session |
|
80 | + add_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
81 | + return self::$_instance; |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * private constructor to prevent direct creation |
|
87 | + * |
|
88 | + * @Constructor |
|
89 | + * @access private |
|
90 | + * @param EE_Line_Item $grand_total |
|
91 | + * @param EE_Session $session |
|
92 | + */ |
|
93 | + private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
94 | + { |
|
95 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
96 | + $this->set_session($session); |
|
97 | + if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) { |
|
98 | + $this->set_grand_total_line_item($grand_total); |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * Resets the cart completely (whereas empty_cart |
|
105 | + * |
|
106 | + * @param EE_Line_Item $grand_total |
|
107 | + * @param EE_Session $session |
|
108 | + * @return EE_Cart |
|
109 | + * @throws \EE_Error |
|
110 | + */ |
|
111 | + public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
112 | + { |
|
113 | + remove_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
114 | + if ($session instanceof EE_Session) { |
|
115 | + $session->reset_cart(); |
|
116 | + } |
|
117 | + self::$_instance = null; |
|
118 | + return self::instance($grand_total, $session); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @return \EE_Session |
|
124 | + */ |
|
125 | + public function session() |
|
126 | + { |
|
127 | + if (! $this->_session instanceof EE_Session) { |
|
128 | + $this->set_session(); |
|
129 | + } |
|
130 | + return $this->_session; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * @param EE_Session $session |
|
136 | + */ |
|
137 | + public function set_session(EE_Session $session = null) |
|
138 | + { |
|
139 | + $this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session'); |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * Sets the cart to match the line item. Especially handy for loading an old cart where you |
|
145 | + * know the grand total line item on it |
|
146 | + * |
|
147 | + * @param EE_Line_Item $line_item |
|
148 | + */ |
|
149 | + public function set_grand_total_line_item(EE_Line_Item $line_item) |
|
150 | + { |
|
151 | + $this->_grand_total = $line_item; |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * get_cart_from_reg_url_link |
|
157 | + * |
|
158 | + * @access public |
|
159 | + * @param EE_Transaction $transaction |
|
160 | + * @param EE_Session $session |
|
161 | + * @return \EE_Cart |
|
162 | + * @throws \EE_Error |
|
163 | + */ |
|
164 | + public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null) |
|
165 | + { |
|
166 | + $grand_total = $transaction->total_line_item(); |
|
167 | + $grand_total->get_items(); |
|
168 | + $grand_total->tax_descendants(); |
|
169 | + return EE_Cart::instance($grand_total, $session); |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items |
|
175 | + * |
|
176 | + * @return EE_Line_Item |
|
177 | + * @throws \EE_Error |
|
178 | + */ |
|
179 | + private function _create_grand_total() |
|
180 | + { |
|
181 | + $this->_grand_total = EEH_Line_Item::create_total_line_item(); |
|
182 | + return $this->_grand_total; |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * Gets all the line items of object type Ticket |
|
188 | + * |
|
189 | + * @access public |
|
190 | + * @return \EE_Line_Item[] |
|
191 | + */ |
|
192 | + public function get_tickets() |
|
193 | + { |
|
194 | + if ($this->_grand_total === null) { |
|
195 | + return array(); |
|
196 | + } |
|
197 | + return EEH_Line_Item::get_ticket_line_items($this->_grand_total); |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * returns the total quantity of tickets in the cart |
|
203 | + * |
|
204 | + * @access public |
|
205 | + * @return int |
|
206 | + * @throws \EE_Error |
|
207 | + */ |
|
208 | + public function all_ticket_quantity_count() |
|
209 | + { |
|
210 | + $tickets = $this->get_tickets(); |
|
211 | + if (empty($tickets)) { |
|
212 | + return 0; |
|
213 | + } |
|
214 | + $count = 0; |
|
215 | + foreach ($tickets as $ticket) { |
|
216 | + $count += $ticket->get('LIN_quantity'); |
|
217 | + } |
|
218 | + return $count; |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * Gets all the tax line items |
|
224 | + * |
|
225 | + * @return \EE_Line_Item[] |
|
226 | + * @throws \EE_Error |
|
227 | + */ |
|
228 | + public function get_taxes() |
|
229 | + { |
|
230 | + return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children(); |
|
231 | + } |
|
232 | + |
|
233 | + |
|
234 | + /** |
|
235 | + * Gets the total line item (which is a parent of all other line items) on this cart |
|
236 | + * |
|
237 | + * @return EE_Line_Item |
|
238 | + * @throws \EE_Error |
|
239 | + */ |
|
240 | + public function get_grand_total() |
|
241 | + { |
|
242 | + return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total(); |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * @process items for adding to cart |
|
248 | + * @access public |
|
249 | + * @param EE_Ticket $ticket |
|
250 | + * @param int $qty |
|
251 | + * @return TRUE on success, FALSE on fail |
|
252 | + * @throws \EE_Error |
|
253 | + */ |
|
254 | + public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1) |
|
255 | + { |
|
256 | + EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty); |
|
257 | + return $this->save_cart() ? true : false; |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + /** |
|
262 | + * get_cart_total_before_tax |
|
263 | + * |
|
264 | + * @access public |
|
265 | + * @return float |
|
266 | + * @throws \EE_Error |
|
267 | + */ |
|
268 | + public function get_cart_total_before_tax() |
|
269 | + { |
|
270 | + return $this->get_grand_total()->recalculate_pre_tax_total(); |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * gets the total amount of tax paid for items in this cart |
|
276 | + * |
|
277 | + * @access public |
|
278 | + * @return float |
|
279 | + * @throws \EE_Error |
|
280 | + */ |
|
281 | + public function get_applied_taxes() |
|
282 | + { |
|
283 | + return EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
289 | + * |
|
290 | + * @access public |
|
291 | + * @return float |
|
292 | + * @throws \EE_Error |
|
293 | + */ |
|
294 | + public function get_cart_grand_total() |
|
295 | + { |
|
296 | + EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
297 | + return $this->get_grand_total()->total(); |
|
298 | + } |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
303 | + * |
|
304 | + * @access public |
|
305 | + * @return float |
|
306 | + * @throws \EE_Error |
|
307 | + */ |
|
308 | + public function recalculate_all_cart_totals() |
|
309 | + { |
|
310 | + $pre_tax_total = $this->get_cart_total_before_tax(); |
|
311 | + $taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
312 | + $this->_grand_total->set_total($pre_tax_total + $taxes_total); |
|
313 | + $this->_grand_total->save_this_and_descendants_to_txn(); |
|
314 | + return $this->get_grand_total()->total(); |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * deletes an item from the cart |
|
320 | + * |
|
321 | + * @access public |
|
322 | + * @param array|bool|string $line_item_codes |
|
323 | + * @return int on success, FALSE on fail |
|
324 | + * @throws \EE_Error |
|
325 | + */ |
|
326 | + public function delete_items($line_item_codes = false) |
|
327 | + { |
|
328 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
329 | + return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes); |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + /** |
|
334 | + * @remove ALL items from cart and zero ALL totals |
|
335 | + * @access public |
|
336 | + * @return bool |
|
337 | + * @throws \EE_Error |
|
338 | + */ |
|
339 | + public function empty_cart() |
|
340 | + { |
|
341 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
342 | + $this->_grand_total = $this->_create_grand_total(); |
|
343 | + return $this->save_cart(true); |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * @remove ALL items from cart and delete total as well |
|
349 | + * @access public |
|
350 | + * @return bool |
|
351 | + * @throws \EE_Error |
|
352 | + */ |
|
353 | + public function delete_cart() |
|
354 | + { |
|
355 | + if ($this->_grand_total instanceof EE_Line_Item) { |
|
356 | + $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total); |
|
357 | + if ($deleted) { |
|
358 | + $deleted += $this->_grand_total->delete(); |
|
359 | + $this->_grand_total = null; |
|
360 | + return true; |
|
361 | + } |
|
362 | + } |
|
363 | + return false; |
|
364 | + } |
|
365 | + |
|
366 | + |
|
367 | + /** |
|
368 | + * @save cart to session |
|
369 | + * @access public |
|
370 | + * @param bool $apply_taxes |
|
371 | + * @return TRUE on success, FALSE on fail |
|
372 | + * @throws \EE_Error |
|
373 | + */ |
|
374 | + public function save_cart($apply_taxes = true) |
|
375 | + { |
|
376 | + if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) { |
|
377 | + EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
378 | + // make sure we don't cache the transaction because it can get stale |
|
379 | + if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction |
|
380 | + && $this->_grand_total->get_one_from_cache('Transaction')->ID() |
|
381 | + ) { |
|
382 | + $this->_grand_total->clear_cache('Transaction', null, true); |
|
383 | + } |
|
384 | + } |
|
385 | + if ($this->session() instanceof EE_Session) { |
|
386 | + return $this->session()->set_cart($this); |
|
387 | + } else { |
|
388 | + return false; |
|
389 | + } |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + public function __wakeup() |
|
394 | + { |
|
395 | + if (! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) { |
|
396 | + // $this->_grand_total is actually just an ID, so use it to get the object from the db |
|
397 | + $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total); |
|
398 | + } |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + /** |
|
403 | + * @return array |
|
404 | + */ |
|
405 | + public function __sleep() |
|
406 | + { |
|
407 | + if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) { |
|
408 | + $this->_grand_total = $this->_grand_total->ID(); |
|
409 | + } |
|
410 | + return array('_grand_total'); |
|
411 | + } |
|
412 | 412 | } |
@@ -613,7 +613,7 @@ discard block |
||
613 | 613 | * |
614 | 614 | * @since 4.6.0 |
615 | 615 | * @global WPDB $wpdb |
616 | - * @return mixed null|int WP_user ID or NULL |
|
616 | + * @return integer|null null|int WP_user ID or NULL |
|
617 | 617 | */ |
618 | 618 | public static function get_default_creator_id() |
619 | 619 | { |
@@ -774,7 +774,7 @@ discard block |
||
774 | 774 | * @static |
775 | 775 | * @deprecated instead use TableManager::dropTable() |
776 | 776 | * @param string $table_name |
777 | - * @return bool | int |
|
777 | + * @return integer | int |
|
778 | 778 | */ |
779 | 779 | public static function delete_unused_db_table($table_name) |
780 | 780 | { |
@@ -791,7 +791,7 @@ discard block |
||
791 | 791 | * @deprecated instead use TableManager::dropIndex() |
792 | 792 | * @param string $table_name |
793 | 793 | * @param string $index_name |
794 | - * @return bool | int |
|
794 | + * @return integer | int |
|
795 | 795 | */ |
796 | 796 | public static function drop_index($table_name, $index_name) |
797 | 797 | { |
@@ -15,232 +15,232 @@ discard block |
||
15 | 15 | class EEH_Activation implements ResettableInterface |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * constant used to indicate a cron task is no longer in use |
|
20 | - */ |
|
21 | - const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
22 | - |
|
23 | - /** |
|
24 | - * WP_User->ID |
|
25 | - * |
|
26 | - * @var int |
|
27 | - */ |
|
28 | - private static $_default_creator_id; |
|
29 | - |
|
30 | - /** |
|
31 | - * indicates whether or not we've already verified core's default data during this request, |
|
32 | - * because after migrations are done, any addons activated while in maintenance mode |
|
33 | - * will want to setup their own default data, and they might hook into core's default data |
|
34 | - * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
35 | - * This prevents doing that for EVERY single addon. |
|
36 | - * |
|
37 | - * @var boolean |
|
38 | - */ |
|
39 | - protected static $_initialized_db_content_already_in_this_request = false; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
43 | - */ |
|
44 | - private static $table_analysis; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
48 | - */ |
|
49 | - private static $table_manager; |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @return \EventEspresso\core\services\database\TableAnalysis |
|
54 | - */ |
|
55 | - public static function getTableAnalysis() |
|
56 | - { |
|
57 | - if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
58 | - self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
59 | - } |
|
60 | - return self::$table_analysis; |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * @return \EventEspresso\core\services\database\TableManager |
|
66 | - */ |
|
67 | - public static function getTableManager() |
|
68 | - { |
|
69 | - if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
70 | - self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
71 | - } |
|
72 | - return self::$table_manager; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * _ensure_table_name_has_prefix |
|
78 | - * |
|
79 | - * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
80 | - * @access public |
|
81 | - * @static |
|
82 | - * @param $table_name |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public static function ensure_table_name_has_prefix($table_name) |
|
86 | - { |
|
87 | - return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * system_initialization |
|
93 | - * ensures the EE configuration settings are loaded with at least default options set |
|
94 | - * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
95 | - * |
|
96 | - * @access public |
|
97 | - * @static |
|
98 | - * @return void |
|
99 | - */ |
|
100 | - public static function system_initialization() |
|
101 | - { |
|
102 | - EEH_Activation::reset_and_update_config(); |
|
103 | - // which is fired BEFORE activation of plugin anyways |
|
104 | - EEH_Activation::verify_default_pages_exist(); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * Sets the database schema and creates folders. This should |
|
110 | - * be called on plugin activation and reactivation |
|
111 | - * |
|
112 | - * @return boolean success, whether the database and folders are setup properly |
|
113 | - * @throws \EE_Error |
|
114 | - */ |
|
115 | - public static function initialize_db_and_folders() |
|
116 | - { |
|
117 | - return EEH_Activation::create_database_tables(); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * assuming we have an up-to-date database schema, this will populate it |
|
123 | - * with default and initial data. This should be called |
|
124 | - * upon activation of a new plugin, reactivation, and at the end |
|
125 | - * of running migration scripts |
|
126 | - * |
|
127 | - * @throws \EE_Error |
|
128 | - */ |
|
129 | - public static function initialize_db_content() |
|
130 | - { |
|
131 | - // let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
132 | - if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
133 | - return; |
|
134 | - } |
|
135 | - EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
136 | - |
|
137 | - EEH_Activation::initialize_system_questions(); |
|
138 | - EEH_Activation::insert_default_status_codes(); |
|
139 | - EEH_Activation::generate_default_message_templates(); |
|
140 | - EEH_Activation::create_no_ticket_prices_array(); |
|
141 | - |
|
142 | - EEH_Activation::validate_messages_system(); |
|
143 | - EEH_Activation::insert_default_payment_methods(); |
|
144 | - // in case we've |
|
145 | - EEH_Activation::remove_cron_tasks(); |
|
146 | - EEH_Activation::create_cron_tasks(); |
|
147 | - // remove all TXN locks since that is being done via extra meta now |
|
148 | - delete_option('ee_locked_transactions'); |
|
149 | - // also, check for CAF default db content |
|
150 | - do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
151 | - // also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
152 | - // which users really won't care about on initial activation |
|
153 | - EE_Error::overwrite_success(); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
159 | - * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
160 | - * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
161 | - * (null) |
|
162 | - * |
|
163 | - * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
164 | - * 'old' (only returns ones that should no longer be used),or 'all', |
|
165 | - * @return array |
|
166 | - * @throws \EE_Error |
|
167 | - */ |
|
168 | - public static function get_cron_tasks($which_to_include) |
|
169 | - { |
|
170 | - $cron_tasks = apply_filters( |
|
171 | - 'FHEE__EEH_Activation__get_cron_tasks', |
|
172 | - array( |
|
173 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
174 | - // 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use |
|
175 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
176 | - // there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
177 | - 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
178 | - ) |
|
179 | - ); |
|
180 | - if ($which_to_include === 'old') { |
|
181 | - $cron_tasks = array_filter( |
|
182 | - $cron_tasks, |
|
183 | - function ($value) { |
|
184 | - return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
185 | - } |
|
186 | - ); |
|
187 | - } elseif ($which_to_include === 'current') { |
|
188 | - $cron_tasks = array_filter($cron_tasks); |
|
189 | - } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
190 | - throw new EE_Error( |
|
191 | - sprintf( |
|
192 | - __( |
|
193 | - 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
194 | - 'event_espresso' |
|
195 | - ), |
|
196 | - $which_to_include |
|
197 | - ) |
|
198 | - ); |
|
199 | - } |
|
200 | - return $cron_tasks; |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
206 | - * |
|
207 | - * @throws \EE_Error |
|
208 | - */ |
|
209 | - public static function create_cron_tasks() |
|
210 | - { |
|
211 | - |
|
212 | - foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
213 | - if (! wp_next_scheduled($hook_name)) { |
|
214 | - /** |
|
215 | - * This allows client code to define the initial start timestamp for this schedule. |
|
216 | - */ |
|
217 | - if (is_array($frequency) |
|
218 | - && count($frequency) === 2 |
|
219 | - && isset($frequency[0], $frequency[1]) |
|
220 | - ) { |
|
221 | - $start_timestamp = $frequency[0]; |
|
222 | - $frequency = $frequency[1]; |
|
223 | - } else { |
|
224 | - $start_timestamp = time(); |
|
225 | - } |
|
226 | - wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
227 | - } |
|
228 | - } |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * Remove the currently-existing and now-removed cron tasks. |
|
234 | - * |
|
235 | - * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
236 | - * @throws \EE_Error |
|
237 | - */ |
|
238 | - public static function remove_cron_tasks($remove_all = true) |
|
239 | - { |
|
240 | - $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
241 | - $crons = _get_cron_array(); |
|
242 | - $crons = is_array($crons) ? $crons : array(); |
|
243 | - /* reminder of what $crons look like: |
|
18 | + /** |
|
19 | + * constant used to indicate a cron task is no longer in use |
|
20 | + */ |
|
21 | + const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
22 | + |
|
23 | + /** |
|
24 | + * WP_User->ID |
|
25 | + * |
|
26 | + * @var int |
|
27 | + */ |
|
28 | + private static $_default_creator_id; |
|
29 | + |
|
30 | + /** |
|
31 | + * indicates whether or not we've already verified core's default data during this request, |
|
32 | + * because after migrations are done, any addons activated while in maintenance mode |
|
33 | + * will want to setup their own default data, and they might hook into core's default data |
|
34 | + * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
35 | + * This prevents doing that for EVERY single addon. |
|
36 | + * |
|
37 | + * @var boolean |
|
38 | + */ |
|
39 | + protected static $_initialized_db_content_already_in_this_request = false; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
43 | + */ |
|
44 | + private static $table_analysis; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
48 | + */ |
|
49 | + private static $table_manager; |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @return \EventEspresso\core\services\database\TableAnalysis |
|
54 | + */ |
|
55 | + public static function getTableAnalysis() |
|
56 | + { |
|
57 | + if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
58 | + self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
59 | + } |
|
60 | + return self::$table_analysis; |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * @return \EventEspresso\core\services\database\TableManager |
|
66 | + */ |
|
67 | + public static function getTableManager() |
|
68 | + { |
|
69 | + if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
70 | + self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
71 | + } |
|
72 | + return self::$table_manager; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * _ensure_table_name_has_prefix |
|
78 | + * |
|
79 | + * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
80 | + * @access public |
|
81 | + * @static |
|
82 | + * @param $table_name |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public static function ensure_table_name_has_prefix($table_name) |
|
86 | + { |
|
87 | + return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * system_initialization |
|
93 | + * ensures the EE configuration settings are loaded with at least default options set |
|
94 | + * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
95 | + * |
|
96 | + * @access public |
|
97 | + * @static |
|
98 | + * @return void |
|
99 | + */ |
|
100 | + public static function system_initialization() |
|
101 | + { |
|
102 | + EEH_Activation::reset_and_update_config(); |
|
103 | + // which is fired BEFORE activation of plugin anyways |
|
104 | + EEH_Activation::verify_default_pages_exist(); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * Sets the database schema and creates folders. This should |
|
110 | + * be called on plugin activation and reactivation |
|
111 | + * |
|
112 | + * @return boolean success, whether the database and folders are setup properly |
|
113 | + * @throws \EE_Error |
|
114 | + */ |
|
115 | + public static function initialize_db_and_folders() |
|
116 | + { |
|
117 | + return EEH_Activation::create_database_tables(); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * assuming we have an up-to-date database schema, this will populate it |
|
123 | + * with default and initial data. This should be called |
|
124 | + * upon activation of a new plugin, reactivation, and at the end |
|
125 | + * of running migration scripts |
|
126 | + * |
|
127 | + * @throws \EE_Error |
|
128 | + */ |
|
129 | + public static function initialize_db_content() |
|
130 | + { |
|
131 | + // let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
132 | + if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
133 | + return; |
|
134 | + } |
|
135 | + EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
136 | + |
|
137 | + EEH_Activation::initialize_system_questions(); |
|
138 | + EEH_Activation::insert_default_status_codes(); |
|
139 | + EEH_Activation::generate_default_message_templates(); |
|
140 | + EEH_Activation::create_no_ticket_prices_array(); |
|
141 | + |
|
142 | + EEH_Activation::validate_messages_system(); |
|
143 | + EEH_Activation::insert_default_payment_methods(); |
|
144 | + // in case we've |
|
145 | + EEH_Activation::remove_cron_tasks(); |
|
146 | + EEH_Activation::create_cron_tasks(); |
|
147 | + // remove all TXN locks since that is being done via extra meta now |
|
148 | + delete_option('ee_locked_transactions'); |
|
149 | + // also, check for CAF default db content |
|
150 | + do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
151 | + // also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
152 | + // which users really won't care about on initial activation |
|
153 | + EE_Error::overwrite_success(); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
159 | + * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
160 | + * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
161 | + * (null) |
|
162 | + * |
|
163 | + * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
164 | + * 'old' (only returns ones that should no longer be used),or 'all', |
|
165 | + * @return array |
|
166 | + * @throws \EE_Error |
|
167 | + */ |
|
168 | + public static function get_cron_tasks($which_to_include) |
|
169 | + { |
|
170 | + $cron_tasks = apply_filters( |
|
171 | + 'FHEE__EEH_Activation__get_cron_tasks', |
|
172 | + array( |
|
173 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
174 | + // 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use |
|
175 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
176 | + // there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
177 | + 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
178 | + ) |
|
179 | + ); |
|
180 | + if ($which_to_include === 'old') { |
|
181 | + $cron_tasks = array_filter( |
|
182 | + $cron_tasks, |
|
183 | + function ($value) { |
|
184 | + return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
185 | + } |
|
186 | + ); |
|
187 | + } elseif ($which_to_include === 'current') { |
|
188 | + $cron_tasks = array_filter($cron_tasks); |
|
189 | + } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
190 | + throw new EE_Error( |
|
191 | + sprintf( |
|
192 | + __( |
|
193 | + 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
194 | + 'event_espresso' |
|
195 | + ), |
|
196 | + $which_to_include |
|
197 | + ) |
|
198 | + ); |
|
199 | + } |
|
200 | + return $cron_tasks; |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
206 | + * |
|
207 | + * @throws \EE_Error |
|
208 | + */ |
|
209 | + public static function create_cron_tasks() |
|
210 | + { |
|
211 | + |
|
212 | + foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
213 | + if (! wp_next_scheduled($hook_name)) { |
|
214 | + /** |
|
215 | + * This allows client code to define the initial start timestamp for this schedule. |
|
216 | + */ |
|
217 | + if (is_array($frequency) |
|
218 | + && count($frequency) === 2 |
|
219 | + && isset($frequency[0], $frequency[1]) |
|
220 | + ) { |
|
221 | + $start_timestamp = $frequency[0]; |
|
222 | + $frequency = $frequency[1]; |
|
223 | + } else { |
|
224 | + $start_timestamp = time(); |
|
225 | + } |
|
226 | + wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
227 | + } |
|
228 | + } |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * Remove the currently-existing and now-removed cron tasks. |
|
234 | + * |
|
235 | + * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
236 | + * @throws \EE_Error |
|
237 | + */ |
|
238 | + public static function remove_cron_tasks($remove_all = true) |
|
239 | + { |
|
240 | + $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
241 | + $crons = _get_cron_array(); |
|
242 | + $crons = is_array($crons) ? $crons : array(); |
|
243 | + /* reminder of what $crons look like: |
|
244 | 244 | * Top-level keys are timestamps, and their values are arrays. |
245 | 245 | * The 2nd level arrays have keys with each of the cron task hook names to run at that time |
246 | 246 | * and their values are arrays. |
@@ -257,909 +257,909 @@ discard block |
||
257 | 257 | * ... |
258 | 258 | * ... |
259 | 259 | */ |
260 | - $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
261 | - foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
262 | - if (is_array($hooks_to_fire_at_time)) { |
|
263 | - foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
264 | - if (isset($ee_cron_tasks_to_remove[ $hook_name ]) |
|
265 | - && is_array($ee_cron_tasks_to_remove[ $hook_name ]) |
|
266 | - ) { |
|
267 | - unset($crons[ $timestamp ][ $hook_name ]); |
|
268 | - } |
|
269 | - } |
|
270 | - // also take care of any empty cron timestamps. |
|
271 | - if (empty($hooks_to_fire_at_time)) { |
|
272 | - unset($crons[ $timestamp ]); |
|
273 | - } |
|
274 | - } |
|
275 | - } |
|
276 | - _set_cron_array($crons); |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * CPT_initialization |
|
282 | - * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
283 | - * |
|
284 | - * @access public |
|
285 | - * @static |
|
286 | - * @return void |
|
287 | - */ |
|
288 | - public static function CPT_initialization() |
|
289 | - { |
|
290 | - // register Custom Post Types |
|
291 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
292 | - flush_rewrite_rules(); |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * reset_and_update_config |
|
299 | - * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
300 | - * If there is old calendar config data saved, then it will get converted on activation. |
|
301 | - * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
302 | - * |
|
303 | - * @access public |
|
304 | - * @static |
|
305 | - * @return void |
|
306 | - */ |
|
307 | - public static function reset_and_update_config() |
|
308 | - { |
|
309 | - do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
310 | - add_filter( |
|
311 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
312 | - array('EEH_Activation', 'migrate_old_config_data'), |
|
313 | - 10, |
|
314 | - 3 |
|
315 | - ); |
|
316 | - // EE_Config::reset(); |
|
317 | - if (! EE_Config::logging_enabled()) { |
|
318 | - delete_option(EE_Config::LOG_NAME); |
|
319 | - } |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * load_calendar_config |
|
325 | - * |
|
326 | - * @access public |
|
327 | - * @return void |
|
328 | - */ |
|
329 | - public static function load_calendar_config() |
|
330 | - { |
|
331 | - // grab array of all plugin folders and loop thru it |
|
332 | - $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
333 | - if (empty($plugins)) { |
|
334 | - return; |
|
335 | - } |
|
336 | - foreach ($plugins as $plugin_path) { |
|
337 | - // grab plugin folder name from path |
|
338 | - $plugin = basename($plugin_path); |
|
339 | - // drill down to Espresso plugins |
|
340 | - // then to calendar related plugins |
|
341 | - if (strpos($plugin, 'espresso') !== false |
|
342 | - || strpos($plugin, 'Espresso') !== false |
|
343 | - || strpos($plugin, 'ee4') !== false |
|
344 | - || strpos($plugin, 'EE4') !== false |
|
345 | - || strpos($plugin, 'calendar') !== false |
|
346 | - ) { |
|
347 | - // this is what we are looking for |
|
348 | - $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
349 | - // does it exist in this folder ? |
|
350 | - if (is_readable($calendar_config)) { |
|
351 | - // YEAH! let's load it |
|
352 | - require_once($calendar_config); |
|
353 | - } |
|
354 | - } |
|
355 | - } |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * _migrate_old_config_data |
|
362 | - * |
|
363 | - * @access public |
|
364 | - * @param array|stdClass $settings |
|
365 | - * @param string $config |
|
366 | - * @param \EE_Config $EE_Config |
|
367 | - * @return \stdClass |
|
368 | - */ |
|
369 | - public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
370 | - { |
|
371 | - $convert_from_array = array('addons'); |
|
372 | - // in case old settings were saved as an array |
|
373 | - if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
374 | - // convert existing settings to an object |
|
375 | - $config_array = $settings; |
|
376 | - $settings = new stdClass(); |
|
377 | - foreach ($config_array as $key => $value) { |
|
378 | - if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
379 | - $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
380 | - } else { |
|
381 | - $settings->{$key} = $value; |
|
382 | - } |
|
383 | - } |
|
384 | - add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
385 | - } |
|
386 | - return $settings; |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * deactivate_event_espresso |
|
392 | - * |
|
393 | - * @access public |
|
394 | - * @static |
|
395 | - * @return void |
|
396 | - */ |
|
397 | - public static function deactivate_event_espresso() |
|
398 | - { |
|
399 | - // check permissions |
|
400 | - if (current_user_can('activate_plugins')) { |
|
401 | - deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
402 | - } |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * verify_default_pages_exist |
|
409 | - * |
|
410 | - * @access public |
|
411 | - * @static |
|
412 | - * @return void |
|
413 | - * @throws InvalidDataTypeException |
|
414 | - */ |
|
415 | - public static function verify_default_pages_exist() |
|
416 | - { |
|
417 | - $critical_page_problem = false; |
|
418 | - $critical_pages = array( |
|
419 | - array( |
|
420 | - 'id' => 'reg_page_id', |
|
421 | - 'name' => __('Registration Checkout', 'event_espresso'), |
|
422 | - 'post' => null, |
|
423 | - 'code' => 'ESPRESSO_CHECKOUT', |
|
424 | - ), |
|
425 | - array( |
|
426 | - 'id' => 'txn_page_id', |
|
427 | - 'name' => __('Transactions', 'event_espresso'), |
|
428 | - 'post' => null, |
|
429 | - 'code' => 'ESPRESSO_TXN_PAGE', |
|
430 | - ), |
|
431 | - array( |
|
432 | - 'id' => 'thank_you_page_id', |
|
433 | - 'name' => __('Thank You', 'event_espresso'), |
|
434 | - 'post' => null, |
|
435 | - 'code' => 'ESPRESSO_THANK_YOU', |
|
436 | - ), |
|
437 | - array( |
|
438 | - 'id' => 'cancel_page_id', |
|
439 | - 'name' => __('Registration Cancelled', 'event_espresso'), |
|
440 | - 'post' => null, |
|
441 | - 'code' => 'ESPRESSO_CANCELLED', |
|
442 | - ), |
|
443 | - ); |
|
444 | - $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
445 | - foreach ($critical_pages as $critical_page) { |
|
446 | - // is critical page ID set in config ? |
|
447 | - if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
448 | - // attempt to find post by ID |
|
449 | - $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
450 | - } |
|
451 | - // no dice? |
|
452 | - if ($critical_page['post'] === null) { |
|
453 | - // attempt to find post by title |
|
454 | - $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
455 | - // still nothing? |
|
456 | - if ($critical_page['post'] === null) { |
|
457 | - $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
458 | - // REALLY? Still nothing ??!?!? |
|
459 | - if ($critical_page['post'] === null) { |
|
460 | - $msg = __( |
|
461 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
462 | - 'event_espresso' |
|
463 | - ); |
|
464 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
465 | - break; |
|
466 | - } |
|
467 | - } |
|
468 | - } |
|
469 | - // check that Post ID matches critical page ID in config |
|
470 | - if (isset($critical_page['post']->ID) |
|
471 | - && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
472 | - ) { |
|
473 | - // update Config with post ID |
|
474 | - $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
475 | - if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
476 | - $msg = __( |
|
477 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
478 | - 'event_espresso' |
|
479 | - ); |
|
480 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
481 | - } |
|
482 | - } |
|
483 | - $critical_page_problem = |
|
484 | - ! isset($critical_page['post']->post_status) |
|
485 | - || $critical_page['post']->post_status !== 'publish' |
|
486 | - || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
487 | - ? true |
|
488 | - : $critical_page_problem; |
|
489 | - } |
|
490 | - if ($critical_page_problem) { |
|
491 | - new PersistentAdminNotice( |
|
492 | - 'critical_page_problem', |
|
493 | - sprintf( |
|
494 | - esc_html__( |
|
495 | - 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
496 | - 'event_espresso' |
|
497 | - ), |
|
498 | - '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' |
|
499 | - . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
500 | - . '</a>' |
|
501 | - ) |
|
502 | - ); |
|
503 | - } |
|
504 | - if (EE_Error::has_notices()) { |
|
505 | - EE_Error::get_notices(false, true, true); |
|
506 | - } |
|
507 | - } |
|
508 | - |
|
509 | - |
|
510 | - |
|
511 | - /** |
|
512 | - * Returns the first post which uses the specified shortcode |
|
513 | - * |
|
514 | - * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
515 | - * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
516 | - * "[ESPRESSO_THANK_YOU" |
|
517 | - * (we don't search for the closing shortcode bracket because they might have added |
|
518 | - * parameter to the shortcode |
|
519 | - * @return WP_Post or NULl |
|
520 | - */ |
|
521 | - public static function get_page_by_ee_shortcode($ee_shortcode) |
|
522 | - { |
|
523 | - global $wpdb; |
|
524 | - $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
525 | - $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
526 | - if ($post_id) { |
|
527 | - return get_post($post_id); |
|
528 | - } else { |
|
529 | - return null; |
|
530 | - } |
|
531 | - } |
|
532 | - |
|
533 | - |
|
534 | - /** |
|
535 | - * This function generates a post for critical espresso pages |
|
536 | - * |
|
537 | - * @access public |
|
538 | - * @static |
|
539 | - * @param array $critical_page |
|
540 | - * @return array |
|
541 | - */ |
|
542 | - public static function create_critical_page($critical_page) |
|
543 | - { |
|
544 | - |
|
545 | - $post_args = array( |
|
546 | - 'post_title' => $critical_page['name'], |
|
547 | - 'post_status' => 'publish', |
|
548 | - 'post_type' => 'page', |
|
549 | - 'comment_status' => 'closed', |
|
550 | - 'post_content' => '[' . $critical_page['code'] . ']', |
|
551 | - ); |
|
552 | - |
|
553 | - $post_id = wp_insert_post($post_args); |
|
554 | - if (! $post_id) { |
|
555 | - $msg = sprintf( |
|
556 | - __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
557 | - $critical_page['name'] |
|
558 | - ); |
|
559 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
560 | - return $critical_page; |
|
561 | - } |
|
562 | - // get newly created post's details |
|
563 | - if (! $critical_page['post'] = get_post($post_id)) { |
|
564 | - $msg = sprintf( |
|
565 | - __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
566 | - $critical_page['name'] |
|
567 | - ); |
|
568 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
569 | - } |
|
570 | - |
|
571 | - return $critical_page; |
|
572 | - } |
|
573 | - |
|
574 | - |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
579 | - * The role being used to check is filterable. |
|
580 | - * |
|
581 | - * @since 4.6.0 |
|
582 | - * @global WPDB $wpdb |
|
583 | - * @return mixed null|int WP_user ID or NULL |
|
584 | - */ |
|
585 | - public static function get_default_creator_id() |
|
586 | - { |
|
587 | - global $wpdb; |
|
588 | - if (! empty(self::$_default_creator_id)) { |
|
589 | - return self::$_default_creator_id; |
|
590 | - }/**/ |
|
591 | - $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
592 | - // let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
593 | - $pre_filtered_id = apply_filters( |
|
594 | - 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
595 | - false, |
|
596 | - $role_to_check |
|
597 | - ); |
|
598 | - if ($pre_filtered_id !== false) { |
|
599 | - return (int) $pre_filtered_id; |
|
600 | - } |
|
601 | - $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
602 | - $query = $wpdb->prepare( |
|
603 | - "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
604 | - '%' . $role_to_check . '%' |
|
605 | - ); |
|
606 | - $user_id = $wpdb->get_var($query); |
|
607 | - $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
608 | - if ($user_id && (int) $user_id) { |
|
609 | - self::$_default_creator_id = (int) $user_id; |
|
610 | - return self::$_default_creator_id; |
|
611 | - } else { |
|
612 | - return null; |
|
613 | - } |
|
614 | - } |
|
615 | - |
|
616 | - |
|
617 | - |
|
618 | - /** |
|
619 | - * used by EE and EE addons during plugin activation to create tables. |
|
620 | - * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
621 | - * but includes extra logic regarding activations. |
|
622 | - * |
|
623 | - * @access public |
|
624 | - * @static |
|
625 | - * @param string $table_name without the $wpdb->prefix |
|
626 | - * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
627 | - * table query) |
|
628 | - * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
629 | - * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
630 | - * and new once this function is done (ie, you really do want to CREATE a |
|
631 | - * table, and expect it to be empty once you're done) leave as FALSE when |
|
632 | - * you just want to verify the table exists and matches this definition |
|
633 | - * (and if it HAS data in it you want to leave it be) |
|
634 | - * @return void |
|
635 | - * @throws EE_Error if there are database errors |
|
636 | - */ |
|
637 | - public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
638 | - { |
|
639 | - if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
640 | - return; |
|
641 | - } |
|
642 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
643 | - if (! function_exists('dbDelta')) { |
|
644 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
645 | - } |
|
646 | - $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
647 | - $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
648 | - // do we need to first delete an existing version of this table ? |
|
649 | - if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
650 | - // ok, delete the table... but ONLY if it's empty |
|
651 | - $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
652 | - // table is NOT empty, are you SURE you want to delete this table ??? |
|
653 | - if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
654 | - \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
655 | - } elseif (! $deleted_safely) { |
|
656 | - // so we should be more cautious rather than just dropping tables so easily |
|
657 | - error_log( |
|
658 | - sprintf( |
|
659 | - __( |
|
660 | - 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
661 | - 'event_espresso' |
|
662 | - ), |
|
663 | - $wp_table_name, |
|
664 | - '<br/>', |
|
665 | - 'espresso_db_update' |
|
666 | - ) |
|
667 | - ); |
|
668 | - } |
|
669 | - } |
|
670 | - $engine = str_replace('ENGINE=', '', $engine); |
|
671 | - \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
672 | - } |
|
673 | - |
|
674 | - |
|
675 | - |
|
676 | - /** |
|
677 | - * add_column_if_it_doesn't_exist |
|
678 | - * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
679 | - * |
|
680 | - * @access public |
|
681 | - * @static |
|
682 | - * @deprecated instead use TableManager::addColumn() |
|
683 | - * @param string $table_name (without "wp_", eg "esp_attendee" |
|
684 | - * @param string $column_name |
|
685 | - * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
686 | - * 'VARCHAR(10)' |
|
687 | - * @return bool|int |
|
688 | - */ |
|
689 | - public static function add_column_if_it_doesnt_exist( |
|
690 | - $table_name, |
|
691 | - $column_name, |
|
692 | - $column_info = 'INT UNSIGNED NOT NULL' |
|
693 | - ) { |
|
694 | - return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
695 | - } |
|
696 | - |
|
697 | - |
|
698 | - /** |
|
699 | - * get_fields_on_table |
|
700 | - * Gets all the fields on the database table. |
|
701 | - * |
|
702 | - * @access public |
|
703 | - * @deprecated instead use TableManager::getTableColumns() |
|
704 | - * @static |
|
705 | - * @param string $table_name , without prefixed $wpdb->prefix |
|
706 | - * @return array of database column names |
|
707 | - */ |
|
708 | - public static function get_fields_on_table($table_name = null) |
|
709 | - { |
|
710 | - return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
711 | - } |
|
712 | - |
|
713 | - |
|
714 | - /** |
|
715 | - * db_table_is_empty |
|
716 | - * |
|
717 | - * @access public\ |
|
718 | - * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
719 | - * @static |
|
720 | - * @param string $table_name |
|
721 | - * @return bool |
|
722 | - */ |
|
723 | - public static function db_table_is_empty($table_name) |
|
724 | - { |
|
725 | - return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
726 | - } |
|
727 | - |
|
728 | - |
|
729 | - /** |
|
730 | - * delete_db_table_if_empty |
|
731 | - * |
|
732 | - * @access public |
|
733 | - * @static |
|
734 | - * @param string $table_name |
|
735 | - * @return bool | int |
|
736 | - */ |
|
737 | - public static function delete_db_table_if_empty($table_name) |
|
738 | - { |
|
739 | - if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
740 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
741 | - } |
|
742 | - return false; |
|
743 | - } |
|
744 | - |
|
745 | - |
|
746 | - /** |
|
747 | - * delete_unused_db_table |
|
748 | - * |
|
749 | - * @access public |
|
750 | - * @static |
|
751 | - * @deprecated instead use TableManager::dropTable() |
|
752 | - * @param string $table_name |
|
753 | - * @return bool | int |
|
754 | - */ |
|
755 | - public static function delete_unused_db_table($table_name) |
|
756 | - { |
|
757 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
758 | - } |
|
759 | - |
|
760 | - |
|
761 | - /** |
|
762 | - * drop_index |
|
763 | - * |
|
764 | - * @access public |
|
765 | - * @static |
|
766 | - * @deprecated instead use TableManager::dropIndex() |
|
767 | - * @param string $table_name |
|
768 | - * @param string $index_name |
|
769 | - * @return bool | int |
|
770 | - */ |
|
771 | - public static function drop_index($table_name, $index_name) |
|
772 | - { |
|
773 | - return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
774 | - } |
|
775 | - |
|
776 | - |
|
777 | - |
|
778 | - /** |
|
779 | - * create_database_tables |
|
780 | - * |
|
781 | - * @access public |
|
782 | - * @static |
|
783 | - * @throws EE_Error |
|
784 | - * @return boolean success (whether database is setup properly or not) |
|
785 | - */ |
|
786 | - public static function create_database_tables() |
|
787 | - { |
|
788 | - EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
789 | - // find the migration script that sets the database to be compatible with the code |
|
790 | - $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
791 | - if ($dms_name) { |
|
792 | - $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
793 | - $current_data_migration_script->set_migrating(false); |
|
794 | - $current_data_migration_script->schema_changes_before_migration(); |
|
795 | - $current_data_migration_script->schema_changes_after_migration(); |
|
796 | - if ($current_data_migration_script->get_errors()) { |
|
797 | - if (WP_DEBUG) { |
|
798 | - foreach ($current_data_migration_script->get_errors() as $error) { |
|
799 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
800 | - } |
|
801 | - } else { |
|
802 | - EE_Error::add_error( |
|
803 | - __( |
|
804 | - 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
260 | + $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
261 | + foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
262 | + if (is_array($hooks_to_fire_at_time)) { |
|
263 | + foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
264 | + if (isset($ee_cron_tasks_to_remove[ $hook_name ]) |
|
265 | + && is_array($ee_cron_tasks_to_remove[ $hook_name ]) |
|
266 | + ) { |
|
267 | + unset($crons[ $timestamp ][ $hook_name ]); |
|
268 | + } |
|
269 | + } |
|
270 | + // also take care of any empty cron timestamps. |
|
271 | + if (empty($hooks_to_fire_at_time)) { |
|
272 | + unset($crons[ $timestamp ]); |
|
273 | + } |
|
274 | + } |
|
275 | + } |
|
276 | + _set_cron_array($crons); |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * CPT_initialization |
|
282 | + * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
283 | + * |
|
284 | + * @access public |
|
285 | + * @static |
|
286 | + * @return void |
|
287 | + */ |
|
288 | + public static function CPT_initialization() |
|
289 | + { |
|
290 | + // register Custom Post Types |
|
291 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
292 | + flush_rewrite_rules(); |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * reset_and_update_config |
|
299 | + * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
300 | + * If there is old calendar config data saved, then it will get converted on activation. |
|
301 | + * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
302 | + * |
|
303 | + * @access public |
|
304 | + * @static |
|
305 | + * @return void |
|
306 | + */ |
|
307 | + public static function reset_and_update_config() |
|
308 | + { |
|
309 | + do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
310 | + add_filter( |
|
311 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
312 | + array('EEH_Activation', 'migrate_old_config_data'), |
|
313 | + 10, |
|
314 | + 3 |
|
315 | + ); |
|
316 | + // EE_Config::reset(); |
|
317 | + if (! EE_Config::logging_enabled()) { |
|
318 | + delete_option(EE_Config::LOG_NAME); |
|
319 | + } |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * load_calendar_config |
|
325 | + * |
|
326 | + * @access public |
|
327 | + * @return void |
|
328 | + */ |
|
329 | + public static function load_calendar_config() |
|
330 | + { |
|
331 | + // grab array of all plugin folders and loop thru it |
|
332 | + $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
333 | + if (empty($plugins)) { |
|
334 | + return; |
|
335 | + } |
|
336 | + foreach ($plugins as $plugin_path) { |
|
337 | + // grab plugin folder name from path |
|
338 | + $plugin = basename($plugin_path); |
|
339 | + // drill down to Espresso plugins |
|
340 | + // then to calendar related plugins |
|
341 | + if (strpos($plugin, 'espresso') !== false |
|
342 | + || strpos($plugin, 'Espresso') !== false |
|
343 | + || strpos($plugin, 'ee4') !== false |
|
344 | + || strpos($plugin, 'EE4') !== false |
|
345 | + || strpos($plugin, 'calendar') !== false |
|
346 | + ) { |
|
347 | + // this is what we are looking for |
|
348 | + $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
349 | + // does it exist in this folder ? |
|
350 | + if (is_readable($calendar_config)) { |
|
351 | + // YEAH! let's load it |
|
352 | + require_once($calendar_config); |
|
353 | + } |
|
354 | + } |
|
355 | + } |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * _migrate_old_config_data |
|
362 | + * |
|
363 | + * @access public |
|
364 | + * @param array|stdClass $settings |
|
365 | + * @param string $config |
|
366 | + * @param \EE_Config $EE_Config |
|
367 | + * @return \stdClass |
|
368 | + */ |
|
369 | + public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
370 | + { |
|
371 | + $convert_from_array = array('addons'); |
|
372 | + // in case old settings were saved as an array |
|
373 | + if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
374 | + // convert existing settings to an object |
|
375 | + $config_array = $settings; |
|
376 | + $settings = new stdClass(); |
|
377 | + foreach ($config_array as $key => $value) { |
|
378 | + if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
379 | + $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
380 | + } else { |
|
381 | + $settings->{$key} = $value; |
|
382 | + } |
|
383 | + } |
|
384 | + add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
385 | + } |
|
386 | + return $settings; |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * deactivate_event_espresso |
|
392 | + * |
|
393 | + * @access public |
|
394 | + * @static |
|
395 | + * @return void |
|
396 | + */ |
|
397 | + public static function deactivate_event_espresso() |
|
398 | + { |
|
399 | + // check permissions |
|
400 | + if (current_user_can('activate_plugins')) { |
|
401 | + deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
402 | + } |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * verify_default_pages_exist |
|
409 | + * |
|
410 | + * @access public |
|
411 | + * @static |
|
412 | + * @return void |
|
413 | + * @throws InvalidDataTypeException |
|
414 | + */ |
|
415 | + public static function verify_default_pages_exist() |
|
416 | + { |
|
417 | + $critical_page_problem = false; |
|
418 | + $critical_pages = array( |
|
419 | + array( |
|
420 | + 'id' => 'reg_page_id', |
|
421 | + 'name' => __('Registration Checkout', 'event_espresso'), |
|
422 | + 'post' => null, |
|
423 | + 'code' => 'ESPRESSO_CHECKOUT', |
|
424 | + ), |
|
425 | + array( |
|
426 | + 'id' => 'txn_page_id', |
|
427 | + 'name' => __('Transactions', 'event_espresso'), |
|
428 | + 'post' => null, |
|
429 | + 'code' => 'ESPRESSO_TXN_PAGE', |
|
430 | + ), |
|
431 | + array( |
|
432 | + 'id' => 'thank_you_page_id', |
|
433 | + 'name' => __('Thank You', 'event_espresso'), |
|
434 | + 'post' => null, |
|
435 | + 'code' => 'ESPRESSO_THANK_YOU', |
|
436 | + ), |
|
437 | + array( |
|
438 | + 'id' => 'cancel_page_id', |
|
439 | + 'name' => __('Registration Cancelled', 'event_espresso'), |
|
440 | + 'post' => null, |
|
441 | + 'code' => 'ESPRESSO_CANCELLED', |
|
442 | + ), |
|
443 | + ); |
|
444 | + $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
445 | + foreach ($critical_pages as $critical_page) { |
|
446 | + // is critical page ID set in config ? |
|
447 | + if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
448 | + // attempt to find post by ID |
|
449 | + $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
450 | + } |
|
451 | + // no dice? |
|
452 | + if ($critical_page['post'] === null) { |
|
453 | + // attempt to find post by title |
|
454 | + $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
455 | + // still nothing? |
|
456 | + if ($critical_page['post'] === null) { |
|
457 | + $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
458 | + // REALLY? Still nothing ??!?!? |
|
459 | + if ($critical_page['post'] === null) { |
|
460 | + $msg = __( |
|
461 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
462 | + 'event_espresso' |
|
463 | + ); |
|
464 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
465 | + break; |
|
466 | + } |
|
467 | + } |
|
468 | + } |
|
469 | + // check that Post ID matches critical page ID in config |
|
470 | + if (isset($critical_page['post']->ID) |
|
471 | + && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
472 | + ) { |
|
473 | + // update Config with post ID |
|
474 | + $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
475 | + if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
476 | + $msg = __( |
|
477 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
478 | + 'event_espresso' |
|
479 | + ); |
|
480 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
481 | + } |
|
482 | + } |
|
483 | + $critical_page_problem = |
|
484 | + ! isset($critical_page['post']->post_status) |
|
485 | + || $critical_page['post']->post_status !== 'publish' |
|
486 | + || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
487 | + ? true |
|
488 | + : $critical_page_problem; |
|
489 | + } |
|
490 | + if ($critical_page_problem) { |
|
491 | + new PersistentAdminNotice( |
|
492 | + 'critical_page_problem', |
|
493 | + sprintf( |
|
494 | + esc_html__( |
|
495 | + 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
496 | + 'event_espresso' |
|
497 | + ), |
|
498 | + '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' |
|
499 | + . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
500 | + . '</a>' |
|
501 | + ) |
|
502 | + ); |
|
503 | + } |
|
504 | + if (EE_Error::has_notices()) { |
|
505 | + EE_Error::get_notices(false, true, true); |
|
506 | + } |
|
507 | + } |
|
508 | + |
|
509 | + |
|
510 | + |
|
511 | + /** |
|
512 | + * Returns the first post which uses the specified shortcode |
|
513 | + * |
|
514 | + * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
515 | + * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
516 | + * "[ESPRESSO_THANK_YOU" |
|
517 | + * (we don't search for the closing shortcode bracket because they might have added |
|
518 | + * parameter to the shortcode |
|
519 | + * @return WP_Post or NULl |
|
520 | + */ |
|
521 | + public static function get_page_by_ee_shortcode($ee_shortcode) |
|
522 | + { |
|
523 | + global $wpdb; |
|
524 | + $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
525 | + $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
526 | + if ($post_id) { |
|
527 | + return get_post($post_id); |
|
528 | + } else { |
|
529 | + return null; |
|
530 | + } |
|
531 | + } |
|
532 | + |
|
533 | + |
|
534 | + /** |
|
535 | + * This function generates a post for critical espresso pages |
|
536 | + * |
|
537 | + * @access public |
|
538 | + * @static |
|
539 | + * @param array $critical_page |
|
540 | + * @return array |
|
541 | + */ |
|
542 | + public static function create_critical_page($critical_page) |
|
543 | + { |
|
544 | + |
|
545 | + $post_args = array( |
|
546 | + 'post_title' => $critical_page['name'], |
|
547 | + 'post_status' => 'publish', |
|
548 | + 'post_type' => 'page', |
|
549 | + 'comment_status' => 'closed', |
|
550 | + 'post_content' => '[' . $critical_page['code'] . ']', |
|
551 | + ); |
|
552 | + |
|
553 | + $post_id = wp_insert_post($post_args); |
|
554 | + if (! $post_id) { |
|
555 | + $msg = sprintf( |
|
556 | + __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
557 | + $critical_page['name'] |
|
558 | + ); |
|
559 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
560 | + return $critical_page; |
|
561 | + } |
|
562 | + // get newly created post's details |
|
563 | + if (! $critical_page['post'] = get_post($post_id)) { |
|
564 | + $msg = sprintf( |
|
565 | + __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
566 | + $critical_page['name'] |
|
567 | + ); |
|
568 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
569 | + } |
|
570 | + |
|
571 | + return $critical_page; |
|
572 | + } |
|
573 | + |
|
574 | + |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
579 | + * The role being used to check is filterable. |
|
580 | + * |
|
581 | + * @since 4.6.0 |
|
582 | + * @global WPDB $wpdb |
|
583 | + * @return mixed null|int WP_user ID or NULL |
|
584 | + */ |
|
585 | + public static function get_default_creator_id() |
|
586 | + { |
|
587 | + global $wpdb; |
|
588 | + if (! empty(self::$_default_creator_id)) { |
|
589 | + return self::$_default_creator_id; |
|
590 | + }/**/ |
|
591 | + $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
592 | + // let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
593 | + $pre_filtered_id = apply_filters( |
|
594 | + 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
595 | + false, |
|
596 | + $role_to_check |
|
597 | + ); |
|
598 | + if ($pre_filtered_id !== false) { |
|
599 | + return (int) $pre_filtered_id; |
|
600 | + } |
|
601 | + $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
602 | + $query = $wpdb->prepare( |
|
603 | + "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
604 | + '%' . $role_to_check . '%' |
|
605 | + ); |
|
606 | + $user_id = $wpdb->get_var($query); |
|
607 | + $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
608 | + if ($user_id && (int) $user_id) { |
|
609 | + self::$_default_creator_id = (int) $user_id; |
|
610 | + return self::$_default_creator_id; |
|
611 | + } else { |
|
612 | + return null; |
|
613 | + } |
|
614 | + } |
|
615 | + |
|
616 | + |
|
617 | + |
|
618 | + /** |
|
619 | + * used by EE and EE addons during plugin activation to create tables. |
|
620 | + * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
621 | + * but includes extra logic regarding activations. |
|
622 | + * |
|
623 | + * @access public |
|
624 | + * @static |
|
625 | + * @param string $table_name without the $wpdb->prefix |
|
626 | + * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
627 | + * table query) |
|
628 | + * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
629 | + * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
630 | + * and new once this function is done (ie, you really do want to CREATE a |
|
631 | + * table, and expect it to be empty once you're done) leave as FALSE when |
|
632 | + * you just want to verify the table exists and matches this definition |
|
633 | + * (and if it HAS data in it you want to leave it be) |
|
634 | + * @return void |
|
635 | + * @throws EE_Error if there are database errors |
|
636 | + */ |
|
637 | + public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
638 | + { |
|
639 | + if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
640 | + return; |
|
641 | + } |
|
642 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
643 | + if (! function_exists('dbDelta')) { |
|
644 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
645 | + } |
|
646 | + $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
647 | + $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
648 | + // do we need to first delete an existing version of this table ? |
|
649 | + if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
650 | + // ok, delete the table... but ONLY if it's empty |
|
651 | + $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
652 | + // table is NOT empty, are you SURE you want to delete this table ??? |
|
653 | + if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
654 | + \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
655 | + } elseif (! $deleted_safely) { |
|
656 | + // so we should be more cautious rather than just dropping tables so easily |
|
657 | + error_log( |
|
658 | + sprintf( |
|
659 | + __( |
|
660 | + 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
661 | + 'event_espresso' |
|
662 | + ), |
|
663 | + $wp_table_name, |
|
664 | + '<br/>', |
|
665 | + 'espresso_db_update' |
|
666 | + ) |
|
667 | + ); |
|
668 | + } |
|
669 | + } |
|
670 | + $engine = str_replace('ENGINE=', '', $engine); |
|
671 | + \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
672 | + } |
|
673 | + |
|
674 | + |
|
675 | + |
|
676 | + /** |
|
677 | + * add_column_if_it_doesn't_exist |
|
678 | + * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
679 | + * |
|
680 | + * @access public |
|
681 | + * @static |
|
682 | + * @deprecated instead use TableManager::addColumn() |
|
683 | + * @param string $table_name (without "wp_", eg "esp_attendee" |
|
684 | + * @param string $column_name |
|
685 | + * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
686 | + * 'VARCHAR(10)' |
|
687 | + * @return bool|int |
|
688 | + */ |
|
689 | + public static function add_column_if_it_doesnt_exist( |
|
690 | + $table_name, |
|
691 | + $column_name, |
|
692 | + $column_info = 'INT UNSIGNED NOT NULL' |
|
693 | + ) { |
|
694 | + return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
695 | + } |
|
696 | + |
|
697 | + |
|
698 | + /** |
|
699 | + * get_fields_on_table |
|
700 | + * Gets all the fields on the database table. |
|
701 | + * |
|
702 | + * @access public |
|
703 | + * @deprecated instead use TableManager::getTableColumns() |
|
704 | + * @static |
|
705 | + * @param string $table_name , without prefixed $wpdb->prefix |
|
706 | + * @return array of database column names |
|
707 | + */ |
|
708 | + public static function get_fields_on_table($table_name = null) |
|
709 | + { |
|
710 | + return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
711 | + } |
|
712 | + |
|
713 | + |
|
714 | + /** |
|
715 | + * db_table_is_empty |
|
716 | + * |
|
717 | + * @access public\ |
|
718 | + * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
719 | + * @static |
|
720 | + * @param string $table_name |
|
721 | + * @return bool |
|
722 | + */ |
|
723 | + public static function db_table_is_empty($table_name) |
|
724 | + { |
|
725 | + return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
726 | + } |
|
727 | + |
|
728 | + |
|
729 | + /** |
|
730 | + * delete_db_table_if_empty |
|
731 | + * |
|
732 | + * @access public |
|
733 | + * @static |
|
734 | + * @param string $table_name |
|
735 | + * @return bool | int |
|
736 | + */ |
|
737 | + public static function delete_db_table_if_empty($table_name) |
|
738 | + { |
|
739 | + if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
740 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
741 | + } |
|
742 | + return false; |
|
743 | + } |
|
744 | + |
|
745 | + |
|
746 | + /** |
|
747 | + * delete_unused_db_table |
|
748 | + * |
|
749 | + * @access public |
|
750 | + * @static |
|
751 | + * @deprecated instead use TableManager::dropTable() |
|
752 | + * @param string $table_name |
|
753 | + * @return bool | int |
|
754 | + */ |
|
755 | + public static function delete_unused_db_table($table_name) |
|
756 | + { |
|
757 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
758 | + } |
|
759 | + |
|
760 | + |
|
761 | + /** |
|
762 | + * drop_index |
|
763 | + * |
|
764 | + * @access public |
|
765 | + * @static |
|
766 | + * @deprecated instead use TableManager::dropIndex() |
|
767 | + * @param string $table_name |
|
768 | + * @param string $index_name |
|
769 | + * @return bool | int |
|
770 | + */ |
|
771 | + public static function drop_index($table_name, $index_name) |
|
772 | + { |
|
773 | + return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
774 | + } |
|
775 | + |
|
776 | + |
|
777 | + |
|
778 | + /** |
|
779 | + * create_database_tables |
|
780 | + * |
|
781 | + * @access public |
|
782 | + * @static |
|
783 | + * @throws EE_Error |
|
784 | + * @return boolean success (whether database is setup properly or not) |
|
785 | + */ |
|
786 | + public static function create_database_tables() |
|
787 | + { |
|
788 | + EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
789 | + // find the migration script that sets the database to be compatible with the code |
|
790 | + $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
791 | + if ($dms_name) { |
|
792 | + $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
793 | + $current_data_migration_script->set_migrating(false); |
|
794 | + $current_data_migration_script->schema_changes_before_migration(); |
|
795 | + $current_data_migration_script->schema_changes_after_migration(); |
|
796 | + if ($current_data_migration_script->get_errors()) { |
|
797 | + if (WP_DEBUG) { |
|
798 | + foreach ($current_data_migration_script->get_errors() as $error) { |
|
799 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
800 | + } |
|
801 | + } else { |
|
802 | + EE_Error::add_error( |
|
803 | + __( |
|
804 | + 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
805 | 805 | deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.', |
806 | - 'event_espresso' |
|
807 | - ) |
|
808 | - ); |
|
809 | - } |
|
810 | - return false; |
|
811 | - } |
|
812 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
813 | - } else { |
|
814 | - EE_Error::add_error( |
|
815 | - __( |
|
816 | - 'Could not determine most up-to-date data migration script from which to pull database schema |
|
806 | + 'event_espresso' |
|
807 | + ) |
|
808 | + ); |
|
809 | + } |
|
810 | + return false; |
|
811 | + } |
|
812 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
813 | + } else { |
|
814 | + EE_Error::add_error( |
|
815 | + __( |
|
816 | + 'Could not determine most up-to-date data migration script from which to pull database schema |
|
817 | 817 | structure. So database is probably not setup properly', |
818 | - 'event_espresso' |
|
819 | - ), |
|
820 | - __FILE__, |
|
821 | - __FUNCTION__, |
|
822 | - __LINE__ |
|
823 | - ); |
|
824 | - return false; |
|
825 | - } |
|
826 | - return true; |
|
827 | - } |
|
828 | - |
|
829 | - |
|
830 | - |
|
831 | - /** |
|
832 | - * initialize_system_questions |
|
833 | - * |
|
834 | - * @access public |
|
835 | - * @static |
|
836 | - * @return void |
|
837 | - */ |
|
838 | - public static function initialize_system_questions() |
|
839 | - { |
|
840 | - // QUESTION GROUPS |
|
841 | - global $wpdb; |
|
842 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
843 | - $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
844 | - // what we have |
|
845 | - $question_groups = $wpdb->get_col($SQL); |
|
846 | - // check the response |
|
847 | - $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
848 | - // what we should have |
|
849 | - $QSG_systems = array(1, 2); |
|
850 | - // loop thru what we should have and compare to what we have |
|
851 | - foreach ($QSG_systems as $QSG_system) { |
|
852 | - // reset values array |
|
853 | - $QSG_values = array(); |
|
854 | - // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
855 | - if (! in_array("$QSG_system", $question_groups)) { |
|
856 | - // add it |
|
857 | - switch ($QSG_system) { |
|
858 | - case 1: |
|
859 | - $QSG_values = array( |
|
860 | - 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
861 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
862 | - 'QSG_desc' => '', |
|
863 | - 'QSG_order' => 1, |
|
864 | - 'QSG_show_group_name' => 1, |
|
865 | - 'QSG_show_group_desc' => 1, |
|
866 | - 'QSG_system' => EEM_Question_Group::system_personal, |
|
867 | - 'QSG_deleted' => 0, |
|
868 | - ); |
|
869 | - break; |
|
870 | - case 2: |
|
871 | - $QSG_values = array( |
|
872 | - 'QSG_name' => __('Address Information', 'event_espresso'), |
|
873 | - 'QSG_identifier' => 'address-information-' . time(), |
|
874 | - 'QSG_desc' => '', |
|
875 | - 'QSG_order' => 2, |
|
876 | - 'QSG_show_group_name' => 1, |
|
877 | - 'QSG_show_group_desc' => 1, |
|
878 | - 'QSG_system' => EEM_Question_Group::system_address, |
|
879 | - 'QSG_deleted' => 0, |
|
880 | - ); |
|
881 | - break; |
|
882 | - } |
|
883 | - // make sure we have some values before inserting them |
|
884 | - if (! empty($QSG_values)) { |
|
885 | - // insert system question |
|
886 | - $wpdb->insert( |
|
887 | - $table_name, |
|
888 | - $QSG_values, |
|
889 | - array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
890 | - ); |
|
891 | - $QSG_IDs[ $QSG_system ] = $wpdb->insert_id; |
|
892 | - } |
|
893 | - } |
|
894 | - } |
|
895 | - // QUESTIONS |
|
896 | - global $wpdb; |
|
897 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
898 | - $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
899 | - // what we have |
|
900 | - $questions = $wpdb->get_col($SQL); |
|
901 | - // what we should have |
|
902 | - $QST_systems = array( |
|
903 | - 'fname', |
|
904 | - 'lname', |
|
905 | - 'email', |
|
906 | - 'address', |
|
907 | - 'address2', |
|
908 | - 'city', |
|
909 | - 'country', |
|
910 | - 'state', |
|
911 | - 'zip', |
|
912 | - 'phone', |
|
913 | - ); |
|
914 | - $order_for_group_1 = 1; |
|
915 | - $order_for_group_2 = 1; |
|
916 | - // loop thru what we should have and compare to what we have |
|
917 | - foreach ($QST_systems as $QST_system) { |
|
918 | - // reset values array |
|
919 | - $QST_values = array(); |
|
920 | - // if we don't have what we should have |
|
921 | - if (! in_array($QST_system, $questions)) { |
|
922 | - // add it |
|
923 | - switch ($QST_system) { |
|
924 | - case 'fname': |
|
925 | - $QST_values = array( |
|
926 | - 'QST_display_text' => __('First Name', 'event_espresso'), |
|
927 | - 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
928 | - 'QST_system' => 'fname', |
|
929 | - 'QST_type' => 'TEXT', |
|
930 | - 'QST_required' => 1, |
|
931 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
932 | - 'QST_order' => 1, |
|
933 | - 'QST_admin_only' => 0, |
|
934 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
935 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
936 | - 'QST_deleted' => 0, |
|
937 | - ); |
|
938 | - break; |
|
939 | - case 'lname': |
|
940 | - $QST_values = array( |
|
941 | - 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
942 | - 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
943 | - 'QST_system' => 'lname', |
|
944 | - 'QST_type' => 'TEXT', |
|
945 | - 'QST_required' => 1, |
|
946 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
947 | - 'QST_order' => 2, |
|
948 | - 'QST_admin_only' => 0, |
|
949 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
950 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
951 | - 'QST_deleted' => 0, |
|
952 | - ); |
|
953 | - break; |
|
954 | - case 'email': |
|
955 | - $QST_values = array( |
|
956 | - 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
957 | - 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
958 | - 'QST_system' => 'email', |
|
959 | - 'QST_type' => 'EMAIL', |
|
960 | - 'QST_required' => 1, |
|
961 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
962 | - 'QST_order' => 3, |
|
963 | - 'QST_admin_only' => 0, |
|
964 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
965 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
966 | - 'QST_deleted' => 0, |
|
967 | - ); |
|
968 | - break; |
|
969 | - case 'address': |
|
970 | - $QST_values = array( |
|
971 | - 'QST_display_text' => __('Address', 'event_espresso'), |
|
972 | - 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
973 | - 'QST_system' => 'address', |
|
974 | - 'QST_type' => 'TEXT', |
|
975 | - 'QST_required' => 0, |
|
976 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
977 | - 'QST_order' => 4, |
|
978 | - 'QST_admin_only' => 0, |
|
979 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
980 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
981 | - 'QST_deleted' => 0, |
|
982 | - ); |
|
983 | - break; |
|
984 | - case 'address2': |
|
985 | - $QST_values = array( |
|
986 | - 'QST_display_text' => __('Address2', 'event_espresso'), |
|
987 | - 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
988 | - 'QST_system' => 'address2', |
|
989 | - 'QST_type' => 'TEXT', |
|
990 | - 'QST_required' => 0, |
|
991 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
992 | - 'QST_order' => 5, |
|
993 | - 'QST_admin_only' => 0, |
|
994 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
995 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
996 | - 'QST_deleted' => 0, |
|
997 | - ); |
|
998 | - break; |
|
999 | - case 'city': |
|
1000 | - $QST_values = array( |
|
1001 | - 'QST_display_text' => __('City', 'event_espresso'), |
|
1002 | - 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
1003 | - 'QST_system' => 'city', |
|
1004 | - 'QST_type' => 'TEXT', |
|
1005 | - 'QST_required' => 0, |
|
1006 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1007 | - 'QST_order' => 6, |
|
1008 | - 'QST_admin_only' => 0, |
|
1009 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1010 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1011 | - 'QST_deleted' => 0, |
|
1012 | - ); |
|
1013 | - break; |
|
1014 | - case 'country': |
|
1015 | - $QST_values = array( |
|
1016 | - 'QST_display_text' => __('Country', 'event_espresso'), |
|
1017 | - 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
1018 | - 'QST_system' => 'country', |
|
1019 | - 'QST_type' => 'COUNTRY', |
|
1020 | - 'QST_required' => 0, |
|
1021 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1022 | - 'QST_order' => 7, |
|
1023 | - 'QST_admin_only' => 0, |
|
1024 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1025 | - 'QST_deleted' => 0, |
|
1026 | - ); |
|
1027 | - break; |
|
1028 | - case 'state': |
|
1029 | - $QST_values = array( |
|
1030 | - 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
1031 | - 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
1032 | - 'QST_system' => 'state', |
|
1033 | - 'QST_type' => 'STATE', |
|
1034 | - 'QST_required' => 0, |
|
1035 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1036 | - 'QST_order' => 8, |
|
1037 | - 'QST_admin_only' => 0, |
|
1038 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1039 | - 'QST_deleted' => 0, |
|
1040 | - ); |
|
1041 | - break; |
|
1042 | - case 'zip': |
|
1043 | - $QST_values = array( |
|
1044 | - 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
1045 | - 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
1046 | - 'QST_system' => 'zip', |
|
1047 | - 'QST_type' => 'TEXT', |
|
1048 | - 'QST_required' => 0, |
|
1049 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1050 | - 'QST_order' => 9, |
|
1051 | - 'QST_admin_only' => 0, |
|
1052 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1053 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1054 | - 'QST_deleted' => 0, |
|
1055 | - ); |
|
1056 | - break; |
|
1057 | - case 'phone': |
|
1058 | - $QST_values = array( |
|
1059 | - 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
1060 | - 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
1061 | - 'QST_system' => 'phone', |
|
1062 | - 'QST_type' => 'TEXT', |
|
1063 | - 'QST_required' => 0, |
|
1064 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1065 | - 'QST_order' => 10, |
|
1066 | - 'QST_admin_only' => 0, |
|
1067 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1068 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
1069 | - 'QST_deleted' => 0, |
|
1070 | - ); |
|
1071 | - break; |
|
1072 | - } |
|
1073 | - if (! empty($QST_values)) { |
|
1074 | - // insert system question |
|
1075 | - $wpdb->insert( |
|
1076 | - $table_name, |
|
1077 | - $QST_values, |
|
1078 | - array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
1079 | - ); |
|
1080 | - $QST_ID = $wpdb->insert_id; |
|
1081 | - // QUESTION GROUP QUESTIONS |
|
1082 | - if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
1083 | - $system_question_we_want = EEM_Question_Group::system_personal; |
|
1084 | - } else { |
|
1085 | - $system_question_we_want = EEM_Question_Group::system_address; |
|
1086 | - } |
|
1087 | - if (isset($QSG_IDs[ $system_question_we_want ])) { |
|
1088 | - $QSG_ID = $QSG_IDs[ $system_question_we_want ]; |
|
1089 | - } else { |
|
1090 | - $id_col = EEM_Question_Group::instance() |
|
1091 | - ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
1092 | - if (is_array($id_col)) { |
|
1093 | - $QSG_ID = reset($id_col); |
|
1094 | - } else { |
|
1095 | - // ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
1096 | - EE_Log::instance()->log( |
|
1097 | - __FILE__, |
|
1098 | - __FUNCTION__, |
|
1099 | - sprintf( |
|
1100 | - __( |
|
1101 | - 'Could not associate question %1$s to a question group because no system question |
|
818 | + 'event_espresso' |
|
819 | + ), |
|
820 | + __FILE__, |
|
821 | + __FUNCTION__, |
|
822 | + __LINE__ |
|
823 | + ); |
|
824 | + return false; |
|
825 | + } |
|
826 | + return true; |
|
827 | + } |
|
828 | + |
|
829 | + |
|
830 | + |
|
831 | + /** |
|
832 | + * initialize_system_questions |
|
833 | + * |
|
834 | + * @access public |
|
835 | + * @static |
|
836 | + * @return void |
|
837 | + */ |
|
838 | + public static function initialize_system_questions() |
|
839 | + { |
|
840 | + // QUESTION GROUPS |
|
841 | + global $wpdb; |
|
842 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
843 | + $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
844 | + // what we have |
|
845 | + $question_groups = $wpdb->get_col($SQL); |
|
846 | + // check the response |
|
847 | + $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
848 | + // what we should have |
|
849 | + $QSG_systems = array(1, 2); |
|
850 | + // loop thru what we should have and compare to what we have |
|
851 | + foreach ($QSG_systems as $QSG_system) { |
|
852 | + // reset values array |
|
853 | + $QSG_values = array(); |
|
854 | + // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
855 | + if (! in_array("$QSG_system", $question_groups)) { |
|
856 | + // add it |
|
857 | + switch ($QSG_system) { |
|
858 | + case 1: |
|
859 | + $QSG_values = array( |
|
860 | + 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
861 | + 'QSG_identifier' => 'personal-information-' . time(), |
|
862 | + 'QSG_desc' => '', |
|
863 | + 'QSG_order' => 1, |
|
864 | + 'QSG_show_group_name' => 1, |
|
865 | + 'QSG_show_group_desc' => 1, |
|
866 | + 'QSG_system' => EEM_Question_Group::system_personal, |
|
867 | + 'QSG_deleted' => 0, |
|
868 | + ); |
|
869 | + break; |
|
870 | + case 2: |
|
871 | + $QSG_values = array( |
|
872 | + 'QSG_name' => __('Address Information', 'event_espresso'), |
|
873 | + 'QSG_identifier' => 'address-information-' . time(), |
|
874 | + 'QSG_desc' => '', |
|
875 | + 'QSG_order' => 2, |
|
876 | + 'QSG_show_group_name' => 1, |
|
877 | + 'QSG_show_group_desc' => 1, |
|
878 | + 'QSG_system' => EEM_Question_Group::system_address, |
|
879 | + 'QSG_deleted' => 0, |
|
880 | + ); |
|
881 | + break; |
|
882 | + } |
|
883 | + // make sure we have some values before inserting them |
|
884 | + if (! empty($QSG_values)) { |
|
885 | + // insert system question |
|
886 | + $wpdb->insert( |
|
887 | + $table_name, |
|
888 | + $QSG_values, |
|
889 | + array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
890 | + ); |
|
891 | + $QSG_IDs[ $QSG_system ] = $wpdb->insert_id; |
|
892 | + } |
|
893 | + } |
|
894 | + } |
|
895 | + // QUESTIONS |
|
896 | + global $wpdb; |
|
897 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
898 | + $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
899 | + // what we have |
|
900 | + $questions = $wpdb->get_col($SQL); |
|
901 | + // what we should have |
|
902 | + $QST_systems = array( |
|
903 | + 'fname', |
|
904 | + 'lname', |
|
905 | + 'email', |
|
906 | + 'address', |
|
907 | + 'address2', |
|
908 | + 'city', |
|
909 | + 'country', |
|
910 | + 'state', |
|
911 | + 'zip', |
|
912 | + 'phone', |
|
913 | + ); |
|
914 | + $order_for_group_1 = 1; |
|
915 | + $order_for_group_2 = 1; |
|
916 | + // loop thru what we should have and compare to what we have |
|
917 | + foreach ($QST_systems as $QST_system) { |
|
918 | + // reset values array |
|
919 | + $QST_values = array(); |
|
920 | + // if we don't have what we should have |
|
921 | + if (! in_array($QST_system, $questions)) { |
|
922 | + // add it |
|
923 | + switch ($QST_system) { |
|
924 | + case 'fname': |
|
925 | + $QST_values = array( |
|
926 | + 'QST_display_text' => __('First Name', 'event_espresso'), |
|
927 | + 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
928 | + 'QST_system' => 'fname', |
|
929 | + 'QST_type' => 'TEXT', |
|
930 | + 'QST_required' => 1, |
|
931 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
932 | + 'QST_order' => 1, |
|
933 | + 'QST_admin_only' => 0, |
|
934 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
935 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
936 | + 'QST_deleted' => 0, |
|
937 | + ); |
|
938 | + break; |
|
939 | + case 'lname': |
|
940 | + $QST_values = array( |
|
941 | + 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
942 | + 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
943 | + 'QST_system' => 'lname', |
|
944 | + 'QST_type' => 'TEXT', |
|
945 | + 'QST_required' => 1, |
|
946 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
947 | + 'QST_order' => 2, |
|
948 | + 'QST_admin_only' => 0, |
|
949 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
950 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
951 | + 'QST_deleted' => 0, |
|
952 | + ); |
|
953 | + break; |
|
954 | + case 'email': |
|
955 | + $QST_values = array( |
|
956 | + 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
957 | + 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
958 | + 'QST_system' => 'email', |
|
959 | + 'QST_type' => 'EMAIL', |
|
960 | + 'QST_required' => 1, |
|
961 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
962 | + 'QST_order' => 3, |
|
963 | + 'QST_admin_only' => 0, |
|
964 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
965 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
966 | + 'QST_deleted' => 0, |
|
967 | + ); |
|
968 | + break; |
|
969 | + case 'address': |
|
970 | + $QST_values = array( |
|
971 | + 'QST_display_text' => __('Address', 'event_espresso'), |
|
972 | + 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
973 | + 'QST_system' => 'address', |
|
974 | + 'QST_type' => 'TEXT', |
|
975 | + 'QST_required' => 0, |
|
976 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
977 | + 'QST_order' => 4, |
|
978 | + 'QST_admin_only' => 0, |
|
979 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
980 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
981 | + 'QST_deleted' => 0, |
|
982 | + ); |
|
983 | + break; |
|
984 | + case 'address2': |
|
985 | + $QST_values = array( |
|
986 | + 'QST_display_text' => __('Address2', 'event_espresso'), |
|
987 | + 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
988 | + 'QST_system' => 'address2', |
|
989 | + 'QST_type' => 'TEXT', |
|
990 | + 'QST_required' => 0, |
|
991 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
992 | + 'QST_order' => 5, |
|
993 | + 'QST_admin_only' => 0, |
|
994 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
995 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
996 | + 'QST_deleted' => 0, |
|
997 | + ); |
|
998 | + break; |
|
999 | + case 'city': |
|
1000 | + $QST_values = array( |
|
1001 | + 'QST_display_text' => __('City', 'event_espresso'), |
|
1002 | + 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
1003 | + 'QST_system' => 'city', |
|
1004 | + 'QST_type' => 'TEXT', |
|
1005 | + 'QST_required' => 0, |
|
1006 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1007 | + 'QST_order' => 6, |
|
1008 | + 'QST_admin_only' => 0, |
|
1009 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1010 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1011 | + 'QST_deleted' => 0, |
|
1012 | + ); |
|
1013 | + break; |
|
1014 | + case 'country': |
|
1015 | + $QST_values = array( |
|
1016 | + 'QST_display_text' => __('Country', 'event_espresso'), |
|
1017 | + 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
1018 | + 'QST_system' => 'country', |
|
1019 | + 'QST_type' => 'COUNTRY', |
|
1020 | + 'QST_required' => 0, |
|
1021 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1022 | + 'QST_order' => 7, |
|
1023 | + 'QST_admin_only' => 0, |
|
1024 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1025 | + 'QST_deleted' => 0, |
|
1026 | + ); |
|
1027 | + break; |
|
1028 | + case 'state': |
|
1029 | + $QST_values = array( |
|
1030 | + 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
1031 | + 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
1032 | + 'QST_system' => 'state', |
|
1033 | + 'QST_type' => 'STATE', |
|
1034 | + 'QST_required' => 0, |
|
1035 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1036 | + 'QST_order' => 8, |
|
1037 | + 'QST_admin_only' => 0, |
|
1038 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1039 | + 'QST_deleted' => 0, |
|
1040 | + ); |
|
1041 | + break; |
|
1042 | + case 'zip': |
|
1043 | + $QST_values = array( |
|
1044 | + 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
1045 | + 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
1046 | + 'QST_system' => 'zip', |
|
1047 | + 'QST_type' => 'TEXT', |
|
1048 | + 'QST_required' => 0, |
|
1049 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1050 | + 'QST_order' => 9, |
|
1051 | + 'QST_admin_only' => 0, |
|
1052 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1053 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1054 | + 'QST_deleted' => 0, |
|
1055 | + ); |
|
1056 | + break; |
|
1057 | + case 'phone': |
|
1058 | + $QST_values = array( |
|
1059 | + 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
1060 | + 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
1061 | + 'QST_system' => 'phone', |
|
1062 | + 'QST_type' => 'TEXT', |
|
1063 | + 'QST_required' => 0, |
|
1064 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
1065 | + 'QST_order' => 10, |
|
1066 | + 'QST_admin_only' => 0, |
|
1067 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
1068 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
1069 | + 'QST_deleted' => 0, |
|
1070 | + ); |
|
1071 | + break; |
|
1072 | + } |
|
1073 | + if (! empty($QST_values)) { |
|
1074 | + // insert system question |
|
1075 | + $wpdb->insert( |
|
1076 | + $table_name, |
|
1077 | + $QST_values, |
|
1078 | + array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
1079 | + ); |
|
1080 | + $QST_ID = $wpdb->insert_id; |
|
1081 | + // QUESTION GROUP QUESTIONS |
|
1082 | + if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
1083 | + $system_question_we_want = EEM_Question_Group::system_personal; |
|
1084 | + } else { |
|
1085 | + $system_question_we_want = EEM_Question_Group::system_address; |
|
1086 | + } |
|
1087 | + if (isset($QSG_IDs[ $system_question_we_want ])) { |
|
1088 | + $QSG_ID = $QSG_IDs[ $system_question_we_want ]; |
|
1089 | + } else { |
|
1090 | + $id_col = EEM_Question_Group::instance() |
|
1091 | + ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
1092 | + if (is_array($id_col)) { |
|
1093 | + $QSG_ID = reset($id_col); |
|
1094 | + } else { |
|
1095 | + // ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
1096 | + EE_Log::instance()->log( |
|
1097 | + __FILE__, |
|
1098 | + __FUNCTION__, |
|
1099 | + sprintf( |
|
1100 | + __( |
|
1101 | + 'Could not associate question %1$s to a question group because no system question |
|
1102 | 1102 | group existed', |
1103 | - 'event_espresso' |
|
1104 | - ), |
|
1105 | - $QST_ID |
|
1106 | - ), |
|
1107 | - 'error' |
|
1108 | - ); |
|
1109 | - continue; |
|
1110 | - } |
|
1111 | - } |
|
1112 | - // add system questions to groups |
|
1113 | - $wpdb->insert( |
|
1114 | - \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
1115 | - array( |
|
1116 | - 'QSG_ID' => $QSG_ID, |
|
1117 | - 'QST_ID' => $QST_ID, |
|
1118 | - 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
1119 | - ), |
|
1120 | - array('%d', '%d', '%d') |
|
1121 | - ); |
|
1122 | - } |
|
1123 | - } |
|
1124 | - } |
|
1125 | - } |
|
1126 | - |
|
1127 | - |
|
1128 | - /** |
|
1129 | - * Makes sure the default payment method (Invoice) is active. |
|
1130 | - * This used to be done automatically as part of constructing the old gateways config |
|
1131 | - * |
|
1132 | - * @throws \EE_Error |
|
1133 | - */ |
|
1134 | - public static function insert_default_payment_methods() |
|
1135 | - { |
|
1136 | - if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1137 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
1138 | - EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
1139 | - } else { |
|
1140 | - EEM_Payment_Method::instance()->verify_button_urls(); |
|
1141 | - } |
|
1142 | - } |
|
1143 | - |
|
1144 | - /** |
|
1145 | - * insert_default_status_codes |
|
1146 | - * |
|
1147 | - * @access public |
|
1148 | - * @static |
|
1149 | - * @return void |
|
1150 | - */ |
|
1151 | - public static function insert_default_status_codes() |
|
1152 | - { |
|
1153 | - |
|
1154 | - global $wpdb; |
|
1155 | - |
|
1156 | - if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
1157 | - $table_name = EEM_Status::instance()->table(); |
|
1158 | - |
|
1159 | - $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
1160 | - $wpdb->query($SQL); |
|
1161 | - |
|
1162 | - $SQL = "INSERT INTO $table_name |
|
1103 | + 'event_espresso' |
|
1104 | + ), |
|
1105 | + $QST_ID |
|
1106 | + ), |
|
1107 | + 'error' |
|
1108 | + ); |
|
1109 | + continue; |
|
1110 | + } |
|
1111 | + } |
|
1112 | + // add system questions to groups |
|
1113 | + $wpdb->insert( |
|
1114 | + \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
1115 | + array( |
|
1116 | + 'QSG_ID' => $QSG_ID, |
|
1117 | + 'QST_ID' => $QST_ID, |
|
1118 | + 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
1119 | + ), |
|
1120 | + array('%d', '%d', '%d') |
|
1121 | + ); |
|
1122 | + } |
|
1123 | + } |
|
1124 | + } |
|
1125 | + } |
|
1126 | + |
|
1127 | + |
|
1128 | + /** |
|
1129 | + * Makes sure the default payment method (Invoice) is active. |
|
1130 | + * This used to be done automatically as part of constructing the old gateways config |
|
1131 | + * |
|
1132 | + * @throws \EE_Error |
|
1133 | + */ |
|
1134 | + public static function insert_default_payment_methods() |
|
1135 | + { |
|
1136 | + if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1137 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
1138 | + EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
1139 | + } else { |
|
1140 | + EEM_Payment_Method::instance()->verify_button_urls(); |
|
1141 | + } |
|
1142 | + } |
|
1143 | + |
|
1144 | + /** |
|
1145 | + * insert_default_status_codes |
|
1146 | + * |
|
1147 | + * @access public |
|
1148 | + * @static |
|
1149 | + * @return void |
|
1150 | + */ |
|
1151 | + public static function insert_default_status_codes() |
|
1152 | + { |
|
1153 | + |
|
1154 | + global $wpdb; |
|
1155 | + |
|
1156 | + if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
1157 | + $table_name = EEM_Status::instance()->table(); |
|
1158 | + |
|
1159 | + $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
1160 | + $wpdb->query($SQL); |
|
1161 | + |
|
1162 | + $SQL = "INSERT INTO $table_name |
|
1163 | 1163 | (STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES |
1164 | 1164 | ('ACT', 'ACTIVE', 'event', 0, NULL, 1), |
1165 | 1165 | ('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0), |
@@ -1199,457 +1199,457 @@ discard block |
||
1199 | 1199 | ('MID', 'IDLE', 'message', 0, NULL, 1), |
1200 | 1200 | ('MRS', 'RESEND', 'message', 0, NULL, 1), |
1201 | 1201 | ('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);"; |
1202 | - $wpdb->query($SQL); |
|
1203 | - } |
|
1204 | - } |
|
1205 | - |
|
1206 | - |
|
1207 | - /** |
|
1208 | - * generate_default_message_templates |
|
1209 | - * |
|
1210 | - * @static |
|
1211 | - * @throws EE_Error |
|
1212 | - * @return bool true means new templates were created. |
|
1213 | - * false means no templates were created. |
|
1214 | - * This is NOT an error flag. To check for errors you will want |
|
1215 | - * to use either EE_Error or a try catch for an EE_Error exception. |
|
1216 | - */ |
|
1217 | - public static function generate_default_message_templates() |
|
1218 | - { |
|
1219 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1220 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1221 | - /* |
|
1202 | + $wpdb->query($SQL); |
|
1203 | + } |
|
1204 | + } |
|
1205 | + |
|
1206 | + |
|
1207 | + /** |
|
1208 | + * generate_default_message_templates |
|
1209 | + * |
|
1210 | + * @static |
|
1211 | + * @throws EE_Error |
|
1212 | + * @return bool true means new templates were created. |
|
1213 | + * false means no templates were created. |
|
1214 | + * This is NOT an error flag. To check for errors you will want |
|
1215 | + * to use either EE_Error or a try catch for an EE_Error exception. |
|
1216 | + */ |
|
1217 | + public static function generate_default_message_templates() |
|
1218 | + { |
|
1219 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1220 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1221 | + /* |
|
1222 | 1222 | * This first method is taking care of ensuring any default messengers |
1223 | 1223 | * that should be made active and have templates generated are done. |
1224 | 1224 | */ |
1225 | - $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
1226 | - $message_resource_manager |
|
1227 | - ); |
|
1228 | - /** |
|
1229 | - * This method is verifying there are no NEW default message types |
|
1230 | - * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
1231 | - */ |
|
1232 | - $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1233 | - $message_resource_manager |
|
1234 | - ); |
|
1235 | - // after all is done, let's persist these changes to the db. |
|
1236 | - $message_resource_manager->update_has_activated_messengers_option(); |
|
1237 | - $message_resource_manager->update_active_messengers_option(); |
|
1238 | - // will return true if either of these are true. Otherwise will return false. |
|
1239 | - return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
1240 | - } |
|
1241 | - |
|
1242 | - |
|
1243 | - |
|
1244 | - /** |
|
1245 | - * @param \EE_Message_Resource_Manager $message_resource_manager |
|
1246 | - * @return array|bool |
|
1247 | - * @throws \EE_Error |
|
1248 | - */ |
|
1249 | - protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1250 | - EE_Message_Resource_Manager $message_resource_manager |
|
1251 | - ) { |
|
1252 | - /** @type EE_messenger[] $active_messengers */ |
|
1253 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
1254 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1255 | - $templates_created = false; |
|
1256 | - foreach ($active_messengers as $active_messenger) { |
|
1257 | - $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
1258 | - $default_message_type_names_to_activate = array(); |
|
1259 | - // looping through each default message type reported by the messenger |
|
1260 | - // and setup the actual message types to activate. |
|
1261 | - foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
1262 | - // if already active or has already been activated before we skip |
|
1263 | - // (otherwise we might reactivate something user's intentionally deactivated.) |
|
1264 | - // we also skip if the message type is not installed. |
|
1265 | - if ($message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1266 | - $default_message_type_name_for_messenger, |
|
1267 | - $active_messenger->name |
|
1268 | - ) |
|
1269 | - || $message_resource_manager->is_message_type_active_for_messenger( |
|
1270 | - $active_messenger->name, |
|
1271 | - $default_message_type_name_for_messenger |
|
1272 | - ) |
|
1273 | - || ! isset($installed_message_types[ $default_message_type_name_for_messenger ]) |
|
1274 | - ) { |
|
1275 | - continue; |
|
1276 | - } |
|
1277 | - $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
1278 | - } |
|
1279 | - // let's activate! |
|
1280 | - $message_resource_manager->ensure_message_types_are_active( |
|
1281 | - $default_message_type_names_to_activate, |
|
1282 | - $active_messenger->name, |
|
1283 | - false |
|
1284 | - ); |
|
1285 | - // activate the templates for these message types |
|
1286 | - if (! empty($default_message_type_names_to_activate)) { |
|
1287 | - $templates_created = EEH_MSG_Template::generate_new_templates( |
|
1288 | - $active_messenger->name, |
|
1289 | - $default_message_type_names_for_messenger, |
|
1290 | - '', |
|
1291 | - true |
|
1292 | - ); |
|
1293 | - } |
|
1294 | - } |
|
1295 | - return $templates_created; |
|
1296 | - } |
|
1297 | - |
|
1298 | - |
|
1299 | - |
|
1300 | - /** |
|
1301 | - * This will activate and generate default messengers and default message types for those messengers. |
|
1302 | - * |
|
1303 | - * @param EE_message_Resource_Manager $message_resource_manager |
|
1304 | - * @return array|bool True means there were default messengers and message type templates generated. |
|
1305 | - * False means that there were no templates generated |
|
1306 | - * (which could simply mean there are no default message types for a messenger). |
|
1307 | - * @throws EE_Error |
|
1308 | - */ |
|
1309 | - protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
1310 | - EE_Message_Resource_Manager $message_resource_manager |
|
1311 | - ) { |
|
1312 | - /** @type EE_messenger[] $messengers_to_generate */ |
|
1313 | - $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
1314 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1315 | - $templates_generated = false; |
|
1316 | - foreach ($messengers_to_generate as $messenger_to_generate) { |
|
1317 | - $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
1318 | - // verify the default message types match an installed message type. |
|
1319 | - foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
1320 | - if (! isset($installed_message_types[ $name ]) |
|
1321 | - || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1322 | - $name, |
|
1323 | - $messenger_to_generate->name |
|
1324 | - ) |
|
1325 | - ) { |
|
1326 | - unset($default_message_type_names_for_messenger[ $key ]); |
|
1327 | - } |
|
1328 | - } |
|
1329 | - // in previous iterations, the active_messengers option in the db |
|
1330 | - // needed updated before calling create templates. however with the changes this may not be necessary. |
|
1331 | - // This comment is left here just in case we discover that we _do_ need to update before |
|
1332 | - // passing off to create templates (after the refactor is done). |
|
1333 | - // @todo remove this comment when determined not necessary. |
|
1334 | - $message_resource_manager->activate_messenger( |
|
1335 | - $messenger_to_generate->name, |
|
1336 | - $default_message_type_names_for_messenger, |
|
1337 | - false |
|
1338 | - ); |
|
1339 | - // create any templates needing created (or will reactivate templates already generated as necessary). |
|
1340 | - if (! empty($default_message_type_names_for_messenger)) { |
|
1341 | - $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
1342 | - $messenger_to_generate->name, |
|
1343 | - $default_message_type_names_for_messenger, |
|
1344 | - '', |
|
1345 | - true |
|
1346 | - ); |
|
1347 | - } |
|
1348 | - } |
|
1349 | - return $templates_generated; |
|
1350 | - } |
|
1351 | - |
|
1352 | - |
|
1353 | - /** |
|
1354 | - * This returns the default messengers to generate templates for on activation of EE. |
|
1355 | - * It considers: |
|
1356 | - * - whether a messenger is already active in the db. |
|
1357 | - * - whether a messenger has been made active at any time in the past. |
|
1358 | - * |
|
1359 | - * @static |
|
1360 | - * @param EE_Message_Resource_Manager $message_resource_manager |
|
1361 | - * @return EE_messenger[] |
|
1362 | - */ |
|
1363 | - protected static function _get_default_messengers_to_generate_on_activation( |
|
1364 | - EE_Message_Resource_Manager $message_resource_manager |
|
1365 | - ) { |
|
1366 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
1367 | - $installed_messengers = $message_resource_manager->installed_messengers(); |
|
1368 | - $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
1369 | - |
|
1370 | - $messengers_to_generate = array(); |
|
1371 | - foreach ($installed_messengers as $installed_messenger) { |
|
1372 | - // if installed messenger is a messenger that should be activated on install |
|
1373 | - // and is not already active |
|
1374 | - // and has never been activated |
|
1375 | - if (! $installed_messenger->activate_on_install |
|
1376 | - || isset($active_messengers[ $installed_messenger->name ]) |
|
1377 | - || isset($has_activated[ $installed_messenger->name ]) |
|
1378 | - ) { |
|
1379 | - continue; |
|
1380 | - } |
|
1381 | - $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger; |
|
1382 | - } |
|
1383 | - return $messengers_to_generate; |
|
1384 | - } |
|
1385 | - |
|
1386 | - |
|
1387 | - /** |
|
1388 | - * This simply validates active message types to ensure they actually match installed |
|
1389 | - * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
1390 | - * rows are set inactive. |
|
1391 | - * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
1392 | - * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
1393 | - * are still handled in here. |
|
1394 | - * |
|
1395 | - * @since 4.3.1 |
|
1396 | - * @return void |
|
1397 | - */ |
|
1398 | - public static function validate_messages_system() |
|
1399 | - { |
|
1400 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1401 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1402 | - $message_resource_manager->validate_active_message_types_are_installed(); |
|
1403 | - do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
1404 | - } |
|
1405 | - |
|
1406 | - |
|
1407 | - /** |
|
1408 | - * create_no_ticket_prices_array |
|
1409 | - * |
|
1410 | - * @access public |
|
1411 | - * @static |
|
1412 | - * @return void |
|
1413 | - */ |
|
1414 | - public static function create_no_ticket_prices_array() |
|
1415 | - { |
|
1416 | - // this creates an array for tracking events that have no active ticket prices created |
|
1417 | - // this allows us to warn admins of the situation so that it can be corrected |
|
1418 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
1419 | - if (! $espresso_no_ticket_prices) { |
|
1420 | - add_option('ee_no_ticket_prices', array(), '', false); |
|
1421 | - } |
|
1422 | - } |
|
1423 | - |
|
1424 | - |
|
1425 | - /** |
|
1426 | - * plugin_deactivation |
|
1427 | - * |
|
1428 | - * @access public |
|
1429 | - * @static |
|
1430 | - * @return void |
|
1431 | - */ |
|
1432 | - public static function plugin_deactivation() |
|
1433 | - { |
|
1434 | - } |
|
1435 | - |
|
1436 | - |
|
1437 | - /** |
|
1438 | - * Finds all our EE4 custom post types, and deletes them and their associated data |
|
1439 | - * (like post meta or term relations) |
|
1440 | - * |
|
1441 | - * @global wpdb $wpdb |
|
1442 | - * @throws \EE_Error |
|
1443 | - */ |
|
1444 | - public static function delete_all_espresso_cpt_data() |
|
1445 | - { |
|
1446 | - global $wpdb; |
|
1447 | - // get all the CPT post_types |
|
1448 | - $ee_post_types = array(); |
|
1449 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1450 | - if (method_exists($model_name, 'instance')) { |
|
1451 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
1452 | - if ($model_obj instanceof EEM_CPT_Base) { |
|
1453 | - $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
1454 | - } |
|
1455 | - } |
|
1456 | - } |
|
1457 | - // get all our CPTs |
|
1458 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
1459 | - $cpt_ids = $wpdb->get_col($query); |
|
1460 | - // delete each post meta and term relations too |
|
1461 | - foreach ($cpt_ids as $post_id) { |
|
1462 | - wp_delete_post($post_id, true); |
|
1463 | - } |
|
1464 | - } |
|
1465 | - |
|
1466 | - /** |
|
1467 | - * Deletes all EE custom tables |
|
1468 | - * |
|
1469 | - * @return array |
|
1470 | - */ |
|
1471 | - public static function drop_espresso_tables() |
|
1472 | - { |
|
1473 | - $tables = array(); |
|
1474 | - // load registry |
|
1475 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1476 | - if (method_exists($model_name, 'instance')) { |
|
1477 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
1478 | - if ($model_obj instanceof EEM_Base) { |
|
1479 | - foreach ($model_obj->get_tables() as $table) { |
|
1480 | - if (strpos($table->get_table_name(), 'esp_') |
|
1481 | - && |
|
1482 | - ( |
|
1483 | - is_main_site()// main site? nuke them all |
|
1484 | - || ! $table->is_global()// not main site,but not global either. nuke it |
|
1485 | - ) |
|
1486 | - ) { |
|
1487 | - $tables[ $table->get_table_name() ] = $table->get_table_name(); |
|
1488 | - } |
|
1489 | - } |
|
1490 | - } |
|
1491 | - } |
|
1492 | - } |
|
1493 | - |
|
1494 | - // there are some tables whose models were removed. |
|
1495 | - // they should be removed when removing all EE core's data |
|
1496 | - $tables_without_models = array( |
|
1497 | - 'esp_promotion', |
|
1498 | - 'esp_promotion_applied', |
|
1499 | - 'esp_promotion_object', |
|
1500 | - 'esp_promotion_rule', |
|
1501 | - 'esp_rule', |
|
1502 | - ); |
|
1503 | - foreach ($tables_without_models as $table) { |
|
1504 | - $tables[ $table ] = $table; |
|
1505 | - } |
|
1506 | - return \EEH_Activation::getTableManager()->dropTables($tables); |
|
1507 | - } |
|
1508 | - |
|
1509 | - |
|
1510 | - |
|
1511 | - /** |
|
1512 | - * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
1513 | - * each table name provided has a wpdb prefix attached, and that it exists. |
|
1514 | - * Returns the list actually deleted |
|
1515 | - * |
|
1516 | - * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
1517 | - * @global WPDB $wpdb |
|
1518 | - * @param array $table_names |
|
1519 | - * @return array of table names which we deleted |
|
1520 | - */ |
|
1521 | - public static function drop_tables($table_names) |
|
1522 | - { |
|
1523 | - return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
1524 | - } |
|
1525 | - |
|
1526 | - |
|
1527 | - |
|
1528 | - /** |
|
1529 | - * plugin_uninstall |
|
1530 | - * |
|
1531 | - * @access public |
|
1532 | - * @static |
|
1533 | - * @param bool $remove_all |
|
1534 | - * @return void |
|
1535 | - */ |
|
1536 | - public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
1537 | - { |
|
1538 | - global $wpdb; |
|
1539 | - self::drop_espresso_tables(); |
|
1540 | - $wp_options_to_delete = array( |
|
1541 | - 'ee_no_ticket_prices' => true, |
|
1542 | - 'ee_active_messengers' => true, |
|
1543 | - 'ee_has_activated_messenger' => true, |
|
1544 | - RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES => true, |
|
1545 | - 'ee_config' => false, |
|
1546 | - 'ee_data_migration_current_db_state' => true, |
|
1547 | - 'ee_data_migration_mapping_' => false, |
|
1548 | - 'ee_data_migration_script_' => false, |
|
1549 | - 'ee_data_migrations' => true, |
|
1550 | - 'ee_dms_map' => false, |
|
1551 | - 'ee_notices' => true, |
|
1552 | - 'lang_file_check_' => false, |
|
1553 | - 'ee_maintenance_mode' => true, |
|
1554 | - 'ee_ueip_optin' => true, |
|
1555 | - 'ee_ueip_has_notified' => true, |
|
1556 | - 'ee_plugin_activation_errors' => true, |
|
1557 | - 'ee_id_mapping_from' => false, |
|
1558 | - 'espresso_persistent_admin_notices' => true, |
|
1559 | - 'ee_encryption_key' => true, |
|
1560 | - 'pue_force_upgrade_' => false, |
|
1561 | - 'pue_json_error_' => false, |
|
1562 | - 'pue_install_key_' => false, |
|
1563 | - 'pue_verification_error_' => false, |
|
1564 | - 'pu_dismissed_upgrade_' => false, |
|
1565 | - 'external_updates-' => false, |
|
1566 | - 'ee_extra_data' => true, |
|
1567 | - 'ee_ssn_' => false, |
|
1568 | - 'ee_rss_' => false, |
|
1569 | - 'ee_rte_n_tx_' => false, |
|
1570 | - 'ee_pers_admin_notices' => true, |
|
1571 | - 'ee_job_parameters_' => false, |
|
1572 | - 'ee_upload_directories_incomplete' => true, |
|
1573 | - 'ee_verified_db_collations' => true, |
|
1574 | - ); |
|
1575 | - if (is_main_site()) { |
|
1576 | - $wp_options_to_delete['ee_network_config'] = true; |
|
1577 | - } |
|
1578 | - $undeleted_options = array(); |
|
1579 | - foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
1580 | - if ($no_wildcard) { |
|
1581 | - if (! delete_option($option_name)) { |
|
1582 | - $undeleted_options[] = $option_name; |
|
1583 | - } |
|
1584 | - } else { |
|
1585 | - $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
1586 | - foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
1587 | - if (! delete_option($option_name_from_wildcard)) { |
|
1588 | - $undeleted_options[] = $option_name_from_wildcard; |
|
1589 | - } |
|
1590 | - } |
|
1591 | - } |
|
1592 | - } |
|
1593 | - // also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
1594 | - remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
1595 | - if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
1596 | - $db_update_sans_ee4 = array(); |
|
1597 | - foreach ($espresso_db_update as $version => $times_activated) { |
|
1598 | - if ((string) $version[0] === '3') {// if its NON EE4 |
|
1599 | - $db_update_sans_ee4[ $version ] = $times_activated; |
|
1600 | - } |
|
1601 | - } |
|
1602 | - update_option('espresso_db_update', $db_update_sans_ee4); |
|
1603 | - } |
|
1604 | - $errors = ''; |
|
1605 | - if (! empty($undeleted_options)) { |
|
1606 | - $errors .= sprintf( |
|
1607 | - __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
1608 | - '<br/>', |
|
1609 | - implode(',<br/>', $undeleted_options) |
|
1610 | - ); |
|
1611 | - } |
|
1612 | - if (! empty($errors)) { |
|
1613 | - EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
1614 | - } |
|
1615 | - } |
|
1616 | - |
|
1617 | - /** |
|
1618 | - * Gets the mysql error code from the last used query by wpdb |
|
1619 | - * |
|
1620 | - * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
1621 | - */ |
|
1622 | - public static function last_wpdb_error_code() |
|
1623 | - { |
|
1624 | - // phpcs:disable PHPCompatibility.PHP.RemovedExtensions.mysql_DeprecatedRemoved |
|
1625 | - global $wpdb; |
|
1626 | - if ($wpdb->use_mysqli) { |
|
1627 | - return mysqli_errno($wpdb->dbh); |
|
1628 | - } else { |
|
1629 | - return mysql_errno($wpdb->dbh); |
|
1630 | - } |
|
1631 | - // phpcs:enable |
|
1632 | - } |
|
1633 | - |
|
1634 | - /** |
|
1635 | - * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
1636 | - * |
|
1637 | - * @global wpdb $wpdb |
|
1638 | - * @deprecated instead use TableAnalysis::tableExists() |
|
1639 | - * @param string $table_name with or without $wpdb->prefix |
|
1640 | - * @return boolean |
|
1641 | - */ |
|
1642 | - public static function table_exists($table_name) |
|
1643 | - { |
|
1644 | - return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
1645 | - } |
|
1646 | - |
|
1647 | - /** |
|
1648 | - * Resets the cache on EEH_Activation |
|
1649 | - */ |
|
1650 | - public static function reset() |
|
1651 | - { |
|
1652 | - self::$_default_creator_id = null; |
|
1653 | - self::$_initialized_db_content_already_in_this_request = false; |
|
1654 | - } |
|
1225 | + $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
1226 | + $message_resource_manager |
|
1227 | + ); |
|
1228 | + /** |
|
1229 | + * This method is verifying there are no NEW default message types |
|
1230 | + * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
1231 | + */ |
|
1232 | + $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1233 | + $message_resource_manager |
|
1234 | + ); |
|
1235 | + // after all is done, let's persist these changes to the db. |
|
1236 | + $message_resource_manager->update_has_activated_messengers_option(); |
|
1237 | + $message_resource_manager->update_active_messengers_option(); |
|
1238 | + // will return true if either of these are true. Otherwise will return false. |
|
1239 | + return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
1240 | + } |
|
1241 | + |
|
1242 | + |
|
1243 | + |
|
1244 | + /** |
|
1245 | + * @param \EE_Message_Resource_Manager $message_resource_manager |
|
1246 | + * @return array|bool |
|
1247 | + * @throws \EE_Error |
|
1248 | + */ |
|
1249 | + protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
1250 | + EE_Message_Resource_Manager $message_resource_manager |
|
1251 | + ) { |
|
1252 | + /** @type EE_messenger[] $active_messengers */ |
|
1253 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
1254 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1255 | + $templates_created = false; |
|
1256 | + foreach ($active_messengers as $active_messenger) { |
|
1257 | + $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
1258 | + $default_message_type_names_to_activate = array(); |
|
1259 | + // looping through each default message type reported by the messenger |
|
1260 | + // and setup the actual message types to activate. |
|
1261 | + foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
1262 | + // if already active or has already been activated before we skip |
|
1263 | + // (otherwise we might reactivate something user's intentionally deactivated.) |
|
1264 | + // we also skip if the message type is not installed. |
|
1265 | + if ($message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1266 | + $default_message_type_name_for_messenger, |
|
1267 | + $active_messenger->name |
|
1268 | + ) |
|
1269 | + || $message_resource_manager->is_message_type_active_for_messenger( |
|
1270 | + $active_messenger->name, |
|
1271 | + $default_message_type_name_for_messenger |
|
1272 | + ) |
|
1273 | + || ! isset($installed_message_types[ $default_message_type_name_for_messenger ]) |
|
1274 | + ) { |
|
1275 | + continue; |
|
1276 | + } |
|
1277 | + $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
1278 | + } |
|
1279 | + // let's activate! |
|
1280 | + $message_resource_manager->ensure_message_types_are_active( |
|
1281 | + $default_message_type_names_to_activate, |
|
1282 | + $active_messenger->name, |
|
1283 | + false |
|
1284 | + ); |
|
1285 | + // activate the templates for these message types |
|
1286 | + if (! empty($default_message_type_names_to_activate)) { |
|
1287 | + $templates_created = EEH_MSG_Template::generate_new_templates( |
|
1288 | + $active_messenger->name, |
|
1289 | + $default_message_type_names_for_messenger, |
|
1290 | + '', |
|
1291 | + true |
|
1292 | + ); |
|
1293 | + } |
|
1294 | + } |
|
1295 | + return $templates_created; |
|
1296 | + } |
|
1297 | + |
|
1298 | + |
|
1299 | + |
|
1300 | + /** |
|
1301 | + * This will activate and generate default messengers and default message types for those messengers. |
|
1302 | + * |
|
1303 | + * @param EE_message_Resource_Manager $message_resource_manager |
|
1304 | + * @return array|bool True means there were default messengers and message type templates generated. |
|
1305 | + * False means that there were no templates generated |
|
1306 | + * (which could simply mean there are no default message types for a messenger). |
|
1307 | + * @throws EE_Error |
|
1308 | + */ |
|
1309 | + protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
1310 | + EE_Message_Resource_Manager $message_resource_manager |
|
1311 | + ) { |
|
1312 | + /** @type EE_messenger[] $messengers_to_generate */ |
|
1313 | + $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
1314 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
1315 | + $templates_generated = false; |
|
1316 | + foreach ($messengers_to_generate as $messenger_to_generate) { |
|
1317 | + $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
1318 | + // verify the default message types match an installed message type. |
|
1319 | + foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
1320 | + if (! isset($installed_message_types[ $name ]) |
|
1321 | + || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
1322 | + $name, |
|
1323 | + $messenger_to_generate->name |
|
1324 | + ) |
|
1325 | + ) { |
|
1326 | + unset($default_message_type_names_for_messenger[ $key ]); |
|
1327 | + } |
|
1328 | + } |
|
1329 | + // in previous iterations, the active_messengers option in the db |
|
1330 | + // needed updated before calling create templates. however with the changes this may not be necessary. |
|
1331 | + // This comment is left here just in case we discover that we _do_ need to update before |
|
1332 | + // passing off to create templates (after the refactor is done). |
|
1333 | + // @todo remove this comment when determined not necessary. |
|
1334 | + $message_resource_manager->activate_messenger( |
|
1335 | + $messenger_to_generate->name, |
|
1336 | + $default_message_type_names_for_messenger, |
|
1337 | + false |
|
1338 | + ); |
|
1339 | + // create any templates needing created (or will reactivate templates already generated as necessary). |
|
1340 | + if (! empty($default_message_type_names_for_messenger)) { |
|
1341 | + $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
1342 | + $messenger_to_generate->name, |
|
1343 | + $default_message_type_names_for_messenger, |
|
1344 | + '', |
|
1345 | + true |
|
1346 | + ); |
|
1347 | + } |
|
1348 | + } |
|
1349 | + return $templates_generated; |
|
1350 | + } |
|
1351 | + |
|
1352 | + |
|
1353 | + /** |
|
1354 | + * This returns the default messengers to generate templates for on activation of EE. |
|
1355 | + * It considers: |
|
1356 | + * - whether a messenger is already active in the db. |
|
1357 | + * - whether a messenger has been made active at any time in the past. |
|
1358 | + * |
|
1359 | + * @static |
|
1360 | + * @param EE_Message_Resource_Manager $message_resource_manager |
|
1361 | + * @return EE_messenger[] |
|
1362 | + */ |
|
1363 | + protected static function _get_default_messengers_to_generate_on_activation( |
|
1364 | + EE_Message_Resource_Manager $message_resource_manager |
|
1365 | + ) { |
|
1366 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
1367 | + $installed_messengers = $message_resource_manager->installed_messengers(); |
|
1368 | + $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
1369 | + |
|
1370 | + $messengers_to_generate = array(); |
|
1371 | + foreach ($installed_messengers as $installed_messenger) { |
|
1372 | + // if installed messenger is a messenger that should be activated on install |
|
1373 | + // and is not already active |
|
1374 | + // and has never been activated |
|
1375 | + if (! $installed_messenger->activate_on_install |
|
1376 | + || isset($active_messengers[ $installed_messenger->name ]) |
|
1377 | + || isset($has_activated[ $installed_messenger->name ]) |
|
1378 | + ) { |
|
1379 | + continue; |
|
1380 | + } |
|
1381 | + $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger; |
|
1382 | + } |
|
1383 | + return $messengers_to_generate; |
|
1384 | + } |
|
1385 | + |
|
1386 | + |
|
1387 | + /** |
|
1388 | + * This simply validates active message types to ensure they actually match installed |
|
1389 | + * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
1390 | + * rows are set inactive. |
|
1391 | + * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
1392 | + * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
1393 | + * are still handled in here. |
|
1394 | + * |
|
1395 | + * @since 4.3.1 |
|
1396 | + * @return void |
|
1397 | + */ |
|
1398 | + public static function validate_messages_system() |
|
1399 | + { |
|
1400 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
1401 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
1402 | + $message_resource_manager->validate_active_message_types_are_installed(); |
|
1403 | + do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
1404 | + } |
|
1405 | + |
|
1406 | + |
|
1407 | + /** |
|
1408 | + * create_no_ticket_prices_array |
|
1409 | + * |
|
1410 | + * @access public |
|
1411 | + * @static |
|
1412 | + * @return void |
|
1413 | + */ |
|
1414 | + public static function create_no_ticket_prices_array() |
|
1415 | + { |
|
1416 | + // this creates an array for tracking events that have no active ticket prices created |
|
1417 | + // this allows us to warn admins of the situation so that it can be corrected |
|
1418 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
1419 | + if (! $espresso_no_ticket_prices) { |
|
1420 | + add_option('ee_no_ticket_prices', array(), '', false); |
|
1421 | + } |
|
1422 | + } |
|
1423 | + |
|
1424 | + |
|
1425 | + /** |
|
1426 | + * plugin_deactivation |
|
1427 | + * |
|
1428 | + * @access public |
|
1429 | + * @static |
|
1430 | + * @return void |
|
1431 | + */ |
|
1432 | + public static function plugin_deactivation() |
|
1433 | + { |
|
1434 | + } |
|
1435 | + |
|
1436 | + |
|
1437 | + /** |
|
1438 | + * Finds all our EE4 custom post types, and deletes them and their associated data |
|
1439 | + * (like post meta or term relations) |
|
1440 | + * |
|
1441 | + * @global wpdb $wpdb |
|
1442 | + * @throws \EE_Error |
|
1443 | + */ |
|
1444 | + public static function delete_all_espresso_cpt_data() |
|
1445 | + { |
|
1446 | + global $wpdb; |
|
1447 | + // get all the CPT post_types |
|
1448 | + $ee_post_types = array(); |
|
1449 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1450 | + if (method_exists($model_name, 'instance')) { |
|
1451 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
1452 | + if ($model_obj instanceof EEM_CPT_Base) { |
|
1453 | + $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
1454 | + } |
|
1455 | + } |
|
1456 | + } |
|
1457 | + // get all our CPTs |
|
1458 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
1459 | + $cpt_ids = $wpdb->get_col($query); |
|
1460 | + // delete each post meta and term relations too |
|
1461 | + foreach ($cpt_ids as $post_id) { |
|
1462 | + wp_delete_post($post_id, true); |
|
1463 | + } |
|
1464 | + } |
|
1465 | + |
|
1466 | + /** |
|
1467 | + * Deletes all EE custom tables |
|
1468 | + * |
|
1469 | + * @return array |
|
1470 | + */ |
|
1471 | + public static function drop_espresso_tables() |
|
1472 | + { |
|
1473 | + $tables = array(); |
|
1474 | + // load registry |
|
1475 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
1476 | + if (method_exists($model_name, 'instance')) { |
|
1477 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
1478 | + if ($model_obj instanceof EEM_Base) { |
|
1479 | + foreach ($model_obj->get_tables() as $table) { |
|
1480 | + if (strpos($table->get_table_name(), 'esp_') |
|
1481 | + && |
|
1482 | + ( |
|
1483 | + is_main_site()// main site? nuke them all |
|
1484 | + || ! $table->is_global()// not main site,but not global either. nuke it |
|
1485 | + ) |
|
1486 | + ) { |
|
1487 | + $tables[ $table->get_table_name() ] = $table->get_table_name(); |
|
1488 | + } |
|
1489 | + } |
|
1490 | + } |
|
1491 | + } |
|
1492 | + } |
|
1493 | + |
|
1494 | + // there are some tables whose models were removed. |
|
1495 | + // they should be removed when removing all EE core's data |
|
1496 | + $tables_without_models = array( |
|
1497 | + 'esp_promotion', |
|
1498 | + 'esp_promotion_applied', |
|
1499 | + 'esp_promotion_object', |
|
1500 | + 'esp_promotion_rule', |
|
1501 | + 'esp_rule', |
|
1502 | + ); |
|
1503 | + foreach ($tables_without_models as $table) { |
|
1504 | + $tables[ $table ] = $table; |
|
1505 | + } |
|
1506 | + return \EEH_Activation::getTableManager()->dropTables($tables); |
|
1507 | + } |
|
1508 | + |
|
1509 | + |
|
1510 | + |
|
1511 | + /** |
|
1512 | + * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
1513 | + * each table name provided has a wpdb prefix attached, and that it exists. |
|
1514 | + * Returns the list actually deleted |
|
1515 | + * |
|
1516 | + * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
1517 | + * @global WPDB $wpdb |
|
1518 | + * @param array $table_names |
|
1519 | + * @return array of table names which we deleted |
|
1520 | + */ |
|
1521 | + public static function drop_tables($table_names) |
|
1522 | + { |
|
1523 | + return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
1524 | + } |
|
1525 | + |
|
1526 | + |
|
1527 | + |
|
1528 | + /** |
|
1529 | + * plugin_uninstall |
|
1530 | + * |
|
1531 | + * @access public |
|
1532 | + * @static |
|
1533 | + * @param bool $remove_all |
|
1534 | + * @return void |
|
1535 | + */ |
|
1536 | + public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
1537 | + { |
|
1538 | + global $wpdb; |
|
1539 | + self::drop_espresso_tables(); |
|
1540 | + $wp_options_to_delete = array( |
|
1541 | + 'ee_no_ticket_prices' => true, |
|
1542 | + 'ee_active_messengers' => true, |
|
1543 | + 'ee_has_activated_messenger' => true, |
|
1544 | + RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES => true, |
|
1545 | + 'ee_config' => false, |
|
1546 | + 'ee_data_migration_current_db_state' => true, |
|
1547 | + 'ee_data_migration_mapping_' => false, |
|
1548 | + 'ee_data_migration_script_' => false, |
|
1549 | + 'ee_data_migrations' => true, |
|
1550 | + 'ee_dms_map' => false, |
|
1551 | + 'ee_notices' => true, |
|
1552 | + 'lang_file_check_' => false, |
|
1553 | + 'ee_maintenance_mode' => true, |
|
1554 | + 'ee_ueip_optin' => true, |
|
1555 | + 'ee_ueip_has_notified' => true, |
|
1556 | + 'ee_plugin_activation_errors' => true, |
|
1557 | + 'ee_id_mapping_from' => false, |
|
1558 | + 'espresso_persistent_admin_notices' => true, |
|
1559 | + 'ee_encryption_key' => true, |
|
1560 | + 'pue_force_upgrade_' => false, |
|
1561 | + 'pue_json_error_' => false, |
|
1562 | + 'pue_install_key_' => false, |
|
1563 | + 'pue_verification_error_' => false, |
|
1564 | + 'pu_dismissed_upgrade_' => false, |
|
1565 | + 'external_updates-' => false, |
|
1566 | + 'ee_extra_data' => true, |
|
1567 | + 'ee_ssn_' => false, |
|
1568 | + 'ee_rss_' => false, |
|
1569 | + 'ee_rte_n_tx_' => false, |
|
1570 | + 'ee_pers_admin_notices' => true, |
|
1571 | + 'ee_job_parameters_' => false, |
|
1572 | + 'ee_upload_directories_incomplete' => true, |
|
1573 | + 'ee_verified_db_collations' => true, |
|
1574 | + ); |
|
1575 | + if (is_main_site()) { |
|
1576 | + $wp_options_to_delete['ee_network_config'] = true; |
|
1577 | + } |
|
1578 | + $undeleted_options = array(); |
|
1579 | + foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
1580 | + if ($no_wildcard) { |
|
1581 | + if (! delete_option($option_name)) { |
|
1582 | + $undeleted_options[] = $option_name; |
|
1583 | + } |
|
1584 | + } else { |
|
1585 | + $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
1586 | + foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
1587 | + if (! delete_option($option_name_from_wildcard)) { |
|
1588 | + $undeleted_options[] = $option_name_from_wildcard; |
|
1589 | + } |
|
1590 | + } |
|
1591 | + } |
|
1592 | + } |
|
1593 | + // also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
1594 | + remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
1595 | + if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
1596 | + $db_update_sans_ee4 = array(); |
|
1597 | + foreach ($espresso_db_update as $version => $times_activated) { |
|
1598 | + if ((string) $version[0] === '3') {// if its NON EE4 |
|
1599 | + $db_update_sans_ee4[ $version ] = $times_activated; |
|
1600 | + } |
|
1601 | + } |
|
1602 | + update_option('espresso_db_update', $db_update_sans_ee4); |
|
1603 | + } |
|
1604 | + $errors = ''; |
|
1605 | + if (! empty($undeleted_options)) { |
|
1606 | + $errors .= sprintf( |
|
1607 | + __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
1608 | + '<br/>', |
|
1609 | + implode(',<br/>', $undeleted_options) |
|
1610 | + ); |
|
1611 | + } |
|
1612 | + if (! empty($errors)) { |
|
1613 | + EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
1614 | + } |
|
1615 | + } |
|
1616 | + |
|
1617 | + /** |
|
1618 | + * Gets the mysql error code from the last used query by wpdb |
|
1619 | + * |
|
1620 | + * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
1621 | + */ |
|
1622 | + public static function last_wpdb_error_code() |
|
1623 | + { |
|
1624 | + // phpcs:disable PHPCompatibility.PHP.RemovedExtensions.mysql_DeprecatedRemoved |
|
1625 | + global $wpdb; |
|
1626 | + if ($wpdb->use_mysqli) { |
|
1627 | + return mysqli_errno($wpdb->dbh); |
|
1628 | + } else { |
|
1629 | + return mysql_errno($wpdb->dbh); |
|
1630 | + } |
|
1631 | + // phpcs:enable |
|
1632 | + } |
|
1633 | + |
|
1634 | + /** |
|
1635 | + * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
1636 | + * |
|
1637 | + * @global wpdb $wpdb |
|
1638 | + * @deprecated instead use TableAnalysis::tableExists() |
|
1639 | + * @param string $table_name with or without $wpdb->prefix |
|
1640 | + * @return boolean |
|
1641 | + */ |
|
1642 | + public static function table_exists($table_name) |
|
1643 | + { |
|
1644 | + return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
1645 | + } |
|
1646 | + |
|
1647 | + /** |
|
1648 | + * Resets the cache on EEH_Activation |
|
1649 | + */ |
|
1650 | + public static function reset() |
|
1651 | + { |
|
1652 | + self::$_default_creator_id = null; |
|
1653 | + self::$_initialized_db_content_already_in_this_request = false; |
|
1654 | + } |
|
1655 | 1655 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public static function getTableAnalysis() |
56 | 56 | { |
57 | - if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
57 | + if ( ! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
58 | 58 | self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
59 | 59 | } |
60 | 60 | return self::$table_analysis; |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public static function getTableManager() |
68 | 68 | { |
69 | - if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
69 | + if ( ! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
70 | 70 | self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
71 | 71 | } |
72 | 72 | return self::$table_manager; |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | if ($which_to_include === 'old') { |
181 | 181 | $cron_tasks = array_filter( |
182 | 182 | $cron_tasks, |
183 | - function ($value) { |
|
183 | + function($value) { |
|
184 | 184 | return $value === EEH_Activation::cron_task_no_longer_in_use; |
185 | 185 | } |
186 | 186 | ); |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | { |
211 | 211 | |
212 | 212 | foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
213 | - if (! wp_next_scheduled($hook_name)) { |
|
213 | + if ( ! wp_next_scheduled($hook_name)) { |
|
214 | 214 | /** |
215 | 215 | * This allows client code to define the initial start timestamp for this schedule. |
216 | 216 | */ |
@@ -261,15 +261,15 @@ discard block |
||
261 | 261 | foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
262 | 262 | if (is_array($hooks_to_fire_at_time)) { |
263 | 263 | foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
264 | - if (isset($ee_cron_tasks_to_remove[ $hook_name ]) |
|
265 | - && is_array($ee_cron_tasks_to_remove[ $hook_name ]) |
|
264 | + if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
265 | + && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
266 | 266 | ) { |
267 | - unset($crons[ $timestamp ][ $hook_name ]); |
|
267 | + unset($crons[$timestamp][$hook_name]); |
|
268 | 268 | } |
269 | 269 | } |
270 | 270 | // also take care of any empty cron timestamps. |
271 | 271 | if (empty($hooks_to_fire_at_time)) { |
272 | - unset($crons[ $timestamp ]); |
|
272 | + unset($crons[$timestamp]); |
|
273 | 273 | } |
274 | 274 | } |
275 | 275 | } |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | 3 |
315 | 315 | ); |
316 | 316 | // EE_Config::reset(); |
317 | - if (! EE_Config::logging_enabled()) { |
|
317 | + if ( ! EE_Config::logging_enabled()) { |
|
318 | 318 | delete_option(EE_Config::LOG_NAME); |
319 | 319 | } |
320 | 320 | } |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | public static function load_calendar_config() |
330 | 330 | { |
331 | 331 | // grab array of all plugin folders and loop thru it |
332 | - $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
332 | + $plugins = glob(WP_PLUGIN_DIR.DS.'*', GLOB_ONLYDIR); |
|
333 | 333 | if (empty($plugins)) { |
334 | 334 | return; |
335 | 335 | } |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | || strpos($plugin, 'calendar') !== false |
346 | 346 | ) { |
347 | 347 | // this is what we are looking for |
348 | - $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
348 | + $calendar_config = $plugin_path.DS.'EE_Calendar_Config.php'; |
|
349 | 349 | // does it exist in this folder ? |
350 | 350 | if (is_readable($calendar_config)) { |
351 | 351 | // YEAH! let's load it |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | ) { |
473 | 473 | // update Config with post ID |
474 | 474 | $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
475 | - if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
475 | + if ( ! EE_Config::instance()->update_espresso_config(false, false)) { |
|
476 | 476 | $msg = __( |
477 | 477 | 'The Event Espresso critical page configuration settings could not be updated.', |
478 | 478 | 'event_espresso' |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
496 | 496 | 'event_espresso' |
497 | 497 | ), |
498 | - '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">' |
|
498 | + '<a href="'.admin_url('admin.php?page=espresso_general_settings&action=critical_pages').'">' |
|
499 | 499 | . __('Event Espresso Critical Pages Settings', 'event_espresso') |
500 | 500 | . '</a>' |
501 | 501 | ) |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | public static function get_page_by_ee_shortcode($ee_shortcode) |
522 | 522 | { |
523 | 523 | global $wpdb; |
524 | - $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
524 | + $shortcode_and_opening_bracket = '['.$ee_shortcode; |
|
525 | 525 | $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
526 | 526 | if ($post_id) { |
527 | 527 | return get_post($post_id); |
@@ -547,11 +547,11 @@ discard block |
||
547 | 547 | 'post_status' => 'publish', |
548 | 548 | 'post_type' => 'page', |
549 | 549 | 'comment_status' => 'closed', |
550 | - 'post_content' => '[' . $critical_page['code'] . ']', |
|
550 | + 'post_content' => '['.$critical_page['code'].']', |
|
551 | 551 | ); |
552 | 552 | |
553 | 553 | $post_id = wp_insert_post($post_args); |
554 | - if (! $post_id) { |
|
554 | + if ( ! $post_id) { |
|
555 | 555 | $msg = sprintf( |
556 | 556 | __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
557 | 557 | $critical_page['name'] |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | return $critical_page; |
561 | 561 | } |
562 | 562 | // get newly created post's details |
563 | - if (! $critical_page['post'] = get_post($post_id)) { |
|
563 | + if ( ! $critical_page['post'] = get_post($post_id)) { |
|
564 | 564 | $msg = sprintf( |
565 | 565 | __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
566 | 566 | $critical_page['name'] |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | public static function get_default_creator_id() |
586 | 586 | { |
587 | 587 | global $wpdb; |
588 | - if (! empty(self::$_default_creator_id)) { |
|
588 | + if ( ! empty(self::$_default_creator_id)) { |
|
589 | 589 | return self::$_default_creator_id; |
590 | 590 | }/**/ |
591 | 591 | $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
@@ -601,7 +601,7 @@ discard block |
||
601 | 601 | $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
602 | 602 | $query = $wpdb->prepare( |
603 | 603 | "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
604 | - '%' . $role_to_check . '%' |
|
604 | + '%'.$role_to_check.'%' |
|
605 | 605 | ); |
606 | 606 | $user_id = $wpdb->get_var($query); |
607 | 607 | $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
@@ -640,8 +640,8 @@ discard block |
||
640 | 640 | return; |
641 | 641 | } |
642 | 642 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
643 | - if (! function_exists('dbDelta')) { |
|
644 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
643 | + if ( ! function_exists('dbDelta')) { |
|
644 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
645 | 645 | } |
646 | 646 | $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
647 | 647 | $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
@@ -650,9 +650,9 @@ discard block |
||
650 | 650 | // ok, delete the table... but ONLY if it's empty |
651 | 651 | $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
652 | 652 | // table is NOT empty, are you SURE you want to delete this table ??? |
653 | - if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
653 | + if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
654 | 654 | \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
655 | - } elseif (! $deleted_safely) { |
|
655 | + } elseif ( ! $deleted_safely) { |
|
656 | 656 | // so we should be more cautious rather than just dropping tables so easily |
657 | 657 | error_log( |
658 | 658 | sprintf( |
@@ -852,13 +852,13 @@ discard block |
||
852 | 852 | // reset values array |
853 | 853 | $QSG_values = array(); |
854 | 854 | // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
855 | - if (! in_array("$QSG_system", $question_groups)) { |
|
855 | + if ( ! in_array("$QSG_system", $question_groups)) { |
|
856 | 856 | // add it |
857 | 857 | switch ($QSG_system) { |
858 | 858 | case 1: |
859 | 859 | $QSG_values = array( |
860 | 860 | 'QSG_name' => __('Personal Information', 'event_espresso'), |
861 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
861 | + 'QSG_identifier' => 'personal-information-'.time(), |
|
862 | 862 | 'QSG_desc' => '', |
863 | 863 | 'QSG_order' => 1, |
864 | 864 | 'QSG_show_group_name' => 1, |
@@ -870,7 +870,7 @@ discard block |
||
870 | 870 | case 2: |
871 | 871 | $QSG_values = array( |
872 | 872 | 'QSG_name' => __('Address Information', 'event_espresso'), |
873 | - 'QSG_identifier' => 'address-information-' . time(), |
|
873 | + 'QSG_identifier' => 'address-information-'.time(), |
|
874 | 874 | 'QSG_desc' => '', |
875 | 875 | 'QSG_order' => 2, |
876 | 876 | 'QSG_show_group_name' => 1, |
@@ -881,14 +881,14 @@ discard block |
||
881 | 881 | break; |
882 | 882 | } |
883 | 883 | // make sure we have some values before inserting them |
884 | - if (! empty($QSG_values)) { |
|
884 | + if ( ! empty($QSG_values)) { |
|
885 | 885 | // insert system question |
886 | 886 | $wpdb->insert( |
887 | 887 | $table_name, |
888 | 888 | $QSG_values, |
889 | 889 | array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
890 | 890 | ); |
891 | - $QSG_IDs[ $QSG_system ] = $wpdb->insert_id; |
|
891 | + $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
892 | 892 | } |
893 | 893 | } |
894 | 894 | } |
@@ -918,7 +918,7 @@ discard block |
||
918 | 918 | // reset values array |
919 | 919 | $QST_values = array(); |
920 | 920 | // if we don't have what we should have |
921 | - if (! in_array($QST_system, $questions)) { |
|
921 | + if ( ! in_array($QST_system, $questions)) { |
|
922 | 922 | // add it |
923 | 923 | switch ($QST_system) { |
924 | 924 | case 'fname': |
@@ -1070,7 +1070,7 @@ discard block |
||
1070 | 1070 | ); |
1071 | 1071 | break; |
1072 | 1072 | } |
1073 | - if (! empty($QST_values)) { |
|
1073 | + if ( ! empty($QST_values)) { |
|
1074 | 1074 | // insert system question |
1075 | 1075 | $wpdb->insert( |
1076 | 1076 | $table_name, |
@@ -1084,8 +1084,8 @@ discard block |
||
1084 | 1084 | } else { |
1085 | 1085 | $system_question_we_want = EEM_Question_Group::system_address; |
1086 | 1086 | } |
1087 | - if (isset($QSG_IDs[ $system_question_we_want ])) { |
|
1088 | - $QSG_ID = $QSG_IDs[ $system_question_we_want ]; |
|
1087 | + if (isset($QSG_IDs[$system_question_we_want])) { |
|
1088 | + $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
1089 | 1089 | } else { |
1090 | 1090 | $id_col = EEM_Question_Group::instance() |
1091 | 1091 | ->get_col(array(array('QSG_system' => $system_question_we_want))); |
@@ -1133,7 +1133,7 @@ discard block |
||
1133 | 1133 | */ |
1134 | 1134 | public static function insert_default_payment_methods() |
1135 | 1135 | { |
1136 | - if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1136 | + if ( ! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
1137 | 1137 | EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
1138 | 1138 | EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
1139 | 1139 | } else { |
@@ -1270,7 +1270,7 @@ discard block |
||
1270 | 1270 | $active_messenger->name, |
1271 | 1271 | $default_message_type_name_for_messenger |
1272 | 1272 | ) |
1273 | - || ! isset($installed_message_types[ $default_message_type_name_for_messenger ]) |
|
1273 | + || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
1274 | 1274 | ) { |
1275 | 1275 | continue; |
1276 | 1276 | } |
@@ -1283,7 +1283,7 @@ discard block |
||
1283 | 1283 | false |
1284 | 1284 | ); |
1285 | 1285 | // activate the templates for these message types |
1286 | - if (! empty($default_message_type_names_to_activate)) { |
|
1286 | + if ( ! empty($default_message_type_names_to_activate)) { |
|
1287 | 1287 | $templates_created = EEH_MSG_Template::generate_new_templates( |
1288 | 1288 | $active_messenger->name, |
1289 | 1289 | $default_message_type_names_for_messenger, |
@@ -1317,13 +1317,13 @@ discard block |
||
1317 | 1317 | $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
1318 | 1318 | // verify the default message types match an installed message type. |
1319 | 1319 | foreach ($default_message_type_names_for_messenger as $key => $name) { |
1320 | - if (! isset($installed_message_types[ $name ]) |
|
1320 | + if ( ! isset($installed_message_types[$name]) |
|
1321 | 1321 | || $message_resource_manager->has_message_type_been_activated_for_messenger( |
1322 | 1322 | $name, |
1323 | 1323 | $messenger_to_generate->name |
1324 | 1324 | ) |
1325 | 1325 | ) { |
1326 | - unset($default_message_type_names_for_messenger[ $key ]); |
|
1326 | + unset($default_message_type_names_for_messenger[$key]); |
|
1327 | 1327 | } |
1328 | 1328 | } |
1329 | 1329 | // in previous iterations, the active_messengers option in the db |
@@ -1337,7 +1337,7 @@ discard block |
||
1337 | 1337 | false |
1338 | 1338 | ); |
1339 | 1339 | // create any templates needing created (or will reactivate templates already generated as necessary). |
1340 | - if (! empty($default_message_type_names_for_messenger)) { |
|
1340 | + if ( ! empty($default_message_type_names_for_messenger)) { |
|
1341 | 1341 | $templates_generated = EEH_MSG_Template::generate_new_templates( |
1342 | 1342 | $messenger_to_generate->name, |
1343 | 1343 | $default_message_type_names_for_messenger, |
@@ -1372,13 +1372,13 @@ discard block |
||
1372 | 1372 | // if installed messenger is a messenger that should be activated on install |
1373 | 1373 | // and is not already active |
1374 | 1374 | // and has never been activated |
1375 | - if (! $installed_messenger->activate_on_install |
|
1376 | - || isset($active_messengers[ $installed_messenger->name ]) |
|
1377 | - || isset($has_activated[ $installed_messenger->name ]) |
|
1375 | + if ( ! $installed_messenger->activate_on_install |
|
1376 | + || isset($active_messengers[$installed_messenger->name]) |
|
1377 | + || isset($has_activated[$installed_messenger->name]) |
|
1378 | 1378 | ) { |
1379 | 1379 | continue; |
1380 | 1380 | } |
1381 | - $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger; |
|
1381 | + $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
1382 | 1382 | } |
1383 | 1383 | return $messengers_to_generate; |
1384 | 1384 | } |
@@ -1416,7 +1416,7 @@ discard block |
||
1416 | 1416 | // this creates an array for tracking events that have no active ticket prices created |
1417 | 1417 | // this allows us to warn admins of the situation so that it can be corrected |
1418 | 1418 | $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
1419 | - if (! $espresso_no_ticket_prices) { |
|
1419 | + if ( ! $espresso_no_ticket_prices) { |
|
1420 | 1420 | add_option('ee_no_ticket_prices', array(), '', false); |
1421 | 1421 | } |
1422 | 1422 | } |
@@ -1455,7 +1455,7 @@ discard block |
||
1455 | 1455 | } |
1456 | 1456 | } |
1457 | 1457 | // get all our CPTs |
1458 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
1458 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",", $ee_post_types).")"; |
|
1459 | 1459 | $cpt_ids = $wpdb->get_col($query); |
1460 | 1460 | // delete each post meta and term relations too |
1461 | 1461 | foreach ($cpt_ids as $post_id) { |
@@ -1484,7 +1484,7 @@ discard block |
||
1484 | 1484 | || ! $table->is_global()// not main site,but not global either. nuke it |
1485 | 1485 | ) |
1486 | 1486 | ) { |
1487 | - $tables[ $table->get_table_name() ] = $table->get_table_name(); |
|
1487 | + $tables[$table->get_table_name()] = $table->get_table_name(); |
|
1488 | 1488 | } |
1489 | 1489 | } |
1490 | 1490 | } |
@@ -1501,7 +1501,7 @@ discard block |
||
1501 | 1501 | 'esp_rule', |
1502 | 1502 | ); |
1503 | 1503 | foreach ($tables_without_models as $table) { |
1504 | - $tables[ $table ] = $table; |
|
1504 | + $tables[$table] = $table; |
|
1505 | 1505 | } |
1506 | 1506 | return \EEH_Activation::getTableManager()->dropTables($tables); |
1507 | 1507 | } |
@@ -1578,13 +1578,13 @@ discard block |
||
1578 | 1578 | $undeleted_options = array(); |
1579 | 1579 | foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
1580 | 1580 | if ($no_wildcard) { |
1581 | - if (! delete_option($option_name)) { |
|
1581 | + if ( ! delete_option($option_name)) { |
|
1582 | 1582 | $undeleted_options[] = $option_name; |
1583 | 1583 | } |
1584 | 1584 | } else { |
1585 | 1585 | $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
1586 | 1586 | foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
1587 | - if (! delete_option($option_name_from_wildcard)) { |
|
1587 | + if ( ! delete_option($option_name_from_wildcard)) { |
|
1588 | 1588 | $undeleted_options[] = $option_name_from_wildcard; |
1589 | 1589 | } |
1590 | 1590 | } |
@@ -1596,20 +1596,20 @@ discard block |
||
1596 | 1596 | $db_update_sans_ee4 = array(); |
1597 | 1597 | foreach ($espresso_db_update as $version => $times_activated) { |
1598 | 1598 | if ((string) $version[0] === '3') {// if its NON EE4 |
1599 | - $db_update_sans_ee4[ $version ] = $times_activated; |
|
1599 | + $db_update_sans_ee4[$version] = $times_activated; |
|
1600 | 1600 | } |
1601 | 1601 | } |
1602 | 1602 | update_option('espresso_db_update', $db_update_sans_ee4); |
1603 | 1603 | } |
1604 | 1604 | $errors = ''; |
1605 | - if (! empty($undeleted_options)) { |
|
1605 | + if ( ! empty($undeleted_options)) { |
|
1606 | 1606 | $errors .= sprintf( |
1607 | 1607 | __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
1608 | 1608 | '<br/>', |
1609 | 1609 | implode(',<br/>', $undeleted_options) |
1610 | 1610 | ); |
1611 | 1611 | } |
1612 | - if (! empty($errors)) { |
|
1612 | + if ( ! empty($errors)) { |
|
1613 | 1613 | EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
1614 | 1614 | } |
1615 | 1615 | } |
@@ -529,7 +529,7 @@ |
||
529 | 529 | /** |
530 | 530 | * This returns an array of counts of datetimes in the database for each Datetime status that can be queried. |
531 | 531 | * |
532 | - * @param array $stati_to_include If included you can restrict the statuses we return counts for by including the |
|
532 | + * @param string[] $stati_to_include If included you can restrict the statuses we return counts for by including the |
|
533 | 533 | * stati you want counts for as values in the array. An empty array returns counts |
534 | 534 | * for all valid stati. |
535 | 535 | * @param array $query_params If included can be used to refine the conditions for returning the count (i.e. |
@@ -13,747 +13,747 @@ |
||
13 | 13 | class EEM_Datetime extends EEM_Soft_Delete_Base |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @var EEM_Datetime $_instance |
|
18 | - */ |
|
19 | - protected static $_instance; |
|
20 | - |
|
21 | - |
|
22 | - /** |
|
23 | - * private constructor to prevent direct creation |
|
24 | - * |
|
25 | - * @param string $timezone A string representing the timezone we want to set for returned Date Time Strings |
|
26 | - * (and any incoming timezone data that gets saved). |
|
27 | - * Note this just sends the timezone info to the date time model field objects. |
|
28 | - * Default is NULL |
|
29 | - * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
30 | - * @throws EE_Error |
|
31 | - * @throws InvalidArgumentException |
|
32 | - * @throws InvalidArgumentException |
|
33 | - */ |
|
34 | - protected function __construct($timezone) |
|
35 | - { |
|
36 | - $this->singular_item = esc_html__('Datetime', 'event_espresso'); |
|
37 | - $this->plural_item = esc_html__('Datetimes', 'event_espresso'); |
|
38 | - $this->_tables = array( |
|
39 | - 'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'), |
|
40 | - ); |
|
41 | - $this->_fields = array( |
|
42 | - 'Datetime' => array( |
|
43 | - 'DTT_ID' => new EE_Primary_Key_Int_Field( |
|
44 | - 'DTT_ID', |
|
45 | - esc_html__('Datetime ID', 'event_espresso') |
|
46 | - ), |
|
47 | - 'EVT_ID' => new EE_Foreign_Key_Int_Field( |
|
48 | - 'EVT_ID', |
|
49 | - esc_html__('Event ID', 'event_espresso'), |
|
50 | - false, |
|
51 | - 0, |
|
52 | - 'Event' |
|
53 | - ), |
|
54 | - 'DTT_name' => new EE_Plain_Text_Field( |
|
55 | - 'DTT_name', |
|
56 | - esc_html__('Datetime Name', 'event_espresso'), |
|
57 | - false, |
|
58 | - '' |
|
59 | - ), |
|
60 | - 'DTT_description' => new EE_Post_Content_Field( |
|
61 | - 'DTT_description', |
|
62 | - esc_html__('Description for Datetime', 'event_espresso'), |
|
63 | - false, |
|
64 | - '' |
|
65 | - ), |
|
66 | - 'DTT_EVT_start' => new EE_Datetime_Field( |
|
67 | - 'DTT_EVT_start', |
|
68 | - esc_html__('Start time/date of Event', 'event_espresso'), |
|
69 | - false, |
|
70 | - EE_Datetime_Field::now, |
|
71 | - $timezone |
|
72 | - ), |
|
73 | - 'DTT_EVT_end' => new EE_Datetime_Field( |
|
74 | - 'DTT_EVT_end', |
|
75 | - esc_html__('End time/date of Event', 'event_espresso'), |
|
76 | - false, |
|
77 | - EE_Datetime_Field::now, |
|
78 | - $timezone |
|
79 | - ), |
|
80 | - 'DTT_reg_limit' => new EE_Infinite_Integer_Field( |
|
81 | - 'DTT_reg_limit', |
|
82 | - esc_html__('Registration Limit for this time', 'event_espresso'), |
|
83 | - true, |
|
84 | - EE_INF |
|
85 | - ), |
|
86 | - 'DTT_sold' => new EE_Integer_Field( |
|
87 | - 'DTT_sold', |
|
88 | - esc_html__('How many sales for this Datetime that have occurred', 'event_espresso'), |
|
89 | - true, |
|
90 | - 0 |
|
91 | - ), |
|
92 | - 'DTT_reserved' => new EE_Integer_Field( |
|
93 | - 'DTT_reserved', |
|
94 | - esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'), |
|
95 | - false, |
|
96 | - 0 |
|
97 | - ), |
|
98 | - 'DTT_is_primary' => new EE_Boolean_Field( |
|
99 | - 'DTT_is_primary', |
|
100 | - esc_html__('Flag indicating datetime is primary one for event', 'event_espresso'), |
|
101 | - false, |
|
102 | - false |
|
103 | - ), |
|
104 | - 'DTT_order' => new EE_Integer_Field( |
|
105 | - 'DTT_order', |
|
106 | - esc_html__('The order in which the Datetime is displayed', 'event_espresso'), |
|
107 | - false, |
|
108 | - 0 |
|
109 | - ), |
|
110 | - 'DTT_parent' => new EE_Integer_Field( |
|
111 | - 'DTT_parent', |
|
112 | - esc_html__('Indicates what DTT_ID is the parent of this DTT_ID', 'event_espresso'), |
|
113 | - true, |
|
114 | - 0 |
|
115 | - ), |
|
116 | - 'DTT_deleted' => new EE_Trashed_Flag_Field( |
|
117 | - 'DTT_deleted', |
|
118 | - esc_html__('Flag indicating datetime is archived', 'event_espresso'), |
|
119 | - false, |
|
120 | - false |
|
121 | - ), |
|
122 | - ), |
|
123 | - ); |
|
124 | - $this->_model_relations = array( |
|
125 | - 'Ticket' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
126 | - 'Event' => new EE_Belongs_To_Relation(), |
|
127 | - 'Checkin' => new EE_Has_Many_Relation(), |
|
128 | - 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
|
129 | - ); |
|
130 | - $path_to_event_model = 'Event'; |
|
131 | - $this->model_chain_to_password = $path_to_event_model; |
|
132 | - $this->_model_chain_to_wp_user = $path_to_event_model; |
|
133 | - // this model is generally available for reading |
|
134 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
135 | - $path_to_event_model |
|
136 | - ); |
|
137 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
138 | - $path_to_event_model |
|
139 | - ); |
|
140 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
141 | - $path_to_event_model |
|
142 | - ); |
|
143 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
144 | - $path_to_event_model, |
|
145 | - EEM_Base::caps_edit |
|
146 | - ); |
|
147 | - parent::__construct($timezone); |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * create new blank datetime |
|
153 | - * |
|
154 | - * @access public |
|
155 | - * @return EE_Datetime[] array on success, FALSE on fail |
|
156 | - * @throws EE_Error |
|
157 | - * @throws InvalidArgumentException |
|
158 | - * @throws InvalidDataTypeException |
|
159 | - * @throws ReflectionException |
|
160 | - * @throws InvalidInterfaceException |
|
161 | - */ |
|
162 | - public function create_new_blank_datetime() |
|
163 | - { |
|
164 | - // makes sure timezone is always set. |
|
165 | - $timezone_string = $this->get_timezone(); |
|
166 | - /** |
|
167 | - * Filters the initial start date for the new datetime. |
|
168 | - * Any time included in this value will be overridden later so use additional filters to modify the time. |
|
169 | - * |
|
170 | - * @param int $start_date Unixtimestamp representing now + 30 days in seconds. |
|
171 | - * @return int unixtimestamp |
|
172 | - */ |
|
173 | - $start_date = apply_filters( |
|
174 | - 'FHEE__EEM_Datetime__create_new_blank_datetime__start_date', |
|
175 | - $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS |
|
176 | - ); |
|
177 | - /** |
|
178 | - * Filters the initial end date for the new datetime. |
|
179 | - * Any time included in this value will be overridden later so use additional filters to modify the time. |
|
180 | - * |
|
181 | - * @param int $end_data Unixtimestamp representing now + 30 days in seconds. |
|
182 | - * @return int unixtimestamp |
|
183 | - */ |
|
184 | - $end_date = apply_filters( |
|
185 | - 'FHEE__EEM_Datetime__create_new_blank_datetime__end_date', |
|
186 | - $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS |
|
187 | - ); |
|
188 | - $blank_datetime = EE_Datetime::new_instance( |
|
189 | - array( |
|
190 | - 'DTT_EVT_start' => $start_date, |
|
191 | - 'DTT_EVT_end' => $end_date, |
|
192 | - 'DTT_order' => 1, |
|
193 | - 'DTT_reg_limit' => EE_INF, |
|
194 | - ), |
|
195 | - $timezone_string |
|
196 | - ); |
|
197 | - /** |
|
198 | - * Filters the initial start time and format for the new EE_Datetime instance. |
|
199 | - * |
|
200 | - * @param array $start_time An array having size 2. First element is the time, second element is the time |
|
201 | - * format. |
|
202 | - * @return array |
|
203 | - */ |
|
204 | - $start_time = apply_filters( |
|
205 | - 'FHEE__EEM_Datetime__create_new_blank_datetime__start_time', |
|
206 | - ['8am', 'ga'] |
|
207 | - ); |
|
208 | - /** |
|
209 | - * Filters the initial end time and format for the new EE_Datetime instance. |
|
210 | - * |
|
211 | - * @param array $end_time An array having size 2. First element is the time, second element is the time |
|
212 | - * format |
|
213 | - * @return array |
|
214 | - */ |
|
215 | - $end_time = apply_filters( |
|
216 | - 'FHEE__EEM_Datetime__create_new_blank_datetime__end_time', |
|
217 | - ['5pm', 'ga'] |
|
218 | - ); |
|
219 | - $this->validateStartAndEndTimeForBlankDate($start_time, $end_time); |
|
220 | - $blank_datetime->set_start_time( |
|
221 | - $this->convert_datetime_for_query( |
|
222 | - 'DTT_EVT_start', |
|
223 | - $start_time[0], |
|
224 | - $start_time[1], |
|
225 | - $timezone_string |
|
226 | - ) |
|
227 | - ); |
|
228 | - $blank_datetime->set_end_time( |
|
229 | - $this->convert_datetime_for_query( |
|
230 | - 'DTT_EVT_end', |
|
231 | - $end_time[0], |
|
232 | - $end_time[1], |
|
233 | - $timezone_string |
|
234 | - ) |
|
235 | - ); |
|
236 | - return array($blank_datetime); |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * Validates whether the start_time and end_time are in the expected format. |
|
242 | - * @param array $start_time |
|
243 | - * @param array $end_time |
|
244 | - * @throws InvalidArgumentException |
|
245 | - * @throws InvalidDataTypeException |
|
246 | - */ |
|
247 | - private function validateStartAndEndTimeForBlankDate($start_time, $end_time) |
|
248 | - { |
|
249 | - if (! is_array($start_time)) { |
|
250 | - throw new InvalidDataTypeException('start_time', $start_time, 'array'); |
|
251 | - } |
|
252 | - if (! is_array($end_time)) { |
|
253 | - throw new InvalidDataTypeException('end_time', $end_time, 'array'); |
|
254 | - } |
|
255 | - if (count($start_time) !== 2) { |
|
256 | - throw new InvalidArgumentException( |
|
257 | - sprintf( |
|
258 | - 'The variable %1$s is expected to be an array with two elements. The first item in the ' |
|
259 | - . 'array should be a valid time string, the second item in the array should be a valid time format', |
|
260 | - '$start_time' |
|
261 | - ) |
|
262 | - ); |
|
263 | - } |
|
264 | - if (count($end_time) !== 2) { |
|
265 | - throw new InvalidArgumentException( |
|
266 | - sprintf( |
|
267 | - 'The variable %1$s is expected to be an array with two elements. The first item in the ' |
|
268 | - . 'array should be a valid time string, the second item in the array should be a valid time format', |
|
269 | - '$end_time' |
|
270 | - ) |
|
271 | - ); |
|
272 | - } |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * get event start date from db |
|
278 | - * |
|
279 | - * @access public |
|
280 | - * @param int $EVT_ID |
|
281 | - * @return EE_Datetime[] array on success, FALSE on fail |
|
282 | - * @throws EE_Error |
|
283 | - */ |
|
284 | - public function get_all_event_dates($EVT_ID = 0) |
|
285 | - { |
|
286 | - if (! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
287 | - return $this->create_new_blank_datetime(); |
|
288 | - } |
|
289 | - $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID); |
|
290 | - if (empty($results)) { |
|
291 | - return $this->create_new_blank_datetime(); |
|
292 | - } |
|
293 | - return $results; |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * get all datetimes attached to an event ordered by the DTT_order field |
|
299 | - * |
|
300 | - * @public |
|
301 | - * @param int $EVT_ID event id |
|
302 | - * @param boolean $include_expired |
|
303 | - * @param boolean $include_deleted |
|
304 | - * @param int $limit If included then limit the count of results by |
|
305 | - * the given number |
|
306 | - * @return EE_Datetime[] |
|
307 | - * @throws EE_Error |
|
308 | - */ |
|
309 | - public function get_datetimes_for_event_ordered_by_DTT_order( |
|
310 | - $EVT_ID, |
|
311 | - $include_expired = true, |
|
312 | - $include_deleted = true, |
|
313 | - $limit = null |
|
314 | - ) { |
|
315 | - // sanitize EVT_ID |
|
316 | - $EVT_ID = absint($EVT_ID); |
|
317 | - $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
318 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
319 | - $where_params = array('Event.EVT_ID' => $EVT_ID); |
|
320 | - $query_params = ! empty($limit) |
|
321 | - ? array( |
|
322 | - $where_params, |
|
323 | - 'limit' => $limit, |
|
324 | - 'order_by' => array('DTT_order' => 'ASC'), |
|
325 | - 'default_where_conditions' => 'none', |
|
326 | - ) |
|
327 | - : array( |
|
328 | - $where_params, |
|
329 | - 'order_by' => array('DTT_order' => 'ASC'), |
|
330 | - 'default_where_conditions' => 'none', |
|
331 | - ); |
|
332 | - if (! $include_expired) { |
|
333 | - $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
334 | - } |
|
335 | - if ($include_deleted) { |
|
336 | - $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
337 | - } |
|
338 | - /** @var EE_Datetime[] $result */ |
|
339 | - $result = $this->get_all($query_params); |
|
340 | - $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
341 | - return $result; |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - /** |
|
346 | - * Gets the datetimes for the event (with the given limit), and orders them by "importance". |
|
347 | - * By importance, we mean that the primary datetimes are most important (DEPRECATED FOR NOW), |
|
348 | - * and then the earlier datetimes are the most important. |
|
349 | - * Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet. |
|
350 | - * |
|
351 | - * @param int $EVT_ID |
|
352 | - * @param int $limit |
|
353 | - * @return EE_Datetime[]|EE_Base_Class[] |
|
354 | - * @throws EE_Error |
|
355 | - */ |
|
356 | - public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null) |
|
357 | - { |
|
358 | - return $this->get_all( |
|
359 | - array( |
|
360 | - array('Event.EVT_ID' => $EVT_ID), |
|
361 | - 'limit' => $limit, |
|
362 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
363 | - 'default_where_conditions' => 'none', |
|
364 | - ) |
|
365 | - ); |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * @param int $EVT_ID |
|
371 | - * @param boolean $include_expired |
|
372 | - * @param boolean $include_deleted |
|
373 | - * @return EE_Datetime |
|
374 | - * @throws EE_Error |
|
375 | - */ |
|
376 | - public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false) |
|
377 | - { |
|
378 | - $results = $this->get_datetimes_for_event_ordered_by_start_time( |
|
379 | - $EVT_ID, |
|
380 | - $include_expired, |
|
381 | - $include_deleted, |
|
382 | - 1 |
|
383 | - ); |
|
384 | - if ($results) { |
|
385 | - return array_shift($results); |
|
386 | - } |
|
387 | - return null; |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - /** |
|
392 | - * Gets the 'primary' datetime for an event. |
|
393 | - * |
|
394 | - * @param int $EVT_ID |
|
395 | - * @param bool $try_to_exclude_expired |
|
396 | - * @param bool $try_to_exclude_deleted |
|
397 | - * @return \EE_Datetime |
|
398 | - * @throws EE_Error |
|
399 | - */ |
|
400 | - public function get_primary_datetime_for_event( |
|
401 | - $EVT_ID, |
|
402 | - $try_to_exclude_expired = true, |
|
403 | - $try_to_exclude_deleted = true |
|
404 | - ) { |
|
405 | - if ($try_to_exclude_expired) { |
|
406 | - $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false); |
|
407 | - if ($non_expired) { |
|
408 | - return $non_expired; |
|
409 | - } |
|
410 | - } |
|
411 | - if ($try_to_exclude_deleted) { |
|
412 | - $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true); |
|
413 | - if ($expired_even) { |
|
414 | - return $expired_even; |
|
415 | - } |
|
416 | - } |
|
417 | - return $this->get_oldest_datetime_for_event($EVT_ID, true, true); |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - /** |
|
422 | - * Gets ALL the datetimes for an event (including trashed ones, for now), ordered |
|
423 | - * only by start date |
|
424 | - * |
|
425 | - * @param int $EVT_ID |
|
426 | - * @param boolean $include_expired |
|
427 | - * @param boolean $include_deleted |
|
428 | - * @param int $limit |
|
429 | - * @return EE_Datetime[] |
|
430 | - * @throws EE_Error |
|
431 | - */ |
|
432 | - public function get_datetimes_for_event_ordered_by_start_time( |
|
433 | - $EVT_ID, |
|
434 | - $include_expired = true, |
|
435 | - $include_deleted = true, |
|
436 | - $limit = null |
|
437 | - ) { |
|
438 | - // sanitize EVT_ID |
|
439 | - $EVT_ID = absint($EVT_ID); |
|
440 | - $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
441 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
442 | - $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
|
443 | - if (! $include_expired) { |
|
444 | - $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
445 | - } |
|
446 | - if ($include_deleted) { |
|
447 | - $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
448 | - } |
|
449 | - if ($limit) { |
|
450 | - $query_params['limit'] = $limit; |
|
451 | - } |
|
452 | - /** @var EE_Datetime[] $result */ |
|
453 | - $result = $this->get_all($query_params); |
|
454 | - $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
455 | - return $result; |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered |
|
461 | - * only by start date |
|
462 | - * |
|
463 | - * @param int $TKT_ID |
|
464 | - * @param boolean $include_expired |
|
465 | - * @param boolean $include_deleted |
|
466 | - * @param int $limit |
|
467 | - * @return EE_Datetime[] |
|
468 | - * @throws EE_Error |
|
469 | - */ |
|
470 | - public function get_datetimes_for_ticket_ordered_by_start_time( |
|
471 | - $TKT_ID, |
|
472 | - $include_expired = true, |
|
473 | - $include_deleted = true, |
|
474 | - $limit = null |
|
475 | - ) { |
|
476 | - // sanitize TKT_ID |
|
477 | - $TKT_ID = absint($TKT_ID); |
|
478 | - $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
479 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
480 | - $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
|
481 | - if (! $include_expired) { |
|
482 | - $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
483 | - } |
|
484 | - if ($include_deleted) { |
|
485 | - $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
486 | - } |
|
487 | - if ($limit) { |
|
488 | - $query_params['limit'] = $limit; |
|
489 | - } |
|
490 | - /** @var EE_Datetime[] $result */ |
|
491 | - $result = $this->get_all($query_params); |
|
492 | - $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
493 | - return $result; |
|
494 | - } |
|
495 | - |
|
496 | - |
|
497 | - /** |
|
498 | - * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the |
|
499 | - * datetimes. |
|
500 | - * |
|
501 | - * @param int $TKT_ID ID of ticket to retrieve the datetimes for |
|
502 | - * @param boolean $include_expired whether to include expired datetimes or not |
|
503 | - * @param boolean $include_deleted whether to include trashed datetimes or not. |
|
504 | - * @param int|null $limit if null, no limit, if int then limit results by |
|
505 | - * that number |
|
506 | - * @return EE_Datetime[] |
|
507 | - * @throws EE_Error |
|
508 | - */ |
|
509 | - public function get_datetimes_for_ticket_ordered_by_DTT_order( |
|
510 | - $TKT_ID, |
|
511 | - $include_expired = true, |
|
512 | - $include_deleted = true, |
|
513 | - $limit = null |
|
514 | - ) { |
|
515 | - // sanitize id. |
|
516 | - $TKT_ID = absint($TKT_ID); |
|
517 | - $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
518 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
519 | - $where_params = array('Ticket.TKT_ID' => $TKT_ID); |
|
520 | - $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC')); |
|
521 | - if (! $include_expired) { |
|
522 | - $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
523 | - } |
|
524 | - if ($include_deleted) { |
|
525 | - $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
526 | - } |
|
527 | - if ($limit) { |
|
528 | - $query_params['limit'] = $limit; |
|
529 | - } |
|
530 | - /** @var EE_Datetime[] $result */ |
|
531 | - $result = $this->get_all($query_params); |
|
532 | - $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
533 | - return $result; |
|
534 | - } |
|
535 | - |
|
536 | - |
|
537 | - /** |
|
538 | - * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK |
|
539 | - * reason it doesn't exist, we consider the earliest event the most important) |
|
540 | - * |
|
541 | - * @param int $EVT_ID |
|
542 | - * @return EE_Datetime |
|
543 | - * @throws EE_Error |
|
544 | - */ |
|
545 | - public function get_most_important_datetime_for_event($EVT_ID) |
|
546 | - { |
|
547 | - $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1); |
|
548 | - if ($results) { |
|
549 | - return array_shift($results); |
|
550 | - } |
|
551 | - return null; |
|
552 | - } |
|
553 | - |
|
554 | - |
|
555 | - /** |
|
556 | - * This returns a wpdb->results Array of all DTT month and years matching the incoming query params and |
|
557 | - * grouped by month and year. |
|
558 | - * |
|
559 | - * @param array $where_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions |
|
560 | - * @param string $evt_active_status A string representing the evt active status to filter the months by. |
|
561 | - * Can be: |
|
562 | - * - '' = no filter |
|
563 | - * - upcoming = Published events with at least one upcoming datetime. |
|
564 | - * - expired = Events with all datetimes expired. |
|
565 | - * - active = Events that are published and have at least one datetime that |
|
566 | - * starts before now and ends after now. |
|
567 | - * - inactive = Events that are either not published. |
|
568 | - * @return EE_Base_Class[] |
|
569 | - * @throws EE_Error |
|
570 | - * @throws InvalidArgumentException |
|
571 | - * @throws InvalidArgumentException |
|
572 | - */ |
|
573 | - public function get_dtt_months_and_years($where_params, $evt_active_status = '') |
|
574 | - { |
|
575 | - $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start'); |
|
576 | - $current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end'); |
|
577 | - switch ($evt_active_status) { |
|
578 | - case 'upcoming': |
|
579 | - $where_params['Event.status'] = 'publish'; |
|
580 | - // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
581 | - if (isset($where_params['DTT_EVT_start'])) { |
|
582 | - $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start']; |
|
583 | - } |
|
584 | - $where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start); |
|
585 | - break; |
|
586 | - case 'expired': |
|
587 | - if (isset($where_params['Event.status'])) { |
|
588 | - unset($where_params['Event.status']); |
|
589 | - } |
|
590 | - // get events to exclude |
|
591 | - $exclude_query[0] = array_merge( |
|
592 | - $where_params, |
|
593 | - array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end)) |
|
594 | - ); |
|
595 | - // first get all events that have datetimes where its not expired. |
|
596 | - $event_ids = $this->_get_all_wpdb_results( |
|
597 | - $exclude_query, |
|
598 | - OBJECT_K, |
|
599 | - 'Datetime.EVT_ID' |
|
600 | - ); |
|
601 | - $event_ids = array_keys($event_ids); |
|
602 | - if (isset($where_params['DTT_EVT_end'])) { |
|
603 | - $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
604 | - } |
|
605 | - $where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end); |
|
606 | - $where_params['Event.EVT_ID'] = array('NOT IN', $event_ids); |
|
607 | - break; |
|
608 | - case 'active': |
|
609 | - $where_params['Event.status'] = 'publish'; |
|
610 | - if (isset($where_params['DTT_EVT_start'])) { |
|
611 | - $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start']; |
|
612 | - } |
|
613 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
614 | - $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end']; |
|
615 | - } |
|
616 | - $where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start); |
|
617 | - $where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end); |
|
618 | - break; |
|
619 | - case 'inactive': |
|
620 | - if (isset($where_params['Event.status'])) { |
|
621 | - unset($where_params['Event.status']); |
|
622 | - } |
|
623 | - if (isset($where_params['OR'])) { |
|
624 | - $where_params['AND']['OR'] = $where_params['OR']; |
|
625 | - } |
|
626 | - if (isset($where_params['DTT_EVT_end'])) { |
|
627 | - $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
628 | - unset($where_params['DTT_EVT_end']); |
|
629 | - } |
|
630 | - if (isset($where_params['DTT_EVT_start'])) { |
|
631 | - $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start']; |
|
632 | - unset($where_params['DTT_EVT_start']); |
|
633 | - } |
|
634 | - $where_params['AND']['Event.status'] = array('!=', 'publish'); |
|
635 | - break; |
|
636 | - } |
|
637 | - $query_params[0] = $where_params; |
|
638 | - $query_params['group_by'] = array('dtt_year', 'dtt_month'); |
|
639 | - $query_params['order_by'] = array('DTT_EVT_start' => 'DESC'); |
|
640 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset( |
|
641 | - $this->get_timezone(), |
|
642 | - 'DTT_EVT_start' |
|
643 | - ); |
|
644 | - $columns_to_select = array( |
|
645 | - 'dtt_year' => array('YEAR(' . $query_interval . ')', '%s'), |
|
646 | - 'dtt_month' => array('MONTHNAME(' . $query_interval . ')', '%s'), |
|
647 | - 'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'), |
|
648 | - ); |
|
649 | - return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
|
650 | - } |
|
651 | - |
|
652 | - |
|
653 | - /** |
|
654 | - * Updates the DTT_sold attribute on each datetime (based on the registrations |
|
655 | - * for the tickets for each datetime) |
|
656 | - * |
|
657 | - * @param EE_Base_Class[]|EE_Datetime[] $datetimes |
|
658 | - * @throws EE_Error |
|
659 | - */ |
|
660 | - public function update_sold($datetimes) |
|
661 | - { |
|
662 | - EE_Error::doing_it_wrong( |
|
663 | - __FUNCTION__, |
|
664 | - esc_html__( |
|
665 | - 'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.', |
|
666 | - 'event_espresso' |
|
667 | - ), |
|
668 | - '4.9.32.rc.005' |
|
669 | - ); |
|
670 | - foreach ($datetimes as $datetime) { |
|
671 | - $datetime->update_sold(); |
|
672 | - } |
|
673 | - } |
|
674 | - |
|
675 | - |
|
676 | - /** |
|
677 | - * Gets the total number of tickets available at a particular datetime |
|
678 | - * (does NOT take into account the datetime's spaces available) |
|
679 | - * |
|
680 | - * @param int $DTT_ID |
|
681 | - * @param array $query_params |
|
682 | - * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF, IF there are NO |
|
683 | - * tickets attached to datetime then FALSE is returned. |
|
684 | - */ |
|
685 | - public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array()) |
|
686 | - { |
|
687 | - $datetime = $this->get_one_by_ID($DTT_ID); |
|
688 | - if ($datetime instanceof EE_Datetime) { |
|
689 | - return $datetime->tickets_remaining($query_params); |
|
690 | - } |
|
691 | - return 0; |
|
692 | - } |
|
693 | - |
|
694 | - |
|
695 | - /** |
|
696 | - * This returns an array of counts of datetimes in the database for each Datetime status that can be queried. |
|
697 | - * |
|
698 | - * @param array $stati_to_include If included you can restrict the statuses we return counts for by including the |
|
699 | - * stati you want counts for as values in the array. An empty array returns counts |
|
700 | - * for all valid stati. |
|
701 | - * @param array $query_params If included can be used to refine the conditions for returning the count (i.e. |
|
702 | - * only for Datetimes connected to a specific event, or specific ticket. |
|
703 | - * @return array The value returned is an array indexed by Datetime Status and the values are the counts. The |
|
704 | - * @throws EE_Error |
|
705 | - * stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming |
|
706 | - * EE_Datetime::expired |
|
707 | - */ |
|
708 | - public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array()) |
|
709 | - { |
|
710 | - // only accept where conditions for this query. |
|
711 | - $_where = isset($query_params[0]) ? $query_params[0] : array(); |
|
712 | - $status_query_args = array( |
|
713 | - EE_Datetime::active => array_merge( |
|
714 | - $_where, |
|
715 | - array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time())) |
|
716 | - ), |
|
717 | - EE_Datetime::upcoming => array_merge( |
|
718 | - $_where, |
|
719 | - array('DTT_EVT_start' => array('>', time())) |
|
720 | - ), |
|
721 | - EE_Datetime::expired => array_merge( |
|
722 | - $_where, |
|
723 | - array('DTT_EVT_end' => array('<', time())) |
|
724 | - ), |
|
725 | - ); |
|
726 | - if (! empty($stati_to_include)) { |
|
727 | - foreach (array_keys($status_query_args) as $status) { |
|
728 | - if (! in_array($status, $stati_to_include, true)) { |
|
729 | - unset($status_query_args[ $status ]); |
|
730 | - } |
|
731 | - } |
|
732 | - } |
|
733 | - // loop through and query counts for each stati. |
|
734 | - $status_query_results = array(); |
|
735 | - foreach ($status_query_args as $status => $status_where_conditions) { |
|
736 | - $status_query_results[ $status ] = EEM_Datetime::count( |
|
737 | - array($status_where_conditions), |
|
738 | - 'DTT_ID', |
|
739 | - true |
|
740 | - ); |
|
741 | - } |
|
742 | - return $status_query_results; |
|
743 | - } |
|
744 | - |
|
745 | - |
|
746 | - /** |
|
747 | - * Returns the specific count for a given Datetime status matching any given query_params. |
|
748 | - * |
|
749 | - * @param string $status Valid string representation for Datetime status requested. (Defaults to Active). |
|
750 | - * @param array $query_params |
|
751 | - * @return int |
|
752 | - * @throws EE_Error |
|
753 | - */ |
|
754 | - public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array()) |
|
755 | - { |
|
756 | - $count = $this->get_datetime_counts_by_status(array($status), $query_params); |
|
757 | - return ! empty($count[ $status ]) ? $count[ $status ] : 0; |
|
758 | - } |
|
16 | + /** |
|
17 | + * @var EEM_Datetime $_instance |
|
18 | + */ |
|
19 | + protected static $_instance; |
|
20 | + |
|
21 | + |
|
22 | + /** |
|
23 | + * private constructor to prevent direct creation |
|
24 | + * |
|
25 | + * @param string $timezone A string representing the timezone we want to set for returned Date Time Strings |
|
26 | + * (and any incoming timezone data that gets saved). |
|
27 | + * Note this just sends the timezone info to the date time model field objects. |
|
28 | + * Default is NULL |
|
29 | + * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
30 | + * @throws EE_Error |
|
31 | + * @throws InvalidArgumentException |
|
32 | + * @throws InvalidArgumentException |
|
33 | + */ |
|
34 | + protected function __construct($timezone) |
|
35 | + { |
|
36 | + $this->singular_item = esc_html__('Datetime', 'event_espresso'); |
|
37 | + $this->plural_item = esc_html__('Datetimes', 'event_espresso'); |
|
38 | + $this->_tables = array( |
|
39 | + 'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'), |
|
40 | + ); |
|
41 | + $this->_fields = array( |
|
42 | + 'Datetime' => array( |
|
43 | + 'DTT_ID' => new EE_Primary_Key_Int_Field( |
|
44 | + 'DTT_ID', |
|
45 | + esc_html__('Datetime ID', 'event_espresso') |
|
46 | + ), |
|
47 | + 'EVT_ID' => new EE_Foreign_Key_Int_Field( |
|
48 | + 'EVT_ID', |
|
49 | + esc_html__('Event ID', 'event_espresso'), |
|
50 | + false, |
|
51 | + 0, |
|
52 | + 'Event' |
|
53 | + ), |
|
54 | + 'DTT_name' => new EE_Plain_Text_Field( |
|
55 | + 'DTT_name', |
|
56 | + esc_html__('Datetime Name', 'event_espresso'), |
|
57 | + false, |
|
58 | + '' |
|
59 | + ), |
|
60 | + 'DTT_description' => new EE_Post_Content_Field( |
|
61 | + 'DTT_description', |
|
62 | + esc_html__('Description for Datetime', 'event_espresso'), |
|
63 | + false, |
|
64 | + '' |
|
65 | + ), |
|
66 | + 'DTT_EVT_start' => new EE_Datetime_Field( |
|
67 | + 'DTT_EVT_start', |
|
68 | + esc_html__('Start time/date of Event', 'event_espresso'), |
|
69 | + false, |
|
70 | + EE_Datetime_Field::now, |
|
71 | + $timezone |
|
72 | + ), |
|
73 | + 'DTT_EVT_end' => new EE_Datetime_Field( |
|
74 | + 'DTT_EVT_end', |
|
75 | + esc_html__('End time/date of Event', 'event_espresso'), |
|
76 | + false, |
|
77 | + EE_Datetime_Field::now, |
|
78 | + $timezone |
|
79 | + ), |
|
80 | + 'DTT_reg_limit' => new EE_Infinite_Integer_Field( |
|
81 | + 'DTT_reg_limit', |
|
82 | + esc_html__('Registration Limit for this time', 'event_espresso'), |
|
83 | + true, |
|
84 | + EE_INF |
|
85 | + ), |
|
86 | + 'DTT_sold' => new EE_Integer_Field( |
|
87 | + 'DTT_sold', |
|
88 | + esc_html__('How many sales for this Datetime that have occurred', 'event_espresso'), |
|
89 | + true, |
|
90 | + 0 |
|
91 | + ), |
|
92 | + 'DTT_reserved' => new EE_Integer_Field( |
|
93 | + 'DTT_reserved', |
|
94 | + esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'), |
|
95 | + false, |
|
96 | + 0 |
|
97 | + ), |
|
98 | + 'DTT_is_primary' => new EE_Boolean_Field( |
|
99 | + 'DTT_is_primary', |
|
100 | + esc_html__('Flag indicating datetime is primary one for event', 'event_espresso'), |
|
101 | + false, |
|
102 | + false |
|
103 | + ), |
|
104 | + 'DTT_order' => new EE_Integer_Field( |
|
105 | + 'DTT_order', |
|
106 | + esc_html__('The order in which the Datetime is displayed', 'event_espresso'), |
|
107 | + false, |
|
108 | + 0 |
|
109 | + ), |
|
110 | + 'DTT_parent' => new EE_Integer_Field( |
|
111 | + 'DTT_parent', |
|
112 | + esc_html__('Indicates what DTT_ID is the parent of this DTT_ID', 'event_espresso'), |
|
113 | + true, |
|
114 | + 0 |
|
115 | + ), |
|
116 | + 'DTT_deleted' => new EE_Trashed_Flag_Field( |
|
117 | + 'DTT_deleted', |
|
118 | + esc_html__('Flag indicating datetime is archived', 'event_espresso'), |
|
119 | + false, |
|
120 | + false |
|
121 | + ), |
|
122 | + ), |
|
123 | + ); |
|
124 | + $this->_model_relations = array( |
|
125 | + 'Ticket' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
126 | + 'Event' => new EE_Belongs_To_Relation(), |
|
127 | + 'Checkin' => new EE_Has_Many_Relation(), |
|
128 | + 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
|
129 | + ); |
|
130 | + $path_to_event_model = 'Event'; |
|
131 | + $this->model_chain_to_password = $path_to_event_model; |
|
132 | + $this->_model_chain_to_wp_user = $path_to_event_model; |
|
133 | + // this model is generally available for reading |
|
134 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
135 | + $path_to_event_model |
|
136 | + ); |
|
137 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
138 | + $path_to_event_model |
|
139 | + ); |
|
140 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
141 | + $path_to_event_model |
|
142 | + ); |
|
143 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
144 | + $path_to_event_model, |
|
145 | + EEM_Base::caps_edit |
|
146 | + ); |
|
147 | + parent::__construct($timezone); |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * create new blank datetime |
|
153 | + * |
|
154 | + * @access public |
|
155 | + * @return EE_Datetime[] array on success, FALSE on fail |
|
156 | + * @throws EE_Error |
|
157 | + * @throws InvalidArgumentException |
|
158 | + * @throws InvalidDataTypeException |
|
159 | + * @throws ReflectionException |
|
160 | + * @throws InvalidInterfaceException |
|
161 | + */ |
|
162 | + public function create_new_blank_datetime() |
|
163 | + { |
|
164 | + // makes sure timezone is always set. |
|
165 | + $timezone_string = $this->get_timezone(); |
|
166 | + /** |
|
167 | + * Filters the initial start date for the new datetime. |
|
168 | + * Any time included in this value will be overridden later so use additional filters to modify the time. |
|
169 | + * |
|
170 | + * @param int $start_date Unixtimestamp representing now + 30 days in seconds. |
|
171 | + * @return int unixtimestamp |
|
172 | + */ |
|
173 | + $start_date = apply_filters( |
|
174 | + 'FHEE__EEM_Datetime__create_new_blank_datetime__start_date', |
|
175 | + $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS |
|
176 | + ); |
|
177 | + /** |
|
178 | + * Filters the initial end date for the new datetime. |
|
179 | + * Any time included in this value will be overridden later so use additional filters to modify the time. |
|
180 | + * |
|
181 | + * @param int $end_data Unixtimestamp representing now + 30 days in seconds. |
|
182 | + * @return int unixtimestamp |
|
183 | + */ |
|
184 | + $end_date = apply_filters( |
|
185 | + 'FHEE__EEM_Datetime__create_new_blank_datetime__end_date', |
|
186 | + $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS |
|
187 | + ); |
|
188 | + $blank_datetime = EE_Datetime::new_instance( |
|
189 | + array( |
|
190 | + 'DTT_EVT_start' => $start_date, |
|
191 | + 'DTT_EVT_end' => $end_date, |
|
192 | + 'DTT_order' => 1, |
|
193 | + 'DTT_reg_limit' => EE_INF, |
|
194 | + ), |
|
195 | + $timezone_string |
|
196 | + ); |
|
197 | + /** |
|
198 | + * Filters the initial start time and format for the new EE_Datetime instance. |
|
199 | + * |
|
200 | + * @param array $start_time An array having size 2. First element is the time, second element is the time |
|
201 | + * format. |
|
202 | + * @return array |
|
203 | + */ |
|
204 | + $start_time = apply_filters( |
|
205 | + 'FHEE__EEM_Datetime__create_new_blank_datetime__start_time', |
|
206 | + ['8am', 'ga'] |
|
207 | + ); |
|
208 | + /** |
|
209 | + * Filters the initial end time and format for the new EE_Datetime instance. |
|
210 | + * |
|
211 | + * @param array $end_time An array having size 2. First element is the time, second element is the time |
|
212 | + * format |
|
213 | + * @return array |
|
214 | + */ |
|
215 | + $end_time = apply_filters( |
|
216 | + 'FHEE__EEM_Datetime__create_new_blank_datetime__end_time', |
|
217 | + ['5pm', 'ga'] |
|
218 | + ); |
|
219 | + $this->validateStartAndEndTimeForBlankDate($start_time, $end_time); |
|
220 | + $blank_datetime->set_start_time( |
|
221 | + $this->convert_datetime_for_query( |
|
222 | + 'DTT_EVT_start', |
|
223 | + $start_time[0], |
|
224 | + $start_time[1], |
|
225 | + $timezone_string |
|
226 | + ) |
|
227 | + ); |
|
228 | + $blank_datetime->set_end_time( |
|
229 | + $this->convert_datetime_for_query( |
|
230 | + 'DTT_EVT_end', |
|
231 | + $end_time[0], |
|
232 | + $end_time[1], |
|
233 | + $timezone_string |
|
234 | + ) |
|
235 | + ); |
|
236 | + return array($blank_datetime); |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * Validates whether the start_time and end_time are in the expected format. |
|
242 | + * @param array $start_time |
|
243 | + * @param array $end_time |
|
244 | + * @throws InvalidArgumentException |
|
245 | + * @throws InvalidDataTypeException |
|
246 | + */ |
|
247 | + private function validateStartAndEndTimeForBlankDate($start_time, $end_time) |
|
248 | + { |
|
249 | + if (! is_array($start_time)) { |
|
250 | + throw new InvalidDataTypeException('start_time', $start_time, 'array'); |
|
251 | + } |
|
252 | + if (! is_array($end_time)) { |
|
253 | + throw new InvalidDataTypeException('end_time', $end_time, 'array'); |
|
254 | + } |
|
255 | + if (count($start_time) !== 2) { |
|
256 | + throw new InvalidArgumentException( |
|
257 | + sprintf( |
|
258 | + 'The variable %1$s is expected to be an array with two elements. The first item in the ' |
|
259 | + . 'array should be a valid time string, the second item in the array should be a valid time format', |
|
260 | + '$start_time' |
|
261 | + ) |
|
262 | + ); |
|
263 | + } |
|
264 | + if (count($end_time) !== 2) { |
|
265 | + throw new InvalidArgumentException( |
|
266 | + sprintf( |
|
267 | + 'The variable %1$s is expected to be an array with two elements. The first item in the ' |
|
268 | + . 'array should be a valid time string, the second item in the array should be a valid time format', |
|
269 | + '$end_time' |
|
270 | + ) |
|
271 | + ); |
|
272 | + } |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * get event start date from db |
|
278 | + * |
|
279 | + * @access public |
|
280 | + * @param int $EVT_ID |
|
281 | + * @return EE_Datetime[] array on success, FALSE on fail |
|
282 | + * @throws EE_Error |
|
283 | + */ |
|
284 | + public function get_all_event_dates($EVT_ID = 0) |
|
285 | + { |
|
286 | + if (! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
287 | + return $this->create_new_blank_datetime(); |
|
288 | + } |
|
289 | + $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID); |
|
290 | + if (empty($results)) { |
|
291 | + return $this->create_new_blank_datetime(); |
|
292 | + } |
|
293 | + return $results; |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * get all datetimes attached to an event ordered by the DTT_order field |
|
299 | + * |
|
300 | + * @public |
|
301 | + * @param int $EVT_ID event id |
|
302 | + * @param boolean $include_expired |
|
303 | + * @param boolean $include_deleted |
|
304 | + * @param int $limit If included then limit the count of results by |
|
305 | + * the given number |
|
306 | + * @return EE_Datetime[] |
|
307 | + * @throws EE_Error |
|
308 | + */ |
|
309 | + public function get_datetimes_for_event_ordered_by_DTT_order( |
|
310 | + $EVT_ID, |
|
311 | + $include_expired = true, |
|
312 | + $include_deleted = true, |
|
313 | + $limit = null |
|
314 | + ) { |
|
315 | + // sanitize EVT_ID |
|
316 | + $EVT_ID = absint($EVT_ID); |
|
317 | + $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
318 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
319 | + $where_params = array('Event.EVT_ID' => $EVT_ID); |
|
320 | + $query_params = ! empty($limit) |
|
321 | + ? array( |
|
322 | + $where_params, |
|
323 | + 'limit' => $limit, |
|
324 | + 'order_by' => array('DTT_order' => 'ASC'), |
|
325 | + 'default_where_conditions' => 'none', |
|
326 | + ) |
|
327 | + : array( |
|
328 | + $where_params, |
|
329 | + 'order_by' => array('DTT_order' => 'ASC'), |
|
330 | + 'default_where_conditions' => 'none', |
|
331 | + ); |
|
332 | + if (! $include_expired) { |
|
333 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
334 | + } |
|
335 | + if ($include_deleted) { |
|
336 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
337 | + } |
|
338 | + /** @var EE_Datetime[] $result */ |
|
339 | + $result = $this->get_all($query_params); |
|
340 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
341 | + return $result; |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + /** |
|
346 | + * Gets the datetimes for the event (with the given limit), and orders them by "importance". |
|
347 | + * By importance, we mean that the primary datetimes are most important (DEPRECATED FOR NOW), |
|
348 | + * and then the earlier datetimes are the most important. |
|
349 | + * Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet. |
|
350 | + * |
|
351 | + * @param int $EVT_ID |
|
352 | + * @param int $limit |
|
353 | + * @return EE_Datetime[]|EE_Base_Class[] |
|
354 | + * @throws EE_Error |
|
355 | + */ |
|
356 | + public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null) |
|
357 | + { |
|
358 | + return $this->get_all( |
|
359 | + array( |
|
360 | + array('Event.EVT_ID' => $EVT_ID), |
|
361 | + 'limit' => $limit, |
|
362 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
363 | + 'default_where_conditions' => 'none', |
|
364 | + ) |
|
365 | + ); |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * @param int $EVT_ID |
|
371 | + * @param boolean $include_expired |
|
372 | + * @param boolean $include_deleted |
|
373 | + * @return EE_Datetime |
|
374 | + * @throws EE_Error |
|
375 | + */ |
|
376 | + public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false) |
|
377 | + { |
|
378 | + $results = $this->get_datetimes_for_event_ordered_by_start_time( |
|
379 | + $EVT_ID, |
|
380 | + $include_expired, |
|
381 | + $include_deleted, |
|
382 | + 1 |
|
383 | + ); |
|
384 | + if ($results) { |
|
385 | + return array_shift($results); |
|
386 | + } |
|
387 | + return null; |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + /** |
|
392 | + * Gets the 'primary' datetime for an event. |
|
393 | + * |
|
394 | + * @param int $EVT_ID |
|
395 | + * @param bool $try_to_exclude_expired |
|
396 | + * @param bool $try_to_exclude_deleted |
|
397 | + * @return \EE_Datetime |
|
398 | + * @throws EE_Error |
|
399 | + */ |
|
400 | + public function get_primary_datetime_for_event( |
|
401 | + $EVT_ID, |
|
402 | + $try_to_exclude_expired = true, |
|
403 | + $try_to_exclude_deleted = true |
|
404 | + ) { |
|
405 | + if ($try_to_exclude_expired) { |
|
406 | + $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false); |
|
407 | + if ($non_expired) { |
|
408 | + return $non_expired; |
|
409 | + } |
|
410 | + } |
|
411 | + if ($try_to_exclude_deleted) { |
|
412 | + $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true); |
|
413 | + if ($expired_even) { |
|
414 | + return $expired_even; |
|
415 | + } |
|
416 | + } |
|
417 | + return $this->get_oldest_datetime_for_event($EVT_ID, true, true); |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + /** |
|
422 | + * Gets ALL the datetimes for an event (including trashed ones, for now), ordered |
|
423 | + * only by start date |
|
424 | + * |
|
425 | + * @param int $EVT_ID |
|
426 | + * @param boolean $include_expired |
|
427 | + * @param boolean $include_deleted |
|
428 | + * @param int $limit |
|
429 | + * @return EE_Datetime[] |
|
430 | + * @throws EE_Error |
|
431 | + */ |
|
432 | + public function get_datetimes_for_event_ordered_by_start_time( |
|
433 | + $EVT_ID, |
|
434 | + $include_expired = true, |
|
435 | + $include_deleted = true, |
|
436 | + $limit = null |
|
437 | + ) { |
|
438 | + // sanitize EVT_ID |
|
439 | + $EVT_ID = absint($EVT_ID); |
|
440 | + $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
441 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
442 | + $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
|
443 | + if (! $include_expired) { |
|
444 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
445 | + } |
|
446 | + if ($include_deleted) { |
|
447 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
448 | + } |
|
449 | + if ($limit) { |
|
450 | + $query_params['limit'] = $limit; |
|
451 | + } |
|
452 | + /** @var EE_Datetime[] $result */ |
|
453 | + $result = $this->get_all($query_params); |
|
454 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
455 | + return $result; |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered |
|
461 | + * only by start date |
|
462 | + * |
|
463 | + * @param int $TKT_ID |
|
464 | + * @param boolean $include_expired |
|
465 | + * @param boolean $include_deleted |
|
466 | + * @param int $limit |
|
467 | + * @return EE_Datetime[] |
|
468 | + * @throws EE_Error |
|
469 | + */ |
|
470 | + public function get_datetimes_for_ticket_ordered_by_start_time( |
|
471 | + $TKT_ID, |
|
472 | + $include_expired = true, |
|
473 | + $include_deleted = true, |
|
474 | + $limit = null |
|
475 | + ) { |
|
476 | + // sanitize TKT_ID |
|
477 | + $TKT_ID = absint($TKT_ID); |
|
478 | + $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
479 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
480 | + $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
|
481 | + if (! $include_expired) { |
|
482 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
483 | + } |
|
484 | + if ($include_deleted) { |
|
485 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
486 | + } |
|
487 | + if ($limit) { |
|
488 | + $query_params['limit'] = $limit; |
|
489 | + } |
|
490 | + /** @var EE_Datetime[] $result */ |
|
491 | + $result = $this->get_all($query_params); |
|
492 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
493 | + return $result; |
|
494 | + } |
|
495 | + |
|
496 | + |
|
497 | + /** |
|
498 | + * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the |
|
499 | + * datetimes. |
|
500 | + * |
|
501 | + * @param int $TKT_ID ID of ticket to retrieve the datetimes for |
|
502 | + * @param boolean $include_expired whether to include expired datetimes or not |
|
503 | + * @param boolean $include_deleted whether to include trashed datetimes or not. |
|
504 | + * @param int|null $limit if null, no limit, if int then limit results by |
|
505 | + * that number |
|
506 | + * @return EE_Datetime[] |
|
507 | + * @throws EE_Error |
|
508 | + */ |
|
509 | + public function get_datetimes_for_ticket_ordered_by_DTT_order( |
|
510 | + $TKT_ID, |
|
511 | + $include_expired = true, |
|
512 | + $include_deleted = true, |
|
513 | + $limit = null |
|
514 | + ) { |
|
515 | + // sanitize id. |
|
516 | + $TKT_ID = absint($TKT_ID); |
|
517 | + $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
518 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
519 | + $where_params = array('Ticket.TKT_ID' => $TKT_ID); |
|
520 | + $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC')); |
|
521 | + if (! $include_expired) { |
|
522 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
523 | + } |
|
524 | + if ($include_deleted) { |
|
525 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
526 | + } |
|
527 | + if ($limit) { |
|
528 | + $query_params['limit'] = $limit; |
|
529 | + } |
|
530 | + /** @var EE_Datetime[] $result */ |
|
531 | + $result = $this->get_all($query_params); |
|
532 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
533 | + return $result; |
|
534 | + } |
|
535 | + |
|
536 | + |
|
537 | + /** |
|
538 | + * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK |
|
539 | + * reason it doesn't exist, we consider the earliest event the most important) |
|
540 | + * |
|
541 | + * @param int $EVT_ID |
|
542 | + * @return EE_Datetime |
|
543 | + * @throws EE_Error |
|
544 | + */ |
|
545 | + public function get_most_important_datetime_for_event($EVT_ID) |
|
546 | + { |
|
547 | + $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1); |
|
548 | + if ($results) { |
|
549 | + return array_shift($results); |
|
550 | + } |
|
551 | + return null; |
|
552 | + } |
|
553 | + |
|
554 | + |
|
555 | + /** |
|
556 | + * This returns a wpdb->results Array of all DTT month and years matching the incoming query params and |
|
557 | + * grouped by month and year. |
|
558 | + * |
|
559 | + * @param array $where_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions |
|
560 | + * @param string $evt_active_status A string representing the evt active status to filter the months by. |
|
561 | + * Can be: |
|
562 | + * - '' = no filter |
|
563 | + * - upcoming = Published events with at least one upcoming datetime. |
|
564 | + * - expired = Events with all datetimes expired. |
|
565 | + * - active = Events that are published and have at least one datetime that |
|
566 | + * starts before now and ends after now. |
|
567 | + * - inactive = Events that are either not published. |
|
568 | + * @return EE_Base_Class[] |
|
569 | + * @throws EE_Error |
|
570 | + * @throws InvalidArgumentException |
|
571 | + * @throws InvalidArgumentException |
|
572 | + */ |
|
573 | + public function get_dtt_months_and_years($where_params, $evt_active_status = '') |
|
574 | + { |
|
575 | + $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start'); |
|
576 | + $current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end'); |
|
577 | + switch ($evt_active_status) { |
|
578 | + case 'upcoming': |
|
579 | + $where_params['Event.status'] = 'publish'; |
|
580 | + // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
581 | + if (isset($where_params['DTT_EVT_start'])) { |
|
582 | + $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start']; |
|
583 | + } |
|
584 | + $where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start); |
|
585 | + break; |
|
586 | + case 'expired': |
|
587 | + if (isset($where_params['Event.status'])) { |
|
588 | + unset($where_params['Event.status']); |
|
589 | + } |
|
590 | + // get events to exclude |
|
591 | + $exclude_query[0] = array_merge( |
|
592 | + $where_params, |
|
593 | + array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end)) |
|
594 | + ); |
|
595 | + // first get all events that have datetimes where its not expired. |
|
596 | + $event_ids = $this->_get_all_wpdb_results( |
|
597 | + $exclude_query, |
|
598 | + OBJECT_K, |
|
599 | + 'Datetime.EVT_ID' |
|
600 | + ); |
|
601 | + $event_ids = array_keys($event_ids); |
|
602 | + if (isset($where_params['DTT_EVT_end'])) { |
|
603 | + $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
604 | + } |
|
605 | + $where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end); |
|
606 | + $where_params['Event.EVT_ID'] = array('NOT IN', $event_ids); |
|
607 | + break; |
|
608 | + case 'active': |
|
609 | + $where_params['Event.status'] = 'publish'; |
|
610 | + if (isset($where_params['DTT_EVT_start'])) { |
|
611 | + $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start']; |
|
612 | + } |
|
613 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
614 | + $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end']; |
|
615 | + } |
|
616 | + $where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start); |
|
617 | + $where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end); |
|
618 | + break; |
|
619 | + case 'inactive': |
|
620 | + if (isset($where_params['Event.status'])) { |
|
621 | + unset($where_params['Event.status']); |
|
622 | + } |
|
623 | + if (isset($where_params['OR'])) { |
|
624 | + $where_params['AND']['OR'] = $where_params['OR']; |
|
625 | + } |
|
626 | + if (isset($where_params['DTT_EVT_end'])) { |
|
627 | + $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
628 | + unset($where_params['DTT_EVT_end']); |
|
629 | + } |
|
630 | + if (isset($where_params['DTT_EVT_start'])) { |
|
631 | + $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start']; |
|
632 | + unset($where_params['DTT_EVT_start']); |
|
633 | + } |
|
634 | + $where_params['AND']['Event.status'] = array('!=', 'publish'); |
|
635 | + break; |
|
636 | + } |
|
637 | + $query_params[0] = $where_params; |
|
638 | + $query_params['group_by'] = array('dtt_year', 'dtt_month'); |
|
639 | + $query_params['order_by'] = array('DTT_EVT_start' => 'DESC'); |
|
640 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset( |
|
641 | + $this->get_timezone(), |
|
642 | + 'DTT_EVT_start' |
|
643 | + ); |
|
644 | + $columns_to_select = array( |
|
645 | + 'dtt_year' => array('YEAR(' . $query_interval . ')', '%s'), |
|
646 | + 'dtt_month' => array('MONTHNAME(' . $query_interval . ')', '%s'), |
|
647 | + 'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'), |
|
648 | + ); |
|
649 | + return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
|
650 | + } |
|
651 | + |
|
652 | + |
|
653 | + /** |
|
654 | + * Updates the DTT_sold attribute on each datetime (based on the registrations |
|
655 | + * for the tickets for each datetime) |
|
656 | + * |
|
657 | + * @param EE_Base_Class[]|EE_Datetime[] $datetimes |
|
658 | + * @throws EE_Error |
|
659 | + */ |
|
660 | + public function update_sold($datetimes) |
|
661 | + { |
|
662 | + EE_Error::doing_it_wrong( |
|
663 | + __FUNCTION__, |
|
664 | + esc_html__( |
|
665 | + 'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.', |
|
666 | + 'event_espresso' |
|
667 | + ), |
|
668 | + '4.9.32.rc.005' |
|
669 | + ); |
|
670 | + foreach ($datetimes as $datetime) { |
|
671 | + $datetime->update_sold(); |
|
672 | + } |
|
673 | + } |
|
674 | + |
|
675 | + |
|
676 | + /** |
|
677 | + * Gets the total number of tickets available at a particular datetime |
|
678 | + * (does NOT take into account the datetime's spaces available) |
|
679 | + * |
|
680 | + * @param int $DTT_ID |
|
681 | + * @param array $query_params |
|
682 | + * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF, IF there are NO |
|
683 | + * tickets attached to datetime then FALSE is returned. |
|
684 | + */ |
|
685 | + public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array()) |
|
686 | + { |
|
687 | + $datetime = $this->get_one_by_ID($DTT_ID); |
|
688 | + if ($datetime instanceof EE_Datetime) { |
|
689 | + return $datetime->tickets_remaining($query_params); |
|
690 | + } |
|
691 | + return 0; |
|
692 | + } |
|
693 | + |
|
694 | + |
|
695 | + /** |
|
696 | + * This returns an array of counts of datetimes in the database for each Datetime status that can be queried. |
|
697 | + * |
|
698 | + * @param array $stati_to_include If included you can restrict the statuses we return counts for by including the |
|
699 | + * stati you want counts for as values in the array. An empty array returns counts |
|
700 | + * for all valid stati. |
|
701 | + * @param array $query_params If included can be used to refine the conditions for returning the count (i.e. |
|
702 | + * only for Datetimes connected to a specific event, or specific ticket. |
|
703 | + * @return array The value returned is an array indexed by Datetime Status and the values are the counts. The |
|
704 | + * @throws EE_Error |
|
705 | + * stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming |
|
706 | + * EE_Datetime::expired |
|
707 | + */ |
|
708 | + public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array()) |
|
709 | + { |
|
710 | + // only accept where conditions for this query. |
|
711 | + $_where = isset($query_params[0]) ? $query_params[0] : array(); |
|
712 | + $status_query_args = array( |
|
713 | + EE_Datetime::active => array_merge( |
|
714 | + $_where, |
|
715 | + array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time())) |
|
716 | + ), |
|
717 | + EE_Datetime::upcoming => array_merge( |
|
718 | + $_where, |
|
719 | + array('DTT_EVT_start' => array('>', time())) |
|
720 | + ), |
|
721 | + EE_Datetime::expired => array_merge( |
|
722 | + $_where, |
|
723 | + array('DTT_EVT_end' => array('<', time())) |
|
724 | + ), |
|
725 | + ); |
|
726 | + if (! empty($stati_to_include)) { |
|
727 | + foreach (array_keys($status_query_args) as $status) { |
|
728 | + if (! in_array($status, $stati_to_include, true)) { |
|
729 | + unset($status_query_args[ $status ]); |
|
730 | + } |
|
731 | + } |
|
732 | + } |
|
733 | + // loop through and query counts for each stati. |
|
734 | + $status_query_results = array(); |
|
735 | + foreach ($status_query_args as $status => $status_where_conditions) { |
|
736 | + $status_query_results[ $status ] = EEM_Datetime::count( |
|
737 | + array($status_where_conditions), |
|
738 | + 'DTT_ID', |
|
739 | + true |
|
740 | + ); |
|
741 | + } |
|
742 | + return $status_query_results; |
|
743 | + } |
|
744 | + |
|
745 | + |
|
746 | + /** |
|
747 | + * Returns the specific count for a given Datetime status matching any given query_params. |
|
748 | + * |
|
749 | + * @param string $status Valid string representation for Datetime status requested. (Defaults to Active). |
|
750 | + * @param array $query_params |
|
751 | + * @return int |
|
752 | + * @throws EE_Error |
|
753 | + */ |
|
754 | + public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array()) |
|
755 | + { |
|
756 | + $count = $this->get_datetime_counts_by_status(array($status), $query_params); |
|
757 | + return ! empty($count[ $status ]) ? $count[ $status ] : 0; |
|
758 | + } |
|
759 | 759 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | ), |
122 | 122 | ), |
123 | 123 | ); |
124 | - $this->_model_relations = array( |
|
124 | + $this->_model_relations = array( |
|
125 | 125 | 'Ticket' => new EE_HABTM_Relation('Datetime_Ticket'), |
126 | 126 | 'Event' => new EE_Belongs_To_Relation(), |
127 | 127 | 'Checkin' => new EE_Has_Many_Relation(), |
@@ -131,16 +131,16 @@ discard block |
||
131 | 131 | $this->model_chain_to_password = $path_to_event_model; |
132 | 132 | $this->_model_chain_to_wp_user = $path_to_event_model; |
133 | 133 | // this model is generally available for reading |
134 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
134 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public( |
|
135 | 135 | $path_to_event_model |
136 | 136 | ); |
137 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
137 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected( |
|
138 | 138 | $path_to_event_model |
139 | 139 | ); |
140 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
140 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected( |
|
141 | 141 | $path_to_event_model |
142 | 142 | ); |
143 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
143 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected( |
|
144 | 144 | $path_to_event_model, |
145 | 145 | EEM_Base::caps_edit |
146 | 146 | ); |
@@ -246,10 +246,10 @@ discard block |
||
246 | 246 | */ |
247 | 247 | private function validateStartAndEndTimeForBlankDate($start_time, $end_time) |
248 | 248 | { |
249 | - if (! is_array($start_time)) { |
|
249 | + if ( ! is_array($start_time)) { |
|
250 | 250 | throw new InvalidDataTypeException('start_time', $start_time, 'array'); |
251 | 251 | } |
252 | - if (! is_array($end_time)) { |
|
252 | + if ( ! is_array($end_time)) { |
|
253 | 253 | throw new InvalidDataTypeException('end_time', $end_time, 'array'); |
254 | 254 | } |
255 | 255 | if (count($start_time) !== 2) { |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | */ |
284 | 284 | public function get_all_event_dates($EVT_ID = 0) |
285 | 285 | { |
286 | - if (! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
286 | + if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
287 | 287 | return $this->create_new_blank_datetime(); |
288 | 288 | } |
289 | 289 | $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID); |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | 'order_by' => array('DTT_order' => 'ASC'), |
330 | 330 | 'default_where_conditions' => 'none', |
331 | 331 | ); |
332 | - if (! $include_expired) { |
|
332 | + if ( ! $include_expired) { |
|
333 | 333 | $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
334 | 334 | } |
335 | 335 | if ($include_deleted) { |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
441 | 441 | $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
442 | 442 | $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
443 | - if (! $include_expired) { |
|
443 | + if ( ! $include_expired) { |
|
444 | 444 | $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
445 | 445 | } |
446 | 446 | if ($include_deleted) { |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
479 | 479 | $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
480 | 480 | $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
481 | - if (! $include_expired) { |
|
481 | + if ( ! $include_expired) { |
|
482 | 482 | $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
483 | 483 | } |
484 | 484 | if ($include_deleted) { |
@@ -518,7 +518,7 @@ discard block |
||
518 | 518 | $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
519 | 519 | $where_params = array('Ticket.TKT_ID' => $TKT_ID); |
520 | 520 | $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC')); |
521 | - if (! $include_expired) { |
|
521 | + if ( ! $include_expired) { |
|
522 | 522 | $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
523 | 523 | } |
524 | 524 | if ($include_deleted) { |
@@ -641,10 +641,10 @@ discard block |
||
641 | 641 | $this->get_timezone(), |
642 | 642 | 'DTT_EVT_start' |
643 | 643 | ); |
644 | - $columns_to_select = array( |
|
645 | - 'dtt_year' => array('YEAR(' . $query_interval . ')', '%s'), |
|
646 | - 'dtt_month' => array('MONTHNAME(' . $query_interval . ')', '%s'), |
|
647 | - 'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'), |
|
644 | + $columns_to_select = array( |
|
645 | + 'dtt_year' => array('YEAR('.$query_interval.')', '%s'), |
|
646 | + 'dtt_month' => array('MONTHNAME('.$query_interval.')', '%s'), |
|
647 | + 'dtt_month_num' => array('MONTH('.$query_interval.')', '%s'), |
|
648 | 648 | ); |
649 | 649 | return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
650 | 650 | } |
@@ -723,17 +723,17 @@ discard block |
||
723 | 723 | array('DTT_EVT_end' => array('<', time())) |
724 | 724 | ), |
725 | 725 | ); |
726 | - if (! empty($stati_to_include)) { |
|
726 | + if ( ! empty($stati_to_include)) { |
|
727 | 727 | foreach (array_keys($status_query_args) as $status) { |
728 | - if (! in_array($status, $stati_to_include, true)) { |
|
729 | - unset($status_query_args[ $status ]); |
|
728 | + if ( ! in_array($status, $stati_to_include, true)) { |
|
729 | + unset($status_query_args[$status]); |
|
730 | 730 | } |
731 | 731 | } |
732 | 732 | } |
733 | 733 | // loop through and query counts for each stati. |
734 | 734 | $status_query_results = array(); |
735 | 735 | foreach ($status_query_args as $status => $status_where_conditions) { |
736 | - $status_query_results[ $status ] = EEM_Datetime::count( |
|
736 | + $status_query_results[$status] = EEM_Datetime::count( |
|
737 | 737 | array($status_where_conditions), |
738 | 738 | 'DTT_ID', |
739 | 739 | true |
@@ -754,6 +754,6 @@ discard block |
||
754 | 754 | public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array()) |
755 | 755 | { |
756 | 756 | $count = $this->get_datetime_counts_by_status(array($status), $query_params); |
757 | - return ! empty($count[ $status ]) ? $count[ $status ] : 0; |
|
757 | + return ! empty($count[$status]) ? $count[$status] : 0; |
|
758 | 758 | } |
759 | 759 | } |
@@ -1,15 +1,15 @@ |
||
1 | 1 | <?php |
2 | 2 | //echo '<br/><h6 style="color:#2EA2CC;">'. __FILE__ . ' <span style="font-weight:normal;color:#E76700"> Line #: ' . __LINE__ . '</span></h6>'; |
3 | 3 | |
4 | -if ( is_single() || ( is_archive() && espresso_display_datetimes_in_event_list() ) ) : |
|
4 | +if (is_single() || (is_archive() && espresso_display_datetimes_in_event_list())) : |
|
5 | 5 | global $post; |
6 | -do_action( 'AHEE_event_details_before_event_date', $post ); |
|
6 | +do_action('AHEE_event_details_before_event_date', $post); |
|
7 | 7 | ?> |
8 | 8 | <div class="event-datetimes"> |
9 | - <?php espresso_list_of_event_dates( $post->ID );?> |
|
9 | + <?php espresso_list_of_event_dates($post->ID); ?> |
|
10 | 10 | </div> |
11 | 11 | <!-- .event-datetimes --> |
12 | 12 | <?php |
13 | -do_action( 'AHEE_event_details_after_event_date', $post ); |
|
13 | +do_action('AHEE_event_details_after_event_date', $post); |
|
14 | 14 | endif; |
15 | 15 | ?> |
16 | 16 | \ No newline at end of file |
@@ -1247,7 +1247,7 @@ |
||
1247 | 1247 | /** |
1248 | 1248 | * Sets up the limit for the registrations query. |
1249 | 1249 | * |
1250 | - * @param $per_page |
|
1250 | + * @param integer $per_page |
|
1251 | 1251 | * @return array |
1252 | 1252 | */ |
1253 | 1253 | protected function _get_limit($per_page) |
@@ -697,7 +697,7 @@ |
||
697 | 697 | /** |
698 | 698 | * Gets any error message. |
699 | 699 | * |
700 | - * @return mixed|null |
|
700 | + * @return string |
|
701 | 701 | */ |
702 | 702 | public function error_message() |
703 | 703 | { |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | { |
52 | 52 | $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
53 | 53 | // if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db. |
54 | - if (! $has_object) { |
|
54 | + if ( ! $has_object) { |
|
55 | 55 | EE_Registry::instance()->load_helper('URL'); |
56 | 56 | $props_n_values['MSG_token'] = EEH_URL::generate_unique_token(); |
57 | 57 | } |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | { |
220 | 220 | $label_type = $plural ? 'plural' : 'singular'; |
221 | 221 | $messenger = $this->messenger_object(); |
222 | - return $messenger instanceof EE_messenger ? $messenger->label[ $label_type ] : $this->messenger(); |
|
222 | + return $messenger instanceof EE_messenger ? $messenger->label[$label_type] : $this->messenger(); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | $this->messenger(), |
337 | 337 | $this->message_type() |
338 | 338 | ); |
339 | - if (! $valid && $throw_exceptions) { |
|
339 | + if ( ! $valid && $throw_exceptions) { |
|
340 | 340 | throw new EE_Error( |
341 | 341 | sprintf( |
342 | 342 | __( |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | $label_type = $plural ? 'plural' : 'singular'; |
367 | 367 | $message_type = $this->message_type_object(); |
368 | 368 | return $message_type instanceof EE_message_type |
369 | - ? $message_type->label[ $label_type ] |
|
369 | + ? $message_type->label[$label_type] |
|
370 | 370 | : str_replace( |
371 | 371 | '_', |
372 | 372 | ' ', |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | /** @type EE_Message_Resource_Manager $message_resource_manager */ |
398 | 398 | $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
399 | 399 | $contexts = $message_resource_manager->get_all_contexts(); |
400 | - return isset($contexts[ $this->context() ]) ? $contexts[ $this->context() ] : $this->context(); |
|
400 | + return isset($contexts[$this->context()]) ? $contexts[$this->context()] : $this->context(); |
|
401 | 401 | } |
402 | 402 | |
403 | 403 | |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | */ |
453 | 453 | public function recipient_object() |
454 | 454 | { |
455 | - if (! $this->recipient_type() || ! $this->recipient_ID()) { |
|
455 | + if ( ! $this->recipient_type() || ! $this->recipient_ID()) { |
|
456 | 456 | return null; |
457 | 457 | } |
458 | 458 | |
@@ -736,13 +736,13 @@ discard block |
||
736 | 736 | /** |
737 | 737 | * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
738 | 738 | */ |
739 | - if (! empty($this->template_pack)) { |
|
739 | + if ( ! empty($this->template_pack)) { |
|
740 | 740 | return $this->template_pack; |
741 | 741 | } |
742 | 742 | /** @type EE_Message_Template_Group $grp */ |
743 | 743 | $grp = $this->get_first_related('Message_Template_Group'); |
744 | 744 | // if no group then let's try to get the first related group by internal messenger and message type (will use global grp). |
745 | - if (! $grp instanceof EE_Message_Template_Group) { |
|
745 | + if ( ! $grp instanceof EE_Message_Template_Group) { |
|
746 | 746 | $grp = EEM_Message_Template_Group::instance()->get_one( |
747 | 747 | array( |
748 | 748 | array( |
@@ -768,7 +768,7 @@ discard block |
||
768 | 768 | /** |
769 | 769 | * This is deprecated functionality that will be removed eventually but included here now for backward compat. |
770 | 770 | */ |
771 | - if (! empty($this->template_variation)) { |
|
771 | + if ( ! empty($this->template_variation)) { |
|
772 | 772 | return $this->template_variation; |
773 | 773 | } |
774 | 774 | |
@@ -776,7 +776,7 @@ discard block |
||
776 | 776 | $grp = $this->get_first_related('Message_Template_Group'); |
777 | 777 | |
778 | 778 | // if no group then let's try to get the first related group by internal messenger and message type (will use global grp). |
779 | - if (! $grp instanceof EE_Message_Template_Group) { |
|
779 | + if ( ! $grp instanceof EE_Message_Template_Group) { |
|
780 | 780 | $grp = EEM_Message_Template_Group::instance()->get_one( |
781 | 781 | array( |
782 | 782 | array( |
@@ -603,7 +603,7 @@ |
||
603 | 603 | * @param EE_Message $message |
604 | 604 | * @param EE_messenger $messenger |
605 | 605 | * @param EE_message_type $message_type |
606 | - * @param $test_send |
|
606 | + * @param boolean $test_send |
|
607 | 607 | * @return bool true means all went well, false means, not so much. |
608 | 608 | */ |
609 | 609 | protected function _do_preview( |
@@ -133,9 +133,9 @@ discard block |
||
133 | 133 | |
134 | 134 | /** |
135 | 135 | * @param $other_table |
136 | - * @param $other_table_alias |
|
136 | + * @param string $other_table_alias |
|
137 | 137 | * @param $other_table_column |
138 | - * @param $this_table_alias |
|
138 | + * @param string $this_table_alias |
|
139 | 139 | * @param $this_table_join_column |
140 | 140 | * @param string $extra_join_sql |
141 | 141 | * @return string |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * Alters the $query_params to disable default where conditions, unless otherwise specified |
190 | 190 | * |
191 | 191 | * @param string $query_params |
192 | - * @return array |
|
192 | + * @return string |
|
193 | 193 | */ |
194 | 194 | protected function _disable_default_where_conditions_on_query_param($query_params) |
195 | 195 | { |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | * Note: If the related model is extends EEM_Soft_Delete_Base, then the related |
207 | 207 | * model objects will only be soft-deleted. |
208 | 208 | * |
209 | - * @param EE_Base_Class|int|string $model_object_or_id |
|
209 | + * @param EE_Base_Class|null $model_object_or_id |
|
210 | 210 | * @param array $query_params |
211 | 211 | * @return int of how many related models got deleted |
212 | 212 | * @throws \EE_Error |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | * Note: If the related model is extends EEM_Soft_Delete_Base, then the related |
238 | 238 | * model objects will only be soft-deleted. |
239 | 239 | * |
240 | - * @param EE_Base_Class|int|string $model_object_or_id |
|
240 | + * @param EE_Base_Class|null $model_object_or_id |
|
241 | 241 | * @param array $query_params |
242 | 242 | * @return int of how many related models got deleted |
243 | 243 | * @throws \EE_Error |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | $this_table_join_column, |
157 | 157 | $extra_join_sql = '' |
158 | 158 | ) { |
159 | - return " LEFT JOIN " . $other_table . " AS " . $other_table_alias . " ON " . $other_table_alias . "." . $other_table_column . "=" . $this_table_alias . "." . $this_table_join_column . ($extra_join_sql ? " AND $extra_join_sql" : ''); |
|
159 | + return " LEFT JOIN ".$other_table." AS ".$other_table_alias." ON ".$other_table_alias.".".$other_table_column."=".$this_table_alias.".".$this_table_join_column.($extra_join_sql ? " AND $extra_join_sql" : ''); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | . "." |
191 | 191 | . $this->get_this_model()->get_primary_key_field()->get_name(); |
192 | 192 | $model_object_id = $this->_get_model_object_id($model_object_or_id); |
193 | - $query_params[0][ $query_param_where_this_model_pk ] = $model_object_id; |
|
193 | + $query_params[0][$query_param_where_this_model_pk] = $model_object_id; |
|
194 | 194 | return $this->get_other_model()->get_all($query_params); |
195 | 195 | } |
196 | 196 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | */ |
204 | 204 | protected function _disable_default_where_conditions_on_query_param($query_params) |
205 | 205 | { |
206 | - if (! isset($query_params['default_where_conditions'])) { |
|
206 | + if ( ! isset($query_params['default_where_conditions'])) { |
|
207 | 207 | $query_params['default_where_conditions'] = 'none'; |
208 | 208 | } |
209 | 209 | return $query_params; |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | $model_object_or_id |
234 | 234 | ); |
235 | 235 | /* @var $model_object_or_id EE_Base_Class */ |
236 | - if (! $delete_is_blocked) { |
|
236 | + if ( ! $delete_is_blocked) { |
|
237 | 237 | $this->remove_relation_to($model_object_or_id, $related_model_object); |
238 | 238 | $related_model_object->delete(); |
239 | 239 | $deleted_count++; |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | if ($related_model_object instanceof EE_Soft_Delete_Base_Class) { |
270 | 270 | $this->remove_relation_to($model_object_or_id, $related_model_object); |
271 | 271 | $deleted_count++; |
272 | - if (! $delete_is_blocked) { |
|
272 | + if ( ! $delete_is_blocked) { |
|
273 | 273 | $related_model_object->delete_permanently(); |
274 | 274 | } else { |
275 | 275 | // delete is blocked |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | } |
279 | 279 | } else { |
280 | 280 | // its not a soft-deletable thing anyways. do the normal logic. |
281 | - if (! $delete_is_blocked) { |
|
281 | + if ( ! $delete_is_blocked) { |
|
282 | 282 | $this->remove_relation_to($model_object_or_id, $related_model_object); |
283 | 283 | $related_model_object->delete(); |
284 | 284 | $deleted_count++; |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | if ($model_object_or_id instanceof EE_Base_Class) { |
303 | 303 | $model_object_id = $model_object_or_id->ID(); |
304 | 304 | } |
305 | - if (! $model_object_id) { |
|
305 | + if ( ! $model_object_id) { |
|
306 | 306 | throw new EE_Error(sprintf( |
307 | 307 | __( |
308 | 308 | "Sorry, we cant get the related %s model objects to %s model object before it has an ID. You can solve that by just saving it before trying to get its related model objects", |
@@ -15,502 +15,502 @@ |
||
15 | 15 | */ |
16 | 16 | abstract class EE_Model_Relation_Base implements HasSchemaInterface |
17 | 17 | { |
18 | - /** |
|
19 | - * The model name of which this relation is a component (ie, the model that called new EE_Model_Relation_Base) |
|
20 | - * |
|
21 | - * @var string eg Event, Question_Group, Registration |
|
22 | - */ |
|
23 | - private $_this_model_name; |
|
24 | - /** |
|
25 | - * The model name pointed to by this relation (ie, the model we want to establish a relationship to) |
|
26 | - * |
|
27 | - * @var string eg Event, Question_Group, Registration |
|
28 | - */ |
|
29 | - private $_other_model_name; |
|
30 | - |
|
31 | - /** |
|
32 | - * this is typically used when calling the relation models to make sure they inherit any set timezone from the |
|
33 | - * initiating model. |
|
34 | - * |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - protected $_timezone; |
|
38 | - |
|
39 | - /** |
|
40 | - * If you try to delete "this_model", and there are related "other_models", |
|
41 | - * and this isn't null, then abandon the deletion and add this warning. |
|
42 | - * This effectively makes it impossible to delete "this_model" while there are |
|
43 | - * related "other_models" along this relation. |
|
44 | - * |
|
45 | - * @var string (internationalized) |
|
46 | - */ |
|
47 | - protected $_blocking_delete_error_message; |
|
48 | - |
|
49 | - protected $_blocking_delete = false; |
|
50 | - |
|
51 | - /** |
|
52 | - * Object representing the relationship between two models. This knows how to join the models, |
|
53 | - * get related models across the relation, and add-and-remove the relationships. |
|
54 | - * |
|
55 | - * @param boolean $block_deletes if there are related models across this relation, block (prevent |
|
56 | - * and add an error) the deletion of this model |
|
57 | - * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
58 | - * default |
|
59 | - */ |
|
60 | - public function __construct($block_deletes, $blocking_delete_error_message) |
|
61 | - { |
|
62 | - $this->_blocking_delete = $block_deletes; |
|
63 | - $this->_blocking_delete_error_message = $blocking_delete_error_message; |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * @param $this_model_name |
|
69 | - * @param $other_model_name |
|
70 | - * @throws EE_Error |
|
71 | - */ |
|
72 | - public function _construct_finalize_set_models($this_model_name, $other_model_name) |
|
73 | - { |
|
74 | - $this->_this_model_name = $this_model_name; |
|
75 | - $this->_other_model_name = $other_model_name; |
|
76 | - if (is_string($this->_blocking_delete)) { |
|
77 | - throw new EE_Error(sprintf( |
|
78 | - __( |
|
79 | - "When instantiating the relation of type %s from %s to %s, the \$block_deletes argument should be a boolean, not a string (%s)", |
|
80 | - "event_espresso" |
|
81 | - ), |
|
82 | - get_class($this), |
|
83 | - $this_model_name, |
|
84 | - $other_model_name, |
|
85 | - $this->_blocking_delete |
|
86 | - )); |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * Gets the model where this relation is defined. |
|
93 | - * |
|
94 | - * @return EEM_Base |
|
95 | - */ |
|
96 | - public function get_this_model() |
|
97 | - { |
|
98 | - return $this->_get_model($this->_this_model_name); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * Gets the model which this relation establishes the relation TO (ie, |
|
104 | - * this relation object was defined on get_this_model(), get_other_model() is the other one) |
|
105 | - * |
|
106 | - * @return EEM_Base |
|
107 | - */ |
|
108 | - public function get_other_model() |
|
109 | - { |
|
110 | - return $this->_get_model($this->_other_model_name); |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * Internally used by get_this_model() and get_other_model() |
|
116 | - * |
|
117 | - * @param string $model_name like Event, Question_Group, etc. omit the EEM_ |
|
118 | - * @return EEM_Base |
|
119 | - */ |
|
120 | - protected function _get_model($model_name) |
|
121 | - { |
|
122 | - $modelInstance = EE_Registry::instance()->load_model($model_name); |
|
123 | - $modelInstance->set_timezone($this->_timezone); |
|
124 | - return $modelInstance; |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * entirely possible that relations may be called from a model and we need to make sure those relations have their |
|
130 | - * timezone set correctly. |
|
131 | - * |
|
132 | - * @param string $timezone timezone to set. |
|
133 | - */ |
|
134 | - public function set_timezone($timezone) |
|
135 | - { |
|
136 | - if ($timezone !== null) { |
|
137 | - $this->_timezone = $timezone; |
|
138 | - } |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @param $other_table |
|
144 | - * @param $other_table_alias |
|
145 | - * @param $other_table_column |
|
146 | - * @param $this_table_alias |
|
147 | - * @param $this_table_join_column |
|
148 | - * @param string $extra_join_sql |
|
149 | - * @return string |
|
150 | - */ |
|
151 | - protected function _left_join( |
|
152 | - $other_table, |
|
153 | - $other_table_alias, |
|
154 | - $other_table_column, |
|
155 | - $this_table_alias, |
|
156 | - $this_table_join_column, |
|
157 | - $extra_join_sql = '' |
|
158 | - ) { |
|
159 | - return " LEFT JOIN " . $other_table . " AS " . $other_table_alias . " ON " . $other_table_alias . "." . $other_table_column . "=" . $this_table_alias . "." . $this_table_join_column . ($extra_join_sql ? " AND $extra_join_sql" : ''); |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * Gets all the model objects of type of other model related to $model_object, |
|
165 | - * according to this relation. This is the same code for EE_HABTM_Relation and EE_Has_Many_Relation. |
|
166 | - * For both of those child classes, $model_object must be saved so that it has an ID before querying, |
|
167 | - * otherwise an error will be thrown. Note: by default we disable default_where_conditions |
|
168 | - * EE_Belongs_To_Relation doesn't need to be saved before querying. |
|
169 | - * |
|
170 | - * @param EE_Base_Class|int $model_object_or_id or the primary key of this model |
|
171 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
172 | - * @param boolean $values_already_prepared_by_model_object @deprecated since 4.8.1 |
|
173 | - * @return EE_Base_Class[] |
|
174 | - * @throws \EE_Error |
|
175 | - */ |
|
176 | - public function get_all_related( |
|
177 | - $model_object_or_id, |
|
178 | - $query_params = array(), |
|
179 | - $values_already_prepared_by_model_object = false |
|
180 | - ) { |
|
181 | - if ($values_already_prepared_by_model_object !== false) { |
|
182 | - EE_Error::doing_it_wrong( |
|
183 | - 'EE_Model_Relation_Base::get_all_related', |
|
184 | - __('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'), |
|
185 | - '4.8.1' |
|
186 | - ); |
|
187 | - } |
|
188 | - $query_params = $this->_disable_default_where_conditions_on_query_param($query_params); |
|
189 | - $query_param_where_this_model_pk = $this->get_this_model()->get_this_model_name() |
|
190 | - . "." |
|
191 | - . $this->get_this_model()->get_primary_key_field()->get_name(); |
|
192 | - $model_object_id = $this->_get_model_object_id($model_object_or_id); |
|
193 | - $query_params[0][ $query_param_where_this_model_pk ] = $model_object_id; |
|
194 | - return $this->get_other_model()->get_all($query_params); |
|
195 | - } |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * Alters the $query_params to disable default where conditions, unless otherwise specified |
|
200 | - * |
|
201 | - * @param string $query_params |
|
202 | - * @return array |
|
203 | - */ |
|
204 | - protected function _disable_default_where_conditions_on_query_param($query_params) |
|
205 | - { |
|
206 | - if (! isset($query_params['default_where_conditions'])) { |
|
207 | - $query_params['default_where_conditions'] = 'none'; |
|
208 | - } |
|
209 | - return $query_params; |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * Deletes the related model objects which meet the query parameters. If no |
|
215 | - * parameters are specified, then all related model objects will be deleted. |
|
216 | - * Note: If the related model is extends EEM_Soft_Delete_Base, then the related |
|
217 | - * model objects will only be soft-deleted. |
|
218 | - * |
|
219 | - * @param EE_Base_Class|int|string $model_object_or_id |
|
220 | - * @param array $query_params |
|
221 | - * @return int of how many related models got deleted |
|
222 | - * @throws \EE_Error |
|
223 | - */ |
|
224 | - public function delete_all_related($model_object_or_id, $query_params = array()) |
|
225 | - { |
|
226 | - // for each thing we would delete, |
|
227 | - $related_model_objects = $this->get_all_related($model_object_or_id, $query_params); |
|
228 | - // determine if it's blocked by anything else before it can be deleted |
|
229 | - $deleted_count = 0; |
|
230 | - foreach ($related_model_objects as $related_model_object) { |
|
231 | - $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models( |
|
232 | - $related_model_object, |
|
233 | - $model_object_or_id |
|
234 | - ); |
|
235 | - /* @var $model_object_or_id EE_Base_Class */ |
|
236 | - if (! $delete_is_blocked) { |
|
237 | - $this->remove_relation_to($model_object_or_id, $related_model_object); |
|
238 | - $related_model_object->delete(); |
|
239 | - $deleted_count++; |
|
240 | - } |
|
241 | - } |
|
242 | - return $deleted_count; |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * Deletes the related model objects which meet the query parameters. If no |
|
248 | - * parameters are specified, then all related model objects will be deleted. |
|
249 | - * Note: If the related model is extends EEM_Soft_Delete_Base, then the related |
|
250 | - * model objects will only be soft-deleted. |
|
251 | - * |
|
252 | - * @param EE_Base_Class|int|string $model_object_or_id |
|
253 | - * @param array $query_params |
|
254 | - * @return int of how many related models got deleted |
|
255 | - * @throws \EE_Error |
|
256 | - */ |
|
257 | - public function delete_related_permanently($model_object_or_id, $query_params = array()) |
|
258 | - { |
|
259 | - // for each thing we would delete, |
|
260 | - $related_model_objects = $this->get_all_related($model_object_or_id, $query_params); |
|
261 | - // determine if it's blocked by anything else before it can be deleted |
|
262 | - $deleted_count = 0; |
|
263 | - foreach ($related_model_objects as $related_model_object) { |
|
264 | - $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models( |
|
265 | - $related_model_object, |
|
266 | - $model_object_or_id |
|
267 | - ); |
|
268 | - /* @var $model_object_or_id EE_Base_Class */ |
|
269 | - if ($related_model_object instanceof EE_Soft_Delete_Base_Class) { |
|
270 | - $this->remove_relation_to($model_object_or_id, $related_model_object); |
|
271 | - $deleted_count++; |
|
272 | - if (! $delete_is_blocked) { |
|
273 | - $related_model_object->delete_permanently(); |
|
274 | - } else { |
|
275 | - // delete is blocked |
|
276 | - // brent and darren, in this case, wanted to just soft delete it then |
|
277 | - $related_model_object->delete(); |
|
278 | - } |
|
279 | - } else { |
|
280 | - // its not a soft-deletable thing anyways. do the normal logic. |
|
281 | - if (! $delete_is_blocked) { |
|
282 | - $this->remove_relation_to($model_object_or_id, $related_model_object); |
|
283 | - $related_model_object->delete(); |
|
284 | - $deleted_count++; |
|
285 | - } |
|
286 | - } |
|
287 | - } |
|
288 | - return $deleted_count; |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * this just returns a model_object_id for incoming item that could be an object or id. |
|
294 | - * |
|
295 | - * @param EE_Base_Class|int $model_object_or_id model object or the primary key of this model |
|
296 | - * @throws EE_Error |
|
297 | - * @return int |
|
298 | - */ |
|
299 | - protected function _get_model_object_id($model_object_or_id) |
|
300 | - { |
|
301 | - $model_object_id = $model_object_or_id; |
|
302 | - if ($model_object_or_id instanceof EE_Base_Class) { |
|
303 | - $model_object_id = $model_object_or_id->ID(); |
|
304 | - } |
|
305 | - if (! $model_object_id) { |
|
306 | - throw new EE_Error(sprintf( |
|
307 | - __( |
|
308 | - "Sorry, we cant get the related %s model objects to %s model object before it has an ID. You can solve that by just saving it before trying to get its related model objects", |
|
309 | - "event_espresso" |
|
310 | - ), |
|
311 | - $this->get_other_model()->get_this_model_name(), |
|
312 | - $this->get_this_model()->get_this_model_name() |
|
313 | - )); |
|
314 | - } |
|
315 | - return $model_object_id; |
|
316 | - } |
|
317 | - |
|
318 | - |
|
319 | - /** |
|
320 | - * Gets the SQL string for performing the join between this model and the other model. |
|
321 | - * |
|
322 | - * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
323 | - * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk = |
|
324 | - * other_model_primary_table.fk" etc |
|
325 | - */ |
|
326 | - abstract public function get_join_statement($model_relation_chain); |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * Adds a relationships between the two model objects provided. Each type of relationship handles this differently |
|
331 | - * (EE_Belongs_To is a slight exception, it should more accurately be called set_relation_to(...), as this |
|
332 | - * relationship only allows this model to be related to a single other model of this type) |
|
333 | - * |
|
334 | - * @param $this_obj_or_id |
|
335 | - * @param $other_obj_or_id |
|
336 | - * @param array $extra_join_model_fields_n_values |
|
337 | - * @return \EE_Base_Class the EE_Base_Class which was added as a relation. (Convenient if you only pass an ID for |
|
338 | - * $other_obj_or_id) |
|
339 | - */ |
|
340 | - abstract public function add_relation_to( |
|
341 | - $this_obj_or_id, |
|
342 | - $other_obj_or_id, |
|
343 | - $extra_join_model_fields_n_values = array() |
|
344 | - ); |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * Similar to 'add_relation_to(...)', performs the opposite action of removing the relationship between the two |
|
349 | - * model objects |
|
350 | - * |
|
351 | - * @param $this_obj_or_id |
|
352 | - * @param $other_obj_or_id |
|
353 | - * @param array $where_query |
|
354 | - * @return bool |
|
355 | - */ |
|
356 | - abstract public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()); |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * Removes ALL relation instances for this relation obj |
|
361 | - * |
|
362 | - * @param EE_Base_Class|int $this_obj_or_id |
|
363 | - * @param array $where_query_param @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions |
|
364 | - * @return EE_Base_Class[] |
|
365 | - * @throws \EE_Error |
|
366 | - */ |
|
367 | - public function remove_relations($this_obj_or_id, $where_query_param = array()) |
|
368 | - { |
|
369 | - $related_things = $this->get_all_related($this_obj_or_id, array($where_query_param)); |
|
370 | - $objs_removed = array(); |
|
371 | - foreach ($related_things as $related_thing) { |
|
372 | - $objs_removed[] = $this->remove_relation_to($this_obj_or_id, $related_thing); |
|
373 | - } |
|
374 | - return $objs_removed; |
|
375 | - } |
|
376 | - |
|
377 | - |
|
378 | - /** |
|
379 | - * If you aren't allowed to delete this model when there are related models across this |
|
380 | - * relation object, return true. Otherwise, if you can delete this model even though |
|
381 | - * related objects exist, returns false. |
|
382 | - * |
|
383 | - * @return boolean |
|
384 | - */ |
|
385 | - public function block_delete_if_related_models_exist() |
|
386 | - { |
|
387 | - return $this->_blocking_delete; |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - /** |
|
392 | - * Gets the error message to show |
|
393 | - * |
|
394 | - * @return string |
|
395 | - */ |
|
396 | - public function get_deletion_error_message() |
|
397 | - { |
|
398 | - if ($this->_blocking_delete_error_message) { |
|
399 | - return $this->_blocking_delete_error_message; |
|
400 | - } else { |
|
18 | + /** |
|
19 | + * The model name of which this relation is a component (ie, the model that called new EE_Model_Relation_Base) |
|
20 | + * |
|
21 | + * @var string eg Event, Question_Group, Registration |
|
22 | + */ |
|
23 | + private $_this_model_name; |
|
24 | + /** |
|
25 | + * The model name pointed to by this relation (ie, the model we want to establish a relationship to) |
|
26 | + * |
|
27 | + * @var string eg Event, Question_Group, Registration |
|
28 | + */ |
|
29 | + private $_other_model_name; |
|
30 | + |
|
31 | + /** |
|
32 | + * this is typically used when calling the relation models to make sure they inherit any set timezone from the |
|
33 | + * initiating model. |
|
34 | + * |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + protected $_timezone; |
|
38 | + |
|
39 | + /** |
|
40 | + * If you try to delete "this_model", and there are related "other_models", |
|
41 | + * and this isn't null, then abandon the deletion and add this warning. |
|
42 | + * This effectively makes it impossible to delete "this_model" while there are |
|
43 | + * related "other_models" along this relation. |
|
44 | + * |
|
45 | + * @var string (internationalized) |
|
46 | + */ |
|
47 | + protected $_blocking_delete_error_message; |
|
48 | + |
|
49 | + protected $_blocking_delete = false; |
|
50 | + |
|
51 | + /** |
|
52 | + * Object representing the relationship between two models. This knows how to join the models, |
|
53 | + * get related models across the relation, and add-and-remove the relationships. |
|
54 | + * |
|
55 | + * @param boolean $block_deletes if there are related models across this relation, block (prevent |
|
56 | + * and add an error) the deletion of this model |
|
57 | + * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
58 | + * default |
|
59 | + */ |
|
60 | + public function __construct($block_deletes, $blocking_delete_error_message) |
|
61 | + { |
|
62 | + $this->_blocking_delete = $block_deletes; |
|
63 | + $this->_blocking_delete_error_message = $blocking_delete_error_message; |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * @param $this_model_name |
|
69 | + * @param $other_model_name |
|
70 | + * @throws EE_Error |
|
71 | + */ |
|
72 | + public function _construct_finalize_set_models($this_model_name, $other_model_name) |
|
73 | + { |
|
74 | + $this->_this_model_name = $this_model_name; |
|
75 | + $this->_other_model_name = $other_model_name; |
|
76 | + if (is_string($this->_blocking_delete)) { |
|
77 | + throw new EE_Error(sprintf( |
|
78 | + __( |
|
79 | + "When instantiating the relation of type %s from %s to %s, the \$block_deletes argument should be a boolean, not a string (%s)", |
|
80 | + "event_espresso" |
|
81 | + ), |
|
82 | + get_class($this), |
|
83 | + $this_model_name, |
|
84 | + $other_model_name, |
|
85 | + $this->_blocking_delete |
|
86 | + )); |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * Gets the model where this relation is defined. |
|
93 | + * |
|
94 | + * @return EEM_Base |
|
95 | + */ |
|
96 | + public function get_this_model() |
|
97 | + { |
|
98 | + return $this->_get_model($this->_this_model_name); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * Gets the model which this relation establishes the relation TO (ie, |
|
104 | + * this relation object was defined on get_this_model(), get_other_model() is the other one) |
|
105 | + * |
|
106 | + * @return EEM_Base |
|
107 | + */ |
|
108 | + public function get_other_model() |
|
109 | + { |
|
110 | + return $this->_get_model($this->_other_model_name); |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * Internally used by get_this_model() and get_other_model() |
|
116 | + * |
|
117 | + * @param string $model_name like Event, Question_Group, etc. omit the EEM_ |
|
118 | + * @return EEM_Base |
|
119 | + */ |
|
120 | + protected function _get_model($model_name) |
|
121 | + { |
|
122 | + $modelInstance = EE_Registry::instance()->load_model($model_name); |
|
123 | + $modelInstance->set_timezone($this->_timezone); |
|
124 | + return $modelInstance; |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * entirely possible that relations may be called from a model and we need to make sure those relations have their |
|
130 | + * timezone set correctly. |
|
131 | + * |
|
132 | + * @param string $timezone timezone to set. |
|
133 | + */ |
|
134 | + public function set_timezone($timezone) |
|
135 | + { |
|
136 | + if ($timezone !== null) { |
|
137 | + $this->_timezone = $timezone; |
|
138 | + } |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @param $other_table |
|
144 | + * @param $other_table_alias |
|
145 | + * @param $other_table_column |
|
146 | + * @param $this_table_alias |
|
147 | + * @param $this_table_join_column |
|
148 | + * @param string $extra_join_sql |
|
149 | + * @return string |
|
150 | + */ |
|
151 | + protected function _left_join( |
|
152 | + $other_table, |
|
153 | + $other_table_alias, |
|
154 | + $other_table_column, |
|
155 | + $this_table_alias, |
|
156 | + $this_table_join_column, |
|
157 | + $extra_join_sql = '' |
|
158 | + ) { |
|
159 | + return " LEFT JOIN " . $other_table . " AS " . $other_table_alias . " ON " . $other_table_alias . "." . $other_table_column . "=" . $this_table_alias . "." . $this_table_join_column . ($extra_join_sql ? " AND $extra_join_sql" : ''); |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * Gets all the model objects of type of other model related to $model_object, |
|
165 | + * according to this relation. This is the same code for EE_HABTM_Relation and EE_Has_Many_Relation. |
|
166 | + * For both of those child classes, $model_object must be saved so that it has an ID before querying, |
|
167 | + * otherwise an error will be thrown. Note: by default we disable default_where_conditions |
|
168 | + * EE_Belongs_To_Relation doesn't need to be saved before querying. |
|
169 | + * |
|
170 | + * @param EE_Base_Class|int $model_object_or_id or the primary key of this model |
|
171 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
172 | + * @param boolean $values_already_prepared_by_model_object @deprecated since 4.8.1 |
|
173 | + * @return EE_Base_Class[] |
|
174 | + * @throws \EE_Error |
|
175 | + */ |
|
176 | + public function get_all_related( |
|
177 | + $model_object_or_id, |
|
178 | + $query_params = array(), |
|
179 | + $values_already_prepared_by_model_object = false |
|
180 | + ) { |
|
181 | + if ($values_already_prepared_by_model_object !== false) { |
|
182 | + EE_Error::doing_it_wrong( |
|
183 | + 'EE_Model_Relation_Base::get_all_related', |
|
184 | + __('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'), |
|
185 | + '4.8.1' |
|
186 | + ); |
|
187 | + } |
|
188 | + $query_params = $this->_disable_default_where_conditions_on_query_param($query_params); |
|
189 | + $query_param_where_this_model_pk = $this->get_this_model()->get_this_model_name() |
|
190 | + . "." |
|
191 | + . $this->get_this_model()->get_primary_key_field()->get_name(); |
|
192 | + $model_object_id = $this->_get_model_object_id($model_object_or_id); |
|
193 | + $query_params[0][ $query_param_where_this_model_pk ] = $model_object_id; |
|
194 | + return $this->get_other_model()->get_all($query_params); |
|
195 | + } |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * Alters the $query_params to disable default where conditions, unless otherwise specified |
|
200 | + * |
|
201 | + * @param string $query_params |
|
202 | + * @return array |
|
203 | + */ |
|
204 | + protected function _disable_default_where_conditions_on_query_param($query_params) |
|
205 | + { |
|
206 | + if (! isset($query_params['default_where_conditions'])) { |
|
207 | + $query_params['default_where_conditions'] = 'none'; |
|
208 | + } |
|
209 | + return $query_params; |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * Deletes the related model objects which meet the query parameters. If no |
|
215 | + * parameters are specified, then all related model objects will be deleted. |
|
216 | + * Note: If the related model is extends EEM_Soft_Delete_Base, then the related |
|
217 | + * model objects will only be soft-deleted. |
|
218 | + * |
|
219 | + * @param EE_Base_Class|int|string $model_object_or_id |
|
220 | + * @param array $query_params |
|
221 | + * @return int of how many related models got deleted |
|
222 | + * @throws \EE_Error |
|
223 | + */ |
|
224 | + public function delete_all_related($model_object_or_id, $query_params = array()) |
|
225 | + { |
|
226 | + // for each thing we would delete, |
|
227 | + $related_model_objects = $this->get_all_related($model_object_or_id, $query_params); |
|
228 | + // determine if it's blocked by anything else before it can be deleted |
|
229 | + $deleted_count = 0; |
|
230 | + foreach ($related_model_objects as $related_model_object) { |
|
231 | + $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models( |
|
232 | + $related_model_object, |
|
233 | + $model_object_or_id |
|
234 | + ); |
|
235 | + /* @var $model_object_or_id EE_Base_Class */ |
|
236 | + if (! $delete_is_blocked) { |
|
237 | + $this->remove_relation_to($model_object_or_id, $related_model_object); |
|
238 | + $related_model_object->delete(); |
|
239 | + $deleted_count++; |
|
240 | + } |
|
241 | + } |
|
242 | + return $deleted_count; |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * Deletes the related model objects which meet the query parameters. If no |
|
248 | + * parameters are specified, then all related model objects will be deleted. |
|
249 | + * Note: If the related model is extends EEM_Soft_Delete_Base, then the related |
|
250 | + * model objects will only be soft-deleted. |
|
251 | + * |
|
252 | + * @param EE_Base_Class|int|string $model_object_or_id |
|
253 | + * @param array $query_params |
|
254 | + * @return int of how many related models got deleted |
|
255 | + * @throws \EE_Error |
|
256 | + */ |
|
257 | + public function delete_related_permanently($model_object_or_id, $query_params = array()) |
|
258 | + { |
|
259 | + // for each thing we would delete, |
|
260 | + $related_model_objects = $this->get_all_related($model_object_or_id, $query_params); |
|
261 | + // determine if it's blocked by anything else before it can be deleted |
|
262 | + $deleted_count = 0; |
|
263 | + foreach ($related_model_objects as $related_model_object) { |
|
264 | + $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models( |
|
265 | + $related_model_object, |
|
266 | + $model_object_or_id |
|
267 | + ); |
|
268 | + /* @var $model_object_or_id EE_Base_Class */ |
|
269 | + if ($related_model_object instanceof EE_Soft_Delete_Base_Class) { |
|
270 | + $this->remove_relation_to($model_object_or_id, $related_model_object); |
|
271 | + $deleted_count++; |
|
272 | + if (! $delete_is_blocked) { |
|
273 | + $related_model_object->delete_permanently(); |
|
274 | + } else { |
|
275 | + // delete is blocked |
|
276 | + // brent and darren, in this case, wanted to just soft delete it then |
|
277 | + $related_model_object->delete(); |
|
278 | + } |
|
279 | + } else { |
|
280 | + // its not a soft-deletable thing anyways. do the normal logic. |
|
281 | + if (! $delete_is_blocked) { |
|
282 | + $this->remove_relation_to($model_object_or_id, $related_model_object); |
|
283 | + $related_model_object->delete(); |
|
284 | + $deleted_count++; |
|
285 | + } |
|
286 | + } |
|
287 | + } |
|
288 | + return $deleted_count; |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * this just returns a model_object_id for incoming item that could be an object or id. |
|
294 | + * |
|
295 | + * @param EE_Base_Class|int $model_object_or_id model object or the primary key of this model |
|
296 | + * @throws EE_Error |
|
297 | + * @return int |
|
298 | + */ |
|
299 | + protected function _get_model_object_id($model_object_or_id) |
|
300 | + { |
|
301 | + $model_object_id = $model_object_or_id; |
|
302 | + if ($model_object_or_id instanceof EE_Base_Class) { |
|
303 | + $model_object_id = $model_object_or_id->ID(); |
|
304 | + } |
|
305 | + if (! $model_object_id) { |
|
306 | + throw new EE_Error(sprintf( |
|
307 | + __( |
|
308 | + "Sorry, we cant get the related %s model objects to %s model object before it has an ID. You can solve that by just saving it before trying to get its related model objects", |
|
309 | + "event_espresso" |
|
310 | + ), |
|
311 | + $this->get_other_model()->get_this_model_name(), |
|
312 | + $this->get_this_model()->get_this_model_name() |
|
313 | + )); |
|
314 | + } |
|
315 | + return $model_object_id; |
|
316 | + } |
|
317 | + |
|
318 | + |
|
319 | + /** |
|
320 | + * Gets the SQL string for performing the join between this model and the other model. |
|
321 | + * |
|
322 | + * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
323 | + * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk = |
|
324 | + * other_model_primary_table.fk" etc |
|
325 | + */ |
|
326 | + abstract public function get_join_statement($model_relation_chain); |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * Adds a relationships between the two model objects provided. Each type of relationship handles this differently |
|
331 | + * (EE_Belongs_To is a slight exception, it should more accurately be called set_relation_to(...), as this |
|
332 | + * relationship only allows this model to be related to a single other model of this type) |
|
333 | + * |
|
334 | + * @param $this_obj_or_id |
|
335 | + * @param $other_obj_or_id |
|
336 | + * @param array $extra_join_model_fields_n_values |
|
337 | + * @return \EE_Base_Class the EE_Base_Class which was added as a relation. (Convenient if you only pass an ID for |
|
338 | + * $other_obj_or_id) |
|
339 | + */ |
|
340 | + abstract public function add_relation_to( |
|
341 | + $this_obj_or_id, |
|
342 | + $other_obj_or_id, |
|
343 | + $extra_join_model_fields_n_values = array() |
|
344 | + ); |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * Similar to 'add_relation_to(...)', performs the opposite action of removing the relationship between the two |
|
349 | + * model objects |
|
350 | + * |
|
351 | + * @param $this_obj_or_id |
|
352 | + * @param $other_obj_or_id |
|
353 | + * @param array $where_query |
|
354 | + * @return bool |
|
355 | + */ |
|
356 | + abstract public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()); |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * Removes ALL relation instances for this relation obj |
|
361 | + * |
|
362 | + * @param EE_Base_Class|int $this_obj_or_id |
|
363 | + * @param array $where_query_param @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions |
|
364 | + * @return EE_Base_Class[] |
|
365 | + * @throws \EE_Error |
|
366 | + */ |
|
367 | + public function remove_relations($this_obj_or_id, $where_query_param = array()) |
|
368 | + { |
|
369 | + $related_things = $this->get_all_related($this_obj_or_id, array($where_query_param)); |
|
370 | + $objs_removed = array(); |
|
371 | + foreach ($related_things as $related_thing) { |
|
372 | + $objs_removed[] = $this->remove_relation_to($this_obj_or_id, $related_thing); |
|
373 | + } |
|
374 | + return $objs_removed; |
|
375 | + } |
|
376 | + |
|
377 | + |
|
378 | + /** |
|
379 | + * If you aren't allowed to delete this model when there are related models across this |
|
380 | + * relation object, return true. Otherwise, if you can delete this model even though |
|
381 | + * related objects exist, returns false. |
|
382 | + * |
|
383 | + * @return boolean |
|
384 | + */ |
|
385 | + public function block_delete_if_related_models_exist() |
|
386 | + { |
|
387 | + return $this->_blocking_delete; |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + /** |
|
392 | + * Gets the error message to show |
|
393 | + * |
|
394 | + * @return string |
|
395 | + */ |
|
396 | + public function get_deletion_error_message() |
|
397 | + { |
|
398 | + if ($this->_blocking_delete_error_message) { |
|
399 | + return $this->_blocking_delete_error_message; |
|
400 | + } else { |
|
401 | 401 | // return sprintf(__('Cannot delete %1$s when there are related %2$s', "event_espresso"),$this->get_this_model()->item_name(2),$this->get_other_model()->item_name(2)); |
402 | - return sprintf( |
|
403 | - __( |
|
404 | - 'This %1$s is currently linked to one or more %2$s records. If this %1$s is incorrect, then please remove it from all %3$s before attempting to delete it.', |
|
405 | - "event_espresso" |
|
406 | - ), |
|
407 | - $this->get_this_model()->item_name(1), |
|
408 | - $this->get_other_model()->item_name(1), |
|
409 | - $this->get_other_model()->item_name(2) |
|
410 | - ); |
|
411 | - } |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
415 | - * Returns whatever is set as the nicename for the object. |
|
416 | - * |
|
417 | - * @return string |
|
418 | - */ |
|
419 | - public function getSchemaDescription() |
|
420 | - { |
|
421 | - $description = $this instanceof EE_Belongs_To_Relation |
|
422 | - ? esc_html__('The related %1$s entity to the %2$s.', 'event_espresso') |
|
423 | - : esc_html__('The related %1$s entities to the %2$s.', 'event_espresso'); |
|
424 | - return sprintf( |
|
425 | - $description, |
|
426 | - $this->get_other_model()->get_this_model_name(), |
|
427 | - $this->get_this_model()->get_this_model_name() |
|
428 | - ); |
|
429 | - } |
|
430 | - |
|
431 | - /** |
|
432 | - * Returns whatever is set as the $_schema_type property for the object. |
|
433 | - * Note: this will automatically add 'null' to the schema if the object is_nullable() |
|
434 | - * |
|
435 | - * @return string|array |
|
436 | - */ |
|
437 | - public function getSchemaType() |
|
438 | - { |
|
439 | - return $this instanceof EE_Belongs_To_Relation ? 'object' : 'array'; |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * This is usually present when the $_schema_type property is 'object'. Any child classes will need to override |
|
444 | - * this method and return the properties for the schema. |
|
445 | - * The reason this is not a property on the class is because there may be filters set on the values for the property |
|
446 | - * that won't be exposed on construct. For example enum type schemas may have the enum values filtered. |
|
447 | - * |
|
448 | - * @return array |
|
449 | - */ |
|
450 | - public function getSchemaProperties() |
|
451 | - { |
|
452 | - return array(); |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * If a child class has enum values, they should override this method and provide a simple array |
|
457 | - * of the enum values. |
|
458 | - * The reason this is not a property on the class is because there may be filterable enum values that |
|
459 | - * are set on the instantiated object that could be filtered after construct. |
|
460 | - * |
|
461 | - * @return array |
|
462 | - */ |
|
463 | - public function getSchemaEnum() |
|
464 | - { |
|
465 | - return array(); |
|
466 | - } |
|
467 | - |
|
468 | - /** |
|
469 | - * This returns the value of the $_schema_format property on the object. |
|
470 | - * |
|
471 | - * @return string |
|
472 | - */ |
|
473 | - public function getSchemaFormat() |
|
474 | - { |
|
475 | - return array(); |
|
476 | - } |
|
477 | - |
|
478 | - /** |
|
479 | - * This returns the value of the $_schema_readonly property on the object. |
|
480 | - * |
|
481 | - * @return bool |
|
482 | - */ |
|
483 | - public function getSchemaReadonly() |
|
484 | - { |
|
485 | - return true; |
|
486 | - } |
|
487 | - |
|
488 | - /** |
|
489 | - * This returns elements used to represent this field in the json schema. |
|
490 | - * |
|
491 | - * @link http://json-schema.org/ |
|
492 | - * @return array |
|
493 | - */ |
|
494 | - public function getSchema() |
|
495 | - { |
|
496 | - $schema = array( |
|
497 | - 'description' => $this->getSchemaDescription(), |
|
498 | - 'type' => $this->getSchemaType(), |
|
499 | - 'relation' => true, |
|
500 | - 'relation_type' => get_class($this), |
|
501 | - 'readonly' => $this->getSchemaReadonly() |
|
502 | - ); |
|
503 | - |
|
504 | - if ($this instanceof EE_HABTM_Relation) { |
|
505 | - $schema['joining_model_name'] = $this->get_join_model()->get_this_model_name(); |
|
506 | - } |
|
507 | - |
|
508 | - if ($this->getSchemaType() === 'array') { |
|
509 | - $schema['items'] = array( |
|
510 | - 'type' => 'object' |
|
511 | - ); |
|
512 | - } |
|
513 | - |
|
514 | - return $schema; |
|
515 | - } |
|
402 | + return sprintf( |
|
403 | + __( |
|
404 | + 'This %1$s is currently linked to one or more %2$s records. If this %1$s is incorrect, then please remove it from all %3$s before attempting to delete it.', |
|
405 | + "event_espresso" |
|
406 | + ), |
|
407 | + $this->get_this_model()->item_name(1), |
|
408 | + $this->get_other_model()->item_name(1), |
|
409 | + $this->get_other_model()->item_name(2) |
|
410 | + ); |
|
411 | + } |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | + * Returns whatever is set as the nicename for the object. |
|
416 | + * |
|
417 | + * @return string |
|
418 | + */ |
|
419 | + public function getSchemaDescription() |
|
420 | + { |
|
421 | + $description = $this instanceof EE_Belongs_To_Relation |
|
422 | + ? esc_html__('The related %1$s entity to the %2$s.', 'event_espresso') |
|
423 | + : esc_html__('The related %1$s entities to the %2$s.', 'event_espresso'); |
|
424 | + return sprintf( |
|
425 | + $description, |
|
426 | + $this->get_other_model()->get_this_model_name(), |
|
427 | + $this->get_this_model()->get_this_model_name() |
|
428 | + ); |
|
429 | + } |
|
430 | + |
|
431 | + /** |
|
432 | + * Returns whatever is set as the $_schema_type property for the object. |
|
433 | + * Note: this will automatically add 'null' to the schema if the object is_nullable() |
|
434 | + * |
|
435 | + * @return string|array |
|
436 | + */ |
|
437 | + public function getSchemaType() |
|
438 | + { |
|
439 | + return $this instanceof EE_Belongs_To_Relation ? 'object' : 'array'; |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * This is usually present when the $_schema_type property is 'object'. Any child classes will need to override |
|
444 | + * this method and return the properties for the schema. |
|
445 | + * The reason this is not a property on the class is because there may be filters set on the values for the property |
|
446 | + * that won't be exposed on construct. For example enum type schemas may have the enum values filtered. |
|
447 | + * |
|
448 | + * @return array |
|
449 | + */ |
|
450 | + public function getSchemaProperties() |
|
451 | + { |
|
452 | + return array(); |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * If a child class has enum values, they should override this method and provide a simple array |
|
457 | + * of the enum values. |
|
458 | + * The reason this is not a property on the class is because there may be filterable enum values that |
|
459 | + * are set on the instantiated object that could be filtered after construct. |
|
460 | + * |
|
461 | + * @return array |
|
462 | + */ |
|
463 | + public function getSchemaEnum() |
|
464 | + { |
|
465 | + return array(); |
|
466 | + } |
|
467 | + |
|
468 | + /** |
|
469 | + * This returns the value of the $_schema_format property on the object. |
|
470 | + * |
|
471 | + * @return string |
|
472 | + */ |
|
473 | + public function getSchemaFormat() |
|
474 | + { |
|
475 | + return array(); |
|
476 | + } |
|
477 | + |
|
478 | + /** |
|
479 | + * This returns the value of the $_schema_readonly property on the object. |
|
480 | + * |
|
481 | + * @return bool |
|
482 | + */ |
|
483 | + public function getSchemaReadonly() |
|
484 | + { |
|
485 | + return true; |
|
486 | + } |
|
487 | + |
|
488 | + /** |
|
489 | + * This returns elements used to represent this field in the json schema. |
|
490 | + * |
|
491 | + * @link http://json-schema.org/ |
|
492 | + * @return array |
|
493 | + */ |
|
494 | + public function getSchema() |
|
495 | + { |
|
496 | + $schema = array( |
|
497 | + 'description' => $this->getSchemaDescription(), |
|
498 | + 'type' => $this->getSchemaType(), |
|
499 | + 'relation' => true, |
|
500 | + 'relation_type' => get_class($this), |
|
501 | + 'readonly' => $this->getSchemaReadonly() |
|
502 | + ); |
|
503 | + |
|
504 | + if ($this instanceof EE_HABTM_Relation) { |
|
505 | + $schema['joining_model_name'] = $this->get_join_model()->get_this_model_name(); |
|
506 | + } |
|
507 | + |
|
508 | + if ($this->getSchemaType() === 'array') { |
|
509 | + $schema['items'] = array( |
|
510 | + 'type' => 'object' |
|
511 | + ); |
|
512 | + } |
|
513 | + |
|
514 | + return $schema; |
|
515 | + } |
|
516 | 516 | } |
@@ -582,7 +582,7 @@ |
||
582 | 582 | /** |
583 | 583 | * Validates that the incoming format is an allowable string to use for the _schema_format property |
584 | 584 | * @throws InvalidArgumentException |
585 | - * @param $format |
|
585 | + * @param string $format |
|
586 | 586 | */ |
587 | 587 | private function validateSchemaFormat($format) |
588 | 588 | { |