@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | |
8 | 8 | function ee_resurse_into_array($data) { |
9 | 9 | if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {//is_object($incomplete_class) actually returns false, hence why we check for it |
10 | - $data = (array)$data; |
|
10 | + $data = (array) $data; |
|
11 | 11 | } |
12 | 12 | if (is_array($data)) { |
13 | 13 | if (EEH_Array::is_associative_array($data)) { |
@@ -19,10 +19,10 @@ discard block |
||
19 | 19 | ?> |
20 | 20 | <tr> |
21 | 21 | <td> |
22 | - <?php echo $data_key;?> |
|
22 | + <?php echo $data_key; ?> |
|
23 | 23 | </td> |
24 | 24 | <td> |
25 | - <?php ee_resurse_into_array($data_values);?> |
|
25 | + <?php ee_resurse_into_array($data_values); ?> |
|
26 | 26 | </td> |
27 | 27 | </tr> |
28 | 28 | <?php |
@@ -36,19 +36,19 @@ discard block |
||
36 | 36 | <ul> |
37 | 37 | <?php |
38 | 38 | foreach ($data as $datum) { |
39 | - echo "<li>";ee_resurse_into_array($datum);echo "</li>"; |
|
39 | + echo "<li>"; ee_resurse_into_array($datum); echo "</li>"; |
|
40 | 40 | }?> |
41 | 41 | </ul> |
42 | 42 | <?php |
43 | 43 | } |
44 | - }else { |
|
44 | + } else { |
|
45 | 45 | //simple value |
46 | 46 | echo $data; |
47 | 47 | } |
48 | 48 | } |
49 | 49 | ?> |
50 | 50 | <h1> |
51 | - <?php _e("System Information", "event_espresso");?> <a href="<?php echo $download_system_status_url;?>" class="button-secondary"><?php esc_html_e( 'Download to File', 'event_espresso' );?></a> |
|
51 | + <?php _e("System Information", "event_espresso"); ?> <a href="<?php echo $download_system_status_url; ?>" class="button-secondary"><?php esc_html_e('Download to File', 'event_espresso'); ?></a> |
|
52 | 52 | </h1> |
53 | 53 | <div class="padding"> |
54 | 54 | |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | <?php |
57 | 57 | foreach ($system_stati as $status_category_slug => $data) { |
58 | 58 | if (is_object($data)) { |
59 | - $data = (array)$data; |
|
59 | + $data = (array) $data; |
|
60 | 60 | } |
61 | 61 | ?> |
62 | 62 | <thead> |
@@ -16,234 +16,234 @@ |
||
16 | 16 | class Registry |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $jsdata = array(); |
|
24 | - |
|
25 | - |
|
26 | - /** |
|
27 | - * Registry constructor. |
|
28 | - * Hooking into WP actions for script registry. |
|
29 | - */ |
|
30 | - public function __construct() |
|
31 | - { |
|
32 | - add_action('wp_enqueue_scripts', array($this, 'scripts'), 100); |
|
33 | - add_action('admin_enqueue_scripts', array($this, 'scripts'), 100); |
|
34 | - add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
35 | - add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
36 | - } |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * Callback for the WP script actions. |
|
41 | - * Used to register globally accessible core scripts. |
|
42 | - * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
43 | - */ |
|
44 | - public function scripts() |
|
45 | - { |
|
46 | - global $wp_version; |
|
47 | - wp_register_script( |
|
48 | - 'eejs-core', |
|
49 | - EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js', |
|
50 | - array(), |
|
51 | - espresso_version(), |
|
52 | - true |
|
53 | - ); |
|
54 | - //only run this if WordPress 4.4.0 > is in use. |
|
55 | - if (version_compare($wp_version, '4.4.0', '>')) { |
|
56 | - //js.api |
|
57 | - wp_register_script( |
|
58 | - 'eejs-api', |
|
59 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
60 | - array('underscore', 'eejs-core'), |
|
61 | - espresso_version(), |
|
62 | - true |
|
63 | - ); |
|
64 | - $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
|
65 | - $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
66 | - } |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * Call back for the script print in frontend and backend. |
|
72 | - * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hookpoint. |
|
73 | - * @since 4.9.31.rc.015 |
|
74 | - */ |
|
75 | - public function enqueueData() |
|
76 | - { |
|
77 | - wp_localize_script('eejs-core', 'eejs', array('data' => $this->jsdata)); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * Used to add data to eejs.data object. |
|
83 | - * |
|
84 | - * Note: Overriding existing data is not allowed. |
|
85 | - * |
|
86 | - * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
87 | - * If the data you add is something like this: |
|
88 | - * |
|
89 | - * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
90 | - * |
|
91 | - * It will be exposed in the page source as: |
|
92 | - * |
|
93 | - * eejs.data.my_plugin_data.foo == gar |
|
94 | - * |
|
95 | - * @param string $key Key used to access your data |
|
96 | - * @param string|array $value Value to attach to key |
|
97 | - * @throws InvalidArgumentException |
|
98 | - */ |
|
99 | - public function addData($key, $value) |
|
100 | - { |
|
101 | - if ($this->verifyDataNotExisting($key)) { |
|
102 | - $this->jsdata[$key] = $value; |
|
103 | - } |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
109 | - * elements in an array. |
|
110 | - * |
|
111 | - * When you use this method, the value you include will be appended to the end of an array on $key. |
|
112 | - * |
|
113 | - * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript object |
|
114 | - * like this, |
|
115 | - * |
|
116 | - * eejs.data.test = [ |
|
117 | - * my_data, |
|
118 | - * ] |
|
119 | - * |
|
120 | - * If there has already been a scalar value attached to the data object given key, then |
|
121 | - * this will throw an exception. |
|
122 | - * |
|
123 | - * @param string $key Key to attach data to. |
|
124 | - * @param string|array $value Value being registered. |
|
125 | - * @throws InvalidArgumentException |
|
126 | - */ |
|
127 | - public function pushData($key, $value) |
|
128 | - { |
|
129 | - if (isset($this->jsdata[$key]) |
|
130 | - && ! is_array($this->jsdata[$key]) |
|
131 | - ) { |
|
132 | - throw new invalidArgumentException( |
|
133 | - sprintf( |
|
134 | - __( |
|
135 | - 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
19 | + /** |
|
20 | + * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $jsdata = array(); |
|
24 | + |
|
25 | + |
|
26 | + /** |
|
27 | + * Registry constructor. |
|
28 | + * Hooking into WP actions for script registry. |
|
29 | + */ |
|
30 | + public function __construct() |
|
31 | + { |
|
32 | + add_action('wp_enqueue_scripts', array($this, 'scripts'), 100); |
|
33 | + add_action('admin_enqueue_scripts', array($this, 'scripts'), 100); |
|
34 | + add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
35 | + add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
36 | + } |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * Callback for the WP script actions. |
|
41 | + * Used to register globally accessible core scripts. |
|
42 | + * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
43 | + */ |
|
44 | + public function scripts() |
|
45 | + { |
|
46 | + global $wp_version; |
|
47 | + wp_register_script( |
|
48 | + 'eejs-core', |
|
49 | + EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js', |
|
50 | + array(), |
|
51 | + espresso_version(), |
|
52 | + true |
|
53 | + ); |
|
54 | + //only run this if WordPress 4.4.0 > is in use. |
|
55 | + if (version_compare($wp_version, '4.4.0', '>')) { |
|
56 | + //js.api |
|
57 | + wp_register_script( |
|
58 | + 'eejs-api', |
|
59 | + EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
60 | + array('underscore', 'eejs-core'), |
|
61 | + espresso_version(), |
|
62 | + true |
|
63 | + ); |
|
64 | + $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
|
65 | + $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
66 | + } |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * Call back for the script print in frontend and backend. |
|
72 | + * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hookpoint. |
|
73 | + * @since 4.9.31.rc.015 |
|
74 | + */ |
|
75 | + public function enqueueData() |
|
76 | + { |
|
77 | + wp_localize_script('eejs-core', 'eejs', array('data' => $this->jsdata)); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * Used to add data to eejs.data object. |
|
83 | + * |
|
84 | + * Note: Overriding existing data is not allowed. |
|
85 | + * |
|
86 | + * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
87 | + * If the data you add is something like this: |
|
88 | + * |
|
89 | + * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
90 | + * |
|
91 | + * It will be exposed in the page source as: |
|
92 | + * |
|
93 | + * eejs.data.my_plugin_data.foo == gar |
|
94 | + * |
|
95 | + * @param string $key Key used to access your data |
|
96 | + * @param string|array $value Value to attach to key |
|
97 | + * @throws InvalidArgumentException |
|
98 | + */ |
|
99 | + public function addData($key, $value) |
|
100 | + { |
|
101 | + if ($this->verifyDataNotExisting($key)) { |
|
102 | + $this->jsdata[$key] = $value; |
|
103 | + } |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
109 | + * elements in an array. |
|
110 | + * |
|
111 | + * When you use this method, the value you include will be appended to the end of an array on $key. |
|
112 | + * |
|
113 | + * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript object |
|
114 | + * like this, |
|
115 | + * |
|
116 | + * eejs.data.test = [ |
|
117 | + * my_data, |
|
118 | + * ] |
|
119 | + * |
|
120 | + * If there has already been a scalar value attached to the data object given key, then |
|
121 | + * this will throw an exception. |
|
122 | + * |
|
123 | + * @param string $key Key to attach data to. |
|
124 | + * @param string|array $value Value being registered. |
|
125 | + * @throws InvalidArgumentException |
|
126 | + */ |
|
127 | + public function pushData($key, $value) |
|
128 | + { |
|
129 | + if (isset($this->jsdata[$key]) |
|
130 | + && ! is_array($this->jsdata[$key]) |
|
131 | + ) { |
|
132 | + throw new invalidArgumentException( |
|
133 | + sprintf( |
|
134 | + __( |
|
135 | + 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
136 | 136 | push values to this data element when it is an array.', |
137 | - 'event_espresso' |
|
138 | - ), |
|
139 | - $key, |
|
140 | - __METHOD__ |
|
141 | - ) |
|
142 | - ); |
|
143 | - } |
|
144 | - |
|
145 | - $this->jsdata[$key][] = $value; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * Used to set content used by javascript for a template. |
|
151 | - * Note: Overrides of existing registered templates are not allowed. |
|
152 | - * |
|
153 | - * @param string $template_reference |
|
154 | - * @param string $template_content |
|
155 | - * @throws InvalidArgumentException |
|
156 | - */ |
|
157 | - public function addTemplate($template_reference, $template_content) |
|
158 | - { |
|
159 | - if (! isset($this->jsdata['templates'])) { |
|
160 | - $this->jsdata['templates'] = array(); |
|
161 | - } |
|
162 | - |
|
163 | - //no overrides allowed. |
|
164 | - if (isset($this->jsdata['templates'][$template_reference])) { |
|
165 | - throw new invalidArgumentException( |
|
166 | - sprintf( |
|
167 | - __( |
|
168 | - 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
169 | - 'event_espresso' |
|
170 | - ), |
|
171 | - $template_reference |
|
172 | - ) |
|
173 | - ); |
|
174 | - } else { |
|
175 | - $this->jsdata['templates'][$template_reference] = $template_content; |
|
176 | - } |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * Retrieve the template content already registered for the given reference. |
|
182 | - * @param string $template_reference |
|
183 | - * @return string |
|
184 | - */ |
|
185 | - public function getTemplate($template_reference) |
|
186 | - { |
|
187 | - return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
188 | - ? $this->jsdata['templates'][$template_reference] |
|
189 | - : ''; |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * Retrieve registered data. |
|
195 | - * |
|
196 | - * @param string $key Name of key to attach data to. |
|
197 | - * @return mixed If there is no for the given key, then false is returned. |
|
198 | - */ |
|
199 | - public function getData($key) |
|
200 | - { |
|
201 | - return isset($this->jsdata[$key]) |
|
202 | - ? $this->jsdata[$key] |
|
203 | - : false; |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * Verifies whether the given data exists already on the jsdata array. |
|
211 | - * |
|
212 | - * Overriding data is not allowed. |
|
213 | - * |
|
214 | - * @param string $key Index for data. |
|
215 | - * @return bool If valid then return true. |
|
216 | - * @throws InvalidArgumentException if data already exists. |
|
217 | - */ |
|
218 | - protected function verifyDataNotExisting($key) |
|
219 | - { |
|
220 | - if (isset($this->jsdata[$key])) { |
|
221 | - if (is_array($this->jsdata[$key])) { |
|
222 | - throw new InvalidArgumentException( |
|
223 | - sprintf( |
|
224 | - __( |
|
225 | - 'The value for %1$s already exists in the Registry::eejs object. |
|
137 | + 'event_espresso' |
|
138 | + ), |
|
139 | + $key, |
|
140 | + __METHOD__ |
|
141 | + ) |
|
142 | + ); |
|
143 | + } |
|
144 | + |
|
145 | + $this->jsdata[$key][] = $value; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * Used to set content used by javascript for a template. |
|
151 | + * Note: Overrides of existing registered templates are not allowed. |
|
152 | + * |
|
153 | + * @param string $template_reference |
|
154 | + * @param string $template_content |
|
155 | + * @throws InvalidArgumentException |
|
156 | + */ |
|
157 | + public function addTemplate($template_reference, $template_content) |
|
158 | + { |
|
159 | + if (! isset($this->jsdata['templates'])) { |
|
160 | + $this->jsdata['templates'] = array(); |
|
161 | + } |
|
162 | + |
|
163 | + //no overrides allowed. |
|
164 | + if (isset($this->jsdata['templates'][$template_reference])) { |
|
165 | + throw new invalidArgumentException( |
|
166 | + sprintf( |
|
167 | + __( |
|
168 | + 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
169 | + 'event_espresso' |
|
170 | + ), |
|
171 | + $template_reference |
|
172 | + ) |
|
173 | + ); |
|
174 | + } else { |
|
175 | + $this->jsdata['templates'][$template_reference] = $template_content; |
|
176 | + } |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * Retrieve the template content already registered for the given reference. |
|
182 | + * @param string $template_reference |
|
183 | + * @return string |
|
184 | + */ |
|
185 | + public function getTemplate($template_reference) |
|
186 | + { |
|
187 | + return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
188 | + ? $this->jsdata['templates'][$template_reference] |
|
189 | + : ''; |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * Retrieve registered data. |
|
195 | + * |
|
196 | + * @param string $key Name of key to attach data to. |
|
197 | + * @return mixed If there is no for the given key, then false is returned. |
|
198 | + */ |
|
199 | + public function getData($key) |
|
200 | + { |
|
201 | + return isset($this->jsdata[$key]) |
|
202 | + ? $this->jsdata[$key] |
|
203 | + : false; |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * Verifies whether the given data exists already on the jsdata array. |
|
211 | + * |
|
212 | + * Overriding data is not allowed. |
|
213 | + * |
|
214 | + * @param string $key Index for data. |
|
215 | + * @return bool If valid then return true. |
|
216 | + * @throws InvalidArgumentException if data already exists. |
|
217 | + */ |
|
218 | + protected function verifyDataNotExisting($key) |
|
219 | + { |
|
220 | + if (isset($this->jsdata[$key])) { |
|
221 | + if (is_array($this->jsdata[$key])) { |
|
222 | + throw new InvalidArgumentException( |
|
223 | + sprintf( |
|
224 | + __( |
|
225 | + 'The value for %1$s already exists in the Registry::eejs object. |
|
226 | 226 | Overrides are not allowed. Since the value of this data is an array, you may want to use the |
227 | 227 | %2$s method to push your value to the array.', |
228 | - 'event_espresso' |
|
229 | - ), |
|
230 | - $key, |
|
231 | - 'pushData()' |
|
232 | - ) |
|
233 | - ); |
|
234 | - } else { |
|
235 | - throw new InvalidArgumentException( |
|
236 | - sprintf( |
|
237 | - __( |
|
238 | - 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
228 | + 'event_espresso' |
|
229 | + ), |
|
230 | + $key, |
|
231 | + 'pushData()' |
|
232 | + ) |
|
233 | + ); |
|
234 | + } else { |
|
235 | + throw new InvalidArgumentException( |
|
236 | + sprintf( |
|
237 | + __( |
|
238 | + 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
239 | 239 | allowed. Consider attaching your value to a different key', |
240 | - 'event_espresso' |
|
241 | - ), |
|
242 | - $key |
|
243 | - ) |
|
244 | - ); |
|
245 | - } |
|
246 | - } |
|
247 | - return true; |
|
248 | - } |
|
240 | + 'event_espresso' |
|
241 | + ), |
|
242 | + $key |
|
243 | + ) |
|
244 | + ); |
|
245 | + } |
|
246 | + } |
|
247 | + return true; |
|
248 | + } |
|
249 | 249 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('NO direct script access allowed'); |
|
3 | + exit('NO direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -28,633 +28,633 @@ discard block |
||
28 | 28 | { |
29 | 29 | |
30 | 30 | |
31 | - public function __construct($routing = true) |
|
32 | - { |
|
33 | - parent::__construct($routing); |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - |
|
38 | - protected function _init_page_props() |
|
39 | - { |
|
40 | - $this->page_slug = EE_MAINTENANCE_PG_SLUG; |
|
41 | - $this->page_label = EE_MAINTENANCE_LABEL; |
|
42 | - $this->_admin_base_url = EE_MAINTENANCE_ADMIN_URL; |
|
43 | - $this->_admin_base_path = EE_MAINTENANCE_ADMIN; |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - |
|
48 | - protected function _ajax_hooks() |
|
49 | - { |
|
50 | - add_action('wp_ajax_migration_step', array($this, 'migration_step')); |
|
51 | - add_action('wp_ajax_add_error_to_migrations_ran', array($this, 'add_error_to_migrations_ran')); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - protected function _define_page_props() |
|
57 | - { |
|
58 | - $this->_admin_page_title = EE_MAINTENANCE_LABEL; |
|
59 | - $this->_labels = array( |
|
60 | - 'buttons' => array( |
|
61 | - 'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'), |
|
62 | - 'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'), |
|
63 | - ), |
|
64 | - ); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - |
|
69 | - protected function _set_page_routes() |
|
70 | - { |
|
71 | - $this->_page_routes = array( |
|
72 | - 'default' => array( |
|
73 | - 'func' => '_maintenance', |
|
74 | - 'capability' => 'manage_options', |
|
75 | - ), |
|
76 | - 'change_maintenance_level' => array( |
|
77 | - 'func' => '_change_maintenance_level', |
|
78 | - 'capability' => 'manage_options', |
|
79 | - 'noheader' => true, |
|
80 | - ), |
|
81 | - 'system_status' => array( |
|
82 | - 'func' => '_system_status', |
|
83 | - 'capability' => 'manage_options', |
|
84 | - ), |
|
85 | - 'download_system_status' => array( |
|
86 | - 'func' => '_download_system_status', |
|
87 | - 'capability' => 'manage_options', |
|
88 | - 'noheader' => true, |
|
89 | - ), |
|
90 | - 'send_migration_crash_report' => array( |
|
91 | - 'func' => '_send_migration_crash_report', |
|
92 | - 'capability' => 'manage_options', |
|
93 | - 'noheader' => true, |
|
94 | - ), |
|
95 | - 'confirm_migration_crash_report_sent' => array( |
|
96 | - 'func' => '_confirm_migration_crash_report_sent', |
|
97 | - 'capability' => 'manage_options', |
|
98 | - ), |
|
99 | - 'data_reset' => array( |
|
100 | - 'func' => '_data_reset_and_delete', |
|
101 | - 'capability' => 'manage_options', |
|
102 | - ), |
|
103 | - 'reset_db' => array( |
|
104 | - 'func' => '_reset_db', |
|
105 | - 'capability' => 'manage_options', |
|
106 | - 'noheader' => true, |
|
107 | - 'args' => array('nuke_old_ee4_data' => true), |
|
108 | - ), |
|
109 | - 'start_with_fresh_ee4_db' => array( |
|
110 | - 'func' => '_reset_db', |
|
111 | - 'capability' => 'manage_options', |
|
112 | - 'noheader' => true, |
|
113 | - 'args' => array('nuke_old_ee4_data' => false), |
|
114 | - ), |
|
115 | - 'delete_db' => array( |
|
116 | - 'func' => '_delete_db', |
|
117 | - 'capability' => 'manage_options', |
|
118 | - 'noheader' => true, |
|
119 | - ), |
|
120 | - 'rerun_migration_from_ee3' => array( |
|
121 | - 'func' => '_rerun_migration_from_ee3', |
|
122 | - 'capability' => 'manage_options', |
|
123 | - 'noheader' => true, |
|
124 | - ), |
|
125 | - 'reset_reservations' => array( |
|
126 | - 'func' => '_reset_reservations', |
|
127 | - 'capability' => 'manage_options', |
|
128 | - 'noheader' => true, |
|
129 | - ), |
|
130 | - 'reset_capabilities' => array( |
|
131 | - 'func' => '_reset_capabilities', |
|
132 | - 'capability' => 'manage_options', |
|
133 | - 'noheader' => true, |
|
134 | - ), |
|
135 | - 'reattempt_migration' => array( |
|
136 | - 'func' => '_reattempt_migration', |
|
137 | - 'capability' => 'manage_options', |
|
138 | - 'noheader' => true, |
|
139 | - ), |
|
140 | - ); |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - |
|
145 | - protected function _set_page_config() |
|
146 | - { |
|
147 | - $this->_page_config = array( |
|
148 | - 'default' => array( |
|
149 | - 'nav' => array( |
|
150 | - 'label' => esc_html__('Maintenance', 'event_espresso'), |
|
151 | - 'order' => 10, |
|
152 | - ), |
|
153 | - 'require_nonce' => false, |
|
154 | - ), |
|
155 | - 'data_reset' => array( |
|
156 | - 'nav' => array( |
|
157 | - 'label' => esc_html__('Reset/Delete Data', 'event_espresso'), |
|
158 | - 'order' => 20, |
|
159 | - ), |
|
160 | - 'require_nonce' => false, |
|
161 | - ), |
|
162 | - 'system_status' => array( |
|
163 | - 'nav' => array( |
|
164 | - 'label' => esc_html__("System Information", "event_espresso"), |
|
165 | - 'order' => 30, |
|
166 | - ), |
|
167 | - 'require_nonce' => false, |
|
168 | - ), |
|
169 | - ); |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * default maintenance page. If we're in maintenance mode level 2, then we need to show |
|
176 | - * the migration scripts and all that UI. |
|
177 | - */ |
|
178 | - public function _maintenance() |
|
179 | - { |
|
180 | - //it all depends if we're in maintenance model level 1 (frontend-only) or |
|
181 | - //level 2 (everything except maintenance page) |
|
182 | - try { |
|
183 | - //get the current maintenance level and check if |
|
184 | - //we are removed |
|
185 | - $mm = EE_Maintenance_Mode::instance()->level(); |
|
186 | - $placed_in_mm = EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
187 | - if ($mm == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) { |
|
188 | - //we just took the site out of maintenance mode, so notify the user. |
|
189 | - //unfortunately this message appears to be echoed on the NEXT page load... |
|
190 | - //oh well, we should really be checking for this on addon deactivation anyways |
|
191 | - EE_Error::add_attention(__('Site taken out of maintenance mode because no data migration scripts are required', |
|
192 | - 'event_espresso')); |
|
193 | - $this->_process_notices(array('page' => 'espresso_maintenance_settings'), false); |
|
194 | - } |
|
195 | - //in case an exception is thrown while trying to handle migrations |
|
196 | - switch (EE_Maintenance_Mode::instance()->level()) { |
|
197 | - case EE_Maintenance_Mode::level_0_not_in_maintenance: |
|
198 | - case EE_Maintenance_Mode::level_1_frontend_only_maintenance: |
|
199 | - $show_maintenance_switch = true; |
|
200 | - $show_backup_db_text = false; |
|
201 | - $show_migration_progress = false; |
|
202 | - $script_names = array(); |
|
203 | - $addons_should_be_upgraded_first = false; |
|
204 | - break; |
|
205 | - case EE_Maintenance_Mode::level_2_complete_maintenance: |
|
206 | - $show_maintenance_switch = false; |
|
207 | - $show_migration_progress = true; |
|
208 | - if (isset($this->_req_data['continue_migration'])) { |
|
209 | - $show_backup_db_text = false; |
|
210 | - } else { |
|
211 | - $show_backup_db_text = true; |
|
212 | - } |
|
213 | - $scripts_needing_to_run = EE_Data_Migration_Manager::instance() |
|
214 | - ->check_for_applicable_data_migration_scripts(); |
|
215 | - $addons_should_be_upgraded_first = EE_Data_Migration_Manager::instance()->addons_need_updating(); |
|
216 | - $script_names = array(); |
|
217 | - $current_script = null; |
|
218 | - foreach ($scripts_needing_to_run as $script) { |
|
219 | - if ($script instanceof EE_Data_Migration_Script_Base) { |
|
220 | - if ( ! $current_script) { |
|
221 | - $current_script = $script; |
|
222 | - $current_script->migration_page_hooks(); |
|
223 | - } |
|
224 | - $script_names[] = $script->pretty_name(); |
|
225 | - } |
|
226 | - } |
|
227 | - break; |
|
228 | - } |
|
229 | - $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true); |
|
230 | - $exception_thrown = false; |
|
231 | - } catch (EE_Error $e) { |
|
232 | - EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage()); |
|
233 | - //now, just so we can display the page correctly, make a error migration script stage object |
|
234 | - //and also put the error on it. It only persists for the duration of this request |
|
235 | - $most_recent_migration = new EE_DMS_Unknown_1_0_0(); |
|
236 | - $most_recent_migration->add_error($e->getMessage()); |
|
237 | - $exception_thrown = true; |
|
238 | - } |
|
239 | - $current_db_state = EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set(); |
|
240 | - $current_db_state = str_replace('.decaf', '', $current_db_state); |
|
241 | - if ($exception_thrown |
|
242 | - || ($most_recent_migration |
|
243 | - && $most_recent_migration instanceof EE_Data_Migration_Script_Base |
|
244 | - && $most_recent_migration->is_broken() |
|
245 | - ) |
|
246 | - ) { |
|
247 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php'; |
|
248 | - $this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/'; |
|
249 | - $this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action' => 'confirm_migration_crash_report_sent', |
|
250 | - 'success' => '0', |
|
251 | - ), EE_MAINTENANCE_ADMIN_URL); |
|
252 | - } elseif ($addons_should_be_upgraded_first) { |
|
253 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php'; |
|
254 | - } else { |
|
255 | - if ($most_recent_migration |
|
256 | - && $most_recent_migration instanceof EE_Data_Migration_Script_Base |
|
257 | - && $most_recent_migration->can_continue() |
|
258 | - ) { |
|
259 | - $show_backup_db_text = false; |
|
260 | - $show_continue_current_migration_script = true; |
|
261 | - $show_most_recent_migration = true; |
|
262 | - } elseif (isset($this->_req_data['continue_migration'])) { |
|
263 | - $show_most_recent_migration = true; |
|
264 | - $show_continue_current_migration_script = false; |
|
265 | - } else { |
|
266 | - $show_most_recent_migration = false; |
|
267 | - $show_continue_current_migration_script = false; |
|
268 | - } |
|
269 | - if (isset($current_script)) { |
|
270 | - $migrates_to = $current_script->migrates_to_version(); |
|
271 | - $plugin_slug = $migrates_to['slug']; |
|
272 | - $new_version = $migrates_to['version']; |
|
273 | - $this->_template_args = array_merge($this->_template_args, array( |
|
274 | - 'current_db_state' => sprintf(__("EE%s (%s)", "event_espresso"), |
|
275 | - isset($current_db_state[$plugin_slug]) ? $current_db_state[$plugin_slug] : 3, $plugin_slug), |
|
276 | - 'next_db_state' => isset($current_script) ? sprintf(__("EE%s (%s)", 'event_espresso'), |
|
277 | - $new_version, $plugin_slug) : null, |
|
278 | - )); |
|
279 | - } |
|
280 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php'; |
|
281 | - $this->_template_args = array_merge( |
|
282 | - $this->_template_args, |
|
283 | - array( |
|
284 | - 'show_most_recent_migration' => $show_most_recent_migration, |
|
285 | - //flag for showing the most recent migration's status and/or errors |
|
286 | - 'show_migration_progress' => $show_migration_progress, |
|
287 | - //flag for showing the option to run migrations and see their progress |
|
288 | - 'show_backup_db_text' => $show_backup_db_text, |
|
289 | - //flag for showing text telling the user to backup their DB |
|
290 | - 'show_maintenance_switch' => $show_maintenance_switch, |
|
291 | - //flag for showing the option to change maintenance mode between levels 0 and 1 |
|
292 | - 'script_names' => $script_names, |
|
293 | - //array of names of scripts that have run |
|
294 | - 'show_continue_current_migration_script' => $show_continue_current_migration_script, |
|
295 | - //flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0 |
|
296 | - 'reset_db_page_link' => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'), |
|
297 | - EE_MAINTENANCE_ADMIN_URL), |
|
298 | - 'data_reset_page' => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'), |
|
299 | - EE_MAINTENANCE_ADMIN_URL), |
|
300 | - 'update_migration_script_page_link' => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'change_maintenance_level'), |
|
301 | - EE_MAINTENANCE_ADMIN_URL), |
|
302 | - 'ultimate_db_state' => sprintf(__("EE%s", 'event_espresso'), |
|
303 | - espresso_version()), |
|
304 | - ) |
|
305 | - ); |
|
306 | - //make sure we have the form fields helper available. It usually is, but sometimes it isn't |
|
307 | - //localize script stuff |
|
308 | - wp_localize_script('ee-maintenance', 'ee_maintenance', array( |
|
309 | - 'migrating' => esc_html__("Updating Database...", "event_espresso"), |
|
310 | - 'next' => esc_html__("Next", "event_espresso"), |
|
311 | - 'fatal_error' => esc_html__("A Fatal Error Has Occurred", "event_espresso"), |
|
312 | - 'click_next_when_ready' => esc_html__("The current Database Update has ended. Click 'next' when ready to proceed", |
|
313 | - "event_espresso"), |
|
314 | - 'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts, |
|
315 | - 'status_fatal_error' => EE_Data_Migration_Manager::status_fatal_error, |
|
316 | - 'status_completed' => EE_Data_Migration_Manager::status_completed, |
|
317 | - )); |
|
318 | - } |
|
319 | - $this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration |
|
320 | - //now render the migration options part, and put it in a variable |
|
321 | - $migration_options_template_file = apply_filters( |
|
322 | - 'FHEE__ee_migration_page__migration_options_template', |
|
323 | - EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php' |
|
324 | - ); |
|
325 | - $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true); |
|
326 | - $this->_template_args['migration_options_html'] = $migration_options_html; |
|
327 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
328 | - $this->_template_args, true); |
|
329 | - $this->display_admin_page_with_sidebar(); |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - |
|
334 | - /** |
|
335 | - * returns JSON and executes another step of the currently-executing data migration (called via ajax) |
|
336 | - */ |
|
337 | - public function migration_step() |
|
338 | - { |
|
339 | - $this->_template_args['data'] = EE_Data_Migration_Manager::instance()->response_to_migration_ajax_request(); |
|
340 | - $this->_return_json(); |
|
341 | - } |
|
342 | - |
|
343 | - |
|
344 | - |
|
345 | - /** |
|
346 | - * Can be used by js when it notices a response with HTML in it in order |
|
347 | - * to log the malformed response |
|
348 | - */ |
|
349 | - public function add_error_to_migrations_ran() |
|
350 | - { |
|
351 | - EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($this->_req_data['message']); |
|
352 | - $this->_template_args['data'] = array('ok' => true); |
|
353 | - $this->_return_json(); |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - |
|
358 | - /** |
|
359 | - * changes the maintenance level, provided there are still no migration scripts that should run |
|
360 | - */ |
|
361 | - public function _change_maintenance_level() |
|
362 | - { |
|
363 | - $new_level = absint($this->_req_data['maintenance_mode_level']); |
|
364 | - if ( ! EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) { |
|
365 | - EE_Maintenance_Mode::instance()->set_maintenance_level($new_level); |
|
366 | - $success = true; |
|
367 | - } else { |
|
368 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
369 | - $success = false; |
|
370 | - } |
|
371 | - $this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso")); |
|
372 | - } |
|
373 | - |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * a tab with options for resetting and/or deleting EE data |
|
378 | - * |
|
379 | - * @throws \EE_Error |
|
380 | - * @throws \DomainException |
|
381 | - */ |
|
382 | - public function _data_reset_and_delete() |
|
383 | - { |
|
384 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php'; |
|
385 | - $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button( |
|
386 | - 'reset_reservations', |
|
387 | - 'reset_reservations', |
|
388 | - array(), |
|
389 | - 'button button-primary', |
|
390 | - '', |
|
391 | - false |
|
392 | - ); |
|
393 | - $this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button( |
|
394 | - 'reset_capabilities', |
|
395 | - 'reset_capabilities', |
|
396 | - array(), |
|
397 | - 'button button-primary', |
|
398 | - '', |
|
399 | - false |
|
400 | - ); |
|
401 | - $this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
402 | - array('action' => 'delete_db'), |
|
403 | - EE_MAINTENANCE_ADMIN_URL |
|
404 | - ); |
|
405 | - $this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
406 | - array('action' => 'reset_db'), |
|
407 | - EE_MAINTENANCE_ADMIN_URL |
|
408 | - ); |
|
409 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
410 | - $this->_template_path, |
|
411 | - $this->_template_args, |
|
412 | - true |
|
413 | - ); |
|
414 | - $this->display_admin_page_with_sidebar(); |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - |
|
419 | - protected function _reset_reservations() |
|
420 | - { |
|
421 | - if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) { |
|
422 | - EE_Error::add_success( |
|
423 | - __( |
|
424 | - 'Ticket and datetime reserved counts have been successfully reset.', |
|
425 | - 'event_espresso' |
|
426 | - ) |
|
427 | - ); |
|
428 | - } else { |
|
429 | - EE_Error::add_success( |
|
430 | - __( |
|
431 | - 'Ticket and datetime reserved counts were correct and did not need resetting.', |
|
432 | - 'event_espresso' |
|
433 | - ) |
|
434 | - ); |
|
435 | - } |
|
436 | - $this->_redirect_after_action(true, '', '', array('action' => 'data_reset'), true); |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - |
|
441 | - protected function _reset_capabilities() |
|
442 | - { |
|
443 | - EE_Registry::instance()->CAP->init_caps(true); |
|
444 | - EE_Error::add_success(__('Default Event Espresso capabilities have been restored for all current roles.', |
|
445 | - 'event_espresso')); |
|
446 | - $this->_redirect_after_action(false, '', '', array('action' => 'data_reset'), true); |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * resets the DMSs so we can attempt to continue migrating after a fatal error |
|
453 | - * (only a good idea when someone has somehow tried ot fix whatever caused |
|
454 | - * the fatal error in teh first place) |
|
455 | - */ |
|
456 | - protected function _reattempt_migration() |
|
457 | - { |
|
458 | - EE_Data_Migration_Manager::instance()->reattempt(); |
|
459 | - $this->_redirect_after_action(false, '', '', array('action' => 'default'), true); |
|
460 | - } |
|
461 | - |
|
462 | - |
|
463 | - |
|
464 | - /** |
|
465 | - * shows the big ol' System Information page |
|
466 | - */ |
|
467 | - public function _system_status() |
|
468 | - { |
|
469 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php'; |
|
470 | - $this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati(); |
|
471 | - $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
472 | - array( |
|
473 | - 'action' => 'download_system_status', |
|
474 | - ), |
|
475 | - EE_MAINTENANCE_ADMIN_URL |
|
476 | - ); |
|
477 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
478 | - $this->_template_args, true); |
|
479 | - $this->display_admin_page_with_sidebar(); |
|
480 | - } |
|
481 | - |
|
482 | - /** |
|
483 | - * Downloads an HTML file of the system status that can be easily stored or emailed |
|
484 | - */ |
|
485 | - public function _download_system_status() |
|
486 | - { |
|
487 | - $status_info = EEM_System_Status::instance()->get_system_stati(); |
|
488 | - header( 'Content-Disposition: attachment' ); |
|
489 | - header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" ); |
|
490 | - echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>"; |
|
491 | - echo "<h1>System Information for " . site_url() . "</h1>"; |
|
492 | - echo EEH_Template::layout_array_as_table( $status_info ); |
|
493 | - die; |
|
494 | - } |
|
495 | - |
|
496 | - |
|
497 | - |
|
498 | - public function _send_migration_crash_report() |
|
499 | - { |
|
500 | - $from = $this->_req_data['from']; |
|
501 | - $from_name = $this->_req_data['from_name']; |
|
502 | - $body = $this->_req_data['body']; |
|
503 | - try { |
|
504 | - $success = wp_mail(EE_SUPPORT_EMAIL, |
|
505 | - 'Migration Crash Report', |
|
506 | - $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true), |
|
507 | - array( |
|
508 | - "from:$from_name<$from>", |
|
509 | - // 'content-type:text/html charset=UTF-8' |
|
510 | - )); |
|
511 | - } catch (Exception $e) { |
|
512 | - $success = false; |
|
513 | - } |
|
514 | - $this->_redirect_after_action($success, esc_html__("Migration Crash Report", "event_espresso"), |
|
515 | - esc_html__("sent", "event_espresso"), |
|
516 | - array('success' => $success, 'action' => 'confirm_migration_crash_report_sent')); |
|
517 | - } |
|
518 | - |
|
519 | - |
|
520 | - |
|
521 | - public function _confirm_migration_crash_report_sent() |
|
522 | - { |
|
523 | - try { |
|
524 | - $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true); |
|
525 | - } catch (EE_Error $e) { |
|
526 | - EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage()); |
|
527 | - //now, just so we can display the page correctly, make a error migration script stage object |
|
528 | - //and also put the error on it. It only persists for the duration of this request |
|
529 | - $most_recent_migration = new EE_DMS_Unknown_1_0_0(); |
|
530 | - $most_recent_migration->add_error($e->getMessage()); |
|
531 | - } |
|
532 | - $success = $this->_req_data['success'] == '1' ? true : false; |
|
533 | - $this->_template_args['success'] = $success; |
|
534 | - $this->_template_args['most_recent_migration'] = $most_recent_migration; |
|
535 | - $this->_template_args['reset_db_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'), |
|
536 | - EE_MAINTENANCE_ADMIN_URL); |
|
537 | - $this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'), |
|
538 | - EE_MAINTENANCE_ADMIN_URL); |
|
539 | - $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'), |
|
540 | - EE_MAINTENANCE_ADMIN_URL); |
|
541 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php'; |
|
542 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
543 | - $this->_template_args, true); |
|
544 | - $this->display_admin_page_with_sidebar(); |
|
545 | - } |
|
546 | - |
|
547 | - |
|
548 | - |
|
549 | - /** |
|
550 | - * Resets the entire EE4 database. |
|
551 | - * Currently basically only sets up ee4 database for a fresh install- doesn't |
|
552 | - * actually clean out the old wp options, or cpts (although does erase old ee table data) |
|
553 | - * |
|
554 | - * @param boolean $nuke_old_ee4_data controls whether or not we |
|
555 | - * destroy the old ee4 data, or just try initializing ee4 default data |
|
556 | - */ |
|
557 | - public function _reset_db($nuke_old_ee4_data = true) |
|
558 | - { |
|
559 | - EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
560 | - if ($nuke_old_ee4_data) { |
|
561 | - EEH_Activation::delete_all_espresso_cpt_data(); |
|
562 | - EEH_Activation::delete_all_espresso_tables_and_data(false); |
|
563 | - EEH_Activation::remove_cron_tasks(); |
|
564 | - } |
|
565 | - //make sure when we reset the registry's config that it |
|
566 | - //switches to using the new singleton |
|
567 | - EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true); |
|
568 | - EE_System::instance()->initialize_db_if_no_migrations_required(true); |
|
569 | - EE_System::instance()->redirect_to_about_ee(); |
|
570 | - } |
|
571 | - |
|
572 | - |
|
573 | - |
|
574 | - /** |
|
575 | - * Deletes ALL EE tables, Records, and Options from the database. |
|
576 | - */ |
|
577 | - public function _delete_db() |
|
578 | - { |
|
579 | - EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
580 | - EEH_Activation::delete_all_espresso_cpt_data(); |
|
581 | - EEH_Activation::delete_all_espresso_tables_and_data(); |
|
582 | - EEH_Activation::remove_cron_tasks(); |
|
583 | - EEH_Activation::deactivate_event_espresso(); |
|
584 | - wp_safe_redirect(admin_url('plugins.php')); |
|
585 | - exit; |
|
586 | - } |
|
587 | - |
|
588 | - |
|
589 | - |
|
590 | - /** |
|
591 | - * sets up EE4 to rerun the migrations from ee3 to ee4 |
|
592 | - */ |
|
593 | - public function _rerun_migration_from_ee3() |
|
594 | - { |
|
595 | - EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
596 | - EEH_Activation::delete_all_espresso_cpt_data(); |
|
597 | - EEH_Activation::delete_all_espresso_tables_and_data(false); |
|
598 | - //set the db state to something that will require migrations |
|
599 | - update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0'); |
|
600 | - EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance); |
|
601 | - $this->_redirect_after_action(true, esc_html__("Database", 'event_espresso'), esc_html__("reset", 'event_espresso')); |
|
602 | - } |
|
603 | - |
|
604 | - |
|
605 | - |
|
606 | - //none of the below group are currently used for Gateway Settings |
|
607 | - protected function _add_screen_options() |
|
608 | - { |
|
609 | - } |
|
610 | - |
|
611 | - |
|
612 | - |
|
613 | - protected function _add_feature_pointers() |
|
614 | - { |
|
615 | - } |
|
616 | - |
|
31 | + public function __construct($routing = true) |
|
32 | + { |
|
33 | + parent::__construct($routing); |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + |
|
38 | + protected function _init_page_props() |
|
39 | + { |
|
40 | + $this->page_slug = EE_MAINTENANCE_PG_SLUG; |
|
41 | + $this->page_label = EE_MAINTENANCE_LABEL; |
|
42 | + $this->_admin_base_url = EE_MAINTENANCE_ADMIN_URL; |
|
43 | + $this->_admin_base_path = EE_MAINTENANCE_ADMIN; |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + |
|
48 | + protected function _ajax_hooks() |
|
49 | + { |
|
50 | + add_action('wp_ajax_migration_step', array($this, 'migration_step')); |
|
51 | + add_action('wp_ajax_add_error_to_migrations_ran', array($this, 'add_error_to_migrations_ran')); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + protected function _define_page_props() |
|
57 | + { |
|
58 | + $this->_admin_page_title = EE_MAINTENANCE_LABEL; |
|
59 | + $this->_labels = array( |
|
60 | + 'buttons' => array( |
|
61 | + 'reset_reservations' => esc_html__('Reset Ticket and Datetime Reserved Counts', 'event_espresso'), |
|
62 | + 'reset_capabilities' => esc_html__('Reset Event Espresso Capabilities', 'event_espresso'), |
|
63 | + ), |
|
64 | + ); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + |
|
69 | + protected function _set_page_routes() |
|
70 | + { |
|
71 | + $this->_page_routes = array( |
|
72 | + 'default' => array( |
|
73 | + 'func' => '_maintenance', |
|
74 | + 'capability' => 'manage_options', |
|
75 | + ), |
|
76 | + 'change_maintenance_level' => array( |
|
77 | + 'func' => '_change_maintenance_level', |
|
78 | + 'capability' => 'manage_options', |
|
79 | + 'noheader' => true, |
|
80 | + ), |
|
81 | + 'system_status' => array( |
|
82 | + 'func' => '_system_status', |
|
83 | + 'capability' => 'manage_options', |
|
84 | + ), |
|
85 | + 'download_system_status' => array( |
|
86 | + 'func' => '_download_system_status', |
|
87 | + 'capability' => 'manage_options', |
|
88 | + 'noheader' => true, |
|
89 | + ), |
|
90 | + 'send_migration_crash_report' => array( |
|
91 | + 'func' => '_send_migration_crash_report', |
|
92 | + 'capability' => 'manage_options', |
|
93 | + 'noheader' => true, |
|
94 | + ), |
|
95 | + 'confirm_migration_crash_report_sent' => array( |
|
96 | + 'func' => '_confirm_migration_crash_report_sent', |
|
97 | + 'capability' => 'manage_options', |
|
98 | + ), |
|
99 | + 'data_reset' => array( |
|
100 | + 'func' => '_data_reset_and_delete', |
|
101 | + 'capability' => 'manage_options', |
|
102 | + ), |
|
103 | + 'reset_db' => array( |
|
104 | + 'func' => '_reset_db', |
|
105 | + 'capability' => 'manage_options', |
|
106 | + 'noheader' => true, |
|
107 | + 'args' => array('nuke_old_ee4_data' => true), |
|
108 | + ), |
|
109 | + 'start_with_fresh_ee4_db' => array( |
|
110 | + 'func' => '_reset_db', |
|
111 | + 'capability' => 'manage_options', |
|
112 | + 'noheader' => true, |
|
113 | + 'args' => array('nuke_old_ee4_data' => false), |
|
114 | + ), |
|
115 | + 'delete_db' => array( |
|
116 | + 'func' => '_delete_db', |
|
117 | + 'capability' => 'manage_options', |
|
118 | + 'noheader' => true, |
|
119 | + ), |
|
120 | + 'rerun_migration_from_ee3' => array( |
|
121 | + 'func' => '_rerun_migration_from_ee3', |
|
122 | + 'capability' => 'manage_options', |
|
123 | + 'noheader' => true, |
|
124 | + ), |
|
125 | + 'reset_reservations' => array( |
|
126 | + 'func' => '_reset_reservations', |
|
127 | + 'capability' => 'manage_options', |
|
128 | + 'noheader' => true, |
|
129 | + ), |
|
130 | + 'reset_capabilities' => array( |
|
131 | + 'func' => '_reset_capabilities', |
|
132 | + 'capability' => 'manage_options', |
|
133 | + 'noheader' => true, |
|
134 | + ), |
|
135 | + 'reattempt_migration' => array( |
|
136 | + 'func' => '_reattempt_migration', |
|
137 | + 'capability' => 'manage_options', |
|
138 | + 'noheader' => true, |
|
139 | + ), |
|
140 | + ); |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + |
|
145 | + protected function _set_page_config() |
|
146 | + { |
|
147 | + $this->_page_config = array( |
|
148 | + 'default' => array( |
|
149 | + 'nav' => array( |
|
150 | + 'label' => esc_html__('Maintenance', 'event_espresso'), |
|
151 | + 'order' => 10, |
|
152 | + ), |
|
153 | + 'require_nonce' => false, |
|
154 | + ), |
|
155 | + 'data_reset' => array( |
|
156 | + 'nav' => array( |
|
157 | + 'label' => esc_html__('Reset/Delete Data', 'event_espresso'), |
|
158 | + 'order' => 20, |
|
159 | + ), |
|
160 | + 'require_nonce' => false, |
|
161 | + ), |
|
162 | + 'system_status' => array( |
|
163 | + 'nav' => array( |
|
164 | + 'label' => esc_html__("System Information", "event_espresso"), |
|
165 | + 'order' => 30, |
|
166 | + ), |
|
167 | + 'require_nonce' => false, |
|
168 | + ), |
|
169 | + ); |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * default maintenance page. If we're in maintenance mode level 2, then we need to show |
|
176 | + * the migration scripts and all that UI. |
|
177 | + */ |
|
178 | + public function _maintenance() |
|
179 | + { |
|
180 | + //it all depends if we're in maintenance model level 1 (frontend-only) or |
|
181 | + //level 2 (everything except maintenance page) |
|
182 | + try { |
|
183 | + //get the current maintenance level and check if |
|
184 | + //we are removed |
|
185 | + $mm = EE_Maintenance_Mode::instance()->level(); |
|
186 | + $placed_in_mm = EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
187 | + if ($mm == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) { |
|
188 | + //we just took the site out of maintenance mode, so notify the user. |
|
189 | + //unfortunately this message appears to be echoed on the NEXT page load... |
|
190 | + //oh well, we should really be checking for this on addon deactivation anyways |
|
191 | + EE_Error::add_attention(__('Site taken out of maintenance mode because no data migration scripts are required', |
|
192 | + 'event_espresso')); |
|
193 | + $this->_process_notices(array('page' => 'espresso_maintenance_settings'), false); |
|
194 | + } |
|
195 | + //in case an exception is thrown while trying to handle migrations |
|
196 | + switch (EE_Maintenance_Mode::instance()->level()) { |
|
197 | + case EE_Maintenance_Mode::level_0_not_in_maintenance: |
|
198 | + case EE_Maintenance_Mode::level_1_frontend_only_maintenance: |
|
199 | + $show_maintenance_switch = true; |
|
200 | + $show_backup_db_text = false; |
|
201 | + $show_migration_progress = false; |
|
202 | + $script_names = array(); |
|
203 | + $addons_should_be_upgraded_first = false; |
|
204 | + break; |
|
205 | + case EE_Maintenance_Mode::level_2_complete_maintenance: |
|
206 | + $show_maintenance_switch = false; |
|
207 | + $show_migration_progress = true; |
|
208 | + if (isset($this->_req_data['continue_migration'])) { |
|
209 | + $show_backup_db_text = false; |
|
210 | + } else { |
|
211 | + $show_backup_db_text = true; |
|
212 | + } |
|
213 | + $scripts_needing_to_run = EE_Data_Migration_Manager::instance() |
|
214 | + ->check_for_applicable_data_migration_scripts(); |
|
215 | + $addons_should_be_upgraded_first = EE_Data_Migration_Manager::instance()->addons_need_updating(); |
|
216 | + $script_names = array(); |
|
217 | + $current_script = null; |
|
218 | + foreach ($scripts_needing_to_run as $script) { |
|
219 | + if ($script instanceof EE_Data_Migration_Script_Base) { |
|
220 | + if ( ! $current_script) { |
|
221 | + $current_script = $script; |
|
222 | + $current_script->migration_page_hooks(); |
|
223 | + } |
|
224 | + $script_names[] = $script->pretty_name(); |
|
225 | + } |
|
226 | + } |
|
227 | + break; |
|
228 | + } |
|
229 | + $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true); |
|
230 | + $exception_thrown = false; |
|
231 | + } catch (EE_Error $e) { |
|
232 | + EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage()); |
|
233 | + //now, just so we can display the page correctly, make a error migration script stage object |
|
234 | + //and also put the error on it. It only persists for the duration of this request |
|
235 | + $most_recent_migration = new EE_DMS_Unknown_1_0_0(); |
|
236 | + $most_recent_migration->add_error($e->getMessage()); |
|
237 | + $exception_thrown = true; |
|
238 | + } |
|
239 | + $current_db_state = EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set(); |
|
240 | + $current_db_state = str_replace('.decaf', '', $current_db_state); |
|
241 | + if ($exception_thrown |
|
242 | + || ($most_recent_migration |
|
243 | + && $most_recent_migration instanceof EE_Data_Migration_Script_Base |
|
244 | + && $most_recent_migration->is_broken() |
|
245 | + ) |
|
246 | + ) { |
|
247 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php'; |
|
248 | + $this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/'; |
|
249 | + $this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action' => 'confirm_migration_crash_report_sent', |
|
250 | + 'success' => '0', |
|
251 | + ), EE_MAINTENANCE_ADMIN_URL); |
|
252 | + } elseif ($addons_should_be_upgraded_first) { |
|
253 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php'; |
|
254 | + } else { |
|
255 | + if ($most_recent_migration |
|
256 | + && $most_recent_migration instanceof EE_Data_Migration_Script_Base |
|
257 | + && $most_recent_migration->can_continue() |
|
258 | + ) { |
|
259 | + $show_backup_db_text = false; |
|
260 | + $show_continue_current_migration_script = true; |
|
261 | + $show_most_recent_migration = true; |
|
262 | + } elseif (isset($this->_req_data['continue_migration'])) { |
|
263 | + $show_most_recent_migration = true; |
|
264 | + $show_continue_current_migration_script = false; |
|
265 | + } else { |
|
266 | + $show_most_recent_migration = false; |
|
267 | + $show_continue_current_migration_script = false; |
|
268 | + } |
|
269 | + if (isset($current_script)) { |
|
270 | + $migrates_to = $current_script->migrates_to_version(); |
|
271 | + $plugin_slug = $migrates_to['slug']; |
|
272 | + $new_version = $migrates_to['version']; |
|
273 | + $this->_template_args = array_merge($this->_template_args, array( |
|
274 | + 'current_db_state' => sprintf(__("EE%s (%s)", "event_espresso"), |
|
275 | + isset($current_db_state[$plugin_slug]) ? $current_db_state[$plugin_slug] : 3, $plugin_slug), |
|
276 | + 'next_db_state' => isset($current_script) ? sprintf(__("EE%s (%s)", 'event_espresso'), |
|
277 | + $new_version, $plugin_slug) : null, |
|
278 | + )); |
|
279 | + } |
|
280 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php'; |
|
281 | + $this->_template_args = array_merge( |
|
282 | + $this->_template_args, |
|
283 | + array( |
|
284 | + 'show_most_recent_migration' => $show_most_recent_migration, |
|
285 | + //flag for showing the most recent migration's status and/or errors |
|
286 | + 'show_migration_progress' => $show_migration_progress, |
|
287 | + //flag for showing the option to run migrations and see their progress |
|
288 | + 'show_backup_db_text' => $show_backup_db_text, |
|
289 | + //flag for showing text telling the user to backup their DB |
|
290 | + 'show_maintenance_switch' => $show_maintenance_switch, |
|
291 | + //flag for showing the option to change maintenance mode between levels 0 and 1 |
|
292 | + 'script_names' => $script_names, |
|
293 | + //array of names of scripts that have run |
|
294 | + 'show_continue_current_migration_script' => $show_continue_current_migration_script, |
|
295 | + //flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0 |
|
296 | + 'reset_db_page_link' => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'), |
|
297 | + EE_MAINTENANCE_ADMIN_URL), |
|
298 | + 'data_reset_page' => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'), |
|
299 | + EE_MAINTENANCE_ADMIN_URL), |
|
300 | + 'update_migration_script_page_link' => EE_Admin_Page::add_query_args_and_nonce(array('action' => 'change_maintenance_level'), |
|
301 | + EE_MAINTENANCE_ADMIN_URL), |
|
302 | + 'ultimate_db_state' => sprintf(__("EE%s", 'event_espresso'), |
|
303 | + espresso_version()), |
|
304 | + ) |
|
305 | + ); |
|
306 | + //make sure we have the form fields helper available. It usually is, but sometimes it isn't |
|
307 | + //localize script stuff |
|
308 | + wp_localize_script('ee-maintenance', 'ee_maintenance', array( |
|
309 | + 'migrating' => esc_html__("Updating Database...", "event_espresso"), |
|
310 | + 'next' => esc_html__("Next", "event_espresso"), |
|
311 | + 'fatal_error' => esc_html__("A Fatal Error Has Occurred", "event_espresso"), |
|
312 | + 'click_next_when_ready' => esc_html__("The current Database Update has ended. Click 'next' when ready to proceed", |
|
313 | + "event_espresso"), |
|
314 | + 'status_no_more_migration_scripts' => EE_Data_Migration_Manager::status_no_more_migration_scripts, |
|
315 | + 'status_fatal_error' => EE_Data_Migration_Manager::status_fatal_error, |
|
316 | + 'status_completed' => EE_Data_Migration_Manager::status_completed, |
|
317 | + )); |
|
318 | + } |
|
319 | + $this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration |
|
320 | + //now render the migration options part, and put it in a variable |
|
321 | + $migration_options_template_file = apply_filters( |
|
322 | + 'FHEE__ee_migration_page__migration_options_template', |
|
323 | + EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php' |
|
324 | + ); |
|
325 | + $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true); |
|
326 | + $this->_template_args['migration_options_html'] = $migration_options_html; |
|
327 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
328 | + $this->_template_args, true); |
|
329 | + $this->display_admin_page_with_sidebar(); |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + |
|
334 | + /** |
|
335 | + * returns JSON and executes another step of the currently-executing data migration (called via ajax) |
|
336 | + */ |
|
337 | + public function migration_step() |
|
338 | + { |
|
339 | + $this->_template_args['data'] = EE_Data_Migration_Manager::instance()->response_to_migration_ajax_request(); |
|
340 | + $this->_return_json(); |
|
341 | + } |
|
342 | + |
|
343 | + |
|
344 | + |
|
345 | + /** |
|
346 | + * Can be used by js when it notices a response with HTML in it in order |
|
347 | + * to log the malformed response |
|
348 | + */ |
|
349 | + public function add_error_to_migrations_ran() |
|
350 | + { |
|
351 | + EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($this->_req_data['message']); |
|
352 | + $this->_template_args['data'] = array('ok' => true); |
|
353 | + $this->_return_json(); |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + |
|
358 | + /** |
|
359 | + * changes the maintenance level, provided there are still no migration scripts that should run |
|
360 | + */ |
|
361 | + public function _change_maintenance_level() |
|
362 | + { |
|
363 | + $new_level = absint($this->_req_data['maintenance_mode_level']); |
|
364 | + if ( ! EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) { |
|
365 | + EE_Maintenance_Mode::instance()->set_maintenance_level($new_level); |
|
366 | + $success = true; |
|
367 | + } else { |
|
368 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
369 | + $success = false; |
|
370 | + } |
|
371 | + $this->_redirect_after_action($success, 'Maintenance Mode', esc_html__("Updated", "event_espresso")); |
|
372 | + } |
|
373 | + |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * a tab with options for resetting and/or deleting EE data |
|
378 | + * |
|
379 | + * @throws \EE_Error |
|
380 | + * @throws \DomainException |
|
381 | + */ |
|
382 | + public function _data_reset_and_delete() |
|
383 | + { |
|
384 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php'; |
|
385 | + $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button( |
|
386 | + 'reset_reservations', |
|
387 | + 'reset_reservations', |
|
388 | + array(), |
|
389 | + 'button button-primary', |
|
390 | + '', |
|
391 | + false |
|
392 | + ); |
|
393 | + $this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button( |
|
394 | + 'reset_capabilities', |
|
395 | + 'reset_capabilities', |
|
396 | + array(), |
|
397 | + 'button button-primary', |
|
398 | + '', |
|
399 | + false |
|
400 | + ); |
|
401 | + $this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
402 | + array('action' => 'delete_db'), |
|
403 | + EE_MAINTENANCE_ADMIN_URL |
|
404 | + ); |
|
405 | + $this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
406 | + array('action' => 'reset_db'), |
|
407 | + EE_MAINTENANCE_ADMIN_URL |
|
408 | + ); |
|
409 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
410 | + $this->_template_path, |
|
411 | + $this->_template_args, |
|
412 | + true |
|
413 | + ); |
|
414 | + $this->display_admin_page_with_sidebar(); |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + |
|
419 | + protected function _reset_reservations() |
|
420 | + { |
|
421 | + if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) { |
|
422 | + EE_Error::add_success( |
|
423 | + __( |
|
424 | + 'Ticket and datetime reserved counts have been successfully reset.', |
|
425 | + 'event_espresso' |
|
426 | + ) |
|
427 | + ); |
|
428 | + } else { |
|
429 | + EE_Error::add_success( |
|
430 | + __( |
|
431 | + 'Ticket and datetime reserved counts were correct and did not need resetting.', |
|
432 | + 'event_espresso' |
|
433 | + ) |
|
434 | + ); |
|
435 | + } |
|
436 | + $this->_redirect_after_action(true, '', '', array('action' => 'data_reset'), true); |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + |
|
441 | + protected function _reset_capabilities() |
|
442 | + { |
|
443 | + EE_Registry::instance()->CAP->init_caps(true); |
|
444 | + EE_Error::add_success(__('Default Event Espresso capabilities have been restored for all current roles.', |
|
445 | + 'event_espresso')); |
|
446 | + $this->_redirect_after_action(false, '', '', array('action' => 'data_reset'), true); |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * resets the DMSs so we can attempt to continue migrating after a fatal error |
|
453 | + * (only a good idea when someone has somehow tried ot fix whatever caused |
|
454 | + * the fatal error in teh first place) |
|
455 | + */ |
|
456 | + protected function _reattempt_migration() |
|
457 | + { |
|
458 | + EE_Data_Migration_Manager::instance()->reattempt(); |
|
459 | + $this->_redirect_after_action(false, '', '', array('action' => 'default'), true); |
|
460 | + } |
|
461 | + |
|
462 | + |
|
463 | + |
|
464 | + /** |
|
465 | + * shows the big ol' System Information page |
|
466 | + */ |
|
467 | + public function _system_status() |
|
468 | + { |
|
469 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php'; |
|
470 | + $this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati(); |
|
471 | + $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
472 | + array( |
|
473 | + 'action' => 'download_system_status', |
|
474 | + ), |
|
475 | + EE_MAINTENANCE_ADMIN_URL |
|
476 | + ); |
|
477 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
478 | + $this->_template_args, true); |
|
479 | + $this->display_admin_page_with_sidebar(); |
|
480 | + } |
|
481 | + |
|
482 | + /** |
|
483 | + * Downloads an HTML file of the system status that can be easily stored or emailed |
|
484 | + */ |
|
485 | + public function _download_system_status() |
|
486 | + { |
|
487 | + $status_info = EEM_System_Status::instance()->get_system_stati(); |
|
488 | + header( 'Content-Disposition: attachment' ); |
|
489 | + header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" ); |
|
490 | + echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>"; |
|
491 | + echo "<h1>System Information for " . site_url() . "</h1>"; |
|
492 | + echo EEH_Template::layout_array_as_table( $status_info ); |
|
493 | + die; |
|
494 | + } |
|
495 | + |
|
496 | + |
|
497 | + |
|
498 | + public function _send_migration_crash_report() |
|
499 | + { |
|
500 | + $from = $this->_req_data['from']; |
|
501 | + $from_name = $this->_req_data['from_name']; |
|
502 | + $body = $this->_req_data['body']; |
|
503 | + try { |
|
504 | + $success = wp_mail(EE_SUPPORT_EMAIL, |
|
505 | + 'Migration Crash Report', |
|
506 | + $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true), |
|
507 | + array( |
|
508 | + "from:$from_name<$from>", |
|
509 | + // 'content-type:text/html charset=UTF-8' |
|
510 | + )); |
|
511 | + } catch (Exception $e) { |
|
512 | + $success = false; |
|
513 | + } |
|
514 | + $this->_redirect_after_action($success, esc_html__("Migration Crash Report", "event_espresso"), |
|
515 | + esc_html__("sent", "event_espresso"), |
|
516 | + array('success' => $success, 'action' => 'confirm_migration_crash_report_sent')); |
|
517 | + } |
|
518 | + |
|
519 | + |
|
520 | + |
|
521 | + public function _confirm_migration_crash_report_sent() |
|
522 | + { |
|
523 | + try { |
|
524 | + $most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true); |
|
525 | + } catch (EE_Error $e) { |
|
526 | + EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage()); |
|
527 | + //now, just so we can display the page correctly, make a error migration script stage object |
|
528 | + //and also put the error on it. It only persists for the duration of this request |
|
529 | + $most_recent_migration = new EE_DMS_Unknown_1_0_0(); |
|
530 | + $most_recent_migration->add_error($e->getMessage()); |
|
531 | + } |
|
532 | + $success = $this->_req_data['success'] == '1' ? true : false; |
|
533 | + $this->_template_args['success'] = $success; |
|
534 | + $this->_template_args['most_recent_migration'] = $most_recent_migration; |
|
535 | + $this->_template_args['reset_db_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reset_db'), |
|
536 | + EE_MAINTENANCE_ADMIN_URL); |
|
537 | + $this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'data_reset'), |
|
538 | + EE_MAINTENANCE_ADMIN_URL); |
|
539 | + $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'), |
|
540 | + EE_MAINTENANCE_ADMIN_URL); |
|
541 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php'; |
|
542 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
|
543 | + $this->_template_args, true); |
|
544 | + $this->display_admin_page_with_sidebar(); |
|
545 | + } |
|
546 | + |
|
547 | + |
|
548 | + |
|
549 | + /** |
|
550 | + * Resets the entire EE4 database. |
|
551 | + * Currently basically only sets up ee4 database for a fresh install- doesn't |
|
552 | + * actually clean out the old wp options, or cpts (although does erase old ee table data) |
|
553 | + * |
|
554 | + * @param boolean $nuke_old_ee4_data controls whether or not we |
|
555 | + * destroy the old ee4 data, or just try initializing ee4 default data |
|
556 | + */ |
|
557 | + public function _reset_db($nuke_old_ee4_data = true) |
|
558 | + { |
|
559 | + EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
560 | + if ($nuke_old_ee4_data) { |
|
561 | + EEH_Activation::delete_all_espresso_cpt_data(); |
|
562 | + EEH_Activation::delete_all_espresso_tables_and_data(false); |
|
563 | + EEH_Activation::remove_cron_tasks(); |
|
564 | + } |
|
565 | + //make sure when we reset the registry's config that it |
|
566 | + //switches to using the new singleton |
|
567 | + EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(true); |
|
568 | + EE_System::instance()->initialize_db_if_no_migrations_required(true); |
|
569 | + EE_System::instance()->redirect_to_about_ee(); |
|
570 | + } |
|
571 | + |
|
572 | + |
|
573 | + |
|
574 | + /** |
|
575 | + * Deletes ALL EE tables, Records, and Options from the database. |
|
576 | + */ |
|
577 | + public function _delete_db() |
|
578 | + { |
|
579 | + EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
580 | + EEH_Activation::delete_all_espresso_cpt_data(); |
|
581 | + EEH_Activation::delete_all_espresso_tables_and_data(); |
|
582 | + EEH_Activation::remove_cron_tasks(); |
|
583 | + EEH_Activation::deactivate_event_espresso(); |
|
584 | + wp_safe_redirect(admin_url('plugins.php')); |
|
585 | + exit; |
|
586 | + } |
|
587 | + |
|
588 | + |
|
589 | + |
|
590 | + /** |
|
591 | + * sets up EE4 to rerun the migrations from ee3 to ee4 |
|
592 | + */ |
|
593 | + public function _rerun_migration_from_ee3() |
|
594 | + { |
|
595 | + EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
596 | + EEH_Activation::delete_all_espresso_cpt_data(); |
|
597 | + EEH_Activation::delete_all_espresso_tables_and_data(false); |
|
598 | + //set the db state to something that will require migrations |
|
599 | + update_option(EE_Data_Migration_Manager::current_database_state, '3.1.36.0'); |
|
600 | + EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_2_complete_maintenance); |
|
601 | + $this->_redirect_after_action(true, esc_html__("Database", 'event_espresso'), esc_html__("reset", 'event_espresso')); |
|
602 | + } |
|
603 | + |
|
604 | + |
|
605 | + |
|
606 | + //none of the below group are currently used for Gateway Settings |
|
607 | + protected function _add_screen_options() |
|
608 | + { |
|
609 | + } |
|
610 | + |
|
611 | + |
|
612 | + |
|
613 | + protected function _add_feature_pointers() |
|
614 | + { |
|
615 | + } |
|
616 | + |
|
617 | 617 | |
618 | 618 | |
619 | - public function admin_init() |
|
620 | - { |
|
621 | - } |
|
622 | - |
|
623 | - |
|
624 | - |
|
625 | - public function admin_notices() |
|
626 | - { |
|
627 | - } |
|
628 | - |
|
619 | + public function admin_init() |
|
620 | + { |
|
621 | + } |
|
622 | + |
|
623 | + |
|
624 | + |
|
625 | + public function admin_notices() |
|
626 | + { |
|
627 | + } |
|
628 | + |
|
629 | 629 | |
630 | 630 | |
631 | - public function admin_footer_scripts() |
|
632 | - { |
|
633 | - } |
|
631 | + public function admin_footer_scripts() |
|
632 | + { |
|
633 | + } |
|
634 | 634 | |
635 | 635 | |
636 | 636 | |
637 | - public function load_scripts_styles() |
|
638 | - { |
|
639 | - wp_enqueue_script('ee_admin_js'); |
|
637 | + public function load_scripts_styles() |
|
638 | + { |
|
639 | + wp_enqueue_script('ee_admin_js'); |
|
640 | 640 | // wp_enqueue_media(); |
641 | 641 | // wp_enqueue_script('media-upload'); |
642 | - wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . '/ee-maintenance.js', array('jquery'), |
|
643 | - EVENT_ESPRESSO_VERSION, true); |
|
644 | - wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(), |
|
645 | - EVENT_ESPRESSO_VERSION); |
|
646 | - wp_enqueue_style('espresso_maintenance'); |
|
647 | - } |
|
642 | + wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . '/ee-maintenance.js', array('jquery'), |
|
643 | + EVENT_ESPRESSO_VERSION, true); |
|
644 | + wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(), |
|
645 | + EVENT_ESPRESSO_VERSION); |
|
646 | + wp_enqueue_style('espresso_maintenance'); |
|
647 | + } |
|
648 | 648 | |
649 | 649 | |
650 | 650 | |
651 | - public function load_scripts_styles_default() |
|
652 | - { |
|
653 | - //styles |
|
651 | + public function load_scripts_styles_default() |
|
652 | + { |
|
653 | + //styles |
|
654 | 654 | // wp_enqueue_style('ee-text-links'); |
655 | 655 | // //scripts |
656 | 656 | // wp_enqueue_script('ee-text-links'); |
657 | - } |
|
657 | + } |
|
658 | 658 | |
659 | 659 | |
660 | 660 |
@@ -244,13 +244,13 @@ discard block |
||
244 | 244 | && $most_recent_migration->is_broken() |
245 | 245 | ) |
246 | 246 | ) { |
247 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php'; |
|
247 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_migration_was_borked_page.template.php'; |
|
248 | 248 | $this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/'; |
249 | 249 | $this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action' => 'confirm_migration_crash_report_sent', |
250 | 250 | 'success' => '0', |
251 | 251 | ), EE_MAINTENANCE_ADMIN_URL); |
252 | 252 | } elseif ($addons_should_be_upgraded_first) { |
253 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php'; |
|
253 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_upgrade_addons_before_migrating.template.php'; |
|
254 | 254 | } else { |
255 | 255 | if ($most_recent_migration |
256 | 256 | && $most_recent_migration instanceof EE_Data_Migration_Script_Base |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | $new_version, $plugin_slug) : null, |
278 | 278 | )); |
279 | 279 | } |
280 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php'; |
|
280 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_migration_page.template.php'; |
|
281 | 281 | $this->_template_args = array_merge( |
282 | 282 | $this->_template_args, |
283 | 283 | array( |
@@ -316,13 +316,13 @@ discard block |
||
316 | 316 | 'status_completed' => EE_Data_Migration_Manager::status_completed, |
317 | 317 | )); |
318 | 318 | } |
319 | - $this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration |
|
319 | + $this->_template_args['most_recent_migration'] = $most_recent_migration; //the actual most recently ran migration |
|
320 | 320 | //now render the migration options part, and put it in a variable |
321 | 321 | $migration_options_template_file = apply_filters( |
322 | 322 | 'FHEE__ee_migration_page__migration_options_template', |
323 | - EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee4.template.php' |
|
323 | + EE_MAINTENANCE_TEMPLATE_PATH.'migration_options_from_ee4.template.php' |
|
324 | 324 | ); |
325 | - $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args,true); |
|
325 | + $migration_options_html = EEH_Template::display_template($migration_options_template_file, $this->_template_args, true); |
|
326 | 326 | $this->_template_args['migration_options_html'] = $migration_options_html; |
327 | 327 | $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
328 | 328 | $this->_template_args, true); |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | */ |
382 | 382 | public function _data_reset_and_delete() |
383 | 383 | { |
384 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php'; |
|
384 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_data_reset_and_delete.template.php'; |
|
385 | 385 | $this->_template_args['reset_reservations_button'] = $this->get_action_link_or_button( |
386 | 386 | 'reset_reservations', |
387 | 387 | 'reset_reservations', |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | |
419 | 419 | protected function _reset_reservations() |
420 | 420 | { |
421 | - if(\EED_Ticket_Sales_Monitor::reset_reservation_counts()) { |
|
421 | + if (\EED_Ticket_Sales_Monitor::reset_reservation_counts()) { |
|
422 | 422 | EE_Error::add_success( |
423 | 423 | __( |
424 | 424 | 'Ticket and datetime reserved counts have been successfully reset.', |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | */ |
467 | 467 | public function _system_status() |
468 | 468 | { |
469 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php'; |
|
469 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_system_stati_page.template.php'; |
|
470 | 470 | $this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati(); |
471 | 471 | $this->_template_args['download_system_status_url'] = EE_Admin_Page::add_query_args_and_nonce( |
472 | 472 | array( |
@@ -485,11 +485,11 @@ discard block |
||
485 | 485 | public function _download_system_status() |
486 | 486 | { |
487 | 487 | $status_info = EEM_System_Status::instance()->get_system_stati(); |
488 | - header( 'Content-Disposition: attachment' ); |
|
489 | - header( "Content-Disposition: attachment; filename=system_status_" . sanitize_key( site_url() ) . ".html" ); |
|
488 | + header('Content-Disposition: attachment'); |
|
489 | + header("Content-Disposition: attachment; filename=system_status_".sanitize_key(site_url()).".html"); |
|
490 | 490 | echo "<style>table{border:1px solid darkgrey;}td{vertical-align:top}</style>"; |
491 | - echo "<h1>System Information for " . site_url() . "</h1>"; |
|
492 | - echo EEH_Template::layout_array_as_table( $status_info ); |
|
491 | + echo "<h1>System Information for ".site_url()."</h1>"; |
|
492 | + echo EEH_Template::layout_array_as_table($status_info); |
|
493 | 493 | die; |
494 | 494 | } |
495 | 495 | |
@@ -503,7 +503,7 @@ discard block |
||
503 | 503 | try { |
504 | 504 | $success = wp_mail(EE_SUPPORT_EMAIL, |
505 | 505 | 'Migration Crash Report', |
506 | - $body . "/r/n<br>" . print_r(EEM_System_Status::instance()->get_system_stati(), true), |
|
506 | + $body."/r/n<br>".print_r(EEM_System_Status::instance()->get_system_stati(), true), |
|
507 | 507 | array( |
508 | 508 | "from:$from_name<$from>", |
509 | 509 | // 'content-type:text/html charset=UTF-8' |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | EE_MAINTENANCE_ADMIN_URL); |
539 | 539 | $this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'), |
540 | 540 | EE_MAINTENANCE_ADMIN_URL); |
541 | - $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php'; |
|
541 | + $this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_confirm_migration_crash_report_sent.template.php'; |
|
542 | 542 | $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, |
543 | 543 | $this->_template_args, true); |
544 | 544 | $this->display_admin_page_with_sidebar(); |
@@ -639,9 +639,9 @@ discard block |
||
639 | 639 | wp_enqueue_script('ee_admin_js'); |
640 | 640 | // wp_enqueue_media(); |
641 | 641 | // wp_enqueue_script('media-upload'); |
642 | - wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL . '/ee-maintenance.js', array('jquery'), |
|
642 | + wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL.'/ee-maintenance.js', array('jquery'), |
|
643 | 643 | EVENT_ESPRESSO_VERSION, true); |
644 | - wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(), |
|
644 | + wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL.'ee-maintenance.css', array(), |
|
645 | 645 | EVENT_ESPRESSO_VERSION); |
646 | 646 | wp_enqueue_style('espresso_maintenance'); |
647 | 647 | } |
@@ -25,120 +25,120 @@ |
||
25 | 25 | class JsonModelSchema |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * @var \EEM_Base |
|
30 | - */ |
|
31 | - protected $model; |
|
32 | - |
|
33 | - /** |
|
34 | - * JsonModelSchema constructor. |
|
35 | - * |
|
36 | - * @param \EEM_Base $model |
|
37 | - */ |
|
38 | - public function __construct(EEM_Base $model) |
|
39 | - { |
|
40 | - $this->model = $model; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Return the schema for a given model from a given model. |
|
45 | - * @param \EEM_Base $model |
|
46 | - * @return array |
|
47 | - */ |
|
48 | - public function getModelSchema() |
|
49 | - { |
|
50 | - return $this->getModelSchemaForRelations( |
|
51 | - $this->model->relation_settings(), |
|
52 | - $this->getModelSchemaForFields( |
|
53 | - $this->model->field_settings(), |
|
54 | - $this->getInitialSchemaStructure() |
|
55 | - ) |
|
56 | - ); |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * Get the schema for a given set of model fields. |
|
62 | - * @param \EE_Model_Field_Base[] $model_fields |
|
63 | - * @return array |
|
64 | - */ |
|
65 | - public function getModelSchemaForFields(array $model_fields, array $schema) |
|
66 | - { |
|
67 | - foreach ($model_fields as $field => $model_field) { |
|
68 | - if (! $model_field instanceof EE_Model_Field_Base) { |
|
69 | - continue; |
|
70 | - } |
|
71 | - $schema['properties'][$field] = $model_field->getSchema(); |
|
72 | - |
|
73 | - //if this is a primary key field add the primary key item |
|
74 | - if ($model_field instanceof EE_Primary_Key_Field_Base) { |
|
75 | - $schema['properties'][$field]['primary_key'] = true; |
|
76 | - if ($model_field instanceof EE_Primary_Key_Int_Field) { |
|
77 | - $schema['properties'][$field]['readonly'] = true; |
|
78 | - } |
|
79 | - } |
|
80 | - |
|
81 | - //if this is a foreign key field add the foreign key item |
|
82 | - if ($model_field instanceof EE_Foreign_Key_Field_Base) { |
|
83 | - $schema['properties'][$field]['foreign_key'] = array( |
|
84 | - 'description' => esc_html__('This is a foreign key the points to the given models.', 'event_espresso'), |
|
85 | - 'type' => 'array', |
|
86 | - 'enum' => $model_field->get_model_class_names_pointed_to() |
|
87 | - ); |
|
88 | - } |
|
89 | - } |
|
90 | - return $schema; |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * Get the schema for a given set of model relations |
|
96 | - * @param EE_Model_Relation_Base[] $relations_on_model |
|
97 | - * @return array |
|
98 | - */ |
|
99 | - public function getModelSchemaForRelations(array $relations_on_model, array $schema) |
|
100 | - { |
|
101 | - foreach ($relations_on_model as $model_name => $relation) { |
|
102 | - if (! $relation instanceof EE_Model_Relation_Base) { |
|
103 | - continue; |
|
104 | - } |
|
105 | - $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation |
|
106 | - ? strtolower($model_name) |
|
107 | - : EEH_Inflector::pluralize_and_lower($model_name); |
|
108 | - $schema['properties'][$model_name_for_schema] = $relation->getSchema(); |
|
109 | - $schema['properties'][$model_name_for_schema]['relation_model'] = $model_name; |
|
110 | - } |
|
111 | - return $schema; |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * Outputs the schema header for a model. |
|
117 | - * @param \EEM_Base $model |
|
118 | - * @return array |
|
119 | - */ |
|
120 | - public function getInitialSchemaStructure() |
|
121 | - { |
|
122 | - return array( |
|
123 | - '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
124 | - 'title' => $this->model->get_this_model_name(), |
|
125 | - 'type' => 'object', |
|
126 | - 'properties' => array() |
|
127 | - ); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * Allows one to just use the object as a string to get the json. |
|
133 | - * eg. |
|
134 | - * |
|
135 | - * $json_schema = new JsonModelSchema(EEM_Event::instance()); |
|
136 | - * echo $json_schema; //outputs the schema as a json formatted string. |
|
137 | - * |
|
138 | - * @return bool|false|mixed|string |
|
139 | - */ |
|
140 | - public function __toString() |
|
141 | - { |
|
142 | - return wp_json_encode($this->getModelSchema()); |
|
143 | - } |
|
28 | + /** |
|
29 | + * @var \EEM_Base |
|
30 | + */ |
|
31 | + protected $model; |
|
32 | + |
|
33 | + /** |
|
34 | + * JsonModelSchema constructor. |
|
35 | + * |
|
36 | + * @param \EEM_Base $model |
|
37 | + */ |
|
38 | + public function __construct(EEM_Base $model) |
|
39 | + { |
|
40 | + $this->model = $model; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Return the schema for a given model from a given model. |
|
45 | + * @param \EEM_Base $model |
|
46 | + * @return array |
|
47 | + */ |
|
48 | + public function getModelSchema() |
|
49 | + { |
|
50 | + return $this->getModelSchemaForRelations( |
|
51 | + $this->model->relation_settings(), |
|
52 | + $this->getModelSchemaForFields( |
|
53 | + $this->model->field_settings(), |
|
54 | + $this->getInitialSchemaStructure() |
|
55 | + ) |
|
56 | + ); |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * Get the schema for a given set of model fields. |
|
62 | + * @param \EE_Model_Field_Base[] $model_fields |
|
63 | + * @return array |
|
64 | + */ |
|
65 | + public function getModelSchemaForFields(array $model_fields, array $schema) |
|
66 | + { |
|
67 | + foreach ($model_fields as $field => $model_field) { |
|
68 | + if (! $model_field instanceof EE_Model_Field_Base) { |
|
69 | + continue; |
|
70 | + } |
|
71 | + $schema['properties'][$field] = $model_field->getSchema(); |
|
72 | + |
|
73 | + //if this is a primary key field add the primary key item |
|
74 | + if ($model_field instanceof EE_Primary_Key_Field_Base) { |
|
75 | + $schema['properties'][$field]['primary_key'] = true; |
|
76 | + if ($model_field instanceof EE_Primary_Key_Int_Field) { |
|
77 | + $schema['properties'][$field]['readonly'] = true; |
|
78 | + } |
|
79 | + } |
|
80 | + |
|
81 | + //if this is a foreign key field add the foreign key item |
|
82 | + if ($model_field instanceof EE_Foreign_Key_Field_Base) { |
|
83 | + $schema['properties'][$field]['foreign_key'] = array( |
|
84 | + 'description' => esc_html__('This is a foreign key the points to the given models.', 'event_espresso'), |
|
85 | + 'type' => 'array', |
|
86 | + 'enum' => $model_field->get_model_class_names_pointed_to() |
|
87 | + ); |
|
88 | + } |
|
89 | + } |
|
90 | + return $schema; |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * Get the schema for a given set of model relations |
|
96 | + * @param EE_Model_Relation_Base[] $relations_on_model |
|
97 | + * @return array |
|
98 | + */ |
|
99 | + public function getModelSchemaForRelations(array $relations_on_model, array $schema) |
|
100 | + { |
|
101 | + foreach ($relations_on_model as $model_name => $relation) { |
|
102 | + if (! $relation instanceof EE_Model_Relation_Base) { |
|
103 | + continue; |
|
104 | + } |
|
105 | + $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation |
|
106 | + ? strtolower($model_name) |
|
107 | + : EEH_Inflector::pluralize_and_lower($model_name); |
|
108 | + $schema['properties'][$model_name_for_schema] = $relation->getSchema(); |
|
109 | + $schema['properties'][$model_name_for_schema]['relation_model'] = $model_name; |
|
110 | + } |
|
111 | + return $schema; |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * Outputs the schema header for a model. |
|
117 | + * @param \EEM_Base $model |
|
118 | + * @return array |
|
119 | + */ |
|
120 | + public function getInitialSchemaStructure() |
|
121 | + { |
|
122 | + return array( |
|
123 | + '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
124 | + 'title' => $this->model->get_this_model_name(), |
|
125 | + 'type' => 'object', |
|
126 | + 'properties' => array() |
|
127 | + ); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * Allows one to just use the object as a string to get the json. |
|
133 | + * eg. |
|
134 | + * |
|
135 | + * $json_schema = new JsonModelSchema(EEM_Event::instance()); |
|
136 | + * echo $json_schema; //outputs the schema as a json formatted string. |
|
137 | + * |
|
138 | + * @return bool|false|mixed|string |
|
139 | + */ |
|
140 | + public function __toString() |
|
141 | + { |
|
142 | + return wp_json_encode($this->getModelSchema()); |
|
143 | + } |
|
144 | 144 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('ABSPATH')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /* |
5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
40 | 40 | * @since 4.0 |
41 | 41 | */ |
42 | 42 | if (function_exists('espresso_version')) { |
43 | - /** |
|
44 | - * espresso_duplicate_plugin_error |
|
45 | - * displays if more than one version of EE is activated at the same time |
|
46 | - */ |
|
47 | - function espresso_duplicate_plugin_error() |
|
48 | - { |
|
49 | - ?> |
|
43 | + /** |
|
44 | + * espresso_duplicate_plugin_error |
|
45 | + * displays if more than one version of EE is activated at the same time |
|
46 | + */ |
|
47 | + function espresso_duplicate_plugin_error() |
|
48 | + { |
|
49 | + ?> |
|
50 | 50 | <div class="error"> |
51 | 51 | <p> |
52 | 52 | <?php echo esc_html__( |
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | 61 | |
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.32.rc.013'); |
|
105 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.32.rc.013'); |
|
105 | + } |
|
106 | 106 | |
107 | - // define versions |
|
108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | - if ( ! defined('DS')) { |
|
115 | - define('DS', '/'); |
|
116 | - } |
|
117 | - if ( ! defined('PS')) { |
|
118 | - define('PS', PATH_SEPARATOR); |
|
119 | - } |
|
120 | - if ( ! defined('SP')) { |
|
121 | - define('SP', ' '); |
|
122 | - } |
|
123 | - if ( ! defined('EENL')) { |
|
124 | - define('EENL', "\n"); |
|
125 | - } |
|
126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | - // define the plugin directory and URL |
|
128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | - // main root folder paths |
|
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | - // core system paths |
|
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | - // gateways |
|
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | - // asset URL paths |
|
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | - // define upload paths |
|
164 | - $uploads = wp_upload_dir(); |
|
165 | - // define the uploads directory and URL |
|
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | - // define the templates directory and URL |
|
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | - // define the gateway directory and URL |
|
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | - // languages folder/path |
|
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | - //check for dompdf fonts in uploads |
|
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | - } |
|
181 | - //ajax constants |
|
182 | - define( |
|
183 | - 'EE_FRONT_AJAX', |
|
184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | - ); |
|
186 | - define( |
|
187 | - 'EE_ADMIN_AJAX', |
|
188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | - ); |
|
190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | - //want to change its default value! or find when -1 means infinity |
|
193 | - define('EE_INF_IN_DB', -1); |
|
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | - define('EE_DEBUG', false); |
|
196 | - // for older WP versions |
|
197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | - } |
|
200 | - /** |
|
201 | - * espresso_plugin_activation |
|
202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | - */ |
|
204 | - function espresso_plugin_activation() |
|
205 | - { |
|
206 | - update_option('ee_espresso_activation', true); |
|
207 | - } |
|
107 | + // define versions |
|
108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | + if ( ! defined('DS')) { |
|
115 | + define('DS', '/'); |
|
116 | + } |
|
117 | + if ( ! defined('PS')) { |
|
118 | + define('PS', PATH_SEPARATOR); |
|
119 | + } |
|
120 | + if ( ! defined('SP')) { |
|
121 | + define('SP', ' '); |
|
122 | + } |
|
123 | + if ( ! defined('EENL')) { |
|
124 | + define('EENL', "\n"); |
|
125 | + } |
|
126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | + // define the plugin directory and URL |
|
128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | + // main root folder paths |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | + // core system paths |
|
141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | + // gateways |
|
154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | + // asset URL paths |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | + // define upload paths |
|
164 | + $uploads = wp_upload_dir(); |
|
165 | + // define the uploads directory and URL |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | + // define the templates directory and URL |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | + // define the gateway directory and URL |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | + // languages folder/path |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | + //check for dompdf fonts in uploads |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | + } |
|
181 | + //ajax constants |
|
182 | + define( |
|
183 | + 'EE_FRONT_AJAX', |
|
184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | + ); |
|
186 | + define( |
|
187 | + 'EE_ADMIN_AJAX', |
|
188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | + ); |
|
190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | + //want to change its default value! or find when -1 means infinity |
|
193 | + define('EE_INF_IN_DB', -1); |
|
194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | + define('EE_DEBUG', false); |
|
196 | + // for older WP versions |
|
197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | + } |
|
200 | + /** |
|
201 | + * espresso_plugin_activation |
|
202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | + */ |
|
204 | + function espresso_plugin_activation() |
|
205 | + { |
|
206 | + update_option('ee_espresso_activation', true); |
|
207 | + } |
|
208 | 208 | |
209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | - /** |
|
211 | - * espresso_load_error_handling |
|
212 | - * this function loads EE's class for handling exceptions and errors |
|
213 | - */ |
|
214 | - function espresso_load_error_handling() |
|
215 | - { |
|
216 | - // load debugging tools |
|
217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | - EEH_Debug_Tools::instance(); |
|
220 | - } |
|
221 | - // load error handling |
|
222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | - } else { |
|
225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | - } |
|
227 | - } |
|
209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | + /** |
|
211 | + * espresso_load_error_handling |
|
212 | + * this function loads EE's class for handling exceptions and errors |
|
213 | + */ |
|
214 | + function espresso_load_error_handling() |
|
215 | + { |
|
216 | + // load debugging tools |
|
217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | + EEH_Debug_Tools::instance(); |
|
220 | + } |
|
221 | + // load error handling |
|
222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | + } else { |
|
225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * espresso_load_required |
|
231 | - * given a class name and path, this function will load that file or throw an exception |
|
232 | - * |
|
233 | - * @param string $classname |
|
234 | - * @param string $full_path_to_file |
|
235 | - * @throws EE_Error |
|
236 | - */ |
|
237 | - function espresso_load_required($classname, $full_path_to_file) |
|
238 | - { |
|
239 | - static $error_handling_loaded = false; |
|
240 | - if ( ! $error_handling_loaded) { |
|
241 | - espresso_load_error_handling(); |
|
242 | - $error_handling_loaded = true; |
|
243 | - } |
|
244 | - if (is_readable($full_path_to_file)) { |
|
245 | - require_once($full_path_to_file); |
|
246 | - } else { |
|
247 | - throw new EE_Error ( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $classname |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - } |
|
229 | + /** |
|
230 | + * espresso_load_required |
|
231 | + * given a class name and path, this function will load that file or throw an exception |
|
232 | + * |
|
233 | + * @param string $classname |
|
234 | + * @param string $full_path_to_file |
|
235 | + * @throws EE_Error |
|
236 | + */ |
|
237 | + function espresso_load_required($classname, $full_path_to_file) |
|
238 | + { |
|
239 | + static $error_handling_loaded = false; |
|
240 | + if ( ! $error_handling_loaded) { |
|
241 | + espresso_load_error_handling(); |
|
242 | + $error_handling_loaded = true; |
|
243 | + } |
|
244 | + if (is_readable($full_path_to_file)) { |
|
245 | + require_once($full_path_to_file); |
|
246 | + } else { |
|
247 | + throw new EE_Error ( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $classname |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | - new EE_Bootstrap(); |
|
263 | - } |
|
259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | + new EE_Bootstrap(); |
|
263 | + } |
|
264 | 264 | } |
265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
266 | - /** |
|
267 | - * deactivate_plugin |
|
268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | - * @return void |
|
273 | - */ |
|
274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | - { |
|
276 | - if ( ! function_exists('deactivate_plugins')) { |
|
277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | - } |
|
279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | - deactivate_plugins($plugin_basename); |
|
281 | - } |
|
266 | + /** |
|
267 | + * deactivate_plugin |
|
268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | + * @return void |
|
273 | + */ |
|
274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | + { |
|
276 | + if ( ! function_exists('deactivate_plugins')) { |
|
277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | + } |
|
279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | + deactivate_plugins($plugin_basename); |
|
281 | + } |
|
282 | 282 | } |
283 | 283 | \ No newline at end of file |
@@ -362,22 +362,22 @@ |
||
362 | 362 | |
363 | 363 | |
364 | 364 | |
365 | - /** |
|
366 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
367 | - * @throws \EE_Error |
|
368 | - */ |
|
369 | - public function get_total_line_items_just_added_to_cart() |
|
370 | - { |
|
371 | - return $this->get_all(array( |
|
372 | - array( |
|
373 | - 'TXN_ID' => 0, |
|
374 | - 'LIN_type' => 'total', |
|
375 | - 'LIN_timestamp' => array( |
|
376 | - '>', |
|
377 | - time() - EE_Registry::instance()->SSN->lifespan() |
|
378 | - ), ) |
|
379 | - )); |
|
380 | - } |
|
365 | + /** |
|
366 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
367 | + * @throws \EE_Error |
|
368 | + */ |
|
369 | + public function get_total_line_items_just_added_to_cart() |
|
370 | + { |
|
371 | + return $this->get_all(array( |
|
372 | + array( |
|
373 | + 'TXN_ID' => 0, |
|
374 | + 'LIN_type' => 'total', |
|
375 | + 'LIN_timestamp' => array( |
|
376 | + '>', |
|
377 | + time() - EE_Registry::instance()->SSN->lifespan() |
|
378 | + ), ) |
|
379 | + )); |
|
380 | + } |
|
381 | 381 | |
382 | 382 | |
383 | 383 |
@@ -105,41 +105,41 @@ discard block |
||
105 | 105 | * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
106 | 106 | * @return \EEM_Line_Item |
107 | 107 | */ |
108 | - protected function __construct( $timezone ) { |
|
109 | - $this->singular_item = __('Line Item','event_espresso'); |
|
110 | - $this->plural_item = __('Line Items','event_espresso'); |
|
108 | + protected function __construct($timezone) { |
|
109 | + $this->singular_item = __('Line Item', 'event_espresso'); |
|
110 | + $this->plural_item = __('Line Items', 'event_espresso'); |
|
111 | 111 | |
112 | 112 | $this->_tables = array( |
113 | - 'Line_Item'=>new EE_Primary_Table('esp_line_item','LIN_ID') |
|
113 | + 'Line_Item'=>new EE_Primary_Table('esp_line_item', 'LIN_ID') |
|
114 | 114 | ); |
115 | - $line_items_can_be_for = apply_filters( 'FHEE__EEM_Line_Item__line_items_can_be_for', array('Ticket','Price', 'Event' ) ); |
|
115 | + $line_items_can_be_for = apply_filters('FHEE__EEM_Line_Item__line_items_can_be_for', array('Ticket', 'Price', 'Event')); |
|
116 | 116 | $this->_fields = array( |
117 | 117 | 'Line_Item' => array( |
118 | - 'LIN_ID' => new EE_Primary_Key_Int_Field( 'LIN_ID', __( "ID", "event_espresso" ) ), |
|
119 | - 'LIN_code' => new EE_Slug_Field( 'LIN_code', __( "Code for index into Cart", "event_espresso" ), TRUE ), |
|
120 | - 'TXN_ID' => new EE_Foreign_Key_Int_Field( 'TXN_ID', __( "Transaction ID", "event_espresso" ), TRUE, NULL, 'Transaction' ), |
|
121 | - 'LIN_name' => new EE_Full_HTML_Field( 'LIN_name', __( "Line Item Name", "event_espresso" ), FALSE, '' ), |
|
122 | - 'LIN_desc' => new EE_Full_HTML_Field( 'LIN_desc', __( "Line Item Description", "event_espresso" ), TRUE ), |
|
123 | - 'LIN_unit_price' => new EE_Money_Field( 'LIN_unit_price', __( "Unit Price", "event_espresso" ), FALSE, 0 ), |
|
124 | - 'LIN_percent' => new EE_Float_Field( 'LIN_percent', __( "Percent", "event_espresso" ), FALSE, 0 ), |
|
125 | - 'LIN_is_taxable' => new EE_Boolean_Field( 'LIN_is_taxable', __( "Taxable", "event_espresso" ), FALSE, FALSE ), |
|
126 | - 'LIN_order' => new EE_Integer_Field( 'LIN_order', __( "Order of Application towards total of parent", "event_espresso" ), FALSE, 1 ), |
|
127 | - 'LIN_total' => new EE_Money_Field( 'LIN_total', __( "Total (unit price x quantity)", "event_espresso" ), FALSE, 0 ), |
|
128 | - 'LIN_quantity' => new EE_Integer_Field( 'LIN_quantity', __( "Quantity", "event_espresso" ), TRUE, 1 ), |
|
129 | - 'LIN_parent' => new EE_Integer_Field( 'LIN_parent', __( "Parent ID (this item goes towards that Line Item's total)", "event_espresso" ), TRUE, NULL ), |
|
130 | - 'LIN_type' => new EE_Enum_Text_Field( 'LIN_type', __( "Type", "event_espresso" ), FALSE, 'line-item', array( |
|
118 | + 'LIN_ID' => new EE_Primary_Key_Int_Field('LIN_ID', __("ID", "event_espresso")), |
|
119 | + 'LIN_code' => new EE_Slug_Field('LIN_code', __("Code for index into Cart", "event_espresso"), TRUE), |
|
120 | + 'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', __("Transaction ID", "event_espresso"), TRUE, NULL, 'Transaction'), |
|
121 | + 'LIN_name' => new EE_Full_HTML_Field('LIN_name', __("Line Item Name", "event_espresso"), FALSE, ''), |
|
122 | + 'LIN_desc' => new EE_Full_HTML_Field('LIN_desc', __("Line Item Description", "event_espresso"), TRUE), |
|
123 | + 'LIN_unit_price' => new EE_Money_Field('LIN_unit_price', __("Unit Price", "event_espresso"), FALSE, 0), |
|
124 | + 'LIN_percent' => new EE_Float_Field('LIN_percent', __("Percent", "event_espresso"), FALSE, 0), |
|
125 | + 'LIN_is_taxable' => new EE_Boolean_Field('LIN_is_taxable', __("Taxable", "event_espresso"), FALSE, FALSE), |
|
126 | + 'LIN_order' => new EE_Integer_Field('LIN_order', __("Order of Application towards total of parent", "event_espresso"), FALSE, 1), |
|
127 | + 'LIN_total' => new EE_Money_Field('LIN_total', __("Total (unit price x quantity)", "event_espresso"), FALSE, 0), |
|
128 | + 'LIN_quantity' => new EE_Integer_Field('LIN_quantity', __("Quantity", "event_espresso"), TRUE, 1), |
|
129 | + 'LIN_parent' => new EE_Integer_Field('LIN_parent', __("Parent ID (this item goes towards that Line Item's total)", "event_espresso"), TRUE, NULL), |
|
130 | + 'LIN_type' => new EE_Enum_Text_Field('LIN_type', __("Type", "event_espresso"), FALSE, 'line-item', array( |
|
131 | 131 | self::type_line_item => __("Line Item", "event_espresso"), |
132 | 132 | self::type_sub_line_item => __("Sub-Item", "event_espresso"), |
133 | 133 | self::type_sub_total => __("Subtotal", "event_espresso"), |
134 | 134 | self::type_tax_sub_total => __("Tax Subtotal", "event_espresso"), |
135 | 135 | self::type_tax => __("Tax", "event_espresso"), |
136 | 136 | self::type_total => __("Total", "event_espresso"), |
137 | - self::type_cancellation => __( 'Cancellation', 'event_espresso' ) |
|
137 | + self::type_cancellation => __('Cancellation', 'event_espresso') |
|
138 | 138 | ) |
139 | 139 | ), |
140 | - 'OBJ_ID' => new EE_Foreign_Key_Int_Field( 'OBJ_ID', __( 'ID of Item purchased.', 'event_espresso' ), TRUE, NULL, $line_items_can_be_for ), |
|
141 | - 'OBJ_type' =>new EE_Any_Foreign_Model_Name_Field( 'OBJ_type', __( "Model Name this Line Item is for", "event_espresso" ), TRUE, NULL, $line_items_can_be_for ), |
|
142 | - 'LIN_timestamp' => new EE_Datetime_Field('LIN_timestamp', __('When the line item was created','event_espresso'), false, EE_Datetime_Field::now, $timezone ), |
|
140 | + 'OBJ_ID' => new EE_Foreign_Key_Int_Field('OBJ_ID', __('ID of Item purchased.', 'event_espresso'), TRUE, NULL, $line_items_can_be_for), |
|
141 | + 'OBJ_type' =>new EE_Any_Foreign_Model_Name_Field('OBJ_type', __("Model Name this Line Item is for", "event_espresso"), TRUE, NULL, $line_items_can_be_for), |
|
142 | + 'LIN_timestamp' => new EE_Datetime_Field('LIN_timestamp', __('When the line item was created', 'event_espresso'), false, EE_Datetime_Field::now, $timezone), |
|
143 | 143 | ) |
144 | 144 | ); |
145 | 145 | $this->_model_relations = array( |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | ); |
151 | 151 | $this->_model_chain_to_wp_user = 'Transaction.Registration.Event'; |
152 | 152 | $this->_caps_slug = 'transactions'; |
153 | - parent::__construct( $timezone ); |
|
153 | + parent::__construct($timezone); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | |
@@ -161,9 +161,9 @@ discard block |
||
161 | 161 | * @param EE_Transaction|int $transaction |
162 | 162 | * @return EE_Line_Item[] |
163 | 163 | */ |
164 | - public function get_all_of_type_for_transaction( $line_item_type, $transaction ){ |
|
165 | - $transaction = EEM_Transaction::instance()->ensure_is_ID( $transaction ); |
|
166 | - return $this->get_all( array( array( |
|
164 | + public function get_all_of_type_for_transaction($line_item_type, $transaction) { |
|
165 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
166 | + return $this->get_all(array(array( |
|
167 | 167 | 'LIN_type' => $line_item_type, |
168 | 168 | 'TXN_ID' => $transaction |
169 | 169 | ))); |
@@ -177,14 +177,14 @@ discard block |
||
177 | 177 | * @param EE_Transaction|int $transaction |
178 | 178 | * @return EE_Line_Item[] |
179 | 179 | */ |
180 | - public function get_all_non_ticket_line_items_for_transaction( $transaction ) { |
|
181 | - $transaction = EEM_Transaction::instance()->ensure_is_ID( $transaction ); |
|
182 | - return $this->get_all( array( array( |
|
180 | + public function get_all_non_ticket_line_items_for_transaction($transaction) { |
|
181 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
182 | + return $this->get_all(array(array( |
|
183 | 183 | 'LIN_type' => self::type_line_item, |
184 | 184 | 'TXN_ID' => $transaction, |
185 | 185 | 'OR' => array( |
186 | - 'OBJ_type*notticket' => array( '!=', 'Ticket'), |
|
187 | - 'OBJ_type*null' => array( 'IS_NULL' )) |
|
186 | + 'OBJ_type*notticket' => array('!=', 'Ticket'), |
|
187 | + 'OBJ_type*null' => array('IS_NULL')) |
|
188 | 188 | ))); |
189 | 189 | } |
190 | 190 | |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | * because if there are spam bots afoot there will be LOTS of line items |
195 | 195 | * @return int count of how many deleted |
196 | 196 | */ |
197 | - public function delete_line_items_with_no_transaction(){ |
|
197 | + public function delete_line_items_with_no_transaction() { |
|
198 | 198 | /** @type WPDB $wpdb */ |
199 | 199 | global $wpdb; |
200 | 200 | $time_to_leave_alone = apply_filters( |
@@ -202,13 +202,13 @@ discard block |
||
202 | 202 | ); |
203 | 203 | $query = $wpdb->prepare( |
204 | 204 | 'DELETE li |
205 | - FROM ' . $this->table() . ' li |
|
206 | - LEFT JOIN ' . EEM_Transaction::instance()->table(). ' t ON li.TXN_ID = t.TXN_ID |
|
205 | + FROM ' . $this->table().' li |
|
206 | + LEFT JOIN ' . EEM_Transaction::instance()->table().' t ON li.TXN_ID = t.TXN_ID |
|
207 | 207 | WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s', |
208 | 208 | // use GMT time because that's what TXN_timestamps are in |
209 | - date( 'Y-m-d H:i:s', time() - $time_to_leave_alone ) |
|
209 | + date('Y-m-d H:i:s', time() - $time_to_leave_alone) |
|
210 | 210 | ); |
211 | - return $wpdb->query( $query ); |
|
211 | + return $wpdb->query($query); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | |
@@ -221,10 +221,10 @@ discard block |
||
221 | 221 | * @param \EE_Base_Class $object |
222 | 222 | * @return EE_Line_Item[] |
223 | 223 | */ |
224 | - public function get_line_item_for_transaction_object( $TXN_ID, EE_Base_Class $object ){ |
|
225 | - return $this->get_all( array( array( |
|
224 | + public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) { |
|
225 | + return $this->get_all(array(array( |
|
226 | 226 | 'TXN_ID' => $TXN_ID, |
227 | - 'OBJ_type' => str_replace( 'EE_', '', get_class( $object )), |
|
227 | + 'OBJ_type' => str_replace('EE_', '', get_class($object)), |
|
228 | 228 | 'OBJ_ID' => $object->ID() |
229 | 229 | ))); |
230 | 230 | } |
@@ -240,16 +240,16 @@ discard block |
||
240 | 240 | * @param array $OBJ_IDs |
241 | 241 | * @return EE_Line_Item[] |
242 | 242 | */ |
243 | - public function get_object_line_items_for_transaction( $TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array() ){ |
|
243 | + public function get_object_line_items_for_transaction($TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array()) { |
|
244 | 244 | $query_params = array( |
245 | 245 | 'OBJ_type' => $OBJ_type, |
246 | 246 | // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query |
247 | - 'OBJ_ID' => is_array( $OBJ_IDs ) && ! isset( $OBJ_IDs['IN'] ) ? array( 'IN', $OBJ_IDs ) : $OBJ_IDs |
|
247 | + 'OBJ_ID' => is_array($OBJ_IDs) && ! isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs |
|
248 | 248 | ); |
249 | - if ( $TXN_ID ) { |
|
249 | + if ($TXN_ID) { |
|
250 | 250 | $query_params['TXN_ID'] = $TXN_ID; |
251 | 251 | } |
252 | - return $this->get_all( array( $query_params )); |
|
252 | + return $this->get_all(array($query_params)); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | |
@@ -260,13 +260,13 @@ discard block |
||
260 | 260 | * @param EE_Transaction $transaction |
261 | 261 | * @return EE_Line_Item[] |
262 | 262 | */ |
263 | - public function get_all_ticket_line_items_for_transaction( EE_Transaction $transaction ) { |
|
264 | - return $this->get_all( array( |
|
263 | + public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction) { |
|
264 | + return $this->get_all(array( |
|
265 | 265 | array( |
266 | 266 | 'TXN_ID' => $transaction->ID(), |
267 | 267 | 'OBJ_type' => 'Ticket', |
268 | 268 | ) |
269 | - ) ); |
|
269 | + )); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | |
@@ -278,14 +278,14 @@ discard block |
||
278 | 278 | * @param int $TKT_ID |
279 | 279 | * @return \EE_Line_Item |
280 | 280 | */ |
281 | - public function get_ticket_line_item_for_transaction( $TXN_ID, $TKT_ID ) { |
|
282 | - return $this->get_one( array( |
|
281 | + public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID) { |
|
282 | + return $this->get_one(array( |
|
283 | 283 | array( |
284 | - 'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID( $TXN_ID ), |
|
284 | + 'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID), |
|
285 | 285 | 'OBJ_ID' => $TKT_ID, |
286 | 286 | 'OBJ_type' => 'Ticket', |
287 | 287 | ) |
288 | - ) ); |
|
288 | + )); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | |
@@ -300,8 +300,8 @@ discard block |
||
300 | 300 | * @param EE_Promotion $promotion |
301 | 301 | * @return EE_Line_Item |
302 | 302 | */ |
303 | - public function get_existing_promotion_line_item( EE_Line_Item $parent_line_item, EE_Promotion $promotion ) { |
|
304 | - return $this->get_one( array( |
|
303 | + public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) { |
|
304 | + return $this->get_one(array( |
|
305 | 305 | array( |
306 | 306 | 'TXN_ID' => $parent_line_item->TXN_ID(), |
307 | 307 | 'LIN_parent' => $parent_line_item->ID(), |
@@ -322,8 +322,8 @@ discard block |
||
322 | 322 | * @param EE_Line_Item $parent_line_item |
323 | 323 | * @return EE_Line_Item[] |
324 | 324 | */ |
325 | - public function get_all_promotion_line_items( EE_Line_Item $parent_line_item ) { |
|
326 | - return $this->get_all( array( |
|
325 | + public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) { |
|
326 | + return $this->get_all(array( |
|
327 | 327 | array( |
328 | 328 | 'TXN_ID' => $parent_line_item->TXN_ID(), |
329 | 329 | 'LIN_parent' => $parent_line_item->ID(), |
@@ -340,8 +340,8 @@ discard block |
||
340 | 340 | * @param EE_Registration $registration |
341 | 341 | * @return EE_Line_ITem |
342 | 342 | */ |
343 | - public function get_line_item_for_registration( EE_Registration $registration ) { |
|
344 | - return $this->get_one( $this->line_item_for_registration_query_params( $registration )); |
|
343 | + public function get_line_item_for_registration(EE_Registration $registration) { |
|
344 | + return $this->get_one($this->line_item_for_registration_query_params($registration)); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | /** |
@@ -350,14 +350,14 @@ discard block |
||
350 | 350 | * @param array $original_query_params any extra query params you'd like to be merged with |
351 | 351 | * @return array like EEM_Base::get_all()'s $query_params |
352 | 352 | */ |
353 | - public function line_item_for_registration_query_params( EE_Registration $registration, $original_query_params = array() ) { |
|
354 | - return array_replace_recursive( $original_query_params, array( |
|
353 | + public function line_item_for_registration_query_params(EE_Registration $registration, $original_query_params = array()) { |
|
354 | + return array_replace_recursive($original_query_params, array( |
|
355 | 355 | array( |
356 | 356 | 'OBJ_ID' => $registration->ticket_ID(), |
357 | 357 | 'OBJ_type' => 'Ticket', |
358 | 358 | 'TXN_ID' => $registration->transaction_ID() |
359 | 359 | ) |
360 | - ) ); |
|
360 | + )); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | 'LIN_timestamp' => array( |
376 | 376 | '>', |
377 | 377 | time() - EE_Registry::instance()->SSN->lifespan() |
378 | - ), ) |
|
378 | + ),) |
|
379 | 379 | )); |
380 | 380 | } |
381 | 381 |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use EventEspresso\core\exceptions\UnexpectedEntityException; |
3 | 3 | |
4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -21,846 +21,846 @@ discard block |
||
21 | 21 | class EED_Ticket_Sales_Monitor extends EED_Module |
22 | 22 | { |
23 | 23 | |
24 | - const debug = false; // true false |
|
25 | - |
|
26 | - /** |
|
27 | - * an array of raw ticket data from EED_Ticket_Selector |
|
28 | - * |
|
29 | - * @var array $ticket_selections |
|
30 | - */ |
|
31 | - protected $ticket_selections = array(); |
|
32 | - |
|
33 | - /** |
|
34 | - * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
35 | - * according to how they are displayed in the actual Ticket_Selector |
|
36 | - * this tracks the current row being processed |
|
37 | - * |
|
38 | - * @var int $current_row |
|
39 | - */ |
|
40 | - protected $current_row = 0; |
|
41 | - |
|
42 | - /** |
|
43 | - * an array for tracking names of tickets that have sold out |
|
44 | - * |
|
45 | - * @var array $sold_out_tickets |
|
46 | - */ |
|
47 | - protected $sold_out_tickets = array(); |
|
48 | - |
|
49 | - /** |
|
50 | - * an array for tracking names of tickets that have had their quantities reduced |
|
51 | - * |
|
52 | - * @var array $decremented_tickets |
|
53 | - */ |
|
54 | - protected $decremented_tickets = array(); |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
60 | - * |
|
61 | - * @access public |
|
62 | - * @return void |
|
63 | - */ |
|
64 | - public static function set_hooks() |
|
65 | - { |
|
66 | - // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
67 | - add_filter('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
68 | - array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
69 | - 20, 3 |
|
70 | - ); |
|
71 | - // add notices for sold out tickets |
|
72 | - add_action('AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
73 | - array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
74 | - 10 |
|
75 | - ); |
|
76 | - // handle ticket quantities adjusted in cart |
|
77 | - //add_action( |
|
78 | - // 'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated', |
|
79 | - // array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ), |
|
80 | - // 10, 2 |
|
81 | - //); |
|
82 | - // handle tickets deleted from cart |
|
83 | - add_action( |
|
84 | - 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
85 | - array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
86 | - 10, 2 |
|
87 | - ); |
|
88 | - // handle emptied carts |
|
89 | - add_action( |
|
90 | - 'AHEE__EE_Session__reset_cart__before_reset', |
|
91 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
92 | - 10, 1 |
|
93 | - ); |
|
94 | - add_action( |
|
95 | - 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
96 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
97 | - 10, 1 |
|
98 | - ); |
|
99 | - // handle cancelled registrations |
|
100 | - add_action( |
|
101 | - 'AHEE__EE_Session__reset_checkout__before_reset', |
|
102 | - array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
103 | - 10, 1 |
|
104 | - ); |
|
105 | - // cron tasks |
|
106 | - add_action( |
|
107 | - 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions__abandoned_transaction', |
|
108 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
109 | - 10, 1 |
|
110 | - ); |
|
111 | - add_action( |
|
112 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
113 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
114 | - 10, 1 |
|
115 | - ); |
|
116 | - add_action( |
|
117 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
118 | - array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
119 | - 10, 1 |
|
120 | - ); |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @return void |
|
130 | - */ |
|
131 | - public static function set_hooks_admin() |
|
132 | - { |
|
133 | - EED_Ticket_Sales_Monitor::set_hooks(); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * @return EED_Ticket_Sales_Monitor|EED_Module |
|
140 | - */ |
|
141 | - public static function instance() |
|
142 | - { |
|
143 | - return parent::get_instance(__CLASS__); |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * run |
|
150 | - * |
|
151 | - * @access public |
|
152 | - * @param WP_Query $WP_Query |
|
153 | - * @return void |
|
154 | - */ |
|
155 | - public function run($WP_Query) |
|
156 | - { |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - |
|
161 | - /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
162 | - |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * validate_ticket_sales |
|
167 | - * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
168 | - * |
|
169 | - * @access public |
|
170 | - * @param int $qty |
|
171 | - * @param \EE_Ticket $ticket |
|
172 | - * @return bool |
|
173 | - * @throws UnexpectedEntityException |
|
174 | - * @throws EE_Error |
|
175 | - */ |
|
176 | - public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
177 | - { |
|
178 | - $qty = absint($qty); |
|
179 | - if ($qty > 0) { |
|
180 | - $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
181 | - } |
|
182 | - if (self::debug) { |
|
183 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()'; |
|
184 | - echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>'; |
|
185 | - } |
|
186 | - return $qty; |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * _validate_ticket_sale |
|
193 | - * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
194 | - * |
|
195 | - * @access protected |
|
196 | - * @param \EE_Ticket $ticket |
|
197 | - * @param int $qty |
|
198 | - * @return int |
|
199 | - * @throws UnexpectedEntityException |
|
200 | - * @throws EE_Error |
|
201 | - */ |
|
202 | - protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
203 | - { |
|
204 | - if (self::debug) { |
|
205 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
206 | - } |
|
207 | - if ( ! $ticket instanceof EE_Ticket) { |
|
208 | - return 0; |
|
209 | - } |
|
210 | - if (self::debug) { |
|
211 | - echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
212 | - echo '<br /> . original ticket->reserved: ' . $ticket->reserved(); |
|
213 | - } |
|
214 | - $ticket->refresh_from_db(); |
|
215 | - // first let's determine the ticket availability based on sales |
|
216 | - $available = $ticket->qty('saleable'); |
|
217 | - if (self::debug) { |
|
218 | - echo '<br /> . . . ticket->qty: ' . $ticket->qty(); |
|
219 | - echo '<br /> . . . ticket->sold: ' . $ticket->sold(); |
|
220 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
221 | - echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
222 | - echo '<br /> . . . available: ' . $available; |
|
223 | - } |
|
224 | - if ($available < 1) { |
|
225 | - $this->_ticket_sold_out($ticket); |
|
226 | - return 0; |
|
227 | - } |
|
228 | - if (self::debug) { |
|
229 | - echo '<br /> . . . qty: ' . $qty; |
|
230 | - } |
|
231 | - if ($available < $qty) { |
|
232 | - $qty = $available; |
|
233 | - if (self::debug) { |
|
234 | - echo '<br /> . . . QTY ADJUSTED: ' . $qty; |
|
235 | - } |
|
236 | - $this->_ticket_quantity_decremented($ticket); |
|
237 | - } |
|
238 | - $this->_reserve_ticket($ticket, $qty); |
|
239 | - return $qty; |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - |
|
244 | - /** |
|
245 | - * _reserve_ticket |
|
246 | - * increments ticket reserved based on quantity passed |
|
247 | - * |
|
248 | - * @access protected |
|
249 | - * @param \EE_Ticket $ticket |
|
250 | - * @param int $quantity |
|
251 | - * @return bool |
|
252 | - * @throws EE_Error |
|
253 | - */ |
|
254 | - protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
255 | - { |
|
256 | - if (self::debug) { |
|
257 | - echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity; |
|
258 | - } |
|
259 | - $ticket->increase_reserved($quantity); |
|
260 | - return $ticket->save(); |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * _release_reserved_ticket |
|
267 | - * |
|
268 | - * @access protected |
|
269 | - * @param EE_Ticket $ticket |
|
270 | - * @param int $quantity |
|
271 | - * @return bool |
|
272 | - * @throws EE_Error |
|
273 | - */ |
|
274 | - protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
275 | - { |
|
276 | - if (self::debug) { |
|
277 | - echo '<br /> . . . ticket->ID: ' . $ticket->ID(); |
|
278 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
279 | - } |
|
280 | - $ticket->decrease_reserved($quantity); |
|
281 | - if (self::debug) { |
|
282 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
283 | - } |
|
284 | - return $ticket->save() ? 1 : 0; |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * _ticket_sold_out |
|
291 | - * removes quantities within the ticket selector based on zero ticket availability |
|
292 | - * |
|
293 | - * @access protected |
|
294 | - * @param \EE_Ticket $ticket |
|
295 | - * @return void |
|
296 | - * @throws UnexpectedEntityException |
|
297 | - * @throws EE_Error |
|
298 | - */ |
|
299 | - protected function _ticket_sold_out(EE_Ticket $ticket) |
|
300 | - { |
|
301 | - if (self::debug) { |
|
302 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
303 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
304 | - } |
|
305 | - $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
306 | - } |
|
307 | - |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * _ticket_quantity_decremented |
|
312 | - * adjusts quantities within the ticket selector based on decreased ticket availability |
|
313 | - * |
|
314 | - * @access protected |
|
315 | - * @param \EE_Ticket $ticket |
|
316 | - * @return void |
|
317 | - * @throws UnexpectedEntityException |
|
318 | - * @throws EE_Error |
|
319 | - */ |
|
320 | - protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
321 | - { |
|
322 | - if (self::debug) { |
|
323 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
324 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
325 | - } |
|
326 | - $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - |
|
331 | - /** |
|
332 | - * _get_ticket_and_event_name |
|
333 | - * builds string out of ticket and event name |
|
334 | - * |
|
335 | - * @access protected |
|
336 | - * @param \EE_Ticket $ticket |
|
337 | - * @return string |
|
338 | - * @throws UnexpectedEntityException |
|
339 | - * @throws EE_Error |
|
340 | - */ |
|
341 | - protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
342 | - { |
|
343 | - $event = $ticket->get_related_event(); |
|
344 | - if ($event instanceof EE_Event) { |
|
345 | - $ticket_name = sprintf( |
|
346 | - _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
347 | - $ticket->name(), |
|
348 | - $event->name() |
|
349 | - ); |
|
350 | - } else { |
|
351 | - $ticket_name = $ticket->name(); |
|
352 | - } |
|
353 | - return $ticket_name; |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - |
|
358 | - /********************************** EVENT CART **********************************/ |
|
359 | - |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * ticket_quantity_updated |
|
364 | - * releases or reserves ticket(s) based on quantity passed |
|
365 | - * |
|
366 | - * @access public |
|
367 | - * @param EE_Line_Item $line_item |
|
368 | - * @param int $quantity |
|
369 | - * @return void |
|
370 | - * @throws EE_Error |
|
371 | - */ |
|
372 | - public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
373 | - { |
|
374 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
375 | - if ($ticket instanceof EE_Ticket) { |
|
376 | - if ($quantity > 0) { |
|
377 | - EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
378 | - } else { |
|
379 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
380 | - } |
|
381 | - } |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - |
|
386 | - /** |
|
387 | - * ticket_removed_from_cart |
|
388 | - * releases reserved ticket(s) based on quantity passed |
|
389 | - * |
|
390 | - * @access public |
|
391 | - * @param EE_Ticket $ticket |
|
392 | - * @param int $quantity |
|
393 | - * @return void |
|
394 | - * @throws EE_Error |
|
395 | - */ |
|
396 | - public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
397 | - { |
|
398 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - |
|
403 | - /********************************** POST_NOTICES **********************************/ |
|
404 | - |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * post_notices |
|
409 | - * |
|
410 | - * @access public |
|
411 | - * @return void |
|
412 | - * @throws EE_Error |
|
413 | - */ |
|
414 | - public static function post_notices() |
|
415 | - { |
|
416 | - EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
417 | - } |
|
418 | - |
|
419 | - |
|
420 | - |
|
421 | - /** |
|
422 | - * _post_notices |
|
423 | - * |
|
424 | - * @access protected |
|
425 | - * @return void |
|
426 | - * @throws EE_Error |
|
427 | - */ |
|
428 | - protected function _post_notices() |
|
429 | - { |
|
430 | - if (self::debug) { |
|
431 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
432 | - } |
|
433 | - $refresh_msg = ''; |
|
434 | - $none_added_msg = ''; |
|
435 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
436 | - $refresh_msg = __('Please refresh the page to view updated ticket quantities.', |
|
437 | - 'event_espresso'); |
|
438 | - $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
439 | - } |
|
440 | - if ( ! empty($this->sold_out_tickets)) { |
|
441 | - EE_Error::add_attention( |
|
442 | - sprintf( |
|
443 | - apply_filters( |
|
444 | - 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
445 | - __('We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
446 | - 'event_espresso') |
|
447 | - ), |
|
448 | - '<br />', |
|
449 | - implode('<br />', $this->sold_out_tickets), |
|
450 | - $none_added_msg, |
|
451 | - $refresh_msg |
|
452 | - ) |
|
453 | - ); |
|
454 | - // alter code flow in the Ticket Selector for better UX |
|
455 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
456 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
457 | - $this->sold_out_tickets = array(); |
|
458 | - // and reset the cart |
|
459 | - EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
460 | - } |
|
461 | - if ( ! empty($this->decremented_tickets)) { |
|
462 | - EE_Error::add_attention( |
|
463 | - sprintf( |
|
464 | - apply_filters( |
|
465 | - 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
466 | - __('We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
467 | - 'event_espresso') |
|
468 | - ), |
|
469 | - '<br />', |
|
470 | - implode('<br />', $this->decremented_tickets), |
|
471 | - $none_added_msg, |
|
472 | - $refresh_msg |
|
473 | - ) |
|
474 | - ); |
|
475 | - $this->decremented_tickets = array(); |
|
476 | - } |
|
477 | - } |
|
478 | - |
|
479 | - |
|
480 | - |
|
481 | - /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
482 | - |
|
483 | - |
|
484 | - |
|
485 | - /** |
|
486 | - * _release_all_reserved_tickets_for_transaction |
|
487 | - * releases reserved tickets for all registrations of an EE_Transaction |
|
488 | - * by default, will NOT release tickets for finalized transactions |
|
489 | - * |
|
490 | - * @access protected |
|
491 | - * @param EE_Transaction $transaction |
|
492 | - * @return int |
|
493 | - * @throws EE_Error |
|
494 | - */ |
|
495 | - protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
496 | - { |
|
497 | - if (self::debug) { |
|
498 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
499 | - echo '<br /> . transaction->ID: ' . $transaction->ID(); |
|
500 | - } |
|
501 | - // check if 'finalize_registration' step has been completed... |
|
502 | - $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
503 | - if (self::debug) { |
|
504 | - // DEBUG LOG |
|
505 | - EEH_Debug_Tools::log( |
|
506 | - __CLASS__, __FUNCTION__, __LINE__, |
|
507 | - array('finalized' => $finalized), |
|
508 | - false, 'EE_Transaction: ' . $transaction->ID() |
|
509 | - ); |
|
510 | - } |
|
511 | - // how many tickets were released |
|
512 | - $count = 0; |
|
513 | - if (self::debug) { |
|
514 | - echo '<br /> . . . finalized: ' . $finalized; |
|
515 | - } |
|
516 | - $release_tickets_with_TXN_status = array( |
|
517 | - EEM_Transaction::failed_status_code, |
|
518 | - EEM_Transaction::abandoned_status_code, |
|
519 | - EEM_Transaction::incomplete_status_code, |
|
520 | - ); |
|
521 | - // if the session is getting cleared BEFORE the TXN has been finalized |
|
522 | - if ( ! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
523 | - // let's cancel any reserved tickets |
|
524 | - $registrations = $transaction->registrations(); |
|
525 | - if ( ! empty($registrations)) { |
|
526 | - foreach ($registrations as $registration) { |
|
527 | - if ($registration instanceof EE_Registration) { |
|
528 | - $count += $this->_release_reserved_ticket_for_registration($registration, $transaction); |
|
529 | - } |
|
530 | - } |
|
531 | - } |
|
532 | - } |
|
533 | - return $count; |
|
534 | - } |
|
535 | - |
|
536 | - |
|
537 | - |
|
538 | - /** |
|
539 | - * _release_reserved_ticket_for_registration |
|
540 | - * releases reserved tickets for an EE_Registration |
|
541 | - * by default, will NOT release tickets for APPROVED registrations |
|
542 | - * |
|
543 | - * @access protected |
|
544 | - * @param EE_Registration $registration |
|
545 | - * @param EE_Transaction $transaction |
|
546 | - * @return int |
|
547 | - * @throws EE_Error |
|
548 | - */ |
|
549 | - protected function _release_reserved_ticket_for_registration( |
|
550 | - EE_Registration $registration, |
|
551 | - EE_Transaction $transaction |
|
552 | - ) { |
|
553 | - $STS_ID = $transaction->status_ID(); |
|
554 | - if (self::debug) { |
|
555 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
556 | - echo '<br /> . . registration->ID: ' . $registration->ID(); |
|
557 | - echo '<br /> . . registration->status_ID: ' . $registration->status_ID(); |
|
558 | - echo '<br /> . . transaction->status_ID(): ' . $STS_ID; |
|
559 | - } |
|
560 | - if ( |
|
561 | - // release Tickets for Failed Transactions and Abandoned Transactions |
|
562 | - $STS_ID === EEM_Transaction::failed_status_code |
|
563 | - || $STS_ID === EEM_Transaction::abandoned_status_code |
|
564 | - || ( |
|
565 | - // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
566 | - $STS_ID === EEM_Transaction::incomplete_status_code |
|
567 | - && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
568 | - ) |
|
569 | - ) { |
|
570 | - $ticket = $registration->ticket(); |
|
571 | - if ($ticket instanceof EE_Ticket) { |
|
572 | - return $this->_release_reserved_ticket($ticket); |
|
573 | - } |
|
574 | - } |
|
575 | - return 0; |
|
576 | - } |
|
577 | - |
|
578 | - |
|
579 | - |
|
580 | - /********************************** SESSION_CART_RESET **********************************/ |
|
581 | - |
|
582 | - |
|
583 | - |
|
584 | - /** |
|
585 | - * session_cart_reset |
|
586 | - * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
587 | - * |
|
588 | - * @access public |
|
589 | - * @param EE_Session $session |
|
590 | - * @return void |
|
591 | - * @throws EE_Error |
|
592 | - */ |
|
593 | - public static function session_cart_reset(EE_Session $session) |
|
594 | - { |
|
595 | - if (self::debug) { |
|
596 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
597 | - } |
|
598 | - $cart = $session->cart(); |
|
599 | - if ($cart instanceof EE_Cart) { |
|
600 | - if (self::debug) { |
|
601 | - echo '<br /><br /> cart instance of EE_Cart: '; |
|
602 | - } |
|
603 | - EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart); |
|
604 | - } else { |
|
605 | - if (self::debug) { |
|
606 | - echo '<br /><br /> invalid EE_Cart: '; |
|
607 | - var_dump($cart); |
|
608 | - } |
|
609 | - } |
|
610 | - } |
|
611 | - |
|
612 | - |
|
613 | - |
|
614 | - /** |
|
615 | - * _session_cart_reset |
|
616 | - * releases reserved tickets in the EE_Cart |
|
617 | - * |
|
618 | - * @access protected |
|
619 | - * @param EE_Cart $cart |
|
620 | - * @return void |
|
621 | - * @throws EE_Error |
|
622 | - */ |
|
623 | - protected function _session_cart_reset(EE_Cart $cart) |
|
624 | - { |
|
625 | - if (self::debug) { |
|
626 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
627 | - } |
|
628 | - EE_Registry::instance()->load_helper('Line_Item'); |
|
629 | - $ticket_line_items = $cart->get_tickets(); |
|
630 | - if (empty($ticket_line_items)) { |
|
631 | - return; |
|
632 | - } |
|
633 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
634 | - if (self::debug) { |
|
635 | - echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
636 | - } |
|
637 | - if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
638 | - if (self::debug) { |
|
639 | - echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
640 | - } |
|
641 | - $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
642 | - if ($ticket instanceof EE_Ticket) { |
|
643 | - if (self::debug) { |
|
644 | - echo '<br /> . . ticket->ID(): ' . $ticket->ID(); |
|
645 | - echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
646 | - } |
|
647 | - $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
648 | - } |
|
649 | - } |
|
650 | - } |
|
651 | - if (self::debug) { |
|
652 | - echo '<br /><br /> RESET COMPLETED '; |
|
653 | - } |
|
654 | - } |
|
655 | - |
|
656 | - |
|
657 | - |
|
658 | - /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
659 | - |
|
660 | - |
|
661 | - |
|
662 | - /** |
|
663 | - * session_checkout_reset |
|
664 | - * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
665 | - * |
|
666 | - * @access public |
|
667 | - * @param EE_Session $session |
|
668 | - * @return void |
|
669 | - * @throws EE_Error |
|
670 | - */ |
|
671 | - public static function session_checkout_reset(EE_Session $session) |
|
672 | - { |
|
673 | - $checkout = $session->checkout(); |
|
674 | - if ($checkout instanceof EE_Checkout) { |
|
675 | - EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
676 | - } |
|
677 | - } |
|
678 | - |
|
679 | - |
|
680 | - |
|
681 | - /** |
|
682 | - * _session_checkout_reset |
|
683 | - * releases reserved tickets for the EE_Checkout->transaction |
|
684 | - * |
|
685 | - * @access protected |
|
686 | - * @param EE_Checkout $checkout |
|
687 | - * @return void |
|
688 | - * @throws EE_Error |
|
689 | - */ |
|
690 | - protected function _session_checkout_reset(EE_Checkout $checkout) |
|
691 | - { |
|
692 | - if (self::debug) { |
|
693 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
694 | - } |
|
695 | - // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
696 | - if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
697 | - return; |
|
698 | - } |
|
699 | - $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
700 | - } |
|
701 | - |
|
702 | - |
|
703 | - |
|
704 | - /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
705 | - |
|
706 | - |
|
707 | - |
|
708 | - /** |
|
709 | - * session_expired_reset |
|
710 | - * |
|
711 | - * @access public |
|
712 | - * @param EE_Session $session |
|
713 | - * @return void |
|
714 | - */ |
|
715 | - public static function session_expired_reset(EE_Session $session) |
|
716 | - { |
|
717 | - } |
|
718 | - |
|
719 | - |
|
720 | - |
|
721 | - /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
722 | - |
|
723 | - |
|
724 | - |
|
725 | - /** |
|
726 | - * process_abandoned_transactions |
|
727 | - * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
728 | - * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
729 | - * |
|
730 | - * @access public |
|
731 | - * @param EE_Transaction $transaction |
|
732 | - * @return void |
|
733 | - * @throws EE_Error |
|
734 | - */ |
|
735 | - public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
736 | - { |
|
737 | - // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
738 | - if ($transaction->is_free() || $transaction->paid() > 0) { |
|
739 | - if (self::debug) { |
|
740 | - // DEBUG LOG |
|
741 | - EEH_Debug_Tools::log( |
|
742 | - __CLASS__, __FUNCTION__, __LINE__, |
|
743 | - array($transaction), |
|
744 | - false, 'EE_Transaction: ' . $transaction->ID() |
|
745 | - ); |
|
746 | - } |
|
747 | - return; |
|
748 | - } |
|
749 | - // have their been any successful payments made ? |
|
750 | - $payments = $transaction->payments(); |
|
751 | - foreach ($payments as $payment) { |
|
752 | - if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
753 | - if (self::debug) { |
|
754 | - // DEBUG LOG |
|
755 | - EEH_Debug_Tools::log( |
|
756 | - __CLASS__, __FUNCTION__, __LINE__, |
|
757 | - array($payment), |
|
758 | - false, 'EE_Transaction: ' . $transaction->ID() |
|
759 | - ); |
|
760 | - } |
|
761 | - return; |
|
762 | - } |
|
763 | - } |
|
764 | - // since you haven't even attempted to pay for your ticket... |
|
765 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
766 | - } |
|
767 | - |
|
768 | - |
|
769 | - |
|
770 | - /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
771 | - |
|
772 | - |
|
773 | - |
|
774 | - /** |
|
775 | - * process_abandoned_transactions |
|
776 | - * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
777 | - * |
|
778 | - * @access public |
|
779 | - * @param EE_Transaction $transaction |
|
780 | - * @return void |
|
781 | - * @throws EE_Error |
|
782 | - */ |
|
783 | - public static function process_failed_transactions(EE_Transaction $transaction) |
|
784 | - { |
|
785 | - // since you haven't even attempted to pay for your ticket... |
|
786 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
787 | - } |
|
788 | - |
|
789 | - |
|
790 | - |
|
791 | - /********************************** RESET RESERVATION COUNTS *********************************/ |
|
792 | - |
|
793 | - |
|
794 | - |
|
795 | - /** |
|
796 | - * Resets all ticket and datetime reserved counts to zero |
|
797 | - * Tickets that are currently associated with a Transaction that is in progress |
|
798 | - * |
|
799 | - * @throws \EE_Error |
|
800 | - * @throws \DomainException |
|
801 | - */ |
|
802 | - public static function reset_reservation_counts() |
|
803 | - { |
|
804 | - $total_tickets_released = 0; |
|
805 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
806 | - $valid_reserved_tickets = array(); |
|
807 | - $transactions_in_progress = EEM_Transaction::instance()->get_transactions_in_progress(); |
|
808 | - foreach ($transactions_in_progress as $transaction_in_progress) { |
|
809 | - // if this TXN has been fully completed, then skip it |
|
810 | - if ($transaction_in_progress->reg_step_completed('finalize_registration')) { |
|
811 | - continue; |
|
812 | - } |
|
813 | - /** @var EE_Transaction $transaction_in_progress */ |
|
814 | - $total_line_item = $transaction_in_progress->total_line_item(); |
|
815 | - // $transaction_in_progress->line |
|
816 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
817 | - throw new DomainException( |
|
818 | - esc_html__('Transaction does not have a valid Total Line Item associated with it.', 'event_espresso') |
|
819 | - ); |
|
820 | - } |
|
821 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_reserved_tickets_for_line_item($total_line_item); |
|
822 | - } |
|
823 | - $total_line_items = EEM_Line_Item::instance()->get_total_line_items_just_added_to_cart(); |
|
824 | - foreach ($total_line_items as $total_line_item) { |
|
825 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_reserved_tickets_for_line_item($total_line_item); |
|
826 | - } |
|
827 | - $tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations(); |
|
828 | - foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
829 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
830 | - continue; |
|
831 | - } |
|
832 | - $reserved_qty = $ticket_with_reservations->reserved(); |
|
833 | - foreach ($valid_reserved_tickets as $valid_reserved_ticket) { |
|
834 | - if( |
|
835 | - $valid_reserved_ticket instanceof EE_Line_Item |
|
836 | - && $valid_reserved_ticket->OBJ_ID() === $ticket_with_reservations->ID() |
|
837 | - ) { |
|
838 | - $reserved_qty -= $valid_reserved_ticket->quantity(); |
|
839 | - } |
|
840 | - } |
|
841 | - if ($reserved_qty > 0) { |
|
842 | - $ticket_with_reservations->decrease_reserved($reserved_qty); |
|
843 | - $ticket_with_reservations->save(); |
|
844 | - $total_tickets_released += $reserved_qty; |
|
845 | - } |
|
846 | - } |
|
847 | - return $total_tickets_released; |
|
848 | - } |
|
849 | - |
|
850 | - |
|
851 | - |
|
852 | - private static function get_reserved_tickets_for_line_item(EE_Line_Item $total_line_item) |
|
853 | - { |
|
854 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
855 | - $valid_reserved_tickets = array(); |
|
856 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
857 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
858 | - if ($ticket_line_item instanceof EE_Line_Item) { |
|
859 | - $valid_reserved_tickets[] = $ticket_line_item; |
|
860 | - } |
|
861 | - } |
|
862 | - return $valid_reserved_tickets; |
|
863 | - } |
|
24 | + const debug = false; // true false |
|
25 | + |
|
26 | + /** |
|
27 | + * an array of raw ticket data from EED_Ticket_Selector |
|
28 | + * |
|
29 | + * @var array $ticket_selections |
|
30 | + */ |
|
31 | + protected $ticket_selections = array(); |
|
32 | + |
|
33 | + /** |
|
34 | + * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
35 | + * according to how they are displayed in the actual Ticket_Selector |
|
36 | + * this tracks the current row being processed |
|
37 | + * |
|
38 | + * @var int $current_row |
|
39 | + */ |
|
40 | + protected $current_row = 0; |
|
41 | + |
|
42 | + /** |
|
43 | + * an array for tracking names of tickets that have sold out |
|
44 | + * |
|
45 | + * @var array $sold_out_tickets |
|
46 | + */ |
|
47 | + protected $sold_out_tickets = array(); |
|
48 | + |
|
49 | + /** |
|
50 | + * an array for tracking names of tickets that have had their quantities reduced |
|
51 | + * |
|
52 | + * @var array $decremented_tickets |
|
53 | + */ |
|
54 | + protected $decremented_tickets = array(); |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
60 | + * |
|
61 | + * @access public |
|
62 | + * @return void |
|
63 | + */ |
|
64 | + public static function set_hooks() |
|
65 | + { |
|
66 | + // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
67 | + add_filter('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
68 | + array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
69 | + 20, 3 |
|
70 | + ); |
|
71 | + // add notices for sold out tickets |
|
72 | + add_action('AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
73 | + array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
74 | + 10 |
|
75 | + ); |
|
76 | + // handle ticket quantities adjusted in cart |
|
77 | + //add_action( |
|
78 | + // 'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated', |
|
79 | + // array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ), |
|
80 | + // 10, 2 |
|
81 | + //); |
|
82 | + // handle tickets deleted from cart |
|
83 | + add_action( |
|
84 | + 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
85 | + array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
86 | + 10, 2 |
|
87 | + ); |
|
88 | + // handle emptied carts |
|
89 | + add_action( |
|
90 | + 'AHEE__EE_Session__reset_cart__before_reset', |
|
91 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
92 | + 10, 1 |
|
93 | + ); |
|
94 | + add_action( |
|
95 | + 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
96 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
97 | + 10, 1 |
|
98 | + ); |
|
99 | + // handle cancelled registrations |
|
100 | + add_action( |
|
101 | + 'AHEE__EE_Session__reset_checkout__before_reset', |
|
102 | + array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
103 | + 10, 1 |
|
104 | + ); |
|
105 | + // cron tasks |
|
106 | + add_action( |
|
107 | + 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions__abandoned_transaction', |
|
108 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
109 | + 10, 1 |
|
110 | + ); |
|
111 | + add_action( |
|
112 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
113 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
114 | + 10, 1 |
|
115 | + ); |
|
116 | + add_action( |
|
117 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
118 | + array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
119 | + 10, 1 |
|
120 | + ); |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @return void |
|
130 | + */ |
|
131 | + public static function set_hooks_admin() |
|
132 | + { |
|
133 | + EED_Ticket_Sales_Monitor::set_hooks(); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * @return EED_Ticket_Sales_Monitor|EED_Module |
|
140 | + */ |
|
141 | + public static function instance() |
|
142 | + { |
|
143 | + return parent::get_instance(__CLASS__); |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * run |
|
150 | + * |
|
151 | + * @access public |
|
152 | + * @param WP_Query $WP_Query |
|
153 | + * @return void |
|
154 | + */ |
|
155 | + public function run($WP_Query) |
|
156 | + { |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + |
|
161 | + /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
162 | + |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * validate_ticket_sales |
|
167 | + * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
168 | + * |
|
169 | + * @access public |
|
170 | + * @param int $qty |
|
171 | + * @param \EE_Ticket $ticket |
|
172 | + * @return bool |
|
173 | + * @throws UnexpectedEntityException |
|
174 | + * @throws EE_Error |
|
175 | + */ |
|
176 | + public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
177 | + { |
|
178 | + $qty = absint($qty); |
|
179 | + if ($qty > 0) { |
|
180 | + $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
181 | + } |
|
182 | + if (self::debug) { |
|
183 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()'; |
|
184 | + echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>'; |
|
185 | + } |
|
186 | + return $qty; |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * _validate_ticket_sale |
|
193 | + * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
194 | + * |
|
195 | + * @access protected |
|
196 | + * @param \EE_Ticket $ticket |
|
197 | + * @param int $qty |
|
198 | + * @return int |
|
199 | + * @throws UnexpectedEntityException |
|
200 | + * @throws EE_Error |
|
201 | + */ |
|
202 | + protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
203 | + { |
|
204 | + if (self::debug) { |
|
205 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
206 | + } |
|
207 | + if ( ! $ticket instanceof EE_Ticket) { |
|
208 | + return 0; |
|
209 | + } |
|
210 | + if (self::debug) { |
|
211 | + echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
212 | + echo '<br /> . original ticket->reserved: ' . $ticket->reserved(); |
|
213 | + } |
|
214 | + $ticket->refresh_from_db(); |
|
215 | + // first let's determine the ticket availability based on sales |
|
216 | + $available = $ticket->qty('saleable'); |
|
217 | + if (self::debug) { |
|
218 | + echo '<br /> . . . ticket->qty: ' . $ticket->qty(); |
|
219 | + echo '<br /> . . . ticket->sold: ' . $ticket->sold(); |
|
220 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
221 | + echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
222 | + echo '<br /> . . . available: ' . $available; |
|
223 | + } |
|
224 | + if ($available < 1) { |
|
225 | + $this->_ticket_sold_out($ticket); |
|
226 | + return 0; |
|
227 | + } |
|
228 | + if (self::debug) { |
|
229 | + echo '<br /> . . . qty: ' . $qty; |
|
230 | + } |
|
231 | + if ($available < $qty) { |
|
232 | + $qty = $available; |
|
233 | + if (self::debug) { |
|
234 | + echo '<br /> . . . QTY ADJUSTED: ' . $qty; |
|
235 | + } |
|
236 | + $this->_ticket_quantity_decremented($ticket); |
|
237 | + } |
|
238 | + $this->_reserve_ticket($ticket, $qty); |
|
239 | + return $qty; |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + |
|
244 | + /** |
|
245 | + * _reserve_ticket |
|
246 | + * increments ticket reserved based on quantity passed |
|
247 | + * |
|
248 | + * @access protected |
|
249 | + * @param \EE_Ticket $ticket |
|
250 | + * @param int $quantity |
|
251 | + * @return bool |
|
252 | + * @throws EE_Error |
|
253 | + */ |
|
254 | + protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
255 | + { |
|
256 | + if (self::debug) { |
|
257 | + echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity; |
|
258 | + } |
|
259 | + $ticket->increase_reserved($quantity); |
|
260 | + return $ticket->save(); |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * _release_reserved_ticket |
|
267 | + * |
|
268 | + * @access protected |
|
269 | + * @param EE_Ticket $ticket |
|
270 | + * @param int $quantity |
|
271 | + * @return bool |
|
272 | + * @throws EE_Error |
|
273 | + */ |
|
274 | + protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
275 | + { |
|
276 | + if (self::debug) { |
|
277 | + echo '<br /> . . . ticket->ID: ' . $ticket->ID(); |
|
278 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
279 | + } |
|
280 | + $ticket->decrease_reserved($quantity); |
|
281 | + if (self::debug) { |
|
282 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
283 | + } |
|
284 | + return $ticket->save() ? 1 : 0; |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * _ticket_sold_out |
|
291 | + * removes quantities within the ticket selector based on zero ticket availability |
|
292 | + * |
|
293 | + * @access protected |
|
294 | + * @param \EE_Ticket $ticket |
|
295 | + * @return void |
|
296 | + * @throws UnexpectedEntityException |
|
297 | + * @throws EE_Error |
|
298 | + */ |
|
299 | + protected function _ticket_sold_out(EE_Ticket $ticket) |
|
300 | + { |
|
301 | + if (self::debug) { |
|
302 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
303 | + echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
304 | + } |
|
305 | + $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
306 | + } |
|
307 | + |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * _ticket_quantity_decremented |
|
312 | + * adjusts quantities within the ticket selector based on decreased ticket availability |
|
313 | + * |
|
314 | + * @access protected |
|
315 | + * @param \EE_Ticket $ticket |
|
316 | + * @return void |
|
317 | + * @throws UnexpectedEntityException |
|
318 | + * @throws EE_Error |
|
319 | + */ |
|
320 | + protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
321 | + { |
|
322 | + if (self::debug) { |
|
323 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
324 | + echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
325 | + } |
|
326 | + $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + |
|
331 | + /** |
|
332 | + * _get_ticket_and_event_name |
|
333 | + * builds string out of ticket and event name |
|
334 | + * |
|
335 | + * @access protected |
|
336 | + * @param \EE_Ticket $ticket |
|
337 | + * @return string |
|
338 | + * @throws UnexpectedEntityException |
|
339 | + * @throws EE_Error |
|
340 | + */ |
|
341 | + protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
342 | + { |
|
343 | + $event = $ticket->get_related_event(); |
|
344 | + if ($event instanceof EE_Event) { |
|
345 | + $ticket_name = sprintf( |
|
346 | + _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
347 | + $ticket->name(), |
|
348 | + $event->name() |
|
349 | + ); |
|
350 | + } else { |
|
351 | + $ticket_name = $ticket->name(); |
|
352 | + } |
|
353 | + return $ticket_name; |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + |
|
358 | + /********************************** EVENT CART **********************************/ |
|
359 | + |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * ticket_quantity_updated |
|
364 | + * releases or reserves ticket(s) based on quantity passed |
|
365 | + * |
|
366 | + * @access public |
|
367 | + * @param EE_Line_Item $line_item |
|
368 | + * @param int $quantity |
|
369 | + * @return void |
|
370 | + * @throws EE_Error |
|
371 | + */ |
|
372 | + public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
373 | + { |
|
374 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
375 | + if ($ticket instanceof EE_Ticket) { |
|
376 | + if ($quantity > 0) { |
|
377 | + EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
378 | + } else { |
|
379 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
380 | + } |
|
381 | + } |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + |
|
386 | + /** |
|
387 | + * ticket_removed_from_cart |
|
388 | + * releases reserved ticket(s) based on quantity passed |
|
389 | + * |
|
390 | + * @access public |
|
391 | + * @param EE_Ticket $ticket |
|
392 | + * @param int $quantity |
|
393 | + * @return void |
|
394 | + * @throws EE_Error |
|
395 | + */ |
|
396 | + public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
397 | + { |
|
398 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + |
|
403 | + /********************************** POST_NOTICES **********************************/ |
|
404 | + |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * post_notices |
|
409 | + * |
|
410 | + * @access public |
|
411 | + * @return void |
|
412 | + * @throws EE_Error |
|
413 | + */ |
|
414 | + public static function post_notices() |
|
415 | + { |
|
416 | + EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
417 | + } |
|
418 | + |
|
419 | + |
|
420 | + |
|
421 | + /** |
|
422 | + * _post_notices |
|
423 | + * |
|
424 | + * @access protected |
|
425 | + * @return void |
|
426 | + * @throws EE_Error |
|
427 | + */ |
|
428 | + protected function _post_notices() |
|
429 | + { |
|
430 | + if (self::debug) { |
|
431 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
432 | + } |
|
433 | + $refresh_msg = ''; |
|
434 | + $none_added_msg = ''; |
|
435 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
436 | + $refresh_msg = __('Please refresh the page to view updated ticket quantities.', |
|
437 | + 'event_espresso'); |
|
438 | + $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
439 | + } |
|
440 | + if ( ! empty($this->sold_out_tickets)) { |
|
441 | + EE_Error::add_attention( |
|
442 | + sprintf( |
|
443 | + apply_filters( |
|
444 | + 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
445 | + __('We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
446 | + 'event_espresso') |
|
447 | + ), |
|
448 | + '<br />', |
|
449 | + implode('<br />', $this->sold_out_tickets), |
|
450 | + $none_added_msg, |
|
451 | + $refresh_msg |
|
452 | + ) |
|
453 | + ); |
|
454 | + // alter code flow in the Ticket Selector for better UX |
|
455 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
456 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
457 | + $this->sold_out_tickets = array(); |
|
458 | + // and reset the cart |
|
459 | + EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
460 | + } |
|
461 | + if ( ! empty($this->decremented_tickets)) { |
|
462 | + EE_Error::add_attention( |
|
463 | + sprintf( |
|
464 | + apply_filters( |
|
465 | + 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
466 | + __('We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
467 | + 'event_espresso') |
|
468 | + ), |
|
469 | + '<br />', |
|
470 | + implode('<br />', $this->decremented_tickets), |
|
471 | + $none_added_msg, |
|
472 | + $refresh_msg |
|
473 | + ) |
|
474 | + ); |
|
475 | + $this->decremented_tickets = array(); |
|
476 | + } |
|
477 | + } |
|
478 | + |
|
479 | + |
|
480 | + |
|
481 | + /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
482 | + |
|
483 | + |
|
484 | + |
|
485 | + /** |
|
486 | + * _release_all_reserved_tickets_for_transaction |
|
487 | + * releases reserved tickets for all registrations of an EE_Transaction |
|
488 | + * by default, will NOT release tickets for finalized transactions |
|
489 | + * |
|
490 | + * @access protected |
|
491 | + * @param EE_Transaction $transaction |
|
492 | + * @return int |
|
493 | + * @throws EE_Error |
|
494 | + */ |
|
495 | + protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
496 | + { |
|
497 | + if (self::debug) { |
|
498 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
499 | + echo '<br /> . transaction->ID: ' . $transaction->ID(); |
|
500 | + } |
|
501 | + // check if 'finalize_registration' step has been completed... |
|
502 | + $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
503 | + if (self::debug) { |
|
504 | + // DEBUG LOG |
|
505 | + EEH_Debug_Tools::log( |
|
506 | + __CLASS__, __FUNCTION__, __LINE__, |
|
507 | + array('finalized' => $finalized), |
|
508 | + false, 'EE_Transaction: ' . $transaction->ID() |
|
509 | + ); |
|
510 | + } |
|
511 | + // how many tickets were released |
|
512 | + $count = 0; |
|
513 | + if (self::debug) { |
|
514 | + echo '<br /> . . . finalized: ' . $finalized; |
|
515 | + } |
|
516 | + $release_tickets_with_TXN_status = array( |
|
517 | + EEM_Transaction::failed_status_code, |
|
518 | + EEM_Transaction::abandoned_status_code, |
|
519 | + EEM_Transaction::incomplete_status_code, |
|
520 | + ); |
|
521 | + // if the session is getting cleared BEFORE the TXN has been finalized |
|
522 | + if ( ! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
523 | + // let's cancel any reserved tickets |
|
524 | + $registrations = $transaction->registrations(); |
|
525 | + if ( ! empty($registrations)) { |
|
526 | + foreach ($registrations as $registration) { |
|
527 | + if ($registration instanceof EE_Registration) { |
|
528 | + $count += $this->_release_reserved_ticket_for_registration($registration, $transaction); |
|
529 | + } |
|
530 | + } |
|
531 | + } |
|
532 | + } |
|
533 | + return $count; |
|
534 | + } |
|
535 | + |
|
536 | + |
|
537 | + |
|
538 | + /** |
|
539 | + * _release_reserved_ticket_for_registration |
|
540 | + * releases reserved tickets for an EE_Registration |
|
541 | + * by default, will NOT release tickets for APPROVED registrations |
|
542 | + * |
|
543 | + * @access protected |
|
544 | + * @param EE_Registration $registration |
|
545 | + * @param EE_Transaction $transaction |
|
546 | + * @return int |
|
547 | + * @throws EE_Error |
|
548 | + */ |
|
549 | + protected function _release_reserved_ticket_for_registration( |
|
550 | + EE_Registration $registration, |
|
551 | + EE_Transaction $transaction |
|
552 | + ) { |
|
553 | + $STS_ID = $transaction->status_ID(); |
|
554 | + if (self::debug) { |
|
555 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
556 | + echo '<br /> . . registration->ID: ' . $registration->ID(); |
|
557 | + echo '<br /> . . registration->status_ID: ' . $registration->status_ID(); |
|
558 | + echo '<br /> . . transaction->status_ID(): ' . $STS_ID; |
|
559 | + } |
|
560 | + if ( |
|
561 | + // release Tickets for Failed Transactions and Abandoned Transactions |
|
562 | + $STS_ID === EEM_Transaction::failed_status_code |
|
563 | + || $STS_ID === EEM_Transaction::abandoned_status_code |
|
564 | + || ( |
|
565 | + // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
566 | + $STS_ID === EEM_Transaction::incomplete_status_code |
|
567 | + && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
568 | + ) |
|
569 | + ) { |
|
570 | + $ticket = $registration->ticket(); |
|
571 | + if ($ticket instanceof EE_Ticket) { |
|
572 | + return $this->_release_reserved_ticket($ticket); |
|
573 | + } |
|
574 | + } |
|
575 | + return 0; |
|
576 | + } |
|
577 | + |
|
578 | + |
|
579 | + |
|
580 | + /********************************** SESSION_CART_RESET **********************************/ |
|
581 | + |
|
582 | + |
|
583 | + |
|
584 | + /** |
|
585 | + * session_cart_reset |
|
586 | + * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
587 | + * |
|
588 | + * @access public |
|
589 | + * @param EE_Session $session |
|
590 | + * @return void |
|
591 | + * @throws EE_Error |
|
592 | + */ |
|
593 | + public static function session_cart_reset(EE_Session $session) |
|
594 | + { |
|
595 | + if (self::debug) { |
|
596 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
597 | + } |
|
598 | + $cart = $session->cart(); |
|
599 | + if ($cart instanceof EE_Cart) { |
|
600 | + if (self::debug) { |
|
601 | + echo '<br /><br /> cart instance of EE_Cart: '; |
|
602 | + } |
|
603 | + EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart); |
|
604 | + } else { |
|
605 | + if (self::debug) { |
|
606 | + echo '<br /><br /> invalid EE_Cart: '; |
|
607 | + var_dump($cart); |
|
608 | + } |
|
609 | + } |
|
610 | + } |
|
611 | + |
|
612 | + |
|
613 | + |
|
614 | + /** |
|
615 | + * _session_cart_reset |
|
616 | + * releases reserved tickets in the EE_Cart |
|
617 | + * |
|
618 | + * @access protected |
|
619 | + * @param EE_Cart $cart |
|
620 | + * @return void |
|
621 | + * @throws EE_Error |
|
622 | + */ |
|
623 | + protected function _session_cart_reset(EE_Cart $cart) |
|
624 | + { |
|
625 | + if (self::debug) { |
|
626 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
627 | + } |
|
628 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
629 | + $ticket_line_items = $cart->get_tickets(); |
|
630 | + if (empty($ticket_line_items)) { |
|
631 | + return; |
|
632 | + } |
|
633 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
634 | + if (self::debug) { |
|
635 | + echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
636 | + } |
|
637 | + if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
638 | + if (self::debug) { |
|
639 | + echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
640 | + } |
|
641 | + $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
642 | + if ($ticket instanceof EE_Ticket) { |
|
643 | + if (self::debug) { |
|
644 | + echo '<br /> . . ticket->ID(): ' . $ticket->ID(); |
|
645 | + echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
646 | + } |
|
647 | + $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
648 | + } |
|
649 | + } |
|
650 | + } |
|
651 | + if (self::debug) { |
|
652 | + echo '<br /><br /> RESET COMPLETED '; |
|
653 | + } |
|
654 | + } |
|
655 | + |
|
656 | + |
|
657 | + |
|
658 | + /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
659 | + |
|
660 | + |
|
661 | + |
|
662 | + /** |
|
663 | + * session_checkout_reset |
|
664 | + * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
665 | + * |
|
666 | + * @access public |
|
667 | + * @param EE_Session $session |
|
668 | + * @return void |
|
669 | + * @throws EE_Error |
|
670 | + */ |
|
671 | + public static function session_checkout_reset(EE_Session $session) |
|
672 | + { |
|
673 | + $checkout = $session->checkout(); |
|
674 | + if ($checkout instanceof EE_Checkout) { |
|
675 | + EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
676 | + } |
|
677 | + } |
|
678 | + |
|
679 | + |
|
680 | + |
|
681 | + /** |
|
682 | + * _session_checkout_reset |
|
683 | + * releases reserved tickets for the EE_Checkout->transaction |
|
684 | + * |
|
685 | + * @access protected |
|
686 | + * @param EE_Checkout $checkout |
|
687 | + * @return void |
|
688 | + * @throws EE_Error |
|
689 | + */ |
|
690 | + protected function _session_checkout_reset(EE_Checkout $checkout) |
|
691 | + { |
|
692 | + if (self::debug) { |
|
693 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
694 | + } |
|
695 | + // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
696 | + if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
697 | + return; |
|
698 | + } |
|
699 | + $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
700 | + } |
|
701 | + |
|
702 | + |
|
703 | + |
|
704 | + /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
705 | + |
|
706 | + |
|
707 | + |
|
708 | + /** |
|
709 | + * session_expired_reset |
|
710 | + * |
|
711 | + * @access public |
|
712 | + * @param EE_Session $session |
|
713 | + * @return void |
|
714 | + */ |
|
715 | + public static function session_expired_reset(EE_Session $session) |
|
716 | + { |
|
717 | + } |
|
718 | + |
|
719 | + |
|
720 | + |
|
721 | + /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
722 | + |
|
723 | + |
|
724 | + |
|
725 | + /** |
|
726 | + * process_abandoned_transactions |
|
727 | + * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
728 | + * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
729 | + * |
|
730 | + * @access public |
|
731 | + * @param EE_Transaction $transaction |
|
732 | + * @return void |
|
733 | + * @throws EE_Error |
|
734 | + */ |
|
735 | + public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
736 | + { |
|
737 | + // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
738 | + if ($transaction->is_free() || $transaction->paid() > 0) { |
|
739 | + if (self::debug) { |
|
740 | + // DEBUG LOG |
|
741 | + EEH_Debug_Tools::log( |
|
742 | + __CLASS__, __FUNCTION__, __LINE__, |
|
743 | + array($transaction), |
|
744 | + false, 'EE_Transaction: ' . $transaction->ID() |
|
745 | + ); |
|
746 | + } |
|
747 | + return; |
|
748 | + } |
|
749 | + // have their been any successful payments made ? |
|
750 | + $payments = $transaction->payments(); |
|
751 | + foreach ($payments as $payment) { |
|
752 | + if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
753 | + if (self::debug) { |
|
754 | + // DEBUG LOG |
|
755 | + EEH_Debug_Tools::log( |
|
756 | + __CLASS__, __FUNCTION__, __LINE__, |
|
757 | + array($payment), |
|
758 | + false, 'EE_Transaction: ' . $transaction->ID() |
|
759 | + ); |
|
760 | + } |
|
761 | + return; |
|
762 | + } |
|
763 | + } |
|
764 | + // since you haven't even attempted to pay for your ticket... |
|
765 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
766 | + } |
|
767 | + |
|
768 | + |
|
769 | + |
|
770 | + /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
771 | + |
|
772 | + |
|
773 | + |
|
774 | + /** |
|
775 | + * process_abandoned_transactions |
|
776 | + * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
777 | + * |
|
778 | + * @access public |
|
779 | + * @param EE_Transaction $transaction |
|
780 | + * @return void |
|
781 | + * @throws EE_Error |
|
782 | + */ |
|
783 | + public static function process_failed_transactions(EE_Transaction $transaction) |
|
784 | + { |
|
785 | + // since you haven't even attempted to pay for your ticket... |
|
786 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
787 | + } |
|
788 | + |
|
789 | + |
|
790 | + |
|
791 | + /********************************** RESET RESERVATION COUNTS *********************************/ |
|
792 | + |
|
793 | + |
|
794 | + |
|
795 | + /** |
|
796 | + * Resets all ticket and datetime reserved counts to zero |
|
797 | + * Tickets that are currently associated with a Transaction that is in progress |
|
798 | + * |
|
799 | + * @throws \EE_Error |
|
800 | + * @throws \DomainException |
|
801 | + */ |
|
802 | + public static function reset_reservation_counts() |
|
803 | + { |
|
804 | + $total_tickets_released = 0; |
|
805 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
806 | + $valid_reserved_tickets = array(); |
|
807 | + $transactions_in_progress = EEM_Transaction::instance()->get_transactions_in_progress(); |
|
808 | + foreach ($transactions_in_progress as $transaction_in_progress) { |
|
809 | + // if this TXN has been fully completed, then skip it |
|
810 | + if ($transaction_in_progress->reg_step_completed('finalize_registration')) { |
|
811 | + continue; |
|
812 | + } |
|
813 | + /** @var EE_Transaction $transaction_in_progress */ |
|
814 | + $total_line_item = $transaction_in_progress->total_line_item(); |
|
815 | + // $transaction_in_progress->line |
|
816 | + if (! $total_line_item instanceof EE_Line_Item) { |
|
817 | + throw new DomainException( |
|
818 | + esc_html__('Transaction does not have a valid Total Line Item associated with it.', 'event_espresso') |
|
819 | + ); |
|
820 | + } |
|
821 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_reserved_tickets_for_line_item($total_line_item); |
|
822 | + } |
|
823 | + $total_line_items = EEM_Line_Item::instance()->get_total_line_items_just_added_to_cart(); |
|
824 | + foreach ($total_line_items as $total_line_item) { |
|
825 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_reserved_tickets_for_line_item($total_line_item); |
|
826 | + } |
|
827 | + $tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations(); |
|
828 | + foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
829 | + if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
830 | + continue; |
|
831 | + } |
|
832 | + $reserved_qty = $ticket_with_reservations->reserved(); |
|
833 | + foreach ($valid_reserved_tickets as $valid_reserved_ticket) { |
|
834 | + if( |
|
835 | + $valid_reserved_ticket instanceof EE_Line_Item |
|
836 | + && $valid_reserved_ticket->OBJ_ID() === $ticket_with_reservations->ID() |
|
837 | + ) { |
|
838 | + $reserved_qty -= $valid_reserved_ticket->quantity(); |
|
839 | + } |
|
840 | + } |
|
841 | + if ($reserved_qty > 0) { |
|
842 | + $ticket_with_reservations->decrease_reserved($reserved_qty); |
|
843 | + $ticket_with_reservations->save(); |
|
844 | + $total_tickets_released += $reserved_qty; |
|
845 | + } |
|
846 | + } |
|
847 | + return $total_tickets_released; |
|
848 | + } |
|
849 | + |
|
850 | + |
|
851 | + |
|
852 | + private static function get_reserved_tickets_for_line_item(EE_Line_Item $total_line_item) |
|
853 | + { |
|
854 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
855 | + $valid_reserved_tickets = array(); |
|
856 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
857 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
858 | + if ($ticket_line_item instanceof EE_Line_Item) { |
|
859 | + $valid_reserved_tickets[] = $ticket_line_item; |
|
860 | + } |
|
861 | + } |
|
862 | + return $valid_reserved_tickets; |
|
863 | + } |
|
864 | 864 | |
865 | 865 | } |
866 | 866 | // End of file EED_Ticket_Sales_Monitor.module.php |