From c9eedc95d4f8f4bb87a7e1123653bfcee84ce101 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 19 Mar 2021 17:03:44 +0100 Subject: [PATCH] [FEATURE] Add button to delete all mails and answers The "Mail list" page has a "cleanup" button that opens a small form which allows one to delete all mails and answers on the current page. Port of the old patch from 2018 https://github.com/einpraegsam/powermail/pull/304 --- Classes/Controller/ModuleController.php | 43 +++++++++++++++++++ Resources/Private/Language/de.locallang.xlf | 20 +++++++++ Resources/Private/Language/locallang.xlf | 15 +++++++ .../Partials/Module/DeleteAllMails.html | 41 ++++++++++++++++++ Resources/Private/Templates/Module/List.html | 4 ++ ext_tables.php | 1 + 6 files changed, 124 insertions(+) create mode 100644 Resources/Private/Partials/Module/DeleteAllMails.html diff --git a/Classes/Controller/ModuleController.php b/Classes/Controller/ModuleController.php index 6a2e6b270..eef0c5824 100644 --- a/Classes/Controller/ModuleController.php +++ b/Classes/Controller/ModuleController.php @@ -8,6 +8,8 @@ use In2code\Powermail\Utility\BackendUtility; use In2code\Powermail\Utility\BasicFileUtility; use In2code\Powermail\Utility\ConfigurationUtility; +use In2code\Powermail\Utility\DatabaseUtility; +use In2code\Powermail\Utility\LocalizationUtility; use In2code\Powermail\Utility\MailUtility; use In2code\Powermail\Utility\ReportingUtility; use In2code\Powermail\Utility\StringUtility; @@ -62,6 +64,47 @@ public function listAction(): void ); } + /** + * Delete all mails and answers if the confirmation checkbox has been checked + * + * @return void + */ + public function deleteAllMailsBeAction(): void + { + $args = $this->request->getArguments(); + if ($args['reallyDelete'] === '1' && $this->id > 0) { + $this->deleteAllMails(); + } + $this->forward('list'); + } + + /** + * Delete all mails and answers on the current page + * + * @return void + */ + protected function deleteAllMails(): void + { + $queryBuilder = DatabaseUtility::getQueryBuilderForTable(Answer::TABLE_NAME); + $queryBuilder->delete(Answer::TABLE_NAME) + ->where( + $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($this->id)) + ) + ->execute(); + + $queryBuilder = DatabaseUtility::getQueryBuilderForTable(Answer::TABLE_NAME); + $queryBuilder->delete(Mail::TABLE_NAME) + ->where( + $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($this->id)) + ) + ->execute(); + + $this->addFlashMessage( + LocalizationUtility::translate('BackendDeleteAllMailsFinished'), + '' + ); + } + /** * @return void * @throws InvalidQueryException diff --git a/Resources/Private/Language/de.locallang.xlf b/Resources/Private/Language/de.locallang.xlf index 8e5cfef11..8a458b151 100644 --- a/Resources/Private/Language/de.locallang.xlf +++ b/Resources/Private/Language/de.locallang.xlf @@ -747,6 +747,26 @@ This TYPO3 instance is running in development context. You can use %s in the AdditionalConfiguration.php to enforce powermail to send testmails to this email-address only. Diese TYPO3-Instanz läuft aktuell im Development Context. Mit %s in der AdditionalConfiguration.php kann man powermail anweisen, nur noch an diese Formulare zu senden. + + Cleanup + Aufräumen + + + Delete all mails + Alle Mails löschen + + + All mails and answers on this page have been deleted + Alle Mails und Antworten auf dieser Seite wurden gelöscht. + + + Yes, delete all mails and answers on this page + Ja, alle Mails und Antworten auf dieser Seite löschen + + + Delete all + Alle löschen + Form Overview Formular Übersicht diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index ed3cd70b4..7b10926bf 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -559,6 +559,21 @@ This TYPO3 instance is running in development context. You can use %s in the AdditionalConfiguration.php to enforce powermail to send testmails to this email-address only. + + Cleanup + + + Delete all mails + + + All mails and answers on this page have been deleted + + + Yes, delete all mails and answers on this page + + + Delete all + Form Overview diff --git a/Resources/Private/Partials/Module/DeleteAllMails.html b/Resources/Private/Partials/Module/DeleteAllMails.html new file mode 100644 index 000000000..1549b63d5 --- /dev/null +++ b/Resources/Private/Partials/Module/DeleteAllMails.html @@ -0,0 +1,41 @@ +
+
+ + Cleanup + +
+
+ +
+

+ Delete all mails +

+ +
+ + +
+
+ +
+
+ + + +
+
+
+
+
diff --git a/Resources/Private/Templates/Module/List.html b/Resources/Private/Templates/Module/List.html index ebd470527..454e19932 100644 --- a/Resources/Private/Templates/Module/List.html +++ b/Resources/Private/Templates/Module/List.html @@ -39,4 +39,8 @@

+ + + + diff --git a/ext_tables.php b/ext_tables.php index 2b41d3215..948a95ae8 100644 --- a/ext_tables.php +++ b/ext_tables.php @@ -21,6 +21,7 @@ function () { [ \In2code\Powermail\Controller\ModuleController::class => 'dispatch, list, exportXls, exportCsv, reportingBe, toolsBe, overviewBe, ' . + 'deleteAllMailsBe, ' . 'checkBe, converterBe, converterUpdateBe, reportingFormBe, reportingMarketingBe, ' . 'fixUploadFolder, fixWrongLocalizedForms, fixFilledMarkersInLocalizedFields, ' . 'fixWrongLocalizedPages, fixFilledMarkersInLocalizedPages'