Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/UpdateScripts/UpdateGlobalVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private function migrateFileStructure(): void

$globalSet->save();

File::put($variablesPath, YAML::dump($data));
$globalSet->inDefaultSite()->data($data)->saveQuietly();
});
}
}
27 changes: 27 additions & 0 deletions tests/UpdateScripts/UpdateGlobalVariablesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Facades\File;
use PHPUnit\Framework\Attributes\Test;
use Statamic\Facades\GlobalSet;
use Statamic\Facades\YAML;
use Statamic\UpdateScripts\UpdateGlobalVariables;
use Tests\PreventSavingStacheItemsToDisk;
Expand Down Expand Up @@ -79,6 +80,32 @@ public function it_migrates_global_variables_with_empty_data_in_a_single_site_in
unlink($this->globalsPath.'/en/test.yaml');
}

#[Test]
public function migrated_variables_survive_being_saved_later_in_the_same_process()
{
File::put($this->globalsPath.'/test.yaml', Yaml::dump([
'title' => 'Test',
'data' => [
'foo' => 'Bar',
],
]));

$this->runUpdateScript(UpdateGlobalVariables::class);

// Simulates an addon update script saving variables after the migration
$variables = GlobalSet::findByHandle('test')->inDefaultSite();
$variables->set('baz', 'Qux');
$variables->save();

$this->assertEquals(
['foo' => 'Bar', 'baz' => 'Qux'],
YAML::parse(File::get($this->globalsPath.'/en/test.yaml'))
);

unlink($this->globalsPath.'/test.yaml');
unlink($this->globalsPath.'/en/test.yaml');
}

#[Test]
public function it_builds_the_sites_array_in_a_multi_site_install()
{
Expand Down
Loading