| @@ -6,8 +6,13 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace MainWP\Dashboard; |
| 9 | 9 | |
| 10 | +// Exit if accessed directly. | |
| 11 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 12 | + exit; | |
| 13 | +} | |
| 14 | + | |
| 10 | 15 | /** |
| 11 | 16 | * Class MainWP_Cron_Jobs_Batch |
| 12 | 17 | * |
| 13 | 18 | * @package MainWP\Dashboard |
| @@ -61,10 +66,32 @@ | ||
| 61 | 66 | */ |
| 62 | 67 | public function check_to_run_batch_updates() { |
| 63 | 68 | $batch_updates_running = get_option( 'mainwp_batch_updates_is_running', 0 ); |
| 64 | 69 | $batch_individual_updates_running = get_option( 'mainwp_batch_individual_updates_is_running', 0 ); |
| 70 | + | |
| 71 | + $local_timestamp = MainWP_Utility::get_timestamp(); | |
| 72 | + | |
| 73 | + if ( $batch_updates_running ) { | |
| 74 | + // check timeout. | |
| 75 | + $start_time = get_option( 'mainwp_batch_updates_start_time', 0 ); | |
| 76 | + if ( ! empty( $start_time ) && $local_timestamp > $start_time + 4 * HOUR_IN_SECONDS ) { | |
| 77 | + $batch_updates_running = 0; | |
| 78 | + MainWP_Utility::update_option( 'mainwp_batch_updates_is_running', 0 ); // stop. | |
| 79 | + } | |
| 80 | + } | |
| 81 | + | |
| 82 | + if ( $batch_individual_updates_running ) { | |
| 83 | + // check timeout. | |
| 84 | + $start_time = get_option( 'mainwp_batch_updates_individual_start_time', 0 ); | |
| 85 | + if ( ! empty( $start_time ) && $local_timestamp > $start_time + 3 * HOUR_IN_SECONDS ) { | |
| 86 | + $batch_individual_updates_running = 0; | |
| 87 | + MainWP_Utility::update_option( 'mainwp_batch_individual_updates_is_running', 0 ); // stop. | |
| 88 | + } | |
| 89 | + } | |
| 90 | + | |
| 65 | 91 | // a batch updates running so wait to finish to run auto updates check. |
| 66 | 92 | if ( $batch_updates_running || $batch_individual_updates_running ) { |
| 93 | + | |
| 67 | 94 | return true; |
| 68 | 95 | } |
| 69 | 96 | return false; |
| 70 | 97 | } |
| @@ -206,9 +233,9 @@ | ||
| 206 | 233 | if ( ! is_array( $info ) ) { |
| 207 | 234 | continue; |
| 208 | 235 | } |
| 209 | 236 | if ( ! isset( $updated_status['updates_processed']['plugins'][ $slug ] ) ) { |
| 210 | - $ignored = MainWP_Common_Functions::instance()->is_ignored_updates( $info, $decodedIgnoredPlugins ) || MainWP_Common_Functions::instance()->is_ignored_updates( $info, $websiteDecodedIgnoredPlugins ); | |
| 237 | + $ignored = MainWP_Common_Functions::instance()->is_ignored_updates( $info, $decodedIgnoredPlugins, 'plugin' ) || MainWP_Common_Functions::instance()->is_ignored_updates( $info, $websiteDecodedIgnoredPlugins, 'plugin' ); | |
| 211 | 238 | if ( $ignored ) { |
| 212 | 239 | $info['ignored'] = 1; |
| 213 | 240 | } |
| 214 | 241 | $updated_status['updates_processed']['plugins'][ $slug ] = $info; |
| @@ -256,12 +283,8 @@ | ||
| 256 | 283 | * |
| 257 | 284 | * @since 4.1 |
| 258 | 285 | */ |
| 259 | 286 | do_action( 'mainwp_after_plugin_theme_translation_update', $information, 'plugin', implode( ',', $pluginsToUpdateNow ), $website ); |
| 260 | - | |
| 261 | - if ( isset( $information['sync'] ) && ! empty( $information['sync'] ) ) { | |
| 262 | - MainWP_Sync::sync_information_array( $website, $information['sync'] ); | |
| 263 | - } | |
| 264 | 287 | } catch ( \Exception $e ) { |
| 265 | 288 | // error. |
| 266 | 289 | } |
| 267 | 290 | } |
| @@ -272,9 +295,9 @@ | ||
| 272 | 295 | if ( ! is_array( $info ) ) { |
| 273 | 296 | continue; |
| 274 | 297 | } |
| 275 | 298 | if ( ! isset( $updated_status['updates_processed']['themes'][ $slug ] ) ) { |
| 276 | - $ignored = MainWP_Common_Functions::instance()->is_ignored_updates( $info, $decodedIgnoredThemes ) || MainWP_Common_Functions::instance()->is_ignored_updates( $info, $websiteDecodedIgnoredThemes ); | |
| 299 | + $ignored = MainWP_Common_Functions::instance()->is_ignored_updates( $info, $decodedIgnoredThemes, 'theme' ) || MainWP_Common_Functions::instance()->is_ignored_updates( $info, $websiteDecodedIgnoredThemes, 'theme' ); | |
| 277 | 300 | if ( $ignored ) { |
| 278 | 301 | $info['ignored'] = 1; |
| 279 | 302 | } |
| 280 | 303 | $updated_status['updates_processed']['themes'][ $slug ] = $info; |
| @@ -309,12 +332,8 @@ | ||
| 309 | 332 | 'type' => 'theme', |
| 310 | 333 | 'list' => urldecode( implode( ',', $themesToUpdateNow ) ), |
| 311 | 334 | ) |
| 312 | 335 | ); |
| 313 | - | |
| 314 | - if ( isset( $information['sync'] ) && ! empty( $information['sync'] ) ) { | |
| 315 | - MainWP_Sync::sync_information_array( $website, $information['sync'] ); | |
| 316 | - } | |
| 317 | 336 | } catch ( \Exception $e ) { |
| 318 | 337 | // ok. |
| 319 | 338 | } |
| 320 | 339 | |
| @@ -329,9 +348,9 @@ | ||
| 329 | 348 | } |
| 330 | 349 | } |
| 331 | 350 | |
| 332 | 351 | // batch processing limits. |
| 333 | - if ( $count_processed_now < $items_limit && ! empty( $coreToUpdate ) && empty( $updated_status['wp'] ) ) { | |
| 352 | + if ( $count_processed_now < $items_limit && ! empty( $coreToUpdate ) ) { | |
| 334 | 353 | |
| 335 | 354 | $info = $coreToUpdate; |
| 336 | 355 | |
| 337 | 356 | $ignored = MainWP_Common_Functions::instance()->is_ignored_updates( $coreToUpdate, $decodedIgnoredCores, 'core' ) || MainWP_Common_Functions::instance()->is_ignored_updates( $coreToUpdate, $websiteDecodedIgnoredCores, 'core' ); |
| @@ -341,8 +360,17 @@ | ||
| 341 | 360 | } |
| 342 | 361 | |
| 343 | 362 | $updated_status['updates_processed']['wp'] = $info; |
| 344 | 363 | |
| 364 | + // Clear previous errors before processing. | |
| 365 | + if ( isset( $updated_status['wp']['error'] ) ) { | |
| 366 | + unset( $updated_status['wp']['error'] ); | |
| 367 | + } | |
| 368 | + | |
| 369 | + if ( isset( $updated_status['wp']['lasttime_error'] ) ) { | |
| 370 | + unset( $updated_status['wp']['lasttime_error'] ); | |
| 371 | + } | |
| 372 | + | |
| 345 | 373 | if ( ! $ignored ) { |
| 346 | 374 | ++$count_processed_now; |
| 347 | 375 | MainWP_DB::instance()->update_website_option( $website, 'bulk_updates_info', wp_json_encode( $updated_status ) ); |
| 348 | 376 | MainWP_Logger::instance()->log_update_check( 'Batch updates core [websiteid=' . $website->id . ']' ); |
| @@ -348,9 +376,10 @@ | ||
| 348 | 376 | MainWP_Logger::instance()->log_update_check( 'Batch updates core [websiteid=' . $website->id . ']' ); |
| 349 | 377 | try { |
| 350 | 378 | MainWP_Connect::fetch_url_authed( $website, 'upgrade' ); |
| 351 | 379 | } catch ( \Exception $e ) { |
| 352 | - $updated_status['wp']['error'] = $e->getMessage(); | |
| 380 | + $updated_status['wp']['error'] = $e->getMessage(); | |
| 381 | + $updated_status['wp']['lasttime_error'] = time(); | |
| 353 | 382 | MainWP_DB::instance()->update_website_option( $website, 'bulk_updates_info', wp_json_encode( $updated_status ) ); |
| 354 | 383 | } |
| 355 | 384 | } |
| 356 | 385 | } |
| @@ -474,9 +503,9 @@ | ||
| 474 | 503 | foreach ( $websitePlugins as $pluginSlug => $pluginInfo ) { |
| 475 | 504 | if ( $website->is_ignorePluginUpdates ) { |
| 476 | 505 | continue; |
| 477 | 506 | } |
| 478 | - if ( MainWP_Common_Functions::instance()->is_ignored_updates( $pluginInfo, $decodedIgnoredPlugins ) || MainWP_Common_Functions::instance()->is_ignored_updates( $pluginInfo, $websiteDecodedIgnoredPlugins ) ) { | |
| 507 | + if ( MainWP_Common_Functions::instance()->is_ignored_updates( $pluginInfo, $decodedIgnoredPlugins, 'plugin' ) || MainWP_Common_Functions::instance()->is_ignored_updates( $pluginInfo, $websiteDecodedIgnoredPlugins, 'plugin' ) ) { | |
| 479 | 508 | continue; |
| 480 | 509 | } |
| 481 | 510 | |
| 482 | 511 | $change_log = ''; |
| @@ -502,9 +531,9 @@ | ||
| 502 | 531 | foreach ( $websiteThemes as $themeSlug => $themeInfo ) { |
| 503 | 532 | if ( $website->is_ignoreThemeUpdates ) { |
| 504 | 533 | continue; |
| 505 | 534 | } |
| 506 | - if ( MainWP_Common_Functions::instance()->is_ignored_updates( $themeInfo, $decodedIgnoredThemes ) || MainWP_Common_Functions::instance()->is_ignored_updates( $themeInfo, $websiteDecodedIgnoredThemes ) ) { | |
| 535 | + if ( MainWP_Common_Functions::instance()->is_ignored_updates( $themeInfo, $decodedIgnoredThemes, 'theme' ) || MainWP_Common_Functions::instance()->is_ignored_updates( $themeInfo, $websiteDecodedIgnoredThemes, 'theme' ) ) { | |
| 507 | 536 | continue; |
| 508 | 537 | } |
| 509 | 538 | $item = array( |
| 510 | 539 | 'slug' => $themeSlug, |