PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / 2.0.1
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce v2.0.1
2.15.0 trunk 1.0.0 1.0.1 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1.2 2.1.3 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 All 62 releases
hurrytimer / includes / Upgrade.php

Upgrade.php in HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce 2.0.1, at includes/Upgrade.php

142 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Hurrytimer;
4
5 class Upgrade
6 {
7 static $instance;
8
9
10 /**
11 * @return Upgrade
12 */
13 public static function getInstance()
14 {
15 if ( ! static::$instance) {
16 static::$instance = new static();
17 }
18
19 return static::$instance;
20 }
21
22 /**
23 * Run upgrade
24 *
25 * @return void
26 */
27 public function run()
28 {
29 $this->upgradeDb();
30 $this->upgradeCore();
31 }
32
33 public function upgradeCore()
34 {
35 $this->backwardCompat();
36 $this->updatePluginVersion();
37 }
38
39 function buildCssFile(){
40 Campaign::buildCss();
41 }
42
43 /**
44 * Upgrade or created table.
45 *
46 * @return void
47 */
48 private function upgradeDb()
49 {
50 $ver = $this->getInstalledDbVersion();
51
52 if ( ! $ver || $ver != HURRYT_DB_VERSION) {
53 $this->createTables();
54 $this->updateDbVersion();
55 }
56 }
57
58 public function createTables()
59 {
60 global $wpdb;
61
62 $table = "{$wpdb->prefix}hurrytimer_evergreen";
63 $charset_collate = $wpdb->get_charset_collate();
64
65 $sql = "CREATE TABLE {$table} (
66 id bigint(20) NOT NULL AUTO_INCREMENT,
67 countdown_id bigint(20) unsigned NOT NULL,
68 client_ip_address varchar(50) NOT NULL,
69 expired tinyint(1) unsigned DEFAULT NULL,
70 client_expires_at bigint(20) unsigned NOT NULL,
71 destroy_at timestamp NULL DEFAULT NULL,
72 PRIMARY KEY (id)
73 ) {$charset_collate}";
74
75 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
76
77 dbDelta($sql);
78 }
79
80 /**
81 * Returns installed plugin version.
82 *
83 * @return string
84 */
85 private function getInstalledPluginVersion()
86 {
87 return get_option('hurrytimer_version');
88 }
89
90 /**
91 * Update plugin version.
92 *
93 * @return void
94 */
95 private function updatePluginVersion()
96 {
97 update_option('hurrytimer_version', HURRYT_VERSION);
98 }
99
100 /**
101 * Returns installed db version.
102 *
103 * @return string
104 */
105 private function getInstalledDbVersion()
106 {
107 return get_option('hurrytimer_db_version');
108 }
109
110 /**
111 * Save new db version.
112 *
113 * @return void
114 */
115 private function updateDbVersion()
116 {
117 update_option('hurrytimer_db_version', HURRYT_DB_VERSION);
118 }
119
120 /**
121 * Run global backward compatibility if applicable.
122 *
123 * @return void
124 */
125 private function backwardCompat()
126 {
127 $ver = $this->getInstalledPluginVersion();
128
129 // Clean up unused `_htmr_reset_cookie` option.
130 if (version_compare($ver, '1.1.3', '<=')) {
131 delete_option('_htmr_reset_cookie');
132 }
133
134 // Legacy code for some features.
135 if (version_compare($ver, '2.0.0', '<')) {
136 update_option('hurrytimer_legacy', 'yes');
137 $this->buildCssFile();
138 }
139
140 }
141 }
142