From eaf2e44aac3e5c85b1f8f80fedbadf3e54c1a540 Mon Sep 17 00:00:00 2001 From: Hai Zheng Date: Wed, 11 Dec 2024 16:00:42 -0500 Subject: [PATCH] v7.0-b23: Finished v7 upgrade QC status data migration. --- litespeed-cache.php | 4 ++-- src/cloud.cls.php | 13 +++++++++---- src/data.upgrade.func.php | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/litespeed-cache.php b/litespeed-cache.php index 7e327d4a3..41774ef9f 100644 --- a/litespeed-cache.php +++ b/litespeed-cache.php @@ -4,7 +4,7 @@ * Plugin Name: LiteSpeed Cache * Plugin URI: https://www.litespeedtech.com/products/cache-plugins/wordpress-acceleration * Description: High-performance page caching and site optimization from LiteSpeed - * Version: 7.0-b22 + * Version: 7.0-b23 * Author: LiteSpeed Technologies * Author URI: https://www.litespeedtech.com * License: GPLv3 @@ -34,7 +34,7 @@ return; } -!defined('LSCWP_V') && define('LSCWP_V', '7.0-b22'); +!defined('LSCWP_V') && define('LSCWP_V', '7.0-b23'); !defined('LSCWP_CONTENT_DIR') && define('LSCWP_CONTENT_DIR', WP_CONTENT_DIR); !defined('LSCWP_DIR') && define('LSCWP_DIR', __DIR__ . '/'); // Full absolute path '/var/www/html/***/wp-content/plugins/litespeed-cache/' or MU diff --git a/src/cloud.cls.php b/src/cloud.cls.php index f0523c5ab..102ea2389 100644 --- a/src/cloud.cls.php +++ b/src/cloud.cls.php @@ -24,6 +24,7 @@ class Cloud extends Base const SVC_D_LINK = 'd/link'; const SVC_D_API = 'd/api'; const SVC_D_DASH = 'd/dash'; + const SVC_D_V3UPGRADE = 'd/v3upgrade'; const SVC_U_LINK = 'u/wp3/link'; const SVC_U_ENABLE_CDN = 'u/wp3/enablecdn'; const SVC_D_STATUS_CDN_CLI = 'd/status/cdn_cli'; @@ -66,6 +67,7 @@ class Cloud extends Base self::SVC_D_SYNC_CONF, self::SVC_D_USAGE, self::SVC_D_API, + self::SVC_D_V3UPGRADE, self::SVC_D_DASH, self::SVC_D_STATUS_CDN_CLI, // self::API_NEWS, @@ -79,7 +81,7 @@ class Cloud extends Base private static $WP_SVC_SET = array(self::API_NEWS, self::API_VER, self::API_BETA_TEST, self::API_REST_ECHO); // No api key needed for these services - private static $_PUB_SVC_SET = array(self::API_NEWS, self::API_REPORT, self::API_VER, self::API_BETA_TEST, self::API_REST_ECHO); + private static $_PUB_SVC_SET = array(self::API_NEWS, self::API_REPORT, self::API_VER, self::API_BETA_TEST, self::API_REST_ECHO, self::SVC_D_V3UPGRADE); private static $_QUEUE_SVC_SET = array(self::SVC_UCSS, self::SVC_VPI); @@ -131,7 +133,7 @@ public function __construct() * * @since 7.0 */ - private function _init_qc_prepare() + public function init_qc_prepare() { if (empty($this->_summary['sk_b64'])) { $keypair = sodium_crypto_sign_keypair(); @@ -141,7 +143,10 @@ private function _init_qc_prepare() $this->_summary['sk_b64'] = $sk; $this->save_summary(); // ATM `qc_activated` = null + return true; } + + return false; } /** @@ -151,7 +156,7 @@ private function _init_qc_prepare() */ public function init_qc() { - $this->_init_qc_prepare(); + $this->init_qc_prepare(); $ref = $this->_get_ref_url(); @@ -226,7 +231,7 @@ private function _get_ref_url($ref = false) */ public function init_qc_cli() { - $this->_init_qc_prepare(); + $this->init_qc_prepare(); $server_ip = $this->conf(self::O_SERVER_IP); if (!$server_ip) { diff --git a/src/data.upgrade.func.php b/src/data.upgrade.func.php index b85654ad8..1de68d0a0 100644 --- a/src/data.upgrade.func.php +++ b/src/data.upgrade.func.php @@ -1,4 +1,5 @@ conf('api_key'); + if (!$domain_key) { + Debug2::debug('[Data] No domain key, bypassed migration'); + return; + } + + $new_prepared = $__cloud->init_qc_prepare(); + $cloud_summary = Cloud::get_summary(); + if (!$new_prepared && $__cloud->activated()) { + Debug2::debug('[Data] QC previously activated in v7, bypassed migration'); + return; + } + $data = array( + 'domain_key' => $domain_key, + ); + $res = $__cloud->post(self::SVC_D_V3UPGRADE, $data); + if (!empty($res['qc_activated'])) { + if ($res['qc_activated'] != 'deleted') { + Cloud::save_summary(array('qc_activated' => $res['qc_activated'])); + Debug2::debug('[Data] Updated QC activated status to ' . $res['qc_activated']); + } + } +} /** * Append webp/mobile to url_file