| @@ -94,8 +94,14 @@ | ||
| 94 | 94 | * Upgrade routine for network wide activation |
| 95 | 95 | */ |
| 96 | 96 | public function maybe_upgrade_network_wide() { |
| 97 | 97 | if ( version_compare( get_site_option( DB_VERSION_OPTION_NAME ), POWERED_CACHE_DB_VERSION, '<' ) ) { |
| 98 | + $this->upgrade_30( true ); | |
| 99 | + $this->upgrade_32( true ); | |
| 100 | + $this->upgrade_33( true ); | |
| 101 | + $this->upgrade_34( true ); | |
| 102 | + | |
| 103 | + \PoweredCache\Utils\log( sprintf( '[Networkwide] Upgrade DB version: %s', POWERED_CACHE_DB_VERSION ) ); | |
| 98 | 104 | update_site_option( DB_VERSION_OPTION_NAME, POWERED_CACHE_DB_VERSION ); |
| 99 | 105 | } |
| 100 | 106 | } |
| 101 | 107 | |
| @@ -103,15 +109,165 @@ | ||
| 103 | 109 | * Upgrade routine |
| 104 | 110 | */ |
| 105 | 111 | public function maybe_upgrade() { |
| 106 | 112 | if ( version_compare( get_option( DB_VERSION_OPTION_NAME ), POWERED_CACHE_DB_VERSION, '<' ) ) { |
| 113 | + \PoweredCache\Utils\log( sprintf( 'Upgrade DB version: %s', POWERED_CACHE_DB_VERSION ) ); | |
| 107 | 114 | $this->maybe_migrate_from_1x(); |
| 115 | + $this->upgrade_30(); | |
| 116 | + $this->upgrade_32(); | |
| 117 | + $this->upgrade_33(); | |
| 118 | + $this->upgrade_34(); | |
| 108 | 119 | |
| 109 | - \PoweredCache\Utils\log( sprintf( 'Upgrade DB version: %d', POWERED_CACHE_DB_VERSION ) ); | |
| 110 | 120 | update_option( DB_VERSION_OPTION_NAME, POWERED_CACHE_DB_VERSION ); |
| 111 | 121 | } |
| 112 | 122 | } |
| 113 | 123 | |
| 124 | + /** | |
| 125 | + * Changing "accepted query string" as "ignored query string" with version 3.x | |
| 126 | + * | |
| 127 | + * @param bool $network_wide whether plugin activated network-wide or not | |
| 128 | + * | |
| 129 | + * @return void | |
| 130 | + * @since 3.0 | |
| 131 | + */ | |
| 132 | + public function upgrade_30( $network_wide = false ) { | |
| 133 | + $current_version = $network_wide ? get_site_option( DB_VERSION_OPTION_NAME ) : get_option( DB_VERSION_OPTION_NAME ); | |
| 134 | + if ( ! version_compare( $current_version, '3.0', '<' ) ) { | |
| 135 | + return; | |
| 136 | + } | |
| 137 | + | |
| 138 | + $settings = \PoweredCache\Utils\get_settings( $network_wide ); | |
| 139 | + | |
| 140 | + if ( empty( $settings['accepted_query_strings'] ) ) { | |
| 141 | + return; | |
| 142 | + } | |
| 143 | + | |
| 144 | + $settings['ignored_query_strings'] = $settings['accepted_query_strings']; | |
| 145 | + unset( $settings['accepted_query_strings'] ); | |
| 146 | + | |
| 147 | + if ( $network_wide ) { | |
| 148 | + update_site_option( SETTING_OPTION, $settings ); | |
| 149 | + } else { | |
| 150 | + update_option( SETTING_OPTION, $settings ); | |
| 151 | + } | |
| 152 | + | |
| 153 | + Config::factory()->save_configuration( $settings, $network_wide ); | |
| 154 | + \PoweredCache\Utils\log( 'Upgraded to version 3.0' ); | |
| 155 | + } | |
| 156 | + | |
| 157 | + /** | |
| 158 | + * Changing js execution method | |
| 159 | + * | |
| 160 | + * @param bool $network_wide whether plugin activated network-wide or not | |
| 161 | + * | |
| 162 | + * @return void | |
| 163 | + * @since 3.2 | |
| 164 | + */ | |
| 165 | + public function upgrade_32( $network_wide = false ) { | |
| 166 | + $current_version = $network_wide ? get_site_option( DB_VERSION_OPTION_NAME ) : get_option( DB_VERSION_OPTION_NAME ); | |
| 167 | + if ( ! version_compare( $current_version, '3.2', '<' ) ) { | |
| 168 | + return; | |
| 169 | + } | |
| 170 | + | |
| 171 | + $settings = \PoweredCache\Utils\get_settings( $network_wide ); | |
| 172 | + | |
| 173 | + if ( ! empty( $settings['js_execution_method'] ) ) { | |
| 174 | + if ( in_array( $settings['js_execution_method'], [ 'async', 'defer' ], true ) ) { | |
| 175 | + $settings['js_defer'] = true; | |
| 176 | + } | |
| 177 | + | |
| 178 | + if ( 'delayed' === $settings['js_execution_method'] ) { | |
| 179 | + $settings['js_delay'] = true; | |
| 180 | + $settings['combine_js'] = false; | |
| 181 | + } | |
| 182 | + | |
| 183 | + unset( $settings['js_execution_method'] ); | |
| 184 | + unset( $settings['js_execution_optimized_only'] ); | |
| 185 | + } | |
| 186 | + | |
| 187 | + if ( $network_wide ) { | |
| 188 | + update_site_option( SETTING_OPTION, $settings ); | |
| 189 | + } else { | |
| 190 | + update_option( SETTING_OPTION, $settings ); | |
| 191 | + } | |
| 192 | + | |
| 193 | + Config::factory()->save_configuration( $settings, $network_wide ); | |
| 194 | + \PoweredCache\Utils\log( 'Upgraded to version 3.2' ); | |
| 195 | + } | |
| 196 | + | |
| 197 | + /** | |
| 198 | + * Upgrade routine for version 3.3 | |
| 199 | + * | |
| 200 | + * @param bool $network_wide whether plugin activated network-wide or not | |
| 201 | + * | |
| 202 | + * @return void | |
| 203 | + */ | |
| 204 | + public function upgrade_33( $network_wide = false ) { | |
| 205 | + $current_version = $network_wide ? get_site_option( DB_VERSION_OPTION_NAME ) : get_option( DB_VERSION_OPTION_NAME ); | |
| 206 | + if ( ! version_compare( $current_version, '3.3', '<' ) ) { | |
| 207 | + return; | |
| 208 | + } | |
| 209 | + | |
| 210 | + $settings = \PoweredCache\Utils\get_settings( $network_wide ); | |
| 211 | + | |
| 212 | + // disable rewrite file optimizer if auto configure htaccess is disabled | |
| 213 | + if ( ! $settings['auto_configure_htaccess'] && $settings['rewrite_file_optimizer'] ) { | |
| 214 | + $settings['rewrite_file_optimizer'] = false; | |
| 215 | + } | |
| 216 | + | |
| 217 | + if ( $network_wide ) { | |
| 218 | + update_site_option( SETTING_OPTION, $settings ); | |
| 219 | + } else { | |
| 220 | + update_option( SETTING_OPTION, $settings ); | |
| 221 | + } | |
| 222 | + | |
| 223 | + Config::factory()->save_configuration( $settings, $network_wide ); | |
| 224 | + | |
| 225 | + if ( $settings['auto_configure_htaccess'] && $settings['rewrite_file_optimizer'] ) { | |
| 226 | + if ( $network_wide ) { | |
| 227 | + \PoweredCache\Utils\clean_page_cache_dir(); | |
| 228 | + } else { | |
| 229 | + \PoweredCache\Utils\clean_site_cache_dir(); | |
| 230 | + } | |
| 231 | + } | |
| 232 | + | |
| 233 | + \PoweredCache\Utils\log( 'Upgraded to version 3.3' ); | |
| 234 | + } | |
| 235 | + | |
| 236 | + /** | |
| 237 | + * Upgrade routine for version 3.4 | |
| 238 | + * | |
| 239 | + * @param bool $network_wide whether plugin activated network-wide or not | |
| 240 | + * * | |
| 241 | + * @return void | |
| 242 | + */ | |
| 243 | + public function upgrade_34( $network_wide = false ) { | |
| 244 | + $current_version = $network_wide ? get_site_option( DB_VERSION_OPTION_NAME ) : get_option( DB_VERSION_OPTION_NAME ); | |
| 245 | + if ( ! version_compare( $current_version, '3.4', '<' ) ) { | |
| 246 | + return; | |
| 247 | + } | |
| 248 | + | |
| 249 | + $settings = \PoweredCache\Utils\get_settings( $network_wide ); | |
| 250 | + | |
| 251 | + $encryption = new Encryption(); | |
| 252 | + | |
| 253 | + if ( ! empty( $settings['cloudflare_api_key'] ) && false === $encryption->decrypt( $settings['cloudflare_api_key'] ) ) { | |
| 254 | + $settings['cloudflare_api_key'] = $encryption->encrypt( $settings['cloudflare_api_key'] ); | |
| 255 | + } | |
| 256 | + | |
| 257 | + if ( ! empty( $settings['cloudflare_api_token'] ) && false === $encryption->decrypt( $settings['cloudflare_api_token'] ) ) { | |
| 258 | + $settings['cloudflare_api_token'] = $encryption->encrypt( $settings['cloudflare_api_token'] ); | |
| 259 | + } | |
| 260 | + | |
| 261 | + if ( $network_wide ) { | |
| 262 | + update_site_option( SETTING_OPTION, $settings ); | |
| 263 | + } else { | |
| 264 | + update_option( SETTING_OPTION, $settings ); | |
| 265 | + } | |
| 266 | + | |
| 267 | + Config::factory()->save_configuration( $settings, $network_wide ); | |
| 268 | + \PoweredCache\Utils\log( 'Upgraded to version 3.4' ); | |
| 269 | + } | |
| 114 | 270 | |
| 115 | 271 | /** |
| 116 | 272 | * Check if a lock exists of the upgrade routine |
| 117 | 273 | * |