diff --git a/modules/monitoring/application/controllers/CommentsController.php b/modules/monitoring/application/controllers/CommentsController.php index 106dd4650..9521af7c9 100644 --- a/modules/monitoring/application/controllers/CommentsController.php +++ b/modules/monitoring/application/controllers/CommentsController.php @@ -90,8 +90,8 @@ class Monitoring_CommentsController extends Controller $this->translate('Confirm removal of %d comments.'), count($this->comments) )); - $delCommentForm->setObjects($this->comments) - ->setRedirectUrl(Url::fromPath('monitoring/list/downtimes')) + $delCommentForm->setComments($this->comments) + ->setRedirectUrl(Url::fromPath('monitoring/list/comments')) ->handleRequest(); $this->view->delCommentForm = $delCommentForm; } diff --git a/modules/monitoring/application/forms/Command/Object/DeleteCommentsCommandForm.php b/modules/monitoring/application/forms/Command/Object/DeleteCommentsCommandForm.php index 119020411..57f6aae5a 100644 --- a/modules/monitoring/application/forms/Command/Object/DeleteCommentsCommandForm.php +++ b/modules/monitoring/application/forms/Command/Object/DeleteCommentsCommandForm.php @@ -4,13 +4,21 @@ namespace Icinga\Module\Monitoring\Forms\Command\Object; use Icinga\Module\Monitoring\Command\Object\DeleteCommentCommand; +use \Icinga\Module\Monitoring\Forms\Command\CommandForm; use Icinga\Web\Notification; /** * Form for deleting host or service comments */ -class DeleteCommentsCommandForm extends ObjectsCommandForm +class DeleteCommentsCommandForm extends CommandForm { + /** + * The comments deleted on success + * + * @var array + */ + protected $comments; + /** * (non-PHPDoc) * @see \Zend_Form::init() For the method documentation. @@ -27,20 +35,10 @@ class DeleteCommentsCommandForm extends ObjectsCommandForm public function createElements(array $formData = array()) { $this->addElements(array( - array( - 'hidden', - 'comment_id', - array( - 'required' => true, - 'decorators' => array('ViewHelper') - ) - ), array( 'hidden', 'redirect', - array( - 'decorators' => array('ViewHelper') - ) + array('decorators' => array('ViewHelper')) ) )); return $this; @@ -74,13 +72,11 @@ class DeleteCommentsCommandForm extends ObjectsCommandForm */ public function onSuccess() { - foreach ($this->objects as $object) { - /** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */ - $delComment = new DeleteCommentCommand(); - $delComment - ->setObject($object) - ->setCommentId($this->getElement('comment_id')->getValue()); - $this->getTransport($this->request)->send($delComment); + foreach ($this->comments as $comment) { + $cmd = new DeleteCommentCommand(); + $cmd->setCommentId($comment->id) + ->setIsService(isset($comment->service_description)); + $this->getTransport($this->request)->send($cmd); } $redirect = $this->getElement('redirect')->getValue(); if (! empty($redirect)) { @@ -89,4 +85,17 @@ class DeleteCommentsCommandForm extends ObjectsCommandForm Notification::success($this->translate('Deleting comment..')); return true; } + + /** + * Set the comments to be deleted upon success + * + * @param array $comments + * + * @return this fluent interface + */ + public function setComments(array $comments) + { + $this->comments = $comments; + return $this; + } } diff --git a/modules/monitoring/application/forms/Command/Object/DeleteDowntimesCommandForm.php b/modules/monitoring/application/forms/Command/Object/DeleteDowntimesCommandForm.php index f11ac1128..566ad572c 100644 --- a/modules/monitoring/application/forms/Command/Object/DeleteDowntimesCommandForm.php +++ b/modules/monitoring/application/forms/Command/Object/DeleteDowntimesCommandForm.php @@ -64,11 +64,7 @@ class DeleteDowntimesCommandForm extends CommandForm foreach ($this->downtimes as $downtime) { $delDowntime = new DeleteDowntimeCommand(); $delDowntime->setDowntimeId($downtime->id); - $delDowntime->setDowntimeType( - isset($downtime->service_description) ? - DeleteDowntimeCommand::DOWNTIME_TYPE_SERVICE : - DeleteDowntimeCommand::DOWNTIME_TYPE_HOST - ); + $delDowntime->setIsService(isset($downtime->service_description)); $this->getTransport($this->request)->send($delDowntime); } $redirect = $this->getElement('redirect')->getValue(); @@ -86,7 +82,7 @@ class DeleteDowntimesCommandForm extends CommandForm * * @return $this */ - public function setDowntimes($downtimes) + public function setDowntimes(array $downtimes) { $this->downtimes = $downtimes; return $this; diff --git a/modules/monitoring/application/views/scripts/list/comments.phtml b/modules/monitoring/application/views/scripts/list/comments.phtml index 141c688e7..690095360 100644 --- a/modules/monitoring/application/views/scripts/list/comments.phtml +++ b/modules/monitoring/application/views/scripts/list/comments.phtml @@ -83,7 +83,13 @@ if (count($comments) === 0) {