// Sort our changes from our map to be chapters first
// Since they need to be process to ensure book alignment for child page changes.
$sortMapItems = $sortMap->all();
- usort($sortMapItems, function(BookSortMapItem $itemA, BookSortMapItem $itemB) {
+ usort($sortMapItems, function (BookSortMapItem $itemA, BookSortMapItem $itemB) {
$aScore = $itemA->type === 'page' ? 2 : 1;
$bScore = $itemB->type === 'page' ? 2 : 1;
+
return $aScore - $bScore;
});
return;
}
- $currentParentKey = 'book:' . $model->book_id;
+ $currentParentKey = 'book:' . $model->book_id;
if ($model instanceof Page && $model->chapter_id) {
- $currentParentKey = 'chapter:' . $model->chapter_id;
+ $currentParentKey = 'chapter:' . $model->chapter_id;
}
$currentParent = $modelMap[$currentParentKey] ?? null;
/**
* Load models from the database into the given sort map.
+ *
* @return array<string, Entity>
*/
protected function loadModelsFromSortMap(BookSortMap $sortMap): array
$modelMap = [];
$ids = [
'chapter' => [],
- 'page' => [],
- 'book' => [],
+ 'page' => [],
+ 'book' => [],
];
foreach ($sortMap->all() as $sortMapItem) {
namespace BookStack\Uploads;
use BookStack\Exceptions\ImageUploadException;
-use BookStack\Util\WebSafeMimeSniffer;
use ErrorException;
use Exception;
use Illuminate\Contracts\Cache\Repository as Cache;
}
$initialHeader = substr($imageData, 0, strpos($imageData, 'IDAT'));
+
return strpos($initialHeader, 'acTL') !== false;
}
$storage = $this->getStorageDisk($image->type);
if ($storage->exists($this->adjustPathForStorageDisk($thumbFilePath, $image->type))) {
$this->cache->put($thumbCacheKey, $thumbFilePath, 60 * 60 * 72);
+
return $this->getPublicUrl($thumbFilePath);
}
// Do not resize apng images where we're not cropping
if ($keepRatio && $this->isApngData($image, $imageData)) {
$this->cache->put($thumbCacheKey, $image->path, 60 * 60 * 72);
+
return $this->getPublicUrl($image->path);
}
// Create request data
$reqData = [
[
- 'id' => $chapterToMove->id,
- 'sort' => 0,
+ 'id' => $chapterToMove->id,
+ 'sort' => 0,
'parentChapter' => false,
- 'type' => 'chapter',
- 'book' => $newBook->id,
+ 'type' => 'chapter',
+ 'book' => $newBook->id,
],
];
foreach ($pagesToMove as $index => $page) {
$reqData[] = [
- 'id' => $page->id,
- 'sort' => $index,
+ 'id' => $page->id,
+ 'sort' => $index,
'parentChapter' => $index === count($pagesToMove) - 1 ? $chapterToMove->id : false,
- 'type' => 'page',
- 'book' => $newBook->id,
+ 'type' => 'page',
+ 'book' => $newBook->id,
];
}
$sortResp->assertRedirect($newBook->getUrl());
$sortResp->assertStatus(302);
$this->assertDatabaseHas('chapters', [
- 'id' => $chapterToMove->id,
- 'book_id' => $newBook->id,
+ 'id' => $chapterToMove->id,
+ 'book_id' => $newBook->id,
'priority' => 0,
]);
$this->assertTrue($newBook->chapters()->count() === 1);
$otherChapter = Chapter::query()->where('book_id', '!=', $page->book_id)->first();
$sortData = [
- 'id' => $page->id,
- 'sort' => 0,
+ 'id' => $page->id,
+ 'sort' => 0,
'parentChapter' => $otherChapter->id,
- 'type' => 'page',
- 'book' => $page->book_id,
+ 'type' => 'page',
+ 'book' => $page->book_id,
];
$this->asEditor()->put($page->book->getUrl('/sort'), ['sort-tree' => json_encode([$sortData])])->assertRedirect();
$this->setEntityRestrictions($otherChapter);
$sortData = [
- 'id' => $page->id,
- 'sort' => 0,
+ 'id' => $page->id,
+ 'sort' => 0,
'parentChapter' => $otherChapter->id,
- 'type' => 'page',
- 'book' => $otherChapter->book_id,
+ 'type' => 'page',
+ 'book' => $otherChapter->book_id,
];
$this->asEditor()->put($page->book->getUrl('/sort'), ['sort-tree' => json_encode([$sortData])])->assertRedirect();
$this->setEntityRestrictions($otherChapter->book, ['update', 'delete'], [$editor->roles()->first()]);
$sortData = [
- 'id' => $page->id,
- 'sort' => 0,
+ 'id' => $page->id,
+ 'sort' => 0,
'parentChapter' => $otherChapter->id,
- 'type' => 'page',
- 'book' => $otherChapter->book_id,
+ 'type' => 'page',
+ 'book' => $otherChapter->book_id,
];
$this->actingAs($editor)->put($page->book->getUrl('/sort'), ['sort-tree' => json_encode([$sortData])])->assertRedirect();
$this->setEntityRestrictions($otherChapter, ['view', 'delete'], [$editor->roles()->first()]);
$sortData = [
- 'id' => $page->id,
- 'sort' => 0,
+ 'id' => $page->id,
+ 'sort' => 0,
'parentChapter' => $otherChapter->id,
- 'type' => 'page',
- 'book' => $otherChapter->book_id,
+ 'type' => 'page',
+ 'book' => $otherChapter->book_id,
];
$this->actingAs($editor)->put($page->book->getUrl('/sort'), ['sort-tree' => json_encode([$sortData])])->assertRedirect();
$this->setEntityRestrictions($page, ['view', 'delete'], [$editor->roles()->first()]);
$sortData = [
- 'id' => $page->id,
- 'sort' => 0,
+ 'id' => $page->id,
+ 'sort' => 0,
'parentChapter' => $otherChapter->id,
- 'type' => 'page',
- 'book' => $otherChapter->book_id,
+ 'type' => 'page',
+ 'book' => $otherChapter->book_id,
];
$this->actingAs($editor)->put($page->book->getUrl('/sort'), ['sort-tree' => json_encode([$sortData])])->assertRedirect();
$this->setEntityRestrictions($page, ['view', 'update'], [$editor->roles()->first()]);
$sortData = [
- 'id' => $page->id,
- 'sort' => 0,
+ 'id' => $page->id,
+ 'sort' => 0,
'parentChapter' => $otherChapter->id,
- 'type' => 'page',
- 'book' => $otherChapter->book_id,
+ 'type' => 'page',
+ 'book' => $otherChapter->book_id,
];
$this->actingAs($editor)->put($page->book->getUrl('/sort'), ['sort-tree' => json_encode([$sortData])])->assertRedirect();
]);
}
-
public function test_book_sort_item_returns_book_content()
{
$books = Book::all();