Completed
Branch FET-10766-extract-activation-d... (a650cc)
by
unknown
87:01 queued 68:06
created
strategies/validation/EE_Email_Validation_Strategy.strategy.php 2 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -18,72 +18,72 @@
 block discarded – undo
18 18
 {
19 19
 
20 20
 
21
-    /**
22
-     * @param string               $validation_error_message
23
-     */
24
-    public function __construct($validation_error_message = '')
25
-    {
26
-        if (! $validation_error_message) {
27
-            $validation_error_message = esc_html__('Please enter a valid email address.', 'event_espresso');
28
-        }
29
-        parent::__construct($validation_error_message);
30
-    }
21
+	/**
22
+	 * @param string               $validation_error_message
23
+	 */
24
+	public function __construct($validation_error_message = '')
25
+	{
26
+		if (! $validation_error_message) {
27
+			$validation_error_message = esc_html__('Please enter a valid email address.', 'event_espresso');
28
+		}
29
+		parent::__construct($validation_error_message);
30
+	}
31 31
 
32 32
 
33 33
 
34
-    /**
35
-     * just checks the field isn't blank
36
-     *
37
-     * @param $normalized_value
38
-     * @return bool
39
-     * @throws InvalidArgumentException
40
-     * @throws InvalidInterfaceException
41
-     * @throws InvalidDataTypeException
42
-     * @throws EE_Validation_Error
43
-     */
44
-    public function validate($normalized_value)
45
-    {
46
-        if ($normalized_value && ! $this->_validate_email($normalized_value)) {
47
-            throw new EE_Validation_Error($this->get_validation_error_message(), 'required');
48
-        }
49
-        return true;
50
-    }
34
+	/**
35
+	 * just checks the field isn't blank
36
+	 *
37
+	 * @param $normalized_value
38
+	 * @return bool
39
+	 * @throws InvalidArgumentException
40
+	 * @throws InvalidInterfaceException
41
+	 * @throws InvalidDataTypeException
42
+	 * @throws EE_Validation_Error
43
+	 */
44
+	public function validate($normalized_value)
45
+	{
46
+		if ($normalized_value && ! $this->_validate_email($normalized_value)) {
47
+			throw new EE_Validation_Error($this->get_validation_error_message(), 'required');
48
+		}
49
+		return true;
50
+	}
51 51
 
52 52
 
53 53
 
54
-    /**
55
-     * @return array
56
-     */
57
-    public function get_jquery_validation_rule_array()
58
-    {
59
-        return array('email' => true, 'messages' => array('email' => $this->get_validation_error_message()));
60
-    }
54
+	/**
55
+	 * @return array
56
+	 */
57
+	public function get_jquery_validation_rule_array()
58
+	{
59
+		return array('email' => true, 'messages' => array('email' => $this->get_validation_error_message()));
60
+	}
61 61
 
62 62
 
63 63
 
64
-    /**
65
-     * Validate an email address.
66
-     * Provide email address (raw input)
67
-     *
68
-     * @param $email
69
-     * @return bool of whether the email is valid or not
70
-     * @throws InvalidArgumentException
71
-     * @throws InvalidInterfaceException
72
-     * @throws InvalidDataTypeException
73
-     * @throws EE_Validation_Error
74
-     */
75
-    private function _validate_email($email)
76
-    {
77
-        try {
78
-            EmailAddressFactory::create($email);
79
-        } catch (EmailValidationException $e) {
80
-            throw new EE_Validation_Error(
81
-                $e->getMessage(),
82
-                'invalid_email',
83
-                $this->_input,
84
-                $e
85
-            );
86
-        }
87
-        return true;
88
-    }
64
+	/**
65
+	 * Validate an email address.
66
+	 * Provide email address (raw input)
67
+	 *
68
+	 * @param $email
69
+	 * @return bool of whether the email is valid or not
70
+	 * @throws InvalidArgumentException
71
+	 * @throws InvalidInterfaceException
72
+	 * @throws InvalidDataTypeException
73
+	 * @throws EE_Validation_Error
74
+	 */
75
+	private function _validate_email($email)
76
+	{
77
+		try {
78
+			EmailAddressFactory::create($email);
79
+		} catch (EmailValidationException $e) {
80
+			throw new EE_Validation_Error(
81
+				$e->getMessage(),
82
+				'invalid_email',
83
+				$this->_input,
84
+				$e
85
+			);
86
+		}
87
+		return true;
88
+	}
89 89
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
      */
24 24
     public function __construct($validation_error_message = '')
25 25
     {
26
-        if (! $validation_error_message) {
26
+        if ( ! $validation_error_message) {
27 27
             $validation_error_message = esc_html__('Please enter a valid email address.', 'event_espresso');
28 28
         }
29 29
         parent::__construct($validation_error_message);
Please login to merge, or discard this patch.
core/domain/services/factories/EmailAddressFactory.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -23,21 +23,21 @@
 block discarded – undo
23 23
 class EmailAddressFactory implements FactoryInterface
24 24
 {
25 25
 
26
-    /**
27
-     * @param string $email_address
28
-     * @return EmailAddress
29
-     * @throws EmailValidationException
30
-     * @throws InvalidDataTypeException
31
-     * @throws InvalidInterfaceException
32
-     * @throws InvalidArgumentException
33
-     */
34
-    public static function create($email_address)
35
-    {
36
-        return LoaderFactory::getLoader()->getNew(
37
-            'EventEspresso\core\domain\values\EmailAddress',
38
-            array($email_address)
39
-        );
40
-    }
26
+	/**
27
+	 * @param string $email_address
28
+	 * @return EmailAddress
29
+	 * @throws EmailValidationException
30
+	 * @throws InvalidDataTypeException
31
+	 * @throws InvalidInterfaceException
32
+	 * @throws InvalidArgumentException
33
+	 */
34
+	public static function create($email_address)
35
+	{
36
+		return LoaderFactory::getLoader()->getNew(
37
+			'EventEspresso\core\domain\values\EmailAddress',
38
+			array($email_address)
39
+		);
40
+	}
41 41
 
42 42
 }
43 43
 // Location: core/domain/services/factories/EmailAddressFactory.php
Please login to merge, or discard this patch.
core/EE_Load_Espresso_Core.core.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\core\exceptions\InvalidInterfaceException;
4 4
 use EventEspresso\core\services\loaders\LoaderFactory;
5 5
 
6
-if (! defined('EVENT_ESPRESSO_VERSION')) {
6
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
7 7
     exit('No direct script access allowed');
8 8
 }
9 9
 
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      */
52 52
     public function __construct()
53 53
     {
54
-        espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php');
54
+        espresso_load_required('EventEspresso\core\Factory', EE_CORE.'Factory.php');
55 55
     }
56 56
 
57 57
 
@@ -105,9 +105,9 @@  discard block
 block discarded – undo
105 105
         $this->_load_class_tools();
106 106
         // load interfaces
107 107
         espresso_load_required('EEI_Payment_Method_Interfaces',
108
-            EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php');
108
+            EE_LIBRARIES.'payment_methods'.DS.'EEI_Payment_Method_Interfaces.php');
109 109
         // deprecated functions
110
-        espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
110
+        espresso_load_required('EE_Deprecated', EE_CORE.'EE_Deprecated.core.php');
111 111
         // WP cron jobs
112 112
         $loader->getShared('EE_Cron_Tasks');
113 113
         $loader->getShared('EE_Request_Handler');
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
      */
144 144
     public function dependency_map()
145 145
     {
146
-        if (! $this->dependency_map instanceof EE_Dependency_Map) {
146
+        if ( ! $this->dependency_map instanceof EE_Dependency_Map) {
147 147
             throw new EE_Error(
148 148
                 sprintf(
149 149
                     __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'),
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
      */
163 163
     public function registry()
164 164
     {
165
-        if (! $this->registry instanceof EE_Registry) {
165
+        if ( ! $this->registry instanceof EE_Registry) {
166 166
             throw new EE_Error(
167 167
                 sprintf(
168 168
                     __('Invalid EE_Registry: "%1$s"', 'event_espresso'),
@@ -180,14 +180,14 @@  discard block
 block discarded – undo
180 180
      */
181 181
     private function _load_dependency_map()
182 182
     {
183
-        if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) {
183
+        if ( ! is_readable(EE_CORE.'EE_Dependency_Map.core.php')) {
184 184
             EE_Error::add_error(
185 185
                 __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'),
186 186
                 __FILE__, __FUNCTION__, __LINE__
187 187
             );
188 188
             wp_die(EE_Error::get_notices());
189 189
         }
190
-        require_once(EE_CORE . 'EE_Dependency_Map.core.php');
190
+        require_once(EE_CORE.'EE_Dependency_Map.core.php');
191 191
         return EE_Dependency_Map::instance($this->request, $this->response);
192 192
     }
193 193
 
@@ -198,14 +198,14 @@  discard block
 block discarded – undo
198 198
      */
199 199
     private function _load_registry()
200 200
     {
201
-        if (! is_readable(EE_CORE . 'EE_Registry.core.php')) {
201
+        if ( ! is_readable(EE_CORE.'EE_Registry.core.php')) {
202 202
             EE_Error::add_error(
203 203
                 __('The EE_Registry core class could not be loaded.', 'event_espresso'),
204 204
                 __FILE__, __FUNCTION__, __LINE__
205 205
             );
206 206
             wp_die(EE_Error::get_notices());
207 207
         }
208
-        require_once(EE_CORE . 'EE_Registry.core.php');
208
+        require_once(EE_CORE.'EE_Registry.core.php');
209 209
         return EE_Registry::instance($this->dependency_map);
210 210
     }
211 211
 
@@ -216,13 +216,13 @@  discard block
 block discarded – undo
216 216
      */
217 217
     private function _load_class_tools()
218 218
     {
219
-        if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) {
219
+        if ( ! is_readable(EE_HELPERS.'EEH_Class_Tools.helper.php')) {
220 220
             EE_Error::add_error(
221 221
                 __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'),
222 222
                 __FILE__, __FUNCTION__, __LINE__
223 223
             );
224 224
         }
225
-        require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php');
225
+        require_once(EE_HELPERS.'EEH_Class_Tools.helper.php');
226 226
     }
227 227
 
228 228
 
Please login to merge, or discard this patch.
Indentation   +201 added lines, -201 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\services\loaders\LoaderFactory;
5 5
 
6 6
 if (! defined('EVENT_ESPRESSO_VERSION')) {
7
-    exit('No direct script access allowed');
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 
10 10
 
@@ -24,206 +24,206 @@  discard block
 block discarded – undo
24 24
 class EE_Load_Espresso_Core implements EEI_Request_Decorator, EEI_Request_Stack_Core_App
25 25
 {
26 26
 
27
-    /**
28
-     * @var EE_Request $request
29
-     */
30
-    protected $request;
31
-
32
-    /**
33
-     * @var EE_Response $response
34
-     */
35
-    protected $response;
36
-
37
-    /**
38
-     * @var EE_Dependency_Map $dependency_map
39
-     */
40
-    protected $dependency_map;
41
-
42
-    /**
43
-     * @var EE_Registry $registry
44
-     */
45
-    protected $registry;
46
-
47
-
48
-
49
-    /**
50
-     * EE_Load_Espresso_Core constructor
51
-     */
52
-    public function __construct()
53
-    {
54
-        espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php');
55
-    }
56
-
57
-
58
-
59
-    /**
60
-     * handle
61
-     * sets hooks for running rest of system
62
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
63
-     * starting EE Addons from any other point may lead to problems
64
-     *
65
-     * @param EE_Request  $request
66
-     * @param EE_Response $response
67
-     * @return EE_Response
68
-     * @throws EE_Error
69
-     * @throws InvalidDataTypeException
70
-     * @throws InvalidInterfaceException
71
-     * @throws InvalidArgumentException
72
-     */
73
-    public function handle_request(EE_Request $request, EE_Response $response)
74
-    {
75
-        $this->request = $request;
76
-        $this->response = $response;
77
-        // info about how to load classes required by other classes
78
-        $this->dependency_map = $this->_load_dependency_map();
79
-        // central repository for classes
80
-        $this->registry = $this->_load_registry();
81
-        do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading');
82
-        $loader = LoaderFactory::getLoader($this->registry);
83
-        $this->dependency_map->setLoader($loader);
84
-        // build DI container
85
-        // $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop();
86
-        // $OpenCoffeeShop->addRecipes();
87
-        // $CoffeeShop = $OpenCoffeeShop->CoffeeShop();
88
-        // workarounds for PHP < 5.3
89
-        $this->_load_class_tools();
90
-        // load interfaces
91
-        espresso_load_required('EEI_Payment_Method_Interfaces',
92
-            EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php');
93
-        // deprecated functions
94
-        espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
95
-        // WP cron jobs
96
-        $loader->getShared('EE_Cron_Tasks');
97
-        $loader->getShared('EE_Request_Handler');
98
-        $loader->getShared('EE_System');
99
-        return $this->response;
100
-    }
101
-
102
-
103
-
104
-    /**
105
-     * @return EE_Request
106
-     */
107
-    public function request()
108
-    {
109
-        return $this->request;
110
-    }
111
-
112
-
113
-
114
-    /**
115
-     * @return EE_Response
116
-     */
117
-    public function response()
118
-    {
119
-        return $this->response;
120
-    }
121
-
122
-
123
-
124
-    /**
125
-     * @return EE_Dependency_Map
126
-     * @throws EE_Error
127
-     */
128
-    public function dependency_map()
129
-    {
130
-        if (! $this->dependency_map instanceof EE_Dependency_Map) {
131
-            throw new EE_Error(
132
-                sprintf(
133
-                    __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'),
134
-                    print_r($this->dependency_map, true)
135
-                )
136
-            );
137
-        }
138
-        return $this->dependency_map;
139
-    }
140
-
141
-
142
-
143
-    /**
144
-     * @return EE_Registry
145
-     * @throws EE_Error
146
-     */
147
-    public function registry()
148
-    {
149
-        if (! $this->registry instanceof EE_Registry) {
150
-            throw new EE_Error(
151
-                sprintf(
152
-                    __('Invalid EE_Registry: "%1$s"', 'event_espresso'),
153
-                    print_r($this->registry, true)
154
-                )
155
-            );
156
-        }
157
-        return $this->registry;
158
-    }
159
-
160
-
161
-
162
-    /**
163
-     * @return EE_Dependency_Map
164
-     */
165
-    private function _load_dependency_map()
166
-    {
167
-        if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) {
168
-            EE_Error::add_error(
169
-                __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'),
170
-                __FILE__, __FUNCTION__, __LINE__
171
-            );
172
-            wp_die(EE_Error::get_notices());
173
-        }
174
-        require_once(EE_CORE . 'EE_Dependency_Map.core.php');
175
-        return EE_Dependency_Map::instance($this->request, $this->response);
176
-    }
177
-
178
-
179
-
180
-    /**
181
-     * @return EE_Registry
182
-     */
183
-    private function _load_registry()
184
-    {
185
-        if (! is_readable(EE_CORE . 'EE_Registry.core.php')) {
186
-            EE_Error::add_error(
187
-                __('The EE_Registry core class could not be loaded.', 'event_espresso'),
188
-                __FILE__, __FUNCTION__, __LINE__
189
-            );
190
-            wp_die(EE_Error::get_notices());
191
-        }
192
-        require_once(EE_CORE . 'EE_Registry.core.php');
193
-        return EE_Registry::instance($this->dependency_map);
194
-    }
195
-
196
-
197
-
198
-    /**
199
-     * @return void
200
-     */
201
-    private function _load_class_tools()
202
-    {
203
-        if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) {
204
-            EE_Error::add_error(
205
-                __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'),
206
-                __FILE__, __FUNCTION__, __LINE__
207
-            );
208
-        }
209
-        require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php');
210
-    }
211
-
212
-
213
-
214
-    /**
215
-     * called after the request stack has been fully processed
216
-     * if any of the middleware apps has requested the plugin be deactivated, then we do that now
217
-     *
218
-     * @param EE_Request  $request
219
-     * @param EE_Response $response
220
-     */
221
-    public function handle_response(EE_Request $request, EE_Response $response)
222
-    {
223
-        if ($response->plugin_deactivated()) {
224
-            espresso_deactivate_plugin(EE_PLUGIN_BASENAME);
225
-        }
226
-    }
27
+	/**
28
+	 * @var EE_Request $request
29
+	 */
30
+	protected $request;
31
+
32
+	/**
33
+	 * @var EE_Response $response
34
+	 */
35
+	protected $response;
36
+
37
+	/**
38
+	 * @var EE_Dependency_Map $dependency_map
39
+	 */
40
+	protected $dependency_map;
41
+
42
+	/**
43
+	 * @var EE_Registry $registry
44
+	 */
45
+	protected $registry;
46
+
47
+
48
+
49
+	/**
50
+	 * EE_Load_Espresso_Core constructor
51
+	 */
52
+	public function __construct()
53
+	{
54
+		espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php');
55
+	}
56
+
57
+
58
+
59
+	/**
60
+	 * handle
61
+	 * sets hooks for running rest of system
62
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
63
+	 * starting EE Addons from any other point may lead to problems
64
+	 *
65
+	 * @param EE_Request  $request
66
+	 * @param EE_Response $response
67
+	 * @return EE_Response
68
+	 * @throws EE_Error
69
+	 * @throws InvalidDataTypeException
70
+	 * @throws InvalidInterfaceException
71
+	 * @throws InvalidArgumentException
72
+	 */
73
+	public function handle_request(EE_Request $request, EE_Response $response)
74
+	{
75
+		$this->request = $request;
76
+		$this->response = $response;
77
+		// info about how to load classes required by other classes
78
+		$this->dependency_map = $this->_load_dependency_map();
79
+		// central repository for classes
80
+		$this->registry = $this->_load_registry();
81
+		do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading');
82
+		$loader = LoaderFactory::getLoader($this->registry);
83
+		$this->dependency_map->setLoader($loader);
84
+		// build DI container
85
+		// $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop();
86
+		// $OpenCoffeeShop->addRecipes();
87
+		// $CoffeeShop = $OpenCoffeeShop->CoffeeShop();
88
+		// workarounds for PHP < 5.3
89
+		$this->_load_class_tools();
90
+		// load interfaces
91
+		espresso_load_required('EEI_Payment_Method_Interfaces',
92
+			EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php');
93
+		// deprecated functions
94
+		espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php');
95
+		// WP cron jobs
96
+		$loader->getShared('EE_Cron_Tasks');
97
+		$loader->getShared('EE_Request_Handler');
98
+		$loader->getShared('EE_System');
99
+		return $this->response;
100
+	}
101
+
102
+
103
+
104
+	/**
105
+	 * @return EE_Request
106
+	 */
107
+	public function request()
108
+	{
109
+		return $this->request;
110
+	}
111
+
112
+
113
+
114
+	/**
115
+	 * @return EE_Response
116
+	 */
117
+	public function response()
118
+	{
119
+		return $this->response;
120
+	}
121
+
122
+
123
+
124
+	/**
125
+	 * @return EE_Dependency_Map
126
+	 * @throws EE_Error
127
+	 */
128
+	public function dependency_map()
129
+	{
130
+		if (! $this->dependency_map instanceof EE_Dependency_Map) {
131
+			throw new EE_Error(
132
+				sprintf(
133
+					__('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'),
134
+					print_r($this->dependency_map, true)
135
+				)
136
+			);
137
+		}
138
+		return $this->dependency_map;
139
+	}
140
+
141
+
142
+
143
+	/**
144
+	 * @return EE_Registry
145
+	 * @throws EE_Error
146
+	 */
147
+	public function registry()
148
+	{
149
+		if (! $this->registry instanceof EE_Registry) {
150
+			throw new EE_Error(
151
+				sprintf(
152
+					__('Invalid EE_Registry: "%1$s"', 'event_espresso'),
153
+					print_r($this->registry, true)
154
+				)
155
+			);
156
+		}
157
+		return $this->registry;
158
+	}
159
+
160
+
161
+
162
+	/**
163
+	 * @return EE_Dependency_Map
164
+	 */
165
+	private function _load_dependency_map()
166
+	{
167
+		if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) {
168
+			EE_Error::add_error(
169
+				__('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'),
170
+				__FILE__, __FUNCTION__, __LINE__
171
+			);
172
+			wp_die(EE_Error::get_notices());
173
+		}
174
+		require_once(EE_CORE . 'EE_Dependency_Map.core.php');
175
+		return EE_Dependency_Map::instance($this->request, $this->response);
176
+	}
177
+
178
+
179
+
180
+	/**
181
+	 * @return EE_Registry
182
+	 */
183
+	private function _load_registry()
184
+	{
185
+		if (! is_readable(EE_CORE . 'EE_Registry.core.php')) {
186
+			EE_Error::add_error(
187
+				__('The EE_Registry core class could not be loaded.', 'event_espresso'),
188
+				__FILE__, __FUNCTION__, __LINE__
189
+			);
190
+			wp_die(EE_Error::get_notices());
191
+		}
192
+		require_once(EE_CORE . 'EE_Registry.core.php');
193
+		return EE_Registry::instance($this->dependency_map);
194
+	}
195
+
196
+
197
+
198
+	/**
199
+	 * @return void
200
+	 */
201
+	private function _load_class_tools()
202
+	{
203
+		if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) {
204
+			EE_Error::add_error(
205
+				__('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'),
206
+				__FILE__, __FUNCTION__, __LINE__
207
+			);
208
+		}
209
+		require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php');
210
+	}
211
+
212
+
213
+
214
+	/**
215
+	 * called after the request stack has been fully processed
216
+	 * if any of the middleware apps has requested the plugin be deactivated, then we do that now
217
+	 *
218
+	 * @param EE_Request  $request
219
+	 * @param EE_Response $response
220
+	 */
221
+	public function handle_response(EE_Request $request, EE_Response $response)
222
+	{
223
+		if ($response->plugin_deactivated()) {
224
+			espresso_deactivate_plugin(EE_PLUGIN_BASENAME);
225
+		}
226
+	}
227 227
 
228 228
 
229 229
 
Please login to merge, or discard this patch.
core/db_models/EEM_Transaction.model.php 2 patches
Indentation   +363 added lines, -363 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 require_once(EE_MODELS . 'EEM_Base.model.php');
7 7
 
@@ -17,193 +17,193 @@  discard block
 block discarded – undo
17 17
 class EEM_Transaction extends EEM_Base
18 18
 {
19 19
 
20
-    // private instance of the Transaction object
21
-    protected static $_instance;
22
-
23
-    /**
24
-     * Status ID(STS_ID on esp_status table) to indicate the transaction is complete,
25
-     * but payment is pending. This is the state for transactions where payment is promised
26
-     * from an offline gateway.
27
-     */
28
-    //	const open_status_code = 'TPN';
29
-
30
-    /**
31
-     * Status ID(STS_ID on esp_status table) to indicate the transaction failed,
32
-     * either due to a technical reason (server or computer crash during registration),
33
-     *  or some other reason that prevent the collection of any useful contact information from any of the registrants
34
-     */
35
-    const failed_status_code = 'TFL';
36
-
37
-    /**
38
-     * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned,
39
-     * either due to a technical reason (server or computer crash during registration),
40
-     * or due to an abandoned cart after registrant chose not to complete the registration process
41
-     * HOWEVER...
42
-     * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one
43
-     * registrant
44
-     */
45
-    const abandoned_status_code = 'TAB';
46
-
47
-    /**
48
-     * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction,
49
-     * meaning that monies are still owing: TXN_paid < TXN_total
50
-     */
51
-    const incomplete_status_code = 'TIN';
52
-
53
-    /**
54
-     * Status ID (STS_ID on esp_status table) to indicate a complete transaction.
55
-     * meaning that NO monies are owing: TXN_paid == TXN_total
56
-     */
57
-    const complete_status_code = 'TCM';
58
-
59
-    /**
60
-     *  Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid.
61
-     *  This is the same as complete, but site admins actually owe clients the moneys!  TXN_paid > TXN_total
62
-     */
63
-    const overpaid_status_code = 'TOP';
64
-
65
-
66
-    /**
67
-     *    private constructor to prevent direct creation
68
-     *
69
-     * @Constructor
70
-     * @access protected
71
-     *
72
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
73
-     *                         incoming timezone data that gets saved). Note this just sends the timezone info to the
74
-     *                         date time model field objects.  Default is NULL (and will be assumed using the set
75
-     *                         timezone in the 'timezone_string' wp option)
76
-     *
77
-     * @return EEM_Transaction
78
-     * @throws \EE_Error
79
-     */
80
-    protected function __construct($timezone)
81
-    {
82
-        $this->singular_item = __('Transaction', 'event_espresso');
83
-        $this->plural_item   = __('Transactions', 'event_espresso');
84
-
85
-        $this->_tables                 = array(
86
-            'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID')
87
-        );
88
-        $this->_fields                 = array(
89
-            'TransactionTable' => array(
90
-                'TXN_ID'           => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')),
91
-                'TXN_timestamp'    => new EE_Datetime_Field('TXN_timestamp',
92
-                    __('date when transaction was created', 'event_espresso'), false, EE_Datetime_Field::now,
93
-                    $timezone),
94
-                'TXN_total'        => new EE_Money_Field('TXN_total',
95
-                    __('Total value of Transaction', 'event_espresso'), false, 0),
96
-                'TXN_paid'         => new EE_Money_Field('TXN_paid',
97
-                    __('Amount paid towards transaction to date', 'event_espresso'), false, 0),
98
-                'STS_ID'           => new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'),
99
-                    false, EEM_Transaction::failed_status_code, 'Status'),
100
-                'TXN_session_data' => new EE_Serialized_Text_Field('TXN_session_data',
101
-                    __('Serialized session data', 'event_espresso'), true, ''),
102
-                'TXN_hash_salt'    => new EE_Plain_Text_Field('TXN_hash_salt',
103
-                    __('Transaction Hash Salt', 'event_espresso'), true, ''),
104
-                'PMD_ID'           => new EE_Foreign_Key_Int_Field('PMD_ID',
105
-                    __("Last Used Payment Method", 'event_espresso'), true, null, 'Payment_Method'),
106
-                'TXN_reg_steps'    => new EE_Serialized_Text_Field('TXN_reg_steps',
107
-                    __('Registration Steps', 'event_espresso'), false, array()),
108
-            )
109
-        );
110
-        $this->_model_relations        = array(
111
-            'Registration'   => new EE_Has_Many_Relation(),
112
-            'Payment'        => new EE_Has_Many_Relation(),
113
-            'Status'         => new EE_Belongs_To_Relation(),
114
-            'Line_Item'      => new EE_Has_Many_Relation(false),
115
-            //you can delete a transaction without needing to delete its line items
116
-            'Payment_Method' => new EE_Belongs_To_Relation(),
117
-            'Message'        => new EE_Has_Many_Relation()
118
-        );
119
-        $this->_model_chain_to_wp_user = 'Registration.Event';
120
-        parent::__construct($timezone);
121
-
122
-    }
123
-
124
-
125
-    /**
126
-     *    txn_status_array
127
-     * get list of transaction statuses
128
-     *
129
-     * @access public
130
-     * @return array
131
-     */
132
-    public static function txn_status_array()
133
-    {
134
-        return apply_filters(
135
-            'FHEE__EEM_Transaction__txn_status_array',
136
-            array(
137
-                EEM_Transaction::overpaid_status_code,
138
-                EEM_Transaction::complete_status_code,
139
-                EEM_Transaction::incomplete_status_code,
140
-                EEM_Transaction::abandoned_status_code,
141
-                EEM_Transaction::failed_status_code,
142
-            )
143
-        );
144
-    }
145
-
146
-    /**
147
-     *        get the revenue per day  for the Transaction Admin page Reports Tab
148
-     *
149
-     * @access        public
150
-     *
151
-     * @param string $period
152
-     *
153
-     * @return \stdClass[]
154
-     */
155
-    public function get_revenue_per_day_report($period = '-1 month')
156
-    {
157
-        $sql_date = $this->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', strtotime($period)),
158
-            'Y-m-d H:i:s', 'UTC');
159
-
160
-        $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp');
161
-
162
-        return $this->_get_all_wpdb_results(
163
-            array(
164
-                array(
165
-                    'TXN_timestamp' => array('>=', $sql_date)
166
-                ),
167
-                'group_by' => 'txnDate',
168
-                'order_by' => array('TXN_timestamp' => 'ASC')
169
-            ),
170
-            OBJECT,
171
-            array(
172
-                'txnDate' => array('DATE(' . $query_interval . ')', '%s'),
173
-                'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d')
174
-            )
175
-        );
176
-    }
177
-
178
-
179
-    /**
180
-     *        get the revenue per event  for the Transaction Admin page Reports Tab
181
-     *
182
-     * @access        public
183
-     *
184
-     * @param string $period
185
-     *
186
-     * @throws \EE_Error
187
-     * @return mixed
188
-     */
189
-    public function get_revenue_per_event_report($period = '-1 month')
190
-    {
191
-        global $wpdb;
192
-        $transaction_table          = $wpdb->prefix . 'esp_transaction';
193
-        $registration_table         = $wpdb->prefix . 'esp_registration';
194
-        $registration_payment_table = $wpdb->prefix . 'esp_registration_payment';
195
-        $event_table                = $wpdb->posts;
196
-        $payment_table              = $wpdb->prefix . 'esp_payment';
197
-        $sql_date                   = date('Y-m-d H:i:s', strtotime($period));
198
-        $approved_payment_status    = EEM_Payment::status_id_approved;
199
-        $extra_event_on_join        = '';
200
-        //exclude events not authored by user if permissions in effect
201
-        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
202
-            $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id();
203
-        }
204
-
205
-        return $wpdb->get_results(
206
-            "SELECT
20
+	// private instance of the Transaction object
21
+	protected static $_instance;
22
+
23
+	/**
24
+	 * Status ID(STS_ID on esp_status table) to indicate the transaction is complete,
25
+	 * but payment is pending. This is the state for transactions where payment is promised
26
+	 * from an offline gateway.
27
+	 */
28
+	//	const open_status_code = 'TPN';
29
+
30
+	/**
31
+	 * Status ID(STS_ID on esp_status table) to indicate the transaction failed,
32
+	 * either due to a technical reason (server or computer crash during registration),
33
+	 *  or some other reason that prevent the collection of any useful contact information from any of the registrants
34
+	 */
35
+	const failed_status_code = 'TFL';
36
+
37
+	/**
38
+	 * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned,
39
+	 * either due to a technical reason (server or computer crash during registration),
40
+	 * or due to an abandoned cart after registrant chose not to complete the registration process
41
+	 * HOWEVER...
42
+	 * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one
43
+	 * registrant
44
+	 */
45
+	const abandoned_status_code = 'TAB';
46
+
47
+	/**
48
+	 * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction,
49
+	 * meaning that monies are still owing: TXN_paid < TXN_total
50
+	 */
51
+	const incomplete_status_code = 'TIN';
52
+
53
+	/**
54
+	 * Status ID (STS_ID on esp_status table) to indicate a complete transaction.
55
+	 * meaning that NO monies are owing: TXN_paid == TXN_total
56
+	 */
57
+	const complete_status_code = 'TCM';
58
+
59
+	/**
60
+	 *  Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid.
61
+	 *  This is the same as complete, but site admins actually owe clients the moneys!  TXN_paid > TXN_total
62
+	 */
63
+	const overpaid_status_code = 'TOP';
64
+
65
+
66
+	/**
67
+	 *    private constructor to prevent direct creation
68
+	 *
69
+	 * @Constructor
70
+	 * @access protected
71
+	 *
72
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any
73
+	 *                         incoming timezone data that gets saved). Note this just sends the timezone info to the
74
+	 *                         date time model field objects.  Default is NULL (and will be assumed using the set
75
+	 *                         timezone in the 'timezone_string' wp option)
76
+	 *
77
+	 * @return EEM_Transaction
78
+	 * @throws \EE_Error
79
+	 */
80
+	protected function __construct($timezone)
81
+	{
82
+		$this->singular_item = __('Transaction', 'event_espresso');
83
+		$this->plural_item   = __('Transactions', 'event_espresso');
84
+
85
+		$this->_tables                 = array(
86
+			'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID')
87
+		);
88
+		$this->_fields                 = array(
89
+			'TransactionTable' => array(
90
+				'TXN_ID'           => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')),
91
+				'TXN_timestamp'    => new EE_Datetime_Field('TXN_timestamp',
92
+					__('date when transaction was created', 'event_espresso'), false, EE_Datetime_Field::now,
93
+					$timezone),
94
+				'TXN_total'        => new EE_Money_Field('TXN_total',
95
+					__('Total value of Transaction', 'event_espresso'), false, 0),
96
+				'TXN_paid'         => new EE_Money_Field('TXN_paid',
97
+					__('Amount paid towards transaction to date', 'event_espresso'), false, 0),
98
+				'STS_ID'           => new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'),
99
+					false, EEM_Transaction::failed_status_code, 'Status'),
100
+				'TXN_session_data' => new EE_Serialized_Text_Field('TXN_session_data',
101
+					__('Serialized session data', 'event_espresso'), true, ''),
102
+				'TXN_hash_salt'    => new EE_Plain_Text_Field('TXN_hash_salt',
103
+					__('Transaction Hash Salt', 'event_espresso'), true, ''),
104
+				'PMD_ID'           => new EE_Foreign_Key_Int_Field('PMD_ID',
105
+					__("Last Used Payment Method", 'event_espresso'), true, null, 'Payment_Method'),
106
+				'TXN_reg_steps'    => new EE_Serialized_Text_Field('TXN_reg_steps',
107
+					__('Registration Steps', 'event_espresso'), false, array()),
108
+			)
109
+		);
110
+		$this->_model_relations        = array(
111
+			'Registration'   => new EE_Has_Many_Relation(),
112
+			'Payment'        => new EE_Has_Many_Relation(),
113
+			'Status'         => new EE_Belongs_To_Relation(),
114
+			'Line_Item'      => new EE_Has_Many_Relation(false),
115
+			//you can delete a transaction without needing to delete its line items
116
+			'Payment_Method' => new EE_Belongs_To_Relation(),
117
+			'Message'        => new EE_Has_Many_Relation()
118
+		);
119
+		$this->_model_chain_to_wp_user = 'Registration.Event';
120
+		parent::__construct($timezone);
121
+
122
+	}
123
+
124
+
125
+	/**
126
+	 *    txn_status_array
127
+	 * get list of transaction statuses
128
+	 *
129
+	 * @access public
130
+	 * @return array
131
+	 */
132
+	public static function txn_status_array()
133
+	{
134
+		return apply_filters(
135
+			'FHEE__EEM_Transaction__txn_status_array',
136
+			array(
137
+				EEM_Transaction::overpaid_status_code,
138
+				EEM_Transaction::complete_status_code,
139
+				EEM_Transaction::incomplete_status_code,
140
+				EEM_Transaction::abandoned_status_code,
141
+				EEM_Transaction::failed_status_code,
142
+			)
143
+		);
144
+	}
145
+
146
+	/**
147
+	 *        get the revenue per day  for the Transaction Admin page Reports Tab
148
+	 *
149
+	 * @access        public
150
+	 *
151
+	 * @param string $period
152
+	 *
153
+	 * @return \stdClass[]
154
+	 */
155
+	public function get_revenue_per_day_report($period = '-1 month')
156
+	{
157
+		$sql_date = $this->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', strtotime($period)),
158
+			'Y-m-d H:i:s', 'UTC');
159
+
160
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp');
161
+
162
+		return $this->_get_all_wpdb_results(
163
+			array(
164
+				array(
165
+					'TXN_timestamp' => array('>=', $sql_date)
166
+				),
167
+				'group_by' => 'txnDate',
168
+				'order_by' => array('TXN_timestamp' => 'ASC')
169
+			),
170
+			OBJECT,
171
+			array(
172
+				'txnDate' => array('DATE(' . $query_interval . ')', '%s'),
173
+				'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d')
174
+			)
175
+		);
176
+	}
177
+
178
+
179
+	/**
180
+	 *        get the revenue per event  for the Transaction Admin page Reports Tab
181
+	 *
182
+	 * @access        public
183
+	 *
184
+	 * @param string $period
185
+	 *
186
+	 * @throws \EE_Error
187
+	 * @return mixed
188
+	 */
189
+	public function get_revenue_per_event_report($period = '-1 month')
190
+	{
191
+		global $wpdb;
192
+		$transaction_table          = $wpdb->prefix . 'esp_transaction';
193
+		$registration_table         = $wpdb->prefix . 'esp_registration';
194
+		$registration_payment_table = $wpdb->prefix . 'esp_registration_payment';
195
+		$event_table                = $wpdb->posts;
196
+		$payment_table              = $wpdb->prefix . 'esp_payment';
197
+		$sql_date                   = date('Y-m-d H:i:s', strtotime($period));
198
+		$approved_payment_status    = EEM_Payment::status_id_approved;
199
+		$extra_event_on_join        = '';
200
+		//exclude events not authored by user if permissions in effect
201
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
202
+			$extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id();
203
+		}
204
+
205
+		return $wpdb->get_results(
206
+			"SELECT
207 207
 			Transaction_Event.event_name AS event_name,
208 208
 			SUM(Transaction_Event.paid) AS revenue
209 209
 			FROM
@@ -230,185 +230,185 @@  discard block
 block discarded – undo
230 230
 					$extra_event_on_join
231 231
 				) AS Transaction_Event
232 232
 			GROUP BY event_name",
233
-            OBJECT
234
-        );
235
-    }
236
-
237
-
238
-    /**
239
-     * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the
240
-     * $_REQUEST global variable. Either way, tries to find the current transaction (through
241
-     * the registration pointed to by reg_url_link), if not returns null
242
-     *
243
-     * @param string $reg_url_link
244
-     *
245
-     * @return EE_Transaction
246
-     */
247
-    public function get_transaction_from_reg_url_link($reg_url_link = '')
248
-    {
249
-        return $this->get_one(array(
250
-            array(
251
-                'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get('e_reg_url_link',
252
-                    '')
253
-            )
254
-        ));
255
-    }
256
-
257
-
258
-    /**
259
-     * Updates the provided EE_Transaction with all the applicable payments
260
-     * (or fetch the EE_Transaction from its ID)
261
-     *
262
-     * @deprecated
263
-     *
264
-     * @param EE_Transaction|int $transaction_obj_or_id
265
-     * @param boolean            $save_txn whether or not to save the transaction during this function call
266
-     *
267
-     * @return boolean
268
-     * @throws \EE_Error
269
-     */
270
-    public function update_based_on_payments($transaction_obj_or_id, $save_txn = true)
271
-    {
272
-        EE_Error::doing_it_wrong(
273
-            __CLASS__ . '::' . __FUNCTION__,
274
-            sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
275
-                'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'),
276
-            '4.6.0'
277
-        );
278
-        /** @type EE_Transaction_Processor $transaction_processor */
279
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
280
-
281
-        return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
282
-            $this->ensure_is_obj($transaction_obj_or_id)
283
-        );
284
-    }
285
-
286
-    /**
287
-     * Deletes "junk" transactions that were probably added by bots. There might be TONS
288
-     * of these, so we are very careful to NOT select (which the models do even when deleting),
289
-     * and so we only use wpdb directly and only do minimal joins.
290
-     * Transactions are considered "junk" if they're failed for longer than a week.
291
-     * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on
292
-     * it, it's probably not junk (regardless of what status it has).
293
-     * The downside to this approach is that is addons are listening for object deletions
294
-     * on EEM_Base::delete() they won't be notified of this.  However, there is an action that plugins can hook into
295
-     * to catch these types of deletions.
296
-     *
297
-     * @global WPDB $wpdb
298
-     * @return mixed
299
-     */
300
-    public function delete_junk_transactions()
301
-    {
302
-        /** @type WPDB $wpdb */
303
-        global $wpdb;
304
-        $deleted             = false;
305
-        $time_to_leave_alone = apply_filters(
306
-            'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone'
307
-            , WEEK_IN_SECONDS
308
-        );
309
-
310
-
311
-        /**
312
-         * This allows code to filter the query arguments used for retrieving the transaction IDs to delete.
313
-         * Useful for plugins that want to exclude transactions matching certain query parameters.
314
-         * The query parameters should be in the format accepted by the EEM_Base model queries.
315
-         */
316
-        $ids_query = apply_filters(
317
-            'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args',
318
-            array(
319
-                0 => array(
320
-                    'STS_ID'        => EEM_Transaction::failed_status_code,
321
-                    'Payment.PAY_ID' => array( 'IS NULL' ),
322
-                    'TXN_timestamp' => array('<', time() - $time_to_leave_alone)
323
-                )
324
-            ),
325
-            $time_to_leave_alone
326
-        );
327
-
328
-
329
-        /**
330
-         * This filter is for when code needs to filter the list of transaction ids that represent transactions
331
-         * about to be deleted based on some other criteria that isn't easily done via the query args filter.
332
-         */
333
-        $txn_ids = apply_filters(
334
-            'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete',
335
-            EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'),
336
-            $time_to_leave_alone
337
-        );
338
-        //now that we have the ids to delete
339
-        if (! empty($txn_ids) && is_array($txn_ids)) {
340
-            // first, make sure these TXN's are removed the "ee_locked_transactions" array
341
-            EEM_Transaction::unset_locked_transactions($txn_ids);
342
-            // let's get deletin'...
343
-            // Why no wpdb->prepare?  Because the data is trusted.
344
-            // We got the ids from the original query to get them FROM
345
-            // the db (which is sanitized) so no need to prepare them again.
346
-            $query   = '
233
+			OBJECT
234
+		);
235
+	}
236
+
237
+
238
+	/**
239
+	 * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the
240
+	 * $_REQUEST global variable. Either way, tries to find the current transaction (through
241
+	 * the registration pointed to by reg_url_link), if not returns null
242
+	 *
243
+	 * @param string $reg_url_link
244
+	 *
245
+	 * @return EE_Transaction
246
+	 */
247
+	public function get_transaction_from_reg_url_link($reg_url_link = '')
248
+	{
249
+		return $this->get_one(array(
250
+			array(
251
+				'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get('e_reg_url_link',
252
+					'')
253
+			)
254
+		));
255
+	}
256
+
257
+
258
+	/**
259
+	 * Updates the provided EE_Transaction with all the applicable payments
260
+	 * (or fetch the EE_Transaction from its ID)
261
+	 *
262
+	 * @deprecated
263
+	 *
264
+	 * @param EE_Transaction|int $transaction_obj_or_id
265
+	 * @param boolean            $save_txn whether or not to save the transaction during this function call
266
+	 *
267
+	 * @return boolean
268
+	 * @throws \EE_Error
269
+	 */
270
+	public function update_based_on_payments($transaction_obj_or_id, $save_txn = true)
271
+	{
272
+		EE_Error::doing_it_wrong(
273
+			__CLASS__ . '::' . __FUNCTION__,
274
+			sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
275
+				'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'),
276
+			'4.6.0'
277
+		);
278
+		/** @type EE_Transaction_Processor $transaction_processor */
279
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
280
+
281
+		return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
282
+			$this->ensure_is_obj($transaction_obj_or_id)
283
+		);
284
+	}
285
+
286
+	/**
287
+	 * Deletes "junk" transactions that were probably added by bots. There might be TONS
288
+	 * of these, so we are very careful to NOT select (which the models do even when deleting),
289
+	 * and so we only use wpdb directly and only do minimal joins.
290
+	 * Transactions are considered "junk" if they're failed for longer than a week.
291
+	 * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on
292
+	 * it, it's probably not junk (regardless of what status it has).
293
+	 * The downside to this approach is that is addons are listening for object deletions
294
+	 * on EEM_Base::delete() they won't be notified of this.  However, there is an action that plugins can hook into
295
+	 * to catch these types of deletions.
296
+	 *
297
+	 * @global WPDB $wpdb
298
+	 * @return mixed
299
+	 */
300
+	public function delete_junk_transactions()
301
+	{
302
+		/** @type WPDB $wpdb */
303
+		global $wpdb;
304
+		$deleted             = false;
305
+		$time_to_leave_alone = apply_filters(
306
+			'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone'
307
+			, WEEK_IN_SECONDS
308
+		);
309
+
310
+
311
+		/**
312
+		 * This allows code to filter the query arguments used for retrieving the transaction IDs to delete.
313
+		 * Useful for plugins that want to exclude transactions matching certain query parameters.
314
+		 * The query parameters should be in the format accepted by the EEM_Base model queries.
315
+		 */
316
+		$ids_query = apply_filters(
317
+			'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args',
318
+			array(
319
+				0 => array(
320
+					'STS_ID'        => EEM_Transaction::failed_status_code,
321
+					'Payment.PAY_ID' => array( 'IS NULL' ),
322
+					'TXN_timestamp' => array('<', time() - $time_to_leave_alone)
323
+				)
324
+			),
325
+			$time_to_leave_alone
326
+		);
327
+
328
+
329
+		/**
330
+		 * This filter is for when code needs to filter the list of transaction ids that represent transactions
331
+		 * about to be deleted based on some other criteria that isn't easily done via the query args filter.
332
+		 */
333
+		$txn_ids = apply_filters(
334
+			'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete',
335
+			EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'),
336
+			$time_to_leave_alone
337
+		);
338
+		//now that we have the ids to delete
339
+		if (! empty($txn_ids) && is_array($txn_ids)) {
340
+			// first, make sure these TXN's are removed the "ee_locked_transactions" array
341
+			EEM_Transaction::unset_locked_transactions($txn_ids);
342
+			// let's get deletin'...
343
+			// Why no wpdb->prepare?  Because the data is trusted.
344
+			// We got the ids from the original query to get them FROM
345
+			// the db (which is sanitized) so no need to prepare them again.
346
+			$query   = '
347 347
 				DELETE
348 348
 				FROM ' . $this->table() . '
349 349
 				WHERE
350 350
 					TXN_ID IN ( ' . implode(",", $txn_ids) . ')';
351
-            $deleted = $wpdb->query($query);
352
-        }
353
-        if ($deleted) {
354
-            /**
355
-             * Allows code to do something after the transactions have been deleted.
356
-             */
357
-            do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids);
358
-        }
359
-
360
-        return $deleted;
361
-    }
362
-
363
-
364
-    /**
365
-     * @param array $transaction_IDs
366
-     *
367
-     * @return bool
368
-     */
369
-    public static function unset_locked_transactions(array $transaction_IDs)
370
-    {
371
-        $locked_transactions = get_option('ee_locked_transactions', array());
372
-        $update              = false;
373
-        foreach ($transaction_IDs as $TXN_ID) {
374
-            if (isset($locked_transactions[$TXN_ID])) {
375
-                unset($locked_transactions[$TXN_ID]);
376
-                $update = true;
377
-            }
378
-        }
379
-        if ($update) {
380
-            update_option('ee_locked_transactions', $locked_transactions);
381
-        }
382
-
383
-        return $update;
384
-    }
385
-
386
-
387
-
388
-    /**
389
-     * returns an array of EE_Transaction objects whose timestamp is less than
390
-     * the current time minus the session lifespan, which defaults to 60 minutes
391
-     *
392
-     * @return EE_Base_Class[]|EE_Transaction[]
393
-     * @throws \EE_Error
394
-     */
395
-    public function get_transactions_in_progress()
396
-    {
397
-        return $this->get_all(
398
-            array(
399
-                array(
400
-                    'TXN_timestamp' => array(
401
-                        '>',
402
-                        time() - EE_Registry::instance()->SSN->lifespan()
403
-                    ),
404
-                    'STS_ID' => array(
405
-                        '!=',
406
-                        EEM_Transaction::complete_status_code
407
-                    ),
408
-                )
409
-            )
410
-        );
411
-    }
351
+			$deleted = $wpdb->query($query);
352
+		}
353
+		if ($deleted) {
354
+			/**
355
+			 * Allows code to do something after the transactions have been deleted.
356
+			 */
357
+			do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids);
358
+		}
359
+
360
+		return $deleted;
361
+	}
362
+
363
+
364
+	/**
365
+	 * @param array $transaction_IDs
366
+	 *
367
+	 * @return bool
368
+	 */
369
+	public static function unset_locked_transactions(array $transaction_IDs)
370
+	{
371
+		$locked_transactions = get_option('ee_locked_transactions', array());
372
+		$update              = false;
373
+		foreach ($transaction_IDs as $TXN_ID) {
374
+			if (isset($locked_transactions[$TXN_ID])) {
375
+				unset($locked_transactions[$TXN_ID]);
376
+				$update = true;
377
+			}
378
+		}
379
+		if ($update) {
380
+			update_option('ee_locked_transactions', $locked_transactions);
381
+		}
382
+
383
+		return $update;
384
+	}
385
+
386
+
387
+
388
+	/**
389
+	 * returns an array of EE_Transaction objects whose timestamp is less than
390
+	 * the current time minus the session lifespan, which defaults to 60 minutes
391
+	 *
392
+	 * @return EE_Base_Class[]|EE_Transaction[]
393
+	 * @throws \EE_Error
394
+	 */
395
+	public function get_transactions_in_progress()
396
+	{
397
+		return $this->get_all(
398
+			array(
399
+				array(
400
+					'TXN_timestamp' => array(
401
+						'>',
402
+						time() - EE_Registry::instance()->SSN->lifespan()
403
+					),
404
+					'STS_ID' => array(
405
+						'!=',
406
+						EEM_Transaction::complete_status_code
407
+					),
408
+				)
409
+			)
410
+		);
411
+	}
412 412
 
413 413
 
414 414
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4 4
     exit('No direct script access allowed');
5 5
 }
6
-require_once(EE_MODELS . 'EEM_Base.model.php');
6
+require_once(EE_MODELS.'EEM_Base.model.php');
7 7
 
8 8
 /**
9 9
  *
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
                     __('Registration Steps', 'event_espresso'), false, array()),
108 108
             )
109 109
         );
110
-        $this->_model_relations        = array(
110
+        $this->_model_relations = array(
111 111
             'Registration'   => new EE_Has_Many_Relation(),
112 112
             'Payment'        => new EE_Has_Many_Relation(),
113 113
             'Status'         => new EE_Belongs_To_Relation(),
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
             ),
170 170
             OBJECT,
171 171
             array(
172
-                'txnDate' => array('DATE(' . $query_interval . ')', '%s'),
172
+                'txnDate' => array('DATE('.$query_interval.')', '%s'),
173 173
                 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d')
174 174
             )
175 175
         );
@@ -189,17 +189,17 @@  discard block
 block discarded – undo
189 189
     public function get_revenue_per_event_report($period = '-1 month')
190 190
     {
191 191
         global $wpdb;
192
-        $transaction_table          = $wpdb->prefix . 'esp_transaction';
193
-        $registration_table         = $wpdb->prefix . 'esp_registration';
194
-        $registration_payment_table = $wpdb->prefix . 'esp_registration_payment';
192
+        $transaction_table          = $wpdb->prefix.'esp_transaction';
193
+        $registration_table         = $wpdb->prefix.'esp_registration';
194
+        $registration_payment_table = $wpdb->prefix.'esp_registration_payment';
195 195
         $event_table                = $wpdb->posts;
196
-        $payment_table              = $wpdb->prefix . 'esp_payment';
196
+        $payment_table              = $wpdb->prefix.'esp_payment';
197 197
         $sql_date                   = date('Y-m-d H:i:s', strtotime($period));
198 198
         $approved_payment_status    = EEM_Payment::status_id_approved;
199 199
         $extra_event_on_join        = '';
200 200
         //exclude events not authored by user if permissions in effect
201 201
         if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
202
-            $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id();
202
+            $extra_event_on_join = ' AND Event.post_author = '.get_current_user_id();
203 203
         }
204 204
 
205 205
         return $wpdb->get_results(
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
     public function update_based_on_payments($transaction_obj_or_id, $save_txn = true)
271 271
     {
272 272
         EE_Error::doing_it_wrong(
273
-            __CLASS__ . '::' . __FUNCTION__,
273
+            __CLASS__.'::'.__FUNCTION__,
274 274
             sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
275 275
                 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'),
276 276
             '4.6.0'
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
             array(
319 319
                 0 => array(
320 320
                     'STS_ID'        => EEM_Transaction::failed_status_code,
321
-                    'Payment.PAY_ID' => array( 'IS NULL' ),
321
+                    'Payment.PAY_ID' => array('IS NULL'),
322 322
                     'TXN_timestamp' => array('<', time() - $time_to_leave_alone)
323 323
                 )
324 324
             ),
@@ -336,18 +336,18 @@  discard block
 block discarded – undo
336 336
             $time_to_leave_alone
337 337
         );
338 338
         //now that we have the ids to delete
339
-        if (! empty($txn_ids) && is_array($txn_ids)) {
339
+        if ( ! empty($txn_ids) && is_array($txn_ids)) {
340 340
             // first, make sure these TXN's are removed the "ee_locked_transactions" array
341 341
             EEM_Transaction::unset_locked_transactions($txn_ids);
342 342
             // let's get deletin'...
343 343
             // Why no wpdb->prepare?  Because the data is trusted.
344 344
             // We got the ids from the original query to get them FROM
345 345
             // the db (which is sanitized) so no need to prepare them again.
346
-            $query   = '
346
+            $query = '
347 347
 				DELETE
348
-				FROM ' . $this->table() . '
348
+				FROM ' . $this->table().'
349 349
 				WHERE
350
-					TXN_ID IN ( ' . implode(",", $txn_ids) . ')';
350
+					TXN_ID IN ( ' . implode(",", $txn_ids).')';
351 351
             $deleted = $wpdb->query($query);
352 352
         }
353 353
         if ($deleted) {
Please login to merge, or discard this patch.
core/db_models/EEM_Answer.model.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -125,14 +125,14 @@
 block discarded – undo
125 125
 	public function get_attendee_property_answer_value( EE_Registration $registration, $question_system_id = NULL, $pretty_answer = FALSE ){
126 126
 		$field_name = NULL;
127 127
 		$value = NULL;
128
-                //backward compat: we still want to find the question's ID
129
-                if( is_numeric( $question_system_id ) ) {
130
-                    //find this question's QST_system value
131
-                    $question_id = $question_system_id;
132
-                    $question_system_id = EEM_Question::instance()->get_var( array( array( 'QST_ID' => $question_system_id ) ), 'QST_system' );
133
-                } else {
134
-                    $question_id = (int) EEM_Question::instance()->get_var( array( array( 'QST_system' => $question_system_id ) ), 'QST_ID' );
135
-                }
128
+				//backward compat: we still want to find the question's ID
129
+				if( is_numeric( $question_system_id ) ) {
130
+					//find this question's QST_system value
131
+					$question_id = $question_system_id;
132
+					$question_system_id = EEM_Question::instance()->get_var( array( array( 'QST_ID' => $question_system_id ) ), 'QST_system' );
133
+				} else {
134
+					$question_id = (int) EEM_Question::instance()->get_var( array( array( 'QST_system' => $question_system_id ) ), 'QST_ID' );
135
+				}
136 136
 		//only bother checking if the registration has an attendee
137 137
 		if( $registration->attendee() instanceof EE_Attendee ) {
138 138
 			$field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question( $question_system_id );
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -51,18 +51,18 @@  discard block
 block discarded – undo
51 51
 	/**
52 52
 	 * 	constructor
53 53
 	 */
54
-	protected function __construct( $timezone = NULL ){
55
-		$this->singular_item = __('Answer','event_espresso');
56
-		$this->plural_item = __('Answers','event_espresso');
54
+	protected function __construct($timezone = NULL) {
55
+		$this->singular_item = __('Answer', 'event_espresso');
56
+		$this->plural_item = __('Answers', 'event_espresso');
57 57
 		$this->_tables = array(
58 58
 			'Answer'=> new EE_Primary_Table('esp_answer', 'ANS_ID')
59 59
 		);
60 60
 		$this->_fields = array(
61 61
 			'Answer'=>array(
62
-				'ANS_ID'=> new EE_Primary_Key_Int_Field('ANS_ID', __('Answer ID','event_espresso')),
63
-				'REG_ID'=>new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID','event_espresso'), false, 0, 'Registration'),
64
-				'QST_ID'=>new EE_Foreign_Key_Int_Field('QST_ID', __('Question ID','event_espresso'), false, 0, 'Question'),
65
-				'ANS_value'=>new EE_Maybe_Serialized_Simple_HTML_Field('ANS_value', __('Answer Value','event_espresso'), false, '')
62
+				'ANS_ID'=> new EE_Primary_Key_Int_Field('ANS_ID', __('Answer ID', 'event_espresso')),
63
+				'REG_ID'=>new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso'), false, 0, 'Registration'),
64
+				'QST_ID'=>new EE_Foreign_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso'), false, 0, 'Question'),
65
+				'ANS_value'=>new EE_Maybe_Serialized_Simple_HTML_Field('ANS_value', __('Answer Value', 'event_espresso'), false, '')
66 66
 			));
67 67
 		$this->_model_relations = array(
68 68
 			'Registration'=>new EE_Belongs_To_Relation(),
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 		);
71 71
 		$this->_model_chain_to_wp_user = 'Registration.Event';
72 72
 		$this->_caps_slug = 'registrations';
73
-		parent::__construct( $timezone );
73
+		parent::__construct($timezone);
74 74
 	}
75 75
 
76 76
 
@@ -83,19 +83,19 @@  discard block
 block discarded – undo
83 83
 	 * @param boolean $pretty_answer whether to call 'pretty_value' or just 'value'
84 84
 	 * @return string
85 85
 	 */
86
-	public function get_answer_value_to_question( EE_Registration $registration, $question_id = NULL,$pretty_answer = FALSE ){
87
-		$value = $this->get_attendee_property_answer_value( $registration, $question_id, $pretty_answer );
88
-		if (  $value === NULL ){
89
-			$answer_obj = $this->get_registration_question_answer_object( $registration, $question_id);
90
-			if( $answer_obj instanceof EE_Answer ){
91
-				if($pretty_answer){
86
+	public function get_answer_value_to_question(EE_Registration $registration, $question_id = NULL, $pretty_answer = FALSE) {
87
+		$value = $this->get_attendee_property_answer_value($registration, $question_id, $pretty_answer);
88
+		if ($value === NULL) {
89
+			$answer_obj = $this->get_registration_question_answer_object($registration, $question_id);
90
+			if ($answer_obj instanceof EE_Answer) {
91
+				if ($pretty_answer) {
92 92
 					$value = $answer_obj->pretty_value();
93
-				}else{
93
+				} else {
94 94
 					$value = $answer_obj->value();
95 95
 				}
96 96
 			}
97 97
 		}
98
-		return apply_filters( 'FHEE__EEM_Answer__get_answer_value_to_question__answer_value', $value, $registration, $question_id );
98
+		return apply_filters('FHEE__EEM_Answer__get_answer_value_to_question__answer_value', $value, $registration, $question_id);
99 99
 	}
100 100
 
101 101
 
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
 	 * @param int $question_id
107 107
 	 * @return EE_Answer
108 108
 	 */
109
-	public function get_registration_question_answer_object( EE_Registration $registration, $question_id = NULL){
110
-		$answer_obj = $this->get_one( array( array( 'QST_ID'=>$question_id, 'REG_ID'=>$registration->ID() )));
111
-		return apply_filters( 'FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id );
109
+	public function get_registration_question_answer_object(EE_Registration $registration, $question_id = NULL) {
110
+		$answer_obj = $this->get_one(array(array('QST_ID'=>$question_id, 'REG_ID'=>$registration->ID())));
111
+		return apply_filters('FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id);
112 112
 	}
113 113
 
114 114
 
@@ -122,39 +122,39 @@  discard block
 block discarded – undo
122 122
 	 * @return string|null (if the registration has no attendee, or the question_system_id is not a QST_ID or QST_system for
123 123
 	 * a question corresponding to an attendee field, returns null)
124 124
 	 */
125
-	public function get_attendee_property_answer_value( EE_Registration $registration, $question_system_id = NULL, $pretty_answer = FALSE ){
125
+	public function get_attendee_property_answer_value(EE_Registration $registration, $question_system_id = NULL, $pretty_answer = FALSE) {
126 126
 		$field_name = NULL;
127 127
 		$value = NULL;
128 128
                 //backward compat: we still want to find the question's ID
129
-                if( is_numeric( $question_system_id ) ) {
129
+                if (is_numeric($question_system_id)) {
130 130
                     //find this question's QST_system value
131 131
                     $question_id = $question_system_id;
132
-                    $question_system_id = EEM_Question::instance()->get_var( array( array( 'QST_ID' => $question_system_id ) ), 'QST_system' );
132
+                    $question_system_id = EEM_Question::instance()->get_var(array(array('QST_ID' => $question_system_id)), 'QST_system');
133 133
                 } else {
134
-                    $question_id = (int) EEM_Question::instance()->get_var( array( array( 'QST_system' => $question_system_id ) ), 'QST_ID' );
134
+                    $question_id = (int) EEM_Question::instance()->get_var(array(array('QST_system' => $question_system_id)), 'QST_ID');
135 135
                 }
136 136
 		//only bother checking if the registration has an attendee
137
-		if( $registration->attendee() instanceof EE_Attendee ) {
138
-			$field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question( $question_system_id );
139
-			if( $field_name ) {
140
-				if( $pretty_answer ) {
141
-					if( $field_name === 'STA_ID' ) {
137
+		if ($registration->attendee() instanceof EE_Attendee) {
138
+			$field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question($question_system_id);
139
+			if ($field_name) {
140
+				if ($pretty_answer) {
141
+					if ($field_name === 'STA_ID') {
142 142
 						$state = $registration->attendee()->state_obj();
143
-						$value = $state instanceof EE_State ? $state->name() : sprintf( __('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID() );
144
-					} else if($field_name === 'CNT_ISO') {
143
+						$value = $state instanceof EE_State ? $state->name() : sprintf(__('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID());
144
+					} else if ($field_name === 'CNT_ISO') {
145 145
 						$country = $registration->attendee()->country_obj();
146
-						$value = $country instanceof EE_Country ? $country->name() : sprintf(__('Unknown Country (%s)', "event_espresso"),$registration->attendee()->country_ID());
146
+						$value = $country instanceof EE_Country ? $country->name() : sprintf(__('Unknown Country (%s)', "event_espresso"), $registration->attendee()->country_ID());
147 147
 					} else {
148
-						$value = $registration->attendee()->get_pretty( $field_name );
148
+						$value = $registration->attendee()->get_pretty($field_name);
149 149
 					}
150 150
 					//if field name is blank, leave the value as null too
151
-				}else{
152
-					$value = $registration->attendee()->get( $field_name );
151
+				} else {
152
+					$value = $registration->attendee()->get($field_name);
153 153
 				}
154 154
 			}
155 155
 			//if no field was found, leave value blank
156 156
 		}
157
-		return apply_filters( 'FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id, $question_system_id );
157
+		return apply_filters('FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id, $question_system_id);
158 158
 	}
159 159
 
160 160
 
Please login to merge, or discard this patch.
core/services/collections/CollectionInterface.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -113,12 +113,12 @@  discard block
 block discarded – undo
113 113
 	public function previous();
114 114
 
115 115
 		/**
116
-	 * Returns the index of a given object, or false if not found
117
-	 *
118
-	 * @see http://stackoverflow.com/a/8736013
119
-	 * @param $object
120
-	 * @return boolean|int|string
121
-	 */
116
+		 * Returns the index of a given object, or false if not found
117
+		 *
118
+		 * @see http://stackoverflow.com/a/8736013
119
+		 * @param $object
120
+		 * @return boolean|int|string
121
+		 */
122 122
 	public function indexOf( $object );
123 123
 
124 124
 
@@ -160,17 +160,17 @@  discard block
 block discarded – undo
160 160
 
161 161
 
162 162
 
163
-    /**
164
-     * detaches ALL objects from the Collection
165
-     */
166
-    public function detachAll();
163
+	/**
164
+	 * detaches ALL objects from the Collection
165
+	 */
166
+	public function detachAll();
167 167
 
168 168
 
169 169
 
170
-    /**
171
-     * unsets and detaches ALL objects from the Collection
172
-     */
173
-    public function trashAndDetachAll();
170
+	/**
171
+	 * unsets and detaches ALL objects from the Collection
172
+	 */
173
+	public function trashAndDetachAll();
174 174
 
175 175
 }
176 176
 // End of file CollectionInterface.php
Please login to merge, or discard this patch.
core/services/collections/Collection.php 1 patch
Indentation   +28 added lines, -29 removed lines patch added patch discarded remove patch
@@ -83,7 +83,6 @@  discard block
 block discarded – undo
83 83
 
84 84
 	 /**
85 85
 	  * setIdentifier
86
-
87 86
 	  * Sets the data associated with an object in the Collection
88 87
 	  * if no $identifier is supplied, then the spl_object_hash() is used
89 88
 	  *
@@ -352,34 +351,34 @@  discard block
 block discarded – undo
352 351
 
353 352
 
354 353
 
355
-     /**
356
-      * detaches ALL objects from the Collection
357
-      */
358
-     public function detachAll()
359
-     {
360
-         $this->rewind();
361
-         while ($this->valid()) {
362
-             $object = $this->current();
363
-             $this->next();
364
-             $this->detach($object);
365
-         }
366
-     }
367
-
368
-
369
-
370
-     /**
371
-      * unsets and detaches ALL objects from the Collection
372
-      */
373
-     public function trashAndDetachAll()
374
-     {
375
-         $this->rewind();
376
-         while ($this->valid()) {
377
-             $object = $this->current();
378
-             $this->next();
379
-             $this->detach($object);
380
-             unset($object);
381
-         }
382
-     }
354
+	 /**
355
+	  * detaches ALL objects from the Collection
356
+	  */
357
+	 public function detachAll()
358
+	 {
359
+		 $this->rewind();
360
+		 while ($this->valid()) {
361
+			 $object = $this->current();
362
+			 $this->next();
363
+			 $this->detach($object);
364
+		 }
365
+	 }
366
+
367
+
368
+
369
+	 /**
370
+	  * unsets and detaches ALL objects from the Collection
371
+	  */
372
+	 public function trashAndDetachAll()
373
+	 {
374
+		 $this->rewind();
375
+		 while ($this->valid()) {
376
+			 $object = $this->current();
377
+			 $this->next();
378
+			 $this->detach($object);
379
+			 unset($object);
380
+		 }
381
+	 }
383 382
 
384 383
 
385 384
 
Please login to merge, or discard this patch.
core/services/loaders/LoaderFactory.php 2 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -79,37 +79,37 @@
 block discarded – undo
79 79
 class LoaderFactory
80 80
 {
81 81
 
82
-    /**
83
-     * @var LoaderInterface $loader ;
84
-     */
85
-    private static $loader;
82
+	/**
83
+	 * @var LoaderInterface $loader ;
84
+	 */
85
+	private static $loader;
86 86
 
87 87
 
88 88
 
89
-    /**
90
-     * @param mixed $generator      provided during  very first instantiation in
91
-     *                              EE_Load_Espresso_Core::handle_request()
92
-     *                              otherwise can be left null
93
-     * @return LoaderInterface
94
-     * @throws InvalidArgumentException
95
-     * @throws InvalidInterfaceException
96
-     * @throws InvalidDataTypeException
97
-     */
98
-    public static function getLoader($generator = null)
99
-    {
100
-        if (! LoaderFactory::$loader instanceof LoaderInterface) {
101
-            $generator = $generator !== null ? $generator : EE_Registry::instance();
102
-            $core_loader = new CoreLoader($generator);
103
-            LoaderFactory::$loader = new Loader(
104
-                $core_loader,
105
-                new CachingLoader(
106
-                    $core_loader,
107
-                    new LooseCollection('')
108
-                )
109
-            );
110
-        }
111
-        return LoaderFactory::$loader;
112
-    }
89
+	/**
90
+	 * @param mixed $generator      provided during  very first instantiation in
91
+	 *                              EE_Load_Espresso_Core::handle_request()
92
+	 *                              otherwise can be left null
93
+	 * @return LoaderInterface
94
+	 * @throws InvalidArgumentException
95
+	 * @throws InvalidInterfaceException
96
+	 * @throws InvalidDataTypeException
97
+	 */
98
+	public static function getLoader($generator = null)
99
+	{
100
+		if (! LoaderFactory::$loader instanceof LoaderInterface) {
101
+			$generator = $generator !== null ? $generator : EE_Registry::instance();
102
+			$core_loader = new CoreLoader($generator);
103
+			LoaderFactory::$loader = new Loader(
104
+				$core_loader,
105
+				new CachingLoader(
106
+					$core_loader,
107
+					new LooseCollection('')
108
+				)
109
+			);
110
+		}
111
+		return LoaderFactory::$loader;
112
+	}
113 113
 
114 114
 
115 115
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@
 block discarded – undo
97 97
      */
98 98
     public static function getLoader($generator = null)
99 99
     {
100
-        if (! LoaderFactory::$loader instanceof LoaderInterface) {
100
+        if ( ! LoaderFactory::$loader instanceof LoaderInterface) {
101 101
             $generator = $generator !== null ? $generator : EE_Registry::instance();
102 102
             $core_loader = new CoreLoader($generator);
103 103
             LoaderFactory::$loader = new Loader(
Please login to merge, or discard this patch.
modules/messages/EED_Messages.module.php 1 patch
Indentation   +1080 added lines, -1080 removed lines patch added patch discarded remove patch
@@ -13,1095 +13,1095 @@
 block discarded – undo
13 13
 class EED_Messages extends EED_Module
14 14
 {
15 15
 
16
-    /**
17
-     * This holds the EE_messages controller
18
-     *
19
-     * @deprecated 4.9.0
20
-     * @var EE_messages $_EEMSG
21
-     */
22
-    protected static $_EEMSG;
23
-
24
-    /**
25
-     * @type EE_Message_Resource_Manager $_message_resource_manager
26
-     */
27
-    protected static $_message_resource_manager;
28
-
29
-    /**
30
-     * This holds the EE_Messages_Processor business class.
31
-     *
32
-     * @type EE_Messages_Processor
33
-     */
34
-    protected static $_MSG_PROCESSOR;
35
-
36
-    /**
37
-     * holds all the paths for various messages components.
38
-     * Utilized by autoloader registry
39
-     *
40
-     * @var array
41
-     */
42
-    protected static $_MSG_PATHS;
43
-
44
-
45
-    /**
46
-     * This will hold an array of messages template packs that are registered in the messages system.
47
-     * Format is:
48
-     * array(
49
-     *    'template_pack_dbref' => EE_Messages_Template_Pack (instance)
50
-     * )
51
-     *
52
-     * @var EE_Messages_Template_Pack[]
53
-     */
54
-    protected static $_TMP_PACKS = array();
55
-
56
-
57
-    /**
58
-     * @return EED_Messages
59
-     */
60
-    public static function instance()
61
-    {
62
-        return parent::get_instance(__CLASS__);
63
-    }
64
-
65
-
66
-    /**
67
-     *  set_hooks - for hooking into EE Core, other modules, etc
68
-     *
69
-     * @since 4.5.0
70
-     * @return    void
71
-     */
72
-    public static function set_hooks()
73
-    {
74
-        //actions
75
-        add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
76
-        add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
77
-            array('EED_Messages', 'maybe_registration'), 10, 2);
78
-        //filters
79
-        add_filter('FHEE__EE_Registration__receipt_url__receipt_url',
80
-            array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
81
-        add_filter('FHEE__EE_Registration__invoice_url__invoice_url',
82
-            array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
83
-        //register routes
84
-        self::_register_routes();
85
-    }
86
-
87
-    /**
88
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
89
-     *
90
-     * @access    public
91
-     * @return    void
92
-     */
93
-    public static function set_hooks_admin()
94
-    {
95
-        //actions
96
-        add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
97
-        add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
98
-            array('EED_Messages', 'payment_reminder'), 10);
99
-        add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
100
-            array('EED_Messages', 'maybe_registration'), 10, 3);
101
-        add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
102
-            array('EED_Messages', 'send_newsletter_message'), 10, 2);
103
-        add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction',
104
-            array('EED_Messages', 'cancelled_registration'), 10);
105
-        add_action('AHEE__EE_Admin_Page___process_admin_payment_notification',
106
-            array('EED_Messages', 'process_admin_payment'), 10, 1);
107
-        //filters
108
-        add_filter('FHEE__EE_Admin_Page___process_resend_registration__success',
109
-            array('EED_Messages', 'process_resend'), 10, 2);
110
-        add_filter('FHEE__EE_Registration__receipt_url__receipt_url',
111
-            array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
112
-        add_filter('FHEE__EE_Registration__invoice_url__invoice_url',
113
-            array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
114
-    }
115
-
116
-
117
-    /**
118
-     * All the message triggers done by route go in here.
119
-     *
120
-     * @since 4.5.0
121
-     * @return void
122
-     */
123
-    protected static function _register_routes()
124
-    {
125
-        EE_Config::register_route('msg_url_trigger', 'Messages', 'run');
126
-        EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request');
127
-        EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger');
128
-        EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger');
129
-        do_action('AHEE__EED_Messages___register_routes');
130
-    }
131
-
132
-
133
-    /**
134
-     * This is called when a browser display trigger is executed.
135
-     * The browser display trigger is typically used when a already generated message is displayed directly in the
136
-     * browser.
137
-     *
138
-     * @since 4.9.0
139
-     * @param WP $WP
140
-     */
141
-    public function browser_trigger($WP)
142
-    {
143
-        //ensure controller is loaded
144
-        self::_load_controller();
145
-        $token = EE_Registry::instance()->REQ->get('token');
146
-        try {
147
-            $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager);
148
-            self::$_MSG_PROCESSOR->generate_and_send_now($mtg);
149
-        } catch (EE_Error $e) {
150
-            $error_msg = __('Please note that a system message failed to send due to a technical issue.',
151
-                'event_espresso');
152
-            // add specific message for developers if WP_DEBUG in on
153
-            $error_msg .= '||' . $e->getMessage();
154
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
155
-        }
156
-    }
157
-
158
-
159
-    /**
160
-     * This is called when a browser error trigger is executed.
161
-     * When triggered this will grab the EE_Message matching the token in the request and use that to get the error
162
-     * message and display it.
163
-     *
164
-     * @since 4.9.0
165
-     * @param $WP
166
-     */
167
-    public function browser_error_trigger($WP)
168
-    {
169
-        $token = EE_Registry::instance()->REQ->get('token');
170
-        if ($token) {
171
-            $message = EEM_Message::instance()->get_one_by_token($token);
172
-            if ($message instanceof EE_Message) {
173
-                header('HTTP/1.1 200 OK');
174
-                $error_msg = nl2br($message->error_message());
175
-                ?>
16
+	/**
17
+	 * This holds the EE_messages controller
18
+	 *
19
+	 * @deprecated 4.9.0
20
+	 * @var EE_messages $_EEMSG
21
+	 */
22
+	protected static $_EEMSG;
23
+
24
+	/**
25
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
26
+	 */
27
+	protected static $_message_resource_manager;
28
+
29
+	/**
30
+	 * This holds the EE_Messages_Processor business class.
31
+	 *
32
+	 * @type EE_Messages_Processor
33
+	 */
34
+	protected static $_MSG_PROCESSOR;
35
+
36
+	/**
37
+	 * holds all the paths for various messages components.
38
+	 * Utilized by autoloader registry
39
+	 *
40
+	 * @var array
41
+	 */
42
+	protected static $_MSG_PATHS;
43
+
44
+
45
+	/**
46
+	 * This will hold an array of messages template packs that are registered in the messages system.
47
+	 * Format is:
48
+	 * array(
49
+	 *    'template_pack_dbref' => EE_Messages_Template_Pack (instance)
50
+	 * )
51
+	 *
52
+	 * @var EE_Messages_Template_Pack[]
53
+	 */
54
+	protected static $_TMP_PACKS = array();
55
+
56
+
57
+	/**
58
+	 * @return EED_Messages
59
+	 */
60
+	public static function instance()
61
+	{
62
+		return parent::get_instance(__CLASS__);
63
+	}
64
+
65
+
66
+	/**
67
+	 *  set_hooks - for hooking into EE Core, other modules, etc
68
+	 *
69
+	 * @since 4.5.0
70
+	 * @return    void
71
+	 */
72
+	public static function set_hooks()
73
+	{
74
+		//actions
75
+		add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
76
+		add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
77
+			array('EED_Messages', 'maybe_registration'), 10, 2);
78
+		//filters
79
+		add_filter('FHEE__EE_Registration__receipt_url__receipt_url',
80
+			array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
81
+		add_filter('FHEE__EE_Registration__invoice_url__invoice_url',
82
+			array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
83
+		//register routes
84
+		self::_register_routes();
85
+	}
86
+
87
+	/**
88
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
89
+	 *
90
+	 * @access    public
91
+	 * @return    void
92
+	 */
93
+	public static function set_hooks_admin()
94
+	{
95
+		//actions
96
+		add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
97
+		add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
98
+			array('EED_Messages', 'payment_reminder'), 10);
99
+		add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
100
+			array('EED_Messages', 'maybe_registration'), 10, 3);
101
+		add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
102
+			array('EED_Messages', 'send_newsletter_message'), 10, 2);
103
+		add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction',
104
+			array('EED_Messages', 'cancelled_registration'), 10);
105
+		add_action('AHEE__EE_Admin_Page___process_admin_payment_notification',
106
+			array('EED_Messages', 'process_admin_payment'), 10, 1);
107
+		//filters
108
+		add_filter('FHEE__EE_Admin_Page___process_resend_registration__success',
109
+			array('EED_Messages', 'process_resend'), 10, 2);
110
+		add_filter('FHEE__EE_Registration__receipt_url__receipt_url',
111
+			array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
112
+		add_filter('FHEE__EE_Registration__invoice_url__invoice_url',
113
+			array('EED_Messages', 'registration_message_trigger_url'), 10, 4);
114
+	}
115
+
116
+
117
+	/**
118
+	 * All the message triggers done by route go in here.
119
+	 *
120
+	 * @since 4.5.0
121
+	 * @return void
122
+	 */
123
+	protected static function _register_routes()
124
+	{
125
+		EE_Config::register_route('msg_url_trigger', 'Messages', 'run');
126
+		EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request');
127
+		EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger');
128
+		EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger');
129
+		do_action('AHEE__EED_Messages___register_routes');
130
+	}
131
+
132
+
133
+	/**
134
+	 * This is called when a browser display trigger is executed.
135
+	 * The browser display trigger is typically used when a already generated message is displayed directly in the
136
+	 * browser.
137
+	 *
138
+	 * @since 4.9.0
139
+	 * @param WP $WP
140
+	 */
141
+	public function browser_trigger($WP)
142
+	{
143
+		//ensure controller is loaded
144
+		self::_load_controller();
145
+		$token = EE_Registry::instance()->REQ->get('token');
146
+		try {
147
+			$mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager);
148
+			self::$_MSG_PROCESSOR->generate_and_send_now($mtg);
149
+		} catch (EE_Error $e) {
150
+			$error_msg = __('Please note that a system message failed to send due to a technical issue.',
151
+				'event_espresso');
152
+			// add specific message for developers if WP_DEBUG in on
153
+			$error_msg .= '||' . $e->getMessage();
154
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
155
+		}
156
+	}
157
+
158
+
159
+	/**
160
+	 * This is called when a browser error trigger is executed.
161
+	 * When triggered this will grab the EE_Message matching the token in the request and use that to get the error
162
+	 * message and display it.
163
+	 *
164
+	 * @since 4.9.0
165
+	 * @param $WP
166
+	 */
167
+	public function browser_error_trigger($WP)
168
+	{
169
+		$token = EE_Registry::instance()->REQ->get('token');
170
+		if ($token) {
171
+			$message = EEM_Message::instance()->get_one_by_token($token);
172
+			if ($message instanceof EE_Message) {
173
+				header('HTTP/1.1 200 OK');
174
+				$error_msg = nl2br($message->error_message());
175
+				?>
176 176
                 <!DOCTYPE html>
177 177
                 <html>
178 178
                 <head></head>
179 179
                 <body>
180 180
                 <?php echo empty($error_msg)
181
-                    ? esc_html__('Unfortunately, we were unable to capture the error message for this message.',
182
-                        'event_espresso')
183
-                    : wp_kses(
184
-                        $error_msg,
185
-                        array(
186
-                            'a'      => array(
187
-                                'href'  => array(),
188
-                                'title' => array(),
189
-                            ),
190
-                            'span'   => array(),
191
-                            'div'    => array(),
192
-                            'p'      => array(),
193
-                            'strong' => array(),
194
-                            'em'     => array(),
195
-                            'br'     => array(),
196
-                        )
197
-                    ); ?>
181
+					? esc_html__('Unfortunately, we were unable to capture the error message for this message.',
182
+						'event_espresso')
183
+					: wp_kses(
184
+						$error_msg,
185
+						array(
186
+							'a'      => array(
187
+								'href'  => array(),
188
+								'title' => array(),
189
+							),
190
+							'span'   => array(),
191
+							'div'    => array(),
192
+							'p'      => array(),
193
+							'strong' => array(),
194
+							'em'     => array(),
195
+							'br'     => array(),
196
+						)
197
+					); ?>
198 198
                 </body>
199 199
                 </html>
200 200
                 <?php
201
-                exit;
202
-            }
203
-        }
204
-        return;
205
-    }
206
-
207
-
208
-    /**
209
-     *  This runs when the msg_url_trigger route has initiated.
210
-     *
211
-     * @since 4.5.0
212
-     * @param WP $WP
213
-     * @throws EE_Error
214
-     * @return    void
215
-     */
216
-    public function run($WP)
217
-    {
218
-        //ensure controller is loaded
219
-        self::_load_controller();
220
-        // attempt to process message
221
-        try {
222
-            /** @type EE_Message_To_Generate_From_Request $message_to_generate */
223
-            $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
224
-            self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate);
225
-        } catch (EE_Error $e) {
226
-            $error_msg = __('Please note that a system message failed to send due to a technical issue.',
227
-                'event_espresso');
228
-            // add specific message for developers if WP_DEBUG in on
229
-            $error_msg .= '||' . $e->getMessage();
230
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
231
-        }
232
-    }
233
-
234
-
235
-    /**
236
-     * This is triggered by the 'msg_cron_trigger' route.
237
-     *
238
-     * @param WP $WP
239
-     */
240
-    public function execute_batch_request($WP)
241
-    {
242
-        $this->run_cron();
243
-        header('HTTP/1.1 200 OK');
244
-        exit();
245
-    }
246
-
247
-
248
-    /**
249
-     * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp
250
-     * request.
251
-     */
252
-    public function run_cron()
253
-    {
254
-        self::_load_controller();
255
-        //get required vars
256
-        $cron_type     = EE_Registry::instance()->REQ->get('type');
257
-        $transient_key = EE_Registry::instance()->REQ->get('key');
258
-
259
-        //now let's verify transient, if not valid exit immediately
260
-        if (! get_transient($transient_key)) {
261
-            /**
262
-             * trigger error so this gets in the error logs.  This is important because it happens on a non-user request.
263
-             */
264
-            trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso'));
265
-        }
266
-
267
-        //if made it here, lets' delete the transient to keep the db clean
268
-        delete_transient($transient_key);
269
-
270
-        if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
271
-
272
-            $method = 'batch_' . $cron_type . '_from_queue';
273
-            if (method_exists(self::$_MSG_PROCESSOR, $method)) {
274
-                self::$_MSG_PROCESSOR->$method();
275
-            } else {
276
-                //no matching task
277
-                /**
278
-                 * trigger error so this gets in the error logs.  This is important because it happens on a non user request.
279
-                 */
280
-                trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'),
281
-                    $cron_type)));
282
-            }
283
-        }
284
-
285
-        do_action('FHEE__EED_Messages__run_cron__end');
286
-    }
287
-
288
-
289
-    /**
290
-     * This is used to retrieve the template pack for the given name.
291
-     * Retrieved packs are cached on the static $_TMP_PACKS array.  If there is no class matching the given name then
292
-     * the default template pack is returned.
293
-     *
294
-     * @deprecated 4.9.0  @see EEH_MSG_Template::get_template_pack()
295
-     * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used
296
-     *                                   in generating the Pack class name).
297
-     * @return EE_Messages_Template_Pack
298
-     */
299
-    public static function get_template_pack($template_pack_name)
300
-    {
301
-        EE_Registry::instance()->load_helper('MSG_Template');
302
-        return EEH_MSG_Template::get_template_pack($template_pack_name);
303
-    }
304
-
305
-
306
-    /**
307
-     * Retrieves an array of all template packs.
308
-     * Array is in the format array( 'dbref' => EE_Messages_Template_Pack )
309
-     *
310
-     * @deprecated 4.9.0  @see EEH_MSG_Template_Pack::get_template_pack_collection
311
-     * @return EE_Messages_Template_Pack[]
312
-     */
313
-    public static function get_template_packs()
314
-    {
315
-        EE_Registry::instance()->load_helper('MSG_Template');
316
-
317
-        //for backward compat, let's make sure this returns in the same format as originally.
318
-        $template_pack_collection = EEH_MSG_Template::get_template_pack_collection();
319
-        $template_pack_collection->rewind();
320
-        $template_packs = array();
321
-        while ($template_pack_collection->valid()) {
322
-            $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current();
323
-            $template_pack_collection->next();
324
-        }
325
-        return $template_packs;
326
-    }
327
-
328
-
329
-    /**
330
-     * This simply makes sure the autoloaders are registered for the EE_messages system.
331
-     *
332
-     * @since 4.5.0
333
-     * @return void
334
-     */
335
-    public static function set_autoloaders()
336
-    {
337
-        if (empty(self::$_MSG_PATHS)) {
338
-            self::_set_messages_paths();
339
-            foreach (self::$_MSG_PATHS as $path) {
340
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);
341
-            }
342
-            // add aliases
343
-            EEH_Autoloader::add_alias('EE_messages', 'EE_messages');
344
-            EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger');
345
-        }
346
-    }
347
-
348
-
349
-    /**
350
-     * Take care of adding all the paths for the messages components to the $_MSG_PATHS property
351
-     * for use by the Messages Autoloaders
352
-     *
353
-     * @since 4.5.0
354
-     * @return void.
355
-     */
356
-    protected static function _set_messages_paths()
357
-    {
358
-        $dir_ref = array(
359
-            'messages/message_type',
360
-            'messages/messenger',
361
-            'messages/defaults',
362
-            'messages/defaults/email',
363
-            'messages/data_class',
364
-            'messages/validators',
365
-            'messages/validators/email',
366
-            'messages/validators/html',
367
-            'shortcodes',
368
-        );
369
-        $paths   = array();
370
-        foreach ($dir_ref as $index => $dir) {
371
-            $paths[$index] = EE_LIBRARIES . $dir;
372
-        }
373
-        self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths);
374
-    }
375
-
376
-
377
-    /**
378
-     * Takes care of loading dependencies
379
-     *
380
-     * @since 4.5.0
381
-     * @return void
382
-     */
383
-    protected static function _load_controller()
384
-    {
385
-        if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
386
-            EE_Registry::instance()->load_core('Request_Handler');
387
-            self::set_autoloaders();
388
-            self::$_EEMSG                    = EE_Registry::instance()->load_lib('messages');
389
-            self::$_MSG_PROCESSOR            = EE_Registry::instance()->load_lib('Messages_Processor');
390
-            self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
391
-        }
392
-    }
393
-
394
-
395
-    /**
396
-     * @param EE_Transaction $transaction
397
-     */
398
-    public static function payment_reminder(EE_Transaction $transaction)
399
-    {
400
-        self::_load_controller();
401
-        $data = array($transaction, null);
402
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data);
403
-    }
404
-
405
-
406
-    /**
407
-     * Any messages triggers for after successful gateway payments should go in here.
408
-     *
409
-     * @param  EE_Transaction object
410
-     * @param  EE_Payment     object
411
-     * @return void
412
-     */
413
-    public static function payment(EE_Transaction $transaction, EE_Payment $payment)
414
-    {
415
-        self::_load_controller();
416
-        $data = array($transaction, $payment);
417
-        EE_Registry::instance()->load_helper('MSG_Template');
418
-        $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
419
-        //if payment amount is less than 0 then switch to payment_refund message type.
420
-        $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
421
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
422
-    }
423
-
424
-
425
-    /**
426
-     * @param EE_Transaction $transaction
427
-     */
428
-    public static function cancelled_registration(EE_Transaction $transaction)
429
-    {
430
-        self::_load_controller();
431
-        $data = array($transaction, null);
432
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data);
433
-    }
434
-
435
-
436
-    /**
437
-     * Trigger for Registration messages
438
-     * Note that what registration message type is sent depends on what the reg status is for the registrations on the
439
-     * incoming transaction.
440
-     *
441
-     * @param EE_Registration $registration
442
-     * @param array           $extra_details
443
-     * @return void
444
-     */
445
-    public static function maybe_registration(EE_Registration $registration, $extra_details = array())
446
-    {
447
-
448
-        if (! self::_verify_registration_notification_send($registration, $extra_details)) {
449
-            //no messages please
450
-            return;
451
-        }
452
-
453
-
454
-        //get all registrations so we make sure we send messages for the right status.
455
-        $all_registrations = $registration->transaction()->registrations();
456
-
457
-        //cached array of statuses so we only trigger messages once per status.
458
-        $statuses_sent = array();
459
-        self::_load_controller();
460
-        $mtgs = array();
461
-
462
-        //loop through registrations and trigger messages once per status.
463
-        foreach ($all_registrations as $reg) {
464
-
465
-            //already triggered?
466
-            if (in_array($reg->status_ID(), $statuses_sent)) {
467
-                continue;
468
-            }
469
-
470
-            $message_type    = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID());
471
-            $mtgs            = array_merge(
472
-                    $mtgs,
473
-                    self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
474
-                            $message_type,
475
-                            array($registration->transaction(), null, $reg->status_ID())
476
-                    )
477
-            );
478
-            $statuses_sent[] = $reg->status_ID();
479
-        }
480
-
481
-        if (count($statuses_sent) > 1) {
482
-            $mtgs = array_merge(
483
-                $mtgs,
484
-                self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
485
-                    'registration_summary',
486
-                    array($registration->transaction(), null)
487
-                )
488
-            );
489
-        }
490
-
491
-        //batch queue and initiate request
492
-        self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs);
493
-        self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
494
-    }
495
-
496
-
497
-    /**
498
-     * This is a helper method used to very whether a registration notification should be sent or
499
-     * not.  Prevents duplicate notifications going out for registration context notifications.
500
-     *
501
-     * @param EE_Registration $registration  [description]
502
-     * @param array           $extra_details [description]
503
-     * @return bool          true = send away, false = nope halt the presses.
504
-     */
505
-    protected static function _verify_registration_notification_send(
506
-        EE_Registration $registration,
507
-        $extra_details = array()
508
-    ) {
509
-        //self::log(
510
-        //	__CLASS__, __FUNCTION__, __LINE__,
511
-        //	$registration->transaction(),
512
-        //	array( '$extra_details' => $extra_details )
513
-        //);
514
-        // currently only using this to send messages for the primary registrant
515
-        if (! $registration->is_primary_registrant()) {
516
-            return false;
517
-        }
518
-        // first we check if we're in admin and not doing front ajax
519
-        if (is_admin() && ! EE_FRONT_AJAX) {
520
-            //make sure appropriate admin params are set for sending messages
521
-            if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) {
522
-                //no messages sent please.
523
-                return false;
524
-            }
525
-        } else {
526
-            // frontend request (either regular or via AJAX)
527
-            // TXN is NOT finalized ?
528
-            if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
529
-                return false;
530
-            }
531
-            // return visit but nothing changed ???
532
-            if (
533
-                isset($extra_details['revisit'], $extra_details['status_updates']) &&
534
-                $extra_details['revisit'] && ! $extra_details['status_updates']
535
-            ) {
536
-                return false;
537
-            }
538
-            // NOT sending messages && reg status is something other than "Not-Approved"
539
-            if (
540
-                ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) &&
541
-                $registration->status_ID() !== EEM_Registration::status_id_not_approved
542
-            ) {
543
-                return false;
544
-            }
545
-        }
546
-        // release the kraken
547
-        return true;
548
-    }
549
-
550
-
551
-    /**
552
-     * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that
553
-     * status id.
554
-     *
555
-     * @deprecated 4.9.0  Use EEH_MSG_Template::reg_status_to_message_type_array()
556
-     *                    or EEH_MSG_Template::convert_reg_status_to_message_type
557
-     * @param string $reg_status
558
-     * @return array
559
-     */
560
-    protected static function _get_reg_status_array($reg_status = '')
561
-    {
562
-        EE_Registry::instance()->load_helper('MSG_Template');
563
-        return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
564
-            ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
565
-            : EEH_MSG_Template::reg_status_to_message_type_array();
566
-    }
567
-
568
-
569
-    /**
570
-     * Simply returns the payment message type for the given payment status.
571
-     *
572
-     * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array
573
-     *                   or EEH_MSG_Template::convert_payment_status_to_message_type
574
-     * @param string $payment_status The payment status being matched.
575
-     * @return string|bool The payment message type slug matching the status or false if no match.
576
-     */
577
-    protected static function _get_payment_message_type($payment_status)
578
-    {
579
-        EE_Registry::instance()->load_helper('MSG_Template');
580
-        return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
581
-            ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
582
-            : false;
583
-    }
584
-
585
-
586
-    /**
587
-     * Message triggers for a resending already sent message(s) (via EE_Message list table)
588
-     *
589
-     * @access public
590
-     * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages
591
-     * @return bool          success/fail
592
-     */
593
-    public static function process_resend($req_data)
594
-    {
595
-        self::_load_controller();
596
-
597
-        //if $msgID in this request then skip to the new resend_message
598
-        if (EE_Registry::instance()->REQ->get('MSG_ID')) {
599
-            return self::resend_message();
600
-        }
601
-
602
-        //make sure any incoming request data is set on the REQ so that it gets picked up later.
603
-        $req_data = (array)$req_data;
604
-        foreach ($req_data as $request_key => $request_value) {
605
-            EE_Registry::instance()->REQ->set($request_key, $request_value);
606
-        }
607
-
608
-        if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) {
609
-            return false;
610
-        }
611
-
612
-        try {
613
-            self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send);
614
-            self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
615
-        } catch (EE_Error $e) {
616
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
617
-            return false;
618
-        }
619
-        EE_Error::add_success(
620
-            __('Messages have been successfully queued for generation and sending.', 'event_espresso')
621
-        );
622
-        return true; //everything got queued.
623
-    }
624
-
625
-
626
-    /**
627
-     * Message triggers for a resending already sent message(s) (via EE_Message list table)
628
-     *
629
-     * @return bool
630
-     */
631
-    public static function resend_message()
632
-    {
633
-        self::_load_controller();
634
-
635
-        $msgID = EE_Registry::instance()->REQ->get('MSG_ID');
636
-        if (! $msgID) {
637
-            EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request',
638
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
639
-            return false;
640
-        }
641
-
642
-        self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID);
643
-
644
-        //setup success message.
645
-        $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
646
-        EE_Error::add_success(sprintf(
647
-            _n(
648
-                'There was %d message queued for resending.',
649
-                'There were %d messages queued for resending.',
650
-                $count_ready_for_resend,
651
-                'event_espresso'
652
-            ),
653
-            $count_ready_for_resend
654
-        ));
655
-        return true;
656
-    }
657
-
658
-
659
-    /**
660
-     * Message triggers for manual payment applied by admin
661
-     *
662
-     * @param  EE_Payment $payment EE_payment object
663
-     * @return bool              success/fail
664
-     */
665
-    public static function process_admin_payment(EE_Payment $payment)
666
-    {
667
-        EE_Registry::instance()->load_helper('MSG_Template');
668
-        //we need to get the transaction object
669
-        $transaction = $payment->transaction();
670
-        if ($transaction instanceof EE_Transaction) {
671
-            $data         = array($transaction, $payment);
672
-            $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
673
-
674
-            //if payment amount is less than 0 then switch to payment_refund message type.
675
-            $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
676
-
677
-            //if payment_refund is selected, but the status is NOT accepted.  Then change message type to false so NO message notification goes out.
678
-            $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type;
679
-
680
-            self::_load_controller();
681
-
682
-            self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
683
-
684
-            //get count of queued for generation
685
-            $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array(
686
-                EEM_Message::status_incomplete,
687
-                EEM_Message::status_idle,
688
-            ));
689
-
690
-            if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) {
691
-                add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
692
-                return true;
693
-            } else {
694
-                $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending());
695
-                /**
696
-                 * Verify that there are actually errors.  If not then we return a success message because the queue might have been emptied due to successful
697
-                 * IMMEDIATE generation.
698
-                 */
699
-                if ($count_failed > 0) {
700
-                    EE_Error::add_error(sprintf(
701
-                        _n(
702
-                            'The payment notification generation failed.',
703
-                            '%d payment notifications failed being sent.',
704
-                            $count_failed,
705
-                            'event_espresso'
706
-                        ),
707
-                        $count_failed
708
-                    ), __FILE__, __FUNCTION__, __LINE__);
709
-
710
-                    return false;
711
-                } else {
712
-                    add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
713
-                    return true;
714
-                }
715
-            }
716
-        } else {
717
-            EE_Error::add_error(
718
-                'Unable to generate the payment notification because the given value for the transaction is invalid.',
719
-                'event_espresso'
720
-            );
721
-            return false;
722
-        }
723
-    }
724
-
725
-
726
-    /**
727
-     * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger
728
-     *
729
-     * @since   4.3.0
730
-     * @param  EE_Registration[] $registrations an array of EE_Registration objects
731
-     * @param  int               $grp_id        a specific message template group id.
732
-     * @return void
733
-     */
734
-    public static function send_newsletter_message($registrations, $grp_id)
735
-    {
736
-        //make sure mtp is id and set it in the EE_Request Handler later messages setup.
737
-        EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id);
738
-        self::_load_controller();
739
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations);
740
-    }
741
-
742
-
743
-    /**
744
-     * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url
745
-     *
746
-     * @since   4.3.0
747
-     * @param    string          $registration_message_trigger_url
748
-     * @param    EE_Registration $registration
749
-     * @param string             $messenger
750
-     * @param string             $message_type
751
-     * @return    string
752
-     */
753
-    public static function registration_message_trigger_url(
754
-        $registration_message_trigger_url,
755
-        EE_Registration $registration,
756
-        $messenger = 'html',
757
-        $message_type = 'invoice'
758
-    ) {
759
-        // whitelist $messenger
760
-        switch ($messenger) {
761
-            case 'pdf' :
762
-                $sending_messenger    = 'pdf';
763
-                $generating_messenger = 'html';
764
-                break;
765
-            case 'html' :
766
-            default :
767
-                $sending_messenger    = 'html';
768
-                $generating_messenger = 'html';
769
-                break;
770
-        }
771
-        // whitelist $message_type
772
-        switch ($message_type) {
773
-            case 'receipt' :
774
-                $message_type = 'receipt';
775
-                break;
776
-            case 'invoice' :
777
-            default :
778
-                $message_type = 'invoice';
779
-                break;
780
-        }
781
-        // verify that both the messenger AND the message type are active
782
-        if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) {
783
-            //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?)
784
-            $template_query_params = array(
785
-                'MTP_is_active'    => true,
786
-                'MTP_messenger'    => $generating_messenger,
787
-                'MTP_message_type' => $message_type,
788
-                'Event.EVT_ID'     => $registration->event_ID(),
789
-            );
790
-            //get the message template group.
791
-            $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
792
-            //if we don't have an EE_Message_Template_Group then return
793
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
794
-                // remove EVT_ID from query params so that global templates get picked up
795
-                unset($template_query_params['Event.EVT_ID']);
796
-                //get global template as the fallback
797
-                $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
798
-            }
799
-            //if we don't have an EE_Message_Template_Group then return
800
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
801
-                return '';
802
-            }
803
-            // generate the URL
804
-            $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger(
805
-                $sending_messenger,
806
-                $generating_messenger,
807
-                'purchaser',
808
-                $message_type,
809
-                $registration,
810
-                $msg_template_group->ID(),
811
-                $registration->transaction_ID()
812
-            );
813
-
814
-        }
815
-        return $registration_message_trigger_url;
816
-    }
817
-
818
-
819
-    /**
820
-     * Use to generate and return a message preview!
821
-     *
822
-     * @param  string $type      This should correspond with a valid message type
823
-     * @param  string $context   This should correspond with a valid context for the message type
824
-     * @param  string $messenger This should correspond with a valid messenger.
825
-     * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
826
-     *                           preview
827
-     * @return bool|string The body of the message or if send is requested, sends.
828
-     * @throws EE_Error
829
-     */
830
-    public static function preview_message($type, $context, $messenger, $send = false)
831
-    {
832
-        self::_load_controller();
833
-        $mtg                     = new EE_Message_To_Generate(
834
-            $messenger,
835
-            $type,
836
-            array(),
837
-            $context,
838
-            true
839
-        );
840
-        $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send);
841
-        if ($generated_preview_queue instanceof EE_Messages_Queue) {
842
-            $content = $generated_preview_queue->get_message_repository()->current()->content();
843
-            //if the current message was persisted to the db (which will happen with any extra fields on a message) then
844
-            //let's delete it because we don't need previews cluttering up the db.
845
-            if ($generated_preview_queue->get_message_repository()->current()->ID() > 0
846
-                && $generated_preview_queue->get_message_repository()->current()->STS_ID() !== EEM_Message::status_failed
847
-            ) {
848
-                $generated_preview_queue->get_message_repository()->delete();
849
-            }
850
-            return $content;
851
-        } else {
852
-            return $generated_preview_queue;
853
-        }
854
-    }
855
-
856
-
857
-    /**
858
-     * This is a method that allows for sending a message using a messenger matching the string given and the provided
859
-     * EE_Message_Queue object.  The EE_Message_Queue object is used to create a single aggregate EE_Message via the
860
-     * content found in the EE_Message objects in the queue.
861
-     *
862
-     * @since 4.9.0
863
-     * @param string            $messenger            a string matching a valid active messenger in the system
864
-     * @param string            $message_type         Although it seems contrary to the name of the method, a message
865
-     *                                                type name is still required to send along the message type to the
866
-     *                                                messenger because this is used for determining what specific
867
-     *                                                variations might be loaded for the generated message.
868
-     * @param EE_Messages_Queue $queue
869
-     * @param string            $custom_subject       Can be used to set what the custom subject string will be on the
870
-     *                                                aggregate EE_Message object.
871
-     * @return bool          success or fail.
872
-     */
873
-    public static function send_message_with_messenger_only(
874
-        $messenger,
875
-        $message_type,
876
-        EE_Messages_Queue $queue,
877
-        $custom_subject = ''
878
-    ) {
879
-        self::_load_controller();
880
-        /** @type EE_Message_To_Generate_From_Queue $message_to_generate */
881
-        $message_to_generate = EE_Registry::instance()->load_lib(
882
-            'Message_To_Generate_From_Queue',
883
-            array(
884
-                $messenger,
885
-                $message_type,
886
-                $queue,
887
-                $custom_subject,
888
-            )
889
-        );
890
-        return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate);
891
-    }
892
-
893
-
894
-    /**
895
-     * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation)
896
-     *
897
-     * @since 4.9.0
898
-     * @param array $message_ids An array of message ids
899
-     * @return bool | EE_Messages_Queue     false if nothing was generated, EE_Messages_Queue containing generated
900
-     *              messages.
901
-     */
902
-    public static function generate_now($message_ids)
903
-    {
904
-        self::_load_controller();
905
-        $messages        = EEM_Message::instance()->get_all(
906
-            array(
907
-                0 => array(
908
-                    'MSG_ID' => array('IN', $message_ids),
909
-                    'STS_ID' => EEM_Message::status_incomplete,
910
-                ),
911
-            )
912
-        );
913
-        $generated_queue = false;
914
-        if ($messages) {
915
-            $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
916
-        }
917
-
918
-        if (! $generated_queue instanceof EE_Messages_Queue) {
919
-            EE_Error::add_error(
920
-                __('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.',
921
-                    'event_espresso'),
922
-                __FILE__, __FUNCTION__, __LINE__
923
-            );
924
-        }
925
-        return $generated_queue;
926
-    }
927
-
928
-
929
-    /**
930
-     * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or,
931
-     * EEM_Message::status_idle
932
-     *
933
-     * @since 4.9.0
934
-     * @param $message_ids
935
-     * @return bool | EE_Messages_Queue  false if no messages sent.
936
-     */
937
-    public static function send_now($message_ids)
938
-    {
939
-        self::_load_controller();
940
-        $messages   = EEM_Message::instance()->get_all(
941
-            array(
942
-                0 => array(
943
-                    'MSG_ID' => array('IN', $message_ids),
944
-                    'STS_ID' => array(
945
-                        'IN',
946
-                        array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry),
947
-                    ),
948
-                ),
949
-            )
950
-        );
951
-        $sent_queue = false;
952
-        if ($messages) {
953
-            $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
954
-        }
955
-
956
-        if (! $sent_queue instanceof EE_Messages_Queue) {
957
-            EE_Error::add_error(
958
-                __('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.',
959
-                    'event_espresso'),
960
-                __FILE__, __FUNCTION__, __LINE__
961
-            );
962
-        } else {
963
-            //can count how many sent by using the messages in the queue
964
-            $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent());
965
-            if ($sent_count > 0) {
966
-                EE_Error::add_success(
967
-                    sprintf(
968
-                        _n(
969
-                            'There was %d message successfully sent.',
970
-                            'There were %d messages successfully sent.',
971
-                            $sent_count,
972
-                            'event_espresso'
973
-                        ),
974
-                        $sent_count
975
-                    )
976
-                );
977
-            } else {
978
-                EE_Error::overwrite_errors();
979
-                EE_Error::add_error(
980
-                    __('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.
201
+				exit;
202
+			}
203
+		}
204
+		return;
205
+	}
206
+
207
+
208
+	/**
209
+	 *  This runs when the msg_url_trigger route has initiated.
210
+	 *
211
+	 * @since 4.5.0
212
+	 * @param WP $WP
213
+	 * @throws EE_Error
214
+	 * @return    void
215
+	 */
216
+	public function run($WP)
217
+	{
218
+		//ensure controller is loaded
219
+		self::_load_controller();
220
+		// attempt to process message
221
+		try {
222
+			/** @type EE_Message_To_Generate_From_Request $message_to_generate */
223
+			$message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
224
+			self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate);
225
+		} catch (EE_Error $e) {
226
+			$error_msg = __('Please note that a system message failed to send due to a technical issue.',
227
+				'event_espresso');
228
+			// add specific message for developers if WP_DEBUG in on
229
+			$error_msg .= '||' . $e->getMessage();
230
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
231
+		}
232
+	}
233
+
234
+
235
+	/**
236
+	 * This is triggered by the 'msg_cron_trigger' route.
237
+	 *
238
+	 * @param WP $WP
239
+	 */
240
+	public function execute_batch_request($WP)
241
+	{
242
+		$this->run_cron();
243
+		header('HTTP/1.1 200 OK');
244
+		exit();
245
+	}
246
+
247
+
248
+	/**
249
+	 * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp
250
+	 * request.
251
+	 */
252
+	public function run_cron()
253
+	{
254
+		self::_load_controller();
255
+		//get required vars
256
+		$cron_type     = EE_Registry::instance()->REQ->get('type');
257
+		$transient_key = EE_Registry::instance()->REQ->get('key');
258
+
259
+		//now let's verify transient, if not valid exit immediately
260
+		if (! get_transient($transient_key)) {
261
+			/**
262
+			 * trigger error so this gets in the error logs.  This is important because it happens on a non-user request.
263
+			 */
264
+			trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso'));
265
+		}
266
+
267
+		//if made it here, lets' delete the transient to keep the db clean
268
+		delete_transient($transient_key);
269
+
270
+		if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
271
+
272
+			$method = 'batch_' . $cron_type . '_from_queue';
273
+			if (method_exists(self::$_MSG_PROCESSOR, $method)) {
274
+				self::$_MSG_PROCESSOR->$method();
275
+			} else {
276
+				//no matching task
277
+				/**
278
+				 * trigger error so this gets in the error logs.  This is important because it happens on a non user request.
279
+				 */
280
+				trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'),
281
+					$cron_type)));
282
+			}
283
+		}
284
+
285
+		do_action('FHEE__EED_Messages__run_cron__end');
286
+	}
287
+
288
+
289
+	/**
290
+	 * This is used to retrieve the template pack for the given name.
291
+	 * Retrieved packs are cached on the static $_TMP_PACKS array.  If there is no class matching the given name then
292
+	 * the default template pack is returned.
293
+	 *
294
+	 * @deprecated 4.9.0  @see EEH_MSG_Template::get_template_pack()
295
+	 * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used
296
+	 *                                   in generating the Pack class name).
297
+	 * @return EE_Messages_Template_Pack
298
+	 */
299
+	public static function get_template_pack($template_pack_name)
300
+	{
301
+		EE_Registry::instance()->load_helper('MSG_Template');
302
+		return EEH_MSG_Template::get_template_pack($template_pack_name);
303
+	}
304
+
305
+
306
+	/**
307
+	 * Retrieves an array of all template packs.
308
+	 * Array is in the format array( 'dbref' => EE_Messages_Template_Pack )
309
+	 *
310
+	 * @deprecated 4.9.0  @see EEH_MSG_Template_Pack::get_template_pack_collection
311
+	 * @return EE_Messages_Template_Pack[]
312
+	 */
313
+	public static function get_template_packs()
314
+	{
315
+		EE_Registry::instance()->load_helper('MSG_Template');
316
+
317
+		//for backward compat, let's make sure this returns in the same format as originally.
318
+		$template_pack_collection = EEH_MSG_Template::get_template_pack_collection();
319
+		$template_pack_collection->rewind();
320
+		$template_packs = array();
321
+		while ($template_pack_collection->valid()) {
322
+			$template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current();
323
+			$template_pack_collection->next();
324
+		}
325
+		return $template_packs;
326
+	}
327
+
328
+
329
+	/**
330
+	 * This simply makes sure the autoloaders are registered for the EE_messages system.
331
+	 *
332
+	 * @since 4.5.0
333
+	 * @return void
334
+	 */
335
+	public static function set_autoloaders()
336
+	{
337
+		if (empty(self::$_MSG_PATHS)) {
338
+			self::_set_messages_paths();
339
+			foreach (self::$_MSG_PATHS as $path) {
340
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);
341
+			}
342
+			// add aliases
343
+			EEH_Autoloader::add_alias('EE_messages', 'EE_messages');
344
+			EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger');
345
+		}
346
+	}
347
+
348
+
349
+	/**
350
+	 * Take care of adding all the paths for the messages components to the $_MSG_PATHS property
351
+	 * for use by the Messages Autoloaders
352
+	 *
353
+	 * @since 4.5.0
354
+	 * @return void.
355
+	 */
356
+	protected static function _set_messages_paths()
357
+	{
358
+		$dir_ref = array(
359
+			'messages/message_type',
360
+			'messages/messenger',
361
+			'messages/defaults',
362
+			'messages/defaults/email',
363
+			'messages/data_class',
364
+			'messages/validators',
365
+			'messages/validators/email',
366
+			'messages/validators/html',
367
+			'shortcodes',
368
+		);
369
+		$paths   = array();
370
+		foreach ($dir_ref as $index => $dir) {
371
+			$paths[$index] = EE_LIBRARIES . $dir;
372
+		}
373
+		self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths);
374
+	}
375
+
376
+
377
+	/**
378
+	 * Takes care of loading dependencies
379
+	 *
380
+	 * @since 4.5.0
381
+	 * @return void
382
+	 */
383
+	protected static function _load_controller()
384
+	{
385
+		if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
386
+			EE_Registry::instance()->load_core('Request_Handler');
387
+			self::set_autoloaders();
388
+			self::$_EEMSG                    = EE_Registry::instance()->load_lib('messages');
389
+			self::$_MSG_PROCESSOR            = EE_Registry::instance()->load_lib('Messages_Processor');
390
+			self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
391
+		}
392
+	}
393
+
394
+
395
+	/**
396
+	 * @param EE_Transaction $transaction
397
+	 */
398
+	public static function payment_reminder(EE_Transaction $transaction)
399
+	{
400
+		self::_load_controller();
401
+		$data = array($transaction, null);
402
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data);
403
+	}
404
+
405
+
406
+	/**
407
+	 * Any messages triggers for after successful gateway payments should go in here.
408
+	 *
409
+	 * @param  EE_Transaction object
410
+	 * @param  EE_Payment     object
411
+	 * @return void
412
+	 */
413
+	public static function payment(EE_Transaction $transaction, EE_Payment $payment)
414
+	{
415
+		self::_load_controller();
416
+		$data = array($transaction, $payment);
417
+		EE_Registry::instance()->load_helper('MSG_Template');
418
+		$message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
419
+		//if payment amount is less than 0 then switch to payment_refund message type.
420
+		$message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
421
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
422
+	}
423
+
424
+
425
+	/**
426
+	 * @param EE_Transaction $transaction
427
+	 */
428
+	public static function cancelled_registration(EE_Transaction $transaction)
429
+	{
430
+		self::_load_controller();
431
+		$data = array($transaction, null);
432
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data);
433
+	}
434
+
435
+
436
+	/**
437
+	 * Trigger for Registration messages
438
+	 * Note that what registration message type is sent depends on what the reg status is for the registrations on the
439
+	 * incoming transaction.
440
+	 *
441
+	 * @param EE_Registration $registration
442
+	 * @param array           $extra_details
443
+	 * @return void
444
+	 */
445
+	public static function maybe_registration(EE_Registration $registration, $extra_details = array())
446
+	{
447
+
448
+		if (! self::_verify_registration_notification_send($registration, $extra_details)) {
449
+			//no messages please
450
+			return;
451
+		}
452
+
453
+
454
+		//get all registrations so we make sure we send messages for the right status.
455
+		$all_registrations = $registration->transaction()->registrations();
456
+
457
+		//cached array of statuses so we only trigger messages once per status.
458
+		$statuses_sent = array();
459
+		self::_load_controller();
460
+		$mtgs = array();
461
+
462
+		//loop through registrations and trigger messages once per status.
463
+		foreach ($all_registrations as $reg) {
464
+
465
+			//already triggered?
466
+			if (in_array($reg->status_ID(), $statuses_sent)) {
467
+				continue;
468
+			}
469
+
470
+			$message_type    = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID());
471
+			$mtgs            = array_merge(
472
+					$mtgs,
473
+					self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
474
+							$message_type,
475
+							array($registration->transaction(), null, $reg->status_ID())
476
+					)
477
+			);
478
+			$statuses_sent[] = $reg->status_ID();
479
+		}
480
+
481
+		if (count($statuses_sent) > 1) {
482
+			$mtgs = array_merge(
483
+				$mtgs,
484
+				self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
485
+					'registration_summary',
486
+					array($registration->transaction(), null)
487
+				)
488
+			);
489
+		}
490
+
491
+		//batch queue and initiate request
492
+		self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs);
493
+		self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
494
+	}
495
+
496
+
497
+	/**
498
+	 * This is a helper method used to very whether a registration notification should be sent or
499
+	 * not.  Prevents duplicate notifications going out for registration context notifications.
500
+	 *
501
+	 * @param EE_Registration $registration  [description]
502
+	 * @param array           $extra_details [description]
503
+	 * @return bool          true = send away, false = nope halt the presses.
504
+	 */
505
+	protected static function _verify_registration_notification_send(
506
+		EE_Registration $registration,
507
+		$extra_details = array()
508
+	) {
509
+		//self::log(
510
+		//	__CLASS__, __FUNCTION__, __LINE__,
511
+		//	$registration->transaction(),
512
+		//	array( '$extra_details' => $extra_details )
513
+		//);
514
+		// currently only using this to send messages for the primary registrant
515
+		if (! $registration->is_primary_registrant()) {
516
+			return false;
517
+		}
518
+		// first we check if we're in admin and not doing front ajax
519
+		if (is_admin() && ! EE_FRONT_AJAX) {
520
+			//make sure appropriate admin params are set for sending messages
521
+			if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) {
522
+				//no messages sent please.
523
+				return false;
524
+			}
525
+		} else {
526
+			// frontend request (either regular or via AJAX)
527
+			// TXN is NOT finalized ?
528
+			if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
529
+				return false;
530
+			}
531
+			// return visit but nothing changed ???
532
+			if (
533
+				isset($extra_details['revisit'], $extra_details['status_updates']) &&
534
+				$extra_details['revisit'] && ! $extra_details['status_updates']
535
+			) {
536
+				return false;
537
+			}
538
+			// NOT sending messages && reg status is something other than "Not-Approved"
539
+			if (
540
+				! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) &&
541
+				$registration->status_ID() !== EEM_Registration::status_id_not_approved
542
+			) {
543
+				return false;
544
+			}
545
+		}
546
+		// release the kraken
547
+		return true;
548
+	}
549
+
550
+
551
+	/**
552
+	 * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that
553
+	 * status id.
554
+	 *
555
+	 * @deprecated 4.9.0  Use EEH_MSG_Template::reg_status_to_message_type_array()
556
+	 *                    or EEH_MSG_Template::convert_reg_status_to_message_type
557
+	 * @param string $reg_status
558
+	 * @return array
559
+	 */
560
+	protected static function _get_reg_status_array($reg_status = '')
561
+	{
562
+		EE_Registry::instance()->load_helper('MSG_Template');
563
+		return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
564
+			? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
565
+			: EEH_MSG_Template::reg_status_to_message_type_array();
566
+	}
567
+
568
+
569
+	/**
570
+	 * Simply returns the payment message type for the given payment status.
571
+	 *
572
+	 * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array
573
+	 *                   or EEH_MSG_Template::convert_payment_status_to_message_type
574
+	 * @param string $payment_status The payment status being matched.
575
+	 * @return string|bool The payment message type slug matching the status or false if no match.
576
+	 */
577
+	protected static function _get_payment_message_type($payment_status)
578
+	{
579
+		EE_Registry::instance()->load_helper('MSG_Template');
580
+		return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
581
+			? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
582
+			: false;
583
+	}
584
+
585
+
586
+	/**
587
+	 * Message triggers for a resending already sent message(s) (via EE_Message list table)
588
+	 *
589
+	 * @access public
590
+	 * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages
591
+	 * @return bool          success/fail
592
+	 */
593
+	public static function process_resend($req_data)
594
+	{
595
+		self::_load_controller();
596
+
597
+		//if $msgID in this request then skip to the new resend_message
598
+		if (EE_Registry::instance()->REQ->get('MSG_ID')) {
599
+			return self::resend_message();
600
+		}
601
+
602
+		//make sure any incoming request data is set on the REQ so that it gets picked up later.
603
+		$req_data = (array)$req_data;
604
+		foreach ($req_data as $request_key => $request_value) {
605
+			EE_Registry::instance()->REQ->set($request_key, $request_value);
606
+		}
607
+
608
+		if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) {
609
+			return false;
610
+		}
611
+
612
+		try {
613
+			self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send);
614
+			self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
615
+		} catch (EE_Error $e) {
616
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
617
+			return false;
618
+		}
619
+		EE_Error::add_success(
620
+			__('Messages have been successfully queued for generation and sending.', 'event_espresso')
621
+		);
622
+		return true; //everything got queued.
623
+	}
624
+
625
+
626
+	/**
627
+	 * Message triggers for a resending already sent message(s) (via EE_Message list table)
628
+	 *
629
+	 * @return bool
630
+	 */
631
+	public static function resend_message()
632
+	{
633
+		self::_load_controller();
634
+
635
+		$msgID = EE_Registry::instance()->REQ->get('MSG_ID');
636
+		if (! $msgID) {
637
+			EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request',
638
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
639
+			return false;
640
+		}
641
+
642
+		self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID);
643
+
644
+		//setup success message.
645
+		$count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
646
+		EE_Error::add_success(sprintf(
647
+			_n(
648
+				'There was %d message queued for resending.',
649
+				'There were %d messages queued for resending.',
650
+				$count_ready_for_resend,
651
+				'event_espresso'
652
+			),
653
+			$count_ready_for_resend
654
+		));
655
+		return true;
656
+	}
657
+
658
+
659
+	/**
660
+	 * Message triggers for manual payment applied by admin
661
+	 *
662
+	 * @param  EE_Payment $payment EE_payment object
663
+	 * @return bool              success/fail
664
+	 */
665
+	public static function process_admin_payment(EE_Payment $payment)
666
+	{
667
+		EE_Registry::instance()->load_helper('MSG_Template');
668
+		//we need to get the transaction object
669
+		$transaction = $payment->transaction();
670
+		if ($transaction instanceof EE_Transaction) {
671
+			$data         = array($transaction, $payment);
672
+			$message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
673
+
674
+			//if payment amount is less than 0 then switch to payment_refund message type.
675
+			$message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
676
+
677
+			//if payment_refund is selected, but the status is NOT accepted.  Then change message type to false so NO message notification goes out.
678
+			$message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type;
679
+
680
+			self::_load_controller();
681
+
682
+			self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
683
+
684
+			//get count of queued for generation
685
+			$count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array(
686
+				EEM_Message::status_incomplete,
687
+				EEM_Message::status_idle,
688
+			));
689
+
690
+			if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) {
691
+				add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
692
+				return true;
693
+			} else {
694
+				$count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending());
695
+				/**
696
+				 * Verify that there are actually errors.  If not then we return a success message because the queue might have been emptied due to successful
697
+				 * IMMEDIATE generation.
698
+				 */
699
+				if ($count_failed > 0) {
700
+					EE_Error::add_error(sprintf(
701
+						_n(
702
+							'The payment notification generation failed.',
703
+							'%d payment notifications failed being sent.',
704
+							$count_failed,
705
+							'event_espresso'
706
+						),
707
+						$count_failed
708
+					), __FILE__, __FUNCTION__, __LINE__);
709
+
710
+					return false;
711
+				} else {
712
+					add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
713
+					return true;
714
+				}
715
+			}
716
+		} else {
717
+			EE_Error::add_error(
718
+				'Unable to generate the payment notification because the given value for the transaction is invalid.',
719
+				'event_espresso'
720
+			);
721
+			return false;
722
+		}
723
+	}
724
+
725
+
726
+	/**
727
+	 * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger
728
+	 *
729
+	 * @since   4.3.0
730
+	 * @param  EE_Registration[] $registrations an array of EE_Registration objects
731
+	 * @param  int               $grp_id        a specific message template group id.
732
+	 * @return void
733
+	 */
734
+	public static function send_newsletter_message($registrations, $grp_id)
735
+	{
736
+		//make sure mtp is id and set it in the EE_Request Handler later messages setup.
737
+		EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id);
738
+		self::_load_controller();
739
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations);
740
+	}
741
+
742
+
743
+	/**
744
+	 * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url
745
+	 *
746
+	 * @since   4.3.0
747
+	 * @param    string          $registration_message_trigger_url
748
+	 * @param    EE_Registration $registration
749
+	 * @param string             $messenger
750
+	 * @param string             $message_type
751
+	 * @return    string
752
+	 */
753
+	public static function registration_message_trigger_url(
754
+		$registration_message_trigger_url,
755
+		EE_Registration $registration,
756
+		$messenger = 'html',
757
+		$message_type = 'invoice'
758
+	) {
759
+		// whitelist $messenger
760
+		switch ($messenger) {
761
+			case 'pdf' :
762
+				$sending_messenger    = 'pdf';
763
+				$generating_messenger = 'html';
764
+				break;
765
+			case 'html' :
766
+			default :
767
+				$sending_messenger    = 'html';
768
+				$generating_messenger = 'html';
769
+				break;
770
+		}
771
+		// whitelist $message_type
772
+		switch ($message_type) {
773
+			case 'receipt' :
774
+				$message_type = 'receipt';
775
+				break;
776
+			case 'invoice' :
777
+			default :
778
+				$message_type = 'invoice';
779
+				break;
780
+		}
781
+		// verify that both the messenger AND the message type are active
782
+		if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) {
783
+			//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?)
784
+			$template_query_params = array(
785
+				'MTP_is_active'    => true,
786
+				'MTP_messenger'    => $generating_messenger,
787
+				'MTP_message_type' => $message_type,
788
+				'Event.EVT_ID'     => $registration->event_ID(),
789
+			);
790
+			//get the message template group.
791
+			$msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
792
+			//if we don't have an EE_Message_Template_Group then return
793
+			if (! $msg_template_group instanceof EE_Message_Template_Group) {
794
+				// remove EVT_ID from query params so that global templates get picked up
795
+				unset($template_query_params['Event.EVT_ID']);
796
+				//get global template as the fallback
797
+				$msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
798
+			}
799
+			//if we don't have an EE_Message_Template_Group then return
800
+			if (! $msg_template_group instanceof EE_Message_Template_Group) {
801
+				return '';
802
+			}
803
+			// generate the URL
804
+			$registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger(
805
+				$sending_messenger,
806
+				$generating_messenger,
807
+				'purchaser',
808
+				$message_type,
809
+				$registration,
810
+				$msg_template_group->ID(),
811
+				$registration->transaction_ID()
812
+			);
813
+
814
+		}
815
+		return $registration_message_trigger_url;
816
+	}
817
+
818
+
819
+	/**
820
+	 * Use to generate and return a message preview!
821
+	 *
822
+	 * @param  string $type      This should correspond with a valid message type
823
+	 * @param  string $context   This should correspond with a valid context for the message type
824
+	 * @param  string $messenger This should correspond with a valid messenger.
825
+	 * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
826
+	 *                           preview
827
+	 * @return bool|string The body of the message or if send is requested, sends.
828
+	 * @throws EE_Error
829
+	 */
830
+	public static function preview_message($type, $context, $messenger, $send = false)
831
+	{
832
+		self::_load_controller();
833
+		$mtg                     = new EE_Message_To_Generate(
834
+			$messenger,
835
+			$type,
836
+			array(),
837
+			$context,
838
+			true
839
+		);
840
+		$generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send);
841
+		if ($generated_preview_queue instanceof EE_Messages_Queue) {
842
+			$content = $generated_preview_queue->get_message_repository()->current()->content();
843
+			//if the current message was persisted to the db (which will happen with any extra fields on a message) then
844
+			//let's delete it because we don't need previews cluttering up the db.
845
+			if ($generated_preview_queue->get_message_repository()->current()->ID() > 0
846
+				&& $generated_preview_queue->get_message_repository()->current()->STS_ID() !== EEM_Message::status_failed
847
+			) {
848
+				$generated_preview_queue->get_message_repository()->delete();
849
+			}
850
+			return $content;
851
+		} else {
852
+			return $generated_preview_queue;
853
+		}
854
+	}
855
+
856
+
857
+	/**
858
+	 * This is a method that allows for sending a message using a messenger matching the string given and the provided
859
+	 * EE_Message_Queue object.  The EE_Message_Queue object is used to create a single aggregate EE_Message via the
860
+	 * content found in the EE_Message objects in the queue.
861
+	 *
862
+	 * @since 4.9.0
863
+	 * @param string            $messenger            a string matching a valid active messenger in the system
864
+	 * @param string            $message_type         Although it seems contrary to the name of the method, a message
865
+	 *                                                type name is still required to send along the message type to the
866
+	 *                                                messenger because this is used for determining what specific
867
+	 *                                                variations might be loaded for the generated message.
868
+	 * @param EE_Messages_Queue $queue
869
+	 * @param string            $custom_subject       Can be used to set what the custom subject string will be on the
870
+	 *                                                aggregate EE_Message object.
871
+	 * @return bool          success or fail.
872
+	 */
873
+	public static function send_message_with_messenger_only(
874
+		$messenger,
875
+		$message_type,
876
+		EE_Messages_Queue $queue,
877
+		$custom_subject = ''
878
+	) {
879
+		self::_load_controller();
880
+		/** @type EE_Message_To_Generate_From_Queue $message_to_generate */
881
+		$message_to_generate = EE_Registry::instance()->load_lib(
882
+			'Message_To_Generate_From_Queue',
883
+			array(
884
+				$messenger,
885
+				$message_type,
886
+				$queue,
887
+				$custom_subject,
888
+			)
889
+		);
890
+		return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate);
891
+	}
892
+
893
+
894
+	/**
895
+	 * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation)
896
+	 *
897
+	 * @since 4.9.0
898
+	 * @param array $message_ids An array of message ids
899
+	 * @return bool | EE_Messages_Queue     false if nothing was generated, EE_Messages_Queue containing generated
900
+	 *              messages.
901
+	 */
902
+	public static function generate_now($message_ids)
903
+	{
904
+		self::_load_controller();
905
+		$messages        = EEM_Message::instance()->get_all(
906
+			array(
907
+				0 => array(
908
+					'MSG_ID' => array('IN', $message_ids),
909
+					'STS_ID' => EEM_Message::status_incomplete,
910
+				),
911
+			)
912
+		);
913
+		$generated_queue = false;
914
+		if ($messages) {
915
+			$generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
916
+		}
917
+
918
+		if (! $generated_queue instanceof EE_Messages_Queue) {
919
+			EE_Error::add_error(
920
+				__('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.',
921
+					'event_espresso'),
922
+				__FILE__, __FUNCTION__, __LINE__
923
+			);
924
+		}
925
+		return $generated_queue;
926
+	}
927
+
928
+
929
+	/**
930
+	 * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or,
931
+	 * EEM_Message::status_idle
932
+	 *
933
+	 * @since 4.9.0
934
+	 * @param $message_ids
935
+	 * @return bool | EE_Messages_Queue  false if no messages sent.
936
+	 */
937
+	public static function send_now($message_ids)
938
+	{
939
+		self::_load_controller();
940
+		$messages   = EEM_Message::instance()->get_all(
941
+			array(
942
+				0 => array(
943
+					'MSG_ID' => array('IN', $message_ids),
944
+					'STS_ID' => array(
945
+						'IN',
946
+						array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry),
947
+					),
948
+				),
949
+			)
950
+		);
951
+		$sent_queue = false;
952
+		if ($messages) {
953
+			$sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
954
+		}
955
+
956
+		if (! $sent_queue instanceof EE_Messages_Queue) {
957
+			EE_Error::add_error(
958
+				__('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.',
959
+					'event_espresso'),
960
+				__FILE__, __FUNCTION__, __LINE__
961
+			);
962
+		} else {
963
+			//can count how many sent by using the messages in the queue
964
+			$sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent());
965
+			if ($sent_count > 0) {
966
+				EE_Error::add_success(
967
+					sprintf(
968
+						_n(
969
+							'There was %d message successfully sent.',
970
+							'There were %d messages successfully sent.',
971
+							$sent_count,
972
+							'event_espresso'
973
+						),
974
+						$sent_count
975
+					)
976
+				);
977
+			} else {
978
+				EE_Error::overwrite_errors();
979
+				EE_Error::add_error(
980
+					__('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.
981 981
 					If there was an error, you can look at the messages in the message activity list table for any error messages.',
982
-                        'event_espresso'),
983
-                    __FILE__, __FUNCTION__, __LINE__
984
-                );
985
-            }
986
-        }
987
-        return $sent_queue;
988
-    }
989
-
990
-
991
-    /**
992
-     * This will queue the incoming message ids for resending.
993
-     * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued.
994
-     *
995
-     * @since 4.9.0
996
-     * @param array $message_ids An array of EE_Message IDs
997
-     * @return bool  true means messages were successfully queued for resending, false means none were queued for
998
-     *               resending.
999
-     */
1000
-    public static function queue_for_resending($message_ids)
1001
-    {
1002
-        self::_load_controller();
1003
-        self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids);
1004
-
1005
-        //get queue and count
1006
-        $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
1007
-
1008
-        if (
1009
-            $queue_count > 0
1010
-        ) {
1011
-            EE_Error::add_success(
1012
-                sprintf(
1013
-                    _n(
1014
-                        '%d message successfully queued for resending.',
1015
-                        '%d messages successfully queued for resending.',
1016
-                        $queue_count,
1017
-                        'event_espresso'
1018
-                    ),
1019
-                    $queue_count
1020
-                )
1021
-            );
1022
-            /**
1023
-             * @see filter usage in EE_Messages_Queue::initiate_request_by_priority
1024
-             */
1025
-        } elseif (
1026
-            apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true)
1027
-            || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
1028
-        ) {
1029
-            $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent);
1030
-            if ($queue_count > 0) {
1031
-                EE_Error::add_success(
1032
-                    sprintf(
1033
-                        _n(
1034
-                            '%d message successfully sent.',
1035
-                            '%d messages successfully sent.',
1036
-                            $queue_count,
1037
-                            'event_espresso'
1038
-                        ),
1039
-                        $queue_count
1040
-                    )
1041
-                );
1042
-            } else {
1043
-                EE_Error::add_error(
1044
-                    __('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.',
1045
-                        'event_espresso'),
1046
-                    __FILE__, __FUNCTION__, __LINE__
1047
-                );
1048
-            }
1049
-        } else {
1050
-            EE_Error::add_error(
1051
-                __('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.',
1052
-                    'event_espresso'),
1053
-                __FILE__, __FUNCTION__, __LINE__
1054
-            );
1055
-        }
1056
-        return (bool)$queue_count;
1057
-    }
1058
-
1059
-
1060
-    /**
1061
-     * debug
1062
-     *
1063
-     * @param string          $class
1064
-     * @param string          $func
1065
-     * @param string          $line
1066
-     * @param \EE_Transaction $transaction
1067
-     * @param array           $info
1068
-     * @param bool            $display_request
1069
-     */
1070
-    protected static function log(
1071
-        $class = '',
1072
-        $func = '',
1073
-        $line = '',
1074
-        EE_Transaction $transaction,
1075
-        $info = array(),
1076
-        $display_request = false
1077
-    ) {
1078
-        if (WP_DEBUG && false) {
1079
-            if ($transaction instanceof EE_Transaction) {
1080
-                // don't serialize objects
1081
-                $info                  = EEH_Debug_Tools::strip_objects($info);
1082
-                $info['TXN_status']    = $transaction->status_ID();
1083
-                $info['TXN_reg_steps'] = $transaction->reg_steps();
1084
-                if ($transaction->ID()) {
1085
-                    $index = 'EE_Transaction: ' . $transaction->ID();
1086
-                    EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1087
-                }
1088
-            }
1089
-        }
1090
-
1091
-    }
1092
-
1093
-
1094
-    /**
1095
-     *  Resets all the static properties in this class when called.
1096
-     */
1097
-    public static function reset()
1098
-    {
1099
-        self::$_EEMSG                    = null;
1100
-        self::$_message_resource_manager = null;
1101
-        self::$_MSG_PROCESSOR            = null;
1102
-        self::$_MSG_PATHS                = null;
1103
-        self::$_TMP_PACKS                = array();
1104
-    }
982
+						'event_espresso'),
983
+					__FILE__, __FUNCTION__, __LINE__
984
+				);
985
+			}
986
+		}
987
+		return $sent_queue;
988
+	}
989
+
990
+
991
+	/**
992
+	 * This will queue the incoming message ids for resending.
993
+	 * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued.
994
+	 *
995
+	 * @since 4.9.0
996
+	 * @param array $message_ids An array of EE_Message IDs
997
+	 * @return bool  true means messages were successfully queued for resending, false means none were queued for
998
+	 *               resending.
999
+	 */
1000
+	public static function queue_for_resending($message_ids)
1001
+	{
1002
+		self::_load_controller();
1003
+		self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids);
1004
+
1005
+		//get queue and count
1006
+		$queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
1007
+
1008
+		if (
1009
+			$queue_count > 0
1010
+		) {
1011
+			EE_Error::add_success(
1012
+				sprintf(
1013
+					_n(
1014
+						'%d message successfully queued for resending.',
1015
+						'%d messages successfully queued for resending.',
1016
+						$queue_count,
1017
+						'event_espresso'
1018
+					),
1019
+					$queue_count
1020
+				)
1021
+			);
1022
+			/**
1023
+			 * @see filter usage in EE_Messages_Queue::initiate_request_by_priority
1024
+			 */
1025
+		} elseif (
1026
+			apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true)
1027
+			|| EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
1028
+		) {
1029
+			$queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent);
1030
+			if ($queue_count > 0) {
1031
+				EE_Error::add_success(
1032
+					sprintf(
1033
+						_n(
1034
+							'%d message successfully sent.',
1035
+							'%d messages successfully sent.',
1036
+							$queue_count,
1037
+							'event_espresso'
1038
+						),
1039
+						$queue_count
1040
+					)
1041
+				);
1042
+			} else {
1043
+				EE_Error::add_error(
1044
+					__('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.',
1045
+						'event_espresso'),
1046
+					__FILE__, __FUNCTION__, __LINE__
1047
+				);
1048
+			}
1049
+		} else {
1050
+			EE_Error::add_error(
1051
+				__('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.',
1052
+					'event_espresso'),
1053
+				__FILE__, __FUNCTION__, __LINE__
1054
+			);
1055
+		}
1056
+		return (bool)$queue_count;
1057
+	}
1058
+
1059
+
1060
+	/**
1061
+	 * debug
1062
+	 *
1063
+	 * @param string          $class
1064
+	 * @param string          $func
1065
+	 * @param string          $line
1066
+	 * @param \EE_Transaction $transaction
1067
+	 * @param array           $info
1068
+	 * @param bool            $display_request
1069
+	 */
1070
+	protected static function log(
1071
+		$class = '',
1072
+		$func = '',
1073
+		$line = '',
1074
+		EE_Transaction $transaction,
1075
+		$info = array(),
1076
+		$display_request = false
1077
+	) {
1078
+		if (WP_DEBUG && false) {
1079
+			if ($transaction instanceof EE_Transaction) {
1080
+				// don't serialize objects
1081
+				$info                  = EEH_Debug_Tools::strip_objects($info);
1082
+				$info['TXN_status']    = $transaction->status_ID();
1083
+				$info['TXN_reg_steps'] = $transaction->reg_steps();
1084
+				if ($transaction->ID()) {
1085
+					$index = 'EE_Transaction: ' . $transaction->ID();
1086
+					EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1087
+				}
1088
+			}
1089
+		}
1090
+
1091
+	}
1092
+
1093
+
1094
+	/**
1095
+	 *  Resets all the static properties in this class when called.
1096
+	 */
1097
+	public static function reset()
1098
+	{
1099
+		self::$_EEMSG                    = null;
1100
+		self::$_message_resource_manager = null;
1101
+		self::$_MSG_PROCESSOR            = null;
1102
+		self::$_MSG_PATHS                = null;
1103
+		self::$_TMP_PACKS                = array();
1104
+	}
1105 1105
 
1106 1106
 }
1107 1107
 // End of file EED_Messages.module.php
Please login to merge, or discard this patch.