Skip to content

Commit b06147f

Browse files
committed
Merge branch 'development' into release
2 parents 841350a + 776ec7b commit b06147f

File tree

261 files changed

+3913
-2262
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

261 files changed

+3913
-2262
lines changed

.github/translators.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,3 +493,10 @@ Angel Pandey (angel-pandey) :: Nepali
493493
Supriya Shrestha (supriyashrestha) :: Nepali
494494
gprabhat :: Nepali
495495
CellCat :: Chinese Simplified
496+
Al Desrahim (aldesrahim) :: Indonesian
497+
ahmad abbaspour (deshneh.dar.diss) :: Persian
498+
Erjon K. (ekr) :: Albanian
499+
LiZerui (iamzrli) :: Chinese Traditional
500+
Ticker (ticker.com) :: Hebrew
501+
CrazyComputer :: Chinese Simplified
502+
Firr (FirrV) :: Russian

app/Activity/Models/Tag.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* @property int $id
1313
* @property string $name
1414
* @property string $value
15+
* @property int $entity_id
16+
* @property string $entity_type
1517
* @property int $order
1618
*/
1719
class Tag extends Model

app/Activity/Tools/TagClassGenerator.php

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
namespace BookStack\Activity\Tools;
44

55
use BookStack\Activity\Models\Tag;
6+
use BookStack\Entities\Models\BookChild;
7+
use BookStack\Entities\Models\Entity;
8+
use BookStack\Entities\Models\Page;
69

710
class TagClassGenerator
811
{
9-
protected array $tags;
10-
11-
/**
12-
* @param Tag[] $tags
13-
*/
14-
public function __construct(array $tags)
15-
{
16-
$this->tags = $tags;
12+
public function __construct(
13+
protected Entity $entity
14+
) {
1715
}
1816

1917
/**
@@ -22,14 +20,23 @@ public function __construct(array $tags)
2220
public function generate(): array
2321
{
2422
$classes = [];
23+
$tags = $this->entity->tags->all();
24+
25+
foreach ($tags as $tag) {
26+
array_push($classes, ...$this->generateClassesForTag($tag));
27+
}
28+
29+
if ($this->entity instanceof BookChild && userCan('view', $this->entity->book)) {
30+
$bookTags = $this->entity->book->tags;
31+
foreach ($bookTags as $bookTag) {
32+
array_push($classes, ...$this->generateClassesForTag($bookTag, 'book-'));
33+
}
34+
}
2535

26-
foreach ($this->tags as $tag) {
27-
$name = $this->normalizeTagClassString($tag->name);
28-
$value = $this->normalizeTagClassString($tag->value);
29-
$classes[] = 'tag-name-' . $name;
30-
if ($value) {
31-
$classes[] = 'tag-value-' . $value;
32-
$classes[] = 'tag-pair-' . $name . '-' . $value;
36+
if ($this->entity instanceof Page && $this->entity->chapter && userCan('view', $this->entity->chapter)) {
37+
$chapterTags = $this->entity->chapter->tags;
38+
foreach ($chapterTags as $chapterTag) {
39+
array_push($classes, ...$this->generateClassesForTag($chapterTag, 'chapter-'));
3340
}
3441
}
3542

@@ -41,6 +48,22 @@ public function generateAsString(): string
4148
return implode(' ', $this->generate());
4249
}
4350

51+
/**
52+
* @return string[]
53+
*/
54+
protected function generateClassesForTag(Tag $tag, string $prefix = ''): array
55+
{
56+
$classes = [];
57+
$name = $this->normalizeTagClassString($tag->name);
58+
$value = $this->normalizeTagClassString($tag->value);
59+
$classes[] = "{$prefix}tag-name-{$name}";
60+
if ($value) {
61+
$classes[] = "{$prefix}tag-value-{$value}";
62+
$classes[] = "{$prefix}tag-pair-{$name}-{$value}";
63+
}
64+
return $classes;
65+
}
66+
4467
protected function normalizeTagClassString(string $value): string
4568
{
4669
$value = str_replace(' ', '', strtolower($value));

app/Config/mail.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// Configured mail encryption method.
1212
// STARTTLS should still be attempted, but tls/ssl forces TLS usage.
1313
$mailEncryption = env('MAIL_ENCRYPTION', null);
14+
$mailPort = intval(env('MAIL_PORT', 587));
1415

1516
return [
1617

@@ -33,13 +34,13 @@
3334
'transport' => 'smtp',
3435
'scheme' => null,
3536
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
36-
'port' => env('MAIL_PORT', 587),
37+
'port' => $mailPort,
3738
'username' => env('MAIL_USERNAME'),
3839
'password' => env('MAIL_PASSWORD'),
3940
'verify_peer' => env('MAIL_VERIFY_SSL', true),
4041
'timeout' => null,
4142
'local_domain' => null,
42-
'tls_required' => ($mailEncryption === 'tls' || $mailEncryption === 'ssl'),
43+
'require_tls' => ($mailEncryption === 'tls' || $mailEncryption === 'ssl' || $mailPort === 465),
4344
],
4445

4546
'sendmail' => [

app/Entities/Controllers/BookController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use BookStack\Facades\Activity;
1919
use BookStack\Http\Controller;
2020
use BookStack\References\ReferenceFetcher;
21+
use BookStack\Util\DatabaseTransaction;
2122
use BookStack\Util\SimpleListOptions;
2223
use Illuminate\Http\Request;
2324
use Illuminate\Validation\ValidationException;
@@ -263,7 +264,9 @@ public function convertToShelf(HierarchyTransformer $transformer, string $bookSl
263264
$this->checkPermission('bookshelf-create-all');
264265
$this->checkPermission('book-create-all');
265266

266-
$shelf = $transformer->transformBookToShelf($book);
267+
$shelf = (new DatabaseTransaction(function () use ($book, $transformer) {
268+
return $transformer->transformBookToShelf($book);
269+
}))->run();
267270

268271
return redirect($shelf->getUrl());
269272
}

app/Entities/Controllers/ChapterApiController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
use BookStack\Exceptions\PermissionsException;
1010
use BookStack\Http\ApiController;
1111
use Exception;
12-
use Illuminate\Database\Eloquent\Relations\HasMany;
1312
use Illuminate\Http\Request;
1413

1514
class ChapterApiController extends ApiController
1615
{
17-
protected $rules = [
16+
protected array $rules = [
1817
'create' => [
1918
'book_id' => ['required', 'integer'],
2019
'name' => ['required', 'string', 'max:255'],

app/Entities/Controllers/ChapterController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use BookStack\Exceptions\PermissionsException;
1919
use BookStack\Http\Controller;
2020
use BookStack\References\ReferenceFetcher;
21+
use BookStack\Util\DatabaseTransaction;
2122
use Illuminate\Http\Request;
2223
use Illuminate\Validation\ValidationException;
2324
use Throwable;
@@ -269,7 +270,9 @@ public function convertToBook(HierarchyTransformer $transformer, string $bookSlu
269270
$this->checkOwnablePermission('chapter-delete', $chapter);
270271
$this->checkPermission('book-create-all');
271272

272-
$book = $transformer->transformChapterToBook($chapter);
273+
$book = (new DatabaseTransaction(function () use ($chapter, $transformer) {
274+
return $transformer->transformChapterToBook($chapter);
275+
}))->run();
273276

274277
return redirect($book->getUrl());
275278
}

app/Entities/Controllers/PageApiController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
class PageApiController extends ApiController
1414
{
15-
protected $rules = [
15+
protected array $rules = [
1616
'create' => [
1717
'book_id' => ['required_without:chapter_id', 'integer'],
1818
'chapter_id' => ['required_without:book_id', 'integer'],

app/Entities/Repos/BaseRepo.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ public function update(Entity $entity, array $input)
7777
$entity->touch();
7878
}
7979

80-
$entity->rebuildPermissions();
8180
$entity->indexForSearch();
8281
$this->referenceStore->updateForEntity($entity);
8382

@@ -139,7 +138,7 @@ public function updateDefaultTemplate(Book|Chapter $entity, int $templateId): vo
139138

140139
/**
141140
* Sort the parent of the given entity, if any auto sort actions are set for it.
142-
* Typical ran during create/update/insert events.
141+
* Typically ran during create/update/insert events.
143142
*/
144143
public function sortParent(Entity $entity): void
145144
{

app/Entities/Repos/BookRepo.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use BookStack\Facades\Activity;
1111
use BookStack\Sorting\SortRule;
1212
use BookStack\Uploads\ImageRepo;
13+
use BookStack\Util\DatabaseTransaction;
1314
use Exception;
1415
use Illuminate\Http\UploadedFile;
1516

@@ -28,19 +29,22 @@ public function __construct(
2829
*/
2930
public function create(array $input): Book
3031
{
31-
$book = new Book();
32-
$this->baseRepo->create($book, $input);
33-
$this->baseRepo->updateCoverImage($book, $input['image'] ?? null);
34-
$this->baseRepo->updateDefaultTemplate($book, intval($input['default_template_id'] ?? null));
35-
Activity::add(ActivityType::BOOK_CREATE, $book);
32+
return (new DatabaseTransaction(function () use ($input) {
33+
$book = new Book();
3634

37-
$defaultBookSortSetting = intval(setting('sorting-book-default', '0'));
38-
if ($defaultBookSortSetting && SortRule::query()->find($defaultBookSortSetting)) {
39-
$book->sort_rule_id = $defaultBookSortSetting;
40-
$book->save();
41-
}
35+
$this->baseRepo->create($book, $input);
36+
$this->baseRepo->updateCoverImage($book, $input['image'] ?? null);
37+
$this->baseRepo->updateDefaultTemplate($book, intval($input['default_template_id'] ?? null));
38+
Activity::add(ActivityType::BOOK_CREATE, $book);
4239

43-
return $book;
40+
$defaultBookSortSetting = intval(setting('sorting-book-default', '0'));
41+
if ($defaultBookSortSetting && SortRule::query()->find($defaultBookSortSetting)) {
42+
$book->sort_rule_id = $defaultBookSortSetting;
43+
$book->save();
44+
}
45+
46+
return $book;
47+
}))->run();
4448
}
4549

4650
/**

0 commit comments

Comments
 (0)