PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / 2.3.4
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce v2.3.4
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 / Installer.php

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

127 lines 3.1 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 use Hurrytimer\Traits\Singleton;
6
7
8 /**
9 *
10 * @since 2.3.0
11 * @package Hurrytimer
12 * @subpackage Hurrytimer/includes
13 * @author Nabil Lemsieh <contact@nabillemsieh.com>
14 */
15 class Installer
16 {
17 use Singleton;
18
19 public function upgrade()
20 {
21
22 // Update table structure if available.
23 $this->create_or_upgrade_evergreen_timers_tracking_table();
24
25 // Preserve compatibility with versions prior 2.3.0
26 $installed_version = get_option( 'hurrytimer_version' );
27
28 // A workaround to find installed version.
29 if ( !$installed_version ) {
30
31 $campaigns = get_posts( [ 'post_type' => HURRYT_POST_TYPE, 'post_status' => 'any', 'fields' => 'ids' ] );
32 if ( !empty( $campaigns ) ) {
33 $installed_version = '2.2.28';
34 }
35 }
36
37 if ( $installed_version && version_compare( $installed_version, '2.2.28', '<=' ) ) {
38 $this->upgrade_2_2_28();
39 }
40
41 // Update the current version.
42 update_option( 'hurrytimer_version', HURRYT_VERSION );
43 }
44
45
46 /**
47 * Should we preserve compatibility with 2.2.28 and prior?
48 *
49 * @return bool|mixed
50 */
51 public function should_backward_compat_2_2_28_and_prior()
52 {
53 if ( version_compare( get_option( 'hurrytimer_version' ), '2.2.28', '<=' ) ) {
54 return true;
55 }
56
57 return filter_var( get_option( 'hurrytimer_upgraded_2_2_28' ), FILTER_VALIDATE_BOOLEAN );
58
59 }
60
61 /**
62 * Upgraded from 2.2.28?
63 *
64 * @return bool
65 */
66 public function has_upgraded_from_2_2_28_or_prior()
67 {
68 return filter_var( get_option( 'hurrytimer_upgraded_2_2_28' ), FILTER_VALIDATE_BOOLEAN );
69 }
70
71 /**
72 * Backward compatibility with versions <= 2.2.28
73 */
74 public function upgrade_2_2_28()
75 {
76 add_option( 'hurrytimer_upgraded_2_2_28', '1' );
77 }
78
79 /**
80 * Plugin activation hook
81 *
82 * @since 2.3.0
83 */
84 public function activate()
85 {
86
87 $this->create_or_upgrade_evergreen_timers_tracking_table();
88
89 // Add the current version.
90 add_option( 'hurrytimer_version', HURRYT_VERSION );
91
92 // Rebuild css
93 try {
94 CSS_Builder::get_instance()->build();
95 } catch ( \Exception $e ) {
96
97 }
98
99 }
100
101 private function create_or_upgrade_evergreen_timers_tracking_table()
102 {
103
104 global $wpdb;
105
106 $table = "{$wpdb->prefix}hurrytimer_evergreen";
107 $charset_collate = $wpdb->get_charset_collate();
108
109 $sql = "CREATE TABLE {$table} (
110 id bigint(20) NOT NULL AUTO_INCREMENT,
111 countdown_id bigint(20) unsigned NOT NULL,
112 client_ip_address varchar(50) NOT NULL,
113 expired tinyint(1) unsigned DEFAULT NULL,
114 client_expires_at bigint(20) unsigned NOT NULL,
115 reset_token varchar(20) NULL,
116 destroy_at timestamp NULL DEFAULT NULL,
117 PRIMARY KEY (id)
118 ) {$charset_collate}";
119
120 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
121
122 dbDelta( $sql );
123
124 }
125
126 }
127