@@ -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,7 +1,9 @@ |
||
1 | 1 | <?php |
2 | 2 | use EventEspresso\core\interfaces\InterminableInterface; |
3 | 3 | |
4 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
4 | +if ( ! defined( 'EVENT_ESPRESSO_VERSION')) { |
|
5 | + exit('No direct script access allowed'); |
|
6 | +} |
|
5 | 7 | /** |
6 | 8 | * Event Espresso |
7 | 9 | * |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | use EventEspresso\core\interfaces\InterminableInterface; |
3 | 3 | |
4 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
5 | 5 | /** |
6 | 6 | * Event Espresso |
7 | 7 | * |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public static function instance() { |
45 | 45 | // check if class object is instantiated |
46 | - if ( ! self::$_instance instanceof EE_Admin ) { |
|
46 | + if ( ! self::$_instance instanceof EE_Admin) { |
|
47 | 47 | self::$_instance = new self(); |
48 | 48 | } |
49 | 49 | return self::$_instance; |
@@ -70,25 +70,25 @@ discard block |
||
70 | 70 | // define global EE_Admin constants |
71 | 71 | $this->_define_all_constants(); |
72 | 72 | // set autoloaders for our admin page classes based on included path information |
73 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder( EE_ADMIN ); |
|
73 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN); |
|
74 | 74 | // admin hooks |
75 | - add_filter( 'plugin_action_links', array( $this, 'filter_plugin_actions' ), 10, 2 ); |
|
75 | + add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2); |
|
76 | 76 | // load EE_Request_Handler early |
77 | - add_action( 'AHEE__EE_System__core_loaded_and_ready', array( $this, 'get_request' )); |
|
78 | - add_action( 'AHEE__EE_System__initialize_last', array( $this, 'init' )); |
|
79 | - add_action( 'AHEE__EE_Admin_Page__route_admin_request', array( $this, 'route_admin_request' ), 100, 2 ); |
|
80 | - add_action( 'wp_loaded', array( $this, 'wp_loaded' ), 100 ); |
|
81 | - add_action( 'admin_init', array( $this, 'admin_init' ), 100 ); |
|
82 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ), 20 ); |
|
83 | - add_action( 'admin_notices', array( $this, 'display_admin_notices' ), 10 ); |
|
84 | - add_action( 'network_admin_notices', array( $this, 'display_admin_notices' ), 10 ); |
|
85 | - add_filter( 'pre_update_option', array( $this, 'check_for_invalid_datetime_formats' ), 100, 2 ); |
|
86 | - add_filter('admin_footer_text', array( $this, 'espresso_admin_footer' )); |
|
77 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request')); |
|
78 | + add_action('AHEE__EE_System__initialize_last', array($this, 'init')); |
|
79 | + add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2); |
|
80 | + add_action('wp_loaded', array($this, 'wp_loaded'), 100); |
|
81 | + add_action('admin_init', array($this, 'admin_init'), 100); |
|
82 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20); |
|
83 | + add_action('admin_notices', array($this, 'display_admin_notices'), 10); |
|
84 | + add_action('network_admin_notices', array($this, 'display_admin_notices'), 10); |
|
85 | + add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2); |
|
86 | + add_filter('admin_footer_text', array($this, 'espresso_admin_footer')); |
|
87 | 87 | |
88 | 88 | //reset Environment config (we only do this on admin page loads); |
89 | 89 | EE_Registry::instance()->CFG->environment->recheck_values(); |
90 | 90 | |
91 | - do_action( 'AHEE__EE_Admin__loaded' ); |
|
91 | + do_action('AHEE__EE_Admin__loaded'); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | |
@@ -103,12 +103,12 @@ discard block |
||
103 | 103 | * @return void |
104 | 104 | */ |
105 | 105 | private function _define_all_constants() { |
106 | - if ( ! defined( 'EE_ADMIN_URL' ) ) { |
|
107 | - define( 'EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/' ); |
|
108 | - define( 'EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/' ); |
|
109 | - define( 'EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS ); |
|
110 | - define( 'WP_ADMIN_PATH', ABSPATH . 'wp-admin/' ); |
|
111 | - define( 'WP_AJAX_URL', admin_url( 'admin-ajax.php' ) ); |
|
106 | + if ( ! defined('EE_ADMIN_URL')) { |
|
107 | + define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL.'core/admin/'); |
|
108 | + define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL.'admin_pages/'); |
|
109 | + define('EE_ADMIN_TEMPLATE', EE_ADMIN.'templates'.DS); |
|
110 | + define('WP_ADMIN_PATH', ABSPATH.'wp-admin/'); |
|
111 | + define('WP_AJAX_URL', admin_url('admin-ajax.php')); |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
@@ -122,23 +122,23 @@ discard block |
||
122 | 122 | * @param string $plugin |
123 | 123 | * @return array |
124 | 124 | */ |
125 | - public function filter_plugin_actions( $links, $plugin ) { |
|
125 | + public function filter_plugin_actions($links, $plugin) { |
|
126 | 126 | // set $main_file in stone |
127 | 127 | static $main_file; |
128 | 128 | // if $main_file is not set yet |
129 | - if ( ! $main_file ) { |
|
130 | - $main_file = plugin_basename( EVENT_ESPRESSO_MAIN_FILE ); |
|
129 | + if ( ! $main_file) { |
|
130 | + $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE); |
|
131 | 131 | } |
132 | - if ( $plugin === $main_file ) { |
|
132 | + if ($plugin === $main_file) { |
|
133 | 133 | // compare current plugin to this one |
134 | - if ( EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance ) { |
|
135 | - $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings" title="Event Espresso is in maintenance mode. Click this link to learn why.">' . __('Maintenance Mode Active', 'event_espresso' ) . '</a>'; |
|
136 | - array_unshift( $links, $maintenance_link ); |
|
134 | + if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
135 | + $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings" title="Event Espresso is in maintenance mode. Click this link to learn why.">'.__('Maintenance Mode Active', 'event_espresso').'</a>'; |
|
136 | + array_unshift($links, $maintenance_link); |
|
137 | 137 | } else { |
138 | - $org_settings_link = '<a href="admin.php?page=espresso_general_settings">' . __( 'Settings', 'event_espresso' ) . '</a>'; |
|
139 | - $events_link = '<a href="admin.php?page=espresso_events">' . __( 'Events', 'event_espresso' ) . '</a>'; |
|
138 | + $org_settings_link = '<a href="admin.php?page=espresso_general_settings">'.__('Settings', 'event_espresso').'</a>'; |
|
139 | + $events_link = '<a href="admin.php?page=espresso_events">'.__('Events', 'event_espresso').'</a>'; |
|
140 | 140 | // add before other links |
141 | - array_unshift( $links, $org_settings_link, $events_link ); |
|
141 | + array_unshift($links, $org_settings_link, $events_link); |
|
142 | 142 | } |
143 | 143 | } |
144 | 144 | return $links; |
@@ -153,8 +153,8 @@ discard block |
||
153 | 153 | * @return void |
154 | 154 | */ |
155 | 155 | public function get_request() { |
156 | - EE_Registry::instance()->load_core( 'Request_Handler' ); |
|
157 | - EE_Registry::instance()->load_core( 'CPT_Strategy' ); |
|
156 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
157 | + EE_Registry::instance()->load_core('CPT_Strategy'); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | |
@@ -166,11 +166,11 @@ discard block |
||
166 | 166 | * @param array $admin_page_folder_names |
167 | 167 | * @return array |
168 | 168 | */ |
169 | - public function hide_admin_pages_except_maintenance_mode( $admin_page_folder_names = array() ){ |
|
169 | + public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array()) { |
|
170 | 170 | return array( |
171 | - 'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS, |
|
172 | - 'about' => EE_ADMIN_PAGES . 'about' . DS, |
|
173 | - 'support' => EE_ADMIN_PAGES . 'support' . DS |
|
171 | + 'maintenance' => EE_ADMIN_PAGES.'maintenance'.DS, |
|
172 | + 'about' => EE_ADMIN_PAGES.'about'.DS, |
|
173 | + 'support' => EE_ADMIN_PAGES.'support'.DS |
|
174 | 174 | ); |
175 | 175 | } |
176 | 176 | |
@@ -184,31 +184,31 @@ discard block |
||
184 | 184 | */ |
185 | 185 | public function init() { |
186 | 186 | //only enable most of the EE_Admin IF we're not in full maintenance mode |
187 | - if ( EE_Maintenance_Mode::instance()->models_can_query() ){ |
|
187 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
188 | 188 | //ok so we want to enable the entire admin |
189 | - add_action( 'wp_ajax_dismiss_ee_nag_notice', array( $this, 'dismiss_ee_nag_notice_callback' )); |
|
190 | - add_action( 'admin_notices', array( $this, 'get_persistent_admin_notices' ), 9 ); |
|
191 | - add_action( 'network_admin_notices', array( $this, 'get_persistent_admin_notices' ), 9 ); |
|
189 | + add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismiss_ee_nag_notice_callback')); |
|
190 | + add_action('admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
191 | + add_action('network_admin_notices', array($this, 'get_persistent_admin_notices'), 9); |
|
192 | 192 | //at a glance dashboard widget |
193 | - add_filter( 'dashboard_glance_items', array( $this, 'dashboard_glance_items' ), 10 ); |
|
193 | + add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10); |
|
194 | 194 | //filter for get_edit_post_link used on comments for custom post types |
195 | - add_filter( 'get_edit_post_link', array( $this, 'modify_edit_post_link' ), 10, 2 ); |
|
195 | + add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2); |
|
196 | 196 | } |
197 | 197 | // run the admin page factory but ONLY if we are doing an ee admin ajax request |
198 | - if ( !defined('DOING_AJAX') || EE_ADMIN_AJAX ) { |
|
198 | + if ( ! defined('DOING_AJAX') || EE_ADMIN_AJAX) { |
|
199 | 199 | try { |
200 | 200 | //this loads the controller for the admin pages which will setup routing etc |
201 | - EE_Registry::instance()->load_core( 'Admin_Page_Loader' ); |
|
202 | - } catch ( EE_Error $e ) { |
|
201 | + EE_Registry::instance()->load_core('Admin_Page_Loader'); |
|
202 | + } catch (EE_Error $e) { |
|
203 | 203 | $e->get_error(); |
204 | 204 | } |
205 | 205 | } |
206 | - add_filter( 'content_save_pre', array( $this, 'its_eSpresso' ), 10, 1 ); |
|
206 | + add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1); |
|
207 | 207 | //make sure our CPTs and custom taxonomy metaboxes get shown for first time users |
208 | - add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes' ), 10 ); |
|
209 | - add_action('admin_head', array( $this, 'register_custom_nav_menu_boxes' ), 10 ); |
|
208 | + add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10); |
|
209 | + add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10); |
|
210 | 210 | //exclude EE critical pages from all nav menus and wp_list_pages |
211 | - add_filter('nav_menu_meta_box_object', array( $this, 'remove_pages_from_nav_menu'), 10 ); |
|
211 | + add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | |
@@ -221,9 +221,9 @@ discard block |
||
221 | 221 | * @param object $post_type WP post type object |
222 | 222 | * @return object WP post type object |
223 | 223 | */ |
224 | - public function remove_pages_from_nav_menu( $post_type ) { |
|
224 | + public function remove_pages_from_nav_menu($post_type) { |
|
225 | 225 | //if this isn't the "pages" post type let's get out |
226 | - if ( $post_type->name !== 'page' ) { |
|
226 | + if ($post_type->name !== 'page') { |
|
227 | 227 | return $post_type; |
228 | 228 | } |
229 | 229 | $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
@@ -243,28 +243,28 @@ discard block |
||
243 | 243 | */ |
244 | 244 | public function enable_hidden_ee_nav_menu_metaboxes() { |
245 | 245 | global $wp_meta_boxes, $pagenow; |
246 | - if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php' ) { |
|
246 | + if ( ! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') { |
|
247 | 247 | return; |
248 | 248 | } |
249 | 249 | $user = wp_get_current_user(); |
250 | 250 | //has this been done yet? |
251 | - if ( get_user_option( 'ee_nav_menu_initialized', $user->ID ) ) { |
|
251 | + if (get_user_option('ee_nav_menu_initialized', $user->ID)) { |
|
252 | 252 | return; |
253 | 253 | } |
254 | 254 | |
255 | - $hidden_meta_boxes = get_user_option( 'metaboxhidden_nav-menus', $user->ID ); |
|
256 | - $initial_meta_boxes = apply_filters( 'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', array( 'nav-menu-theme-locations', 'add-page', 'add-custom-links', 'add-category', 'add-espresso_events', 'add-espresso_venues', 'add-espresso_event_categories', 'add-espresso_venue_categories', 'add-post-type-post', 'add-post-type-page' ) ); |
|
255 | + $hidden_meta_boxes = get_user_option('metaboxhidden_nav-menus', $user->ID); |
|
256 | + $initial_meta_boxes = apply_filters('FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes', array('nav-menu-theme-locations', 'add-page', 'add-custom-links', 'add-category', 'add-espresso_events', 'add-espresso_venues', 'add-espresso_event_categories', 'add-espresso_venue_categories', 'add-post-type-post', 'add-post-type-page')); |
|
257 | 257 | |
258 | - if ( is_array( $hidden_meta_boxes ) ) { |
|
259 | - foreach ( $hidden_meta_boxes as $key => $meta_box_id ) { |
|
260 | - if ( in_array( $meta_box_id, $initial_meta_boxes ) ) { |
|
261 | - unset( $hidden_meta_boxes[ $key ] ); |
|
258 | + if (is_array($hidden_meta_boxes)) { |
|
259 | + foreach ($hidden_meta_boxes as $key => $meta_box_id) { |
|
260 | + if (in_array($meta_box_id, $initial_meta_boxes)) { |
|
261 | + unset($hidden_meta_boxes[$key]); |
|
262 | 262 | } |
263 | 263 | } |
264 | 264 | } |
265 | 265 | |
266 | - update_user_option( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true ); |
|
267 | - update_user_option( $user->ID, 'ee_nav_menu_initialized', 1, true ); |
|
266 | + update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true); |
|
267 | + update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * @return void |
284 | 284 | */ |
285 | 285 | public function register_custom_nav_menu_boxes() { |
286 | - add_meta_box( 'add-extra-nav-menu-pages', __('Event Espresso Pages', 'event_espresso'), array( $this, 'ee_cpt_archive_pages' ), 'nav-menus', 'side', 'core' ); |
|
286 | + add_meta_box('add-extra-nav-menu-pages', __('Event Espresso Pages', 'event_espresso'), array($this, 'ee_cpt_archive_pages'), 'nav-menus', 'side', 'core'); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | |
@@ -299,16 +299,16 @@ discard block |
||
299 | 299 | * |
300 | 300 | * @return string the (maybe) modified link |
301 | 301 | */ |
302 | - public function modify_edit_post_link( $link, $id ) { |
|
303 | - if ( ! $post = get_post( $id ) ){ |
|
302 | + public function modify_edit_post_link($link, $id) { |
|
303 | + if ( ! $post = get_post($id)) { |
|
304 | 304 | return $link; |
305 | 305 | } |
306 | - if ( $post->post_type === 'espresso_attendees' ) { |
|
306 | + if ($post->post_type === 'espresso_attendees') { |
|
307 | 307 | $query_args = array( |
308 | 308 | 'action' => 'edit_attendee', |
309 | 309 | 'post' => $id |
310 | 310 | ); |
311 | - return EEH_URL::add_query_args_and_nonce( $query_args, admin_url('admin.php?page=espresso_registrations') ); |
|
311 | + return EEH_URL::add_query_args_and_nonce($query_args, admin_url('admin.php?page=espresso_registrations')); |
|
312 | 312 | } |
313 | 313 | return $link; |
314 | 314 | } |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | global $nav_menu_selected_id; |
321 | 321 | |
322 | 322 | $db_fields = false; |
323 | - $walker = new Walker_Nav_Menu_Checklist( $db_fields ); |
|
323 | + $walker = new Walker_Nav_Menu_Checklist($db_fields); |
|
324 | 324 | $current_tab = 'event-archives'; |
325 | 325 | |
326 | 326 | /*if ( ! empty( $_REQUEST['quick-search-posttype-' . $post_type_name] ) ) { |
@@ -339,9 +339,9 @@ discard block |
||
339 | 339 | ?> |
340 | 340 | <div id="posttype-extra-nav-menu-pages" class="posttypediv"> |
341 | 341 | <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs"> |
342 | - <li <?php echo ( 'event-archives' === $current_tab ? ' class="tabs"' : '' ); ?>> |
|
343 | - <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" href="<?php if ( $nav_menu_selected_id ) {echo esc_url(add_query_arg('extra-nav-menu-pages-tab', 'event-archives', remove_query_arg($removed_args)));} ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
344 | - <?php _e( 'Event Archive Pages', 'event_espresso' ); ?> |
|
342 | + <li <?php echo ('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>> |
|
343 | + <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives" href="<?php if ($nav_menu_selected_id) {echo esc_url(add_query_arg('extra-nav-menu-pages-tab', 'event-archives', remove_query_arg($removed_args))); } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives"> |
|
344 | + <?php _e('Event Archive Pages', 'event_espresso'); ?> |
|
345 | 345 | </a> |
346 | 346 | </li> |
347 | 347 | <?php /* // temporarily removing but leaving skeleton in place in case we ever decide to add more tabs. |
@@ -359,13 +359,13 @@ discard block |
||
359 | 359 | <?php */ ?> |
360 | 360 | |
361 | 361 | <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php |
362 | - echo ( 'event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); |
|
362 | + echo ('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive'); |
|
363 | 363 | ?>"> |
364 | 364 | <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear"> |
365 | 365 | <?php |
366 | 366 | $pages = $this->_get_extra_nav_menu_pages_items(); |
367 | 367 | $args['walker'] = $walker; |
368 | - echo walk_nav_menu_tree( array_map( array( $this, '_setup_extra_nav_menu_pages_items' ), $pages), 0, (object) $args ); |
|
368 | + echo walk_nav_menu_tree(array_map(array($this, '_setup_extra_nav_menu_pages_items'), $pages), 0, (object) $args); |
|
369 | 369 | ?> |
370 | 370 | </ul> |
371 | 371 | </div><!-- /.tabs-panel --> |
@@ -373,18 +373,18 @@ discard block |
||
373 | 373 | <p class="button-controls"> |
374 | 374 | <span class="list-controls"> |
375 | 375 | <a href="<?php |
376 | - echo esc_url( add_query_arg( |
|
376 | + echo esc_url(add_query_arg( |
|
377 | 377 | array( |
378 | 378 | 'extra-nav-menu-pages-tab' => 'event-archives', |
379 | 379 | 'selectall' => 1, |
380 | 380 | ), |
381 | - remove_query_arg( $removed_args ) |
|
381 | + remove_query_arg($removed_args) |
|
382 | 382 | )); |
383 | 383 | ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a> |
384 | 384 | </span> |
385 | 385 | |
386 | 386 | <span class="add-to-menu"> |
387 | - <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( __( 'Add to Menu' ) ); ?>" name="add-post-type-menu-item" id="<?php esc_attr_e( 'submit-posttype-extra-nav-menu-pages' ); ?>" /> |
|
387 | + <input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e(__('Add to Menu')); ?>" name="add-post-type-menu-item" id="<?php esc_attr_e('submit-posttype-extra-nav-menu-pages'); ?>" /> |
|
388 | 388 | <span class="spinner"></span> |
389 | 389 | </span> |
390 | 390 | </p> |
@@ -405,10 +405,10 @@ discard block |
||
405 | 405 | private function _get_extra_nav_menu_pages_items() { |
406 | 406 | $menuitems[] = array( |
407 | 407 | 'title' => __('Event List', 'event_espresso'), |
408 | - 'url' => get_post_type_archive_link( 'espresso_events' ), |
|
408 | + 'url' => get_post_type_archive_link('espresso_events'), |
|
409 | 409 | 'description' => __('Archive page for all events.', 'event_espresso') |
410 | 410 | ); |
411 | - return apply_filters( 'FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems ); |
|
411 | + return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems); |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | * @param $menu_item_values |
421 | 421 | * @return stdClass |
422 | 422 | */ |
423 | - private function _setup_extra_nav_menu_pages_items( $menu_item_values ) { |
|
423 | + private function _setup_extra_nav_menu_pages_items($menu_item_values) { |
|
424 | 424 | $menu_item = new stdClass(); |
425 | 425 | $keys = array( |
426 | 426 | 'ID' => 0, |
@@ -440,8 +440,8 @@ discard block |
||
440 | 440 | 'xfn' => '' |
441 | 441 | ); |
442 | 442 | |
443 | - foreach ( $keys as $key => $value) { |
|
444 | - $menu_item->{$key} = isset( $menu_item_values[ $key]) ? $menu_item_values[ $key] : $value; |
|
443 | + foreach ($keys as $key => $value) { |
|
444 | + $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value; |
|
445 | 445 | } |
446 | 446 | return $menu_item; |
447 | 447 | } |
@@ -480,9 +480,9 @@ discard block |
||
480 | 480 | * - check if doing post processing of one of EE CPTs |
481 | 481 | * - instantiate the corresponding EE CPT model for the post_type being processed. |
482 | 482 | */ |
483 | - if ( isset( $_POST['action'], $_POST['post_type'] ) && $_POST['action'] === 'editpost' ) { |
|
484 | - EE_Registry::instance()->load_core( 'Register_CPTs' ); |
|
485 | - EE_Register_CPTs::instantiate_cpt_models( $_POST['post_type'] ); |
|
483 | + if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') { |
|
484 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
485 | + EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']); |
|
486 | 486 | } |
487 | 487 | |
488 | 488 | |
@@ -492,7 +492,7 @@ discard block |
||
492 | 492 | * tab in the EE General Settings Admin page. |
493 | 493 | * This is for user-proofing. |
494 | 494 | */ |
495 | - add_filter( 'wp_dropdown_pages', array( $this, 'modify_dropdown_pages' ) ); |
|
495 | + add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages')); |
|
496 | 496 | |
497 | 497 | } |
498 | 498 | |
@@ -503,25 +503,25 @@ discard block |
||
503 | 503 | * @param string $output Current output. |
504 | 504 | * @return string |
505 | 505 | */ |
506 | - public function modify_dropdown_pages( $output ) { |
|
506 | + public function modify_dropdown_pages($output) { |
|
507 | 507 | //get critical pages |
508 | 508 | $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array(); |
509 | 509 | |
510 | 510 | //split current output by line break for easier parsing. |
511 | - $split_output = explode( "\n", $output ); |
|
511 | + $split_output = explode("\n", $output); |
|
512 | 512 | |
513 | 513 | //loop through to remove any critical pages from the array. |
514 | - foreach ( $critical_pages as $page_id ) { |
|
515 | - $needle = 'value="' . $page_id . '"'; |
|
516 | - foreach( $split_output as $key => $haystack ) { |
|
517 | - if( strpos( $haystack, $needle ) !== false ) { |
|
518 | - unset( $split_output[$key] ); |
|
514 | + foreach ($critical_pages as $page_id) { |
|
515 | + $needle = 'value="'.$page_id.'"'; |
|
516 | + foreach ($split_output as $key => $haystack) { |
|
517 | + if (strpos($haystack, $needle) !== false) { |
|
518 | + unset($split_output[$key]); |
|
519 | 519 | } |
520 | 520 | } |
521 | 521 | } |
522 | 522 | |
523 | 523 | //replace output with the new contents |
524 | - return implode( "\n", $split_output ); |
|
524 | + return implode("\n", $split_output); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | |
@@ -535,17 +535,17 @@ discard block |
||
535 | 535 | public function enqueue_admin_scripts() { |
536 | 536 | // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js. |
537 | 537 | // Note: the intention of this script is to only do TARGETED injections. I.E, only injecting on certain script calls. |
538 | - wp_enqueue_script('ee-inject-wp', EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE); |
|
538 | + wp_enqueue_script('ee-inject-wp', EE_ADMIN_URL.'assets/ee-cpt-wp-injects.js', array('jquery'), EVENT_ESPRESSO_VERSION, TRUE); |
|
539 | 539 | // register cookie script for future dependencies |
540 | - wp_register_script('jquery-cookie', EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js', array('jquery'), '2.1', TRUE ); |
|
540 | + wp_register_script('jquery-cookie', EE_THIRD_PARTY_URL.'joyride/jquery.cookie.js', array('jquery'), '2.1', TRUE); |
|
541 | 541 | //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again vai: add_filter('FHEE_load_joyride', '__return_true' ); |
542 | - if ( apply_filters( 'FHEE_load_joyride', FALSE ) ) { |
|
542 | + if (apply_filters('FHEE_load_joyride', FALSE)) { |
|
543 | 543 | //joyride style |
544 | - wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1'); |
|
545 | - wp_register_style('ee-joyride-css', EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css', array('joyride-css'), EVENT_ESPRESSO_VERSION ); |
|
546 | - wp_register_script('joyride-modernizr', EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js', array(), '2.1', TRUE ); |
|
544 | + wp_register_style('joyride-css', EE_THIRD_PARTY_URL.'joyride/joyride-2.1.css', array(), '2.1'); |
|
545 | + wp_register_style('ee-joyride-css', EE_GLOBAL_ASSETS_URL.'css/ee-joyride-styles.css', array('joyride-css'), EVENT_ESPRESSO_VERSION); |
|
546 | + wp_register_script('joyride-modernizr', EE_THIRD_PARTY_URL.'joyride/modernizr.mq.js', array(), '2.1', TRUE); |
|
547 | 547 | //joyride JS |
548 | - wp_register_script('jquery-joyride', EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js', array('jquery-cookie', 'joyride-modernizr'), '2.1', TRUE ); |
|
548 | + wp_register_script('jquery-joyride', EE_THIRD_PARTY_URL.'joyride/jquery.joyride-2.1.js', array('jquery-cookie', 'joyride-modernizr'), '2.1', TRUE); |
|
549 | 549 | // wanna go for a joyride? |
550 | 550 | wp_enqueue_style('ee-joyride-css'); |
551 | 551 | wp_enqueue_script('jquery-joyride'); |
@@ -575,11 +575,11 @@ discard block |
||
575 | 575 | public function get_persistent_admin_notices() { |
576 | 576 | // http://www.example.com/wp-admin/admin.php?page=espresso_general_settings&action=critical_pages&critical_pages_nonce=2831ce0f30 |
577 | 577 | $args = array( |
578 | - 'page' => EE_Registry::instance()->REQ->is_set( 'page' ) ? EE_Registry::instance()->REQ->get( 'page' ) : '', |
|
579 | - 'action' => EE_Registry::instance()->REQ->is_set( 'action' ) ? EE_Registry::instance()->REQ->get( 'action' ) : '', |
|
578 | + 'page' => EE_Registry::instance()->REQ->is_set('page') ? EE_Registry::instance()->REQ->get('page') : '', |
|
579 | + 'action' => EE_Registry::instance()->REQ->is_set('action') ? EE_Registry::instance()->REQ->get('action') : '', |
|
580 | 580 | ); |
581 | - $return_url = EE_Admin_Page::add_query_args_and_nonce( $args, EE_ADMIN_URL ); |
|
582 | - echo EE_Error::get_persistent_admin_notices( $return_url ); |
|
581 | + $return_url = EE_Admin_Page::add_query_args_and_nonce($args, EE_ADMIN_URL); |
|
582 | + echo EE_Error::get_persistent_admin_notices($return_url); |
|
583 | 583 | } |
584 | 584 | |
585 | 585 | |
@@ -604,24 +604,24 @@ discard block |
||
604 | 604 | public function dashboard_glance_items($elements) { |
605 | 605 | $elements = is_array($elements) ? $elements : array($elements); |
606 | 606 | $events = EEM_Event::instance()->count(); |
607 | - $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce( array('page' => 'espresso_events'), admin_url('admin.php') ); |
|
608 | - $items['events']['text'] = sprintf( _n( '%s Event', '%s Events', $events ), number_format_i18n( $events ) ); |
|
607 | + $items['events']['url'] = EE_Admin_Page::add_query_args_and_nonce(array('page' => 'espresso_events'), admin_url('admin.php')); |
|
608 | + $items['events']['text'] = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events)); |
|
609 | 609 | $items['events']['title'] = __('Click to view all Events', 'event_espresso'); |
610 | 610 | $registrations = EEM_Registration::instance()->count( |
611 | 611 | array( |
612 | 612 | array( |
613 | - 'STS_ID' => array( '!=', EEM_Registration::status_id_incomplete ) |
|
613 | + 'STS_ID' => array('!=', EEM_Registration::status_id_incomplete) |
|
614 | 614 | ) |
615 | 615 | ) |
616 | 616 | ); |
617 | - $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce( array('page' => 'espresso_registrations' ), admin_url('admin.php') ); |
|
618 | - $items['registrations']['text'] = sprintf( _n( '%s Registration', '%s Registrations', $registrations ), number_format_i18n($registrations) ); |
|
617 | + $items['registrations']['url'] = EE_Admin_Page::add_query_args_and_nonce(array('page' => 'espresso_registrations'), admin_url('admin.php')); |
|
618 | + $items['registrations']['text'] = sprintf(_n('%s Registration', '%s Registrations', $registrations), number_format_i18n($registrations)); |
|
619 | 619 | $items['registrations']['title'] = __('Click to view all registrations', 'event_espresso'); |
620 | 620 | |
621 | - $items = (array) apply_filters( 'FHEE__EE_Admin__dashboard_glance_items__items', $items ); |
|
621 | + $items = (array) apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items); |
|
622 | 622 | |
623 | - foreach ( $items as $type => $item_properties ) { |
|
624 | - $elements[] = sprintf( '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>', $item_properties['url'], $item_properties['title'], $item_properties['text'] ); |
|
623 | + foreach ($items as $type => $item_properties) { |
|
624 | + $elements[] = sprintf('<a class="ee-dashboard-link-'.$type.'" href="%s" title="%s">%s</a>', $item_properties['url'], $item_properties['title'], $item_properties['text']); |
|
625 | 625 | } |
626 | 626 | return $elements; |
627 | 627 | } |
@@ -638,31 +638,31 @@ discard block |
||
638 | 638 | * @throws EE_Error |
639 | 639 | * @return string |
640 | 640 | */ |
641 | - public function check_for_invalid_datetime_formats( $value, $option ) { |
|
641 | + public function check_for_invalid_datetime_formats($value, $option) { |
|
642 | 642 | // check for date_format or time_format |
643 | - switch ( $option ) { |
|
643 | + switch ($option) { |
|
644 | 644 | case 'date_format' : |
645 | - $date_time_format = $value . ' ' . get_option('time_format'); |
|
645 | + $date_time_format = $value.' '.get_option('time_format'); |
|
646 | 646 | break; |
647 | 647 | case 'time_format' : |
648 | - $date_time_format = get_option('date_format') . ' ' . $value; |
|
648 | + $date_time_format = get_option('date_format').' '.$value; |
|
649 | 649 | break; |
650 | 650 | default : |
651 | 651 | $date_time_format = FALSE; |
652 | 652 | } |
653 | 653 | // do we have a date_time format to check ? |
654 | - if ( $date_time_format ) { |
|
655 | - $error_msg = EEH_DTT_Helper::validate_format_string( $date_time_format ); |
|
654 | + if ($date_time_format) { |
|
655 | + $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format); |
|
656 | 656 | |
657 | - if ( is_array( $error_msg ) ) { |
|
658 | - $msg = '<p>' . sprintf( __( 'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', 'event_espresso' ), date( $date_time_format ) , $date_time_format ) . '</p><p><ul>'; |
|
657 | + if (is_array($error_msg)) { |
|
658 | + $msg = '<p>'.sprintf(__('The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:', 'event_espresso'), date($date_time_format), $date_time_format).'</p><p><ul>'; |
|
659 | 659 | |
660 | 660 | |
661 | - foreach ( $error_msg as $error ) { |
|
662 | - $msg .= '<li>' . $error . '</li>'; |
|
661 | + foreach ($error_msg as $error) { |
|
662 | + $msg .= '<li>'.$error.'</li>'; |
|
663 | 663 | } |
664 | 664 | |
665 | - $msg .= '</ul></p><p>' . sprintf( __( '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', 'event_espresso' ), '<span style="color:#D54E21;">', '</span>' ) . '</p>'; |
|
665 | + $msg .= '</ul></p><p>'.sprintf(__('%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s', 'event_espresso'), '<span style="color:#D54E21;">', '</span>').'</p>'; |
|
666 | 666 | |
667 | 667 | // trigger WP settings error |
668 | 668 | add_settings_error( |
@@ -672,7 +672,7 @@ discard block |
||
672 | 672 | ); |
673 | 673 | |
674 | 674 | // set format to something valid |
675 | - switch ( $option ) { |
|
675 | + switch ($option) { |
|
676 | 676 | case 'date_format' : |
677 | 677 | $value = 'F j, Y'; |
678 | 678 | break; |
@@ -694,8 +694,8 @@ discard block |
||
694 | 694 | * @param $content |
695 | 695 | * @return string |
696 | 696 | */ |
697 | - public function its_eSpresso( $content ) { |
|
698 | - return str_replace( '[EXPRESSO_', '[ESPRESSO_', $content ); |
|
697 | + public function its_eSpresso($content) { |
|
698 | + return str_replace('[EXPRESSO_', '[ESPRESSO_', $content); |
|
699 | 699 | } |
700 | 700 | |
701 | 701 | |
@@ -707,7 +707,7 @@ discard block |
||
707 | 707 | * @return string |
708 | 708 | */ |
709 | 709 | public function espresso_admin_footer() { |
710 | - return \EEH_Template::powered_by_event_espresso( 'aln-cntr', '', array( 'utm_content' => 'admin_footer' )); |
|
710 | + return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer')); |
|
711 | 711 | } |
712 | 712 | |
713 | 713 | |
@@ -726,12 +726,12 @@ discard block |
||
726 | 726 | * @param array $config |
727 | 727 | * @return void |
728 | 728 | */ |
729 | - public static function register_ee_admin_page( $page_basename, $page_path, $config = array() ) { |
|
730 | - EE_Error::doing_it_wrong( __METHOD__, sprintf( __('Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', 'event_espresso'), $page_basename), '4.3' ); |
|
731 | - if ( class_exists( 'EE_Register_Admin_Page' ) ) { |
|
729 | + public static function register_ee_admin_page($page_basename, $page_path, $config = array()) { |
|
730 | + EE_Error::doing_it_wrong(__METHOD__, sprintf(__('Usage is deprecated. Use EE_Register_Admin_Page::register() for registering the %s admin page.', 'event_espresso'), $page_basename), '4.3'); |
|
731 | + if (class_exists('EE_Register_Admin_Page')) { |
|
732 | 732 | $config['page_path'] = $page_path; |
733 | 733 | } |
734 | - EE_Register_Admin_Page::register( $page_basename, $config ); |
|
734 | + EE_Register_Admin_Page::register($page_basename, $config); |
|
735 | 735 | |
736 | 736 | } |
737 | 737 | |
@@ -744,7 +744,7 @@ discard block |
||
744 | 744 | * @param \WP_Post $post |
745 | 745 | * @return void |
746 | 746 | */ |
747 | - public static function parse_post_content_on_save( $post_ID, $post ) { |
|
747 | + public static function parse_post_content_on_save($post_ID, $post) { |
|
748 | 748 | EE_Error::doing_it_wrong( |
749 | 749 | __METHOD__, |
750 | 750 | __('Usage is deprecated', 'event_espresso'), |
@@ -762,7 +762,7 @@ discard block |
||
762 | 762 | * @param $value |
763 | 763 | * @return void |
764 | 764 | */ |
765 | - public function reset_page_for_posts_on_change( $option, $old_value, $value ) { |
|
765 | + public function reset_page_for_posts_on_change($option, $old_value, $value) { |
|
766 | 766 | EE_Error::doing_it_wrong( |
767 | 767 | __METHOD__, |
768 | 768 | __('Usage is deprecated', 'event_espresso'), |
@@ -1,8 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\interfaces; |
3 | 3 | |
4 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
5 | - exit( 'No direct script access allowed' ); |
|
4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use EventEspresso\core\interfaces\InterminableInterface; |
3 | 3 | |
4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -18,231 +18,231 @@ discard block |
||
18 | 18 | class EE_Request implements InterminableInterface |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @access private |
|
23 | - * @var array $_get $_GET parameters |
|
24 | - */ |
|
25 | - private $_get = array(); |
|
26 | - |
|
27 | - /** |
|
28 | - * @access private |
|
29 | - * @var array $_post $_POST parameters |
|
30 | - */ |
|
31 | - private $_post = array(); |
|
32 | - |
|
33 | - /** |
|
34 | - * @access private |
|
35 | - * @var array $_cookie $_COOKIE parameters |
|
36 | - */ |
|
37 | - private $_cookie = array(); |
|
38 | - |
|
39 | - /** |
|
40 | - * @access private |
|
41 | - * @var array $_params $_REQUEST parameters |
|
42 | - */ |
|
43 | - private $_params = array(); |
|
44 | - |
|
45 | - /** |
|
46 | - * whether current request is via AJAX |
|
47 | - * |
|
48 | - * @var boolean |
|
49 | - * @access public |
|
50 | - */ |
|
51 | - public $ajax = false; |
|
52 | - |
|
53 | - /** |
|
54 | - * whether current request is via AJAX from the frontend of the site |
|
55 | - * |
|
56 | - * @var boolean |
|
57 | - * @access public |
|
58 | - */ |
|
59 | - public $front_ajax = false; |
|
60 | - |
|
61 | - /** |
|
62 | - * IP address for request |
|
63 | - * |
|
64 | - * @var string $_ip_address |
|
65 | - */ |
|
66 | - private $_ip_address = ''; |
|
67 | - |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * class constructor |
|
72 | - * |
|
73 | - * @access public |
|
74 | - * @param array $get |
|
75 | - * @param array $post |
|
76 | - * @param array $cookie |
|
77 | - */ |
|
78 | - public function __construct($get, $post, $cookie) |
|
79 | - { |
|
80 | - // grab request vars |
|
81 | - $this->_get = (array)$get; |
|
82 | - $this->_post = (array)$post; |
|
83 | - $this->_cookie = (array)$cookie; |
|
84 | - $this->_params = array_merge($this->_get, $this->_post); |
|
85 | - // AJAX ??? |
|
86 | - $this->ajax = defined('DOING_AJAX') ? true : false; |
|
87 | - $this->front_ajax = $this->is_set('ee_front_ajax') && (int)$this->get('ee_front_ajax') === 1; |
|
88 | - // grab user IP |
|
89 | - $this->_ip_address = $this->_visitor_ip(); |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - public function get_params() |
|
98 | - { |
|
99 | - return $this->_get; |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * @return array |
|
106 | - */ |
|
107 | - public function post_params() |
|
108 | - { |
|
109 | - return $this->_post; |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * @return array |
|
116 | - */ |
|
117 | - public function cookie_params() |
|
118 | - { |
|
119 | - return $this->_cookie; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * returns contents of $_REQUEST |
|
126 | - * |
|
127 | - * @return array |
|
128 | - */ |
|
129 | - public function params() |
|
130 | - { |
|
131 | - return $this->_params; |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * setter |
|
138 | - * |
|
139 | - * @access public |
|
140 | - * @param $key |
|
141 | - * @param $value |
|
142 | - * @param bool $override_ee |
|
143 | - * @return void |
|
144 | - */ |
|
145 | - public function set($key, $value, $override_ee = false) |
|
146 | - { |
|
147 | - // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
148 | - if ( |
|
149 | - $key !== 'ee' |
|
150 | - || ($key === 'ee' && empty($this->_params['ee'])) |
|
151 | - || ($key === 'ee' && ! empty($this->_params['ee']) && $override_ee) |
|
152 | - ) { |
|
153 | - $this->_params[$key] = $value; |
|
154 | - } |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * getter |
|
161 | - * |
|
162 | - * @access public |
|
163 | - * @param $key |
|
164 | - * @param null $default |
|
165 | - * @return mixed |
|
166 | - */ |
|
167 | - public function get($key, $default = null) |
|
168 | - { |
|
169 | - return isset($this->_params[$key]) ? $this->_params[$key] : $default; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * check if param exists |
|
176 | - * |
|
177 | - * @access public |
|
178 | - * @param $key |
|
179 | - * @return boolean |
|
180 | - */ |
|
181 | - public function is_set($key) |
|
182 | - { |
|
183 | - return isset($this->_params[$key]) ? true : false; |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * remove param |
|
190 | - * |
|
191 | - * @access public |
|
192 | - * @param $key |
|
193 | - * @param bool $unset_from_global_too |
|
194 | - */ |
|
195 | - public function un_set($key, $unset_from_global_too = false) |
|
196 | - { |
|
197 | - unset($this->_params[$key]); |
|
198 | - if ($unset_from_global_too) { |
|
199 | - unset($_REQUEST[$key]); |
|
200 | - } |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - |
|
205 | - /** |
|
206 | - * @return string |
|
207 | - */ |
|
208 | - public function ip_address() |
|
209 | - { |
|
210 | - return $this->_ip_address; |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * _visitor_ip |
|
217 | - * attempt to get IP address of current visitor from server |
|
218 | - * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
219 | - * |
|
220 | - * @access public |
|
221 | - * @return string |
|
222 | - */ |
|
223 | - private function _visitor_ip() |
|
224 | - { |
|
225 | - $visitor_ip = '0.0.0.0'; |
|
226 | - $server_keys = array( |
|
227 | - 'HTTP_CLIENT_IP', |
|
228 | - 'HTTP_X_FORWARDED_FOR', |
|
229 | - 'HTTP_X_FORWARDED', |
|
230 | - 'HTTP_X_CLUSTER_CLIENT_IP', |
|
231 | - 'HTTP_FORWARDED_FOR', |
|
232 | - 'HTTP_FORWARDED', |
|
233 | - 'REMOTE_ADDR', |
|
234 | - ); |
|
235 | - foreach ($server_keys as $key) { |
|
236 | - if (isset($_SERVER[$key])) { |
|
237 | - foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) { |
|
238 | - if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
239 | - $visitor_ip = $ip; |
|
240 | - } |
|
241 | - } |
|
242 | - } |
|
243 | - } |
|
244 | - return $visitor_ip; |
|
245 | - } |
|
21 | + /** |
|
22 | + * @access private |
|
23 | + * @var array $_get $_GET parameters |
|
24 | + */ |
|
25 | + private $_get = array(); |
|
26 | + |
|
27 | + /** |
|
28 | + * @access private |
|
29 | + * @var array $_post $_POST parameters |
|
30 | + */ |
|
31 | + private $_post = array(); |
|
32 | + |
|
33 | + /** |
|
34 | + * @access private |
|
35 | + * @var array $_cookie $_COOKIE parameters |
|
36 | + */ |
|
37 | + private $_cookie = array(); |
|
38 | + |
|
39 | + /** |
|
40 | + * @access private |
|
41 | + * @var array $_params $_REQUEST parameters |
|
42 | + */ |
|
43 | + private $_params = array(); |
|
44 | + |
|
45 | + /** |
|
46 | + * whether current request is via AJAX |
|
47 | + * |
|
48 | + * @var boolean |
|
49 | + * @access public |
|
50 | + */ |
|
51 | + public $ajax = false; |
|
52 | + |
|
53 | + /** |
|
54 | + * whether current request is via AJAX from the frontend of the site |
|
55 | + * |
|
56 | + * @var boolean |
|
57 | + * @access public |
|
58 | + */ |
|
59 | + public $front_ajax = false; |
|
60 | + |
|
61 | + /** |
|
62 | + * IP address for request |
|
63 | + * |
|
64 | + * @var string $_ip_address |
|
65 | + */ |
|
66 | + private $_ip_address = ''; |
|
67 | + |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * class constructor |
|
72 | + * |
|
73 | + * @access public |
|
74 | + * @param array $get |
|
75 | + * @param array $post |
|
76 | + * @param array $cookie |
|
77 | + */ |
|
78 | + public function __construct($get, $post, $cookie) |
|
79 | + { |
|
80 | + // grab request vars |
|
81 | + $this->_get = (array)$get; |
|
82 | + $this->_post = (array)$post; |
|
83 | + $this->_cookie = (array)$cookie; |
|
84 | + $this->_params = array_merge($this->_get, $this->_post); |
|
85 | + // AJAX ??? |
|
86 | + $this->ajax = defined('DOING_AJAX') ? true : false; |
|
87 | + $this->front_ajax = $this->is_set('ee_front_ajax') && (int)$this->get('ee_front_ajax') === 1; |
|
88 | + // grab user IP |
|
89 | + $this->_ip_address = $this->_visitor_ip(); |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + public function get_params() |
|
98 | + { |
|
99 | + return $this->_get; |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * @return array |
|
106 | + */ |
|
107 | + public function post_params() |
|
108 | + { |
|
109 | + return $this->_post; |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * @return array |
|
116 | + */ |
|
117 | + public function cookie_params() |
|
118 | + { |
|
119 | + return $this->_cookie; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * returns contents of $_REQUEST |
|
126 | + * |
|
127 | + * @return array |
|
128 | + */ |
|
129 | + public function params() |
|
130 | + { |
|
131 | + return $this->_params; |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * setter |
|
138 | + * |
|
139 | + * @access public |
|
140 | + * @param $key |
|
141 | + * @param $value |
|
142 | + * @param bool $override_ee |
|
143 | + * @return void |
|
144 | + */ |
|
145 | + public function set($key, $value, $override_ee = false) |
|
146 | + { |
|
147 | + // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
148 | + if ( |
|
149 | + $key !== 'ee' |
|
150 | + || ($key === 'ee' && empty($this->_params['ee'])) |
|
151 | + || ($key === 'ee' && ! empty($this->_params['ee']) && $override_ee) |
|
152 | + ) { |
|
153 | + $this->_params[$key] = $value; |
|
154 | + } |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * getter |
|
161 | + * |
|
162 | + * @access public |
|
163 | + * @param $key |
|
164 | + * @param null $default |
|
165 | + * @return mixed |
|
166 | + */ |
|
167 | + public function get($key, $default = null) |
|
168 | + { |
|
169 | + return isset($this->_params[$key]) ? $this->_params[$key] : $default; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * check if param exists |
|
176 | + * |
|
177 | + * @access public |
|
178 | + * @param $key |
|
179 | + * @return boolean |
|
180 | + */ |
|
181 | + public function is_set($key) |
|
182 | + { |
|
183 | + return isset($this->_params[$key]) ? true : false; |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * remove param |
|
190 | + * |
|
191 | + * @access public |
|
192 | + * @param $key |
|
193 | + * @param bool $unset_from_global_too |
|
194 | + */ |
|
195 | + public function un_set($key, $unset_from_global_too = false) |
|
196 | + { |
|
197 | + unset($this->_params[$key]); |
|
198 | + if ($unset_from_global_too) { |
|
199 | + unset($_REQUEST[$key]); |
|
200 | + } |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + |
|
205 | + /** |
|
206 | + * @return string |
|
207 | + */ |
|
208 | + public function ip_address() |
|
209 | + { |
|
210 | + return $this->_ip_address; |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * _visitor_ip |
|
217 | + * attempt to get IP address of current visitor from server |
|
218 | + * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
219 | + * |
|
220 | + * @access public |
|
221 | + * @return string |
|
222 | + */ |
|
223 | + private function _visitor_ip() |
|
224 | + { |
|
225 | + $visitor_ip = '0.0.0.0'; |
|
226 | + $server_keys = array( |
|
227 | + 'HTTP_CLIENT_IP', |
|
228 | + 'HTTP_X_FORWARDED_FOR', |
|
229 | + 'HTTP_X_FORWARDED', |
|
230 | + 'HTTP_X_CLUSTER_CLIENT_IP', |
|
231 | + 'HTTP_FORWARDED_FOR', |
|
232 | + 'HTTP_FORWARDED', |
|
233 | + 'REMOTE_ADDR', |
|
234 | + ); |
|
235 | + foreach ($server_keys as $key) { |
|
236 | + if (isset($_SERVER[$key])) { |
|
237 | + foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) { |
|
238 | + if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
239 | + $visitor_ip = $ip; |
|
240 | + } |
|
241 | + } |
|
242 | + } |
|
243 | + } |
|
244 | + return $visitor_ip; |
|
245 | + } |
|
246 | 246 | |
247 | 247 | |
248 | 248 |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | use EventEspresso\core\Psr4Autoloader; |
3 | 3 | |
4 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
|
4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
|
5 | 5 | |
6 | 6 | /** |
7 | 7 | * Class EE_Psr4AutoloaderInit |
@@ -37,15 +37,15 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public static function initialize_psr4_loader() { |
39 | 39 | static $initialized = false; |
40 | - if ( ! $initialized ) { |
|
40 | + if ( ! $initialized) { |
|
41 | 41 | // instantiate PSR4 autoloader |
42 | - espresso_load_required( 'Psr4Autoloader', EE_CORE . 'Psr4Autoloader.php' ); |
|
42 | + espresso_load_required('Psr4Autoloader', EE_CORE.'Psr4Autoloader.php'); |
|
43 | 43 | EE_Psr4AutoloaderInit::$psr4_loader = new Psr4Autoloader(); |
44 | 44 | // register the autoloader |
45 | 45 | EE_Psr4AutoloaderInit::$psr4_loader->register(); |
46 | 46 | // register the base directories for the namespace prefix |
47 | - EE_Psr4AutoloaderInit::$psr4_loader->addNamespace( 'EventEspresso', EE_PLUGIN_DIR_PATH ); |
|
48 | - EE_Psr4AutoloaderInit::$psr4_loader->addNamespace( 'EventEspressoBatchRequest', EE_LIBRARIES . 'batch' ); |
|
47 | + EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspresso', EE_PLUGIN_DIR_PATH); |
|
48 | + EE_Psr4AutoloaderInit::$psr4_loader->addNamespace('EventEspressoBatchRequest', EE_LIBRARIES.'batch'); |
|
49 | 49 | $initialized = true; |
50 | 50 | } |
51 | 51 | } |