Skip to content

Commit

Permalink
Fix console export now that repositories are split (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell authored Aug 14, 2023
1 parent 92ef3da commit a1bf88e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/Commands/ExportGlobals.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
use Statamic\Console\RunsInPlease;
use Statamic\Contracts\Globals\GlobalRepository as GlobalRepositoryContract;
use Statamic\Contracts\Globals\GlobalSet as GlobalSetContract;
use Statamic\Contracts\Globals\GlobalVariablesRepository as GlobalVariablesRepositoryContract;
use Statamic\Contracts\Globals\Variables as VariablesContract;
use Statamic\Eloquent\Globals\GlobalSetModel;
use Statamic\Eloquent\Globals\VariablesModel;
use Statamic\Facades\GlobalSet as GlobalSetFacade;
use Statamic\Globals\GlobalSet;
use Statamic\Globals\Variables;
use Statamic\Stache\Repositories\GlobalRepository;
use Statamic\Stache\Repositories\GlobalVariablesRepository;
use Statamic\Statamic;

class ExportGlobals extends Command
Expand Down Expand Up @@ -49,25 +54,29 @@ public function handle()
private function usingDefaultRepositories(Closure $callback)
{
Facade::clearResolvedInstance(GlobalRepositoryContract::class);
Facade::clearResolvedInstance(GlobalVariablesRepositoryContract::class);

Statamic::repository(GlobalRepositoryContract::class, GlobalRepository::class);
Statamic::repository(GlobalVariablesRepositoryContract::class, GlobalVariablesRepository::class);

app()->bind(GlobalSetContract::class, GlobalSet::class);
app()->bind(VariablesContract::class, Variables::class);

$callback();
}

private function exportGlobals()
{
$sets = GlobalSetModel::all();
$variables = VariablesModel::all();

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

foreach ($model->localizations as $localization) {
foreach ($variables->where('handle', $model->handle) as $localization) {
$global->makeLocalization($localization->locale)
->data($localization->data)
->origin($localization->origin ?? null)
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ExportNavs.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private function exportNavs()

private function exportNavTrees()
{
if (! $this->confirm('Do you want to export navs?')) {
if (! $this->confirm('Do you want to export nav trees?')) {
return;
}

Expand Down

0 comments on commit a1bf88e

Please sign in to comment.