From 64d76ce27a2c55131d298554c07a511520289a5f Mon Sep 17 00:00:00 2001 From: Mike Robinson Date: Sun, 5 Apr 2020 23:35:57 -0600 Subject: [PATCH] Add option to purge only deleted messages (#565) * Add option to purge deleted messages * Add "scan errors" column to messages table --- assets/js/messages.js | 11 ++++++++-- classes/ThemeScanner.php | 4 ++++ controllers/Messages.php | 7 +++++- controllers/messages/_scan_messages_form.htm | 16 +++++++++++++- controllers/messages/_table_headers.htm | 5 +++++ controllers/messages/config_table.yaml | 3 +++ controllers/messages/index.htm | 2 +- lang/en/lang.php | 5 +++++ models/Message.php | 10 ++++++++- updates/update_messages_table.php | 23 ++++++++++++++++++++ updates/version.yaml | 4 ++++ 11 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 updates/update_messages_table.php diff --git a/assets/js/messages.js b/assets/js/messages.js index f43558f4..74648fd8 100644 --- a/assets/js/messages.js +++ b/assets/js/messages.js @@ -33,6 +33,11 @@ */ this.toHeader = null + /* + * Template for the "found" header (title) + */ + this.foundHeader = null + /* * The table widget element */ @@ -76,14 +81,16 @@ $toolbar.prepend(Mustache.render(this.tableToolbar.html())) } - this.setTitleContents = function(fromEl, toEl) { + this.setTitleContents = function(fromEl, toEl, foundEl) { if (fromEl) this.fromHeader = $(fromEl) if (toEl) this.toHeader = $(toEl) + if (foundEl) this.foundHeader = $(foundEl) if (!this.tableElement) return var $headers = $('table.headers th', this.tableElement) $headers.eq(0).html(this.fromHeader.html()) $headers.eq(1).html(Mustache.render(this.toHeader.html(), { hideTranslated: this.hideTranslated } )) + $headers.eq(2).html(this.foundHeader.html()) } this.setTableElement = function(el) { @@ -155,4 +162,4 @@ $.translateMessages = new TranslateMessages; -}(window.jQuery); \ No newline at end of file +}(window.jQuery); diff --git a/classes/ThemeScanner.php b/classes/ThemeScanner.php index c9e00ee1..bf40b17d 100644 --- a/classes/ThemeScanner.php +++ b/classes/ThemeScanner.php @@ -33,6 +33,10 @@ public static function scan() */ public function scanForMessages() { + // Set all messages initially as being not found. The scanner later + // sets the entries it finds as found. + Message::query()->update(['found' => false]); + $this->scanThemeConfigForMessages(); $this->scanThemeTemplatesForMessages(); $this->scanMailTemplatesForMessages(); diff --git a/controllers/Messages.php b/controllers/Messages.php index d075ff61..6dac51f1 100644 --- a/controllers/Messages.php +++ b/controllers/Messages.php @@ -74,6 +74,10 @@ public function onScanMessages() } ThemeScanner::scan(); + + if (post('purge_deleted_messages', false)) { + Message::where('found', 0)->delete(); + } Flash::success(Lang::get('rainlab.translate::lang.messages.scan_messages_success')); @@ -198,7 +202,8 @@ protected function processTableData($messages, $from, $to) 'id' => $message->id, 'code' => $message->code, 'from' => $message->forLocale($fromCode), - 'to' => $toContent + 'to' => $toContent, + 'found' => $message->found ? '' : Lang::get('rainlab.translate::lang.messages.not_found'), ]; } diff --git a/controllers/messages/_scan_messages_form.htm b/controllers/messages/_scan_messages_form.htm index fb3d143e..4d7b169f 100644 --- a/controllers/messages/_scan_messages_form.htm +++ b/controllers/messages/_scan_messages_form.htm @@ -10,7 +10,7 @@