Skip to content

Commit 7caed3b

Browse files
committed
Merge branch 'master' into release
2 parents 45641d0 + 11960d9 commit 7caed3b

Some content is hidden

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

44 files changed

+951
-330
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
### For Feature Requests
2+
Desired Feature:
3+
4+
### For Bug Reports
5+
PHP Version:
6+
7+
MySQL Version:
8+
9+
Expected Behavior:
10+
11+
Actual Behavior:

.travis.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ php:
66

77
cache:
88
directories:
9-
- vendor
10-
- node_modules
119
- $HOME/.composer/cache
1210

1311
addons:
@@ -17,19 +15,17 @@ addons:
1715
- mysql-client-core-5.6
1816
- mysql-client-5.6
1917

20-
before_install:
21-
- npm install -g npm@latest
22-
2318
before_script:
2419
- mysql -u root -e 'create database `bookstack-test`;'
2520
- composer config -g github-oauth.github.com $GITHUB_ACCESS_TOKEN
2621
- phpenv config-rm xdebug.ini
2722
- composer self-update
23+
- composer dump-autoload --no-interaction
2824
- composer install --prefer-dist --no-interaction
29-
- npm install
30-
- ./node_modules/.bin/gulp
25+
- php artisan clear-compiled -n
26+
- php artisan optimize -n
3127
- php artisan migrate --force -n --database=mysql_testing
3228
- php artisan db:seed --force -n --class=DummyContentSeeder --database=mysql_testing
3329

3430
script:
35-
- vendor/bin/phpunit
31+
- phpunit

app/Entity.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ public function fullTextSearchQuery($fieldsToSearch, $terms, $wheres = [])
167167
foreach ($terms as $key => $term) {
168168
$term = htmlentities($term, ENT_QUOTES);
169169
$term = preg_replace('/[+\-><\(\)~*\"@]+/', ' ', $term);
170-
if (preg_match('/\s/', $term)) {
170+
if (preg_match('/&quot;.*?&quot;/', $term)) {
171+
$term = str_replace('&quot;', '', $term);
171172
$exactTerms[] = '%' . $term . '%';
172173
$term = '"' . $term . '"';
173174
} else {
@@ -206,5 +207,5 @@ public function fullTextSearchQuery($fieldsToSearch, $terms, $wheres = [])
206207

207208
return $search->orderBy($orderBy, 'desc');
208209
}
209-
210+
210211
}

app/Exceptions/Handler.php

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,44 @@ public function render($request, Exception $e)
4747
{
4848
// Handle notify exceptions which will redirect to the
4949
// specified location then show a notification message.
50-
if ($e instanceof NotifyException) {
51-
session()->flash('error', $e->message);
50+
if ($this->isExceptionType($e, NotifyException::class)) {
51+
session()->flash('error', $this->getOriginalMessage($e));
5252
return redirect($e->redirectLocation);
5353
}
5454

5555
// Handle pretty exceptions which will show a friendly application-fitting page
5656
// Which will include the basic message to point the user roughly to the cause.
57-
if (($e instanceof PrettyException || $e->getPrevious() instanceof PrettyException) && !config('app.debug')) {
58-
$message = ($e instanceof PrettyException) ? $e->getMessage() : $e->getPrevious()->getMessage();
57+
if ($this->isExceptionType($e, PrettyException::class) && !config('app.debug')) {
58+
$message = $this->getOriginalMessage($e);
5959
$code = ($e->getCode() === 0) ? 500 : $e->getCode();
6060
return response()->view('errors/' . $code, ['message' => $message], $code);
6161
}
6262

6363
return parent::render($request, $e);
6464
}
65+
66+
/**
67+
* Check the exception chain to compare against the original exception type.
68+
* @param Exception $e
69+
* @param $type
70+
* @return bool
71+
*/
72+
protected function isExceptionType(Exception $e, $type) {
73+
do {
74+
if (is_a($e, $type)) return true;
75+
} while ($e = $e->getPrevious());
76+
return false;
77+
}
78+
79+
/**
80+
* Get original exception message.
81+
* @param Exception $e
82+
* @return string
83+
*/
84+
protected function getOriginalMessage(Exception $e) {
85+
do {
86+
$message = $e->getMessage();
87+
} while ($e = $e->getPrevious());
88+
return $message;
89+
}
6590
}

app/Exceptions/PrettyException.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
<?php namespace BookStack\Exceptions;
22

3-
use Exception;
4-
5-
class PrettyException extends Exception {}
3+
class PrettyException extends \Exception {}

app/Http/Controllers/BookController.php

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use Activity;
44
use BookStack\Repos\UserRepo;
55
use Illuminate\Http\Request;
6-
use Illuminate\Support\Facades\Auth;
76
use BookStack\Http\Requests;
87
use BookStack\Repos\BookRepo;
98
use BookStack\Repos\ChapterRepo;
@@ -180,21 +179,31 @@ public function saveSort($bookSlug, Request $request)
180179
return redirect($book->getUrl());
181180
}
182181

183-
$sortedBooks = [];
184182
// Sort pages and chapters
183+
$sortedBooks = [];
184+
$updatedModels = collect();
185185
$sortMap = json_decode($request->get('sort-tree'));
186186
$defaultBookId = $book->id;
187-
foreach ($sortMap as $index => $bookChild) {
188-
$id = $bookChild->id;
187+
188+
// Loop through contents of provided map and update entities accordingly
189+
foreach ($sortMap as $bookChild) {
190+
$priority = $bookChild->sort;
191+
$id = intval($bookChild->id);
189192
$isPage = $bookChild->type == 'page';
190-
$bookId = $this->bookRepo->exists($bookChild->book) ? $bookChild->book : $defaultBookId;
193+
$bookId = $this->bookRepo->exists($bookChild->book) ? intval($bookChild->book) : $defaultBookId;
194+
$chapterId = ($isPage && $bookChild->parentChapter === false) ? 0 : intval($bookChild->parentChapter);
191195
$model = $isPage ? $this->pageRepo->getById($id) : $this->chapterRepo->getById($id);
192-
$isPage ? $this->pageRepo->changeBook($bookId, $model) : $this->chapterRepo->changeBook($bookId, $model);
193-
$model->priority = $index;
194-
if ($isPage) {
195-
$model->chapter_id = ($bookChild->parentChapter === false) ? 0 : $bookChild->parentChapter;
196+
197+
// Update models only if there's a change in parent chain or ordering.
198+
if ($model->priority !== $priority || $model->book_id !== $bookId || ($isPage && $model->chapter_id !== $chapterId)) {
199+
$isPage ? $this->pageRepo->changeBook($bookId, $model) : $this->chapterRepo->changeBook($bookId, $model);
200+
$model->priority = $priority;
201+
if ($isPage) $model->chapter_id = $chapterId;
202+
$model->save();
203+
$updatedModels->push($model);
196204
}
197-
$model->save();
205+
206+
// Store involved books to be sorted later
198207
if (!in_array($bookId, $sortedBooks)) {
199208
$sortedBooks[] = $bookId;
200209
}
@@ -203,10 +212,12 @@ public function saveSort($bookSlug, Request $request)
203212
// Add activity for books
204213
foreach ($sortedBooks as $bookId) {
205214
$updatedBook = $this->bookRepo->getById($bookId);
206-
$this->bookRepo->updateBookPermissions($updatedBook);
207215
Activity::add($updatedBook, 'book_sort', $updatedBook->id);
208216
}
209217

218+
// Update permissions on changed models
219+
$this->bookRepo->buildJointPermissions($updatedModels);
220+
210221
return redirect($book->getUrl());
211222
}
212223

app/Http/Controllers/ChapterController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function move($bookSlug, $chapterSlug, Request $request) {
204204
return redirect()->back();
205205
}
206206

207-
$this->chapterRepo->changeBook($parent->id, $chapter);
207+
$this->chapterRepo->changeBook($parent->id, $chapter, true);
208208
Activity::add($chapter, 'chapter_move', $chapter->book->id);
209209
session()->flash('success', sprintf('Chapter moved to "%s"', $parent->name));
210210

app/PageRevision.php

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

44
class PageRevision extends Model
55
{
6-
protected $fillable = ['name', 'html', 'text', 'markdown'];
6+
protected $fillable = ['name', 'html', 'text', 'markdown', 'summary'];
77

88
/**
99
* Get the user that created the page revision

app/Providers/AppServiceProvider.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
<?php
1+
<?php namespace BookStack\Providers;
22

3-
namespace BookStack\Providers;
4-
5-
use Illuminate\Support\Facades\Auth;
63
use Illuminate\Support\ServiceProvider;
7-
use BookStack\User;
84

95
class AppServiceProvider extends ServiceProvider
106
{

app/Repos/BookRepo.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use Alpha\B;
44
use BookStack\Exceptions\NotFoundException;
5+
use Illuminate\Database\Eloquent\Collection;
56
use Illuminate\Support\Str;
67
use BookStack\Book;
78
use Views;
@@ -173,15 +174,6 @@ public function destroy(Book $book)
173174
$book->delete();
174175
}
175176

176-
/**
177-
* Alias method to update the book jointPermissions in the PermissionService.
178-
* @param Book $book
179-
*/
180-
public function updateBookPermissions(Book $book)
181-
{
182-
$this->permissionService->buildJointPermissionsForEntity($book);
183-
}
184-
185177
/**
186178
* Get the next child element priority.
187179
* @param Book $book

0 commit comments

Comments
 (0)