-
-
Notifications
You must be signed in to change notification settings - Fork 554
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[6.x] Remove "Parent" field from entries (#11506)
- Loading branch information
1 parent
2639a2d
commit d255f5f
Showing
10 changed files
with
121 additions
and
114 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
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
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,30 @@ | ||
<?php | ||
|
||
namespace Statamic\UpdateScripts; | ||
|
||
use Statamic\Facades\Collection; | ||
|
||
class RemoveParentField extends UpdateScript | ||
{ | ||
public function shouldUpdate($newVersion, $oldVersion) | ||
{ | ||
return $this->isUpdatingTo('6.0.0'); | ||
} | ||
|
||
public function update() | ||
{ | ||
Collection::all()->each(function ($collection) { | ||
$collection->entryBlueprints()->each(function ($blueprint) use ($collection) { | ||
if ($collection->hasStructure() && $blueprint->hasField('parent')) { | ||
$blueprint->removeField('parent')->save(); | ||
|
||
$this->console->line(sprintf( | ||
'Parent field removed from the <comment>%s</comment> collection\'s <info>%s</info> blueprint.', | ||
$collection->handle(), | ||
$blueprint->handle() | ||
)); | ||
} | ||
}); | ||
}); | ||
} | ||
} |
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,82 @@ | ||
<?php | ||
|
||
namespace Tests\UpdateScripts; | ||
|
||
use PHPUnit\Framework\Attributes\Test; | ||
use Statamic\Facades\Blueprint; | ||
use Statamic\Facades\Collection; | ||
use Statamic\UpdateScripts\RemoveParentField; | ||
use Tests\PreventSavingStacheItemsToDisk; | ||
use Tests\TestCase; | ||
use Tests\UpdateScripts\Concerns\RunsUpdateScripts; | ||
|
||
class RemoveParentFieldTest extends TestCase | ||
{ | ||
use PreventSavingStacheItemsToDisk, RunsUpdateScripts; | ||
|
||
#[Test] | ||
public function it_is_registered() | ||
{ | ||
$this->assertUpdateScriptRegistered(RemoveParentField::class); | ||
} | ||
|
||
#[Test] | ||
public function it_removes_parent_field_from_structured_collection_blueprint() | ||
{ | ||
$collection = tap(Collection::make('test')->structureContents(['tree' => []]))->save(); | ||
|
||
$blueprint = $collection->entryBlueprint(); | ||
|
||
$blueprint->setContents(['tabs' => [ | ||
'main' => ['sections' => [ | ||
['fields' => [ | ||
['handle' => 'title', 'field' => ['type' => 'text']], | ||
]], | ||
]], | ||
'sidebar' => ['sections' => [ | ||
['fields' => [ | ||
['handle' => 'slug', 'field' => ['type' => 'slug']], | ||
['handle' => 'parent', 'field' => ['type' => 'entries', 'collections' => ['test'], 'max_items' => 1]], | ||
]], | ||
]], | ||
]]); | ||
|
||
$blueprint->save(); | ||
|
||
$this->runUpdateScript(RemoveParentField::class); | ||
|
||
$blueprint = Blueprint::find($blueprint->fullyQualifiedHandle()); | ||
|
||
$this->assertFalse($blueprint->hasField('parent')); | ||
} | ||
|
||
#[Test] | ||
public function it_does_not_remove_parent_field_from_unstructured_collection_blueprint() | ||
{ | ||
$collection = tap(Collection::make('test'))->save(); | ||
|
||
$blueprint = $collection->entryBlueprint(); | ||
|
||
$blueprint->setContents(['tabs' => [ | ||
'main' => ['sections' => [ | ||
['fields' => [ | ||
['handle' => 'title', 'field' => ['type' => 'text']], | ||
]], | ||
]], | ||
'sidebar' => ['sections' => [ | ||
['fields' => [ | ||
['handle' => 'slug', 'field' => ['type' => 'slug']], | ||
['handle' => 'parent', 'field' => ['type' => 'entries', 'collections' => ['test'], 'max_items' => 1]], | ||
]], | ||
]], | ||
]]); | ||
|
||
$blueprint->save(); | ||
|
||
$this->runUpdateScript(RemoveParentField::class); | ||
|
||
$blueprint = Blueprint::find($blueprint->fullyQualifiedHandle()); | ||
|
||
$this->assertTrue($blueprint->hasField('parent')); | ||
} | ||
} |