Skip to content

Commit a4c9a84

Browse files
committed
Merge branch 'master' into release
2 parents 70ee636 + 2704962 commit a4c9a84

File tree

11 files changed

+141
-56
lines changed

11 files changed

+141
-56
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace BookStack\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\DB;
7+
8+
class UpgradeDatabaseEncoding extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'bookstack:db-utf8mb4 {--database= : The database connection to use.}';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Generate SQL commands to upgrade the database to UTF8mb4';
23+
24+
/**
25+
* Create a new command instance.
26+
*
27+
*/
28+
public function __construct()
29+
{
30+
parent::__construct();
31+
}
32+
33+
/**
34+
* Execute the console command.
35+
*
36+
* @return mixed
37+
*/
38+
public function handle()
39+
{
40+
$connection = DB::getDefaultConnection();
41+
if ($this->option('database') !== null) {
42+
DB::setDefaultConnection($this->option('database'));
43+
}
44+
45+
$database = DB::getDatabaseName();
46+
$tables = DB::select('SHOW TABLES');
47+
$this->line('ALTER DATABASE `'.$database.'` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;');
48+
$this->line('USE `'.$database.'`;');
49+
$key = 'Tables_in_' . $database;
50+
foreach ($tables as $table) {
51+
$tableName = $table->$key;
52+
$this->line('ALTER TABLE `'.$tableName.'` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;');
53+
}
54+
55+
DB::setDefaultConnection($connection);
56+
}
57+
}

app/Console/Kernel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ class Kernel extends ConsoleKernel
1515
Commands\ClearActivity::class,
1616
Commands\ClearRevisions::class,
1717
Commands\RegeneratePermissions::class,
18-
Commands\RegenerateSearch::class
18+
Commands\RegenerateSearch::class,
19+
Commands\UpgradeDatabaseEncoding::class
1920
];
2021

2122
/**

app/Repos/EntityRepo.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ public function publishPageDraft(Page $draftPage, array $input)
571571

572572
$draftPage->slug = $this->findSuitableSlug('page', $draftPage->name, false, $draftPage->book->id);
573573
$draftPage->html = $this->formatHtml($input['html']);
574-
$draftPage->text = strip_tags($draftPage->html);
574+
$draftPage->text = $this->pageToPlainText($draftPage->html);
575575
$draftPage->draft = false;
576576
$draftPage->revision_count = 1;
577577

@@ -713,6 +713,17 @@ public function renderPage(Page $page)
713713
return $content;
714714
}
715715

716+
/**
717+
* Get the plain text version of a page's content.
718+
* @param Page $page
719+
* @return string
720+
*/
721+
public function pageToPlainText(Page $page)
722+
{
723+
$html = $this->renderPage($page);
724+
return strip_tags($html);
725+
}
726+
716727
/**
717728
* Get a new draft page instance.
718729
* @param Book $book
@@ -816,7 +827,7 @@ public function updatePage(Page $page, $book_id, $input)
816827
$userId = user()->id;
817828
$page->fill($input);
818829
$page->html = $this->formatHtml($input['html']);
819-
$page->text = strip_tags($page->html);
830+
$page->text = $this->pageToPlainText($page);
820831
if (setting('app-editor') !== 'markdown') $page->markdown = '';
821832
$page->updated_by = $userId;
822833
$page->revision_count++;
@@ -933,7 +944,7 @@ public function restorePageRevision(Page $page, Book $book, $revisionId)
933944
$revision = $page->revisions()->where('id', '=', $revisionId)->first();
934945
$page->fill($revision->toArray());
935946
$page->slug = $this->findSuitableSlug('page', $page->name, $page->id, $book->id);
936-
$page->text = strip_tags($page->html);
947+
$page->text = $this->pageToPlainText($page->html);
937948
$page->updated_by = user()->id;
938949
$page->save();
939950
$this->searchService->indexEntity($page);
@@ -953,7 +964,7 @@ public function updatePageDraft(Page $page, $data = [])
953964
if ($page->draft) {
954965
$page->fill($data);
955966
if (isset($data['html'])) {
956-
$page->text = strip_tags($data['html']);
967+
$page->text = $this->pageToPlainText($data['html']);
957968
}
958969
$page->save();
959970
return $page;
Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
use Illuminate\Support\Facades\Schema;
4-
use Illuminate\Database\Schema\Blueprint;
53
use Illuminate\Database\Migrations\Migration;
64

75
class UpdateDbEncodingToUt8mb4 extends Migration
@@ -13,16 +11,9 @@ class UpdateDbEncodingToUt8mb4 extends Migration
1311
*/
1412
public function up()
1513
{
16-
$database = DB::getDatabaseName();
17-
$tables = DB::select('SHOW TABLES');
18-
$pdo = DB::getPdo();
19-
$pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
20-
$pdo->exec('ALTER DATABASE `'.$database.'` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
21-
$key = 'Tables_in_' . $database;
22-
foreach ($tables as $table) {
23-
$tableName = $table->$key;
24-
$pdo->exec('ALTER TABLE `'.$tableName.'` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci');
25-
}
14+
// Migration removed due to issues during live migration.
15+
// Instead you can run the command `artisan bookstack:db-utf8mb4`
16+
// which will generate out the SQL request to upgrade your DB to utf8mb4.
2617
}
2718

2819
/**
@@ -32,15 +23,6 @@ public function up()
3223
*/
3324
public function down()
3425
{
35-
$database = DB::getDatabaseName();
36-
$tables = DB::select('SHOW TABLES');
37-
$pdo = DB::getPdo();
38-
$pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
39-
$pdo->exec('ALTER DATABASE `'.$database.'` CHARACTER SET utf8 COLLATE utf8_unicode_ci');
40-
$key = 'Tables_in_' . $database;
41-
foreach ($tables as $table) {
42-
$tableName = $table->$key;
43-
$pdo->exec('ALTER TABLE `'.$tableName.'` CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci');
44-
}
26+
//
4527
}
4628
}

resources/assets/js/controllers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ module.exports = function (ngApp, events) {
379379
*/
380380
$scope.discardDraft = function () {
381381
let url = window.baseUrl('/ajax/page/' + pageId);
382-
$http.get(url).then((responseData) => {
382+
$http.get(url).then(responseData => {
383383
if (autoSave) $interval.cancel(autoSave);
384384
$scope.draftText = trans('entities.pages_editing_page');
385385
$scope.isUpdateDraft = false;

resources/assets/js/directives.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -123,25 +123,31 @@ module.exports = function (ngApp, events) {
123123
restrict: 'A',
124124
link: function (scope, element, attrs) {
125125
const menu = element.find('ul');
126-
element.find('[dropdown-toggle]').on('click', function () {
126+
127+
function hide() {
128+
menu.hide();
129+
menu.removeClass('anim menuIn');
130+
}
131+
132+
function show() {
127133
menu.show().addClass('anim menuIn');
134+
element.mouseleave(hide);
135+
136+
// Focus on input if exist in dropdown and hide on enter press
128137
let inputs = menu.find('input');
129-
let hasInput = inputs.length > 0;
130-
if (hasInput) {
131-
inputs.first().focus();
132-
element.on('keypress', 'input', event => {
133-
if (event.keyCode === 13) {
134-
event.preventDefault();
135-
menu.hide();
136-
menu.removeClass('anim menuIn');
137-
return false;
138-
}
139-
});
140-
}
141-
element.mouseleave(function () {
142-
menu.hide();
143-
menu.removeClass('anim menuIn');
144-
});
138+
if (inputs.length > 0) inputs.first().focus();
139+
}
140+
141+
// Hide menu on option click
142+
element.on('click', '> ul a', hide);
143+
// Show dropdown on toggle click.
144+
element.find('[dropdown-toggle]').on('click', show);
145+
// Hide menu on enter press in inputs
146+
element.on('keypress', 'input', event => {
147+
if (event.keyCode !== 13) return true;
148+
event.preventDefault();
149+
hide();
150+
return false;
145151
});
146152
}
147153
};

resources/assets/sass/_header.scss

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ form.search-box {
142142
color: #aaa;
143143
padding: 0 $-xs;
144144
}
145-
146145
.faded {
147146
a, button, span, span > div {
148147
color: #666;
@@ -178,6 +177,8 @@ form.search-box {
178177
padding-left: 0;
179178
}
180179
}
180+
181+
181182
.action-buttons .dropdown-container:last-child a {
182183
padding-right: 0;
183184
padding-left: $-s;
@@ -196,6 +197,25 @@ form.search-box {
196197
}
197198
}
198199

200+
@include smaller-than($m) {
201+
.breadcrumbs .text-button, .action-buttons .text-button {
202+
padding: $-s $-xs;
203+
}
204+
.action-buttons .dropdown-container:last-child a {
205+
padding-left: $-xs;
206+
}
207+
.breadcrumbs .text-button {
208+
font-size: 0;
209+
}
210+
.breadcrumbs a i {
211+
font-size: $fs-m;
212+
padding-right: 0;
213+
}
214+
.breadcrumbs span.sep {
215+
padding: 0 $-xxs;
216+
}
217+
}
218+
199219
.nav-tabs {
200220
text-align: center;
201221
a, .tab-item {

resources/assets/sass/_text.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ pre {
152152
}
153153
}
154154

155+
@media print {
156+
pre {
157+
padding-left: 12px;
158+
}
159+
pre:after {
160+
display: none;
161+
}
162+
}
155163

156164
blockquote {
157165
display: block;

resources/views/books/show.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
<div class="faded-small toolbar">
66
<div class="container">
77
<div class="row">
8-
<div class="col-sm-6 faded">
8+
<div class="col-sm-6 col-xs-1 faded">
99
@include('books._breadcrumbs', ['book' => $book])
1010
</div>
11-
<div class="col-sm-6">
11+
<div class="col-sm-6 col-xs-11">
1212
<div class="action-buttons faded">
1313
<span dropdown class="dropdown-container">
1414
<div dropdown-toggle class="text-button text-primary"><i class="zmdi zmdi-open-in-new"></i>{{ trans('entities.export') }}</div>
@@ -50,7 +50,7 @@
5050
</div>
5151

5252

53-
<div class="container" id="entity-dashboard" entity-id="{{ $book->id }}" entity-type="book">
53+
<div ng-non-bindable class="container" id="entity-dashboard" entity-id="{{ $book->id }}" entity-type="book">
5454
<div class="row">
5555
<div class="col-md-7">
5656

@@ -112,7 +112,7 @@
112112
@endif
113113

114114
<div class="search-box">
115-
<form v-on:submit="searchBook">
115+
<form v-on:submit.prevent="searchBook">
116116
<input v-model="searchTerm" v-on:change="checkSearchForm()" type="text" name="term" placeholder="{{ trans('entities.books_search_this') }}">
117117
<button type="submit"><i class="zmdi zmdi-search"></i></button>
118118
<button v-if="searching" v-cloak class="text-neg" v-on:click="clearSearch()" type="button"><i class="zmdi zmdi-close"></i></button>

resources/views/chapters/show.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
<div class="faded-small toolbar">
66
<div class="container">
77
<div class="row">
8-
<div class="col-sm-8 faded" ng-non-bindable>
8+
<div class="col-sm-6 col-xs-3 faded" ng-non-bindable>
99
@include('chapters._breadcrumbs', ['chapter' => $chapter])
1010
</div>
11-
<div class="col-sm-4 faded">
11+
<div class="col-sm-6 col-xs-9 faded">
1212
<div class="action-buttons">
1313
<span dropdown class="dropdown-container">
1414
<div dropdown-toggle class="text-button text-primary"><i class="zmdi zmdi-open-in-new"></i>{{ trans('entities.export') }}</div>
@@ -47,7 +47,7 @@
4747
</div>
4848

4949

50-
<div class="container" id="entity-dashboard" entity-id="{{ $chapter->id }}" entity-type="chapter">
50+
<div class="container" id="entity-dashboard" ng-non-bindable entity-id="{{ $chapter->id }}" entity-type="chapter">
5151
<div class="row">
5252
<div class="col-md-7">
5353
<h1>{{ $chapter->name }}</h1>
@@ -116,7 +116,7 @@
116116
@endif
117117

118118
<div class="search-box">
119-
<form v-on:submit="searchBook">
119+
<form v-on:submit.prevent="searchBook">
120120
<input v-model="searchTerm" v-on:change="checkSearchForm()" type="text" name="term" placeholder="{{ trans('entities.chapters_search_this') }}">
121121
<button type="submit"><i class="zmdi zmdi-search"></i></button>
122122
<button v-if="searching" v-cloak class="text-neg" v-on:click="clearSearch()" type="button"><i class="zmdi zmdi-close"></i></button>

0 commit comments

Comments
 (0)