parent
07c7d5af17
commit
2d958e88bf
|
@ -216,12 +216,10 @@ class BookRepo extends EntityRepo
|
||||||
*/
|
*/
|
||||||
public function findSuitableSlug($name, $currentId = false)
|
public function findSuitableSlug($name, $currentId = false)
|
||||||
{
|
{
|
||||||
$originalSlug = Str::slug($name);
|
$slug = Str::slug($name);
|
||||||
$slug = $originalSlug;
|
if ($slug === "") $slug = substr(md5(rand(1, 500)), 0, 5);
|
||||||
$count = 2;
|
|
||||||
while ($this->doesSlugExist($slug, $currentId)) {
|
while ($this->doesSlugExist($slug, $currentId)) {
|
||||||
$slug = $originalSlug . '-' . $count;
|
$slug .= '-' . substr(md5(rand(1, 500)), 0, 3);
|
||||||
$count++;
|
|
||||||
}
|
}
|
||||||
return $slug;
|
return $slug;
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,6 +151,7 @@ class ChapterRepo extends EntityRepo
|
||||||
public function findSuitableSlug($name, $bookId, $currentId = false)
|
public function findSuitableSlug($name, $bookId, $currentId = false)
|
||||||
{
|
{
|
||||||
$slug = Str::slug($name);
|
$slug = Str::slug($name);
|
||||||
|
if ($slug === "") $slug = substr(md5(rand(1, 500)), 0, 5);
|
||||||
while ($this->doesSlugExist($slug, $bookId, $currentId)) {
|
while ($this->doesSlugExist($slug, $bookId, $currentId)) {
|
||||||
$slug .= '-' . substr(md5(rand(1, 500)), 0, 3);
|
$slug .= '-' . substr(md5(rand(1, 500)), 0, 3);
|
||||||
}
|
}
|
||||||
|
|
|
@ -591,14 +591,15 @@ class PageRepo extends EntityRepo
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a suitable slug for the resource
|
* Gets a suitable slug for the resource
|
||||||
* @param $name
|
* @param string $name
|
||||||
* @param $bookId
|
* @param int $bookId
|
||||||
* @param bool|false $currentId
|
* @param bool|false $currentId
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function findSuitableSlug($name, $bookId, $currentId = false)
|
public function findSuitableSlug($name, $bookId, $currentId = false)
|
||||||
{
|
{
|
||||||
$slug = Str::slug($name);
|
$slug = Str::slug($name);
|
||||||
|
if ($slug === "") $slug = substr(md5(rand(1, 500)), 0, 5);
|
||||||
while ($this->doesSlugExist($slug, $bookId, $currentId)) {
|
while ($this->doesSlugExist($slug, $bookId, $currentId)) {
|
||||||
$slug .= '-' . substr(md5(rand(1, 500)), 0, 3);
|
$slug .= '-' . substr(md5(rand(1, 500)), 0, 3);
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,8 +151,10 @@ class EntityTest extends TestCase
|
||||||
->visit('/books/create')
|
->visit('/books/create')
|
||||||
->type($book->name, '#name')
|
->type($book->name, '#name')
|
||||||
->type($book->description, '#description')
|
->type($book->description, '#description')
|
||||||
->press('Save Book')
|
->press('Save Book');
|
||||||
->seePageIs('/books/my-first-book-2');
|
|
||||||
|
$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();
|
$book = \BookStack\Book::where('slug', '=', 'my-first-book')->first();
|
||||||
return $book;
|
return $book;
|
||||||
|
|
Loading…
Reference in New Issue