| @@ -4,15 +4,13 @@ | ||
| 4 | 4 | if (!class_exists('BVManageCallback')) : |
| 5 | 5 | class BVManageCallback extends BVCallbackBase { |
| 6 | 6 | public $settings; |
| 7 | 7 | public $skin; |
| 8 | - public $bvinfo; | |
| 9 | 8 | |
| 10 | - const MANAGE_WING_VERSION = 1.5; | |
| 9 | + const MANAGE_WING_VERSION = 1.0; | |
| 11 | 10 | |
| 12 | 11 | public function __construct($callback_handler) { |
| 13 | 12 | $this->settings = $callback_handler->settings; |
| 14 | - $this->bvinfo = new WPRInfo($this->settings); | |
| 15 | 13 | } |
| 16 | 14 | |
| 17 | 15 | function getError($err) { |
| 18 | 16 | return $this->objectToArray($err); |
| @@ -41,10 +39,8 @@ | ||
| 41 | 39 | @include_once ABSPATH.'wp-admin/includes/misc.php'; |
| 42 | 40 | @include_once ABSPATH.'wp-admin/includes/template.php'; |
| 43 | 41 | @include_once ABSPATH.'wp-includes/pluggable.php'; |
| 44 | 42 | @include_once ABSPATH.'wp-admin/includes/class-wp-upgrader.php'; |
| 45 | - @include_once ABSPATH.'wp-admin/includes/class-theme-upgrader.php'; | |
| 46 | - @include_once ABSPATH.'wp-admin/includes/class-plugin-upgrader.php'; | |
| 47 | 43 | @include_once ABSPATH.'wp-admin/includes/user.php'; |
| 48 | 44 | @include_once ABSPATH.'wp-includes/registration.php'; |
| 49 | 45 | @include_once ABSPATH.'wp-admin/includes/upgrade.php'; |
| 50 | 46 | @include_once ABSPATH.'wp-admin/includes/update.php'; |
| @@ -189,16 +185,11 @@ | ||
| 189 | 185 | return array('status' => "Error", 'message' => $this->getError($result)); |
| 190 | 186 | } |
| 191 | 187 | } |
| 192 | 188 | |
| 193 | - function upgrade($params = null, $has_bv_skin = false, $bv_bulk_upgrade = false) { | |
| 189 | + function upgrade($params = null, $has_bv_skin = false) { | |
| 194 | 190 | $result = array(); |
| 195 | 191 | $premium_upgrades = array(); |
| 196 | - if (array_key_exists('clear_filters', $params)) { | |
| 197 | - $filters = $params['clear_filters']; | |
| 198 | - foreach ($filters as $filter) | |
| 199 | - remove_all_filters($filter); | |
| 200 | - } | |
| 201 | 192 | if (array_key_exists('core', $params) && !empty($params['core'])) { |
| 202 | 193 | $result['core'] = $this->upgradeCore($params['core']); |
| 203 | 194 | } |
| 204 | 195 | if (array_key_exists('translations', $params) && !empty($params['translations'])) { |
| @@ -204,12 +195,24 @@ | ||
| 204 | 195 | if (array_key_exists('translations', $params) && !empty($params['translations'])) { |
| 205 | 196 | $result['translations'] = $this->upgradeTranslations($params['translations'], $has_bv_skin); |
| 206 | 197 | } |
| 207 | 198 | if (array_key_exists('plugins', $params) && !empty($params['plugins'])) { |
| 208 | - $result['plugins'] = $this->upgradePlugins($params['plugins'], $has_bv_skin, $bv_bulk_upgrade); | |
| 199 | + $files = array(); | |
| 200 | + foreach ($params['plugins'] as $plugin) { | |
| 201 | + $files[] = $plugin['file']; | |
| 202 | + } | |
| 203 | + if (!empty($files)) { | |
| 204 | + $result['plugins'] = $this->upgradePlugins($files, $has_bv_skin); | |
| 205 | + } | |
| 209 | 206 | } |
| 210 | 207 | if (array_key_exists('themes', $params) && !empty($params['themes'])) { |
| 211 | - $result['themes'] = $this->upgradeThemes($params['themes'], $has_bv_skin, $bv_bulk_upgrade); | |
| 208 | + $stylesheets = array(); | |
| 209 | + foreach ($params['themes'] as $theme) { | |
| 210 | + $stylesheets[] = $theme['stylesheet']; | |
| 211 | + } | |
| 212 | + if (!empty($stylesheets)) { | |
| 213 | + $result['themes'] = $this->upgradeThemes($stylesheets, $has_bv_skin); | |
| 214 | + } | |
| 212 | 215 | } |
| 213 | 216 | return $result; |
| 214 | 217 | } |
| 215 | 218 | |
| @@ -341,214 +344,34 @@ | ||
| 341 | 344 | } |
| 342 | 345 | } |
| 343 | 346 | } |
| 344 | 347 | |
| 345 | - function bv_plugin_bulk_upgrade($upgrader, $_plugins) { | |
| 346 | - $plugins = array_keys($_plugins); | |
| 347 | - $args = array(); | |
| 348 | - $defaults = array( | |
| 349 | - 'clear_update_cache' => true, | |
| 350 | - ); | |
| 351 | - $parsed_args = wp_parse_args($args, $defaults); | |
| 352 | - $upgrader->init(); | |
| 353 | - $upgrader->bulk = true; | |
| 354 | - $upgrader->upgrade_strings(); | |
| 355 | - add_filter('upgrader_clear_destination', array($upgrader, 'delete_old_plugin'), 10, 4); | |
| 356 | - $upgrader->skin->header(); | |
| 357 | - $res = $upgrader->fs_connect(array(WP_CONTENT_DIR, WP_PLUGIN_DIR)); | |
| 358 | - if (!$res) { | |
| 359 | - $upgrader->skin->footer(); | |
| 360 | - return false; | |
| 361 | - } | |
| 362 | - $upgrader->skin->bulk_header(); | |
| 363 | - $maintenance = (is_multisite() && ! empty($plugins)); | |
| 364 | - foreach ($plugins as $plugin) { | |
| 365 | - $maintenance = $maintenance || (is_plugin_active($plugin)); | |
| 366 | - } | |
| 367 | - if ($maintenance) { | |
| 368 | - $upgrader->maintenance_mode(true); | |
| 369 | - } | |
| 370 | - $results = array(); | |
| 371 | - $upgrader->update_count = count($plugins); | |
| 372 | - $upgrader->update_current = 0; | |
| 373 | - foreach($plugins as $plugin) { | |
| 374 | - $upgrader->update_current++; | |
| 375 | - $upgrader->skin->plugin_info = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin, false, true); | |
| 376 | - $upgrader->skin->plugin_active = is_plugin_active($plugin); | |
| 377 | - $result = $upgrader->run( | |
| 378 | - array( | |
| 379 | - 'package' => $_plugins[$plugin], | |
| 380 | - 'destination' => WP_PLUGIN_DIR, | |
| 381 | - 'clear_destination' => true, | |
| 382 | - 'clear_working' => true, | |
| 383 | - 'is_multi' => true, | |
| 384 | - 'hook_extra' => array( | |
| 385 | - 'plugin' => $plugin, | |
| 386 | - ), | |
| 387 | - ) | |
| 388 | - ); | |
| 389 | - $results[$plugin] = $result; | |
| 390 | - if (false === $result) { | |
| 391 | - break; | |
| 392 | - } | |
| 393 | - } | |
| 394 | - $upgrader->maintenance_mode(false); | |
| 395 | - wp_clean_plugins_cache($parsed_args['clear_update_cache']); | |
| 396 | - do_action( | |
| 397 | - 'upgrader_process_complete', | |
| 398 | - $upgrader, | |
| 399 | - array( | |
| 400 | - 'action' => 'update', | |
| 401 | - 'type' => 'plugin', | |
| 402 | - 'bulk' => true, | |
| 403 | - 'plugins' => $plugins, | |
| 404 | - ) | |
| 405 | - ); | |
| 406 | - $upgrader->skin->bulk_footer(); | |
| 407 | - $upgrader->skin->footer(); | |
| 408 | - remove_filter('upgrader_clear_destination', array($upgrader, 'delete_old_plugin')); | |
| 409 | - $past_failure_emails = get_option('auto_plugin_theme_update_emails', array()); | |
| 410 | - foreach ($results as $plugin => $result) { | |
| 411 | - if (!$result || is_wp_error($result) || !isset($past_failure_emails[$plugin])) { | |
| 412 | - continue; | |
| 413 | - } | |
| 414 | - unset($past_failure_emails[$plugin]); | |
| 415 | - } | |
| 416 | - update_option('auto_plugin_theme_update_emails', $past_failure_emails); | |
| 417 | - return $results; | |
| 418 | - } | |
| 419 | - | |
| 420 | - function upgradePlugins($plugins, $has_bv_skin = false, $bv_bulk_upgrade = false) { | |
| 348 | + function upgradePlugins($plugins, $has_bv_skin = false) { | |
| 421 | 349 | $result = array(); |
| 422 | - $_plugins = array(); | |
| 423 | - $plugins_by_name = array(); | |
| 424 | - foreach ($plugins as $plugin) { | |
| 425 | - $_plugins[$plugin['file']] = $plugin['package']; | |
| 426 | - $plugin_data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin['file'], false, true); | |
| 427 | - $plugins_by_name[$plugin_data['Name']] = $plugin['file']; | |
| 428 | - } | |
| 429 | - if (empty(array_keys($_plugins))) { | |
| 430 | - return $result; | |
| 431 | - } | |
| 432 | 350 | if (class_exists('Plugin_Upgrader')) { |
| 433 | 351 | if ($has_bv_skin) { |
| 434 | 352 | require_once( "bv_upgrader_skin.php" ); |
| 435 | - $skin = new BVUpgraderSkin("plugin_upgrade", $plugins_by_name); | |
| 353 | + $skin = new BVUpgraderSkin("plugin_upgrade"); | |
| 436 | 354 | $this->skin = $skin; |
| 437 | 355 | } else { |
| 438 | 356 | $skin = new Bulk_Plugin_Upgrader_Skin(); |
| 439 | 357 | } |
| 440 | 358 | $upgrader = new Plugin_Upgrader($skin); |
| 441 | - | |
| 442 | - if ($bv_bulk_upgrade) { | |
| 443 | - $result = $this->bv_plugin_bulk_upgrade($upgrader, $_plugins); | |
| 444 | - } else { | |
| 445 | - $result = $upgrader->bulk_upgrade(array_keys($_plugins)); | |
| 446 | - } | |
| 447 | - foreach (array_keys($_plugins) as $file) { | |
| 448 | - if (!array_key_exists($file, $result)) { | |
| 359 | + $result = $upgrader->bulk_upgrade($plugins); | |
| 360 | + } | |
| 361 | + foreach($plugins as $file) { | |
| 362 | + $res = $result[$file]; | |
| 363 | + if (!$res || is_wp_error($res)) { | |
| 449 | 364 | $result[$file] = array('status' => "Error"); |
| 450 | 365 | } else { |
| 451 | - $res = $result[$file]; | |
| 452 | - if (!$res || is_wp_error($res)) { | |
| 453 | - $result[$file] = array('status' => "Error"); | |
| 454 | - } else { | |
| 455 | - $result[$file] = array('status' => "Done"); | |
| 456 | - } | |
| 366 | + $result[$file] = array('status' => "Done"); | |
| 457 | 367 | } |
| 458 | - } | |
| 459 | 368 | } |
| 460 | 369 | return $result; |
| 461 | 370 | } |
| 462 | 371 | |
| 463 | - function bv_theme_bulk_upgrade($upgrader, $_themes) { | |
| 464 | - $themes = array_keys($_themes); | |
| 465 | - $args = array(); | |
| 466 | - $defaults = array( | |
| 467 | - 'clear_update_cache' => true, | |
| 468 | - ); | |
| 469 | - $parsed_args = wp_parse_args($args, $defaults); | |
| 470 | - $upgrader->init(); | |
| 471 | - $upgrader->bulk = true; | |
| 472 | - $upgrader->upgrade_strings(); | |
| 473 | - add_filter('upgrader_pre_install', array($upgrader, 'current_before'), 10, 2); | |
| 474 | - add_filter('upgrader_post_install', array( $upgrader, 'current_after'), 10, 2); | |
| 475 | - add_filter('upgrader_clear_destination', array($upgrader, 'delete_old_theme'), 10, 4); | |
| 476 | - $upgrader->skin->header(); | |
| 477 | - $res = $upgrader->fs_connect(array(WP_CONTENT_DIR)); | |
| 478 | - if (!$res) { | |
| 479 | - $upgrader->skin->footer(); | |
| 480 | - return false; | |
| 481 | - } | |
| 482 | - $upgrader->skin->bulk_header(); | |
| 483 | - $maintenance = (is_multisite() && !empty($themes)); | |
| 484 | - foreach ($themes as $theme) { | |
| 485 | - $maintenance = $maintenance || get_stylesheet() === $theme || get_template() === $theme; | |
| 486 | - } | |
| 487 | - if ($maintenance) { | |
| 488 | - $upgrader->maintenance_mode(true); | |
| 489 | - } | |
| 490 | - $results = array(); | |
| 491 | - $upgrader->update_count = count($themes); | |
| 492 | - $upgrader->update_current = 0; | |
| 493 | - foreach ($themes as $theme) { | |
| 494 | - $upgrader->update_current++; | |
| 495 | - $upgrader->skin->theme_info = $upgrader->theme_info($theme); | |
| 496 | - $result = $upgrader->run( | |
| 497 | - array( | |
| 498 | - 'package' => $_themes[$theme], | |
| 499 | - 'destination' => get_theme_root($theme), | |
| 500 | - 'clear_destination' => true, | |
| 501 | - 'clear_working' => true, | |
| 502 | - 'is_multi' => true, | |
| 503 | - 'hook_extra' => array( | |
| 504 | - 'theme' => $theme, | |
| 505 | - ), | |
| 506 | - ) | |
| 507 | - ); | |
| 508 | - | |
| 509 | - $results[$theme] = $result; | |
| 510 | - if (false === $result) { | |
| 511 | - break; | |
| 512 | - } | |
| 513 | - } | |
| 514 | - $upgrader->maintenance_mode(false); | |
| 515 | - wp_clean_themes_cache($parsed_args['clear_update_cache']); | |
| 516 | - do_action( | |
| 517 | - 'upgrader_process_complete', | |
| 518 | - $upgrader, | |
| 519 | - array( | |
| 520 | - 'action' => 'update', | |
| 521 | - 'type' => 'theme', | |
| 522 | - 'bulk' => true, | |
| 523 | - 'themes' => $themes, | |
| 524 | - ) | |
| 525 | - ); | |
| 526 | - $upgrader->skin->bulk_footer(); | |
| 527 | - $upgrader->skin->footer(); | |
| 528 | - remove_filter('upgrader_pre_install', array($upgrader, 'current_before')); | |
| 529 | - remove_filter('upgrader_post_install', array($upgrader, 'current_after')); | |
| 530 | - remove_filter('upgrader_clear_destination', array($upgrader, 'delete_old_theme')); | |
| 531 | - $past_failure_emails = get_option('auto_plugin_theme_update_emails', array()); | |
| 532 | - foreach ($results as $theme => $result) { | |
| 533 | - if (!$result || is_wp_error($result) || !isset($past_failure_emails[$theme])) { | |
| 534 | - continue; | |
| 535 | - } | |
| 536 | - unset($past_failure_emails[$theme]); | |
| 537 | - } | |
| 538 | - update_option('auto_plugin_theme_update_emails', $past_failure_emails); | |
| 539 | - return $results; | |
| 540 | - } | |
| 541 | - | |
| 542 | - function upgradeThemes($themes, $has_bv_skin = false, $bv_bulk_upgrade = false) { | |
| 372 | + function upgradeThemes($themes, $has_bv_skin = false) { | |
| 543 | 373 | $result = array(); |
| 544 | - $_themes = array(); | |
| 545 | - foreach ($themes as $theme) { | |
| 546 | - $_themes[$theme['stylesheet']] = $theme['package']; | |
| 547 | - } | |
| 548 | - if (empty(array_keys($_themes))) { | |
| 549 | - return $result; | |
| 550 | - } | |
| 551 | 374 | if (class_exists('Theme_Upgrader')) { |
| 552 | 375 | if ($has_bv_skin) { |
| 553 | 376 | require_once( "bv_upgrader_skin.php" ); |
| 554 | 377 | $skin = new BVUpgraderSkin("theme_upgrade"); |
| @@ -556,29 +379,21 @@ | ||
| 556 | 379 | } else { |
| 557 | 380 | $skin = new Bulk_Theme_Upgrader_Skin(); |
| 558 | 381 | } |
| 559 | 382 | $upgrader = new Theme_Upgrader($skin); |
| 560 | - if ($bv_bulk_upgrade) { | |
| 561 | - $result = $this->bv_theme_bulk_upgrade($upgrader, $_themes); | |
| 383 | + $result = $upgrader->bulk_upgrade($themes); | |
| 384 | + } | |
| 385 | + foreach($themes as $stylesheet) { | |
| 386 | + $res = $result[$stylesheet]; | |
| 387 | + if (!$res || is_wp_error($res)) { | |
| 388 | + $result[$stylesheet] = array('status' => "Error"); | |
| 562 | 389 | } else { |
| 563 | - $result = $upgrader->bulk_upgrade(array_keys($_themes)); | |
| 390 | + $result[$stylesheet] = array('status' => "Done"); | |
| 564 | 391 | } |
| 565 | - foreach (array_keys($_themes) as $stylesheet) { | |
| 566 | - if (!array_key_exists($stylesheet, $result)) { | |
| 567 | - $result[$stylesheet] = array('status' => "Error"); | |
| 568 | - } else { | |
| 569 | - $res = $result[$stylesheet]; | |
| 570 | - if (!$res || is_wp_error($res)) { | |
| 571 | - $result[$stylesheet] = array('status' => "Error"); | |
| 572 | - } else { | |
| 573 | - $result[$stylesheet] = array('status' => "Done"); | |
| 574 | - } | |
| 575 | - } | |
| 576 | - } | |
| 577 | 392 | } |
| 578 | 393 | return $result; |
| 579 | 394 | } |
| 580 | - | |
| 395 | + | |
| 581 | 396 | function install($params, $has_bv_skin = false) { |
| 582 | 397 | $result = array(); |
| 583 | 398 | if (isset($params['plugins'])) { |
| 584 | 399 | foreach ($params['plugins'] as $plugin) { |
| @@ -584,9 +399,9 @@ | ||
| 584 | 399 | foreach ($params['plugins'] as $plugin) { |
| 585 | 400 | if (!array_key_exists('plugins', $result)) |
| 586 | 401 | $result["plugins"] = array(); |
| 587 | 402 | $plugin['dest'] = WP_PLUGIN_DIR; |
| 588 | - $res = $this->installPackage("plugin", $plugin, $has_bv_skin); | |
| 403 | + $res = $this->installPackage($plugin, $has_bv_skin); | |
| 589 | 404 | $pluginName = $plugin['package']; |
| 590 | 405 | $result["plugins"][$pluginName] = $res; |
| 591 | 406 | } |
| 592 | 407 | } |
| @@ -594,9 +409,9 @@ | ||
| 594 | 409 | foreach ($params['themes'] as $theme) { |
| 595 | 410 | if (!array_key_exists('themes', $result)) |
| 596 | 411 | $result["themes"] = array(); |
| 597 | 412 | $theme['dest'] = WP_CONTENT_DIR.'/themes'; |
| 598 | - $res = $this->installPackage("theme", $theme, $has_bv_skin); | |
| 413 | + $res = $this->installPackage($theme, $has_bv_skin); | |
| 599 | 414 | $themeName = $theme['package']; |
| 600 | 415 | $result["themes"][$themeName] = $res; |
| 601 | 416 | } |
| 602 | 417 | } |
| @@ -602,9 +417,9 @@ | ||
| 602 | 417 | } |
| 603 | 418 | return $result; |
| 604 | 419 | } |
| 605 | 420 | |
| 606 | - function installPackage($type, $params, $has_bv_skin = false) { | |
| 421 | + function installPackage($params, $has_bv_skin = false) { | |
| 607 | 422 | global $wp_filesystem; |
| 608 | 423 | |
| 609 | 424 | if (!isset($params['package']) || empty($params['package'])) { |
| 610 | 425 | return array('status' => "Error", 'message' => "No package is sent"); |
| @@ -609,31 +424,24 @@ | ||
| 609 | 424 | if (!isset($params['package']) || empty($params['package'])) { |
| 610 | 425 | return array('status' => "Error", 'message' => "No package is sent"); |
| 611 | 426 | } |
| 612 | 427 | $valid_domain_regex = "/^(http|https):\/\/[\-\w]*\.(blogvault\.net|w\.org|wp\.org|wordpress\.org)\//"; |
| 613 | - if (WPRHelper::safePregMatch($valid_domain_regex, $params['package']) !== 1) { | |
| 428 | + if (preg_match($valid_domain_regex, $params['package']) !== 1) { | |
| 614 | 429 | return array('status' => "Error", 'message' => "Invalid package domain"); |
| 615 | 430 | } |
| 616 | 431 | if ($has_bv_skin) { |
| 617 | 432 | require_once( "bv_upgrader_skin.php" ); |
| 618 | - $skin = new BVUpgraderSkin("installer", array(), $params['package']); | |
| 433 | + $skin = new BVUpgraderSkin("installer", $params['package']); | |
| 619 | 434 | $this->skin = $skin; |
| 620 | 435 | } else { |
| 621 | 436 | $skin = new WP_Upgrader_Skin(); |
| 622 | 437 | } |
| 623 | - if ("plugin" === $type) { | |
| 624 | - $upgrader = new Plugin_Upgrader($skin); | |
| 625 | - } elseif ("theme" === $type) { | |
| 626 | - $upgrader = new Theme_Upgrader($skin); | |
| 627 | - } else { | |
| 628 | - $upgrader = new WP_Upgrader($skin); | |
| 629 | - } | |
| 438 | + $upgrader = new WP_Upgrader($skin); | |
| 630 | 439 | $upgrader->init(); |
| 631 | 440 | $destination = $params['dest']; |
| 632 | 441 | $clear_destination = isset($params['cleardest']) ? $params['cleardest'] : false; |
| 633 | 442 | $package_url = $params['package']; |
| 634 | 443 | $key = basename($package_url); |
| 635 | - add_filter('upgrader_source_selection', array($upgrader, 'check_package')); | |
| 636 | 444 | $res = $upgrader->run( |
| 637 | 445 | array( |
| 638 | 446 | 'package' => $package_url, |
| 639 | 447 | 'destination' => $destination, |
| @@ -638,15 +446,11 @@ | ||
| 638 | 446 | 'package' => $package_url, |
| 639 | 447 | 'destination' => $destination, |
| 640 | 448 | 'clear_destination' => $clear_destination, |
| 641 | 449 | 'clear_working' => true, |
| 642 | - 'hook_extra' => array( | |
| 643 | - "type" => $type, | |
| 644 | - "action" => "install" | |
| 645 | - ), | |
| 450 | + 'hook_extra' => array(), | |
| 646 | 451 | ) |
| 647 | 452 | ); |
| 648 | - remove_filter('upgrader_source_selection', array($upgrader, 'check_package')); | |
| 649 | 453 | if (is_wp_error($res)) { |
| 650 | 454 | $res = array('status' => "Error", 'message' => $this->getError($res)); |
| 651 | 455 | } else { |
| 652 | 456 | $res = array( 'status' => "Done"); |
| @@ -678,153 +482,12 @@ | ||
| 678 | 482 | exit; |
| 679 | 483 | } |
| 680 | 484 | } |
| 681 | 485 | |
| 682 | - public function refreshPluginUpdates() { | |
| 683 | - global $wp_current_filter; | |
| 684 | - $wp_current_filter[] = 'load-update-core.php'; | |
| 685 | - | |
| 686 | - wp_update_plugins(); | |
| 687 | - | |
| 688 | - array_pop($wp_current_filter); | |
| 689 | - | |
| 690 | - wp_update_plugins(); | |
| 691 | - | |
| 692 | - return true; | |
| 693 | - } | |
| 694 | - | |
| 695 | - public function refreshThemeUpdates() { | |
| 696 | - global $wp_current_filter; | |
| 697 | - $wp_current_filter[] = 'load-update-core.php'; | |
| 698 | - | |
| 699 | - wp_update_themes(); | |
| 700 | - | |
| 701 | - array_pop($wp_current_filter); | |
| 702 | - | |
| 703 | - wp_update_themes(); | |
| 704 | - | |
| 705 | - return true; | |
| 706 | - } | |
| 707 | - | |
| 708 | - function upgradeElementorDB($file) { | |
| 709 | - try { | |
| 710 | - if (!defined('ELEMENTOR_PATH')) { | |
| 711 | - return array('status' => 'Error', 'error' => 'Elementor not found', 'source' => 'BV'); | |
| 712 | - } | |
| 713 | - | |
| 714 | - $managerFilePath = ELEMENTOR_PATH . 'core/upgrade/manager.php'; | |
| 715 | - if (!file_exists($managerFilePath)) { | |
| 716 | - return array('status' => 'Error', 'error' => 'Manager file not found', 'source' => 'BV'); | |
| 717 | - } | |
| 718 | - | |
| 719 | - require_once $managerFilePath; | |
| 720 | - | |
| 721 | - if ($file === 'elementor-pro/elementor-pro.php') { | |
| 722 | - $managerClass = '\ElementorPro\Core\Upgrade\Manager'; | |
| 723 | - } else { | |
| 724 | - $managerClass = '\Elementor\Core\Upgrade\Manager'; | |
| 725 | - } | |
| 726 | - | |
| 727 | - $manager = new $managerClass(); | |
| 728 | - | |
| 729 | - $required_methods = array('get_task_runner', 'should_upgrade', 'on_runner_complete', | |
| 730 | - 'get_current_version', 'get_new_version'); | |
| 731 | - foreach ($required_methods as $method) { | |
| 732 | - if (!method_exists($manager, $method)) { | |
| 733 | - return array('status' => 'Error', 'error' => 'Required methods are missing', 'source' => 'BV'); | |
| 734 | - } | |
| 735 | - } | |
| 736 | - | |
| 737 | - $updateInfo = array( | |
| 738 | - 'from' => $manager->get_current_version(), | |
| 739 | - 'to' => $manager->get_new_version(), | |
| 740 | - ); | |
| 741 | - | |
| 742 | - if ($manager->should_upgrade()) { | |
| 743 | - $callbacks = $manager->get_upgrade_callbacks(); | |
| 744 | - | |
| 745 | - if (!empty($callbacks)) { | |
| 746 | - $manager->get_task_runner()->handle_immediately($callbacks); | |
| 747 | - $manager->on_runner_complete(true); | |
| 748 | - } | |
| 749 | - } else { | |
| 750 | - return array('status' => 'Error', 'error' => 'Database Update is not available currently', | |
| 751 | - 'update_info' => $updateInfo, 'source' => 'BV'); | |
| 752 | - } | |
| 753 | - | |
| 754 | - return array('status' => 'Done', 'update_info' => $updateInfo); | |
| 755 | - } catch (Exception $e) { | |
| 756 | - return array('status' => 'Error', 'error' => $e->getMessage()); | |
| 757 | - } | |
| 758 | - } | |
| 759 | - | |
| 760 | - function upgradeWoocommerceDb() { | |
| 761 | - try { | |
| 762 | - if (!defined('WC_ABSPATH')) { | |
| 763 | - return array('status' => 'Error', 'error' => 'WC not found', 'source' => 'BV'); | |
| 764 | - } | |
| 765 | - | |
| 766 | - if (file_exists(WC_ABSPATH . 'includes/class-wc-install.php')) { | |
| 767 | - include_once WC_ABSPATH . 'includes/class-wc-install.php'; | |
| 768 | - } | |
| 769 | - | |
| 770 | - if (file_exists(WC_ABSPATH . 'includes/wc-update-functions.php')) { | |
| 771 | - include_once WC_ABSPATH . 'includes/wc-update-functions.php'; | |
| 772 | - } | |
| 773 | - | |
| 774 | - if (!class_exists('WC_Install') || !method_exists('WC_Install', 'needs_db_update') || | |
| 775 | - !method_exists('WC_Install', 'get_db_update_callbacks')) { | |
| 776 | - return array('status' => 'Error', 'error' => 'WC files missing or corrupted', 'source' => 'BV'); | |
| 777 | - } | |
| 778 | - | |
| 779 | - $current_db_version = $this->settings->getOption('woocommerce_db_version'); | |
| 780 | - if (!$current_db_version) { | |
| 781 | - return array('status' => 'Error', 'error' => 'Current WC DB version not available', 'source' => 'BV'); | |
| 782 | - } | |
| 783 | - | |
| 784 | - $latest_db_version = $this->bvinfo->getLatestWooCommerceDBVersion(); | |
| 785 | - if ($current_db_version >= $latest_db_version) { | |
| 786 | - return array('status' => 'Error', 'error' => 'WC DB update not available', 'source' => 'BV'); | |
| 787 | - } | |
| 788 | - | |
| 789 | - $db_update_callbacks = WC_Install::get_db_update_callbacks(); | |
| 790 | - | |
| 791 | - $loop = 0; | |
| 792 | - foreach ($db_update_callbacks as $version => $update_callbacks) { | |
| 793 | - if (version_compare($current_db_version, $version, '<')) { | |
| 794 | - foreach ($update_callbacks as $update_callback) { | |
| 795 | - WC()->queue()->schedule_single( | |
| 796 | - time() + $loop, | |
| 797 | - 'woocommerce_run_update_callback', | |
| 798 | - array('update_callback' => $update_callback), | |
| 799 | - 'woocommerce-db-updates' | |
| 800 | - ); | |
| 801 | - $loop++; | |
| 802 | - } | |
| 803 | - } | |
| 804 | - } | |
| 805 | - | |
| 806 | - $current_wc_version = WC()->version; | |
| 807 | - if (version_compare($current_db_version, $current_wc_version, '<') && | |
| 808 | - !WC()->queue()->get_next('woocommerce_update_db_to_current_version')) { | |
| 809 | - WC()->queue()->schedule_single( | |
| 810 | - time() + $loop, | |
| 811 | - 'woocommerce_update_db_to_current_version', | |
| 812 | - array('version' => $current_wc_version), | |
| 813 | - 'woocommerce-db-updates' | |
| 814 | - ); | |
| 815 | - } | |
| 816 | - | |
| 817 | - return array('status' => 'Done'); | |
| 818 | - } catch (Exception $e) { | |
| 819 | - return array('status' => 'Error', 'error' => $e->getMessage()); | |
| 820 | - } | |
| 821 | - } | |
| 822 | - | |
| 823 | 486 | function upgrade_db(){ |
| 824 | 487 | if (function_exists('wp_upgrade')) { |
| 825 | 488 | wp_upgrade(); |
| 826 | - return "Done"; | |
| 489 | + return "DONE"; | |
| 827 | 490 | } else { |
| 828 | 491 | return "NOUPGRADERFUNCTION"; |
| 829 | 492 | } |
| 830 | 493 | } |
| @@ -844,28 +507,10 @@ | ||
| 844 | 507 | $resp = array("adduser" => $this->addUser($params['args'])); |
| 845 | 508 | break; |
| 846 | 509 | case "upgrde": |
| 847 | 510 | $has_bv_skin = array_key_exists('bvskin', $params); |
| 848 | - $bv_bulk_upgrade = array_key_exists('bv_bulk_update', $params['args']); | |
| 849 | - $resp = array("upgrades" => $this->upgrade($params['args'], $has_bv_skin, $bv_bulk_upgrade)); | |
| 511 | + $resp = array("upgrades" => $this->upgrade($params['args'], $has_bv_skin)); | |
| 850 | 512 | break; |
| 851 | - case "cmbneupgrde": | |
| 852 | - $args = $params['args']; | |
| 853 | - $has_bv_skin = array_key_exists('bvskin', $args); | |
| 854 | - $bv_bulk_upgrade = array_key_exists('bv_bulk_update', $args); | |
| 855 | - | |
| 856 | - $resp['upgrades'] = $this->upgrade($args['upgrades'], $has_bv_skin, $bv_bulk_upgrade); | |
| 857 | - | |
| 858 | - if (isset($args['delete_transient'])) { | |
| 859 | - $resp['delete_transient'] = $this->settings->deleteTransient($args['delete_transient']); | |
| 860 | - } | |
| 861 | - if (isset($args['wp_update_plugins'])) { | |
| 862 | - $resp['wp_update_plugins'] = $this->refreshPluginUpdates(); | |
| 863 | - } | |
| 864 | - if (isset($args['wp_update_themes'])) { | |
| 865 | - $resp['wp_update_themes'] = $this->refreshThemeUpdates(); | |
| 866 | - } | |
| 867 | - break; | |
| 868 | 513 | case "edt": |
| 869 | 514 | $resp = array("edit" => $this->edit($params['args'])); |
| 870 | 515 | break; |
| 871 | 516 | case "instl": |
| @@ -888,25 +533,8 @@ | ||
| 888 | 533 | $resp = array("autologin" => $this->autoLogin($params['username'], $isHttps)); |
| 889 | 534 | break; |
| 890 | 535 | case "updatedb": |
| 891 | 536 | $resp = array("status" => $this->upgrade_db()); |
| 892 | - break; | |
| 893 | - case "updateplgndb": | |
| 894 | - $resp = array(); | |
| 895 | - $files = $params['files']; | |
| 896 | - | |
| 897 | - foreach ($files as $file) { | |
| 898 | - switch ($file) { | |
| 899 | - case "woocommerce/woocommerce.php": | |
| 900 | - $resp[$file] = $this->upgradeWoocommerceDb(); | |
| 901 | - break; | |
| 902 | - case "elementor/elementor.php": | |
| 903 | - case "elementor-pro/elementor-pro.php": | |
| 904 | - $resp[$file] = $this->upgradeElementorDB($file); | |
| 905 | - break; | |
| 906 | - } | |
| 907 | - } | |
| 908 | - | |
| 909 | 537 | break; |
| 910 | 538 | default: |
| 911 | 539 | $resp = false; |
| 912 | 540 | } |