Completed
Branch BUG-10738-inconsistency-in-ses... (a1eed8)
by
unknown
24:27 queued 12:29
created

EE_Messages_Processor   D

Complexity

Total Complexity 70

Size/Duplication

Total Lines 571
Duplicated Lines 0.7 %

Coupling/Cohesion

Components 1
Dependencies 13

Importance

Changes 0
Metric Value
dl 4
loc 571
rs 4.9473
c 0
b 0
f 0
wmc 70
lcom 1
cbo 13

22 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A _init_queue_and_generator() 0 4 1
A get_queue() 0 3 1
A batch_generate_from_queue() 0 13 3
C _build_queue_for_generation() 0 25 7
B _build_queue_for_sending() 0 19 5
A batch_send_from_queue() 0 13 3
A generate_and_return() 0 5 1
A generate_queue() 0 3 1
A batch_queue_for_generation_and_persist() 0 5 1
A batch_queue_for_generation_no_persist() 0 4 1
B _queue_for_generation_loop() 0 12 5
A generate_and_queue_for_sending() 0 5 1
A queue_for_sending() 0 14 3
B generate_and_send_now() 0 33 6
A generate_for_all_active_messengers() 0 9 2
A setup_mtgs_for_all_active_messengers() 0 10 3
A queue_for_generation() 0 5 2
B setup_messages_from_ids_and_send() 0 24 3
C process_immediately_from_queue() 0 33 8
B generate_for_preview() 0 26 4
C setup_messages_to_generate_from_registration_ids_in_request() 4 42 8

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like EE_Messages_Processor often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use EE_Messages_Processor, and based on these observations, apply Extract Interface, too.

1
<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
2
3
/**
4
 * This class contains all business logic related to generating, queuing, and scheduling of
5
 * messages in the EE_messages system.
6
 *
7
 * @package    Event Espresso
8
 * @subpackage messages
9
 * @author     Darren Ethier
10
 * @since      4.9.0
11
 */
12
class EE_Messages_Processor {
13
14
15
	/**
16
	 * @type EE_Message_Resource_Manager $_message_resource_manager
17
	 */
18
	protected $_message_resource_manager;
19
20
	/**
21
	 * @type EE_Messages_Queue
22
	 */
23
	protected $_queue;
24
25
	/**
26
	 * @type  EE_Messages_Generator
27
	 */
28
	protected $_generator;
29
30
31
32
33
	/**
34
	 * constructor
35
	 *
36
	 * @param EE_Message_Resource_Manager $message_resource_manager
37
	 */
38
	public function __construct( EE_Message_Resource_Manager $message_resource_manager ) {
39
		$this->_message_resource_manager = $message_resource_manager;
40
		$this->_init_queue_and_generator();
41
	}
42
43
44
45
46
	/**
47
	 * This method sets (or resets) the various properties for use.
48
	 *
49
	 * - $_queue = holds the messages queue
50
	 * - $_generator = holds the messages generator
51
	 */
52
	protected function _init_queue_and_generator() {
53
		$this->_generator = EE_Registry::factory( 'EE_Messages_Generator' );
54
		$this->_queue = $this->_generator->generation_queue();
55
	}
56
57
58
59
60
	/**
61
	 * This returns the current set queue.
62
	 * @return EE_Messages_Queue
63
	 */
64
	public function get_queue() {
65
		return $this->_queue;
66
	}
67
68
69
70
	/**
71
	 * This method can be utilized to process messages from a queue and they will be processed immediately on the same request.
72
	 * Please note that this method alone does not bypass the usual "locks" for generation/sending (it assumes client code
73
	 * has already filtered those if necessary).
74
	 *
75
	 * @param EE_Messages_Queue $queue_to_process
76
	 * @return bool  true for success false for error.
77
	 */
78
	public function process_immediately_from_queue( EE_Messages_Queue $queue_to_process ) {
79
		$success = false;
80
		$messages_to_send = array();
81
		$messages_to_generate = array();
82
		//loop through and setup the various messages from the queue so we know what is being processed
83
		$queue_to_process->get_message_repository()->rewind();
84
		foreach ( $queue_to_process->get_message_repository() as $message ) {
85
			if ( $message->STS_ID() === EEM_Message::status_incomplete ) {
86
				$messages_to_generate[] = $message;
87
				continue;
88
			}
89
90
			if ( in_array( $message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send() ) ) {
91
				$messages_to_send[] = $message;
92
				continue;
93
			}
94
		}
95
96
		//do generation/sends
97
		if ( $messages_to_generate ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $messages_to_generate of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
98
			$success = $this->batch_generate_from_queue( $messages_to_generate, true );
99
		}
100
101
		if ( $messages_to_send ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $messages_to_send of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
102
			$sent = $this->batch_send_from_queue( $messages_to_send, true );
103
			//if there was messages to generate and it failed, then we override any success value for the sending process
104
			//otherwise we just use the return from batch send.  The intent is that there is a simple response for success/fail.
105
			//Either everything was successful or we consider it a fail.  To be clear, this is a limitation of doing
106
			//all messages processing on the same request.
107
			$success = $messages_to_generate && ! $success ? false : $sent;
0 ignored issues
show
Bug Best Practice introduced by
The expression $messages_to_generate of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
108
		}
109
		return $success;
110
	}
111
112
113
	/**
114
	 * Calls the EE_Messages_Queue::get_batch_to_generate() method and sends to EE_Messages_Generator.
115
	 *
116
	 * @param  EE_Message[] $messages    Array of EE_Message objects (optional) to build the queue with.
117
	 * @param  bool         $clear_queue Whether to ensure a fresh queue or not.
118
	 *
119
	 * @return bool|EE_Messages_Queue return false if nothing generated.  This returns a new EE_Message_Queue with
120
	 *                                   generated messages.
121
	 */
122
	public function batch_generate_from_queue( $messages = array(), $clear_queue = false ) {
123
		if ( $this->_build_queue_for_generation( $messages, $clear_queue ) ) {
124
			$new_queue = $this->_generator->generate();
125
			if ( $new_queue instanceof EE_Messages_Queue ) {
126
				//unlock queue
127
				$this->_queue->unlock_queue();
128
				$new_queue->initiate_request_by_priority( 'send' );
129
				return $new_queue;
130
			}
131
		}
132
		$this->_queue->unlock_queue();
133
		return false;
134
	}
135
136
137
138
	/**
139
	 * This method preps a queue for generation.
140
	 *
141
	 * @since    4.9.0
142
	 *
143
	 * @param EE_Message[] $messages    Array of EE_Message objects to build the queue with
144
	 *
145
	 * @param   bool       $clear_queue This indicates whether the existing queue should be dumped or not.
146
	 *
147
	 * @return bool true means queue prepped, false means there was a lock so no generation please.
148
	 */
149
	protected function _build_queue_for_generation( $messages = array(), $clear_queue = false ) {
150
151
		if ( $clear_queue ) {
152
			$this->_init_queue_and_generator();
153
		}
154
155
		if ( $messages ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $messages of type EE_Message[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
156
			//if generation is locked then get out now because that means processing is already happening.
157
			if ( $this->_queue->is_locked() ) {
158
				return false;
159
			}
160
161
			$this->_queue->lock_queue();
162
			$messages = is_array( $messages ) ? $messages : array( $messages );
163
			foreach ( $messages as $message ) {
164
				if ( $message instanceof EE_Message ) {
165
					$data = $message->all_extra_meta_array();
166
					$this->_queue->add( $message, $data );
167
				}
168
			}
169
			return true;
170
		} else {
171
			return $this->_queue->get_batch_to_generate();
172
		}
173
	}
174
175
176
	/**
177
	 * This method preps a queue for sending.
178
	 *
179
	 * @param EE_Message[] $messages
180
	 * @param bool  $clear_queue Used to indicate whether to start with a fresh queue or not.
181
	 *
182
	 * @return bool true means queue prepped, false means there was a lock so no queue prepped.
183
	 */
184
	protected function _build_queue_for_sending( $messages, $clear_queue = false ) {
185
		//if sending is locked then get out now because that means processing is already happening.
186
		if ( $this->_queue->is_locked( EE_Messages_Queue::action_sending ) ) {
187
			return false;
188
		}
189
190
		$this->_queue->lock_queue( EE_Messages_Queue::action_sending );
191
192
		if ( $clear_queue ) {
193
			$this->_init_queue_and_generator();
194
		}
195
196
		$messages = is_array( $messages ) ? $messages : array( $messages );
197
198
		foreach ( $messages as $message ) {
199
			$this->_queue->add( $message );
200
		}
201
		return true;
202
	}
203
204
205
	/**
206
	 * Calls the EE_Message_Queue::get_to_send_batch_and_send() method and then immediately just calls EE_Message_Queue::execute()
207
	 * to iterate and send unsent messages.
208
	 *
209
	 * @param EE_Message[] $messages    If an array of messages is sent in then use it.
210
	 *
211
	 * @param bool         $clear_queue Whether to initialize a new queue or keep the existing one.
212
	 *
213
	 * @return EE_Messages_Queue
214
	 */
215
	public function batch_send_from_queue( $messages = array(), $clear_queue = false ) {
216
217
		if ( $messages && $this->_build_queue_for_sending( $messages, $clear_queue ) ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $messages of type EE_Message[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
218
			$this->_queue->execute();
219
			$this->_queue->unlock_queue( EE_Messages_Queue::action_sending );
220
		} else {
221
			//get messages to send and execute.
222
			$this->_queue->get_to_send_batch_and_send();
223
		}
224
		//note: callers can use the EE_Messages_Queue::count_STS_in_queue() method to find out if there were any failed
225
		//messages in the queue and decide how to handle at that point.
226
		return $this->_queue;
227
	}
228
229
230
231
232
233
234
	/**
235
	 * This immediately generates messages using the given array of EE_Message_To_Generate objects and returns the
236
	 * EE_Message_Queue with the generated messages for the caller to work with.  Note, this does NOT save the generated
237
	 * messages in the queue, leaving it up to the caller to do so.
238
	 *
239
	 * @param EE_Message_To_Generate[] $messages_to_generate
240
	 * @return EE_Messages_Queue
241
	 */
242
	public function generate_and_return(  $messages_to_generate ) {
243
		$this->_init_queue_and_generator();
244
		$this->_queue_for_generation_loop( $messages_to_generate );
245
		return $this->_generator->generate( false );
246
	}
247
248
249
250
251
	/**
252
	 * Executes the generator generate method on the current internal queue, and returns the generated queue.
253
	 * @param  bool     $persist    Indicate whether to instruct the generator to persist the generated queue (true) or not (false).
254
	 * @return EE_Messages_Queue
255
	 */
256
	public function generate_queue( $persist = true ) {
257
		return $this->_generator->generate( $persist );
258
	}
259
260
261
262
263
	/**
264
	 * Queue for generation.  Note this does NOT persist to the db.  Client code should call get_message_repository()->save() if desire
265
	 * to persist.  This method is provided to client code to decide what it wants to do with queued messages for generation.
266
	 * @param EE_Message_To_Generate $message_to_generate
267
	 * @param bool                   $test_send             Whether this item is for a test send or not.
268
	 * @return  EE_Messages_Queue
269
	 */
270
	public function queue_for_generation( EE_Message_To_Generate $message_to_generate, $test_send = false ) {
271
		if ( $message_to_generate->valid() ) {
272
			$this->_generator->create_and_add_message_to_queue( $message_to_generate, $test_send );
273
		}
274
	}
275
276
277
278
279
280
281
282
	/**
283
	 * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message adds them to the generation queue
284
	 * and then persists to storage.
285
	 *
286
	 * @param EE_Message_To_Generate[] $messages_to_generate
287
	 */
288
	public function batch_queue_for_generation_and_persist( $messages_to_generate ) {
289
		$this->_init_queue_and_generator();
290
		$this->_queue_for_generation_loop( $messages_to_generate );
291
		$this->_queue->save();
292
	}
293
294
295
296
297
298
299
	/**
300
	 * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message and adds them to the generation
301
	 * queue.  Does NOT persist to storage (unless there is an error.
302
	 * Client code can retrieve the generated queue by calling EEM_Messages_Processor::get_queue()
303
	 *
304
	 * @param EE_Message_To_Generate[]  $messages_to_generate
305
	 */
306
	public function batch_queue_for_generation_no_persist( $messages_to_generate ) {
307
		$this->_init_queue_and_generator();
308
		$this->_queue_for_generation_loop( $messages_to_generate );
309
	}
310
311
312
313
314
	/**
315
	 * Simply loops through the given array of EE_Message_To_Generate objects and adds them to the _queue as EE_Message
316
	 * objects.
317
	 *
318
	 * @param EE_Message_To_Generate[] $messages_to_generate
319
	 */
320
	protected function _queue_for_generation_loop( $messages_to_generate ) {
321
		//make sure is in an array.
322
		if ( ! is_array( $messages_to_generate ) ) {
323
			$messages_to_generate = array( $messages_to_generate );
324
		}
325
326
		foreach ( $messages_to_generate as $message_to_generate ) {
327
			if ( $message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid() ) {
328
				$this->queue_for_generation( $message_to_generate );
329
			}
330
		}
331
	}
332
333
334
335
336
337
	/**
338
	 * Receives an array of EE_Message_To_Generate objects and generates the EE_Message objects, then persists (so its
339
	 * queued for sending).
340
	 * @param  EE_Message_To_Generate[]
341
	 * @return EE_Messages_Queue
342
	 */
343
	public function generate_and_queue_for_sending( $messages_to_generate ) {
344
		$this->_init_queue_and_generator();
345
		$this->_queue_for_generation_loop( $messages_to_generate );
346
		return $this->_generator->generate( true );
347
	}
348
349
350
351
352
353
	/**
354
	 * Generate for preview and execute right away.
355
	 *
356
	 * @param   EE_Message_To_Generate $message_to_generate
357
	 * @param   bool                   $test_send                Whether this is a test send or not.
358
	 * @return  EE_Messages_Queue | bool   false if unable to generate otherwise the generated queue.
359
	 */
360
	public function generate_for_preview( EE_Message_To_Generate $message_to_generate, $test_send = false ) {
361
		if ( ! $message_to_generate->valid() ) {
362
			EE_Error::add_error(
363
				__( 'Unable to generate preview because of invalid data', 'event_espresso' ),
364
				__FILE__,
365
				__FUNCTION__,
366
				__LINE__
367
			);
368
			return false;
369
		}
370
		//just make sure preview is set on the $message_to_generate (in case client forgot)
371
		$message_to_generate->set_preview( true );
372
		$this->_init_queue_and_generator();
373
		$this->queue_for_generation( $message_to_generate, $test_send );
374
		$generated_queue = $this->_generator->generate( false );
375
		if ( $generated_queue->execute( false ) ) {
376
			//the first queue item should be the preview
377
			$generated_queue->get_message_repository()->rewind();
378
			if ( ! $generated_queue->get_message_repository()->valid() ) {
379
				return $generated_queue;
380
			}
381
			return $generated_queue;
382
		} else {
383
			return false;
384
		}
385
	}
386
387
388
	/**
389
	 * This queues for sending.
390
	 * The messenger send now method is also verified to see if sending immediately is requested.
391
	 * otherwise its just saved to the queue.
392
	 * @param EE_Message_To_Generate $message_to_generate
393
	 * @return bool true or false for success.
394
	 */
395
	public function queue_for_sending( EE_Message_To_Generate $message_to_generate ) {
396
		if ( ! $message_to_generate->valid() ) {
397
			return false;
398
		}
399
		$this->_init_queue_and_generator();
400
		$message = $message_to_generate->get_EE_Message();
401
		$this->_queue->add( $message );
402
		if ( $message->send_now() ) {
403
			$this->_queue->execute( false );
404
		} else {
405
			$this->_queue->save();
406
		}
407
		return true;
408
	}
409
410
411
	/**
412
	 * This generates and sends from the given EE_Message_To_Generate class immediately.
413
	 * @param EE_Message_To_Generate $message_to_generate
414
	 * @return EE_Messages_Queue | null
415
	 */
416
	public function generate_and_send_now( EE_Message_To_Generate $message_to_generate ) {
417
		if ( ! $message_to_generate->valid() ) {
418
			return null;
419
		}
420
		// is there supposed to be a sending messenger for this message?
421
		if ( $message_to_generate instanceof EEI_Has_Sending_Messenger ) {
422
			// make sure it's valid, but if it's not,
423
			// then set the value of $sending_messenger to an EE_Error object
424
			// so that downstream code can easily see that things went wrong.
425
			$sending_messenger = $message_to_generate->sending_messenger() instanceof EE_messenger
426
				? $message_to_generate->sending_messenger()
427
				: new EE_Error(
428
					__(
429
						'There was a specific sending messenger requested for the send action, but it was either invalid or not active at time of sending.',
430
						'event_espresso'
431
					)
432
				);
433
		} else {
434
			$sending_messenger = null;
435
		}
436
437
		if ( $message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle ) {
438
			$this->_init_queue_and_generator();
439
			$this->_queue->add( $message_to_generate->get_EE_Message() );
440
			$this->_queue->execute( false, $sending_messenger );
441
			return $this->_queue;
442
		} elseif ( $message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete ) {
443
			$generated_queue = $this->generate_and_return( array( $message_to_generate ) );
444
			$generated_queue->execute( false, $sending_messenger );
445
			return $generated_queue;
446
		}
447
		return null;
448
	}
449
450
451
452
453
	/**
454
	 * Creates mtg objects for all active messengers and queues for generation.
455
	 * This method also calls the execute by priority method on the queue which will optionally kick off a new non-blocking
456
	 * request to complete the action if the priority for the message requires immediate action.
457
	 * @param string $message_type
458
	 * @param mixed  $data   The data being used for generation.
459
	 * @param bool   $persist   Whether to persist the queued messages to the db or not.
460
	 */
461
	public function generate_for_all_active_messengers( $message_type, $data, $persist = true ) {
462
		$messages_to_generate = $this->setup_mtgs_for_all_active_messengers( $message_type, $data );
463
		if ( $persist ) {
464
			$this->batch_queue_for_generation_and_persist( $messages_to_generate );
465
			$this->_queue->initiate_request_by_priority();
466
		} else {
467
			$this->batch_queue_for_generation_no_persist( $messages_to_generate );
468
		}
469
	}
470
471
472
473
474
	/**
475
	 * This simply loops through all active messengers and takes care of setting up the
476
	 * EE_Message_To_Generate objects.
477
	 * @param $message_type
478
	 * @param $data
479
	 *
480
	 * @return EE_Message_To_Generate[]
481
	 */
482
	public function setup_mtgs_for_all_active_messengers( $message_type, $data ) {
483
		$messages_to_generate = array();
484
		foreach ( $this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object  ) {
485
			$message_to_generate = new EE_Message_To_Generate( $messenger_slug, $message_type, $data );
486
			if ( $message_to_generate->valid() ) {
487
				$messages_to_generate[] = $message_to_generate;
488
			}
489
		}
490
		return $messages_to_generate;
491
	}
492
493
494
495
496
	/**
497
	 * This accepts an array of EE_Message::MSG_ID values and will use that to retrieve the objects from the database
498
	 * and send.
499
	 * @param array $message_ids
500
	 */
501
	public function setup_messages_from_ids_and_send( $message_ids ) {
502
		$this->_init_queue_and_generator();
503
		$messages = EEM_Message::instance()->get_all( array(
504
			array(
505
				'MSG_ID' => array( 'IN', $message_ids ),
506
				'STS_ID' => array(
507
					'IN',
508
					array_merge(
509
						EEM_Message::instance()->stati_indicating_sent(),
510
						array( EEM_Message::status_retry )
511
					),
512
				),
513
			),
514
		));
515
		//set the Messages to resend.
516
		foreach ( $messages as $message ) {
517
			if ( $message instanceof EE_Message ) {
518
				$message->set_STS_ID( EEM_Message::status_resend );
519
				$this->_queue->add( $message );
520
			}
521
		}
522
523
		$this->_queue->initiate_request_by_priority( 'send' );
524
	}
525
526
527
528
	/**
529
	 * This method checks for registration IDs in the request via the given key and creates the messages to generate
530
	 * objects from them, then returns the array of messages to generate objects.
531
	 * Note, this sets up registrations for the registration family of message types.
532
	 *
533
	 * @param string $registration_ids_key  This is used to indicate what represents the registration ids in the request.
534
	 *
535
	 * @return EE_Message_To_Generate[]
536
	 */
537
	public function setup_messages_to_generate_from_registration_ids_in_request( $registration_ids_key = '_REG_ID' ) {
538
		EE_Registry::instance()->load_core( 'Request_Handler' );
539
		EE_Registry::instance()->load_helper( 'MSG_Template' );
540
		$regs_to_send = array();
541
		$regIDs = EE_Registry::instance()->REQ->get( $registration_ids_key );
542
		if ( empty( $regIDs ) ) {
543
			EE_Error::add_error( __('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
544
			return false;
545
		}
546
547
		//make sure is an array
548
		$regIDs = is_array( $regIDs ) ? $regIDs : array( $regIDs );
549
550
		foreach( $regIDs as $regID ) {
551
			$reg = EEM_Registration::instance()->get_one_by_ID( $regID );
552 View Code Duplication
			if ( ! $reg instanceof EE_Registration ) {
553
				EE_Error::add_error( sprintf( __('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $regID ) );
554
				return false;
555
			}
556
			$regs_to_send[$reg->transaction_ID()][$reg->status_ID()][] = $reg;
557
		}
558
559
		$messages_to_generate = array();
560
561
		foreach ( $regs_to_send as $status_group ) {
562
			foreach ( $status_group as $status_id => $registrations ) {
563
			    $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($status_id);
564
			    if (! $message_type) {
565
			        continue;
566
                }
567
				$messages_to_generate = array_merge(
568
					$messages_to_generate,
569
					$this->setup_mtgs_for_all_active_messengers(
570
						$message_type,
571
						array( $registrations, $status_id )
572
					)
573
				);
574
			}
575
		}
576
577
		return $messages_to_generate;
578
	}
579
580
581
582
} //end class EE_Messages_Processor