PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / 2.2.16
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce v2.2.16
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
← All changes | includes/Upgrade.php +62 -17 2.0.42.2.16 View file →
@@ -5,15 +5,14 @@
5 5 class Upgrade
6 6 {
7 7 static $instance;
8 8
9 -
10 9 /**
11 10 * @return Upgrade
12 11 */
13 12 public static function getInstance()
14 13 {
15 - if ( ! static::$instance) {
14 + if (!static::$instance) {
16 15 static::$instance = new static();
17 16 }
18 17
19 18 return static::$instance;
@@ -19,29 +18,77 @@
19 18 return static::$instance;
20 19 }
21 20
22 21 /**
23 - * Run upgrade
22 + * Run upgrade.
24 23 *
25 24 * @return void
26 25 */
27 26 public function run()
28 27 {
28 + $this->before();
29 29 $this->upgradeDb();
30 30 $this->upgradeCore();
31 + $this->buildCssFile();
32 + $this->after();
31 33 }
32 34
35 + /**
36 + * Run before upgrade.
37 + *
38 + * @return void
39 + */
40 + public function before()
41 + {
42 + if (!$this->getInstalledPluginVersion()) {
43 + Activator::activate();
44 + }
45 + }
46 +
47 + /**
48 + * After upgrade
49 + *
50 + * @return void
51 + */
52 + public function after()
53 + {
54 + $this->updatePluginVersion();
55 + }
56 +
57 + /**
58 + * Upgrade code features.
59 + *
60 + * @return void
61 + */
33 62 public function upgradeCore()
34 63 {
35 64 $this->backwardCompat();
36 - $this->updatePluginVersion();
37 65 }
38 66
39 - function buildCssFile(){
40 - Campaign::buildCss();
67 + /**
68 + * Re-build public CSS file.
69 + *
70 + * @return void
71 + */
72 + public function buildCssFile()
73 + {
74 + if (!$this->isCssBuilt()) {
75 + Campaign::buildCss();
76 + }
41 77 }
42 78
43 79 /**
80 + * Returns true if the public CSS file exits already.
81 + *
82 + * @return boolean
83 + */
84 + public function isCssBuilt()
85 + {
86 + return file_exists(HURRYT_DIR . 'assets/css/hurrytimer.css');
87 + }
88 +
89 +
90 + /**
44 91 * Upgrade or created table.
45 92 *
46 93 * @return void
47 94 */
@@ -48,19 +95,24 @@
48 95 private function upgradeDb()
49 96 {
50 97 $ver = $this->getInstalledDbVersion();
51 98
52 - if ( ! $ver || $ver != HURRYT_DB_VERSION) {
99 + if (!$ver || $ver != HURRYT_DB_VERSION) {
53 100 $this->createTables();
54 101 $this->updateDbVersion();
55 102 }
56 103 }
57 104
105 + /**
106 + * Create custom db tables.
107 + *
108 + * @return void
109 + */
58 110 public function createTables()
59 111 {
60 112 global $wpdb;
61 113
62 - $table = "{$wpdb->prefix}hurrytimer_evergreen";
114 + $table = "{$wpdb->prefix}hurrytimer_evergreen";
63 115 $charset_collate = $wpdb->get_charset_collate();
64 116
65 117 $sql = "CREATE TABLE {$table} (
66 118 id bigint(20) NOT NULL AUTO_INCREMENT,
@@ -83,9 +135,9 @@
83 135 * @return string
84 136 */
85 137 private function getInstalledPluginVersion()
86 138 {
87 - return get_option('hurrytimer_version');
139 + return get_option(HURRYT_OPTION_VERSION_KEY);
88 140 }
89 141
90 142 /**
91 143 * Update plugin version.
@@ -93,9 +145,9 @@
93 145 * @return void
94 146 */
95 147 private function updatePluginVersion()
96 148 {
97 - update_option('hurrytimer_version', HURRYT_VERSION);
149 + update_option(HURRYT_OPTION_VERSION_KEY, HURRYT_VERSION);
98 150 }
99 151
100 152 /**
101 153 * Returns installed db version.
@@ -125,16 +177,9 @@
125 177 private function backwardCompat()
126 178 {
127 179 $ver = $this->getInstalledPluginVersion();
128 180
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 181 if (version_compare($ver, '2.0.0', '<')) {
136 - update_option('hurrytimer_legacy', 'yes');
137 182 $this->buildCssFile();
138 183 }
139 184
140 185 }