@@ -10,21 +10,21 @@ |
||
10 | 10 | class EE_Admin_Page_Sub_Menu extends EE_Admin_Page_Main_Menu |
11 | 11 | { |
12 | 12 | |
13 | - public function __construct($menu_args) |
|
14 | - { |
|
15 | - parent::__construct($menu_args); |
|
16 | - } |
|
13 | + public function __construct($menu_args) |
|
14 | + { |
|
15 | + parent::__construct($menu_args); |
|
16 | + } |
|
17 | 17 | |
18 | 18 | |
19 | - protected function _add_menu_page() |
|
20 | - { |
|
21 | - return add_submenu_page( |
|
22 | - $this->parent_slug, |
|
23 | - $this->title, |
|
24 | - $this->menu_label, |
|
25 | - $this->capability, |
|
26 | - $this->menu_slug, |
|
27 | - $this->menu_callback |
|
28 | - ); |
|
29 | - } |
|
19 | + protected function _add_menu_page() |
|
20 | + { |
|
21 | + return add_submenu_page( |
|
22 | + $this->parent_slug, |
|
23 | + $this->title, |
|
24 | + $this->menu_label, |
|
25 | + $this->capability, |
|
26 | + $this->menu_slug, |
|
27 | + $this->menu_callback |
|
28 | + ); |
|
29 | + } |
|
30 | 30 | } |
@@ -10,76 +10,76 @@ |
||
10 | 10 | class EE_Admin_Page_Main_Menu extends EE_Admin_Page_Menu_Map |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * If included int incoming params, then this class will also register a Sub Menue Admin page with a different |
|
15 | - * subtitle than the main menu item. |
|
16 | - * |
|
17 | - * @since 4.4.0 |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $subtitle; |
|
13 | + /** |
|
14 | + * If included int incoming params, then this class will also register a Sub Menue Admin page with a different |
|
15 | + * subtitle than the main menu item. |
|
16 | + * |
|
17 | + * @since 4.4.0 |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $subtitle; |
|
22 | 22 | |
23 | - /** |
|
24 | - * The page to a icon used for this menu. |
|
25 | - * |
|
26 | - * @since 4.4.0 |
|
27 | - * @see http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters |
|
28 | - * for what can be set for this property. |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - public $icon_url; |
|
23 | + /** |
|
24 | + * The page to a icon used for this menu. |
|
25 | + * |
|
26 | + * @since 4.4.0 |
|
27 | + * @see http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters |
|
28 | + * for what can be set for this property. |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + public $icon_url; |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * What position in the main menu order for the WP admin menu this menu item |
|
36 | - * should show. |
|
37 | - * |
|
38 | - * @since 4.4.0 |
|
39 | - * @see http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters |
|
40 | - * for what can be set for this property. |
|
41 | - * @var integer |
|
42 | - */ |
|
43 | - public $position; |
|
34 | + /** |
|
35 | + * What position in the main menu order for the WP admin menu this menu item |
|
36 | + * should show. |
|
37 | + * |
|
38 | + * @since 4.4.0 |
|
39 | + * @see http://codex.wordpress.org/Function_Reference/add_menu_page#Parameters |
|
40 | + * for what can be set for this property. |
|
41 | + * @var integer |
|
42 | + */ |
|
43 | + public $position; |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * @throws EE_Error |
|
48 | - */ |
|
49 | - public function __construct($menu_args) |
|
50 | - { |
|
51 | - $required = ['menu_label', 'parent_slug', 'menu_slug', 'menu_group', 'menu_order', 'admin_init_page']; |
|
46 | + /** |
|
47 | + * @throws EE_Error |
|
48 | + */ |
|
49 | + public function __construct($menu_args) |
|
50 | + { |
|
51 | + $required = ['menu_label', 'parent_slug', 'menu_slug', 'menu_group', 'menu_order', 'admin_init_page']; |
|
52 | 52 | |
53 | - parent::__construct($menu_args, $required); |
|
53 | + parent::__construct($menu_args, $required); |
|
54 | 54 | |
55 | - $this->position = ! empty($this->position) ? (int) $this->position : $this->position; |
|
56 | - } |
|
55 | + $this->position = ! empty($this->position) ? (int) $this->position : $this->position; |
|
56 | + } |
|
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * Uses the proper WP utility for registering a menu page for the main WP pages. |
|
61 | - */ |
|
62 | - protected function _add_menu_page() |
|
63 | - { |
|
64 | - $main = add_menu_page( |
|
65 | - $this->title, |
|
66 | - $this->menu_label, |
|
67 | - $this->capability, |
|
68 | - $this->parent_slug, |
|
69 | - $this->menu_callback, |
|
70 | - $this->icon_url, |
|
71 | - $this->position |
|
72 | - ); |
|
73 | - if (! empty($this->subtitle)) { |
|
74 | - add_submenu_page( |
|
75 | - $this->parent_slug, |
|
76 | - $this->subtitle, |
|
77 | - $this->subtitle, |
|
78 | - $this->capability, |
|
79 | - $this->menu_slug, |
|
80 | - $this->menu_callback |
|
81 | - ); |
|
82 | - } |
|
83 | - return $main; |
|
84 | - } |
|
59 | + /** |
|
60 | + * Uses the proper WP utility for registering a menu page for the main WP pages. |
|
61 | + */ |
|
62 | + protected function _add_menu_page() |
|
63 | + { |
|
64 | + $main = add_menu_page( |
|
65 | + $this->title, |
|
66 | + $this->menu_label, |
|
67 | + $this->capability, |
|
68 | + $this->parent_slug, |
|
69 | + $this->menu_callback, |
|
70 | + $this->icon_url, |
|
71 | + $this->position |
|
72 | + ); |
|
73 | + if (! empty($this->subtitle)) { |
|
74 | + add_submenu_page( |
|
75 | + $this->parent_slug, |
|
76 | + $this->subtitle, |
|
77 | + $this->subtitle, |
|
78 | + $this->capability, |
|
79 | + $this->menu_slug, |
|
80 | + $this->menu_callback |
|
81 | + ); |
|
82 | + } |
|
83 | + return $main; |
|
84 | + } |
|
85 | 85 | } |
@@ -70,7 +70,7 @@ |
||
70 | 70 | $this->icon_url, |
71 | 71 | $this->position |
72 | 72 | ); |
73 | - if (! empty($this->subtitle)) { |
|
73 | + if ( ! empty($this->subtitle)) { |
|
74 | 74 | add_submenu_page( |
75 | 75 | $this->parent_slug, |
76 | 76 | $this->subtitle, |
@@ -7,10 +7,10 @@ discard block |
||
7 | 7 | ?> |
8 | 8 | <h2><?php esc_html_e('Event Registration Data', 'event_espresso'); ?></h2> |
9 | 9 | <p><?php |
10 | - esc_html_e( |
|
11 | - 'We collect information about you during event registration. This information may include but is not limited to:', |
|
12 | - 'event_espresso' |
|
13 | - ); ?></p> |
|
10 | + esc_html_e( |
|
11 | + 'We collect information about you during event registration. This information may include but is not limited to:', |
|
12 | + 'event_espresso' |
|
13 | + ); ?></p> |
|
14 | 14 | <ul> |
15 | 15 | <li><?php esc_html_e('Your names', 'event_espresso'); ?></li> |
16 | 16 | <li><?php esc_html_e('Billing address', 'event_espresso'); ?></li> |
@@ -18,16 +18,16 @@ discard block |
||
18 | 18 | <li><?php esc_html_e('Email address', 'event_espresso'); ?></li> |
19 | 19 | <li><?php esc_html_e('Phone number', 'event_espresso'); ?></li> |
20 | 20 | <li><?php |
21 | - esc_html_e( |
|
22 | - 'Location and traffic data (including partial IP address and browser type)', |
|
23 | - 'event_espresso' |
|
24 | - ); ?> |
|
21 | + esc_html_e( |
|
22 | + 'Location and traffic data (including partial IP address and browser type)', |
|
23 | + 'event_espresso' |
|
24 | + ); ?> |
|
25 | 25 | </li> |
26 | 26 | <li><?php |
27 | - esc_html_e( |
|
28 | - 'Any other details that might be requested from you for the purpose of processing your registration or ticket purchase', |
|
29 | - 'event_espresso' |
|
30 | - ); ?> |
|
27 | + esc_html_e( |
|
28 | + 'Any other details that might be requested from you for the purpose of processing your registration or ticket purchase', |
|
29 | + 'event_espresso' |
|
30 | + ); ?> |
|
31 | 31 | </li> |
32 | 32 | </ul> |
33 | 33 | |
@@ -36,101 +36,101 @@ discard block |
||
36 | 36 | <li><?php esc_html_e('Send you important account/purchase/service information.', 'event_espresso'); ?></li> |
37 | 37 | <li><?php esc_html_e('Respond to your queries, refund requests, or complaints.', 'event_espresso'); ?></li> |
38 | 38 | <li><?php |
39 | - esc_html_e( |
|
40 | - 'Process payments and prevent fraudulent transactions. We do this on the basis of our legitimate business interests.', |
|
41 | - 'event_espresso' |
|
42 | - ); ?></li> |
|
39 | + esc_html_e( |
|
40 | + 'Process payments and prevent fraudulent transactions. We do this on the basis of our legitimate business interests.', |
|
41 | + 'event_espresso' |
|
42 | + ); ?></li> |
|
43 | 43 | <li><?php |
44 | - esc_html_e( |
|
45 | - 'Set up and administer your account, provide technical and customer support, and to verify your identity.', |
|
46 | - 'event_espresso' |
|
47 | - ); ?></li> |
|
44 | + esc_html_e( |
|
45 | + 'Set up and administer your account, provide technical and customer support, and to verify your identity.', |
|
46 | + 'event_espresso' |
|
47 | + ); ?></li> |
|
48 | 48 | </ul> |
49 | 49 | |
50 | 50 | <?php if (! empty($active_onsite_payment_methods) || ! empty($active_offsite_payment_methods)) { ?> |
51 | 51 | <h2><?php esc_html_e('Billing Information', 'event_espresso'); ?> </h2> |
52 | 52 | <?php |
53 | - // if onsite or offsite payment methods are active |
|
54 | - if (! empty($active_onsite_payment_methods)) { ?> |
|
53 | + // if onsite or offsite payment methods are active |
|
54 | + if (! empty($active_onsite_payment_methods)) { ?> |
|
55 | 55 | <p><?php |
56 | - esc_html_e( |
|
57 | - 'In order to process payments, we collect billing information on-site. Sensitive billing information is not stored on our server, but may be handled while in-transit to the payment processing server.', |
|
58 | - 'event_espresso' |
|
59 | - ); ?></p> |
|
56 | + esc_html_e( |
|
57 | + 'In order to process payments, we collect billing information on-site. Sensitive billing information is not stored on our server, but may be handled while in-transit to the payment processing server.', |
|
58 | + 'event_espresso' |
|
59 | + ); ?></p> |
|
60 | 60 | <p><?php |
61 | - printf( |
|
62 | - esc_html_x( |
|
63 | - 'Please see the privacy policy of %1$s.', |
|
64 | - 'Please see the privacy policy of PayPal Pro', |
|
65 | - 'event_espresso' |
|
66 | - ), |
|
67 | - implode( |
|
68 | - ', ', |
|
69 | - array_merge( |
|
70 | - $active_onsite_payment_methods, |
|
71 | - $active_offsite_payment_methods |
|
72 | - ) |
|
73 | - ) |
|
74 | - ); ?></p> |
|
61 | + printf( |
|
62 | + esc_html_x( |
|
63 | + 'Please see the privacy policy of %1$s.', |
|
64 | + 'Please see the privacy policy of PayPal Pro', |
|
65 | + 'event_espresso' |
|
66 | + ), |
|
67 | + implode( |
|
68 | + ', ', |
|
69 | + array_merge( |
|
70 | + $active_onsite_payment_methods, |
|
71 | + $active_offsite_payment_methods |
|
72 | + ) |
|
73 | + ) |
|
74 | + ); ?></p> |
|
75 | 75 | <p><?php |
76 | - esc_html_e( |
|
77 | - 'Masked billing information may be stored on our servers (eg only the last 4 digits of credit card numbers are stored: **** **** **** 1234).', |
|
78 | - 'event_espresso' |
|
79 | - ); ?></p> |
|
76 | + esc_html_e( |
|
77 | + 'Masked billing information may be stored on our servers (eg only the last 4 digits of credit card numbers are stored: **** **** **** 1234).', |
|
78 | + 'event_espresso' |
|
79 | + ); ?></p> |
|
80 | 80 | <?php } elseif (! empty($active_offsite_payment_methods)) { // IF OFFSITE PAYMENT METHOD ACTIVE ?> |
81 | 81 | <p><?php |
82 | - printf( |
|
83 | - esc_html_x( |
|
84 | - 'Billing information is sent directly to the payment processor, and is not handled by our servers. Please see the privacy policy of %1$s.', |
|
85 | - 'Billing information is sent directly to the payment processor, and is not handled by our servers. Please see the privacy policy of PayPal Pro.', |
|
86 | - 'event_espresso' |
|
87 | - ), |
|
88 | - implode(', ', $active_offsite_payment_methods) |
|
89 | - ); ?></p> |
|
82 | + printf( |
|
83 | + esc_html_x( |
|
84 | + 'Billing information is sent directly to the payment processor, and is not handled by our servers. Please see the privacy policy of %1$s.', |
|
85 | + 'Billing information is sent directly to the payment processor, and is not handled by our servers. Please see the privacy policy of PayPal Pro.', |
|
86 | + 'event_espresso' |
|
87 | + ), |
|
88 | + implode(', ', $active_offsite_payment_methods) |
|
89 | + ); ?></p> |
|
90 | 90 | <?php } ?> |
91 | 91 | <h2><?php esc_html_e('Payment Logging', 'event_espresso'); ?></h2> |
92 | 92 | <p><?php |
93 | - esc_html_e( |
|
94 | - 'Site administrators may keep a log of communications with the payment processors in order to verify payments are being processed correctly. These logs are automatically deleted after a week.', |
|
95 | - 'event_espresso' |
|
96 | - ); ?></p> |
|
93 | + esc_html_e( |
|
94 | + 'Site administrators may keep a log of communications with the payment processors in order to verify payments are being processed correctly. These logs are automatically deleted after a week.', |
|
95 | + 'event_espresso' |
|
96 | + ); ?></p> |
|
97 | 97 | <?php } ?> |
98 | 98 | |
99 | 99 | <h2><?php esc_html_e('Event Registration Cookies', 'event_espresso'); ?></h2> |
100 | 100 | <p><?php |
101 | - printf( |
|
102 | - esc_html_x( |
|
103 | - 'When you begin registering for an event and select a ticket quantity, a cookie will be used to track your registration. This cookie lasts %1$s.', |
|
104 | - 'When you begin registering for an event and select a ticket quantity, a cookie will be used to track your registration. This cookie lasts 2 hours.', |
|
105 | - 'event_espresso' |
|
106 | - ), |
|
107 | - $session_lifespan |
|
108 | - ); ?></p> |
|
101 | + printf( |
|
102 | + esc_html_x( |
|
103 | + 'When you begin registering for an event and select a ticket quantity, a cookie will be used to track your registration. This cookie lasts %1$s.', |
|
104 | + 'When you begin registering for an event and select a ticket quantity, a cookie will be used to track your registration. This cookie lasts 2 hours.', |
|
105 | + 'event_espresso' |
|
106 | + ), |
|
107 | + $session_lifespan |
|
108 | + ); ?></p> |
|
109 | 109 | |
110 | 110 | <h2><?php esc_html_e('Email History Data', 'event_espresso'); ?></h2> |
111 | 111 | <p><?php |
112 | - esc_html_e( |
|
113 | - 'We keep a record of the emails sent to you. This is to ensure communication is successfully sent and its information is accurate.', |
|
114 | - 'event_espresso' |
|
115 | - ); ?></p> |
|
112 | + esc_html_e( |
|
113 | + 'We keep a record of the emails sent to you. This is to ensure communication is successfully sent and its information is accurate.', |
|
114 | + 'event_espresso' |
|
115 | + ); ?></p> |
|
116 | 116 | |
117 | 117 | <h2><?php esc_html_e('Event Check-In Record', 'event_espresso'); ?></h2> |
118 | 118 | <p><?php |
119 | - esc_html_e( |
|
120 | - 'When you attend an event, an event manager may record the time you check in or out of the event.', |
|
121 | - 'event_espresso' |
|
122 | - ); ?></p> |
|
119 | + esc_html_e( |
|
120 | + 'When you attend an event, an event manager may record the time you check in or out of the event.', |
|
121 | + 'event_espresso' |
|
122 | + ); ?></p> |
|
123 | 123 | |
124 | 124 | <h2><?php esc_html_e('Event Registration Data Retention', 'event_espresso'); ?></h2> |
125 | 125 | <p><?php |
126 | - esc_html_e( |
|
127 | - 'Personal data is stored at least until the date of the event, and may be kept indefinitely in case of future registrations.', |
|
128 | - 'event_espresso' |
|
129 | - ); ?></p> |
|
126 | + esc_html_e( |
|
127 | + 'Personal data is stored at least until the date of the event, and may be kept indefinitely in case of future registrations.', |
|
128 | + 'event_espresso' |
|
129 | + ); ?></p> |
|
130 | 130 | |
131 | 131 | <h2><?php esc_html_e('Event Registration Data Erasure and Export', 'event_espresso'); ?></h2> |
132 | 132 | <p><?php |
133 | - esc_html_e( |
|
134 | - 'You have the right to request your personal data be sent to you electronically, and the right to request your registration data be erased after the event. To do so, please contact the event manager or site administrator.', |
|
135 | - 'event_espresso' |
|
136 | - ); ?></p> |
|
133 | + esc_html_e( |
|
134 | + 'You have the right to request your personal data be sent to you electronically, and the right to request your registration data be erased after the event. To do so, please contact the event manager or site administrator.', |
|
135 | + 'event_espresso' |
|
136 | + ); ?></p> |
@@ -47,11 +47,11 @@ discard block |
||
47 | 47 | ); ?></li> |
48 | 48 | </ul> |
49 | 49 | |
50 | -<?php if (! empty($active_onsite_payment_methods) || ! empty($active_offsite_payment_methods)) { ?> |
|
50 | +<?php if ( ! empty($active_onsite_payment_methods) || ! empty($active_offsite_payment_methods)) { ?> |
|
51 | 51 | <h2><?php esc_html_e('Billing Information', 'event_espresso'); ?> </h2> |
52 | 52 | <?php |
53 | 53 | // if onsite or offsite payment methods are active |
54 | - if (! empty($active_onsite_payment_methods)) { ?> |
|
54 | + if ( ! empty($active_onsite_payment_methods)) { ?> |
|
55 | 55 | <p><?php |
56 | 56 | esc_html_e( |
57 | 57 | 'In order to process payments, we collect billing information on-site. Sensitive billing information is not stored on our server, but may be handled while in-transit to the payment processing server.', |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | 'Masked billing information may be stored on our servers (eg only the last 4 digits of credit card numbers are stored: **** **** **** 1234).', |
78 | 78 | 'event_espresso' |
79 | 79 | ); ?></p> |
80 | - <?php } elseif (! empty($active_offsite_payment_methods)) { // IF OFFSITE PAYMENT METHOD ACTIVE ?> |
|
80 | + <?php } elseif ( ! empty($active_offsite_payment_methods)) { // IF OFFSITE PAYMENT METHOD ACTIVE ?> |
|
81 | 81 | <p><?php |
82 | 82 | printf( |
83 | 83 | esc_html_x( |
@@ -11,48 +11,48 @@ |
||
11 | 11 | * @version 4+ |
12 | 12 | */ |
13 | 13 | if (have_posts()) : |
14 | - if (apply_filters('FHEE__archive_espresso_events_template__show_header', true)) : ?> |
|
14 | + if (apply_filters('FHEE__archive_espresso_events_template__show_header', true)) : ?> |
|
15 | 15 | <header class="page-header"> |
16 | 16 | <h1 class="page-title"> |
17 | 17 | <?php |
18 | - if (is_day()) : |
|
19 | - printf(esc_html__('Today\'s Events: %s', 'event_espresso'), get_the_date()); |
|
20 | - elseif (is_month()) : |
|
21 | - printf( |
|
22 | - esc_html__('Events This Month: %s', 'event_espresso'), |
|
23 | - get_the_date(_x('F Y', 'monthly archives date format', 'event_espresso')) |
|
24 | - ); |
|
25 | - elseif (is_year()) : |
|
26 | - printf( |
|
27 | - esc_html__('Events This Year: %s', 'event_espresso'), |
|
28 | - get_the_date(_x('Y', 'yearly archives date format', 'event_espresso')) |
|
29 | - ); |
|
30 | - else : |
|
31 | - echo apply_filters( |
|
32 | - 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
|
33 | - esc_html__('Upcoming Events', 'event_espresso') |
|
34 | - ); |
|
35 | - endif; |
|
36 | - ?> |
|
18 | + if (is_day()) : |
|
19 | + printf(esc_html__('Today\'s Events: %s', 'event_espresso'), get_the_date()); |
|
20 | + elseif (is_month()) : |
|
21 | + printf( |
|
22 | + esc_html__('Events This Month: %s', 'event_espresso'), |
|
23 | + get_the_date(_x('F Y', 'monthly archives date format', 'event_espresso')) |
|
24 | + ); |
|
25 | + elseif (is_year()) : |
|
26 | + printf( |
|
27 | + esc_html__('Events This Year: %s', 'event_espresso'), |
|
28 | + get_the_date(_x('Y', 'yearly archives date format', 'event_espresso')) |
|
29 | + ); |
|
30 | + else : |
|
31 | + echo apply_filters( |
|
32 | + 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
|
33 | + esc_html__('Upcoming Events', 'event_espresso') |
|
34 | + ); |
|
35 | + endif; |
|
36 | + ?> |
|
37 | 37 | </h1> |
38 | 38 | |
39 | 39 | </header><!-- .page-header --> |
40 | 40 | |
41 | 41 | <?php |
42 | - endif; |
|
43 | - // allow other stuff |
|
44 | - do_action('AHEE__archive_espresso_events_template__before_loop'); |
|
45 | - // Start the Loop. |
|
46 | - while (have_posts()) : the_post(); |
|
47 | - // Include the post TYPE-specific template for the content. |
|
48 | - espresso_get_template_part('content', 'espresso_events-shortcode'); |
|
49 | - endwhile; |
|
50 | - // Previous/next page navigation. |
|
51 | - espresso_pagination(); |
|
52 | - // allow moar other stuff |
|
53 | - do_action('AHEE__archive_espresso_events_template__after_loop'); |
|
42 | + endif; |
|
43 | + // allow other stuff |
|
44 | + do_action('AHEE__archive_espresso_events_template__before_loop'); |
|
45 | + // Start the Loop. |
|
46 | + while (have_posts()) : the_post(); |
|
47 | + // Include the post TYPE-specific template for the content. |
|
48 | + espresso_get_template_part('content', 'espresso_events-shortcode'); |
|
49 | + endwhile; |
|
50 | + // Previous/next page navigation. |
|
51 | + espresso_pagination(); |
|
52 | + // allow moar other stuff |
|
53 | + do_action('AHEE__archive_espresso_events_template__after_loop'); |
|
54 | 54 | else : |
55 | - // If no content, include the "No posts found" template. |
|
56 | - espresso_get_template_part('content', 'none'); |
|
55 | + // If no content, include the "No posts found" template. |
|
56 | + espresso_get_template_part('content', 'none'); |
|
57 | 57 | endif; |
58 | 58 |
@@ -27,11 +27,13 @@ discard block |
||
27 | 27 | esc_html__('Events This Year: %s', 'event_espresso'), |
28 | 28 | get_the_date(_x('Y', 'yearly archives date format', 'event_espresso')) |
29 | 29 | ); |
30 | - else : |
|
30 | + else { |
|
31 | + : |
|
31 | 32 | echo apply_filters( |
32 | 33 | 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
33 | 34 | esc_html__('Upcoming Events', 'event_espresso') |
34 | 35 | ); |
36 | + } |
|
35 | 37 | endif; |
36 | 38 | ?> |
37 | 39 | </h1> |
@@ -51,8 +53,10 @@ discard block |
||
51 | 53 | espresso_pagination(); |
52 | 54 | // allow moar other stuff |
53 | 55 | do_action('AHEE__archive_espresso_events_template__after_loop'); |
54 | -else : |
|
56 | +else { |
|
57 | + : |
|
55 | 58 | // If no content, include the "No posts found" template. |
56 | 59 | espresso_get_template_part('content', 'none'); |
60 | +} |
|
57 | 61 | endif; |
58 | 62 |
@@ -9,9 +9,9 @@ discard block |
||
9 | 9 | * @ link http://www.eventespresso.com |
10 | 10 | * @ version 4+ |
11 | 11 | */ |
12 | -define( 'EE_THEME_FUNCTIONS_LOADED', TRUE ); |
|
12 | +define('EE_THEME_FUNCTIONS_LOADED', TRUE); |
|
13 | 13 | |
14 | -if ( ! function_exists( 'espresso_pagination' ) ) { |
|
14 | +if ( ! function_exists('espresso_pagination')) { |
|
15 | 15 | /** |
16 | 16 | * espresso_pagination |
17 | 17 | * |
@@ -23,21 +23,21 @@ discard block |
||
23 | 23 | $big = 999999999; // need an unlikely integer |
24 | 24 | $pagination = paginate_links( |
25 | 25 | array( |
26 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
26 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
27 | 27 | 'format' => '?paged=%#%', |
28 | - 'current' => max( 1, get_query_var( 'paged' ) ), |
|
28 | + 'current' => max(1, get_query_var('paged')), |
|
29 | 29 | 'total' => $wp_query->max_num_pages, |
30 | 30 | 'show_all' => true, |
31 | 31 | 'end_size' => 10, |
32 | 32 | 'mid_size' => 6, |
33 | 33 | 'prev_next' => true, |
34 | - 'prev_text' => esc_html__( '‹ PREV', 'event_espresso' ), |
|
35 | - 'next_text' => esc_html__( 'NEXT ›', 'event_espresso' ), |
|
34 | + 'prev_text' => esc_html__('‹ PREV', 'event_espresso'), |
|
35 | + 'next_text' => esc_html__('NEXT ›', 'event_espresso'), |
|
36 | 36 | 'type' => 'plain', |
37 | 37 | 'add_args' => false, |
38 | 38 | 'add_fragment' => '' |
39 | 39 | ) |
40 | 40 | ); |
41 | - echo ! empty( $pagination ) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
41 | + echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">'.$pagination.'</div>' : ''; |
|
42 | 42 | } |
43 | 43 | } |
44 | 44 | \ No newline at end of file |
@@ -36,88 +36,88 @@ |
||
36 | 36 | class EE_Line_Item_Filter_Processor |
37 | 37 | { |
38 | 38 | |
39 | - /** |
|
40 | - * @type EE_Line_Item_Filter_Collection $line_item_filters |
|
41 | - */ |
|
42 | - protected $line_item_filters; |
|
39 | + /** |
|
40 | + * @type EE_Line_Item_Filter_Collection $line_item_filters |
|
41 | + */ |
|
42 | + protected $line_item_filters; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @type EEI_Line_Item $grand_total_line_item |
|
46 | - */ |
|
47 | - protected $grand_total_line_item; |
|
44 | + /** |
|
45 | + * @type EEI_Line_Item $grand_total_line_item |
|
46 | + */ |
|
47 | + protected $grand_total_line_item; |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * EE_Line_Item_Filter_Processor constructor. |
|
52 | - * |
|
53 | - * @param \EE_Line_Item_Filter_Collection $line_item_filters |
|
54 | - * @param \EEI_Line_Item $grand_total_line_item |
|
55 | - * @throws \EE_Error |
|
56 | - */ |
|
57 | - public function __construct(EE_Line_Item_Filter_Collection $line_item_filters, EEI_Line_Item $grand_total_line_item) |
|
58 | - { |
|
59 | - $this->line_item_filters = $line_item_filters; |
|
60 | - if ($grand_total_line_item->type() !== EEM_Line_Item::type_total) { |
|
61 | - throw new EE_Error(esc_html__('A Line Item of the type total is required', 'event_espresso')); |
|
62 | - } |
|
63 | - $this->grand_total_line_item = $this->clone_and_reset_line_item_tree($grand_total_line_item); |
|
64 | - } |
|
50 | + /** |
|
51 | + * EE_Line_Item_Filter_Processor constructor. |
|
52 | + * |
|
53 | + * @param \EE_Line_Item_Filter_Collection $line_item_filters |
|
54 | + * @param \EEI_Line_Item $grand_total_line_item |
|
55 | + * @throws \EE_Error |
|
56 | + */ |
|
57 | + public function __construct(EE_Line_Item_Filter_Collection $line_item_filters, EEI_Line_Item $grand_total_line_item) |
|
58 | + { |
|
59 | + $this->line_item_filters = $line_item_filters; |
|
60 | + if ($grand_total_line_item->type() !== EEM_Line_Item::type_total) { |
|
61 | + throw new EE_Error(esc_html__('A Line Item of the type total is required', 'event_espresso')); |
|
62 | + } |
|
63 | + $this->grand_total_line_item = $this->clone_and_reset_line_item_tree($grand_total_line_item); |
|
64 | + } |
|
65 | 65 | |
66 | 66 | |
67 | - /** |
|
68 | - * clone_and_reset_line_item_tree |
|
69 | - * |
|
70 | - * @param \EEI_Line_Item $line_item |
|
71 | - * @return \EEI_Line_Item |
|
72 | - */ |
|
73 | - protected function clone_and_reset_line_item_tree(EEI_Line_Item $line_item) |
|
74 | - { |
|
75 | - $cloned_line_item = $this->clone_and_reset_line_item($line_item); |
|
76 | - foreach ($line_item->children() as $child_line_item) { |
|
77 | - $cloned_line_item->add_child_line_item($this->clone_and_reset_line_item_tree($child_line_item)); |
|
78 | - } |
|
79 | - return $cloned_line_item; |
|
80 | - } |
|
67 | + /** |
|
68 | + * clone_and_reset_line_item_tree |
|
69 | + * |
|
70 | + * @param \EEI_Line_Item $line_item |
|
71 | + * @return \EEI_Line_Item |
|
72 | + */ |
|
73 | + protected function clone_and_reset_line_item_tree(EEI_Line_Item $line_item) |
|
74 | + { |
|
75 | + $cloned_line_item = $this->clone_and_reset_line_item($line_item); |
|
76 | + foreach ($line_item->children() as $child_line_item) { |
|
77 | + $cloned_line_item->add_child_line_item($this->clone_and_reset_line_item_tree($child_line_item)); |
|
78 | + } |
|
79 | + return $cloned_line_item; |
|
80 | + } |
|
81 | 81 | |
82 | 82 | |
83 | - /** |
|
84 | - * clone_and_reset_line_item |
|
85 | - * |
|
86 | - * clones the incoming object |
|
87 | - * resets any fields that represent database primary keys |
|
88 | - * resets total |
|
89 | - * |
|
90 | - * @param \EEI_Line_Item $line_item |
|
91 | - * @return \EEI_Line_Item |
|
92 | - */ |
|
93 | - protected function clone_and_reset_line_item(EEI_Line_Item $line_item) |
|
94 | - { |
|
95 | - // we don't actually want to work with the original line item, so clone it |
|
96 | - $cloned_line_item = clone $line_item; |
|
97 | - $cloned_line_item->set('LIN_ID', null); |
|
98 | - $cloned_line_item->set('LIN_parent', null); |
|
99 | - $cloned_line_item->clear_related_line_item_cache(); |
|
100 | - foreach (array_keys(EEM_Line_Item::instance()->relation_settings()) as $relation_name) { |
|
101 | - $cloned_line_item->clear_cache($relation_name, null, true); |
|
102 | - } |
|
103 | - $cloned_line_item->set_allow_persist(false); |
|
104 | - return $cloned_line_item; |
|
105 | - } |
|
83 | + /** |
|
84 | + * clone_and_reset_line_item |
|
85 | + * |
|
86 | + * clones the incoming object |
|
87 | + * resets any fields that represent database primary keys |
|
88 | + * resets total |
|
89 | + * |
|
90 | + * @param \EEI_Line_Item $line_item |
|
91 | + * @return \EEI_Line_Item |
|
92 | + */ |
|
93 | + protected function clone_and_reset_line_item(EEI_Line_Item $line_item) |
|
94 | + { |
|
95 | + // we don't actually want to work with the original line item, so clone it |
|
96 | + $cloned_line_item = clone $line_item; |
|
97 | + $cloned_line_item->set('LIN_ID', null); |
|
98 | + $cloned_line_item->set('LIN_parent', null); |
|
99 | + $cloned_line_item->clear_related_line_item_cache(); |
|
100 | + foreach (array_keys(EEM_Line_Item::instance()->relation_settings()) as $relation_name) { |
|
101 | + $cloned_line_item->clear_cache($relation_name, null, true); |
|
102 | + } |
|
103 | + $cloned_line_item->set_allow_persist(false); |
|
104 | + return $cloned_line_item; |
|
105 | + } |
|
106 | 106 | |
107 | 107 | |
108 | - /** |
|
109 | - * process |
|
110 | - * |
|
111 | - * @return EEI_Line_Item |
|
112 | - */ |
|
113 | - public function process() |
|
114 | - { |
|
115 | - $this->line_item_filters->rewind(); |
|
116 | - while ($this->line_item_filters->valid()) { |
|
117 | - $this->grand_total_line_item = $this->line_item_filters->current()->process($this->grand_total_line_item); |
|
118 | - $this->line_item_filters->next(); |
|
119 | - } |
|
120 | - $this->grand_total_line_item->recalculate_total_including_taxes(); |
|
121 | - return $this->grand_total_line_item; |
|
122 | - } |
|
108 | + /** |
|
109 | + * process |
|
110 | + * |
|
111 | + * @return EEI_Line_Item |
|
112 | + */ |
|
113 | + public function process() |
|
114 | + { |
|
115 | + $this->line_item_filters->rewind(); |
|
116 | + while ($this->line_item_filters->valid()) { |
|
117 | + $this->grand_total_line_item = $this->line_item_filters->current()->process($this->grand_total_line_item); |
|
118 | + $this->line_item_filters->next(); |
|
119 | + } |
|
120 | + $this->grand_total_line_item->recalculate_total_including_taxes(); |
|
121 | + return $this->grand_total_line_item; |
|
122 | + } |
|
123 | 123 | } |
@@ -18,137 +18,137 @@ |
||
18 | 18 | |
19 | 19 | |
20 | 20 | |
21 | - /** |
|
22 | - * For the constructor of this special preview class. |
|
23 | - * |
|
24 | - * The data is expected to be an array that came from the request data |
|
25 | - * and should have at least one property from the list looked for. |
|
26 | - * |
|
27 | - * @param EE_Registration|array $data |
|
28 | - * @throws \EE_Error |
|
29 | - */ |
|
30 | - public function __construct($data) |
|
31 | - { |
|
32 | - $filtered_reg_status = null; |
|
33 | - |
|
34 | - if (! is_array($data) && $data instanceof EE_Registration) { |
|
35 | - $this->reg_obj = $data; |
|
36 | - } else { |
|
37 | - $this->reg_obj = is_array($data) && isset($data[0]) && $data[0] instanceof EE_Registration ? $data[0] : null; |
|
38 | - $filtered_reg_status = is_array($data) && ! empty($data[1]) ? $data[1] : null; |
|
39 | - } |
|
40 | - |
|
41 | - if (! $this->reg_obj instanceof EE_Registration) { |
|
42 | - throw new EE_Error( |
|
43 | - sprintf( |
|
44 | - esc_html__('%1$s requires the incoming data argument to be an instance of %2$s or an array where the first value is an instance of %2$s', 'event_espresso'), |
|
45 | - 'EE_Messages_REG_incoming_data', |
|
46 | - 'EE_Registration' |
|
47 | - ) |
|
48 | - ); |
|
49 | - } |
|
50 | - |
|
51 | - $data = array( |
|
52 | - 'reg_obj' => $this->reg_obj, |
|
53 | - 'filtered_reg_status' => $filtered_reg_status |
|
54 | - ); |
|
55 | - |
|
56 | - parent::__construct($data); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Returns database safe representation of the data later used to when instantiating this object. |
|
61 | - * |
|
62 | - * @param mixed $data The incoming data to be prepped. |
|
63 | - * |
|
64 | - * @return array The prepped data for db |
|
65 | - */ |
|
66 | - public static function convert_data_for_persistent_storage($data) |
|
67 | - { |
|
68 | - $prepped_data = array(); |
|
69 | - if (! is_array($data) && $data instanceof EE_Registration) { |
|
70 | - $prepped_data['Registration'] = $data->ID(); |
|
71 | - return $prepped_data; |
|
72 | - } elseif (! is_array($data)) { |
|
73 | - return array(); |
|
74 | - } else { |
|
75 | - if ($data[0] instanceof EE_Registration) { |
|
76 | - $prepped_data['Registration'] = $data[0]; |
|
77 | - } |
|
78 | - if (! empty($data[1])) { |
|
79 | - $prepped_data['filter'] = $data[1]; |
|
80 | - } |
|
81 | - } |
|
82 | - |
|
83 | - return $prepped_data; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage |
|
88 | - * can be sent into this method and converted back into the format used for instantiating with this data handler. |
|
89 | - * |
|
90 | - * @param $data |
|
91 | - * |
|
92 | - * @return mixed |
|
93 | - */ |
|
94 | - public static function convert_data_from_persistent_storage($data) |
|
95 | - { |
|
96 | - $registration = null; |
|
97 | - // $data['Registration'] could be either an ID (back compat) or a registration object (prepped using old system). |
|
98 | - if (isset($data['Registration'])) { |
|
99 | - $registration = $data['Registration'] instanceof EE_Registration |
|
100 | - ? $data['Registration'] |
|
101 | - : EEM_Registration::instance()->get_one_by_ID($data['Registration']); |
|
102 | - } |
|
103 | - $prepped_data = array( |
|
104 | - 0 => $registration, |
|
105 | - 1 => isset($data['filter']) ? $data['filter'] : null |
|
106 | - ); |
|
107 | - return $prepped_data; |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * This will just setup the _events property in the expected format. |
|
113 | - * @return void |
|
114 | - */ |
|
115 | - protected function _setup_data() |
|
116 | - { |
|
117 | - |
|
118 | - // now let's loop and set up the _events property. At the same time we'll set up attendee properties. |
|
119 | - $this->filtered_reg_status = $this->_data['filtered_reg_status']; |
|
120 | - // get txn |
|
121 | - $this->txn = $this->reg_obj->transaction(); |
|
122 | - // possible session stuff? |
|
123 | - $session = $this->txn->session_data(); |
|
124 | - $session_data = $session instanceof EE_Session ? $session->get_session_data() : array(); |
|
125 | - |
|
126 | - // other data from the session (if possible) |
|
127 | - $this->user_id = isset($session_data['user_id']) ? $session_data['user_id'] : ''; |
|
128 | - $this->ip_address = isset($session_data['ip_address']) ? $session_data['ip_address'] : ''; |
|
129 | - $this->user_agent = isset($session_data['user_agent']) ? $session_data['user_agent'] : ''; |
|
130 | - $this->init_access = $this->last_access = ''; |
|
131 | - |
|
132 | - $this->payment = $this->txn->get_first_related('Payment'); |
|
133 | - // if there is no payments associated with the transaction |
|
134 | - // then we just create a default payment object for potential parsing. |
|
135 | - $this->payment = empty($this->payment) |
|
136 | - ? EE_Payment::new_instance( |
|
137 | - array( |
|
138 | - 'STS_ID' => EEM_Payment::status_id_pending, |
|
139 | - 'PAY_timestamp' => time(), |
|
140 | - 'PMD_ID' => $this->txn->payment_method_ID(), |
|
141 | - 'PAY_gateway_response' => $this->txn->gateway_response_on_transaction(), |
|
142 | - ) |
|
143 | - ) |
|
144 | - : $this->payment; |
|
145 | - |
|
146 | - |
|
147 | - // get reg_objs for txn |
|
148 | - $this->reg_objs = $this->txn->registrations(); |
|
149 | - |
|
150 | - // now we can set things up like we do for other handlers |
|
151 | - |
|
152 | - $this->_assemble_data(); |
|
153 | - } |
|
21 | + /** |
|
22 | + * For the constructor of this special preview class. |
|
23 | + * |
|
24 | + * The data is expected to be an array that came from the request data |
|
25 | + * and should have at least one property from the list looked for. |
|
26 | + * |
|
27 | + * @param EE_Registration|array $data |
|
28 | + * @throws \EE_Error |
|
29 | + */ |
|
30 | + public function __construct($data) |
|
31 | + { |
|
32 | + $filtered_reg_status = null; |
|
33 | + |
|
34 | + if (! is_array($data) && $data instanceof EE_Registration) { |
|
35 | + $this->reg_obj = $data; |
|
36 | + } else { |
|
37 | + $this->reg_obj = is_array($data) && isset($data[0]) && $data[0] instanceof EE_Registration ? $data[0] : null; |
|
38 | + $filtered_reg_status = is_array($data) && ! empty($data[1]) ? $data[1] : null; |
|
39 | + } |
|
40 | + |
|
41 | + if (! $this->reg_obj instanceof EE_Registration) { |
|
42 | + throw new EE_Error( |
|
43 | + sprintf( |
|
44 | + esc_html__('%1$s requires the incoming data argument to be an instance of %2$s or an array where the first value is an instance of %2$s', 'event_espresso'), |
|
45 | + 'EE_Messages_REG_incoming_data', |
|
46 | + 'EE_Registration' |
|
47 | + ) |
|
48 | + ); |
|
49 | + } |
|
50 | + |
|
51 | + $data = array( |
|
52 | + 'reg_obj' => $this->reg_obj, |
|
53 | + 'filtered_reg_status' => $filtered_reg_status |
|
54 | + ); |
|
55 | + |
|
56 | + parent::__construct($data); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Returns database safe representation of the data later used to when instantiating this object. |
|
61 | + * |
|
62 | + * @param mixed $data The incoming data to be prepped. |
|
63 | + * |
|
64 | + * @return array The prepped data for db |
|
65 | + */ |
|
66 | + public static function convert_data_for_persistent_storage($data) |
|
67 | + { |
|
68 | + $prepped_data = array(); |
|
69 | + if (! is_array($data) && $data instanceof EE_Registration) { |
|
70 | + $prepped_data['Registration'] = $data->ID(); |
|
71 | + return $prepped_data; |
|
72 | + } elseif (! is_array($data)) { |
|
73 | + return array(); |
|
74 | + } else { |
|
75 | + if ($data[0] instanceof EE_Registration) { |
|
76 | + $prepped_data['Registration'] = $data[0]; |
|
77 | + } |
|
78 | + if (! empty($data[1])) { |
|
79 | + $prepped_data['filter'] = $data[1]; |
|
80 | + } |
|
81 | + } |
|
82 | + |
|
83 | + return $prepped_data; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage |
|
88 | + * can be sent into this method and converted back into the format used for instantiating with this data handler. |
|
89 | + * |
|
90 | + * @param $data |
|
91 | + * |
|
92 | + * @return mixed |
|
93 | + */ |
|
94 | + public static function convert_data_from_persistent_storage($data) |
|
95 | + { |
|
96 | + $registration = null; |
|
97 | + // $data['Registration'] could be either an ID (back compat) or a registration object (prepped using old system). |
|
98 | + if (isset($data['Registration'])) { |
|
99 | + $registration = $data['Registration'] instanceof EE_Registration |
|
100 | + ? $data['Registration'] |
|
101 | + : EEM_Registration::instance()->get_one_by_ID($data['Registration']); |
|
102 | + } |
|
103 | + $prepped_data = array( |
|
104 | + 0 => $registration, |
|
105 | + 1 => isset($data['filter']) ? $data['filter'] : null |
|
106 | + ); |
|
107 | + return $prepped_data; |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * This will just setup the _events property in the expected format. |
|
113 | + * @return void |
|
114 | + */ |
|
115 | + protected function _setup_data() |
|
116 | + { |
|
117 | + |
|
118 | + // now let's loop and set up the _events property. At the same time we'll set up attendee properties. |
|
119 | + $this->filtered_reg_status = $this->_data['filtered_reg_status']; |
|
120 | + // get txn |
|
121 | + $this->txn = $this->reg_obj->transaction(); |
|
122 | + // possible session stuff? |
|
123 | + $session = $this->txn->session_data(); |
|
124 | + $session_data = $session instanceof EE_Session ? $session->get_session_data() : array(); |
|
125 | + |
|
126 | + // other data from the session (if possible) |
|
127 | + $this->user_id = isset($session_data['user_id']) ? $session_data['user_id'] : ''; |
|
128 | + $this->ip_address = isset($session_data['ip_address']) ? $session_data['ip_address'] : ''; |
|
129 | + $this->user_agent = isset($session_data['user_agent']) ? $session_data['user_agent'] : ''; |
|
130 | + $this->init_access = $this->last_access = ''; |
|
131 | + |
|
132 | + $this->payment = $this->txn->get_first_related('Payment'); |
|
133 | + // if there is no payments associated with the transaction |
|
134 | + // then we just create a default payment object for potential parsing. |
|
135 | + $this->payment = empty($this->payment) |
|
136 | + ? EE_Payment::new_instance( |
|
137 | + array( |
|
138 | + 'STS_ID' => EEM_Payment::status_id_pending, |
|
139 | + 'PAY_timestamp' => time(), |
|
140 | + 'PMD_ID' => $this->txn->payment_method_ID(), |
|
141 | + 'PAY_gateway_response' => $this->txn->gateway_response_on_transaction(), |
|
142 | + ) |
|
143 | + ) |
|
144 | + : $this->payment; |
|
145 | + |
|
146 | + |
|
147 | + // get reg_objs for txn |
|
148 | + $this->reg_objs = $this->txn->registrations(); |
|
149 | + |
|
150 | + // now we can set things up like we do for other handlers |
|
151 | + |
|
152 | + $this->_assemble_data(); |
|
153 | + } |
|
154 | 154 | } |
@@ -31,14 +31,14 @@ discard block |
||
31 | 31 | { |
32 | 32 | $filtered_reg_status = null; |
33 | 33 | |
34 | - if (! is_array($data) && $data instanceof EE_Registration) { |
|
34 | + if ( ! is_array($data) && $data instanceof EE_Registration) { |
|
35 | 35 | $this->reg_obj = $data; |
36 | 36 | } else { |
37 | 37 | $this->reg_obj = is_array($data) && isset($data[0]) && $data[0] instanceof EE_Registration ? $data[0] : null; |
38 | 38 | $filtered_reg_status = is_array($data) && ! empty($data[1]) ? $data[1] : null; |
39 | 39 | } |
40 | 40 | |
41 | - if (! $this->reg_obj instanceof EE_Registration) { |
|
41 | + if ( ! $this->reg_obj instanceof EE_Registration) { |
|
42 | 42 | throw new EE_Error( |
43 | 43 | sprintf( |
44 | 44 | esc_html__('%1$s requires the incoming data argument to be an instance of %2$s or an array where the first value is an instance of %2$s', 'event_espresso'), |
@@ -66,16 +66,16 @@ discard block |
||
66 | 66 | public static function convert_data_for_persistent_storage($data) |
67 | 67 | { |
68 | 68 | $prepped_data = array(); |
69 | - if (! is_array($data) && $data instanceof EE_Registration) { |
|
69 | + if ( ! is_array($data) && $data instanceof EE_Registration) { |
|
70 | 70 | $prepped_data['Registration'] = $data->ID(); |
71 | 71 | return $prepped_data; |
72 | - } elseif (! is_array($data)) { |
|
72 | + } elseif ( ! is_array($data)) { |
|
73 | 73 | return array(); |
74 | 74 | } else { |
75 | 75 | if ($data[0] instanceof EE_Registration) { |
76 | 76 | $prepped_data['Registration'] = $data[0]; |
77 | 77 | } |
78 | - if (! empty($data[1])) { |
|
78 | + if ( ! empty($data[1])) { |
|
79 | 79 | $prepped_data['filter'] = $data[1]; |
80 | 80 | } |
81 | 81 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | $this->txn = $this->reg_obj->transaction(); |
122 | 122 | // possible session stuff? |
123 | 123 | $session = $this->txn->session_data(); |
124 | - $session_data = $session instanceof EE_Session ? $session->get_session_data() : array(); |
|
124 | + $session_data = $session instanceof EE_Session ? $session->get_session_data() : array(); |
|
125 | 125 | |
126 | 126 | // other data from the session (if possible) |
127 | 127 | $this->user_id = isset($session_data['user_id']) ? $session_data['user_id'] : ''; |
@@ -14,141 +14,141 @@ |
||
14 | 14 | class EE_Messages_Gateways_incoming_data extends EE_Messages_incoming_data |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * This holds the incoming payment object |
|
19 | - * @var EE_Payment |
|
20 | - */ |
|
21 | - public $payment; |
|
22 | - |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * incoming data is expected to be a EE_Transaction object and (possibly) EE_Payment object in an array. |
|
27 | - * |
|
28 | - * @param array $data |
|
29 | - * @throws EE_Error |
|
30 | - */ |
|
31 | - public function __construct($data) |
|
32 | - { |
|
33 | - |
|
34 | - // test for valid params |
|
35 | - if (! ( $data[0] instanceof EE_Transaction )) { |
|
36 | - throw new EE_Error(esc_html__('Incoming data for the Gateways data handler must have an EE_Transaction object as the value for the first array index.', 'event_espresso')); |
|
37 | - } |
|
38 | - |
|
39 | - if (empty($data[1]) || ! $data[1] instanceof EE_Payment) { |
|
40 | - $pmt_obj = $this->_get_empty_payment_obj($data[0]); |
|
41 | - } |
|
42 | - |
|
43 | - if (! empty($data[2])) { |
|
44 | - $filtered_reg_status = $data[2]; |
|
45 | - } |
|
17 | + /** |
|
18 | + * This holds the incoming payment object |
|
19 | + * @var EE_Payment |
|
20 | + */ |
|
21 | + public $payment; |
|
22 | + |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * incoming data is expected to be a EE_Transaction object and (possibly) EE_Payment object in an array. |
|
27 | + * |
|
28 | + * @param array $data |
|
29 | + * @throws EE_Error |
|
30 | + */ |
|
31 | + public function __construct($data) |
|
32 | + { |
|
33 | + |
|
34 | + // test for valid params |
|
35 | + if (! ( $data[0] instanceof EE_Transaction )) { |
|
36 | + throw new EE_Error(esc_html__('Incoming data for the Gateways data handler must have an EE_Transaction object as the value for the first array index.', 'event_espresso')); |
|
37 | + } |
|
38 | + |
|
39 | + if (empty($data[1]) || ! $data[1] instanceof EE_Payment) { |
|
40 | + $pmt_obj = $this->_get_empty_payment_obj($data[0]); |
|
41 | + } |
|
42 | + |
|
43 | + if (! empty($data[2])) { |
|
44 | + $filtered_reg_status = $data[2]; |
|
45 | + } |
|
46 | 46 | |
47 | - $data = array( |
|
48 | - 'txn_obj' => $data[0], |
|
49 | - 'pmt_obj' => isset($pmt_obj) ? $pmt_obj : $data[1], |
|
50 | - 'filtered_reg_status' => isset($filtered_reg_status) ? $filtered_reg_status : null |
|
51 | - ); |
|
52 | - parent::__construct($data); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * Returns database safe representation of the data later used to when instantiating this object. |
|
61 | - * |
|
62 | - * @param array $data The incoming data to be prepped. |
|
63 | - * |
|
64 | - * @return array The prepped data for db |
|
65 | - */ |
|
66 | - public static function convert_data_for_persistent_storage($data) |
|
67 | - { |
|
68 | - $prepped_data = array(); |
|
69 | - |
|
70 | - if ($data[0] instanceof EE_Transaction) { |
|
71 | - $prepped_data['Transaction'] = $data[0]->ID(); |
|
72 | - } |
|
73 | - |
|
74 | - if (isset($data[1]) && $data[1] instanceof EE_Payment) { |
|
75 | - $prepped_data['Payment'] = $data[1]->ID(); |
|
76 | - } |
|
77 | - |
|
78 | - if (! empty($data[2])) { |
|
79 | - $prepped_data['filter'] = $data[2]; |
|
80 | - } |
|
81 | - |
|
82 | - return $prepped_data; |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - |
|
87 | - |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage |
|
92 | - * can be sent into this method and converted back into the format used for instantiating with this data handler. |
|
93 | - * |
|
94 | - * @param array $data |
|
95 | - * |
|
96 | - * @return array |
|
97 | - */ |
|
98 | - public static function convert_data_from_persistent_storage($data) |
|
99 | - { |
|
100 | - $prepped_data = array( |
|
101 | - 0 => isset($data['Transaction']) ? EEM_Transaction::instance()->get_one_by_ID($data['Transaction']) : null, |
|
102 | - 1 => isset($data['Payment']) ? EEM_Payment::instance()->get_one_by_ID($data['Payment']) : null, |
|
103 | - 2 => isset($data['filter']) ? $data['filter'] : null |
|
104 | - ); |
|
105 | - return $prepped_data; |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * This sets up an empty EE_Payment object for the purpose of shortcode parsing. Note that this doesn't actually get saved to the db. |
|
111 | - * @param \EE_Transaction $txn |
|
112 | - * @return \EE_Payment |
|
113 | - */ |
|
114 | - private function _get_empty_payment_obj(EE_Transaction $txn) |
|
115 | - { |
|
116 | - $PMT = EE_Payment::new_instance(array( |
|
117 | - 'STS_ID' => EEM_Payment::status_id_pending, |
|
118 | - 'PAY_timestamp' => time(), |
|
119 | - 'PMD_ID' => $txn->payment_method_ID(), |
|
120 | - 'PAY_gateway_response' => $txn->gateway_response_on_transaction(), |
|
121 | - )); |
|
122 | - return $PMT; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * _setup_data |
|
129 | - * |
|
130 | - * @throws EE_Error |
|
131 | - */ |
|
132 | - protected function _setup_data() |
|
133 | - { |
|
134 | - |
|
135 | - $this->reg_info = array(); |
|
136 | - |
|
137 | - $this->txn = $this->_data['txn_obj']; |
|
138 | - $this->payment = $this->_data['pmt_obj']; |
|
139 | - $this->filtered_reg_status = $this->_data['filtered_reg_status']; |
|
140 | - $this->incoming_data = $this->_data; |
|
141 | - |
|
142 | - $session_data = $this->txn->session_data(); |
|
143 | - |
|
144 | - |
|
145 | - // other data from the session (if possible) |
|
146 | - $this->user_id = isset($session_data['user_id']) ? $session_data['user_id'] : ''; |
|
147 | - $this->ip_address = isset($session_data['ip_address']) ? $session_data['ip_address'] : ''; |
|
148 | - $this->user_agent = isset($session_data['user_agent']) ? $session_data['user_agent'] : ''; |
|
149 | - $this->init_access = $this->last_access = ''; |
|
150 | - // get all non-trashed registrations |
|
151 | - $this->reg_objs = $this->txn->registrations(array(array('REG_deleted' => false))); |
|
152 | - $this->_assemble_data(); |
|
153 | - } |
|
47 | + $data = array( |
|
48 | + 'txn_obj' => $data[0], |
|
49 | + 'pmt_obj' => isset($pmt_obj) ? $pmt_obj : $data[1], |
|
50 | + 'filtered_reg_status' => isset($filtered_reg_status) ? $filtered_reg_status : null |
|
51 | + ); |
|
52 | + parent::__construct($data); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * Returns database safe representation of the data later used to when instantiating this object. |
|
61 | + * |
|
62 | + * @param array $data The incoming data to be prepped. |
|
63 | + * |
|
64 | + * @return array The prepped data for db |
|
65 | + */ |
|
66 | + public static function convert_data_for_persistent_storage($data) |
|
67 | + { |
|
68 | + $prepped_data = array(); |
|
69 | + |
|
70 | + if ($data[0] instanceof EE_Transaction) { |
|
71 | + $prepped_data['Transaction'] = $data[0]->ID(); |
|
72 | + } |
|
73 | + |
|
74 | + if (isset($data[1]) && $data[1] instanceof EE_Payment) { |
|
75 | + $prepped_data['Payment'] = $data[1]->ID(); |
|
76 | + } |
|
77 | + |
|
78 | + if (! empty($data[2])) { |
|
79 | + $prepped_data['filter'] = $data[2]; |
|
80 | + } |
|
81 | + |
|
82 | + return $prepped_data; |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + |
|
87 | + |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage |
|
92 | + * can be sent into this method and converted back into the format used for instantiating with this data handler. |
|
93 | + * |
|
94 | + * @param array $data |
|
95 | + * |
|
96 | + * @return array |
|
97 | + */ |
|
98 | + public static function convert_data_from_persistent_storage($data) |
|
99 | + { |
|
100 | + $prepped_data = array( |
|
101 | + 0 => isset($data['Transaction']) ? EEM_Transaction::instance()->get_one_by_ID($data['Transaction']) : null, |
|
102 | + 1 => isset($data['Payment']) ? EEM_Payment::instance()->get_one_by_ID($data['Payment']) : null, |
|
103 | + 2 => isset($data['filter']) ? $data['filter'] : null |
|
104 | + ); |
|
105 | + return $prepped_data; |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * This sets up an empty EE_Payment object for the purpose of shortcode parsing. Note that this doesn't actually get saved to the db. |
|
111 | + * @param \EE_Transaction $txn |
|
112 | + * @return \EE_Payment |
|
113 | + */ |
|
114 | + private function _get_empty_payment_obj(EE_Transaction $txn) |
|
115 | + { |
|
116 | + $PMT = EE_Payment::new_instance(array( |
|
117 | + 'STS_ID' => EEM_Payment::status_id_pending, |
|
118 | + 'PAY_timestamp' => time(), |
|
119 | + 'PMD_ID' => $txn->payment_method_ID(), |
|
120 | + 'PAY_gateway_response' => $txn->gateway_response_on_transaction(), |
|
121 | + )); |
|
122 | + return $PMT; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * _setup_data |
|
129 | + * |
|
130 | + * @throws EE_Error |
|
131 | + */ |
|
132 | + protected function _setup_data() |
|
133 | + { |
|
134 | + |
|
135 | + $this->reg_info = array(); |
|
136 | + |
|
137 | + $this->txn = $this->_data['txn_obj']; |
|
138 | + $this->payment = $this->_data['pmt_obj']; |
|
139 | + $this->filtered_reg_status = $this->_data['filtered_reg_status']; |
|
140 | + $this->incoming_data = $this->_data; |
|
141 | + |
|
142 | + $session_data = $this->txn->session_data(); |
|
143 | + |
|
144 | + |
|
145 | + // other data from the session (if possible) |
|
146 | + $this->user_id = isset($session_data['user_id']) ? $session_data['user_id'] : ''; |
|
147 | + $this->ip_address = isset($session_data['ip_address']) ? $session_data['ip_address'] : ''; |
|
148 | + $this->user_agent = isset($session_data['user_agent']) ? $session_data['user_agent'] : ''; |
|
149 | + $this->init_access = $this->last_access = ''; |
|
150 | + // get all non-trashed registrations |
|
151 | + $this->reg_objs = $this->txn->registrations(array(array('REG_deleted' => false))); |
|
152 | + $this->_assemble_data(); |
|
153 | + } |
|
154 | 154 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | { |
33 | 33 | |
34 | 34 | // test for valid params |
35 | - if (! ( $data[0] instanceof EE_Transaction )) { |
|
35 | + if ( ! ($data[0] instanceof EE_Transaction)) { |
|
36 | 36 | throw new EE_Error(esc_html__('Incoming data for the Gateways data handler must have an EE_Transaction object as the value for the first array index.', 'event_espresso')); |
37 | 37 | } |
38 | 38 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | $pmt_obj = $this->_get_empty_payment_obj($data[0]); |
41 | 41 | } |
42 | 42 | |
43 | - if (! empty($data[2])) { |
|
43 | + if ( ! empty($data[2])) { |
|
44 | 44 | $filtered_reg_status = $data[2]; |
45 | 45 | } |
46 | 46 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | $prepped_data['Payment'] = $data[1]->ID(); |
76 | 76 | } |
77 | 77 | |
78 | - if (! empty($data[2])) { |
|
78 | + if ( ! empty($data[2])) { |
|
79 | 79 | $prepped_data['filter'] = $data[2]; |
80 | 80 | } |
81 | 81 |
@@ -15,699 +15,699 @@ |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * @type string reference for sending action |
|
20 | - */ |
|
21 | - const action_sending = 'sending'; |
|
22 | - |
|
23 | - /** |
|
24 | - * @type string reference for generation action |
|
25 | - */ |
|
26 | - const action_generating = 'generation'; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * @type EE_Message_Repository $_message_repository |
|
31 | - */ |
|
32 | - protected $_message_repository; |
|
33 | - |
|
34 | - /** |
|
35 | - * Sets the limit of how many messages are generated per process. |
|
36 | - * |
|
37 | - * @type int |
|
38 | - */ |
|
39 | - protected $_batch_count; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * This is an array of cached queue items being stored in this object. |
|
44 | - * The array keys will be the ID of the EE_Message in the db if saved. If the EE_Message |
|
45 | - * is not saved to the db then its key will be an increment of "UNS" (i.e. UNS1, UNS2 etc.) |
|
46 | - * |
|
47 | - * @type EE_Message[] |
|
48 | - */ |
|
49 | - protected $_cached_queue_items; |
|
50 | - |
|
51 | - /** |
|
52 | - * Tracks the number of unsaved queue items. |
|
53 | - * |
|
54 | - * @type int |
|
55 | - */ |
|
56 | - protected $_unsaved_count = 0; |
|
57 | - |
|
58 | - /** |
|
59 | - * used to record if a do_messenger_hooks has already been called for a message type. This prevents multiple |
|
60 | - * hooks getting fired if users have setup their action/filter hooks to prevent duplicate calls. |
|
61 | - * |
|
62 | - * @type array |
|
63 | - */ |
|
64 | - protected $_did_hook = array(); |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * Constructor. |
|
69 | - * Setup all the initial properties and load a EE_Message_Repository. |
|
70 | - * |
|
71 | - * @param \EE_Message_Repository $message_repository |
|
72 | - */ |
|
73 | - public function __construct(EE_Message_Repository $message_repository) |
|
74 | - { |
|
75 | - $this->_batch_count = apply_filters('FHEE__EE_Messages_Queue___batch_count', 50); |
|
76 | - $this->_message_repository = $message_repository; |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * Add a EE_Message object to the queue |
|
82 | - * |
|
83 | - * @param EE_Message $message |
|
84 | - * @param array $data This will be an array of data to attach to the object in the repository. If the |
|
85 | - * object is persisted, this data will be saved on an extra_meta object related to |
|
86 | - * EE_Message. |
|
87 | - * @param bool $preview Whether this EE_Message represents a preview or not. |
|
88 | - * @param bool $test_send This indicates whether to do a test send instead of actual send. A test send will |
|
89 | - * use the messenger send method but typically is based on preview data. |
|
90 | - * @return bool Whether the message was successfully added to the repository or not. |
|
91 | - */ |
|
92 | - public function add(EE_Message $message, $data = array(), $preview = false, $test_send = false) |
|
93 | - { |
|
94 | - $data['preview'] = $preview; |
|
95 | - $data['test_send'] = $test_send; |
|
96 | - return $this->_message_repository->add($message, $data); |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * Removes EE_Message from _queue that matches the given EE_Message if the pointer is on a matching EE_Message |
|
102 | - * |
|
103 | - * @param EE_Message $message The message to detach from the queue |
|
104 | - * @param bool $persist This flag indicates whether to attempt to delete the object from the db as well. |
|
105 | - * @return bool |
|
106 | - */ |
|
107 | - public function remove(EE_Message $message, $persist = false) |
|
108 | - { |
|
109 | - if ($persist && $this->_message_repository->current() !== $message) { |
|
110 | - // get pointer on right message |
|
111 | - if ($this->_message_repository->has($message)) { |
|
112 | - $this->_message_repository->rewind(); |
|
113 | - while ($this->_message_repository->valid()) { |
|
114 | - if ($this->_message_repository->current() === $message) { |
|
115 | - break; |
|
116 | - } |
|
117 | - $this->_message_repository->next(); |
|
118 | - } |
|
119 | - } else { |
|
120 | - return false; |
|
121 | - } |
|
122 | - } |
|
123 | - return $persist ? $this->_message_repository->delete() : $this->_message_repository->remove($message); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * Persists all queued EE_Message objects to the db. |
|
129 | - * |
|
130 | - * @param bool $do_hooks_only @see EE_Message_Repository::saveAll |
|
131 | - * @return array @see EE_Messages_Repository::saveAll() for return values. |
|
132 | - */ |
|
133 | - public function save($do_hooks_only = false) |
|
134 | - { |
|
135 | - return $this->_message_repository->saveAll($do_hooks_only); |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @return EE_Message_Repository |
|
141 | - */ |
|
142 | - public function get_message_repository() |
|
143 | - { |
|
144 | - return $this->_message_repository; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * This does the following things: |
|
150 | - * 1. Checks if there is a lock on generation (prevents race conditions). If there is a lock then exits (return |
|
151 | - * false). |
|
152 | - * 2. If no lock, sets lock, then retrieves a batch of non-generated EE_Message objects and adds to queue |
|
153 | - * 3. Returns bool. True = batch ready. False = no batch ready (or nothing available for generation). |
|
154 | - * Note: Callers should make sure they release the lock otherwise batch generation will be prevented from |
|
155 | - * continuing. The lock is on a transient that is set to expire after one hour as a fallback in case locks are not |
|
156 | - * removed. |
|
157 | - * |
|
158 | - * @return bool true if successfully retrieved batch, false no batch ready. |
|
159 | - */ |
|
160 | - public function get_batch_to_generate() |
|
161 | - { |
|
162 | - if ($this->is_locked(EE_Messages_Queue::action_generating)) { |
|
163 | - return false; |
|
164 | - } |
|
165 | - |
|
166 | - // lock batch generation to prevent race conditions. |
|
167 | - $this->lock_queue(EE_Messages_Queue::action_generating); |
|
168 | - |
|
169 | - $query_args = array( |
|
170 | - // key 0 = where conditions |
|
171 | - 0 => array('STS_ID' => EEM_Message::status_incomplete), |
|
172 | - 'order_by' => $this->_get_priority_orderby(), |
|
173 | - 'limit' => $this->_batch_count, |
|
174 | - ); |
|
175 | - $messages = EEM_Message::instance()->get_all($query_args); |
|
176 | - |
|
177 | - if (! $messages) { |
|
178 | - return false; // nothing to generate |
|
179 | - } |
|
180 | - |
|
181 | - foreach ($messages as $message) { |
|
182 | - if ($message instanceof EE_Message) { |
|
183 | - $data = $message->all_extra_meta_array(); |
|
184 | - $this->add($message, $data); |
|
185 | - } |
|
186 | - } |
|
187 | - return true; |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * This does the following things: |
|
193 | - * 1. Checks if there is a lock on sending (prevents race conditions). If there is a lock then exits (return |
|
194 | - * false). |
|
195 | - * 2. Grabs the allowed number of messages to send for the rate_limit. If cannot send any more messages, then |
|
196 | - * return false. |
|
197 | - * 2. If no lock, sets lock, then retrieves a batch of EE_Message objects, adds to queue and triggers execution. |
|
198 | - * 3. On success or unsuccessful send, sets status appropriately. |
|
199 | - * 4. Saves messages via the queue |
|
200 | - * 5. Releases lock. |
|
201 | - * |
|
202 | - * @return bool true on success, false if something preventing sending (i.e. lock set). Note: true does not |
|
203 | - * necessarily mean that all messages were successfully sent. It just means that this method |
|
204 | - * successfully completed. On true, client may want to call $this->count_STS_in_queue( |
|
205 | - * EEM_Message::status_failed ) to see if any failed EE_Message objects. Each failed message object |
|
206 | - * will also have a saved error message on it to assist with notifying user. |
|
207 | - */ |
|
208 | - public function get_to_send_batch_and_send() |
|
209 | - { |
|
210 | - $rate_limit = $this->get_rate_limit(); |
|
211 | - if ( |
|
212 | - $rate_limit < 1 |
|
213 | - || $this->is_locked(EE_Messages_Queue::action_sending) |
|
214 | - ) { |
|
215 | - return false; |
|
216 | - } |
|
217 | - |
|
218 | - $this->lock_queue(EE_Messages_Queue::action_sending); |
|
219 | - |
|
220 | - $batch = $this->_batch_count < $rate_limit ? $this->_batch_count : $rate_limit; |
|
221 | - |
|
222 | - $query_args = array( |
|
223 | - // key 0 = where conditions |
|
224 | - 0 => array('STS_ID' => array('IN', EEM_Message::instance()->stati_indicating_to_send())), |
|
225 | - 'order_by' => $this->_get_priority_orderby(), |
|
226 | - 'limit' => $batch, |
|
227 | - ); |
|
228 | - |
|
229 | - $messages_to_send = EEM_Message::instance()->get_all($query_args); |
|
230 | - |
|
231 | - |
|
232 | - // any to send? |
|
233 | - if (! $messages_to_send) { |
|
234 | - $this->unlock_queue(EE_Messages_Queue::action_sending); |
|
235 | - return false; |
|
236 | - } |
|
237 | - |
|
238 | - $queue_count = 0; |
|
239 | - |
|
240 | - // add to queue. |
|
241 | - foreach ($messages_to_send as $message) { |
|
242 | - if ($message instanceof EE_Message) { |
|
243 | - $queue_count++; |
|
244 | - $this->add($message); |
|
245 | - } |
|
246 | - } |
|
247 | - |
|
248 | - // send messages (this also updates the rate limit) |
|
249 | - $this->execute(); |
|
250 | - |
|
251 | - // release lock |
|
252 | - $this->unlock_queue(EE_Messages_Queue::action_sending); |
|
253 | - // update rate limit |
|
254 | - $this->set_rate_limit($queue_count); |
|
255 | - return true; |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * Locks the queue so that no other queues can call the "batch" methods. |
|
261 | - * |
|
262 | - * @param string $type The type of queue being locked. |
|
263 | - */ |
|
264 | - public function lock_queue($type = EE_Messages_Queue::action_generating) |
|
265 | - { |
|
266 | - update_option($this->_get_lock_key($type), $this->_get_lock_expiry($type)); |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * Unlocks the queue so that batch methods can be used. |
|
272 | - * |
|
273 | - * @param string $type The type of queue being unlocked. |
|
274 | - */ |
|
275 | - public function unlock_queue($type = EE_Messages_Queue::action_generating) |
|
276 | - { |
|
277 | - delete_option($this->_get_lock_key($type)); |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * Retrieve the key used for the lock transient. |
|
283 | - * |
|
284 | - * @param string $type The type of lock. |
|
285 | - * @return string |
|
286 | - */ |
|
287 | - protected function _get_lock_key($type = EE_Messages_Queue::action_generating) |
|
288 | - { |
|
289 | - return '_ee_lock_' . $type; |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * Retrieve the expiry time for the lock transient. |
|
295 | - * |
|
296 | - * @param string $type The type of lock |
|
297 | - * @return int time to expiry in seconds. |
|
298 | - */ |
|
299 | - protected function _get_lock_expiry($type = EE_Messages_Queue::action_generating) |
|
300 | - { |
|
301 | - return time() + (int) apply_filters('FHEE__EE_Messages_Queue__lock_expiry', HOUR_IN_SECONDS, $type); |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * Returns the key used for rate limit transient. |
|
307 | - * |
|
308 | - * @return string |
|
309 | - */ |
|
310 | - protected function _get_rate_limit_key() |
|
311 | - { |
|
312 | - return '_ee_rate_limit'; |
|
313 | - } |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * Returns the rate limit expiry time. |
|
318 | - * |
|
319 | - * @return int |
|
320 | - */ |
|
321 | - protected function _get_rate_limit_expiry() |
|
322 | - { |
|
323 | - return time() + (int) apply_filters('FHEE__EE_Messages_Queue__rate_limit_expiry', HOUR_IN_SECONDS); |
|
324 | - } |
|
325 | - |
|
326 | - |
|
327 | - /** |
|
328 | - * Returns the default rate limit for sending messages. |
|
329 | - * |
|
330 | - * @return int |
|
331 | - */ |
|
332 | - protected function _default_rate_limit() |
|
333 | - { |
|
334 | - return (int) apply_filters('FHEE__EE_Messages_Queue___rate_limit', 200); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * Return the orderby array for priority. |
|
340 | - * |
|
341 | - * @return array |
|
342 | - */ |
|
343 | - protected function _get_priority_orderby() |
|
344 | - { |
|
345 | - return array( |
|
346 | - 'MSG_priority' => 'ASC', |
|
347 | - 'MSG_modified' => 'DESC', |
|
348 | - ); |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * Returns whether batch methods are "locked" or not, and if models an currently be used to query the database. |
|
354 | - * Return true when batch methods should not be used; returns false when they can be. |
|
355 | - * |
|
356 | - * @param string $type The type of lock being checked for. |
|
357 | - * @return bool |
|
358 | - */ |
|
359 | - public function is_locked($type = EE_Messages_Queue::action_generating) |
|
360 | - { |
|
361 | - if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
362 | - return true; |
|
363 | - } |
|
364 | - $lock = (int) get_option($this->_get_lock_key($type), 0); |
|
365 | - /** |
|
366 | - * This filters the default is_locked behaviour. |
|
367 | - */ |
|
368 | - $is_locked = filter_var( |
|
369 | - apply_filters( |
|
370 | - 'FHEE__EE_Messages_Queue__is_locked', |
|
371 | - $lock > time(), |
|
372 | - $this |
|
373 | - ), |
|
374 | - FILTER_VALIDATE_BOOLEAN |
|
375 | - ); |
|
376 | - |
|
377 | - /** |
|
378 | - * @see usage of this filter in EE_Messages_Queue::initiate_request_by_priority() method. |
|
379 | - * Also implemented here because messages processed on the same request should not have any locks applied. |
|
380 | - */ |
|
381 | - if ( |
|
382 | - apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
383 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
384 | - ) { |
|
385 | - $is_locked = false; |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - return $is_locked; |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - /** |
|
394 | - * Retrieves the rate limit that may be cached as a transient. |
|
395 | - * If the rate limit is not set, then this sets the default rate limit and expiry and returns it. |
|
396 | - * |
|
397 | - * @param bool $return_expiry If true then return the expiry time not the rate_limit. |
|
398 | - * @return int |
|
399 | - */ |
|
400 | - protected function get_rate_limit($return_expiry = false) |
|
401 | - { |
|
402 | - $stored_rate_info = get_option($this->_get_rate_limit_key(), array()); |
|
403 | - $rate_limit = isset($stored_rate_info[0]) |
|
404 | - ? (int) $stored_rate_info[0] |
|
405 | - : 0; |
|
406 | - $expiry = isset($stored_rate_info[1]) |
|
407 | - ? (int) $stored_rate_info[1] |
|
408 | - : 0; |
|
409 | - // set the default for tracking? |
|
410 | - if (empty($stored_rate_info) || time() > $expiry) { |
|
411 | - $expiry = $this->_get_rate_limit_expiry(); |
|
412 | - $rate_limit = $this->_default_rate_limit(); |
|
413 | - update_option($this->_get_rate_limit_key(), array($rate_limit, $expiry)); |
|
414 | - } |
|
415 | - return $return_expiry ? $expiry : $rate_limit; |
|
416 | - } |
|
417 | - |
|
418 | - |
|
419 | - /** |
|
420 | - * This updates existing rate limit with the new limit which is the old minus the batch. |
|
421 | - * |
|
422 | - * @param int $batch_completed This sets the new rate limit based on the given batch that was completed. |
|
423 | - */ |
|
424 | - protected function set_rate_limit($batch_completed) |
|
425 | - { |
|
426 | - // first get the most up to date rate limit (in case its expired and reset) |
|
427 | - $rate_limit = $this->get_rate_limit(); |
|
428 | - $expiry = $this->get_rate_limit(true); |
|
429 | - $new_limit = $rate_limit - $batch_completed; |
|
430 | - // updating the transient option directly to avoid resetting the expiry. |
|
431 | - |
|
432 | - update_option($this->_get_rate_limit_key(), array($new_limit, $expiry)); |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * This method checks the queue for ANY EE_Message objects with a priority matching the given priority passed in. |
|
438 | - * If that exists, then we immediately initiate a non-blocking request to do the requested action type. |
|
439 | - * Note: Keep in mind that there is the possibility that the request will not execute if there is already another |
|
440 | - * request running on a queue for the given task. |
|
441 | - * |
|
442 | - * @param string $task This indicates what type of request is going to be initiated. |
|
443 | - * @param int $priority This indicates the priority that triggers initiating the request. |
|
444 | - */ |
|
445 | - public function initiate_request_by_priority($task = 'generate', $priority = EEM_Message::priority_high) |
|
446 | - { |
|
447 | - // determine what status is matched with the priority as part of the trigger conditions. |
|
448 | - $status = $task == 'generate' |
|
449 | - ? EEM_Message::status_incomplete |
|
450 | - : EEM_Message::instance()->stati_indicating_to_send(); |
|
451 | - // always make sure we save because either this will get executed immediately on a separate request |
|
452 | - // or remains in the queue for the regularly scheduled queue batch. |
|
453 | - $this->save(); |
|
454 | - /** |
|
455 | - * This filter/option allows users to override processing of messages on separate requests and instead have everything |
|
456 | - * happen on the same request. If this is utilized remember: |
|
457 | - * - message priorities don't matter |
|
458 | - * - existing unprocessed messages in the queue will not get processed unless manually triggered. |
|
459 | - * - things will be perceived to take longer to happen for end users (i.e. registrations) because of the additional |
|
460 | - * processing happening on the same request. |
|
461 | - * - any race condition protection (locks) are removed because they don't apply when things are processed on |
|
462 | - * the same request. |
|
463 | - */ |
|
464 | - if ( |
|
465 | - apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
466 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
467 | - ) { |
|
468 | - $messages_processor = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
469 | - if ($messages_processor instanceof EE_Messages_Processor) { |
|
470 | - return $messages_processor->process_immediately_from_queue($this); |
|
471 | - } |
|
472 | - // if we get here then that means the messages processor couldn't be loaded so messages will just remain |
|
473 | - // queued for manual triggering by end user. |
|
474 | - } |
|
475 | - |
|
476 | - if ($this->_message_repository->count_by_priority_and_status($priority, $status)) { |
|
477 | - EE_Messages_Scheduler::initiate_scheduled_non_blocking_request($task); |
|
478 | - } |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - /** |
|
483 | - * Loops through the EE_Message objects in the _queue and calls the messenger send methods for each message. |
|
484 | - * |
|
485 | - * @param bool $save Used to indicate whether to save the message queue after sending |
|
486 | - * (default will save). |
|
487 | - * @param mixed $sending_messenger (optional) When the sending messenger is different than |
|
488 | - * what is on the EE_Message object in the queue. |
|
489 | - * For instance, showing the browser view of an email message, |
|
490 | - * or giving a pdf generated view of an html document. |
|
491 | - * This should be an instance of EE_messenger but if you call this |
|
492 | - * method |
|
493 | - * intending it to be a sending messenger but a valid one could not be |
|
494 | - * retrieved then send in an instance of EE_Error that contains the |
|
495 | - * related error message. |
|
496 | - * @param bool|int $by_priority When set, this indicates that only messages |
|
497 | - * matching the given priority should be executed. |
|
498 | - * @return int Number of messages sent. Note, 0 does not mean that no messages were processed. |
|
499 | - * Also, if the messenger is an request type messenger (or a preview), |
|
500 | - * its entirely possible that the messenger will exit before |
|
501 | - */ |
|
502 | - public function execute($save = true, $sending_messenger = null, $by_priority = false) |
|
503 | - { |
|
504 | - $messages_sent = 0; |
|
505 | - $this->_did_hook = array(); |
|
506 | - $this->_message_repository->rewind(); |
|
507 | - |
|
508 | - while ($this->_message_repository->valid()) { |
|
509 | - $error_messages = array(); |
|
510 | - /** @type EE_Message $message */ |
|
511 | - $message = $this->_message_repository->current(); |
|
512 | - // only process things that are queued for sending |
|
513 | - if (! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { |
|
514 | - $this->_message_repository->next(); |
|
515 | - continue; |
|
516 | - } |
|
517 | - // if $by_priority is set and does not match then continue; |
|
518 | - if ($by_priority && $by_priority != $message->priority()) { |
|
519 | - $this->_message_repository->next(); |
|
520 | - continue; |
|
521 | - } |
|
522 | - // error checking |
|
523 | - if (! $message->valid_messenger()) { |
|
524 | - $error_messages[] = sprintf( |
|
525 | - esc_html__('The %s messenger is not active at time of sending.', 'event_espresso'), |
|
526 | - $message->messenger() |
|
527 | - ); |
|
528 | - } |
|
529 | - if (! $message->valid_message_type()) { |
|
530 | - $error_messages[] = sprintf( |
|
531 | - esc_html__('The %s message type is not active at the time of sending.', 'event_espresso'), |
|
532 | - $message->message_type() |
|
533 | - ); |
|
534 | - } |
|
535 | - // if there was supposed to be a sending messenger for this message, but it was invalid/inactive, |
|
536 | - // then it will instead be an EE_Error object, so let's check for that |
|
537 | - if ($sending_messenger instanceof EE_Error) { |
|
538 | - $error_messages[] = $sending_messenger->getMessage(); |
|
539 | - } |
|
540 | - // if there are no errors, then let's process the message |
|
541 | - if (empty($error_messages)) { |
|
542 | - if ($save) { |
|
543 | - $message->set_messenger_is_executing(); |
|
544 | - } |
|
545 | - if ($this->_process_message($message, $sending_messenger)) { |
|
546 | - $messages_sent++; |
|
547 | - } |
|
548 | - } |
|
549 | - $this->_set_error_message($message, $error_messages); |
|
550 | - // add modified time |
|
551 | - $message->set_modified(time()); |
|
552 | - // we save each message after its processed to make sure its status persists in case PHP times-out or runs |
|
553 | - // out of memory. @see https://events.codebasehq.com/projects/event-espresso/tickets/10281 |
|
554 | - if ($save) { |
|
555 | - $message->save(); |
|
556 | - } |
|
557 | - |
|
558 | - $this->_message_repository->next(); |
|
559 | - } |
|
560 | - if ($save) { |
|
561 | - $this->save(true); |
|
562 | - } |
|
563 | - return $messages_sent; |
|
564 | - } |
|
565 | - |
|
566 | - |
|
567 | - /** |
|
568 | - * _process_message |
|
569 | - * |
|
570 | - * @param EE_Message $message |
|
571 | - * @param mixed $sending_messenger (optional) |
|
572 | - * @return bool |
|
573 | - */ |
|
574 | - protected function _process_message(EE_Message $message, $sending_messenger = null) |
|
575 | - { |
|
576 | - // these *should* have been validated in the execute() method above |
|
577 | - $messenger = $message->messenger_object(); |
|
578 | - $message_type = $message->message_type_object(); |
|
579 | - // do actions for sending messenger if it differs from generating messenger and swap values. |
|
580 | - if ( |
|
581 | - $sending_messenger instanceof EE_messenger |
|
582 | - && $messenger instanceof EE_messenger |
|
583 | - && $sending_messenger->name != $messenger->name |
|
584 | - ) { |
|
585 | - $messenger->do_secondary_messenger_hooks($sending_messenger->name); |
|
586 | - $messenger = $sending_messenger; |
|
587 | - } |
|
588 | - // send using messenger, but double check objects |
|
589 | - if ($messenger instanceof EE_messenger && $message_type instanceof EE_message_type) { |
|
590 | - // set hook for message type (but only if not using another messenger to send). |
|
591 | - if (! isset($this->_did_hook[ $message_type->name ])) { |
|
592 | - $message_type->do_messenger_hooks($messenger); |
|
593 | - $this->_did_hook[ $message_type->name ] = 1; |
|
594 | - } |
|
595 | - // if preview then use preview method |
|
596 | - return $this->_message_repository->is_preview() |
|
597 | - ? $this->_do_preview($message, $messenger, $message_type, $this->_message_repository->is_test_send()) |
|
598 | - : $this->_do_send($message, $messenger, $message_type); |
|
599 | - } |
|
600 | - return false; |
|
601 | - } |
|
602 | - |
|
603 | - |
|
604 | - /** |
|
605 | - * The intention of this method is to count how many EE_Message objects |
|
606 | - * are in the queue with a given status. |
|
607 | - * Example usage: |
|
608 | - * After a caller calls the "EE_Message_Queue::execute()" method, the caller can check if there were any failed |
|
609 | - * sends by calling $queue->count_STS_in_queue( EEM_Message_Queue::status_failed ). |
|
610 | - * |
|
611 | - * @param array|string $status Stati to check for in queue |
|
612 | - * @return int Count of EE_Message's matching the given status. |
|
613 | - */ |
|
614 | - public function count_STS_in_queue($status) |
|
615 | - { |
|
616 | - $count = 0; |
|
617 | - $status = is_array($status) ? $status : array($status); |
|
618 | - $this->_message_repository->rewind(); |
|
619 | - foreach ($this->_message_repository as $message) { |
|
620 | - if (in_array($message->STS_ID(), $status)) { |
|
621 | - $count++; |
|
622 | - } |
|
623 | - } |
|
624 | - return $count; |
|
625 | - } |
|
626 | - |
|
627 | - |
|
628 | - /** |
|
629 | - * Executes the get_preview method on the provided messenger. |
|
630 | - * |
|
631 | - * @param EE_Message $message |
|
632 | - * @param EE_messenger $messenger |
|
633 | - * @param EE_message_type $message_type |
|
634 | - * @param $test_send |
|
635 | - * @return bool true means all went well, false means, not so much. |
|
636 | - */ |
|
637 | - protected function _do_preview( |
|
638 | - EE_Message $message, |
|
639 | - EE_messenger $messenger, |
|
640 | - EE_message_type $message_type, |
|
641 | - $test_send |
|
642 | - ) { |
|
643 | - if ($preview = $messenger->get_preview($message, $message_type, $test_send)) { |
|
644 | - if (! $test_send) { |
|
645 | - $message->set_content($preview); |
|
646 | - } |
|
647 | - $message->set_STS_ID(EEM_Message::status_sent); |
|
648 | - return true; |
|
649 | - } else { |
|
650 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
651 | - return false; |
|
652 | - } |
|
653 | - } |
|
654 | - |
|
655 | - |
|
656 | - /** |
|
657 | - * Executes the send method on the provided messenger |
|
658 | - * EE_Messengers are expected to: |
|
659 | - * - return true if the send was successful. |
|
660 | - * - return false if the send was unsuccessful but can be tried again. |
|
661 | - * - throw an Exception if the send was unsuccessful and cannot be tried again. |
|
662 | - * |
|
663 | - * @param EE_Message $message |
|
664 | - * @param EE_messenger $messenger |
|
665 | - * @param EE_message_type $message_type |
|
666 | - * @return bool true means all went well, false means, not so much. |
|
667 | - */ |
|
668 | - protected function _do_send(EE_Message $message, EE_messenger $messenger, EE_message_type $message_type) |
|
669 | - { |
|
670 | - try { |
|
671 | - if ($messenger->send_message($message, $message_type)) { |
|
672 | - $message->set_STS_ID(EEM_Message::status_sent); |
|
673 | - return true; |
|
674 | - } else { |
|
675 | - $message->set_STS_ID(EEM_Message::status_retry); |
|
676 | - return false; |
|
677 | - } |
|
678 | - } catch (SendMessageException $e) { |
|
679 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
680 | - $message->set_error_message($e->getMessage()); |
|
681 | - return false; |
|
682 | - } |
|
683 | - } |
|
684 | - |
|
685 | - |
|
686 | - /** |
|
687 | - * This sets any necessary error messages on the message object and its status to failed. |
|
688 | - * |
|
689 | - * @param EE_Message $message |
|
690 | - * @param array $error_messages the response from the messenger. |
|
691 | - */ |
|
692 | - protected function _set_error_message(EE_Message $message, $error_messages) |
|
693 | - { |
|
694 | - $error_messages = (array) $error_messages; |
|
695 | - if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_failed_sending())) { |
|
696 | - $notices = EE_Error::has_notices(); |
|
697 | - $error_messages[] = esc_html__( |
|
698 | - 'Messenger and Message Type were valid and active, but the messenger send method failed.', |
|
699 | - 'event_espresso' |
|
700 | - ); |
|
701 | - if ($notices === 1) { |
|
702 | - $notices = EE_Error::get_vanilla_notices(); |
|
703 | - $notices['errors'] = isset($notices['errors']) ? $notices['errors'] : array(); |
|
704 | - $error_messages[] = implode("\n", $notices['errors']); |
|
705 | - } |
|
706 | - } |
|
707 | - if (count($error_messages) > 0) { |
|
708 | - $msg = esc_html__('Message was not executed successfully.', 'event_espresso'); |
|
709 | - $msg = $msg . "\n" . implode("\n", $error_messages); |
|
710 | - $message->set_error_message($msg); |
|
711 | - } |
|
712 | - } |
|
18 | + /** |
|
19 | + * @type string reference for sending action |
|
20 | + */ |
|
21 | + const action_sending = 'sending'; |
|
22 | + |
|
23 | + /** |
|
24 | + * @type string reference for generation action |
|
25 | + */ |
|
26 | + const action_generating = 'generation'; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * @type EE_Message_Repository $_message_repository |
|
31 | + */ |
|
32 | + protected $_message_repository; |
|
33 | + |
|
34 | + /** |
|
35 | + * Sets the limit of how many messages are generated per process. |
|
36 | + * |
|
37 | + * @type int |
|
38 | + */ |
|
39 | + protected $_batch_count; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * This is an array of cached queue items being stored in this object. |
|
44 | + * The array keys will be the ID of the EE_Message in the db if saved. If the EE_Message |
|
45 | + * is not saved to the db then its key will be an increment of "UNS" (i.e. UNS1, UNS2 etc.) |
|
46 | + * |
|
47 | + * @type EE_Message[] |
|
48 | + */ |
|
49 | + protected $_cached_queue_items; |
|
50 | + |
|
51 | + /** |
|
52 | + * Tracks the number of unsaved queue items. |
|
53 | + * |
|
54 | + * @type int |
|
55 | + */ |
|
56 | + protected $_unsaved_count = 0; |
|
57 | + |
|
58 | + /** |
|
59 | + * used to record if a do_messenger_hooks has already been called for a message type. This prevents multiple |
|
60 | + * hooks getting fired if users have setup their action/filter hooks to prevent duplicate calls. |
|
61 | + * |
|
62 | + * @type array |
|
63 | + */ |
|
64 | + protected $_did_hook = array(); |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * Constructor. |
|
69 | + * Setup all the initial properties and load a EE_Message_Repository. |
|
70 | + * |
|
71 | + * @param \EE_Message_Repository $message_repository |
|
72 | + */ |
|
73 | + public function __construct(EE_Message_Repository $message_repository) |
|
74 | + { |
|
75 | + $this->_batch_count = apply_filters('FHEE__EE_Messages_Queue___batch_count', 50); |
|
76 | + $this->_message_repository = $message_repository; |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * Add a EE_Message object to the queue |
|
82 | + * |
|
83 | + * @param EE_Message $message |
|
84 | + * @param array $data This will be an array of data to attach to the object in the repository. If the |
|
85 | + * object is persisted, this data will be saved on an extra_meta object related to |
|
86 | + * EE_Message. |
|
87 | + * @param bool $preview Whether this EE_Message represents a preview or not. |
|
88 | + * @param bool $test_send This indicates whether to do a test send instead of actual send. A test send will |
|
89 | + * use the messenger send method but typically is based on preview data. |
|
90 | + * @return bool Whether the message was successfully added to the repository or not. |
|
91 | + */ |
|
92 | + public function add(EE_Message $message, $data = array(), $preview = false, $test_send = false) |
|
93 | + { |
|
94 | + $data['preview'] = $preview; |
|
95 | + $data['test_send'] = $test_send; |
|
96 | + return $this->_message_repository->add($message, $data); |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * Removes EE_Message from _queue that matches the given EE_Message if the pointer is on a matching EE_Message |
|
102 | + * |
|
103 | + * @param EE_Message $message The message to detach from the queue |
|
104 | + * @param bool $persist This flag indicates whether to attempt to delete the object from the db as well. |
|
105 | + * @return bool |
|
106 | + */ |
|
107 | + public function remove(EE_Message $message, $persist = false) |
|
108 | + { |
|
109 | + if ($persist && $this->_message_repository->current() !== $message) { |
|
110 | + // get pointer on right message |
|
111 | + if ($this->_message_repository->has($message)) { |
|
112 | + $this->_message_repository->rewind(); |
|
113 | + while ($this->_message_repository->valid()) { |
|
114 | + if ($this->_message_repository->current() === $message) { |
|
115 | + break; |
|
116 | + } |
|
117 | + $this->_message_repository->next(); |
|
118 | + } |
|
119 | + } else { |
|
120 | + return false; |
|
121 | + } |
|
122 | + } |
|
123 | + return $persist ? $this->_message_repository->delete() : $this->_message_repository->remove($message); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * Persists all queued EE_Message objects to the db. |
|
129 | + * |
|
130 | + * @param bool $do_hooks_only @see EE_Message_Repository::saveAll |
|
131 | + * @return array @see EE_Messages_Repository::saveAll() for return values. |
|
132 | + */ |
|
133 | + public function save($do_hooks_only = false) |
|
134 | + { |
|
135 | + return $this->_message_repository->saveAll($do_hooks_only); |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @return EE_Message_Repository |
|
141 | + */ |
|
142 | + public function get_message_repository() |
|
143 | + { |
|
144 | + return $this->_message_repository; |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * This does the following things: |
|
150 | + * 1. Checks if there is a lock on generation (prevents race conditions). If there is a lock then exits (return |
|
151 | + * false). |
|
152 | + * 2. If no lock, sets lock, then retrieves a batch of non-generated EE_Message objects and adds to queue |
|
153 | + * 3. Returns bool. True = batch ready. False = no batch ready (or nothing available for generation). |
|
154 | + * Note: Callers should make sure they release the lock otherwise batch generation will be prevented from |
|
155 | + * continuing. The lock is on a transient that is set to expire after one hour as a fallback in case locks are not |
|
156 | + * removed. |
|
157 | + * |
|
158 | + * @return bool true if successfully retrieved batch, false no batch ready. |
|
159 | + */ |
|
160 | + public function get_batch_to_generate() |
|
161 | + { |
|
162 | + if ($this->is_locked(EE_Messages_Queue::action_generating)) { |
|
163 | + return false; |
|
164 | + } |
|
165 | + |
|
166 | + // lock batch generation to prevent race conditions. |
|
167 | + $this->lock_queue(EE_Messages_Queue::action_generating); |
|
168 | + |
|
169 | + $query_args = array( |
|
170 | + // key 0 = where conditions |
|
171 | + 0 => array('STS_ID' => EEM_Message::status_incomplete), |
|
172 | + 'order_by' => $this->_get_priority_orderby(), |
|
173 | + 'limit' => $this->_batch_count, |
|
174 | + ); |
|
175 | + $messages = EEM_Message::instance()->get_all($query_args); |
|
176 | + |
|
177 | + if (! $messages) { |
|
178 | + return false; // nothing to generate |
|
179 | + } |
|
180 | + |
|
181 | + foreach ($messages as $message) { |
|
182 | + if ($message instanceof EE_Message) { |
|
183 | + $data = $message->all_extra_meta_array(); |
|
184 | + $this->add($message, $data); |
|
185 | + } |
|
186 | + } |
|
187 | + return true; |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * This does the following things: |
|
193 | + * 1. Checks if there is a lock on sending (prevents race conditions). If there is a lock then exits (return |
|
194 | + * false). |
|
195 | + * 2. Grabs the allowed number of messages to send for the rate_limit. If cannot send any more messages, then |
|
196 | + * return false. |
|
197 | + * 2. If no lock, sets lock, then retrieves a batch of EE_Message objects, adds to queue and triggers execution. |
|
198 | + * 3. On success or unsuccessful send, sets status appropriately. |
|
199 | + * 4. Saves messages via the queue |
|
200 | + * 5. Releases lock. |
|
201 | + * |
|
202 | + * @return bool true on success, false if something preventing sending (i.e. lock set). Note: true does not |
|
203 | + * necessarily mean that all messages were successfully sent. It just means that this method |
|
204 | + * successfully completed. On true, client may want to call $this->count_STS_in_queue( |
|
205 | + * EEM_Message::status_failed ) to see if any failed EE_Message objects. Each failed message object |
|
206 | + * will also have a saved error message on it to assist with notifying user. |
|
207 | + */ |
|
208 | + public function get_to_send_batch_and_send() |
|
209 | + { |
|
210 | + $rate_limit = $this->get_rate_limit(); |
|
211 | + if ( |
|
212 | + $rate_limit < 1 |
|
213 | + || $this->is_locked(EE_Messages_Queue::action_sending) |
|
214 | + ) { |
|
215 | + return false; |
|
216 | + } |
|
217 | + |
|
218 | + $this->lock_queue(EE_Messages_Queue::action_sending); |
|
219 | + |
|
220 | + $batch = $this->_batch_count < $rate_limit ? $this->_batch_count : $rate_limit; |
|
221 | + |
|
222 | + $query_args = array( |
|
223 | + // key 0 = where conditions |
|
224 | + 0 => array('STS_ID' => array('IN', EEM_Message::instance()->stati_indicating_to_send())), |
|
225 | + 'order_by' => $this->_get_priority_orderby(), |
|
226 | + 'limit' => $batch, |
|
227 | + ); |
|
228 | + |
|
229 | + $messages_to_send = EEM_Message::instance()->get_all($query_args); |
|
230 | + |
|
231 | + |
|
232 | + // any to send? |
|
233 | + if (! $messages_to_send) { |
|
234 | + $this->unlock_queue(EE_Messages_Queue::action_sending); |
|
235 | + return false; |
|
236 | + } |
|
237 | + |
|
238 | + $queue_count = 0; |
|
239 | + |
|
240 | + // add to queue. |
|
241 | + foreach ($messages_to_send as $message) { |
|
242 | + if ($message instanceof EE_Message) { |
|
243 | + $queue_count++; |
|
244 | + $this->add($message); |
|
245 | + } |
|
246 | + } |
|
247 | + |
|
248 | + // send messages (this also updates the rate limit) |
|
249 | + $this->execute(); |
|
250 | + |
|
251 | + // release lock |
|
252 | + $this->unlock_queue(EE_Messages_Queue::action_sending); |
|
253 | + // update rate limit |
|
254 | + $this->set_rate_limit($queue_count); |
|
255 | + return true; |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * Locks the queue so that no other queues can call the "batch" methods. |
|
261 | + * |
|
262 | + * @param string $type The type of queue being locked. |
|
263 | + */ |
|
264 | + public function lock_queue($type = EE_Messages_Queue::action_generating) |
|
265 | + { |
|
266 | + update_option($this->_get_lock_key($type), $this->_get_lock_expiry($type)); |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * Unlocks the queue so that batch methods can be used. |
|
272 | + * |
|
273 | + * @param string $type The type of queue being unlocked. |
|
274 | + */ |
|
275 | + public function unlock_queue($type = EE_Messages_Queue::action_generating) |
|
276 | + { |
|
277 | + delete_option($this->_get_lock_key($type)); |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * Retrieve the key used for the lock transient. |
|
283 | + * |
|
284 | + * @param string $type The type of lock. |
|
285 | + * @return string |
|
286 | + */ |
|
287 | + protected function _get_lock_key($type = EE_Messages_Queue::action_generating) |
|
288 | + { |
|
289 | + return '_ee_lock_' . $type; |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * Retrieve the expiry time for the lock transient. |
|
295 | + * |
|
296 | + * @param string $type The type of lock |
|
297 | + * @return int time to expiry in seconds. |
|
298 | + */ |
|
299 | + protected function _get_lock_expiry($type = EE_Messages_Queue::action_generating) |
|
300 | + { |
|
301 | + return time() + (int) apply_filters('FHEE__EE_Messages_Queue__lock_expiry', HOUR_IN_SECONDS, $type); |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * Returns the key used for rate limit transient. |
|
307 | + * |
|
308 | + * @return string |
|
309 | + */ |
|
310 | + protected function _get_rate_limit_key() |
|
311 | + { |
|
312 | + return '_ee_rate_limit'; |
|
313 | + } |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * Returns the rate limit expiry time. |
|
318 | + * |
|
319 | + * @return int |
|
320 | + */ |
|
321 | + protected function _get_rate_limit_expiry() |
|
322 | + { |
|
323 | + return time() + (int) apply_filters('FHEE__EE_Messages_Queue__rate_limit_expiry', HOUR_IN_SECONDS); |
|
324 | + } |
|
325 | + |
|
326 | + |
|
327 | + /** |
|
328 | + * Returns the default rate limit for sending messages. |
|
329 | + * |
|
330 | + * @return int |
|
331 | + */ |
|
332 | + protected function _default_rate_limit() |
|
333 | + { |
|
334 | + return (int) apply_filters('FHEE__EE_Messages_Queue___rate_limit', 200); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * Return the orderby array for priority. |
|
340 | + * |
|
341 | + * @return array |
|
342 | + */ |
|
343 | + protected function _get_priority_orderby() |
|
344 | + { |
|
345 | + return array( |
|
346 | + 'MSG_priority' => 'ASC', |
|
347 | + 'MSG_modified' => 'DESC', |
|
348 | + ); |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * Returns whether batch methods are "locked" or not, and if models an currently be used to query the database. |
|
354 | + * Return true when batch methods should not be used; returns false when they can be. |
|
355 | + * |
|
356 | + * @param string $type The type of lock being checked for. |
|
357 | + * @return bool |
|
358 | + */ |
|
359 | + public function is_locked($type = EE_Messages_Queue::action_generating) |
|
360 | + { |
|
361 | + if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
362 | + return true; |
|
363 | + } |
|
364 | + $lock = (int) get_option($this->_get_lock_key($type), 0); |
|
365 | + /** |
|
366 | + * This filters the default is_locked behaviour. |
|
367 | + */ |
|
368 | + $is_locked = filter_var( |
|
369 | + apply_filters( |
|
370 | + 'FHEE__EE_Messages_Queue__is_locked', |
|
371 | + $lock > time(), |
|
372 | + $this |
|
373 | + ), |
|
374 | + FILTER_VALIDATE_BOOLEAN |
|
375 | + ); |
|
376 | + |
|
377 | + /** |
|
378 | + * @see usage of this filter in EE_Messages_Queue::initiate_request_by_priority() method. |
|
379 | + * Also implemented here because messages processed on the same request should not have any locks applied. |
|
380 | + */ |
|
381 | + if ( |
|
382 | + apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
383 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
384 | + ) { |
|
385 | + $is_locked = false; |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + return $is_locked; |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + /** |
|
394 | + * Retrieves the rate limit that may be cached as a transient. |
|
395 | + * If the rate limit is not set, then this sets the default rate limit and expiry and returns it. |
|
396 | + * |
|
397 | + * @param bool $return_expiry If true then return the expiry time not the rate_limit. |
|
398 | + * @return int |
|
399 | + */ |
|
400 | + protected function get_rate_limit($return_expiry = false) |
|
401 | + { |
|
402 | + $stored_rate_info = get_option($this->_get_rate_limit_key(), array()); |
|
403 | + $rate_limit = isset($stored_rate_info[0]) |
|
404 | + ? (int) $stored_rate_info[0] |
|
405 | + : 0; |
|
406 | + $expiry = isset($stored_rate_info[1]) |
|
407 | + ? (int) $stored_rate_info[1] |
|
408 | + : 0; |
|
409 | + // set the default for tracking? |
|
410 | + if (empty($stored_rate_info) || time() > $expiry) { |
|
411 | + $expiry = $this->_get_rate_limit_expiry(); |
|
412 | + $rate_limit = $this->_default_rate_limit(); |
|
413 | + update_option($this->_get_rate_limit_key(), array($rate_limit, $expiry)); |
|
414 | + } |
|
415 | + return $return_expiry ? $expiry : $rate_limit; |
|
416 | + } |
|
417 | + |
|
418 | + |
|
419 | + /** |
|
420 | + * This updates existing rate limit with the new limit which is the old minus the batch. |
|
421 | + * |
|
422 | + * @param int $batch_completed This sets the new rate limit based on the given batch that was completed. |
|
423 | + */ |
|
424 | + protected function set_rate_limit($batch_completed) |
|
425 | + { |
|
426 | + // first get the most up to date rate limit (in case its expired and reset) |
|
427 | + $rate_limit = $this->get_rate_limit(); |
|
428 | + $expiry = $this->get_rate_limit(true); |
|
429 | + $new_limit = $rate_limit - $batch_completed; |
|
430 | + // updating the transient option directly to avoid resetting the expiry. |
|
431 | + |
|
432 | + update_option($this->_get_rate_limit_key(), array($new_limit, $expiry)); |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * This method checks the queue for ANY EE_Message objects with a priority matching the given priority passed in. |
|
438 | + * If that exists, then we immediately initiate a non-blocking request to do the requested action type. |
|
439 | + * Note: Keep in mind that there is the possibility that the request will not execute if there is already another |
|
440 | + * request running on a queue for the given task. |
|
441 | + * |
|
442 | + * @param string $task This indicates what type of request is going to be initiated. |
|
443 | + * @param int $priority This indicates the priority that triggers initiating the request. |
|
444 | + */ |
|
445 | + public function initiate_request_by_priority($task = 'generate', $priority = EEM_Message::priority_high) |
|
446 | + { |
|
447 | + // determine what status is matched with the priority as part of the trigger conditions. |
|
448 | + $status = $task == 'generate' |
|
449 | + ? EEM_Message::status_incomplete |
|
450 | + : EEM_Message::instance()->stati_indicating_to_send(); |
|
451 | + // always make sure we save because either this will get executed immediately on a separate request |
|
452 | + // or remains in the queue for the regularly scheduled queue batch. |
|
453 | + $this->save(); |
|
454 | + /** |
|
455 | + * This filter/option allows users to override processing of messages on separate requests and instead have everything |
|
456 | + * happen on the same request. If this is utilized remember: |
|
457 | + * - message priorities don't matter |
|
458 | + * - existing unprocessed messages in the queue will not get processed unless manually triggered. |
|
459 | + * - things will be perceived to take longer to happen for end users (i.e. registrations) because of the additional |
|
460 | + * processing happening on the same request. |
|
461 | + * - any race condition protection (locks) are removed because they don't apply when things are processed on |
|
462 | + * the same request. |
|
463 | + */ |
|
464 | + if ( |
|
465 | + apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
466 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
467 | + ) { |
|
468 | + $messages_processor = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
469 | + if ($messages_processor instanceof EE_Messages_Processor) { |
|
470 | + return $messages_processor->process_immediately_from_queue($this); |
|
471 | + } |
|
472 | + // if we get here then that means the messages processor couldn't be loaded so messages will just remain |
|
473 | + // queued for manual triggering by end user. |
|
474 | + } |
|
475 | + |
|
476 | + if ($this->_message_repository->count_by_priority_and_status($priority, $status)) { |
|
477 | + EE_Messages_Scheduler::initiate_scheduled_non_blocking_request($task); |
|
478 | + } |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + /** |
|
483 | + * Loops through the EE_Message objects in the _queue and calls the messenger send methods for each message. |
|
484 | + * |
|
485 | + * @param bool $save Used to indicate whether to save the message queue after sending |
|
486 | + * (default will save). |
|
487 | + * @param mixed $sending_messenger (optional) When the sending messenger is different than |
|
488 | + * what is on the EE_Message object in the queue. |
|
489 | + * For instance, showing the browser view of an email message, |
|
490 | + * or giving a pdf generated view of an html document. |
|
491 | + * This should be an instance of EE_messenger but if you call this |
|
492 | + * method |
|
493 | + * intending it to be a sending messenger but a valid one could not be |
|
494 | + * retrieved then send in an instance of EE_Error that contains the |
|
495 | + * related error message. |
|
496 | + * @param bool|int $by_priority When set, this indicates that only messages |
|
497 | + * matching the given priority should be executed. |
|
498 | + * @return int Number of messages sent. Note, 0 does not mean that no messages were processed. |
|
499 | + * Also, if the messenger is an request type messenger (or a preview), |
|
500 | + * its entirely possible that the messenger will exit before |
|
501 | + */ |
|
502 | + public function execute($save = true, $sending_messenger = null, $by_priority = false) |
|
503 | + { |
|
504 | + $messages_sent = 0; |
|
505 | + $this->_did_hook = array(); |
|
506 | + $this->_message_repository->rewind(); |
|
507 | + |
|
508 | + while ($this->_message_repository->valid()) { |
|
509 | + $error_messages = array(); |
|
510 | + /** @type EE_Message $message */ |
|
511 | + $message = $this->_message_repository->current(); |
|
512 | + // only process things that are queued for sending |
|
513 | + if (! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { |
|
514 | + $this->_message_repository->next(); |
|
515 | + continue; |
|
516 | + } |
|
517 | + // if $by_priority is set and does not match then continue; |
|
518 | + if ($by_priority && $by_priority != $message->priority()) { |
|
519 | + $this->_message_repository->next(); |
|
520 | + continue; |
|
521 | + } |
|
522 | + // error checking |
|
523 | + if (! $message->valid_messenger()) { |
|
524 | + $error_messages[] = sprintf( |
|
525 | + esc_html__('The %s messenger is not active at time of sending.', 'event_espresso'), |
|
526 | + $message->messenger() |
|
527 | + ); |
|
528 | + } |
|
529 | + if (! $message->valid_message_type()) { |
|
530 | + $error_messages[] = sprintf( |
|
531 | + esc_html__('The %s message type is not active at the time of sending.', 'event_espresso'), |
|
532 | + $message->message_type() |
|
533 | + ); |
|
534 | + } |
|
535 | + // if there was supposed to be a sending messenger for this message, but it was invalid/inactive, |
|
536 | + // then it will instead be an EE_Error object, so let's check for that |
|
537 | + if ($sending_messenger instanceof EE_Error) { |
|
538 | + $error_messages[] = $sending_messenger->getMessage(); |
|
539 | + } |
|
540 | + // if there are no errors, then let's process the message |
|
541 | + if (empty($error_messages)) { |
|
542 | + if ($save) { |
|
543 | + $message->set_messenger_is_executing(); |
|
544 | + } |
|
545 | + if ($this->_process_message($message, $sending_messenger)) { |
|
546 | + $messages_sent++; |
|
547 | + } |
|
548 | + } |
|
549 | + $this->_set_error_message($message, $error_messages); |
|
550 | + // add modified time |
|
551 | + $message->set_modified(time()); |
|
552 | + // we save each message after its processed to make sure its status persists in case PHP times-out or runs |
|
553 | + // out of memory. @see https://events.codebasehq.com/projects/event-espresso/tickets/10281 |
|
554 | + if ($save) { |
|
555 | + $message->save(); |
|
556 | + } |
|
557 | + |
|
558 | + $this->_message_repository->next(); |
|
559 | + } |
|
560 | + if ($save) { |
|
561 | + $this->save(true); |
|
562 | + } |
|
563 | + return $messages_sent; |
|
564 | + } |
|
565 | + |
|
566 | + |
|
567 | + /** |
|
568 | + * _process_message |
|
569 | + * |
|
570 | + * @param EE_Message $message |
|
571 | + * @param mixed $sending_messenger (optional) |
|
572 | + * @return bool |
|
573 | + */ |
|
574 | + protected function _process_message(EE_Message $message, $sending_messenger = null) |
|
575 | + { |
|
576 | + // these *should* have been validated in the execute() method above |
|
577 | + $messenger = $message->messenger_object(); |
|
578 | + $message_type = $message->message_type_object(); |
|
579 | + // do actions for sending messenger if it differs from generating messenger and swap values. |
|
580 | + if ( |
|
581 | + $sending_messenger instanceof EE_messenger |
|
582 | + && $messenger instanceof EE_messenger |
|
583 | + && $sending_messenger->name != $messenger->name |
|
584 | + ) { |
|
585 | + $messenger->do_secondary_messenger_hooks($sending_messenger->name); |
|
586 | + $messenger = $sending_messenger; |
|
587 | + } |
|
588 | + // send using messenger, but double check objects |
|
589 | + if ($messenger instanceof EE_messenger && $message_type instanceof EE_message_type) { |
|
590 | + // set hook for message type (but only if not using another messenger to send). |
|
591 | + if (! isset($this->_did_hook[ $message_type->name ])) { |
|
592 | + $message_type->do_messenger_hooks($messenger); |
|
593 | + $this->_did_hook[ $message_type->name ] = 1; |
|
594 | + } |
|
595 | + // if preview then use preview method |
|
596 | + return $this->_message_repository->is_preview() |
|
597 | + ? $this->_do_preview($message, $messenger, $message_type, $this->_message_repository->is_test_send()) |
|
598 | + : $this->_do_send($message, $messenger, $message_type); |
|
599 | + } |
|
600 | + return false; |
|
601 | + } |
|
602 | + |
|
603 | + |
|
604 | + /** |
|
605 | + * The intention of this method is to count how many EE_Message objects |
|
606 | + * are in the queue with a given status. |
|
607 | + * Example usage: |
|
608 | + * After a caller calls the "EE_Message_Queue::execute()" method, the caller can check if there were any failed |
|
609 | + * sends by calling $queue->count_STS_in_queue( EEM_Message_Queue::status_failed ). |
|
610 | + * |
|
611 | + * @param array|string $status Stati to check for in queue |
|
612 | + * @return int Count of EE_Message's matching the given status. |
|
613 | + */ |
|
614 | + public function count_STS_in_queue($status) |
|
615 | + { |
|
616 | + $count = 0; |
|
617 | + $status = is_array($status) ? $status : array($status); |
|
618 | + $this->_message_repository->rewind(); |
|
619 | + foreach ($this->_message_repository as $message) { |
|
620 | + if (in_array($message->STS_ID(), $status)) { |
|
621 | + $count++; |
|
622 | + } |
|
623 | + } |
|
624 | + return $count; |
|
625 | + } |
|
626 | + |
|
627 | + |
|
628 | + /** |
|
629 | + * Executes the get_preview method on the provided messenger. |
|
630 | + * |
|
631 | + * @param EE_Message $message |
|
632 | + * @param EE_messenger $messenger |
|
633 | + * @param EE_message_type $message_type |
|
634 | + * @param $test_send |
|
635 | + * @return bool true means all went well, false means, not so much. |
|
636 | + */ |
|
637 | + protected function _do_preview( |
|
638 | + EE_Message $message, |
|
639 | + EE_messenger $messenger, |
|
640 | + EE_message_type $message_type, |
|
641 | + $test_send |
|
642 | + ) { |
|
643 | + if ($preview = $messenger->get_preview($message, $message_type, $test_send)) { |
|
644 | + if (! $test_send) { |
|
645 | + $message->set_content($preview); |
|
646 | + } |
|
647 | + $message->set_STS_ID(EEM_Message::status_sent); |
|
648 | + return true; |
|
649 | + } else { |
|
650 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
651 | + return false; |
|
652 | + } |
|
653 | + } |
|
654 | + |
|
655 | + |
|
656 | + /** |
|
657 | + * Executes the send method on the provided messenger |
|
658 | + * EE_Messengers are expected to: |
|
659 | + * - return true if the send was successful. |
|
660 | + * - return false if the send was unsuccessful but can be tried again. |
|
661 | + * - throw an Exception if the send was unsuccessful and cannot be tried again. |
|
662 | + * |
|
663 | + * @param EE_Message $message |
|
664 | + * @param EE_messenger $messenger |
|
665 | + * @param EE_message_type $message_type |
|
666 | + * @return bool true means all went well, false means, not so much. |
|
667 | + */ |
|
668 | + protected function _do_send(EE_Message $message, EE_messenger $messenger, EE_message_type $message_type) |
|
669 | + { |
|
670 | + try { |
|
671 | + if ($messenger->send_message($message, $message_type)) { |
|
672 | + $message->set_STS_ID(EEM_Message::status_sent); |
|
673 | + return true; |
|
674 | + } else { |
|
675 | + $message->set_STS_ID(EEM_Message::status_retry); |
|
676 | + return false; |
|
677 | + } |
|
678 | + } catch (SendMessageException $e) { |
|
679 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
680 | + $message->set_error_message($e->getMessage()); |
|
681 | + return false; |
|
682 | + } |
|
683 | + } |
|
684 | + |
|
685 | + |
|
686 | + /** |
|
687 | + * This sets any necessary error messages on the message object and its status to failed. |
|
688 | + * |
|
689 | + * @param EE_Message $message |
|
690 | + * @param array $error_messages the response from the messenger. |
|
691 | + */ |
|
692 | + protected function _set_error_message(EE_Message $message, $error_messages) |
|
693 | + { |
|
694 | + $error_messages = (array) $error_messages; |
|
695 | + if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_failed_sending())) { |
|
696 | + $notices = EE_Error::has_notices(); |
|
697 | + $error_messages[] = esc_html__( |
|
698 | + 'Messenger and Message Type were valid and active, but the messenger send method failed.', |
|
699 | + 'event_espresso' |
|
700 | + ); |
|
701 | + if ($notices === 1) { |
|
702 | + $notices = EE_Error::get_vanilla_notices(); |
|
703 | + $notices['errors'] = isset($notices['errors']) ? $notices['errors'] : array(); |
|
704 | + $error_messages[] = implode("\n", $notices['errors']); |
|
705 | + } |
|
706 | + } |
|
707 | + if (count($error_messages) > 0) { |
|
708 | + $msg = esc_html__('Message was not executed successfully.', 'event_espresso'); |
|
709 | + $msg = $msg . "\n" . implode("\n", $error_messages); |
|
710 | + $message->set_error_message($msg); |
|
711 | + } |
|
712 | + } |
|
713 | 713 | } |
@@ -172,9 +172,9 @@ discard block |
||
172 | 172 | 'order_by' => $this->_get_priority_orderby(), |
173 | 173 | 'limit' => $this->_batch_count, |
174 | 174 | ); |
175 | - $messages = EEM_Message::instance()->get_all($query_args); |
|
175 | + $messages = EEM_Message::instance()->get_all($query_args); |
|
176 | 176 | |
177 | - if (! $messages) { |
|
177 | + if ( ! $messages) { |
|
178 | 178 | return false; // nothing to generate |
179 | 179 | } |
180 | 180 | |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | |
231 | 231 | |
232 | 232 | // any to send? |
233 | - if (! $messages_to_send) { |
|
233 | + if ( ! $messages_to_send) { |
|
234 | 234 | $this->unlock_queue(EE_Messages_Queue::action_sending); |
235 | 235 | return false; |
236 | 236 | } |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | */ |
287 | 287 | protected function _get_lock_key($type = EE_Messages_Queue::action_generating) |
288 | 288 | { |
289 | - return '_ee_lock_' . $type; |
|
289 | + return '_ee_lock_'.$type; |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | */ |
359 | 359 | public function is_locked($type = EE_Messages_Queue::action_generating) |
360 | 360 | { |
361 | - if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
361 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
362 | 362 | return true; |
363 | 363 | } |
364 | 364 | $lock = (int) get_option($this->_get_lock_key($type), 0); |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | /** @type EE_Message $message */ |
511 | 511 | $message = $this->_message_repository->current(); |
512 | 512 | // only process things that are queued for sending |
513 | - if (! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { |
|
513 | + if ( ! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { |
|
514 | 514 | $this->_message_repository->next(); |
515 | 515 | continue; |
516 | 516 | } |
@@ -520,13 +520,13 @@ discard block |
||
520 | 520 | continue; |
521 | 521 | } |
522 | 522 | // error checking |
523 | - if (! $message->valid_messenger()) { |
|
523 | + if ( ! $message->valid_messenger()) { |
|
524 | 524 | $error_messages[] = sprintf( |
525 | 525 | esc_html__('The %s messenger is not active at time of sending.', 'event_espresso'), |
526 | 526 | $message->messenger() |
527 | 527 | ); |
528 | 528 | } |
529 | - if (! $message->valid_message_type()) { |
|
529 | + if ( ! $message->valid_message_type()) { |
|
530 | 530 | $error_messages[] = sprintf( |
531 | 531 | esc_html__('The %s message type is not active at the time of sending.', 'event_espresso'), |
532 | 532 | $message->message_type() |
@@ -588,9 +588,9 @@ discard block |
||
588 | 588 | // send using messenger, but double check objects |
589 | 589 | if ($messenger instanceof EE_messenger && $message_type instanceof EE_message_type) { |
590 | 590 | // set hook for message type (but only if not using another messenger to send). |
591 | - if (! isset($this->_did_hook[ $message_type->name ])) { |
|
591 | + if ( ! isset($this->_did_hook[$message_type->name])) { |
|
592 | 592 | $message_type->do_messenger_hooks($messenger); |
593 | - $this->_did_hook[ $message_type->name ] = 1; |
|
593 | + $this->_did_hook[$message_type->name] = 1; |
|
594 | 594 | } |
595 | 595 | // if preview then use preview method |
596 | 596 | return $this->_message_repository->is_preview() |
@@ -641,7 +641,7 @@ discard block |
||
641 | 641 | $test_send |
642 | 642 | ) { |
643 | 643 | if ($preview = $messenger->get_preview($message, $message_type, $test_send)) { |
644 | - if (! $test_send) { |
|
644 | + if ( ! $test_send) { |
|
645 | 645 | $message->set_content($preview); |
646 | 646 | } |
647 | 647 | $message->set_STS_ID(EEM_Message::status_sent); |
@@ -706,7 +706,7 @@ discard block |
||
706 | 706 | } |
707 | 707 | if (count($error_messages) > 0) { |
708 | 708 | $msg = esc_html__('Message was not executed successfully.', 'event_espresso'); |
709 | - $msg = $msg . "\n" . implode("\n", $error_messages); |
|
709 | + $msg = $msg."\n".implode("\n", $error_messages); |
|
710 | 710 | $message->set_error_message($msg); |
711 | 711 | } |
712 | 712 | } |