Skip to content

Commit a5d5904

Browse files
committed
Merge branch 'master' into release
2 parents 598758b + e3eefba commit a5d5904

File tree

86 files changed

+2650
-1437
lines changed

Some content is hidden

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

86 files changed

+2650
-1437
lines changed

.travis.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dist: trusty
2-
sudo: required
2+
sudo: false
33
language: php
44
php:
55
- 7.0
@@ -8,15 +8,11 @@ cache:
88
directories:
99
- $HOME/.composer/cache
1010

11-
addons:
12-
apt:
13-
packages:
14-
- mysql-server-5.6
15-
- mysql-client-core-5.6
16-
- mysql-client-5.6
17-
1811
before_script:
1912
- mysql -u root -e 'create database `bookstack-test`;'
13+
- mysql -u root -e "CREATE USER 'bookstack-test'@'localhost' IDENTIFIED BY 'bookstack-test';"
14+
- mysql -u root -e "GRANT ALL ON \`bookstack-test\`.* TO 'bookstack-test'@'localhost';"
15+
- mysql -u root -e "FLUSH PRIVILEGES;"
2016
- phpenv config-rm xdebug.ini
2117
- composer dump-autoload --no-interaction
2218
- composer install --prefer-dist --no-interaction
@@ -25,5 +21,8 @@ before_script:
2521
- php artisan migrate --force -n --database=mysql_testing
2622
- php artisan db:seed --force -n --class=DummyContentSeeder --database=mysql_testing
2723

24+
after_failure:
25+
- cat storage/logs/laravel.log
26+
2827
script:
2928
- phpunit
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace BookStack\Console\Commands;
4+
5+
use BookStack\Activity;
6+
use Illuminate\Console\Command;
7+
8+
class ClearActivity extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'bookstack:clear-activity';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Clear user activity from the system';
23+
24+
protected $activity;
25+
26+
/**
27+
* Create a new command instance.
28+
*
29+
* @param Activity $activity
30+
*/
31+
public function __construct(Activity $activity)
32+
{
33+
$this->activity = $activity;
34+
parent::__construct();
35+
}
36+
37+
/**
38+
* Execute the console command.
39+
*
40+
* @return mixed
41+
*/
42+
public function handle()
43+
{
44+
$this->activity->newQuery()->truncate();
45+
$this->comment('System activity cleared');
46+
}
47+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace BookStack\Console\Commands;
4+
5+
use BookStack\PageRevision;
6+
use Illuminate\Console\Command;
7+
8+
class ClearRevisions extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'bookstack:clear-revisions
16+
{--a|all : Include active update drafts in deletion}
17+
';
18+
19+
/**
20+
* The console command description.
21+
*
22+
* @var string
23+
*/
24+
protected $description = 'Clear page revisions';
25+
26+
protected $pageRevision;
27+
28+
/**
29+
* Create a new command instance.
30+
*
31+
* @param PageRevision $pageRevision
32+
*/
33+
public function __construct(PageRevision $pageRevision)
34+
{
35+
$this->pageRevision = $pageRevision;
36+
parent::__construct();
37+
}
38+
39+
/**
40+
* Execute the console command.
41+
*
42+
* @return mixed
43+
*/
44+
public function handle()
45+
{
46+
$deleteTypes = $this->option('all') ? ['version', 'update_draft'] : ['version'];
47+
$this->pageRevision->newQuery()->whereIn('type', $deleteTypes)->delete();
48+
$this->comment('Revisions deleted');
49+
}
50+
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44

55
use Illuminate\Console\Command;
66

7-
class ResetViews extends Command
7+
class ClearViews extends Command
88
{
99
/**
1010
* The name and signature of the console command.
1111
*
1212
* @var string
1313
*/
14-
protected $signature = 'views:reset';
14+
protected $signature = 'bookstack:clear-views';
1515

1616
/**
1717
* The console command description.
1818
*
1919
* @var string
2020
*/
21-
protected $description = 'Reset all view-counts for all entities.';
21+
protected $description = 'Clear all view-counts for all entities.';
2222

2323
/**
2424
* Create a new command instance.
@@ -37,5 +37,6 @@ public function __construct()
3737
public function handle()
3838
{
3939
\Views::resetAll();
40+
$this->comment('Views cleared');
4041
}
4142
}

app/Console/Commands/Inspire.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

app/Console/Commands/RegeneratePermissions.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class RegeneratePermissions extends Command
1212
*
1313
* @var string
1414
*/
15-
protected $signature = 'permissions:regen';
15+
protected $signature = 'bookstack:regenerate-permissions';
1616

1717
/**
1818
* The console command description.
@@ -47,5 +47,6 @@ public function __construct(PermissionService $permissionService)
4747
public function handle()
4848
{
4949
$this->permissionService->buildJointPermissions();
50+
$this->comment('Permissions regenerated');
5051
}
5152
}

app/Console/Kernel.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ class Kernel extends ConsoleKernel
1313
* @var array
1414
*/
1515
protected $commands = [
16-
\BookStack\Console\Commands\Inspire::class,
17-
\BookStack\Console\Commands\ResetViews::class,
16+
\BookStack\Console\Commands\ClearViews::class,
17+
\BookStack\Console\Commands\ClearActivity::class,
18+
\BookStack\Console\Commands\ClearRevisions::class,
1819
\BookStack\Console\Commands\RegeneratePermissions::class,
1920
];
2021

@@ -26,7 +27,6 @@ class Kernel extends ConsoleKernel
2627
*/
2728
protected function schedule(Schedule $schedule)
2829
{
29-
$schedule->command('inspire')
30-
->hourly();
30+
//
3131
}
3232
}

app/Exceptions/Handler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace BookStack\Exceptions;
44

55
use Exception;
6-
use Illuminate\Contracts\Validation\ValidationException;
6+
use Illuminate\Auth\AuthenticationException;
7+
use Illuminate\Validation\ValidationException;
78
use Illuminate\Database\Eloquent\ModelNotFoundException;
8-
use PhpSpec\Exception\Example\ErrorException;
99
use Symfony\Component\HttpKernel\Exception\HttpException;
1010
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
1111
use Illuminate\Auth\Access\AuthorizationException;

app/Http/Controllers/BookController.php

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use Activity;
44
use BookStack\Repos\EntityRepo;
55
use BookStack\Repos\UserRepo;
6+
use BookStack\Services\ExportService;
67
use Illuminate\Http\Request;
78
use Illuminate\Http\Response;
89
use Views;
@@ -12,16 +13,19 @@ class BookController extends Controller
1213

1314
protected $entityRepo;
1415
protected $userRepo;
16+
protected $exportService;
1517

1618
/**
1719
* BookController constructor.
1820
* @param EntityRepo $entityRepo
1921
* @param UserRepo $userRepo
22+
* @param ExportService $exportService
2023
*/
21-
public function __construct(EntityRepo $entityRepo, UserRepo $userRepo)
24+
public function __construct(EntityRepo $entityRepo, UserRepo $userRepo, ExportService $exportService)
2225
{
2326
$this->entityRepo = $entityRepo;
2427
$this->userRepo = $userRepo;
28+
$this->exportService = $exportService;
2529
parent::__construct();
2630
}
2731

@@ -258,4 +262,49 @@ public function restrict($bookSlug, Request $request)
258262
session()->flash('success', trans('entities.books_permissions_updated'));
259263
return redirect($book->getUrl());
260264
}
265+
266+
/**
267+
* Export a book as a PDF file.
268+
* @param string $bookSlug
269+
* @return mixed
270+
*/
271+
public function exportPdf($bookSlug)
272+
{
273+
$book = $this->entityRepo->getBySlug('book', $bookSlug);
274+
$pdfContent = $this->exportService->bookToPdf($book);
275+
return response()->make($pdfContent, 200, [
276+
'Content-Type' => 'application/octet-stream',
277+
'Content-Disposition' => 'attachment; filename="' . $bookSlug . '.pdf'
278+
]);
279+
}
280+
281+
/**
282+
* Export a book as a contained HTML file.
283+
* @param string $bookSlug
284+
* @return mixed
285+
*/
286+
public function exportHtml($bookSlug)
287+
{
288+
$book = $this->entityRepo->getBySlug('book', $bookSlug);
289+
$htmlContent = $this->exportService->bookToContainedHtml($book);
290+
return response()->make($htmlContent, 200, [
291+
'Content-Type' => 'application/octet-stream',
292+
'Content-Disposition' => 'attachment; filename="' . $bookSlug . '.html'
293+
]);
294+
}
295+
296+
/**
297+
* Export a book as a plain text file.
298+
* @param $bookSlug
299+
* @return mixed
300+
*/
301+
public function exportPlainText($bookSlug)
302+
{
303+
$book = $this->entityRepo->getBySlug('book', $bookSlug);
304+
$htmlContent = $this->exportService->bookToPlainText($book);
305+
return response()->make($htmlContent, 200, [
306+
'Content-Type' => 'application/octet-stream',
307+
'Content-Disposition' => 'attachment; filename="' . $bookSlug . '.txt'
308+
]);
309+
}
261310
}

0 commit comments

Comments
 (0)