mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 05:36:00 +00:00
Cleaned up duplicate code in recycle-bin restore
This commit is contained in:
parent
9e033709a7
commit
3e70c661a1
@ -240,26 +240,21 @@ class TrashCan
|
|||||||
$count = 1;
|
$count = 1;
|
||||||
$entity->restore();
|
$entity->restore();
|
||||||
|
|
||||||
if ($entity->isA('chapter') || $entity->isA('book')) {
|
$restoreAction = function ($entity) use (&$count) {
|
||||||
foreach ($entity->pages()->withTrashed()->withCount('deletions')->get() as $page) {
|
if ($entity->deletions_count > 0) {
|
||||||
if ($page->deletions_count > 0) {
|
$entity->deletions()->delete();
|
||||||
$page->deletions()->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
$page->restore();
|
|
||||||
$count++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$entity->restore();
|
||||||
|
$count++;
|
||||||
|
};
|
||||||
|
|
||||||
|
if ($entity->isA('chapter') || $entity->isA('book')) {
|
||||||
|
$entity->pages()->withTrashed()->withCount('deletions')->get()->each($restoreAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($entity->isA('book')) {
|
if ($entity->isA('book')) {
|
||||||
foreach ($entity->chapters()->withTrashed()->withCount('deletions')->get() as $chapter) {
|
$entity->chapters()->withTrashed()->withCount('deletions')->get()->each($restoreAction);
|
||||||
if ($chapter->deletions_count === 0) {
|
|
||||||
$chapter->deletions()->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
$chapter->restore();
|
|
||||||
$count++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $count;
|
return $count;
|
||||||
|
Loading…
Reference in New Issue
Block a user