@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | */ |
114 | 114 | protected function getLoader() |
115 | 115 | { |
116 | - if (!$this->loader instanceof LoaderInterface) { |
|
116 | + if ( ! $this->loader instanceof LoaderInterface) { |
|
117 | 117 | $this->loader = LoaderFactory::getLoader(); |
118 | 118 | } |
119 | 119 | return $this->loader; |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
151 | 151 | wp_enqueue_script( |
152 | 152 | 'batch_runner_init', |
153 | - BATCH_URL . 'assets/batch_runner_init.js', |
|
153 | + BATCH_URL.'assets/batch_runner_init.js', |
|
154 | 154 | array('batch_runner'), |
155 | 155 | EVENT_ESPRESSO_VERSION, |
156 | 156 | true |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
175 | 175 | wp_enqueue_script( |
176 | 176 | 'batch_file_runner_init', |
177 | - BATCH_URL . 'assets/batch_file_runner_init.js', |
|
177 | + BATCH_URL.'assets/batch_file_runner_init.js', |
|
178 | 178 | array('batch_runner'), |
179 | 179 | EVENT_ESPRESSO_VERSION, |
180 | 180 | true |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | array( |
187 | 187 | 'download_and_redirecting' => sprintf( |
188 | 188 | __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'), |
189 | - '<a href="' . $_REQUEST['return_url'] . '">', |
|
189 | + '<a href="'.$_REQUEST['return_url'].'">', |
|
190 | 190 | '</a>' |
191 | 191 | ), |
192 | 192 | 'return_url' => $_REQUEST['return_url'], |
@@ -204,26 +204,26 @@ discard block |
||
204 | 204 | protected function _enqueue_batch_job_scripts_and_styles_and_start_job() |
205 | 205 | { |
206 | 206 | // just copy the bits of EE admin's eei18n that we need in the JS |
207 | - EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__( |
|
207 | + EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__( |
|
208 | 208 | 'An error occurred and the job has been stopped. Please refresh the page to try again.', |
209 | 209 | 'event_espresso' |
210 | 210 | ); |
211 | 211 | wp_register_script( |
212 | 212 | 'progress_bar', |
213 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
213 | + EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.js', |
|
214 | 214 | array('jquery'), |
215 | 215 | EVENT_ESPRESSO_VERSION, |
216 | 216 | true |
217 | 217 | ); |
218 | 218 | wp_enqueue_style( |
219 | 219 | 'progress_bar', |
220 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
220 | + EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.css', |
|
221 | 221 | array(), |
222 | 222 | EVENT_ESPRESSO_VERSION |
223 | 223 | ); |
224 | 224 | wp_enqueue_script( |
225 | 225 | 'batch_runner', |
226 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
226 | + EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/batch_runner.js', |
|
227 | 227 | array('progress_bar', CoreAssetManager::JS_HANDLE_CORE), |
228 | 228 | EVENT_ESPRESSO_VERSION, |
229 | 229 | true |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | public function override_template($template) |
251 | 251 | { |
252 | 252 | if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
253 | - return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html'; |
|
253 | + return EE_MODULES.'batch'.DS.'templates'.DS.'batch_frontend_wrapper.template.html'; |
|
254 | 254 | } |
255 | 255 | return $template; |
256 | 256 | } |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | public function show_admin_page() |
278 | 278 | { |
279 | 279 | echo EEH_Template::locate_template( |
280 | - EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html', |
|
280 | + EE_MODULES.'batch'.DS.'templates'.DS.'batch_wrapper.template.html', |
|
281 | 281 | array('batch_request_type' => $this->batch_request_type()) |
282 | 282 | ); |
283 | 283 | } |
@@ -29,355 +29,355 @@ |
||
29 | 29 | class EED_Batch extends EED_Module |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
34 | - * processes data only |
|
35 | - */ |
|
36 | - const batch_job = 'job'; |
|
37 | - /** |
|
38 | - * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
39 | - * produces a file for download |
|
40 | - */ |
|
41 | - const batch_file_job = 'file'; |
|
42 | - /** |
|
43 | - * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT |
|
44 | - * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ] |
|
45 | - * at all |
|
46 | - */ |
|
47 | - const batch_not_job = 'none'; |
|
32 | + /** |
|
33 | + * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
34 | + * processes data only |
|
35 | + */ |
|
36 | + const batch_job = 'job'; |
|
37 | + /** |
|
38 | + * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that |
|
39 | + * produces a file for download |
|
40 | + */ |
|
41 | + const batch_file_job = 'file'; |
|
42 | + /** |
|
43 | + * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT |
|
44 | + * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ] |
|
45 | + * at all |
|
46 | + */ |
|
47 | + const batch_not_job = 'none'; |
|
48 | 48 | |
49 | - /** |
|
50 | - * |
|
51 | - * @var string 'file', or 'job', or false to indicate its not a batch request at all |
|
52 | - */ |
|
53 | - protected $_batch_request_type = null; |
|
49 | + /** |
|
50 | + * |
|
51 | + * @var string 'file', or 'job', or false to indicate its not a batch request at all |
|
52 | + */ |
|
53 | + protected $_batch_request_type = null; |
|
54 | 54 | |
55 | - /** |
|
56 | - * Because we want to use the response in both the localized JS and in the body |
|
57 | - * we need to make this response available between method calls |
|
58 | - * |
|
59 | - * @var \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
60 | - */ |
|
61 | - protected $_job_step_response = null; |
|
55 | + /** |
|
56 | + * Because we want to use the response in both the localized JS and in the body |
|
57 | + * we need to make this response available between method calls |
|
58 | + * |
|
59 | + * @var \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
60 | + */ |
|
61 | + protected $_job_step_response = null; |
|
62 | 62 | |
63 | - /** |
|
64 | - * @var LoaderInterface |
|
65 | - */ |
|
66 | - protected $loader; |
|
63 | + /** |
|
64 | + * @var LoaderInterface |
|
65 | + */ |
|
66 | + protected $loader; |
|
67 | 67 | |
68 | - /** |
|
69 | - * Gets the batch instance |
|
70 | - * |
|
71 | - * @return EED_Batch |
|
72 | - */ |
|
73 | - public static function instance() |
|
74 | - { |
|
75 | - return self::get_instance(); |
|
76 | - } |
|
68 | + /** |
|
69 | + * Gets the batch instance |
|
70 | + * |
|
71 | + * @return EED_Batch |
|
72 | + */ |
|
73 | + public static function instance() |
|
74 | + { |
|
75 | + return self::get_instance(); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Sets hooks to enable batch jobs on the frontend. Disabled by default |
|
80 | - * because it's an attack vector and there are currently no implementations |
|
81 | - */ |
|
82 | - public static function set_hooks() |
|
83 | - { |
|
84 | - // because this is a possibel attack vector, let's have this disabled until |
|
85 | - // we at least have a real use for it on the frontend |
|
86 | - if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) { |
|
87 | - add_action('wp_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
88 | - add_filter('template_include', array(self::instance(), 'override_template'), 99); |
|
89 | - } |
|
90 | - } |
|
78 | + /** |
|
79 | + * Sets hooks to enable batch jobs on the frontend. Disabled by default |
|
80 | + * because it's an attack vector and there are currently no implementations |
|
81 | + */ |
|
82 | + public static function set_hooks() |
|
83 | + { |
|
84 | + // because this is a possibel attack vector, let's have this disabled until |
|
85 | + // we at least have a real use for it on the frontend |
|
86 | + if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) { |
|
87 | + add_action('wp_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
88 | + add_filter('template_include', array(self::instance(), 'override_template'), 99); |
|
89 | + } |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Initializes some hooks for the admin in order to run batch jobs |
|
94 | - */ |
|
95 | - public static function set_hooks_admin() |
|
96 | - { |
|
97 | - add_action('admin_menu', array(self::instance(), 'register_admin_pages')); |
|
98 | - add_action('admin_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
92 | + /** |
|
93 | + * Initializes some hooks for the admin in order to run batch jobs |
|
94 | + */ |
|
95 | + public static function set_hooks_admin() |
|
96 | + { |
|
97 | + add_action('admin_menu', array(self::instance(), 'register_admin_pages')); |
|
98 | + add_action('admin_enqueue_scripts', array(self::instance(), 'enqueue_scripts')); |
|
99 | 99 | |
100 | - // ajax |
|
101 | - add_action('wp_ajax_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
102 | - add_action('wp_ajax_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
103 | - add_action('wp_ajax_nopriv_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
104 | - add_action('wp_ajax_nopriv_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
105 | - } |
|
100 | + // ajax |
|
101 | + add_action('wp_ajax_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
102 | + add_action('wp_ajax_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
103 | + add_action('wp_ajax_nopriv_espresso_batch_continue', array(self::instance(), 'batch_continue')); |
|
104 | + add_action('wp_ajax_nopriv_espresso_batch_cleanup', array(self::instance(), 'batch_cleanup')); |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * @since 4.9.80.p |
|
109 | - * @return LoaderInterface |
|
110 | - * @throws InvalidArgumentException |
|
111 | - * @throws InvalidDataTypeException |
|
112 | - * @throws InvalidInterfaceException |
|
113 | - */ |
|
114 | - protected function getLoader() |
|
115 | - { |
|
116 | - if (!$this->loader instanceof LoaderInterface) { |
|
117 | - $this->loader = LoaderFactory::getLoader(); |
|
118 | - } |
|
119 | - return $this->loader; |
|
120 | - } |
|
107 | + /** |
|
108 | + * @since 4.9.80.p |
|
109 | + * @return LoaderInterface |
|
110 | + * @throws InvalidArgumentException |
|
111 | + * @throws InvalidDataTypeException |
|
112 | + * @throws InvalidInterfaceException |
|
113 | + */ |
|
114 | + protected function getLoader() |
|
115 | + { |
|
116 | + if (!$this->loader instanceof LoaderInterface) { |
|
117 | + $this->loader = LoaderFactory::getLoader(); |
|
118 | + } |
|
119 | + return $this->loader; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Enqueues batch scripts on the frontend or admin, and creates a job |
|
124 | - */ |
|
125 | - public function enqueue_scripts() |
|
126 | - { |
|
127 | - if (isset($_REQUEST['espresso_batch']) |
|
128 | - || |
|
129 | - ( |
|
130 | - isset($_REQUEST['page']) |
|
131 | - && $_REQUEST['page'] == 'espresso_batch' |
|
132 | - ) |
|
133 | - ) { |
|
134 | - switch ($this->batch_request_type()) { |
|
135 | - case self::batch_job: |
|
136 | - $this->enqueue_scripts_styles_batch_create(); |
|
137 | - break; |
|
138 | - case self::batch_file_job: |
|
139 | - $this->enqueue_scripts_styles_batch_file_create(); |
|
140 | - break; |
|
141 | - } |
|
142 | - } |
|
143 | - } |
|
122 | + /** |
|
123 | + * Enqueues batch scripts on the frontend or admin, and creates a job |
|
124 | + */ |
|
125 | + public function enqueue_scripts() |
|
126 | + { |
|
127 | + if (isset($_REQUEST['espresso_batch']) |
|
128 | + || |
|
129 | + ( |
|
130 | + isset($_REQUEST['page']) |
|
131 | + && $_REQUEST['page'] == 'espresso_batch' |
|
132 | + ) |
|
133 | + ) { |
|
134 | + switch ($this->batch_request_type()) { |
|
135 | + case self::batch_job: |
|
136 | + $this->enqueue_scripts_styles_batch_create(); |
|
137 | + break; |
|
138 | + case self::batch_file_job: |
|
139 | + $this->enqueue_scripts_styles_batch_file_create(); |
|
140 | + break; |
|
141 | + } |
|
142 | + } |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * Create a batch job, enqueues a script to run it, and localizes some data for it |
|
147 | - */ |
|
148 | - public function enqueue_scripts_styles_batch_create() |
|
149 | - { |
|
150 | - $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
151 | - wp_enqueue_script( |
|
152 | - 'batch_runner_init', |
|
153 | - BATCH_URL . 'assets/batch_runner_init.js', |
|
154 | - array('batch_runner'), |
|
155 | - EVENT_ESPRESSO_VERSION, |
|
156 | - true |
|
157 | - ); |
|
158 | - wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array()); |
|
159 | - wp_localize_script( |
|
160 | - 'batch_runner_init', |
|
161 | - 'ee_job_i18n', |
|
162 | - array( |
|
163 | - 'return_url' => $_REQUEST['return_url'], |
|
164 | - ) |
|
165 | - ); |
|
166 | - } |
|
145 | + /** |
|
146 | + * Create a batch job, enqueues a script to run it, and localizes some data for it |
|
147 | + */ |
|
148 | + public function enqueue_scripts_styles_batch_create() |
|
149 | + { |
|
150 | + $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
151 | + wp_enqueue_script( |
|
152 | + 'batch_runner_init', |
|
153 | + BATCH_URL . 'assets/batch_runner_init.js', |
|
154 | + array('batch_runner'), |
|
155 | + EVENT_ESPRESSO_VERSION, |
|
156 | + true |
|
157 | + ); |
|
158 | + wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array()); |
|
159 | + wp_localize_script( |
|
160 | + 'batch_runner_init', |
|
161 | + 'ee_job_i18n', |
|
162 | + array( |
|
163 | + 'return_url' => $_REQUEST['return_url'], |
|
164 | + ) |
|
165 | + ); |
|
166 | + } |
|
167 | 167 | |
168 | - /** |
|
169 | - * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it |
|
170 | - */ |
|
171 | - public function enqueue_scripts_styles_batch_file_create() |
|
172 | - { |
|
173 | - // creates a job based on the request variable |
|
174 | - $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
175 | - wp_enqueue_script( |
|
176 | - 'batch_file_runner_init', |
|
177 | - BATCH_URL . 'assets/batch_file_runner_init.js', |
|
178 | - array('batch_runner'), |
|
179 | - EVENT_ESPRESSO_VERSION, |
|
180 | - true |
|
181 | - ); |
|
182 | - wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array()); |
|
183 | - wp_localize_script( |
|
184 | - 'batch_file_runner_init', |
|
185 | - 'ee_job_i18n', |
|
186 | - array( |
|
187 | - 'download_and_redirecting' => sprintf( |
|
188 | - __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'), |
|
189 | - '<a href="' . $_REQUEST['return_url'] . '">', |
|
190 | - '</a>' |
|
191 | - ), |
|
192 | - 'return_url' => $_REQUEST['return_url'], |
|
193 | - ) |
|
194 | - ); |
|
195 | - } |
|
168 | + /** |
|
169 | + * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it |
|
170 | + */ |
|
171 | + public function enqueue_scripts_styles_batch_file_create() |
|
172 | + { |
|
173 | + // creates a job based on the request variable |
|
174 | + $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job(); |
|
175 | + wp_enqueue_script( |
|
176 | + 'batch_file_runner_init', |
|
177 | + BATCH_URL . 'assets/batch_file_runner_init.js', |
|
178 | + array('batch_runner'), |
|
179 | + EVENT_ESPRESSO_VERSION, |
|
180 | + true |
|
181 | + ); |
|
182 | + wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array()); |
|
183 | + wp_localize_script( |
|
184 | + 'batch_file_runner_init', |
|
185 | + 'ee_job_i18n', |
|
186 | + array( |
|
187 | + 'download_and_redirecting' => sprintf( |
|
188 | + __('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'), |
|
189 | + '<a href="' . $_REQUEST['return_url'] . '">', |
|
190 | + '</a>' |
|
191 | + ), |
|
192 | + 'return_url' => $_REQUEST['return_url'], |
|
193 | + ) |
|
194 | + ); |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * Enqueues scripts and styles common to any batch job, and creates |
|
199 | - * a job from the request data, and stores the response in the |
|
200 | - * $this->_job_step_response property |
|
201 | - * |
|
202 | - * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
203 | - */ |
|
204 | - protected function _enqueue_batch_job_scripts_and_styles_and_start_job() |
|
205 | - { |
|
206 | - // just copy the bits of EE admin's eei18n that we need in the JS |
|
207 | - EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__( |
|
208 | - 'An error occurred and the job has been stopped. Please refresh the page to try again.', |
|
209 | - 'event_espresso' |
|
210 | - ); |
|
211 | - wp_register_script( |
|
212 | - 'progress_bar', |
|
213 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
214 | - array('jquery'), |
|
215 | - EVENT_ESPRESSO_VERSION, |
|
216 | - true |
|
217 | - ); |
|
218 | - wp_enqueue_style( |
|
219 | - 'progress_bar', |
|
220 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
221 | - array(), |
|
222 | - EVENT_ESPRESSO_VERSION |
|
223 | - ); |
|
224 | - wp_enqueue_script( |
|
225 | - 'batch_runner', |
|
226 | - EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
227 | - array('progress_bar', CoreAssetManager::JS_HANDLE_CORE), |
|
228 | - EVENT_ESPRESSO_VERSION, |
|
229 | - true |
|
230 | - ); |
|
231 | - $job_handler_classname = stripslashes($_GET['job_handler']); |
|
232 | - $request_data = array_diff_key( |
|
233 | - $_REQUEST, |
|
234 | - array_flip(array('action', 'page', 'ee', 'batch')) |
|
235 | - ); |
|
236 | - $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
237 | - // eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport' |
|
238 | - $job_response = $batch_runner->create_job($job_handler_classname, $request_data); |
|
239 | - // remember the response for later. We need it to display the page body |
|
240 | - $this->_job_step_response = $job_response; |
|
241 | - return $job_response; |
|
242 | - } |
|
197 | + /** |
|
198 | + * Enqueues scripts and styles common to any batch job, and creates |
|
199 | + * a job from the request data, and stores the response in the |
|
200 | + * $this->_job_step_response property |
|
201 | + * |
|
202 | + * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
203 | + */ |
|
204 | + protected function _enqueue_batch_job_scripts_and_styles_and_start_job() |
|
205 | + { |
|
206 | + // just copy the bits of EE admin's eei18n that we need in the JS |
|
207 | + EE_Registry::$i18n_js_strings['batchJobError'] = esc_html__( |
|
208 | + 'An error occurred and the job has been stopped. Please refresh the page to try again.', |
|
209 | + 'event_espresso' |
|
210 | + ); |
|
211 | + wp_register_script( |
|
212 | + 'progress_bar', |
|
213 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js', |
|
214 | + array('jquery'), |
|
215 | + EVENT_ESPRESSO_VERSION, |
|
216 | + true |
|
217 | + ); |
|
218 | + wp_enqueue_style( |
|
219 | + 'progress_bar', |
|
220 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css', |
|
221 | + array(), |
|
222 | + EVENT_ESPRESSO_VERSION |
|
223 | + ); |
|
224 | + wp_enqueue_script( |
|
225 | + 'batch_runner', |
|
226 | + EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js', |
|
227 | + array('progress_bar', CoreAssetManager::JS_HANDLE_CORE), |
|
228 | + EVENT_ESPRESSO_VERSION, |
|
229 | + true |
|
230 | + ); |
|
231 | + $job_handler_classname = stripslashes($_GET['job_handler']); |
|
232 | + $request_data = array_diff_key( |
|
233 | + $_REQUEST, |
|
234 | + array_flip(array('action', 'page', 'ee', 'batch')) |
|
235 | + ); |
|
236 | + $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
237 | + // eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport' |
|
238 | + $job_response = $batch_runner->create_job($job_handler_classname, $request_data); |
|
239 | + // remember the response for later. We need it to display the page body |
|
240 | + $this->_job_step_response = $job_response; |
|
241 | + return $job_response; |
|
242 | + } |
|
243 | 243 | |
244 | - /** |
|
245 | - * If we are doing a frontend batch job, this makes it so WP shows our template's HTML |
|
246 | - * |
|
247 | - * @param string $template |
|
248 | - * @return string |
|
249 | - */ |
|
250 | - public function override_template($template) |
|
251 | - { |
|
252 | - if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
|
253 | - return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html'; |
|
254 | - } |
|
255 | - return $template; |
|
256 | - } |
|
244 | + /** |
|
245 | + * If we are doing a frontend batch job, this makes it so WP shows our template's HTML |
|
246 | + * |
|
247 | + * @param string $template |
|
248 | + * @return string |
|
249 | + */ |
|
250 | + public function override_template($template) |
|
251 | + { |
|
252 | + if (isset($_REQUEST['espresso_batch']) && isset($_REQUEST['batch'])) { |
|
253 | + return EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_frontend_wrapper.template.html'; |
|
254 | + } |
|
255 | + return $template; |
|
256 | + } |
|
257 | 257 | |
258 | - /** |
|
259 | - * Adds an admin page which doesn't appear in the admin menu |
|
260 | - */ |
|
261 | - public function register_admin_pages() |
|
262 | - { |
|
263 | - add_submenu_page( |
|
264 | - '', // parent slug. we don't want this to actually appear in the menu |
|
265 | - __('Batch Job', 'event_espresso'), // page title |
|
266 | - 'n/a', // menu title |
|
267 | - 'read', // we want this page to actually be accessible to anyone, |
|
268 | - 'espresso_batch', // menu slug |
|
269 | - array(self::instance(), 'show_admin_page') |
|
270 | - ); |
|
271 | - } |
|
258 | + /** |
|
259 | + * Adds an admin page which doesn't appear in the admin menu |
|
260 | + */ |
|
261 | + public function register_admin_pages() |
|
262 | + { |
|
263 | + add_submenu_page( |
|
264 | + '', // parent slug. we don't want this to actually appear in the menu |
|
265 | + __('Batch Job', 'event_espresso'), // page title |
|
266 | + 'n/a', // menu title |
|
267 | + 'read', // we want this page to actually be accessible to anyone, |
|
268 | + 'espresso_batch', // menu slug |
|
269 | + array(self::instance(), 'show_admin_page') |
|
270 | + ); |
|
271 | + } |
|
272 | 272 | |
273 | - /** |
|
274 | - * Renders the admin page, after most of the work was already done during enqueuing scripts |
|
275 | - * of creating the job and localizing some data |
|
276 | - */ |
|
277 | - public function show_admin_page() |
|
278 | - { |
|
279 | - echo EEH_Template::locate_template( |
|
280 | - EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html', |
|
281 | - array('batch_request_type' => $this->batch_request_type()) |
|
282 | - ); |
|
283 | - } |
|
273 | + /** |
|
274 | + * Renders the admin page, after most of the work was already done during enqueuing scripts |
|
275 | + * of creating the job and localizing some data |
|
276 | + */ |
|
277 | + public function show_admin_page() |
|
278 | + { |
|
279 | + echo EEH_Template::locate_template( |
|
280 | + EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html', |
|
281 | + array('batch_request_type' => $this->batch_request_type()) |
|
282 | + ); |
|
283 | + } |
|
284 | 284 | |
285 | - /** |
|
286 | - * Receives ajax calls for continuing a job |
|
287 | - */ |
|
288 | - public function batch_continue() |
|
289 | - { |
|
290 | - $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
291 | - $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
292 | - $response_obj = $batch_runner->continue_job($job_id); |
|
293 | - $this->_return_json($response_obj->to_array()); |
|
294 | - } |
|
285 | + /** |
|
286 | + * Receives ajax calls for continuing a job |
|
287 | + */ |
|
288 | + public function batch_continue() |
|
289 | + { |
|
290 | + $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
291 | + $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
292 | + $response_obj = $batch_runner->continue_job($job_id); |
|
293 | + $this->_return_json($response_obj->to_array()); |
|
294 | + } |
|
295 | 295 | |
296 | - /** |
|
297 | - * Receives the ajax call to cleanup a job |
|
298 | - * |
|
299 | - * @return type |
|
300 | - */ |
|
301 | - public function batch_cleanup() |
|
302 | - { |
|
303 | - $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
304 | - $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
305 | - $response_obj = $batch_runner->cleanup_job($job_id); |
|
306 | - $this->_return_json($response_obj->to_array()); |
|
307 | - } |
|
296 | + /** |
|
297 | + * Receives the ajax call to cleanup a job |
|
298 | + * |
|
299 | + * @return type |
|
300 | + */ |
|
301 | + public function batch_cleanup() |
|
302 | + { |
|
303 | + $job_id = sanitize_text_field($_REQUEST['job_id']); |
|
304 | + $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor'); |
|
305 | + $response_obj = $batch_runner->cleanup_job($job_id); |
|
306 | + $this->_return_json($response_obj->to_array()); |
|
307 | + } |
|
308 | 308 | |
309 | 309 | |
310 | - /** |
|
311 | - * Returns a json response |
|
312 | - * |
|
313 | - * @param array $data The data we want to send echo via in the JSON response's "data" element |
|
314 | - * |
|
315 | - * The returned json object is created from an array in the following format: |
|
316 | - * array( |
|
317 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
318 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
319 | - * We're also going to include the template args with every package (so js can pick out any specific template |
|
320 | - * args that might be included in here) |
|
321 | - * 'isEEajax' => true,//indicates this is a response from EE |
|
322 | - * ) |
|
323 | - */ |
|
324 | - protected function _return_json($data) |
|
325 | - { |
|
326 | - $json = array( |
|
327 | - 'notices' => EE_Error::get_notices(), |
|
328 | - 'data' => $data, |
|
329 | - 'isEEajax' => true |
|
330 | - // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
331 | - ); |
|
310 | + /** |
|
311 | + * Returns a json response |
|
312 | + * |
|
313 | + * @param array $data The data we want to send echo via in the JSON response's "data" element |
|
314 | + * |
|
315 | + * The returned json object is created from an array in the following format: |
|
316 | + * array( |
|
317 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
318 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
319 | + * We're also going to include the template args with every package (so js can pick out any specific template |
|
320 | + * args that might be included in here) |
|
321 | + * 'isEEajax' => true,//indicates this is a response from EE |
|
322 | + * ) |
|
323 | + */ |
|
324 | + protected function _return_json($data) |
|
325 | + { |
|
326 | + $json = array( |
|
327 | + 'notices' => EE_Error::get_notices(), |
|
328 | + 'data' => $data, |
|
329 | + 'isEEajax' => true |
|
330 | + // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
331 | + ); |
|
332 | 332 | |
333 | 333 | |
334 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
335 | - if (null === error_get_last() || ! headers_sent()) { |
|
336 | - header('Content-Type: application/json; charset=UTF-8'); |
|
337 | - } |
|
338 | - echo wp_json_encode($json); |
|
339 | - exit(); |
|
340 | - } |
|
334 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
335 | + if (null === error_get_last() || ! headers_sent()) { |
|
336 | + header('Content-Type: application/json; charset=UTF-8'); |
|
337 | + } |
|
338 | + echo wp_json_encode($json); |
|
339 | + exit(); |
|
340 | + } |
|
341 | 341 | |
342 | - /** |
|
343 | - * Gets the job step response which was done during the enqueuing of scripts |
|
344 | - * |
|
345 | - * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
346 | - */ |
|
347 | - public function job_step_response() |
|
348 | - { |
|
349 | - return $this->_job_step_response; |
|
350 | - } |
|
342 | + /** |
|
343 | + * Gets the job step response which was done during the enqueuing of scripts |
|
344 | + * |
|
345 | + * @return \EventEspressoBatchRequest\Helpers\JobStepResponse |
|
346 | + */ |
|
347 | + public function job_step_response() |
|
348 | + { |
|
349 | + return $this->_job_step_response; |
|
350 | + } |
|
351 | 351 | |
352 | - /** |
|
353 | - * Gets the batch request type indicated in the $_REQUEST |
|
354 | - * |
|
355 | - * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job |
|
356 | - */ |
|
357 | - public function batch_request_type() |
|
358 | - { |
|
359 | - if ($this->_batch_request_type === null) { |
|
360 | - if (isset($_GET['batch'])) { |
|
361 | - if ($_GET['batch'] == self::batch_job) { |
|
362 | - $this->_batch_request_type = self::batch_job; |
|
363 | - } elseif ($_GET['batch'] == self::batch_file_job) { |
|
364 | - $this->_batch_request_type = self::batch_file_job; |
|
365 | - } |
|
366 | - } |
|
367 | - // if we didn't find that it was a batch request, indicate it wasn't |
|
368 | - if ($this->_batch_request_type === null) { |
|
369 | - $this->_batch_request_type = self::batch_not_job; |
|
370 | - } |
|
371 | - } |
|
372 | - return $this->_batch_request_type; |
|
373 | - } |
|
352 | + /** |
|
353 | + * Gets the batch request type indicated in the $_REQUEST |
|
354 | + * |
|
355 | + * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job |
|
356 | + */ |
|
357 | + public function batch_request_type() |
|
358 | + { |
|
359 | + if ($this->_batch_request_type === null) { |
|
360 | + if (isset($_GET['batch'])) { |
|
361 | + if ($_GET['batch'] == self::batch_job) { |
|
362 | + $this->_batch_request_type = self::batch_job; |
|
363 | + } elseif ($_GET['batch'] == self::batch_file_job) { |
|
364 | + $this->_batch_request_type = self::batch_file_job; |
|
365 | + } |
|
366 | + } |
|
367 | + // if we didn't find that it was a batch request, indicate it wasn't |
|
368 | + if ($this->_batch_request_type === null) { |
|
369 | + $this->_batch_request_type = self::batch_not_job; |
|
370 | + } |
|
371 | + } |
|
372 | + return $this->_batch_request_type; |
|
373 | + } |
|
374 | 374 | |
375 | - /** |
|
376 | - * Unnecessary |
|
377 | - * |
|
378 | - * @param type $WP |
|
379 | - */ |
|
380 | - public function run($WP) |
|
381 | - { |
|
382 | - } |
|
375 | + /** |
|
376 | + * Unnecessary |
|
377 | + * |
|
378 | + * @param type $WP |
|
379 | + */ |
|
380 | + public function run($WP) |
|
381 | + { |
|
382 | + } |
|
383 | 383 | } |
@@ -13,19 +13,19 @@ |
||
13 | 13 | class EE_Credit_Card_Validation_Strategy extends EE_Text_Validation_Strategy |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @param null $validation_error_message |
|
18 | - */ |
|
19 | - public function __construct($validation_error_message = null) |
|
20 | - { |
|
21 | - if (! $validation_error_message) { |
|
22 | - $validation_error_message = __("Please enter a valid credit card number", "event_espresso"); |
|
23 | - } |
|
24 | - parent::__construct( |
|
25 | - $validation_error_message, |
|
26 | - // @codingStandardsIgnoreStart |
|
27 | - '~^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|2[2-7][0-9]{14}|6011[0-9]{12}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})$~' |
|
28 | - // @codingStandardsIgnoreEnd |
|
29 | - ); |
|
30 | - } |
|
16 | + /** |
|
17 | + * @param null $validation_error_message |
|
18 | + */ |
|
19 | + public function __construct($validation_error_message = null) |
|
20 | + { |
|
21 | + if (! $validation_error_message) { |
|
22 | + $validation_error_message = __("Please enter a valid credit card number", "event_espresso"); |
|
23 | + } |
|
24 | + parent::__construct( |
|
25 | + $validation_error_message, |
|
26 | + // @codingStandardsIgnoreStart |
|
27 | + '~^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|2[2-7][0-9]{14}|6011[0-9]{12}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})$~' |
|
28 | + // @codingStandardsIgnoreEnd |
|
29 | + ); |
|
30 | + } |
|
31 | 31 | } |
@@ -18,7 +18,7 @@ |
||
18 | 18 | */ |
19 | 19 | public function __construct($validation_error_message = null) |
20 | 20 | { |
21 | - if (! $validation_error_message) { |
|
21 | + if ( ! $validation_error_message) { |
|
22 | 22 | $validation_error_message = __("Please enter a valid credit card number", "event_espresso"); |
23 | 23 | } |
24 | 24 | parent::__construct( |
@@ -15,596 +15,596 @@ |
||
15 | 15 | class EE_Cron_Tasks extends EE_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * WordPress doesn't allow duplicate crons within 10 minutes of the original, |
|
20 | - * so we'll set our retry time for just over 10 minutes to avoid that |
|
21 | - */ |
|
22 | - const reschedule_timeout = 605; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * @var EE_Cron_Tasks |
|
27 | - */ |
|
28 | - private static $_instance; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * @return EE_Cron_Tasks |
|
33 | - * @throws ReflectionException |
|
34 | - * @throws EE_Error |
|
35 | - * @throws InvalidArgumentException |
|
36 | - * @throws InvalidInterfaceException |
|
37 | - * @throws InvalidDataTypeException |
|
38 | - */ |
|
39 | - public static function instance() |
|
40 | - { |
|
41 | - if (! self::$_instance instanceof EE_Cron_Tasks) { |
|
42 | - self::$_instance = new self(); |
|
43 | - } |
|
44 | - return self::$_instance; |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @access private |
|
50 | - * @throws InvalidDataTypeException |
|
51 | - * @throws InvalidInterfaceException |
|
52 | - * @throws InvalidArgumentException |
|
53 | - * @throws EE_Error |
|
54 | - * @throws ReflectionException |
|
55 | - */ |
|
56 | - private function __construct() |
|
57 | - { |
|
58 | - do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
59 | - // verify that WP Cron is enabled |
|
60 | - if (defined('DISABLE_WP_CRON') |
|
61 | - && DISABLE_WP_CRON |
|
62 | - && is_admin() |
|
63 | - && ! get_option('ee_disabled_wp_cron_check') |
|
64 | - ) { |
|
65 | - /** |
|
66 | - * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before |
|
67 | - * config is loaded. |
|
68 | - * This is intentionally using a anonymous function so that its not easily de-registered. Client code |
|
69 | - * wanting to not have this functionality can just register its own action at a priority after this one to |
|
70 | - * reverse any changes. |
|
71 | - */ |
|
72 | - add_action( |
|
73 | - 'AHEE__EE_System__load_core_configuration__complete', |
|
74 | - function () { |
|
75 | - EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true; |
|
76 | - EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
77 | - add_option('ee_disabled_wp_cron_check', 1, '', false); |
|
78 | - } |
|
79 | - ); |
|
80 | - } |
|
81 | - // UPDATE TRANSACTION WITH PAYMENT |
|
82 | - add_action( |
|
83 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
84 | - array('EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'), |
|
85 | - 10, |
|
86 | - 2 |
|
87 | - ); |
|
88 | - // ABANDONED / EXPIRED TRANSACTION CHECK |
|
89 | - add_action( |
|
90 | - 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
|
91 | - array('EE_Cron_Tasks', 'expired_transaction_check'), |
|
92 | - 10, |
|
93 | - 1 |
|
94 | - ); |
|
95 | - // CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA |
|
96 | - add_action( |
|
97 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
98 | - array('EE_Cron_Tasks', 'clean_out_junk_transactions') |
|
99 | - ); |
|
100 | - // logging |
|
101 | - add_action( |
|
102 | - 'AHEE__EE_System__load_core_configuration__complete', |
|
103 | - array('EE_Cron_Tasks', 'log_scheduled_ee_crons') |
|
104 | - ); |
|
105 | - EE_Registry::instance()->load_lib('Messages_Scheduler'); |
|
106 | - // clean out old gateway logs |
|
107 | - add_action( |
|
108 | - 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs', |
|
109 | - array('EE_Cron_Tasks', 'clean_out_old_gateway_logs') |
|
110 | - ); |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * @access protected |
|
116 | - * @return void |
|
117 | - */ |
|
118 | - public static function log_scheduled_ee_crons() |
|
119 | - { |
|
120 | - $ee_crons = array( |
|
121 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment', |
|
122 | - 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
|
123 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
124 | - ); |
|
125 | - $crons = (array) get_option('cron'); |
|
126 | - if (! is_array($crons)) { |
|
127 | - return; |
|
128 | - } |
|
129 | - foreach ($crons as $timestamp => $cron) { |
|
130 | - /** @var array[] $cron */ |
|
131 | - foreach ($ee_crons as $ee_cron) { |
|
132 | - if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) { |
|
133 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron'); |
|
134 | - foreach ($cron[ $ee_cron ] as $ee_cron_details) { |
|
135 | - if (! empty($ee_cron_details['args'])) { |
|
136 | - do_action( |
|
137 | - 'AHEE_log', |
|
138 | - __CLASS__, |
|
139 | - __FUNCTION__, |
|
140 | - print_r($ee_cron_details['args'], true), |
|
141 | - "{$ee_cron} args" |
|
142 | - ); |
|
143 | - } |
|
144 | - } |
|
145 | - } |
|
146 | - } |
|
147 | - } |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * reschedule_cron_for_transactions_if_maintenance_mode |
|
153 | - * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes |
|
154 | - * |
|
155 | - * @param string $cron_task |
|
156 | - * @param array $TXN_IDs |
|
157 | - * @return bool |
|
158 | - * @throws DomainException |
|
159 | - */ |
|
160 | - public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, array $TXN_IDs) |
|
161 | - { |
|
162 | - if (! method_exists('EE_Cron_Tasks', $cron_task)) { |
|
163 | - throw new DomainException( |
|
164 | - sprintf( |
|
165 | - __('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'), |
|
166 | - $cron_task |
|
167 | - ) |
|
168 | - ); |
|
169 | - } |
|
170 | - // reschedule the cron if we can't hit the db right now |
|
171 | - if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
172 | - foreach ($TXN_IDs as $TXN_ID => $additional_vars) { |
|
173 | - // ensure $additional_vars is an array |
|
174 | - $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars); |
|
175 | - // reset cron job for the TXN |
|
176 | - call_user_func_array( |
|
177 | - array('EE_Cron_Tasks', $cron_task), |
|
178 | - array_merge( |
|
179 | - array( |
|
180 | - time() + (10 * MINUTE_IN_SECONDS), |
|
181 | - $TXN_ID, |
|
182 | - ), |
|
183 | - $additional_vars |
|
184 | - ) |
|
185 | - ); |
|
186 | - } |
|
187 | - return true; |
|
188 | - } |
|
189 | - return false; |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - |
|
194 | - |
|
195 | - /**************** UPDATE TRANSACTION WITH PAYMENT ****************/ |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * array of TXN IDs and the payment |
|
200 | - * |
|
201 | - * @var array |
|
202 | - */ |
|
203 | - protected static $_update_transactions_with_payment = array(); |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * schedule_update_transaction_with_payment |
|
208 | - * sets a wp_schedule_single_event() for updating any TXNs that may |
|
209 | - * require updating due to recently received payments |
|
210 | - * |
|
211 | - * @param int $timestamp |
|
212 | - * @param int $TXN_ID |
|
213 | - * @param int $PAY_ID |
|
214 | - */ |
|
215 | - public static function schedule_update_transaction_with_payment( |
|
216 | - $timestamp, |
|
217 | - $TXN_ID, |
|
218 | - $PAY_ID |
|
219 | - ) { |
|
220 | - do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
221 | - // validate $TXN_ID and $timestamp |
|
222 | - $TXN_ID = absint($TXN_ID); |
|
223 | - $timestamp = absint($timestamp); |
|
224 | - if ($TXN_ID && $timestamp) { |
|
225 | - wp_schedule_single_event( |
|
226 | - $timestamp, |
|
227 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
228 | - array($TXN_ID, $PAY_ID) |
|
229 | - ); |
|
230 | - } |
|
231 | - } |
|
232 | - |
|
233 | - |
|
234 | - /** |
|
235 | - * setup_update_for_transaction_with_payment |
|
236 | - * this is the callback for the action hook: |
|
237 | - * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' |
|
238 | - * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment(). |
|
239 | - * The passed TXN_ID and associated payment gets added to an array, and then |
|
240 | - * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into |
|
241 | - * 'shutdown' which will actually handle the processing of any |
|
242 | - * transactions requiring updating, because doing so now would be too early |
|
243 | - * and the required resources may not be available |
|
244 | - * |
|
245 | - * @param int $TXN_ID |
|
246 | - * @param int $PAY_ID |
|
247 | - */ |
|
248 | - public static function setup_update_for_transaction_with_payment($TXN_ID = 0, $PAY_ID = 0) |
|
249 | - { |
|
250 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
251 | - if (absint($TXN_ID)) { |
|
252 | - self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID; |
|
253 | - add_action( |
|
254 | - 'shutdown', |
|
255 | - array('EE_Cron_Tasks', 'update_transaction_with_payment'), |
|
256 | - 5 |
|
257 | - ); |
|
258 | - } |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * update_transaction_with_payment |
|
264 | - * loops through the self::$_abandoned_transactions array |
|
265 | - * and attempts to finalize any TXNs that have not been completed |
|
266 | - * but have had their sessions expired, most likely due to a user not |
|
267 | - * returning from an off-site payment gateway |
|
268 | - * |
|
269 | - * @throws EE_Error |
|
270 | - * @throws DomainException |
|
271 | - * @throws InvalidDataTypeException |
|
272 | - * @throws InvalidInterfaceException |
|
273 | - * @throws InvalidArgumentException |
|
274 | - * @throws ReflectionException |
|
275 | - * @throws RuntimeException |
|
276 | - */ |
|
277 | - public static function update_transaction_with_payment() |
|
278 | - { |
|
279 | - do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
280 | - if (// are there any TXNs that need cleaning up ? |
|
281 | - empty(self::$_update_transactions_with_payment) |
|
282 | - // reschedule the cron if we can't hit the db right now |
|
283 | - || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
|
284 | - 'schedule_update_transaction_with_payment', |
|
285 | - self::$_update_transactions_with_payment |
|
286 | - ) |
|
287 | - ) { |
|
288 | - return; |
|
289 | - } |
|
290 | - /** @type EE_Payment_Processor $payment_processor */ |
|
291 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
292 | - // set revisit flag for payment processor |
|
293 | - $payment_processor->set_revisit(); |
|
294 | - // load EEM_Transaction |
|
295 | - EE_Registry::instance()->load_model('Transaction'); |
|
296 | - foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) { |
|
297 | - // reschedule the cron if we can't hit the db right now |
|
298 | - if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
299 | - // reset cron job for updating the TXN |
|
300 | - EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
301 | - time() + EE_Cron_Tasks::reschedule_timeout, |
|
302 | - $TXN_ID, |
|
303 | - $PAY_ID |
|
304 | - ); |
|
305 | - continue; |
|
306 | - } |
|
307 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
308 | - $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
309 | - // verify transaction |
|
310 | - if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) { |
|
311 | - // now try to update the TXN with any payments |
|
312 | - $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true); |
|
313 | - } |
|
314 | - unset(self::$_update_transactions_with_payment[ $TXN_ID ]); |
|
315 | - } |
|
316 | - } |
|
317 | - |
|
318 | - |
|
319 | - |
|
320 | - /************ END OF UPDATE TRANSACTION WITH PAYMENT ************/ |
|
321 | - |
|
322 | - |
|
323 | - /***************** EXPIRED TRANSACTION CHECK *****************/ |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * array of TXN IDs |
|
328 | - * |
|
329 | - * @var array |
|
330 | - */ |
|
331 | - protected static $_expired_transactions = array(); |
|
332 | - |
|
333 | - |
|
334 | - /** |
|
335 | - * schedule_expired_transaction_check |
|
336 | - * sets a wp_schedule_single_event() for following up on TXNs after their session has expired |
|
337 | - * |
|
338 | - * @param int $timestamp |
|
339 | - * @param int $TXN_ID |
|
340 | - */ |
|
341 | - public static function schedule_expired_transaction_check( |
|
342 | - $timestamp, |
|
343 | - $TXN_ID |
|
344 | - ) { |
|
345 | - // validate $TXN_ID and $timestamp |
|
346 | - $TXN_ID = absint($TXN_ID); |
|
347 | - $timestamp = absint($timestamp); |
|
348 | - if ($TXN_ID && $timestamp) { |
|
349 | - wp_schedule_single_event( |
|
350 | - $timestamp, |
|
351 | - 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
|
352 | - array($TXN_ID) |
|
353 | - ); |
|
354 | - } |
|
355 | - } |
|
356 | - |
|
357 | - |
|
358 | - /** |
|
359 | - * expired_transaction_check |
|
360 | - * this is the callback for the action hook: |
|
361 | - * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check' |
|
362 | - * which is utilized by wp_schedule_single_event() |
|
363 | - * in \EED_Single_Page_Checkout::_initialize_transaction(). |
|
364 | - * The passed TXN_ID gets added to an array, and then the |
|
365 | - * process_expired_transactions() function is hooked into |
|
366 | - * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the |
|
367 | - * processing of any failed transactions, because doing so now would be |
|
368 | - * too early and the required resources may not be available |
|
369 | - * |
|
370 | - * @param int $TXN_ID |
|
371 | - */ |
|
372 | - public static function expired_transaction_check($TXN_ID = 0) |
|
373 | - { |
|
374 | - if (absint($TXN_ID)) { |
|
375 | - self::$_expired_transactions[ $TXN_ID ] = $TXN_ID; |
|
376 | - add_action( |
|
377 | - 'shutdown', |
|
378 | - array('EE_Cron_Tasks', 'process_expired_transactions'), |
|
379 | - 5 |
|
380 | - ); |
|
381 | - } |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * process_expired_transactions |
|
387 | - * loops through the self::$_expired_transactions array and processes any failed TXNs |
|
388 | - * |
|
389 | - * @throws EE_Error |
|
390 | - * @throws InvalidDataTypeException |
|
391 | - * @throws InvalidInterfaceException |
|
392 | - * @throws InvalidArgumentException |
|
393 | - * @throws ReflectionException |
|
394 | - * @throws DomainException |
|
395 | - * @throws RuntimeException |
|
396 | - */ |
|
397 | - public static function process_expired_transactions() |
|
398 | - { |
|
399 | - if (// are there any TXNs that need cleaning up ? |
|
400 | - empty(self::$_expired_transactions) |
|
401 | - // reschedule the cron if we can't hit the db right now |
|
402 | - || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
|
403 | - 'schedule_expired_transaction_check', |
|
404 | - self::$_expired_transactions |
|
405 | - ) |
|
406 | - ) { |
|
407 | - return; |
|
408 | - } |
|
409 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
410 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
411 | - // set revisit flag for txn processor |
|
412 | - $transaction_processor->set_revisit(); |
|
413 | - // load EEM_Transaction |
|
414 | - EE_Registry::instance()->load_model('Transaction'); |
|
415 | - foreach (self::$_expired_transactions as $TXN_ID) { |
|
416 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
417 | - // verify transaction and whether it is failed or not |
|
418 | - if ($transaction instanceof EE_Transaction) { |
|
419 | - switch ($transaction->status_ID()) { |
|
420 | - // Completed TXNs |
|
421 | - case EEM_Transaction::complete_status_code: |
|
422 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
423 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
424 | - $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
425 | - $transaction, |
|
426 | - $transaction->last_payment() |
|
427 | - ); |
|
428 | - do_action( |
|
429 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction', |
|
430 | - $transaction |
|
431 | - ); |
|
432 | - break; |
|
433 | - // Overpaid TXNs |
|
434 | - case EEM_Transaction::overpaid_status_code: |
|
435 | - do_action( |
|
436 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction', |
|
437 | - $transaction |
|
438 | - ); |
|
439 | - break; |
|
440 | - // Incomplete TXNs |
|
441 | - case EEM_Transaction::incomplete_status_code: |
|
442 | - do_action( |
|
443 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
444 | - $transaction |
|
445 | - ); |
|
446 | - // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions |
|
447 | - break; |
|
448 | - // Abandoned TXNs |
|
449 | - case EEM_Transaction::abandoned_status_code: |
|
450 | - // run hook before updating transaction, primarily so |
|
451 | - // EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets |
|
452 | - do_action( |
|
453 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
454 | - $transaction |
|
455 | - ); |
|
456 | - // don't finalize the TXN if it has already been completed |
|
457 | - if ($transaction->all_reg_steps_completed() !== true) { |
|
458 | - /** @type EE_Payment_Processor $payment_processor */ |
|
459 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
460 | - // let's simulate an IPN here which will trigger any notifications that need to go out |
|
461 | - $payment_processor->update_txn_based_on_payment( |
|
462 | - $transaction, |
|
463 | - $transaction->last_payment(), |
|
464 | - true, |
|
465 | - true |
|
466 | - ); |
|
467 | - } |
|
468 | - break; |
|
469 | - // Failed TXNs |
|
470 | - case EEM_Transaction::failed_status_code: |
|
471 | - do_action( |
|
472 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
473 | - $transaction |
|
474 | - ); |
|
475 | - // todo : |
|
476 | - // perform garbage collection here and remove clean_out_junk_transactions() |
|
477 | - // $registrations = $transaction->registrations(); |
|
478 | - // if (! empty($registrations)) { |
|
479 | - // foreach ($registrations as $registration) { |
|
480 | - // if ($registration instanceof EE_Registration) { |
|
481 | - // $delete_registration = true; |
|
482 | - // if ($registration->attendee() instanceof EE_Attendee) { |
|
483 | - // $delete_registration = false; |
|
484 | - // } |
|
485 | - // if ($delete_registration) { |
|
486 | - // $registration->delete_permanently(); |
|
487 | - // $registration->delete_related_permanently(); |
|
488 | - // } |
|
489 | - // } |
|
490 | - // } |
|
491 | - // } |
|
492 | - break; |
|
493 | - } |
|
494 | - } |
|
495 | - unset(self::$_expired_transactions[ $TXN_ID ]); |
|
496 | - } |
|
497 | - } |
|
498 | - |
|
499 | - |
|
500 | - |
|
501 | - /************* END OF EXPIRED TRANSACTION CHECK *************/ |
|
502 | - |
|
503 | - |
|
504 | - /************* START CLEAN UP BOT TRANSACTIONS **********************/ |
|
505 | - |
|
506 | - |
|
507 | - /** |
|
508 | - * callback for 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' |
|
509 | - * which is setup during activation to run on an hourly cron |
|
510 | - * |
|
511 | - * @throws EE_Error |
|
512 | - * @throws InvalidArgumentException |
|
513 | - * @throws InvalidDataTypeException |
|
514 | - * @throws InvalidInterfaceException |
|
515 | - * @throws DomainException |
|
516 | - */ |
|
517 | - public static function clean_out_junk_transactions() |
|
518 | - { |
|
519 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
520 | - EED_Ticket_Sales_Monitor::reset_reservation_counts(); |
|
521 | - EEM_Transaction::instance('')->delete_junk_transactions(); |
|
522 | - EEM_Registration::instance('')->delete_registrations_with_no_transaction(); |
|
523 | - EEM_Line_Item::instance('')->delete_line_items_with_no_transaction(); |
|
524 | - } |
|
525 | - } |
|
526 | - |
|
527 | - |
|
528 | - /** |
|
529 | - * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that. |
|
530 | - * |
|
531 | - * @throws EE_Error |
|
532 | - * @throws InvalidDataTypeException |
|
533 | - * @throws InvalidInterfaceException |
|
534 | - * @throws InvalidArgumentException |
|
535 | - */ |
|
536 | - public static function clean_out_old_gateway_logs() |
|
537 | - { |
|
538 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
539 | - $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config'); |
|
540 | - $time_diff_for_comparison = apply_filters( |
|
541 | - 'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison', |
|
542 | - '-' . $reg_config->gateway_log_lifespan |
|
543 | - ); |
|
544 | - EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison)); |
|
545 | - } |
|
546 | - } |
|
547 | - |
|
548 | - |
|
549 | - /***************** FINALIZE ABANDONED TRANSACTIONS *****************/ |
|
550 | - |
|
551 | - |
|
552 | - /** |
|
553 | - * @var array |
|
554 | - */ |
|
555 | - protected static $_abandoned_transactions = array(); |
|
556 | - |
|
557 | - |
|
558 | - /** |
|
559 | - * @deprecated |
|
560 | - * @param int $timestamp |
|
561 | - * @param int $TXN_ID |
|
562 | - */ |
|
563 | - public static function schedule_finalize_abandoned_transactions_check($timestamp, $TXN_ID) |
|
564 | - { |
|
565 | - EE_Cron_Tasks::schedule_expired_transaction_check($timestamp, $TXN_ID); |
|
566 | - } |
|
567 | - |
|
568 | - |
|
569 | - /** |
|
570 | - * @deprecated |
|
571 | - * @param int $TXN_ID |
|
572 | - */ |
|
573 | - public static function check_for_abandoned_transactions($TXN_ID = 0) |
|
574 | - { |
|
575 | - EE_Cron_Tasks::expired_transaction_check($TXN_ID); |
|
576 | - } |
|
577 | - |
|
578 | - |
|
579 | - /** |
|
580 | - * @deprecated |
|
581 | - * @throws EE_Error |
|
582 | - * @throws DomainException |
|
583 | - * @throws InvalidDataTypeException |
|
584 | - * @throws InvalidInterfaceException |
|
585 | - * @throws InvalidArgumentException |
|
586 | - * @throws ReflectionException |
|
587 | - * @throws RuntimeException |
|
588 | - */ |
|
589 | - public static function finalize_abandoned_transactions() |
|
590 | - { |
|
591 | - do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
592 | - if (// are there any TXNs that need cleaning up ? |
|
593 | - empty(self::$_abandoned_transactions) |
|
594 | - // reschedule the cron if we can't hit the db right now |
|
595 | - || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
|
596 | - 'schedule_expired_transaction_check', |
|
597 | - self::$_abandoned_transactions |
|
598 | - ) |
|
599 | - ) { |
|
600 | - return; |
|
601 | - } |
|
602 | - // combine our arrays of transaction IDs |
|
603 | - self::$_expired_transactions = self::$_abandoned_transactions + self::$_expired_transactions; |
|
604 | - // and deal with abandoned transactions here now... |
|
605 | - EE_Cron_Tasks::process_expired_transactions(); |
|
606 | - } |
|
607 | - |
|
608 | - |
|
609 | - /************* END OF FINALIZE ABANDONED TRANSACTIONS *************/ |
|
18 | + /** |
|
19 | + * WordPress doesn't allow duplicate crons within 10 minutes of the original, |
|
20 | + * so we'll set our retry time for just over 10 minutes to avoid that |
|
21 | + */ |
|
22 | + const reschedule_timeout = 605; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * @var EE_Cron_Tasks |
|
27 | + */ |
|
28 | + private static $_instance; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * @return EE_Cron_Tasks |
|
33 | + * @throws ReflectionException |
|
34 | + * @throws EE_Error |
|
35 | + * @throws InvalidArgumentException |
|
36 | + * @throws InvalidInterfaceException |
|
37 | + * @throws InvalidDataTypeException |
|
38 | + */ |
|
39 | + public static function instance() |
|
40 | + { |
|
41 | + if (! self::$_instance instanceof EE_Cron_Tasks) { |
|
42 | + self::$_instance = new self(); |
|
43 | + } |
|
44 | + return self::$_instance; |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @access private |
|
50 | + * @throws InvalidDataTypeException |
|
51 | + * @throws InvalidInterfaceException |
|
52 | + * @throws InvalidArgumentException |
|
53 | + * @throws EE_Error |
|
54 | + * @throws ReflectionException |
|
55 | + */ |
|
56 | + private function __construct() |
|
57 | + { |
|
58 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
59 | + // verify that WP Cron is enabled |
|
60 | + if (defined('DISABLE_WP_CRON') |
|
61 | + && DISABLE_WP_CRON |
|
62 | + && is_admin() |
|
63 | + && ! get_option('ee_disabled_wp_cron_check') |
|
64 | + ) { |
|
65 | + /** |
|
66 | + * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before |
|
67 | + * config is loaded. |
|
68 | + * This is intentionally using a anonymous function so that its not easily de-registered. Client code |
|
69 | + * wanting to not have this functionality can just register its own action at a priority after this one to |
|
70 | + * reverse any changes. |
|
71 | + */ |
|
72 | + add_action( |
|
73 | + 'AHEE__EE_System__load_core_configuration__complete', |
|
74 | + function () { |
|
75 | + EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true; |
|
76 | + EE_Registry::instance()->NET_CFG->update_config(true, false); |
|
77 | + add_option('ee_disabled_wp_cron_check', 1, '', false); |
|
78 | + } |
|
79 | + ); |
|
80 | + } |
|
81 | + // UPDATE TRANSACTION WITH PAYMENT |
|
82 | + add_action( |
|
83 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
84 | + array('EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'), |
|
85 | + 10, |
|
86 | + 2 |
|
87 | + ); |
|
88 | + // ABANDONED / EXPIRED TRANSACTION CHECK |
|
89 | + add_action( |
|
90 | + 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
|
91 | + array('EE_Cron_Tasks', 'expired_transaction_check'), |
|
92 | + 10, |
|
93 | + 1 |
|
94 | + ); |
|
95 | + // CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA |
|
96 | + add_action( |
|
97 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
98 | + array('EE_Cron_Tasks', 'clean_out_junk_transactions') |
|
99 | + ); |
|
100 | + // logging |
|
101 | + add_action( |
|
102 | + 'AHEE__EE_System__load_core_configuration__complete', |
|
103 | + array('EE_Cron_Tasks', 'log_scheduled_ee_crons') |
|
104 | + ); |
|
105 | + EE_Registry::instance()->load_lib('Messages_Scheduler'); |
|
106 | + // clean out old gateway logs |
|
107 | + add_action( |
|
108 | + 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs', |
|
109 | + array('EE_Cron_Tasks', 'clean_out_old_gateway_logs') |
|
110 | + ); |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * @access protected |
|
116 | + * @return void |
|
117 | + */ |
|
118 | + public static function log_scheduled_ee_crons() |
|
119 | + { |
|
120 | + $ee_crons = array( |
|
121 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment', |
|
122 | + 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions', |
|
123 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions', |
|
124 | + ); |
|
125 | + $crons = (array) get_option('cron'); |
|
126 | + if (! is_array($crons)) { |
|
127 | + return; |
|
128 | + } |
|
129 | + foreach ($crons as $timestamp => $cron) { |
|
130 | + /** @var array[] $cron */ |
|
131 | + foreach ($ee_crons as $ee_cron) { |
|
132 | + if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) { |
|
133 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron'); |
|
134 | + foreach ($cron[ $ee_cron ] as $ee_cron_details) { |
|
135 | + if (! empty($ee_cron_details['args'])) { |
|
136 | + do_action( |
|
137 | + 'AHEE_log', |
|
138 | + __CLASS__, |
|
139 | + __FUNCTION__, |
|
140 | + print_r($ee_cron_details['args'], true), |
|
141 | + "{$ee_cron} args" |
|
142 | + ); |
|
143 | + } |
|
144 | + } |
|
145 | + } |
|
146 | + } |
|
147 | + } |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * reschedule_cron_for_transactions_if_maintenance_mode |
|
153 | + * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes |
|
154 | + * |
|
155 | + * @param string $cron_task |
|
156 | + * @param array $TXN_IDs |
|
157 | + * @return bool |
|
158 | + * @throws DomainException |
|
159 | + */ |
|
160 | + public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, array $TXN_IDs) |
|
161 | + { |
|
162 | + if (! method_exists('EE_Cron_Tasks', $cron_task)) { |
|
163 | + throw new DomainException( |
|
164 | + sprintf( |
|
165 | + __('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'), |
|
166 | + $cron_task |
|
167 | + ) |
|
168 | + ); |
|
169 | + } |
|
170 | + // reschedule the cron if we can't hit the db right now |
|
171 | + if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
172 | + foreach ($TXN_IDs as $TXN_ID => $additional_vars) { |
|
173 | + // ensure $additional_vars is an array |
|
174 | + $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars); |
|
175 | + // reset cron job for the TXN |
|
176 | + call_user_func_array( |
|
177 | + array('EE_Cron_Tasks', $cron_task), |
|
178 | + array_merge( |
|
179 | + array( |
|
180 | + time() + (10 * MINUTE_IN_SECONDS), |
|
181 | + $TXN_ID, |
|
182 | + ), |
|
183 | + $additional_vars |
|
184 | + ) |
|
185 | + ); |
|
186 | + } |
|
187 | + return true; |
|
188 | + } |
|
189 | + return false; |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + |
|
194 | + |
|
195 | + /**************** UPDATE TRANSACTION WITH PAYMENT ****************/ |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * array of TXN IDs and the payment |
|
200 | + * |
|
201 | + * @var array |
|
202 | + */ |
|
203 | + protected static $_update_transactions_with_payment = array(); |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * schedule_update_transaction_with_payment |
|
208 | + * sets a wp_schedule_single_event() for updating any TXNs that may |
|
209 | + * require updating due to recently received payments |
|
210 | + * |
|
211 | + * @param int $timestamp |
|
212 | + * @param int $TXN_ID |
|
213 | + * @param int $PAY_ID |
|
214 | + */ |
|
215 | + public static function schedule_update_transaction_with_payment( |
|
216 | + $timestamp, |
|
217 | + $TXN_ID, |
|
218 | + $PAY_ID |
|
219 | + ) { |
|
220 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
221 | + // validate $TXN_ID and $timestamp |
|
222 | + $TXN_ID = absint($TXN_ID); |
|
223 | + $timestamp = absint($timestamp); |
|
224 | + if ($TXN_ID && $timestamp) { |
|
225 | + wp_schedule_single_event( |
|
226 | + $timestamp, |
|
227 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2', |
|
228 | + array($TXN_ID, $PAY_ID) |
|
229 | + ); |
|
230 | + } |
|
231 | + } |
|
232 | + |
|
233 | + |
|
234 | + /** |
|
235 | + * setup_update_for_transaction_with_payment |
|
236 | + * this is the callback for the action hook: |
|
237 | + * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' |
|
238 | + * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment(). |
|
239 | + * The passed TXN_ID and associated payment gets added to an array, and then |
|
240 | + * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into |
|
241 | + * 'shutdown' which will actually handle the processing of any |
|
242 | + * transactions requiring updating, because doing so now would be too early |
|
243 | + * and the required resources may not be available |
|
244 | + * |
|
245 | + * @param int $TXN_ID |
|
246 | + * @param int $PAY_ID |
|
247 | + */ |
|
248 | + public static function setup_update_for_transaction_with_payment($TXN_ID = 0, $PAY_ID = 0) |
|
249 | + { |
|
250 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID'); |
|
251 | + if (absint($TXN_ID)) { |
|
252 | + self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID; |
|
253 | + add_action( |
|
254 | + 'shutdown', |
|
255 | + array('EE_Cron_Tasks', 'update_transaction_with_payment'), |
|
256 | + 5 |
|
257 | + ); |
|
258 | + } |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * update_transaction_with_payment |
|
264 | + * loops through the self::$_abandoned_transactions array |
|
265 | + * and attempts to finalize any TXNs that have not been completed |
|
266 | + * but have had their sessions expired, most likely due to a user not |
|
267 | + * returning from an off-site payment gateway |
|
268 | + * |
|
269 | + * @throws EE_Error |
|
270 | + * @throws DomainException |
|
271 | + * @throws InvalidDataTypeException |
|
272 | + * @throws InvalidInterfaceException |
|
273 | + * @throws InvalidArgumentException |
|
274 | + * @throws ReflectionException |
|
275 | + * @throws RuntimeException |
|
276 | + */ |
|
277 | + public static function update_transaction_with_payment() |
|
278 | + { |
|
279 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
280 | + if (// are there any TXNs that need cleaning up ? |
|
281 | + empty(self::$_update_transactions_with_payment) |
|
282 | + // reschedule the cron if we can't hit the db right now |
|
283 | + || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
|
284 | + 'schedule_update_transaction_with_payment', |
|
285 | + self::$_update_transactions_with_payment |
|
286 | + ) |
|
287 | + ) { |
|
288 | + return; |
|
289 | + } |
|
290 | + /** @type EE_Payment_Processor $payment_processor */ |
|
291 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
292 | + // set revisit flag for payment processor |
|
293 | + $payment_processor->set_revisit(); |
|
294 | + // load EEM_Transaction |
|
295 | + EE_Registry::instance()->load_model('Transaction'); |
|
296 | + foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) { |
|
297 | + // reschedule the cron if we can't hit the db right now |
|
298 | + if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
299 | + // reset cron job for updating the TXN |
|
300 | + EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
301 | + time() + EE_Cron_Tasks::reschedule_timeout, |
|
302 | + $TXN_ID, |
|
303 | + $PAY_ID |
|
304 | + ); |
|
305 | + continue; |
|
306 | + } |
|
307 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
308 | + $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
309 | + // verify transaction |
|
310 | + if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) { |
|
311 | + // now try to update the TXN with any payments |
|
312 | + $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true); |
|
313 | + } |
|
314 | + unset(self::$_update_transactions_with_payment[ $TXN_ID ]); |
|
315 | + } |
|
316 | + } |
|
317 | + |
|
318 | + |
|
319 | + |
|
320 | + /************ END OF UPDATE TRANSACTION WITH PAYMENT ************/ |
|
321 | + |
|
322 | + |
|
323 | + /***************** EXPIRED TRANSACTION CHECK *****************/ |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * array of TXN IDs |
|
328 | + * |
|
329 | + * @var array |
|
330 | + */ |
|
331 | + protected static $_expired_transactions = array(); |
|
332 | + |
|
333 | + |
|
334 | + /** |
|
335 | + * schedule_expired_transaction_check |
|
336 | + * sets a wp_schedule_single_event() for following up on TXNs after their session has expired |
|
337 | + * |
|
338 | + * @param int $timestamp |
|
339 | + * @param int $TXN_ID |
|
340 | + */ |
|
341 | + public static function schedule_expired_transaction_check( |
|
342 | + $timestamp, |
|
343 | + $TXN_ID |
|
344 | + ) { |
|
345 | + // validate $TXN_ID and $timestamp |
|
346 | + $TXN_ID = absint($TXN_ID); |
|
347 | + $timestamp = absint($timestamp); |
|
348 | + if ($TXN_ID && $timestamp) { |
|
349 | + wp_schedule_single_event( |
|
350 | + $timestamp, |
|
351 | + 'AHEE__EE_Cron_Tasks__expired_transaction_check', |
|
352 | + array($TXN_ID) |
|
353 | + ); |
|
354 | + } |
|
355 | + } |
|
356 | + |
|
357 | + |
|
358 | + /** |
|
359 | + * expired_transaction_check |
|
360 | + * this is the callback for the action hook: |
|
361 | + * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check' |
|
362 | + * which is utilized by wp_schedule_single_event() |
|
363 | + * in \EED_Single_Page_Checkout::_initialize_transaction(). |
|
364 | + * The passed TXN_ID gets added to an array, and then the |
|
365 | + * process_expired_transactions() function is hooked into |
|
366 | + * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the |
|
367 | + * processing of any failed transactions, because doing so now would be |
|
368 | + * too early and the required resources may not be available |
|
369 | + * |
|
370 | + * @param int $TXN_ID |
|
371 | + */ |
|
372 | + public static function expired_transaction_check($TXN_ID = 0) |
|
373 | + { |
|
374 | + if (absint($TXN_ID)) { |
|
375 | + self::$_expired_transactions[ $TXN_ID ] = $TXN_ID; |
|
376 | + add_action( |
|
377 | + 'shutdown', |
|
378 | + array('EE_Cron_Tasks', 'process_expired_transactions'), |
|
379 | + 5 |
|
380 | + ); |
|
381 | + } |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * process_expired_transactions |
|
387 | + * loops through the self::$_expired_transactions array and processes any failed TXNs |
|
388 | + * |
|
389 | + * @throws EE_Error |
|
390 | + * @throws InvalidDataTypeException |
|
391 | + * @throws InvalidInterfaceException |
|
392 | + * @throws InvalidArgumentException |
|
393 | + * @throws ReflectionException |
|
394 | + * @throws DomainException |
|
395 | + * @throws RuntimeException |
|
396 | + */ |
|
397 | + public static function process_expired_transactions() |
|
398 | + { |
|
399 | + if (// are there any TXNs that need cleaning up ? |
|
400 | + empty(self::$_expired_transactions) |
|
401 | + // reschedule the cron if we can't hit the db right now |
|
402 | + || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
|
403 | + 'schedule_expired_transaction_check', |
|
404 | + self::$_expired_transactions |
|
405 | + ) |
|
406 | + ) { |
|
407 | + return; |
|
408 | + } |
|
409 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
410 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
411 | + // set revisit flag for txn processor |
|
412 | + $transaction_processor->set_revisit(); |
|
413 | + // load EEM_Transaction |
|
414 | + EE_Registry::instance()->load_model('Transaction'); |
|
415 | + foreach (self::$_expired_transactions as $TXN_ID) { |
|
416 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
417 | + // verify transaction and whether it is failed or not |
|
418 | + if ($transaction instanceof EE_Transaction) { |
|
419 | + switch ($transaction->status_ID()) { |
|
420 | + // Completed TXNs |
|
421 | + case EEM_Transaction::complete_status_code: |
|
422 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
423 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
424 | + $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
425 | + $transaction, |
|
426 | + $transaction->last_payment() |
|
427 | + ); |
|
428 | + do_action( |
|
429 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction', |
|
430 | + $transaction |
|
431 | + ); |
|
432 | + break; |
|
433 | + // Overpaid TXNs |
|
434 | + case EEM_Transaction::overpaid_status_code: |
|
435 | + do_action( |
|
436 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction', |
|
437 | + $transaction |
|
438 | + ); |
|
439 | + break; |
|
440 | + // Incomplete TXNs |
|
441 | + case EEM_Transaction::incomplete_status_code: |
|
442 | + do_action( |
|
443 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
444 | + $transaction |
|
445 | + ); |
|
446 | + // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions |
|
447 | + break; |
|
448 | + // Abandoned TXNs |
|
449 | + case EEM_Transaction::abandoned_status_code: |
|
450 | + // run hook before updating transaction, primarily so |
|
451 | + // EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets |
|
452 | + do_action( |
|
453 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
454 | + $transaction |
|
455 | + ); |
|
456 | + // don't finalize the TXN if it has already been completed |
|
457 | + if ($transaction->all_reg_steps_completed() !== true) { |
|
458 | + /** @type EE_Payment_Processor $payment_processor */ |
|
459 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
460 | + // let's simulate an IPN here which will trigger any notifications that need to go out |
|
461 | + $payment_processor->update_txn_based_on_payment( |
|
462 | + $transaction, |
|
463 | + $transaction->last_payment(), |
|
464 | + true, |
|
465 | + true |
|
466 | + ); |
|
467 | + } |
|
468 | + break; |
|
469 | + // Failed TXNs |
|
470 | + case EEM_Transaction::failed_status_code: |
|
471 | + do_action( |
|
472 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
473 | + $transaction |
|
474 | + ); |
|
475 | + // todo : |
|
476 | + // perform garbage collection here and remove clean_out_junk_transactions() |
|
477 | + // $registrations = $transaction->registrations(); |
|
478 | + // if (! empty($registrations)) { |
|
479 | + // foreach ($registrations as $registration) { |
|
480 | + // if ($registration instanceof EE_Registration) { |
|
481 | + // $delete_registration = true; |
|
482 | + // if ($registration->attendee() instanceof EE_Attendee) { |
|
483 | + // $delete_registration = false; |
|
484 | + // } |
|
485 | + // if ($delete_registration) { |
|
486 | + // $registration->delete_permanently(); |
|
487 | + // $registration->delete_related_permanently(); |
|
488 | + // } |
|
489 | + // } |
|
490 | + // } |
|
491 | + // } |
|
492 | + break; |
|
493 | + } |
|
494 | + } |
|
495 | + unset(self::$_expired_transactions[ $TXN_ID ]); |
|
496 | + } |
|
497 | + } |
|
498 | + |
|
499 | + |
|
500 | + |
|
501 | + /************* END OF EXPIRED TRANSACTION CHECK *************/ |
|
502 | + |
|
503 | + |
|
504 | + /************* START CLEAN UP BOT TRANSACTIONS **********************/ |
|
505 | + |
|
506 | + |
|
507 | + /** |
|
508 | + * callback for 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' |
|
509 | + * which is setup during activation to run on an hourly cron |
|
510 | + * |
|
511 | + * @throws EE_Error |
|
512 | + * @throws InvalidArgumentException |
|
513 | + * @throws InvalidDataTypeException |
|
514 | + * @throws InvalidInterfaceException |
|
515 | + * @throws DomainException |
|
516 | + */ |
|
517 | + public static function clean_out_junk_transactions() |
|
518 | + { |
|
519 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
520 | + EED_Ticket_Sales_Monitor::reset_reservation_counts(); |
|
521 | + EEM_Transaction::instance('')->delete_junk_transactions(); |
|
522 | + EEM_Registration::instance('')->delete_registrations_with_no_transaction(); |
|
523 | + EEM_Line_Item::instance('')->delete_line_items_with_no_transaction(); |
|
524 | + } |
|
525 | + } |
|
526 | + |
|
527 | + |
|
528 | + /** |
|
529 | + * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that. |
|
530 | + * |
|
531 | + * @throws EE_Error |
|
532 | + * @throws InvalidDataTypeException |
|
533 | + * @throws InvalidInterfaceException |
|
534 | + * @throws InvalidArgumentException |
|
535 | + */ |
|
536 | + public static function clean_out_old_gateway_logs() |
|
537 | + { |
|
538 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
539 | + $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config'); |
|
540 | + $time_diff_for_comparison = apply_filters( |
|
541 | + 'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison', |
|
542 | + '-' . $reg_config->gateway_log_lifespan |
|
543 | + ); |
|
544 | + EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison)); |
|
545 | + } |
|
546 | + } |
|
547 | + |
|
548 | + |
|
549 | + /***************** FINALIZE ABANDONED TRANSACTIONS *****************/ |
|
550 | + |
|
551 | + |
|
552 | + /** |
|
553 | + * @var array |
|
554 | + */ |
|
555 | + protected static $_abandoned_transactions = array(); |
|
556 | + |
|
557 | + |
|
558 | + /** |
|
559 | + * @deprecated |
|
560 | + * @param int $timestamp |
|
561 | + * @param int $TXN_ID |
|
562 | + */ |
|
563 | + public static function schedule_finalize_abandoned_transactions_check($timestamp, $TXN_ID) |
|
564 | + { |
|
565 | + EE_Cron_Tasks::schedule_expired_transaction_check($timestamp, $TXN_ID); |
|
566 | + } |
|
567 | + |
|
568 | + |
|
569 | + /** |
|
570 | + * @deprecated |
|
571 | + * @param int $TXN_ID |
|
572 | + */ |
|
573 | + public static function check_for_abandoned_transactions($TXN_ID = 0) |
|
574 | + { |
|
575 | + EE_Cron_Tasks::expired_transaction_check($TXN_ID); |
|
576 | + } |
|
577 | + |
|
578 | + |
|
579 | + /** |
|
580 | + * @deprecated |
|
581 | + * @throws EE_Error |
|
582 | + * @throws DomainException |
|
583 | + * @throws InvalidDataTypeException |
|
584 | + * @throws InvalidInterfaceException |
|
585 | + * @throws InvalidArgumentException |
|
586 | + * @throws ReflectionException |
|
587 | + * @throws RuntimeException |
|
588 | + */ |
|
589 | + public static function finalize_abandoned_transactions() |
|
590 | + { |
|
591 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
592 | + if (// are there any TXNs that need cleaning up ? |
|
593 | + empty(self::$_abandoned_transactions) |
|
594 | + // reschedule the cron if we can't hit the db right now |
|
595 | + || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode( |
|
596 | + 'schedule_expired_transaction_check', |
|
597 | + self::$_abandoned_transactions |
|
598 | + ) |
|
599 | + ) { |
|
600 | + return; |
|
601 | + } |
|
602 | + // combine our arrays of transaction IDs |
|
603 | + self::$_expired_transactions = self::$_abandoned_transactions + self::$_expired_transactions; |
|
604 | + // and deal with abandoned transactions here now... |
|
605 | + EE_Cron_Tasks::process_expired_transactions(); |
|
606 | + } |
|
607 | + |
|
608 | + |
|
609 | + /************* END OF FINALIZE ABANDONED TRANSACTIONS *************/ |
|
610 | 610 | } |
@@ -22,239 +22,239 @@ |
||
22 | 22 | class ThankYouPageIpnMonitor |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @var string $heartbeat |
|
27 | - */ |
|
28 | - private $heartbeat; |
|
25 | + /** |
|
26 | + * @var string $heartbeat |
|
27 | + */ |
|
28 | + private $heartbeat; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var EED_Thank_You_Page $thank_you_page |
|
32 | - */ |
|
33 | - private $thank_you_page; |
|
30 | + /** |
|
31 | + * @var EED_Thank_You_Page $thank_you_page |
|
32 | + */ |
|
33 | + private $thank_you_page; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @var EE_Transaction $transaction |
|
37 | - */ |
|
38 | - private $transaction; |
|
35 | + /** |
|
36 | + * @var EE_Transaction $transaction |
|
37 | + */ |
|
38 | + private $transaction; |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * EventEditorHeartbeat constructor. |
|
43 | - */ |
|
44 | - public function __construct() |
|
45 | - { |
|
46 | - $this->heartbeat = WordpressHeartbeat::RESPONSE_KEY_THANK_YOU_PAGE; |
|
47 | - add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 3); |
|
48 | - add_filter('heartbeat_nopriv_received', array($this, 'heartbeatResponse'), 10, 3); |
|
49 | - } |
|
41 | + /** |
|
42 | + * EventEditorHeartbeat constructor. |
|
43 | + */ |
|
44 | + public function __construct() |
|
45 | + { |
|
46 | + $this->heartbeat = WordpressHeartbeat::RESPONSE_KEY_THANK_YOU_PAGE; |
|
47 | + add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 3); |
|
48 | + add_filter('heartbeat_nopriv_received', array($this, 'heartbeatResponse'), 10, 3); |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * thank_you_page_IPN_monitor |
|
54 | - * this basically just pulls the TXN based on the reg_url_link sent from the server, |
|
55 | - * then checks that the TXN status is not failed, and that no other errors have been generated. |
|
56 | - * it also calculates the IPN wait time since the Thank You page was first loaded |
|
57 | - * |
|
58 | - * @param array $response |
|
59 | - * @param array $data |
|
60 | - * @return array |
|
61 | - * @throws EE_Error |
|
62 | - * @throws InvalidArgumentException |
|
63 | - * @throws InvalidDataTypeException |
|
64 | - * @throws InvalidInterfaceException |
|
65 | - * @throws ReflectionException |
|
66 | - */ |
|
67 | - public function heartbeatResponse($response = array(), $data = array()) |
|
68 | - { |
|
69 | - // does this heartbeat contain our data ? |
|
70 | - if (! isset($data[ $this->heartbeat ])) { |
|
71 | - return $response; |
|
72 | - } |
|
73 | - // check for reg_url_link in the incoming heartbeat data |
|
74 | - if (! isset($data[ $this->heartbeat ]['e_reg_url_link'])) { |
|
75 | - $response[ $this->heartbeat ] = array( |
|
76 | - 'errors' => ! empty($notices['errors']) |
|
77 | - ? $notices['errors'] |
|
78 | - : __( |
|
79 | - 'No transaction information could be retrieved because the registration URL link is missing or invalid.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - ); |
|
83 | - return $response; |
|
84 | - } |
|
85 | - // kk heartbeat has our data |
|
86 | - $response = $this->initializeThankYouPageAndTransaction($response, $data); |
|
87 | - // if something went wrong... |
|
88 | - if (isset($response[ $this->heartbeat ]['errors'])) { |
|
89 | - return $response; |
|
90 | - } |
|
91 | - // grab transient of Transaction's status |
|
92 | - $txn_status = isset($data[ $this->heartbeat ]['txn_status']) |
|
93 | - ? $data[ $this->heartbeat ]['txn_status'] |
|
94 | - : null; |
|
95 | - $response = $this->getTransactionDetails($txn_status, $response, $data); |
|
96 | - // no payment data yet? |
|
97 | - if (isset($response[ $this->heartbeat ]['still_waiting'])) { |
|
98 | - return $response; |
|
99 | - } |
|
100 | - // TXN is happening so let's get the payments now |
|
101 | - // if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked |
|
102 | - $since = isset($data[ $this->heartbeat ]['get_payments_since']) |
|
103 | - ? $data[ $this->heartbeat ]['get_payments_since'] |
|
104 | - : 0; |
|
105 | - return $this->paymentDetails($response, $since); |
|
106 | - } |
|
52 | + /** |
|
53 | + * thank_you_page_IPN_monitor |
|
54 | + * this basically just pulls the TXN based on the reg_url_link sent from the server, |
|
55 | + * then checks that the TXN status is not failed, and that no other errors have been generated. |
|
56 | + * it also calculates the IPN wait time since the Thank You page was first loaded |
|
57 | + * |
|
58 | + * @param array $response |
|
59 | + * @param array $data |
|
60 | + * @return array |
|
61 | + * @throws EE_Error |
|
62 | + * @throws InvalidArgumentException |
|
63 | + * @throws InvalidDataTypeException |
|
64 | + * @throws InvalidInterfaceException |
|
65 | + * @throws ReflectionException |
|
66 | + */ |
|
67 | + public function heartbeatResponse($response = array(), $data = array()) |
|
68 | + { |
|
69 | + // does this heartbeat contain our data ? |
|
70 | + if (! isset($data[ $this->heartbeat ])) { |
|
71 | + return $response; |
|
72 | + } |
|
73 | + // check for reg_url_link in the incoming heartbeat data |
|
74 | + if (! isset($data[ $this->heartbeat ]['e_reg_url_link'])) { |
|
75 | + $response[ $this->heartbeat ] = array( |
|
76 | + 'errors' => ! empty($notices['errors']) |
|
77 | + ? $notices['errors'] |
|
78 | + : __( |
|
79 | + 'No transaction information could be retrieved because the registration URL link is missing or invalid.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + ); |
|
83 | + return $response; |
|
84 | + } |
|
85 | + // kk heartbeat has our data |
|
86 | + $response = $this->initializeThankYouPageAndTransaction($response, $data); |
|
87 | + // if something went wrong... |
|
88 | + if (isset($response[ $this->heartbeat ]['errors'])) { |
|
89 | + return $response; |
|
90 | + } |
|
91 | + // grab transient of Transaction's status |
|
92 | + $txn_status = isset($data[ $this->heartbeat ]['txn_status']) |
|
93 | + ? $data[ $this->heartbeat ]['txn_status'] |
|
94 | + : null; |
|
95 | + $response = $this->getTransactionDetails($txn_status, $response, $data); |
|
96 | + // no payment data yet? |
|
97 | + if (isset($response[ $this->heartbeat ]['still_waiting'])) { |
|
98 | + return $response; |
|
99 | + } |
|
100 | + // TXN is happening so let's get the payments now |
|
101 | + // if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked |
|
102 | + $since = isset($data[ $this->heartbeat ]['get_payments_since']) |
|
103 | + ? $data[ $this->heartbeat ]['get_payments_since'] |
|
104 | + : 0; |
|
105 | + return $this->paymentDetails($response, $since); |
|
106 | + } |
|
107 | 107 | |
108 | 108 | |
109 | - /** |
|
110 | - * @param array $response |
|
111 | - * @param array $data |
|
112 | - * @return array |
|
113 | - * @throws EE_Error |
|
114 | - * @throws InvalidArgumentException |
|
115 | - * @throws InvalidDataTypeException |
|
116 | - * @throws InvalidInterfaceException |
|
117 | - */ |
|
118 | - private function initializeThankYouPageAndTransaction($response, $data) |
|
119 | - { |
|
120 | - require_once EE_MODULES . 'thank_you_page/EED_Thank_You_Page.module.php'; |
|
121 | - // set_definitions, instantiate the thank you page class, and get the ball rolling |
|
122 | - EED_Thank_You_Page::set_definitions(); |
|
123 | - $this->thank_you_page = EED_Thank_You_Page::instance(); |
|
124 | - $this->thank_you_page->set_reg_url_link($data[ $this->heartbeat ]['e_reg_url_link']); |
|
125 | - $this->thank_you_page->init(); |
|
126 | - // get TXN |
|
127 | - $transaction = $this->thank_you_page->get_txn(); |
|
128 | - // no TXN? then get out |
|
129 | - if (! $transaction instanceof EE_Transaction) { |
|
130 | - $notices = EE_Error::get_notices(); |
|
131 | - $response[ $this->heartbeat ] = array( |
|
132 | - 'errors' => ! empty($notices['errors']) |
|
133 | - ? $notices['errors'] |
|
134 | - : sprintf( |
|
135 | - __( |
|
136 | - 'The information for your transaction could not be retrieved from the server or the transaction data received was invalid because of a technical reason. (%s)', |
|
137 | - 'event_espresso' |
|
138 | - ), |
|
139 | - __LINE__ |
|
140 | - ), |
|
141 | - ); |
|
142 | - return $response; |
|
143 | - } |
|
144 | - $this->transaction = $transaction; |
|
145 | - return $response; |
|
146 | - } |
|
109 | + /** |
|
110 | + * @param array $response |
|
111 | + * @param array $data |
|
112 | + * @return array |
|
113 | + * @throws EE_Error |
|
114 | + * @throws InvalidArgumentException |
|
115 | + * @throws InvalidDataTypeException |
|
116 | + * @throws InvalidInterfaceException |
|
117 | + */ |
|
118 | + private function initializeThankYouPageAndTransaction($response, $data) |
|
119 | + { |
|
120 | + require_once EE_MODULES . 'thank_you_page/EED_Thank_You_Page.module.php'; |
|
121 | + // set_definitions, instantiate the thank you page class, and get the ball rolling |
|
122 | + EED_Thank_You_Page::set_definitions(); |
|
123 | + $this->thank_you_page = EED_Thank_You_Page::instance(); |
|
124 | + $this->thank_you_page->set_reg_url_link($data[ $this->heartbeat ]['e_reg_url_link']); |
|
125 | + $this->thank_you_page->init(); |
|
126 | + // get TXN |
|
127 | + $transaction = $this->thank_you_page->get_txn(); |
|
128 | + // no TXN? then get out |
|
129 | + if (! $transaction instanceof EE_Transaction) { |
|
130 | + $notices = EE_Error::get_notices(); |
|
131 | + $response[ $this->heartbeat ] = array( |
|
132 | + 'errors' => ! empty($notices['errors']) |
|
133 | + ? $notices['errors'] |
|
134 | + : sprintf( |
|
135 | + __( |
|
136 | + 'The information for your transaction could not be retrieved from the server or the transaction data received was invalid because of a technical reason. (%s)', |
|
137 | + 'event_espresso' |
|
138 | + ), |
|
139 | + __LINE__ |
|
140 | + ), |
|
141 | + ); |
|
142 | + return $response; |
|
143 | + } |
|
144 | + $this->transaction = $transaction; |
|
145 | + return $response; |
|
146 | + } |
|
147 | 147 | |
148 | 148 | |
149 | - /** |
|
150 | - * @param string $txn_status |
|
151 | - * @param array $response |
|
152 | - * @param array $data |
|
153 | - * @return array |
|
154 | - * @throws EE_Error |
|
155 | - * @throws InvalidArgumentException |
|
156 | - * @throws InvalidDataTypeException |
|
157 | - * @throws InvalidInterfaceException |
|
158 | - * @throws ReflectionException |
|
159 | - */ |
|
160 | - private function getTransactionDetails($txn_status, $response, $data) |
|
161 | - { |
|
162 | - // has the TXN status changed since we last checked (or empty because this is the first time running through this code)? |
|
163 | - if ($txn_status !== $this->transaction->status_ID()) { |
|
164 | - // switch between two possible basic outcomes |
|
165 | - switch ($this->transaction->status_ID()) { |
|
166 | - // TXN has been updated in some way |
|
167 | - case EEM_Transaction::overpaid_status_code: |
|
168 | - case EEM_Transaction::complete_status_code: |
|
169 | - case EEM_Transaction::incomplete_status_code: |
|
170 | - // send updated TXN results back to client, |
|
171 | - return $this->setTransactionDetails($response); |
|
172 | - // or we have a bad TXN, or really slow IPN, so calculate the wait time and send that back... |
|
173 | - case EEM_Transaction::failed_status_code: |
|
174 | - default: |
|
175 | - // keep on waiting... |
|
176 | - return $this->updateServerWaitTime($data[ $this->heartbeat ]); |
|
177 | - } |
|
178 | - // or is the TXN still failed (never been updated) ??? |
|
179 | - } elseif ($this->transaction->failed()) { |
|
180 | - // keep on waiting... |
|
181 | - return $this->updateServerWaitTime($data[ $this->heartbeat ]); |
|
182 | - } |
|
183 | - return $response; |
|
184 | - } |
|
149 | + /** |
|
150 | + * @param string $txn_status |
|
151 | + * @param array $response |
|
152 | + * @param array $data |
|
153 | + * @return array |
|
154 | + * @throws EE_Error |
|
155 | + * @throws InvalidArgumentException |
|
156 | + * @throws InvalidDataTypeException |
|
157 | + * @throws InvalidInterfaceException |
|
158 | + * @throws ReflectionException |
|
159 | + */ |
|
160 | + private function getTransactionDetails($txn_status, $response, $data) |
|
161 | + { |
|
162 | + // has the TXN status changed since we last checked (or empty because this is the first time running through this code)? |
|
163 | + if ($txn_status !== $this->transaction->status_ID()) { |
|
164 | + // switch between two possible basic outcomes |
|
165 | + switch ($this->transaction->status_ID()) { |
|
166 | + // TXN has been updated in some way |
|
167 | + case EEM_Transaction::overpaid_status_code: |
|
168 | + case EEM_Transaction::complete_status_code: |
|
169 | + case EEM_Transaction::incomplete_status_code: |
|
170 | + // send updated TXN results back to client, |
|
171 | + return $this->setTransactionDetails($response); |
|
172 | + // or we have a bad TXN, or really slow IPN, so calculate the wait time and send that back... |
|
173 | + case EEM_Transaction::failed_status_code: |
|
174 | + default: |
|
175 | + // keep on waiting... |
|
176 | + return $this->updateServerWaitTime($data[ $this->heartbeat ]); |
|
177 | + } |
|
178 | + // or is the TXN still failed (never been updated) ??? |
|
179 | + } elseif ($this->transaction->failed()) { |
|
180 | + // keep on waiting... |
|
181 | + return $this->updateServerWaitTime($data[ $this->heartbeat ]); |
|
182 | + } |
|
183 | + return $response; |
|
184 | + } |
|
185 | 185 | |
186 | 186 | |
187 | - /** |
|
188 | - * @param array $response |
|
189 | - * @param boolean $status_only |
|
190 | - * @return array |
|
191 | - * @throws EE_Error |
|
192 | - * @throws InvalidArgumentException |
|
193 | - * @throws InvalidDataTypeException |
|
194 | - * @throws InvalidInterfaceException |
|
195 | - * @throws ReflectionException |
|
196 | - */ |
|
197 | - private function setTransactionDetails($response, $status_only = false) |
|
198 | - { |
|
199 | - if (! $status_only && ! isset($response[ $this->heartbeat ]['transaction_details'])) { |
|
200 | - $response[ $this->heartbeat ]['transaction_details'] = $this->thank_you_page->get_transaction_details(); |
|
201 | - } |
|
202 | - if (! isset($response[ $this->heartbeat ]['txn_status'])) { |
|
203 | - $response[ $this->heartbeat ]['txn_status'] = $this->transaction->status_ID(); |
|
204 | - } |
|
205 | - return $response; |
|
206 | - } |
|
187 | + /** |
|
188 | + * @param array $response |
|
189 | + * @param boolean $status_only |
|
190 | + * @return array |
|
191 | + * @throws EE_Error |
|
192 | + * @throws InvalidArgumentException |
|
193 | + * @throws InvalidDataTypeException |
|
194 | + * @throws InvalidInterfaceException |
|
195 | + * @throws ReflectionException |
|
196 | + */ |
|
197 | + private function setTransactionDetails($response, $status_only = false) |
|
198 | + { |
|
199 | + if (! $status_only && ! isset($response[ $this->heartbeat ]['transaction_details'])) { |
|
200 | + $response[ $this->heartbeat ]['transaction_details'] = $this->thank_you_page->get_transaction_details(); |
|
201 | + } |
|
202 | + if (! isset($response[ $this->heartbeat ]['txn_status'])) { |
|
203 | + $response[ $this->heartbeat ]['txn_status'] = $this->transaction->status_ID(); |
|
204 | + } |
|
205 | + return $response; |
|
206 | + } |
|
207 | 207 | |
208 | 208 | |
209 | - /** |
|
210 | - * @param array $response |
|
211 | - * @param int $since |
|
212 | - * @return array |
|
213 | - * @throws EE_Error |
|
214 | - * @throws InvalidArgumentException |
|
215 | - * @throws InvalidDataTypeException |
|
216 | - * @throws InvalidInterfaceException |
|
217 | - * @throws ReflectionException |
|
218 | - */ |
|
219 | - private function paymentDetails($response, $since) |
|
220 | - { |
|
221 | - // then check for payments |
|
222 | - $payments = $this->thank_you_page->get_txn_payments($since); |
|
223 | - // has a payment been processed ? |
|
224 | - if (! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) { |
|
225 | - if ($since) { |
|
226 | - $response[ $this->heartbeat ]['new_payments'] = $this->thank_you_page->get_new_payments($payments); |
|
227 | - $response = $this->setTransactionDetails($response); |
|
228 | - } else { |
|
229 | - $response[ $this->heartbeat ]['payment_details'] = $this->thank_you_page->get_payment_details( |
|
230 | - $payments |
|
231 | - ); |
|
232 | - } |
|
233 | - // reset time to check for payments |
|
234 | - $response[ $this->heartbeat ]['get_payments_since'] = time(); |
|
235 | - } else { |
|
236 | - $response[ $this->heartbeat ]['get_payments_since'] = $since; |
|
237 | - } |
|
238 | - return $response; |
|
239 | - } |
|
209 | + /** |
|
210 | + * @param array $response |
|
211 | + * @param int $since |
|
212 | + * @return array |
|
213 | + * @throws EE_Error |
|
214 | + * @throws InvalidArgumentException |
|
215 | + * @throws InvalidDataTypeException |
|
216 | + * @throws InvalidInterfaceException |
|
217 | + * @throws ReflectionException |
|
218 | + */ |
|
219 | + private function paymentDetails($response, $since) |
|
220 | + { |
|
221 | + // then check for payments |
|
222 | + $payments = $this->thank_you_page->get_txn_payments($since); |
|
223 | + // has a payment been processed ? |
|
224 | + if (! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) { |
|
225 | + if ($since) { |
|
226 | + $response[ $this->heartbeat ]['new_payments'] = $this->thank_you_page->get_new_payments($payments); |
|
227 | + $response = $this->setTransactionDetails($response); |
|
228 | + } else { |
|
229 | + $response[ $this->heartbeat ]['payment_details'] = $this->thank_you_page->get_payment_details( |
|
230 | + $payments |
|
231 | + ); |
|
232 | + } |
|
233 | + // reset time to check for payments |
|
234 | + $response[ $this->heartbeat ]['get_payments_since'] = time(); |
|
235 | + } else { |
|
236 | + $response[ $this->heartbeat ]['get_payments_since'] = $since; |
|
237 | + } |
|
238 | + return $response; |
|
239 | + } |
|
240 | 240 | |
241 | 241 | |
242 | - /** |
|
243 | - * @param array $thank_you_page_data thank you page portion of the incoming JSON array |
|
244 | - * from the WP heartbeat data |
|
245 | - * @return array |
|
246 | - * @throws EE_Error |
|
247 | - * @throws InvalidArgumentException |
|
248 | - * @throws InvalidDataTypeException |
|
249 | - * @throws InvalidInterfaceException |
|
250 | - * @throws ReflectionException |
|
251 | - */ |
|
252 | - private function updateServerWaitTime($thank_you_page_data) |
|
253 | - { |
|
254 | - $response[ $this->heartbeat ]['still_waiting'] = isset($thank_you_page_data['initial_access']) |
|
255 | - ? time() - $thank_you_page_data['initial_access'] |
|
256 | - : 0; |
|
257 | - $response = $this->setTransactionDetails($response, true); |
|
258 | - return $response; |
|
259 | - } |
|
242 | + /** |
|
243 | + * @param array $thank_you_page_data thank you page portion of the incoming JSON array |
|
244 | + * from the WP heartbeat data |
|
245 | + * @return array |
|
246 | + * @throws EE_Error |
|
247 | + * @throws InvalidArgumentException |
|
248 | + * @throws InvalidDataTypeException |
|
249 | + * @throws InvalidInterfaceException |
|
250 | + * @throws ReflectionException |
|
251 | + */ |
|
252 | + private function updateServerWaitTime($thank_you_page_data) |
|
253 | + { |
|
254 | + $response[ $this->heartbeat ]['still_waiting'] = isset($thank_you_page_data['initial_access']) |
|
255 | + ? time() - $thank_you_page_data['initial_access'] |
|
256 | + : 0; |
|
257 | + $response = $this->setTransactionDetails($response, true); |
|
258 | + return $response; |
|
259 | + } |
|
260 | 260 | } |
@@ -67,12 +67,12 @@ discard block |
||
67 | 67 | public function heartbeatResponse($response = array(), $data = array()) |
68 | 68 | { |
69 | 69 | // does this heartbeat contain our data ? |
70 | - if (! isset($data[ $this->heartbeat ])) { |
|
70 | + if ( ! isset($data[$this->heartbeat])) { |
|
71 | 71 | return $response; |
72 | 72 | } |
73 | 73 | // check for reg_url_link in the incoming heartbeat data |
74 | - if (! isset($data[ $this->heartbeat ]['e_reg_url_link'])) { |
|
75 | - $response[ $this->heartbeat ] = array( |
|
74 | + if ( ! isset($data[$this->heartbeat]['e_reg_url_link'])) { |
|
75 | + $response[$this->heartbeat] = array( |
|
76 | 76 | 'errors' => ! empty($notices['errors']) |
77 | 77 | ? $notices['errors'] |
78 | 78 | : __( |
@@ -85,22 +85,22 @@ discard block |
||
85 | 85 | // kk heartbeat has our data |
86 | 86 | $response = $this->initializeThankYouPageAndTransaction($response, $data); |
87 | 87 | // if something went wrong... |
88 | - if (isset($response[ $this->heartbeat ]['errors'])) { |
|
88 | + if (isset($response[$this->heartbeat]['errors'])) { |
|
89 | 89 | return $response; |
90 | 90 | } |
91 | 91 | // grab transient of Transaction's status |
92 | - $txn_status = isset($data[ $this->heartbeat ]['txn_status']) |
|
93 | - ? $data[ $this->heartbeat ]['txn_status'] |
|
92 | + $txn_status = isset($data[$this->heartbeat]['txn_status']) |
|
93 | + ? $data[$this->heartbeat]['txn_status'] |
|
94 | 94 | : null; |
95 | 95 | $response = $this->getTransactionDetails($txn_status, $response, $data); |
96 | 96 | // no payment data yet? |
97 | - if (isset($response[ $this->heartbeat ]['still_waiting'])) { |
|
97 | + if (isset($response[$this->heartbeat]['still_waiting'])) { |
|
98 | 98 | return $response; |
99 | 99 | } |
100 | 100 | // TXN is happening so let's get the payments now |
101 | 101 | // if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked |
102 | - $since = isset($data[ $this->heartbeat ]['get_payments_since']) |
|
103 | - ? $data[ $this->heartbeat ]['get_payments_since'] |
|
102 | + $since = isset($data[$this->heartbeat]['get_payments_since']) |
|
103 | + ? $data[$this->heartbeat]['get_payments_since'] |
|
104 | 104 | : 0; |
105 | 105 | return $this->paymentDetails($response, $since); |
106 | 106 | } |
@@ -117,18 +117,18 @@ discard block |
||
117 | 117 | */ |
118 | 118 | private function initializeThankYouPageAndTransaction($response, $data) |
119 | 119 | { |
120 | - require_once EE_MODULES . 'thank_you_page/EED_Thank_You_Page.module.php'; |
|
120 | + require_once EE_MODULES.'thank_you_page/EED_Thank_You_Page.module.php'; |
|
121 | 121 | // set_definitions, instantiate the thank you page class, and get the ball rolling |
122 | 122 | EED_Thank_You_Page::set_definitions(); |
123 | 123 | $this->thank_you_page = EED_Thank_You_Page::instance(); |
124 | - $this->thank_you_page->set_reg_url_link($data[ $this->heartbeat ]['e_reg_url_link']); |
|
124 | + $this->thank_you_page->set_reg_url_link($data[$this->heartbeat]['e_reg_url_link']); |
|
125 | 125 | $this->thank_you_page->init(); |
126 | 126 | // get TXN |
127 | 127 | $transaction = $this->thank_you_page->get_txn(); |
128 | 128 | // no TXN? then get out |
129 | - if (! $transaction instanceof EE_Transaction) { |
|
129 | + if ( ! $transaction instanceof EE_Transaction) { |
|
130 | 130 | $notices = EE_Error::get_notices(); |
131 | - $response[ $this->heartbeat ] = array( |
|
131 | + $response[$this->heartbeat] = array( |
|
132 | 132 | 'errors' => ! empty($notices['errors']) |
133 | 133 | ? $notices['errors'] |
134 | 134 | : sprintf( |
@@ -173,12 +173,12 @@ discard block |
||
173 | 173 | case EEM_Transaction::failed_status_code: |
174 | 174 | default: |
175 | 175 | // keep on waiting... |
176 | - return $this->updateServerWaitTime($data[ $this->heartbeat ]); |
|
176 | + return $this->updateServerWaitTime($data[$this->heartbeat]); |
|
177 | 177 | } |
178 | 178 | // or is the TXN still failed (never been updated) ??? |
179 | 179 | } elseif ($this->transaction->failed()) { |
180 | 180 | // keep on waiting... |
181 | - return $this->updateServerWaitTime($data[ $this->heartbeat ]); |
|
181 | + return $this->updateServerWaitTime($data[$this->heartbeat]); |
|
182 | 182 | } |
183 | 183 | return $response; |
184 | 184 | } |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | */ |
197 | 197 | private function setTransactionDetails($response, $status_only = false) |
198 | 198 | { |
199 | - if (! $status_only && ! isset($response[ $this->heartbeat ]['transaction_details'])) { |
|
200 | - $response[ $this->heartbeat ]['transaction_details'] = $this->thank_you_page->get_transaction_details(); |
|
199 | + if ( ! $status_only && ! isset($response[$this->heartbeat]['transaction_details'])) { |
|
200 | + $response[$this->heartbeat]['transaction_details'] = $this->thank_you_page->get_transaction_details(); |
|
201 | 201 | } |
202 | - if (! isset($response[ $this->heartbeat ]['txn_status'])) { |
|
203 | - $response[ $this->heartbeat ]['txn_status'] = $this->transaction->status_ID(); |
|
202 | + if ( ! isset($response[$this->heartbeat]['txn_status'])) { |
|
203 | + $response[$this->heartbeat]['txn_status'] = $this->transaction->status_ID(); |
|
204 | 204 | } |
205 | 205 | return $response; |
206 | 206 | } |
@@ -221,19 +221,19 @@ discard block |
||
221 | 221 | // then check for payments |
222 | 222 | $payments = $this->thank_you_page->get_txn_payments($since); |
223 | 223 | // has a payment been processed ? |
224 | - if (! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) { |
|
224 | + if ( ! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) { |
|
225 | 225 | if ($since) { |
226 | - $response[ $this->heartbeat ]['new_payments'] = $this->thank_you_page->get_new_payments($payments); |
|
226 | + $response[$this->heartbeat]['new_payments'] = $this->thank_you_page->get_new_payments($payments); |
|
227 | 227 | $response = $this->setTransactionDetails($response); |
228 | 228 | } else { |
229 | - $response[ $this->heartbeat ]['payment_details'] = $this->thank_you_page->get_payment_details( |
|
229 | + $response[$this->heartbeat]['payment_details'] = $this->thank_you_page->get_payment_details( |
|
230 | 230 | $payments |
231 | 231 | ); |
232 | 232 | } |
233 | 233 | // reset time to check for payments |
234 | - $response[ $this->heartbeat ]['get_payments_since'] = time(); |
|
234 | + $response[$this->heartbeat]['get_payments_since'] = time(); |
|
235 | 235 | } else { |
236 | - $response[ $this->heartbeat ]['get_payments_since'] = $since; |
|
236 | + $response[$this->heartbeat]['get_payments_since'] = $since; |
|
237 | 237 | } |
238 | 238 | return $response; |
239 | 239 | } |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | */ |
252 | 252 | private function updateServerWaitTime($thank_you_page_data) |
253 | 253 | { |
254 | - $response[ $this->heartbeat ]['still_waiting'] = isset($thank_you_page_data['initial_access']) |
|
254 | + $response[$this->heartbeat]['still_waiting'] = isset($thank_you_page_data['initial_access']) |
|
255 | 255 | ? time() - $thank_you_page_data['initial_access'] |
256 | 256 | : 0; |
257 | 257 | $response = $this->setTransactionDetails($response, true); |
@@ -17,52 +17,52 @@ |
||
17 | 17 | class WordpressHeartbeat |
18 | 18 | { |
19 | 19 | |
20 | - const RESPONSE_KEY_THANK_YOU_PAGE = 'espresso_thank_you_page'; |
|
20 | + const RESPONSE_KEY_THANK_YOU_PAGE = 'espresso_thank_you_page'; |
|
21 | 21 | |
22 | - /** |
|
23 | - * @var LoaderInterface $loader |
|
24 | - */ |
|
25 | - protected $loader; |
|
22 | + /** |
|
23 | + * @var LoaderInterface $loader |
|
24 | + */ |
|
25 | + protected $loader; |
|
26 | 26 | |
27 | - /** |
|
28 | - * @var RequestInterface $request |
|
29 | - */ |
|
30 | - protected $request; |
|
27 | + /** |
|
28 | + * @var RequestInterface $request |
|
29 | + */ |
|
30 | + protected $request; |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * WordpressHeartbeat constructor. |
|
35 | - * |
|
36 | - * @param LoaderInterface $loader |
|
37 | - * @param RequestInterface $request |
|
38 | - */ |
|
39 | - public function __construct( |
|
40 | - LoaderInterface $loader, |
|
41 | - RequestInterface $request |
|
42 | - ) { |
|
43 | - $this->loader = $loader; |
|
44 | - $this->request = $request; |
|
45 | - do_action('AHEE__EventEspresso_core_domain_services_admin_ajax_WordpressHeartbeat__constructor', $this); |
|
46 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'resolveRoutes')); |
|
47 | - } |
|
33 | + /** |
|
34 | + * WordpressHeartbeat constructor. |
|
35 | + * |
|
36 | + * @param LoaderInterface $loader |
|
37 | + * @param RequestInterface $request |
|
38 | + */ |
|
39 | + public function __construct( |
|
40 | + LoaderInterface $loader, |
|
41 | + RequestInterface $request |
|
42 | + ) { |
|
43 | + $this->loader = $loader; |
|
44 | + $this->request = $request; |
|
45 | + do_action('AHEE__EventEspresso_core_domain_services_admin_ajax_WordpressHeartbeat__constructor', $this); |
|
46 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'resolveRoutes')); |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * @since 4.9.76.p |
|
52 | - * @throws InvalidClassException |
|
53 | - */ |
|
54 | - public function resolveRoutes() |
|
55 | - { |
|
56 | - $screenID = $this->request->getRequestParam('screen_id'); |
|
57 | - $heartbeat_data = $this->request->getRequestParam('data', []); |
|
58 | - if ($screenID === 'espresso_events') { |
|
59 | - $this->loader->getShared( |
|
60 | - 'EventEspresso\core\domain\services\admin\ajax\EventEditorHeartbeat' |
|
61 | - ); |
|
62 | - } elseif ($screenID === 'front' && ! empty($heartbeat_data[ self::RESPONSE_KEY_THANK_YOU_PAGE ])) { |
|
63 | - $this->loader->getShared( |
|
64 | - 'EventEspresso\core\domain\services\admin\ajax\ThankYouPageIpnMonitor' |
|
65 | - ); |
|
66 | - } |
|
67 | - } |
|
50 | + /** |
|
51 | + * @since 4.9.76.p |
|
52 | + * @throws InvalidClassException |
|
53 | + */ |
|
54 | + public function resolveRoutes() |
|
55 | + { |
|
56 | + $screenID = $this->request->getRequestParam('screen_id'); |
|
57 | + $heartbeat_data = $this->request->getRequestParam('data', []); |
|
58 | + if ($screenID === 'espresso_events') { |
|
59 | + $this->loader->getShared( |
|
60 | + 'EventEspresso\core\domain\services\admin\ajax\EventEditorHeartbeat' |
|
61 | + ); |
|
62 | + } elseif ($screenID === 'front' && ! empty($heartbeat_data[ self::RESPONSE_KEY_THANK_YOU_PAGE ])) { |
|
63 | + $this->loader->getShared( |
|
64 | + 'EventEspresso\core\domain\services\admin\ajax\ThankYouPageIpnMonitor' |
|
65 | + ); |
|
66 | + } |
|
67 | + } |
|
68 | 68 | } |
@@ -59,7 +59,7 @@ |
||
59 | 59 | $this->loader->getShared( |
60 | 60 | 'EventEspresso\core\domain\services\admin\ajax\EventEditorHeartbeat' |
61 | 61 | ); |
62 | - } elseif ($screenID === 'front' && ! empty($heartbeat_data[ self::RESPONSE_KEY_THANK_YOU_PAGE ])) { |
|
62 | + } elseif ($screenID === 'front' && ! empty($heartbeat_data[self::RESPONSE_KEY_THANK_YOU_PAGE])) { |
|
63 | 63 | $this->loader->getShared( |
64 | 64 | 'EventEspresso\core\domain\services\admin\ajax\ThankYouPageIpnMonitor' |
65 | 65 | ); |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - 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 | - ); ?> |
|
52 | + 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 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
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.4.0'); |
|
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 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.81.rc.030'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.81.rc.030'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |