Skip to content

Commit c0d2874

Browse files
committed
Merge branch 'development' into release
2 parents 5940a91 + 481f356 commit c0d2874

Some content is hidden

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

56 files changed

+738
-422
lines changed

.github/translators.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,3 +503,5 @@ Firr (FirrV) :: Russian
503503
João Faro (FaroJoaoFaro) :: Portuguese
504504
Danilo dos Santos Barbosa (bozochegou) :: Portuguese, Brazilian
505505
Chris (furesoft) :: German
506+
Silvia Isern (eiendragon) :: Catalan
507+
Dennis Kron Pedersen (ahjdp) :: Danish

app/Entities/Repos/BookshelfRepo.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,37 @@ public function update(Bookshelf $shelf, array $input, ?array $bookIds): Bookshe
5656

5757
/**
5858
* Update which books are assigned to this shelf by syncing the given book ids.
59-
* Function ensures the books are visible to the current user and existing.
59+
* Function ensures the managed books are visible to the current user and existing,
60+
* and that the user does not alter the assignment of books that are not visible to them.
6061
*/
61-
protected function updateBooks(Bookshelf $shelf, array $bookIds)
62+
protected function updateBooks(Bookshelf $shelf, array $bookIds): void
6263
{
6364
$numericIDs = collect($bookIds)->map(function ($id) {
6465
return intval($id);
6566
});
6667

67-
$syncData = $this->bookQueries->visibleForList()
68+
$existingBookIds = $shelf->books()->pluck('id')->toArray();
69+
$visibleExistingBookIds = $this->bookQueries->visibleForList()
70+
->whereIn('id', $existingBookIds)
71+
->pluck('id')
72+
->toArray();
73+
$nonVisibleExistingBookIds = array_values(array_diff($existingBookIds, $visibleExistingBookIds));
74+
75+
$newIdsToAssign = $this->bookQueries->visibleForList()
6876
->whereIn('id', $bookIds)
6977
->pluck('id')
70-
->mapWithKeys(function ($bookId) use ($numericIDs) {
71-
return [$bookId => ['order' => $numericIDs->search($bookId)]];
72-
});
78+
->toArray();
79+
80+
$maxNewIndex = max($numericIDs->keys()->toArray() ?: [0]);
81+
82+
$syncData = [];
83+
foreach ($newIdsToAssign as $id) {
84+
$syncData[$id] = ['order' => $numericIDs->search($id)];
85+
}
86+
87+
foreach ($nonVisibleExistingBookIds as $index => $id) {
88+
$syncData[$id] = ['order' => $maxNewIndex + ($index + 1)];
89+
}
7390

7491
$shelf->books()->sync($syncData);
7592
}

app/Exports/ZipExports/ZipExportBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected function build(): string
7676

7777
$zipFile = tempnam(sys_get_temp_dir(), 'bszip-');
7878
$zip = new ZipArchive();
79-
$opened = $zip->open($zipFile, ZipArchive::CREATE);
79+
$opened = $zip->open($zipFile, ZipArchive::OVERWRITE);
8080
if ($opened !== true) {
8181
throw new ZipExportException('Failed to create zip file for export.');
8282
}

app/Exports/ZipExports/ZipImportReferences.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ class ZipImportReferences
2929
/** @var Image[] */
3030
protected array $images = [];
3131

32-
/** @var array<string, Model> */
32+
/**
33+
* Mapping keyed by "type:old-reference-id" with values being the new imported equivalent model.
34+
* @var array<string, Model>
35+
*/
3336
protected array $referenceMap = [];
3437

3538
/** @var array<int, ZipExportPage> */
@@ -108,6 +111,22 @@ protected function handleReference(string $type, int $id): ?string
108111
return null;
109112
}
110113

114+
protected function replaceDrawingIdReferences(string $content): string
115+
{
116+
$referenceRegex = '/\sdrawio-diagram=[\'"](\d+)[\'"]/';
117+
118+
$result = preg_replace_callback($referenceRegex, function ($matches) {
119+
$key = 'image:' . $matches[1];
120+
$model = $this->referenceMap[$key] ?? null;
121+
if ($model instanceof Image && $model->type === 'drawio') {
122+
return ' drawio-diagram="' . $model->id . '"';
123+
}
124+
return $matches[0];
125+
}, $content);
126+
127+
return $result ?: $content;
128+
}
129+
111130
public function replaceReferences(): void
112131
{
113132
foreach ($this->books as $book) {
@@ -134,7 +153,9 @@ public function replaceReferences(): void
134153
$exportPage = $this->zipExportPageMap[$page->id];
135154
$contentType = $exportPage->markdown ? 'markdown' : 'html';
136155
$content = $exportPage->markdown ?: ($exportPage->html ?: '');
156+
137157
$parsed = $this->parser->parseReferences($content, $this->handleReference(...));
158+
$parsed = $this->replaceDrawingIdReferences($parsed);
138159

139160
$this->pageRepo->setContentFromInput($page, [
140161
$contentType => $parsed,

0 commit comments

Comments
 (0)