1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-12-17 22:02:15 +03:00

Slugs: Fixed storage bugs, added testing coverage

This commit is contained in:
Dan Brown
2025-11-24 10:46:24 +00:00
parent 291a807d98
commit dd5375f480
5 changed files with 143 additions and 51 deletions

View File

@@ -165,10 +165,7 @@ class BaseRepo
*/
public function refreshSlug(Entity $entity): void
{
if ($entity->id) {
$this->slugHistory->recordForEntity($entity);
}
$this->slugHistory->recordForEntity($entity);
$this->slugGenerator->regenerateForEntity($entity);
}
}

View File

@@ -2,6 +2,7 @@
namespace BookStack\Entities\Tools;
use BookStack\Entities\Models\BookChild;
use BookStack\Entities\Models\Entity;
use Illuminate\Support\Facades\DB;
@@ -12,16 +13,25 @@ class SlugHistory
*/
public function recordForEntity(Entity $entity): void
{
if (!$entity->id || !$entity->slug) {
return;
}
$latest = $this->getLatestEntryForEntity($entity);
if ($latest && $latest->slug === $entity->slug && $latest->parent_slug === $entity->getParent()?->slug) {
return;
}
$parentSlug = null;
if ($entity instanceof BookChild) {
$parentSlug = $entity->book()->first()?->slug;
}
$info = [
'sluggable_type' => $entity->getMorphClass(),
'sluggable_id' => $entity->id,
'slug' => $entity->slug,
'parent_slug' => $entity->getParent()?->slug,
'parent_slug' => $parentSlug,
'created_at' => now(),
'updated_at' => now(),
];