-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[6.x] Manage blueprints in the Control Panel (#373)
* Register blueprints * Add update script to migrate existing blueprints * Move blueprints into physical YAML files * Adjust how blueprints are mocked in tests * Remove blueprint from `runway:resources` command * Update tests * Fix final failing test * Ensure blueprints already exist * Add tests to cover updates to Resource * Fix styling * Move migrate blueprint logic into a command * wip * wip * Update documentation * Fix styling * Fix styling * Fix new tests that are failing due to blueprint changes * Delete old blueprints at the end of the migration script * Specify minimum version of statamic/cms * Run Laravel Pint --------- Co-authored-by: duncanmcclean <duncanmcclean@users.noreply.github.com>
- Loading branch information
1 parent
693f397
commit 3560aff
Showing
24 changed files
with
416 additions
and
489 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace DoubleThreeDigital\Runway\Console\Commands; | ||
|
||
use DoubleThreeDigital\Runway\Resource; | ||
use DoubleThreeDigital\Runway\Runway; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\File; | ||
use Statamic\Console\RunsInPlease; | ||
use Statamic\Facades\Blueprint; | ||
use Statamic\Fields\Blueprint as FieldsBlueprint; | ||
|
||
class MigrateBlueprints extends Command | ||
{ | ||
use RunsInPlease; | ||
|
||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'runway:migrate-blueprints'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Part of the v6.0 upgrade. Migrates your blueprints so they can be managed in the Control Panel.'; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
*/ | ||
public function handle() | ||
{ | ||
Runway::allResources() | ||
->each(function (Resource $resource) { | ||
$originalBlueprint = $this->resolveOriginalBlueprint($resource); | ||
|
||
$resource->blueprint()->setContents($originalBlueprint->contents())->save(); | ||
|
||
if (File::exists($originalBlueprint->path())) { | ||
File::delete($originalBlueprint->path()); | ||
} | ||
}); | ||
} | ||
|
||
protected function resolveOriginalBlueprint(Resource $resource): FieldsBlueprint | ||
{ | ||
if (is_string($resource->config()->get('blueprint'))) { | ||
return Blueprint::find($resource->config()->get('blueprint')); | ||
} | ||
|
||
if (is_array($resource->config()->get('blueprint'))) { | ||
return Blueprint::make()->setHandle($resource->handle())->setContents($resource->config()->get('blueprint')); | ||
} | ||
|
||
throw new \Exception("Could not resolve the original blueprint for the [{$resource->handle()}] resource."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace DoubleThreeDigital\Runway\UpdateScripts; | ||
|
||
use Illuminate\Support\Facades\Artisan; | ||
use Statamic\UpdateScripts\UpdateScript; | ||
|
||
class MigrateBlueprints extends UpdateScript | ||
{ | ||
public function shouldUpdate($newVersion, $oldVersion) | ||
{ | ||
return $this->isUpdatingTo('6.0.0'); | ||
} | ||
|
||
public function update() | ||
{ | ||
Artisan::call('runway:migrate-blueprints'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.