PluginProbe
Accessibility by AllAccessible / trunk
Accessibility by AllAccessible vtrunk
2.1.6 2.1.5 2.1.4 2.1.3 2.1.2 2.1.1 2.1.0 2.0.6 trunk 1.0 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2 1.2.1 1.2.10 1.2.2 1.2.3 1.2.4 1.2.5 All 43 releases
allaccessible / inc / VersionManager.php

VersionManager.php in Accessibility by AllAccessible trunk, at inc/VersionManager.php

199 lines 6.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * AllAccessible Version Manager
4 *
5 * Handles version checking and upgrade routines
6 *
7 * @package AllAccessible
8 * @since 1.3.7
9 */
10
11 if (!defined('ABSPATH')) {
12 die('You are not allowed to call this page directly.');
13 }
14
15 class AllAccessible_VersionManager {
16
17 /**
18 * Initialize the version manager
19 */
20 public static function init() {
21 add_action('plugins_loaded', array(__CLASS__, 'check_version'));
22 }
23
24 /**
25 * Check if plugin version has changed and run upgrade routines if needed
26 */
27 public static function check_version() {
28 $installed_version = get_option('aacb_version', '0');
29
30 // If version has changed, run upgrade routines
31 if (version_compare($installed_version, AACB_VERSION, '<')) {
32 self::run_upgrade_routines($installed_version);
33
34 // Update stored version number
35 update_option('aacb_version', AACB_VERSION);
36 }
37 }
38
39 /**
40 * Run version-specific upgrade routines
41 *
42 * @param string $from_version The previously installed version
43 */
44 private static function run_upgrade_routines($from_version) {
45 // Example upgrade routine for version 1.3.0
46 if (version_compare($from_version, '1.3.0', '<')) {
47 self::upgrade_to_1_3_0();
48 }
49
50 // Example upgrade routine for version 1.3.5
51 if (version_compare($from_version, '1.3.5', '<')) {
52 self::upgrade_to_1_3_5();
53 }
54
55 // Add future upgrade routines here
56 if (version_compare($from_version, '1.3.7', '<')) {
57 self::upgrade_to_1_3_7();
58 }
59
60 // Upgrade to 2.0.0 - Handle wizard migration
61 if (version_compare($from_version, '2.0.0', '<')) {
62 self::upgrade_to_2_0_0();
63 }
64
65 // 2.1.0 — consolidated migration for everything between 2.0.x
66 // and the public 2.1.0 release.
67
68 // All four actions are idempotent + cheap. No-op for fresh
69 // installs (only fires when from_version < 2.1.0).
70 if (version_compare($from_version, '2.1.0', '<')) {
71 self::upgrade_to_2_1_0();
72 }
73
74 // 2.1.4 — flip the plugin signing secret off autoload. New fetches
75 // already store it with autoload=off, but rows created by earlier
76 // versions stay autoloaded (WP autoloads small values), so the
77 // secret rides every request until the next re-fetch. Flip the
78 // installed base immediately on upgrade.
79 if (version_compare($from_version, '2.1.4', '<')) {
80 self::upgrade_to_2_1_4();
81 }
82
83 // Always run this to ensure database is up to date
84 self::update_db_check();
85 }
86
87 /**
88 * Upgrade routine for version 2.1.0 — see consolidated comment in
89 * run_upgrade_routines() above.
90 */
91 private static function upgrade_to_2_1_0() {
92 if (class_exists('AllAccessible_ApiClient')) {
93 $client = AllAccessible_ApiClient::get_instance();
94 try { $client->invalidate_site_resolution(); } catch (\Throwable $e) { /* swallow */ }
95 if (method_exists($client, 'bust_manifest_caches')) {
96 try { $client->bust_manifest_caches(); } catch (\Throwable $e) { /* swallow */ }
97 }
98 } else {
99 // Defensive: invalidate site resolution directly if ApiClient
100 // hasn't loaded yet at this hook firing.
101 delete_transient('aacb_site_options_cache');
102 delete_option('aacb_siteID');
103 }
104
105 if (class_exists('AllAccessible_PostLinkBackfill')) {
106 try { AllAccessible_PostLinkBackfill::on_activate(); } catch (\Throwable $e) { /* swallow */ }
107 }
108
109 // Image grid cache stamp — bump even if the helpers above didn't
110 // load. Default is 1, increment past it so the version-stamp
111 // cache key changes and next Image Manager render misses cache.
112 $current = (int) get_option('aacb_image_grid_cache_stamp', 1);
113 update_option('aacb_image_grid_cache_stamp', $current + 1, false);
114 }
115
116 /**
117 * Upgrade routine for version 1.3.0
118 */
119 private static function upgrade_to_1_3_0() {
120 // Example: Add new option
121 // add_option('aacb_new_feature_enabled', true);
122 }
123
124 /**
125 * Upgrade routine for version 1.3.5
126 */
127 private static function upgrade_to_1_3_5() {
128 // Example: Security improvements
129 // delete_option('aacb_deprecated_setting');
130 }
131
132 /**
133 * Upgrade routine for version 1.3.7
134 */
135 private static function upgrade_to_1_3_7() {
136 // Migrate to new version management system
137 $options = get_option('aacb_options', array());
138 if (!empty($options) && !isset($options['version'])) {
139 $options['version'] = AACB_VERSION;
140 update_option('aacb_options', $options);
141 }
142 }
143
144 /**
145 * Upgrade routine for version 2.0.0
146 * Handles migration from 1.x to 2.0 - new wizard system
147 */
148 private static function upgrade_to_2_0_0() {
149 $account_id = get_option('aacb_accountID');
150
151 // If user already has accountID (upgraded from 1.x), mark wizard as completed
152 if (!empty($account_id)) {
153 update_option('aacb_wizard_completed', true);
154
155 // Set tier to 'unknown' since we don't know if they were free or premium in 1.x
156 // They can continue using their existing account
157 if (!get_option('aacb_account_tier')) {
158 update_option('aacb_account_tier', 'legacy');
159 }
160 }
161
162 // Clean up old options that are no longer used in 2.0
163 delete_option('aacb_engagement_score');
164 delete_option('aacb_widget_opens_count');
165 delete_option('aacb_days_since_install');
166 delete_option('aacb_conversion_events');
167 delete_option('aacb_email_capture_shown');
168 delete_option('aacb_email_capture_count');
169 }
170
171 /**
172 * Upgrade routine for version 2.1.4 — move the signing secret off
173 * autoload on existing installs. Re-add each row with autoload='no'
174 * (delete+add, since update_option won't change an existing row's
175 * autoload flag). Idempotent and safe if the rows are absent.
176 */
177 private static function upgrade_to_2_1_4() {
178 $keys = array('aacb_plugin_secret', 'aacb_plugin_secret_canon', 'aacb_plugin_secret_version');
179 foreach ($keys as $key) {
180 $val = get_option($key, null);
181 if ($val === null) {
182 continue;
183 }
184 delete_option($key);
185 add_option($key, $val, '', 'no');
186 }
187 }
188
189 /**
190 * Update database check
191 */
192 private static function update_db_check() {
193 // This is where you would run any database schema updates if needed
194 }
195 }
196
197 // Initialize the version manager
198 AllAccessible_VersionManager::init();
199