Skip to content

[5.x] Allow globals and variables to be exported seperately #431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 4.x
Choose a base branch
from
Open
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
50 changes: 39 additions & 11 deletions src/Commands/ExportGlobals.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ExportGlobals extends Command
*
* @var string
*/
protected $signature = 'statamic:eloquent:export-globals';
protected $signature = 'statamic:eloquent:export-globals {--force : Force the export to run, with all prompts answered "yes"}';

/**
* The console command description.
Expand All @@ -46,6 +46,7 @@ public function handle()
{
$this->usingDefaultRepositories(function () {
$this->exportGlobals();
$this->exportGlobalVariables();
});

return 0;
Expand All @@ -67,24 +68,51 @@ private function usingDefaultRepositories(Closure $callback)

private function exportGlobals()
{
if (! $this->option('force') && ! $this->confirm('Do you want to export global sets?')) {
return;
}

$sets = GlobalSetModel::all();
$variables = VariablesModel::all();

$this->withProgressBar($sets, function ($model) use ($variables) {
$global = GlobalSetFacade::make()
$this->withProgressBar($sets, function ($model) {
GlobalSetFacade::make()
->handle($model->handle)
->title($model->title);
->title($model->title)
->save();
});

$this->newLine();
$this->info('Globals exported');
}

foreach ($variables->where('handle', $model->handle) as $localization) {
$global->makeLocalization($localization->locale)
->data($localization->data)
->origin($localization->origin ?? null);
private function exportGlobalVariables()
{
if (! $this->option('force') && ! $this->confirm('Do you want to export global variables?')) {
return;
}

$variables = VariablesModel::all();

$this->withProgressBar($variables, function ($model) {
if (! $global = GlobalSetFacade::find($model->handle)) {
$global = tap(
GlobalSetFacade::make()
->handle($model->handle)
->title($model->handle)
)
->save();
}

$global->save();
$globalVariable = $global->in($model->locale);

$globalVariable
->data($localization->data)
->origin($localization->origin ?? null);

$globalVariable->save();
});

$this->newLine();
$this->info('Globals exported');
$this->info('Global variables exported');
}
}