From 685751a7314ac4e9dbf398841221ea1564550045 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 27 Mar 2024 13:06:06 +0100 Subject: [PATCH 1/6] Fix success notification messages --- application/forms/CleanupNodeForm.php | 9 +++++++++ application/forms/DeleteNodeForm.php | 8 ++++++++ application/forms/SimulationForm.php | 4 ++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/application/forms/CleanupNodeForm.php b/application/forms/CleanupNodeForm.php index c6e53982..5387e159 100644 --- a/application/forms/CleanupNodeForm.php +++ b/application/forms/CleanupNodeForm.php @@ -54,6 +54,15 @@ public function onSuccess() $changes->deleteNode($node); } + $count = count($nodesToCleanup); + if ($count === 1) { + $successMsg = sprintf($this->translate('Successfully removed missing node %s'), $nodeName); + } else { + $successMsg = sprintf($this->translate('Successfully removed %d missing nodes'), $count); + } + + $this->setSuccessMessage($successMsg); + unset($changes); parent::onSuccess(); diff --git a/application/forms/DeleteNodeForm.php b/application/forms/DeleteNodeForm.php index dba0710c..70215067 100644 --- a/application/forms/DeleteNodeForm.php +++ b/application/forms/DeleteNodeForm.php @@ -98,9 +98,17 @@ public function onSuccess() switch ($confirm) { case 'yes': $changes->deleteNode($this->node, $this->parentNode === null ? null : $this->parentNode->getName()); + $this->setSuccessMessage(sprintf( + $this->translate('Node %s has been deleted'), + $this->node->getAlias() + )); break; case 'all': $changes->deleteNode($this->node); + $this->setSuccessMessage(sprintf( + $this->translate('All occurrences of node %s have been deleted'), + $this->node->getAlias() + )); break; case 'no': $this->setSuccessMessage($this->translate('Well, maybe next time')); diff --git a/application/forms/SimulationForm.php b/application/forms/SimulationForm.php index 04a0f569..cabd859e 100644 --- a/application/forms/SimulationForm.php +++ b/application/forms/SimulationForm.php @@ -106,7 +106,7 @@ public function onSuccess() $state = $this->getValue('state'); if ($state !== null && ctype_digit($state)) { - $this->notifySuccess($this->translate('Simulation has been set')); + $this->setSuccessMessage($this->translate('Simulation has been set')); $this->simulation->set($nodeName, (object) array( 'state' => $this->getValue('state'), 'acknowledged' => $this->getValue('acknowledged'), @@ -114,7 +114,7 @@ public function onSuccess() )); } else { if ($this->simulation->remove($nodeName)) { - $this->notifySuccess($this->translate('Simulation has been removed')); + $this->setSuccessMessage($this->translate('Simulation has been removed')); } } From d6328de32a5249de5082dc110c71afbc5b9ac007 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 27 Mar 2024 13:06:25 +0100 Subject: [PATCH 2/6] MoveNodeForm: Make notification work Because of the `ignore` header, the `req::OnResponce()` returns erlier, and cannot show notifications. --- application/forms/MoveNodeForm.php | 2 +- public/js/module.js | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/application/forms/MoveNodeForm.php b/application/forms/MoveNodeForm.php index 81d15c78..0467e51e 100644 --- a/application/forms/MoveNodeForm.php +++ b/application/forms/MoveNodeForm.php @@ -151,7 +151,7 @@ public function onSuccess() // Trigger session destruction to make sure it get's stored. unset($changes); - $this->notifySuccess($this->getSuccessMessage($this->translate('Node order updated'))); + $this->notifySuccess($this->translate('Node order updated')); $response = $this->getRequest()->getResponse() ->setHeader('X-Icinga-Container', 'ignore') diff --git a/public/js/module.js b/public/js/module.js index 4855c9cc..e93accfd 100644 --- a/public/js/module.js +++ b/public/js/module.js @@ -122,7 +122,9 @@ ].join('&'); var $container = $source.closest('.container'); - icinga.loader.loadUrl(actionUrl, $container, data, 'POST'); + var icingaLoader = this.module.icinga.loader; + icingaLoader.loadUrl(actionUrl, $container, data, 'POST') + .done((_, __, req) => icingaLoader.processNotificationHeader(req)); } }, @@ -155,7 +157,10 @@ ].join('&'); var $container = $target.closest('.container'); - icinga.loader.loadUrl(actionUrl, $container, data, 'POST'); + var icingaLoader = this.module.icinga.loader; + icingaLoader.loadUrl(actionUrl, $container, data, 'POST') + .done((_, __, req) => icingaLoader.processNotificationHeader(req)); + event.stopPropagation(); } }, From 520d027dcb27bfeec42d01ded14e14a8d9b54dd9 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 27 Mar 2024 13:17:51 +0100 Subject: [PATCH 3/6] Add missing tanslations --- application/forms/BpConfigForm.php | 6 +++--- application/forms/BpUploadForm.php | 2 +- application/forms/ProcessForm.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/application/forms/BpConfigForm.php b/application/forms/BpConfigForm.php index 8a0bc95d..1abd9872 100644 --- a/application/forms/BpConfigForm.php +++ b/application/forms/BpConfigForm.php @@ -165,7 +165,7 @@ protected function onRequest() $this->bp->clearAppliedChanges(); $this->storage->deleteProcess($name); $this->setSuccessUrl('businessprocess'); - $this->redirectOnSuccess(sprintf('Process %s has been deleted', $name)); + $this->redirectOnSuccess(sprintf($this->translate('Process %s has been deleted'), $name)); } } } @@ -197,10 +197,10 @@ public function onSuccess() array('config' => $name, 'unlocked' => true) ) ); - $this->setSuccessMessage(sprintf('Process %s has been created', $name)); + $this->setSuccessMessage(sprintf($this->translate('Process %s has been created'), $name)); } else { $config = $this->bp; - $this->setSuccessMessage(sprintf('Process %s has been stored', $name)); + $this->setSuccessMessage(sprintf($this->translate('Process %s has been stored'), $name)); } $meta = $config->getMetadata(); foreach ($this->getValues() as $key => $value) { diff --git a/application/forms/BpUploadForm.php b/application/forms/BpUploadForm.php index a7467408..9327981f 100644 --- a/application/forms/BpUploadForm.php +++ b/application/forms/BpUploadForm.php @@ -198,7 +198,7 @@ public function onSuccess() } $this->storage->storeProcess($config); - Notification::success(sprintf('Process %s has been stored', $name)); + Notification::success(sprintf($this->translate('Process %s has been stored'), $name)); $this->getSuccessUrl()->setParam('config', $name); diff --git a/application/forms/ProcessForm.php b/application/forms/ProcessForm.php index 126fe9ba..1fa40ec2 100644 --- a/application/forms/ProcessForm.php +++ b/application/forms/ProcessForm.php @@ -143,7 +143,7 @@ public function onSuccess() Notification::success( sprintf( - 'Process %s has been modified', + $this->translate('Process %s has been modified'), $this->bp->getName() ) ); From 2dbfe86f16cb4bcea1f2d741b132634413c6f174 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 27 Mar 2024 13:58:09 +0100 Subject: [PATCH 4/6] Fix phpstan issues --- application/forms/CleanupNodeForm.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/forms/CleanupNodeForm.php b/application/forms/CleanupNodeForm.php index 5387e159..b4a7ad3d 100644 --- a/application/forms/CleanupNodeForm.php +++ b/application/forms/CleanupNodeForm.php @@ -45,10 +45,12 @@ public function onSuccess() { $changes = ProcessChanges::construct($this->bp, $this->session); + /** @var string[] $nodesToCleanup */ $nodesToCleanup = $this->getValue('cleanup_all') === '1' ? array_keys($this->bp->getMissingChildren()) : $this->getValue('nodes'); + $nodeName = null; foreach ($nodesToCleanup as $nodeName) { $node = $this->bp->getNode($nodeName); $changes->deleteNode($node); From 3612f3202b67aa98d7643d2fe4f6f62abb1d63b7 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Fri, 19 Apr 2024 13:09:54 +0200 Subject: [PATCH 5/6] QuickBaseForm: Replace method `translate` with trait The trait provides translatePlural method. --- application/forms/CleanupNodeForm.php | 16 +++++++++------- .../Businessprocess/Web/Form/QuickBaseForm.php | 12 +++--------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/application/forms/CleanupNodeForm.php b/application/forms/CleanupNodeForm.php index b4a7ad3d..cc5f1e20 100644 --- a/application/forms/CleanupNodeForm.php +++ b/application/forms/CleanupNodeForm.php @@ -56,14 +56,16 @@ public function onSuccess() $changes->deleteNode($node); } - $count = count($nodesToCleanup); - if ($count === 1) { - $successMsg = sprintf($this->translate('Successfully removed missing node %s'), $nodeName); - } else { - $successMsg = sprintf($this->translate('Successfully removed %d missing nodes'), $count); - } - $this->setSuccessMessage($successMsg); + $count = count($nodesToCleanup); + $this->setSuccessMessage(sprintf( + $this->translatePlural( + 'Successfully removed missing node %s', + 'Successfully removed %d missing nodes', + $count + ), + $count === 1 ? $nodeName : $count + )); unset($changes); diff --git a/library/Businessprocess/Web/Form/QuickBaseForm.php b/library/Businessprocess/Web/Form/QuickBaseForm.php index 36d134fd..2eb0db85 100644 --- a/library/Businessprocess/Web/Form/QuickBaseForm.php +++ b/library/Businessprocess/Web/Form/QuickBaseForm.php @@ -5,10 +5,13 @@ use Icinga\Application\Icinga; use Icinga\Application\Modules\Module; use ipl\Html\ValidHtml; +use ipl\I18n\Translation; use Zend_Form; abstract class QuickBaseForm extends Zend_Form implements ValidHtml { + use Translation; + /** * The Icinga module this form belongs to. Usually only set if the * form is initialized through the FormLoader @@ -154,13 +157,4 @@ protected function valueIsEmpty($value) return strlen($value) === 0; } - - public function translate($string) - { - if ($this->icingaModuleName === null) { - return t($string); - } else { - return mt($this->icingaModuleName, $string); - } - } } From 49e70b06134f189a7b7d2c86b35ac92f6f3c356c Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 27 Mar 2024 14:02:15 +0100 Subject: [PATCH 6/6] Update phpstan baseline --- phpstan-baseline-standard.neon | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/phpstan-baseline-standard.neon b/phpstan-baseline-standard.neon index ebd45d27..7007df31 100644 --- a/phpstan-baseline-standard.neon +++ b/phpstan-baseline-standard.neon @@ -630,11 +630,6 @@ parameters: count: 1 path: application/forms/BpUploadForm.php - - - message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#" - count: 1 - path: application/forms/CleanupNodeForm.php - - message: "#^Method Icinga\\\\Module\\\\Businessprocess\\\\Forms\\\\CleanupNodeForm\\:\\:onSuccess\\(\\) has no return type specified\\.$#" count: 1 @@ -645,11 +640,6 @@ parameters: count: 1 path: application/forms/CleanupNodeForm.php - - - message: "#^Parameter \\#1 \\$name of method Icinga\\\\Module\\\\Businessprocess\\\\BpConfig\\:\\:getNode\\(\\) expects string, mixed given\\.$#" - count: 1 - path: application/forms/CleanupNodeForm.php - - message: "#^Method Icinga\\\\Module\\\\Businessprocess\\\\Forms\\\\DeleteNodeForm\\:\\:onSuccess\\(\\) has no return type specified\\.$#" count: 1 @@ -3965,16 +3955,6 @@ parameters: count: 1 path: library/Businessprocess/Web/Form/QuickBaseForm.php - - - message: "#^Method Icinga\\\\Module\\\\Businessprocess\\\\Web\\\\Form\\\\QuickBaseForm\\:\\:translate\\(\\) has no return type specified\\.$#" - count: 1 - path: library/Businessprocess/Web/Form/QuickBaseForm.php - - - - message: "#^Method Icinga\\\\Module\\\\Businessprocess\\\\Web\\\\Form\\\\QuickBaseForm\\:\\:translate\\(\\) has parameter \\$string with no type specified\\.$#" - count: 1 - path: library/Businessprocess/Web/Form/QuickBaseForm.php - - message: "#^Method Icinga\\\\Module\\\\Businessprocess\\\\Web\\\\Form\\\\QuickBaseForm\\:\\:valueIsEmpty\\(\\) has no return type specified\\.$#" count: 1