PluginProbe
ezCache / 1.3
ezCache v1.3
2.6.5 2.6.4 2.6.2 2.6.3 2.6.1 2.6.0 2.5.6 2.5.5 2.5.4 2.5.3 2.5.2 2.5.1 2.5 2.2.1 2.2.2 trunk 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.3 1.3.1 1.3.10 1.3.11 All 49 releases
ezcache / includes / Updater.php

Updater.php in ezCache 1.3, at includes/Updater.php

114 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Upress\EzCache;
4
5 use Exception;
6 use wpdb;
7
8 class Updater {
9 /** @var string $current_version */
10 protected static $current_version;
11 /** @var string $collate */
12 protected static $collate;
13
14 protected static function wpdb() {
15 global $wpdb;
16 }
17
18 public static function uninstall() {
19 global $wpdb;
20
21 $wpdb->query("DROP TABLE IF EXISTS `{$wpdb->prefix}ezcache_webp_images`");
22 delete_option( 'ezcache_version' );
23 }
24
25 /**
26 * Run any necessary db updates, file upgrades etc.
27 */
28 public static function upgrade() {
29 global $wpdb;
30
31 self::$current_version = get_option( 'ezcache_version' );
32 self::$collate = $wpdb->get_charset_collate();
33
34 /** @noinspection PhpIncludeInspection */
35 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
36
37 try {
38 self::update_0_1_20190811();
39 self::update_0_1_20190812();
40
41 // make sure we update the version in the database so we can run upgrades at later times
42 update_option( 'ezcache_version', EZCACHE_VERSION );
43 } catch ( Exception $ex ) {
44 error_log( $ex );
45 wp_die( $ex->getMessage() );
46 }
47 }
48
49 /**
50 * Update to the 1.0 version
51 * create the 404 database
52 * @throws Exception
53 */
54 protected static function update_0_1_20190811() {
55 global $wpdb;
56
57 $ver = '0.1-20190811';
58 if ( self::$current_version && version_compare( self::$current_version, $ver, '>=' ) ) {
59 return;
60 }
61
62 $wpdb->query( "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}ezcache_webp_images` (
63 `id` bigint(10) UNSIGNED NOT NULL AUTO_INCREMENT,
64 `uid` varchar(191) NOT NULL DEFAULT '',
65 `url` text(0) NOT NULL DEFAULT '',
66 `webp_url` text(0) NOT NULL DEFAULT '',
67 `status` enum('pending', 'completed', 'failed') NOT NULL DEFAULT 'pending',
68 `created_at` datetime(0) NOT NULL DEFAULT '0000-00-00 00:00:00',
69 `updated_at` datetime(0) NOT NULL DEFAULT '0000-00-00 00:00:00',
70 PRIMARY KEY (`id`),
71 UNIQUE INDEX (`uid`) USING BTREE
72 ) ". ( self::$collate ) );
73
74 if ( ! empty( $wpdb->last_error ) ) {
75 throw new Exception( $wpdb->last_error );
76 }
77
78 self::$current_version = $ver;
79 update_option( 'ezcache_version', self::$current_version );
80 }
81
82 /**
83 * Update to the 1.0 version
84 * create the 404 database
85 * @throws Exception
86 */
87 protected static function update_0_1_20190812() {
88 global $wpdb;
89
90 $ver = '0.1-20190812';
91 if ( self::$current_version && version_compare( self::$current_version, $ver, '>=' ) ) {
92 return;
93 }
94
95 $cols = $wpdb->get_col( "SHOW COLUMNS FROM `{$wpdb->prefix}ezcache_webp_images`", 0 );
96 if( ! in_array( 'path', $cols ) ) {
97 $wpdb->query( "ALTER TABLE `{$wpdb->prefix}ezcache_webp_images`
98 ADD COLUMN `path` text(0) NOT NULL DEFAULT '' AFTER `webp_url`,
99 ADD COLUMN `webp_path` text(0) NOT NULL DEFAULT '' AFTER `path`,
100 ADD COLUMN `original_size` int(10) UNSIGNED NOT NULL DEFAULT 0 AFTER `webp_path`,
101 ADD COLUMN `webp_size` int(10) UNSIGNED NOT NULL DEFAULT 0 AFTER `original_size`
102 " );
103 }
104
105 if ( ! empty( $wpdb->last_error ) ) {
106 throw new Exception( $wpdb->last_error );
107 }
108
109 self::$current_version = $ver;
110 update_option( 'ezcache_version', self::$current_version );
111 }
112
113 }
114