mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-05-01 23:19:51 +00:00
parent
07c7d5af17
commit
2d958e88bf
4 changed files with 19 additions and 17 deletions
|
@ -216,12 +216,10 @@ class BookRepo extends EntityRepo
|
|||
*/
|
||||
public function findSuitableSlug($name, $currentId = false)
|
||||
{
|
||||
$originalSlug = Str::slug($name);
|
||||
$slug = $originalSlug;
|
||||
$count = 2;
|
||||
$slug = Str::slug($name);
|
||||
if ($slug === "") $slug = substr(md5(rand(1, 500)), 0, 5);
|
||||
while ($this->doesSlugExist($slug, $currentId)) {
|
||||
$slug = $originalSlug . '-' . $count;
|
||||
$count++;
|
||||
$slug .= '-' . substr(md5(rand(1, 500)), 0, 3);
|
||||
}
|
||||
return $slug;
|
||||
}
|
||||
|
|
|
@ -151,6 +151,7 @@ class ChapterRepo extends EntityRepo
|
|||
public function findSuitableSlug($name, $bookId, $currentId = false)
|
||||
{
|
||||
$slug = Str::slug($name);
|
||||
if ($slug === "") $slug = substr(md5(rand(1, 500)), 0, 5);
|
||||
while ($this->doesSlugExist($slug, $bookId, $currentId)) {
|
||||
$slug .= '-' . substr(md5(rand(1, 500)), 0, 3);
|
||||
}
|
||||
|
|
|
@ -591,14 +591,15 @@ class PageRepo extends EntityRepo
|
|||
|
||||
/**
|
||||
* Gets a suitable slug for the resource
|
||||
* @param $name
|
||||
* @param $bookId
|
||||
* @param string $name
|
||||
* @param int $bookId
|
||||
* @param bool|false $currentId
|
||||
* @return string
|
||||
*/
|
||||
public function findSuitableSlug($name, $bookId, $currentId = false)
|
||||
{
|
||||
$slug = Str::slug($name);
|
||||
if ($slug === "") $slug = substr(md5(rand(1, 500)), 0, 5);
|
||||
while ($this->doesSlugExist($slug, $bookId, $currentId)) {
|
||||
$slug .= '-' . substr(md5(rand(1, 500)), 0, 3);
|
||||
}
|
||||
|
|
|
@ -151,8 +151,10 @@ class EntityTest extends TestCase
|
|||
->visit('/books/create')
|
||||
->type($book->name, '#name')
|
||||
->type($book->description, '#description')
|
||||
->press('Save Book')
|
||||
->seePageIs('/books/my-first-book-2');
|
||||
->press('Save Book');
|
||||
|
||||
$expectedPattern = '/\/books\/my-first-book-[0-9a-zA-Z]{3}/';
|
||||
$this->assertRegExp($expectedPattern, $this->currentUri, "Did not land on expected page [$expectedPattern].\n");
|
||||
|
||||
$book = \BookStack\Book::where('slug', '=', 'my-first-book')->first();
|
||||
return $book;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue