use BookStack\Entities\Queries\EntityQueries;
use BookStack\Entities\Tools\BookContents;
use BookStack\Entities\Tools\PageContent;
-use BookStack\Entities\Tools\PageEditorData;
use BookStack\Entities\Tools\PageEditorType;
use BookStack\Entities\Tools\TrashCan;
use BookStack\Exceptions\MoveOperationException;
'owned_by' => user()->id,
'updated_by' => user()->id,
'draft' => true,
+ 'editor' => PageEditorType::getSystemDefault()->value,
]);
if ($parent instanceof Chapter) {
$pageContent->setNewHTML($input['html'], user());
}
- if ($newEditor !== $currentEditor && userCan('editor-change')) {
+ if (($newEditor !== $currentEditor || empty($page->editor)) && userCan('editor-change')) {
$page->editor = $newEditor->value;
+ } elseif (empty($page->editor)) {
+ $page->editor = $defaultEditor->value;
}
}
--- /dev/null
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Support\Facades\DB;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ */
+ public function up(): void
+ {
+ // Ensure we have an "editor" value set for pages
+
+ // Get default
+ $default = DB::table('settings')
+ ->where('setting_key', '=', 'app-editor')
+ ->first()
+ ->value ?? 'wysiwyg';
+ $default = ($default === 'markdown') ? 'markdown' : 'wysiwyg';
+
+ // We set it to 'markdown' for pages currently with markdown content
+ DB::table('pages')
+ ->where('editor', '=', '')
+ ->where('markdown', '!=', '')
+ ->update(['editor' => 'markdown']);
+
+ // We set it to 'wysiwyg' where we have HTML but no markdown
+ DB::table('pages')
+ ->where('editor', '=', '')
+ ->where('markdown', '=', '')
+ ->where('html', '!=', '')
+ ->update(['editor' => 'wysiwyg']);
+
+ // Otherwise, where still empty, set to the current default
+ DB::table('pages')
+ ->where('editor', '=', '')
+ ->update(['editor' => $default]);
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ // Can't reverse due to not knowing what would have been empty before
+ }
+};
$this->withHtml($this->followRedirects($resp))->assertElementExists('#html-editor');
}
+ public function test_editor_set_for_new_pages()
+ {
+ $book = $this->page->book;
+
+ $this->asEditor()->get($book->getUrl('/create-page'));
+ $newPage = $book->pages()->orderBy('id', 'desc')->first();
+ $this->assertEquals('wysiwyg', $newPage->editor);
+
+ $this->setSettings(['app-editor' => PageEditorType::Markdown->value]);
+
+ $this->asEditor()->get($book->getUrl('/create-page'));
+ $newPage = $book->pages()->orderBy('id', 'desc')->first();
+ $this->assertEquals('markdown', $newPage->editor);
+ }
+
public function test_markdown_setting_shows_markdown_editor_for_new_pages()
{
$this->setSettings(['app-editor' => PageEditorType::Markdown->value]);