From 03d938614f0acc438c9167400f33ba7a2e4a03ec Mon Sep 17 00:00:00 2001 From: John Koster Date: Wed, 11 Sep 2024 03:42:43 -0500 Subject: [PATCH] Corrects issue with importing/exporting Blueprints on Windows (#351) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Corrects issue with importing/exporting Blueprints on Windows * Same for fieldsets * import blueprint facade & rename variable * Move the namespace "normalisation" into the exporter We probably don't need to override the `Blueprint` class to do this, especially since our overridden method is only used in the exporter command. * 🍺 --------- Co-authored-by: Ryan Mitchell Co-authored-by: Duncan McClean --- src/Commands/ExportBlueprints.php | 16 +++++++++++++++- src/Commands/ImportBlueprints.php | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Commands/ExportBlueprints.php b/src/Commands/ExportBlueprints.php index feb5e246..bb1edbf5 100644 --- a/src/Commands/ExportBlueprints.php +++ b/src/Commands/ExportBlueprints.php @@ -8,9 +8,11 @@ use Statamic\Console\RunsInPlease; use Statamic\Eloquent\Fields\BlueprintModel; use Statamic\Eloquent\Fields\FieldsetModel; +use Statamic\Facades\Blueprint as BlueprintFacade; use Statamic\Fields\Blueprint as StacheBlueprint; use Statamic\Fields\Fieldset as StacheFieldset; use Statamic\Support\Arr; +use Statamic\Support\Str; class ExportBlueprints extends Command { @@ -74,7 +76,7 @@ private function exportBlueprints() ->setHandle($model->handle) ->setHidden(Arr::get($model->data, 'hide')) ->setOrder(Arr::get($model->data, 'order')) - ->setNamespace($model->namespace) + ->setNamespace($this->getBlueprintNamespace($model->namespace)) ->setContents($this->updateOrderFromBlueprintSections($model->data)) ->save(); }); @@ -100,6 +102,18 @@ private function exportFieldsets() $this->info('Fieldsets exported'); } + private function getBlueprintNamespace(string $namespace): string + { + $blueprintDirectory = str_replace('\\', '/', BlueprintFacade::directory()); + $blueprintDirectory = str_replace('/', '.', $blueprintDirectory); + + if (Str::startsWith($namespace, $blueprintDirectory)) { + return mb_substr($namespace, mb_strlen($blueprintDirectory)); + } + + return $namespace; + } + private function updateOrderFromBlueprintSections($contents) { $contents['tabs'] = collect($contents['tabs'] ?? []) diff --git a/src/Commands/ImportBlueprints.php b/src/Commands/ImportBlueprints.php index d914c8c4..e14a261c 100644 --- a/src/Commands/ImportBlueprints.php +++ b/src/Commands/ImportBlueprints.php @@ -69,7 +69,7 @@ private function importBlueprints(): void return; } - $directory = resource_path('blueprints'); + $directory = str_replace('\\', '/', resource_path('blueprints')); $files = File::withAbsolutePaths() ->getFilesByTypeRecursively($directory, 'yaml'); @@ -129,7 +129,7 @@ private function importFieldsets(): void return; } - $directory = resource_path('fieldsets'); + $directory = str_replace('\\', '/', resource_path('fieldsets')); $files = File::withAbsolutePaths() ->getFilesByTypeRecursively($directory, 'yaml');