PluginProbe ʕ •ᴥ•ʔ
LiteSpeed Cache / 7.8.1
LiteSpeed Cache v7.8.1
trunk 1.0.15 1.9.1.1 2.9.9.2 3.6.4 4.6 5.7.0.1 6.5.4 7.0.0.1 7.0.1 7.1 7.2 7.3 7.3.0.1 7.4 7.5 7.5.0.1 7.6 7.6.1 7.6.2 7.7 7.8 7.8.0.1 7.8.1
litespeed-cache / src / data.upgrade.func.php
litespeed-cache / src Last commit date
cdn 2 months ago data_structure 2 months ago activation.cls.php 2 months ago admin-display.cls.php 2 months ago admin-settings.cls.php 2 months ago admin.cls.php 2 months ago api.cls.php 2 months ago avatar.cls.php 2 months ago base.cls.php 2 months ago cdn.cls.php 2 months ago cloud-auth-callback.trait.php 2 months ago cloud-auth-ip.trait.php 2 months ago cloud-auth.trait.php 2 months ago cloud-misc.trait.php 2 months ago cloud-node.trait.php 2 months ago cloud-request.trait.php 2 months ago cloud.cls.php 2 months ago conf.cls.php 2 months ago control.cls.php 2 months ago core.cls.php 2 months ago crawler-map.cls.php 2 months ago crawler.cls.php 2 months ago css.cls.php 2 months ago data.cls.php 2 months ago data.upgrade.func.php 2 months ago db-optm.cls.php 2 months ago debug2.cls.php 2 months ago doc.cls.php 2 months ago error.cls.php 2 months ago esi.cls.php 2 months ago file.cls.php 2 months ago guest.cls.php 2 months ago gui.cls.php 2 months ago health.cls.php 2 months ago htaccess.cls.php 2 months ago img-optm-manage.trait.php 2 months ago img-optm-pull.trait.php 2 months ago img-optm-send.trait.php 2 months ago img-optm.cls.php 2 months ago import.cls.php 2 months ago import.preset.cls.php 2 months ago lang.cls.php 2 months ago localization.cls.php 2 months ago media.cls.php 2 months ago metabox.cls.php 2 months ago object-cache-wp.cls.php 2 months ago object-cache.cls.php 2 months ago object.lib.php 2 months ago optimize.cls.php 2 months ago optimizer.cls.php 2 months ago placeholder.cls.php 2 months ago purge.cls.php 2 months ago report.cls.php 2 months ago rest.cls.php 2 months ago root.cls.php 2 months ago router.cls.php 2 months ago str.cls.php 2 months ago tag.cls.php 2 months ago task.cls.php 2 months ago tool.cls.php 2 months ago ucss.cls.php 2 months ago utility.cls.php 2 months ago vary.cls.php 2 months ago vpi.cls.php 2 months ago
data.upgrade.func.php
184 lines
1 <?php
2 /**
3 * Database upgrade funcs
4 *
5 * NOTE: whenever called this file, always call Data::get_upgrade_lock and Data::_set_upgrade_lock first.
6 *
7 * @package LiteSpeed
8 * @since 3.0
9 */
10
11 defined( 'WPINC' ) || exit();
12
13 use LiteSpeed\Debug2;
14 use LiteSpeed\Cloud;
15 use LiteSpeed\Conf;
16
17 /**
18 * Check whether a DB table exists.
19 *
20 * @since 7.2
21 *
22 * @param string $table_name Fully-qualified table name.
23 * @return bool
24 */
25 function litespeed_table_exists( $table_name ) {
26 global $wpdb;
27
28 $save_state = $wpdb->suppress_errors;
29 $wpdb->suppress_errors( true );
30 // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder, WordPress.DB.DirectDatabaseQuery.DirectQuery
31 $tb_exists = $wpdb->get_var( $wpdb->prepare( 'DESCRIBE `%1s`', $table_name ) );
32 $wpdb->suppress_errors( $save_state );
33
34 return null !== $tb_exists;
35 }
36
37 /**
38 * Migrate v7.0- url_files URL from no trailing slash to trailing slash.
39 *
40 * @since 7.0.1
41 * @return void
42 */
43 function litespeed_update_7_0_1() {
44 global $wpdb;
45
46 Debug2::debug( '[Data] v7.0.1 upgrade started' );
47
48 $tb_url = $wpdb->prefix . 'litespeed_url';
49 if ( ! litespeed_table_exists( $tb_url ) ) {
50 Debug2::debug( '[Data] Table `litespeed_url` not found, bypassed migration' );
51 return;
52 }
53
54 // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery
55 $list = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `{$tb_url}` WHERE url LIKE %s", 'https://%/' ), ARRAY_A );
56 $existing_urls = array();
57 if ($list) {
58 foreach ($list as $v) {
59 $existing_urls[] = $v['url'];
60 }
61 }
62
63 // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery
64 $list = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `{$tb_url}` WHERE url LIKE %s", 'https://%' ), ARRAY_A );
65 if ( ! $list ) {
66 return;
67 }
68 foreach ( $list as $v ) {
69 if ( '/' === substr( $v['url'], -1 ) ) {
70 continue;
71 }
72 $new_url = $v['url'] . '/';
73 if ( in_array( $new_url, $existing_urls, true ) ) {
74 continue;
75 }
76 // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery
77 $wpdb->query( $wpdb->prepare( "UPDATE `{$tb_url}` SET url = %s WHERE id = %d", $new_url, $v['id'] ) );
78 }
79 }
80
81 /**
82 * Migrate from domain key to pk/sk for QC
83 *
84 * @since 7.0
85 */
86 function litespeed_update_7() {
87 Debug2::debug('[Data] v7 upgrade started');
88
89 $__cloud = Cloud::cls();
90
91 $domain_key = $__cloud->conf('api_key');
92 if (!$domain_key) {
93 Debug2::debug('[Data] No domain key, bypassed migration');
94 return;
95 }
96
97 $new_prepared = $__cloud->init_qc_prepare();
98 if (!$new_prepared && $__cloud->activated()) {
99 Debug2::debug('[Data] QC previously activated in v7, bypassed migration');
100 return;
101 }
102 $data = array(
103 'domain_key' => $domain_key,
104 );
105 $resp = $__cloud->post(Cloud::SVC_D_V3UPGRADE, $data);
106 if ( ! empty( $resp['qc_activated'] ) ) {
107 if ( 'deleted' !== $resp['qc_activated'] ) {
108 $cloud_summary_updates = array( 'qc_activated' => $resp['qc_activated'] );
109 if (!empty($resp['main_domain'])) {
110 $cloud_summary_updates['main_domain'] = $resp['main_domain'];
111 }
112 Cloud::save_summary($cloud_summary_updates);
113 Debug2::debug('[Data] Updated QC activated status to ' . $resp['qc_activated']);
114 }
115 }
116 }
117
118 /**
119 * Drop deprecated guest_ips and guest_uas from DB options.
120 * Migrate url table to make all links trailing slash for UCSS/CCSS.
121 *
122 * These values are now read from files instead.
123 *
124 * @since 7.7
125 */
126 function litespeed_update_7_7() {
127 global $wpdb;
128
129 Debug2::debug( '[Data] v7.7 upgrade: dropping guest_ips/guest_uas options' );
130
131 Conf::delete_option( 'conf.guest_ips' );
132 Conf::delete_option( 'conf.guest_uas' );
133 Conf::delete_site_option( 'conf.guest_ips' );
134 Conf::delete_site_option( 'conf.guest_uas' );
135
136 // Normalize all URLs to have trailing slash to match UCSS/CCSS generation logic
137 Debug2::debug( '[Data] v7.7 upgrade: normalizing URL trailing slashes' );
138
139 // Skip if plain permalink mode (no trailing slash)
140 $permalink_structure = get_option( 'permalink_structure' );
141 if ( empty( $permalink_structure ) ) {
142 Debug2::debug( '[Data] Plain permalink mode, bypassed URL trailing slash migration' );
143 return;
144 }
145
146 $tb_url = $wpdb->prefix . 'litespeed_url';
147 if ( ! litespeed_table_exists( $tb_url ) ) {
148 Debug2::debug( '[Data] Table `litespeed_url` not found, bypassed URL migration' );
149 return;
150 }
151
152 // Check if there are URLs without trailing slash (exclude URLs with query string)
153 // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery
154 $count = $wpdb->get_var( "SELECT COUNT(*) FROM `{$tb_url}` WHERE url LIKE 'https://%' AND url NOT LIKE '%/' AND url NOT LIKE '%?%'" );
155 if ( ! $count ) {
156 Debug2::debug( '[Data] No URLs without trailing slash found, bypassed' );
157 return;
158 }
159
160 // Append trailing slash to all URLs that don't have one and don't have duplicate with slash (exclude URLs with query string)
161 // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery
162 $wpdb->query( "UPDATE `{$tb_url}` SET url = CONCAT(url, '/') WHERE url LIKE 'https://%' AND url NOT LIKE '%/' AND url NOT LIKE '%?%' AND CONCAT(url, '/') NOT IN (SELECT * FROM (SELECT url FROM `{$tb_url}` WHERE url LIKE '%/') AS tmp)" );
163 }
164
165 /**
166 * Append webp/mobile to url_file
167 *
168 * @since 5.3
169 */
170 function litespeed_update_5_3() {
171 global $wpdb;
172 Debug2::debug('[Data] Upgrade url_file table');
173
174 $tb = $wpdb->prefix . 'litespeed_url_file';
175 if ( litespeed_table_exists( $tb ) ) {
176 $q = "ALTER TABLE `{$tb}`
177 ADD COLUMN `mobile` tinyint(4) NOT NULL COMMENT 'mobile=1',
178 ADD COLUMN `webp` tinyint(4) NOT NULL COMMENT 'webp=1'
179 ";
180 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery
181 $wpdb->query( $q );
182 }
183 }
184