@@ -37,124 +37,124 @@ |
||
37 | 37 | * @since 4.0 |
38 | 38 | */ |
39 | 39 | if (function_exists('espresso_version')) { |
40 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
41 | - /** |
|
42 | - * espresso_duplicate_plugin_error |
|
43 | - * displays if more than one version of EE is activated at the same time. |
|
44 | - */ |
|
45 | - function espresso_duplicate_plugin_error() |
|
46 | - { |
|
47 | - ?> |
|
40 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
41 | + /** |
|
42 | + * espresso_duplicate_plugin_error |
|
43 | + * displays if more than one version of EE is activated at the same time. |
|
44 | + */ |
|
45 | + function espresso_duplicate_plugin_error() |
|
46 | + { |
|
47 | + ?> |
|
48 | 48 | <div class="error"> |
49 | 49 | <p> |
50 | 50 | <?php |
51 | - echo esc_html__( |
|
52 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
53 | - 'event_espresso' |
|
54 | - ); ?> |
|
51 | + echo esc_html__( |
|
52 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
53 | + 'event_espresso' |
|
54 | + ); ?> |
|
55 | 55 | </p> |
56 | 56 | </div> |
57 | 57 | <?php |
58 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
59 | - } |
|
60 | - } |
|
61 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
58 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
59 | + } |
|
60 | + } |
|
61 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | 62 | } else { |
63 | - define('EE_MIN_PHP_VER_REQUIRED', '7.4.0'); |
|
64 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
65 | - /** |
|
66 | - * espresso_minimum_php_version_error |
|
67 | - * |
|
68 | - * @return void |
|
69 | - */ |
|
70 | - function espresso_minimum_php_version_error() |
|
71 | - { |
|
72 | - ?> |
|
63 | + define('EE_MIN_PHP_VER_REQUIRED', '7.4.0'); |
|
64 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
65 | + /** |
|
66 | + * espresso_minimum_php_version_error |
|
67 | + * |
|
68 | + * @return void |
|
69 | + */ |
|
70 | + function espresso_minimum_php_version_error() |
|
71 | + { |
|
72 | + ?> |
|
73 | 73 | <div class="error"> |
74 | 74 | <p> |
75 | 75 | <?php |
76 | - printf( |
|
77 | - esc_html__( |
|
78 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
79 | - 'event_espresso' |
|
80 | - ), |
|
81 | - EE_MIN_PHP_VER_REQUIRED, |
|
82 | - PHP_VERSION, |
|
83 | - '<br/>', |
|
84 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
85 | - ); |
|
86 | - ?> |
|
76 | + printf( |
|
77 | + esc_html__( |
|
78 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
79 | + 'event_espresso' |
|
80 | + ), |
|
81 | + EE_MIN_PHP_VER_REQUIRED, |
|
82 | + PHP_VERSION, |
|
83 | + '<br/>', |
|
84 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
85 | + ); |
|
86 | + ?> |
|
87 | 87 | </p> |
88 | 88 | </div> |
89 | 89 | <?php |
90 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
91 | - } |
|
90 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
91 | + } |
|
92 | 92 | |
93 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
94 | - } else { |
|
95 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
93 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
94 | + } else { |
|
95 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
96 | 96 | |
97 | - require_once __DIR__ . '/vendor/autoload.php'; |
|
98 | - require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php'; |
|
97 | + require_once __DIR__ . '/vendor/autoload.php'; |
|
98 | + require_once __DIR__ . '/vendor/wp-graphql/wp-graphql/wp-graphql.php'; |
|
99 | 99 | |
100 | - /** |
|
101 | - * espresso_version |
|
102 | - * Returns the plugin version |
|
103 | - * |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - function espresso_version() |
|
107 | - { |
|
108 | - return apply_filters('FHEE__espresso__espresso_version', '5.0.1.rc.003'); |
|
109 | - } |
|
100 | + /** |
|
101 | + * espresso_version |
|
102 | + * Returns the plugin version |
|
103 | + * |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + function espresso_version() |
|
107 | + { |
|
108 | + return apply_filters('FHEE__espresso__espresso_version', '5.0.1.rc.003'); |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * espresso_plugin_activation |
|
113 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
114 | - */ |
|
115 | - function espresso_plugin_activation() |
|
116 | - { |
|
117 | - update_option('ee_espresso_activation', true); |
|
118 | - update_option('event-espresso-core_allow_tracking', 'no'); |
|
119 | - update_option('event-espresso-core_tracking_notice', 'hide'); |
|
120 | - // Run WP GraphQL activation callback |
|
121 | - graphql_activation_callback(); |
|
122 | - } |
|
111 | + /** |
|
112 | + * espresso_plugin_activation |
|
113 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
114 | + */ |
|
115 | + function espresso_plugin_activation() |
|
116 | + { |
|
117 | + update_option('ee_espresso_activation', true); |
|
118 | + update_option('event-espresso-core_allow_tracking', 'no'); |
|
119 | + update_option('event-espresso-core_tracking_notice', 'hide'); |
|
120 | + // Run WP GraphQL activation callback |
|
121 | + graphql_activation_callback(); |
|
122 | + } |
|
123 | 123 | |
124 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
124 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
125 | 125 | |
126 | - /** |
|
127 | - * espresso_plugin_deactivation |
|
128 | - */ |
|
129 | - function espresso_plugin_deactivation() |
|
130 | - { |
|
131 | - // Run WP GraphQL deactivation callback |
|
132 | - graphql_deactivation_callback(); |
|
133 | - delete_option('event-espresso-core_allow_tracking'); |
|
134 | - delete_option('event-espresso-core_tracking_notice'); |
|
135 | - } |
|
136 | - register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation'); |
|
126 | + /** |
|
127 | + * espresso_plugin_deactivation |
|
128 | + */ |
|
129 | + function espresso_plugin_deactivation() |
|
130 | + { |
|
131 | + // Run WP GraphQL deactivation callback |
|
132 | + graphql_deactivation_callback(); |
|
133 | + delete_option('event-espresso-core_allow_tracking'); |
|
134 | + delete_option('event-espresso-core_tracking_notice'); |
|
135 | + } |
|
136 | + register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation'); |
|
137 | 137 | |
138 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
139 | - bootstrap_espresso(); |
|
140 | - } |
|
138 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
139 | + bootstrap_espresso(); |
|
140 | + } |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | if (! function_exists('espresso_deactivate_plugin')) { |
144 | - /** |
|
145 | - * deactivate_plugin |
|
146 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
147 | - * |
|
148 | - * @access public |
|
149 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
150 | - * @return void |
|
151 | - */ |
|
152 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
153 | - { |
|
154 | - if (! function_exists('deactivate_plugins')) { |
|
155 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
156 | - } |
|
157 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
158 | - deactivate_plugins($plugin_basename); |
|
159 | - } |
|
144 | + /** |
|
145 | + * deactivate_plugin |
|
146 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
147 | + * |
|
148 | + * @access public |
|
149 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
150 | + * @return void |
|
151 | + */ |
|
152 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
153 | + { |
|
154 | + if (! function_exists('deactivate_plugins')) { |
|
155 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
156 | + } |
|
157 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
158 | + deactivate_plugins($plugin_basename); |
|
159 | + } |
|
160 | 160 | } |
@@ -16,456 +16,456 @@ |
||
16 | 16 | */ |
17 | 17 | class EEM_Payment_Method extends EEM_Base |
18 | 18 | { |
19 | - const scope_cart = 'CART'; |
|
20 | - |
|
21 | - const scope_admin = 'ADMIN'; |
|
22 | - |
|
23 | - const scope_api = 'API'; |
|
24 | - |
|
25 | - /** |
|
26 | - * @type EEM_Payment_Method |
|
27 | - */ |
|
28 | - protected static $_instance = null; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * private constructor to prevent direct creation |
|
33 | - * |
|
34 | - * @param null $timezone |
|
35 | - * @throws EE_Error |
|
36 | - */ |
|
37 | - protected function __construct($timezone = null) |
|
38 | - { |
|
39 | - $this->singular_item = esc_html__('Payment Method', 'event_espresso'); |
|
40 | - $this->plural_item = esc_html__('Payment Methods', 'event_espresso'); |
|
41 | - $this->_tables = [ |
|
42 | - 'Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID'), |
|
43 | - ]; |
|
44 | - $this->_fields = [ |
|
45 | - 'Payment_Method' => [ |
|
46 | - 'PMD_ID' => new EE_Primary_Key_Int_Field( |
|
47 | - 'PMD_ID', |
|
48 | - esc_html__('ID', 'event_espresso') |
|
49 | - ), |
|
50 | - 'PMD_type' => new EE_Plain_Text_Field( |
|
51 | - 'PMD_type', |
|
52 | - esc_html__('Payment Method Type', 'event_espresso'), |
|
53 | - false, |
|
54 | - 'Admin_Only' |
|
55 | - ), |
|
56 | - 'PMD_name' => new EE_Plain_Text_Field( |
|
57 | - 'PMD_name', |
|
58 | - esc_html__('Name', 'event_espresso'), |
|
59 | - false |
|
60 | - ), |
|
61 | - 'PMD_desc' => new EE_Post_Content_Field( |
|
62 | - 'PMD_desc', |
|
63 | - esc_html__('Description', 'event_espresso'), |
|
64 | - false, |
|
65 | - '' |
|
66 | - ), |
|
67 | - 'PMD_admin_name' => new EE_Plain_Text_Field( |
|
68 | - 'PMD_admin_name', |
|
69 | - esc_html__('Admin-Only Name', 'event_espresso'), |
|
70 | - true |
|
71 | - ), |
|
72 | - 'PMD_admin_desc' => new EE_Post_Content_Field( |
|
73 | - 'PMD_admin_desc', |
|
74 | - esc_html__('Admin-Only Description', 'event_espresso'), |
|
75 | - true |
|
76 | - ), |
|
77 | - 'PMD_slug' => new EE_Slug_Field( |
|
78 | - 'PMD_slug', |
|
79 | - esc_html__('Slug', 'event_espresso'), |
|
80 | - false |
|
81 | - ), |
|
82 | - 'PMD_order' => new EE_Integer_Field( |
|
83 | - 'PMD_order', |
|
84 | - esc_html__('Order', 'event_espresso'), |
|
85 | - false, |
|
86 | - 0 |
|
87 | - ), |
|
88 | - 'PMD_debug_mode' => new EE_Boolean_Field( |
|
89 | - 'PMD_debug_mode', |
|
90 | - esc_html__('Sandbox Mode On? (AKA: debug mode)', 'event_espresso'), |
|
91 | - false, |
|
92 | - false |
|
93 | - ), |
|
94 | - 'PMD_wp_user' => new EE_WP_User_Field( |
|
95 | - 'PMD_wp_user', |
|
96 | - esc_html__('Payment Method Creator ID', 'event_espresso'), |
|
97 | - false |
|
98 | - ), |
|
99 | - 'PMD_open_by_default' => new EE_Boolean_Field( |
|
100 | - 'PMD_open_by_default', |
|
101 | - esc_html__('Open by Default?', 'event_espresso'), |
|
102 | - false, |
|
103 | - false |
|
104 | - ), |
|
105 | - 'PMD_button_url' => new EE_Plain_Text_Field( |
|
106 | - 'PMD_button_url', |
|
107 | - esc_html__('Button URL', 'event_espresso'), |
|
108 | - true, |
|
109 | - '' |
|
110 | - ), |
|
111 | - 'PMD_scope' => new EE_Serialized_Text_Field( |
|
112 | - 'PMD_scope', |
|
113 | - esc_html__('Usable From?', 'event_espresso'), |
|
114 | - false, |
|
115 | - []// possible values currently are 'CART','ADMIN','API' |
|
116 | - ), |
|
117 | - ], |
|
118 | - ]; |
|
119 | - $this->_model_relations = [ |
|
120 | - 'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'), |
|
121 | - 'Payment' => new EE_Has_Many_Relation(), |
|
122 | - 'Transaction' => new EE_Has_Many_Relation(), |
|
123 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
124 | - ]; |
|
125 | - parent::__construct($timezone); |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * Gets one by the slug provided |
|
131 | - * |
|
132 | - * @param string $slug |
|
133 | - * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
|
134 | - * @throws EE_Error |
|
135 | - */ |
|
136 | - public function get_one_by_slug($slug) |
|
137 | - { |
|
138 | - return $this->get_one([['PMD_slug' => $slug]]); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * Gets all the acceptable scopes for payment methods. |
|
144 | - * Keys are their names as store din the DB, and values are nice names for displaying them |
|
145 | - * |
|
146 | - * @return array |
|
147 | - */ |
|
148 | - public function scopes() |
|
149 | - { |
|
150 | - return apply_filters( |
|
151 | - 'FHEE__EEM_Payment_Method__scopes', |
|
152 | - [ |
|
153 | - EEM_Payment_Method::scope_cart => esc_html__('Front-end Registration Page', 'event_espresso'), |
|
154 | - EEM_Payment_Method::scope_admin => esc_html__( |
|
155 | - 'Admin Registration Page (no online processing)', |
|
156 | - 'event_espresso' |
|
157 | - ), |
|
158 | - ] |
|
159 | - ); |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * Determines if this is an valid scope |
|
165 | - * |
|
166 | - * @param string $scope like one of EEM_Payment_Method::instance()->scopes() |
|
167 | - * @return boolean |
|
168 | - */ |
|
169 | - public function is_valid_scope($scope) |
|
170 | - { |
|
171 | - $scopes = $this->scopes(); |
|
172 | - if (isset($scopes[ $scope ])) { |
|
173 | - return true; |
|
174 | - } |
|
175 | - return false; |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * Gets all active payment methods |
|
181 | - * |
|
182 | - * @param string $scope one of |
|
183 | - * @param array $query_params |
|
184 | - * @return EE_Base_Class[]|EE_Payment_Method[] |
|
185 | - * @throws EE_Error |
|
186 | - */ |
|
187 | - public function get_all_active($scope = null, $query_params = []) |
|
188 | - { |
|
189 | - if (! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
190 | - $query_params['order_by'] = ['PMD_order' => 'ASC', 'PMD_ID' => 'ASC']; |
|
191 | - } |
|
192 | - return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params)); |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * Counts all active gateways in the specified scope |
|
198 | - * |
|
199 | - * @param string $scope one of EEM_Payment_Method::scope_* |
|
200 | - * @param array $query_params |
|
201 | - * @return int |
|
202 | - * @throws EE_Error |
|
203 | - */ |
|
204 | - public function count_active($scope = null, $query_params = []) |
|
205 | - { |
|
206 | - return $this->count($this->_get_query_params_for_all_active($scope, $query_params)); |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
212 | - * argument to get all active for a given scope |
|
213 | - * |
|
214 | - * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
215 | - * @param array $query_params |
|
216 | - * @return array |
|
217 | - * @throws EE_Error |
|
218 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
219 | - */ |
|
220 | - protected function _get_query_params_for_all_active($scope = null, $query_params = []) |
|
221 | - { |
|
222 | - if ($scope) { |
|
223 | - if ($this->is_valid_scope($scope)) { |
|
224 | - return array_replace_recursive([['PMD_scope' => ['LIKE', "%$scope%"]]], $query_params); |
|
225 | - } |
|
226 | - throw new EE_Error( |
|
227 | - sprintf( |
|
228 | - esc_html__("'%s' is not a valid scope for a payment method", 'event_espresso'), |
|
229 | - $scope |
|
230 | - ) |
|
231 | - ); |
|
232 | - } |
|
233 | - $acceptable_scopes = []; |
|
234 | - $count = 0; |
|
235 | - foreach ($this->scopes() as $scope_name => $desc) { |
|
236 | - $count++; |
|
237 | - $acceptable_scopes[ 'PMD_scope*' . $count ] = ['LIKE', '%' . $scope_name . '%']; |
|
238 | - } |
|
239 | - return array_replace_recursive([['OR*active_scope' => $acceptable_scopes]], $query_params); |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
245 | - * argument to get all active for a given scope |
|
246 | - * |
|
247 | - * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
248 | - * @param array $query_params |
|
249 | - * @return array |
|
250 | - * @throws EE_Error |
|
251 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
252 | - */ |
|
253 | - public function get_query_params_for_all_active($scope = null, $query_params = []) |
|
254 | - { |
|
255 | - return $this->_get_query_params_for_all_active($scope, $query_params); |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * Gets one active payment method. see @get_all_active for documentation |
|
261 | - * |
|
262 | - * @param string $scope |
|
263 | - * @param array $query_params |
|
264 | - * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
|
265 | - * @throws EE_Error |
|
266 | - */ |
|
267 | - public function get_one_active($scope = null, $query_params = []) |
|
268 | - { |
|
269 | - return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params)); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * Gets one payment method of that type, regardless of whether its active or not |
|
275 | - * |
|
276 | - * @param string $type |
|
277 | - * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
|
278 | - * @throws EE_Error |
|
279 | - */ |
|
280 | - public function get_one_of_type($type) |
|
281 | - { |
|
282 | - return $this->get_one([['PMD_type' => $type]]); |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * Overrides parent ot also check by the slug |
|
288 | - * |
|
289 | - * @param string|int|EE_Payment_Method $base_class_obj_or_id |
|
290 | - * @param boolean $ensure_is_in_db |
|
291 | - * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|int|string |
|
292 | - * @throws EE_Error |
|
293 | - * @see EEM_Base::ensure_is_obj() |
|
294 | - */ |
|
295 | - public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = false) |
|
296 | - { |
|
297 | - // first: check if it's a slug |
|
298 | - if (is_string($base_class_obj_or_id)) { |
|
299 | - $obj = $this->get_one_by_slug($base_class_obj_or_id); |
|
300 | - if ($obj) { |
|
301 | - return $obj; |
|
302 | - } |
|
303 | - } |
|
304 | - // ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID) |
|
305 | - try { |
|
306 | - return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db); |
|
307 | - } catch (EE_Error $e) { |
|
308 | - // handle it outside the catch |
|
309 | - } |
|
310 | - throw new EE_Error( |
|
311 | - sprintf( |
|
312 | - esc_html__("'%s' is neither a Payment Method ID, slug, nor object.", 'event_espresso'), |
|
313 | - $base_class_obj_or_id |
|
314 | - ) |
|
315 | - ); |
|
316 | - } |
|
317 | - |
|
318 | - |
|
319 | - /** |
|
320 | - * Gets the ID of this object, or if its a string finds the object's id |
|
321 | - * associated with that slug |
|
322 | - * |
|
323 | - * @param mixed $base_obj_or_id_or_slug |
|
324 | - * @return int |
|
325 | - * @throws EE_Error |
|
326 | - */ |
|
327 | - public function ensure_is_ID($base_obj_or_id_or_slug) |
|
328 | - { |
|
329 | - if (is_string($base_obj_or_id_or_slug)) { |
|
330 | - // assume it's a slug |
|
331 | - $base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug); |
|
332 | - } |
|
333 | - return parent::ensure_is_ID($base_obj_or_id_or_slug); |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * Verifies the button urls on all the passed payment methods have a valid button url. |
|
339 | - * If not, resets them to their default. |
|
340 | - * |
|
341 | - * @param EE_Payment_Method[] $payment_methods if NULL, defaults to all payment methods active in the cart |
|
342 | - * @throws EE_Error |
|
343 | - * @throws ReflectionException |
|
344 | - */ |
|
345 | - public function verify_button_urls($payment_methods = null) |
|
346 | - { |
|
347 | - $payment_methods = is_array($payment_methods) |
|
348 | - ? $payment_methods |
|
349 | - : $this->get_all_active(EEM_Payment_Method::scope_cart); |
|
350 | - foreach ($payment_methods as $payment_method) { |
|
351 | - try { |
|
352 | - // If there is really no button URL at all, or if the button URLs still point to decaf folder even |
|
353 | - // though this is a caffeinated install, reset it to the default. |
|
354 | - $current_button_url = $payment_method->button_url(); |
|
355 | - if ( |
|
356 | - empty($current_button_url) |
|
357 | - || ( |
|
358 | - strpos($current_button_url, 'decaf') !== false |
|
359 | - && strpos($payment_method->type_obj()->default_button_url(), 'decaf') === false |
|
360 | - ) |
|
361 | - ) { |
|
362 | - $payment_method->save( |
|
363 | - [ |
|
364 | - 'PMD_button_url' => $payment_method->type_obj()->default_button_url(), |
|
365 | - ] |
|
366 | - ); |
|
367 | - } |
|
368 | - } catch (EE_Error $e) { |
|
369 | - $payment_method->deactivate(); |
|
370 | - } |
|
371 | - } |
|
372 | - } |
|
373 | - |
|
374 | - |
|
375 | - /** |
|
376 | - * Overrides parent to not only turn wpdb results into EE_Payment_Method objects, |
|
377 | - * but also verifies the payment method type of each is a usable object. If not, |
|
378 | - * deactivate it, sets a notification, and deactivates it |
|
379 | - * |
|
380 | - * @param array $rows |
|
381 | - * @return EE_Payment_Method[] |
|
382 | - * @throws EE_Error |
|
383 | - * @throws InvalidDataTypeException |
|
384 | - * @throws ReflectionException |
|
385 | - */ |
|
386 | - protected function _create_objects($rows = []) |
|
387 | - { |
|
388 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
389 | - $payment_methods = parent::_create_objects($rows); |
|
390 | - /* @var $payment_methods EE_Payment_Method[] */ |
|
391 | - $usable_payment_methods = []; |
|
392 | - foreach ($payment_methods as $key => $payment_method) { |
|
393 | - if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { |
|
394 | - $usable_payment_methods[ $key ] = $payment_method; |
|
395 | - // some payment methods enqueue their scripts in EE_PMT_*::__construct |
|
396 | - // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue |
|
397 | - // its scripts). but for backwards-compat we should continue to do that |
|
398 | - $payment_method->type_obj(); |
|
399 | - } elseif ($payment_method->active()) { |
|
400 | - // only deactivate and notify the admin if the payment is active somewhere |
|
401 | - $payment_method->deactivate(); |
|
402 | - $payment_method->save(); |
|
403 | - do_action( |
|
404 | - 'AHEE__EEM_Payment_Method___create_objects_auto_deactivated_payment_method', |
|
405 | - $payment_method |
|
406 | - ); |
|
407 | - new PersistentAdminNotice( |
|
408 | - 'auto-deactivated-' . $payment_method->type(), |
|
409 | - sprintf( |
|
410 | - esc_html__( |
|
411 | - 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
|
412 | - 'event_espresso' |
|
413 | - ), |
|
414 | - $payment_method->admin_name(), |
|
415 | - '<br />', |
|
416 | - '<a href="' . admin_url('plugins.php') . '">', |
|
417 | - '</a>' |
|
418 | - ), |
|
419 | - true |
|
420 | - ); |
|
421 | - } |
|
422 | - } |
|
423 | - return $usable_payment_methods; |
|
424 | - } |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * Gets all the payment methods which can be used for transaction |
|
429 | - * (according to the relations between payment methods and events, and |
|
430 | - * the currencies used for the transaction and their relation to payment methods) |
|
431 | - * |
|
432 | - * @param EE_Transaction $transaction |
|
433 | - * @param string $scope @see EEM_Payment_Method::get_all_for_events |
|
434 | - * @return EE_Payment_Method[] |
|
435 | - * @throws EE_Error |
|
436 | - */ |
|
437 | - public function get_all_for_transaction($transaction, $scope) |
|
438 | - { |
|
439 | - // give addons a chance to override what payment methods are chosen based on the transaction |
|
440 | - return apply_filters( |
|
441 | - 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods', |
|
442 | - $this->get_all_active($scope, ['group_by' => 'PMD_type']), |
|
443 | - $transaction, |
|
444 | - $scope |
|
445 | - ); |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - /** |
|
450 | - * Returns the payment method used for the last payment made for a registration. |
|
451 | - * Note: if an offline payment method was selected on the related transaction then this will have no payment |
|
452 | - * methods returned. It will ONLY return a payment method for a PAYMENT recorded against the registration. |
|
453 | - * |
|
454 | - * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the |
|
455 | - * registration. |
|
456 | - * @return EE_Payment|null |
|
457 | - * @throws EE_Error |
|
458 | - */ |
|
459 | - public function get_last_used_for_registration($registration_or_reg_id) |
|
460 | - { |
|
461 | - $registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id); |
|
462 | - |
|
463 | - $query_params = [ |
|
464 | - 0 => [ |
|
465 | - 'Payment.Registration.REG_ID' => $registration_id, |
|
466 | - ], |
|
467 | - 'order_by' => ['Payment.PAY_ID' => 'DESC'], |
|
468 | - ]; |
|
469 | - return $this->get_one($query_params); |
|
470 | - } |
|
19 | + const scope_cart = 'CART'; |
|
20 | + |
|
21 | + const scope_admin = 'ADMIN'; |
|
22 | + |
|
23 | + const scope_api = 'API'; |
|
24 | + |
|
25 | + /** |
|
26 | + * @type EEM_Payment_Method |
|
27 | + */ |
|
28 | + protected static $_instance = null; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * private constructor to prevent direct creation |
|
33 | + * |
|
34 | + * @param null $timezone |
|
35 | + * @throws EE_Error |
|
36 | + */ |
|
37 | + protected function __construct($timezone = null) |
|
38 | + { |
|
39 | + $this->singular_item = esc_html__('Payment Method', 'event_espresso'); |
|
40 | + $this->plural_item = esc_html__('Payment Methods', 'event_espresso'); |
|
41 | + $this->_tables = [ |
|
42 | + 'Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID'), |
|
43 | + ]; |
|
44 | + $this->_fields = [ |
|
45 | + 'Payment_Method' => [ |
|
46 | + 'PMD_ID' => new EE_Primary_Key_Int_Field( |
|
47 | + 'PMD_ID', |
|
48 | + esc_html__('ID', 'event_espresso') |
|
49 | + ), |
|
50 | + 'PMD_type' => new EE_Plain_Text_Field( |
|
51 | + 'PMD_type', |
|
52 | + esc_html__('Payment Method Type', 'event_espresso'), |
|
53 | + false, |
|
54 | + 'Admin_Only' |
|
55 | + ), |
|
56 | + 'PMD_name' => new EE_Plain_Text_Field( |
|
57 | + 'PMD_name', |
|
58 | + esc_html__('Name', 'event_espresso'), |
|
59 | + false |
|
60 | + ), |
|
61 | + 'PMD_desc' => new EE_Post_Content_Field( |
|
62 | + 'PMD_desc', |
|
63 | + esc_html__('Description', 'event_espresso'), |
|
64 | + false, |
|
65 | + '' |
|
66 | + ), |
|
67 | + 'PMD_admin_name' => new EE_Plain_Text_Field( |
|
68 | + 'PMD_admin_name', |
|
69 | + esc_html__('Admin-Only Name', 'event_espresso'), |
|
70 | + true |
|
71 | + ), |
|
72 | + 'PMD_admin_desc' => new EE_Post_Content_Field( |
|
73 | + 'PMD_admin_desc', |
|
74 | + esc_html__('Admin-Only Description', 'event_espresso'), |
|
75 | + true |
|
76 | + ), |
|
77 | + 'PMD_slug' => new EE_Slug_Field( |
|
78 | + 'PMD_slug', |
|
79 | + esc_html__('Slug', 'event_espresso'), |
|
80 | + false |
|
81 | + ), |
|
82 | + 'PMD_order' => new EE_Integer_Field( |
|
83 | + 'PMD_order', |
|
84 | + esc_html__('Order', 'event_espresso'), |
|
85 | + false, |
|
86 | + 0 |
|
87 | + ), |
|
88 | + 'PMD_debug_mode' => new EE_Boolean_Field( |
|
89 | + 'PMD_debug_mode', |
|
90 | + esc_html__('Sandbox Mode On? (AKA: debug mode)', 'event_espresso'), |
|
91 | + false, |
|
92 | + false |
|
93 | + ), |
|
94 | + 'PMD_wp_user' => new EE_WP_User_Field( |
|
95 | + 'PMD_wp_user', |
|
96 | + esc_html__('Payment Method Creator ID', 'event_espresso'), |
|
97 | + false |
|
98 | + ), |
|
99 | + 'PMD_open_by_default' => new EE_Boolean_Field( |
|
100 | + 'PMD_open_by_default', |
|
101 | + esc_html__('Open by Default?', 'event_espresso'), |
|
102 | + false, |
|
103 | + false |
|
104 | + ), |
|
105 | + 'PMD_button_url' => new EE_Plain_Text_Field( |
|
106 | + 'PMD_button_url', |
|
107 | + esc_html__('Button URL', 'event_espresso'), |
|
108 | + true, |
|
109 | + '' |
|
110 | + ), |
|
111 | + 'PMD_scope' => new EE_Serialized_Text_Field( |
|
112 | + 'PMD_scope', |
|
113 | + esc_html__('Usable From?', 'event_espresso'), |
|
114 | + false, |
|
115 | + []// possible values currently are 'CART','ADMIN','API' |
|
116 | + ), |
|
117 | + ], |
|
118 | + ]; |
|
119 | + $this->_model_relations = [ |
|
120 | + 'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'), |
|
121 | + 'Payment' => new EE_Has_Many_Relation(), |
|
122 | + 'Transaction' => new EE_Has_Many_Relation(), |
|
123 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
124 | + ]; |
|
125 | + parent::__construct($timezone); |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * Gets one by the slug provided |
|
131 | + * |
|
132 | + * @param string $slug |
|
133 | + * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
|
134 | + * @throws EE_Error |
|
135 | + */ |
|
136 | + public function get_one_by_slug($slug) |
|
137 | + { |
|
138 | + return $this->get_one([['PMD_slug' => $slug]]); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * Gets all the acceptable scopes for payment methods. |
|
144 | + * Keys are their names as store din the DB, and values are nice names for displaying them |
|
145 | + * |
|
146 | + * @return array |
|
147 | + */ |
|
148 | + public function scopes() |
|
149 | + { |
|
150 | + return apply_filters( |
|
151 | + 'FHEE__EEM_Payment_Method__scopes', |
|
152 | + [ |
|
153 | + EEM_Payment_Method::scope_cart => esc_html__('Front-end Registration Page', 'event_espresso'), |
|
154 | + EEM_Payment_Method::scope_admin => esc_html__( |
|
155 | + 'Admin Registration Page (no online processing)', |
|
156 | + 'event_espresso' |
|
157 | + ), |
|
158 | + ] |
|
159 | + ); |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * Determines if this is an valid scope |
|
165 | + * |
|
166 | + * @param string $scope like one of EEM_Payment_Method::instance()->scopes() |
|
167 | + * @return boolean |
|
168 | + */ |
|
169 | + public function is_valid_scope($scope) |
|
170 | + { |
|
171 | + $scopes = $this->scopes(); |
|
172 | + if (isset($scopes[ $scope ])) { |
|
173 | + return true; |
|
174 | + } |
|
175 | + return false; |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * Gets all active payment methods |
|
181 | + * |
|
182 | + * @param string $scope one of |
|
183 | + * @param array $query_params |
|
184 | + * @return EE_Base_Class[]|EE_Payment_Method[] |
|
185 | + * @throws EE_Error |
|
186 | + */ |
|
187 | + public function get_all_active($scope = null, $query_params = []) |
|
188 | + { |
|
189 | + if (! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
190 | + $query_params['order_by'] = ['PMD_order' => 'ASC', 'PMD_ID' => 'ASC']; |
|
191 | + } |
|
192 | + return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params)); |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * Counts all active gateways in the specified scope |
|
198 | + * |
|
199 | + * @param string $scope one of EEM_Payment_Method::scope_* |
|
200 | + * @param array $query_params |
|
201 | + * @return int |
|
202 | + * @throws EE_Error |
|
203 | + */ |
|
204 | + public function count_active($scope = null, $query_params = []) |
|
205 | + { |
|
206 | + return $this->count($this->_get_query_params_for_all_active($scope, $query_params)); |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
212 | + * argument to get all active for a given scope |
|
213 | + * |
|
214 | + * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
215 | + * @param array $query_params |
|
216 | + * @return array |
|
217 | + * @throws EE_Error |
|
218 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
219 | + */ |
|
220 | + protected function _get_query_params_for_all_active($scope = null, $query_params = []) |
|
221 | + { |
|
222 | + if ($scope) { |
|
223 | + if ($this->is_valid_scope($scope)) { |
|
224 | + return array_replace_recursive([['PMD_scope' => ['LIKE', "%$scope%"]]], $query_params); |
|
225 | + } |
|
226 | + throw new EE_Error( |
|
227 | + sprintf( |
|
228 | + esc_html__("'%s' is not a valid scope for a payment method", 'event_espresso'), |
|
229 | + $scope |
|
230 | + ) |
|
231 | + ); |
|
232 | + } |
|
233 | + $acceptable_scopes = []; |
|
234 | + $count = 0; |
|
235 | + foreach ($this->scopes() as $scope_name => $desc) { |
|
236 | + $count++; |
|
237 | + $acceptable_scopes[ 'PMD_scope*' . $count ] = ['LIKE', '%' . $scope_name . '%']; |
|
238 | + } |
|
239 | + return array_replace_recursive([['OR*active_scope' => $acceptable_scopes]], $query_params); |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
245 | + * argument to get all active for a given scope |
|
246 | + * |
|
247 | + * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
248 | + * @param array $query_params |
|
249 | + * @return array |
|
250 | + * @throws EE_Error |
|
251 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
252 | + */ |
|
253 | + public function get_query_params_for_all_active($scope = null, $query_params = []) |
|
254 | + { |
|
255 | + return $this->_get_query_params_for_all_active($scope, $query_params); |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * Gets one active payment method. see @get_all_active for documentation |
|
261 | + * |
|
262 | + * @param string $scope |
|
263 | + * @param array $query_params |
|
264 | + * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
|
265 | + * @throws EE_Error |
|
266 | + */ |
|
267 | + public function get_one_active($scope = null, $query_params = []) |
|
268 | + { |
|
269 | + return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params)); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * Gets one payment method of that type, regardless of whether its active or not |
|
275 | + * |
|
276 | + * @param string $type |
|
277 | + * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
|
278 | + * @throws EE_Error |
|
279 | + */ |
|
280 | + public function get_one_of_type($type) |
|
281 | + { |
|
282 | + return $this->get_one([['PMD_type' => $type]]); |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * Overrides parent ot also check by the slug |
|
288 | + * |
|
289 | + * @param string|int|EE_Payment_Method $base_class_obj_or_id |
|
290 | + * @param boolean $ensure_is_in_db |
|
291 | + * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|int|string |
|
292 | + * @throws EE_Error |
|
293 | + * @see EEM_Base::ensure_is_obj() |
|
294 | + */ |
|
295 | + public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = false) |
|
296 | + { |
|
297 | + // first: check if it's a slug |
|
298 | + if (is_string($base_class_obj_or_id)) { |
|
299 | + $obj = $this->get_one_by_slug($base_class_obj_or_id); |
|
300 | + if ($obj) { |
|
301 | + return $obj; |
|
302 | + } |
|
303 | + } |
|
304 | + // ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID) |
|
305 | + try { |
|
306 | + return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db); |
|
307 | + } catch (EE_Error $e) { |
|
308 | + // handle it outside the catch |
|
309 | + } |
|
310 | + throw new EE_Error( |
|
311 | + sprintf( |
|
312 | + esc_html__("'%s' is neither a Payment Method ID, slug, nor object.", 'event_espresso'), |
|
313 | + $base_class_obj_or_id |
|
314 | + ) |
|
315 | + ); |
|
316 | + } |
|
317 | + |
|
318 | + |
|
319 | + /** |
|
320 | + * Gets the ID of this object, or if its a string finds the object's id |
|
321 | + * associated with that slug |
|
322 | + * |
|
323 | + * @param mixed $base_obj_or_id_or_slug |
|
324 | + * @return int |
|
325 | + * @throws EE_Error |
|
326 | + */ |
|
327 | + public function ensure_is_ID($base_obj_or_id_or_slug) |
|
328 | + { |
|
329 | + if (is_string($base_obj_or_id_or_slug)) { |
|
330 | + // assume it's a slug |
|
331 | + $base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug); |
|
332 | + } |
|
333 | + return parent::ensure_is_ID($base_obj_or_id_or_slug); |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * Verifies the button urls on all the passed payment methods have a valid button url. |
|
339 | + * If not, resets them to their default. |
|
340 | + * |
|
341 | + * @param EE_Payment_Method[] $payment_methods if NULL, defaults to all payment methods active in the cart |
|
342 | + * @throws EE_Error |
|
343 | + * @throws ReflectionException |
|
344 | + */ |
|
345 | + public function verify_button_urls($payment_methods = null) |
|
346 | + { |
|
347 | + $payment_methods = is_array($payment_methods) |
|
348 | + ? $payment_methods |
|
349 | + : $this->get_all_active(EEM_Payment_Method::scope_cart); |
|
350 | + foreach ($payment_methods as $payment_method) { |
|
351 | + try { |
|
352 | + // If there is really no button URL at all, or if the button URLs still point to decaf folder even |
|
353 | + // though this is a caffeinated install, reset it to the default. |
|
354 | + $current_button_url = $payment_method->button_url(); |
|
355 | + if ( |
|
356 | + empty($current_button_url) |
|
357 | + || ( |
|
358 | + strpos($current_button_url, 'decaf') !== false |
|
359 | + && strpos($payment_method->type_obj()->default_button_url(), 'decaf') === false |
|
360 | + ) |
|
361 | + ) { |
|
362 | + $payment_method->save( |
|
363 | + [ |
|
364 | + 'PMD_button_url' => $payment_method->type_obj()->default_button_url(), |
|
365 | + ] |
|
366 | + ); |
|
367 | + } |
|
368 | + } catch (EE_Error $e) { |
|
369 | + $payment_method->deactivate(); |
|
370 | + } |
|
371 | + } |
|
372 | + } |
|
373 | + |
|
374 | + |
|
375 | + /** |
|
376 | + * Overrides parent to not only turn wpdb results into EE_Payment_Method objects, |
|
377 | + * but also verifies the payment method type of each is a usable object. If not, |
|
378 | + * deactivate it, sets a notification, and deactivates it |
|
379 | + * |
|
380 | + * @param array $rows |
|
381 | + * @return EE_Payment_Method[] |
|
382 | + * @throws EE_Error |
|
383 | + * @throws InvalidDataTypeException |
|
384 | + * @throws ReflectionException |
|
385 | + */ |
|
386 | + protected function _create_objects($rows = []) |
|
387 | + { |
|
388 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
389 | + $payment_methods = parent::_create_objects($rows); |
|
390 | + /* @var $payment_methods EE_Payment_Method[] */ |
|
391 | + $usable_payment_methods = []; |
|
392 | + foreach ($payment_methods as $key => $payment_method) { |
|
393 | + if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { |
|
394 | + $usable_payment_methods[ $key ] = $payment_method; |
|
395 | + // some payment methods enqueue their scripts in EE_PMT_*::__construct |
|
396 | + // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue |
|
397 | + // its scripts). but for backwards-compat we should continue to do that |
|
398 | + $payment_method->type_obj(); |
|
399 | + } elseif ($payment_method->active()) { |
|
400 | + // only deactivate and notify the admin if the payment is active somewhere |
|
401 | + $payment_method->deactivate(); |
|
402 | + $payment_method->save(); |
|
403 | + do_action( |
|
404 | + 'AHEE__EEM_Payment_Method___create_objects_auto_deactivated_payment_method', |
|
405 | + $payment_method |
|
406 | + ); |
|
407 | + new PersistentAdminNotice( |
|
408 | + 'auto-deactivated-' . $payment_method->type(), |
|
409 | + sprintf( |
|
410 | + esc_html__( |
|
411 | + 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
|
412 | + 'event_espresso' |
|
413 | + ), |
|
414 | + $payment_method->admin_name(), |
|
415 | + '<br />', |
|
416 | + '<a href="' . admin_url('plugins.php') . '">', |
|
417 | + '</a>' |
|
418 | + ), |
|
419 | + true |
|
420 | + ); |
|
421 | + } |
|
422 | + } |
|
423 | + return $usable_payment_methods; |
|
424 | + } |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * Gets all the payment methods which can be used for transaction |
|
429 | + * (according to the relations between payment methods and events, and |
|
430 | + * the currencies used for the transaction and their relation to payment methods) |
|
431 | + * |
|
432 | + * @param EE_Transaction $transaction |
|
433 | + * @param string $scope @see EEM_Payment_Method::get_all_for_events |
|
434 | + * @return EE_Payment_Method[] |
|
435 | + * @throws EE_Error |
|
436 | + */ |
|
437 | + public function get_all_for_transaction($transaction, $scope) |
|
438 | + { |
|
439 | + // give addons a chance to override what payment methods are chosen based on the transaction |
|
440 | + return apply_filters( |
|
441 | + 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods', |
|
442 | + $this->get_all_active($scope, ['group_by' => 'PMD_type']), |
|
443 | + $transaction, |
|
444 | + $scope |
|
445 | + ); |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + /** |
|
450 | + * Returns the payment method used for the last payment made for a registration. |
|
451 | + * Note: if an offline payment method was selected on the related transaction then this will have no payment |
|
452 | + * methods returned. It will ONLY return a payment method for a PAYMENT recorded against the registration. |
|
453 | + * |
|
454 | + * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the |
|
455 | + * registration. |
|
456 | + * @return EE_Payment|null |
|
457 | + * @throws EE_Error |
|
458 | + */ |
|
459 | + public function get_last_used_for_registration($registration_or_reg_id) |
|
460 | + { |
|
461 | + $registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id); |
|
462 | + |
|
463 | + $query_params = [ |
|
464 | + 0 => [ |
|
465 | + 'Payment.Registration.REG_ID' => $registration_id, |
|
466 | + ], |
|
467 | + 'order_by' => ['Payment.PAY_ID' => 'DESC'], |
|
468 | + ]; |
|
469 | + return $this->get_one($query_params); |
|
470 | + } |
|
471 | 471 | } |
@@ -16,361 +16,361 @@ |
||
16 | 16 | */ |
17 | 17 | class EE_Maintenance_Mode implements ResettableInterface |
18 | 18 | { |
19 | - /** |
|
20 | - * constants available to client code for interpreting the values of EE_Maintenance_Mode::level(). |
|
21 | - * level_0_not_in_maintenance means the site is NOT in maintenance mode (so everything's normal) |
|
22 | - */ |
|
23 | - const level_0_not_in_maintenance = 0; |
|
24 | - |
|
25 | - /** |
|
26 | - * level_1_frontend_only_maintenance means that the site's frontend EE code should be completely disabled |
|
27 | - * but the admin backend should be running as normal. Maybe an admin can view the frontend though |
|
28 | - */ |
|
29 | - const level_1_frontend_only_maintenance = 1; |
|
30 | - |
|
31 | - /** |
|
32 | - * level_2_complete_maintenance means the frontend AND EE backend code are disabled. The only system running |
|
33 | - * is the maintenance mode stuff, which will require users to update all addons, and then finish running all |
|
34 | - * migration scripts before taking the site out of maintenance mode |
|
35 | - */ |
|
36 | - const level_2_complete_maintenance = 2; |
|
37 | - |
|
38 | - /** |
|
39 | - * the name of the option which stores the current level of maintenance mode |
|
40 | - */ |
|
41 | - const option_name_maintenance_mode = 'ee_maintenance_mode'; |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * @var EE_Maintenance_Mode $_instance |
|
46 | - */ |
|
47 | - private static $_instance; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var EE_Registry $EE |
|
51 | - */ |
|
52 | - protected $EE; |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @singleton method used to instantiate class object |
|
57 | - * @return EE_Maintenance_Mode |
|
58 | - */ |
|
59 | - public static function instance() |
|
60 | - { |
|
61 | - // check if class object is instantiated |
|
62 | - if (! self::$_instance instanceof EE_Maintenance_Mode) { |
|
63 | - self::$_instance = new self(); |
|
64 | - } |
|
65 | - return self::$_instance; |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * Resets maintenance mode (mostly just re-checks whether we should be in maintenance mode) |
|
71 | - * |
|
72 | - * @return EE_Maintenance_Mode |
|
73 | - * @throws EE_Error |
|
74 | - */ |
|
75 | - public static function reset() |
|
76 | - { |
|
77 | - self::instance()->set_maintenance_mode_if_db_old(); |
|
78 | - return self::instance(); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - *private constructor to prevent direct creation |
|
84 | - */ |
|
85 | - private function __construct() |
|
86 | - { |
|
87 | - // if M-Mode level 2 is engaged, we still need basic assets loaded |
|
88 | - add_action('wp_enqueue_scripts', [$this, 'load_assets_required_for_m_mode']); |
|
89 | - // shut 'er down for maintenance ? |
|
90 | - add_filter('the_content', [$this, 'the_content'], 2); |
|
91 | - // redirect ee menus to maintenance page |
|
92 | - add_action('admin_page_access_denied', [$this, 'redirect_to_maintenance']); |
|
93 | - // add powered by EE msg |
|
94 | - add_action('shutdown', [$this, 'display_maintenance_mode_notice'], 10); |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * retrieves the maintenance mode option value from the db |
|
100 | - * |
|
101 | - * @return int |
|
102 | - */ |
|
103 | - public function real_level() |
|
104 | - { |
|
105 | - return (int) get_option(self::option_name_maintenance_mode, EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * Returns whether the models reportedly are able to run queries or not |
|
111 | - * (ie, if the system thinks their tables are present and up-to-date). |
|
112 | - * |
|
113 | - * @return boolean |
|
114 | - */ |
|
115 | - public function models_can_query() |
|
116 | - { |
|
117 | - return $this->real_level() !== EE_Maintenance_Mode::level_2_complete_maintenance; |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * Determines whether we're in maintenance mode and what level. However, while the site |
|
123 | - * is in level 1 maintenance, and an admin visits the frontend, this function makes it appear |
|
124 | - * to them as if teh site isn't in maintenance mode. |
|
125 | - * EE_Maintenance_Mode::level_0_not_in_maintenance => not in maintenance mode (in normal mode) |
|
126 | - * EE_Maintenance_Mode::level_1_frontend_only_maintenance=> frontend-only maintenance mode |
|
127 | - * EE_Maintenance_Mode::level_2_complete_maintenance => frontend and backend maintenance mode |
|
128 | - * |
|
129 | - * @return int |
|
130 | - */ |
|
131 | - public function level() |
|
132 | - { |
|
133 | - $maintenance_mode_level = $this->real_level(); |
|
134 | - // if this is an admin request, we'll be honest... except if it's ajax, because that might be from the frontend |
|
135 | - if ( |
|
136 | - $maintenance_mode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance// we're in level 1 |
|
137 | - && ((defined('DOING_AJAX') && DOING_AJAX) || ! is_admin()) // on non-ajax frontend requests |
|
138 | - && current_user_can('administrator') // when the user is an admin |
|
139 | - ) { |
|
140 | - $maintenance_mode_level = EE_Maintenance_Mode::level_0_not_in_maintenance; |
|
141 | - } |
|
142 | - return $maintenance_mode_level; |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * Determines if we need to put EE in maintenance mode because the database needs updating |
|
148 | - * |
|
149 | - * @return boolean true if DB is old and maintenance mode was triggered; false otherwise |
|
150 | - * @throws EE_Error |
|
151 | - */ |
|
152 | - public function set_maintenance_mode_if_db_old() |
|
153 | - { |
|
154 | - LoaderFactory::getLoader()->getShared('Data_Migration_Manager'); |
|
155 | - if (EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) { |
|
156 | - update_option(self::option_name_maintenance_mode, self::level_2_complete_maintenance); |
|
157 | - return true; |
|
158 | - } |
|
159 | - if ($this->level() === self::level_2_complete_maintenance) { |
|
160 | - // we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run |
|
161 | - // then we shouldn't be in mm2. (Maybe an addon got deactivated?) |
|
162 | - update_option(self::option_name_maintenance_mode, self::level_0_not_in_maintenance); |
|
163 | - return false; |
|
164 | - } |
|
165 | - return false; |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * Updates the maintenance level on the site |
|
171 | - * |
|
172 | - * @param int $level |
|
173 | - * @return void |
|
174 | - */ |
|
175 | - public function set_maintenance_level($level) |
|
176 | - { |
|
177 | - do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $level); |
|
178 | - update_option(self::option_name_maintenance_mode, (int) $level); |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * returns TRUE if M-Mode is engaged and the current request is not for the admin |
|
184 | - * |
|
185 | - * @return bool |
|
186 | - */ |
|
187 | - public static function disable_frontend_for_maintenance() |
|
188 | - { |
|
189 | - return (! is_admin() && EE_Maintenance_Mode::instance()->level()); |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * @return void |
|
195 | - */ |
|
196 | - public function load_assets_required_for_m_mode() |
|
197 | - { |
|
198 | - if ( |
|
199 | - $this->real_level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
200 | - && ! wp_script_is('espresso_core') |
|
201 | - ) { |
|
202 | - wp_register_style( |
|
203 | - 'espresso_default', |
|
204 | - EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
205 | - ['dashicons'], |
|
206 | - EVENT_ESPRESSO_VERSION |
|
207 | - ); |
|
208 | - wp_enqueue_style('espresso_default'); |
|
209 | - wp_register_script( |
|
210 | - 'espresso_core', |
|
211 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
212 | - ['jquery'], |
|
213 | - EVENT_ESPRESSO_VERSION, |
|
214 | - true |
|
215 | - ); |
|
216 | - wp_enqueue_script('espresso_core'); |
|
217 | - } |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * replacement EE CPT template that displays message notifying site visitors |
|
223 | - * that EE has been temporarily placed into maintenance mode |
|
224 | - * does NOT get called on non-EE-CPT requests |
|
225 | - * |
|
226 | - * @return string |
|
227 | - */ |
|
228 | - public static function template_include() |
|
229 | - { |
|
230 | - // shut 'er down for maintenance ? then don't use any of our templates for our endpoints |
|
231 | - return get_template_directory() . '/index.php'; |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * displays message notifying site visitors that EE has been temporarily |
|
237 | - * placed into maintenance mode when post_type != EE CPT |
|
238 | - * |
|
239 | - * @param string $the_content |
|
240 | - * @return string |
|
241 | - */ |
|
242 | - public function the_content($the_content) |
|
243 | - { |
|
244 | - // check if M-mode is engaged and for EE shortcode |
|
245 | - if ($this->level() && strpos($the_content, '[ESPRESSO_') !== false) { |
|
246 | - // this can eventually be moved to a template, or edited via admin. But for now... |
|
247 | - $the_content = sprintf( |
|
248 | - esc_html__( |
|
249 | - '%sMaintenance Mode%sEvent Registration has been temporarily closed while system maintenance is being performed. We\'re sorry for any inconveniences this may have caused. Please try back again later.%s', |
|
250 | - 'event_espresso' |
|
251 | - ), |
|
252 | - '<h3>', |
|
253 | - '</h3><p>', |
|
254 | - '</p>' |
|
255 | - ); |
|
256 | - } |
|
257 | - return $the_content; |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - /** |
|
262 | - * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode |
|
263 | - */ |
|
264 | - public function display_maintenance_mode_notice() |
|
265 | - { |
|
266 | - /** @var CurrentPage $current_page */ |
|
267 | - $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
|
268 | - // check if M-mode is engaged and for EE shortcode |
|
269 | - if ( |
|
270 | - ! (defined('DOING_AJAX') && DOING_AJAX) |
|
271 | - && $this->real_level() |
|
272 | - && ! is_admin() |
|
273 | - && current_user_can('administrator') |
|
274 | - && $current_page->isEspressoPage() |
|
275 | - ) { |
|
276 | - printf( |
|
277 | - esc_html__( |
|
278 | - '%sclose%sEvent Registration is currently disabled because Event Espresso has been placed into Maintenance Mode. To change Maintenance Mode settings, click here %sEE Maintenance Mode Admin Page%s', |
|
279 | - 'event_espresso' |
|
280 | - ), |
|
281 | - '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="', |
|
282 | - '"><span class="dashicons dashicons-no"></span></a><p>', |
|
283 | - ' » <a href="' . add_query_arg( |
|
284 | - ['page' => 'espresso_maintenance_settings'], |
|
285 | - admin_url('admin.php') |
|
286 | - ) . '">', |
|
287 | - '</a></p></div>' |
|
288 | - ); |
|
289 | - } |
|
290 | - } |
|
291 | - // espresso-notices important-notice ee-attention |
|
292 | - |
|
293 | - /** |
|
294 | - * Redirects EE admin menu requests to the maintenance page |
|
295 | - */ |
|
296 | - public function redirect_to_maintenance() |
|
297 | - { |
|
298 | - global $pagenow; |
|
299 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
300 | - $page = $request->getRequestParam('page'); |
|
301 | - |
|
302 | - if ( |
|
303 | - $pagenow == 'admin.php' && |
|
304 | - strpos($page, 'espresso_') !== false && |
|
305 | - $this->real_level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
306 | - ) { |
|
307 | - wp_safe_redirect( 'admin.php?page=espresso_maintenance_settings' ); |
|
308 | - exit; |
|
309 | - } |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * override magic methods |
|
315 | - */ |
|
316 | - final public function __destruct() |
|
317 | - { |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - final public function __call($a, $b) |
|
322 | - { |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - final public function __get($a) |
|
327 | - { |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - final public function __set($a, $b) |
|
332 | - { |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - final public function __isset($a) |
|
337 | - { |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - final public function __unset($a) |
|
342 | - { |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - final public function __sleep() |
|
347 | - { |
|
348 | - return []; |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - final public function __wakeup() |
|
353 | - { |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - final public function __invoke() |
|
358 | - { |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - final public static function __set_state($a = null) |
|
363 | - { |
|
364 | - return EE_Maintenance_Mode::instance(); |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - final public function __clone() |
|
369 | - { |
|
370 | - } |
|
19 | + /** |
|
20 | + * constants available to client code for interpreting the values of EE_Maintenance_Mode::level(). |
|
21 | + * level_0_not_in_maintenance means the site is NOT in maintenance mode (so everything's normal) |
|
22 | + */ |
|
23 | + const level_0_not_in_maintenance = 0; |
|
24 | + |
|
25 | + /** |
|
26 | + * level_1_frontend_only_maintenance means that the site's frontend EE code should be completely disabled |
|
27 | + * but the admin backend should be running as normal. Maybe an admin can view the frontend though |
|
28 | + */ |
|
29 | + const level_1_frontend_only_maintenance = 1; |
|
30 | + |
|
31 | + /** |
|
32 | + * level_2_complete_maintenance means the frontend AND EE backend code are disabled. The only system running |
|
33 | + * is the maintenance mode stuff, which will require users to update all addons, and then finish running all |
|
34 | + * migration scripts before taking the site out of maintenance mode |
|
35 | + */ |
|
36 | + const level_2_complete_maintenance = 2; |
|
37 | + |
|
38 | + /** |
|
39 | + * the name of the option which stores the current level of maintenance mode |
|
40 | + */ |
|
41 | + const option_name_maintenance_mode = 'ee_maintenance_mode'; |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * @var EE_Maintenance_Mode $_instance |
|
46 | + */ |
|
47 | + private static $_instance; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var EE_Registry $EE |
|
51 | + */ |
|
52 | + protected $EE; |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @singleton method used to instantiate class object |
|
57 | + * @return EE_Maintenance_Mode |
|
58 | + */ |
|
59 | + public static function instance() |
|
60 | + { |
|
61 | + // check if class object is instantiated |
|
62 | + if (! self::$_instance instanceof EE_Maintenance_Mode) { |
|
63 | + self::$_instance = new self(); |
|
64 | + } |
|
65 | + return self::$_instance; |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * Resets maintenance mode (mostly just re-checks whether we should be in maintenance mode) |
|
71 | + * |
|
72 | + * @return EE_Maintenance_Mode |
|
73 | + * @throws EE_Error |
|
74 | + */ |
|
75 | + public static function reset() |
|
76 | + { |
|
77 | + self::instance()->set_maintenance_mode_if_db_old(); |
|
78 | + return self::instance(); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + *private constructor to prevent direct creation |
|
84 | + */ |
|
85 | + private function __construct() |
|
86 | + { |
|
87 | + // if M-Mode level 2 is engaged, we still need basic assets loaded |
|
88 | + add_action('wp_enqueue_scripts', [$this, 'load_assets_required_for_m_mode']); |
|
89 | + // shut 'er down for maintenance ? |
|
90 | + add_filter('the_content', [$this, 'the_content'], 2); |
|
91 | + // redirect ee menus to maintenance page |
|
92 | + add_action('admin_page_access_denied', [$this, 'redirect_to_maintenance']); |
|
93 | + // add powered by EE msg |
|
94 | + add_action('shutdown', [$this, 'display_maintenance_mode_notice'], 10); |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * retrieves the maintenance mode option value from the db |
|
100 | + * |
|
101 | + * @return int |
|
102 | + */ |
|
103 | + public function real_level() |
|
104 | + { |
|
105 | + return (int) get_option(self::option_name_maintenance_mode, EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * Returns whether the models reportedly are able to run queries or not |
|
111 | + * (ie, if the system thinks their tables are present and up-to-date). |
|
112 | + * |
|
113 | + * @return boolean |
|
114 | + */ |
|
115 | + public function models_can_query() |
|
116 | + { |
|
117 | + return $this->real_level() !== EE_Maintenance_Mode::level_2_complete_maintenance; |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * Determines whether we're in maintenance mode and what level. However, while the site |
|
123 | + * is in level 1 maintenance, and an admin visits the frontend, this function makes it appear |
|
124 | + * to them as if teh site isn't in maintenance mode. |
|
125 | + * EE_Maintenance_Mode::level_0_not_in_maintenance => not in maintenance mode (in normal mode) |
|
126 | + * EE_Maintenance_Mode::level_1_frontend_only_maintenance=> frontend-only maintenance mode |
|
127 | + * EE_Maintenance_Mode::level_2_complete_maintenance => frontend and backend maintenance mode |
|
128 | + * |
|
129 | + * @return int |
|
130 | + */ |
|
131 | + public function level() |
|
132 | + { |
|
133 | + $maintenance_mode_level = $this->real_level(); |
|
134 | + // if this is an admin request, we'll be honest... except if it's ajax, because that might be from the frontend |
|
135 | + if ( |
|
136 | + $maintenance_mode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance// we're in level 1 |
|
137 | + && ((defined('DOING_AJAX') && DOING_AJAX) || ! is_admin()) // on non-ajax frontend requests |
|
138 | + && current_user_can('administrator') // when the user is an admin |
|
139 | + ) { |
|
140 | + $maintenance_mode_level = EE_Maintenance_Mode::level_0_not_in_maintenance; |
|
141 | + } |
|
142 | + return $maintenance_mode_level; |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * Determines if we need to put EE in maintenance mode because the database needs updating |
|
148 | + * |
|
149 | + * @return boolean true if DB is old and maintenance mode was triggered; false otherwise |
|
150 | + * @throws EE_Error |
|
151 | + */ |
|
152 | + public function set_maintenance_mode_if_db_old() |
|
153 | + { |
|
154 | + LoaderFactory::getLoader()->getShared('Data_Migration_Manager'); |
|
155 | + if (EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) { |
|
156 | + update_option(self::option_name_maintenance_mode, self::level_2_complete_maintenance); |
|
157 | + return true; |
|
158 | + } |
|
159 | + if ($this->level() === self::level_2_complete_maintenance) { |
|
160 | + // we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run |
|
161 | + // then we shouldn't be in mm2. (Maybe an addon got deactivated?) |
|
162 | + update_option(self::option_name_maintenance_mode, self::level_0_not_in_maintenance); |
|
163 | + return false; |
|
164 | + } |
|
165 | + return false; |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * Updates the maintenance level on the site |
|
171 | + * |
|
172 | + * @param int $level |
|
173 | + * @return void |
|
174 | + */ |
|
175 | + public function set_maintenance_level($level) |
|
176 | + { |
|
177 | + do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $level); |
|
178 | + update_option(self::option_name_maintenance_mode, (int) $level); |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * returns TRUE if M-Mode is engaged and the current request is not for the admin |
|
184 | + * |
|
185 | + * @return bool |
|
186 | + */ |
|
187 | + public static function disable_frontend_for_maintenance() |
|
188 | + { |
|
189 | + return (! is_admin() && EE_Maintenance_Mode::instance()->level()); |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * @return void |
|
195 | + */ |
|
196 | + public function load_assets_required_for_m_mode() |
|
197 | + { |
|
198 | + if ( |
|
199 | + $this->real_level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
200 | + && ! wp_script_is('espresso_core') |
|
201 | + ) { |
|
202 | + wp_register_style( |
|
203 | + 'espresso_default', |
|
204 | + EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
205 | + ['dashicons'], |
|
206 | + EVENT_ESPRESSO_VERSION |
|
207 | + ); |
|
208 | + wp_enqueue_style('espresso_default'); |
|
209 | + wp_register_script( |
|
210 | + 'espresso_core', |
|
211 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
212 | + ['jquery'], |
|
213 | + EVENT_ESPRESSO_VERSION, |
|
214 | + true |
|
215 | + ); |
|
216 | + wp_enqueue_script('espresso_core'); |
|
217 | + } |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * replacement EE CPT template that displays message notifying site visitors |
|
223 | + * that EE has been temporarily placed into maintenance mode |
|
224 | + * does NOT get called on non-EE-CPT requests |
|
225 | + * |
|
226 | + * @return string |
|
227 | + */ |
|
228 | + public static function template_include() |
|
229 | + { |
|
230 | + // shut 'er down for maintenance ? then don't use any of our templates for our endpoints |
|
231 | + return get_template_directory() . '/index.php'; |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * displays message notifying site visitors that EE has been temporarily |
|
237 | + * placed into maintenance mode when post_type != EE CPT |
|
238 | + * |
|
239 | + * @param string $the_content |
|
240 | + * @return string |
|
241 | + */ |
|
242 | + public function the_content($the_content) |
|
243 | + { |
|
244 | + // check if M-mode is engaged and for EE shortcode |
|
245 | + if ($this->level() && strpos($the_content, '[ESPRESSO_') !== false) { |
|
246 | + // this can eventually be moved to a template, or edited via admin. But for now... |
|
247 | + $the_content = sprintf( |
|
248 | + esc_html__( |
|
249 | + '%sMaintenance Mode%sEvent Registration has been temporarily closed while system maintenance is being performed. We\'re sorry for any inconveniences this may have caused. Please try back again later.%s', |
|
250 | + 'event_espresso' |
|
251 | + ), |
|
252 | + '<h3>', |
|
253 | + '</h3><p>', |
|
254 | + '</p>' |
|
255 | + ); |
|
256 | + } |
|
257 | + return $the_content; |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + /** |
|
262 | + * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode |
|
263 | + */ |
|
264 | + public function display_maintenance_mode_notice() |
|
265 | + { |
|
266 | + /** @var CurrentPage $current_page */ |
|
267 | + $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
|
268 | + // check if M-mode is engaged and for EE shortcode |
|
269 | + if ( |
|
270 | + ! (defined('DOING_AJAX') && DOING_AJAX) |
|
271 | + && $this->real_level() |
|
272 | + && ! is_admin() |
|
273 | + && current_user_can('administrator') |
|
274 | + && $current_page->isEspressoPage() |
|
275 | + ) { |
|
276 | + printf( |
|
277 | + esc_html__( |
|
278 | + '%sclose%sEvent Registration is currently disabled because Event Espresso has been placed into Maintenance Mode. To change Maintenance Mode settings, click here %sEE Maintenance Mode Admin Page%s', |
|
279 | + 'event_espresso' |
|
280 | + ), |
|
281 | + '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="', |
|
282 | + '"><span class="dashicons dashicons-no"></span></a><p>', |
|
283 | + ' » <a href="' . add_query_arg( |
|
284 | + ['page' => 'espresso_maintenance_settings'], |
|
285 | + admin_url('admin.php') |
|
286 | + ) . '">', |
|
287 | + '</a></p></div>' |
|
288 | + ); |
|
289 | + } |
|
290 | + } |
|
291 | + // espresso-notices important-notice ee-attention |
|
292 | + |
|
293 | + /** |
|
294 | + * Redirects EE admin menu requests to the maintenance page |
|
295 | + */ |
|
296 | + public function redirect_to_maintenance() |
|
297 | + { |
|
298 | + global $pagenow; |
|
299 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
300 | + $page = $request->getRequestParam('page'); |
|
301 | + |
|
302 | + if ( |
|
303 | + $pagenow == 'admin.php' && |
|
304 | + strpos($page, 'espresso_') !== false && |
|
305 | + $this->real_level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
306 | + ) { |
|
307 | + wp_safe_redirect( 'admin.php?page=espresso_maintenance_settings' ); |
|
308 | + exit; |
|
309 | + } |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * override magic methods |
|
315 | + */ |
|
316 | + final public function __destruct() |
|
317 | + { |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + final public function __call($a, $b) |
|
322 | + { |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + final public function __get($a) |
|
327 | + { |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + final public function __set($a, $b) |
|
332 | + { |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + final public function __isset($a) |
|
337 | + { |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + final public function __unset($a) |
|
342 | + { |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + final public function __sleep() |
|
347 | + { |
|
348 | + return []; |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + final public function __wakeup() |
|
353 | + { |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + final public function __invoke() |
|
358 | + { |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + final public static function __set_state($a = null) |
|
363 | + { |
|
364 | + return EE_Maintenance_Mode::instance(); |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + final public function __clone() |
|
369 | + { |
|
370 | + } |
|
371 | 371 | |
372 | 372 | |
373 | - final public static function __callStatic($a, $b) |
|
374 | - { |
|
375 | - } |
|
373 | + final public static function __callStatic($a, $b) |
|
374 | + { |
|
375 | + } |
|
376 | 376 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | public static function instance() |
60 | 60 | { |
61 | 61 | // check if class object is instantiated |
62 | - if (! self::$_instance instanceof EE_Maintenance_Mode) { |
|
62 | + if ( ! self::$_instance instanceof EE_Maintenance_Mode) { |
|
63 | 63 | self::$_instance = new self(); |
64 | 64 | } |
65 | 65 | return self::$_instance; |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | */ |
187 | 187 | public static function disable_frontend_for_maintenance() |
188 | 188 | { |
189 | - return (! is_admin() && EE_Maintenance_Mode::instance()->level()); |
|
189 | + return ( ! is_admin() && EE_Maintenance_Mode::instance()->level()); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | |
@@ -201,14 +201,14 @@ discard block |
||
201 | 201 | ) { |
202 | 202 | wp_register_style( |
203 | 203 | 'espresso_default', |
204 | - EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
204 | + EE_GLOBAL_ASSETS_URL.'css/espresso_default.css', |
|
205 | 205 | ['dashicons'], |
206 | 206 | EVENT_ESPRESSO_VERSION |
207 | 207 | ); |
208 | 208 | wp_enqueue_style('espresso_default'); |
209 | 209 | wp_register_script( |
210 | 210 | 'espresso_core', |
211 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
211 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
212 | 212 | ['jquery'], |
213 | 213 | EVENT_ESPRESSO_VERSION, |
214 | 214 | true |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | public static function template_include() |
229 | 229 | { |
230 | 230 | // shut 'er down for maintenance ? then don't use any of our templates for our endpoints |
231 | - return get_template_directory() . '/index.php'; |
|
231 | + return get_template_directory().'/index.php'; |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | |
@@ -280,10 +280,10 @@ discard block |
||
280 | 280 | ), |
281 | 281 | '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="', |
282 | 282 | '"><span class="dashicons dashicons-no"></span></a><p>', |
283 | - ' » <a href="' . add_query_arg( |
|
283 | + ' » <a href="'.add_query_arg( |
|
284 | 284 | ['page' => 'espresso_maintenance_settings'], |
285 | 285 | admin_url('admin.php') |
286 | - ) . '">', |
|
286 | + ).'">', |
|
287 | 287 | '</a></p></div>' |
288 | 288 | ); |
289 | 289 | } |
@@ -297,14 +297,14 @@ discard block |
||
297 | 297 | { |
298 | 298 | global $pagenow; |
299 | 299 | $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
300 | - $page = $request->getRequestParam('page'); |
|
300 | + $page = $request->getRequestParam('page'); |
|
301 | 301 | |
302 | 302 | if ( |
303 | 303 | $pagenow == 'admin.php' && |
304 | 304 | strpos($page, 'espresso_') !== false && |
305 | 305 | $this->real_level() == EE_Maintenance_Mode::level_2_complete_maintenance |
306 | 306 | ) { |
307 | - wp_safe_redirect( 'admin.php?page=espresso_maintenance_settings' ); |
|
307 | + wp_safe_redirect('admin.php?page=espresso_maintenance_settings'); |
|
308 | 308 | exit; |
309 | 309 | } |
310 | 310 | } |
@@ -26,210 +26,210 @@ |
||
26 | 26 | */ |
27 | 27 | class FormElement extends TypeBase |
28 | 28 | { |
29 | - /** |
|
30 | - * FormElement constructor. |
|
31 | - * |
|
32 | - * @param EEM_Form_Element $form_element_model |
|
33 | - */ |
|
34 | - public function __construct(EEM_Form_Element $form_element_model) |
|
35 | - { |
|
36 | - $this->setName($this->namespace . 'FormElement'); |
|
37 | - $this->setDescription(__('A form element', 'event_espresso')); |
|
38 | - $this->setIsCustomPostType(false); |
|
29 | + /** |
|
30 | + * FormElement constructor. |
|
31 | + * |
|
32 | + * @param EEM_Form_Element $form_element_model |
|
33 | + */ |
|
34 | + public function __construct(EEM_Form_Element $form_element_model) |
|
35 | + { |
|
36 | + $this->setName($this->namespace . 'FormElement'); |
|
37 | + $this->setDescription(__('A form element', 'event_espresso')); |
|
38 | + $this->setIsCustomPostType(false); |
|
39 | 39 | |
40 | - parent::__construct($form_element_model); |
|
41 | - } |
|
40 | + parent::__construct($form_element_model); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @return GraphQLFieldInterface[] |
|
46 | - */ |
|
47 | - public function getFields(): array |
|
48 | - { |
|
49 | - $fields = [ |
|
50 | - new GraphQLField( |
|
51 | - 'id', |
|
52 | - ['non_null' => 'ID'], |
|
53 | - null, |
|
54 | - esc_html__('The globally unique ID for the object.', 'event_espresso') |
|
55 | - ), |
|
56 | - new GraphQLField( |
|
57 | - 'adminOnly', |
|
58 | - 'Boolean', |
|
59 | - 'adminOnly', |
|
60 | - esc_html__( |
|
61 | - 'Whether or not the element is only displayed in the admin. If false, input will appear in public forms', |
|
62 | - 'event_espresso' |
|
63 | - ) |
|
64 | - ), |
|
65 | - new GraphQLField( |
|
66 | - 'attributes', |
|
67 | - 'String', |
|
68 | - 'attributes', |
|
69 | - esc_html__( |
|
70 | - 'JSON string of HTML attributes such as class, max, min, placeholder, type, etc.', |
|
71 | - 'event_espresso' |
|
72 | - ), |
|
73 | - [$this, 'toJson'] |
|
74 | - ), |
|
75 | - new GraphQLField( |
|
76 | - 'belongsTo', |
|
77 | - 'String', |
|
78 | - 'belongsTo', |
|
79 | - esc_html__('UUID of parent form section this form element belongs to.', 'event_espresso') |
|
80 | - ), |
|
81 | - new GraphQLField( |
|
82 | - 'helpText', |
|
83 | - 'String', |
|
84 | - 'helpText', |
|
85 | - esc_html__( |
|
86 | - "JSON string of properties pertaining to any help text required for an input.", |
|
87 | - 'event_espresso' |
|
88 | - ), |
|
89 | - [$this, 'toJson'] |
|
90 | - ), |
|
91 | - new GraphQLField( |
|
92 | - 'label', |
|
93 | - 'String', |
|
94 | - 'label', |
|
95 | - esc_html__( |
|
96 | - 'JSON string of properties pertaining to an element\'s label.', |
|
97 | - 'event_espresso' |
|
98 | - ), |
|
99 | - [$this, 'toJson'] |
|
100 | - ), |
|
101 | - new GraphQLField( |
|
102 | - 'mapsTo', |
|
103 | - 'String', |
|
104 | - 'mapsTo', |
|
105 | - esc_html__("Model and Fields name that this element maps to; ex: Attendee.email", 'event_espresso') |
|
106 | - ), |
|
107 | - new GraphQLField( |
|
108 | - 'options', |
|
109 | - 'String', |
|
110 | - 'options', |
|
111 | - esc_html__( |
|
112 | - "JSON string of options for ENUM type inputs like checkboxes, radio buttons, select inputs, etc.", |
|
113 | - 'event_espresso' |
|
114 | - ), |
|
115 | - [$this, 'toJson'] |
|
116 | - ), |
|
117 | - new GraphQLField( |
|
118 | - 'order', |
|
119 | - 'Int', |
|
120 | - 'order', |
|
121 | - esc_html__('Order in which form element appears in a form.', 'event_espresso') |
|
122 | - ), |
|
123 | - new GraphQLField( |
|
124 | - 'required', |
|
125 | - 'String', |
|
126 | - 'required', |
|
127 | - esc_html__( |
|
128 | - "properties pertaining to an input\'s required status and the validation text to display.", |
|
129 | - 'event_espresso' |
|
130 | - ), |
|
131 | - [$this, 'toJson'] |
|
132 | - ), |
|
133 | - new GraphQLField( |
|
134 | - 'status', |
|
135 | - $this->namespace . 'FormStatusEnum', |
|
136 | - 'status', |
|
137 | - esc_html__( |
|
138 | - 'Whether form element is active, archived, trashed, or used as a default on new forms.', |
|
139 | - 'event_espresso' |
|
140 | - ) |
|
141 | - ), |
|
142 | - new GraphQLField( |
|
143 | - 'type', |
|
144 | - $this->namespace . 'ElementTypeEnum', |
|
145 | - 'type', |
|
146 | - esc_html__('Form element type.', 'event_espresso') |
|
147 | - ), |
|
148 | - new GraphQLOutputField( |
|
149 | - 'wpUser', |
|
150 | - 'User', |
|
151 | - null, |
|
152 | - esc_html__('WP User that created this form element.', 'event_espresso') |
|
153 | - ), |
|
154 | - new GraphQLInputField( |
|
155 | - 'wpUser', |
|
156 | - 'ID', |
|
157 | - null, |
|
158 | - esc_html__('ID of the WP User that created the form element.', 'event_espresso') |
|
159 | - ), |
|
160 | - ]; |
|
44 | + /** |
|
45 | + * @return GraphQLFieldInterface[] |
|
46 | + */ |
|
47 | + public function getFields(): array |
|
48 | + { |
|
49 | + $fields = [ |
|
50 | + new GraphQLField( |
|
51 | + 'id', |
|
52 | + ['non_null' => 'ID'], |
|
53 | + null, |
|
54 | + esc_html__('The globally unique ID for the object.', 'event_espresso') |
|
55 | + ), |
|
56 | + new GraphQLField( |
|
57 | + 'adminOnly', |
|
58 | + 'Boolean', |
|
59 | + 'adminOnly', |
|
60 | + esc_html__( |
|
61 | + 'Whether or not the element is only displayed in the admin. If false, input will appear in public forms', |
|
62 | + 'event_espresso' |
|
63 | + ) |
|
64 | + ), |
|
65 | + new GraphQLField( |
|
66 | + 'attributes', |
|
67 | + 'String', |
|
68 | + 'attributes', |
|
69 | + esc_html__( |
|
70 | + 'JSON string of HTML attributes such as class, max, min, placeholder, type, etc.', |
|
71 | + 'event_espresso' |
|
72 | + ), |
|
73 | + [$this, 'toJson'] |
|
74 | + ), |
|
75 | + new GraphQLField( |
|
76 | + 'belongsTo', |
|
77 | + 'String', |
|
78 | + 'belongsTo', |
|
79 | + esc_html__('UUID of parent form section this form element belongs to.', 'event_espresso') |
|
80 | + ), |
|
81 | + new GraphQLField( |
|
82 | + 'helpText', |
|
83 | + 'String', |
|
84 | + 'helpText', |
|
85 | + esc_html__( |
|
86 | + "JSON string of properties pertaining to any help text required for an input.", |
|
87 | + 'event_espresso' |
|
88 | + ), |
|
89 | + [$this, 'toJson'] |
|
90 | + ), |
|
91 | + new GraphQLField( |
|
92 | + 'label', |
|
93 | + 'String', |
|
94 | + 'label', |
|
95 | + esc_html__( |
|
96 | + 'JSON string of properties pertaining to an element\'s label.', |
|
97 | + 'event_espresso' |
|
98 | + ), |
|
99 | + [$this, 'toJson'] |
|
100 | + ), |
|
101 | + new GraphQLField( |
|
102 | + 'mapsTo', |
|
103 | + 'String', |
|
104 | + 'mapsTo', |
|
105 | + esc_html__("Model and Fields name that this element maps to; ex: Attendee.email", 'event_espresso') |
|
106 | + ), |
|
107 | + new GraphQLField( |
|
108 | + 'options', |
|
109 | + 'String', |
|
110 | + 'options', |
|
111 | + esc_html__( |
|
112 | + "JSON string of options for ENUM type inputs like checkboxes, radio buttons, select inputs, etc.", |
|
113 | + 'event_espresso' |
|
114 | + ), |
|
115 | + [$this, 'toJson'] |
|
116 | + ), |
|
117 | + new GraphQLField( |
|
118 | + 'order', |
|
119 | + 'Int', |
|
120 | + 'order', |
|
121 | + esc_html__('Order in which form element appears in a form.', 'event_espresso') |
|
122 | + ), |
|
123 | + new GraphQLField( |
|
124 | + 'required', |
|
125 | + 'String', |
|
126 | + 'required', |
|
127 | + esc_html__( |
|
128 | + "properties pertaining to an input\'s required status and the validation text to display.", |
|
129 | + 'event_espresso' |
|
130 | + ), |
|
131 | + [$this, 'toJson'] |
|
132 | + ), |
|
133 | + new GraphQLField( |
|
134 | + 'status', |
|
135 | + $this->namespace . 'FormStatusEnum', |
|
136 | + 'status', |
|
137 | + esc_html__( |
|
138 | + 'Whether form element is active, archived, trashed, or used as a default on new forms.', |
|
139 | + 'event_espresso' |
|
140 | + ) |
|
141 | + ), |
|
142 | + new GraphQLField( |
|
143 | + 'type', |
|
144 | + $this->namespace . 'ElementTypeEnum', |
|
145 | + 'type', |
|
146 | + esc_html__('Form element type.', 'event_espresso') |
|
147 | + ), |
|
148 | + new GraphQLOutputField( |
|
149 | + 'wpUser', |
|
150 | + 'User', |
|
151 | + null, |
|
152 | + esc_html__('WP User that created this form element.', 'event_espresso') |
|
153 | + ), |
|
154 | + new GraphQLInputField( |
|
155 | + 'wpUser', |
|
156 | + 'ID', |
|
157 | + null, |
|
158 | + esc_html__('ID of the WP User that created the form element.', 'event_espresso') |
|
159 | + ), |
|
160 | + ]; |
|
161 | 161 | |
162 | - return apply_filters( |
|
163 | - 'FHEE__EventEspresso_core_domain_services_graphql_types__form_element_fields', |
|
164 | - $fields, |
|
165 | - $this->name, |
|
166 | - $this->model |
|
167 | - ); |
|
168 | - } |
|
162 | + return apply_filters( |
|
163 | + 'FHEE__EventEspresso_core_domain_services_graphql_types__form_element_fields', |
|
164 | + $fields, |
|
165 | + $this->name, |
|
166 | + $this->model |
|
167 | + ); |
|
168 | + } |
|
169 | 169 | |
170 | 170 | |
171 | - /** |
|
172 | - * @param array $inputFields The mutation input fields. |
|
173 | - * @throws InvalidArgumentException |
|
174 | - * @throws ReflectionException |
|
175 | - * @throws Exception |
|
176 | - * @since $VID:$ |
|
177 | - */ |
|
178 | - public function registerMutations(array $inputFields) |
|
179 | - { |
|
180 | - // Register mutation to update an entity. |
|
181 | - register_graphql_mutation( |
|
182 | - 'update' . $this->name(), |
|
183 | - [ |
|
184 | - 'inputFields' => $inputFields, |
|
185 | - 'outputFields' => [ |
|
186 | - lcfirst($this->name()) => [ |
|
187 | - 'type' => $this->name(), |
|
188 | - 'resolve' => [$this, 'resolveFromPayload'], |
|
189 | - ], |
|
190 | - ], |
|
191 | - 'mutateAndGetPayload' => FormElementUpdate::mutateAndGetPayload($this->model), |
|
192 | - ] |
|
193 | - ); |
|
194 | - // Register mutation to delete an entity. |
|
195 | - register_graphql_mutation( |
|
196 | - 'delete' . $this->name(), |
|
197 | - [ |
|
198 | - 'inputFields' => [ |
|
199 | - 'id' => $inputFields['id'], |
|
200 | - ], |
|
201 | - 'outputFields' => [ |
|
202 | - lcfirst($this->name()) => [ |
|
203 | - 'type' => $this->name(), |
|
204 | - 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
|
205 | - 'resolve' => static function ($payload) { |
|
206 | - $deleted = (object) $payload['deleted']; |
|
171 | + /** |
|
172 | + * @param array $inputFields The mutation input fields. |
|
173 | + * @throws InvalidArgumentException |
|
174 | + * @throws ReflectionException |
|
175 | + * @throws Exception |
|
176 | + * @since $VID:$ |
|
177 | + */ |
|
178 | + public function registerMutations(array $inputFields) |
|
179 | + { |
|
180 | + // Register mutation to update an entity. |
|
181 | + register_graphql_mutation( |
|
182 | + 'update' . $this->name(), |
|
183 | + [ |
|
184 | + 'inputFields' => $inputFields, |
|
185 | + 'outputFields' => [ |
|
186 | + lcfirst($this->name()) => [ |
|
187 | + 'type' => $this->name(), |
|
188 | + 'resolve' => [$this, 'resolveFromPayload'], |
|
189 | + ], |
|
190 | + ], |
|
191 | + 'mutateAndGetPayload' => FormElementUpdate::mutateAndGetPayload($this->model), |
|
192 | + ] |
|
193 | + ); |
|
194 | + // Register mutation to delete an entity. |
|
195 | + register_graphql_mutation( |
|
196 | + 'delete' . $this->name(), |
|
197 | + [ |
|
198 | + 'inputFields' => [ |
|
199 | + 'id' => $inputFields['id'], |
|
200 | + ], |
|
201 | + 'outputFields' => [ |
|
202 | + lcfirst($this->name()) => [ |
|
203 | + 'type' => $this->name(), |
|
204 | + 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
|
205 | + 'resolve' => static function ($payload) { |
|
206 | + $deleted = (object) $payload['deleted']; |
|
207 | 207 | |
208 | - return ! empty($deleted) ? $deleted : null; |
|
209 | - }, |
|
210 | - ], |
|
211 | - ], |
|
212 | - 'mutateAndGetPayload' => FormElementDelete::mutateAndGetPayload($this->model), |
|
213 | - ] |
|
214 | - ); |
|
208 | + return ! empty($deleted) ? $deleted : null; |
|
209 | + }, |
|
210 | + ], |
|
211 | + ], |
|
212 | + 'mutateAndGetPayload' => FormElementDelete::mutateAndGetPayload($this->model), |
|
213 | + ] |
|
214 | + ); |
|
215 | 215 | |
216 | - // Make element 'type' a required field for create mutations |
|
217 | - // Yes it's "['type']['type']" |
@@ -11,33 +11,33 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Currency_Payment_Method extends EE_Base_Class |
13 | 13 | { |
14 | - /** |
|
15 | - * @param array $props_n_values incoming values |
|
16 | - * @param null $timezone incoming timezone (if not set the timezone set for the website will be |
|
17 | - * used.) |
|
18 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
19 | - * date_format and the second value is the time format |
|
20 | - * @return EE_Currency_Payment_Method |
|
21 | - * @throws EE_Error |
|
22 | - * @throws ReflectionException |
|
23 | - */ |
|
24 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
25 | - { |
|
26 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
27 | - return $has_object ?: new self($props_n_values, false, $timezone, $date_formats); |
|
28 | - } |
|
14 | + /** |
|
15 | + * @param array $props_n_values incoming values |
|
16 | + * @param null $timezone incoming timezone (if not set the timezone set for the website will be |
|
17 | + * used.) |
|
18 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
19 | + * date_format and the second value is the time format |
|
20 | + * @return EE_Currency_Payment_Method |
|
21 | + * @throws EE_Error |
|
22 | + * @throws ReflectionException |
|
23 | + */ |
|
24 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
25 | + { |
|
26 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
27 | + return $has_object ?: new self($props_n_values, false, $timezone, $date_formats); |
|
28 | + } |
|
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * @param array $props_n_values incoming values from the database |
|
33 | - * @param null $timezone incoming timezone as set by the model. If not set the timezone for |
|
34 | - * the website will be used. |
|
35 | - * @return EE_Currency_Payment_Method |
|
36 | - * @throws EE_Error |
|
37 | - * @throws ReflectionException |
|
38 | - */ |
|
39 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
40 | - { |
|
41 | - return new self($props_n_values, true, $timezone); |
|
42 | - } |
|
31 | + /** |
|
32 | + * @param array $props_n_values incoming values from the database |
|
33 | + * @param null $timezone incoming timezone as set by the model. If not set the timezone for |
|
34 | + * the website will be used. |
|
35 | + * @return EE_Currency_Payment_Method |
|
36 | + * @throws EE_Error |
|
37 | + * @throws ReflectionException |
|
38 | + */ |
|
39 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
40 | + { |
|
41 | + return new self($props_n_values, true, $timezone); |
|
42 | + } |
|
43 | 43 | } |
@@ -11,9 +11,9 @@ discard block |
||
11 | 11 | $stages = glob(EE_CORE . 'data_migration_scripts/4_12_0_stages/*'); |
12 | 12 | $class_to_filepath = []; |
13 | 13 | foreach ($stages as $filepath) { |
14 | - $matches = []; |
|
15 | - preg_match('~4_12_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
16 | - $class_to_filepath[ $matches[1] ] = $filepath; |
|
14 | + $matches = []; |
|
15 | + preg_match('~4_12_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
16 | + $class_to_filepath[ $matches[1] ] = $filepath; |
|
17 | 17 | } |
18 | 18 | // give addons a chance to autoload their stages too |
19 | 19 | $class_to_filepath = apply_filters('FHEE__EE_DMS_4_12_0__autoloaded_stages', $class_to_filepath); |
@@ -29,67 +29,67 @@ discard block |
||
29 | 29 | */ |
30 | 30 | class EE_DMS_Core_5_0_0 extends EE_Data_Migration_Script_Base |
31 | 31 | { |
32 | - /** |
|
33 | - * |
|
34 | - * @param EE_DMS_Core_4_10_0 $dms_4_10 |
|
35 | - * @param TableManager|null $table_manager |
|
36 | - * @param TableAnalysis|null $table_analysis |
|
37 | - */ |
|
38 | - public function __construct( |
|
39 | - EE_DMS_Core_4_10_0 $dms_4_10, |
|
40 | - TableManager $table_manager = null, |
|
41 | - TableAnalysis $table_analysis = null |
|
42 | - ) { |
|
43 | - $this->previous_dms = $dms_4_10; |
|
44 | - $this->_pretty_name = esc_html__("Data Update to Event Espresso 5.0.0", "event_espresso"); |
|
45 | - $this->_priority = 10; |
|
46 | - $this->_migration_stages = [ |
|
47 | - |
|
48 | - ]; |
|
49 | - parent::__construct($table_manager, $table_analysis); |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * Whether to migrate or not. |
|
55 | - * |
|
56 | - * @param array $version_array |
|
57 | - * @return bool |
|
58 | - */ |
|
59 | - public function can_migrate_from_version($version_array): bool |
|
60 | - { |
|
61 | - $version_string = $version_array['Core']; |
|
62 | - return $version_string |
|
63 | - && version_compare($version_string, '5.0.0.decaf', '<') |
|
64 | - && version_compare($version_string, '4.10.0.decaf', '>='); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * @return bool |
|
70 | - * @throws EE_Error |
|
71 | - * @throws ReflectionException |
|
72 | - */ |
|
73 | - public function schema_changes_before_migration(): bool |
|
74 | - { |
|
75 | - require_once EE_HELPERS . 'EEH_Activation.helper.php'; |
|
76 | - |
|
77 | - $this->_table_has_not_changed_since_previous( |
|
78 | - 'esp_answer', |
|
79 | - ' ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
32 | + /** |
|
33 | + * |
|
34 | + * @param EE_DMS_Core_4_10_0 $dms_4_10 |
|
35 | + * @param TableManager|null $table_manager |
|
36 | + * @param TableAnalysis|null $table_analysis |
|
37 | + */ |
|
38 | + public function __construct( |
|
39 | + EE_DMS_Core_4_10_0 $dms_4_10, |
|
40 | + TableManager $table_manager = null, |
|
41 | + TableAnalysis $table_analysis = null |
|
42 | + ) { |
|
43 | + $this->previous_dms = $dms_4_10; |
|
44 | + $this->_pretty_name = esc_html__("Data Update to Event Espresso 5.0.0", "event_espresso"); |
|
45 | + $this->_priority = 10; |
|
46 | + $this->_migration_stages = [ |
|
47 | + |
|
48 | + ]; |
|
49 | + parent::__construct($table_manager, $table_analysis); |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * Whether to migrate or not. |
|
55 | + * |
|
56 | + * @param array $version_array |
|
57 | + * @return bool |
|
58 | + */ |
|
59 | + public function can_migrate_from_version($version_array): bool |
|
60 | + { |
|
61 | + $version_string = $version_array['Core']; |
|
62 | + return $version_string |
|
63 | + && version_compare($version_string, '5.0.0.decaf', '<') |
|
64 | + && version_compare($version_string, '4.10.0.decaf', '>='); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * @return bool |
|
70 | + * @throws EE_Error |
|
71 | + * @throws ReflectionException |
|
72 | + */ |
|
73 | + public function schema_changes_before_migration(): bool |
|
74 | + { |
|
75 | + require_once EE_HELPERS . 'EEH_Activation.helper.php'; |
|
76 | + |
|
77 | + $this->_table_has_not_changed_since_previous( |
|
78 | + 'esp_answer', |
|
79 | + ' ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
80 | 80 | REG_ID int(10) unsigned NOT NULL, |
81 | 81 | QST_ID int(10) unsigned NOT NULL, |
82 | 82 | ANS_value text NOT NULL, |
83 | 83 | PRIMARY KEY (ANS_ID), |
84 | 84 | KEY REG_ID (REG_ID), |
85 | 85 | KEY QST_ID (QST_ID)', |
86 | - 'ENGINE=InnoDB' |
|
87 | - ); |
|
86 | + 'ENGINE=InnoDB' |
|
87 | + ); |
|
88 | 88 | |
89 | 89 | |
90 | - $this->_table_has_not_changed_since_previous( |
|
91 | - 'esp_attendee_meta', |
|
92 | - "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
90 | + $this->_table_has_not_changed_since_previous( |
|
91 | + 'esp_attendee_meta', |
|
92 | + "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
93 | 93 | ATT_ID bigint(20) unsigned NOT NULL, |
94 | 94 | ATT_fname varchar(45) NOT NULL, |
95 | 95 | ATT_lname varchar(45) NOT NULL, |
@@ -106,13 +106,13 @@ discard block |
||
106 | 106 | KEY ATT_email (ATT_email(191)), |
107 | 107 | KEY ATT_lname (ATT_lname), |
108 | 108 | KEY ATT_fname (ATT_fname)", |
109 | - 'ENGINE=InnoDB' |
|
110 | - ); |
|
109 | + 'ENGINE=InnoDB' |
|
110 | + ); |
|
111 | 111 | |
112 | 112 | |
113 | - $this->_table_has_not_changed_since_previous( |
|
114 | - 'esp_checkin', |
|
115 | - "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
113 | + $this->_table_has_not_changed_since_previous( |
|
114 | + 'esp_checkin', |
|
115 | + "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
116 | 116 | REG_ID int(10) unsigned NOT NULL, |
117 | 117 | DTT_ID int(10) unsigned NOT NULL, |
118 | 118 | CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -120,13 +120,13 @@ discard block |
||
120 | 120 | PRIMARY KEY (CHK_ID), |
121 | 121 | KEY REG_ID (REG_ID), |
122 | 122 | KEY DTT_ID (DTT_ID)", |
123 | - 'ENGINE=InnoDB' |
|
124 | - ); |
|
123 | + 'ENGINE=InnoDB' |
|
124 | + ); |
|
125 | 125 | |
126 | 126 | |
127 | - $this->_table_has_not_changed_since_previous( |
|
128 | - 'esp_country', |
|
129 | - "CNT_ISO varchar(2) NOT NULL, |
|
127 | + $this->_table_has_not_changed_since_previous( |
|
128 | + 'esp_country', |
|
129 | + "CNT_ISO varchar(2) NOT NULL, |
|
130 | 130 | CNT_ISO3 varchar(3) NOT NULL, |
131 | 131 | RGN_ID tinyint(3) unsigned DEFAULT NULL, |
132 | 132 | CNT_name varchar(45) NOT NULL, |
@@ -142,41 +142,41 @@ discard block |
||
142 | 142 | CNT_is_EU tinyint(1) DEFAULT '0', |
143 | 143 | CNT_active tinyint(1) DEFAULT '0', |
144 | 144 | PRIMARY KEY (CNT_ISO)", |
145 | - 'ENGINE=InnoDB' |
|
146 | - ); |
|
145 | + 'ENGINE=InnoDB' |
|
146 | + ); |
|
147 | 147 | |
148 | 148 | |
149 | - $this->_table_has_not_changed_since_previous( |
|
150 | - 'esp_currency', |
|
151 | - "CUR_code varchar(6) NOT NULL, |
|
149 | + $this->_table_has_not_changed_since_previous( |
|
150 | + 'esp_currency', |
|
151 | + "CUR_code varchar(6) NOT NULL, |
|
152 | 152 | CUR_single varchar(45) DEFAULT 'dollar', |
153 | 153 | CUR_plural varchar(45) DEFAULT 'dollars', |
154 | 154 | CUR_sign varchar(45) DEFAULT '$', |
155 | 155 | CUR_dec_plc varchar(1) NOT NULL DEFAULT '2', |
156 | 156 | CUR_active tinyint(1) DEFAULT '0', |
157 | 157 | PRIMARY KEY (CUR_code)", |
158 | - 'ENGINE=InnoDB' |
|
159 | - ); |
|
158 | + 'ENGINE=InnoDB' |
|
159 | + ); |
|
160 | 160 | |
161 | 161 | |
162 | - // note: although this table is no longer in use, |
|
163 | - // it hasn't been removed because then queries to the model will have errors. |
|
164 | - // but you should expect this table and its corresponding model to be removed in |
|
165 | - // the next few months |
|
166 | - $this->_table_is_new_in_this_version( |
|
167 | - 'esp_currency_payment_method', |
|
168 | - "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
162 | + // note: although this table is no longer in use, |
|
163 | + // it hasn't been removed because then queries to the model will have errors. |
|
164 | + // but you should expect this table and its corresponding model to be removed in |
|
165 | + // the next few months |
|
166 | + $this->_table_is_new_in_this_version( |
|
167 | + 'esp_currency_payment_method', |
|
168 | + "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
169 | 169 | CUR_code varchar(6) NOT NULL, |
170 | 170 | PMD_ID int(11) NOT NULL, |
171 | 171 | PRIMARY KEY (CPM_ID), |
172 | 172 | KEY PMD_ID (PMD_ID)", |
173 | - 'ENGINE=InnoDB' |
|
174 | - ); |
|
173 | + 'ENGINE=InnoDB' |
|
174 | + ); |
|
175 | 175 | |
176 | 176 | |
177 | - $this->_table_is_changed_in_this_version( |
|
178 | - 'esp_datetime', |
|
179 | - "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
177 | + $this->_table_is_changed_in_this_version( |
|
178 | + 'esp_datetime', |
|
179 | + "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
180 | 180 | EVT_ID bigint(20) unsigned NOT NULL, |
181 | 181 | VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
182 | 182 | DTT_name varchar(255) NOT NULL DEFAULT '', |
@@ -194,37 +194,37 @@ discard block |
||
194 | 194 | KEY DTT_EVT_start (DTT_EVT_start), |
195 | 195 | KEY EVT_ID (EVT_ID), |
196 | 196 | KEY DTT_is_primary (DTT_is_primary)", |
197 | - 'ENGINE=InnoDB' |
|
198 | - ); |
|
197 | + 'ENGINE=InnoDB' |
|
198 | + ); |
|
199 | 199 | |
200 | 200 | |
201 | - $this->_table_has_not_changed_since_previous( |
|
202 | - 'esp_datetime_ticket', |
|
203 | - "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
201 | + $this->_table_has_not_changed_since_previous( |
|
202 | + 'esp_datetime_ticket', |
|
203 | + "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
204 | 204 | DTT_ID int(10) unsigned NOT NULL, |
205 | 205 | TKT_ID int(10) unsigned NOT NULL, |
206 | 206 | PRIMARY KEY (DTK_ID), |
207 | 207 | KEY DTT_ID (DTT_ID), |
208 | 208 | KEY TKT_ID (TKT_ID)", |
209 | - 'ENGINE=InnoDB' |
|
210 | - ); |
|
209 | + 'ENGINE=InnoDB' |
|
210 | + ); |
|
211 | 211 | |
212 | 212 | |
213 | - $this->_table_has_not_changed_since_previous( |
|
214 | - 'esp_event_message_template', |
|
215 | - "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
213 | + $this->_table_has_not_changed_since_previous( |
|
214 | + 'esp_event_message_template', |
|
215 | + "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
216 | 216 | EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
217 | 217 | GRP_ID int(10) unsigned NOT NULL DEFAULT 0, |
218 | 218 | PRIMARY KEY (EMT_ID), |
219 | 219 | KEY EVT_ID (EVT_ID), |
220 | 220 | KEY GRP_ID (GRP_ID)", |
221 | - 'ENGINE=InnoDB' |
|
222 | - ); |
|
221 | + 'ENGINE=InnoDB' |
|
222 | + ); |
|
223 | 223 | |
224 | 224 | |
225 | - $this->_table_is_changed_in_this_version( |
|
226 | - 'esp_event_meta', |
|
227 | - "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
225 | + $this->_table_is_changed_in_this_version( |
|
226 | + 'esp_event_meta', |
|
227 | + "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
228 | 228 | EVT_ID bigint(20) unsigned NOT NULL, |
229 | 229 | VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
230 | 230 | EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -241,13 +241,13 @@ discard block |
||
241 | 241 | FSC_UUID varchar(25) DEFAULT NULL, |
242 | 242 | PRIMARY KEY (EVTM_ID), |
243 | 243 | KEY EVT_ID (EVT_ID)", |
244 | - 'ENGINE=InnoDB' |
|
245 | - ); |
|
244 | + 'ENGINE=InnoDB' |
|
245 | + ); |
|
246 | 246 | |
247 | 247 | |
248 | - $this->_table_has_not_changed_since_previous( |
|
249 | - 'esp_event_question_group', |
|
250 | - "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
248 | + $this->_table_has_not_changed_since_previous( |
|
249 | + 'esp_event_question_group', |
|
250 | + "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
251 | 251 | EVT_ID bigint(20) unsigned NOT NULL, |
252 | 252 | QSG_ID int(10) unsigned NOT NULL, |
253 | 253 | EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
@@ -255,37 +255,37 @@ discard block |
||
255 | 255 | PRIMARY KEY (EQG_ID), |
256 | 256 | KEY EVT_ID (EVT_ID), |
257 | 257 | KEY QSG_ID (QSG_ID)", |
258 | - 'ENGINE=InnoDB' |
|
259 | - ); |
|
258 | + 'ENGINE=InnoDB' |
|
259 | + ); |
|
260 | 260 | |
261 | 261 | |
262 | - $this->_table_has_not_changed_since_previous( |
|
263 | - 'esp_event_venue', |
|
264 | - "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
262 | + $this->_table_has_not_changed_since_previous( |
|
263 | + 'esp_event_venue', |
|
264 | + "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
265 | 265 | EVT_ID bigint(20) unsigned NOT NULL, |
266 | 266 | VNU_ID bigint(20) unsigned NOT NULL, |
267 | 267 | EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
268 | 268 | PRIMARY KEY (EVV_ID)", |
269 | - 'ENGINE=InnoDB' |
|
270 | - ); |
|
269 | + 'ENGINE=InnoDB' |
|
270 | + ); |
|
271 | 271 | |
272 | 272 | |
273 | - $this->_table_has_not_changed_since_previous( |
|
274 | - 'esp_extra_meta', |
|
275 | - "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
273 | + $this->_table_has_not_changed_since_previous( |
|
274 | + 'esp_extra_meta', |
|
275 | + "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
276 | 276 | OBJ_ID int(11) DEFAULT NULL, |
277 | 277 | EXM_type varchar(45) DEFAULT NULL, |
278 | 278 | EXM_key varchar(45) DEFAULT NULL, |
279 | 279 | EXM_value text, |
280 | 280 | PRIMARY KEY (EXM_ID), |
281 | 281 | KEY EXM_type (EXM_type,OBJ_ID,EXM_key)", |
282 | - 'ENGINE=InnoDB' |
|
283 | - ); |
|
282 | + 'ENGINE=InnoDB' |
|
283 | + ); |
|
284 | 284 | |
285 | 285 | |
286 | - $this->_table_has_not_changed_since_previous( |
|
287 | - 'esp_extra_join', |
|
288 | - "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
286 | + $this->_table_has_not_changed_since_previous( |
|
287 | + 'esp_extra_join', |
|
288 | + "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
289 | 289 | EXJ_first_model_id varchar(6) NOT NULL, |
290 | 290 | EXJ_first_model_name varchar(20) NOT NULL, |
291 | 291 | EXJ_second_model_id varchar(6) NOT NULL, |
@@ -293,13 +293,13 @@ discard block |
||
293 | 293 | PRIMARY KEY (EXJ_ID), |
294 | 294 | KEY first_model (EXJ_first_model_name,EXJ_first_model_id), |
295 | 295 | KEY second_model (EXJ_second_model_name,EXJ_second_model_id)", |
296 | - 'ENGINE=InnoDB' |
|
297 | - ); |
|
296 | + 'ENGINE=InnoDB' |
|
297 | + ); |
|
298 | 298 | |
299 | 299 | |
300 | - $this->_table_is_new_in_this_version( |
|
301 | - 'esp_form_element', |
|
302 | - "FIN_UUID varchar(25) NOT NULL, |
|
300 | + $this->_table_is_new_in_this_version( |
|
301 | + 'esp_form_element', |
|
302 | + "FIN_UUID varchar(25) NOT NULL, |
|
303 | 303 | FSC_UUID varchar(25) NOT NULL, |
304 | 304 | FIN_adminOnly tinyint(1) unsigned NOT NULL DEFAULT 0, |
305 | 305 | FIN_attributes text DEFAULT NULL, |
@@ -316,13 +316,13 @@ discard block |
||
316 | 316 | KEY FSC_UUID (FSC_UUID), |
317 | 317 | KEY FIN_order (FIN_order), |
318 | 318 | KEY FIN_status (FIN_status)", |
319 | - 'ENGINE=InnoDB' |
|
320 | - ); |
|
319 | + 'ENGINE=InnoDB' |
|
320 | + ); |
|
321 | 321 | |
322 | 322 | |
323 | - $this->_table_is_new_in_this_version( |
|
324 | - 'esp_form_section', |
|
325 | - "FSC_UUID varchar(25) NOT NULL, |
|
323 | + $this->_table_is_new_in_this_version( |
|
324 | + 'esp_form_section', |
|
325 | + "FSC_UUID varchar(25) NOT NULL, |
|
326 | 326 | FSC_appliesTo tinytext NOT NULL, |
327 | 327 | FSC_attributes text DEFAULT NULL, |
328 | 328 | FSC_belongsTo varchar(25) DEFAULT NULL, |
@@ -334,13 +334,13 @@ discard block |
||
334 | 334 | KEY FSC_belongsTo (FSC_belongsTo), |
335 | 335 | KEY FSC_order (FSC_order), |
336 | 336 | KEY FSC_status (FSC_status)", |
337 | - 'ENGINE=InnoDB' |
|
338 | - ); |
|
337 | + 'ENGINE=InnoDB' |
|
338 | + ); |
|
339 | 339 | |
340 | 340 | |
341 | - $this->_table_is_new_in_this_version( |
|
342 | - 'esp_form_submission', |
|
343 | - "FSB_UUID varchar(25) NOT NULL, |
|
341 | + $this->_table_is_new_in_this_version( |
|
342 | + 'esp_form_submission', |
|
343 | + "FSB_UUID varchar(25) NOT NULL, |
|
344 | 344 | FSC_UUID varchar(25) NOT NULL, |
345 | 345 | TXN_ID int(10) DEFAULT NULL, |
346 | 346 | FSB_data mediumtext DEFAULT NULL, |
@@ -348,13 +348,13 @@ discard block |
||
348 | 348 | PRIMARY KEY (FSB_UUID), |
349 | 349 | KEY FSC_UUID (FSC_UUID), |
350 | 350 | KEY TXN_ID (TXN_ID)", |
351 | - 'ENGINE=InnoDB' |
|
352 | - ); |
|
351 | + 'ENGINE=InnoDB' |
|
352 | + ); |
|
353 | 353 | |
354 | 354 | |
355 | - $this->_table_is_changed_in_this_version( |
|
356 | - 'esp_line_item', |
|
357 | - "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
355 | + $this->_table_is_changed_in_this_version( |
|
356 | + 'esp_line_item', |
|
357 | + "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
358 | 358 | LIN_code varchar(245) NOT NULL DEFAULT '', |
359 | 359 | TXN_ID int(10) DEFAULT NULL, |
360 | 360 | LIN_name varchar(245) NOT NULL DEFAULT '', |
@@ -376,13 +376,13 @@ discard block |
||
376 | 376 | KEY txn_type_timestamp (TXN_ID,LIN_type,LIN_timestamp), |
377 | 377 | KEY txn_obj_id_obj_type (TXN_ID,OBJ_ID,OBJ_type), |
378 | 378 | KEY obj_id_obj_type (OBJ_ID,OBJ_type)", |
379 | - 'ENGINE=InnoDB' |
|
380 | - ); |
|
379 | + 'ENGINE=InnoDB' |
|
380 | + ); |
|
381 | 381 | |
382 | 382 | |
383 | - $this->_table_has_not_changed_since_previous( |
|
384 | - 'esp_log', |
|
385 | - "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
383 | + $this->_table_has_not_changed_since_previous( |
|
384 | + 'esp_log', |
|
385 | + "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
386 | 386 | LOG_time datetime DEFAULT NULL, |
387 | 387 | OBJ_ID varchar(45) DEFAULT NULL, |
388 | 388 | OBJ_type varchar(45) DEFAULT NULL, |
@@ -393,13 +393,13 @@ discard block |
||
393 | 393 | KEY LOG_time (LOG_time), |
394 | 394 | KEY OBJ (OBJ_type,OBJ_ID), |
395 | 395 | KEY LOG_type (LOG_type)", |
396 | - 'ENGINE=InnoDB' |
|
397 | - ); |
|
396 | + 'ENGINE=InnoDB' |
|
397 | + ); |
|
398 | 398 | |
399 | 399 | |
400 | - $this->_table_has_not_changed_since_previous( |
|
401 | - 'esp_message', |
|
402 | - "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
400 | + $this->_table_has_not_changed_since_previous( |
|
401 | + 'esp_message', |
|
402 | + "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
403 | 403 | GRP_ID int(10) unsigned NULL, |
404 | 404 | MSG_token varchar(255) NULL, |
405 | 405 | TXN_ID int(10) unsigned NULL, |
@@ -431,26 +431,26 @@ discard block |
||
431 | 431 | KEY STS_ID (STS_ID), |
432 | 432 | KEY MSG_created (MSG_created), |
433 | 433 | KEY MSG_modified (MSG_modified)", |
434 | - 'ENGINE=InnoDB' |
|
435 | - ); |
|
434 | + 'ENGINE=InnoDB' |
|
435 | + ); |
|
436 | 436 | |
437 | 437 | |
438 | - $this->_table_has_not_changed_since_previous( |
|
439 | - 'esp_message_template', |
|
440 | - "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
438 | + $this->_table_has_not_changed_since_previous( |
|
439 | + 'esp_message_template', |
|
440 | + "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
441 | 441 | GRP_ID int(10) unsigned NOT NULL, |
442 | 442 | MTP_context varchar(50) NOT NULL, |
443 | 443 | MTP_template_field varchar(30) NOT NULL, |
444 | 444 | MTP_content text NOT NULL, |
445 | 445 | PRIMARY KEY (MTP_ID), |
446 | 446 | KEY GRP_ID (GRP_ID)", |
447 | - 'ENGINE=InnoDB' |
|
448 | - ); |
|
447 | + 'ENGINE=InnoDB' |
|
448 | + ); |
|
449 | 449 | |
450 | 450 | |
451 | - $this->_table_has_not_changed_since_previous( |
|
452 | - 'esp_message_template_group', |
|
453 | - "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
451 | + $this->_table_has_not_changed_since_previous( |
|
452 | + 'esp_message_template_group', |
|
453 | + "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
454 | 454 | MTP_user_id int(10) NOT NULL DEFAULT '1', |
455 | 455 | MTP_name varchar(245) NOT NULL DEFAULT '', |
456 | 456 | MTP_description varchar(245) NOT NULL DEFAULT '', |
@@ -462,13 +462,13 @@ discard block |
||
462 | 462 | MTP_is_active tinyint(1) NOT NULL DEFAULT '1', |
463 | 463 | PRIMARY KEY (GRP_ID), |
464 | 464 | KEY MTP_user_id (MTP_user_id)", |
465 | - 'ENGINE=InnoDB' |
|
466 | - ); |
|
465 | + 'ENGINE=InnoDB' |
|
466 | + ); |
|
467 | 467 | |
468 | 468 | |
469 | - $this->_table_has_not_changed_since_previous( |
|
470 | - 'esp_payment', |
|
471 | - "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
469 | + $this->_table_has_not_changed_since_previous( |
|
470 | + 'esp_payment', |
|
471 | + "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
472 | 472 | TXN_ID int(10) unsigned DEFAULT NULL, |
473 | 473 | STS_ID varchar(3) DEFAULT NULL, |
474 | 474 | PAY_timestamp datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
@@ -485,13 +485,13 @@ discard block |
||
485 | 485 | PRIMARY KEY (PAY_ID), |
486 | 486 | KEY PAY_timestamp (PAY_timestamp), |
487 | 487 | KEY TXN_ID (TXN_ID)", |
488 | - 'ENGINE=InnoDB' |
|
489 | - ); |
|
488 | + 'ENGINE=InnoDB' |
|
489 | + ); |
|
490 | 490 | |
491 | 491 | |
492 | - $this->_table_has_not_changed_since_previous( |
|
493 | - 'esp_payment_method', |
|
494 | - "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
492 | + $this->_table_has_not_changed_since_previous( |
|
493 | + 'esp_payment_method', |
|
494 | + "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
495 | 495 | PMD_type varchar(124) DEFAULT NULL, |
496 | 496 | PMD_name varchar(255) DEFAULT NULL, |
497 | 497 | PMD_desc text, |
@@ -507,13 +507,13 @@ discard block |
||
507 | 507 | PRIMARY KEY (PMD_ID), |
508 | 508 | UNIQUE KEY PMD_slug_UNIQUE (PMD_slug), |
509 | 509 | KEY PMD_type (PMD_type)", |
510 | - 'ENGINE=InnoDB' |
|
511 | - ); |
|
510 | + 'ENGINE=InnoDB' |
|
511 | + ); |
|
512 | 512 | |
513 | 513 | |
514 | - $this->_table_is_changed_in_this_version( |
|
515 | - 'esp_price', |
|
516 | - "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
514 | + $this->_table_is_changed_in_this_version( |
|
515 | + 'esp_price', |
|
516 | + "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
517 | 517 | PRT_ID tinyint(3) unsigned NOT NULL, |
518 | 518 | PRC_amount decimal(12,6) NOT NULL DEFAULT '0.00', |
519 | 519 | PRC_name varchar(245) NOT NULL, |
@@ -526,13 +526,13 @@ discard block |
||
526 | 526 | PRC_parent int(10) unsigned DEFAULT 0, |
527 | 527 | PRIMARY KEY (PRC_ID), |
528 | 528 | KEY PRT_ID (PRT_ID)", |
529 | - 'ENGINE=InnoDB' |
|
530 | - ); |
|
529 | + 'ENGINE=InnoDB' |
|
530 | + ); |
|
531 | 531 | |
532 | 532 | |
533 | - $this->_table_has_not_changed_since_previous( |
|
534 | - 'esp_price_type', |
|
535 | - "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
533 | + $this->_table_has_not_changed_since_previous( |
|
534 | + 'esp_price_type', |
|
535 | + "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
536 | 536 | PRT_name varchar(45) NOT NULL, |
537 | 537 | PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1', |
538 | 538 | PRT_is_percent tinyint(1) NOT NULL DEFAULT '0', |
@@ -541,36 +541,36 @@ discard block |
||
541 | 541 | PRT_deleted tinyint(1) NOT NULL DEFAULT '0', |
542 | 542 | UNIQUE KEY PRT_name_UNIQUE (PRT_name), |
543 | 543 | PRIMARY KEY (PRT_ID)", |
544 | - 'ENGINE=InnoDB' |
|
545 | - ); |
|
544 | + 'ENGINE=InnoDB' |
|
545 | + ); |
|
546 | 546 | |
547 | 547 | |
548 | - $this->_table_has_not_changed_since_previous( |
|
549 | - 'esp_ticket_price', |
|
550 | - "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
548 | + $this->_table_has_not_changed_since_previous( |
|
549 | + 'esp_ticket_price', |
|
550 | + "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
551 | 551 | TKT_ID int(10) unsigned NOT NULL, |
552 | 552 | PRC_ID int(10) unsigned NOT NULL, |
553 | 553 | PRIMARY KEY (TKP_ID), |
554 | 554 | KEY TKT_ID (TKT_ID), |
555 | 555 | KEY PRC_ID (PRC_ID)", |
556 | - 'ENGINE=InnoDB' |
|
557 | - ); |
|
556 | + 'ENGINE=InnoDB' |
|
557 | + ); |
|
558 | 558 | |
559 | 559 | |
560 | - $this->_table_has_not_changed_since_previous( |
|
561 | - 'esp_ticket_template', |
|
562 | - "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
560 | + $this->_table_has_not_changed_since_previous( |
|
561 | + 'esp_ticket_template', |
|
562 | + "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
563 | 563 | TTM_name varchar(45) NOT NULL, |
564 | 564 | TTM_description text, |
565 | 565 | TTM_file varchar(45), |
566 | 566 | PRIMARY KEY (TTM_ID)", |
567 | - 'ENGINE=InnoDB' |
|
568 | - ); |
|
567 | + 'ENGINE=InnoDB' |
|
568 | + ); |
|
569 | 569 | |
570 | 570 | |
571 | - $this->_table_has_not_changed_since_previous( |
|
572 | - 'esp_question', |
|
573 | - "QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
571 | + $this->_table_has_not_changed_since_previous( |
|
572 | + 'esp_question', |
|
573 | + "QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
574 | 574 | QST_display_text text NOT NULL, |
575 | 575 | QST_admin_label varchar(255) NOT NULL, |
576 | 576 | QST_system varchar(25) DEFAULT NULL, |
@@ -584,13 +584,13 @@ discard block |
||
584 | 584 | QST_deleted tinyint(2) unsigned NOT NULL DEFAULT 0, |
585 | 585 | PRIMARY KEY (QST_ID), |
586 | 586 | KEY QST_order (QST_order)", |
587 | - 'ENGINE=InnoDB' |
|
588 | - ); |
|
587 | + 'ENGINE=InnoDB' |
|
588 | + ); |
|
589 | 589 | |
590 | 590 | |
591 | - $this->_table_has_not_changed_since_previous( |
|
592 | - 'esp_question_group', |
|
593 | - "QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
591 | + $this->_table_has_not_changed_since_previous( |
|
592 | + 'esp_question_group', |
|
593 | + "QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
594 | 594 | QSG_name varchar(255) NOT NULL, |
595 | 595 | QSG_identifier varchar(100) NOT NULL, |
596 | 596 | QSG_desc text NULL, |
@@ -603,26 +603,26 @@ discard block |
||
603 | 603 | PRIMARY KEY (QSG_ID), |
604 | 604 | UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier), |
605 | 605 | KEY QSG_order (QSG_order)", |
606 | - 'ENGINE=InnoDB' |
|
607 | - ); |
|
606 | + 'ENGINE=InnoDB' |
|
607 | + ); |
|
608 | 608 | |
609 | 609 | |
610 | - $this->_table_has_not_changed_since_previous( |
|
611 | - 'esp_question_group_question', |
|
612 | - "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
610 | + $this->_table_has_not_changed_since_previous( |
|
611 | + 'esp_question_group_question', |
|
612 | + "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
613 | 613 | QSG_ID int(10) unsigned NOT NULL, |
614 | 614 | QST_ID int(10) unsigned NOT NULL, |
615 | 615 | QGQ_order int(10) unsigned NOT NULL DEFAULT 0, |
616 | 616 | PRIMARY KEY (QGQ_ID), |
617 | 617 | KEY QST_ID (QST_ID), |
618 | 618 | KEY QSG_ID_order (QSG_ID,QGQ_order)", |
619 | - 'ENGINE=InnoDB' |
|
620 | - ); |
|
619 | + 'ENGINE=InnoDB' |
|
620 | + ); |
|
621 | 621 | |
622 | 622 | |
623 | - $this->_table_has_not_changed_since_previous( |
|
624 | - 'esp_question_option', |
|
625 | - "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
623 | + $this->_table_has_not_changed_since_previous( |
|
624 | + 'esp_question_option', |
|
625 | + "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
626 | 626 | QSO_value varchar(255) NOT NULL, |
627 | 627 | QSO_desc text NOT NULL, |
628 | 628 | QST_ID int(10) unsigned NOT NULL, |
@@ -632,13 +632,13 @@ discard block |
||
632 | 632 | PRIMARY KEY (QSO_ID), |
633 | 633 | KEY QST_ID (QST_ID), |
634 | 634 | KEY QSO_order (QSO_order)", |
635 | - 'ENGINE=InnoDB' |
|
636 | - ); |
|
635 | + 'ENGINE=InnoDB' |
|
636 | + ); |
|
637 | 637 | |
638 | 638 | |
639 | - $this->_table_has_not_changed_since_previous( |
|
640 | - 'esp_registration', |
|
641 | - "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
639 | + $this->_table_has_not_changed_since_previous( |
|
640 | + 'esp_registration', |
|
641 | + "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
642 | 642 | EVT_ID bigint(20) unsigned NOT NULL, |
643 | 643 | ATT_ID bigint(20) unsigned NOT NULL, |
644 | 644 | TXN_ID int(10) unsigned NOT NULL, |
@@ -662,26 +662,26 @@ discard block |
||
662 | 662 | KEY TKT_ID (TKT_ID), |
663 | 663 | KEY EVT_ID (EVT_ID), |
664 | 664 | KEY STS_ID (STS_ID)", |
665 | - 'ENGINE=InnoDB' |
|
666 | - ); |
|
665 | + 'ENGINE=InnoDB' |
|
666 | + ); |
|
667 | 667 | |
668 | 668 | |
669 | - $this->_table_has_not_changed_since_previous( |
|
670 | - 'esp_registration_payment', |
|
671 | - "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
669 | + $this->_table_has_not_changed_since_previous( |
|
670 | + 'esp_registration_payment', |
|
671 | + "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
672 | 672 | REG_ID int(10) unsigned NOT NULL, |
673 | 673 | PAY_ID int(10) unsigned NULL, |
674 | 674 | RPY_amount decimal(12,3) NOT NULL DEFAULT '0.00', |
675 | 675 | PRIMARY KEY (RPY_ID), |
676 | 676 | KEY REG_ID (REG_ID), |
677 | 677 | KEY PAY_ID (PAY_ID)", |
678 | - 'ENGINE=InnoDB' |
|
679 | - ); |
|
678 | + 'ENGINE=InnoDB' |
|
679 | + ); |
|
680 | 680 | |
681 | 681 | |
682 | - $this->_table_has_not_changed_since_previous( |
|
683 | - 'esp_state', |
|
684 | - "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
682 | + $this->_table_has_not_changed_since_previous( |
|
683 | + 'esp_state', |
|
684 | + "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
685 | 685 | CNT_ISO varchar(2) NOT NULL, |
686 | 686 | STA_abbrev varchar(24) NOT NULL, |
687 | 687 | STA_name varchar(100) NOT NULL, |
@@ -689,13 +689,13 @@ discard block |
||
689 | 689 | PRIMARY KEY (STA_ID), |
690 | 690 | KEY STA_abbrev (STA_abbrev), |
691 | 691 | KEY CNT_ISO (CNT_ISO)", |
692 | - 'ENGINE=InnoDB' |
|
693 | - ); |
|
692 | + 'ENGINE=InnoDB' |
|
693 | + ); |
|
694 | 694 | |
695 | 695 | |
696 | - $this->_table_has_not_changed_since_previous( |
|
697 | - 'esp_status', |
|
698 | - "STS_ID varchar(3) NOT NULL, |
|
696 | + $this->_table_has_not_changed_since_previous( |
|
697 | + 'esp_status', |
|
698 | + "STS_ID varchar(3) NOT NULL, |
|
699 | 699 | STS_code varchar(45) NOT NULL, |
700 | 700 | STS_type varchar(45) NOT NULL, |
701 | 701 | STS_can_edit tinyint(1) NOT NULL DEFAULT 0, |
@@ -703,13 +703,13 @@ discard block |
||
703 | 703 | STS_open tinyint(1) NOT NULL DEFAULT 1, |
704 | 704 | UNIQUE KEY STS_ID_UNIQUE (STS_ID), |
705 | 705 | KEY STS_type (STS_type)", |
706 | - 'ENGINE=InnoDB' |
|
707 | - ); |
|
706 | + 'ENGINE=InnoDB' |
|
707 | + ); |
|
708 | 708 | |
709 | 709 | |
710 | - $this->_table_is_changed_in_this_version( |
|
711 | - 'esp_ticket', |
|
712 | - "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
710 | + $this->_table_is_changed_in_this_version( |
|
711 | + 'esp_ticket', |
|
712 | + "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
713 | 713 | TTM_ID int(10) unsigned NOT NULL, |
714 | 714 | TKT_name varchar(245) NOT NULL DEFAULT '', |
715 | 715 | TKT_description text NOT NULL, |
@@ -734,13 +734,13 @@ discard block |
||
734 | 734 | TKT_visibility smallint(6) unsigned NOT NULL DEFAULT 100, |
735 | 735 | PRIMARY KEY (TKT_ID), |
736 | 736 | KEY TKT_start_date (TKT_start_date)", |
737 | - 'ENGINE=InnoDB' |
|
738 | - ); |
|
737 | + 'ENGINE=InnoDB' |
|
738 | + ); |
|
739 | 739 | |
740 | 740 | |
741 | - $this->_table_has_not_changed_since_previous( |
|
742 | - 'esp_transaction', |
|
743 | - "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
741 | + $this->_table_has_not_changed_since_previous( |
|
742 | + 'esp_transaction', |
|
743 | + "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
744 | 744 | TXN_timestamp datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, |
745 | 745 | TXN_total decimal(12,3) DEFAULT '0.00', |
746 | 746 | TXN_paid decimal(12,3) NOT NULL DEFAULT '0.00', |
@@ -752,13 +752,13 @@ discard block |
||
752 | 752 | PRIMARY KEY (TXN_ID), |
753 | 753 | KEY TXN_timestamp (TXN_timestamp), |
754 | 754 | KEY STS_ID (STS_ID)", |
755 | - 'ENGINE=InnoDB' |
|
756 | - ); |
|
755 | + 'ENGINE=InnoDB' |
|
756 | + ); |
|
757 | 757 | |
758 | 758 | |
759 | - $this->_table_has_not_changed_since_previous( |
|
760 | - 'esp_venue_meta', |
|
761 | - 'VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
759 | + $this->_table_has_not_changed_since_previous( |
|
760 | + 'esp_venue_meta', |
|
761 | + 'VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
762 | 762 | VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
763 | 763 | VNU_address varchar(255) DEFAULT NULL, |
764 | 764 | VNU_address2 varchar(255) DEFAULT NULL, |
@@ -777,28 +777,28 @@ discard block |
||
777 | 777 | KEY VNU_ID (VNU_ID), |
778 | 778 | KEY STA_ID (STA_ID), |
779 | 779 | KEY CNT_ISO (CNT_ISO)', |
780 | - 'ENGINE=InnoDB' |
|
781 | - ); |
|
780 | + 'ENGINE=InnoDB' |
|
781 | + ); |
|
782 | 782 | |
783 | - EE_Data_Migration_Script_Base::_delete_table_if_empty('esp_currency_payment_method'); |
|
783 | + EE_Data_Migration_Script_Base::_delete_table_if_empty('esp_currency_payment_method'); |
|
784 | 784 | |
785 | - $this->previous_dms->insert_default_data(); |
|
786 | - $LegacyTextDomainOptions = new LegacyTextDomainOptions(); |
|
787 | - $LegacyTextDomainOptions->convertToConsolidatedFormat(); |
|
788 | - return true; |
|
789 | - } |
|
785 | + $this->previous_dms->insert_default_data(); |
|
786 | + $LegacyTextDomainOptions = new LegacyTextDomainOptions(); |
|
787 | + $LegacyTextDomainOptions->convertToConsolidatedFormat(); |
|
788 | + return true; |
|
789 | + } |
|
790 | 790 | |
791 | 791 | |
792 | - /** |
|
793 | - * @return bool |
|
794 | - */ |
|
795 | - public function schema_changes_after_migration(): bool |
|
796 | - { |
|
797 | - return true; |
|
798 | - } |
|
792 | + /** |
|
793 | + * @return bool |
|
794 | + */ |
|
795 | + public function schema_changes_after_migration(): bool |
|
796 | + { |
|
797 | + return true; |
|
798 | + } |
|
799 | 799 | |
800 | 800 | |
801 | - public function migration_page_hooks() |
|
802 | - { |
|
803 | - } |
|
801 | + public function migration_page_hooks() |
|
802 | + { |
|
803 | + } |
|
804 | 804 | } |
@@ -16,264 +16,264 @@ |
||
16 | 16 | */ |
17 | 17 | class TableManager extends EE_Base |
18 | 18 | { |
19 | - private ?TableAnalysis $table_analysis; |
|
19 | + private ?TableAnalysis $table_analysis; |
|
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * TableManager constructor. |
|
24 | - * |
|
25 | - * @param TableAnalysis $TableAnalysis |
|
26 | - */ |
|
27 | - public function __construct(TableAnalysis $TableAnalysis) |
|
28 | - { |
|
29 | - $this->table_analysis = $TableAnalysis; |
|
30 | - } |
|
22 | + /** |
|
23 | + * TableManager constructor. |
|
24 | + * |
|
25 | + * @param TableAnalysis $TableAnalysis |
|
26 | + */ |
|
27 | + public function __construct(TableAnalysis $TableAnalysis) |
|
28 | + { |
|
29 | + $this->table_analysis = $TableAnalysis; |
|
30 | + } |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * Gets the injected table analyzer, or throws an exception |
|
35 | - * |
|
36 | - * @return TableAnalysis |
|
37 | - * @throws EE_Error |
|
38 | - */ |
|
39 | - protected function getTableAnalysis(): ?TableAnalysis |
|
40 | - { |
|
41 | - if ($this->table_analysis instanceof TableAnalysis) { |
|
42 | - return $this->table_analysis; |
|
43 | - } else { |
|
44 | - throw new EE_Error( |
|
45 | - sprintf( |
|
46 | - esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
47 | - get_class($this) |
|
48 | - ) |
|
49 | - ); |
|
50 | - } |
|
51 | - } |
|
33 | + /** |
|
34 | + * Gets the injected table analyzer, or throws an exception |
|
35 | + * |
|
36 | + * @return TableAnalysis |
|
37 | + * @throws EE_Error |
|
38 | + */ |
|
39 | + protected function getTableAnalysis(): ?TableAnalysis |
|
40 | + { |
|
41 | + if ($this->table_analysis instanceof TableAnalysis) { |
|
42 | + return $this->table_analysis; |
|
43 | + } else { |
|
44 | + throw new EE_Error( |
|
45 | + sprintf( |
|
46 | + esc_html__('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
47 | + get_class($this) |
|
48 | + ) |
|
49 | + ); |
|
50 | + } |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * @param string $table_name which can optionally start with $wpdb->prefix or not |
|
56 | - * @param string $column_name |
|
57 | - * @param string $column_info |
|
58 | - * @return bool|false|int |
|
59 | - * @throws EE_Error |
|
60 | - */ |
|
61 | - public function addColumn(string $table_name, string $column_name, string $column_info = 'INT UNSIGNED NOT NULL') |
|
62 | - { |
|
63 | - if (apply_filters('FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', false)) { |
|
64 | - return false; |
|
65 | - } |
|
66 | - global $wpdb; |
|
67 | - $full_table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
68 | - $columns = $this->getTableColumns($table_name); |
|
69 | - if (! in_array($column_name, $columns)) { |
|
70 | - $alter_query = "ALTER TABLE $full_table_name ADD $column_name $column_info"; |
|
71 | - return $wpdb->query($alter_query); |
|
72 | - } |
|
73 | - return true; |
|
74 | - } |
|
54 | + /** |
|
55 | + * @param string $table_name which can optionally start with $wpdb->prefix or not |
|
56 | + * @param string $column_name |
|
57 | + * @param string $column_info |
|
58 | + * @return bool|false|int |
|
59 | + * @throws EE_Error |
|
60 | + */ |
|
61 | + public function addColumn(string $table_name, string $column_name, string $column_info = 'INT UNSIGNED NOT NULL') |
|
62 | + { |
|
63 | + if (apply_filters('FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', false)) { |
|
64 | + return false; |
|
65 | + } |
|
66 | + global $wpdb; |
|
67 | + $full_table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
68 | + $columns = $this->getTableColumns($table_name); |
|
69 | + if (! in_array($column_name, $columns)) { |
|
70 | + $alter_query = "ALTER TABLE $full_table_name ADD $column_name $column_info"; |
|
71 | + return $wpdb->query($alter_query); |
|
72 | + } |
|
73 | + return true; |
|
74 | + } |
|
75 | 75 | |
76 | 76 | |
77 | - /** |
|
78 | - * Gets the name of all columns on the table. $table_name can |
|
79 | - * optionally start with $wpdb->prefix or not |
|
80 | - * |
|
81 | - * @param string $table_name |
|
82 | - * @return array |
|
83 | - * @throws EE_Error |
|
84 | - * @global wpdb $wpdb |
|
85 | - */ |
|
86 | - public function getTableColumns(string $table_name): array |
|
87 | - { |
|
88 | - global $wpdb; |
|
89 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
90 | - $field_array = []; |
|
91 | - if (! empty($table_name)) { |
|
92 | - $columns = $wpdb->get_results("SHOW COLUMNS FROM $table_name "); |
|
93 | - if ($columns !== false) { |
|
94 | - foreach ($columns as $column) { |
|
95 | - $field_array[] = $column->Field; |
|
96 | - } |
|
97 | - } |
|
98 | - } |
|
99 | - return $field_array; |
|
100 | - } |
|
77 | + /** |
|
78 | + * Gets the name of all columns on the table. $table_name can |
|
79 | + * optionally start with $wpdb->prefix or not |
|
80 | + * |
|
81 | + * @param string $table_name |
|
82 | + * @return array |
|
83 | + * @throws EE_Error |
|
84 | + * @global wpdb $wpdb |
|
85 | + */ |
|
86 | + public function getTableColumns(string $table_name): array |
|
87 | + { |
|
88 | + global $wpdb; |
|
89 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
90 | + $field_array = []; |
|
91 | + if (! empty($table_name)) { |
|
92 | + $columns = $wpdb->get_results("SHOW COLUMNS FROM $table_name "); |
|
93 | + if ($columns !== false) { |
|
94 | + foreach ($columns as $column) { |
|
95 | + $field_array[] = $column->Field; |
|
96 | + } |
|
97 | + } |
|
98 | + } |
|
99 | + return $field_array; |
|
100 | + } |
|
101 | 101 | |
102 | 102 | |
103 | - /** |
|
104 | - * Drops the specified table from the database. $table_name can |
|
105 | - * optionally start with $wpdb->prefix or not |
|
106 | - * |
|
107 | - * @param string $table_name |
|
108 | - * @return bool|int |
|
109 | - * @throws EE_Error |
|
110 | - * @global wpdb $wpdb |
|
111 | - */ |
|
112 | - public function dropTable(string $table_name) |
|
113 | - { |
|
114 | - global $wpdb; |
|
115 | - if ($this->getTableAnalysis()->tableExists($table_name)) { |
|
116 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
117 | - return $wpdb->query("DROP TABLE IF EXISTS $table_name"); |
|
118 | - } |
|
119 | - return 0; |
|
120 | - } |
|
103 | + /** |
|
104 | + * Drops the specified table from the database. $table_name can |
|
105 | + * optionally start with $wpdb->prefix or not |
|
106 | + * |
|
107 | + * @param string $table_name |
|
108 | + * @return bool|int |
|
109 | + * @throws EE_Error |
|
110 | + * @global wpdb $wpdb |
|
111 | + */ |
|
112 | + public function dropTable(string $table_name) |
|
113 | + { |
|
114 | + global $wpdb; |
|
115 | + if ($this->getTableAnalysis()->tableExists($table_name)) { |
|
116 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
117 | + return $wpdb->query("DROP TABLE IF EXISTS $table_name"); |
|
118 | + } |
|
119 | + return 0; |
|
120 | + } |
|
121 | 121 | |
122 | 122 | |
123 | - /** |
|
124 | - * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
125 | - * each table name provided has a wpdb prefix attached, and that it exists. |
|
126 | - * Returns the list actually deleted |
|
127 | - * |
|
128 | - * @param string[] $table_names |
|
129 | - * @return array of table names which we deleted |
|
130 | - * @throws EE_Error |
|
131 | - * @global WPDB $wpdb |
|
132 | - */ |
|
133 | - public function dropTables(array $table_names): array |
|
134 | - { |
|
135 | - $tables_to_delete = []; |
|
136 | - foreach ($table_names as $table_name) { |
|
137 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
138 | - if ($this->getTableAnalysis()->tableExists($table_name)) { |
|
139 | - $tables_to_delete[ $table_name ] = $table_name; |
|
140 | - } |
|
141 | - } |
|
142 | - if (! empty($tables_to_delete)) { |
|
143 | - global $wpdb; |
|
144 | - // make sure we only have a unique strings in the array. |
|
145 | - $tables_to_delete = array_unique($tables_to_delete); |
|
146 | - $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete)); |
|
147 | - } |
|
148 | - return $tables_to_delete; |
|
149 | - } |
|
123 | + /** |
|
124 | + * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
125 | + * each table name provided has a wpdb prefix attached, and that it exists. |
|
126 | + * Returns the list actually deleted |
|
127 | + * |
|
128 | + * @param string[] $table_names |
|
129 | + * @return array of table names which we deleted |
|
130 | + * @throws EE_Error |
|
131 | + * @global WPDB $wpdb |
|
132 | + */ |
|
133 | + public function dropTables(array $table_names): array |
|
134 | + { |
|
135 | + $tables_to_delete = []; |
|
136 | + foreach ($table_names as $table_name) { |
|
137 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
138 | + if ($this->getTableAnalysis()->tableExists($table_name)) { |
|
139 | + $tables_to_delete[ $table_name ] = $table_name; |
|
140 | + } |
|
141 | + } |
|
142 | + if (! empty($tables_to_delete)) { |
|
143 | + global $wpdb; |
|
144 | + // make sure we only have a unique strings in the array. |
|
145 | + $tables_to_delete = array_unique($tables_to_delete); |
|
146 | + $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete)); |
|
147 | + } |
|
148 | + return $tables_to_delete; |
|
149 | + } |
|
150 | 150 | |
151 | 151 | |
152 | - /** |
|
153 | - * Drops the specified index from the specified table. $table_name can |
|
154 | - * optionally start with $wpdb->prefix or not |
|
155 | - * |
|
156 | - * @param string $table_name |
|
157 | - * @param string $index_name |
|
158 | - * @return bool|int the number of indexes dropped. False if there was a datbase error |
|
159 | - * @throws EE_Error |
|
160 | - * @global wpdb $wpdb |
|
161 | - */ |
|
162 | - public function dropIndex(string $table_name, string $index_name) |
|
163 | - { |
|
164 | - if (apply_filters('FHEE__EEH_Activation__drop_index__short_circuit', false)) { |
|
165 | - return 0; |
|
166 | - } |
|
167 | - global $wpdb; |
|
168 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
169 | - $index_exists_query = "SHOW INDEX FROM $table_name WHERE key_name = '$index_name'"; |
|
170 | - if ( |
|
171 | - $this->getTableAnalysis()->tableExists($table_name) |
|
172 | - && $wpdb->get_var($index_exists_query) |
|
173 | - === $table_name // using get_var with the $index_exists_query returns the table's name |
|
174 | - ) { |
|
175 | - return $wpdb->query("ALTER TABLE $table_name DROP INDEX $index_name"); |
|
176 | - } |
|
177 | - return 0; |
|
178 | - } |
|
152 | + /** |
|
153 | + * Drops the specified index from the specified table. $table_name can |
|
154 | + * optionally start with $wpdb->prefix or not |
|
155 | + * |
|
156 | + * @param string $table_name |
|
157 | + * @param string $index_name |
|
158 | + * @return bool|int the number of indexes dropped. False if there was a datbase error |
|
159 | + * @throws EE_Error |
|
160 | + * @global wpdb $wpdb |
|
161 | + */ |
|
162 | + public function dropIndex(string $table_name, string $index_name) |
|
163 | + { |
|
164 | + if (apply_filters('FHEE__EEH_Activation__drop_index__short_circuit', false)) { |
|
165 | + return 0; |
|
166 | + } |
|
167 | + global $wpdb; |
|
168 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
169 | + $index_exists_query = "SHOW INDEX FROM $table_name WHERE key_name = '$index_name'"; |
|
170 | + if ( |
|
171 | + $this->getTableAnalysis()->tableExists($table_name) |
|
172 | + && $wpdb->get_var($index_exists_query) |
|
173 | + === $table_name // using get_var with the $index_exists_query returns the table's name |
|
174 | + ) { |
|
175 | + return $wpdb->query("ALTER TABLE $table_name DROP INDEX $index_name"); |
|
176 | + } |
|
177 | + return 0; |
|
178 | + } |
|
179 | 179 | |
180 | 180 | |
181 | - /** |
|
182 | - * Just creates the requested table. $table_name can |
|
183 | - * optionally start with $wpdb->prefix or not |
|
184 | - * |
|
185 | - * @param string $table_name |
|
186 | - * @param string $create_sql defining the table's columns and indexes |
|
187 | - * @param string $engine (no need to specify "ENGINE=", that's implied) |
|
188 | - * @return void |
|
189 | - * @throws EE_Error |
|
190 | - */ |
|
191 | - public function createTable(string $table_name, string $create_sql, string $engine = 'MyISAM') |
|
192 | - { |
|
193 | - $engine = apply_filters( |
|
194 | - 'FHEE__EventEspresso_core_services_database_TableManager__createTable__engine', |
|
195 | - $engine, |
|
196 | - $table_name, |
|
197 | - $create_sql |
|
198 | - ); |
|
199 | - // does $sql contain valid column information? ( LPT: https://regex101.com/ is great for working out regex patterns ) |
|
200 | - if (preg_match('((((.*?))(,\s))+)', $create_sql, $valid_column_data)) { |
|
201 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
202 | - /** @var wpdb $wpdb */ |
|
203 | - global $wpdb; |
|
204 | - $SQL = "CREATE TABLE $table_name ( $create_sql ) ENGINE=$engine " . $wpdb->get_charset_collate(); |
|
181 | + /** |
|
182 | + * Just creates the requested table. $table_name can |
|
183 | + * optionally start with $wpdb->prefix or not |
|
184 | + * |
|
185 | + * @param string $table_name |
|
186 | + * @param string $create_sql defining the table's columns and indexes |
|
187 | + * @param string $engine (no need to specify "ENGINE=", that's implied) |
|
188 | + * @return void |
|
189 | + * @throws EE_Error |
|
190 | + */ |
|
191 | + public function createTable(string $table_name, string $create_sql, string $engine = 'MyISAM') |
|
192 | + { |
|
193 | + $engine = apply_filters( |
|
194 | + 'FHEE__EventEspresso_core_services_database_TableManager__createTable__engine', |
|
195 | + $engine, |
|
196 | + $table_name, |
|
197 | + $create_sql |
|
198 | + ); |
|
199 | + // does $sql contain valid column information? ( LPT: https://regex101.com/ is great for working out regex patterns ) |
|
200 | + if (preg_match('((((.*?))(,\s))+)', $create_sql, $valid_column_data)) { |
|
201 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
202 | + /** @var wpdb $wpdb */ |
|
203 | + global $wpdb; |
|
204 | + $SQL = "CREATE TABLE $table_name ( $create_sql ) ENGINE=$engine " . $wpdb->get_charset_collate(); |
|
205 | 205 | |
206 | - // get $wpdb to echo errors, but buffer them. This way at least WE know an error |
|
207 | - // happened. And then we can choose to tell the end user |
|
208 | - $old_show_errors_policy = $wpdb->show_errors(); |
|
209 | - $old_error_suppression_policy = $wpdb->suppress_errors(false); |
|
206 | + // get $wpdb to echo errors, but buffer them. This way at least WE know an error |
|
207 | + // happened. And then we can choose to tell the end user |
|
208 | + $old_show_errors_policy = $wpdb->show_errors(); |
|
209 | + $old_error_suppression_policy = $wpdb->suppress_errors(false); |
|
210 | 210 | |
211 | - if (! function_exists('dbDelta')) { |
|
212 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
213 | - } |
|
211 | + if (! function_exists('dbDelta')) { |
|
212 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
213 | + } |
|
214 | 214 | |
215 | - ob_start(); |
|
216 | - dbDelta($SQL); |
|
217 | - $output = ob_get_contents(); |
|
218 | - ob_end_clean(); |
|
219 | - $wpdb->show_errors($old_show_errors_policy); |
|
220 | - $wpdb->suppress_errors($old_error_suppression_policy); |
|
221 | - if (! empty($output)) { |
|
222 | - throw new EE_Error($output); |
|
223 | - } |
|
224 | - } else { |
|
225 | - throw new EE_Error( |
|
226 | - sprintf( |
|
227 | - esc_html__( |
|
228 | - 'The following table creation SQL does not contain valid information about the table columns: %1$s %2$s', |
|
229 | - 'event_espresso' |
|
230 | - ), |
|
231 | - '<br />', |
|
232 | - $create_sql |
|
233 | - ) |
|
234 | - ); |
|
235 | - } |
|
236 | - } |
|
215 | + ob_start(); |
|
216 | + dbDelta($SQL); |
|
217 | + $output = ob_get_contents(); |
|
218 | + ob_end_clean(); |
|
219 | + $wpdb->show_errors($old_show_errors_policy); |
|
220 | + $wpdb->suppress_errors($old_error_suppression_policy); |
|
221 | + if (! empty($output)) { |
|
222 | + throw new EE_Error($output); |
|
223 | + } |
|
224 | + } else { |
|
225 | + throw new EE_Error( |
|
226 | + sprintf( |
|
227 | + esc_html__( |
|
228 | + 'The following table creation SQL does not contain valid information about the table columns: %1$s %2$s', |
|
229 | + 'event_espresso' |
|
230 | + ), |
|
231 | + '<br />', |
|
232 | + $create_sql |
|
233 | + ) |
|
234 | + ); |
|
235 | + } |
|
236 | + } |
|
237 | 237 | |
238 | 238 | |
239 | - /** |
|
240 | - * Drops the specified index if it's size differs from $desired_index_size. |
|
241 | - * WordPress' dbdelta method doesn't automatically change index sizes, so this |
|
242 | - * method can be used to only drop the index if needed, and afterwards dbdelta can be used as normal. |
|
243 | - * If the table doesn't exist, or it exists but the index does not, or returns false |
|
244 | - * |
|
245 | - * @param string $table_name |
|
246 | - * @param string $index_name |
|
247 | - * @param string $column_name if none is provided, we assume the column name matches the index |
|
248 | - * (often true in EE) |
|
249 | - * @param string|int $desired_index_size defaults to TableAnalysis::index_col_size, the max for utf8mb4. |
|
250 | - * @return bool whether an index was dropped or not |
|
251 | - * @throws /EE_Error if table analysis object isn't defined |
|
252 | - */ |
|
253 | - public function dropIndexIfSizeNot( |
|
254 | - string $table_name, |
|
255 | - string $index_name, |
|
256 | - string $column_name = '', |
|
257 | - $desired_index_size = TableAnalysis::INDEX_COLUMN_SIZE |
|
258 | - ) { |
|
259 | - if ($column_name === '') { |
|
260 | - $column_name = $index_name; |
|
261 | - } |
|
262 | - if (! $this->getTableAnalysis()->tableExists($table_name)) { |
|
263 | - return false; |
|
264 | - } |
|
265 | - $index_entries = $this->getTableAnalysis()->showIndexes($table_name, $index_name); |
|
266 | - if (empty($index_entries)) { |
|
267 | - return false; |
|
268 | - } |
|
269 | - foreach ($index_entries as $index_entry) { |
|
270 | - if ( |
|
271 | - $column_name === $index_entry->Column_name |
|
272 | - && (string)$desired_index_size !== $index_entry->Sub_part |
|
273 | - ) { |
|
274 | - return $this->dropIndex($table_name, $index_name); |
|
275 | - } |
|
276 | - } |
|
277 | - return false; |
|
278 | - } |
|
239 | + /** |
|
240 | + * Drops the specified index if it's size differs from $desired_index_size. |
|
241 | + * WordPress' dbdelta method doesn't automatically change index sizes, so this |
|
242 | + * method can be used to only drop the index if needed, and afterwards dbdelta can be used as normal. |
|
243 | + * If the table doesn't exist, or it exists but the index does not, or returns false |
|
244 | + * |
|
245 | + * @param string $table_name |
|
246 | + * @param string $index_name |
|
247 | + * @param string $column_name if none is provided, we assume the column name matches the index |
|
248 | + * (often true in EE) |
|
249 | + * @param string|int $desired_index_size defaults to TableAnalysis::index_col_size, the max for utf8mb4. |
|
250 | + * @return bool whether an index was dropped or not |
|
251 | + * @throws /EE_Error if table analysis object isn't defined |
|
252 | + */ |
|
253 | + public function dropIndexIfSizeNot( |
|
254 | + string $table_name, |
|
255 | + string $index_name, |
|
256 | + string $column_name = '', |
|
257 | + $desired_index_size = TableAnalysis::INDEX_COLUMN_SIZE |
|
258 | + ) { |
|
259 | + if ($column_name === '') { |
|
260 | + $column_name = $index_name; |
|
261 | + } |
|
262 | + if (! $this->getTableAnalysis()->tableExists($table_name)) { |
|
263 | + return false; |
|
264 | + } |
|
265 | + $index_entries = $this->getTableAnalysis()->showIndexes($table_name, $index_name); |
|
266 | + if (empty($index_entries)) { |
|
267 | + return false; |
|
268 | + } |
|
269 | + foreach ($index_entries as $index_entry) { |
|
270 | + if ( |
|
271 | + $column_name === $index_entry->Column_name |
|
272 | + && (string)$desired_index_size !== $index_entry->Sub_part |
|
273 | + ) { |
|
274 | + return $this->dropIndex($table_name, $index_name); |
|
275 | + } |
|
276 | + } |
|
277 | + return false; |
|
278 | + } |
|
279 | 279 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | global $wpdb; |
67 | 67 | $full_table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
68 | 68 | $columns = $this->getTableColumns($table_name); |
69 | - if (! in_array($column_name, $columns)) { |
|
69 | + if ( ! in_array($column_name, $columns)) { |
|
70 | 70 | $alter_query = "ALTER TABLE $full_table_name ADD $column_name $column_info"; |
71 | 71 | return $wpdb->query($alter_query); |
72 | 72 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | global $wpdb; |
89 | 89 | $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
90 | 90 | $field_array = []; |
91 | - if (! empty($table_name)) { |
|
91 | + if ( ! empty($table_name)) { |
|
92 | 92 | $columns = $wpdb->get_results("SHOW COLUMNS FROM $table_name "); |
93 | 93 | if ($columns !== false) { |
94 | 94 | foreach ($columns as $column) { |
@@ -136,14 +136,14 @@ discard block |
||
136 | 136 | foreach ($table_names as $table_name) { |
137 | 137 | $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
138 | 138 | if ($this->getTableAnalysis()->tableExists($table_name)) { |
139 | - $tables_to_delete[ $table_name ] = $table_name; |
|
139 | + $tables_to_delete[$table_name] = $table_name; |
|
140 | 140 | } |
141 | 141 | } |
142 | - if (! empty($tables_to_delete)) { |
|
142 | + if ( ! empty($tables_to_delete)) { |
|
143 | 143 | global $wpdb; |
144 | 144 | // make sure we only have a unique strings in the array. |
145 | 145 | $tables_to_delete = array_unique($tables_to_delete); |
146 | - $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete)); |
|
146 | + $wpdb->query('DROP TABLE '.implode(', ', $tables_to_delete)); |
|
147 | 147 | } |
148 | 148 | return $tables_to_delete; |
149 | 149 | } |
@@ -201,15 +201,15 @@ discard block |
||
201 | 201 | $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
202 | 202 | /** @var wpdb $wpdb */ |
203 | 203 | global $wpdb; |
204 | - $SQL = "CREATE TABLE $table_name ( $create_sql ) ENGINE=$engine " . $wpdb->get_charset_collate(); |
|
204 | + $SQL = "CREATE TABLE $table_name ( $create_sql ) ENGINE=$engine ".$wpdb->get_charset_collate(); |
|
205 | 205 | |
206 | 206 | // get $wpdb to echo errors, but buffer them. This way at least WE know an error |
207 | 207 | // happened. And then we can choose to tell the end user |
208 | 208 | $old_show_errors_policy = $wpdb->show_errors(); |
209 | 209 | $old_error_suppression_policy = $wpdb->suppress_errors(false); |
210 | 210 | |
211 | - if (! function_exists('dbDelta')) { |
|
212 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
211 | + if ( ! function_exists('dbDelta')) { |
|
212 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | ob_start(); |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | ob_end_clean(); |
219 | 219 | $wpdb->show_errors($old_show_errors_policy); |
220 | 220 | $wpdb->suppress_errors($old_error_suppression_policy); |
221 | - if (! empty($output)) { |
|
221 | + if ( ! empty($output)) { |
|
222 | 222 | throw new EE_Error($output); |
223 | 223 | } |
224 | 224 | } else { |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | if ($column_name === '') { |
260 | 260 | $column_name = $index_name; |
261 | 261 | } |
262 | - if (! $this->getTableAnalysis()->tableExists($table_name)) { |
|
262 | + if ( ! $this->getTableAnalysis()->tableExists($table_name)) { |
|
263 | 263 | return false; |
264 | 264 | } |
265 | 265 | $index_entries = $this->getTableAnalysis()->showIndexes($table_name, $index_name); |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | foreach ($index_entries as $index_entry) { |
270 | 270 | if ( |
271 | 271 | $column_name === $index_entry->Column_name |
272 | - && (string)$desired_index_size !== $index_entry->Sub_part |
|
272 | + && (string) $desired_index_size !== $index_entry->Sub_part |
|
273 | 273 | ) { |
274 | 274 | return $this->dropIndex($table_name, $index_name); |
275 | 275 | } |