Completed
Branch fix/resend-notifications (bed62e)
by
unknown
17:13 queued 15:09
created
core/business/EE_Registration_Processor.class.php 2 patches
Indentation   +773 added lines, -773 removed lines patch added patch discarded remove patch
@@ -26,778 +26,778 @@
 block discarded – undo
26 26
 class EE_Registration_Processor extends EE_Processor_Base
27 27
 {
28 28
 
29
-    /**
30
-     * @var EE_Registration_Processor $_instance
31
-     * @access    private
32
-     */
33
-    private static $_instance;
34
-
35
-    /**
36
-     * initial reg status at the beginning of this request.
37
-     * indexed by registration ID
38
-     *
39
-     * @var array
40
-     */
41
-    protected $_old_reg_status = [];
42
-
43
-    /**
44
-     * reg status at the end of the request after all processing.
45
-     * indexed by registration ID
46
-     *
47
-     * @var array
48
-     */
49
-    protected $_new_reg_status = [];
50
-
51
-    /**
52
-     * amounts paid at the end of the request after all processing.
53
-     * indexed by registration ID
54
-     *
55
-     * @var array
56
-     */
57
-    protected static $_amount_paid = [];
58
-
59
-    /**
60
-     * Cache of the reg final price for registrations corresponding to a ticket line item
61
-     *
62
-     * @deprecated
63
-     * @var array @see EEH_Line_Item::calculate_reg_final_prices_per_line_item()'s return value
64
-     */
65
-    protected $_reg_final_price_per_tkt_line_item;
66
-
67
-    /**
68
-     * @var RequestInterface $request
69
-     */
70
-    protected $request;
71
-
72
-
73
-    /**
74
-     * @singleton method used to instantiate class object
75
-     * @param RequestInterface|null $request
76
-     * @return EE_Registration_Processor instance
77
-     * @throws InvalidArgumentException
78
-     * @throws InvalidInterfaceException
79
-     * @throws InvalidDataTypeException
80
-     */
81
-    public static function instance(RequestInterface $request = null)
82
-    {
83
-        // check if class object is instantiated
84
-        if (! self::$_instance instanceof EE_Registration_Processor) {
85
-            if (! $request instanceof RequestInterface) {
86
-                $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request');
87
-            }
88
-            self::$_instance = new self($request);
89
-        }
90
-        return self::$_instance;
91
-    }
92
-
93
-
94
-    /**
95
-     * EE_Registration_Processor constructor.
96
-     *
97
-     * @param RequestInterface $request
98
-     */
99
-    public function __construct(RequestInterface $request)
100
-    {
101
-        $this->request = $request;
102
-    }
103
-
104
-
105
-    /**
106
-     * @param int $REG_ID
107
-     * @return string
108
-     */
109
-    public function old_reg_status($REG_ID)
110
-    {
111
-        return isset($this->_old_reg_status[ $REG_ID ]) ? $this->_old_reg_status[ $REG_ID ] : null;
112
-    }
113
-
114
-
115
-    /**
116
-     * @param int    $REG_ID
117
-     * @param string $old_reg_status
118
-     */
119
-    public function set_old_reg_status($REG_ID, $old_reg_status)
120
-    {
121
-        // only set the first time
122
-        if (! isset($this->_old_reg_status[ $REG_ID ])) {
123
-            $this->_old_reg_status[ $REG_ID ] = $old_reg_status;
124
-        }
125
-    }
126
-
127
-
128
-    /**
129
-     * @param int $REG_ID
130
-     * @return string
131
-     */
132
-    public function new_reg_status($REG_ID)
133
-    {
134
-        return isset($this->_new_reg_status[ $REG_ID ]) ? $this->_new_reg_status[ $REG_ID ] : null;
135
-    }
136
-
137
-
138
-    /**
139
-     * @param int    $REG_ID
140
-     * @param string $new_reg_status
141
-     */
142
-    public function set_new_reg_status($REG_ID, $new_reg_status)
143
-    {
144
-        $this->_new_reg_status[ $REG_ID ] = $new_reg_status;
145
-    }
146
-
147
-
148
-    /**
149
-     * reg_status_updated
150
-     *
151
-     * @param int $REG_ID
152
-     * @return bool
153
-     */
154
-    public function reg_status_updated($REG_ID)
155
-    {
156
-        return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID);
157
-    }
158
-
159
-
160
-    /**
161
-     * @param EE_Registration $registration
162
-     * @throws EE_Error
163
-     * @throws EntityNotFoundException
164
-     * @throws InvalidArgumentException
165
-     * @throws InvalidDataTypeException
166
-     * @throws InvalidInterfaceException
167
-     * @throws ReflectionException
168
-     * @throws RuntimeException
169
-     */
170
-    public function update_registration_status_and_trigger_notifications(EE_Registration $registration)
171
-    {
172
-        $this->toggle_incomplete_registration_status_to_default($registration, false);
173
-        $this->toggle_registration_status_for_default_approved_events($registration, false);
174
-        $this->toggle_registration_status_if_no_monies_owing($registration, false);
175
-        $registration->save();
176
-        // trigger notifications
177
-        $this->trigger_registration_update_notifications($registration);
178
-    }
179
-
180
-
181
-    /**
182
-     *    manually_update_registration_status
183
-     *
184
-     * @access public
185
-     * @param EE_Registration $registration
186
-     * @param string          $new_reg_status
187
-     * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
188
-     *                              to client code
189
-     * @return bool
190
-     * @throws EE_Error
191
-     * @throws EntityNotFoundException
192
-     * @throws InvalidArgumentException
193
-     * @throws InvalidDataTypeException
194
-     * @throws InvalidInterfaceException
195
-     * @throws ReflectionException
196
-     * @throws RuntimeException
197
-     */
198
-    public function manually_update_registration_status(
199
-        EE_Registration $registration,
200
-        $new_reg_status = '',
201
-        $save = true
202
-    ) {
203
-        // set initial REG_Status
204
-        $this->set_old_reg_status($registration->ID(), $registration->status_ID());
205
-        // set incoming REG_Status
206
-        $this->set_new_reg_status($registration->ID(), $new_reg_status);
207
-        // toggle reg status but only if it has changed and the user can do so
208
-        if (
209
-            $this->reg_status_updated($registration->ID())
210
-            && (
211
-                (! $this->request->isAdmin() || $this->request->isFrontAjax())
212
-                || EE_Registry::instance()->CAP->current_user_can(
213
-                    'ee_edit_registration',
214
-                    'toggle_registration_status',
215
-                    $registration->ID()
216
-                )
217
-            )
218
-        ) {
219
-            // change status to new value
220
-            $updated = $registration->set_status($this->new_reg_status($registration->ID()));
221
-            if ($updated && $save) {
222
-                $registration->save();
223
-            }
224
-            return true;
225
-        }
226
-        return false;
227
-    }
228
-
229
-
230
-    /**
231
-     *    toggle_incomplete_registration_status_to_default
232
-     *        changes any incomplete registrations to either the event or global default registration status
233
-     *
234
-     * @access public
235
-     * @param EE_Registration       $registration
236
-     * @param bool                  $save TRUE will save the registration if the status is updated, FALSE will leave
237
-     *                                    that up to client code
238
-     * @param ContextInterface|null $context
239
-     * @return void
240
-     * @throws EE_Error
241
-     * @throws InvalidArgumentException
242
-     * @throws ReflectionException
243
-     * @throws RuntimeException
244
-     * @throws EntityNotFoundException
245
-     * @throws InvalidDataTypeException
246
-     * @throws InvalidInterfaceException
247
-     */
248
-    public function toggle_incomplete_registration_status_to_default(
249
-        EE_Registration $registration,
250
-        $save = true,
251
-        ContextInterface $context = null
252
-    ) {
253
-        $existing_reg_status = $registration->status_ID();
254
-        // set initial REG_Status
255
-        $this->set_old_reg_status($registration->ID(), $existing_reg_status);
256
-        // is the registration currently incomplete ?
257
-        if ($registration->status_ID() === EEM_Registration::status_id_incomplete) {
258
-            // grab default reg status for the event, if set
259
-            $event_default_registration_status = $registration->event()->default_registration_status();
260
-            // if no default reg status is set for the event, then use the global value
261
-            $STS_ID = ! empty($event_default_registration_status)
262
-                ? $event_default_registration_status
263
-                : EE_Registry::instance()->CFG->registration->default_STS_ID;
264
-            // if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered
265
-            $STS_ID = $STS_ID === EEM_Registration::status_id_approved ? EEM_Registration::status_id_pending_payment
266
-                : $STS_ID;
267
-            // set incoming REG_Status
268
-            $this->set_new_reg_status($registration->ID(), $STS_ID);
269
-            $registration->set_status($STS_ID, false, $context);
270
-            if ($save) {
271
-                $registration->save();
272
-            }
273
-            // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
274
-            if (! EE_Processor_Base::$IPN) {
275
-                // otherwise, send out notifications
276
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
277
-            }
278
-            // DEBUG LOG
279
-            // $this->log(
280
-            //     __CLASS__,
281
-            //     __FUNCTION__,
282
-            //     __LINE__,
283
-            //     $registration->transaction(),
284
-            //     array(
285
-            //         'IPN' => EE_Processor_Base::$IPN,
286
-            //         'deliver_notifications' => has_filter(
287
-            //             'FHEE__EED_Messages___maybe_registration__deliver_notifications'
288
-            //         ),
289
-            //     )
290
-            // );
291
-        }
292
-    }
293
-
294
-
295
-    /**
296
-     *    toggle_registration_status_for_default_approved_events
297
-     *
298
-     * @access public
299
-     * @param EE_Registration $registration
300
-     * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
301
-     *                              to client code
302
-     * @return bool
303
-     * @throws EE_Error
304
-     * @throws EntityNotFoundException
305
-     * @throws InvalidArgumentException
306
-     * @throws InvalidDataTypeException
307
-     * @throws InvalidInterfaceException
308
-     * @throws ReflectionException
309
-     * @throws RuntimeException
310
-     */
311
-    public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = true)
312
-    {
313
-        $reg_status = $registration->status_ID();
314
-        // set initial REG_Status
315
-        $this->set_old_reg_status($registration->ID(), $reg_status);
316
-        // if not already, toggle reg status to approved IF the event default reg status is approved
317
-        // ( as long as the registration wasn't cancelled or declined at some point )
318
-        if (
319
-            $reg_status !== EEM_Registration::status_id_cancelled
320
-            && $reg_status
321
-               !== EEM_Registration::status_id_declined
322
-            && $reg_status !== EEM_Registration::status_id_approved
323
-            && $registration->event()->default_registration_status() === EEM_Registration::status_id_approved
324
-        ) {
325
-            // set incoming REG_Status
326
-            $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
327
-            // toggle status to approved
328
-            $registration->set_status(EEM_Registration::status_id_approved);
329
-            if ($save) {
330
-                $registration->save();
331
-            }
332
-            // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
333
-            if (! EE_Processor_Base::$IPN) {
334
-                // otherwise, send out notifications
335
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
336
-            }
337
-            // DEBUG LOG
338
-            // $this->log(
339
-            //     __CLASS__,
340
-            //     __FUNCTION__,
341
-            //     __LINE__,
342
-            //     $registration->transaction(),
343
-            //     array(
344
-            //         'IPN' => EE_Processor_Base::$IPN,
345
-            //         'deliver_notifications' => has_filter(
346
-            //             'FHEE__EED_Messages___maybe_registration__deliver_notifications'
347
-            //         ),
348
-            //     )
349
-            // );
350
-            return true;
351
-        }
352
-        return false;
353
-    }
354
-
355
-
356
-    /**
357
-     *    toggle_registration_statuses_if_no_monies_owing
358
-     *
359
-     * @access public
360
-     * @param EE_Registration $registration
361
-     * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
362
-     *                              to client code
363
-     * @param array           $additional_details
364
-     * @return bool
365
-     * @throws EE_Error
366
-     * @throws EntityNotFoundException
367
-     * @throws InvalidArgumentException
368
-     * @throws InvalidDataTypeException
369
-     * @throws InvalidInterfaceException
370
-     * @throws ReflectionException
371
-     * @throws RuntimeException
372
-     */
373
-    public function toggle_registration_status_if_no_monies_owing(
374
-        EE_Registration $registration,
375
-        $save = true,
376
-        array $additional_details = []
377
-    ) {
378
-        // set initial REG_Status
379
-        $this->set_old_reg_status($registration->ID(), $registration->status_ID());
380
-        // was a payment just made ?
381
-        $payment    = isset($additional_details['payment_updates'], $additional_details['last_payment'])
382
-                      && $additional_details['payment_updates']
383
-                      && $additional_details['last_payment'] instanceof EE_Payment
384
-            ? $additional_details['last_payment']
385
-            : null;
386
-        $total_paid = array_sum(self::$_amount_paid);
387
-        // toggle reg status to approved IF
388
-        if (
29
+	/**
30
+	 * @var EE_Registration_Processor $_instance
31
+	 * @access    private
32
+	 */
33
+	private static $_instance;
34
+
35
+	/**
36
+	 * initial reg status at the beginning of this request.
37
+	 * indexed by registration ID
38
+	 *
39
+	 * @var array
40
+	 */
41
+	protected $_old_reg_status = [];
42
+
43
+	/**
44
+	 * reg status at the end of the request after all processing.
45
+	 * indexed by registration ID
46
+	 *
47
+	 * @var array
48
+	 */
49
+	protected $_new_reg_status = [];
50
+
51
+	/**
52
+	 * amounts paid at the end of the request after all processing.
53
+	 * indexed by registration ID
54
+	 *
55
+	 * @var array
56
+	 */
57
+	protected static $_amount_paid = [];
58
+
59
+	/**
60
+	 * Cache of the reg final price for registrations corresponding to a ticket line item
61
+	 *
62
+	 * @deprecated
63
+	 * @var array @see EEH_Line_Item::calculate_reg_final_prices_per_line_item()'s return value
64
+	 */
65
+	protected $_reg_final_price_per_tkt_line_item;
66
+
67
+	/**
68
+	 * @var RequestInterface $request
69
+	 */
70
+	protected $request;
71
+
72
+
73
+	/**
74
+	 * @singleton method used to instantiate class object
75
+	 * @param RequestInterface|null $request
76
+	 * @return EE_Registration_Processor instance
77
+	 * @throws InvalidArgumentException
78
+	 * @throws InvalidInterfaceException
79
+	 * @throws InvalidDataTypeException
80
+	 */
81
+	public static function instance(RequestInterface $request = null)
82
+	{
83
+		// check if class object is instantiated
84
+		if (! self::$_instance instanceof EE_Registration_Processor) {
85
+			if (! $request instanceof RequestInterface) {
86
+				$request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request');
87
+			}
88
+			self::$_instance = new self($request);
89
+		}
90
+		return self::$_instance;
91
+	}
92
+
93
+
94
+	/**
95
+	 * EE_Registration_Processor constructor.
96
+	 *
97
+	 * @param RequestInterface $request
98
+	 */
99
+	public function __construct(RequestInterface $request)
100
+	{
101
+		$this->request = $request;
102
+	}
103
+
104
+
105
+	/**
106
+	 * @param int $REG_ID
107
+	 * @return string
108
+	 */
109
+	public function old_reg_status($REG_ID)
110
+	{
111
+		return isset($this->_old_reg_status[ $REG_ID ]) ? $this->_old_reg_status[ $REG_ID ] : null;
112
+	}
113
+
114
+
115
+	/**
116
+	 * @param int    $REG_ID
117
+	 * @param string $old_reg_status
118
+	 */
119
+	public function set_old_reg_status($REG_ID, $old_reg_status)
120
+	{
121
+		// only set the first time
122
+		if (! isset($this->_old_reg_status[ $REG_ID ])) {
123
+			$this->_old_reg_status[ $REG_ID ] = $old_reg_status;
124
+		}
125
+	}
126
+
127
+
128
+	/**
129
+	 * @param int $REG_ID
130
+	 * @return string
131
+	 */
132
+	public function new_reg_status($REG_ID)
133
+	{
134
+		return isset($this->_new_reg_status[ $REG_ID ]) ? $this->_new_reg_status[ $REG_ID ] : null;
135
+	}
136
+
137
+
138
+	/**
139
+	 * @param int    $REG_ID
140
+	 * @param string $new_reg_status
141
+	 */
142
+	public function set_new_reg_status($REG_ID, $new_reg_status)
143
+	{
144
+		$this->_new_reg_status[ $REG_ID ] = $new_reg_status;
145
+	}
146
+
147
+
148
+	/**
149
+	 * reg_status_updated
150
+	 *
151
+	 * @param int $REG_ID
152
+	 * @return bool
153
+	 */
154
+	public function reg_status_updated($REG_ID)
155
+	{
156
+		return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID);
157
+	}
158
+
159
+
160
+	/**
161
+	 * @param EE_Registration $registration
162
+	 * @throws EE_Error
163
+	 * @throws EntityNotFoundException
164
+	 * @throws InvalidArgumentException
165
+	 * @throws InvalidDataTypeException
166
+	 * @throws InvalidInterfaceException
167
+	 * @throws ReflectionException
168
+	 * @throws RuntimeException
169
+	 */
170
+	public function update_registration_status_and_trigger_notifications(EE_Registration $registration)
171
+	{
172
+		$this->toggle_incomplete_registration_status_to_default($registration, false);
173
+		$this->toggle_registration_status_for_default_approved_events($registration, false);
174
+		$this->toggle_registration_status_if_no_monies_owing($registration, false);
175
+		$registration->save();
176
+		// trigger notifications
177
+		$this->trigger_registration_update_notifications($registration);
178
+	}
179
+
180
+
181
+	/**
182
+	 *    manually_update_registration_status
183
+	 *
184
+	 * @access public
185
+	 * @param EE_Registration $registration
186
+	 * @param string          $new_reg_status
187
+	 * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
188
+	 *                              to client code
189
+	 * @return bool
190
+	 * @throws EE_Error
191
+	 * @throws EntityNotFoundException
192
+	 * @throws InvalidArgumentException
193
+	 * @throws InvalidDataTypeException
194
+	 * @throws InvalidInterfaceException
195
+	 * @throws ReflectionException
196
+	 * @throws RuntimeException
197
+	 */
198
+	public function manually_update_registration_status(
199
+		EE_Registration $registration,
200
+		$new_reg_status = '',
201
+		$save = true
202
+	) {
203
+		// set initial REG_Status
204
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
205
+		// set incoming REG_Status
206
+		$this->set_new_reg_status($registration->ID(), $new_reg_status);
207
+		// toggle reg status but only if it has changed and the user can do so
208
+		if (
209
+			$this->reg_status_updated($registration->ID())
210
+			&& (
211
+				(! $this->request->isAdmin() || $this->request->isFrontAjax())
212
+				|| EE_Registry::instance()->CAP->current_user_can(
213
+					'ee_edit_registration',
214
+					'toggle_registration_status',
215
+					$registration->ID()
216
+				)
217
+			)
218
+		) {
219
+			// change status to new value
220
+			$updated = $registration->set_status($this->new_reg_status($registration->ID()));
221
+			if ($updated && $save) {
222
+				$registration->save();
223
+			}
224
+			return true;
225
+		}
226
+		return false;
227
+	}
228
+
229
+
230
+	/**
231
+	 *    toggle_incomplete_registration_status_to_default
232
+	 *        changes any incomplete registrations to either the event or global default registration status
233
+	 *
234
+	 * @access public
235
+	 * @param EE_Registration       $registration
236
+	 * @param bool                  $save TRUE will save the registration if the status is updated, FALSE will leave
237
+	 *                                    that up to client code
238
+	 * @param ContextInterface|null $context
239
+	 * @return void
240
+	 * @throws EE_Error
241
+	 * @throws InvalidArgumentException
242
+	 * @throws ReflectionException
243
+	 * @throws RuntimeException
244
+	 * @throws EntityNotFoundException
245
+	 * @throws InvalidDataTypeException
246
+	 * @throws InvalidInterfaceException
247
+	 */
248
+	public function toggle_incomplete_registration_status_to_default(
249
+		EE_Registration $registration,
250
+		$save = true,
251
+		ContextInterface $context = null
252
+	) {
253
+		$existing_reg_status = $registration->status_ID();
254
+		// set initial REG_Status
255
+		$this->set_old_reg_status($registration->ID(), $existing_reg_status);
256
+		// is the registration currently incomplete ?
257
+		if ($registration->status_ID() === EEM_Registration::status_id_incomplete) {
258
+			// grab default reg status for the event, if set
259
+			$event_default_registration_status = $registration->event()->default_registration_status();
260
+			// if no default reg status is set for the event, then use the global value
261
+			$STS_ID = ! empty($event_default_registration_status)
262
+				? $event_default_registration_status
263
+				: EE_Registry::instance()->CFG->registration->default_STS_ID;
264
+			// if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered
265
+			$STS_ID = $STS_ID === EEM_Registration::status_id_approved ? EEM_Registration::status_id_pending_payment
266
+				: $STS_ID;
267
+			// set incoming REG_Status
268
+			$this->set_new_reg_status($registration->ID(), $STS_ID);
269
+			$registration->set_status($STS_ID, false, $context);
270
+			if ($save) {
271
+				$registration->save();
272
+			}
273
+			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
274
+			if (! EE_Processor_Base::$IPN) {
275
+				// otherwise, send out notifications
276
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
277
+			}
278
+			// DEBUG LOG
279
+			// $this->log(
280
+			//     __CLASS__,
281
+			//     __FUNCTION__,
282
+			//     __LINE__,
283
+			//     $registration->transaction(),
284
+			//     array(
285
+			//         'IPN' => EE_Processor_Base::$IPN,
286
+			//         'deliver_notifications' => has_filter(
287
+			//             'FHEE__EED_Messages___maybe_registration__deliver_notifications'
288
+			//         ),
289
+			//     )
290
+			// );
291
+		}
292
+	}
293
+
294
+
295
+	/**
296
+	 *    toggle_registration_status_for_default_approved_events
297
+	 *
298
+	 * @access public
299
+	 * @param EE_Registration $registration
300
+	 * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
301
+	 *                              to client code
302
+	 * @return bool
303
+	 * @throws EE_Error
304
+	 * @throws EntityNotFoundException
305
+	 * @throws InvalidArgumentException
306
+	 * @throws InvalidDataTypeException
307
+	 * @throws InvalidInterfaceException
308
+	 * @throws ReflectionException
309
+	 * @throws RuntimeException
310
+	 */
311
+	public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = true)
312
+	{
313
+		$reg_status = $registration->status_ID();
314
+		// set initial REG_Status
315
+		$this->set_old_reg_status($registration->ID(), $reg_status);
316
+		// if not already, toggle reg status to approved IF the event default reg status is approved
317
+		// ( as long as the registration wasn't cancelled or declined at some point )
318
+		if (
319
+			$reg_status !== EEM_Registration::status_id_cancelled
320
+			&& $reg_status
321
+			   !== EEM_Registration::status_id_declined
322
+			&& $reg_status !== EEM_Registration::status_id_approved
323
+			&& $registration->event()->default_registration_status() === EEM_Registration::status_id_approved
324
+		) {
325
+			// set incoming REG_Status
326
+			$this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
327
+			// toggle status to approved
328
+			$registration->set_status(EEM_Registration::status_id_approved);
329
+			if ($save) {
330
+				$registration->save();
331
+			}
332
+			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
333
+			if (! EE_Processor_Base::$IPN) {
334
+				// otherwise, send out notifications
335
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
336
+			}
337
+			// DEBUG LOG
338
+			// $this->log(
339
+			//     __CLASS__,
340
+			//     __FUNCTION__,
341
+			//     __LINE__,
342
+			//     $registration->transaction(),
343
+			//     array(
344
+			//         'IPN' => EE_Processor_Base::$IPN,
345
+			//         'deliver_notifications' => has_filter(
346
+			//             'FHEE__EED_Messages___maybe_registration__deliver_notifications'
347
+			//         ),
348
+			//     )
349
+			// );
350
+			return true;
351
+		}
352
+		return false;
353
+	}
354
+
355
+
356
+	/**
357
+	 *    toggle_registration_statuses_if_no_monies_owing
358
+	 *
359
+	 * @access public
360
+	 * @param EE_Registration $registration
361
+	 * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
362
+	 *                              to client code
363
+	 * @param array           $additional_details
364
+	 * @return bool
365
+	 * @throws EE_Error
366
+	 * @throws EntityNotFoundException
367
+	 * @throws InvalidArgumentException
368
+	 * @throws InvalidDataTypeException
369
+	 * @throws InvalidInterfaceException
370
+	 * @throws ReflectionException
371
+	 * @throws RuntimeException
372
+	 */
373
+	public function toggle_registration_status_if_no_monies_owing(
374
+		EE_Registration $registration,
375
+		$save = true,
376
+		array $additional_details = []
377
+	) {
378
+		// set initial REG_Status
379
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
380
+		// was a payment just made ?
381
+		$payment    = isset($additional_details['payment_updates'], $additional_details['last_payment'])
382
+					  && $additional_details['payment_updates']
383
+					  && $additional_details['last_payment'] instanceof EE_Payment
384
+			? $additional_details['last_payment']
385
+			: null;
386
+		$total_paid = array_sum(self::$_amount_paid);
387
+		// toggle reg status to approved IF
388
+		if (
389 389
 // REG status is pending payment
390
-            $registration->status_ID() === EEM_Registration::status_id_pending_payment
391
-            // AND no monies are owing
392
-            && (
393
-                (
394
-                    $registration->transaction()->is_completed()
395
-                    || $registration->transaction()->is_overpaid()
396
-                    || $registration->transaction()->is_free()
397
-                    || apply_filters(
398
-                        'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing',
399
-                        false,
400
-                        $registration
401
-                    )
402
-                )
403
-                || (
404
-                    $payment instanceof EE_Payment && $payment->is_approved()
405
-                    && // this specific registration has not yet been paid for
406
-                    ! isset(self::$_amount_paid[ $registration->ID() ])
407
-                    && // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price
408
-                    $payment->amount() - $total_paid >= $registration->final_price()
409
-                )
410
-            )
411
-        ) {
412
-            // mark as paid
413
-            self::$_amount_paid[ $registration->ID() ] = $registration->final_price();
414
-            // track new REG_Status
415
-            $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
416
-            // toggle status to approved
417
-            $registration->set_status(EEM_Registration::status_id_approved);
418
-            if ($save) {
419
-                $registration->save();
420
-            }
421
-            // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
422
-            if (! EE_Processor_Base::$IPN) {
423
-                // otherwise, send out notifications
424
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
425
-            }
426
-            // DEBUG LOG
427
-            // $this->log(
428
-            //     __CLASS__,
429
-            //     __FUNCTION__,
430
-            //     __LINE__,
431
-            //     $registration->transaction(),
432
-            //     array(
433
-            //         'IPN' => EE_Processor_Base::$IPN,
434
-            //         'deliver_notifications' => has_filter(
435
-            //             'FHEE__EED_Messages___maybe_registration__deliver_notifications'
436
-            //         ),
437
-            //     )
438
-            // );
439
-            return true;
440
-        }
441
-        return false;
442
-    }
443
-
444
-
445
-    /**
446
-     *    registration_status_changed
447
-     *
448
-     * @access public
449
-     * @param EE_Registration $registration
450
-     * @param array           $additional_details
451
-     * @return void
452
-     */
453
-    public function trigger_registration_update_notifications($registration, array $additional_details = [])
454
-    {
455
-        try {
456
-            if (! $registration instanceof EE_Registration) {
457
-                throw new EE_Error(
458
-                    esc_html__('An invalid registration was received.', 'event_espresso')
459
-                );
460
-            }
461
-            // EE_Registry::instance()->load_helper('Debug_Tools');
462
-            // EEH_Debug_Tools::log(
463
-            //     __CLASS__,
464
-            //     __FUNCTION__,
465
-            //     __LINE__,
466
-            //     array($registration->transaction(), $additional_details),
467
-            //     false,
468
-            //     'EE_Transaction: ' . $registration->transaction()->ID()
469
-            // );
470
-            if (
471
-                ! $this->request->getRequestParam('non_primary_reg_notification', 0, 'int')
472
-                && ! $registration->is_primary_registrant()
473
-            ) {
474
-                return;
475
-            }
476
-            do_action(
477
-                'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
478
-                $registration,
479
-                $additional_details
480
-            );
481
-        } catch (Exception $e) {
482
-            EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine());
483
-        }
484
-    }
485
-
486
-
487
-    /**
488
-     * sets reg status based either on passed param or on transaction status and event pre-approval setting
489
-     *
490
-     * @param EE_Registration $registration
491
-     * @param array           $additional_details
492
-     * @return bool
493
-     * @throws EE_Error
494
-     * @throws EntityNotFoundException
495
-     * @throws InvalidArgumentException
496
-     * @throws InvalidDataTypeException
497
-     * @throws InvalidInterfaceException
498
-     * @throws ReflectionException
499
-     * @throws RuntimeException
500
-     */
501
-    public function update_registration_after_checkout_or_payment(
502
-        EE_Registration $registration,
503
-        array $additional_details = []
504
-    ) {
505
-        // set initial REG_Status
506
-        $this->set_old_reg_status($registration->ID(), $registration->status_ID());
507
-        // if the registration status gets updated, then save the registration
508
-        if (
509
-            $this->toggle_registration_status_for_default_approved_events($registration, false)
510
-            || $this->toggle_registration_status_if_no_monies_owing(
511
-                $registration,
512
-                false,
513
-                $additional_details
514
-            )
515
-        ) {
516
-            $registration->save();
517
-        }
518
-        // set new  REG_Status
519
-        $this->set_new_reg_status($registration->ID(), $registration->status_ID());
520
-        return $this->reg_status_updated($registration->ID())
521
-               && $this->new_reg_status($registration->ID()) === EEM_Registration::status_id_approved;
522
-    }
523
-
524
-
525
-    /**
526
-     * Updates the registration' final prices based on the current line item tree (taking into account
527
-     * discounts, taxes, and other line items unrelated to tickets.)
528
-     *
529
-     * @param EE_Transaction $transaction
530
-     * @param boolean        $save_regs whether to immediately save registrations in this function or not
531
-     * @return void
532
-     * @throws EE_Error
533
-     * @throws InvalidArgumentException
534
-     * @throws InvalidDataTypeException
535
-     * @throws InvalidInterfaceException
536
-     * @throws RuntimeException
537
-     * @throws ReflectionException
538
-     */
539
-    public function update_registration_final_prices($transaction, $save_regs = true)
540
-    {
541
-        $reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item(
542
-            $transaction->total_line_item()
543
-        );
544
-        foreach ($transaction->registrations() as $registration) {
545
-            /** @var EE_Line_Item $line_item */
546
-            $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration);
547
-            if (isset($reg_final_price_per_ticket_line_item[ $line_item->ID() ])) {
548
-                $registration->set_final_price($reg_final_price_per_ticket_line_item[ $line_item->ID() ]);
549
-                if ($save_regs) {
550
-                    $registration->save();
551
-                }
552
-            }
553
-        }
554
-        // and make sure there's no rounding problem
555
-        $this->fix_reg_final_price_rounding_issue($transaction);
556
-    }
557
-
558
-
559
-    /**
560
-     * Makes sure there is no rounding errors for the REG_final_prices.
561
-     * Eg, if we have 3 registrations for $1, and there is a $0.01 discount between the three of them,
562
-     * they will each be for $0.99333333, which gets rounded to $1 again.
563
-     * So the transaction total will be $2.99, but each registration will be for $1,
564
-     * so if each registrant paid individually they will have overpaid by $0.01.
565
-     * So in order to overcome this, we check for any difference, and if there is a difference
566
-     * we just grab one registrant at random and make them responsible for it.
567
-     * This should be used after setting REG_final_prices (it's done automatically as part of
568
-     * EE_Registration_Processor::update_registration_final_prices())
569
-     *
570
-     * @param EE_Transaction $transaction
571
-     * @return bool success verifying that there is NO difference after this method is done
572
-     * @throws EE_Error
573
-     * @throws InvalidArgumentException
574
-     * @throws InvalidDataTypeException
575
-     * @throws InvalidInterfaceException
576
-     * @throws ReflectionException
577
-     */
578
-    public function fix_reg_final_price_rounding_issue($transaction)
579
-    {
580
-        $reg_final_price_sum = EEM_Registration::instance()->sum(
581
-            [
582
-                [
583
-                    'TXN_ID' => $transaction->ID(),
584
-                ],
585
-            ],
586
-            'REG_final_price'
587
-        );
588
-        $diff                = $transaction->total() - $reg_final_price_sum;
589
-        // ok then, just grab one of the registrations
590
-        if ($diff !== (float) 0) {
591
-            $a_reg = EEM_Registration::instance()->get_one(
592
-                [
593
-                    [
594
-                        'TXN_ID' => $transaction->ID(),
595
-                    ],
596
-                ]
597
-            );
598
-            return $a_reg instanceof EE_Registration
599
-                   && $a_reg->save(['REG_final_price' => $a_reg->final_price() + $diff]);
600
-        }
601
-        return true;
602
-    }
603
-
604
-
605
-    /**
606
-     * update_registration_after_being_canceled_or_declined
607
-     *
608
-     * @param EE_Registration $registration
609
-     * @param array           $closed_reg_statuses
610
-     * @param bool            $update_reg
611
-     * @return bool
612
-     * @throws EE_Error
613
-     * @throws RuntimeException
614
-     * @throws ReflectionException
615
-     */
616
-    public function update_registration_after_being_canceled_or_declined(
617
-        EE_Registration $registration,
618
-        array $closed_reg_statuses = [],
619
-        $update_reg = true
620
-    ) {
621
-        // these reg statuses should not be considered in any calculations involving monies owing
622
-        $closed_reg_statuses = ! empty($closed_reg_statuses)
623
-            ? $closed_reg_statuses
624
-            : EEM_Registration::closed_reg_statuses();
625
-        if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
626
-            return false;
627
-        }
628
-        // release a reserved ticket by decrementing ticket and datetime reserved values
629
-        $registration->release_reserved_ticket(true, 'RegProcessor:' . __LINE__);
630
-        $registration->set_final_price(0);
631
-        if ($update_reg) {
632
-            $registration->save();
633
-        }
634
-        return true;
635
-    }
636
-
637
-
638
-    /**
639
-     * update_canceled_or_declined_registration_after_being_reinstated
640
-     *
641
-     * @param EE_Registration $registration
642
-     * @param array           $closed_reg_statuses
643
-     * @param bool            $update_reg
644
-     * @return bool
645
-     * @throws EE_Error
646
-     * @throws RuntimeException
647
-     * @throws ReflectionException
648
-     */
649
-    public function update_canceled_or_declined_registration_after_being_reinstated(
650
-        EE_Registration $registration,
651
-        array $closed_reg_statuses = [],
652
-        $update_reg = true
653
-    ) {
654
-        // these reg statuses should not be considered in any calculations involving monies owing
655
-        $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
656
-            : EEM_Registration::closed_reg_statuses();
657
-        if (in_array($registration->status_ID(), $closed_reg_statuses, true)) {
658
-            return false;
659
-        }
660
-        $ticket = $registration->ticket();
661
-        if (! $ticket instanceof EE_Ticket) {
662
-            throw new EE_Error(
663
-                sprintf(
664
-                    esc_html__(
665
-                        'The Ticket for Registration %1$d was not found or is invalid.',
666
-                        'event_espresso'
667
-                    ),
668
-                    $registration->ticket_ID()
669
-                )
670
-            );
671
-        }
672
-        $registration->set_final_price($ticket->price());
673
-        if ($update_reg) {
674
-            $registration->save();
675
-        }
676
-        return true;
677
-    }
678
-
679
-
680
-    /**
681
-     * generate_ONE_registration_from_line_item
682
-     * Although a ticket line item may have a quantity greater than 1,
683
-     * this method will ONLY CREATE ONE REGISTRATION !!!
684
-     * Regardless of the ticket line item quantity.
685
-     * This means that any code calling this method is responsible for ensuring
686
-     * that the final registration count matches the ticket line item quantity.
687
-     * This was done to make it easier to match the number of registrations
688
-     * to the number of tickets in the cart, when the cart has been edited
689
-     * after SPCO has already been initialized. So if an additional ticket was added to the cart, you can simply pass
690
-     * the line item to this method to add a second ticket, and in this case, you would not want to add 2 tickets.
691
-     *
692
-     * @param EE_Line_Item   $line_item
693
-     * @param EE_Transaction $transaction
694
-     * @param int            $att_nmbr
695
-     * @param int            $total_ticket_count
696
-     * @return EE_Registration | null
697
-     * @throws OutOfRangeException
698
-     * @throws UnexpectedEntityException
699
-     * @throws EE_Error
700
-     * @throws ReflectionException
701
-     * @deprecated
702
-     * @since 4.9.1
703
-     */
704
-    public function generate_ONE_registration_from_line_item(
705
-        EE_Line_Item $line_item,
706
-        EE_Transaction $transaction,
707
-        $att_nmbr = 1,
708
-        $total_ticket_count = 1
709
-    ) {
710
-        EE_Error::doing_it_wrong(
711
-            __CLASS__ . '::' . __FUNCTION__,
712
-            sprintf(
713
-                esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
714
-                '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()'
715
-            ),
716
-            '4.9.1',
717
-            '5.0.0'
718
-        );
719
-        // grab the related ticket object for this line_item
720
-        $ticket = $line_item->ticket();
721
-        if (! $ticket instanceof EE_Ticket) {
722
-            EE_Error::add_error(
723
-                sprintf(
724
-                    esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'),
725
-                    $line_item->ID()
726
-                ),
727
-                __FILE__,
728
-                __FUNCTION__,
729
-                __LINE__
730
-            );
731
-            return null;
732
-        }
733
-        $registration_service = new CreateRegistrationService();
734
-        // then generate a new registration from that
735
-        return $registration_service->create(
736
-            $ticket->get_related_event(),
737
-            $transaction,
738
-            $ticket,
739
-            $line_item,
740
-            $att_nmbr,
741
-            $total_ticket_count
742
-        );
743
-    }
744
-
745
-
746
-    /**
747
-     * generates reg_url_link
748
-     *
749
-     * @param int                   $att_nmbr
750
-     * @param EE_Line_Item | string $item
751
-     * @return RegUrlLink
752
-     * @throws InvalidArgumentException
753
-     * @deprecated
754
-     * @since 4.9.1
755
-     */
756
-    public function generate_reg_url_link($att_nmbr, $item)
757
-    {
758
-        EE_Error::doing_it_wrong(
759
-            __CLASS__ . '::' . __FUNCTION__,
760
-            sprintf(
761
-                esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
762
-                'EventEspresso\core\domain\entities\RegUrlLink'
763
-            ),
764
-            '4.9.1',
765
-            '5.0.0'
766
-        );
767
-        return new RegUrlLink($att_nmbr, $item);
768
-    }
769
-
770
-
771
-    /**
772
-     * generates reg code
773
-     *
774
-     * @param EE_Registration $registration
775
-     * @return RegCode
776
-     * @throws EE_Error
777
-     * @throws EntityNotFoundException
778
-     * @throws InvalidArgumentException
779
-     * @since 4.9.1
780
-     * @deprecated
781
-     */
782
-    public function generate_reg_code(EE_Registration $registration)
783
-    {
784
-        EE_Error::doing_it_wrong(
785
-            __CLASS__ . '::' . __FUNCTION__,
786
-            sprintf(
787
-                esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
788
-                'EventEspresso\core\domain\entities\RegCode'
789
-            ),
790
-            '4.9.1',
791
-            '5.0.0'
792
-        );
793
-        return apply_filters(
794
-            'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code',
795
-            new RegCode(
796
-                RegUrlLink::fromRegistration($registration),
797
-                $registration->transaction(),
798
-                $registration->ticket()
799
-            ),
800
-            $registration
801
-        );
802
-    }
390
+			$registration->status_ID() === EEM_Registration::status_id_pending_payment
391
+			// AND no monies are owing
392
+			&& (
393
+				(
394
+					$registration->transaction()->is_completed()
395
+					|| $registration->transaction()->is_overpaid()
396
+					|| $registration->transaction()->is_free()
397
+					|| apply_filters(
398
+						'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing',
399
+						false,
400
+						$registration
401
+					)
402
+				)
403
+				|| (
404
+					$payment instanceof EE_Payment && $payment->is_approved()
405
+					&& // this specific registration has not yet been paid for
406
+					! isset(self::$_amount_paid[ $registration->ID() ])
407
+					&& // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price
408
+					$payment->amount() - $total_paid >= $registration->final_price()
409
+				)
410
+			)
411
+		) {
412
+			// mark as paid
413
+			self::$_amount_paid[ $registration->ID() ] = $registration->final_price();
414
+			// track new REG_Status
415
+			$this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
416
+			// toggle status to approved
417
+			$registration->set_status(EEM_Registration::status_id_approved);
418
+			if ($save) {
419
+				$registration->save();
420
+			}
421
+			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
422
+			if (! EE_Processor_Base::$IPN) {
423
+				// otherwise, send out notifications
424
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
425
+			}
426
+			// DEBUG LOG
427
+			// $this->log(
428
+			//     __CLASS__,
429
+			//     __FUNCTION__,
430
+			//     __LINE__,
431
+			//     $registration->transaction(),
432
+			//     array(
433
+			//         'IPN' => EE_Processor_Base::$IPN,
434
+			//         'deliver_notifications' => has_filter(
435
+			//             'FHEE__EED_Messages___maybe_registration__deliver_notifications'
436
+			//         ),
437
+			//     )
438
+			// );
439
+			return true;
440
+		}
441
+		return false;
442
+	}
443
+
444
+
445
+	/**
446
+	 *    registration_status_changed
447
+	 *
448
+	 * @access public
449
+	 * @param EE_Registration $registration
450
+	 * @param array           $additional_details
451
+	 * @return void
452
+	 */
453
+	public function trigger_registration_update_notifications($registration, array $additional_details = [])
454
+	{
455
+		try {
456
+			if (! $registration instanceof EE_Registration) {
457
+				throw new EE_Error(
458
+					esc_html__('An invalid registration was received.', 'event_espresso')
459
+				);
460
+			}
461
+			// EE_Registry::instance()->load_helper('Debug_Tools');
462
+			// EEH_Debug_Tools::log(
463
+			//     __CLASS__,
464
+			//     __FUNCTION__,
465
+			//     __LINE__,
466
+			//     array($registration->transaction(), $additional_details),
467
+			//     false,
468
+			//     'EE_Transaction: ' . $registration->transaction()->ID()
469
+			// );
470
+			if (
471
+				! $this->request->getRequestParam('non_primary_reg_notification', 0, 'int')
472
+				&& ! $registration->is_primary_registrant()
473
+			) {
474
+				return;
475
+			}
476
+			do_action(
477
+				'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
478
+				$registration,
479
+				$additional_details
480
+			);
481
+		} catch (Exception $e) {
482
+			EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine());
483
+		}
484
+	}
485
+
486
+
487
+	/**
488
+	 * sets reg status based either on passed param or on transaction status and event pre-approval setting
489
+	 *
490
+	 * @param EE_Registration $registration
491
+	 * @param array           $additional_details
492
+	 * @return bool
493
+	 * @throws EE_Error
494
+	 * @throws EntityNotFoundException
495
+	 * @throws InvalidArgumentException
496
+	 * @throws InvalidDataTypeException
497
+	 * @throws InvalidInterfaceException
498
+	 * @throws ReflectionException
499
+	 * @throws RuntimeException
500
+	 */
501
+	public function update_registration_after_checkout_or_payment(
502
+		EE_Registration $registration,
503
+		array $additional_details = []
504
+	) {
505
+		// set initial REG_Status
506
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
507
+		// if the registration status gets updated, then save the registration
508
+		if (
509
+			$this->toggle_registration_status_for_default_approved_events($registration, false)
510
+			|| $this->toggle_registration_status_if_no_monies_owing(
511
+				$registration,
512
+				false,
513
+				$additional_details
514
+			)
515
+		) {
516
+			$registration->save();
517
+		}
518
+		// set new  REG_Status
519
+		$this->set_new_reg_status($registration->ID(), $registration->status_ID());
520
+		return $this->reg_status_updated($registration->ID())
521
+			   && $this->new_reg_status($registration->ID()) === EEM_Registration::status_id_approved;
522
+	}
523
+
524
+
525
+	/**
526
+	 * Updates the registration' final prices based on the current line item tree (taking into account
527
+	 * discounts, taxes, and other line items unrelated to tickets.)
528
+	 *
529
+	 * @param EE_Transaction $transaction
530
+	 * @param boolean        $save_regs whether to immediately save registrations in this function or not
531
+	 * @return void
532
+	 * @throws EE_Error
533
+	 * @throws InvalidArgumentException
534
+	 * @throws InvalidDataTypeException
535
+	 * @throws InvalidInterfaceException
536
+	 * @throws RuntimeException
537
+	 * @throws ReflectionException
538
+	 */
539
+	public function update_registration_final_prices($transaction, $save_regs = true)
540
+	{
541
+		$reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item(
542
+			$transaction->total_line_item()
543
+		);
544
+		foreach ($transaction->registrations() as $registration) {
545
+			/** @var EE_Line_Item $line_item */
546
+			$line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration);
547
+			if (isset($reg_final_price_per_ticket_line_item[ $line_item->ID() ])) {
548
+				$registration->set_final_price($reg_final_price_per_ticket_line_item[ $line_item->ID() ]);
549
+				if ($save_regs) {
550
+					$registration->save();
551
+				}
552
+			}
553
+		}
554
+		// and make sure there's no rounding problem
555
+		$this->fix_reg_final_price_rounding_issue($transaction);
556
+	}
557
+
558
+
559
+	/**
560
+	 * Makes sure there is no rounding errors for the REG_final_prices.
561
+	 * Eg, if we have 3 registrations for $1, and there is a $0.01 discount between the three of them,
562
+	 * they will each be for $0.99333333, which gets rounded to $1 again.
563
+	 * So the transaction total will be $2.99, but each registration will be for $1,
564
+	 * so if each registrant paid individually they will have overpaid by $0.01.
565
+	 * So in order to overcome this, we check for any difference, and if there is a difference
566
+	 * we just grab one registrant at random and make them responsible for it.
567
+	 * This should be used after setting REG_final_prices (it's done automatically as part of
568
+	 * EE_Registration_Processor::update_registration_final_prices())
569
+	 *
570
+	 * @param EE_Transaction $transaction
571
+	 * @return bool success verifying that there is NO difference after this method is done
572
+	 * @throws EE_Error
573
+	 * @throws InvalidArgumentException
574
+	 * @throws InvalidDataTypeException
575
+	 * @throws InvalidInterfaceException
576
+	 * @throws ReflectionException
577
+	 */
578
+	public function fix_reg_final_price_rounding_issue($transaction)
579
+	{
580
+		$reg_final_price_sum = EEM_Registration::instance()->sum(
581
+			[
582
+				[
583
+					'TXN_ID' => $transaction->ID(),
584
+				],
585
+			],
586
+			'REG_final_price'
587
+		);
588
+		$diff                = $transaction->total() - $reg_final_price_sum;
589
+		// ok then, just grab one of the registrations
590
+		if ($diff !== (float) 0) {
591
+			$a_reg = EEM_Registration::instance()->get_one(
592
+				[
593
+					[
594
+						'TXN_ID' => $transaction->ID(),
595
+					],
596
+				]
597
+			);
598
+			return $a_reg instanceof EE_Registration
599
+				   && $a_reg->save(['REG_final_price' => $a_reg->final_price() + $diff]);
600
+		}
601
+		return true;
602
+	}
603
+
604
+
605
+	/**
606
+	 * update_registration_after_being_canceled_or_declined
607
+	 *
608
+	 * @param EE_Registration $registration
609
+	 * @param array           $closed_reg_statuses
610
+	 * @param bool            $update_reg
611
+	 * @return bool
612
+	 * @throws EE_Error
613
+	 * @throws RuntimeException
614
+	 * @throws ReflectionException
615
+	 */
616
+	public function update_registration_after_being_canceled_or_declined(
617
+		EE_Registration $registration,
618
+		array $closed_reg_statuses = [],
619
+		$update_reg = true
620
+	) {
621
+		// these reg statuses should not be considered in any calculations involving monies owing
622
+		$closed_reg_statuses = ! empty($closed_reg_statuses)
623
+			? $closed_reg_statuses
624
+			: EEM_Registration::closed_reg_statuses();
625
+		if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
626
+			return false;
627
+		}
628
+		// release a reserved ticket by decrementing ticket and datetime reserved values
629
+		$registration->release_reserved_ticket(true, 'RegProcessor:' . __LINE__);
630
+		$registration->set_final_price(0);
631
+		if ($update_reg) {
632
+			$registration->save();
633
+		}
634
+		return true;
635
+	}
636
+
637
+
638
+	/**
639
+	 * update_canceled_or_declined_registration_after_being_reinstated
640
+	 *
641
+	 * @param EE_Registration $registration
642
+	 * @param array           $closed_reg_statuses
643
+	 * @param bool            $update_reg
644
+	 * @return bool
645
+	 * @throws EE_Error
646
+	 * @throws RuntimeException
647
+	 * @throws ReflectionException
648
+	 */
649
+	public function update_canceled_or_declined_registration_after_being_reinstated(
650
+		EE_Registration $registration,
651
+		array $closed_reg_statuses = [],
652
+		$update_reg = true
653
+	) {
654
+		// these reg statuses should not be considered in any calculations involving monies owing
655
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
656
+			: EEM_Registration::closed_reg_statuses();
657
+		if (in_array($registration->status_ID(), $closed_reg_statuses, true)) {
658
+			return false;
659
+		}
660
+		$ticket = $registration->ticket();
661
+		if (! $ticket instanceof EE_Ticket) {
662
+			throw new EE_Error(
663
+				sprintf(
664
+					esc_html__(
665
+						'The Ticket for Registration %1$d was not found or is invalid.',
666
+						'event_espresso'
667
+					),
668
+					$registration->ticket_ID()
669
+				)
670
+			);
671
+		}
672
+		$registration->set_final_price($ticket->price());
673
+		if ($update_reg) {
674
+			$registration->save();
675
+		}
676
+		return true;
677
+	}
678
+
679
+
680
+	/**
681
+	 * generate_ONE_registration_from_line_item
682
+	 * Although a ticket line item may have a quantity greater than 1,
683
+	 * this method will ONLY CREATE ONE REGISTRATION !!!
684
+	 * Regardless of the ticket line item quantity.
685
+	 * This means that any code calling this method is responsible for ensuring
686
+	 * that the final registration count matches the ticket line item quantity.
687
+	 * This was done to make it easier to match the number of registrations
688
+	 * to the number of tickets in the cart, when the cart has been edited
689
+	 * after SPCO has already been initialized. So if an additional ticket was added to the cart, you can simply pass
690
+	 * the line item to this method to add a second ticket, and in this case, you would not want to add 2 tickets.
691
+	 *
692
+	 * @param EE_Line_Item   $line_item
693
+	 * @param EE_Transaction $transaction
694
+	 * @param int            $att_nmbr
695
+	 * @param int            $total_ticket_count
696
+	 * @return EE_Registration | null
697
+	 * @throws OutOfRangeException
698
+	 * @throws UnexpectedEntityException
699
+	 * @throws EE_Error
700
+	 * @throws ReflectionException
701
+	 * @deprecated
702
+	 * @since 4.9.1
703
+	 */
704
+	public function generate_ONE_registration_from_line_item(
705
+		EE_Line_Item $line_item,
706
+		EE_Transaction $transaction,
707
+		$att_nmbr = 1,
708
+		$total_ticket_count = 1
709
+	) {
710
+		EE_Error::doing_it_wrong(
711
+			__CLASS__ . '::' . __FUNCTION__,
712
+			sprintf(
713
+				esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
714
+				'\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()'
715
+			),
716
+			'4.9.1',
717
+			'5.0.0'
718
+		);
719
+		// grab the related ticket object for this line_item
720
+		$ticket = $line_item->ticket();
721
+		if (! $ticket instanceof EE_Ticket) {
722
+			EE_Error::add_error(
723
+				sprintf(
724
+					esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'),
725
+					$line_item->ID()
726
+				),
727
+				__FILE__,
728
+				__FUNCTION__,
729
+				__LINE__
730
+			);
731
+			return null;
732
+		}
733
+		$registration_service = new CreateRegistrationService();
734
+		// then generate a new registration from that
735
+		return $registration_service->create(
736
+			$ticket->get_related_event(),
737
+			$transaction,
738
+			$ticket,
739
+			$line_item,
740
+			$att_nmbr,
741
+			$total_ticket_count
742
+		);
743
+	}
744
+
745
+
746
+	/**
747
+	 * generates reg_url_link
748
+	 *
749
+	 * @param int                   $att_nmbr
750
+	 * @param EE_Line_Item | string $item
751
+	 * @return RegUrlLink
752
+	 * @throws InvalidArgumentException
753
+	 * @deprecated
754
+	 * @since 4.9.1
755
+	 */
756
+	public function generate_reg_url_link($att_nmbr, $item)
757
+	{
758
+		EE_Error::doing_it_wrong(
759
+			__CLASS__ . '::' . __FUNCTION__,
760
+			sprintf(
761
+				esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
762
+				'EventEspresso\core\domain\entities\RegUrlLink'
763
+			),
764
+			'4.9.1',
765
+			'5.0.0'
766
+		);
767
+		return new RegUrlLink($att_nmbr, $item);
768
+	}
769
+
770
+
771
+	/**
772
+	 * generates reg code
773
+	 *
774
+	 * @param EE_Registration $registration
775
+	 * @return RegCode
776
+	 * @throws EE_Error
777
+	 * @throws EntityNotFoundException
778
+	 * @throws InvalidArgumentException
779
+	 * @since 4.9.1
780
+	 * @deprecated
781
+	 */
782
+	public function generate_reg_code(EE_Registration $registration)
783
+	{
784
+		EE_Error::doing_it_wrong(
785
+			__CLASS__ . '::' . __FUNCTION__,
786
+			sprintf(
787
+				esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
788
+				'EventEspresso\core\domain\entities\RegCode'
789
+			),
790
+			'4.9.1',
791
+			'5.0.0'
792
+		);
793
+		return apply_filters(
794
+			'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code',
795
+			new RegCode(
796
+				RegUrlLink::fromRegistration($registration),
797
+				$registration->transaction(),
798
+				$registration->ticket()
799
+			),
800
+			$registration
801
+		);
802
+	}
803 803
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
     public static function instance(RequestInterface $request = null)
82 82
     {
83 83
         // check if class object is instantiated
84
-        if (! self::$_instance instanceof EE_Registration_Processor) {
85
-            if (! $request instanceof RequestInterface) {
84
+        if ( ! self::$_instance instanceof EE_Registration_Processor) {
85
+            if ( ! $request instanceof RequestInterface) {
86 86
                 $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request');
87 87
             }
88 88
             self::$_instance = new self($request);
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
      */
109 109
     public function old_reg_status($REG_ID)
110 110
     {
111
-        return isset($this->_old_reg_status[ $REG_ID ]) ? $this->_old_reg_status[ $REG_ID ] : null;
111
+        return isset($this->_old_reg_status[$REG_ID]) ? $this->_old_reg_status[$REG_ID] : null;
112 112
     }
113 113
 
114 114
 
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
     public function set_old_reg_status($REG_ID, $old_reg_status)
120 120
     {
121 121
         // only set the first time
122
-        if (! isset($this->_old_reg_status[ $REG_ID ])) {
123
-            $this->_old_reg_status[ $REG_ID ] = $old_reg_status;
122
+        if ( ! isset($this->_old_reg_status[$REG_ID])) {
123
+            $this->_old_reg_status[$REG_ID] = $old_reg_status;
124 124
         }
125 125
     }
126 126
 
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      */
132 132
     public function new_reg_status($REG_ID)
133 133
     {
134
-        return isset($this->_new_reg_status[ $REG_ID ]) ? $this->_new_reg_status[ $REG_ID ] : null;
134
+        return isset($this->_new_reg_status[$REG_ID]) ? $this->_new_reg_status[$REG_ID] : null;
135 135
     }
136 136
 
137 137
 
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      */
142 142
     public function set_new_reg_status($REG_ID, $new_reg_status)
143 143
     {
144
-        $this->_new_reg_status[ $REG_ID ] = $new_reg_status;
144
+        $this->_new_reg_status[$REG_ID] = $new_reg_status;
145 145
     }
146 146
 
147 147
 
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
         if (
209 209
             $this->reg_status_updated($registration->ID())
210 210
             && (
211
-                (! $this->request->isAdmin() || $this->request->isFrontAjax())
211
+                ( ! $this->request->isAdmin() || $this->request->isFrontAjax())
212 212
                 || EE_Registry::instance()->CAP->current_user_can(
213 213
                     'ee_edit_registration',
214 214
                     'toggle_registration_status',
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
                 $registration->save();
272 272
             }
273 273
             // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
274
-            if (! EE_Processor_Base::$IPN) {
274
+            if ( ! EE_Processor_Base::$IPN) {
275 275
                 // otherwise, send out notifications
276 276
                 add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
277 277
             }
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
                 $registration->save();
331 331
             }
332 332
             // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
333
-            if (! EE_Processor_Base::$IPN) {
333
+            if ( ! EE_Processor_Base::$IPN) {
334 334
                 // otherwise, send out notifications
335 335
                 add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
336 336
             }
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
         // set initial REG_Status
379 379
         $this->set_old_reg_status($registration->ID(), $registration->status_ID());
380 380
         // was a payment just made ?
381
-        $payment    = isset($additional_details['payment_updates'], $additional_details['last_payment'])
381
+        $payment = isset($additional_details['payment_updates'], $additional_details['last_payment'])
382 382
                       && $additional_details['payment_updates']
383 383
                       && $additional_details['last_payment'] instanceof EE_Payment
384 384
             ? $additional_details['last_payment']
@@ -403,14 +403,14 @@  discard block
 block discarded – undo
403 403
                 || (
404 404
                     $payment instanceof EE_Payment && $payment->is_approved()
405 405
                     && // this specific registration has not yet been paid for
406
-                    ! isset(self::$_amount_paid[ $registration->ID() ])
406
+                    ! isset(self::$_amount_paid[$registration->ID()])
407 407
                     && // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price
408 408
                     $payment->amount() - $total_paid >= $registration->final_price()
409 409
                 )
410 410
             )
411 411
         ) {
412 412
             // mark as paid
413
-            self::$_amount_paid[ $registration->ID() ] = $registration->final_price();
413
+            self::$_amount_paid[$registration->ID()] = $registration->final_price();
414 414
             // track new REG_Status
415 415
             $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
416 416
             // toggle status to approved
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
                 $registration->save();
420 420
             }
421 421
             // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
422
-            if (! EE_Processor_Base::$IPN) {
422
+            if ( ! EE_Processor_Base::$IPN) {
423 423
                 // otherwise, send out notifications
424 424
                 add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
425 425
             }
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
     public function trigger_registration_update_notifications($registration, array $additional_details = [])
454 454
     {
455 455
         try {
456
-            if (! $registration instanceof EE_Registration) {
456
+            if ( ! $registration instanceof EE_Registration) {
457 457
                 throw new EE_Error(
458 458
                     esc_html__('An invalid registration was received.', 'event_espresso')
459 459
                 );
@@ -544,8 +544,8 @@  discard block
 block discarded – undo
544 544
         foreach ($transaction->registrations() as $registration) {
545 545
             /** @var EE_Line_Item $line_item */
546 546
             $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration);
547
-            if (isset($reg_final_price_per_ticket_line_item[ $line_item->ID() ])) {
548
-                $registration->set_final_price($reg_final_price_per_ticket_line_item[ $line_item->ID() ]);
547
+            if (isset($reg_final_price_per_ticket_line_item[$line_item->ID()])) {
548
+                $registration->set_final_price($reg_final_price_per_ticket_line_item[$line_item->ID()]);
549 549
                 if ($save_regs) {
550 550
                     $registration->save();
551 551
                 }
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
             ],
586 586
             'REG_final_price'
587 587
         );
588
-        $diff                = $transaction->total() - $reg_final_price_sum;
588
+        $diff = $transaction->total() - $reg_final_price_sum;
589 589
         // ok then, just grab one of the registrations
590 590
         if ($diff !== (float) 0) {
591 591
             $a_reg = EEM_Registration::instance()->get_one(
@@ -622,11 +622,11 @@  discard block
 block discarded – undo
622 622
         $closed_reg_statuses = ! empty($closed_reg_statuses)
623 623
             ? $closed_reg_statuses
624 624
             : EEM_Registration::closed_reg_statuses();
625
-        if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
625
+        if ( ! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
626 626
             return false;
627 627
         }
628 628
         // release a reserved ticket by decrementing ticket and datetime reserved values
629
-        $registration->release_reserved_ticket(true, 'RegProcessor:' . __LINE__);
629
+        $registration->release_reserved_ticket(true, 'RegProcessor:'.__LINE__);
630 630
         $registration->set_final_price(0);
631 631
         if ($update_reg) {
632 632
             $registration->save();
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
             return false;
659 659
         }
660 660
         $ticket = $registration->ticket();
661
-        if (! $ticket instanceof EE_Ticket) {
661
+        if ( ! $ticket instanceof EE_Ticket) {
662 662
             throw new EE_Error(
663 663
                 sprintf(
664 664
                     esc_html__(
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
         $total_ticket_count = 1
709 709
     ) {
710 710
         EE_Error::doing_it_wrong(
711
-            __CLASS__ . '::' . __FUNCTION__,
711
+            __CLASS__.'::'.__FUNCTION__,
712 712
             sprintf(
713 713
                 esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
714 714
                 '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()'
@@ -718,7 +718,7 @@  discard block
 block discarded – undo
718 718
         );
719 719
         // grab the related ticket object for this line_item
720 720
         $ticket = $line_item->ticket();
721
-        if (! $ticket instanceof EE_Ticket) {
721
+        if ( ! $ticket instanceof EE_Ticket) {
722 722
             EE_Error::add_error(
723 723
                 sprintf(
724 724
                     esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'),
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
     public function generate_reg_url_link($att_nmbr, $item)
757 757
     {
758 758
         EE_Error::doing_it_wrong(
759
-            __CLASS__ . '::' . __FUNCTION__,
759
+            __CLASS__.'::'.__FUNCTION__,
760 760
             sprintf(
761 761
                 esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
762 762
                 'EventEspresso\core\domain\entities\RegUrlLink'
@@ -782,7 +782,7 @@  discard block
 block discarded – undo
782 782
     public function generate_reg_code(EE_Registration $registration)
783 783
     {
784 784
         EE_Error::doing_it_wrong(
785
-            __CLASS__ . '::' . __FUNCTION__,
785
+            __CLASS__.'::'.__FUNCTION__,
786 786
             sprintf(
787 787
                 esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
788 788
                 'EventEspresso\core\domain\entities\RegCode'
Please login to merge, or discard this patch.
modules/messages/EED_Messages.module.php 2 patches
Indentation   +1340 added lines, -1340 removed lines patch added patch discarded remove patch
@@ -16,1353 +16,1353 @@
 block discarded – undo
16 16
 class EED_Messages extends EED_Module
17 17
 {
18 18
 
19
-    /**
20
-     * This holds the EE_messages controller
21
-     *
22
-     * @deprecated 4.9.0
23
-     * @var EE_messages $_EEMSG
24
-     */
25
-    protected static $_EEMSG;
26
-
27
-    /**
28
-     * @type EE_Message_Resource_Manager $_message_resource_manager
29
-     */
30
-    protected static $_message_resource_manager;
31
-
32
-    /**
33
-     * This holds the EE_Messages_Processor business class.
34
-     *
35
-     * @type EE_Messages_Processor
36
-     */
37
-    protected static $_MSG_PROCESSOR;
38
-
39
-    /**
40
-     * holds all the paths for various messages components.
41
-     * Utilized by autoloader registry
42
-     *
43
-     * @var array
44
-     */
45
-    protected static $_MSG_PATHS;
46
-
47
-
48
-    /**
49
-     * This will hold an array of messages template packs that are registered in the messages system.
50
-     * Format is:
51
-     * array(
52
-     *    'template_pack_dbref' => EE_Messages_Template_Pack (instance)
53
-     * )
54
-     *
55
-     * @var EE_Messages_Template_Pack[]
56
-     */
57
-    protected static $_TMP_PACKS = array();
58
-
59
-
60
-    /**
61
-     * @return EED_Messages|EED_Module
62
-     * @throws EE_Error
63
-     * @throws ReflectionException
64
-     */
65
-    public static function instance()
66
-    {
67
-        return parent::get_instance(__CLASS__);
68
-    }
69
-
70
-
71
-    /**
72
-     *  set_hooks - for hooking into EE Core, other modules, etc
73
-     *
74
-     * @since 4.5.0
75
-     * @return    void
76
-     */
77
-    public static function set_hooks()
78
-    {
79
-        // actions
80
-        add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
81
-        add_action(
82
-            'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
83
-            array('EED_Messages', 'maybe_registration'),
84
-            10,
85
-            2
86
-        );
87
-        // filters
88
-        add_filter(
89
-            'FHEE__EE_Registration__receipt_url__receipt_url',
90
-            array('EED_Messages', 'registration_message_trigger_url'),
91
-            10,
92
-            4
93
-        );
94
-        add_filter(
95
-            'FHEE__EE_Registration__invoice_url__invoice_url',
96
-            array('EED_Messages', 'registration_message_trigger_url'),
97
-            10,
98
-            4
99
-        );
100
-        // register routes
101
-        self::_register_routes();
102
-    }
103
-
104
-    /**
105
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
106
-     *
107
-     * @access    public
108
-     * @return    void
109
-     */
110
-    public static function set_hooks_admin()
111
-    {
112
-        // actions
113
-        add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
114
-        add_action(
115
-            'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
116
-            array('EED_Messages', 'payment_reminder'),
117
-            10
118
-        );
119
-        add_action(
120
-            'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
121
-            array('EED_Messages', 'maybe_registration'),
122
-            10,
123
-            3
124
-        );
125
-        add_action(
126
-            'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
127
-            array('EED_Messages', 'send_newsletter_message'),
128
-            10,
129
-            2
130
-        );
131
-        add_action(
132
-            'AHEE__EES_Espresso_Cancelled__process_shortcode__transaction',
133
-            array('EED_Messages', 'cancelled_registration'),
134
-            10
135
-        );
136
-        add_action(
137
-            'AHEE__EE_Admin_Page___process_admin_payment_notification',
138
-            array('EED_Messages', 'process_admin_payment'),
139
-            10,
140
-            1
141
-        );
142
-        // filters
143
-        add_filter(
144
-            'FHEE__EE_Admin_Page___process_resend_registration__success',
145
-            array('EED_Messages', 'process_resend'),
146
-            10,
147
-            2
148
-        );
149
-        add_filter(
150
-            'FHEE__EE_Registration__receipt_url__receipt_url',
151
-            array('EED_Messages', 'registration_message_trigger_url'),
152
-            10,
153
-            4
154
-        );
155
-        add_filter(
156
-            'FHEE__EE_Registration__invoice_url__invoice_url',
157
-            array('EED_Messages', 'registration_message_trigger_url'),
158
-            10,
159
-            4
160
-        );
161
-    }
162
-
163
-
164
-    /**
165
-     * All the message triggers done by route go in here.
166
-     *
167
-     * @since 4.5.0
168
-     * @return void
169
-     */
170
-    protected static function _register_routes()
171
-    {
172
-        EE_Config::register_route('msg_url_trigger', 'Messages', 'run');
173
-        EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request');
174
-        EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger');
175
-        EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger');
176
-        do_action('AHEE__EED_Messages___register_routes');
177
-    }
178
-
179
-
180
-    /**
181
-     * This is called when a browser display trigger is executed.
182
-     * The browser display trigger is typically used when a already generated message is displayed directly in the
183
-     * browser.
184
-     *
185
-     * @since 4.9.0
186
-     * @param WP $WP
187
-     * @throws EE_Error
188
-     * @throws InvalidArgumentException
189
-     * @throws ReflectionException
190
-     * @throws InvalidDataTypeException
191
-     * @throws InvalidInterfaceException
192
-     */
193
-    public function browser_trigger($WP)
194
-    {
195
-        // ensure controller is loaded
196
-        self::_load_controller();
197
-        $token = self::getRequest()->getRequestParam('token');
198
-        try {
199
-            $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager);
200
-            self::$_MSG_PROCESSOR->generate_and_send_now($mtg);
201
-        } catch (EE_Error $e) {
202
-            $error_msg = esc_html__(
203
-                'Please note that a system message failed to send due to a technical issue.',
204
-                'event_espresso'
205
-            );
206
-            // add specific message for developers if WP_DEBUG in on
207
-            $error_msg .= '||' . $e->getMessage();
208
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
209
-        }
210
-    }
211
-
212
-
213
-    /**
214
-     * This is called when a browser error trigger is executed.
215
-     * When triggered this will grab the EE_Message matching the token in the request and use that to get the error
216
-     * message and display it.
217
-     *
218
-     * @since 4.9.0
219
-     * @param $WP
220
-     * @throws EE_Error
221
-     * @throws InvalidArgumentException
222
-     * @throws InvalidDataTypeException
223
-     * @throws InvalidInterfaceException
224
-     */
225
-    public function browser_error_trigger($WP)
226
-    {
227
-        $token = self::getRequest()->getRequestParam('token');
228
-        if ($token) {
229
-            $message = EEM_Message::instance()->get_one_by_token($token);
230
-            if ($message instanceof EE_Message) {
231
-                header('HTTP/1.1 200 OK');
232
-                $error_msg = nl2br($message->error_message());
233
-                ?>
19
+	/**
20
+	 * This holds the EE_messages controller
21
+	 *
22
+	 * @deprecated 4.9.0
23
+	 * @var EE_messages $_EEMSG
24
+	 */
25
+	protected static $_EEMSG;
26
+
27
+	/**
28
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
29
+	 */
30
+	protected static $_message_resource_manager;
31
+
32
+	/**
33
+	 * This holds the EE_Messages_Processor business class.
34
+	 *
35
+	 * @type EE_Messages_Processor
36
+	 */
37
+	protected static $_MSG_PROCESSOR;
38
+
39
+	/**
40
+	 * holds all the paths for various messages components.
41
+	 * Utilized by autoloader registry
42
+	 *
43
+	 * @var array
44
+	 */
45
+	protected static $_MSG_PATHS;
46
+
47
+
48
+	/**
49
+	 * This will hold an array of messages template packs that are registered in the messages system.
50
+	 * Format is:
51
+	 * array(
52
+	 *    'template_pack_dbref' => EE_Messages_Template_Pack (instance)
53
+	 * )
54
+	 *
55
+	 * @var EE_Messages_Template_Pack[]
56
+	 */
57
+	protected static $_TMP_PACKS = array();
58
+
59
+
60
+	/**
61
+	 * @return EED_Messages|EED_Module
62
+	 * @throws EE_Error
63
+	 * @throws ReflectionException
64
+	 */
65
+	public static function instance()
66
+	{
67
+		return parent::get_instance(__CLASS__);
68
+	}
69
+
70
+
71
+	/**
72
+	 *  set_hooks - for hooking into EE Core, other modules, etc
73
+	 *
74
+	 * @since 4.5.0
75
+	 * @return    void
76
+	 */
77
+	public static function set_hooks()
78
+	{
79
+		// actions
80
+		add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
81
+		add_action(
82
+			'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
83
+			array('EED_Messages', 'maybe_registration'),
84
+			10,
85
+			2
86
+		);
87
+		// filters
88
+		add_filter(
89
+			'FHEE__EE_Registration__receipt_url__receipt_url',
90
+			array('EED_Messages', 'registration_message_trigger_url'),
91
+			10,
92
+			4
93
+		);
94
+		add_filter(
95
+			'FHEE__EE_Registration__invoice_url__invoice_url',
96
+			array('EED_Messages', 'registration_message_trigger_url'),
97
+			10,
98
+			4
99
+		);
100
+		// register routes
101
+		self::_register_routes();
102
+	}
103
+
104
+	/**
105
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
106
+	 *
107
+	 * @access    public
108
+	 * @return    void
109
+	 */
110
+	public static function set_hooks_admin()
111
+	{
112
+		// actions
113
+		add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
114
+		add_action(
115
+			'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
116
+			array('EED_Messages', 'payment_reminder'),
117
+			10
118
+		);
119
+		add_action(
120
+			'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
121
+			array('EED_Messages', 'maybe_registration'),
122
+			10,
123
+			3
124
+		);
125
+		add_action(
126
+			'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
127
+			array('EED_Messages', 'send_newsletter_message'),
128
+			10,
129
+			2
130
+		);
131
+		add_action(
132
+			'AHEE__EES_Espresso_Cancelled__process_shortcode__transaction',
133
+			array('EED_Messages', 'cancelled_registration'),
134
+			10
135
+		);
136
+		add_action(
137
+			'AHEE__EE_Admin_Page___process_admin_payment_notification',
138
+			array('EED_Messages', 'process_admin_payment'),
139
+			10,
140
+			1
141
+		);
142
+		// filters
143
+		add_filter(
144
+			'FHEE__EE_Admin_Page___process_resend_registration__success',
145
+			array('EED_Messages', 'process_resend'),
146
+			10,
147
+			2
148
+		);
149
+		add_filter(
150
+			'FHEE__EE_Registration__receipt_url__receipt_url',
151
+			array('EED_Messages', 'registration_message_trigger_url'),
152
+			10,
153
+			4
154
+		);
155
+		add_filter(
156
+			'FHEE__EE_Registration__invoice_url__invoice_url',
157
+			array('EED_Messages', 'registration_message_trigger_url'),
158
+			10,
159
+			4
160
+		);
161
+	}
162
+
163
+
164
+	/**
165
+	 * All the message triggers done by route go in here.
166
+	 *
167
+	 * @since 4.5.0
168
+	 * @return void
169
+	 */
170
+	protected static function _register_routes()
171
+	{
172
+		EE_Config::register_route('msg_url_trigger', 'Messages', 'run');
173
+		EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request');
174
+		EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger');
175
+		EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger');
176
+		do_action('AHEE__EED_Messages___register_routes');
177
+	}
178
+
179
+
180
+	/**
181
+	 * This is called when a browser display trigger is executed.
182
+	 * The browser display trigger is typically used when a already generated message is displayed directly in the
183
+	 * browser.
184
+	 *
185
+	 * @since 4.9.0
186
+	 * @param WP $WP
187
+	 * @throws EE_Error
188
+	 * @throws InvalidArgumentException
189
+	 * @throws ReflectionException
190
+	 * @throws InvalidDataTypeException
191
+	 * @throws InvalidInterfaceException
192
+	 */
193
+	public function browser_trigger($WP)
194
+	{
195
+		// ensure controller is loaded
196
+		self::_load_controller();
197
+		$token = self::getRequest()->getRequestParam('token');
198
+		try {
199
+			$mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager);
200
+			self::$_MSG_PROCESSOR->generate_and_send_now($mtg);
201
+		} catch (EE_Error $e) {
202
+			$error_msg = esc_html__(
203
+				'Please note that a system message failed to send due to a technical issue.',
204
+				'event_espresso'
205
+			);
206
+			// add specific message for developers if WP_DEBUG in on
207
+			$error_msg .= '||' . $e->getMessage();
208
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
209
+		}
210
+	}
211
+
212
+
213
+	/**
214
+	 * This is called when a browser error trigger is executed.
215
+	 * When triggered this will grab the EE_Message matching the token in the request and use that to get the error
216
+	 * message and display it.
217
+	 *
218
+	 * @since 4.9.0
219
+	 * @param $WP
220
+	 * @throws EE_Error
221
+	 * @throws InvalidArgumentException
222
+	 * @throws InvalidDataTypeException
223
+	 * @throws InvalidInterfaceException
224
+	 */
225
+	public function browser_error_trigger($WP)
226
+	{
227
+		$token = self::getRequest()->getRequestParam('token');
228
+		if ($token) {
229
+			$message = EEM_Message::instance()->get_one_by_token($token);
230
+			if ($message instanceof EE_Message) {
231
+				header('HTTP/1.1 200 OK');
232
+				$error_msg = nl2br($message->error_message());
233
+				?>
234 234
                 <!DOCTYPE html>
235 235
                 <html>
236 236
                 <head></head>
237 237
                 <body>
238 238
                 <?php echo empty($error_msg)
239
-                    ? esc_html__(
240
-                        'Unfortunately, we were unable to capture the error message for this message.',
241
-                        'event_espresso'
242
-                    )
243
-                    : wp_kses(
244
-                        $error_msg,
245
-                        array(
246
-                            'a'      => array(
247
-                                'href'  => array(),
248
-                                'title' => array(),
249
-                            ),
250
-                            'span'   => array(),
251
-                            'div'    => array(),
252
-                            'p'      => array(),
253
-                            'strong' => array(),
254
-                            'em'     => array(),
255
-                            'br'     => array(),
256
-                        )
257
-                    ); ?>
239
+					? esc_html__(
240
+						'Unfortunately, we were unable to capture the error message for this message.',
241
+						'event_espresso'
242
+					)
243
+					: wp_kses(
244
+						$error_msg,
245
+						array(
246
+							'a'      => array(
247
+								'href'  => array(),
248
+								'title' => array(),
249
+							),
250
+							'span'   => array(),
251
+							'div'    => array(),
252
+							'p'      => array(),
253
+							'strong' => array(),
254
+							'em'     => array(),
255
+							'br'     => array(),
256
+						)
257
+					); ?>
258 258
                 </body>
259 259
                 </html>
260 260
                 <?php
261
-                exit;
262
-            }
263
-        }
264
-    }
265
-
266
-
267
-    /**
268
-     *  This runs when the msg_url_trigger route has initiated.
269
-     *
270
-     * @since 4.5.0
271
-     * @param WP $WP
272
-     * @throws EE_Error
273
-     * @throws InvalidArgumentException
274
-     * @throws ReflectionException
275
-     * @throws InvalidDataTypeException
276
-     * @throws InvalidInterfaceException
277
-     */
278
-    public function run($WP)
279
-    {
280
-        // ensure controller is loaded
281
-        self::_load_controller();
282
-        // attempt to process message
283
-        try {
284
-            /** @type EE_Message_To_Generate_From_Request $message_to_generate */
285
-            $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
286
-            self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate);
287
-        } catch (EE_Error $e) {
288
-            $error_msg = esc_html__(
289
-                'Please note that a system message failed to send due to a technical issue.',
290
-                'event_espresso'
291
-            );
292
-            // add specific message for developers if WP_DEBUG in on
293
-            $error_msg .= '||' . $e->getMessage();
294
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
295
-        }
296
-    }
297
-
298
-
299
-    /**
300
-     * This is triggered by the 'msg_cron_trigger' route.
301
-     *
302
-     * @param WP $WP
303
-     */
304
-    public function execute_batch_request($WP)
305
-    {
306
-        $this->run_cron();
307
-        header('HTTP/1.1 200 OK');
308
-        exit();
309
-    }
310
-
311
-
312
-    /**
313
-     * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp
314
-     * request.
315
-     */
316
-    public function run_cron()
317
-    {
318
-        self::_load_controller();
319
-        $request = self::getRequest();
320
-        // get required vars
321
-        $cron_type = $request->getRequestParam('type');
322
-        $transient_key = $request->getRequestParam('key');
323
-
324
-        // now let's verify transient, if not valid exit immediately
325
-        if (! get_transient($transient_key)) {
326
-            /**
327
-             * trigger error so this gets in the error logs.  This is important because it happens on a non-user
328
-             * request.
329
-             */
330
-            trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso'));
331
-        }
332
-
333
-        // if made it here, lets' delete the transient to keep the db clean
334
-        delete_transient($transient_key);
335
-
336
-        if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
337
-            $method = 'batch_' . $cron_type . '_from_queue';
338
-            if (method_exists(self::$_MSG_PROCESSOR, $method)) {
339
-                self::$_MSG_PROCESSOR->$method();
340
-            } else {
341
-                // no matching task
342
-                /**
343
-                 * trigger error so this gets in the error logs.  This is important because it happens on a non user
344
-                 * request.
345
-                 */
346
-                trigger_error(
347
-                    esc_attr(
348
-                        sprintf(
349
-                            esc_html__('There is no task corresponding to this route %s', 'event_espresso'),
350
-                            $cron_type
351
-                        )
352
-                    )
353
-                );
354
-            }
355
-        }
356
-
357
-        do_action('FHEE__EED_Messages__run_cron__end');
358
-    }
359
-
360
-
361
-    /**
362
-     * This is used to retrieve the template pack for the given name.
363
-     * Retrieved packs are cached on the static $_TMP_PACKS array.  If there is no class matching the given name then
364
-     * the default template pack is returned.
365
-     *
366
-     * @deprecated 4.9.0  @see EEH_MSG_Template::get_template_pack()
367
-     * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used
368
-     *                                   in generating the Pack class name).
369
-     * @return EE_Messages_Template_Pack
370
-     * @throws EE_Error
371
-     * @throws InvalidArgumentException
372
-     * @throws ReflectionException
373
-     * @throws InvalidDataTypeException
374
-     * @throws InvalidInterfaceException
375
-     */
376
-    public static function get_template_pack($template_pack_name)
377
-    {
378
-        EE_Registry::instance()->load_helper('MSG_Template');
379
-        return EEH_MSG_Template::get_template_pack($template_pack_name);
380
-    }
381
-
382
-
383
-    /**
384
-     * Retrieves an array of all template packs.
385
-     * Array is in the format array( 'dbref' => EE_Messages_Template_Pack )
386
-     *
387
-     * @deprecated 4.9.0  @see EEH_MSG_Template_Pack::get_template_pack_collection
388
-     * @return EE_Messages_Template_Pack[]
389
-     * @throws EE_Error
390
-     * @throws InvalidArgumentException
391
-     * @throws ReflectionException
392
-     * @throws InvalidDataTypeException
393
-     * @throws InvalidInterfaceException
394
-     */
395
-    public static function get_template_packs()
396
-    {
397
-        EE_Registry::instance()->load_helper('MSG_Template');
398
-
399
-        // for backward compat, let's make sure this returns in the same format as originally.
400
-        $template_pack_collection = EEH_MSG_Template::get_template_pack_collection();
401
-        $template_pack_collection->rewind();
402
-        $template_packs = array();
403
-        while ($template_pack_collection->valid()) {
404
-            $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current();
405
-            $template_pack_collection->next();
406
-        }
407
-        return $template_packs;
408
-    }
409
-
410
-
411
-    /**
412
-     * This simply makes sure the autoloaders are registered for the EE_messages system.
413
-     *
414
-     * @since 4.5.0
415
-     * @return void
416
-     * @throws EE_Error
417
-     */
418
-    public static function set_autoloaders()
419
-    {
420
-        if (empty(self::$_MSG_PATHS)) {
421
-            self::_set_messages_paths();
422
-            foreach (self::$_MSG_PATHS as $path) {
423
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);
424
-            }
425
-            // add aliases
426
-            EEH_Autoloader::add_alias('EE_messages', 'EE_messages');
427
-            EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger');
428
-        }
429
-    }
430
-
431
-
432
-    /**
433
-     * Take care of adding all the paths for the messages components to the $_MSG_PATHS property
434
-     * for use by the Messages Autoloaders
435
-     *
436
-     * @since 4.5.0
437
-     * @return void.
438
-     */
439
-    protected static function _set_messages_paths()
440
-    {
441
-        $dir_ref = array(
442
-            'messages/message_type',
443
-            'messages/messenger',
444
-            'messages/defaults',
445
-            'messages/defaults/email',
446
-            'messages/data_class',
447
-            'messages/validators',
448
-            'messages/validators/email',
449
-            'messages/validators/html',
450
-            'shortcodes',
451
-        );
452
-        $paths = array();
453
-        foreach ($dir_ref as $index => $dir) {
454
-            $paths[ $index ] = EE_LIBRARIES . $dir;
455
-        }
456
-        self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths);
457
-    }
458
-
459
-
460
-    /**
461
-     * Takes care of loading dependencies
462
-     *
463
-     * @since 4.5.0
464
-     * @return void
465
-     * @throws EE_Error
466
-     * @throws InvalidArgumentException
467
-     * @throws ReflectionException
468
-     * @throws InvalidDataTypeException
469
-     * @throws InvalidInterfaceException
470
-     */
471
-    protected static function _load_controller()
472
-    {
473
-        if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
474
-            EE_Registry::instance()->load_core('Request_Handler');
475
-            self::set_autoloaders();
476
-            self::$_EEMSG = EE_Registry::instance()->load_lib('messages');
477
-            self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor');
478
-            self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
479
-        }
480
-    }
481
-
482
-
483
-    /**
484
-     * @param EE_Transaction $transaction
485
-     * @throws EE_Error
486
-     * @throws InvalidArgumentException
487
-     * @throws InvalidDataTypeException
488
-     * @throws InvalidInterfaceException
489
-     * @throws ReflectionException
490
-     */
491
-    public static function payment_reminder(EE_Transaction $transaction)
492
-    {
493
-        self::_load_controller();
494
-        $data = array($transaction, null);
495
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data);
496
-    }
497
-
498
-
499
-    /**
500
-     * Any messages triggers for after successful gateway payments should go in here.
501
-     *
502
-     * @param EE_Transaction  $transaction object
503
-     * @param EE_Payment|null $payment     object
504
-     * @return void
505
-     * @throws EE_Error
506
-     * @throws InvalidArgumentException
507
-     * @throws ReflectionException
508
-     * @throws InvalidDataTypeException
509
-     * @throws InvalidInterfaceException
510
-     */
511
-    public static function payment(EE_Transaction $transaction, EE_Payment $payment = null)
512
-    {
513
-        // if there's no payment object, then we cannot do a payment type message!
514
-        if (! $payment instanceof EE_Payment) {
515
-            return;
516
-        }
517
-        self::_load_controller();
518
-        $data = array($transaction, $payment);
519
-        EE_Registry::instance()->load_helper('MSG_Template');
520
-        $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
521
-        // if payment amount is less than 0 then switch to payment_refund message type.
522
-        $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
523
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
524
-    }
525
-
526
-
527
-    /**
528
-     * @param EE_Transaction $transaction
529
-     * @throws EE_Error
530
-     * @throws InvalidArgumentException
531
-     * @throws InvalidDataTypeException
532
-     * @throws InvalidInterfaceException
533
-     * @throws ReflectionException
534
-     */
535
-    public static function cancelled_registration(EE_Transaction $transaction)
536
-    {
537
-        self::_load_controller();
538
-        $data = array($transaction, null);
539
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data);
540
-    }
541
-
542
-
543
-    /**
544
-     * Trigger for Registration messages
545
-     * Note that what registration message type is sent depends on what the reg status is for the registrations on the
546
-     * incoming transaction.
547
-     *
548
-     * @param EE_Registration $registration
549
-     * @param array           $extra_details
550
-     * @return void
551
-     * @throws EE_Error
552
-     * @throws InvalidArgumentException
553
-     * @throws InvalidDataTypeException
554
-     * @throws InvalidInterfaceException
555
-     * @throws ReflectionException
556
-     * @throws EntityNotFoundException
557
-     */
558
-    public static function maybe_registration(EE_Registration $registration, $extra_details = array())
559
-    {
560
-
561
-        if (! self::_verify_registration_notification_send($registration, $extra_details)) {
562
-            // no messages please
563
-            return;
564
-        }
565
-
566
-        // get all non-trashed registrations so we make sure we send messages for the right status.
567
-        $all_registrations = $registration->transaction()->registrations(
568
-            array(
569
-                array('REG_deleted' => false),
570
-                'order_by' => array(
571
-                    'Event.EVT_name'     => 'ASC',
572
-                    'Attendee.ATT_lname' => 'ASC',
573
-                    'Attendee.ATT_fname' => 'ASC',
574
-                ),
575
-            )
576
-        );
577
-        // cached array of statuses so we only trigger messages once per status.
578
-        $statuses_sent = array();
579
-        self::_load_controller();
580
-        $mtgs = array();
581
-
582
-        // loop through registrations and trigger messages once per status.
583
-        foreach ($all_registrations as $reg) {
584
-            // already triggered?
585
-            if (in_array($reg->status_ID(), $statuses_sent)) {
586
-                continue;
587
-            }
588
-
589
-            $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID());
590
-            $mtgs = array_merge(
591
-                $mtgs,
592
-                self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
593
-                    $message_type,
594
-                    array($registration->transaction(), null, $reg->status_ID())
595
-                )
596
-            );
597
-            $statuses_sent[] = $reg->status_ID();
598
-        }
599
-
600
-        if (count($statuses_sent) > 1) {
601
-            $mtgs = array_merge(
602
-                $mtgs,
603
-                self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
604
-                    'registration_summary',
605
-                    array($registration->transaction(), null)
606
-                )
607
-            );
608
-        }
609
-
610
-        // batch queue and initiate request
611
-        self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs);
612
-        self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
613
-    }
614
-
615
-
616
-    /**
617
-     * This is a helper method used to very whether a registration notification should be sent or
618
-     * not.  Prevents duplicate notifications going out for registration context notifications.
619
-     *
620
-     * @param EE_Registration $registration  [description]
621
-     * @param array           $extra_details [description]
622
-     * @return bool          true = send away, false = nope halt the presses.
623
-     */
624
-    protected static function _verify_registration_notification_send(
625
-        EE_Registration $registration,
626
-        $extra_details = array()
627
-    ) {
628
-        $request = self::getRequest();
629
-        if (
630
-            ! $request->getRequestParam('non_primary_reg_notification', 0, 'int')
631
-            && ! $registration->is_primary_registrant()
632
-        ) {
633
-            return false;
634
-        }
635
-        // first we check if we're in admin and not doing front ajax
636
-        if (
637
-            ($request->isAdmin() || $request->isAdminAjax())
638
-            && ! $request->isFrontAjax()
639
-        ) {
640
-            $status_change = $request->getRequestParam('txn_reg_status_change', [], 'int', true);
641
-            // make sure appropriate admin params are set for sending messages
642
-            if (
643
-                ! isset($status_change['send_notifications'])
644
-                || (isset($status_change['send_notifications']) && ! $status_change['send_notifications'])
645
-            ) {
646
-                // no messages sent please.
647
-                return false;
648
-            }
649
-        } else {
650
-            // frontend request (either regular or via AJAX)
651
-            // TXN is NOT finalized ?
652
-            if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
653
-                return false;
654
-            }
655
-            // return visit but nothing changed ???
656
-            if (
657
-                isset($extra_details['revisit'], $extra_details['status_updates']) &&
658
-                $extra_details['revisit'] && ! $extra_details['status_updates']
659
-            ) {
660
-                return false;
661
-            }
662
-            // NOT sending messages && reg status is something other than "Not-Approved"
663
-            if (
664
-                ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) &&
665
-                $registration->status_ID() !== EEM_Registration::status_id_not_approved
666
-            ) {
667
-                return false;
668
-            }
669
-        }
670
-        // release the kraken
671
-        return true;
672
-    }
673
-
674
-
675
-    /**
676
-     * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that
677
-     * status id.
678
-     *
679
-     * @deprecated 4.9.0  Use EEH_MSG_Template::reg_status_to_message_type_array()
680
-     *                    or EEH_MSG_Template::convert_reg_status_to_message_type
681
-     * @param string $reg_status
682
-     * @return array
683
-     * @throws EE_Error
684
-     * @throws InvalidArgumentException
685
-     * @throws ReflectionException
686
-     * @throws InvalidDataTypeException
687
-     * @throws InvalidInterfaceException
688
-     */
689
-    protected static function _get_reg_status_array($reg_status = '')
690
-    {
691
-        EE_Registry::instance()->load_helper('MSG_Template');
692
-        return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
693
-            ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
694
-            : EEH_MSG_Template::reg_status_to_message_type_array();
695
-    }
696
-
697
-
698
-    /**
699
-     * Simply returns the payment message type for the given payment status.
700
-     *
701
-     * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array
702
-     *                   or EEH_MSG_Template::convert_payment_status_to_message_type
703
-     * @param string $payment_status The payment status being matched.
704
-     * @return bool|string The payment message type slug matching the status or false if no match.
705
-     * @throws EE_Error
706
-     * @throws InvalidArgumentException
707
-     * @throws ReflectionException
708
-     * @throws InvalidDataTypeException
709
-     * @throws InvalidInterfaceException
710
-     */
711
-    protected static function _get_payment_message_type($payment_status)
712
-    {
713
-        EE_Registry::instance()->load_helper('MSG_Template');
714
-        return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
715
-            ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
716
-            : false;
717
-    }
718
-
719
-
720
-    /**
721
-     * Message triggers for a resending already sent message(s) (via EE_Message list table)
722
-     *
723
-     * @access public
724
-     * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages
725
-     * @return bool success/fail
726
-     * @throws EE_Error
727
-     * @throws InvalidArgumentException
728
-     * @throws InvalidDataTypeException
729
-     * @throws InvalidInterfaceException
730
-     * @throws ReflectionException
731
-     */
732
-    public static function process_resend(array $req_data = [])
733
-    {
734
-        self::_load_controller();
735
-        $request = self::getRequest();
736
-        // if $msgID in this request then skip to the new resend_message
737
-        if ($request->getRequestParam('MSG_ID')) {
738
-            return self::resend_message();
739
-        }
740
-
741
-        // make sure any incoming request data is set on the request so that it gets picked up later.
742
-        foreach ((array) $req_data as $request_key => $request_value) {
743
-            if (! $request->requestParamIsSet($request_key)) {
744
-                $request->setRequestParam($request_key, $request_value);
745
-            }
746
-        }
747
-
748
-        if (
749
-            ! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()
750
-        ) {
751
-            return false;
752
-        }
753
-
754
-        try {
755
-            self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send);
756
-            self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
757
-        } catch (EE_Error $e) {
758
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
759
-            return false;
760
-        }
761
-        EE_Error::add_success(
762
-            esc_html__('Messages have been successfully queued for generation and sending.', 'event_espresso')
763
-        );
764
-        return true; // everything got queued.
765
-    }
766
-
767
-
768
-    /**
769
-     * Message triggers for a resending already sent message(s) (via EE_Message list table)
770
-     *
771
-     * @return bool
772
-     * @throws EE_Error
773
-     * @throws InvalidArgumentException
774
-     * @throws InvalidDataTypeException
775
-     * @throws InvalidInterfaceException
776
-     * @throws ReflectionException
777
-     */
778
-    public static function resend_message()
779
-    {
780
-        self::_load_controller();
781
-
782
-        $msgID = self::getRequest()->getRequestParam('MSG_ID', 0, 'int');
783
-        if (! $msgID) {
784
-            EE_Error::add_error(
785
-                esc_html__(
786
-                    'Something went wrong because there is no "MSG_ID" value in the request',
787
-                    'event_espresso'
788
-                ),
789
-                __FILE__,
790
-                __FUNCTION__,
791
-                __LINE__
792
-            );
793
-            return false;
794
-        }
795
-
796
-        self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID);
797
-
798
-        // setup success message.
799
-        $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
800
-        EE_Error::add_success(
801
-            sprintf(
802
-                _n(
803
-                    'There was %d message queued for resending.',
804
-                    'There were %d messages queued for resending.',
805
-                    $count_ready_for_resend,
806
-                    'event_espresso'
807
-                ),
808
-                $count_ready_for_resend
809
-            )
810
-        );
811
-        return true;
812
-    }
813
-
814
-
815
-    /**
816
-     * Message triggers for manual payment applied by admin
817
-     *
818
-     * @param  EE_Payment $payment EE_payment object
819
-     * @return bool success/fail
820
-     * @throws EE_Error
821
-     * @throws InvalidArgumentException
822
-     * @throws ReflectionException
823
-     * @throws InvalidDataTypeException
824
-     * @throws InvalidInterfaceException
825
-     */
826
-    public static function process_admin_payment(EE_Payment $payment)
827
-    {
828
-        EE_Registry::instance()->load_helper('MSG_Template');
829
-        // we need to get the transaction object
830
-        $transaction = $payment->transaction();
831
-        if ($transaction instanceof EE_Transaction) {
832
-            $data = array($transaction, $payment);
833
-            $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
834
-
835
-            // if payment amount is less than 0 then switch to payment_refund message type.
836
-            $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
837
-
838
-            // if payment_refund is selected, but the status is NOT accepted.  Then change message type to false so NO message notification goes out.
839
-            $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved
840
-                ? false : $message_type;
841
-
842
-            self::_load_controller();
843
-
844
-            self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
845
-
846
-            // get count of queued for generation
847
-            $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(
848
-                array(
849
-                    EEM_Message::status_incomplete,
850
-                    EEM_Message::status_idle,
851
-                )
852
-            );
853
-
854
-            if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) {
855
-                add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
856
-                return true;
857
-            } else {
858
-                $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(
859
-                    EEM_Message::instance()->stati_indicating_failed_sending()
860
-                );
861
-                /**
862
-                 * Verify that there are actually errors.  If not then we return a success message because the queue might have been emptied due to successful
863
-                 * IMMEDIATE generation.
864
-                 */
865
-                if ($count_failed > 0) {
866
-                    EE_Error::add_error(
867
-                        sprintf(
868
-                            _n(
869
-                                'The payment notification generation failed.',
870
-                                '%d payment notifications failed being sent.',
871
-                                $count_failed,
872
-                                'event_espresso'
873
-                            ),
874
-                            $count_failed
875
-                        ),
876
-                        __FILE__,
877
-                        __FUNCTION__,
878
-                        __LINE__
879
-                    );
880
-
881
-                    return false;
882
-                } else {
883
-                    add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
884
-                    return true;
885
-                }
886
-            }
887
-        } else {
888
-            EE_Error::add_error(
889
-                'Unable to generate the payment notification because the given value for the transaction is invalid.',
890
-                'event_espresso'
891
-            );
892
-            return false;
893
-        }
894
-    }
895
-
896
-
897
-    /**
898
-     * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger
899
-     *
900
-     * @since   4.3.0
901
-     * @param  EE_Registration[] $registrations an array of EE_Registration objects
902
-     * @param  int               $grp_id        a specific message template group id.
903
-     * @return void
904
-     * @throws EE_Error
905
-     * @throws InvalidArgumentException
906
-     * @throws InvalidDataTypeException
907
-     * @throws InvalidInterfaceException
908
-     * @throws ReflectionException
909
-     */
910
-    public static function send_newsletter_message($registrations, $grp_id)
911
-    {
912
-        // make sure mtp is id and set it in the request later messages setup.
913
-        self::getRequest()->setRequestParam('GRP_ID', (int) $grp_id);
914
-        self::_load_controller();
915
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations);
916
-    }
917
-
918
-
919
-    /**
920
-     * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url
921
-     *
922
-     * @since   4.3.0
923
-     * @param    string          $registration_message_trigger_url
924
-     * @param    EE_Registration $registration
925
-     * @param string             $messenger
926
-     * @param string             $message_type
927
-     * @return string
928
-     * @throws EE_Error
929
-     * @throws InvalidArgumentException
930
-     * @throws InvalidDataTypeException
931
-     * @throws InvalidInterfaceException
932
-     */
933
-    public static function registration_message_trigger_url(
934
-        $registration_message_trigger_url,
935
-        EE_Registration $registration,
936
-        $messenger = 'html',
937
-        $message_type = 'invoice'
938
-    ) {
939
-        // whitelist $messenger
940
-        switch ($messenger) {
941
-            case 'pdf':
942
-                $sending_messenger = 'pdf';
943
-                $generating_messenger = 'html';
944
-                break;
945
-            case 'html':
946
-            default:
947
-                $sending_messenger = 'html';
948
-                $generating_messenger = 'html';
949
-                break;
950
-        }
951
-        // whitelist $message_type
952
-        switch ($message_type) {
953
-            case 'receipt':
954
-                $message_type = 'receipt';
955
-                break;
956
-            case 'invoice':
957
-            default:
958
-                $message_type = 'invoice';
959
-                break;
960
-        }
961
-        // verify that both the messenger AND the message type are active
962
-        if (
963
-            EEH_MSG_Template::is_messenger_active($sending_messenger)
964
-            && EEH_MSG_Template::is_mt_active($message_type)
965
-        ) {
966
-            // need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?)
967
-            $template_query_params = array(
968
-                'MTP_is_active'    => true,
969
-                'MTP_messenger'    => $generating_messenger,
970
-                'MTP_message_type' => $message_type,
971
-                'Event.EVT_ID'     => $registration->event_ID(),
972
-            );
973
-            // get the message template group.
974
-            $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
975
-            // if we don't have an EE_Message_Template_Group then return
976
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
977
-                // remove EVT_ID from query params so that global templates get picked up
978
-                unset($template_query_params['Event.EVT_ID']);
979
-                // get global template as the fallback
980
-                $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
981
-            }
982
-            // if we don't have an EE_Message_Template_Group then return
983
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
984
-                return '';
985
-            }
986
-            // generate the URL
987
-            $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger(
988
-                $sending_messenger,
989
-                $generating_messenger,
990
-                'purchaser',
991
-                $message_type,
992
-                $registration,
993
-                $msg_template_group->ID(),
994
-                $registration->transaction_ID()
995
-            );
996
-        }
997
-        return $registration_message_trigger_url;
998
-    }
999
-
1000
-
1001
-    /**
1002
-     * Use to generate and return a message preview!
1003
-     *
1004
-     * @param  string $type      This should correspond with a valid message type
1005
-     * @param  string $context   This should correspond with a valid context for the message type
1006
-     * @param  string $messenger This should correspond with a valid messenger.
1007
-     * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
1008
-     *                           preview
1009
-     * @return bool|string The body of the message or if send is requested, sends.
1010
-     * @throws EE_Error
1011
-     * @throws InvalidArgumentException
1012
-     * @throws InvalidDataTypeException
1013
-     * @throws InvalidInterfaceException
1014
-     * @throws ReflectionException
1015
-     */
1016
-    public static function preview_message($type, $context, $messenger, $send = false)
1017
-    {
1018
-        self::_load_controller();
1019
-        $mtg = new EE_Message_To_Generate(
1020
-            $messenger,
1021
-            $type,
1022
-            array(),
1023
-            $context,
1024
-            true
1025
-        );
1026
-        $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send);
1027
-        if ($generated_preview_queue instanceof EE_Messages_Queue) {
1028
-            // loop through all content for the preview and remove any persisted records.
1029
-            $content = '';
1030
-            foreach ($generated_preview_queue->get_message_repository() as $message) {
1031
-                $content = $message->content();
1032
-                if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) {
1033
-                    $message->delete();
1034
-                }
1035
-            }
1036
-            return $content;
1037
-        } else {
1038
-            return $generated_preview_queue;
1039
-        }
1040
-    }
1041
-
1042
-
1043
-    /**
1044
-     * This is a method that allows for sending a message using a messenger matching the string given and the provided
1045
-     * EE_Message_Queue object.  The EE_Message_Queue object is used to create a single aggregate EE_Message via the
1046
-     * content found in the EE_Message objects in the queue.
1047
-     *
1048
-     * @since 4.9.0
1049
-     * @param string            $messenger            a string matching a valid active messenger in the system
1050
-     * @param string            $message_type         Although it seems contrary to the name of the method, a message
1051
-     *                                                type name is still required to send along the message type to the
1052
-     *                                                messenger because this is used for determining what specific
1053
-     *                                                variations might be loaded for the generated message.
1054
-     * @param EE_Messages_Queue $queue
1055
-     * @param string            $custom_subject       Can be used to set what the custom subject string will be on the
1056
-     *                                                aggregate EE_Message object.
1057
-     * @return bool success or fail.
1058
-     * @throws EE_Error
1059
-     * @throws InvalidArgumentException
1060
-     * @throws ReflectionException
1061
-     * @throws InvalidDataTypeException
1062
-     * @throws InvalidInterfaceException
1063
-     */
1064
-    public static function send_message_with_messenger_only(
1065
-        $messenger,
1066
-        $message_type,
1067
-        EE_Messages_Queue $queue,
1068
-        $custom_subject = ''
1069
-    ) {
1070
-        self::_load_controller();
1071
-        /** @type EE_Message_To_Generate_From_Queue $message_to_generate */
1072
-        $message_to_generate = EE_Registry::instance()->load_lib(
1073
-            'Message_To_Generate_From_Queue',
1074
-            array(
1075
-                $messenger,
1076
-                $message_type,
1077
-                $queue,
1078
-                $custom_subject,
1079
-            )
1080
-        );
1081
-        return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate);
1082
-    }
1083
-
1084
-
1085
-    /**
1086
-     * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation)
1087
-     *
1088
-     * @since 4.9.0
1089
-     * @param array $message_ids An array of message ids
1090
-     * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated
1091
-     *                           messages.
1092
-     * @throws EE_Error
1093
-     * @throws InvalidArgumentException
1094
-     * @throws InvalidDataTypeException
1095
-     * @throws InvalidInterfaceException
1096
-     * @throws ReflectionException
1097
-     */
1098
-    public static function generate_now($message_ids)
1099
-    {
1100
-        self::_load_controller();
1101
-        $messages = EEM_Message::instance()->get_all(
1102
-            array(
1103
-                0 => array(
1104
-                    'MSG_ID' => array('IN', $message_ids),
1105
-                    'STS_ID' => EEM_Message::status_incomplete,
1106
-                ),
1107
-            )
1108
-        );
1109
-        $generated_queue = false;
1110
-        if ($messages) {
1111
-            $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
1112
-        }
1113
-
1114
-        if (! $generated_queue instanceof EE_Messages_Queue) {
1115
-            EE_Error::add_error(
1116
-                esc_html__(
1117
-                    'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.',
1118
-                    'event_espresso'
1119
-                ),
1120
-                __FILE__,
1121
-                __FUNCTION__,
1122
-                __LINE__
1123
-            );
1124
-        }
1125
-        return $generated_queue;
1126
-    }
1127
-
1128
-
1129
-    /**
1130
-     * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or,
1131
-     * EEM_Message::status_idle
1132
-     *
1133
-     * @since 4.9.0
1134
-     * @param $message_ids
1135
-     * @return bool|EE_Messages_Queue false if no messages sent.
1136
-     * @throws EE_Error
1137
-     * @throws InvalidArgumentException
1138
-     * @throws InvalidDataTypeException
1139
-     * @throws InvalidInterfaceException
1140
-     * @throws ReflectionException
1141
-     */
1142
-    public static function send_now($message_ids)
1143
-    {
1144
-        self::_load_controller();
1145
-        $messages = EEM_Message::instance()->get_all(
1146
-            array(
1147
-                0 => array(
1148
-                    'MSG_ID' => array('IN', $message_ids),
1149
-                    'STS_ID' => array(
1150
-                        'IN',
1151
-                        array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry),
1152
-                    ),
1153
-                ),
1154
-            )
1155
-        );
1156
-        $sent_queue = false;
1157
-        if ($messages) {
1158
-            $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
1159
-        }
1160
-
1161
-        if (! $sent_queue instanceof EE_Messages_Queue) {
1162
-            EE_Error::add_error(
1163
-                esc_html__(
1164
-                    'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.',
1165
-                    'event_espresso'
1166
-                ),
1167
-                __FILE__,
1168
-                __FUNCTION__,
1169
-                __LINE__
1170
-            );
1171
-        } else {
1172
-            // can count how many sent by using the messages in the queue
1173
-            $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent());
1174
-            if ($sent_count > 0) {
1175
-                EE_Error::add_success(
1176
-                    sprintf(
1177
-                        _n(
1178
-                            'There was %d message successfully sent.',
1179
-                            'There were %d messages successfully sent.',
1180
-                            $sent_count,
1181
-                            'event_espresso'
1182
-                        ),
1183
-                        $sent_count
1184
-                    )
1185
-                );
1186
-            } else {
1187
-                EE_Error::overwrite_errors();
1188
-                EE_Error::add_error(
1189
-                    esc_html__(
1190
-                        'No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error.
261
+				exit;
262
+			}
263
+		}
264
+	}
265
+
266
+
267
+	/**
268
+	 *  This runs when the msg_url_trigger route has initiated.
269
+	 *
270
+	 * @since 4.5.0
271
+	 * @param WP $WP
272
+	 * @throws EE_Error
273
+	 * @throws InvalidArgumentException
274
+	 * @throws ReflectionException
275
+	 * @throws InvalidDataTypeException
276
+	 * @throws InvalidInterfaceException
277
+	 */
278
+	public function run($WP)
279
+	{
280
+		// ensure controller is loaded
281
+		self::_load_controller();
282
+		// attempt to process message
283
+		try {
284
+			/** @type EE_Message_To_Generate_From_Request $message_to_generate */
285
+			$message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
286
+			self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate);
287
+		} catch (EE_Error $e) {
288
+			$error_msg = esc_html__(
289
+				'Please note that a system message failed to send due to a technical issue.',
290
+				'event_espresso'
291
+			);
292
+			// add specific message for developers if WP_DEBUG in on
293
+			$error_msg .= '||' . $e->getMessage();
294
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
295
+		}
296
+	}
297
+
298
+
299
+	/**
300
+	 * This is triggered by the 'msg_cron_trigger' route.
301
+	 *
302
+	 * @param WP $WP
303
+	 */
304
+	public function execute_batch_request($WP)
305
+	{
306
+		$this->run_cron();
307
+		header('HTTP/1.1 200 OK');
308
+		exit();
309
+	}
310
+
311
+
312
+	/**
313
+	 * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp
314
+	 * request.
315
+	 */
316
+	public function run_cron()
317
+	{
318
+		self::_load_controller();
319
+		$request = self::getRequest();
320
+		// get required vars
321
+		$cron_type = $request->getRequestParam('type');
322
+		$transient_key = $request->getRequestParam('key');
323
+
324
+		// now let's verify transient, if not valid exit immediately
325
+		if (! get_transient($transient_key)) {
326
+			/**
327
+			 * trigger error so this gets in the error logs.  This is important because it happens on a non-user
328
+			 * request.
329
+			 */
330
+			trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso'));
331
+		}
332
+
333
+		// if made it here, lets' delete the transient to keep the db clean
334
+		delete_transient($transient_key);
335
+
336
+		if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
337
+			$method = 'batch_' . $cron_type . '_from_queue';
338
+			if (method_exists(self::$_MSG_PROCESSOR, $method)) {
339
+				self::$_MSG_PROCESSOR->$method();
340
+			} else {
341
+				// no matching task
342
+				/**
343
+				 * trigger error so this gets in the error logs.  This is important because it happens on a non user
344
+				 * request.
345
+				 */
346
+				trigger_error(
347
+					esc_attr(
348
+						sprintf(
349
+							esc_html__('There is no task corresponding to this route %s', 'event_espresso'),
350
+							$cron_type
351
+						)
352
+					)
353
+				);
354
+			}
355
+		}
356
+
357
+		do_action('FHEE__EED_Messages__run_cron__end');
358
+	}
359
+
360
+
361
+	/**
362
+	 * This is used to retrieve the template pack for the given name.
363
+	 * Retrieved packs are cached on the static $_TMP_PACKS array.  If there is no class matching the given name then
364
+	 * the default template pack is returned.
365
+	 *
366
+	 * @deprecated 4.9.0  @see EEH_MSG_Template::get_template_pack()
367
+	 * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used
368
+	 *                                   in generating the Pack class name).
369
+	 * @return EE_Messages_Template_Pack
370
+	 * @throws EE_Error
371
+	 * @throws InvalidArgumentException
372
+	 * @throws ReflectionException
373
+	 * @throws InvalidDataTypeException
374
+	 * @throws InvalidInterfaceException
375
+	 */
376
+	public static function get_template_pack($template_pack_name)
377
+	{
378
+		EE_Registry::instance()->load_helper('MSG_Template');
379
+		return EEH_MSG_Template::get_template_pack($template_pack_name);
380
+	}
381
+
382
+
383
+	/**
384
+	 * Retrieves an array of all template packs.
385
+	 * Array is in the format array( 'dbref' => EE_Messages_Template_Pack )
386
+	 *
387
+	 * @deprecated 4.9.0  @see EEH_MSG_Template_Pack::get_template_pack_collection
388
+	 * @return EE_Messages_Template_Pack[]
389
+	 * @throws EE_Error
390
+	 * @throws InvalidArgumentException
391
+	 * @throws ReflectionException
392
+	 * @throws InvalidDataTypeException
393
+	 * @throws InvalidInterfaceException
394
+	 */
395
+	public static function get_template_packs()
396
+	{
397
+		EE_Registry::instance()->load_helper('MSG_Template');
398
+
399
+		// for backward compat, let's make sure this returns in the same format as originally.
400
+		$template_pack_collection = EEH_MSG_Template::get_template_pack_collection();
401
+		$template_pack_collection->rewind();
402
+		$template_packs = array();
403
+		while ($template_pack_collection->valid()) {
404
+			$template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current();
405
+			$template_pack_collection->next();
406
+		}
407
+		return $template_packs;
408
+	}
409
+
410
+
411
+	/**
412
+	 * This simply makes sure the autoloaders are registered for the EE_messages system.
413
+	 *
414
+	 * @since 4.5.0
415
+	 * @return void
416
+	 * @throws EE_Error
417
+	 */
418
+	public static function set_autoloaders()
419
+	{
420
+		if (empty(self::$_MSG_PATHS)) {
421
+			self::_set_messages_paths();
422
+			foreach (self::$_MSG_PATHS as $path) {
423
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);
424
+			}
425
+			// add aliases
426
+			EEH_Autoloader::add_alias('EE_messages', 'EE_messages');
427
+			EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger');
428
+		}
429
+	}
430
+
431
+
432
+	/**
433
+	 * Take care of adding all the paths for the messages components to the $_MSG_PATHS property
434
+	 * for use by the Messages Autoloaders
435
+	 *
436
+	 * @since 4.5.0
437
+	 * @return void.
438
+	 */
439
+	protected static function _set_messages_paths()
440
+	{
441
+		$dir_ref = array(
442
+			'messages/message_type',
443
+			'messages/messenger',
444
+			'messages/defaults',
445
+			'messages/defaults/email',
446
+			'messages/data_class',
447
+			'messages/validators',
448
+			'messages/validators/email',
449
+			'messages/validators/html',
450
+			'shortcodes',
451
+		);
452
+		$paths = array();
453
+		foreach ($dir_ref as $index => $dir) {
454
+			$paths[ $index ] = EE_LIBRARIES . $dir;
455
+		}
456
+		self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths);
457
+	}
458
+
459
+
460
+	/**
461
+	 * Takes care of loading dependencies
462
+	 *
463
+	 * @since 4.5.0
464
+	 * @return void
465
+	 * @throws EE_Error
466
+	 * @throws InvalidArgumentException
467
+	 * @throws ReflectionException
468
+	 * @throws InvalidDataTypeException
469
+	 * @throws InvalidInterfaceException
470
+	 */
471
+	protected static function _load_controller()
472
+	{
473
+		if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
474
+			EE_Registry::instance()->load_core('Request_Handler');
475
+			self::set_autoloaders();
476
+			self::$_EEMSG = EE_Registry::instance()->load_lib('messages');
477
+			self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor');
478
+			self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
479
+		}
480
+	}
481
+
482
+
483
+	/**
484
+	 * @param EE_Transaction $transaction
485
+	 * @throws EE_Error
486
+	 * @throws InvalidArgumentException
487
+	 * @throws InvalidDataTypeException
488
+	 * @throws InvalidInterfaceException
489
+	 * @throws ReflectionException
490
+	 */
491
+	public static function payment_reminder(EE_Transaction $transaction)
492
+	{
493
+		self::_load_controller();
494
+		$data = array($transaction, null);
495
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data);
496
+	}
497
+
498
+
499
+	/**
500
+	 * Any messages triggers for after successful gateway payments should go in here.
501
+	 *
502
+	 * @param EE_Transaction  $transaction object
503
+	 * @param EE_Payment|null $payment     object
504
+	 * @return void
505
+	 * @throws EE_Error
506
+	 * @throws InvalidArgumentException
507
+	 * @throws ReflectionException
508
+	 * @throws InvalidDataTypeException
509
+	 * @throws InvalidInterfaceException
510
+	 */
511
+	public static function payment(EE_Transaction $transaction, EE_Payment $payment = null)
512
+	{
513
+		// if there's no payment object, then we cannot do a payment type message!
514
+		if (! $payment instanceof EE_Payment) {
515
+			return;
516
+		}
517
+		self::_load_controller();
518
+		$data = array($transaction, $payment);
519
+		EE_Registry::instance()->load_helper('MSG_Template');
520
+		$message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
521
+		// if payment amount is less than 0 then switch to payment_refund message type.
522
+		$message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
523
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
524
+	}
525
+
526
+
527
+	/**
528
+	 * @param EE_Transaction $transaction
529
+	 * @throws EE_Error
530
+	 * @throws InvalidArgumentException
531
+	 * @throws InvalidDataTypeException
532
+	 * @throws InvalidInterfaceException
533
+	 * @throws ReflectionException
534
+	 */
535
+	public static function cancelled_registration(EE_Transaction $transaction)
536
+	{
537
+		self::_load_controller();
538
+		$data = array($transaction, null);
539
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data);
540
+	}
541
+
542
+
543
+	/**
544
+	 * Trigger for Registration messages
545
+	 * Note that what registration message type is sent depends on what the reg status is for the registrations on the
546
+	 * incoming transaction.
547
+	 *
548
+	 * @param EE_Registration $registration
549
+	 * @param array           $extra_details
550
+	 * @return void
551
+	 * @throws EE_Error
552
+	 * @throws InvalidArgumentException
553
+	 * @throws InvalidDataTypeException
554
+	 * @throws InvalidInterfaceException
555
+	 * @throws ReflectionException
556
+	 * @throws EntityNotFoundException
557
+	 */
558
+	public static function maybe_registration(EE_Registration $registration, $extra_details = array())
559
+	{
560
+
561
+		if (! self::_verify_registration_notification_send($registration, $extra_details)) {
562
+			// no messages please
563
+			return;
564
+		}
565
+
566
+		// get all non-trashed registrations so we make sure we send messages for the right status.
567
+		$all_registrations = $registration->transaction()->registrations(
568
+			array(
569
+				array('REG_deleted' => false),
570
+				'order_by' => array(
571
+					'Event.EVT_name'     => 'ASC',
572
+					'Attendee.ATT_lname' => 'ASC',
573
+					'Attendee.ATT_fname' => 'ASC',
574
+				),
575
+			)
576
+		);
577
+		// cached array of statuses so we only trigger messages once per status.
578
+		$statuses_sent = array();
579
+		self::_load_controller();
580
+		$mtgs = array();
581
+
582
+		// loop through registrations and trigger messages once per status.
583
+		foreach ($all_registrations as $reg) {
584
+			// already triggered?
585
+			if (in_array($reg->status_ID(), $statuses_sent)) {
586
+				continue;
587
+			}
588
+
589
+			$message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID());
590
+			$mtgs = array_merge(
591
+				$mtgs,
592
+				self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
593
+					$message_type,
594
+					array($registration->transaction(), null, $reg->status_ID())
595
+				)
596
+			);
597
+			$statuses_sent[] = $reg->status_ID();
598
+		}
599
+
600
+		if (count($statuses_sent) > 1) {
601
+			$mtgs = array_merge(
602
+				$mtgs,
603
+				self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
604
+					'registration_summary',
605
+					array($registration->transaction(), null)
606
+				)
607
+			);
608
+		}
609
+
610
+		// batch queue and initiate request
611
+		self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs);
612
+		self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
613
+	}
614
+
615
+
616
+	/**
617
+	 * This is a helper method used to very whether a registration notification should be sent or
618
+	 * not.  Prevents duplicate notifications going out for registration context notifications.
619
+	 *
620
+	 * @param EE_Registration $registration  [description]
621
+	 * @param array           $extra_details [description]
622
+	 * @return bool          true = send away, false = nope halt the presses.
623
+	 */
624
+	protected static function _verify_registration_notification_send(
625
+		EE_Registration $registration,
626
+		$extra_details = array()
627
+	) {
628
+		$request = self::getRequest();
629
+		if (
630
+			! $request->getRequestParam('non_primary_reg_notification', 0, 'int')
631
+			&& ! $registration->is_primary_registrant()
632
+		) {
633
+			return false;
634
+		}
635
+		// first we check if we're in admin and not doing front ajax
636
+		if (
637
+			($request->isAdmin() || $request->isAdminAjax())
638
+			&& ! $request->isFrontAjax()
639
+		) {
640
+			$status_change = $request->getRequestParam('txn_reg_status_change', [], 'int', true);
641
+			// make sure appropriate admin params are set for sending messages
642
+			if (
643
+				! isset($status_change['send_notifications'])
644
+				|| (isset($status_change['send_notifications']) && ! $status_change['send_notifications'])
645
+			) {
646
+				// no messages sent please.
647
+				return false;
648
+			}
649
+		} else {
650
+			// frontend request (either regular or via AJAX)
651
+			// TXN is NOT finalized ?
652
+			if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
653
+				return false;
654
+			}
655
+			// return visit but nothing changed ???
656
+			if (
657
+				isset($extra_details['revisit'], $extra_details['status_updates']) &&
658
+				$extra_details['revisit'] && ! $extra_details['status_updates']
659
+			) {
660
+				return false;
661
+			}
662
+			// NOT sending messages && reg status is something other than "Not-Approved"
663
+			if (
664
+				! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) &&
665
+				$registration->status_ID() !== EEM_Registration::status_id_not_approved
666
+			) {
667
+				return false;
668
+			}
669
+		}
670
+		// release the kraken
671
+		return true;
672
+	}
673
+
674
+
675
+	/**
676
+	 * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that
677
+	 * status id.
678
+	 *
679
+	 * @deprecated 4.9.0  Use EEH_MSG_Template::reg_status_to_message_type_array()
680
+	 *                    or EEH_MSG_Template::convert_reg_status_to_message_type
681
+	 * @param string $reg_status
682
+	 * @return array
683
+	 * @throws EE_Error
684
+	 * @throws InvalidArgumentException
685
+	 * @throws ReflectionException
686
+	 * @throws InvalidDataTypeException
687
+	 * @throws InvalidInterfaceException
688
+	 */
689
+	protected static function _get_reg_status_array($reg_status = '')
690
+	{
691
+		EE_Registry::instance()->load_helper('MSG_Template');
692
+		return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
693
+			? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
694
+			: EEH_MSG_Template::reg_status_to_message_type_array();
695
+	}
696
+
697
+
698
+	/**
699
+	 * Simply returns the payment message type for the given payment status.
700
+	 *
701
+	 * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array
702
+	 *                   or EEH_MSG_Template::convert_payment_status_to_message_type
703
+	 * @param string $payment_status The payment status being matched.
704
+	 * @return bool|string The payment message type slug matching the status or false if no match.
705
+	 * @throws EE_Error
706
+	 * @throws InvalidArgumentException
707
+	 * @throws ReflectionException
708
+	 * @throws InvalidDataTypeException
709
+	 * @throws InvalidInterfaceException
710
+	 */
711
+	protected static function _get_payment_message_type($payment_status)
712
+	{
713
+		EE_Registry::instance()->load_helper('MSG_Template');
714
+		return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
715
+			? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
716
+			: false;
717
+	}
718
+
719
+
720
+	/**
721
+	 * Message triggers for a resending already sent message(s) (via EE_Message list table)
722
+	 *
723
+	 * @access public
724
+	 * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages
725
+	 * @return bool success/fail
726
+	 * @throws EE_Error
727
+	 * @throws InvalidArgumentException
728
+	 * @throws InvalidDataTypeException
729
+	 * @throws InvalidInterfaceException
730
+	 * @throws ReflectionException
731
+	 */
732
+	public static function process_resend(array $req_data = [])
733
+	{
734
+		self::_load_controller();
735
+		$request = self::getRequest();
736
+		// if $msgID in this request then skip to the new resend_message
737
+		if ($request->getRequestParam('MSG_ID')) {
738
+			return self::resend_message();
739
+		}
740
+
741
+		// make sure any incoming request data is set on the request so that it gets picked up later.
742
+		foreach ((array) $req_data as $request_key => $request_value) {
743
+			if (! $request->requestParamIsSet($request_key)) {
744
+				$request->setRequestParam($request_key, $request_value);
745
+			}
746
+		}
747
+
748
+		if (
749
+			! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()
750
+		) {
751
+			return false;
752
+		}
753
+
754
+		try {
755
+			self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send);
756
+			self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
757
+		} catch (EE_Error $e) {
758
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
759
+			return false;
760
+		}
761
+		EE_Error::add_success(
762
+			esc_html__('Messages have been successfully queued for generation and sending.', 'event_espresso')
763
+		);
764
+		return true; // everything got queued.
765
+	}
766
+
767
+
768
+	/**
769
+	 * Message triggers for a resending already sent message(s) (via EE_Message list table)
770
+	 *
771
+	 * @return bool
772
+	 * @throws EE_Error
773
+	 * @throws InvalidArgumentException
774
+	 * @throws InvalidDataTypeException
775
+	 * @throws InvalidInterfaceException
776
+	 * @throws ReflectionException
777
+	 */
778
+	public static function resend_message()
779
+	{
780
+		self::_load_controller();
781
+
782
+		$msgID = self::getRequest()->getRequestParam('MSG_ID', 0, 'int');
783
+		if (! $msgID) {
784
+			EE_Error::add_error(
785
+				esc_html__(
786
+					'Something went wrong because there is no "MSG_ID" value in the request',
787
+					'event_espresso'
788
+				),
789
+				__FILE__,
790
+				__FUNCTION__,
791
+				__LINE__
792
+			);
793
+			return false;
794
+		}
795
+
796
+		self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID);
797
+
798
+		// setup success message.
799
+		$count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
800
+		EE_Error::add_success(
801
+			sprintf(
802
+				_n(
803
+					'There was %d message queued for resending.',
804
+					'There were %d messages queued for resending.',
805
+					$count_ready_for_resend,
806
+					'event_espresso'
807
+				),
808
+				$count_ready_for_resend
809
+			)
810
+		);
811
+		return true;
812
+	}
813
+
814
+
815
+	/**
816
+	 * Message triggers for manual payment applied by admin
817
+	 *
818
+	 * @param  EE_Payment $payment EE_payment object
819
+	 * @return bool success/fail
820
+	 * @throws EE_Error
821
+	 * @throws InvalidArgumentException
822
+	 * @throws ReflectionException
823
+	 * @throws InvalidDataTypeException
824
+	 * @throws InvalidInterfaceException
825
+	 */
826
+	public static function process_admin_payment(EE_Payment $payment)
827
+	{
828
+		EE_Registry::instance()->load_helper('MSG_Template');
829
+		// we need to get the transaction object
830
+		$transaction = $payment->transaction();
831
+		if ($transaction instanceof EE_Transaction) {
832
+			$data = array($transaction, $payment);
833
+			$message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
834
+
835
+			// if payment amount is less than 0 then switch to payment_refund message type.
836
+			$message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
837
+
838
+			// if payment_refund is selected, but the status is NOT accepted.  Then change message type to false so NO message notification goes out.
839
+			$message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved
840
+				? false : $message_type;
841
+
842
+			self::_load_controller();
843
+
844
+			self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
845
+
846
+			// get count of queued for generation
847
+			$count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(
848
+				array(
849
+					EEM_Message::status_incomplete,
850
+					EEM_Message::status_idle,
851
+				)
852
+			);
853
+
854
+			if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) {
855
+				add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
856
+				return true;
857
+			} else {
858
+				$count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(
859
+					EEM_Message::instance()->stati_indicating_failed_sending()
860
+				);
861
+				/**
862
+				 * Verify that there are actually errors.  If not then we return a success message because the queue might have been emptied due to successful
863
+				 * IMMEDIATE generation.
864
+				 */
865
+				if ($count_failed > 0) {
866
+					EE_Error::add_error(
867
+						sprintf(
868
+							_n(
869
+								'The payment notification generation failed.',
870
+								'%d payment notifications failed being sent.',
871
+								$count_failed,
872
+								'event_espresso'
873
+							),
874
+							$count_failed
875
+						),
876
+						__FILE__,
877
+						__FUNCTION__,
878
+						__LINE__
879
+					);
880
+
881
+					return false;
882
+				} else {
883
+					add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
884
+					return true;
885
+				}
886
+			}
887
+		} else {
888
+			EE_Error::add_error(
889
+				'Unable to generate the payment notification because the given value for the transaction is invalid.',
890
+				'event_espresso'
891
+			);
892
+			return false;
893
+		}
894
+	}
895
+
896
+
897
+	/**
898
+	 * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger
899
+	 *
900
+	 * @since   4.3.0
901
+	 * @param  EE_Registration[] $registrations an array of EE_Registration objects
902
+	 * @param  int               $grp_id        a specific message template group id.
903
+	 * @return void
904
+	 * @throws EE_Error
905
+	 * @throws InvalidArgumentException
906
+	 * @throws InvalidDataTypeException
907
+	 * @throws InvalidInterfaceException
908
+	 * @throws ReflectionException
909
+	 */
910
+	public static function send_newsletter_message($registrations, $grp_id)
911
+	{
912
+		// make sure mtp is id and set it in the request later messages setup.
913
+		self::getRequest()->setRequestParam('GRP_ID', (int) $grp_id);
914
+		self::_load_controller();
915
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations);
916
+	}
917
+
918
+
919
+	/**
920
+	 * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url
921
+	 *
922
+	 * @since   4.3.0
923
+	 * @param    string          $registration_message_trigger_url
924
+	 * @param    EE_Registration $registration
925
+	 * @param string             $messenger
926
+	 * @param string             $message_type
927
+	 * @return string
928
+	 * @throws EE_Error
929
+	 * @throws InvalidArgumentException
930
+	 * @throws InvalidDataTypeException
931
+	 * @throws InvalidInterfaceException
932
+	 */
933
+	public static function registration_message_trigger_url(
934
+		$registration_message_trigger_url,
935
+		EE_Registration $registration,
936
+		$messenger = 'html',
937
+		$message_type = 'invoice'
938
+	) {
939
+		// whitelist $messenger
940
+		switch ($messenger) {
941
+			case 'pdf':
942
+				$sending_messenger = 'pdf';
943
+				$generating_messenger = 'html';
944
+				break;
945
+			case 'html':
946
+			default:
947
+				$sending_messenger = 'html';
948
+				$generating_messenger = 'html';
949
+				break;
950
+		}
951
+		// whitelist $message_type
952
+		switch ($message_type) {
953
+			case 'receipt':
954
+				$message_type = 'receipt';
955
+				break;
956
+			case 'invoice':
957
+			default:
958
+				$message_type = 'invoice';
959
+				break;
960
+		}
961
+		// verify that both the messenger AND the message type are active
962
+		if (
963
+			EEH_MSG_Template::is_messenger_active($sending_messenger)
964
+			&& EEH_MSG_Template::is_mt_active($message_type)
965
+		) {
966
+			// need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?)
967
+			$template_query_params = array(
968
+				'MTP_is_active'    => true,
969
+				'MTP_messenger'    => $generating_messenger,
970
+				'MTP_message_type' => $message_type,
971
+				'Event.EVT_ID'     => $registration->event_ID(),
972
+			);
973
+			// get the message template group.
974
+			$msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
975
+			// if we don't have an EE_Message_Template_Group then return
976
+			if (! $msg_template_group instanceof EE_Message_Template_Group) {
977
+				// remove EVT_ID from query params so that global templates get picked up
978
+				unset($template_query_params['Event.EVT_ID']);
979
+				// get global template as the fallback
980
+				$msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
981
+			}
982
+			// if we don't have an EE_Message_Template_Group then return
983
+			if (! $msg_template_group instanceof EE_Message_Template_Group) {
984
+				return '';
985
+			}
986
+			// generate the URL
987
+			$registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger(
988
+				$sending_messenger,
989
+				$generating_messenger,
990
+				'purchaser',
991
+				$message_type,
992
+				$registration,
993
+				$msg_template_group->ID(),
994
+				$registration->transaction_ID()
995
+			);
996
+		}
997
+		return $registration_message_trigger_url;
998
+	}
999
+
1000
+
1001
+	/**
1002
+	 * Use to generate and return a message preview!
1003
+	 *
1004
+	 * @param  string $type      This should correspond with a valid message type
1005
+	 * @param  string $context   This should correspond with a valid context for the message type
1006
+	 * @param  string $messenger This should correspond with a valid messenger.
1007
+	 * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
1008
+	 *                           preview
1009
+	 * @return bool|string The body of the message or if send is requested, sends.
1010
+	 * @throws EE_Error
1011
+	 * @throws InvalidArgumentException
1012
+	 * @throws InvalidDataTypeException
1013
+	 * @throws InvalidInterfaceException
1014
+	 * @throws ReflectionException
1015
+	 */
1016
+	public static function preview_message($type, $context, $messenger, $send = false)
1017
+	{
1018
+		self::_load_controller();
1019
+		$mtg = new EE_Message_To_Generate(
1020
+			$messenger,
1021
+			$type,
1022
+			array(),
1023
+			$context,
1024
+			true
1025
+		);
1026
+		$generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send);
1027
+		if ($generated_preview_queue instanceof EE_Messages_Queue) {
1028
+			// loop through all content for the preview and remove any persisted records.
1029
+			$content = '';
1030
+			foreach ($generated_preview_queue->get_message_repository() as $message) {
1031
+				$content = $message->content();
1032
+				if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) {
1033
+					$message->delete();
1034
+				}
1035
+			}
1036
+			return $content;
1037
+		} else {
1038
+			return $generated_preview_queue;
1039
+		}
1040
+	}
1041
+
1042
+
1043
+	/**
1044
+	 * This is a method that allows for sending a message using a messenger matching the string given and the provided
1045
+	 * EE_Message_Queue object.  The EE_Message_Queue object is used to create a single aggregate EE_Message via the
1046
+	 * content found in the EE_Message objects in the queue.
1047
+	 *
1048
+	 * @since 4.9.0
1049
+	 * @param string            $messenger            a string matching a valid active messenger in the system
1050
+	 * @param string            $message_type         Although it seems contrary to the name of the method, a message
1051
+	 *                                                type name is still required to send along the message type to the
1052
+	 *                                                messenger because this is used for determining what specific
1053
+	 *                                                variations might be loaded for the generated message.
1054
+	 * @param EE_Messages_Queue $queue
1055
+	 * @param string            $custom_subject       Can be used to set what the custom subject string will be on the
1056
+	 *                                                aggregate EE_Message object.
1057
+	 * @return bool success or fail.
1058
+	 * @throws EE_Error
1059
+	 * @throws InvalidArgumentException
1060
+	 * @throws ReflectionException
1061
+	 * @throws InvalidDataTypeException
1062
+	 * @throws InvalidInterfaceException
1063
+	 */
1064
+	public static function send_message_with_messenger_only(
1065
+		$messenger,
1066
+		$message_type,
1067
+		EE_Messages_Queue $queue,
1068
+		$custom_subject = ''
1069
+	) {
1070
+		self::_load_controller();
1071
+		/** @type EE_Message_To_Generate_From_Queue $message_to_generate */
1072
+		$message_to_generate = EE_Registry::instance()->load_lib(
1073
+			'Message_To_Generate_From_Queue',
1074
+			array(
1075
+				$messenger,
1076
+				$message_type,
1077
+				$queue,
1078
+				$custom_subject,
1079
+			)
1080
+		);
1081
+		return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate);
1082
+	}
1083
+
1084
+
1085
+	/**
1086
+	 * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation)
1087
+	 *
1088
+	 * @since 4.9.0
1089
+	 * @param array $message_ids An array of message ids
1090
+	 * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated
1091
+	 *                           messages.
1092
+	 * @throws EE_Error
1093
+	 * @throws InvalidArgumentException
1094
+	 * @throws InvalidDataTypeException
1095
+	 * @throws InvalidInterfaceException
1096
+	 * @throws ReflectionException
1097
+	 */
1098
+	public static function generate_now($message_ids)
1099
+	{
1100
+		self::_load_controller();
1101
+		$messages = EEM_Message::instance()->get_all(
1102
+			array(
1103
+				0 => array(
1104
+					'MSG_ID' => array('IN', $message_ids),
1105
+					'STS_ID' => EEM_Message::status_incomplete,
1106
+				),
1107
+			)
1108
+		);
1109
+		$generated_queue = false;
1110
+		if ($messages) {
1111
+			$generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
1112
+		}
1113
+
1114
+		if (! $generated_queue instanceof EE_Messages_Queue) {
1115
+			EE_Error::add_error(
1116
+				esc_html__(
1117
+					'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.',
1118
+					'event_espresso'
1119
+				),
1120
+				__FILE__,
1121
+				__FUNCTION__,
1122
+				__LINE__
1123
+			);
1124
+		}
1125
+		return $generated_queue;
1126
+	}
1127
+
1128
+
1129
+	/**
1130
+	 * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or,
1131
+	 * EEM_Message::status_idle
1132
+	 *
1133
+	 * @since 4.9.0
1134
+	 * @param $message_ids
1135
+	 * @return bool|EE_Messages_Queue false if no messages sent.
1136
+	 * @throws EE_Error
1137
+	 * @throws InvalidArgumentException
1138
+	 * @throws InvalidDataTypeException
1139
+	 * @throws InvalidInterfaceException
1140
+	 * @throws ReflectionException
1141
+	 */
1142
+	public static function send_now($message_ids)
1143
+	{
1144
+		self::_load_controller();
1145
+		$messages = EEM_Message::instance()->get_all(
1146
+			array(
1147
+				0 => array(
1148
+					'MSG_ID' => array('IN', $message_ids),
1149
+					'STS_ID' => array(
1150
+						'IN',
1151
+						array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry),
1152
+					),
1153
+				),
1154
+			)
1155
+		);
1156
+		$sent_queue = false;
1157
+		if ($messages) {
1158
+			$sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
1159
+		}
1160
+
1161
+		if (! $sent_queue instanceof EE_Messages_Queue) {
1162
+			EE_Error::add_error(
1163
+				esc_html__(
1164
+					'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.',
1165
+					'event_espresso'
1166
+				),
1167
+				__FILE__,
1168
+				__FUNCTION__,
1169
+				__LINE__
1170
+			);
1171
+		} else {
1172
+			// can count how many sent by using the messages in the queue
1173
+			$sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent());
1174
+			if ($sent_count > 0) {
1175
+				EE_Error::add_success(
1176
+					sprintf(
1177
+						_n(
1178
+							'There was %d message successfully sent.',
1179
+							'There were %d messages successfully sent.',
1180
+							$sent_count,
1181
+							'event_espresso'
1182
+						),
1183
+						$sent_count
1184
+					)
1185
+				);
1186
+			} else {
1187
+				EE_Error::overwrite_errors();
1188
+				EE_Error::add_error(
1189
+					esc_html__(
1190
+						'No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error.
1191 1191
 					If there was an error, you can look at the messages in the message activity list table for any error messages.',
1192
-                        'event_espresso'
1193
-                    ),
1194
-                    __FILE__,
1195
-                    __FUNCTION__,
1196
-                    __LINE__
1197
-                );
1198
-            }
1199
-        }
1200
-        return $sent_queue;
1201
-    }
1202
-
1203
-
1204
-    /**
1205
-     * Generate and send immediately from the given $message_ids
1206
-     *
1207
-     * @param array $message_ids EE_Message entity ids.
1208
-     * @throws EE_Error
1209
-     * @throws InvalidArgumentException
1210
-     * @throws InvalidDataTypeException
1211
-     * @throws InvalidInterfaceException
1212
-     * @throws ReflectionException
1213
-     */
1214
-    public static function generate_and_send_now(array $message_ids)
1215
-    {
1216
-        $generated_queue = self::generate_now($message_ids);
1217
-        // now let's just trigger sending immediately from this queue.
1218
-        $messages_sent = $generated_queue instanceof EE_Messages_Queue
1219
-            ? $generated_queue->execute()
1220
-            : 0;
1221
-        if ($messages_sent) {
1222
-            EE_Error::add_success(
1223
-                esc_html(
1224
-                    sprintf(
1225
-                        _n(
1226
-                            'There was %d message successfully generated and sent.',
1227
-                            'There were %d messages successfully generated and sent.',
1228
-                            $messages_sent,
1229
-                            'event_espresso'
1230
-                        ),
1231
-                        $messages_sent
1232
-                    )
1233
-                )
1234
-            );
1235
-            // errors would be added via the generate_now method.
1236
-        }
1237
-    }
1238
-
1239
-
1240
-    /**
1241
-     * This will queue the incoming message ids for resending.
1242
-     * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued.
1243
-     *
1244
-     * @since 4.9.0
1245
-     * @param array $message_ids An array of EE_Message IDs
1246
-     * @return bool true means messages were successfully queued for resending, false means none were queued for
1247
-     *                           resending.
1248
-     * @throws EE_Error
1249
-     * @throws InvalidArgumentException
1250
-     * @throws InvalidDataTypeException
1251
-     * @throws InvalidInterfaceException
1252
-     * @throws ReflectionException
1253
-     */
1254
-    public static function queue_for_resending($message_ids)
1255
-    {
1256
-        self::_load_controller();
1257
-        self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids);
1258
-
1259
-        // get queue and count
1260
-        $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
1261
-
1262
-        if (
1263
-            $queue_count > 0
1264
-        ) {
1265
-            EE_Error::add_success(
1266
-                sprintf(
1267
-                    _n(
1268
-                        '%d message successfully queued for resending.',
1269
-                        '%d messages successfully queued for resending.',
1270
-                        $queue_count,
1271
-                        'event_espresso'
1272
-                    ),
1273
-                    $queue_count
1274
-                )
1275
-            );
1276
-            /**
1277
-             * @see filter usage in EE_Messages_Queue::initiate_request_by_priority
1278
-             */
1279
-        } elseif (
1280
-            apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true)
1281
-            || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
1282
-        ) {
1283
-            $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent);
1284
-            if ($queue_count > 0) {
1285
-                EE_Error::add_success(
1286
-                    sprintf(
1287
-                        _n(
1288
-                            '%d message successfully sent.',
1289
-                            '%d messages successfully sent.',
1290
-                            $queue_count,
1291
-                            'event_espresso'
1292
-                        ),
1293
-                        $queue_count
1294
-                    )
1295
-                );
1296
-            } else {
1297
-                EE_Error::add_error(
1298
-                    esc_html__(
1299
-                        'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.',
1300
-                        'event_espresso'
1301
-                    ),
1302
-                    __FILE__,
1303
-                    __FUNCTION__,
1304
-                    __LINE__
1305
-                );
1306
-            }
1307
-        } else {
1308
-            EE_Error::add_error(
1309
-                esc_html__(
1310
-                    'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.',
1311
-                    'event_espresso'
1312
-                ),
1313
-                __FILE__,
1314
-                __FUNCTION__,
1315
-                __LINE__
1316
-            );
1317
-        }
1318
-        return (bool) $queue_count;
1319
-    }
1320
-
1321
-
1322
-    /**
1323
-     * debug
1324
-     *
1325
-     * @param string          $class
1326
-     * @param string          $func
1327
-     * @param string          $line
1328
-     * @param \EE_Transaction $transaction
1329
-     * @param array           $info
1330
-     * @param bool            $display_request
1331
-     * @throws EE_Error
1332
-     * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
1333
-     */
1334
-    protected static function log(
1335
-        $class = '',
1336
-        $func = '',
1337
-        $line = '',
1338
-        EE_Transaction $transaction,
1339
-        $info = array(),
1340
-        $display_request = false
1341
-    ) {
1342
-        if (defined('EE_DEBUG') && EE_DEBUG) {
1343
-            if ($transaction instanceof EE_Transaction) {
1344
-                // don't serialize objects
1345
-                $info = EEH_Debug_Tools::strip_objects($info);
1346
-                $info['TXN_status'] = $transaction->status_ID();
1347
-                $info['TXN_reg_steps'] = $transaction->reg_steps();
1348
-                if ($transaction->ID()) {
1349
-                    $index = 'EE_Transaction: ' . $transaction->ID();
1350
-                    EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1351
-                }
1352
-            }
1353
-        }
1354
-    }
1355
-
1356
-
1357
-    /**
1358
-     *  Resets all the static properties in this class when called.
1359
-     */
1360
-    public static function reset()
1361
-    {
1362
-        self::$_EEMSG = null;
1363
-        self::$_message_resource_manager = null;
1364
-        self::$_MSG_PROCESSOR = null;
1365
-        self::$_MSG_PATHS = null;
1366
-        self::$_TMP_PACKS = array();
1367
-    }
1192
+						'event_espresso'
1193
+					),
1194
+					__FILE__,
1195
+					__FUNCTION__,
1196
+					__LINE__
1197
+				);
1198
+			}
1199
+		}
1200
+		return $sent_queue;
1201
+	}
1202
+
1203
+
1204
+	/**
1205
+	 * Generate and send immediately from the given $message_ids
1206
+	 *
1207
+	 * @param array $message_ids EE_Message entity ids.
1208
+	 * @throws EE_Error
1209
+	 * @throws InvalidArgumentException
1210
+	 * @throws InvalidDataTypeException
1211
+	 * @throws InvalidInterfaceException
1212
+	 * @throws ReflectionException
1213
+	 */
1214
+	public static function generate_and_send_now(array $message_ids)
1215
+	{
1216
+		$generated_queue = self::generate_now($message_ids);
1217
+		// now let's just trigger sending immediately from this queue.
1218
+		$messages_sent = $generated_queue instanceof EE_Messages_Queue
1219
+			? $generated_queue->execute()
1220
+			: 0;
1221
+		if ($messages_sent) {
1222
+			EE_Error::add_success(
1223
+				esc_html(
1224
+					sprintf(
1225
+						_n(
1226
+							'There was %d message successfully generated and sent.',
1227
+							'There were %d messages successfully generated and sent.',
1228
+							$messages_sent,
1229
+							'event_espresso'
1230
+						),
1231
+						$messages_sent
1232
+					)
1233
+				)
1234
+			);
1235
+			// errors would be added via the generate_now method.
1236
+		}
1237
+	}
1238
+
1239
+
1240
+	/**
1241
+	 * This will queue the incoming message ids for resending.
1242
+	 * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued.
1243
+	 *
1244
+	 * @since 4.9.0
1245
+	 * @param array $message_ids An array of EE_Message IDs
1246
+	 * @return bool true means messages were successfully queued for resending, false means none were queued for
1247
+	 *                           resending.
1248
+	 * @throws EE_Error
1249
+	 * @throws InvalidArgumentException
1250
+	 * @throws InvalidDataTypeException
1251
+	 * @throws InvalidInterfaceException
1252
+	 * @throws ReflectionException
1253
+	 */
1254
+	public static function queue_for_resending($message_ids)
1255
+	{
1256
+		self::_load_controller();
1257
+		self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids);
1258
+
1259
+		// get queue and count
1260
+		$queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
1261
+
1262
+		if (
1263
+			$queue_count > 0
1264
+		) {
1265
+			EE_Error::add_success(
1266
+				sprintf(
1267
+					_n(
1268
+						'%d message successfully queued for resending.',
1269
+						'%d messages successfully queued for resending.',
1270
+						$queue_count,
1271
+						'event_espresso'
1272
+					),
1273
+					$queue_count
1274
+				)
1275
+			);
1276
+			/**
1277
+			 * @see filter usage in EE_Messages_Queue::initiate_request_by_priority
1278
+			 */
1279
+		} elseif (
1280
+			apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true)
1281
+			|| EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
1282
+		) {
1283
+			$queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent);
1284
+			if ($queue_count > 0) {
1285
+				EE_Error::add_success(
1286
+					sprintf(
1287
+						_n(
1288
+							'%d message successfully sent.',
1289
+							'%d messages successfully sent.',
1290
+							$queue_count,
1291
+							'event_espresso'
1292
+						),
1293
+						$queue_count
1294
+					)
1295
+				);
1296
+			} else {
1297
+				EE_Error::add_error(
1298
+					esc_html__(
1299
+						'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.',
1300
+						'event_espresso'
1301
+					),
1302
+					__FILE__,
1303
+					__FUNCTION__,
1304
+					__LINE__
1305
+				);
1306
+			}
1307
+		} else {
1308
+			EE_Error::add_error(
1309
+				esc_html__(
1310
+					'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.',
1311
+					'event_espresso'
1312
+				),
1313
+				__FILE__,
1314
+				__FUNCTION__,
1315
+				__LINE__
1316
+			);
1317
+		}
1318
+		return (bool) $queue_count;
1319
+	}
1320
+
1321
+
1322
+	/**
1323
+	 * debug
1324
+	 *
1325
+	 * @param string          $class
1326
+	 * @param string          $func
1327
+	 * @param string          $line
1328
+	 * @param \EE_Transaction $transaction
1329
+	 * @param array           $info
1330
+	 * @param bool            $display_request
1331
+	 * @throws EE_Error
1332
+	 * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
1333
+	 */
1334
+	protected static function log(
1335
+		$class = '',
1336
+		$func = '',
1337
+		$line = '',
1338
+		EE_Transaction $transaction,
1339
+		$info = array(),
1340
+		$display_request = false
1341
+	) {
1342
+		if (defined('EE_DEBUG') && EE_DEBUG) {
1343
+			if ($transaction instanceof EE_Transaction) {
1344
+				// don't serialize objects
1345
+				$info = EEH_Debug_Tools::strip_objects($info);
1346
+				$info['TXN_status'] = $transaction->status_ID();
1347
+				$info['TXN_reg_steps'] = $transaction->reg_steps();
1348
+				if ($transaction->ID()) {
1349
+					$index = 'EE_Transaction: ' . $transaction->ID();
1350
+					EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1351
+				}
1352
+			}
1353
+		}
1354
+	}
1355
+
1356
+
1357
+	/**
1358
+	 *  Resets all the static properties in this class when called.
1359
+	 */
1360
+	public static function reset()
1361
+	{
1362
+		self::$_EEMSG = null;
1363
+		self::$_message_resource_manager = null;
1364
+		self::$_MSG_PROCESSOR = null;
1365
+		self::$_MSG_PATHS = null;
1366
+		self::$_TMP_PACKS = array();
1367
+	}
1368 1368
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
                 'event_espresso'
205 205
             );
206 206
             // add specific message for developers if WP_DEBUG in on
207
-            $error_msg .= '||' . $e->getMessage();
207
+            $error_msg .= '||'.$e->getMessage();
208 208
             EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
209 209
         }
210 210
     }
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
                 'event_espresso'
291 291
             );
292 292
             // add specific message for developers if WP_DEBUG in on
293
-            $error_msg .= '||' . $e->getMessage();
293
+            $error_msg .= '||'.$e->getMessage();
294 294
             EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
295 295
         }
296 296
     }
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
         $transient_key = $request->getRequestParam('key');
323 323
 
324 324
         // now let's verify transient, if not valid exit immediately
325
-        if (! get_transient($transient_key)) {
325
+        if ( ! get_transient($transient_key)) {
326 326
             /**
327 327
              * trigger error so this gets in the error logs.  This is important because it happens on a non-user
328 328
              * request.
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
         delete_transient($transient_key);
335 335
 
336 336
         if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
337
-            $method = 'batch_' . $cron_type . '_from_queue';
337
+            $method = 'batch_'.$cron_type.'_from_queue';
338 338
             if (method_exists(self::$_MSG_PROCESSOR, $method)) {
339 339
                 self::$_MSG_PROCESSOR->$method();
340 340
             } else {
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
         $template_pack_collection->rewind();
402 402
         $template_packs = array();
403 403
         while ($template_pack_collection->valid()) {
404
-            $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current();
404
+            $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current();
405 405
             $template_pack_collection->next();
406 406
         }
407 407
         return $template_packs;
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
         );
452 452
         $paths = array();
453 453
         foreach ($dir_ref as $index => $dir) {
454
-            $paths[ $index ] = EE_LIBRARIES . $dir;
454
+            $paths[$index] = EE_LIBRARIES.$dir;
455 455
         }
456 456
         self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths);
457 457
     }
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
      */
471 471
     protected static function _load_controller()
472 472
     {
473
-        if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
473
+        if ( ! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
474 474
             EE_Registry::instance()->load_core('Request_Handler');
475 475
             self::set_autoloaders();
476 476
             self::$_EEMSG = EE_Registry::instance()->load_lib('messages');
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
     public static function payment(EE_Transaction $transaction, EE_Payment $payment = null)
512 512
     {
513 513
         // if there's no payment object, then we cannot do a payment type message!
514
-        if (! $payment instanceof EE_Payment) {
514
+        if ( ! $payment instanceof EE_Payment) {
515 515
             return;
516 516
         }
517 517
         self::_load_controller();
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
     public static function maybe_registration(EE_Registration $registration, $extra_details = array())
559 559
     {
560 560
 
561
-        if (! self::_verify_registration_notification_send($registration, $extra_details)) {
561
+        if ( ! self::_verify_registration_notification_send($registration, $extra_details)) {
562 562
             // no messages please
563 563
             return;
564 564
         }
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
         } else {
650 650
             // frontend request (either regular or via AJAX)
651 651
             // TXN is NOT finalized ?
652
-            if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
652
+            if ( ! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
653 653
                 return false;
654 654
             }
655 655
             // return visit but nothing changed ???
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
 
741 741
         // make sure any incoming request data is set on the request so that it gets picked up later.
742 742
         foreach ((array) $req_data as $request_key => $request_value) {
743
-            if (! $request->requestParamIsSet($request_key)) {
743
+            if ( ! $request->requestParamIsSet($request_key)) {
744 744
                 $request->setRequestParam($request_key, $request_value);
745 745
             }
746 746
         }
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
         self::_load_controller();
781 781
 
782 782
         $msgID = self::getRequest()->getRequestParam('MSG_ID', 0, 'int');
783
-        if (! $msgID) {
783
+        if ( ! $msgID) {
784 784
             EE_Error::add_error(
785 785
                 esc_html__(
786 786
                     'Something went wrong because there is no "MSG_ID" value in the request',
@@ -973,14 +973,14 @@  discard block
 block discarded – undo
973 973
             // get the message template group.
974 974
             $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
975 975
             // if we don't have an EE_Message_Template_Group then return
976
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
976
+            if ( ! $msg_template_group instanceof EE_Message_Template_Group) {
977 977
                 // remove EVT_ID from query params so that global templates get picked up
978 978
                 unset($template_query_params['Event.EVT_ID']);
979 979
                 // get global template as the fallback
980 980
                 $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
981 981
             }
982 982
             // if we don't have an EE_Message_Template_Group then return
983
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
983
+            if ( ! $msg_template_group instanceof EE_Message_Template_Group) {
984 984
                 return '';
985 985
             }
986 986
             // generate the URL
@@ -1111,7 +1111,7 @@  discard block
 block discarded – undo
1111 1111
             $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
1112 1112
         }
1113 1113
 
1114
-        if (! $generated_queue instanceof EE_Messages_Queue) {
1114
+        if ( ! $generated_queue instanceof EE_Messages_Queue) {
1115 1115
             EE_Error::add_error(
1116 1116
                 esc_html__(
1117 1117
                     'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.',
@@ -1158,7 +1158,7 @@  discard block
 block discarded – undo
1158 1158
             $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
1159 1159
         }
1160 1160
 
1161
-        if (! $sent_queue instanceof EE_Messages_Queue) {
1161
+        if ( ! $sent_queue instanceof EE_Messages_Queue) {
1162 1162
             EE_Error::add_error(
1163 1163
                 esc_html__(
1164 1164
                     'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.',
@@ -1346,7 +1346,7 @@  discard block
 block discarded – undo
1346 1346
                 $info['TXN_status'] = $transaction->status_ID();
1347 1347
                 $info['TXN_reg_steps'] = $transaction->reg_steps();
1348 1348
                 if ($transaction->ID()) {
1349
-                    $index = 'EE_Transaction: ' . $transaction->ID();
1349
+                    $index = 'EE_Transaction: '.$transaction->ID();
1350 1350
                     EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1351 1351
                 }
1352 1352
             }
Please login to merge, or discard this patch.