From e5088b47702943cce73b3768f325774765bfef75 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Fri, 28 Aug 2026 09:37:47 +0100 Subject: [PATCH] build the global set `sites` array in the order of the sites config `Stache\Traverser::traverse()` sorts paths by modification time, so `UpdateGlobalVariables` built the `sites` array in whatever order the variable files happened to be written in. When the writes tie on mtime the name order survives, which is why this only showed up on the slower Windows CI runners. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01Mj2inC2cHsqnqD47JhiYbf --- src/UpdateScripts/UpdateGlobalVariables.php | 16 ++++++++++------ .../UpdateScripts/UpdateGlobalVariablesTest.php | 9 ++++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/UpdateScripts/UpdateGlobalVariables.php b/src/UpdateScripts/UpdateGlobalVariables.php index 8fe0755f904..6fb734012e2 100644 --- a/src/UpdateScripts/UpdateGlobalVariables.php +++ b/src/UpdateScripts/UpdateGlobalVariables.php @@ -38,15 +38,19 @@ public function update() */ private function buildSitesArray(): void { - GlobalSet::all()->each(function ($globalSet) { + $siteOrder = Site::all()->keys()->flip(); + + GlobalSet::all()->each(function ($globalSet) use ($siteOrder) { $variables = GlobalVariables::whereSet($globalSet->handle()); - $sites = $variables->mapWithKeys(function ($variable) { - $contents = YAML::file($variable->path())->parse(); - $origin = Arr::get($contents, 'origin'); + $sites = $variables + ->sortBy(fn ($variable) => $siteOrder->get($variable->locale(), $siteOrder->count())) + ->mapWithKeys(function ($variable) { + $contents = YAML::file($variable->path())->parse(); + $origin = Arr::get($contents, 'origin'); - return [$variable->locale() => $origin]; - }); + return [$variable->locale() => $origin]; + }); $globalSet->sites($sites)->save(); diff --git a/tests/UpdateScripts/UpdateGlobalVariablesTest.php b/tests/UpdateScripts/UpdateGlobalVariablesTest.php index 9d74711bc03..fcde4ecf478 100644 --- a/tests/UpdateScripts/UpdateGlobalVariablesTest.php +++ b/tests/UpdateScripts/UpdateGlobalVariablesTest.php @@ -120,9 +120,12 @@ public function it_builds_the_sites_array_in_a_multi_site_install() File::ensureDirectoryExists($this->globalsPath.'/de'); File::put($this->globalsPath.'/test.yaml', Yaml::dump(['title' => 'Test'])); - File::put($this->globalsPath.'/en/test.yaml', Yaml::dump(['foo' => 'Bar', 'baz' => 'Qux'])); - File::put($this->globalsPath.'/fr/test.yaml', Yaml::dump(['origin' => 'en', 'foo' => 'Bar'])); + + // Written out of order on purpose. The Stache indexes variables by modification + // time, but the sites array should follow the order of the sites config. File::put($this->globalsPath.'/de/test.yaml', Yaml::dump(['origin' => 'fr'])); + File::put($this->globalsPath.'/fr/test.yaml', Yaml::dump(['origin' => 'en', 'foo' => 'Bar'])); + File::put($this->globalsPath.'/en/test.yaml', Yaml::dump(['foo' => 'Bar', 'baz' => 'Qux'])); $this->runUpdateScript(UpdateGlobalVariables::class); @@ -130,9 +133,9 @@ public function it_builds_the_sites_array_in_a_multi_site_install() $expected = <<<'YAML' title: Test sites: - de: fr en: null fr: en + de: fr YAML;