Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksleight committed Feb 1, 2024
1 parent a5b7e90 commit 3e2aaed
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
7 changes: 7 additions & 0 deletions src/Entries/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,13 @@ public function updateEntryOrder($ids = null)
return $this;
}

public function updateEntryParent($ids = null)
{
Facades\Collection::updateEntryParent($this, $ids);

return $this;
}

public function path()
{
return vsprintf('%s/%s.yaml', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Statamic\Events\CollectionTreeSaved;

class UpdateStructuredEntryOrder
class UpdateStructuredEntryOrderAndParent
{
public function handle(CollectionTreeSaved $event)
{
Expand All @@ -19,5 +19,6 @@ public function handle(CollectionTreeSaved $event)
}

$collection->updateEntryOrder($ids);
$collection->updateEntryParent($ids);
}
}
2 changes: 1 addition & 1 deletion src/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class EventServiceProvider extends ServiceProvider
],
\Statamic\Events\CollectionTreeSaved::class => [
\Statamic\Entries\UpdateStructuredEntryUris::class,
\Statamic\Entries\UpdateStructuredEntryOrder::class,
\Statamic\Entries\UpdateStructuredEntryOrderAndParent::class,
],
\Statamic\Events\EntryBlueprintFound::class => [
\Statamic\Entries\AddSiteColumnToBlueprint::class,
Expand Down
5 changes: 5 additions & 0 deletions src/Stache/Repositories/CollectionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public function updateEntryOrder(Collection $collection, $ids = null)
$this->store->updateEntryOrder($collection, $ids);
}

public function updateEntryParent(Collection $collection, $ids = null)
{
$this->store->updateEntryParent($collection, $ids);
}

public function whereStructured(): IlluminateCollection
{
return $this->all()->filter->hasStructure();
Expand Down
14 changes: 0 additions & 14 deletions src/Stache/Repositories/CollectionTreeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace Statamic\Stache\Repositories;

use Statamic\Contracts\Structures\CollectionTree as TreeContract;
use Statamic\Contracts\Structures\Tree;
use Statamic\Facades\Stache as StacheFacade;
use Statamic\Stache\Stache;
use Statamic\Structures\CollectionTree;

Expand All @@ -22,16 +20,4 @@ public static function bindings()
TreeContract::class => CollectionTree::class,
];
}

public function save(Tree $tree)
{
$result = parent::save($tree);

StacheFacade::store('entries')
->store($tree->collection()->handle())
->resolveIndexes()
->each->update();

return $result;
}
}
9 changes: 9 additions & 0 deletions src/Stache/Stores/CollectionsStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ public function updateEntryOrder($collection, $ids = null)
$this->updateEntriesWithinIndex($index, $ids);
}

public function updateEntryParent($collection, $ids = null)
{
$index = Stache::store('entries')
->store($collection->handle())
->index('parent');

$this->updateEntriesWithinIndex($index, $ids);
}

private function updateEntriesWithinIndex($index, $ids)
{
if (empty($ids)) {
Expand Down

0 comments on commit 3e2aaed

Please sign in to comment.