@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\interfaces\InterminableInterface; |
2 | 2 | |
3 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
4 | 4 | /** |
5 | 5 | * EE_PUE |
6 | 6 | * |
@@ -19,13 +19,13 @@ discard block |
||
19 | 19 | public function __construct() { |
20 | 20 | // throw new EE_Error('error'); |
21 | 21 | |
22 | - do_action( 'AHEE_log', __CLASS__, __FUNCTION__ ); |
|
22 | + do_action('AHEE_log', __CLASS__, __FUNCTION__); |
|
23 | 23 | |
24 | 24 | //wp have no MONTH_IN_SECONDS constant. So we approximate our own assuming all months are 4 weeks long. |
25 | - if ( !defined('MONTH_IN_SECONDS' ) ) |
|
26 | - define( 'MONTH_IN_SECONDS', WEEK_IN_SECONDS * 4 ); |
|
25 | + if ( ! defined('MONTH_IN_SECONDS')) |
|
26 | + define('MONTH_IN_SECONDS', WEEK_IN_SECONDS * 4); |
|
27 | 27 | |
28 | - if(EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance){ |
|
28 | + if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
29 | 29 | $this->_uxip_hooks(); |
30 | 30 | } |
31 | 31 | |
@@ -34,12 +34,12 @@ discard block |
||
34 | 34 | $ueip_has_notified = EE_Registry::instance()->CFG->core->ee_ueip_has_notified; |
35 | 35 | |
36 | 36 | //has optin been selected for data collection? |
37 | - $espresso_data_optin = !empty($ueip_optin) ? $ueip_optin : NULL; |
|
37 | + $espresso_data_optin = ! empty($ueip_optin) ? $ueip_optin : NULL; |
|
38 | 38 | |
39 | - if ( empty($ueip_has_notified) && EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance ) { |
|
40 | - add_action('admin_notices', array( $this, 'espresso_data_collection_optin_notice' ), 10 ); |
|
41 | - add_action('admin_enqueue_scripts', array( $this, 'espresso_data_collection_enqueue_scripts' ), 10 ); |
|
42 | - add_action('wp_ajax_espresso_data_optin', array( $this, 'espresso_data_optin_ajax_handler' ), 10 ); |
|
39 | + if (empty($ueip_has_notified) && EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
40 | + add_action('admin_notices', array($this, 'espresso_data_collection_optin_notice'), 10); |
|
41 | + add_action('admin_enqueue_scripts', array($this, 'espresso_data_collection_enqueue_scripts'), 10); |
|
42 | + add_action('wp_ajax_espresso_data_optin', array($this, 'espresso_data_optin_ajax_handler'), 10); |
|
43 | 43 | update_option('ee_ueip_optin', 'yes'); |
44 | 44 | $espresso_data_optin = 'yes'; |
45 | 45 | } |
@@ -48,80 +48,80 @@ discard block |
||
48 | 48 | $extra_stats = array(); |
49 | 49 | |
50 | 50 | //only collect extra stats if the plugin user has opted in. |
51 | - if ( !empty($espresso_data_optin) && $espresso_data_optin == 'yes' ) { |
|
51 | + if ( ! empty($espresso_data_optin) && $espresso_data_optin == 'yes') { |
|
52 | 52 | //let's only setup extra data if transient has expired |
53 | - if ( false === ( $transient = get_transient('ee_extra_data') ) && EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance ) { |
|
53 | + if (false === ($transient = get_transient('ee_extra_data')) && EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
54 | 54 | |
55 | 55 | $current_site = is_multisite() ? get_current_site() : NULL; |
56 | - $site_pre = ! is_main_site() && ! empty($current_site) ? trim( preg_replace('/\b\w\S\w\b/', '', $current_site->domain ), '.' ) . '_' : ''; |
|
56 | + $site_pre = ! is_main_site() && ! empty($current_site) ? trim(preg_replace('/\b\w\S\w\b/', '', $current_site->domain), '.').'_' : ''; |
|
57 | 57 | |
58 | 58 | |
59 | 59 | //active gateways |
60 | 60 | $active_gateways = get_option('event_espresso_active_gateways'); |
61 | - if ( !empty($active_gateways ) ) { |
|
62 | - foreach ( (array) $active_gateways as $gateway => $ignore ) { |
|
63 | - $extra_stats[$site_pre . $gateway . '_gateway_active'] = 1; |
|
61 | + if ( ! empty($active_gateways)) { |
|
62 | + foreach ((array) $active_gateways as $gateway => $ignore) { |
|
63 | + $extra_stats[$site_pre.$gateway.'_gateway_active'] = 1; |
|
64 | 64 | } |
65 | 65 | } |
66 | 66 | |
67 | - if ( is_multisite() && is_main_site() ) { |
|
67 | + if (is_multisite() && is_main_site()) { |
|
68 | 68 | $extra_stats['is_multisite'] = true; |
69 | 69 | } |
70 | 70 | |
71 | 71 | //what is the current active theme? |
72 | 72 | $active_theme = get_option('uxip_ee_active_theme'); |
73 | - if ( !empty( $active_theme ) ) |
|
74 | - $extra_stats[$site_pre . 'active_theme'] = $active_theme; |
|
73 | + if ( ! empty($active_theme)) |
|
74 | + $extra_stats[$site_pre.'active_theme'] = $active_theme; |
|
75 | 75 | |
76 | 76 | //event info regarding an all event count and all "active" event count |
77 | 77 | $all_events_count = get_option('uxip_ee4_all_events_count'); |
78 | - if ( !empty( $all_events_count ) ) |
|
79 | - $extra_stats[$site_pre . 'ee4_all_events_count'] = $all_events_count; |
|
78 | + if ( ! empty($all_events_count)) |
|
79 | + $extra_stats[$site_pre.'ee4_all_events_count'] = $all_events_count; |
|
80 | 80 | $active_events_count = get_option('uxip_ee4_active_events_count'); |
81 | - if ( !empty( $active_events_count ) ) |
|
82 | - $extra_stats[$site_pre . 'ee4_active_events_count'] = $active_events_count; |
|
81 | + if ( ! empty($active_events_count)) |
|
82 | + $extra_stats[$site_pre.'ee4_active_events_count'] = $active_events_count; |
|
83 | 83 | |
84 | 84 | //datetime stuff |
85 | 85 | $dtt_count = get_option('uxip_ee_all_dtts_count'); |
86 | - if ( !empty( $dtt_count ) ) |
|
87 | - $extra_stats[$site_pre . 'all_dtts_count'] = $dtt_count; |
|
86 | + if ( ! empty($dtt_count)) |
|
87 | + $extra_stats[$site_pre.'all_dtts_count'] = $dtt_count; |
|
88 | 88 | |
89 | 89 | $dtt_sold = get_option('uxip_ee_dtt_sold'); |
90 | - if ( !empty( $dtt_sold ) ) |
|
91 | - $extra_stats[$site_pre . 'dtt_sold'] = $dtt_sold; |
|
90 | + if ( ! empty($dtt_sold)) |
|
91 | + $extra_stats[$site_pre.'dtt_sold'] = $dtt_sold; |
|
92 | 92 | |
93 | 93 | //ticket stuff |
94 | 94 | $all_tkt_count = get_option('uxip_ee_all_tkt_count'); |
95 | - if ( !empty( $all_tkt_count ) ) |
|
96 | - $extra_stats[$site_pre . 'all_tkt_count'] = $all_tkt_count; |
|
95 | + if ( ! empty($all_tkt_count)) |
|
96 | + $extra_stats[$site_pre.'all_tkt_count'] = $all_tkt_count; |
|
97 | 97 | |
98 | 98 | $free_tkt_count = get_option('uxip_ee_free_tkt_count'); |
99 | - if ( !empty( $free_tkt_count ) ) |
|
100 | - $extra_stats[$site_pre . 'free_tkt_count'] = $free_tkt_count; |
|
99 | + if ( ! empty($free_tkt_count)) |
|
100 | + $extra_stats[$site_pre.'free_tkt_count'] = $free_tkt_count; |
|
101 | 101 | |
102 | 102 | $paid_tkt_count = get_option('uxip_ee_paid_tkt_count'); |
103 | - if ( !empty( $paid_tkt_count ) ) |
|
104 | - $extra_stats[$site_pre . 'paid_tkt_count'] = $paid_tkt_count; |
|
103 | + if ( ! empty($paid_tkt_count)) |
|
104 | + $extra_stats[$site_pre.'paid_tkt_count'] = $paid_tkt_count; |
|
105 | 105 | |
106 | - $tkt_sold = get_option('uxip_ee_tkt_sold' ); |
|
107 | - if ( !empty($tkt_sold) ) |
|
108 | - $extra_stats[$site_pre . 'tkt_sold'] = $tkt_sold; |
|
106 | + $tkt_sold = get_option('uxip_ee_tkt_sold'); |
|
107 | + if ( ! empty($tkt_sold)) |
|
108 | + $extra_stats[$site_pre.'tkt_sold'] = $tkt_sold; |
|
109 | 109 | |
110 | 110 | //phpversion checking |
111 | 111 | $extra_stats['phpversion'] = function_exists('phpversion') ? phpversion() : 'unknown'; |
112 | 112 | |
113 | 113 | //set transient |
114 | - set_transient( 'ee_extra_data', $extra_stats, WEEK_IN_SECONDS ); |
|
114 | + set_transient('ee_extra_data', $extra_stats, WEEK_IN_SECONDS); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
118 | 118 | |
119 | 119 | |
120 | 120 | // PUE Auto Upgrades stuff |
121 | - if (is_readable(EE_THIRD_PARTY . 'pue/pue-client.php')) { //include the file |
|
122 | - require_once(EE_THIRD_PARTY . 'pue/pue-client.php' ); |
|
121 | + if (is_readable(EE_THIRD_PARTY.'pue/pue-client.php')) { //include the file |
|
122 | + require_once(EE_THIRD_PARTY.'pue/pue-client.php'); |
|
123 | 123 | |
124 | - $api_key = isset( EE_Registry::instance()->NET_CFG->core->site_license_key ) ? EE_Registry::instance()->NET_CFG->core->site_license_key : ''; |
|
124 | + $api_key = isset(EE_Registry::instance()->NET_CFG->core->site_license_key) ? EE_Registry::instance()->NET_CFG->core->site_license_key : ''; |
|
125 | 125 | $host_server_url = 'https://eventespresso.com'; //this needs to be the host server where plugin update engine is installed. Note, if you leave this blank then it is assumed the WordPress repo will be used and we'll just check there. |
126 | 126 | |
127 | 127 | //Note: PUE uses a simple preg_match to determine what type is currently installed based on version number. So it's important that you use a key for the version type that is unique and not found in another key. |
@@ -133,9 +133,9 @@ discard block |
||
133 | 133 | //$plugin_slug['prerelease']['b'] = 'some-pre-release-slug'; |
134 | 134 | //..WOULD work! |
135 | 135 | $plugin_slug = array( |
136 | - 'free' => array( 'decaf' => 'event-espresso-core-decaf' ), |
|
137 | - 'premium' => array( 'p' => 'event-espresso-core-reg' ), |
|
138 | - 'prerelease' => array( 'beta' => 'event-espresso-core-pr' ) |
|
136 | + 'free' => array('decaf' => 'event-espresso-core-decaf'), |
|
137 | + 'premium' => array('p' => 'event-espresso-core-reg'), |
|
138 | + 'prerelease' => array('beta' => 'event-espresso-core-pr') |
|
139 | 139 | ); |
140 | 140 | |
141 | 141 | |
@@ -165,14 +165,14 @@ discard block |
||
165 | 165 | * @param bool $extra |
166 | 166 | * @return string html. |
167 | 167 | */ |
168 | - public static function espresso_data_collection_optin_text( $extra = true ) { |
|
169 | - if ( ! $extra ) { |
|
170 | - echo '<h2 class="ee-admin-settings-hdr" '. (!$extra ? 'id="UXIP_settings"' : '').'>'.__('User eXperience Improvement Program (UXIP)', 'event_espresso').EEH_Template::get_help_tab_link('organization_logo_info').'</h2>'; |
|
171 | - echo sprintf( __('%sPlease help us make Event Espresso better and vote for your favorite features.%s The %sUser eXperience Improvement Program (UXIP)%s, has been created so when you use Event Espresso you are voting for the features and settings that are important to you. The UXIP helps us understand how you use our products and services, track problems and in what context. If you opt-out of the UXIP you essentially elect for us to disregard how you use Event Espresso as we build new features and make changes. Participation in the program is completely voluntary but it is enabled by default. The end results of the UXIP are software improvements to better meet your needs. The data we collect will never be sold, traded, or misused in any way. %sPlease see our %sPrivacy Policy%s for more information.', 'event_espresso'), '<p><em>', '</em></p>','<a href="http://eventespresso.com/about/user-experience-improvement-program-uxip/" target="_blank">','</a>','<br><br>','<a href="http://eventespresso.com/about/privacy-policy/" target="_blank">','</a>' ); |
|
168 | + public static function espresso_data_collection_optin_text($extra = true) { |
|
169 | + if ( ! $extra) { |
|
170 | + echo '<h2 class="ee-admin-settings-hdr" '.( ! $extra ? 'id="UXIP_settings"' : '').'>'.__('User eXperience Improvement Program (UXIP)', 'event_espresso').EEH_Template::get_help_tab_link('organization_logo_info').'</h2>'; |
|
171 | + echo sprintf(__('%sPlease help us make Event Espresso better and vote for your favorite features.%s The %sUser eXperience Improvement Program (UXIP)%s, has been created so when you use Event Espresso you are voting for the features and settings that are important to you. The UXIP helps us understand how you use our products and services, track problems and in what context. If you opt-out of the UXIP you essentially elect for us to disregard how you use Event Espresso as we build new features and make changes. Participation in the program is completely voluntary but it is enabled by default. The end results of the UXIP are software improvements to better meet your needs. The data we collect will never be sold, traded, or misused in any way. %sPlease see our %sPrivacy Policy%s for more information.', 'event_espresso'), '<p><em>', '</em></p>', '<a href="http://eventespresso.com/about/user-experience-improvement-program-uxip/" target="_blank">', '</a>', '<br><br>', '<a href="http://eventespresso.com/about/privacy-policy/" target="_blank">', '</a>'); |
|
172 | 172 | } else { |
173 | - $settings_url = EE_Admin_Page::add_query_args_and_nonce( array( 'action' => 'default'), admin_url( 'admin.php?page=espresso_general_settings') ); |
|
173 | + $settings_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'default'), admin_url('admin.php?page=espresso_general_settings')); |
|
174 | 174 | $settings_url .= '#UXIP_settings'; |
175 | - echo sprintf( __( 'The Event Espresso UXIP feature is active on your site. For %smore info%s and to opt-out %sclick here%s.', 'event_espresso' ), '<a href="http://eventespresso.com/about/user-experience-improvement-program-uxip/" target="_blank">', '</a>', '<a href="' . $settings_url . '" target="_blank">', '</a>' ); |
|
175 | + echo sprintf(__('The Event Espresso UXIP feature is active on your site. For %smore info%s and to opt-out %sclick here%s.', 'event_espresso'), '<a href="http://eventespresso.com/about/user-experience-improvement-program-uxip/" target="_blank">', '</a>', '<a href="'.$settings_url.'" target="_blank">', '</a>'); |
|
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | |
182 | 182 | function espresso_data_collection_optin_notice() { |
183 | 183 | $ueip_has_notified = EE_Registry::instance()->CFG->core->ee_ueip_has_notified; |
184 | - if ( $ueip_has_notified ) return; |
|
184 | + if ($ueip_has_notified) return; |
|
185 | 185 | // $settings_url = EE_Admin_Page::add_query_args_and_nonce( array( 'action' => 'default'), admin_url( 'admin.php?page=espresso_general_settings') ); |
186 | 186 | // $settings_url = $settings_url . '#UXIP_settings'; |
187 | 187 | ?> |
@@ -205,8 +205,8 @@ discard block |
||
205 | 205 | * @return void |
206 | 206 | */ |
207 | 207 | function espresso_data_collection_enqueue_scripts() { |
208 | - wp_register_script( 'ee-data-optin-js', EE_GLOBAL_ASSETS_URL . 'scripts/ee-data-optin.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
209 | - wp_register_style( 'ee-data-optin-css', EE_GLOBAL_ASSETS_URL . 'css/ee-data-optin.css', array(), EVENT_ESPRESSO_VERSION ); |
|
208 | + wp_register_script('ee-data-optin-js', EE_GLOBAL_ASSETS_URL.'scripts/ee-data-optin.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE); |
|
209 | + wp_register_style('ee-data-optin-css', EE_GLOBAL_ASSETS_URL.'css/ee-data-optin.css', array(), EVENT_ESPRESSO_VERSION); |
|
210 | 210 | |
211 | 211 | wp_enqueue_script('ee-data-optin-js'); |
212 | 212 | wp_enqueue_style('ee-data-optin-css'); |
@@ -221,14 +221,14 @@ discard block |
||
221 | 221 | function espresso_data_optin_ajax_handler() { |
222 | 222 | |
223 | 223 | //verify nonce |
224 | - if ( isset($_POST['nonce']) && !wp_verify_nonce($_POST['nonce'], 'ee-data-optin') ) exit(); |
|
224 | + if (isset($_POST['nonce']) && ! wp_verify_nonce($_POST['nonce'], 'ee-data-optin')) exit(); |
|
225 | 225 | |
226 | 226 | //made it here so let's save the selection |
227 | 227 | // $ueip_optin = isset( $_POST['selection'] ) ? $_POST['selection'] : 'no'; |
228 | 228 | |
229 | 229 | //update_option('ee_ueip_optin', $ueip_optin); |
230 | 230 | EE_Registry::instance()->CFG->core->ee_ueip_has_notified = 1; |
231 | - EE_Registry::instance()->CFG->update_espresso_config( FALSE, FALSE ); |
|
231 | + EE_Registry::instance()->CFG->update_espresso_config(FALSE, FALSE); |
|
232 | 232 | exit(); |
233 | 233 | } |
234 | 234 | |
@@ -241,22 +241,22 @@ discard block |
||
241 | 241 | */ |
242 | 242 | public static function is_update_available($basename = '') { |
243 | 243 | |
244 | - $basename = ! empty( $basename ) ? $basename : EE_PLUGIN_BASENAME; |
|
244 | + $basename = ! empty($basename) ? $basename : EE_PLUGIN_BASENAME; |
|
245 | 245 | |
246 | 246 | $update = false; |
247 | 247 | |
248 | - $folder = DS . dirname($basename); // should take "event-espresso-core/espresso.php" and change to "/event-espresso-core" |
|
248 | + $folder = DS.dirname($basename); // should take "event-espresso-core/espresso.php" and change to "/event-espresso-core" |
|
249 | 249 | |
250 | 250 | $plugins = get_plugins($folder); |
251 | - $current = get_site_transient( 'update_plugins' ); |
|
251 | + $current = get_site_transient('update_plugins'); |
|
252 | 252 | |
253 | - foreach ( (array) $plugins as $plugin_file => $plugin_data ) { |
|
254 | - if ( isset( $current->response['plugin_file'] ) ) |
|
253 | + foreach ((array) $plugins as $plugin_file => $plugin_data) { |
|
254 | + if (isset($current->response['plugin_file'])) |
|
255 | 255 | $update = true; |
256 | 256 | } |
257 | 257 | |
258 | 258 | //it's possible that there is an update but an invalid site-license-key is in use |
259 | - if ( get_site_option('pue_json_error_' . $basename ) ) |
|
259 | + if (get_site_option('pue_json_error_'.$basename)) |
|
260 | 260 | $update = true; |
261 | 261 | |
262 | 262 | return $update; |
@@ -274,9 +274,9 @@ discard block |
||
274 | 274 | * @return void |
275 | 275 | */ |
276 | 276 | public function _uxip_hooks() { |
277 | - if ( EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance ) { |
|
278 | - add_action('admin_init', array( $this, 'track_active_theme' ) ); |
|
279 | - add_action('admin_init', array( $this, 'track_event_info' ) ); |
|
277 | + if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
278 | + add_action('admin_init', array($this, 'track_active_theme')); |
|
279 | + add_action('admin_init', array($this, 'track_event_info')); |
|
280 | 280 | } |
281 | 281 | } |
282 | 282 | |
@@ -285,66 +285,66 @@ discard block |
||
285 | 285 | |
286 | 286 | public function track_active_theme() { |
287 | 287 | //we only check this once a month. |
288 | - if ( false === ( $transient = get_transient( 'ee_active_theme_check' ) ) ) { |
|
288 | + if (false === ($transient = get_transient('ee_active_theme_check'))) { |
|
289 | 289 | $theme = wp_get_theme(); |
290 | - update_option('uxip_ee_active_theme', $theme->get('Name') ); |
|
291 | - set_transient('ee_active_theme_check', 1, MONTH_IN_SECONDS ); |
|
290 | + update_option('uxip_ee_active_theme', $theme->get('Name')); |
|
291 | + set_transient('ee_active_theme_check', 1, MONTH_IN_SECONDS); |
|
292 | 292 | } |
293 | 293 | } |
294 | 294 | |
295 | 295 | |
296 | 296 | public function track_event_info() { |
297 | 297 | //we only check this once every couple weeks. |
298 | - if ( false === ( $transient = get_transient( 'ee4_event_info_check') ) ) { |
|
298 | + if (false === ($transient = get_transient('ee4_event_info_check'))) { |
|
299 | 299 | //first let's get the number for ALL events |
300 | 300 | /** @var EEM_Event $EVT */ |
301 | - $EVT = EE_Registry::instance()->load_model( 'Event'); |
|
301 | + $EVT = EE_Registry::instance()->load_model('Event'); |
|
302 | 302 | $DTT = EE_Registry::instance()->load_model('Datetime'); |
303 | 303 | $TKT = EE_Registry::instance()->load_model('Ticket'); |
304 | 304 | $count = $EVT->count(); |
305 | - if ( $count > 0 ) |
|
305 | + if ($count > 0) |
|
306 | 306 | update_option('uxip_ee4_all_events_count', $count); |
307 | 307 | |
308 | 308 | //next let's just get the number of ACTIVE events |
309 | 309 | $count_active = $EVT->get_active_events(array(), TRUE); |
310 | - if ( $count_active > 0 ) |
|
310 | + if ($count_active > 0) |
|
311 | 311 | update_option('uxip_ee4_active_events_count', $count_active); |
312 | 312 | |
313 | 313 | //datetimes! |
314 | 314 | $dtt_count = $DTT->count(); |
315 | - if ( $dtt_count > 0 ) |
|
316 | - update_option( 'uxip_ee_all_dtts_count', $dtt_count ); |
|
315 | + if ($dtt_count > 0) |
|
316 | + update_option('uxip_ee_all_dtts_count', $dtt_count); |
|
317 | 317 | |
318 | 318 | |
319 | 319 | //dttsold |
320 | 320 | $dtt_sold = $DTT->sum(array(), 'DTT_sold'); |
321 | - if ( $dtt_sold > 0 ) |
|
322 | - update_option( 'uxip_ee_dtt_sold', $dtt_sold ); |
|
321 | + if ($dtt_sold > 0) |
|
322 | + update_option('uxip_ee_dtt_sold', $dtt_sold); |
|
323 | 323 | |
324 | 324 | //allticketcount |
325 | 325 | $all_tkt_count = $TKT->count(); |
326 | - if ( $all_tkt_count > 0 ) |
|
327 | - update_option( 'uxip_ee_all_tkt_count', $all_tkt_count ); |
|
326 | + if ($all_tkt_count > 0) |
|
327 | + update_option('uxip_ee_all_tkt_count', $all_tkt_count); |
|
328 | 328 | |
329 | 329 | //freetktcount |
330 | - $_where = array( 'TKT_price' => 0 ); |
|
330 | + $_where = array('TKT_price' => 0); |
|
331 | 331 | $free_tkt_count = $TKT->count(array($_where)); |
332 | - if ( $free_tkt_count > 0 ) |
|
333 | - update_option( 'uxip_ee_free_tkt_count', $free_tkt_count ); |
|
332 | + if ($free_tkt_count > 0) |
|
333 | + update_option('uxip_ee_free_tkt_count', $free_tkt_count); |
|
334 | 334 | |
335 | 335 | //paidtktcount |
336 | - $_where = array( 'TKT_price' => array('>', 0) ); |
|
337 | - $paid_tkt_count = $TKT->count( array( $_where ) ); |
|
338 | - if ( $paid_tkt_count > 0 ) |
|
339 | - update_option( 'uxip_ee_paid_tkt_count', $paid_tkt_count ); |
|
336 | + $_where = array('TKT_price' => array('>', 0)); |
|
337 | + $paid_tkt_count = $TKT->count(array($_where)); |
|
338 | + if ($paid_tkt_count > 0) |
|
339 | + update_option('uxip_ee_paid_tkt_count', $paid_tkt_count); |
|
340 | 340 | |
341 | 341 | //tktsold |
342 | - $tkt_sold = $TKT->sum( array(), 'TKT_sold' ); |
|
343 | - if( $tkt_sold > 0 ) |
|
344 | - update_option( 'uxip_ee_tkt_sold', $tkt_sold ); |
|
342 | + $tkt_sold = $TKT->sum(array(), 'TKT_sold'); |
|
343 | + if ($tkt_sold > 0) |
|
344 | + update_option('uxip_ee_tkt_sold', $tkt_sold); |
|
345 | 345 | |
346 | 346 | |
347 | - set_transient( 'ee4_event_info_check', 1, WEEK_IN_SECONDS * 2 ); |
|
347 | + set_transient('ee4_event_info_check', 1, WEEK_IN_SECONDS * 2); |
|
348 | 348 | } |
349 | 349 | } |
350 | 350 |
@@ -1,6 +1,8 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\interfaces\InterminableInterface; |
2 | 2 | |
3 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
3 | +if ( ! defined( 'EVENT_ESPRESSO_VERSION')) { |
|
4 | + exit('No direct script access allowed'); |
|
5 | +} |
|
4 | 6 | /** |
5 | 7 | * EE_PUE |
6 | 8 | * |
@@ -22,8 +24,9 @@ discard block |
||
22 | 24 | do_action( 'AHEE_log', __CLASS__, __FUNCTION__ ); |
23 | 25 | |
24 | 26 | //wp have no MONTH_IN_SECONDS constant. So we approximate our own assuming all months are 4 weeks long. |
25 | - if ( !defined('MONTH_IN_SECONDS' ) ) |
|
26 | - define( 'MONTH_IN_SECONDS', WEEK_IN_SECONDS * 4 ); |
|
27 | + if ( !defined('MONTH_IN_SECONDS' ) ) { |
|
28 | + define( 'MONTH_IN_SECONDS', WEEK_IN_SECONDS * 4 ); |
|
29 | + } |
|
27 | 30 | |
28 | 31 | if(EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance){ |
29 | 32 | $this->_uxip_hooks(); |
@@ -70,42 +73,51 @@ discard block |
||
70 | 73 | |
71 | 74 | //what is the current active theme? |
72 | 75 | $active_theme = get_option('uxip_ee_active_theme'); |
73 | - if ( !empty( $active_theme ) ) |
|
74 | - $extra_stats[$site_pre . 'active_theme'] = $active_theme; |
|
76 | + if ( !empty( $active_theme ) ) { |
|
77 | + $extra_stats[$site_pre . 'active_theme'] = $active_theme; |
|
78 | + } |
|
75 | 79 | |
76 | 80 | //event info regarding an all event count and all "active" event count |
77 | 81 | $all_events_count = get_option('uxip_ee4_all_events_count'); |
78 | - if ( !empty( $all_events_count ) ) |
|
79 | - $extra_stats[$site_pre . 'ee4_all_events_count'] = $all_events_count; |
|
82 | + if ( !empty( $all_events_count ) ) { |
|
83 | + $extra_stats[$site_pre . 'ee4_all_events_count'] = $all_events_count; |
|
84 | + } |
|
80 | 85 | $active_events_count = get_option('uxip_ee4_active_events_count'); |
81 | - if ( !empty( $active_events_count ) ) |
|
82 | - $extra_stats[$site_pre . 'ee4_active_events_count'] = $active_events_count; |
|
86 | + if ( !empty( $active_events_count ) ) { |
|
87 | + $extra_stats[$site_pre . 'ee4_active_events_count'] = $active_events_count; |
|
88 | + } |
|
83 | 89 | |
84 | 90 | //datetime stuff |
85 | 91 | $dtt_count = get_option('uxip_ee_all_dtts_count'); |
86 | - if ( !empty( $dtt_count ) ) |
|
87 | - $extra_stats[$site_pre . 'all_dtts_count'] = $dtt_count; |
|
92 | + if ( !empty( $dtt_count ) ) { |
|
93 | + $extra_stats[$site_pre . 'all_dtts_count'] = $dtt_count; |
|
94 | + } |
|
88 | 95 | |
89 | 96 | $dtt_sold = get_option('uxip_ee_dtt_sold'); |
90 | - if ( !empty( $dtt_sold ) ) |
|
91 | - $extra_stats[$site_pre . 'dtt_sold'] = $dtt_sold; |
|
97 | + if ( !empty( $dtt_sold ) ) { |
|
98 | + $extra_stats[$site_pre . 'dtt_sold'] = $dtt_sold; |
|
99 | + } |
|
92 | 100 | |
93 | 101 | //ticket stuff |
94 | 102 | $all_tkt_count = get_option('uxip_ee_all_tkt_count'); |
95 | - if ( !empty( $all_tkt_count ) ) |
|
96 | - $extra_stats[$site_pre . 'all_tkt_count'] = $all_tkt_count; |
|
103 | + if ( !empty( $all_tkt_count ) ) { |
|
104 | + $extra_stats[$site_pre . 'all_tkt_count'] = $all_tkt_count; |
|
105 | + } |
|
97 | 106 | |
98 | 107 | $free_tkt_count = get_option('uxip_ee_free_tkt_count'); |
99 | - if ( !empty( $free_tkt_count ) ) |
|
100 | - $extra_stats[$site_pre . 'free_tkt_count'] = $free_tkt_count; |
|
108 | + if ( !empty( $free_tkt_count ) ) { |
|
109 | + $extra_stats[$site_pre . 'free_tkt_count'] = $free_tkt_count; |
|
110 | + } |
|
101 | 111 | |
102 | 112 | $paid_tkt_count = get_option('uxip_ee_paid_tkt_count'); |
103 | - if ( !empty( $paid_tkt_count ) ) |
|
104 | - $extra_stats[$site_pre . 'paid_tkt_count'] = $paid_tkt_count; |
|
113 | + if ( !empty( $paid_tkt_count ) ) { |
|
114 | + $extra_stats[$site_pre . 'paid_tkt_count'] = $paid_tkt_count; |
|
115 | + } |
|
105 | 116 | |
106 | 117 | $tkt_sold = get_option('uxip_ee_tkt_sold' ); |
107 | - if ( !empty($tkt_sold) ) |
|
108 | - $extra_stats[$site_pre . 'tkt_sold'] = $tkt_sold; |
|
118 | + if ( !empty($tkt_sold) ) { |
|
119 | + $extra_stats[$site_pre . 'tkt_sold'] = $tkt_sold; |
|
120 | + } |
|
109 | 121 | |
110 | 122 | //phpversion checking |
111 | 123 | $extra_stats['phpversion'] = function_exists('phpversion') ? phpversion() : 'unknown'; |
@@ -181,7 +193,9 @@ discard block |
||
181 | 193 | |
182 | 194 | function espresso_data_collection_optin_notice() { |
183 | 195 | $ueip_has_notified = EE_Registry::instance()->CFG->core->ee_ueip_has_notified; |
184 | - if ( $ueip_has_notified ) return; |
|
196 | + if ( $ueip_has_notified ) { |
|
197 | + return; |
|
198 | + } |
|
185 | 199 | // $settings_url = EE_Admin_Page::add_query_args_and_nonce( array( 'action' => 'default'), admin_url( 'admin.php?page=espresso_general_settings') ); |
186 | 200 | // $settings_url = $settings_url . '#UXIP_settings'; |
187 | 201 | ?> |
@@ -221,7 +235,9 @@ discard block |
||
221 | 235 | function espresso_data_optin_ajax_handler() { |
222 | 236 | |
223 | 237 | //verify nonce |
224 | - if ( isset($_POST['nonce']) && !wp_verify_nonce($_POST['nonce'], 'ee-data-optin') ) exit(); |
|
238 | + if ( isset($_POST['nonce']) && !wp_verify_nonce($_POST['nonce'], 'ee-data-optin') ) { |
|
239 | + exit(); |
|
240 | + } |
|
225 | 241 | |
226 | 242 | //made it here so let's save the selection |
227 | 243 | // $ueip_optin = isset( $_POST['selection'] ) ? $_POST['selection'] : 'no'; |
@@ -251,13 +267,15 @@ discard block |
||
251 | 267 | $current = get_site_transient( 'update_plugins' ); |
252 | 268 | |
253 | 269 | foreach ( (array) $plugins as $plugin_file => $plugin_data ) { |
254 | - if ( isset( $current->response['plugin_file'] ) ) |
|
255 | - $update = true; |
|
270 | + if ( isset( $current->response['plugin_file'] ) ) { |
|
271 | + $update = true; |
|
272 | + } |
|
256 | 273 | } |
257 | 274 | |
258 | 275 | //it's possible that there is an update but an invalid site-license-key is in use |
259 | - if ( get_site_option('pue_json_error_' . $basename ) ) |
|
260 | - $update = true; |
|
276 | + if ( get_site_option('pue_json_error_' . $basename ) ) { |
|
277 | + $update = true; |
|
278 | + } |
|
261 | 279 | |
262 | 280 | return $update; |
263 | 281 | } |
@@ -302,46 +320,54 @@ discard block |
||
302 | 320 | $DTT = EE_Registry::instance()->load_model('Datetime'); |
303 | 321 | $TKT = EE_Registry::instance()->load_model('Ticket'); |
304 | 322 | $count = $EVT->count(); |
305 | - if ( $count > 0 ) |
|
306 | - update_option('uxip_ee4_all_events_count', $count); |
|
323 | + if ( $count > 0 ) { |
|
324 | + update_option('uxip_ee4_all_events_count', $count); |
|
325 | + } |
|
307 | 326 | |
308 | 327 | //next let's just get the number of ACTIVE events |
309 | 328 | $count_active = $EVT->get_active_events(array(), TRUE); |
310 | - if ( $count_active > 0 ) |
|
311 | - update_option('uxip_ee4_active_events_count', $count_active); |
|
329 | + if ( $count_active > 0 ) { |
|
330 | + update_option('uxip_ee4_active_events_count', $count_active); |
|
331 | + } |
|
312 | 332 | |
313 | 333 | //datetimes! |
314 | 334 | $dtt_count = $DTT->count(); |
315 | - if ( $dtt_count > 0 ) |
|
316 | - update_option( 'uxip_ee_all_dtts_count', $dtt_count ); |
|
335 | + if ( $dtt_count > 0 ) { |
|
336 | + update_option( 'uxip_ee_all_dtts_count', $dtt_count ); |
|
337 | + } |
|
317 | 338 | |
318 | 339 | |
319 | 340 | //dttsold |
320 | 341 | $dtt_sold = $DTT->sum(array(), 'DTT_sold'); |
321 | - if ( $dtt_sold > 0 ) |
|
322 | - update_option( 'uxip_ee_dtt_sold', $dtt_sold ); |
|
342 | + if ( $dtt_sold > 0 ) { |
|
343 | + update_option( 'uxip_ee_dtt_sold', $dtt_sold ); |
|
344 | + } |
|
323 | 345 | |
324 | 346 | //allticketcount |
325 | 347 | $all_tkt_count = $TKT->count(); |
326 | - if ( $all_tkt_count > 0 ) |
|
327 | - update_option( 'uxip_ee_all_tkt_count', $all_tkt_count ); |
|
348 | + if ( $all_tkt_count > 0 ) { |
|
349 | + update_option( 'uxip_ee_all_tkt_count', $all_tkt_count ); |
|
350 | + } |
|
328 | 351 | |
329 | 352 | //freetktcount |
330 | 353 | $_where = array( 'TKT_price' => 0 ); |
331 | 354 | $free_tkt_count = $TKT->count(array($_where)); |
332 | - if ( $free_tkt_count > 0 ) |
|
333 | - update_option( 'uxip_ee_free_tkt_count', $free_tkt_count ); |
|
355 | + if ( $free_tkt_count > 0 ) { |
|
356 | + update_option( 'uxip_ee_free_tkt_count', $free_tkt_count ); |
|
357 | + } |
|
334 | 358 | |
335 | 359 | //paidtktcount |
336 | 360 | $_where = array( 'TKT_price' => array('>', 0) ); |
337 | 361 | $paid_tkt_count = $TKT->count( array( $_where ) ); |
338 | - if ( $paid_tkt_count > 0 ) |
|
339 | - update_option( 'uxip_ee_paid_tkt_count', $paid_tkt_count ); |
|
362 | + if ( $paid_tkt_count > 0 ) { |
|
363 | + update_option( 'uxip_ee_paid_tkt_count', $paid_tkt_count ); |
|
364 | + } |
|
340 | 365 | |
341 | 366 | //tktsold |
342 | 367 | $tkt_sold = $TKT->sum( array(), 'TKT_sold' ); |
343 | - if( $tkt_sold > 0 ) |
|
344 | - update_option( 'uxip_ee_tkt_sold', $tkt_sold ); |
|
368 | + if( $tkt_sold > 0 ) { |
|
369 | + update_option( 'uxip_ee_tkt_sold', $tkt_sold ); |
|
370 | + } |
|
345 | 371 | |
346 | 372 | |
347 | 373 | set_transient( 'ee4_event_info_check', 1, WEEK_IN_SECONDS * 2 ); |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\interfaces\InterminableInterface; |
2 | 2 | |
3 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
4 | 4 | /** |
5 | 5 | * Event Espresso |
6 | 6 | * |
@@ -63,31 +63,31 @@ discard block |
||
63 | 63 | * @param WP_Query $WP_Query |
64 | 64 | * @return string | NULL |
65 | 65 | */ |
66 | - public function get_route( WP_Query $WP_Query ) { |
|
66 | + public function get_route(WP_Query $WP_Query) { |
|
67 | 67 | $this->WP_Query = $WP_Query; |
68 | 68 | // assume this if first route being called |
69 | 69 | $previous_route = FALSE; |
70 | 70 | // but is it really ??? |
71 | - if ( ! empty( self::$_previous_routes )) { |
|
71 | + if ( ! empty(self::$_previous_routes)) { |
|
72 | 72 | // get last run route |
73 | - $previous_routes = array_values( self::$_previous_routes ); |
|
74 | - $previous_route = array_pop( $previous_routes ); |
|
73 | + $previous_routes = array_values(self::$_previous_routes); |
|
74 | + $previous_route = array_pop($previous_routes); |
|
75 | 75 | } |
76 | 76 | // has another route already been run ? |
77 | - if ( $previous_route ) { |
|
77 | + if ($previous_route) { |
|
78 | 78 | // check if forwarding has been set |
79 | - $current_route = $this->get_forward( $previous_route ); |
|
79 | + $current_route = $this->get_forward($previous_route); |
|
80 | 80 | try { |
81 | 81 | //check for recursive forwarding |
82 | - if ( isset( self::$_previous_routes[ $current_route ] )) { |
|
82 | + if (isset(self::$_previous_routes[$current_route])) { |
|
83 | 83 | throw new EE_Error( |
84 | 84 | sprintf( |
85 | - __('An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.','event_espresso'), |
|
85 | + __('An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.', 'event_espresso'), |
|
86 | 86 | $current_route |
87 | 87 | ) |
88 | 88 | ); |
89 | 89 | } |
90 | - } catch ( EE_Error $e ) { |
|
90 | + } catch (EE_Error $e) { |
|
91 | 91 | $e->get_error(); |
92 | 92 | return NULL; |
93 | 93 | } |
@@ -97,13 +97,13 @@ discard block |
||
97 | 97 | // grab all routes |
98 | 98 | $routes = EE_Registry::instance()->CFG->get_routes(); |
99 | 99 | //d( $routes ); |
100 | - foreach( $routes as $key => $route ) { |
|
100 | + foreach ($routes as $key => $route) { |
|
101 | 101 | // check request for module route |
102 | - if ( EE_Registry::instance()->REQ->is_set( $key )) { |
|
102 | + if (EE_Registry::instance()->REQ->is_set($key)) { |
|
103 | 103 | //echo '<b style="color:#2EA2CC;">key : <span style="color:#E76700">' . $key . '</span></b><br />'; |
104 | - $current_route = sanitize_text_field( EE_Registry::instance()->REQ->get( $key )); |
|
105 | - if ( $current_route ) { |
|
106 | - $current_route = array( $key, $current_route ); |
|
104 | + $current_route = sanitize_text_field(EE_Registry::instance()->REQ->get($key)); |
|
105 | + if ($current_route) { |
|
106 | + $current_route = array($key, $current_route); |
|
107 | 107 | //echo '<b style="color:#2EA2CC;">current_route : <span style="color:#E76700">' . $current_route . '</span></b><br />'; |
108 | 108 | break; |
109 | 109 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | } |
112 | 112 | } |
113 | 113 | // sorry, but I can't read what you route ! |
114 | - if ( empty( $current_route )) { |
|
114 | + if (empty($current_route)) { |
|
115 | 115 | return NULL; |
116 | 116 | } |
117 | 117 | //add route to previous routes array |
@@ -131,46 +131,46 @@ discard block |
||
131 | 131 | * @param string $current_route |
132 | 132 | * @return mixed EED_Module | boolean |
133 | 133 | */ |
134 | - public function resolve_route( $key, $current_route ) { |
|
134 | + public function resolve_route($key, $current_route) { |
|
135 | 135 | // get module method that route has been mapped to |
136 | - $module_method = EE_Config::get_route( $current_route, $key ); |
|
136 | + $module_method = EE_Config::get_route($current_route, $key); |
|
137 | 137 | //EEH_Debug_Tools::printr( $module_method, '$module_method <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
138 | 138 | // verify result was returned |
139 | - if ( empty( $module_method )) { |
|
140 | - $msg = sprintf( __( 'The requested route %s could not be mapped to any registered modules.', 'event_espresso' ), $current_route ); |
|
141 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
139 | + if (empty($module_method)) { |
|
140 | + $msg = sprintf(__('The requested route %s could not be mapped to any registered modules.', 'event_espresso'), $current_route); |
|
141 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
142 | 142 | return FALSE; |
143 | 143 | } |
144 | 144 | // verify that result is an array |
145 | - if ( ! is_array( $module_method )) { |
|
146 | - $msg = sprintf( __( 'The %s route has not been properly registered.', 'event_espresso' ), $current_route ); |
|
147 | - EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
145 | + if ( ! is_array($module_method)) { |
|
146 | + $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
|
147 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
148 | 148 | return FALSE; |
149 | 149 | } |
150 | 150 | // grab module name |
151 | 151 | $module_name = $module_method[0]; |
152 | 152 | // verify that a class method was registered properly |
153 | - if ( ! isset( $module_method[1] )) { |
|
154 | - $msg = sprintf( __( 'A class method for the %s route has not been properly registered.', 'event_espresso' ), $current_route ); |
|
155 | - EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
153 | + if ( ! isset($module_method[1])) { |
|
154 | + $msg = sprintf(__('A class method for the %s route has not been properly registered.', 'event_espresso'), $current_route); |
|
155 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
156 | 156 | return FALSE; |
157 | 157 | } |
158 | 158 | // grab method |
159 | 159 | $method = $module_method[1]; |
160 | 160 | // verify that class exists |
161 | - if ( ! class_exists( $module_name )) { |
|
162 | - $msg = sprintf( __( 'The requested %s class could not be found.', 'event_espresso' ), $module_name ); |
|
163 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
161 | + if ( ! class_exists($module_name)) { |
|
162 | + $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
|
163 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
164 | 164 | return FALSE; |
165 | 165 | } |
166 | 166 | // verify that method exists |
167 | - if ( ! method_exists( $module_name, $method )) { |
|
168 | - $msg = sprintf( __( 'The class method %s for the %s route is in invalid.', 'event_espresso' ), $method, $current_route ); |
|
169 | - EE_Error::add_error( $msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
167 | + if ( ! method_exists($module_name, $method)) { |
|
168 | + $msg = sprintf(__('The class method %s for the %s route is in invalid.', 'event_espresso'), $method, $current_route); |
|
169 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
170 | 170 | return FALSE; |
171 | 171 | } |
172 | 172 | // instantiate module and call route method |
173 | - return $this->_module_router( $module_name, $method ); |
|
173 | + return $this->_module_router($module_name, $method); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | |
@@ -184,16 +184,16 @@ discard block |
||
184 | 184 | * @param string $module_name |
185 | 185 | * @return EED_Module | NULL |
186 | 186 | */ |
187 | - public static function module_factory( $module_name ) { |
|
188 | - if ( $module_name == 'EED_Module' ) { |
|
189 | - EE_Error::add_error( sprintf( __( 'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.', 'event_espresso' ), $module_name ), __FILE__, __FUNCTION__, __LINE__ ); |
|
187 | + public static function module_factory($module_name) { |
|
188 | + if ($module_name == 'EED_Module') { |
|
189 | + EE_Error::add_error(sprintf(__('EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.', 'event_espresso'), $module_name), __FILE__, __FUNCTION__, __LINE__); |
|
190 | 190 | return NULL; |
191 | 191 | } |
192 | 192 | // let's pause to reflect on this... |
193 | - $mod_reflector = new ReflectionClass( $module_name ); |
|
193 | + $mod_reflector = new ReflectionClass($module_name); |
|
194 | 194 | // ensure that class is actually a module |
195 | - if ( ! $mod_reflector->isSubclassOf( 'EED_Module' )) { |
|
196 | - EE_Error::add_error( sprintf( __( 'The requested %s module is not of the class EED_Module.', 'event_espresso' ), $module_name ), __FILE__, __FUNCTION__, __LINE__ ); |
|
195 | + if ( ! $mod_reflector->isSubclassOf('EED_Module')) { |
|
196 | + EE_Error::add_error(sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), __FILE__, __FUNCTION__, __LINE__); |
|
197 | 197 | return NULL; |
198 | 198 | } |
199 | 199 | // instantiate and return module class |
@@ -211,14 +211,14 @@ discard block |
||
211 | 211 | * @param string $method |
212 | 212 | * @return EED_Module | NULL |
213 | 213 | */ |
214 | - private function _module_router( $module_name, $method ) { |
|
214 | + private function _module_router($module_name, $method) { |
|
215 | 215 | // instantiate module class |
216 | - $module = EE_Module_Request_Router::module_factory( $module_name ); |
|
217 | - if ( $module instanceof EED_Module ) { |
|
216 | + $module = EE_Module_Request_Router::module_factory($module_name); |
|
217 | + if ($module instanceof EED_Module) { |
|
218 | 218 | // and call whatever action the route was for |
219 | 219 | try { |
220 | - call_user_func( array( $module, $method ), $this->WP_Query ); |
|
221 | - } catch ( EE_Error $e ) { |
|
220 | + call_user_func(array($module, $method), $this->WP_Query); |
|
221 | + } catch (EE_Error $e) { |
|
222 | 222 | $e->get_error(); |
223 | 223 | return NULL; |
224 | 224 | } |
@@ -235,8 +235,8 @@ discard block |
||
235 | 235 | * @param $current_route |
236 | 236 | * @return string |
237 | 237 | */ |
238 | - public function get_forward( $current_route ) { |
|
239 | - return EE_Config::get_forward( $current_route ); |
|
238 | + public function get_forward($current_route) { |
|
239 | + return EE_Config::get_forward($current_route); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | |
@@ -248,8 +248,8 @@ discard block |
||
248 | 248 | * @param $current_route |
249 | 249 | * @return string |
250 | 250 | */ |
251 | - public function get_view( $current_route ) { |
|
252 | - return EE_Config::get_view( $current_route ); |
|
251 | + public function get_view($current_route) { |
|
252 | + return EE_Config::get_view($current_route); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | * @param $b |
260 | 260 | * @return bool |
261 | 261 | */ |
262 | - public function __set($a,$b) { return FALSE; } |
|
262 | + public function __set($a, $b) { return FALSE; } |
|
263 | 263 | |
264 | 264 | |
265 | 265 |
@@ -1,6 +1,8 @@ |
||
1 | 1 | <?php use EventEspresso\core\interfaces\InterminableInterface; |
2 | 2 | |
3 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
3 | +if ( ! defined( 'EVENT_ESPRESSO_VERSION')) { |
|
4 | + exit('No direct script access allowed'); |
|
5 | +} |
|
4 | 6 | /** |
5 | 7 | * Event Espresso |
6 | 8 | * |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\interfaces\ResettableInterface; |
2 | 2 | |
3 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
4 | 4 | /** |
5 | 5 | * Event Espresso |
6 | 6 | * |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | * @var WP $WP |
84 | 84 | * @return void |
85 | 85 | */ |
86 | - public abstract function run( $WP ); |
|
86 | + public abstract function run($WP); |
|
87 | 87 | |
88 | 88 | |
89 | 89 | |
@@ -106,12 +106,12 @@ discard block |
||
106 | 106 | * @param $module_name |
107 | 107 | * @return EED_Module |
108 | 108 | */ |
109 | - protected static function get_instance( $module_name = '' ) { |
|
110 | - $module_name = ! empty( $module_name ) ? $module_name : get_called_class(); |
|
111 | - if ( ! isset( EE_Registry::instance()->modules->{$module_name} ) || ! EE_Registry::instance()->modules->{$module_name} instanceof EED_Module ) { |
|
112 | - EE_Registry::instance()->add_module( $module_name ); |
|
109 | + protected static function get_instance($module_name = '') { |
|
110 | + $module_name = ! empty($module_name) ? $module_name : get_called_class(); |
|
111 | + if ( ! isset(EE_Registry::instance()->modules->{$module_name} ) || ! EE_Registry::instance()->modules->{$module_name} instanceof EED_Module) { |
|
112 | + EE_Registry::instance()->add_module($module_name); |
|
113 | 113 | } |
114 | - return EE_Registry::instance()->get_module( $module_name ); |
|
114 | + return EE_Registry::instance()->get_module($module_name); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | * @return string |
124 | 124 | */ |
125 | 125 | public function module_name() { |
126 | - return get_class( $this ); |
|
126 | + return get_class($this); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 |
@@ -1,6 +1,8 @@ |
||
1 | 1 | <?php use EventEspresso\core\interfaces\ResettableInterface; |
2 | 2 | |
3 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
3 | +if ( ! defined( 'EVENT_ESPRESSO_VERSION')) { |
|
4 | + exit('No direct script access allowed'); |
|
5 | +} |
|
4 | 6 | /** |
5 | 7 | * Event Espresso |
6 | 8 | * |
@@ -1,6 +1,8 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\interfaces\ResettableInterface; |
2 | 2 | |
3 | -if (!defined( 'EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
3 | +if (!defined( 'EVENT_ESPRESSO_VERSION')) { |
|
4 | + exit('No direct script access allowed'); |
|
5 | +} |
|
4 | 6 | do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
5 | 7 | /** |
6 | 8 | * EE_Import class |
@@ -297,7 +299,7 @@ discard block |
||
297 | 299 | if(isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()){ |
298 | 300 | EE_Error::add_attention(sprintf(__("CSV Data appears to be from the same database, so attempting to update data", "event_espresso"))); |
299 | 301 | $export_from_site_a_to_b = false; |
300 | - }else{ |
|
302 | + } else{ |
|
301 | 303 | $old_site_url = isset( $csv_metadata['site_url']) ? $csv_metadata['site_url'] : $old_site_url; |
302 | 304 | EE_Error::add_attention(sprintf(__("CSV Data appears to be from a different database (%s instead of %s), so we assume IDs in the CSV data DO NOT correspond to IDs in this database", "event_espresso"),$old_site_url,site_url())); |
303 | 305 | }; |
@@ -378,7 +380,7 @@ discard block |
||
378 | 380 | //now check that assumption was correct. If |
379 | 381 | if ( EE_Registry::instance()->is_model_name($model_name_in_csv_data)) { |
380 | 382 | $model_name = $model_name_in_csv_data; |
381 | - }else { |
|
383 | + } else { |
|
382 | 384 | // no table info in the array and no table name passed to the function?? FAIL |
383 | 385 | EE_Error::add_error( __('No table information was specified and/or found, therefore the import could not be completed','event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
384 | 386 | return FALSE; |
@@ -402,7 +404,7 @@ discard block |
||
402 | 404 | //there is no primary key) |
403 | 405 | if($model->has_primary_key_field()){ |
404 | 406 | $id_in_csv = $model_object_data[$model->primary_key_name()]; |
405 | - }else{ |
|
407 | + } else{ |
|
406 | 408 | $id_in_csv = $model->get_index_primary_key_string($model_object_data); |
407 | 409 | } |
408 | 410 | |
@@ -412,7 +414,7 @@ discard block |
||
412 | 414 | //or just update. |
413 | 415 | if($export_from_site_a_to_b){ |
414 | 416 | $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_other_db( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
415 | - }else{//this is just a re-import |
|
417 | + } else{//this is just a re-import |
|
416 | 418 | $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
417 | 419 | } |
418 | 420 | if( $what_to_do == self::do_nothing ) { |
@@ -432,7 +434,7 @@ discard block |
||
432 | 434 | if($model->has_primary_key_field()){ |
433 | 435 | $old_db_to_new_db_mapping[$model_name][$id_in_csv] = $conflicting->ID(); |
434 | 436 | $model_object_data[$model->primary_key_name()] = $conflicting->ID(); |
435 | - }else{ |
|
437 | + } else{ |
|
436 | 438 | //we want to update this conflicting item, instead of inserting a conflicting item |
437 | 439 | //so we need to make sure they match entirely (its possible that they only conflicted on one field, but we need them to match on other fields |
438 | 440 | //for the WHERE conditions in the update). At the time of this comment, there were no models like this |
@@ -444,9 +446,9 @@ discard block |
||
444 | 446 | } |
445 | 447 | if( $what_to_do == self::do_insert ) { |
446 | 448 | $old_db_to_new_db_mapping = $this->_insert_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
447 | - }elseif( $what_to_do == self::do_update ) { |
|
449 | + } elseif( $what_to_do == self::do_update ) { |
|
448 | 450 | $old_db_to_new_db_mapping = $this->_update_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
449 | - }else{ |
|
451 | + } else{ |
|
450 | 452 | throw new EE_Error( sprintf( __( 'Programming error. We shoudl be inserting or updating, but instead we are being told to "%s", whifh is invalid', 'event_espresso' ), $what_to_do ) ); |
451 | 453 | } |
452 | 454 | } |
@@ -474,7 +476,7 @@ discard block |
||
474 | 476 | //in the old data that we know of |
475 | 477 | if( isset($old_db_to_new_db_mapping[$model_name][$id_in_csv]) ){ |
476 | 478 | return self::do_update; |
477 | - }else{ |
|
479 | + } else{ |
|
478 | 480 | return self::do_insert; |
479 | 481 | } |
480 | 482 | } |
@@ -493,7 +495,7 @@ discard block |
||
493 | 495 | //in this case, check if this thing ACTUALLY exists in the database |
494 | 496 | if( $model->get_one_conflicting( $model_object_data ) ){ |
495 | 497 | return self::do_update; |
496 | - }else{ |
|
498 | + } else{ |
|
497 | 499 | return self::do_insert; |
498 | 500 | } |
499 | 501 | } |
@@ -524,7 +526,7 @@ discard block |
||
524 | 526 | try{ |
525 | 527 | $model_name_field = $model->get_field_containing_related_model_name(); |
526 | 528 | $models_pointed_to_by_model_name_field = $model_name_field->get_model_names_pointed_to(); |
527 | - }catch( EE_Error $e ){ |
|
529 | + } catch( EE_Error $e ){ |
|
528 | 530 | $model_name_field = NULL; |
529 | 531 | $models_pointed_to_by_model_name_field = array(); |
530 | 532 | } |
@@ -545,7 +547,7 @@ discard block |
||
545 | 547 | $found_a_mapping = true; |
546 | 548 | break; |
547 | 549 | } |
548 | - }else{ |
|
550 | + } else{ |
|
549 | 551 | $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
550 | 552 | $model_object_data[ $field_obj->get_name() ], |
551 | 553 | $model_pointed_to_by_fk, |
@@ -560,7 +562,7 @@ discard block |
||
560 | 562 | |
561 | 563 | |
562 | 564 | } |
563 | - }else{ |
|
565 | + } else{ |
|
564 | 566 | //it's a string foreign key (which we leave alone, because those are things |
565 | 567 | //like country names, which we'd really rather not make 2 USAs etc (we'd actually |
566 | 568 | //prefer to just update one) |
@@ -603,14 +605,14 @@ discard block |
||
603 | 605 | if( isset( $old_db_to_new_db_mapping[ $model_name ][ $object_id ] ) ){ |
604 | 606 | |
605 | 607 | return $old_db_to_new_db_mapping[ $model_name ][ $object_id ]; |
606 | - }elseif( $object_id == '0' || $object_id == '' ) { |
|
608 | + } elseif( $object_id == '0' || $object_id == '' ) { |
|
607 | 609 | //leave as-is |
608 | 610 | return $object_id; |
609 | - }elseif( $export_from_site_a_to_b ){ |
|
611 | + } elseif( $export_from_site_a_to_b ){ |
|
610 | 612 | //we couldn't find a mapping for this, and it's from a different site, |
611 | 613 | //so blank it out |
612 | 614 | return NULL; |
613 | - }elseif( ! $export_from_site_a_to_b ) { |
|
615 | + } elseif( ! $export_from_site_a_to_b ) { |
|
614 | 616 | //we coudln't find a mapping for this, but it's from thsi DB anyway |
615 | 617 | //so let's just leave it as-is |
616 | 618 | return $object_id; |
@@ -631,7 +633,7 @@ discard block |
||
631 | 633 | if($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()){ |
632 | 634 | $effective_id = $model_object_data[$model->primary_key_name()]; |
633 | 635 | unset($model_object_data[$model->primary_key_name()]); |
634 | - }else{ |
|
636 | + } else{ |
|
635 | 637 | $effective_id = $model->get_index_primary_key_string( $model_object_data ); |
636 | 638 | } |
637 | 639 | //the model takes care of validating the CSV's input |
@@ -641,7 +643,7 @@ discard block |
||
641 | 643 | $old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_id; |
642 | 644 | $this->_total_inserts++; |
643 | 645 | EE_Error::add_success( sprintf(__("Successfully added new %s (with id %s) with csv data %s", "event_espresso"),$model->get_this_model_name(),$new_id, implode(",",$model_object_data))); |
644 | - }else{ |
|
646 | + } else{ |
|
645 | 647 | $this->_total_insert_errors++; |
646 | 648 | //put the ID used back in there for the error message |
647 | 649 | if($model->has_primary_key_field()){ |
@@ -649,7 +651,7 @@ discard block |
||
649 | 651 | } |
650 | 652 | EE_Error::add_error( sprintf(__("Could not insert new %s with the csv data: %s", "event_espresso"),$model->get_this_model_name(),http_build_query($model_object_data)), __FILE__, __FUNCTION__, __LINE__ ); |
651 | 653 | } |
652 | - }catch(EE_Error $e){ |
|
654 | + } catch(EE_Error $e){ |
|
653 | 655 | $this->_total_insert_errors++; |
654 | 656 | if($model->has_primary_key_field()){ |
655 | 657 | $model_object_data[$model->primary_key_name()] = $effective_id; |
@@ -676,12 +678,12 @@ discard block |
||
676 | 678 | $conditions = array($model->primary_key_name() => $model_object_data[$model->primary_key_name()]); |
677 | 679 | //remove the primary key because we shouldn't use it for updating |
678 | 680 | unset($model_object_data_for_update[$model->primary_key_name()]); |
679 | - }elseif($model->get_combined_primary_key_fields() > 1 ){ |
|
681 | + } elseif($model->get_combined_primary_key_fields() > 1 ){ |
|
680 | 682 | $conditions = array(); |
681 | 683 | foreach($model->get_combined_primary_key_fields() as $key_field){ |
682 | 684 | $conditions[$key_field->get_name()] = $model_object_data[$key_field->get_name()]; |
683 | 685 | } |
684 | - }else{ |
|
686 | + } else{ |
|
685 | 687 | $model->primary_key_name();//this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey) |
686 | 688 | } |
687 | 689 | |
@@ -695,23 +697,23 @@ discard block |
||
695 | 697 | //and so we record what record ended up being updated using the mapping |
696 | 698 | if( $model->has_primary_key_field() ){ |
697 | 699 | $new_key_for_mapping = $model_object_data[ $model->primary_key_name() ]; |
698 | - }else{ |
|
700 | + } else{ |
|
699 | 701 | //no primary key just a combined key |
700 | 702 | $new_key_for_mapping = $model->get_index_primary_key_string( $model_object_data ); |
701 | 703 | } |
702 | 704 | $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_key_for_mapping; |
703 | - }else{ |
|
705 | + } else{ |
|
704 | 706 | $matched_items = $model->get_all(array($conditions)); |
705 | 707 | if( ! $matched_items){ |
706 | 708 | //no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck? |
707 | 709 | $this->_total_update_errors++; |
708 | 710 | EE_Error::add_error( sprintf(__("Could not update %s with the csv data: '%s' for an unknown reason (using WHERE conditions %s)", "event_espresso"),$model->get_this_model_name(),http_build_query($model_object_data),http_build_query($conditions)), __FILE__, __FUNCTION__, __LINE__ ); |
709 | - }else{ |
|
711 | + } else{ |
|
710 | 712 | $this->_total_updates++; |
711 | 713 | EE_Error::add_success( sprintf(__("%s with csv data '%s' was found in the database and didn't need updating because all the data is identical.", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data))); |
712 | 714 | } |
713 | 715 | } |
714 | - }catch(EE_Error $e){ |
|
716 | + } catch(EE_Error $e){ |
|
715 | 717 | $this->_total_update_errors++; |
716 | 718 | $basic_message = sprintf(__("Could not update %s with the csv data: %s because %s", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data),$e->getMessage()); |
717 | 719 | $debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString(); |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\interfaces\ResettableInterface; |
2 | 2 | |
3 | -if (!defined( 'EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
4 | -do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
4 | +do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
5 | 5 | /** |
6 | 6 | * EE_Import class |
7 | 7 | * |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public static function instance() { |
60 | 60 | // check if class object is instantiated |
61 | - if ( self::$_instance === NULL or ! is_object( self::$_instance ) or ! ( self::$_instance instanceof EE_Import )) { |
|
61 | + if (self::$_instance === NULL or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Import)) { |
|
62 | 62 | self::$_instance = new self(); |
63 | 63 | } |
64 | 64 | return self::$_instance; |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * Resets the importer |
69 | 69 | * @return EE_Import |
70 | 70 | */ |
71 | - public static function reset(){ |
|
71 | + public static function reset() { |
|
72 | 72 | self::$_instance = null; |
73 | 73 | return self::instance(); |
74 | 74 | } |
@@ -86,27 +86,27 @@ discard block |
||
86 | 86 | * @param string $type - type of file to import |
87 | 87 | * @ return string |
88 | 88 | */ |
89 | - public function upload_form ( $title, $intro, $form_url, $action, $type ) { |
|
89 | + public function upload_form($title, $intro, $form_url, $action, $type) { |
|
90 | 90 | |
91 | - $form_url = EE_Admin_Page::add_query_args_and_nonce( array( 'action' => $action ), $form_url ); |
|
91 | + $form_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => $action), $form_url); |
|
92 | 92 | |
93 | 93 | ob_start(); |
94 | 94 | ?> |
95 | 95 | <div class="ee-upload-form-dv"> |
96 | - <h3><?php echo $title;?></h3> |
|
97 | - <p><?php echo $intro;?></p> |
|
96 | + <h3><?php echo $title; ?></h3> |
|
97 | + <p><?php echo $intro; ?></p> |
|
98 | 98 | |
99 | 99 | <form action="<?php echo $form_url?>" method="post" enctype="multipart/form-data"> |
100 | - <input type="hidden" name="csv_submitted" value="TRUE" id="<?php echo time();?>"> |
|
101 | - <input name="import" type="hidden" value="<?php echo $type;?>" /> |
|
100 | + <input type="hidden" name="csv_submitted" value="TRUE" id="<?php echo time(); ?>"> |
|
101 | + <input name="import" type="hidden" value="<?php echo $type; ?>" /> |
|
102 | 102 | <input type="file" name="file[]" size="90" > |
103 | - <input class="button-primary" type="submit" value="<?php _e( 'Upload File', 'event_espresso' );?>"> |
|
103 | + <input class="button-primary" type="submit" value="<?php _e('Upload File', 'event_espresso'); ?>"> |
|
104 | 104 | </form> |
105 | 105 | |
106 | 106 | <p class="ee-attention"> |
107 | - <b><?php _e( 'Attention', 'event_espresso' );?></b><br/> |
|
108 | - <?php echo sprintf( __( 'Accepts .%s file types only.', 'event_espresso' ), $type ) ;?> |
|
109 | - <?php echo __( 'Please only import CSV files exported from Event Espresso, or compatible 3rd-party software.', 'event_espresso' );?> |
|
107 | + <b><?php _e('Attention', 'event_espresso'); ?></b><br/> |
|
108 | + <?php echo sprintf(__('Accepts .%s file types only.', 'event_espresso'), $type); ?> |
|
109 | + <?php echo __('Please only import CSV files exported from Event Espresso, or compatible 3rd-party software.', 'event_espresso'); ?> |
|
110 | 110 | </p> |
111 | 111 | |
112 | 112 | </div> |
@@ -127,13 +127,13 @@ discard block |
||
127 | 127 | */ |
128 | 128 | public function import() { |
129 | 129 | |
130 | - require_once( EE_CLASSES . 'EE_CSV.class.php' ); |
|
130 | + require_once(EE_CLASSES.'EE_CSV.class.php'); |
|
131 | 131 | $this->EE_CSV = EE_CSV::instance(); |
132 | 132 | |
133 | - if ( isset( $_REQUEST['import'] )) { |
|
134 | - if( isset( $_POST['csv_submitted'] )) { |
|
133 | + if (isset($_REQUEST['import'])) { |
|
134 | + if (isset($_POST['csv_submitted'])) { |
|
135 | 135 | |
136 | - switch ( $_FILES['file']['error'][0] ) { |
|
136 | + switch ($_FILES['file']['error'][0]) { |
|
137 | 137 | case UPLOAD_ERR_OK: |
138 | 138 | $error_msg = FALSE; |
139 | 139 | break; |
@@ -163,32 +163,32 @@ discard block |
||
163 | 163 | break; |
164 | 164 | } |
165 | 165 | |
166 | - if ( ! $error_msg ) { |
|
166 | + if ( ! $error_msg) { |
|
167 | 167 | |
168 | - $filename = $_FILES['file']['name'][0]; |
|
169 | - $file_ext = substr( strrchr( $filename, '.' ), 1 ); |
|
170 | - $file_type = $_FILES['file']['type'][0]; |
|
171 | - $temp_file = $_FILES['file']['tmp_name'][0]; |
|
172 | - $filesize = $_FILES['file']['size'][0] / 1024;//convert from bytes to KB |
|
168 | + $filename = $_FILES['file']['name'][0]; |
|
169 | + $file_ext = substr(strrchr($filename, '.'), 1); |
|
170 | + $file_type = $_FILES['file']['type'][0]; |
|
171 | + $temp_file = $_FILES['file']['tmp_name'][0]; |
|
172 | + $filesize = $_FILES['file']['size'][0] / 1024; //convert from bytes to KB |
|
173 | 173 | |
174 | - if ( $file_ext=='csv' ) { |
|
174 | + if ($file_ext == 'csv') { |
|
175 | 175 | |
176 | - $max_upload = $this->EE_CSV->get_max_upload_size();//max upload size in KB |
|
177 | - if ( $filesize < $max_upload || true) { |
|
176 | + $max_upload = $this->EE_CSV->get_max_upload_size(); //max upload size in KB |
|
177 | + if ($filesize < $max_upload || true) { |
|
178 | 178 | |
179 | - $wp_upload_dir = str_replace( array( '\\', '/' ), DS, wp_upload_dir()); |
|
180 | - $path_to_file = $wp_upload_dir['basedir'] . DS . 'espresso' . DS . $filename; |
|
179 | + $wp_upload_dir = str_replace(array('\\', '/'), DS, wp_upload_dir()); |
|
180 | + $path_to_file = $wp_upload_dir['basedir'].DS.'espresso'.DS.$filename; |
|
181 | 181 | |
182 | - if( move_uploaded_file( $temp_file, $path_to_file )) { |
|
182 | + if (move_uploaded_file($temp_file, $path_to_file)) { |
|
183 | 183 | |
184 | 184 | // convert csv to array |
185 | - $this->csv_array = $this->EE_CSV->import_csv_to_model_data_array( $path_to_file ); |
|
185 | + $this->csv_array = $this->EE_CSV->import_csv_to_model_data_array($path_to_file); |
|
186 | 186 | |
187 | 187 | // was data successfully stored in an array? |
188 | - if ( is_array( $this->csv_array ) ) { |
|
188 | + if (is_array($this->csv_array)) { |
|
189 | 189 | |
190 | - $import_what = str_replace( 'csv_import_', '', $_REQUEST['action'] ); |
|
191 | - $import_what = str_replace( '_', ' ', ucwords( $import_what )); |
|
190 | + $import_what = str_replace('csv_import_', '', $_REQUEST['action']); |
|
191 | + $import_what = str_replace('_', ' ', ucwords($import_what)); |
|
192 | 192 | $processed_data = $this->csv_array; |
193 | 193 | $this->columns_to_save = FALSE; |
194 | 194 | |
@@ -207,33 +207,33 @@ discard block |
||
207 | 207 | |
208 | 208 | } |
209 | 209 | // save processed codes to db |
210 | - if ( $this->save_csv_data_array_to_db( $processed_data, $this->columns_to_save ) ) { |
|
210 | + if ($this->save_csv_data_array_to_db($processed_data, $this->columns_to_save)) { |
|
211 | 211 | return TRUE; |
212 | 212 | |
213 | 213 | } |
214 | 214 | } else { |
215 | 215 | // no array? must be an error |
216 | - EE_Error::add_error(sprintf(__("No file seems to have been uploaded", "event_espresso")), __FILE__, __FUNCTION__, __LINE__ ); |
|
216 | + EE_Error::add_error(sprintf(__("No file seems to have been uploaded", "event_espresso")), __FILE__, __FUNCTION__, __LINE__); |
|
217 | 217 | return FALSE; |
218 | 218 | } |
219 | 219 | |
220 | 220 | } else { |
221 | - EE_Error::add_error(sprintf(__("%s was not successfully uploaded", "event_espresso"),$filename), __FILE__, __FUNCTION__, __LINE__ ); |
|
221 | + EE_Error::add_error(sprintf(__("%s was not successfully uploaded", "event_espresso"), $filename), __FILE__, __FUNCTION__, __LINE__); |
|
222 | 222 | return FALSE; |
223 | 223 | } |
224 | 224 | |
225 | 225 | } else { |
226 | - EE_Error::add_error( sprintf(__("%s was too large of a file and could not be uploaded. The max filesize is %s' KB.", "event_espresso"),$filename,$max_upload), __FILE__, __FUNCTION__, __LINE__ ); |
|
226 | + EE_Error::add_error(sprintf(__("%s was too large of a file and could not be uploaded. The max filesize is %s' KB.", "event_espresso"), $filename, $max_upload), __FILE__, __FUNCTION__, __LINE__); |
|
227 | 227 | return FALSE; |
228 | 228 | } |
229 | 229 | |
230 | 230 | } else { |
231 | - EE_Error::add_error( sprintf(__("%s had an invalid file extension, not uploaded", "event_espresso"),$filename), __FILE__, __FUNCTION__, __LINE__ ); |
|
231 | + EE_Error::add_error(sprintf(__("%s had an invalid file extension, not uploaded", "event_espresso"), $filename), __FILE__, __FUNCTION__, __LINE__); |
|
232 | 232 | return FALSE; |
233 | 233 | } |
234 | 234 | |
235 | 235 | } else { |
236 | - EE_Error::add_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
236 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
237 | 237 | return FALSE; |
238 | 238 | } |
239 | 239 | |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | * @return TRUE on success, FALSE on fail |
279 | 279 | * @throws \EE_Error |
280 | 280 | */ |
281 | - public function save_csv_data_array_to_db( $csv_data_array, $model_name = FALSE ) { |
|
281 | + public function save_csv_data_array_to_db($csv_data_array, $model_name = FALSE) { |
|
282 | 282 | |
283 | 283 | |
284 | 284 | $success = FALSE; |
@@ -288,22 +288,22 @@ discard block |
||
288 | 288 | $export_from_site_a_to_b = true; |
289 | 289 | // first level of array is not table information but a table name was passed to the function |
290 | 290 | // array is only two levels deep, so let's fix that by adding a level, else the next steps will fail |
291 | - if($model_name){ |
|
291 | + if ($model_name) { |
|
292 | 292 | $csv_data_array = array($csv_data_array); |
293 | 293 | } |
294 | 294 | // begin looking through the $csv_data_array, expecting the toplevel key to be the model's name... |
295 | 295 | $old_site_url = 'none-specified'; |
296 | 296 | |
297 | 297 | //hanlde metadata |
298 | - if(isset($csv_data_array[EE_CSV::metadata_header]) ){ |
|
298 | + if (isset($csv_data_array[EE_CSV::metadata_header])) { |
|
299 | 299 | $csv_metadata = array_shift($csv_data_array[EE_CSV::metadata_header]); |
300 | 300 | //ok so its metadata, dont try to save it to ehte db obviously... |
301 | - if(isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()){ |
|
301 | + if (isset($csv_metadata['site_url']) && $csv_metadata['site_url'] == site_url()) { |
|
302 | 302 | EE_Error::add_attention(sprintf(__("CSV Data appears to be from the same database, so attempting to update data", "event_espresso"))); |
303 | 303 | $export_from_site_a_to_b = false; |
304 | - }else{ |
|
305 | - $old_site_url = isset( $csv_metadata['site_url']) ? $csv_metadata['site_url'] : $old_site_url; |
|
306 | - EE_Error::add_attention(sprintf(__("CSV Data appears to be from a different database (%s instead of %s), so we assume IDs in the CSV data DO NOT correspond to IDs in this database", "event_espresso"),$old_site_url,site_url())); |
|
304 | + } else { |
|
305 | + $old_site_url = isset($csv_metadata['site_url']) ? $csv_metadata['site_url'] : $old_site_url; |
|
306 | + EE_Error::add_attention(sprintf(__("CSV Data appears to be from a different database (%s instead of %s), so we assume IDs in the CSV data DO NOT correspond to IDs in this database", "event_espresso"), $old_site_url, site_url())); |
|
307 | 307 | }; |
308 | 308 | unset($csv_data_array[EE_CSV::metadata_header]); |
309 | 309 | } |
@@ -312,30 +312,30 @@ discard block |
||
312 | 312 | * the value will be the newly-inserted ID. |
313 | 313 | * If we have already imported data from the same website via CSV, it shoudl be kept in this wp option |
314 | 314 | */ |
315 | - $old_db_to_new_db_mapping = get_option('ee_id_mapping_from'.sanitize_title($old_site_url),array()); |
|
316 | - if( $old_db_to_new_db_mapping){ |
|
317 | - EE_Error::add_attention(sprintf(__("We noticed you have imported data via CSV from %s before. Because of this, IDs in your CSV have been mapped to their new IDs in %s", "event_espresso"),$old_site_url,site_url())); |
|
315 | + $old_db_to_new_db_mapping = get_option('ee_id_mapping_from'.sanitize_title($old_site_url), array()); |
|
316 | + if ($old_db_to_new_db_mapping) { |
|
317 | + EE_Error::add_attention(sprintf(__("We noticed you have imported data via CSV from %s before. Because of this, IDs in your CSV have been mapped to their new IDs in %s", "event_espresso"), $old_site_url, site_url())); |
|
318 | 318 | } |
319 | 319 | $old_db_to_new_db_mapping = $this->save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping); |
320 | 320 | |
321 | 321 | //save the mapping from old db to new db in case they try re-importing the same data from the same website again |
322 | - update_option('ee_id_mapping_from'.sanitize_title($old_site_url),$old_db_to_new_db_mapping); |
|
322 | + update_option('ee_id_mapping_from'.sanitize_title($old_site_url), $old_db_to_new_db_mapping); |
|
323 | 323 | |
324 | - if ( $this->_total_updates > 0 ) { |
|
325 | - EE_Error::add_success( sprintf(__("%s existing records in the database were updated.", "event_espresso"),$this->_total_updates)); |
|
324 | + if ($this->_total_updates > 0) { |
|
325 | + EE_Error::add_success(sprintf(__("%s existing records in the database were updated.", "event_espresso"), $this->_total_updates)); |
|
326 | 326 | $success = true; |
327 | 327 | } |
328 | - if ( $this->_total_inserts > 0 ) { |
|
329 | - EE_Error::add_success(sprintf(__("%s new records were added to the database.", "event_espresso"),$this->_total_inserts)); |
|
328 | + if ($this->_total_inserts > 0) { |
|
329 | + EE_Error::add_success(sprintf(__("%s new records were added to the database.", "event_espresso"), $this->_total_inserts)); |
|
330 | 330 | $success = true; |
331 | 331 | } |
332 | 332 | |
333 | - if ( $this->_total_update_errors > 0 ) { |
|
334 | - EE_Error::add_error(sprintf(__("'One or more errors occurred, and a total of %s existing records in the database were <strong>not</strong> updated.'", "event_espresso"),$this->_total_update_errors), __FILE__, __FUNCTION__, __LINE__ ); |
|
333 | + if ($this->_total_update_errors > 0) { |
|
334 | + EE_Error::add_error(sprintf(__("'One or more errors occurred, and a total of %s existing records in the database were <strong>not</strong> updated.'", "event_espresso"), $this->_total_update_errors), __FILE__, __FUNCTION__, __LINE__); |
|
335 | 335 | $error = true; |
336 | 336 | } |
337 | - if ( $this->_total_insert_errors > 0 ) { |
|
338 | - EE_Error::add_error(sprintf(__("One or more errors occurred, and a total of %s new records were <strong>not</strong> added to the database.'", "event_espresso"),$this->_total_insert_errors), __FILE__, __FUNCTION__, __LINE__ ); |
|
337 | + if ($this->_total_insert_errors > 0) { |
|
338 | + EE_Error::add_error(sprintf(__("One or more errors occurred, and a total of %s new records were <strong>not</strong> added to the database.'", "event_espresso"), $this->_total_insert_errors), __FILE__, __FUNCTION__, __LINE__); |
|
339 | 339 | $error = true; |
340 | 340 | } |
341 | 341 | |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | EEM_Ticket::instance()->update_tickets_sold(EEM_Ticket::instance()->get_all()); |
345 | 345 | |
346 | 346 | // if there was at least one success and absolutely no errors |
347 | - if ( $success && ! $error ) { |
|
347 | + if ($success && ! $error) { |
|
348 | 348 | return TRUE; |
349 | 349 | } else { |
350 | 350 | return FALSE; |
@@ -376,81 +376,81 @@ discard block |
||
376 | 376 | * @param type $old_db_to_new_db_mapping |
377 | 377 | * @return array updated $old_db_to_new_db_mapping |
378 | 378 | */ |
379 | - public function save_data_rows_to_db( $csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping ) { |
|
380 | - foreach ( $csv_data_array as $model_name_in_csv_data => $model_data_from_import ) { |
|
379 | + public function save_data_rows_to_db($csv_data_array, $export_from_site_a_to_b, $old_db_to_new_db_mapping) { |
|
380 | + foreach ($csv_data_array as $model_name_in_csv_data => $model_data_from_import) { |
|
381 | 381 | //now check that assumption was correct. If |
382 | - if ( EE_Registry::instance()->is_model_name($model_name_in_csv_data)) { |
|
382 | + if (EE_Registry::instance()->is_model_name($model_name_in_csv_data)) { |
|
383 | 383 | $model_name = $model_name_in_csv_data; |
384 | - }else { |
|
384 | + } else { |
|
385 | 385 | // no table info in the array and no table name passed to the function?? FAIL |
386 | - EE_Error::add_error( __('No table information was specified and/or found, therefore the import could not be completed','event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
386 | + EE_Error::add_error(__('No table information was specified and/or found, therefore the import could not be completed', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
387 | 387 | return FALSE; |
388 | 388 | } |
389 | 389 | /* @var $model EEM_Base */ |
390 | 390 | $model = EE_Registry::instance()->load_model($model_name); |
391 | 391 | |
392 | 392 | //so without further ado, scanning all the data provided for primary keys and their inital values |
393 | - foreach ( $model_data_from_import as $model_object_data ) { |
|
393 | + foreach ($model_data_from_import as $model_object_data) { |
|
394 | 394 | //before we do ANYTHING, make sure the csv row wasn't just completely blank |
395 | 395 | $row_is_completely_empty = true; |
396 | - foreach($model_object_data as $field){ |
|
397 | - if($field){ |
|
396 | + foreach ($model_object_data as $field) { |
|
397 | + if ($field) { |
|
398 | 398 | $row_is_completely_empty = false; |
399 | 399 | } |
400 | 400 | } |
401 | - if($row_is_completely_empty){ |
|
401 | + if ($row_is_completely_empty) { |
|
402 | 402 | continue; |
403 | 403 | } |
404 | 404 | //find the PK in the row of data (or a combined key if |
405 | 405 | //there is no primary key) |
406 | - if($model->has_primary_key_field()){ |
|
407 | - $id_in_csv = $model_object_data[$model->primary_key_name()]; |
|
408 | - }else{ |
|
406 | + if ($model->has_primary_key_field()) { |
|
407 | + $id_in_csv = $model_object_data[$model->primary_key_name()]; |
|
408 | + } else { |
|
409 | 409 | $id_in_csv = $model->get_index_primary_key_string($model_object_data); |
410 | 410 | } |
411 | 411 | |
412 | 412 | |
413 | - $model_object_data = $this->_replace_temp_ids_with_mappings( $model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b ); |
|
413 | + $model_object_data = $this->_replace_temp_ids_with_mappings($model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b); |
|
414 | 414 | //now we need to decide if we're going to add a new model object given the $model_object_data, |
415 | 415 | //or just update. |
416 | - if($export_from_site_a_to_b){ |
|
417 | - $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_other_db( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
|
418 | - }else{//this is just a re-import |
|
419 | - $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
|
416 | + if ($export_from_site_a_to_b) { |
|
417 | + $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_other_db($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping); |
|
418 | + } else {//this is just a re-import |
|
419 | + $what_to_do = $this->_decide_whether_to_insert_or_update_given_data_from_same_db($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping); |
|
420 | 420 | } |
421 | - if( $what_to_do == self::do_nothing ) { |
|
421 | + if ($what_to_do == self::do_nothing) { |
|
422 | 422 | continue; |
423 | 423 | } |
424 | 424 | |
425 | 425 | //double-check we actually want to insert, if that's what we're planning |
426 | 426 | //based on whether this item would be unique in the DB or not |
427 | - if( $what_to_do == self::do_insert ) { |
|
427 | + if ($what_to_do == self::do_insert) { |
|
428 | 428 | //we're supposed to be inserting. But wait, will this thing |
429 | 429 | //be acceptable if inserted? |
430 | - $conflicting = $model->get_one_conflicting( $model_object_data, false ); |
|
431 | - if($conflicting){ |
|
430 | + $conflicting = $model->get_one_conflicting($model_object_data, false); |
|
431 | + if ($conflicting) { |
|
432 | 432 | //ok, this item would conflict if inserted. Just update the item that it conflicts with. |
433 | 433 | $what_to_do = self::do_update; |
434 | 434 | //and if this model has a primary key, remember its mapping |
435 | - if($model->has_primary_key_field()){ |
|
435 | + if ($model->has_primary_key_field()) { |
|
436 | 436 | $old_db_to_new_db_mapping[$model_name][$id_in_csv] = $conflicting->ID(); |
437 | 437 | $model_object_data[$model->primary_key_name()] = $conflicting->ID(); |
438 | - }else{ |
|
438 | + } else { |
|
439 | 439 | //we want to update this conflicting item, instead of inserting a conflicting item |
440 | 440 | //so we need to make sure they match entirely (its possible that they only conflicted on one field, but we need them to match on other fields |
441 | 441 | //for the WHERE conditions in the update). At the time of this comment, there were no models like this |
442 | - foreach($model->get_combined_primary_key_fields() as $key_field){ |
|
442 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
443 | 443 | $model_object_data[$key_field->get_name()] = $conflicting->get($key_field->get_name()); |
444 | 444 | } |
445 | 445 | } |
446 | 446 | } |
447 | 447 | } |
448 | - if( $what_to_do == self::do_insert ) { |
|
449 | - $old_db_to_new_db_mapping = $this->_insert_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
|
450 | - }elseif( $what_to_do == self::do_update ) { |
|
451 | - $old_db_to_new_db_mapping = $this->_update_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ); |
|
452 | - }else{ |
|
453 | - throw new EE_Error( sprintf( __( 'Programming error. We shoudl be inserting or updating, but instead we are being told to "%s", whifh is invalid', 'event_espresso' ), $what_to_do ) ); |
|
448 | + if ($what_to_do == self::do_insert) { |
|
449 | + $old_db_to_new_db_mapping = $this->_insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping); |
|
450 | + }elseif ($what_to_do == self::do_update) { |
|
451 | + $old_db_to_new_db_mapping = $this->_update_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping); |
|
452 | + } else { |
|
453 | + throw new EE_Error(sprintf(__('Programming error. We shoudl be inserting or updating, but instead we are being told to "%s", whifh is invalid', 'event_espresso'), $what_to_do)); |
|
454 | 454 | } |
455 | 455 | } |
456 | 456 | } |
@@ -471,13 +471,13 @@ discard block |
||
471 | 471 | * @param array $old_db_to_new_db_mapping by reference so it can be modified |
472 | 472 | * @return string one of the consts on this class that starts with do_* |
473 | 473 | */ |
474 | - protected function _decide_whether_to_insert_or_update_given_data_from_other_db( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ) { |
|
474 | + protected function _decide_whether_to_insert_or_update_given_data_from_other_db($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) { |
|
475 | 475 | $model_name = $model->get_this_model_name(); |
476 | 476 | //if it's a site-to-site export-and-import, see if this modelobject's id |
477 | 477 | //in the old data that we know of |
478 | - if( isset($old_db_to_new_db_mapping[$model_name][$id_in_csv]) ){ |
|
478 | + if (isset($old_db_to_new_db_mapping[$model_name][$id_in_csv])) { |
|
479 | 479 | return self::do_update; |
480 | - }else{ |
|
480 | + } else { |
|
481 | 481 | return self::do_insert; |
482 | 482 | } |
483 | 483 | } |
@@ -492,11 +492,11 @@ discard block |
||
492 | 492 | * @param type $old_db_to_new_db_mapping |
493 | 493 | * @return |
494 | 494 | */ |
495 | - protected function _decide_whether_to_insert_or_update_given_data_from_same_db( $id_in_csv, $model_object_data, $model ) { |
|
495 | + protected function _decide_whether_to_insert_or_update_given_data_from_same_db($id_in_csv, $model_object_data, $model) { |
|
496 | 496 | //in this case, check if this thing ACTUALLY exists in the database |
497 | - if( $model->get_one_conflicting( $model_object_data ) ){ |
|
497 | + if ($model->get_one_conflicting($model_object_data)) { |
|
498 | 498 | return self::do_update; |
499 | - }else{ |
|
499 | + } else { |
|
500 | 500 | return self::do_insert; |
501 | 501 | } |
502 | 502 | } |
@@ -515,55 +515,55 @@ discard block |
||
515 | 515 | * @param boolean $export_from_site_a_to_b |
516 | 516 | * @return array updated model object data with temp IDs removed |
517 | 517 | */ |
518 | - protected function _replace_temp_ids_with_mappings( $model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b ) { |
|
518 | + protected function _replace_temp_ids_with_mappings($model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b) { |
|
519 | 519 | //if this model object's primary key is in the mapping, replace it |
520 | - if( $model->has_primary_key_field() && |
|
520 | + if ($model->has_primary_key_field() && |
|
521 | 521 | $model->get_primary_key_field()->is_auto_increment() && |
522 | - isset( $old_db_to_new_db_mapping[ $model->get_this_model_name() ] ) && |
|
523 | - isset( $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ] ) ) { |
|
524 | - $model_object_data[ $model->primary_key_name() ] = $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $model_object_data[ $model->primary_key_name() ] ]; |
|
522 | + isset($old_db_to_new_db_mapping[$model->get_this_model_name()]) && |
|
523 | + isset($old_db_to_new_db_mapping[$model->get_this_model_name()][$model_object_data[$model->primary_key_name()]])) { |
|
524 | + $model_object_data[$model->primary_key_name()] = $old_db_to_new_db_mapping[$model->get_this_model_name()][$model_object_data[$model->primary_key_name()]]; |
|
525 | 525 | } |
526 | 526 | |
527 | - try{ |
|
527 | + try { |
|
528 | 528 | $model_name_field = $model->get_field_containing_related_model_name(); |
529 | 529 | $models_pointed_to_by_model_name_field = $model_name_field->get_model_names_pointed_to(); |
530 | - }catch( EE_Error $e ){ |
|
530 | + } catch (EE_Error $e) { |
|
531 | 531 | $model_name_field = NULL; |
532 | 532 | $models_pointed_to_by_model_name_field = array(); |
533 | 533 | } |
534 | - foreach( $model->field_settings( true ) as $field_obj ){ |
|
535 | - if( $field_obj instanceof EE_Foreign_Key_Int_Field ) { |
|
534 | + foreach ($model->field_settings(true) as $field_obj) { |
|
535 | + if ($field_obj instanceof EE_Foreign_Key_Int_Field) { |
|
536 | 536 | $models_pointed_to = $field_obj->get_model_names_pointed_to(); |
537 | 537 | $found_a_mapping = false; |
538 | - foreach( $models_pointed_to as $model_pointed_to_by_fk ) { |
|
538 | + foreach ($models_pointed_to as $model_pointed_to_by_fk) { |
|
539 | 539 | |
540 | - if( $model_name_field ){ |
|
541 | - $value_of_model_name_field = $model_object_data[ $model_name_field->get_name() ]; |
|
542 | - if( $value_of_model_name_field == $model_pointed_to_by_fk ) { |
|
543 | - $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
544 | - $model_object_data[ $field_obj->get_name() ], |
|
540 | + if ($model_name_field) { |
|
541 | + $value_of_model_name_field = $model_object_data[$model_name_field->get_name()]; |
|
542 | + if ($value_of_model_name_field == $model_pointed_to_by_fk) { |
|
543 | + $model_object_data[$field_obj->get_name()] = $this->_find_mapping_in( |
|
544 | + $model_object_data[$field_obj->get_name()], |
|
545 | 545 | $model_pointed_to_by_fk, |
546 | 546 | $old_db_to_new_db_mapping, |
547 | 547 | $export_from_site_a_to_b ); |
548 | 548 | $found_a_mapping = true; |
549 | 549 | break; |
550 | 550 | } |
551 | - }else{ |
|
552 | - $model_object_data[ $field_obj->get_name() ] = $this->_find_mapping_in( |
|
553 | - $model_object_data[ $field_obj->get_name() ], |
|
551 | + } else { |
|
552 | + $model_object_data[$field_obj->get_name()] = $this->_find_mapping_in( |
|
553 | + $model_object_data[$field_obj->get_name()], |
|
554 | 554 | $model_pointed_to_by_fk, |
555 | 555 | $old_db_to_new_db_mapping, |
556 | 556 | $export_from_site_a_to_b ); |
557 | 557 | $found_a_mapping = true; |
558 | 558 | } |
559 | 559 | //once we've found a mapping for this field no need to continue |
560 | - if( $found_a_mapping ) { |
|
560 | + if ($found_a_mapping) { |
|
561 | 561 | break; |
562 | 562 | } |
563 | 563 | |
564 | 564 | |
565 | 565 | } |
566 | - }else{ |
|
566 | + } else { |
|
567 | 567 | //it's a string foreign key (which we leave alone, because those are things |
568 | 568 | //like country names, which we'd really rather not make 2 USAs etc (we'd actually |
569 | 569 | //prefer to just update one) |
@@ -571,8 +571,8 @@ discard block |
||
571 | 571 | } |
572 | 572 | } |
573 | 573 | // |
574 | - if( $model instanceof EEM_Term_Taxonomy ){ |
|
575 | - $model_object_data = $this->_handle_split_term_ids( $model_object_data ); |
|
574 | + if ($model instanceof EEM_Term_Taxonomy) { |
|
575 | + $model_object_data = $this->_handle_split_term_ids($model_object_data); |
|
576 | 576 | } |
577 | 577 | return $model_object_data; |
578 | 578 | } |
@@ -584,11 +584,11 @@ discard block |
||
584 | 584 | * @param type $model_object_data |
585 | 585 | * @return array new model object data |
586 | 586 | */ |
587 | - protected function _handle_split_term_ids( $model_object_data ){ |
|
588 | - if( isset( $model_object_data['term_id'] ) && isset( $model_object_data[ 'taxonomy' ]) && apply_filters( 'FHEE__EE_Import__handle_split_term_ids__function_exists', function_exists( 'wp_get_split_term' ), $model_object_data ) ) { |
|
589 | - $new_term_id = wp_get_split_term( $model_object_data[ 'term_id' ], $model_object_data[ 'taxonomy' ] ); |
|
590 | - if( $new_term_id ){ |
|
591 | - $model_object_data[ 'term_id' ] = $new_term_id; |
|
587 | + protected function _handle_split_term_ids($model_object_data) { |
|
588 | + if (isset($model_object_data['term_id']) && isset($model_object_data['taxonomy']) && apply_filters('FHEE__EE_Import__handle_split_term_ids__function_exists', function_exists('wp_get_split_term'), $model_object_data)) { |
|
589 | + $new_term_id = wp_get_split_term($model_object_data['term_id'], $model_object_data['taxonomy']); |
|
590 | + if ($new_term_id) { |
|
591 | + $model_object_data['term_id'] = $new_term_id; |
|
592 | 592 | } |
593 | 593 | } |
594 | 594 | return $model_object_data; |
@@ -602,18 +602,18 @@ discard block |
||
602 | 602 | * @param type $export_from_site_a_to_b |
603 | 603 | * @return int |
604 | 604 | */ |
605 | - protected function _find_mapping_in( $object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) { |
|
606 | - if( isset( $old_db_to_new_db_mapping[ $model_name ][ $object_id ] ) ){ |
|
605 | + protected function _find_mapping_in($object_id, $model_name, $old_db_to_new_db_mapping, $export_from_site_a_to_b) { |
|
606 | + if (isset($old_db_to_new_db_mapping[$model_name][$object_id])) { |
|
607 | 607 | |
608 | - return $old_db_to_new_db_mapping[ $model_name ][ $object_id ]; |
|
609 | - }elseif( $object_id == '0' || $object_id == '' ) { |
|
608 | + return $old_db_to_new_db_mapping[$model_name][$object_id]; |
|
609 | + }elseif ($object_id == '0' || $object_id == '') { |
|
610 | 610 | //leave as-is |
611 | 611 | return $object_id; |
612 | - }elseif( $export_from_site_a_to_b ){ |
|
612 | + }elseif ($export_from_site_a_to_b) { |
|
613 | 613 | //we couldn't find a mapping for this, and it's from a different site, |
614 | 614 | //so blank it out |
615 | 615 | return NULL; |
616 | - }elseif( ! $export_from_site_a_to_b ) { |
|
616 | + }elseif ( ! $export_from_site_a_to_b) { |
|
617 | 617 | //we coudln't find a mapping for this, but it's from thsi DB anyway |
618 | 618 | //so let's just leave it as-is |
619 | 619 | return $object_id; |
@@ -628,36 +628,36 @@ discard block |
||
628 | 628 | * @param type $old_db_to_new_db_mapping |
629 | 629 | * @return array updated $old_db_to_new_db_mapping |
630 | 630 | */ |
631 | - protected function _insert_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ) { |
|
631 | + protected function _insert_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) { |
|
632 | 632 | //remove the primary key, if there is one (we don't want it for inserts OR updates) |
633 | 633 | //we'll put it back in if we need it |
634 | - if($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()){ |
|
634 | + if ($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment()) { |
|
635 | 635 | $effective_id = $model_object_data[$model->primary_key_name()]; |
636 | 636 | unset($model_object_data[$model->primary_key_name()]); |
637 | - }else{ |
|
638 | - $effective_id = $model->get_index_primary_key_string( $model_object_data ); |
|
637 | + } else { |
|
638 | + $effective_id = $model->get_index_primary_key_string($model_object_data); |
|
639 | 639 | } |
640 | 640 | //the model takes care of validating the CSV's input |
641 | - try{ |
|
641 | + try { |
|
642 | 642 | $new_id = $model->insert($model_object_data); |
643 | - if( $new_id ){ |
|
643 | + if ($new_id) { |
|
644 | 644 | $old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_id; |
645 | 645 | $this->_total_inserts++; |
646 | - EE_Error::add_success( sprintf(__("Successfully added new %s (with id %s) with csv data %s", "event_espresso"),$model->get_this_model_name(),$new_id, implode(",",$model_object_data))); |
|
647 | - }else{ |
|
646 | + EE_Error::add_success(sprintf(__("Successfully added new %s (with id %s) with csv data %s", "event_espresso"), $model->get_this_model_name(), $new_id, implode(",", $model_object_data))); |
|
647 | + } else { |
|
648 | 648 | $this->_total_insert_errors++; |
649 | 649 | //put the ID used back in there for the error message |
650 | - if($model->has_primary_key_field()){ |
|
650 | + if ($model->has_primary_key_field()) { |
|
651 | 651 | $model_object_data[$model->primary_key_name()] = $effective_id; |
652 | 652 | } |
653 | - EE_Error::add_error( sprintf(__("Could not insert new %s with the csv data: %s", "event_espresso"),$model->get_this_model_name(),http_build_query($model_object_data)), __FILE__, __FUNCTION__, __LINE__ ); |
|
653 | + EE_Error::add_error(sprintf(__("Could not insert new %s with the csv data: %s", "event_espresso"), $model->get_this_model_name(), http_build_query($model_object_data)), __FILE__, __FUNCTION__, __LINE__); |
|
654 | 654 | } |
655 | - }catch(EE_Error $e){ |
|
655 | + } catch (EE_Error $e) { |
|
656 | 656 | $this->_total_insert_errors++; |
657 | - if($model->has_primary_key_field()){ |
|
657 | + if ($model->has_primary_key_field()) { |
|
658 | 658 | $model_object_data[$model->primary_key_name()] = $effective_id; |
659 | 659 | } |
660 | - EE_Error::add_error( sprintf(__("Could not insert new %s with the csv data: %s because %s", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data),$e->getMessage()), __FILE__, __FUNCTION__, __LINE__ ); |
|
660 | + EE_Error::add_error(sprintf(__("Could not insert new %s with the csv data: %s because %s", "event_espresso"), $model->get_this_model_name(), implode(",", $model_object_data), $e->getMessage()), __FILE__, __FUNCTION__, __LINE__); |
|
661 | 661 | } |
662 | 662 | return $old_db_to_new_db_mapping; |
663 | 663 | } |
@@ -670,55 +670,55 @@ discard block |
||
670 | 670 | * @param array $old_db_to_new_db_mapping |
671 | 671 | * @return array updated $old_db_to_new_db_mapping |
672 | 672 | */ |
673 | - protected function _update_from_data_array( $id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping ) { |
|
674 | - try{ |
|
673 | + protected function _update_from_data_array($id_in_csv, $model_object_data, $model, $old_db_to_new_db_mapping) { |
|
674 | + try { |
|
675 | 675 | //let's keep two copies of the model object data: |
676 | 676 | //one for performing an update, one for everthing else |
677 | 677 | $model_object_data_for_update = $model_object_data; |
678 | - if($model->has_primary_key_field()){ |
|
678 | + if ($model->has_primary_key_field()) { |
|
679 | 679 | $conditions = array($model->primary_key_name() => $model_object_data[$model->primary_key_name()]); |
680 | 680 | //remove the primary key because we shouldn't use it for updating |
681 | 681 | unset($model_object_data_for_update[$model->primary_key_name()]); |
682 | - }elseif($model->get_combined_primary_key_fields() > 1 ){ |
|
682 | + }elseif ($model->get_combined_primary_key_fields() > 1) { |
|
683 | 683 | $conditions = array(); |
684 | - foreach($model->get_combined_primary_key_fields() as $key_field){ |
|
684 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
685 | 685 | $conditions[$key_field->get_name()] = $model_object_data[$key_field->get_name()]; |
686 | 686 | } |
687 | - }else{ |
|
688 | - $model->primary_key_name();//this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey) |
|
687 | + } else { |
|
688 | + $model->primary_key_name(); //this shoudl just throw an exception, explaining that we dont have a primary key (or a combine dkey) |
|
689 | 689 | } |
690 | 690 | |
691 | - $success = $model->update($model_object_data_for_update,array($conditions)); |
|
692 | - if($success){ |
|
691 | + $success = $model->update($model_object_data_for_update, array($conditions)); |
|
692 | + if ($success) { |
|
693 | 693 | $this->_total_updates++; |
694 | - EE_Error::add_success( sprintf(__("Successfully updated %s with csv data %s", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data_for_update))); |
|
694 | + EE_Error::add_success(sprintf(__("Successfully updated %s with csv data %s", "event_espresso"), $model->get_this_model_name(), implode(",", $model_object_data_for_update))); |
|
695 | 695 | //we should still record the mapping even though it was an update |
696 | 696 | //because if we were going to insert somethign but it was going to conflict |
697 | 697 | //we would have last-minute decided to update. So we'd like to know what we updated |
698 | 698 | //and so we record what record ended up being updated using the mapping |
699 | - if( $model->has_primary_key_field() ){ |
|
700 | - $new_key_for_mapping = $model_object_data[ $model->primary_key_name() ]; |
|
701 | - }else{ |
|
699 | + if ($model->has_primary_key_field()) { |
|
700 | + $new_key_for_mapping = $model_object_data[$model->primary_key_name()]; |
|
701 | + } else { |
|
702 | 702 | //no primary key just a combined key |
703 | - $new_key_for_mapping = $model->get_index_primary_key_string( $model_object_data ); |
|
703 | + $new_key_for_mapping = $model->get_index_primary_key_string($model_object_data); |
|
704 | 704 | } |
705 | - $old_db_to_new_db_mapping[ $model->get_this_model_name() ][ $id_in_csv ] = $new_key_for_mapping; |
|
706 | - }else{ |
|
705 | + $old_db_to_new_db_mapping[$model->get_this_model_name()][$id_in_csv] = $new_key_for_mapping; |
|
706 | + } else { |
|
707 | 707 | $matched_items = $model->get_all(array($conditions)); |
708 | - if( ! $matched_items){ |
|
708 | + if ( ! $matched_items) { |
|
709 | 709 | //no items were matched (so we shouldn't have updated)... but then we should have inserted? what the heck? |
710 | 710 | $this->_total_update_errors++; |
711 | - EE_Error::add_error( sprintf(__("Could not update %s with the csv data: '%s' for an unknown reason (using WHERE conditions %s)", "event_espresso"),$model->get_this_model_name(),http_build_query($model_object_data),http_build_query($conditions)), __FILE__, __FUNCTION__, __LINE__ ); |
|
712 | - }else{ |
|
711 | + EE_Error::add_error(sprintf(__("Could not update %s with the csv data: '%s' for an unknown reason (using WHERE conditions %s)", "event_espresso"), $model->get_this_model_name(), http_build_query($model_object_data), http_build_query($conditions)), __FILE__, __FUNCTION__, __LINE__); |
|
712 | + } else { |
|
713 | 713 | $this->_total_updates++; |
714 | - EE_Error::add_success( sprintf(__("%s with csv data '%s' was found in the database and didn't need updating because all the data is identical.", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data))); |
|
714 | + EE_Error::add_success(sprintf(__("%s with csv data '%s' was found in the database and didn't need updating because all the data is identical.", "event_espresso"), $model->get_this_model_name(), implode(",", $model_object_data))); |
|
715 | 715 | } |
716 | 716 | } |
717 | - }catch(EE_Error $e){ |
|
717 | + } catch (EE_Error $e) { |
|
718 | 718 | $this->_total_update_errors++; |
719 | - $basic_message = sprintf(__("Could not update %s with the csv data: %s because %s", "event_espresso"),$model->get_this_model_name(),implode(",",$model_object_data),$e->getMessage()); |
|
720 | - $debug_message = $basic_message . ' Stack trace: ' . $e->getTraceAsString(); |
|
721 | - EE_Error::add_error( "$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__ ); |
|
719 | + $basic_message = sprintf(__("Could not update %s with the csv data: %s because %s", "event_espresso"), $model->get_this_model_name(), implode(",", $model_object_data), $e->getMessage()); |
|
720 | + $debug_message = $basic_message.' Stack trace: '.$e->getTraceAsString(); |
|
721 | + EE_Error::add_error("$basic_message | $debug_message", __FILE__, __FUNCTION__, __LINE__); |
|
722 | 722 | } |
723 | 723 | return $old_db_to_new_db_mapping; |
724 | 724 | } |
@@ -727,28 +727,28 @@ discard block |
||
727 | 727 | * Gets the number of inserts performed since importer was instantiated or reset |
728 | 728 | * @return int |
729 | 729 | */ |
730 | - public function get_total_inserts(){ |
|
730 | + public function get_total_inserts() { |
|
731 | 731 | return $this->_total_inserts; |
732 | 732 | } |
733 | 733 | /** |
734 | 734 | * Gets the number of insert errors since importer was instantiated or reset |
735 | 735 | * @return int |
736 | 736 | */ |
737 | - public function get_total_insert_errors(){ |
|
737 | + public function get_total_insert_errors() { |
|
738 | 738 | return $this->_total_insert_errors; |
739 | 739 | } |
740 | 740 | /** |
741 | 741 | * Gets the number of updates performed since importer was instantiated or reset |
742 | 742 | * @return int |
743 | 743 | */ |
744 | - public function get_total_updates(){ |
|
744 | + public function get_total_updates() { |
|
745 | 745 | return $this->_total_updates; |
746 | 746 | } |
747 | 747 | /** |
748 | 748 | * Gets the number of update errors since importer was instantiated or reset |
749 | 749 | * @return int |
750 | 750 | */ |
751 | - public function get_total_update_errors(){ |
|
751 | + public function get_total_update_errors() { |
|
752 | 752 | return $this->_total_update_errors; |
753 | 753 | } |
754 | 754 |
@@ -1,6 +1,5 @@ |
||
1 | 1 | <?php |
2 | 2 | use EventEspresso\core\interfaces\ResettableInterface; |
3 | - |
|
4 | 3 | use EventEspresso\core\services\database\TableManager; |
5 | 4 | use EventEspresso\core\services\database\TableAnalysis; |
6 | 5 |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * of this EE installation. Keys should be the name of the version the script upgraded to |
83 | 83 | * @var EE_Data_Migration_Script_Base[] |
84 | 84 | */ |
85 | - private $_data_migrations_ran =null; |
|
85 | + private $_data_migrations_ran = null; |
|
86 | 86 | /** |
87 | 87 | * The last ran script. It's nice to store this somewhere accessible, as its easiest |
88 | 88 | * to know which was the last run by which is the newest wp option; but in most of the code |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | */ |
143 | 143 | public static function instance() { |
144 | 144 | // check if class object is instantiated |
145 | - if ( ! self::$_instance instanceof EE_Data_Migration_Manager ) { |
|
145 | + if ( ! self::$_instance instanceof EE_Data_Migration_Manager) { |
|
146 | 146 | self::$_instance = new self(); |
147 | 147 | } |
148 | 148 | return self::$_instance; |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | * all new usages of the singleton should be made with Classname::instance()) and returns it |
153 | 153 | * @return EE_Data_Migration_Manager |
154 | 154 | */ |
155 | - public static function reset(){ |
|
155 | + public static function reset() { |
|
156 | 156 | self::$_instance = NULL; |
157 | 157 | return self::instance(); |
158 | 158 | } |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | /** |
163 | 163 | * constructor |
164 | 164 | */ |
165 | - private function __construct(){ |
|
165 | + private function __construct() { |
|
166 | 166 | $this->stati_that_indicate_to_continue_migrations = array( |
167 | 167 | self::status_continue, |
168 | 168 | self::status_completed |
@@ -181,13 +181,13 @@ discard block |
||
181 | 181 | ); |
182 | 182 | //make sure we've included the base migration script, because we may need the EE_DMS_Unknown_1_0_0 class |
183 | 183 | //to be defined, because right now it doesn't get autoloaded on its own |
184 | - EE_Registry::instance()->load_core( 'Data_Migration_Class_Base', array(), TRUE ); |
|
185 | - EE_Registry::instance()->load_core( 'Data_Migration_Script_Base', array(), TRUE ); |
|
186 | - EE_Registry::instance()->load_core( 'DMS_Unknown_1_0_0', array(), TRUE ); |
|
187 | - EE_Registry::instance()->load_core( 'Data_Migration_Script_Stage', array(), TRUE ); |
|
188 | - EE_Registry::instance()->load_core( 'Data_Migration_Script_Stage_Table', array(), TRUE ); |
|
189 | - $this->_table_manager = EE_Registry::instance()->create( 'TableManager', array(), true ); |
|
190 | - $this->_table_analysis = EE_Registry::instance()->create( 'TableAnalysis', array(), true ); |
|
184 | + EE_Registry::instance()->load_core('Data_Migration_Class_Base', array(), TRUE); |
|
185 | + EE_Registry::instance()->load_core('Data_Migration_Script_Base', array(), TRUE); |
|
186 | + EE_Registry::instance()->load_core('DMS_Unknown_1_0_0', array(), TRUE); |
|
187 | + EE_Registry::instance()->load_core('Data_Migration_Script_Stage', array(), TRUE); |
|
188 | + EE_Registry::instance()->load_core('Data_Migration_Script_Stage_Table', array(), TRUE); |
|
189 | + $this->_table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
190 | + $this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | |
@@ -200,21 +200,21 @@ discard block |
||
200 | 200 | * @param string $option_name (see EE_Data_Migration_Manage::_save_migrations_ran() where the option name is set) |
201 | 201 | * @return array where the first item is the plugin slug (eg 'Core','Calendar',etc) and the 2nd is the version of that plugin (eg '4.1.0') |
202 | 202 | */ |
203 | - private function _get_plugin_slug_and_version_string_from_dms_option_name($option_name){ |
|
203 | + private function _get_plugin_slug_and_version_string_from_dms_option_name($option_name) { |
|
204 | 204 | $plugin_slug_and_version_string = str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_name); |
205 | 205 | //check if $plugin_slug_and_version_string is like '4.1.0' (4.1-style) or 'Core.4.1.0' (4.2-style) |
206 | - $parts = explode(".",$plugin_slug_and_version_string); |
|
206 | + $parts = explode(".", $plugin_slug_and_version_string); |
|
207 | 207 | |
208 | - if(count($parts) == 4){ |
|
208 | + if (count($parts) == 4) { |
|
209 | 209 | //it's 4.2-style.eg Core.4.1.0 |
210 | - $plugin_slug = $parts[0];//eg Core |
|
210 | + $plugin_slug = $parts[0]; //eg Core |
|
211 | 211 | $version_string = $parts[1].".".$parts[2].".".$parts[3]; //eg 4.1.0 |
212 | - }else{ |
|
212 | + } else { |
|
213 | 213 | //it's 4.1-style: eg 4.1.0 |
214 | 214 | $plugin_slug = 'Core'; |
215 | - $version_string = $plugin_slug_and_version_string;//eg 4.1.0 |
|
215 | + $version_string = $plugin_slug_and_version_string; //eg 4.1.0 |
|
216 | 216 | } |
217 | - return array($plugin_slug,$version_string); |
|
217 | + return array($plugin_slug, $version_string); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -225,21 +225,21 @@ discard block |
||
225 | 225 | * @return EE_Data_Migration_Script_Base |
226 | 226 | * @throws EE_Error |
227 | 227 | */ |
228 | - private function _get_dms_class_from_wp_option($dms_option_name,$dms_option_value){ |
|
228 | + private function _get_dms_class_from_wp_option($dms_option_name, $dms_option_value) { |
|
229 | 229 | $data_migration_data = maybe_unserialize($dms_option_value); |
230 | - if(isset($data_migration_data['class']) && class_exists($data_migration_data['class'])){ |
|
230 | + if (isset($data_migration_data['class']) && class_exists($data_migration_data['class'])) { |
|
231 | 231 | $class = new $data_migration_data['class']; |
232 | - if($class instanceof EE_Data_Migration_Script_Base){ |
|
232 | + if ($class instanceof EE_Data_Migration_Script_Base) { |
|
233 | 233 | $class->instantiate_from_array_of_properties($data_migration_data); |
234 | 234 | return $class; |
235 | - }else{ |
|
235 | + } else { |
|
236 | 236 | //huh, so its an object but not a data migration script?? that shouldn't happen |
237 | 237 | //just leave it as an array (which will probably just get ignored) |
238 | - throw new EE_Error(sprintf(__("Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists", 'event_espresso'),$data_migration_data['class'])); |
|
238 | + throw new EE_Error(sprintf(__("Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists", 'event_espresso'), $data_migration_data['class'])); |
|
239 | 239 | } |
240 | - }else{ |
|
240 | + } else { |
|
241 | 241 | //so the data doesn't specify a class. So it must either be a legacy array of info or some array (which we'll probably just ignore), or a class that no longer exists |
242 | - throw new EE_Error(sprintf(__("The wp option with key '%s' does not represent a DMS", 'event_espresso'),$dms_option_name)); |
|
242 | + throw new EE_Error(sprintf(__("The wp option with key '%s' does not represent a DMS", 'event_espresso'), $dms_option_name)); |
|
243 | 243 | } |
244 | 244 | } |
245 | 245 | /** |
@@ -247,34 +247,34 @@ discard block |
||
247 | 247 | * the last ran which hasn't finished yet |
248 | 248 | * @return array where each element should be an array of EE_Data_Migration_Script_Base (but also has a few legacy arrays in there - which should probably be ignored) |
249 | 249 | */ |
250 | - public function get_data_migrations_ran(){ |
|
251 | - if( ! $this->_data_migrations_ran ){ |
|
250 | + public function get_data_migrations_ran() { |
|
251 | + if ( ! $this->_data_migrations_ran) { |
|
252 | 252 | //setup autoloaders for each of the scripts in there |
253 | 253 | $this->get_all_data_migration_scripts_available(); |
254 | - $data_migrations_options = $this->get_all_migration_script_options();//get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
254 | + $data_migrations_options = $this->get_all_migration_script_options(); //get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
255 | 255 | |
256 | 256 | $data_migrations_ran = array(); |
257 | 257 | //convert into data migration script classes where possible |
258 | - foreach($data_migrations_options as $data_migration_option){ |
|
259 | - list($plugin_slug,$version_string) = $this->_get_plugin_slug_and_version_string_from_dms_option_name($data_migration_option['option_name']); |
|
258 | + foreach ($data_migrations_options as $data_migration_option) { |
|
259 | + list($plugin_slug, $version_string) = $this->_get_plugin_slug_and_version_string_from_dms_option_name($data_migration_option['option_name']); |
|
260 | 260 | |
261 | - try{ |
|
262 | - $class = $this->_get_dms_class_from_wp_option($data_migration_option['option_name'],$data_migration_option['option_value']); |
|
261 | + try { |
|
262 | + $class = $this->_get_dms_class_from_wp_option($data_migration_option['option_name'], $data_migration_option['option_value']); |
|
263 | 263 | $data_migrations_ran[$plugin_slug][$version_string] = $class; |
264 | 264 | //ok so far THIS is the 'last-ran-script'... unless we find another on next iteration |
265 | 265 | $this->_last_ran_script = $class; |
266 | - if( ! $class->is_completed()){ |
|
266 | + if ( ! $class->is_completed()) { |
|
267 | 267 | //sometimes we also like to know which was the last incomplete script (or if there are any at all) |
268 | 268 | $this->_last_ran_incomplete_script = $class; |
269 | 269 | } |
270 | - }catch(EE_Error $e){ |
|
270 | + } catch (EE_Error $e) { |
|
271 | 271 | //ok so its not a DMS. We'll just keep it, although other code will need to expect non-DMSs |
272 | 272 | $data_migrations_ran[$plugin_slug][$version_string] = maybe_unserialize($data_migration_option['option_value']); |
273 | 273 | } |
274 | 274 | } |
275 | 275 | //so here the array of $data_migrations_ran is actually a mix of classes and a few legacy arrays |
276 | 276 | $this->_data_migrations_ran = $data_migrations_ran; |
277 | - if ( ! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran) ){ |
|
277 | + if ( ! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran)) { |
|
278 | 278 | $this->_data_migrations_ran = array(); |
279 | 279 | } |
280 | 280 | } |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | * @param $new_table |
292 | 292 | * @return mixed string or int |
293 | 293 | */ |
294 | - public function get_mapping_new_pk( $script_name, $old_table, $old_pk, $new_table){ |
|
294 | + public function get_mapping_new_pk($script_name, $old_table, $old_pk, $new_table) { |
|
295 | 295 | $script = EE_Registry::instance()->load_dms($script_name); |
296 | 296 | $mapping = $script->get_mapping_new_pk($old_table, $old_pk, $new_table); |
297 | 297 | return $mapping; |
@@ -302,9 +302,9 @@ discard block |
||
302 | 302 | * option returned in this array is the most-recently ran DMS option |
303 | 303 | * @return array |
304 | 304 | */ |
305 | - public function get_all_migration_script_options(){ |
|
305 | + public function get_all_migration_script_options() { |
|
306 | 306 | global $wpdb; |
307 | - return $wpdb->get_results("SELECT * FROM {$wpdb->options} WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id ASC",ARRAY_A); |
|
307 | + return $wpdb->get_results("SELECT * FROM {$wpdb->options} WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id ASC", ARRAY_A); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
@@ -312,8 +312,8 @@ discard block |
||
312 | 312 | * @return array where each value is the full folder path of a folder containing data migration scripts, WITH slashes at the end of the |
313 | 313 | * folder name. |
314 | 314 | */ |
315 | - public function get_data_migration_script_folders(){ |
|
316 | - return apply_filters( 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders',array(EE_CORE.'data_migration_scripts') ); |
|
315 | + public function get_data_migration_script_folders() { |
|
316 | + return apply_filters('FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', array(EE_CORE.'data_migration_scripts')); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -325,11 +325,11 @@ discard block |
||
325 | 325 | * } |
326 | 326 | * @throws EE_Error |
327 | 327 | */ |
328 | - public function script_migrates_to_version($migration_script_name){ |
|
328 | + public function script_migrates_to_version($migration_script_name) { |
|
329 | 329 | $dms_info = $this->parse_dms_classname($migration_script_name); |
330 | 330 | return array( |
331 | - 'slug'=> $dms_info[ 'slug' ], |
|
332 | - 'version'=> $dms_info[ 'major_version' ] . "." . $dms_info[ 'minor_version' ] . "." . $dms_info[ 'micro_version' ] ); |
|
331 | + 'slug'=> $dms_info['slug'], |
|
332 | + 'version'=> $dms_info['major_version'].".".$dms_info['minor_version'].".".$dms_info['micro_version'] ); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
@@ -338,13 +338,13 @@ discard block |
||
338 | 338 | * @return array with keys 'slug','major_version','minor_version', and 'micro_version' (the last 3 are ints) |
339 | 339 | * @throws EE_Error |
340 | 340 | */ |
341 | - public function parse_dms_classname($classname){ |
|
341 | + public function parse_dms_classname($classname) { |
|
342 | 342 | $matches = array(); |
343 | - preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~',$classname,$matches); |
|
344 | - if( ! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))){ |
|
345 | - throw new EE_Error(sprintf(__("%s is not a valid Data Migration Script. The classname should be like EE_DMS_w_x_y_z, where w is either 'Core' or the slug of an addon and x, y and z are numbers, ", "event_espresso"),$classname)); |
|
343 | + preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~', $classname, $matches); |
|
344 | + if ( ! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))) { |
|
345 | + throw new EE_Error(sprintf(__("%s is not a valid Data Migration Script. The classname should be like EE_DMS_w_x_y_z, where w is either 'Core' or the slug of an addon and x, y and z are numbers, ", "event_espresso"), $classname)); |
|
346 | 346 | } |
347 | - return array('slug'=>$matches[1],'major_version'=>intval($matches[2]),'minor_version'=>intval($matches[3]),'micro_version'=>intval($matches[4])); |
|
347 | + return array('slug'=>$matches[1], 'major_version'=>intval($matches[2]), 'minor_version'=>intval($matches[3]), 'micro_version'=>intval($matches[4])); |
|
348 | 348 | } |
349 | 349 | /** |
350 | 350 | * Ensures that the option indicating the current DB version is set. This should only be |
@@ -353,33 +353,33 @@ discard block |
||
353 | 353 | * to 4.1.x. |
354 | 354 | * @return string of current db state |
355 | 355 | */ |
356 | - public function ensure_current_database_state_is_set(){ |
|
357 | - $espresso_db_core_updates = get_option( 'espresso_db_update', array() ); |
|
356 | + public function ensure_current_database_state_is_set() { |
|
357 | + $espresso_db_core_updates = get_option('espresso_db_update', array()); |
|
358 | 358 | $db_state = get_option(EE_Data_Migration_Manager::current_database_state); |
359 | - if( ! $db_state ){ |
|
359 | + if ( ! $db_state) { |
|
360 | 360 | //mark the DB as being in the state as the last version in there. |
361 | 361 | //this is done to trigger maintenance mode and do data migration scripts |
362 | 362 | //if the admin installed this version of EE over 3.1.x or 4.0.x |
363 | 363 | //otherwise, the normal maintenance mode code is fine |
364 | 364 | $previous_versions_installed = array_keys($espresso_db_core_updates); |
365 | 365 | $previous_version_installed = end($previous_versions_installed); |
366 | - if(version_compare('4.1.0', $previous_version_installed)){ |
|
366 | + if (version_compare('4.1.0', $previous_version_installed)) { |
|
367 | 367 | //last installed version was less than 4.1 |
368 | 368 | //so we want the data migrations to happen. SO, we're going to say the DB is at that state |
369 | 369 | // echo "4.1.0 is greater than $previous_version_installed! update the option"; |
370 | 370 | $db_state = array('Core'=>$previous_version_installed); |
371 | - }else{ |
|
371 | + } else { |
|
372 | 372 | // echo "4.1.0 is SMALLER than $previous_version_installed"; |
373 | 373 | $db_state = array('Core'=>EVENT_ESPRESSO_VERSION); |
374 | 374 | } |
375 | - update_option(EE_Data_Migration_Manager::current_database_state,$db_state); |
|
375 | + update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
376 | 376 | } |
377 | 377 | //in 4.1, $db_state would have only been a simple string like '4.1.0', |
378 | 378 | //but in 4.2+ it should be an array with at least key 'Core' and the value of that plugin's |
379 | 379 | //db, and possibly other keys for other addons like 'Calendar','Permissions',etc |
380 | - if( ! is_array($db_state)){ |
|
380 | + if ( ! is_array($db_state)) { |
|
381 | 381 | $db_state = array('Core'=>$db_state); |
382 | - update_option(EE_Data_Migration_Manager::current_database_state,$db_state); |
|
382 | + update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
383 | 383 | } |
384 | 384 | return $db_state; |
385 | 385 | } |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | * or they don't apply), returns an empty array |
391 | 391 | * @return EE_Data_Migration_Script_Base[] |
392 | 392 | */ |
393 | - public function check_for_applicable_data_migration_scripts(){ |
|
393 | + public function check_for_applicable_data_migration_scripts() { |
|
394 | 394 | //get the option describing what options have already run |
395 | 395 | $scripts_ran = $this->get_data_migrations_ran(); |
396 | 396 | //$scripts_ran = array('4.1.0.core'=>array('monkey'=>null)); |
@@ -403,62 +403,62 @@ discard block |
||
403 | 403 | $iteration = 0; |
404 | 404 | $next_database_state_to_consider = $current_database_state; |
405 | 405 | $theoretical_database_state = NULL; |
406 | - do{ |
|
406 | + do { |
|
407 | 407 | //the next state after the currently-considered one will start off looking the same as the current, but we may make additions... |
408 | 408 | $theoretical_database_state = $next_database_state_to_consider; |
409 | 409 | //the next db state to consider is "what would the DB be like had we run all the scripts we found that applied last time?) |
410 | - foreach($script_class_and_filepaths_available as $classname => $filepath){ |
|
410 | + foreach ($script_class_and_filepaths_available as $classname => $filepath) { |
|
411 | 411 | |
412 | 412 | $migrates_to_version = $this->script_migrates_to_version($classname); |
413 | - $script_converts_plugin_slug = $migrates_to_version[ 'slug' ]; |
|
414 | - $script_converts_to_version = $migrates_to_version[ 'version' ]; |
|
413 | + $script_converts_plugin_slug = $migrates_to_version['slug']; |
|
414 | + $script_converts_to_version = $migrates_to_version['version']; |
|
415 | 415 | //check if this version script is DONE or not; or if it's never been ran |
416 | - if( ! $scripts_ran || |
|
416 | + if ( ! $scripts_ran || |
|
417 | 417 | ! isset($scripts_ran[$script_converts_plugin_slug]) || |
418 | - ! isset($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version])){ |
|
418 | + ! isset($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version])) { |
|
419 | 419 | //we haven't ran this conversion script before |
420 | 420 | //now check if it applies... note that we've added an autoloader for it on get_all_data_migration_scripts_available |
421 | - $script = new $classname( $this->_get_table_manager(), $this->_get_table_analysis() ); |
|
421 | + $script = new $classname($this->_get_table_manager(), $this->_get_table_analysis()); |
|
422 | 422 | /* @var $script EE_Data_Migration_Script_Base */ |
423 | 423 | $can_migrate = $script->can_migrate_from_version($theoretical_database_state); |
424 | - if($can_migrate){ |
|
424 | + if ($can_migrate) { |
|
425 | 425 | $script_classes_that_should_run_per_iteration[$iteration][$script->priority()][] = $script; |
426 | 426 | $migrates_to_version = $script->migrates_to_version(); |
427 | - $next_database_state_to_consider[ $migrates_to_version[ 'slug' ] ] = $migrates_to_version[ 'version' ]; |
|
427 | + $next_database_state_to_consider[$migrates_to_version['slug']] = $migrates_to_version['version']; |
|
428 | 428 | unset($script_class_and_filepaths_available[$classname]); |
429 | 429 | } |
430 | - } elseif($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version] instanceof EE_Data_Migration_Script_Base){ |
|
430 | + } elseif ($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version] instanceof EE_Data_Migration_Script_Base) { |
|
431 | 431 | //this script has been ran, or at least started |
432 | 432 | $script = $scripts_ran[$script_converts_plugin_slug][$script_converts_to_version]; |
433 | - if( $script->get_status() != self::status_completed){ |
|
433 | + if ($script->get_status() != self::status_completed) { |
|
434 | 434 | //this script is already underway... keep going with it |
435 | 435 | $script_classes_that_should_run_per_iteration[$iteration][$script->priority()][] = $script; |
436 | 436 | $migrates_to_version = $script->migrates_to_version(); |
437 | - $next_database_state_to_consider[ $migrates_to_version[ 'slug' ] ] = $migrates_to_version[ 'version' ]; |
|
437 | + $next_database_state_to_consider[$migrates_to_version['slug']] = $migrates_to_version['version']; |
|
438 | 438 | unset($script_class_and_filepaths_available[$classname]); |
439 | - }else{ |
|
439 | + } else { |
|
440 | 440 | //it must have a status that indicates it has finished, so we don't want to try and run it again |
441 | 441 | } |
442 | - }else{ |
|
442 | + } else { |
|
443 | 443 | //it exists but it's not a proper data migration script |
444 | 444 | //maybe the script got renamed? or was simply removed from EE? |
445 | 445 | //either way, its certainly not runnable! |
446 | 446 | } |
447 | 447 | } |
448 | 448 | $iteration++; |
449 | - }while( $next_database_state_to_consider != $theoretical_database_state && $iteration<6); |
|
449 | + }while ($next_database_state_to_consider != $theoretical_database_state && $iteration < 6); |
|
450 | 450 | //ok we have all the scripts that should run, now let's make them into flat array |
451 | 451 | $scripts_that_should_run = array(); |
452 | - foreach($script_classes_that_should_run_per_iteration as $scripts_at_priority){ |
|
452 | + foreach ($script_classes_that_should_run_per_iteration as $scripts_at_priority) { |
|
453 | 453 | ksort($scripts_at_priority); |
454 | - foreach($scripts_at_priority as $scripts){ |
|
455 | - foreach($scripts as $script){ |
|
454 | + foreach ($scripts_at_priority as $scripts) { |
|
455 | + foreach ($scripts as $script) { |
|
456 | 456 | $scripts_that_should_run[get_class($script)] = $script; |
457 | 457 | } |
458 | 458 | } |
459 | 459 | } |
460 | 460 | |
461 | - do_action( 'AHEE__EE_Data_Migration_Manager__check_for_applicable_data_migration_scripts__scripts_that_should_run', $scripts_that_should_run ); |
|
461 | + do_action('AHEE__EE_Data_Migration_Manager__check_for_applicable_data_migration_scripts__scripts_that_should_run', $scripts_that_should_run); |
|
462 | 462 | return $scripts_that_should_run; |
463 | 463 | } |
464 | 464 | |
@@ -472,14 +472,14 @@ discard block |
||
472 | 472 | * @param bool $include_completed_scripts |
473 | 473 | * @return EE_Data_Migration_Script_Base |
474 | 474 | */ |
475 | - public function get_last_ran_script($include_completed_scripts = false){ |
|
475 | + public function get_last_ran_script($include_completed_scripts = false) { |
|
476 | 476 | //make sure we've setup the class properties _last_ran_script and _last_ran_incomplete_script |
477 | - if( ! $this->_data_migrations_ran){ |
|
477 | + if ( ! $this->_data_migrations_ran) { |
|
478 | 478 | $this->get_data_migrations_ran(); |
479 | 479 | } |
480 | - if($include_completed_scripts){ |
|
480 | + if ($include_completed_scripts) { |
|
481 | 481 | return $this->_last_ran_script; |
482 | - }else{ |
|
482 | + } else { |
|
483 | 483 | return $this->_last_ran_incomplete_script; |
484 | 484 | } |
485 | 485 | } |
@@ -502,19 +502,19 @@ discard block |
||
502 | 502 | * @type string $message string describing what was done during this step |
503 | 503 | * } |
504 | 504 | */ |
505 | - public function migration_step( $step_size = 0 ){ |
|
505 | + public function migration_step($step_size = 0) { |
|
506 | 506 | |
507 | 507 | //bandaid fix for issue https://events.codebasehq.com/projects/event-espresso/tickets/7535 |
508 | - if ( class_exists( 'EE_CPT_Strategy' ) ) { |
|
509 | - remove_action( 'pre_get_posts', array( EE_CPT_Strategy::instance(), 'pre_get_posts' ), 5 ); |
|
508 | + if (class_exists('EE_CPT_Strategy')) { |
|
509 | + remove_action('pre_get_posts', array(EE_CPT_Strategy::instance(), 'pre_get_posts'), 5); |
|
510 | 510 | } |
511 | 511 | |
512 | - try{ |
|
512 | + try { |
|
513 | 513 | $currently_executing_script = $this->get_last_ran_script(); |
514 | - if( ! $currently_executing_script){ |
|
514 | + if ( ! $currently_executing_script) { |
|
515 | 515 | //Find the next script that needs to execute |
516 | 516 | $scripts = $this->check_for_applicable_data_migration_scripts(); |
517 | - if( ! $scripts ){ |
|
517 | + if ( ! $scripts) { |
|
518 | 518 | //huh, no more scripts to run... apparently we're done! |
519 | 519 | //but dont forget to make sure initial data is there |
520 | 520 | //we should be good to allow them to exit maintenance mode now |
@@ -535,18 +535,18 @@ discard block |
||
535 | 535 | //and add to the array/wp option showing the scripts ran |
536 | 536 | // $this->_data_migrations_ran[$this->script_migrates_to_version(get_class($currently_executing_script))] = $currently_executing_script; |
537 | 537 | $migrates_to = $this->script_migrates_to_version(get_class($currently_executing_script)); |
538 | - $plugin_slug = $migrates_to[ 'slug' ]; |
|
539 | - $version = $migrates_to[ 'version' ]; |
|
538 | + $plugin_slug = $migrates_to['slug']; |
|
539 | + $version = $migrates_to['version']; |
|
540 | 540 | $this->_data_migrations_ran[$plugin_slug][$version] = $currently_executing_script; |
541 | 541 | } |
542 | 542 | $current_script_name = get_class($currently_executing_script); |
543 | - }catch(Exception $e){ |
|
543 | + } catch (Exception $e) { |
|
544 | 544 | //an exception occurred while trying to get migration scripts |
545 | 545 | |
546 | - $message = sprintf( __("Error Message: %sStack Trace:%s", "event_espresso"), $e->getMessage() . '<br>', $e->getTraceAsString() ); |
|
546 | + $message = sprintf(__("Error Message: %sStack Trace:%s", "event_espresso"), $e->getMessage().'<br>', $e->getTraceAsString()); |
|
547 | 547 | //record it on the array of data migration scripts ran. This will be overwritten next time we try and try to run data migrations |
548 | 548 | //but that's ok-- it's just an FYI to support that we couldn't even run any data migrations |
549 | - $this->add_error_to_migrations_ran(sprintf(__("Could not run data migrations because: %s", "event_espresso"),$message)); |
|
549 | + $this->add_error_to_migrations_ran(sprintf(__("Could not run data migrations because: %s", "event_espresso"), $message)); |
|
550 | 550 | return array( |
551 | 551 | 'records_to_migrate'=>1, |
552 | 552 | 'records_migrated'=>0, |
@@ -556,16 +556,16 @@ discard block |
||
556 | 556 | ); |
557 | 557 | } |
558 | 558 | //ok so we definitely have a data migration script |
559 | - try{ |
|
559 | + try { |
|
560 | 560 | //how big of a bite do we want to take? Allow users to easily override via their wp-config |
561 | - if( ! absint( $step_size ) > 0 ){ |
|
562 | - $step_size = defined( 'EE_MIGRATION_STEP_SIZE' ) && absint( EE_MIGRATION_STEP_SIZE ) ? EE_MIGRATION_STEP_SIZE : EE_Data_Migration_Manager::step_size; |
|
561 | + if ( ! absint($step_size) > 0) { |
|
562 | + $step_size = defined('EE_MIGRATION_STEP_SIZE') && absint(EE_MIGRATION_STEP_SIZE) ? EE_MIGRATION_STEP_SIZE : EE_Data_Migration_Manager::step_size; |
|
563 | 563 | } |
564 | 564 | //do what we came to do! |
565 | 565 | $currently_executing_script->migration_step($step_size); |
566 | 566 | //can we wrap it up and verify default data? |
567 | 567 | $init_dbs = false; |
568 | - switch($currently_executing_script->get_status()){ |
|
568 | + switch ($currently_executing_script->get_status()) { |
|
569 | 569 | case EE_Data_Migration_Manager::status_continue: |
570 | 570 | $response_array = array( |
571 | 571 | 'records_to_migrate'=>$currently_executing_script->count_records_to_migrate(), |
@@ -577,16 +577,16 @@ discard block |
||
577 | 577 | case EE_Data_Migration_Manager::status_completed: |
578 | 578 | //ok so THAT script has completed |
579 | 579 | $this->update_current_database_state_to($this->script_migrates_to_version($current_script_name)); |
580 | - $response_array = array( |
|
580 | + $response_array = array( |
|
581 | 581 | 'records_to_migrate'=>$currently_executing_script->count_records_to_migrate(), |
582 | 582 | 'records_migrated'=>$currently_executing_script->count_records_migrated(), |
583 | 583 | 'status'=> EE_Data_Migration_Manager::status_completed, |
584 | 584 | 'message'=>$currently_executing_script->get_feedback_message(), |
585 | - 'script'=> sprintf(__("%s Completed",'event_espresso'),$currently_executing_script->pretty_name()) |
|
585 | + 'script'=> sprintf(__("%s Completed", 'event_espresso'), $currently_executing_script->pretty_name()) |
|
586 | 586 | ); |
587 | 587 | //check if there are any more after this one. |
588 | 588 | $scripts_remaining = $this->check_for_applicable_data_migration_scripts(); |
589 | - if( ! $scripts_remaining ){ |
|
589 | + if ( ! $scripts_remaining) { |
|
590 | 590 | //we should be good to allow them to exit maintenance mode now |
591 | 591 | EE_Maintenance_Mode::instance()->set_maintenance_level(intval(EE_Maintenance_Mode::level_0_not_in_maintenance)); |
592 | 592 | ////huh, no more scripts to run... apparently we're done! |
@@ -600,39 +600,39 @@ discard block |
||
600 | 600 | 'records_to_migrate'=>$currently_executing_script->count_records_to_migrate(), |
601 | 601 | 'records_migrated'=>$currently_executing_script->count_records_migrated(), |
602 | 602 | 'status'=> $currently_executing_script->get_status(), |
603 | - 'message'=> sprintf(__("Minor errors occurred during %s: %s", "event_espresso"), $currently_executing_script->pretty_name(), implode(", ",$currently_executing_script->get_errors())), |
|
603 | + 'message'=> sprintf(__("Minor errors occurred during %s: %s", "event_espresso"), $currently_executing_script->pretty_name(), implode(", ", $currently_executing_script->get_errors())), |
|
604 | 604 | 'script'=>$currently_executing_script->pretty_name() |
605 | 605 | ); |
606 | 606 | break; |
607 | 607 | } |
608 | - }catch(Exception $e){ |
|
608 | + } catch (Exception $e) { |
|
609 | 609 | //ok so some exception was thrown which killed the data migration script |
610 | 610 | //double-check we have a real script |
611 | - if($currently_executing_script instanceof EE_Data_Migration_Script_Base){ |
|
611 | + if ($currently_executing_script instanceof EE_Data_Migration_Script_Base) { |
|
612 | 612 | $script_name = $currently_executing_script->pretty_name(); |
613 | 613 | $currently_executing_script->set_broken(); |
614 | 614 | $currently_executing_script->add_error($e->getMessage()); |
615 | - }else{ |
|
615 | + } else { |
|
616 | 616 | $script_name = __("Error getting Migration Script", "event_espresso"); |
617 | 617 | } |
618 | 618 | $response_array = array( |
619 | 619 | 'records_to_migrate'=>1, |
620 | 620 | 'records_migrated'=>0, |
621 | 621 | 'status'=>self::status_fatal_error, |
622 | - 'message'=> sprintf(__("A fatal error occurred during the migration: %s", "event_espresso"),$e->getMessage()), |
|
622 | + 'message'=> sprintf(__("A fatal error occurred during the migration: %s", "event_espresso"), $e->getMessage()), |
|
623 | 623 | 'script'=>$script_name |
624 | 624 | ); |
625 | 625 | } |
626 | 626 | $successful_save = $this->_save_migrations_ran(); |
627 | - if($successful_save !== TRUE){ |
|
627 | + if ($successful_save !== TRUE) { |
|
628 | 628 | //ok so the current wp option didn't save. that's tricky, because we'd like to update it |
629 | 629 | //and mark it as having a fatal error, but remember- WE CAN'T SAVE THIS WP OPTION! |
630 | 630 | //however, if we throw an exception, and return that, then the next request |
631 | 631 | //won't have as much info in it, and it may be able to save |
632 | - throw new EE_Error(sprintf(__("The error '%s' occurred updating the status of the migration. This is a FATAL ERROR, but the error is preventing the system from remembering that. Please contact event espresso support.", "event_espresso"),$successful_save)); |
|
632 | + throw new EE_Error(sprintf(__("The error '%s' occurred updating the status of the migration. This is a FATAL ERROR, but the error is preventing the system from remembering that. Please contact event espresso support.", "event_espresso"), $successful_save)); |
|
633 | 633 | } |
634 | 634 | //if we're all done, initialize EE plugins' default data etc. |
635 | - if( $init_dbs ) { |
|
635 | + if ($init_dbs) { |
|
636 | 636 | $this->initialize_db_for_enqueued_ee_plugins(); |
637 | 637 | } |
638 | 638 | return $response_array; |
@@ -650,23 +650,23 @@ discard block |
||
650 | 650 | * 'message'=>a string, containing any message you want to show to the user. We may decide to split this up into errors, notifications, and successes |
651 | 651 | * 'script'=>a pretty name of the script currently running |
652 | 652 | */ |
653 | - public function response_to_migration_ajax_request(){ |
|
653 | + public function response_to_migration_ajax_request() { |
|
654 | 654 | // //start output buffer just to make sure we don't mess up the json |
655 | 655 | ob_start(); |
656 | - try{ |
|
656 | + try { |
|
657 | 657 | $response = $this->migration_step(); |
658 | - }catch(Exception $e){ |
|
658 | + } catch (Exception $e) { |
|
659 | 659 | $response = array( |
660 | 660 | 'records_to_migrate'=>0, |
661 | 661 | 'records_migrated'=>0, |
662 | 662 | 'status'=> EE_Data_Migration_Manager::status_fatal_error, |
663 | - 'message'=> sprintf(__("Unknown fatal error occurred: %s", "event_espresso"),$e->getMessage()), |
|
663 | + 'message'=> sprintf(__("Unknown fatal error occurred: %s", "event_espresso"), $e->getMessage()), |
|
664 | 664 | 'script'=>'Unknown'); |
665 | 665 | $this->add_error_to_migrations_ran($e->getMessage()."; Stack trace:".$e->getTraceAsString()); |
666 | 666 | } |
667 | 667 | $warnings_etc = @ob_get_contents(); |
668 | 668 | ob_end_clean(); |
669 | - $response['message'] .=$warnings_etc; |
|
669 | + $response['message'] .= $warnings_etc; |
|
670 | 670 | return $response; |
671 | 671 | } |
672 | 672 | |
@@ -679,14 +679,14 @@ discard block |
||
679 | 679 | * } |
680 | 680 | * @return void |
681 | 681 | */ |
682 | - public function update_current_database_state_to($slug_and_version = null){ |
|
683 | - if( ! $slug_and_version ){ |
|
682 | + public function update_current_database_state_to($slug_and_version = null) { |
|
683 | + if ( ! $slug_and_version) { |
|
684 | 684 | //no version was provided, assume it should be at the current code version |
685 | 685 | $slug_and_version = array('slug' => 'Core', 'version' => espresso_version()); |
686 | 686 | } |
687 | 687 | $current_database_state = get_option(self::current_database_state); |
688 | - $current_database_state[ $slug_and_version[ 'slug' ] ]=$slug_and_version[ 'version' ]; |
|
689 | - update_option(self::current_database_state,$current_database_state); |
|
688 | + $current_database_state[$slug_and_version['slug']] = $slug_and_version['version']; |
|
689 | + update_option(self::current_database_state, $current_database_state); |
|
690 | 690 | } |
691 | 691 | |
692 | 692 | /** |
@@ -697,20 +697,20 @@ discard block |
||
697 | 697 | * } |
698 | 698 | * @return boolean |
699 | 699 | */ |
700 | - public function database_needs_updating_to( $slug_and_version ) { |
|
700 | + public function database_needs_updating_to($slug_and_version) { |
|
701 | 701 | |
702 | - $slug = $slug_and_version[ 'slug' ]; |
|
703 | - $version = $slug_and_version[ 'version' ]; |
|
702 | + $slug = $slug_and_version['slug']; |
|
703 | + $version = $slug_and_version['version']; |
|
704 | 704 | $current_database_state = get_option(self::current_database_state); |
705 | - if( ! isset( $current_database_state[ $slug ] ) ) { |
|
705 | + if ( ! isset($current_database_state[$slug])) { |
|
706 | 706 | return true; |
707 | - }else{ |
|
707 | + } else { |
|
708 | 708 | //just compare the first 3 parts of version string, eg "4.7.1", not "4.7.1.dev.032" because DBs shouldn't change on nano version changes |
709 | - $version_parts_current_db_state = array_slice( explode('.', $current_database_state[ $slug ] ), 0, 3); |
|
710 | - $version_parts_of_provided_db_state = array_slice( explode( '.', $version ), 0, 3 ); |
|
709 | + $version_parts_current_db_state = array_slice(explode('.', $current_database_state[$slug]), 0, 3); |
|
710 | + $version_parts_of_provided_db_state = array_slice(explode('.', $version), 0, 3); |
|
711 | 711 | $needs_updating = false; |
712 | - foreach($version_parts_current_db_state as $offset => $version_part_in_current_db_state ) { |
|
713 | - if( $version_part_in_current_db_state < $version_parts_of_provided_db_state[ $offset ] ) { |
|
712 | + foreach ($version_parts_current_db_state as $offset => $version_part_in_current_db_state) { |
|
713 | + if ($version_part_in_current_db_state < $version_parts_of_provided_db_state[$offset]) { |
|
714 | 714 | $needs_updating = true; |
715 | 715 | break; |
716 | 716 | } |
@@ -728,33 +728,33 @@ discard block |
||
728 | 728 | * @return array keys are expected classnames, values are their filepaths |
729 | 729 | * @throws \EE_Error |
730 | 730 | */ |
731 | - public function get_all_data_migration_scripts_available(){ |
|
732 | - if( ! $this->_data_migration_class_to_filepath_map){ |
|
731 | + public function get_all_data_migration_scripts_available() { |
|
732 | + if ( ! $this->_data_migration_class_to_filepath_map) { |
|
733 | 733 | $this->_data_migration_class_to_filepath_map = array(); |
734 | - foreach($this->get_data_migration_script_folders() as $folder_path){ |
|
734 | + foreach ($this->get_data_migration_script_folders() as $folder_path) { |
|
735 | 735 | $folder_path = EEH_File::end_with_directory_separator($folder_path); |
736 | - $files = glob( $folder_path. '*.dms.php' ); |
|
736 | + $files = glob($folder_path.'*.dms.php'); |
|
737 | 737 | |
738 | - if ( empty( $files ) ) { |
|
738 | + if (empty($files)) { |
|
739 | 739 | continue; |
740 | 740 | } |
741 | 741 | |
742 | - foreach($files as $file){ |
|
743 | - $pos_of_last_slash = strrpos($file,DS); |
|
742 | + foreach ($files as $file) { |
|
743 | + $pos_of_last_slash = strrpos($file, DS); |
|
744 | 744 | $classname = str_replace('.dms.php', '', substr($file, $pos_of_last_slash + 1)); |
745 | - $migrates_to = $this->script_migrates_to_version( $classname ); |
|
746 | - $slug = $migrates_to[ 'slug' ]; |
|
745 | + $migrates_to = $this->script_migrates_to_version($classname); |
|
746 | + $slug = $migrates_to['slug']; |
|
747 | 747 | //check that the slug as contained in the DMS is associated with |
748 | 748 | //the slug of an addon or core |
749 | - if( $slug !== 'Core' ){ |
|
750 | - if( ! EE_Registry::instance()->get_addon_by_name( $slug ) ) { |
|
749 | + if ($slug !== 'Core') { |
|
750 | + if ( ! EE_Registry::instance()->get_addon_by_name($slug)) { |
|
751 | 751 | EE_Error::doing_it_wrong( |
752 | 752 | __FUNCTION__, |
753 | 753 | sprintf( |
754 | - __( 'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', 'event_espresso' ), |
|
754 | + __('The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', 'event_espresso'), |
|
755 | 755 | $classname, |
756 | 756 | $slug, |
757 | - implode(', ', array_keys( EE_Registry::instance()->get_addons_by_name() ) ) |
|
757 | + implode(', ', array_keys(EE_Registry::instance()->get_addons_by_name())) |
|
758 | 758 | ), |
759 | 759 | '4.3.0.alpha.019' |
760 | 760 | ); |
@@ -777,7 +777,7 @@ discard block |
||
777 | 777 | * from each addon, and check if they need updating, |
778 | 778 | * @return boolean |
779 | 779 | */ |
780 | - public function addons_need_updating(){ |
|
780 | + public function addons_need_updating() { |
|
781 | 781 | return false; |
782 | 782 | } |
783 | 783 | /** |
@@ -786,25 +786,25 @@ discard block |
||
786 | 786 | * @param string $error_message |
787 | 787 | * @throws EE_Error |
788 | 788 | */ |
789 | - public function add_error_to_migrations_ran($error_message){ |
|
789 | + public function add_error_to_migrations_ran($error_message) { |
|
790 | 790 | //get last-ran migration script |
791 | 791 | global $wpdb; |
792 | - $last_migration_script_option = $wpdb->get_row("SELECT * FROM $wpdb->options WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id DESC LIMIT 1",ARRAY_A); |
|
792 | + $last_migration_script_option = $wpdb->get_row("SELECT * FROM $wpdb->options WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id DESC LIMIT 1", ARRAY_A); |
|
793 | 793 | |
794 | 794 | $last_ran_migration_script_properties = isset($last_migration_script_option['option_value']) ? maybe_unserialize($last_migration_script_option['option_value']) : null; |
795 | 795 | //now, tread lightly because we're here because a FATAL non-catchable error |
796 | 796 | //was thrown last time when we were trying to run a data migration script |
797 | 797 | //so the fatal error could have happened while getting the migration script |
798 | 798 | //or doing running it... |
799 | - $versions_migrated_to = isset($last_migration_script_option['option_name']) ? str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix,"",$last_migration_script_option['option_name']) : null; |
|
799 | + $versions_migrated_to = isset($last_migration_script_option['option_name']) ? str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $last_migration_script_option['option_name']) : null; |
|
800 | 800 | |
801 | 801 | //check if it THINKS its a data migration script and especially if it's one that HASN'T finished yet |
802 | 802 | //because if it has finished, then it obviously couldn't be the cause of this error, right? (because its all done) |
803 | - if(isset($last_ran_migration_script_properties['class']) && isset($last_ran_migration_script_properties['_status']) && $last_ran_migration_script_properties['_status'] != self::status_completed){ |
|
803 | + if (isset($last_ran_migration_script_properties['class']) && isset($last_ran_migration_script_properties['_status']) && $last_ran_migration_script_properties['_status'] != self::status_completed) { |
|
804 | 804 | //ok then just add this error to its list of errors |
805 | 805 | $last_ran_migration_script_properties['_errors'][] = $error_message; |
806 | 806 | $last_ran_migration_script_properties['_status'] = self::status_fatal_error; |
807 | - }else{ |
|
807 | + } else { |
|
808 | 808 | //so we don't even know which script was last running |
809 | 809 | //use the data migration error stub, which is designed specifically for this type of thing |
810 | 810 | $general_migration_error = new EE_DMS_Unknown_1_0_0(); |
@@ -814,39 +814,39 @@ discard block |
||
814 | 814 | $versions_migrated_to = 'Unknown.1.0.0'; |
815 | 815 | //now just to make sure appears as last (in case the were previously a fatal error like this) |
816 | 816 | //delete the old one |
817 | - delete_option( self::data_migration_script_option_prefix . $versions_migrated_to ); |
|
817 | + delete_option(self::data_migration_script_option_prefix.$versions_migrated_to); |
|
818 | 818 | } |
819 | - update_option(self::data_migration_script_option_prefix.$versions_migrated_to,$last_ran_migration_script_properties); |
|
819 | + update_option(self::data_migration_script_option_prefix.$versions_migrated_to, $last_ran_migration_script_properties); |
|
820 | 820 | |
821 | 821 | } |
822 | 822 | /** |
823 | 823 | * saves what data migrations have ran to the database |
824 | 824 | * @return mixed TRUE if successfully saved migrations ran, string if an error occurred |
825 | 825 | */ |
826 | - protected function _save_migrations_ran(){ |
|
827 | - if($this->_data_migrations_ran == null){ |
|
826 | + protected function _save_migrations_ran() { |
|
827 | + if ($this->_data_migrations_ran == null) { |
|
828 | 828 | $this->get_data_migrations_ran(); |
829 | 829 | } |
830 | 830 | //now, we don't want to save actual classes to the DB because that's messy |
831 | 831 | $successful_updates = true; |
832 | - foreach($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin){ |
|
833 | - foreach($migrations_ran_for_plugin as $version_string => $array_or_migration_obj){ |
|
832 | + foreach ($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin) { |
|
833 | + foreach ($migrations_ran_for_plugin as $version_string => $array_or_migration_obj) { |
|
834 | 834 | // echo "saving migration script to $version_string<br>"; |
835 | 835 | $plugin_slug_for_use_in_option_name = $plugin_slug."."; |
836 | 836 | $option_name = self::data_migration_script_option_prefix.$plugin_slug_for_use_in_option_name.$version_string; |
837 | 837 | $old_option_value = get_option($option_name); |
838 | - if($array_or_migration_obj instanceof EE_Data_Migration_Script_Base){ |
|
838 | + if ($array_or_migration_obj instanceof EE_Data_Migration_Script_Base) { |
|
839 | 839 | $script_array_for_saving = $array_or_migration_obj->properties_as_array(); |
840 | - if( $old_option_value != $script_array_for_saving){ |
|
841 | - $successful_updates = update_option($option_name,$script_array_for_saving); |
|
840 | + if ($old_option_value != $script_array_for_saving) { |
|
841 | + $successful_updates = update_option($option_name, $script_array_for_saving); |
|
842 | 842 | } |
843 | - }else{//we don't know what this array-thing is. So just save it as-is |
|
843 | + } else {//we don't know what this array-thing is. So just save it as-is |
|
844 | 844 | // $array_of_migrations[$version_string] = $array_or_migration_obj; |
845 | - if($old_option_value != $array_or_migration_obj){ |
|
846 | - $successful_updates = update_option($option_name,$array_or_migration_obj); |
|
845 | + if ($old_option_value != $array_or_migration_obj) { |
|
846 | + $successful_updates = update_option($option_name, $array_or_migration_obj); |
|
847 | 847 | } |
848 | 848 | } |
849 | - if( ! $successful_updates ){ |
|
849 | + if ( ! $successful_updates) { |
|
850 | 850 | global $wpdb; |
851 | 851 | return $wpdb->last_error; |
852 | 852 | } |
@@ -870,17 +870,17 @@ discard block |
||
870 | 870 | * @return EE_Data_Migration_Script_Base |
871 | 871 | * @throws EE_Error |
872 | 872 | */ |
873 | - function _instantiate_script_from_properties_array($properties_array){ |
|
874 | - if( ! isset($properties_array['class'])){ |
|
875 | - throw new EE_Error(sprintf(__("Properties array has no 'class' properties. Here's what it has: %s", "event_espresso"),implode(",",$properties_array))); |
|
873 | + function _instantiate_script_from_properties_array($properties_array) { |
|
874 | + if ( ! isset($properties_array['class'])) { |
|
875 | + throw new EE_Error(sprintf(__("Properties array has no 'class' properties. Here's what it has: %s", "event_espresso"), implode(",", $properties_array))); |
|
876 | 876 | } |
877 | 877 | $class_name = $properties_array['class']; |
878 | - if( ! class_exists($class_name)){ |
|
879 | - throw new EE_Error(sprintf(__("There is no migration script named %s", "event_espresso"),$class_name)); |
|
878 | + if ( ! class_exists($class_name)) { |
|
879 | + throw new EE_Error(sprintf(__("There is no migration script named %s", "event_espresso"), $class_name)); |
|
880 | 880 | } |
881 | 881 | $class = new $class_name; |
882 | - if( ! $class instanceof EE_Data_Migration_Script_Base){ |
|
883 | - throw new EE_Error(sprintf(__("Class '%s' is supposed to be a migration script. Its not, its a '%s'", "event_espresso"),$class_name,get_class($class))); |
|
882 | + if ( ! $class instanceof EE_Data_Migration_Script_Base) { |
|
883 | + throw new EE_Error(sprintf(__("Class '%s' is supposed to be a migration script. Its not, its a '%s'", "event_espresso"), $class_name, get_class($class))); |
|
884 | 884 | } |
885 | 885 | $class->instantiate_from_array_of_properties($properties_array); |
886 | 886 | return $class; |
@@ -892,25 +892,25 @@ discard block |
||
892 | 892 | * @param string $plugin_slug the slug for the ee plugin we are searching for. Default is 'Core' |
893 | 893 | * @return string |
894 | 894 | */ |
895 | - public function get_most_up_to_date_dms($plugin_slug = 'Core'){ |
|
895 | + public function get_most_up_to_date_dms($plugin_slug = 'Core') { |
|
896 | 896 | $class_to_filepath_map = $this->get_all_data_migration_scripts_available(); |
897 | 897 | $most_up_to_date_dms_classname = NULL; |
898 | - foreach($class_to_filepath_map as $classname => $filepath){ |
|
899 | - if($most_up_to_date_dms_classname === NULL){ |
|
898 | + foreach ($class_to_filepath_map as $classname => $filepath) { |
|
899 | + if ($most_up_to_date_dms_classname === NULL) { |
|
900 | 900 | $migrates_to = $this->script_migrates_to_version($classname); |
901 | - $this_plugin_slug = $migrates_to[ 'slug' ]; |
|
901 | + $this_plugin_slug = $migrates_to['slug']; |
|
902 | 902 | // $version_string = $migrates_to[ 'version' ]; |
903 | 903 | // $details = $this->parse_dms_classname($classname); |
904 | - if($this_plugin_slug == $plugin_slug){ |
|
904 | + if ($this_plugin_slug == $plugin_slug) { |
|
905 | 905 | //if it's for core, it wins |
906 | 906 | $most_up_to_date_dms_classname = $classname; |
907 | 907 | } |
908 | 908 | //if it wasn't for core, we must keep searching for one that is! |
909 | 909 | continue; |
910 | - }else{ |
|
911 | - $champion_migrates_to= $this->script_migrates_to_version($most_up_to_date_dms_classname); |
|
910 | + } else { |
|
911 | + $champion_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms_classname); |
|
912 | 912 | $contender_migrates_to = $this->script_migrates_to_version($classname); |
913 | - if($contender_migrates_to[ 'slug' ] == $plugin_slug && version_compare($champion_migrates_to[ 'version' ], $contender_migrates_to[ 'version' ], '<')){ |
|
913 | + if ($contender_migrates_to['slug'] == $plugin_slug && version_compare($champion_migrates_to['version'], $contender_migrates_to['version'], '<')) { |
|
914 | 914 | //so the contenders version is higher and its for Core |
915 | 915 | $most_up_to_date_dms_classname = $classname; |
916 | 916 | } |
@@ -930,11 +930,11 @@ discard block |
||
930 | 930 | * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
931 | 931 | * @return EE_Data_Migration_Script_Base |
932 | 932 | */ |
933 | - public function get_migration_ran( $version, $plugin_slug = 'Core' ) { |
|
933 | + public function get_migration_ran($version, $plugin_slug = 'Core') { |
|
934 | 934 | $migrations_ran = $this->get_data_migrations_ran(); |
935 | - if( isset( $migrations_ran[ $plugin_slug ] ) && isset( $migrations_ran[ $plugin_slug ][ $version ] ) ){ |
|
936 | - return $migrations_ran[ $plugin_slug ][ $version ]; |
|
937 | - }else{ |
|
935 | + if (isset($migrations_ran[$plugin_slug]) && isset($migrations_ran[$plugin_slug][$version])) { |
|
936 | + return $migrations_ran[$plugin_slug][$version]; |
|
937 | + } else { |
|
938 | 938 | return NULL; |
939 | 939 | } |
940 | 940 | } |
@@ -946,20 +946,20 @@ discard block |
||
946 | 946 | * @return bool |
947 | 947 | * @throws \EE_Error |
948 | 948 | */ |
949 | - public function reattempt(){ |
|
949 | + public function reattempt() { |
|
950 | 950 | //find if the last-ran script was borked |
951 | 951 | //set it as being non-borked (we shouldn't ever get DMSs that we don't recognize) |
952 | 952 | //add an 'error' saying that we attempted to reset |
953 | 953 | //does it have a stage that was borked too? if so make it no longer borked |
954 | 954 | //add an 'error' saying we attempted to reset |
955 | 955 | $last_ran_script = $this->get_last_ran_script(); |
956 | - if( $last_ran_script instanceof EE_DMS_Unknown_1_0_0 ){ |
|
956 | + if ($last_ran_script instanceof EE_DMS_Unknown_1_0_0) { |
|
957 | 957 | //if it was an error DMS, just mark it as complete (if another error occurs it will overwrite it) |
958 | 958 | $last_ran_script->set_completed(); |
959 | - }elseif( $last_ran_script instanceof EE_Data_Migration_Script_Base ) { |
|
959 | + }elseif ($last_ran_script instanceof EE_Data_Migration_Script_Base) { |
|
960 | 960 | $last_ran_script->reattempt(); |
961 | - }else{ |
|
962 | - throw new EE_Error( sprintf( __( 'Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s', 'event_espresso' ), print_r( $last_ran_script, true ) ) ); |
|
961 | + } else { |
|
962 | + throw new EE_Error(sprintf(__('Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s', 'event_espresso'), print_r($last_ran_script, true))); |
|
963 | 963 | } |
964 | 964 | return $this->_save_migrations_ran(); |
965 | 965 | } |
@@ -969,19 +969,19 @@ discard block |
||
969 | 969 | * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
970 | 970 | * @return boolean |
971 | 971 | */ |
972 | - public function migration_has_ran( $version, $plugin_slug = 'Core' ) { |
|
973 | - return $this->get_migration_ran( $version, $plugin_slug ) !== NULL; |
|
972 | + public function migration_has_ran($version, $plugin_slug = 'Core') { |
|
973 | + return $this->get_migration_ran($version, $plugin_slug) !== NULL; |
|
974 | 974 | } |
975 | 975 | /** |
976 | 976 | * Enqueues this ee plugin to have its data initialized |
977 | 977 | * @param string $plugin_slug either 'Core' or EE_Addon::name()'s return value |
978 | 978 | */ |
979 | - public function enqueue_db_initialization_for( $plugin_slug ) { |
|
979 | + public function enqueue_db_initialization_for($plugin_slug) { |
|
980 | 980 | $queue = $this->get_db_initialization_queue(); |
981 | - if( ! in_array( $plugin_slug, $queue ) ) { |
|
981 | + if ( ! in_array($plugin_slug, $queue)) { |
|
982 | 982 | $queue[] = $plugin_slug; |
983 | 983 | } |
984 | - update_option( self::db_init_queue_option_name, $queue ); |
|
984 | + update_option(self::db_init_queue_option_name, $queue); |
|
985 | 985 | } |
986 | 986 | /** |
987 | 987 | * Calls EE_Addon::initialize_db_if_no_migrations_required() on each addon |
@@ -991,26 +991,26 @@ discard block |
||
991 | 991 | public function initialize_db_for_enqueued_ee_plugins() { |
992 | 992 | // EEH_Debug_Tools::instance()->start_timer( 'initialize_db_for_enqueued_ee_plugins' ); |
993 | 993 | $queue = $this->get_db_initialization_queue(); |
994 | - foreach( $queue as $plugin_slug ) { |
|
995 | - $most_up_to_date_dms = $this->get_most_up_to_date_dms( $plugin_slug ); |
|
996 | - if( ! $most_up_to_date_dms ) { |
|
994 | + foreach ($queue as $plugin_slug) { |
|
995 | + $most_up_to_date_dms = $this->get_most_up_to_date_dms($plugin_slug); |
|
996 | + if ( ! $most_up_to_date_dms) { |
|
997 | 997 | //if there is NO DMS for this plugin, obviously there's no schema to verify anyways |
998 | 998 | $verify_db = false; |
999 | - }else{ |
|
1000 | - $most_up_to_date_dms_migrates_to = $this->script_migrates_to_version( $most_up_to_date_dms ); |
|
1001 | - $verify_db = $this->database_needs_updating_to( $most_up_to_date_dms_migrates_to ); |
|
999 | + } else { |
|
1000 | + $most_up_to_date_dms_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms); |
|
1001 | + $verify_db = $this->database_needs_updating_to($most_up_to_date_dms_migrates_to); |
|
1002 | 1002 | } |
1003 | - if( $plugin_slug == 'Core' ){ |
|
1003 | + if ($plugin_slug == 'Core') { |
|
1004 | 1004 | EE_System::instance()->initialize_db_if_no_migrations_required( |
1005 | 1005 | false, |
1006 | 1006 | $verify_db |
1007 | 1007 | ); |
1008 | - }else{ |
|
1008 | + } else { |
|
1009 | 1009 | //just loop through the addons to make sure their database is setup |
1010 | - foreach( EE_Registry::instance()->addons as $addon ) { |
|
1011 | - if( $addon->name() == $plugin_slug ) { |
|
1010 | + foreach (EE_Registry::instance()->addons as $addon) { |
|
1011 | + if ($addon->name() == $plugin_slug) { |
|
1012 | 1012 | |
1013 | - $addon->initialize_db_if_no_migrations_required( $verify_db ); |
|
1013 | + $addon->initialize_db_if_no_migrations_required($verify_db); |
|
1014 | 1014 | break; |
1015 | 1015 | } |
1016 | 1016 | } |
@@ -1020,7 +1020,7 @@ discard block |
||
1020 | 1020 | // EEH_Debug_Tools::instance()->show_times(); |
1021 | 1021 | //because we just initialized the DBs for the enqueued ee plugins |
1022 | 1022 | //we don't need to keep remembering which ones needed to be initialized |
1023 | - delete_option( self::db_init_queue_option_name ); |
|
1023 | + delete_option(self::db_init_queue_option_name); |
|
1024 | 1024 | } |
1025 | 1025 | |
1026 | 1026 | /** |
@@ -1029,8 +1029,8 @@ discard block |
||
1029 | 1029 | * 'Core', or the return value of EE_Addon::name() for an addon |
1030 | 1030 | * @return array |
1031 | 1031 | */ |
1032 | - public function get_db_initialization_queue(){ |
|
1033 | - return get_option ( self::db_init_queue_option_name, array() ); |
|
1032 | + public function get_db_initialization_queue() { |
|
1033 | + return get_option(self::db_init_queue_option_name, array()); |
|
1034 | 1034 | } |
1035 | 1035 | |
1036 | 1036 | /** |
@@ -1039,13 +1039,13 @@ discard block |
||
1039 | 1039 | * @throws \EE_Error |
1040 | 1040 | */ |
1041 | 1041 | protected function _get_table_analysis() { |
1042 | - if( $this->_table_analysis instanceof TableAnalysis ) { |
|
1042 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
1043 | 1043 | return $this->_table_analysis; |
1044 | 1044 | } else { |
1045 | 1045 | throw new \EE_Error( |
1046 | 1046 | sprintf( |
1047 | - __( 'Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
1048 | - get_class( $this ) |
|
1047 | + __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
1048 | + get_class($this) |
|
1049 | 1049 | ) |
1050 | 1050 | ); |
1051 | 1051 | } |
@@ -1057,13 +1057,13 @@ discard block |
||
1057 | 1057 | * @throws \EE_Error |
1058 | 1058 | */ |
1059 | 1059 | protected function _get_table_manager() { |
1060 | - if( $this->_table_manager instanceof TableManager ) { |
|
1060 | + if ($this->_table_manager instanceof TableManager) { |
|
1061 | 1061 | return $this->_table_manager; |
1062 | 1062 | } else { |
1063 | 1063 | throw new \EE_Error( |
1064 | 1064 | sprintf( |
1065 | - __( 'Table manager class on class %1$s is not set properly.', 'event_espresso'), |
|
1066 | - get_class( $this ) |
|
1065 | + __('Table manager class on class %1$s is not set properly.', 'event_espresso'), |
|
1066 | + get_class($this) |
|
1067 | 1067 | ) |
1068 | 1068 | ); |
1069 | 1069 | } |
@@ -1,22 +1,22 @@ discard block |
||
1 | 1 | |
2 | 2 | <div class="misc-pub-section"> |
3 | 3 | <span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20"></span> |
4 | - <a href="<?php echo $view_approved_reg_url;?>"> |
|
5 | - <?php printf( __('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_approved, FALSE, 'sentence') ); ?> |
|
4 | + <a href="<?php echo $view_approved_reg_url; ?>"> |
|
5 | + <?php printf(__('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_approved, FALSE, 'sentence')); ?> |
|
6 | 6 | </a>: |
7 | 7 | <?php echo $approved_regs; ?> |
8 | 8 | </div> |
9 | 9 | <div class="misc-pub-section"> |
10 | 10 | <span class="dashicons dashicons-groups ee-icon-color-ee-blue ee-icon-size-20"></span> |
11 | - <a href="<?php echo $view_pending_payment_reg_url;?>"> |
|
12 | - <?php printf( __('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, FALSE, 'sentence') ); ?> |
|
11 | + <a href="<?php echo $view_pending_payment_reg_url; ?>"> |
|
12 | + <?php printf(__('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, FALSE, 'sentence')); ?> |
|
13 | 13 | </a>: |
14 | 14 | <?php echo $pending_payment_regs; ?> |
15 | 15 | </div> |
16 | 16 | <div class="misc-pub-section"> |
17 | 17 | <span class="dashicons dashicons-groups ee-icon-color-ee-orange ee-icon-size-20"></span> |
18 | - <a href="<?php echo $view_not_approved_reg_url;?>"> |
|
19 | - <?php printf( __('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, FALSE, 'sentence') ); ?> |
|
18 | + <a href="<?php echo $view_not_approved_reg_url; ?>"> |
|
19 | + <?php printf(__('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, FALSE, 'sentence')); ?> |
|
20 | 20 | </a>: |
21 | 21 | <?php echo $not_approved_regs; ?> |
22 | 22 | </div> |
@@ -29,5 +29,5 @@ discard block |
||
29 | 29 | </a> |
30 | 30 | </div> /**/ ?> |
31 | 31 | |
32 | -<?php echo $event_editor_overview_add;?> |
|
32 | +<?php echo $event_editor_overview_add; ?> |
|
33 | 33 | <br/> |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | 4 | |
5 | 5 | /** |
@@ -116,42 +116,42 @@ discard block |
||
116 | 116 | |
117 | 117 | |
118 | 118 | protected function _start() { |
119 | - $content = '<h3>' . __('Questions Overview', 'event_espresso') . '</h3>'; |
|
120 | - $content .= '<p>' . __('This tour of the Questions Overview page will go over different areas of the screen to help you understand what they are used for.', 'event_espresso') . '</p>'; |
|
119 | + $content = '<h3>'.__('Questions Overview', 'event_espresso').'</h3>'; |
|
120 | + $content .= '<p>'.__('This tour of the Questions Overview page will go over different areas of the screen to help you understand what they are used for.', 'event_espresso').'</p>'; |
|
121 | 121 | |
122 | 122 | return $content; |
123 | 123 | } |
124 | 124 | |
125 | 125 | protected function _display_text_stop() { |
126 | - return '<p>' . __('View available questions.', 'event_espresso') . '</p>'; |
|
126 | + return '<p>'.__('View available questions.', 'event_espresso').'</p>'; |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | protected function _admin_label_stop() { |
130 | - return '<p>' . __('View the admin label for your questions.', 'event_espresso') . '</p>'; |
|
130 | + return '<p>'.__('View the admin label for your questions.', 'event_espresso').'</p>'; |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | protected function _type_stop() { |
134 | - return '<p>' . __('View the type of question. Available options are Text, Textarea, Checkboxes, Radio Buttons, Dropdown, State/Province Dropdown, Country Dropdown, and Date Picker.', 'event_espresso') . '</p>'; |
|
134 | + return '<p>'.__('View the type of question. Available options are Text, Textarea, Checkboxes, Radio Buttons, Dropdown, State/Province Dropdown, Country Dropdown, and Date Picker.', 'event_espresso').'</p>'; |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | protected function _values_stop() { |
138 | - return '<p>' . __('View stored values for checkboxes, radio buttons, and select boxes.', 'event_espresso') . '</p>'; |
|
138 | + return '<p>'.__('View stored values for checkboxes, radio buttons, and select boxes.', 'event_espresso').'</p>'; |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | protected function _required_stop() { |
142 | - return '<p>' . __('View if a question is required.', 'event_espresso') . '</p>'; |
|
142 | + return '<p>'.__('View if a question is required.', 'event_espresso').'</p>'; |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | protected function _bulk_actions_stop() { |
146 | - return '<p>' . __('Perform bulk actions to multiple questions.', 'event_espresso') . '</p>'; |
|
146 | + return '<p>'.__('Perform bulk actions to multiple questions.', 'event_espresso').'</p>'; |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | protected function _search_stop() { |
150 | - return '<p>' . __('Search through questions. The following sources will be searched: Name of Question (display text).', 'event_espresso') . '</p>'; |
|
150 | + return '<p>'.__('Search through questions. The following sources will be searched: Name of Question (display text).', 'event_espresso').'</p>'; |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | protected function _add_new_question_stop() { |
154 | - return '<p>' . __('Click here to add a new question.', 'event_espresso') . '</p>'; |
|
154 | + return '<p>'.__('Click here to add a new question.', 'event_espresso').'</p>'; |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | } |
158 | 158 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('NO direct script access allowed'); |
|
3 | + exit('NO direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -18,64 +18,64 @@ discard block |
||
18 | 18 | class Registration_Form_Questions_Overview_Help_Tour extends EE_Help_Tour |
19 | 19 | { |
20 | 20 | |
21 | - protected function _set_tour_properties() |
|
22 | - { |
|
23 | - $this->_label = __('Questions Overview Tour', 'event_espresso'); |
|
24 | - $this->_slug = $this->_is_caf ? 'questions-overview-caf-joyride' : 'questions-overview-joyride'; |
|
25 | - } |
|
21 | + protected function _set_tour_properties() |
|
22 | + { |
|
23 | + $this->_label = __('Questions Overview Tour', 'event_espresso'); |
|
24 | + $this->_slug = $this->_is_caf ? 'questions-overview-caf-joyride' : 'questions-overview-joyride'; |
|
25 | + } |
|
26 | 26 | |
27 | - protected function _set_tour_stops() |
|
28 | - { |
|
29 | - $this->_stops = array( |
|
30 | - 10 => array( |
|
31 | - 'content' => $this->_start(), |
|
32 | - ), |
|
33 | - 30 => array( |
|
34 | - 'id' => 'display_text', |
|
35 | - 'content' => $this->_display_text_stop(), |
|
36 | - 'options' => array( |
|
37 | - 'tipLocation' => 'top', |
|
38 | - 'tipAdjustmentX' => -5, |
|
39 | - 'tipAdjustmentY' => -25 |
|
40 | - ) |
|
41 | - ), |
|
42 | - 40 => array( |
|
43 | - 'id' => 'admin_label', |
|
44 | - 'content' => $this->_admin_label_stop(), |
|
45 | - 'options' => array( |
|
46 | - 'tipLocation' => 'top', |
|
47 | - 'tipAdjustmentX' => 20, |
|
48 | - 'tipAdjustmentY' => -25 |
|
49 | - ) |
|
50 | - ), |
|
51 | - 50 => array( |
|
52 | - 'id' => 'type', |
|
53 | - 'content' => $this->_type_stop(), |
|
54 | - 'options' => array( |
|
55 | - 'tipLocation' => 'top', |
|
56 | - 'tipAdjustmentX' => -5, |
|
57 | - 'tipAdjustmentY' => -25 |
|
58 | - ) |
|
59 | - ), |
|
60 | - 60 => array( |
|
61 | - 'id' => 'values', |
|
62 | - 'content' => $this->_values_stop(), |
|
63 | - 'options' => array( |
|
64 | - 'tipLocation' => 'top', |
|
65 | - 'tipAdjustmentX' => -5, |
|
66 | - 'tipAdjustmentY' => -25 |
|
67 | - ) |
|
68 | - ), |
|
69 | - 70 => array( |
|
70 | - 'id' => 'required', |
|
71 | - 'content' => $this->_required_stop(), |
|
72 | - 'options' => array( |
|
73 | - 'tipLocation' => 'top', |
|
74 | - 'tipAdjustmentY' => -20, |
|
75 | - 'tipAdjustmentX' => -15 |
|
76 | - ) |
|
77 | - ), |
|
78 | - /*80 => array( |
|
27 | + protected function _set_tour_stops() |
|
28 | + { |
|
29 | + $this->_stops = array( |
|
30 | + 10 => array( |
|
31 | + 'content' => $this->_start(), |
|
32 | + ), |
|
33 | + 30 => array( |
|
34 | + 'id' => 'display_text', |
|
35 | + 'content' => $this->_display_text_stop(), |
|
36 | + 'options' => array( |
|
37 | + 'tipLocation' => 'top', |
|
38 | + 'tipAdjustmentX' => -5, |
|
39 | + 'tipAdjustmentY' => -25 |
|
40 | + ) |
|
41 | + ), |
|
42 | + 40 => array( |
|
43 | + 'id' => 'admin_label', |
|
44 | + 'content' => $this->_admin_label_stop(), |
|
45 | + 'options' => array( |
|
46 | + 'tipLocation' => 'top', |
|
47 | + 'tipAdjustmentX' => 20, |
|
48 | + 'tipAdjustmentY' => -25 |
|
49 | + ) |
|
50 | + ), |
|
51 | + 50 => array( |
|
52 | + 'id' => 'type', |
|
53 | + 'content' => $this->_type_stop(), |
|
54 | + 'options' => array( |
|
55 | + 'tipLocation' => 'top', |
|
56 | + 'tipAdjustmentX' => -5, |
|
57 | + 'tipAdjustmentY' => -25 |
|
58 | + ) |
|
59 | + ), |
|
60 | + 60 => array( |
|
61 | + 'id' => 'values', |
|
62 | + 'content' => $this->_values_stop(), |
|
63 | + 'options' => array( |
|
64 | + 'tipLocation' => 'top', |
|
65 | + 'tipAdjustmentX' => -5, |
|
66 | + 'tipAdjustmentY' => -25 |
|
67 | + ) |
|
68 | + ), |
|
69 | + 70 => array( |
|
70 | + 'id' => 'required', |
|
71 | + 'content' => $this->_required_stop(), |
|
72 | + 'options' => array( |
|
73 | + 'tipLocation' => 'top', |
|
74 | + 'tipAdjustmentY' => -20, |
|
75 | + 'tipAdjustmentX' => -15 |
|
76 | + ) |
|
77 | + ), |
|
78 | + /*80 => array( |
|
79 | 79 | 'class' => 'bulkactions', |
80 | 80 | 'content' => $this->_bulk_actions_stop(), |
81 | 81 | 'options' => array( |
@@ -84,77 +84,77 @@ discard block |
||
84 | 84 | 'tipAdjustmentX' => -15 |
85 | 85 | ) |
86 | 86 | ),*/ |
87 | - 90 => array( |
|
88 | - 'id' => 'event-espresso_page_espresso_registration_form-search-input', |
|
89 | - 'content' => $this->_search_stop(), |
|
90 | - 'options' => array( |
|
91 | - 'tipLocation' => 'left', |
|
92 | - 'tipAdjustmentY' => -50, |
|
93 | - 'tipAdjustmentX' => -15 |
|
94 | - ) |
|
95 | - ), |
|
96 | - 100 => array( |
|
97 | - 'id' => 'add-new-question', |
|
98 | - 'content' => $this->_add_new_question_stop(), |
|
99 | - 'options' => array( |
|
100 | - 'tipLocation' => 'right', |
|
101 | - 'tipAdjustmentY' => -50, |
|
102 | - 'tipAdjustmentX' => 15 |
|
103 | - ) |
|
104 | - ), |
|
105 | - ); |
|
106 | - } |
|
87 | + 90 => array( |
|
88 | + 'id' => 'event-espresso_page_espresso_registration_form-search-input', |
|
89 | + 'content' => $this->_search_stop(), |
|
90 | + 'options' => array( |
|
91 | + 'tipLocation' => 'left', |
|
92 | + 'tipAdjustmentY' => -50, |
|
93 | + 'tipAdjustmentX' => -15 |
|
94 | + ) |
|
95 | + ), |
|
96 | + 100 => array( |
|
97 | + 'id' => 'add-new-question', |
|
98 | + 'content' => $this->_add_new_question_stop(), |
|
99 | + 'options' => array( |
|
100 | + 'tipLocation' => 'right', |
|
101 | + 'tipAdjustmentY' => -50, |
|
102 | + 'tipAdjustmentX' => 15 |
|
103 | + ) |
|
104 | + ), |
|
105 | + ); |
|
106 | + } |
|
107 | 107 | |
108 | 108 | |
109 | - protected function _start() |
|
110 | - { |
|
111 | - $content = '<h3>' . __('Questions Overview', 'event_espresso') . '</h3>'; |
|
112 | - $content .= '<p>' . __('This tour of the Questions Overview page will go over different areas of the screen to help you understand what they are used for.', |
|
113 | - 'event_espresso') . '</p>'; |
|
109 | + protected function _start() |
|
110 | + { |
|
111 | + $content = '<h3>' . __('Questions Overview', 'event_espresso') . '</h3>'; |
|
112 | + $content .= '<p>' . __('This tour of the Questions Overview page will go over different areas of the screen to help you understand what they are used for.', |
|
113 | + 'event_espresso') . '</p>'; |
|
114 | 114 | |
115 | - return $content; |
|
116 | - } |
|
115 | + return $content; |
|
116 | + } |
|
117 | 117 | |
118 | - protected function _display_text_stop() |
|
119 | - { |
|
120 | - return '<p>' . __('View available questions.', 'event_espresso') . '</p>'; |
|
121 | - } |
|
118 | + protected function _display_text_stop() |
|
119 | + { |
|
120 | + return '<p>' . __('View available questions.', 'event_espresso') . '</p>'; |
|
121 | + } |
|
122 | 122 | |
123 | - protected function _admin_label_stop() |
|
124 | - { |
|
125 | - return '<p>' . __('View the admin label for your questions.', 'event_espresso') . '</p>'; |
|
126 | - } |
|
123 | + protected function _admin_label_stop() |
|
124 | + { |
|
125 | + return '<p>' . __('View the admin label for your questions.', 'event_espresso') . '</p>'; |
|
126 | + } |
|
127 | 127 | |
128 | - protected function _type_stop() |
|
129 | - { |
|
130 | - return '<p>' . __('View the type of question. Available options are Text, Textarea, Checkboxes, Radio Buttons, Dropdown, State/Province Dropdown, Country Dropdown, and Date Picker.', |
|
131 | - 'event_espresso') . '</p>'; |
|
132 | - } |
|
128 | + protected function _type_stop() |
|
129 | + { |
|
130 | + return '<p>' . __('View the type of question. Available options are Text, Textarea, Checkboxes, Radio Buttons, Dropdown, State/Province Dropdown, Country Dropdown, and Date Picker.', |
|
131 | + 'event_espresso') . '</p>'; |
|
132 | + } |
|
133 | 133 | |
134 | - protected function _values_stop() |
|
135 | - { |
|
136 | - return '<p>' . __('View stored values for checkboxes, radio buttons, and select boxes.', |
|
137 | - 'event_espresso') . '</p>'; |
|
138 | - } |
|
134 | + protected function _values_stop() |
|
135 | + { |
|
136 | + return '<p>' . __('View stored values for checkboxes, radio buttons, and select boxes.', |
|
137 | + 'event_espresso') . '</p>'; |
|
138 | + } |
|
139 | 139 | |
140 | - protected function _required_stop() |
|
141 | - { |
|
142 | - return '<p>' . __('View if a question is required.', 'event_espresso') . '</p>'; |
|
143 | - } |
|
140 | + protected function _required_stop() |
|
141 | + { |
|
142 | + return '<p>' . __('View if a question is required.', 'event_espresso') . '</p>'; |
|
143 | + } |
|
144 | 144 | |
145 | - /* protected function _bulk_actions_stop() { |
|
145 | + /* protected function _bulk_actions_stop() { |
|
146 | 146 | return '<p>' . __('Perform bulk actions to multiple questions.', 'event_espresso') . '</p>'; |
147 | 147 | } */ |
148 | 148 | |
149 | - protected function _search_stop() |
|
150 | - { |
|
151 | - return '<p>' . __('Search through questions. The following sources will be searched: Name of Question (display text).', |
|
152 | - 'event_espresso') . '</p>'; |
|
153 | - } |
|
149 | + protected function _search_stop() |
|
150 | + { |
|
151 | + return '<p>' . __('Search through questions. The following sources will be searched: Name of Question (display text).', |
|
152 | + 'event_espresso') . '</p>'; |
|
153 | + } |
|
154 | 154 | |
155 | - protected function _add_new_question_stop() |
|
156 | - { |
|
157 | - return '<p>' . __('Click here to add a new question.', 'event_espresso') . '</p>'; |
|
158 | - } |
|
155 | + protected function _add_new_question_stop() |
|
156 | + { |
|
157 | + return '<p>' . __('Click here to add a new question.', 'event_espresso') . '</p>'; |
|
158 | + } |
|
159 | 159 | |
160 | 160 | } |
161 | 161 | \ No newline at end of file |
@@ -108,38 +108,38 @@ discard block |
||
108 | 108 | |
109 | 109 | protected function _start() |
110 | 110 | { |
111 | - $content = '<h3>' . __('Questions Overview', 'event_espresso') . '</h3>'; |
|
112 | - $content .= '<p>' . __('This tour of the Questions Overview page will go over different areas of the screen to help you understand what they are used for.', |
|
113 | - 'event_espresso') . '</p>'; |
|
111 | + $content = '<h3>'.__('Questions Overview', 'event_espresso').'</h3>'; |
|
112 | + $content .= '<p>'.__('This tour of the Questions Overview page will go over different areas of the screen to help you understand what they are used for.', |
|
113 | + 'event_espresso').'</p>'; |
|
114 | 114 | |
115 | 115 | return $content; |
116 | 116 | } |
117 | 117 | |
118 | 118 | protected function _display_text_stop() |
119 | 119 | { |
120 | - return '<p>' . __('View available questions.', 'event_espresso') . '</p>'; |
|
120 | + return '<p>'.__('View available questions.', 'event_espresso').'</p>'; |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | protected function _admin_label_stop() |
124 | 124 | { |
125 | - return '<p>' . __('View the admin label for your questions.', 'event_espresso') . '</p>'; |
|
125 | + return '<p>'.__('View the admin label for your questions.', 'event_espresso').'</p>'; |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | protected function _type_stop() |
129 | 129 | { |
130 | - return '<p>' . __('View the type of question. Available options are Text, Textarea, Checkboxes, Radio Buttons, Dropdown, State/Province Dropdown, Country Dropdown, and Date Picker.', |
|
131 | - 'event_espresso') . '</p>'; |
|
130 | + return '<p>'.__('View the type of question. Available options are Text, Textarea, Checkboxes, Radio Buttons, Dropdown, State/Province Dropdown, Country Dropdown, and Date Picker.', |
|
131 | + 'event_espresso').'</p>'; |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | protected function _values_stop() |
135 | 135 | { |
136 | - return '<p>' . __('View stored values for checkboxes, radio buttons, and select boxes.', |
|
137 | - 'event_espresso') . '</p>'; |
|
136 | + return '<p>'.__('View stored values for checkboxes, radio buttons, and select boxes.', |
|
137 | + 'event_espresso').'</p>'; |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | protected function _required_stop() |
141 | 141 | { |
142 | - return '<p>' . __('View if a question is required.', 'event_espresso') . '</p>'; |
|
142 | + return '<p>'.__('View if a question is required.', 'event_espresso').'</p>'; |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /* protected function _bulk_actions_stop() { |
@@ -148,13 +148,13 @@ discard block |
||
148 | 148 | |
149 | 149 | protected function _search_stop() |
150 | 150 | { |
151 | - return '<p>' . __('Search through questions. The following sources will be searched: Name of Question (display text).', |
|
152 | - 'event_espresso') . '</p>'; |
|
151 | + return '<p>'.__('Search through questions. The following sources will be searched: Name of Question (display text).', |
|
152 | + 'event_espresso').'</p>'; |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | protected function _add_new_question_stop() |
156 | 156 | { |
157 | - return '<p>' . __('Click here to add a new question.', 'event_espresso') . '</p>'; |
|
157 | + return '<p>'.__('Click here to add a new question.', 'event_espresso').'</p>'; |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | } |
161 | 161 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | -require_once(EE_MODELS . 'EEM_Base.model.php'); |
|
4 | +require_once(EE_MODELS.'EEM_Base.model.php'); |
|
5 | 5 | |
6 | 6 | /** |
7 | 7 | * |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | __('Registration Steps', 'event_espresso'), false, array()), |
106 | 106 | ) |
107 | 107 | ); |
108 | - $this->_model_relations = array( |
|
108 | + $this->_model_relations = array( |
|
109 | 109 | 'Registration' => new EE_Has_Many_Relation(), |
110 | 110 | 'Payment' => new EE_Has_Many_Relation(), |
111 | 111 | 'Status' => new EE_Belongs_To_Relation(), |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | ), |
168 | 168 | OBJECT, |
169 | 169 | array( |
170 | - 'txnDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
170 | + 'txnDate' => array('DATE('.$query_interval.')', '%s'), |
|
171 | 171 | 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') |
172 | 172 | ) |
173 | 173 | ); |
@@ -187,17 +187,17 @@ discard block |
||
187 | 187 | public function get_revenue_per_event_report($period = '-1 month') |
188 | 188 | { |
189 | 189 | global $wpdb; |
190 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
191 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
192 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
190 | + $transaction_table = $wpdb->prefix.'esp_transaction'; |
|
191 | + $registration_table = $wpdb->prefix.'esp_registration'; |
|
192 | + $registration_payment_table = $wpdb->prefix.'esp_registration_payment'; |
|
193 | 193 | $event_table = $wpdb->posts; |
194 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
194 | + $payment_table = $wpdb->prefix.'esp_payment'; |
|
195 | 195 | $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
196 | 196 | $approved_payment_status = EEM_Payment::status_id_approved; |
197 | 197 | $extra_event_on_join = ''; |
198 | 198 | //exclude events not authored by user if permissions in effect |
199 | 199 | if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
200 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
200 | + $extra_event_on_join = ' AND Event.post_author = '.get_current_user_id(); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | return $wpdb->get_results( |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
269 | 269 | { |
270 | 270 | EE_Error::doing_it_wrong( |
271 | - __CLASS__ . '::' . __FUNCTION__, |
|
271 | + __CLASS__.'::'.__FUNCTION__, |
|
272 | 272 | sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
273 | 273 | 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'), |
274 | 274 | '4.6.0' |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | array( |
317 | 317 | 0 => array( |
318 | 318 | 'STS_ID' => EEM_Transaction::failed_status_code, |
319 | - 'Payment.PAY_ID' => array( 'IS NULL' ), |
|
319 | + 'Payment.PAY_ID' => array('IS NULL'), |
|
320 | 320 | 'TXN_timestamp' => array('<', time() - $time_to_leave_alone) |
321 | 321 | ) |
322 | 322 | ), |
@@ -334,18 +334,18 @@ discard block |
||
334 | 334 | $time_to_leave_alone |
335 | 335 | ); |
336 | 336 | //now that we have the ids to delete |
337 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
337 | + if ( ! empty($txn_ids) && is_array($txn_ids)) { |
|
338 | 338 | // first, make sure these TXN's are removed the "ee_locked_transactions" array |
339 | 339 | EEM_Transaction::unset_locked_transactions($txn_ids); |
340 | 340 | // let's get deletin'... |
341 | 341 | // Why no wpdb->prepare? Because the data is trusted. |
342 | 342 | // We got the ids from the original query to get them FROM |
343 | 343 | // the db (which is sanitized) so no need to prepare them again. |
344 | - $query = ' |
|
344 | + $query = ' |
|
345 | 345 | DELETE |
346 | - FROM ' . $this->table() . ' |
|
346 | + FROM ' . $this->table().' |
|
347 | 347 | WHERE |
348 | - TXN_ID IN ( ' . implode(",", $txn_ids) . ')'; |
|
348 | + TXN_ID IN ( ' . implode(",", $txn_ids).')'; |
|
349 | 349 | $deleted = $wpdb->query($query); |
350 | 350 | } |
351 | 351 | if ($deleted) { |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | require_once(EE_MODELS . 'EEM_Base.model.php'); |
5 | 5 | |
@@ -15,193 +15,193 @@ discard block |
||
15 | 15 | class EEM_Transaction extends EEM_Base |
16 | 16 | { |
17 | 17 | |
18 | - // private instance of the Transaction object |
|
19 | - protected static $_instance; |
|
20 | - |
|
21 | - /** |
|
22 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
23 | - * but payment is pending. This is the state for transactions where payment is promised |
|
24 | - * from an offline gateway. |
|
25 | - */ |
|
26 | - // const open_status_code = 'TPN'; |
|
27 | - |
|
28 | - /** |
|
29 | - * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
30 | - * either due to a technical reason (server or computer crash during registration), |
|
31 | - * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
32 | - */ |
|
33 | - const failed_status_code = 'TFL'; |
|
34 | - |
|
35 | - /** |
|
36 | - * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
37 | - * either due to a technical reason (server or computer crash during registration), |
|
38 | - * or due to an abandoned cart after registrant chose not to complete the registration process |
|
39 | - * HOWEVER... |
|
40 | - * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
41 | - * registrant |
|
42 | - */ |
|
43 | - const abandoned_status_code = 'TAB'; |
|
44 | - |
|
45 | - /** |
|
46 | - * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
47 | - * meaning that monies are still owing: TXN_paid < TXN_total |
|
48 | - */ |
|
49 | - const incomplete_status_code = 'TIN'; |
|
50 | - |
|
51 | - /** |
|
52 | - * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
53 | - * meaning that NO monies are owing: TXN_paid == TXN_total |
|
54 | - */ |
|
55 | - const complete_status_code = 'TCM'; |
|
56 | - |
|
57 | - /** |
|
58 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
59 | - * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
60 | - */ |
|
61 | - const overpaid_status_code = 'TOP'; |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * private constructor to prevent direct creation |
|
66 | - * |
|
67 | - * @Constructor |
|
68 | - * @access protected |
|
69 | - * |
|
70 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
71 | - * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
72 | - * date time model field objects. Default is NULL (and will be assumed using the set |
|
73 | - * timezone in the 'timezone_string' wp option) |
|
74 | - * |
|
75 | - * @return EEM_Transaction |
|
76 | - * @throws \EE_Error |
|
77 | - */ |
|
78 | - protected function __construct($timezone) |
|
79 | - { |
|
80 | - $this->singular_item = __('Transaction', 'event_espresso'); |
|
81 | - $this->plural_item = __('Transactions', 'event_espresso'); |
|
82 | - |
|
83 | - $this->_tables = array( |
|
84 | - 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID') |
|
85 | - ); |
|
86 | - $this->_fields = array( |
|
87 | - 'TransactionTable' => array( |
|
88 | - 'TXN_ID' => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')), |
|
89 | - 'TXN_timestamp' => new EE_Datetime_Field('TXN_timestamp', |
|
90 | - __('date when transaction was created', 'event_espresso'), false, EE_Datetime_Field::now, |
|
91 | - $timezone), |
|
92 | - 'TXN_total' => new EE_Money_Field('TXN_total', |
|
93 | - __('Total value of Transaction', 'event_espresso'), false, 0), |
|
94 | - 'TXN_paid' => new EE_Money_Field('TXN_paid', |
|
95 | - __('Amount paid towards transaction to date', 'event_espresso'), false, 0), |
|
96 | - 'STS_ID' => new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'), |
|
97 | - false, EEM_Transaction::failed_status_code, 'Status'), |
|
98 | - 'TXN_session_data' => new EE_Serialized_Text_Field('TXN_session_data', |
|
99 | - __('Serialized session data', 'event_espresso'), true, ''), |
|
100 | - 'TXN_hash_salt' => new EE_Plain_Text_Field('TXN_hash_salt', |
|
101 | - __('Transaction Hash Salt', 'event_espresso'), true, ''), |
|
102 | - 'PMD_ID' => new EE_Foreign_Key_Int_Field('PMD_ID', |
|
103 | - __("Last Used Payment Method", 'event_espresso'), true, null, 'Payment_Method'), |
|
104 | - 'TXN_reg_steps' => new EE_Serialized_Text_Field('TXN_reg_steps', |
|
105 | - __('Registration Steps', 'event_espresso'), false, array()), |
|
106 | - ) |
|
107 | - ); |
|
108 | - $this->_model_relations = array( |
|
109 | - 'Registration' => new EE_Has_Many_Relation(), |
|
110 | - 'Payment' => new EE_Has_Many_Relation(), |
|
111 | - 'Status' => new EE_Belongs_To_Relation(), |
|
112 | - 'Line_Item' => new EE_Has_Many_Relation(false), |
|
113 | - //you can delete a transaction without needing to delete its line items |
|
114 | - 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
115 | - 'Message' => new EE_Has_Many_Relation() |
|
116 | - ); |
|
117 | - $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
118 | - parent::__construct($timezone); |
|
119 | - |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * txn_status_array |
|
125 | - * get list of transaction statuses |
|
126 | - * |
|
127 | - * @access public |
|
128 | - * @return array |
|
129 | - */ |
|
130 | - public static function txn_status_array() |
|
131 | - { |
|
132 | - return apply_filters( |
|
133 | - 'FHEE__EEM_Transaction__txn_status_array', |
|
134 | - array( |
|
135 | - EEM_Transaction::overpaid_status_code, |
|
136 | - EEM_Transaction::complete_status_code, |
|
137 | - EEM_Transaction::incomplete_status_code, |
|
138 | - EEM_Transaction::abandoned_status_code, |
|
139 | - EEM_Transaction::failed_status_code, |
|
140 | - ) |
|
141 | - ); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * get the revenue per day for the Transaction Admin page Reports Tab |
|
146 | - * |
|
147 | - * @access public |
|
148 | - * |
|
149 | - * @param string $period |
|
150 | - * |
|
151 | - * @return \stdClass[] |
|
152 | - */ |
|
153 | - public function get_revenue_per_day_report($period = '-1 month') |
|
154 | - { |
|
155 | - $sql_date = $this->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', strtotime($period)), |
|
156 | - 'Y-m-d H:i:s', 'UTC'); |
|
157 | - |
|
158 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
159 | - |
|
160 | - return $this->_get_all_wpdb_results( |
|
161 | - array( |
|
162 | - array( |
|
163 | - 'TXN_timestamp' => array('>=', $sql_date) |
|
164 | - ), |
|
165 | - 'group_by' => 'txnDate', |
|
166 | - 'order_by' => array('TXN_timestamp' => 'ASC') |
|
167 | - ), |
|
168 | - OBJECT, |
|
169 | - array( |
|
170 | - 'txnDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
171 | - 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') |
|
172 | - ) |
|
173 | - ); |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * get the revenue per event for the Transaction Admin page Reports Tab |
|
179 | - * |
|
180 | - * @access public |
|
181 | - * |
|
182 | - * @param string $period |
|
183 | - * |
|
184 | - * @throws \EE_Error |
|
185 | - * @return mixed |
|
186 | - */ |
|
187 | - public function get_revenue_per_event_report($period = '-1 month') |
|
188 | - { |
|
189 | - global $wpdb; |
|
190 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
191 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
192 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
193 | - $event_table = $wpdb->posts; |
|
194 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
195 | - $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
196 | - $approved_payment_status = EEM_Payment::status_id_approved; |
|
197 | - $extra_event_on_join = ''; |
|
198 | - //exclude events not authored by user if permissions in effect |
|
199 | - if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
200 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
201 | - } |
|
202 | - |
|
203 | - return $wpdb->get_results( |
|
204 | - "SELECT |
|
18 | + // private instance of the Transaction object |
|
19 | + protected static $_instance; |
|
20 | + |
|
21 | + /** |
|
22 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
23 | + * but payment is pending. This is the state for transactions where payment is promised |
|
24 | + * from an offline gateway. |
|
25 | + */ |
|
26 | + // const open_status_code = 'TPN'; |
|
27 | + |
|
28 | + /** |
|
29 | + * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
30 | + * either due to a technical reason (server or computer crash during registration), |
|
31 | + * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
32 | + */ |
|
33 | + const failed_status_code = 'TFL'; |
|
34 | + |
|
35 | + /** |
|
36 | + * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
37 | + * either due to a technical reason (server or computer crash during registration), |
|
38 | + * or due to an abandoned cart after registrant chose not to complete the registration process |
|
39 | + * HOWEVER... |
|
40 | + * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
41 | + * registrant |
|
42 | + */ |
|
43 | + const abandoned_status_code = 'TAB'; |
|
44 | + |
|
45 | + /** |
|
46 | + * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
47 | + * meaning that monies are still owing: TXN_paid < TXN_total |
|
48 | + */ |
|
49 | + const incomplete_status_code = 'TIN'; |
|
50 | + |
|
51 | + /** |
|
52 | + * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
53 | + * meaning that NO monies are owing: TXN_paid == TXN_total |
|
54 | + */ |
|
55 | + const complete_status_code = 'TCM'; |
|
56 | + |
|
57 | + /** |
|
58 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
59 | + * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
60 | + */ |
|
61 | + const overpaid_status_code = 'TOP'; |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * private constructor to prevent direct creation |
|
66 | + * |
|
67 | + * @Constructor |
|
68 | + * @access protected |
|
69 | + * |
|
70 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
71 | + * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
72 | + * date time model field objects. Default is NULL (and will be assumed using the set |
|
73 | + * timezone in the 'timezone_string' wp option) |
|
74 | + * |
|
75 | + * @return EEM_Transaction |
|
76 | + * @throws \EE_Error |
|
77 | + */ |
|
78 | + protected function __construct($timezone) |
|
79 | + { |
|
80 | + $this->singular_item = __('Transaction', 'event_espresso'); |
|
81 | + $this->plural_item = __('Transactions', 'event_espresso'); |
|
82 | + |
|
83 | + $this->_tables = array( |
|
84 | + 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID') |
|
85 | + ); |
|
86 | + $this->_fields = array( |
|
87 | + 'TransactionTable' => array( |
|
88 | + 'TXN_ID' => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')), |
|
89 | + 'TXN_timestamp' => new EE_Datetime_Field('TXN_timestamp', |
|
90 | + __('date when transaction was created', 'event_espresso'), false, EE_Datetime_Field::now, |
|
91 | + $timezone), |
|
92 | + 'TXN_total' => new EE_Money_Field('TXN_total', |
|
93 | + __('Total value of Transaction', 'event_espresso'), false, 0), |
|
94 | + 'TXN_paid' => new EE_Money_Field('TXN_paid', |
|
95 | + __('Amount paid towards transaction to date', 'event_espresso'), false, 0), |
|
96 | + 'STS_ID' => new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'), |
|
97 | + false, EEM_Transaction::failed_status_code, 'Status'), |
|
98 | + 'TXN_session_data' => new EE_Serialized_Text_Field('TXN_session_data', |
|
99 | + __('Serialized session data', 'event_espresso'), true, ''), |
|
100 | + 'TXN_hash_salt' => new EE_Plain_Text_Field('TXN_hash_salt', |
|
101 | + __('Transaction Hash Salt', 'event_espresso'), true, ''), |
|
102 | + 'PMD_ID' => new EE_Foreign_Key_Int_Field('PMD_ID', |
|
103 | + __("Last Used Payment Method", 'event_espresso'), true, null, 'Payment_Method'), |
|
104 | + 'TXN_reg_steps' => new EE_Serialized_Text_Field('TXN_reg_steps', |
|
105 | + __('Registration Steps', 'event_espresso'), false, array()), |
|
106 | + ) |
|
107 | + ); |
|
108 | + $this->_model_relations = array( |
|
109 | + 'Registration' => new EE_Has_Many_Relation(), |
|
110 | + 'Payment' => new EE_Has_Many_Relation(), |
|
111 | + 'Status' => new EE_Belongs_To_Relation(), |
|
112 | + 'Line_Item' => new EE_Has_Many_Relation(false), |
|
113 | + //you can delete a transaction without needing to delete its line items |
|
114 | + 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
115 | + 'Message' => new EE_Has_Many_Relation() |
|
116 | + ); |
|
117 | + $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
118 | + parent::__construct($timezone); |
|
119 | + |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * txn_status_array |
|
125 | + * get list of transaction statuses |
|
126 | + * |
|
127 | + * @access public |
|
128 | + * @return array |
|
129 | + */ |
|
130 | + public static function txn_status_array() |
|
131 | + { |
|
132 | + return apply_filters( |
|
133 | + 'FHEE__EEM_Transaction__txn_status_array', |
|
134 | + array( |
|
135 | + EEM_Transaction::overpaid_status_code, |
|
136 | + EEM_Transaction::complete_status_code, |
|
137 | + EEM_Transaction::incomplete_status_code, |
|
138 | + EEM_Transaction::abandoned_status_code, |
|
139 | + EEM_Transaction::failed_status_code, |
|
140 | + ) |
|
141 | + ); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * get the revenue per day for the Transaction Admin page Reports Tab |
|
146 | + * |
|
147 | + * @access public |
|
148 | + * |
|
149 | + * @param string $period |
|
150 | + * |
|
151 | + * @return \stdClass[] |
|
152 | + */ |
|
153 | + public function get_revenue_per_day_report($period = '-1 month') |
|
154 | + { |
|
155 | + $sql_date = $this->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', strtotime($period)), |
|
156 | + 'Y-m-d H:i:s', 'UTC'); |
|
157 | + |
|
158 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
159 | + |
|
160 | + return $this->_get_all_wpdb_results( |
|
161 | + array( |
|
162 | + array( |
|
163 | + 'TXN_timestamp' => array('>=', $sql_date) |
|
164 | + ), |
|
165 | + 'group_by' => 'txnDate', |
|
166 | + 'order_by' => array('TXN_timestamp' => 'ASC') |
|
167 | + ), |
|
168 | + OBJECT, |
|
169 | + array( |
|
170 | + 'txnDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
171 | + 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') |
|
172 | + ) |
|
173 | + ); |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * get the revenue per event for the Transaction Admin page Reports Tab |
|
179 | + * |
|
180 | + * @access public |
|
181 | + * |
|
182 | + * @param string $period |
|
183 | + * |
|
184 | + * @throws \EE_Error |
|
185 | + * @return mixed |
|
186 | + */ |
|
187 | + public function get_revenue_per_event_report($period = '-1 month') |
|
188 | + { |
|
189 | + global $wpdb; |
|
190 | + $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
191 | + $registration_table = $wpdb->prefix . 'esp_registration'; |
|
192 | + $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
193 | + $event_table = $wpdb->posts; |
|
194 | + $payment_table = $wpdb->prefix . 'esp_payment'; |
|
195 | + $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
196 | + $approved_payment_status = EEM_Payment::status_id_approved; |
|
197 | + $extra_event_on_join = ''; |
|
198 | + //exclude events not authored by user if permissions in effect |
|
199 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
200 | + $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
201 | + } |
|
202 | + |
|
203 | + return $wpdb->get_results( |
|
204 | + "SELECT |
|
205 | 205 | Transaction_Event.event_name AS event_name, |
206 | 206 | SUM(Transaction_Event.paid) AS revenue |
207 | 207 | FROM |
@@ -228,185 +228,185 @@ discard block |
||
228 | 228 | $extra_event_on_join |
229 | 229 | ) AS Transaction_Event |
230 | 230 | GROUP BY event_name", |
231 | - OBJECT |
|
232 | - ); |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
238 | - * $_REQUEST global variable. Either way, tries to find the current transaction (through |
|
239 | - * the registration pointed to by reg_url_link), if not returns null |
|
240 | - * |
|
241 | - * @param string $reg_url_link |
|
242 | - * |
|
243 | - * @return EE_Transaction |
|
244 | - */ |
|
245 | - public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
246 | - { |
|
247 | - return $this->get_one(array( |
|
248 | - array( |
|
249 | - 'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get('e_reg_url_link', |
|
250 | - '') |
|
251 | - ) |
|
252 | - )); |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * Updates the provided EE_Transaction with all the applicable payments |
|
258 | - * (or fetch the EE_Transaction from its ID) |
|
259 | - * |
|
260 | - * @deprecated |
|
261 | - * |
|
262 | - * @param EE_Transaction|int $transaction_obj_or_id |
|
263 | - * @param boolean $save_txn whether or not to save the transaction during this function call |
|
264 | - * |
|
265 | - * @return boolean |
|
266 | - * @throws \EE_Error |
|
267 | - */ |
|
268 | - public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
269 | - { |
|
270 | - EE_Error::doing_it_wrong( |
|
271 | - __CLASS__ . '::' . __FUNCTION__, |
|
272 | - sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
273 | - 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'), |
|
274 | - '4.6.0' |
|
275 | - ); |
|
276 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
277 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
278 | - |
|
279 | - return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
280 | - $this->ensure_is_obj($transaction_obj_or_id) |
|
281 | - ); |
|
282 | - } |
|
283 | - |
|
284 | - /** |
|
285 | - * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
286 | - * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
287 | - * and so we only use wpdb directly and only do minimal joins. |
|
288 | - * Transactions are considered "junk" if they're failed for longer than a week. |
|
289 | - * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
290 | - * it, it's probably not junk (regardless of what status it has). |
|
291 | - * The downside to this approach is that is addons are listening for object deletions |
|
292 | - * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
293 | - * to catch these types of deletions. |
|
294 | - * |
|
295 | - * @global WPDB $wpdb |
|
296 | - * @return mixed |
|
297 | - */ |
|
298 | - public function delete_junk_transactions() |
|
299 | - { |
|
300 | - /** @type WPDB $wpdb */ |
|
301 | - global $wpdb; |
|
302 | - $deleted = false; |
|
303 | - $time_to_leave_alone = apply_filters( |
|
304 | - 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone' |
|
305 | - , WEEK_IN_SECONDS |
|
306 | - ); |
|
307 | - |
|
308 | - |
|
309 | - /** |
|
310 | - * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
311 | - * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
312 | - * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
313 | - */ |
|
314 | - $ids_query = apply_filters( |
|
315 | - 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
316 | - array( |
|
317 | - 0 => array( |
|
318 | - 'STS_ID' => EEM_Transaction::failed_status_code, |
|
319 | - 'Payment.PAY_ID' => array( 'IS NULL' ), |
|
320 | - 'TXN_timestamp' => array('<', time() - $time_to_leave_alone) |
|
321 | - ) |
|
322 | - ), |
|
323 | - $time_to_leave_alone |
|
324 | - ); |
|
325 | - |
|
326 | - |
|
327 | - /** |
|
328 | - * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
329 | - * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
330 | - */ |
|
331 | - $txn_ids = apply_filters( |
|
332 | - 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
333 | - EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
334 | - $time_to_leave_alone |
|
335 | - ); |
|
336 | - //now that we have the ids to delete |
|
337 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
338 | - // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
339 | - EEM_Transaction::unset_locked_transactions($txn_ids); |
|
340 | - // let's get deletin'... |
|
341 | - // Why no wpdb->prepare? Because the data is trusted. |
|
342 | - // We got the ids from the original query to get them FROM |
|
343 | - // the db (which is sanitized) so no need to prepare them again. |
|
344 | - $query = ' |
|
231 | + OBJECT |
|
232 | + ); |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
238 | + * $_REQUEST global variable. Either way, tries to find the current transaction (through |
|
239 | + * the registration pointed to by reg_url_link), if not returns null |
|
240 | + * |
|
241 | + * @param string $reg_url_link |
|
242 | + * |
|
243 | + * @return EE_Transaction |
|
244 | + */ |
|
245 | + public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
246 | + { |
|
247 | + return $this->get_one(array( |
|
248 | + array( |
|
249 | + 'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get('e_reg_url_link', |
|
250 | + '') |
|
251 | + ) |
|
252 | + )); |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * Updates the provided EE_Transaction with all the applicable payments |
|
258 | + * (or fetch the EE_Transaction from its ID) |
|
259 | + * |
|
260 | + * @deprecated |
|
261 | + * |
|
262 | + * @param EE_Transaction|int $transaction_obj_or_id |
|
263 | + * @param boolean $save_txn whether or not to save the transaction during this function call |
|
264 | + * |
|
265 | + * @return boolean |
|
266 | + * @throws \EE_Error |
|
267 | + */ |
|
268 | + public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
269 | + { |
|
270 | + EE_Error::doing_it_wrong( |
|
271 | + __CLASS__ . '::' . __FUNCTION__, |
|
272 | + sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
273 | + 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'), |
|
274 | + '4.6.0' |
|
275 | + ); |
|
276 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
277 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
278 | + |
|
279 | + return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
280 | + $this->ensure_is_obj($transaction_obj_or_id) |
|
281 | + ); |
|
282 | + } |
|
283 | + |
|
284 | + /** |
|
285 | + * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
286 | + * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
287 | + * and so we only use wpdb directly and only do minimal joins. |
|
288 | + * Transactions are considered "junk" if they're failed for longer than a week. |
|
289 | + * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
290 | + * it, it's probably not junk (regardless of what status it has). |
|
291 | + * The downside to this approach is that is addons are listening for object deletions |
|
292 | + * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
293 | + * to catch these types of deletions. |
|
294 | + * |
|
295 | + * @global WPDB $wpdb |
|
296 | + * @return mixed |
|
297 | + */ |
|
298 | + public function delete_junk_transactions() |
|
299 | + { |
|
300 | + /** @type WPDB $wpdb */ |
|
301 | + global $wpdb; |
|
302 | + $deleted = false; |
|
303 | + $time_to_leave_alone = apply_filters( |
|
304 | + 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone' |
|
305 | + , WEEK_IN_SECONDS |
|
306 | + ); |
|
307 | + |
|
308 | + |
|
309 | + /** |
|
310 | + * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
311 | + * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
312 | + * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
313 | + */ |
|
314 | + $ids_query = apply_filters( |
|
315 | + 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
316 | + array( |
|
317 | + 0 => array( |
|
318 | + 'STS_ID' => EEM_Transaction::failed_status_code, |
|
319 | + 'Payment.PAY_ID' => array( 'IS NULL' ), |
|
320 | + 'TXN_timestamp' => array('<', time() - $time_to_leave_alone) |
|
321 | + ) |
|
322 | + ), |
|
323 | + $time_to_leave_alone |
|
324 | + ); |
|
325 | + |
|
326 | + |
|
327 | + /** |
|
328 | + * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
329 | + * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
330 | + */ |
|
331 | + $txn_ids = apply_filters( |
|
332 | + 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
333 | + EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
334 | + $time_to_leave_alone |
|
335 | + ); |
|
336 | + //now that we have the ids to delete |
|
337 | + if (! empty($txn_ids) && is_array($txn_ids)) { |
|
338 | + // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
339 | + EEM_Transaction::unset_locked_transactions($txn_ids); |
|
340 | + // let's get deletin'... |
|
341 | + // Why no wpdb->prepare? Because the data is trusted. |
|
342 | + // We got the ids from the original query to get them FROM |
|
343 | + // the db (which is sanitized) so no need to prepare them again. |
|
344 | + $query = ' |
|
345 | 345 | DELETE |
346 | 346 | FROM ' . $this->table() . ' |
347 | 347 | WHERE |
348 | 348 | TXN_ID IN ( ' . implode(",", $txn_ids) . ')'; |
349 | - $deleted = $wpdb->query($query); |
|
350 | - } |
|
351 | - if ($deleted) { |
|
352 | - /** |
|
353 | - * Allows code to do something after the transactions have been deleted. |
|
354 | - */ |
|
355 | - do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
356 | - } |
|
357 | - |
|
358 | - return $deleted; |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * @param array $transaction_IDs |
|
364 | - * |
|
365 | - * @return bool |
|
366 | - */ |
|
367 | - public static function unset_locked_transactions(array $transaction_IDs) |
|
368 | - { |
|
369 | - $locked_transactions = get_option('ee_locked_transactions', array()); |
|
370 | - $update = false; |
|
371 | - foreach ($transaction_IDs as $TXN_ID) { |
|
372 | - if (isset($locked_transactions[$TXN_ID])) { |
|
373 | - unset($locked_transactions[$TXN_ID]); |
|
374 | - $update = true; |
|
375 | - } |
|
376 | - } |
|
377 | - if ($update) { |
|
378 | - update_option('ee_locked_transactions', $locked_transactions); |
|
379 | - } |
|
380 | - |
|
381 | - return $update; |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - |
|
386 | - /** |
|
387 | - * returns an array of EE_Transaction objects whose timestamp is less than |
|
388 | - * the current time minus the session lifespan, which defaults to 60 minutes |
|
389 | - * |
|
390 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
391 | - * @throws \EE_Error |
|
392 | - */ |
|
393 | - public function get_transactions_in_progress() |
|
394 | - { |
|
395 | - return $this->get_all( |
|
396 | - array( |
|
397 | - array( |
|
398 | - 'TXN_timestamp' => array( |
|
399 | - '>', |
|
400 | - time() - EE_Registry::instance()->SSN->lifespan() |
|
401 | - ), |
|
402 | - 'STS_ID' => array( |
|
403 | - '!=', |
|
404 | - EEM_Transaction::complete_status_code |
|
405 | - ), |
|
406 | - ) |
|
407 | - ) |
|
408 | - ); |
|
409 | - } |
|
349 | + $deleted = $wpdb->query($query); |
|
350 | + } |
|
351 | + if ($deleted) { |
|
352 | + /** |
|
353 | + * Allows code to do something after the transactions have been deleted. |
|
354 | + */ |
|
355 | + do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
356 | + } |
|
357 | + |
|
358 | + return $deleted; |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * @param array $transaction_IDs |
|
364 | + * |
|
365 | + * @return bool |
|
366 | + */ |
|
367 | + public static function unset_locked_transactions(array $transaction_IDs) |
|
368 | + { |
|
369 | + $locked_transactions = get_option('ee_locked_transactions', array()); |
|
370 | + $update = false; |
|
371 | + foreach ($transaction_IDs as $TXN_ID) { |
|
372 | + if (isset($locked_transactions[$TXN_ID])) { |
|
373 | + unset($locked_transactions[$TXN_ID]); |
|
374 | + $update = true; |
|
375 | + } |
|
376 | + } |
|
377 | + if ($update) { |
|
378 | + update_option('ee_locked_transactions', $locked_transactions); |
|
379 | + } |
|
380 | + |
|
381 | + return $update; |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + |
|
386 | + /** |
|
387 | + * returns an array of EE_Transaction objects whose timestamp is less than |
|
388 | + * the current time minus the session lifespan, which defaults to 60 minutes |
|
389 | + * |
|
390 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
391 | + * @throws \EE_Error |
|
392 | + */ |
|
393 | + public function get_transactions_in_progress() |
|
394 | + { |
|
395 | + return $this->get_all( |
|
396 | + array( |
|
397 | + array( |
|
398 | + 'TXN_timestamp' => array( |
|
399 | + '>', |
|
400 | + time() - EE_Registry::instance()->SSN->lifespan() |
|
401 | + ), |
|
402 | + 'STS_ID' => array( |
|
403 | + '!=', |
|
404 | + EEM_Transaction::complete_status_code |
|
405 | + ), |
|
406 | + ) |
|
407 | + ) |
|
408 | + ); |
|
409 | + } |
|
410 | 410 | |
411 | 411 | |
412 | 412 | } |