Skip to content

Commit a5679f3

Browse files
committed
Improved upgrader. Removed old updater. Offloaded environment checks.
1 parent 722f26b commit a5679f3

File tree

12 files changed

+410
-839
lines changed

12 files changed

+410
-839
lines changed

bootstrap/envtest.php

Lines changed: 0 additions & 144 deletions
This file was deleted.

bootstrap/update.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,12 @@ function _prepare_tsf_nag_installer_scripts() {
4545
'updates',
4646
];
4747
$scriptid = 'tsfinstaller';
48-
49-
// Don't rely on the script name! Rely on the script-id, if you so choose to manipulate it.
50-
// This name will change back once we stop supporting WP<5.5
51-
$scriptname = version_compare( $GLOBALS['wp_version'], '5.5', '<' ) ? 'tsfinstaller' : 'tsfinstallernew';
52-
$suffix = SCRIPT_DEBUG ? '' : '.min';
53-
54-
$strings = [
48+
$suffix = SCRIPT_DEBUG ? '' : '.min';
49+
$strings = [
5550
'slug' => 'autodescription',
5651
];
5752

58-
// NB 82% of our users are on WP 5.5+. Do we really _want_ to maintain compatibility with earlier versions?
59-
60-
\wp_register_script( $scriptid, TSF_EXTENSION_MANAGER_DIR_URL . "lib/js/{$scriptname}{$suffix}.js", $deps, TSF_EXTENSION_MANAGER_VERSION, true );
53+
\wp_register_script( $scriptid, TSF_EXTENSION_MANAGER_DIR_URL . "lib/js/{$scriptid}{$suffix}.js", $deps, TSF_EXTENSION_MANAGER_VERSION, true );
6154
\wp_localize_script( $scriptid, "{$scriptid}L10n", $strings );
6255

6356
\add_action( 'admin_print_styles', __NAMESPACE__ . '\\_print_tsf_nag_installer_styles' );

bootstrap/upgrade.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626

2727
\TSF_Extension_Manager\load_upgrader();
2828

29+
// Note to self: We use "critical" here because it runs before extensions are loaded.
30+
// We should not attach to other hooks because we must upgrade in sequence.
31+
// We shouldn't have called it "critical", "plugin" vs "extension" instead. TODO Fixme?
32+
// We should also abandon the "admin" vs "always" upgrader? Not loading some parts of the admin might make some migrations difficult, however.
33+
2934
\add_action( 'tsfem_prepare_critical_upgrade', __NAMESPACE__ . '\\_do_critical_core_upgrade', 0, 1 );
3035
/**
3136
* Upgrades the core plugin database before the plugin runs.
@@ -41,12 +46,21 @@ function _do_critical_core_upgrade( Upgrader $upgrader ) {
4146
// phpcs:disable -- Example with unused variable.
4247
$version = $upgrader->get_current_version( 'core' );
4348

44-
// Example:
45-
// if ( $version < 1500 ) {
46-
// $upgrader->_register_upgrade( 'core', '1500', function( $version ) { return (bool) $success; } );
47-
// }
48-
49-
// phpcs:enable
49+
switch ( true ) :
50+
case $version < 2500:
51+
$upgrader->_register_upgrade(
52+
'core',
53+
'2500',
54+
function( $version ) {
55+
// Declare success when the option doesn't exist or is succesfully deleted.
56+
$success = ! \get_option( 'tsfem_tested_environment_version' ) || \delete_option( 'tsfem_tested_environment_version' );
57+
return $success;
58+
}
59+
);
60+
// no break, do moar upgrades;
5061

51-
$upgrader->_register_upgrade( 'core', TSF_EXTENSION_MANAGER_DB_VERSION, '\\__return_true' );
62+
default:
63+
$upgrader->_register_upgrade( 'core', TSF_EXTENSION_MANAGER_DB_VERSION, '\\__return_true' );
64+
break;
65+
endswitch;
5266
}

bootstrap/upgrader.class.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ private function construct() {
103103
$this->set_defaults();
104104
$this->increase_available_memory();
105105

106+
// These are not available to extensions.
106107
\add_action( 'plugins_loaded', [ $this, '_load_critical_hook' ], 0 );
107108
\add_action( 'plugins_loaded', [ $this, '_parse_critical' ], 1 );
108109

@@ -182,6 +183,7 @@ public function get_current_version( $member ) {
182183
* shouldn't interfere flow, ever. Let defensive and state programming occur instead.
183184
*
184185
* @since 1.5.0
186+
* @since 2.5.3 Now supports multiple callbacks per version. Order of registration is important.
185187
* @factory
186188
*
187189
* @param string $member The member of the upgrade, e.g. the extension slug.
@@ -193,10 +195,9 @@ public function _register_upgrade( $member, $version, callable $callback ) {
193195
$c = &$this->_upgrade_collector();
194196

195197
// phpcs:ignore, WordPress.WhiteSpace.OperatorSpacing
196-
isset( $c->{$member} ) or $c->{$member} = new \stdClass;
197-
isset( $c->{$member}->{$version} ) or $c->{$member}->{$version} = [];
198+
isset( $c->{$member} ) or $c->{$member} = new \stdClass;
198199

199-
$c->{$member}->{$version} = $callback;
200+
$c->{$member}->{$version}[] = $callback;
200201
}
201202

202203
/**
@@ -231,7 +232,7 @@ public function _load_hooks() {
231232

232233
if ( \is_admin() ) {
233234
$this->do_admin_upgrade();
234-
$ms and $this->do_admin_upgrade();
235+
$ms and $this->do_network_admin_upgrade();
235236
}
236237

237238
$this->do_always_upgrade();
@@ -326,6 +327,7 @@ public function _parse() {
326327

327328
foreach ( $upgrades as $member => $version ) {
328329
$upgrades->{$member} = (array) $upgrades->{$member};
330+
// Sort by version.
329331
ksort( $upgrades->{$member} );
330332
}
331333

@@ -338,6 +340,7 @@ public function _parse() {
338340
// Continue anyway?
339341
break;
340342
}
343+
341344
if ( ! $updated ) {
342345
// TODO log error. Wait for logger factory/framework.
343346
// REASON: Database error while trying to store data.
@@ -356,14 +359,17 @@ public function _parse() {
356359
* Doesn't yield when the input is empty.
357360
*
358361
* @since 1.5.0
362+
* @since 2.5.3 Now supports multiple callbacks per version.
359363
*
360364
* @param \stdClass $upgrade The upgrade iterator object.
361365
* @yield array { $member => $version }
362366
*/
363367
private function yield_runs( \stdClass $upgrade ) {
364-
foreach ( $upgrade as $member => $data ) {
365-
foreach ( $data as $version => $callback ) {
366-
yield $member => $this->do_upgrade_cb( (string) $version, $callback );
368+
foreach ( $upgrade as $member => $versions ) {
369+
foreach ( $versions as $version => $callbacks ) {
370+
foreach ( $callbacks as $callback ) {
371+
yield $member => $this->do_upgrade_cb( (string) $version, $callback );
372+
}
367373
}
368374
}
369375
}

extensions/essentials/articles/trunk/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ add_filter( 'the_seo_framework_sitemap_articles_news_sitemap_query_args', functi
260260

261261
* **Added:**
262262
* The Article markup author object now has a URL provided, as suggested by Google. This URL points to the author archive page of the website.
263-
* A misconfigured NGINX-compatible endpoint for the Google News sitemap was added (`/news-sitemap.xml`).
264-
* Namecheap, EasyWP, SpinupWP, etc. blindly implemented the broken NGINX script from Yoast SEO; this changes makes Articles compatible with witless hosting providers.
263+
* A compatible endpoint for the Google News sitemap supporting misconfigured NGINX profiles has been added (`/news-sitemap.xml`).
264+
* Namecheap, EasyWP, SpinupWP, etc. blindly implemented the broken NGINX script from Yoast SEO; this change makes Articles compatible with witless hosting providers.
265265
* **Improved:**
266266
* A News Sitemap URL has been added to the Extensions Settings page.
267267
* This is only visible after the sitemap has been enabled and the settings page refreshed.

inc/traits/manager/extensions.trait.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private static function get_extensions() {
8888
'author' => 'Sybre Waaijer',
8989
'party' => 'first',
9090
'last_updated' => '1635798852',
91-
'requires' => '5.4',
91+
'requires' => '5.5',
9292
'tested' => '6.0',
9393
'requires_tsf' => '4.1.4',
9494
'tested_tsf' => '4.2',
@@ -101,7 +101,7 @@ private static function get_extensions() {
101101
'author' => 'Sybre Waaijer',
102102
'party' => 'first',
103103
'last_updated' => '1651198376',
104-
'requires' => '5.4',
104+
'requires' => '5.5',
105105
'tested' => '6.0',
106106
'requires_tsf' => '4.1.4',
107107
'tested_tsf' => '4.2',
@@ -114,7 +114,7 @@ private static function get_extensions() {
114114
'author' => 'Sybre Waaijer',
115115
'party' => 'first',
116116
'last_updated' => '1612160183',
117-
'requires' => '5.4',
117+
'requires' => '5.5',
118118
'tested' => '6.0',
119119
'requires_tsf' => '4.1.4',
120120
'tested_tsf' => '4.2',
@@ -127,7 +127,7 @@ private static function get_extensions() {
127127
'author' => 'Sybre Waaijer',
128128
'party' => 'first',
129129
'last_updated' => '1576470514',
130-
'requires' => '5.4',
130+
'requires' => '5.5',
131131
'tested' => '6.0',
132132
'requires_tsf' => '4.1.4',
133133
'tested_tsf' => '4.2',
@@ -140,7 +140,7 @@ private static function get_extensions() {
140140
'author' => 'Sybre Waaijer',
141141
'party' => 'first',
142142
'last_updated' => '1633798024',
143-
'requires' => '5.4',
143+
'requires' => '5.5',
144144
'tested' => '6.0',
145145
'requires_tsf' => '4.1.4',
146146
'tested_tsf' => '4.2',
@@ -153,7 +153,7 @@ private static function get_extensions() {
153153
'author' => 'Sybre Waaijer',
154154
'party' => 'first',
155155
'last_updated' => '1565627638',
156-
'requires' => '5.4',
156+
'requires' => '5.5',
157157
'tested' => '6.0',
158158
'requires_tsf' => '4.1.4',
159159
'tested_tsf' => '4.2',
@@ -166,7 +166,7 @@ private static function get_extensions() {
166166
'author' => 'Sybre Waaijer',
167167
'party' => 'first',
168168
'last_updated' => '1633797930',
169-
'requires' => '5.4',
169+
'requires' => '5.5',
170170
'tested' => '6.0',
171171
'requires_tsf' => '4.1.4',
172172
'tested_tsf' => '4.2',
@@ -179,7 +179,7 @@ private static function get_extensions() {
179179
'author' => 'Sybre Waaijer',
180180
'party' => 'first',
181181
'last_updated' => '1515109560',
182-
'requires' => '5.4',
182+
'requires' => '5.5',
183183
'tested' => '6.0',
184184
'requires_tsf' => '4.1.4',
185185
'tested_tsf' => '4.2',
@@ -192,7 +192,7 @@ private static function get_extensions() {
192192
'author' => 'Sybre Waaijer',
193193
'party' => 'first',
194194
'last_updated' => '1541601833',
195-
'requires' => '5.4',
195+
'requires' => '5.5',
196196
'tested' => '6.0',
197197
'requires_tsf' => '4.1.4',
198198
'tested_tsf' => '4.2',
@@ -205,7 +205,7 @@ private static function get_extensions() {
205205
'author' => 'Sybre Waaijer',
206206
'party' => 'first',
207207
'last_updated' => '1572496812',
208-
'requires' => '5.4',
208+
'requires' => '5.5',
209209
'tested' => '6.0',
210210
'requires_tsf' => '4.1.4',
211211
'tested_tsf' => '4.2',
@@ -226,9 +226,9 @@ private static function get_extensions() {
226226
*/
227227
private static function get_external_extensions_checksum() {
228228
return [
229-
'sha256' => '1738e94a24b54681c348bbe05983e3fc7a4d1e689da7abf2139ae9c79bcc4783',
230-
'sha1' => 'dda31ed9e11d54419da20b40dda331c1b492b37c',
231-
'md5' => '8afcc0ecb8c2b063767f86e896ca7768',
229+
'sha256' => '5b80680cd8b82eb998370ea50b5aa5afdbe2c4a45d1386a1cec399f462741dc9',
230+
'sha1' => '00968dd9ff0d9791e083c2766a5d17af1dd0ad0a',
231+
'md5' => '3ddc34319cd368d11459cbc5cb34029e',
232232
];
233233
}
234234

0 commit comments

Comments
 (0)