Skip to content

Commit

Permalink
Merge pull request #8 from BookStackApp/master
Browse files Browse the repository at this point in the history
Getting the latest changes.
  • Loading branch information
Abijeet authored Mar 25, 2017
2 parents 388f2f4 + cc0ce7c commit 4e71a5a
Show file tree
Hide file tree
Showing 108 changed files with 3,548 additions and 526 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@ _ide_helper.php
/storage/debugbar
.phpstorm.meta.php
yarn.lock
/bin
/bin
.buildpath

.project

.settings/org.eclipse.wst.common.project.facet.core.xml

.settings/org.eclipse.php.core.prefs
15 changes: 7 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dist: trusty
sudo: required
sudo: false
language: php
php:
- 7.0
Expand All @@ -8,15 +8,11 @@ cache:
directories:
- $HOME/.composer/cache

addons:
apt:
packages:
- mysql-server-5.6
- mysql-client-core-5.6
- mysql-client-5.6

before_script:
- mysql -u root -e 'create database `bookstack-test`;'
- mysql -u root -e "CREATE USER 'bookstack-test'@'localhost' IDENTIFIED BY 'bookstack-test';"
- mysql -u root -e "GRANT ALL ON \`bookstack-test\`.* TO 'bookstack-test'@'localhost';"
- mysql -u root -e "FLUSH PRIVILEGES;"
- phpenv config-rm xdebug.ini
- composer dump-autoload --no-interaction
- composer install --prefer-dist --no-interaction
Expand All @@ -25,5 +21,8 @@ before_script:
- php artisan migrate --force -n --database=mysql_testing
- php artisan db:seed --force -n --class=DummyContentSeeder --database=mysql_testing

after_failure:
- cat storage/logs/laravel.log

script:
- phpunit
47 changes: 47 additions & 0 deletions app/Console/Commands/ClearActivity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace BookStack\Console\Commands;

use BookStack\Activity;
use Illuminate\Console\Command;

class ClearActivity extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'bookstack:clear-activity';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Clear user activity from the system';

protected $activity;

/**
* Create a new command instance.
*
* @param Activity $activity
*/
public function __construct(Activity $activity)
{
$this->activity = $activity;
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->activity->newQuery()->truncate();
$this->comment('System activity cleared');
}
}
50 changes: 50 additions & 0 deletions app/Console/Commands/ClearRevisions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace BookStack\Console\Commands;

use BookStack\PageRevision;
use Illuminate\Console\Command;

class ClearRevisions extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'bookstack:clear-revisions
{--a|all : Include active update drafts in deletion}
';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Clear page revisions';

protected $pageRevision;

/**
* Create a new command instance.
*
* @param PageRevision $pageRevision
*/
public function __construct(PageRevision $pageRevision)
{
$this->pageRevision = $pageRevision;
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$deleteTypes = $this->option('all') ? ['version', 'update_draft'] : ['version'];
$this->pageRevision->newQuery()->whereIn('type', $deleteTypes)->delete();
$this->comment('Revisions deleted');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

use Illuminate\Console\Command;

class ResetViews extends Command
class ClearViews extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'views:reset';
protected $signature = 'bookstack:clear-views';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Reset all view-counts for all entities.';
protected $description = 'Clear all view-counts for all entities.';

/**
* Create a new command instance.
Expand All @@ -37,5 +37,6 @@ public function __construct()
public function handle()
{
\Views::resetAll();
$this->comment('Views cleared');
}
}
33 changes: 0 additions & 33 deletions app/Console/Commands/Inspire.php

This file was deleted.

3 changes: 2 additions & 1 deletion app/Console/Commands/RegeneratePermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class RegeneratePermissions extends Command
*
* @var string
*/
protected $signature = 'permissions:regen';
protected $signature = 'bookstack:regenerate-permissions';

/**
* The console command description.
Expand Down Expand Up @@ -47,5 +47,6 @@ public function __construct(PermissionService $permissionService)
public function handle()
{
$this->permissionService->buildJointPermissions();
$this->comment('Permissions regenerated');
}
}
8 changes: 4 additions & 4 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ class Kernel extends ConsoleKernel
* @var array
*/
protected $commands = [
\BookStack\Console\Commands\Inspire::class,
\BookStack\Console\Commands\ResetViews::class,
\BookStack\Console\Commands\ClearViews::class,
\BookStack\Console\Commands\ClearActivity::class,
\BookStack\Console\Commands\ClearRevisions::class,
\BookStack\Console\Commands\RegeneratePermissions::class,
];

Expand All @@ -26,7 +27,6 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('inspire')
->hourly();
//
}
}
51 changes: 50 additions & 1 deletion app/Http/Controllers/BookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Activity;
use BookStack\Repos\EntityRepo;
use BookStack\Repos\UserRepo;
use BookStack\Services\ExportService;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Views;
Expand All @@ -12,16 +13,19 @@ class BookController extends Controller

protected $entityRepo;
protected $userRepo;
protected $exportService;

/**
* BookController constructor.
* @param EntityRepo $entityRepo
* @param UserRepo $userRepo
* @param ExportService $exportService
*/
public function __construct(EntityRepo $entityRepo, UserRepo $userRepo)
public function __construct(EntityRepo $entityRepo, UserRepo $userRepo, ExportService $exportService)
{
$this->entityRepo = $entityRepo;
$this->userRepo = $userRepo;
$this->exportService = $exportService;
parent::__construct();
}

Expand Down Expand Up @@ -258,4 +262,49 @@ public function restrict($bookSlug, Request $request)
session()->flash('success', trans('entities.books_permissions_updated'));
return redirect($book->getUrl());
}

/**
* Export a book as a PDF file.
* @param string $bookSlug
* @return mixed
*/
public function exportPdf($bookSlug)
{
$book = $this->entityRepo->getBySlug('book', $bookSlug);
$pdfContent = $this->exportService->bookToPdf($book);
return response()->make($pdfContent, 200, [
'Content-Type' => 'application/octet-stream',
'Content-Disposition' => 'attachment; filename="' . $bookSlug . '.pdf'
]);
}

/**
* Export a book as a contained HTML file.
* @param string $bookSlug
* @return mixed
*/
public function exportHtml($bookSlug)
{
$book = $this->entityRepo->getBySlug('book', $bookSlug);
$htmlContent = $this->exportService->bookToContainedHtml($book);
return response()->make($htmlContent, 200, [
'Content-Type' => 'application/octet-stream',
'Content-Disposition' => 'attachment; filename="' . $bookSlug . '.html'
]);
}

/**
* Export a book as a plain text file.
* @param $bookSlug
* @return mixed
*/
public function exportPlainText($bookSlug)
{
$book = $this->entityRepo->getBySlug('book', $bookSlug);
$htmlContent = $this->exportService->bookToPlainText($book);
return response()->make($htmlContent, 200, [
'Content-Type' => 'application/octet-stream',
'Content-Disposition' => 'attachment; filename="' . $bookSlug . '.txt'
]);
}
}
Loading

0 comments on commit 4e71a5a

Please sign in to comment.