diff --git a/app/Repos/EntityRepo.php b/app/Repos/EntityRepo.php index 449e3aa7d..f1041f126 100644 --- a/app/Repos/EntityRepo.php +++ b/app/Repos/EntityRepo.php @@ -569,6 +569,7 @@ class EntityRepo $draftPage->html = $this->formatHtml($input['html']); $draftPage->text = strip_tags($draftPage->html); $draftPage->draft = false; + $draftPage->revision_count = 1; $draftPage->save(); $this->savePageRevision($draftPage, trans('entities.pages_initial_revision')); @@ -593,6 +594,7 @@ class EntityRepo $revision->created_at = $page->updated_at; $revision->type = 'version'; $revision->summary = $summary; + $revision->revision_number = $page->revision_count; $revision->save(); // Clear old revisions @@ -812,6 +814,7 @@ class EntityRepo $page->text = strip_tags($page->html); if (setting('app-editor') !== 'markdown') $page->markdown = ''; $page->updated_by = $userId; + $page->revision_count++; $page->save(); // Remove all update drafts for this user & page. @@ -920,6 +923,7 @@ class EntityRepo */ public function restorePageRevision(Page $page, Book $book, $revisionId) { + $page->revision_count++; $this->savePageRevision($page); $revision = $page->revisions()->where('id', '=', $revisionId)->first(); $page->fill($revision->toArray()); diff --git a/database/migrations/2017_04_20_185112_add_revision_counts.php b/database/migrations/2017_04_20_185112_add_revision_counts.php new file mode 100644 index 000000000..3583f36f3 --- /dev/null +++ b/database/migrations/2017_04_20_185112_add_revision_counts.php @@ -0,0 +1,44 @@ +integer('revision_count'); + }); + Schema::table('page_revisions', function (Blueprint $table) { + $table->integer('revision_number'); + $table->index('revision_number'); + }); + + // Update revision count + $pTable = DB::getTablePrefix() . 'pages'; + $rTable = DB::getTablePrefix() . 'page_revisions'; + DB::statement("UPDATE ${pTable} SET ${pTable}.revision_count=(SELECT count(*) FROM ${rTable} WHERE ${rTable}.page_id=${pTable}.id)"); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('pages', function (Blueprint $table) { + $table->dropColumn('revision_count'); + }); + Schema::table('page_revisions', function (Blueprint $table) { + $table->dropColumn('revision_number'); + }); + } +} diff --git a/resources/lang/en/entities.php b/resources/lang/en/entities.php index 8644f7a4a..450f4ce48 100644 --- a/resources/lang/en/entities.php +++ b/resources/lang/en/entities.php @@ -14,6 +14,7 @@ return [ 'recent_activity' => 'Recent Activity', 'create_now' => 'Create one now', 'revisions' => 'Revisions', + 'meta_revision' => 'Revision #:revisionCount', 'meta_created' => 'Created :timeLength', 'meta_created_name' => 'Created :timeLength by :user', 'meta_updated' => 'Updated :timeLength', @@ -168,6 +169,7 @@ return [ 'pages_revision_named' => 'Page Revision for :pageName', 'pages_revisions_created_by' => 'Created By', 'pages_revisions_date' => 'Revision Date', + 'pages_revisions_number' => '#', 'pages_revisions_changelog' => 'Changelog', 'pages_revisions_changes' => 'Changes', 'pages_revisions_current' => 'Current Version', diff --git a/resources/views/pages/revisions.blade.php b/resources/views/pages/revisions.blade.php index 3b9812abd..bdc8460ef 100644 --- a/resources/views/pages/revisions.blade.php +++ b/resources/views/pages/revisions.blade.php @@ -19,6 +19,7 @@
{{ trans('entities.pages_revisions_number') }} | {{ trans('entities.pages_name') }} | {{ trans('entities.pages_revisions_created_by') }} | {{ trans('entities.pages_revisions_date') }} | @@ -27,6 +28,7 @@|
---|---|---|---|---|
{{ $revision->revision_number == 0 ? '' : $revision->revision_number }} | {{ $revision->name }} |
@if($revision->createdBy)
diff --git a/resources/views/partials/entity-meta.blade.php b/resources/views/partials/entity-meta.blade.php
index 2a7427422..0442ce50c 100644
--- a/resources/views/partials/entity-meta.blade.php
+++ b/resources/views/partials/entity-meta.blade.php
@@ -1,13 +1,20 @@
+ @if ($entity->isA('page')) {{ trans('entities.meta_revision', ['revisionCount' => $entity->revision_count]) }} |