Skip to content

Commit

Permalink
v7.0-b23: Finished v7 upgrade QC status data migration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hai Zheng committed Dec 11, 2024
1 parent d6fcfdc commit eaf2e44
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
4 changes: 2 additions & 2 deletions litespeed-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions src/cloud.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -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);

Expand Down Expand Up @@ -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();
Expand All @@ -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;
}

/**
Expand All @@ -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();

Expand Down Expand Up @@ -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) {
Expand Down
37 changes: 37 additions & 0 deletions src/data.upgrade.func.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Database upgrade funcs
*
Expand All @@ -12,6 +13,42 @@
use LiteSpeed\Conf;
use LiteSpeed\Admin_Display;
use LiteSpeed\File;
use LiteSpeed\Cloud;

/**
* Migrate from domain key to pk/sk for QC
* @since 7.0
*/
function litespeed_update_7()
{
global $wpdb;
Debug2::debug('[Data] v7 upgrade started');

$__cloud = Cloud::cls();

$domain_key = $__cloud->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
Expand Down

0 comments on commit eaf2e44

Please sign in to comment.