Skip to content

Commit fdbbcf2

Browse files
committed
Merge branch 'portazips' into development
2 parents 0a07b0d + bdca9fc commit fdbbcf2

File tree

84 files changed

+5269
-717
lines changed

Some content is hidden

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

84 files changed

+5269
-717
lines changed

app/Activity/ActivityType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ class ActivityType
6767
const WEBHOOK_UPDATE = 'webhook_update';
6868
const WEBHOOK_DELETE = 'webhook_delete';
6969

70+
const IMPORT_CREATE = 'import_create';
71+
const IMPORT_RUN = 'import_run';
72+
const IMPORT_DELETE = 'import_delete';
73+
7074
/**
7175
* Get all the possible values.
7276
*/

app/Entities/Models/Chapter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function defaultTemplate(): BelongsTo
6060

6161
/**
6262
* Get the visible pages in this chapter.
63+
* @returns Collection<Page>
6364
*/
6465
public function getVisiblePages(): Collection
6566
{

app/Entities/Repos/PageRepo.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ public function publishDraft(Page $draft, array $input): Page
8787
return $draft;
8888
}
8989

90+
/**
91+
* Directly update the content for the given page from the provided input.
92+
* Used for direct content access in a way that performs required changes
93+
* (Search index & reference regen) without performing an official update.
94+
*/
95+
public function setContentFromInput(Page $page, array $input): void
96+
{
97+
$this->updateTemplateStatusAndContentFromInput($page, $input);
98+
$this->baseRepo->update($page, []);
99+
}
100+
90101
/**
91102
* Update a page in the system.
92103
*/
@@ -121,7 +132,7 @@ public function update(Page $page, array $input): Page
121132
return $page;
122133
}
123134

124-
protected function updateTemplateStatusAndContentFromInput(Page $page, array $input)
135+
protected function updateTemplateStatusAndContentFromInput(Page $page, array $input): void
125136
{
126137
if (isset($input['template']) && userCan('templates-manage')) {
127138
$page->template = ($input['template'] === 'true');

app/Entities/Tools/Cloner.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,12 @@
1818

1919
class Cloner
2020
{
21-
protected PageRepo $pageRepo;
22-
protected ChapterRepo $chapterRepo;
23-
protected BookRepo $bookRepo;
24-
protected ImageService $imageService;
25-
26-
public function __construct(PageRepo $pageRepo, ChapterRepo $chapterRepo, BookRepo $bookRepo, ImageService $imageService)
27-
{
28-
$this->pageRepo = $pageRepo;
29-
$this->chapterRepo = $chapterRepo;
30-
$this->bookRepo = $bookRepo;
31-
$this->imageService = $imageService;
21+
public function __construct(
22+
protected PageRepo $pageRepo,
23+
protected ChapterRepo $chapterRepo,
24+
protected BookRepo $bookRepo,
25+
protected ImageService $imageService,
26+
) {
3227
}
3328

3429
/**

app/Exceptions/ZipExportException.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace BookStack\Exceptions;
4+
5+
class ZipExportException extends \Exception
6+
{
7+
}

app/Exceptions/ZipImportException.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace BookStack\Exceptions;
4+
5+
class ZipImportException extends \Exception
6+
{
7+
public function __construct(
8+
public array $errors
9+
) {
10+
$message = "Import failed with errors:" . implode("\n", $this->errors);
11+
parent::__construct($message);
12+
}
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace BookStack\Exceptions;
4+
5+
class ZipValidationException extends \Exception
6+
{
7+
public function __construct(
8+
public array $errors
9+
) {
10+
parent::__construct();
11+
}
12+
}

app/Entities/Controllers/BookExportApiController.php renamed to app/Exports/Controllers/BookExportApiController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
namespace BookStack\Entities\Controllers;
3+
namespace BookStack\Exports\Controllers;
44

55
use BookStack\Entities\Queries\BookQueries;
6-
use BookStack\Entities\Tools\ExportFormatter;
6+
use BookStack\Exports\ExportFormatter;
77
use BookStack\Http\ApiController;
88
use Throwable;
99

app/Entities/Controllers/BookExportController.php renamed to app/Exports/Controllers/BookExportController.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<?php
22

3-
namespace BookStack\Entities\Controllers;
3+
namespace BookStack\Exports\Controllers;
44

55
use BookStack\Entities\Queries\BookQueries;
6-
use BookStack\Entities\Tools\ExportFormatter;
6+
use BookStack\Exceptions\NotFoundException;
7+
use BookStack\Exports\ExportFormatter;
8+
use BookStack\Exports\ZipExports\ZipExportBuilder;
79
use BookStack\Http\Controller;
810
use Throwable;
911

@@ -63,4 +65,16 @@ public function markdown(string $bookSlug)
6365

6466
return $this->download()->directly($textContent, $bookSlug . '.md');
6567
}
68+
69+
/**
70+
* Export a book to a contained ZIP export file.
71+
* @throws NotFoundException
72+
*/
73+
public function zip(string $bookSlug, ZipExportBuilder $builder)
74+
{
75+
$book = $this->queries->findVisibleBySlugOrFail($bookSlug);
76+
$zip = $builder->buildForBook($book);
77+
78+
return $this->download()->streamedDirectly(fopen($zip, 'r'), $bookSlug . '.zip', filesize($zip));
79+
}
6680
}

app/Entities/Controllers/ChapterExportApiController.php renamed to app/Exports/Controllers/ChapterExportApiController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
namespace BookStack\Entities\Controllers;
3+
namespace BookStack\Exports\Controllers;
44

55
use BookStack\Entities\Queries\ChapterQueries;
6-
use BookStack\Entities\Tools\ExportFormatter;
6+
use BookStack\Exports\ExportFormatter;
77
use BookStack\Http\ApiController;
88
use Throwable;
99

0 commit comments

Comments
 (0)