@@ -80,34 +80,34 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @param array $args |
82 | 82 | */ |
83 | - public function register( $args ) { |
|
83 | + public function register($args) { |
|
84 | 84 | $args_default = array( |
85 | 85 | 'id' => '', |
86 | 86 | 'version' => '', |
87 | 87 | 'callback' => '', |
88 | 88 | ); |
89 | 89 | |
90 | - $args = wp_parse_args( $args, $args_default ); |
|
90 | + $args = wp_parse_args($args, $args_default); |
|
91 | 91 | |
92 | 92 | // You can only register database upgrade. |
93 | 93 | $args['type'] = 'database'; |
94 | 94 | |
95 | 95 | // Bailout. |
96 | 96 | if ( |
97 | - empty( $args['id'] ) || |
|
98 | - empty( $args['version'] ) || |
|
99 | - empty( $args['callback'] ) || |
|
100 | - ! is_callable( $args['callback'] ) |
|
97 | + empty($args['id']) || |
|
98 | + empty($args['version']) || |
|
99 | + empty($args['callback']) || |
|
100 | + ! is_callable($args['callback']) |
|
101 | 101 | ) { |
102 | 102 | return; |
103 | 103 | } |
104 | 104 | |
105 | 105 | // Change depend param to array. |
106 | - if ( isset( $args['depend'] ) && is_string( $args['depend'] ) ) { |
|
107 | - $args['depend'] = array( $args['depend'] ); |
|
106 | + if (isset($args['depend']) && is_string($args['depend'])) { |
|
107 | + $args['depend'] = array($args['depend']); |
|
108 | 108 | } |
109 | 109 | |
110 | - $this->updates[ $args['type'] ][] = $args; |
|
110 | + $this->updates[$args['type']][] = $args; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * @return static |
119 | 119 | */ |
120 | 120 | static function get_instance() { |
121 | - if ( is_null( self::$instance ) ) { |
|
121 | + if (is_null(self::$instance)) { |
|
122 | 122 | self::$instance = new self(); |
123 | 123 | } |
124 | 124 | |
@@ -136,27 +136,27 @@ discard block |
||
136 | 136 | /** |
137 | 137 | * Load file |
138 | 138 | */ |
139 | - require_once GIVE_PLUGIN_DIR . 'includes/class-give-background-updater.php'; |
|
140 | - require_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/upgrade-functions.php'; |
|
139 | + require_once GIVE_PLUGIN_DIR.'includes/class-give-background-updater.php'; |
|
140 | + require_once GIVE_PLUGIN_DIR.'includes/admin/upgrades/upgrade-functions.php'; |
|
141 | 141 | |
142 | 142 | self::$background_updater = new Give_Background_Updater(); |
143 | 143 | |
144 | 144 | /** |
145 | 145 | * Setup hooks. |
146 | 146 | */ |
147 | - add_action( 'init', array( $this, '__register_upgrade' ), 9999 ); |
|
148 | - add_action( 'give_set_upgrade_completed', array( $this, '__flush_resume_updates' ), 9999 ); |
|
149 | - add_action( 'wp_ajax_give_db_updates_info', array( $this, '__give_db_updates_info' ) ); |
|
150 | - add_action( 'wp_ajax_give_run_db_updates', array( $this, '__give_start_updating' ) ); |
|
151 | - add_action( 'admin_init', array( $this, '__redirect_admin' ) ); |
|
152 | - add_action( 'admin_init', array( $this, '__pause_db_update' ), - 1 ); |
|
153 | - add_action( 'admin_init', array( $this, '__restart_db_update' ), - 1 ); |
|
154 | - add_action( 'admin_notices', array( $this, '__show_notice' ) ); |
|
155 | - add_action( 'give_restart_db_upgrade', array( $this, '__health_background_update' ) ); |
|
156 | - |
|
157 | - if ( is_admin() ) { |
|
158 | - add_action( 'admin_init', array( $this, '__change_donations_label' ), 9999 ); |
|
159 | - add_action( 'admin_menu', array( $this, '__register_menu' ), 9999 ); |
|
147 | + add_action('init', array($this, '__register_upgrade'), 9999); |
|
148 | + add_action('give_set_upgrade_completed', array($this, '__flush_resume_updates'), 9999); |
|
149 | + add_action('wp_ajax_give_db_updates_info', array($this, '__give_db_updates_info')); |
|
150 | + add_action('wp_ajax_give_run_db_updates', array($this, '__give_start_updating')); |
|
151 | + add_action('admin_init', array($this, '__redirect_admin')); |
|
152 | + add_action('admin_init', array($this, '__pause_db_update'), - 1); |
|
153 | + add_action('admin_init', array($this, '__restart_db_update'), - 1); |
|
154 | + add_action('admin_notices', array($this, '__show_notice')); |
|
155 | + add_action('give_restart_db_upgrade', array($this, '__health_background_update')); |
|
156 | + |
|
157 | + if (is_admin()) { |
|
158 | + add_action('admin_init', array($this, '__change_donations_label'), 9999); |
|
159 | + add_action('admin_menu', array($this, '__register_menu'), 9999); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
@@ -170,12 +170,12 @@ discard block |
||
170 | 170 | $addons = give_get_plugins(); |
171 | 171 | $plugin_updates = get_plugin_updates(); |
172 | 172 | |
173 | - foreach ( $addons as $key => $info ) { |
|
174 | - if ( 'active' != $info['Status'] || 'add-on' != $info['Type'] || empty( $plugin_updates[ $key ] ) ) { |
|
173 | + foreach ($addons as $key => $info) { |
|
174 | + if ('active' != $info['Status'] || 'add-on' != $info['Type'] || empty($plugin_updates[$key])) { |
|
175 | 175 | continue; |
176 | 176 | } |
177 | 177 | |
178 | - $this->updates['plugin'][] = array_merge( $info, (array) $plugin_updates[ $key ] ); |
|
178 | + $this->updates['plugin'][] = array_merge($info, (array) $plugin_updates[$key]); |
|
179 | 179 | } |
180 | 180 | } |
181 | 181 | |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * @access public |
188 | 188 | */ |
189 | 189 | public function __register_upgrade() { |
190 | - if ( ! is_admin() ) { |
|
190 | + if ( ! is_admin()) { |
|
191 | 191 | return; |
192 | 192 | } |
193 | 193 | |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | * |
197 | 197 | * @since 1.8.12 |
198 | 198 | */ |
199 | - do_action( 'give_register_updates', $this ); |
|
199 | + do_action('give_register_updates', $this); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
@@ -209,23 +209,22 @@ discard block |
||
209 | 209 | global $menu; |
210 | 210 | |
211 | 211 | // Bailout. |
212 | - if ( empty( $menu ) || ! $this->get_total_update_count() ) { |
|
212 | + if (empty($menu) || ! $this->get_total_update_count()) { |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 | |
216 | - $is_update = ( $this->is_doing_updates() && ! self::$background_updater->is_paused_process() ); |
|
216 | + $is_update = ($this->is_doing_updates() && ! self::$background_updater->is_paused_process()); |
|
217 | 217 | |
218 | - foreach ( $menu as $index => $menu_item ) { |
|
219 | - if ( 'edit.php?post_type=give_forms' !== $menu_item[2] ) { |
|
218 | + foreach ($menu as $index => $menu_item) { |
|
219 | + if ('edit.php?post_type=give_forms' !== $menu_item[2]) { |
|
220 | 220 | continue; |
221 | 221 | } |
222 | 222 | |
223 | - $menu[ $index ][0] = sprintf( |
|
223 | + $menu[$index][0] = sprintf( |
|
224 | 224 | '%1$s <span class="update-plugins"><span class="plugin-count give-update-progress-count">%2$s%3$s</span></span>', |
225 | - __( 'Donations', 'give' ), |
|
225 | + __('Donations', 'give'), |
|
226 | 226 | $is_update ? |
227 | - $this->get_db_update_processing_percentage() : |
|
228 | - $this->get_total_update_count(), |
|
227 | + $this->get_db_update_processing_percentage() : $this->get_total_update_count(), |
|
229 | 228 | $is_update ? '%' : '' |
230 | 229 | ); |
231 | 230 | |
@@ -241,7 +240,7 @@ discard block |
||
241 | 240 | */ |
242 | 241 | public function __register_menu() { |
243 | 242 | // Bailout. |
244 | - if ( ! give_test_ajax_works() ) { |
|
243 | + if ( ! give_test_ajax_works()) { |
|
245 | 244 | return; |
246 | 245 | } |
247 | 246 | |
@@ -249,41 +248,40 @@ discard block |
||
249 | 248 | $this->__register_plugin_addon_updates(); |
250 | 249 | |
251 | 250 | // Bailout. |
252 | - if ( ! $this->get_total_update_count() ) { |
|
251 | + if ( ! $this->get_total_update_count()) { |
|
253 | 252 | // Show complete update message if still on update setting page. |
254 | - if ( isset( $_GET['page'] ) && 'give-updates' === $_GET['page'] ) { |
|
253 | + if (isset($_GET['page']) && 'give-updates' === $_GET['page']) { |
|
255 | 254 | // Upgrades |
256 | 255 | add_submenu_page( |
257 | 256 | 'edit.php?post_type=give_forms', |
258 | - esc_html__( 'Give Updates Complete', 'give' ), |
|
259 | - __( 'Updates', 'give' ), |
|
257 | + esc_html__('Give Updates Complete', 'give'), |
|
258 | + __('Updates', 'give'), |
|
260 | 259 | 'manage_give_settings', |
261 | 260 | 'give-updates', |
262 | - array( $this, 'render_complete_page' ) |
|
261 | + array($this, 'render_complete_page') |
|
263 | 262 | ); |
264 | 263 | } |
265 | 264 | |
266 | 265 | return; |
267 | 266 | } |
268 | 267 | |
269 | - $is_update = ( $this->is_doing_updates() && ! self::$background_updater->is_paused_process() ); |
|
268 | + $is_update = ($this->is_doing_updates() && ! self::$background_updater->is_paused_process()); |
|
270 | 269 | |
271 | 270 | // Upgrades |
272 | 271 | add_submenu_page( |
273 | 272 | 'edit.php?post_type=give_forms', |
274 | - esc_html__( 'Give Updates', 'give' ), |
|
273 | + esc_html__('Give Updates', 'give'), |
|
275 | 274 | sprintf( |
276 | 275 | '%1$s <span class="update-plugins"%2$s><span class="plugin-count give-update-progress-count">%3$s%4$s</span></span>', |
277 | - __( 'Updates', 'give' ), |
|
278 | - isset( $_GET['give-pause-db-upgrades'] ) ? ' style="display:none;"' : '', |
|
276 | + __('Updates', 'give'), |
|
277 | + isset($_GET['give-pause-db-upgrades']) ? ' style="display:none;"' : '', |
|
279 | 278 | $is_update ? |
280 | - $this->get_db_update_processing_percentage() : |
|
281 | - $this->get_total_update_count(), |
|
279 | + $this->get_db_update_processing_percentage() : $this->get_total_update_count(), |
|
282 | 280 | $is_update ? '%' : '' |
283 | 281 | ), |
284 | 282 | 'manage_give_settings', |
285 | 283 | 'give-updates', |
286 | - array( $this, 'render_page' ) |
|
284 | + array($this, 'render_page') |
|
287 | 285 | ); |
288 | 286 | } |
289 | 287 | |
@@ -298,13 +296,13 @@ discard block |
||
298 | 296 | // Show db upgrade completed notice. |
299 | 297 | if ( |
300 | 298 | ! wp_doing_ajax() && |
301 | - current_user_can( 'manage_give_settings' ) && |
|
302 | - get_option( 'give_show_db_upgrade_complete_notice' ) && |
|
303 | - ! isset( $_GET['give-db-update-completed'] ) |
|
299 | + current_user_can('manage_give_settings') && |
|
300 | + get_option('give_show_db_upgrade_complete_notice') && |
|
301 | + ! isset($_GET['give-db-update-completed']) |
|
304 | 302 | ) { |
305 | - delete_option( 'give_show_db_upgrade_complete_notice' ); |
|
303 | + delete_option('give_show_db_upgrade_complete_notice'); |
|
306 | 304 | |
307 | - wp_redirect( add_query_arg( array( 'give-db-update-completed' => 'give_db_upgrade_completed' ) ) ); |
|
305 | + wp_redirect(add_query_arg(array('give-db-update-completed' => 'give_db_upgrade_completed'))); |
|
308 | 306 | exit(); |
309 | 307 | } |
310 | 308 | } |
@@ -320,15 +318,15 @@ discard block |
||
320 | 318 | * |
321 | 319 | * @return bool |
322 | 320 | */ |
323 | - public function __pause_db_update( $force = false ) { |
|
321 | + public function __pause_db_update($force = false) { |
|
324 | 322 | // Bailout. |
325 | 323 | if ( |
326 | 324 | ! $force && |
327 | 325 | ( |
328 | 326 | wp_doing_ajax() || |
329 | - ! isset( $_GET['page'] ) || |
|
327 | + ! isset($_GET['page']) || |
|
330 | 328 | 'give-updates' !== $_GET['page'] || |
331 | - ! isset( $_GET['give-pause-db-upgrades'] ) || |
|
329 | + ! isset($_GET['give-pause-db-upgrades']) || |
|
332 | 330 | self::$background_updater->is_paused_process() |
333 | 331 | ) |
334 | 332 | |
@@ -336,13 +334,13 @@ discard block |
||
336 | 334 | return false; |
337 | 335 | } |
338 | 336 | |
339 | - delete_option( 'give_upgrade_error' ); |
|
337 | + delete_option('give_upgrade_error'); |
|
340 | 338 | |
341 | - $this->__health_background_update( $this ); |
|
339 | + $this->__health_background_update($this); |
|
342 | 340 | $batch = self::$background_updater->get_all_batch(); |
343 | 341 | |
344 | 342 | // Bailout: if batch is empty |
345 | - if ( empty( $batch->data ) ) { |
|
343 | + if (empty($batch->data)) { |
|
346 | 344 | return false; |
347 | 345 | } |
348 | 346 | |
@@ -351,25 +349,25 @@ discard block |
||
351 | 349 | |
352 | 350 | // Do not stop background process immediately if task running. |
353 | 351 | // @see Give_Background_Updater::lock_process |
354 | - if ( ! $force && self::$background_updater->is_process_running() ) { |
|
355 | - update_option( 'give_pause_upgrade', 1 ); |
|
352 | + if ( ! $force && self::$background_updater->is_process_running()) { |
|
353 | + update_option('give_pause_upgrade', 1); |
|
356 | 354 | |
357 | 355 | return true; |
358 | 356 | } |
359 | 357 | |
360 | - update_option( 'give_paused_batches', $batch, 'no' ); |
|
361 | - delete_option( $batch->key ); |
|
362 | - delete_site_transient( self::$background_updater->get_identifier() . '_process_lock' ); |
|
363 | - wp_clear_scheduled_hook( self::$background_updater->get_cron_identifier() ); |
|
358 | + update_option('give_paused_batches', $batch, 'no'); |
|
359 | + delete_option($batch->key); |
|
360 | + delete_site_transient(self::$background_updater->get_identifier().'_process_lock'); |
|
361 | + wp_clear_scheduled_hook(self::$background_updater->get_cron_identifier()); |
|
364 | 362 | |
365 | - Give()->logs->add( 'Update Pause', print_r( $batch, true ), 0, 'update' ); |
|
363 | + Give()->logs->add('Update Pause', print_r($batch, true), 0, 'update'); |
|
366 | 364 | |
367 | 365 | /** |
368 | 366 | * Fire action when pause db updates |
369 | 367 | * |
370 | 368 | * @since 2.0.1 |
371 | 369 | */ |
372 | - do_action( 'give_pause_db_upgrade', $this ); |
|
370 | + do_action('give_pause_db_upgrade', $this); |
|
373 | 371 | |
374 | 372 | return true; |
375 | 373 | } |
@@ -386,31 +384,31 @@ discard block |
||
386 | 384 | // Bailout. |
387 | 385 | if ( |
388 | 386 | wp_doing_ajax() || |
389 | - ! isset( $_GET['page'] ) || |
|
387 | + ! isset($_GET['page']) || |
|
390 | 388 | 'give-updates' !== $_GET['page'] || |
391 | - ! isset( $_GET['give-restart-db-upgrades'] ) || |
|
389 | + ! isset($_GET['give-restart-db-upgrades']) || |
|
392 | 390 | ! self::$background_updater->is_paused_process() |
393 | 391 | ) { |
394 | 392 | return false; |
395 | 393 | } |
396 | 394 | |
397 | 395 | Give_Background_Updater::flush_cache(); |
398 | - $batch = get_option( 'give_paused_batches' ); |
|
396 | + $batch = get_option('give_paused_batches'); |
|
399 | 397 | |
400 | - if ( ! empty( $batch ) ) { |
|
401 | - wp_cache_delete( $batch->key, 'options' ); |
|
402 | - update_option( $batch->key, $batch->data ); |
|
398 | + if ( ! empty($batch)) { |
|
399 | + wp_cache_delete($batch->key, 'options'); |
|
400 | + update_option($batch->key, $batch->data); |
|
403 | 401 | |
404 | - delete_option( 'give_paused_batches' ); |
|
402 | + delete_option('give_paused_batches'); |
|
405 | 403 | |
406 | - Give()->logs->add( 'Update Restart', print_r( $batch, true ), 0, 'update' ); |
|
404 | + Give()->logs->add('Update Restart', print_r($batch, true), 0, 'update'); |
|
407 | 405 | |
408 | 406 | |
409 | 407 | /** Fire action when restart db updates |
410 | 408 | * |
411 | 409 | * @since 2.0.1 |
412 | 410 | */ |
413 | - do_action( 'give_restart_db_upgrade', $this ); |
|
411 | + do_action('give_restart_db_upgrade', $this); |
|
414 | 412 | |
415 | 413 | self::$background_updater->dispatch(); |
416 | 414 | } |
@@ -426,53 +424,53 @@ discard block |
||
426 | 424 | * |
427 | 425 | * @param Give_Updates $give_updates |
428 | 426 | */ |
429 | - public function __health_background_update( $give_updates ) { |
|
430 | - if ( ! $this->is_doing_updates() ) { |
|
427 | + public function __health_background_update($give_updates) { |
|
428 | + if ( ! $this->is_doing_updates()) { |
|
431 | 429 | return; |
432 | 430 | } |
433 | 431 | |
434 | 432 | Give_Background_Updater::flush_cache(); |
435 | 433 | |
436 | 434 | $batch = Give_Updates::$background_updater->get_all_batch(); |
437 | - $batch_data_count = count( $batch->data ); |
|
438 | - $all_updates = $give_updates->get_updates( 'database', 'all' ); |
|
439 | - $all_update_ids = wp_list_pluck( $all_updates, 'id' ); |
|
440 | - $all_batch_update_ids = ! empty( $batch->data ) ? wp_list_pluck( $batch->data, 'id' ) : array(); |
|
435 | + $batch_data_count = count($batch->data); |
|
436 | + $all_updates = $give_updates->get_updates('database', 'all'); |
|
437 | + $all_update_ids = wp_list_pluck($all_updates, 'id'); |
|
438 | + $all_batch_update_ids = ! empty($batch->data) ? wp_list_pluck($batch->data, 'id') : array(); |
|
441 | 439 | $log_data = ''; |
442 | - $doing_upgrade_args = get_option( 'give_doing_upgrade' ); |
|
440 | + $doing_upgrade_args = get_option('give_doing_upgrade'); |
|
443 | 441 | |
444 | - if ( ! empty( $doing_upgrade_args ) ) { |
|
445 | - $log_data .= 'Doing update:' . "\n"; |
|
446 | - $log_data .= print_r( $doing_upgrade_args, true ) . "\n"; |
|
442 | + if ( ! empty($doing_upgrade_args)) { |
|
443 | + $log_data .= 'Doing update:'."\n"; |
|
444 | + $log_data .= print_r($doing_upgrade_args, true)."\n"; |
|
447 | 445 | } |
448 | 446 | |
449 | 447 | /** |
450 | 448 | * Add remove upgrade from batch |
451 | 449 | */ |
452 | - if ( ! empty( $batch->data ) ) { |
|
450 | + if ( ! empty($batch->data)) { |
|
453 | 451 | |
454 | - foreach ( $batch->data as $index => $update ) { |
|
455 | - $log_data = print_r( $update, true ) . "\n"; |
|
452 | + foreach ($batch->data as $index => $update) { |
|
453 | + $log_data = print_r($update, true)."\n"; |
|
456 | 454 | |
457 | - if ( ! is_callable( $update['callback'] ) ) { |
|
458 | - $log_data .= 'Removing missing callback update: ' . "{$update['id']}\n"; |
|
459 | - unset( $batch->data[ $index ] ); |
|
460 | - } elseif ( give_has_upgrade_completed( $update['id'] ) ) { |
|
461 | - $log_data .= 'Removing already completed update: ' . "{$update['id']}\n"; |
|
462 | - unset( $batch->data[ $index ] ); |
|
455 | + if ( ! is_callable($update['callback'])) { |
|
456 | + $log_data .= 'Removing missing callback update: '."{$update['id']}\n"; |
|
457 | + unset($batch->data[$index]); |
|
458 | + } elseif (give_has_upgrade_completed($update['id'])) { |
|
459 | + $log_data .= 'Removing already completed update: '."{$update['id']}\n"; |
|
460 | + unset($batch->data[$index]); |
|
463 | 461 | } |
464 | 462 | |
465 | - if ( ! empty( $update['depend'] ) ) { |
|
463 | + if ( ! empty($update['depend'])) { |
|
466 | 464 | |
467 | - foreach ( $update['depend'] as $depend ) { |
|
468 | - if ( give_has_upgrade_completed( $depend ) ) { |
|
469 | - $log_data .= 'Completed update: ' . "{$depend}\n"; |
|
465 | + foreach ($update['depend'] as $depend) { |
|
466 | + if (give_has_upgrade_completed($depend)) { |
|
467 | + $log_data .= 'Completed update: '."{$depend}\n"; |
|
470 | 468 | continue; |
471 | 469 | } |
472 | 470 | |
473 | - if ( in_array( $depend, $all_update_ids ) && ! in_array( $depend, $all_batch_update_ids ) ) { |
|
474 | - $log_data .= 'Adding missing update: ' . "{$depend}\n"; |
|
475 | - array_unshift( $batch->data, $all_updates[ array_search( $depend, $all_update_ids ) ] ); |
|
471 | + if (in_array($depend, $all_update_ids) && ! in_array($depend, $all_batch_update_ids)) { |
|
472 | + $log_data .= 'Adding missing update: '."{$depend}\n"; |
|
473 | + array_unshift($batch->data, $all_updates[array_search($depend, $all_update_ids)]); |
|
476 | 474 | } |
477 | 475 | } |
478 | 476 | } |
@@ -482,60 +480,60 @@ discard block |
||
482 | 480 | /** |
483 | 481 | * Add new upgrade to batch |
484 | 482 | */ |
485 | - if ( $new_updates = $this->get_updates( 'database', 'new' ) ) { |
|
486 | - $all_batch_update_ids = ! empty( $batch->data ) ? wp_list_pluck( $batch->data, 'id' ) : array(); |
|
483 | + if ($new_updates = $this->get_updates('database', 'new')) { |
|
484 | + $all_batch_update_ids = ! empty($batch->data) ? wp_list_pluck($batch->data, 'id') : array(); |
|
487 | 485 | |
488 | - foreach ( $new_updates as $index => $new_update ) { |
|
489 | - if ( give_has_upgrade_completed( $new_update['id'] ) || in_array( $new_update['id'], $all_batch_update_ids ) ) { |
|
490 | - unset( $new_updates[ $index ] ); |
|
486 | + foreach ($new_updates as $index => $new_update) { |
|
487 | + if (give_has_upgrade_completed($new_update['id']) || in_array($new_update['id'], $all_batch_update_ids)) { |
|
488 | + unset($new_updates[$index]); |
|
491 | 489 | } |
492 | 490 | } |
493 | 491 | |
494 | - if ( ! empty( $new_updates ) ) { |
|
495 | - $log_data .= 'Adding new update: ' . "\n"; |
|
496 | - $log_data .= print_r( $new_updates, true ) . "\n"; |
|
492 | + if ( ! empty($new_updates)) { |
|
493 | + $log_data .= 'Adding new update: '."\n"; |
|
494 | + $log_data .= print_r($new_updates, true)."\n"; |
|
497 | 495 | |
498 | - $batch->data = array_merge( (array) $batch->data, $new_updates ); |
|
499 | - update_option( 'give_db_update_count', ( absint( get_option( 'give_db_update_count' ) ) + count( $new_updates ) ) ); |
|
496 | + $batch->data = array_merge((array) $batch->data, $new_updates); |
|
497 | + update_option('give_db_update_count', (absint(get_option('give_db_update_count')) + count($new_updates))); |
|
500 | 498 | } |
501 | 499 | } |
502 | 500 | |
503 | 501 | /** |
504 | 502 | * Fix batch |
505 | 503 | */ |
506 | - if ( empty( $batch->data ) ) { |
|
504 | + if (empty($batch->data)) { |
|
507 | 505 | // Complete batch if do not have any data to process. |
508 | - self::$background_updater->delete( $batch->key ); |
|
506 | + self::$background_updater->delete($batch->key); |
|
509 | 507 | |
510 | - if ( self::$background_updater->has_queue() ) { |
|
511 | - $this->__health_background_update( $this ); |
|
508 | + if (self::$background_updater->has_queue()) { |
|
509 | + $this->__health_background_update($this); |
|
512 | 510 | } else { |
513 | 511 | self::$background_updater->complete(); |
514 | 512 | } |
515 | 513 | |
516 | - } elseif ( $batch_data_count !== count( $batch->data ) ) { |
|
514 | + } elseif ($batch_data_count !== count($batch->data)) { |
|
517 | 515 | |
518 | - $log_data .= 'Updating batch' . "\n"; |
|
519 | - $log_data .= print_r( $batch, true ); |
|
516 | + $log_data .= 'Updating batch'."\n"; |
|
517 | + $log_data .= print_r($batch, true); |
|
520 | 518 | |
521 | - $doing_upgrade_args['heading'] = sprintf( 'Update %s of %s', $doing_upgrade_args['update'], get_option( 'give_db_update_count' ) ); |
|
519 | + $doing_upgrade_args['heading'] = sprintf('Update %s of %s', $doing_upgrade_args['update'], get_option('give_db_update_count')); |
|
522 | 520 | $doing_upgrade_args['total_percentage'] = $this->get_db_update_processing_percentage(); |
523 | - update_option( 'give_doing_upgrade', $doing_upgrade_args ); |
|
521 | + update_option('give_doing_upgrade', $doing_upgrade_args); |
|
524 | 522 | |
525 | - if ( ! empty( $batch->key ) ) { |
|
526 | - wp_cache_delete( $batch->key, 'options' ); |
|
527 | - update_option( $batch->key, $batch->data ); |
|
523 | + if ( ! empty($batch->key)) { |
|
524 | + wp_cache_delete($batch->key, 'options'); |
|
525 | + update_option($batch->key, $batch->data); |
|
528 | 526 | } else { |
529 | 527 | |
530 | - update_option( 'give_db_update_count', count( $batch->data ) ); |
|
528 | + update_option('give_db_update_count', count($batch->data)); |
|
531 | 529 | |
532 | 530 | $doing_upgrade_args['update'] = $give_updates->update; |
533 | - $doing_upgrade_args['heading'] = sprintf( 'Update %s of %s', 1, count( $batch->data ) ); |
|
531 | + $doing_upgrade_args['heading'] = sprintf('Update %s of %s', 1, count($batch->data)); |
|
534 | 532 | |
535 | - update_option( 'give_doing_upgrade', $doing_upgrade_args ); |
|
533 | + update_option('give_doing_upgrade', $doing_upgrade_args); |
|
536 | 534 | |
537 | - foreach ( $batch->data as $data ) { |
|
538 | - Give_Updates::$background_updater->push_to_queue( $data ); |
|
535 | + foreach ($batch->data as $data) { |
|
536 | + Give_Updates::$background_updater->push_to_queue($data); |
|
539 | 537 | } |
540 | 538 | |
541 | 539 | Give_Updates::$background_updater->save(); |
@@ -547,27 +545,27 @@ discard block |
||
547 | 545 | * Fix give_doing_upgrade option |
548 | 546 | */ |
549 | 547 | $update_option = false; |
550 | - $fresh_new_db_count = $this->get_total_new_db_update_count( true ); |
|
551 | - if ( $fresh_new_db_count < $doing_upgrade_args['update'] ) { |
|
552 | - update_option( 'give_db_update_count', $fresh_new_db_count ); |
|
548 | + $fresh_new_db_count = $this->get_total_new_db_update_count(true); |
|
549 | + if ($fresh_new_db_count < $doing_upgrade_args['update']) { |
|
550 | + update_option('give_db_update_count', $fresh_new_db_count); |
|
553 | 551 | $doing_upgrade_args['update'] = 1; |
554 | - $doing_upgrade_args['heading'] = sprintf( 'Update %s of %s', 1, $fresh_new_db_count ); |
|
552 | + $doing_upgrade_args['heading'] = sprintf('Update %s of %s', 1, $fresh_new_db_count); |
|
555 | 553 | $update_option = true; |
556 | 554 | } |
557 | 555 | |
558 | - if ( 101 < $doing_upgrade_args['total_percentage'] ) { |
|
559 | - $doing_upgrade_args['total_percentage'] = $this->get_db_update_processing_percentage( true ); |
|
556 | + if (101 < $doing_upgrade_args['total_percentage']) { |
|
557 | + $doing_upgrade_args['total_percentage'] = $this->get_db_update_processing_percentage(true); |
|
560 | 558 | $update_option = true; |
561 | 559 | } |
562 | 560 | |
563 | - if ( $update_option ) { |
|
564 | - update_option( 'give_doing_upgrade', $doing_upgrade_args ); |
|
561 | + if ($update_option) { |
|
562 | + update_option('give_doing_upgrade', $doing_upgrade_args); |
|
565 | 563 | |
566 | - $log_data .= 'Updated doing update:' . "\n"; |
|
567 | - $log_data .= print_r( $doing_upgrade_args, true ) . "\n"; |
|
564 | + $log_data .= 'Updated doing update:'."\n"; |
|
565 | + $log_data .= print_r($doing_upgrade_args, true)."\n"; |
|
568 | 566 | } |
569 | 567 | |
570 | - Give()->logs->add( 'Update Health Check', $log_data, 0, 'update' ); |
|
568 | + Give()->logs->add('Update Health Check', $log_data, 0, 'update'); |
|
571 | 569 | } |
572 | 570 | |
573 | 571 | |
@@ -579,66 +577,66 @@ discard block |
||
579 | 577 | */ |
580 | 578 | public function __show_notice() { |
581 | 579 | // Bailout. |
582 | - if ( ! current_user_can( 'manage_give_settings' ) ) { |
|
580 | + if ( ! current_user_can('manage_give_settings')) { |
|
583 | 581 | return; |
584 | 582 | } |
585 | 583 | |
586 | 584 | // Run DB updates. |
587 | - if ( ! empty( $_GET['give-run-db-update'] ) ) { |
|
585 | + if ( ! empty($_GET['give-run-db-update'])) { |
|
588 | 586 | $this->run_db_update(); |
589 | 587 | } |
590 | 588 | |
591 | 589 | |
592 | 590 | // Bailout. |
593 | - if ( isset( $_GET['page'] ) && 'give-updates' === $_GET['page'] ) { |
|
591 | + if (isset($_GET['page']) && 'give-updates' === $_GET['page']) { |
|
594 | 592 | return; |
595 | 593 | } |
596 | 594 | |
597 | 595 | // Show notice if upgrade paused. |
598 | - if ( self::$background_updater->is_paused_process() ) { |
|
596 | + if (self::$background_updater->is_paused_process()) { |
|
599 | 597 | ob_start(); |
600 | 598 | |
601 | - $upgrade_error = get_option( 'give_upgrade_error' ); |
|
602 | - if ( ! $upgrade_error ) : ?> |
|
603 | - <strong><?php _e( 'Database Update', 'give' ); ?></strong> |
|
604 | - – <?php _e( 'GiveWP needs to update your database to the latest version. The following process will make updates to your site\'s database. Please create a backup before proceeding.', 'give' ); ?> |
|
599 | + $upgrade_error = get_option('give_upgrade_error'); |
|
600 | + if ( ! $upgrade_error) : ?> |
|
601 | + <strong><?php _e('Database Update', 'give'); ?></strong> |
|
602 | + – <?php _e('GiveWP needs to update your database to the latest version. The following process will make updates to your site\'s database. Please create a backup before proceeding.', 'give'); ?> |
|
605 | 603 | <br> |
606 | 604 | <br> |
607 | - <a href="<?php echo esc_url( add_query_arg( array( 'give-restart-db-upgrades' => 1 ), admin_url( 'edit.php?post_type=give_forms&page=give-updates' ) ) ); ?>" class="button button-primary give-restart-updater-btn"> |
|
608 | - <?php _e( 'Restart the updater', 'give' ); ?> |
|
605 | + <a href="<?php echo esc_url(add_query_arg(array('give-restart-db-upgrades' => 1), admin_url('edit.php?post_type=give_forms&page=give-updates'))); ?>" class="button button-primary give-restart-updater-btn"> |
|
606 | + <?php _e('Restart the updater', 'give'); ?> |
|
609 | 607 | </a> |
610 | 608 | <script type="text/javascript"> |
611 | 609 | jQuery('.give-restart-updater-btn').click('click', function () { |
612 | - return window.confirm('<?php echo esc_js( __( 'It is recommended that you backup your database before proceeding. Do you want to run the update now?', 'give' ) ); ?>'); // jshint ignore:line |
|
610 | + return window.confirm('<?php echo esc_js(__('It is recommended that you backup your database before proceeding. Do you want to run the update now?', 'give')); ?>'); // jshint ignore:line |
|
613 | 611 | }); |
614 | 612 | </script> |
615 | 613 | <?php else: ?> |
616 | - <strong><?php _e( 'Database Update', 'give' ); ?></strong> |
|
617 | - – <?php _e( 'An unexpected issue occurred during the database update which caused it to stop automatically. Please contact support for assistance.', 'give' ); ?> |
|
614 | + <strong><?php _e('Database Update', 'give'); ?></strong> |
|
615 | + – <?php _e('An unexpected issue occurred during the database update which caused it to stop automatically. Please contact support for assistance.', 'give'); ?> |
|
618 | 616 | <?php |
619 | 617 | endif; |
620 | 618 | $desc_html = ob_get_clean(); |
621 | 619 | |
622 | - Give()->notices->register_notice( array( |
|
620 | + Give()->notices->register_notice(array( |
|
623 | 621 | 'id' => 'give_upgrade_db', |
624 | 622 | 'type' => 'error', |
625 | 623 | 'dismissible' => false, |
626 | 624 | 'description' => $desc_html, |
627 | - ) ); |
|
625 | + )); |
|
628 | 626 | } |
629 | 627 | |
630 | 628 | // Bailout if doing upgrades. |
631 | - if ( $this->is_doing_updates() ) { |
|
629 | + if ($this->is_doing_updates()) { |
|
632 | 630 | return; |
633 | 631 | } |
634 | 632 | |
635 | 633 | // Show notice if ajax is not working. |
636 | - if ( ! give_test_ajax_works() ) { |
|
634 | + if ( ! give_test_ajax_works()) { |
|
637 | 635 | Give()->notices->register_notice( |
638 | 636 | array( |
639 | 637 | 'id' => 'give_db_upgrade_ajax_inaccessible', |
640 | 638 | 'type' => 'error', |
641 | - 'description' => sprintf( '%1$s <a href="%2$s" target="_blank">%3$s</a>', __( 'Give needs to upgrade the database but cannot because AJAX does not appear accessible. This could be because your website is password protected, in maintenance mode, or has a specific hosting configuration or plugin active that is preventing access.', 'give' ), 'http://docs.givewp.com/admin-ajax-error', __( 'Read More', 'give' ) . ' »' ), |
|
639 | + 'description' => sprintf('%1$s <a href="%2$s" target="_blank">%3$s</a>', __('Give needs to upgrade the database but cannot because AJAX does not appear accessible. This could be because your website is password protected, in maintenance mode, or has a specific hosting configuration or plugin active that is preventing access.', 'give'), 'http://docs.givewp.com/admin-ajax-error', __('Read More', 'give').' »'), |
|
642 | 640 | 'show' => true, |
643 | 641 | ) |
644 | 642 | ); |
@@ -647,45 +645,45 @@ discard block |
||
647 | 645 | } |
648 | 646 | |
649 | 647 | // Show db upgrade completed notice. |
650 | - if ( ! empty( $_GET['give-db-update-completed'] ) ) { |
|
651 | - Give()->notices->register_notice( array( |
|
648 | + if ( ! empty($_GET['give-db-update-completed'])) { |
|
649 | + Give()->notices->register_notice(array( |
|
652 | 650 | 'id' => 'give_db_upgrade_completed', |
653 | 651 | 'type' => 'updated', |
654 | - 'description' => __( 'Give database updates completed successfully. Thank you for updating to the latest version!', 'give' ), |
|
652 | + 'description' => __('Give database updates completed successfully. Thank you for updating to the latest version!', 'give'), |
|
655 | 653 | 'show' => true, |
656 | - ) ); |
|
654 | + )); |
|
657 | 655 | |
658 | 656 | // Start update. |
659 | - } elseif ( ! empty( $_GET['give-run-db-update'] ) ) { |
|
657 | + } elseif ( ! empty($_GET['give-run-db-update'])) { |
|
660 | 658 | $this->run_db_update(); |
661 | 659 | |
662 | 660 | // Show run the update notice. |
663 | - } elseif ( $this->get_total_new_db_update_count() ) { |
|
661 | + } elseif ($this->get_total_new_db_update_count()) { |
|
664 | 662 | ob_start(); |
665 | 663 | ?> |
666 | 664 | <p> |
667 | - <strong><?php _e( 'Database Update', 'give' ); ?></strong> |
|
668 | - – <?php _e( 'GiveWP needs to update your database to the latest version. The following process will make updates to your site\'s database. Please create a complete backup before proceeding.', 'give' ); ?> |
|
665 | + <strong><?php _e('Database Update', 'give'); ?></strong> |
|
666 | + – <?php _e('GiveWP needs to update your database to the latest version. The following process will make updates to your site\'s database. Please create a complete backup before proceeding.', 'give'); ?> |
|
669 | 667 | </p> |
670 | 668 | <p class="submit"> |
671 | - <a href="<?php echo esc_url( add_query_arg( array( 'give-run-db-update' => 1 ), admin_url( 'edit.php?post_type=give_forms&page=give-updates' ) ) ); ?>" class="button button-primary give-run-update-now"> |
|
672 | - <?php _e( 'Run the updater', 'give' ); ?> |
|
669 | + <a href="<?php echo esc_url(add_query_arg(array('give-run-db-update' => 1), admin_url('edit.php?post_type=give_forms&page=give-updates'))); ?>" class="button button-primary give-run-update-now"> |
|
670 | + <?php _e('Run the updater', 'give'); ?> |
|
673 | 671 | </a> |
674 | 672 | </p> |
675 | 673 | <script type="text/javascript"> |
676 | 674 | jQuery('.give-run-update-now').click('click', function () { |
677 | - return window.confirm('<?php echo esc_js( __( 'It is recommended that you backup your database before proceeding. Do you want to run the update now?', 'give' ) ); ?>'); // jshint ignore:line |
|
675 | + return window.confirm('<?php echo esc_js(__('It is recommended that you backup your database before proceeding. Do you want to run the update now?', 'give')); ?>'); // jshint ignore:line |
|
678 | 676 | }); |
679 | 677 | </script> |
680 | 678 | <?php |
681 | 679 | $desc_html = ob_get_clean(); |
682 | 680 | |
683 | - Give()->notices->register_notice( array( |
|
681 | + Give()->notices->register_notice(array( |
|
684 | 682 | 'id' => 'give_upgrade_db', |
685 | 683 | 'type' => 'updated', |
686 | 684 | 'dismissible' => false, |
687 | 685 | 'description' => $desc_html, |
688 | - ) ); |
|
686 | + )); |
|
689 | 687 | } |
690 | 688 | } |
691 | 689 | |
@@ -696,7 +694,7 @@ discard block |
||
696 | 694 | * @access public |
697 | 695 | */ |
698 | 696 | public function render_complete_page() { |
699 | - include_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/views/upgrades-complete.php'; |
|
697 | + include_once GIVE_PLUGIN_DIR.'includes/admin/upgrades/views/upgrades-complete.php'; |
|
700 | 698 | } |
701 | 699 | |
702 | 700 | /** |
@@ -706,7 +704,7 @@ discard block |
||
706 | 704 | * @access public |
707 | 705 | */ |
708 | 706 | public function render_page() { |
709 | - include_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/views/upgrades.php'; |
|
707 | + include_once GIVE_PLUGIN_DIR.'includes/admin/upgrades/views/upgrades.php'; |
|
710 | 708 | } |
711 | 709 | |
712 | 710 | /** |
@@ -717,26 +715,26 @@ discard block |
||
717 | 715 | */ |
718 | 716 | private function run_db_update() { |
719 | 717 | // Bailout. |
720 | - if ( $this->is_doing_updates() || ! $this->get_total_new_db_update_count() ) { |
|
718 | + if ($this->is_doing_updates() || ! $this->get_total_new_db_update_count()) { |
|
721 | 719 | return; |
722 | 720 | } |
723 | 721 | |
724 | - $updates = $this->get_updates( 'database', 'new' ); |
|
722 | + $updates = $this->get_updates('database', 'new'); |
|
725 | 723 | |
726 | - foreach ( $updates as $update ) { |
|
727 | - self::$background_updater->push_to_queue( $update ); |
|
724 | + foreach ($updates as $update) { |
|
725 | + self::$background_updater->push_to_queue($update); |
|
728 | 726 | } |
729 | 727 | |
730 | - add_option( 'give_db_update_count', count( $updates ), '', 'no' ); |
|
728 | + add_option('give_db_update_count', count($updates), '', 'no'); |
|
731 | 729 | |
732 | - add_option( 'give_doing_upgrade', array( |
|
730 | + add_option('give_doing_upgrade', array( |
|
733 | 731 | 'update_info' => $updates[0], |
734 | 732 | 'step' => 1, |
735 | 733 | 'update' => 1, |
736 | - 'heading' => sprintf( 'Update %s of %s', 1, count( $updates ) ), |
|
734 | + 'heading' => sprintf('Update %s of %s', 1, count($updates)), |
|
737 | 735 | 'percentage' => 0, |
738 | 736 | 'total_percentage' => 0, |
739 | - ), '', 'no' ); |
|
737 | + ), '', 'no'); |
|
740 | 738 | |
741 | 739 | self::$background_updater->save()->dispatch(); |
742 | 740 | } |
@@ -750,14 +748,13 @@ discard block |
||
750 | 748 | */ |
751 | 749 | public function __flush_resume_updates() { |
752 | 750 | //delete_option( 'give_doing_upgrade' ); |
753 | - update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) ); |
|
751 | + update_option('give_version', preg_replace('/[^0-9.].*/', '', GIVE_VERSION)); |
|
754 | 752 | |
755 | 753 | // Reset counter. |
756 | 754 | $this->step = $this->percentage = 0; |
757 | 755 | |
758 | - $this->update = ( $this->get_total_db_update_count() > $this->update ) ? |
|
759 | - ( $this->update + 1 ) : |
|
760 | - $this->update; |
|
756 | + $this->update = ($this->get_total_db_update_count() > $this->update) ? |
|
757 | + ($this->update + 1) : $this->update; |
|
761 | 758 | } |
762 | 759 | |
763 | 760 | |
@@ -772,7 +769,7 @@ discard block |
||
772 | 769 | public function __give_start_updating() { |
773 | 770 | // Check permission. |
774 | 771 | if ( |
775 | - ! current_user_can( 'manage_give_settings' ) || |
|
772 | + ! current_user_can('manage_give_settings') || |
|
776 | 773 | $this->is_doing_updates() |
777 | 774 | ) { |
778 | 775 | wp_send_json_error(); |
@@ -780,7 +777,7 @@ discard block |
||
780 | 777 | |
781 | 778 | // @todo: validate nonce |
782 | 779 | // @todo: set http method to post |
783 | - if ( empty( $_POST['run_db_update'] ) ) { |
|
780 | + if (empty($_POST['run_db_update'])) { |
|
784 | 781 | wp_send_json_error(); |
785 | 782 | } |
786 | 783 | |
@@ -799,34 +796,34 @@ discard block |
||
799 | 796 | * @return string |
800 | 797 | */ |
801 | 798 | public function __give_db_updates_info() { |
802 | - $update_info = get_option( 'give_doing_upgrade' ); |
|
799 | + $update_info = get_option('give_doing_upgrade'); |
|
803 | 800 | $response_type = ''; |
804 | 801 | |
805 | - if ( self::$background_updater->is_paused_process() ) { |
|
802 | + if (self::$background_updater->is_paused_process()) { |
|
806 | 803 | $update_info = array( |
807 | - 'message' => __( 'The updates have been paused.', 'give' ), |
|
808 | - 'heading' => __( '', 'give' ), |
|
804 | + 'message' => __('The updates have been paused.', 'give'), |
|
805 | + 'heading' => __('', 'give'), |
|
809 | 806 | 'percentage' => 0, |
810 | 807 | ); |
811 | 808 | |
812 | - if ( get_option( 'give_upgrade_error' ) ) { |
|
813 | - $update_info['message'] = __( 'An unexpected issue occurred during the database update which caused it to stop automatically. Please contact support for assistance.', 'give' ); |
|
809 | + if (get_option('give_upgrade_error')) { |
|
810 | + $update_info['message'] = __('An unexpected issue occurred during the database update which caused it to stop automatically. Please contact support for assistance.', 'give'); |
|
814 | 811 | } |
815 | 812 | |
816 | 813 | $response_type = 'error'; |
817 | 814 | |
818 | - } elseif ( empty( $update_info ) ) { |
|
815 | + } elseif (empty($update_info)) { |
|
819 | 816 | $update_info = array( |
820 | - 'message' => __( 'Give database updates completed successfully. Thank you for updating to the latest version!', 'give' ), |
|
821 | - 'heading' => __( 'Updates Completed.', 'give' ), |
|
817 | + 'message' => __('Give database updates completed successfully. Thank you for updating to the latest version!', 'give'), |
|
818 | + 'heading' => __('Updates Completed.', 'give'), |
|
822 | 819 | 'percentage' => 0, |
823 | 820 | ); |
824 | 821 | $response_type = 'success'; |
825 | 822 | |
826 | - delete_option( 'give_show_db_upgrade_complete_notice' ); |
|
823 | + delete_option('give_show_db_upgrade_complete_notice'); |
|
827 | 824 | } |
828 | 825 | |
829 | - $this->send_ajax_response( $update_info, $response_type ); |
|
826 | + $this->send_ajax_response($update_info, $response_type); |
|
830 | 827 | } |
831 | 828 | |
832 | 829 | /** |
@@ -838,7 +835,7 @@ discard block |
||
838 | 835 | * @param $data |
839 | 836 | * @param string $type |
840 | 837 | */ |
841 | - public function send_ajax_response( $data, $type = '' ) { |
|
838 | + public function send_ajax_response($data, $type = '') { |
|
842 | 839 | $default = array( |
843 | 840 | 'message' => '', |
844 | 841 | 'heading' => '', |
@@ -848,24 +845,24 @@ discard block |
||
848 | 845 | ); |
849 | 846 | |
850 | 847 | // Set data. |
851 | - $data = wp_parse_args( $data, $default ); |
|
848 | + $data = wp_parse_args($data, $default); |
|
852 | 849 | |
853 | 850 | // Enable cache. |
854 | 851 | Give_Cache::enable(); |
855 | 852 | |
856 | - switch ( $type ) { |
|
853 | + switch ($type) { |
|
857 | 854 | case 'success': |
858 | - wp_send_json_success( $data ); |
|
855 | + wp_send_json_success($data); |
|
859 | 856 | break; |
860 | 857 | |
861 | 858 | case 'error': |
862 | - wp_send_json_error( $data ); |
|
859 | + wp_send_json_error($data); |
|
863 | 860 | break; |
864 | 861 | |
865 | 862 | default: |
866 | - wp_send_json( array( |
|
863 | + wp_send_json(array( |
|
867 | 864 | 'data' => $data, |
868 | - ) ); |
|
865 | + )); |
|
869 | 866 | break; |
870 | 867 | } |
871 | 868 | } |
@@ -879,12 +876,12 @@ discard block |
||
879 | 876 | * @param $total |
880 | 877 | * @param $current_total |
881 | 878 | */ |
882 | - public function set_percentage( $total, $current_total ) { |
|
879 | + public function set_percentage($total, $current_total) { |
|
883 | 880 | // Set percentage. |
884 | - $this->percentage = $total ? ( ( $current_total ) / $total ) * 100 : 0; |
|
881 | + $this->percentage = $total ? (($current_total) / $total) * 100 : 0; |
|
885 | 882 | |
886 | 883 | // Verify percentage. |
887 | - $this->percentage = ( 100 < $this->percentage ) ? 100 : $this->percentage; |
|
884 | + $this->percentage = (100 < $this->percentage) ? 100 : $this->percentage; |
|
888 | 885 | } |
889 | 886 | |
890 | 887 | /** |
@@ -897,22 +894,22 @@ discard block |
||
897 | 894 | * |
898 | 895 | * @return bool|null |
899 | 896 | */ |
900 | - public function is_parent_updates_completed( $update ) { |
|
897 | + public function is_parent_updates_completed($update) { |
|
901 | 898 | // Bailout. |
902 | - if ( empty( $update['depend'] ) ) { |
|
899 | + if (empty($update['depend'])) { |
|
903 | 900 | return true; |
904 | 901 | } |
905 | 902 | |
906 | 903 | // Check if dependency is valid or not. |
907 | - if ( ! $this->has_valid_dependency( $update ) ) { |
|
904 | + if ( ! $this->has_valid_dependency($update)) { |
|
908 | 905 | return null; |
909 | 906 | } |
910 | 907 | |
911 | 908 | $is_dependency_completed = true; |
912 | 909 | |
913 | - foreach ( $update['depend'] as $depend ) { |
|
910 | + foreach ($update['depend'] as $depend) { |
|
914 | 911 | |
915 | - if ( ! give_has_upgrade_completed( $depend ) ) { |
|
912 | + if ( ! give_has_upgrade_completed($depend)) { |
|
916 | 913 | $is_dependency_completed = false; |
917 | 914 | break; |
918 | 915 | } |
@@ -929,7 +926,7 @@ discard block |
||
929 | 926 | * @return bool |
930 | 927 | */ |
931 | 928 | public function is_doing_updates() { |
932 | - return (bool) get_option( 'give_doing_upgrade' ); |
|
929 | + return (bool) get_option('give_doing_upgrade'); |
|
933 | 930 | } |
934 | 931 | |
935 | 932 | |
@@ -943,7 +940,7 @@ discard block |
||
943 | 940 | * |
944 | 941 | * @return bool |
945 | 942 | */ |
946 | - public function has_valid_dependency( $update ) { |
|
943 | + public function has_valid_dependency($update) { |
|
947 | 944 | $is_valid_dependency = true; |
948 | 945 | // $update_ids = wp_list_pluck( $this->get_updates( 'database', 'all' ), 'id' ); |
949 | 946 | // |
@@ -969,33 +966,33 @@ discard block |
||
969 | 966 | * |
970 | 967 | * @return array |
971 | 968 | */ |
972 | - public function get_updates( $update_type = '', $status = 'all' ) { |
|
969 | + public function get_updates($update_type = '', $status = 'all') { |
|
973 | 970 | // return all updates. |
974 | - if ( empty( $update_type ) ) { |
|
971 | + if (empty($update_type)) { |
|
975 | 972 | return $this->updates; |
976 | 973 | } |
977 | 974 | |
978 | 975 | // Get specific update. |
979 | - $updates = ! empty( $this->updates[ $update_type ] ) ? $this->updates[ $update_type ] : array(); |
|
976 | + $updates = ! empty($this->updates[$update_type]) ? $this->updates[$update_type] : array(); |
|
980 | 977 | |
981 | 978 | // Bailout. |
982 | - if ( empty( $updates ) ) { |
|
979 | + if (empty($updates)) { |
|
983 | 980 | return $updates; |
984 | 981 | } |
985 | 982 | |
986 | - switch ( $status ) { |
|
983 | + switch ($status) { |
|
987 | 984 | case 'new': |
988 | 985 | // Remove already completed updates. |
989 | - wp_cache_delete( 'give_completed_upgrades', 'options' ); |
|
986 | + wp_cache_delete('give_completed_upgrades', 'options'); |
|
990 | 987 | $completed_updates = give_get_completed_upgrades(); |
991 | 988 | |
992 | - if ( ! empty( $completed_updates ) ) { |
|
993 | - foreach ( $updates as $index => $update ) { |
|
994 | - if ( in_array( $update['id'], $completed_updates ) ) { |
|
995 | - unset( $updates[ $index ] ); |
|
989 | + if ( ! empty($completed_updates)) { |
|
990 | + foreach ($updates as $index => $update) { |
|
991 | + if (in_array($update['id'], $completed_updates)) { |
|
992 | + unset($updates[$index]); |
|
996 | 993 | } |
997 | 994 | } |
998 | - $updates = array_values( $updates ); |
|
995 | + $updates = array_values($updates); |
|
999 | 996 | } |
1000 | 997 | |
1001 | 998 | break; |
@@ -1012,7 +1009,7 @@ discard block |
||
1012 | 1009 | * @return int |
1013 | 1010 | */ |
1014 | 1011 | public function get_total_plugin_update_count() { |
1015 | - return count( $this->get_updates( 'plugin' ) ); |
|
1012 | + return count($this->get_updates('plugin')); |
|
1016 | 1013 | } |
1017 | 1014 | |
1018 | 1015 | /** |
@@ -1027,7 +1024,7 @@ discard block |
||
1027 | 1024 | $db_update_count = $this->get_pending_db_update_count(); |
1028 | 1025 | $plugin_update_count = $this->get_total_plugin_update_count(); |
1029 | 1026 | |
1030 | - return ( $db_update_count + $plugin_update_count ); |
|
1027 | + return ($db_update_count + $plugin_update_count); |
|
1031 | 1028 | } |
1032 | 1029 | |
1033 | 1030 | /** |
@@ -1039,7 +1036,7 @@ discard block |
||
1039 | 1036 | * @return int |
1040 | 1037 | */ |
1041 | 1038 | public function get_pending_db_update_count() { |
1042 | - return count( $this->get_updates( 'database', 'new' ) ); |
|
1039 | + return count($this->get_updates('database', 'new')); |
|
1043 | 1040 | } |
1044 | 1041 | |
1045 | 1042 | /** |
@@ -1051,7 +1048,7 @@ discard block |
||
1051 | 1048 | * @return int |
1052 | 1049 | */ |
1053 | 1050 | public function get_total_db_update_count() { |
1054 | - return count( $this->get_updates( 'database', 'all' ) ); |
|
1051 | + return count($this->get_updates('database', 'all')); |
|
1055 | 1052 | } |
1056 | 1053 | |
1057 | 1054 | /** |
@@ -1064,10 +1061,9 @@ discard block |
||
1064 | 1061 | * |
1065 | 1062 | * @return int |
1066 | 1063 | */ |
1067 | - public function get_total_new_db_update_count( $refresh = false ) { |
|
1064 | + public function get_total_new_db_update_count($refresh = false) { |
|
1068 | 1065 | $update_count = $this->is_doing_updates() && ! $refresh ? |
1069 | - get_option( 'give_db_update_count' ) : |
|
1070 | - $this->get_pending_db_update_count(); |
|
1066 | + get_option('give_db_update_count') : $this->get_pending_db_update_count(); |
|
1071 | 1067 | |
1072 | 1068 | return $update_count; |
1073 | 1069 | } |
@@ -1082,11 +1078,11 @@ discard block |
||
1082 | 1078 | * |
1083 | 1079 | * @return int |
1084 | 1080 | */ |
1085 | - public function get_running_db_update( $refresh = false ) { |
|
1081 | + public function get_running_db_update($refresh = false) { |
|
1086 | 1082 | $current_update = 1; |
1087 | 1083 | |
1088 | - if ( $this->is_doing_updates() && ! $refresh ) { |
|
1089 | - $current_update = get_option( 'give_doing_upgrade' ); |
|
1084 | + if ($this->is_doing_updates() && ! $refresh) { |
|
1085 | + $current_update = get_option('give_doing_upgrade'); |
|
1090 | 1086 | $current_update = $current_update['update']; |
1091 | 1087 | } |
1092 | 1088 | |
@@ -1103,25 +1099,23 @@ discard block |
||
1103 | 1099 | * |
1104 | 1100 | * @return float|int |
1105 | 1101 | */ |
1106 | - public function get_db_update_processing_percentage( $refresh = false ) { |
|
1102 | + public function get_db_update_processing_percentage($refresh = false) { |
|
1107 | 1103 | // Bailout. |
1108 | - if ( ! $this->get_total_new_db_update_count( $refresh ) ) { |
|
1104 | + if ( ! $this->get_total_new_db_update_count($refresh)) { |
|
1109 | 1105 | return 0; |
1110 | 1106 | } |
1111 | 1107 | |
1112 | - $resume_update = get_option( 'give_doing_upgrade' ); |
|
1113 | - $update_count_percentages = ( ( $this->get_running_db_update( $refresh ) - 1 ) / $this->get_total_new_db_update_count( $refresh ) ) * 100; |
|
1114 | - $update_percentage_share = ( 1 / $this->get_total_new_db_update_count() ) * 100; |
|
1115 | - $upgrade_percentage = ( ( $resume_update['percentage'] * $update_percentage_share ) / 100 ); |
|
1108 | + $resume_update = get_option('give_doing_upgrade'); |
|
1109 | + $update_count_percentages = (($this->get_running_db_update($refresh) - 1) / $this->get_total_new_db_update_count($refresh)) * 100; |
|
1110 | + $update_percentage_share = (1 / $this->get_total_new_db_update_count()) * 100; |
|
1111 | + $upgrade_percentage = (($resume_update['percentage'] * $update_percentage_share) / 100); |
|
1116 | 1112 | |
1117 | 1113 | $final_percentage = $update_count_percentages + $upgrade_percentage; |
1118 | 1114 | |
1119 | 1115 | return $this->is_doing_updates() ? |
1120 | - ( absint( $final_percentage ) ? |
|
1121 | - absint( $final_percentage ) : |
|
1122 | - round( $final_percentage, 2 ) |
|
1123 | - ) : |
|
1124 | - 0; |
|
1116 | + (absint($final_percentage) ? |
|
1117 | + absint($final_percentage) : round($final_percentage, 2) |
|
1118 | + ) : 0; |
|
1125 | 1119 | } |
1126 | 1120 | |
1127 | 1121 | |
@@ -1133,8 +1127,8 @@ discard block |
||
1133 | 1127 | * @return array |
1134 | 1128 | */ |
1135 | 1129 | public function get_update_ids() { |
1136 | - $all_updates = $this->get_updates( 'database', 'all' ); |
|
1137 | - $all_update_ids = wp_list_pluck( $all_updates, 'id' ); |
|
1130 | + $all_updates = $this->get_updates('database', 'all'); |
|
1131 | + $all_update_ids = wp_list_pluck($all_updates, 'id'); |
|
1138 | 1132 | |
1139 | 1133 | return $all_update_ids; |
1140 | 1134 | } |