Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/UpdateScripts/UpdateGlobalVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
9 changes: 6 additions & 3 deletions tests/UpdateScripts/UpdateGlobalVariablesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,22 @@ 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);

// Ensures that the sites array is built correctly.
$expected = <<<'YAML'
title: Test
sites:
de: fr
en: null
fr: en
de: fr

YAML;

Expand Down
Loading