mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 07:44:04 +02:00
Merge branch 'bugfix/delete-multiple-downtimes-and-comments-8624'
fixes #8624
This commit is contained in:
commit
cf8376f478
@ -64,25 +64,26 @@ class Monitoring_CommentController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function showAction()
|
public function showAction()
|
||||||
{
|
{
|
||||||
|
$listCommentsLink = Url::fromPath('monitoring/list/comments')
|
||||||
|
->setQueryString('comment_type=(comment|ack)');
|
||||||
|
|
||||||
$this->view->comment = $this->comment;
|
$this->view->comment = $this->comment;
|
||||||
if ($this->hasPermission('monitoring/command/comment/delete')) {
|
if ($this->hasPermission('monitoring/command/comment/delete')) {
|
||||||
$this->view->delCommentForm = $this->createDelCommentForm();
|
$this->view->delCommentForm = $this->createDelCommentForm();
|
||||||
|
$this->view->delCommentForm->populate(
|
||||||
|
array(
|
||||||
|
'redirect' => $listCommentsLink,
|
||||||
|
'comment_id' => $this->comment->id,
|
||||||
|
'comment_is_service' => isset($this->comment->service_description)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Receive DeleteCommentCommandForm post from other controller
|
|
||||||
*/
|
|
||||||
public function removeAction()
|
|
||||||
{
|
|
||||||
$this->assertHttpMethod('POST');
|
|
||||||
$this->createDelCommentForm();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a command form to delete a single comment
|
* Create a command form to delete a single comment
|
||||||
*
|
*
|
||||||
* @return DeleteCommentCommandForm
|
* @return DeleteCommentsCommandForm
|
||||||
*/
|
*/
|
||||||
private function createDelCommentForm()
|
private function createDelCommentForm()
|
||||||
{
|
{
|
||||||
@ -93,12 +94,6 @@ class Monitoring_CommentController extends Controller
|
|||||||
Url::fromPath('monitoring/comment/show')
|
Url::fromPath('monitoring/comment/show')
|
||||||
->setParam('comment_id', $this->comment->id)
|
->setParam('comment_id', $this->comment->id)
|
||||||
);
|
);
|
||||||
$delCommentForm->populate(
|
|
||||||
array(
|
|
||||||
'redirect' => Url::fromPath('monitoring/list/comments'),
|
|
||||||
'comment_id' => $this->comment->id
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$delCommentForm->handleRequest();
|
$delCommentForm->handleRequest();
|
||||||
return $delCommentForm;
|
return $delCommentForm;
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,8 @@
|
|||||||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||||
|
|
||||||
use Icinga\Module\Monitoring\Controller;
|
use Icinga\Module\Monitoring\Controller;
|
||||||
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentCommandForm;
|
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteCommentsCommandForm;
|
||||||
use Icinga\Web\Url;
|
use Icinga\Web\Url;
|
||||||
use Icinga\Web\Widget\Tabextension\DashboardAction;
|
|
||||||
use Icinga\Data\Filter\Filter;
|
use Icinga\Data\Filter\Filter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,28 +70,31 @@ class Monitoring_CommentsController extends Controller
|
|||||||
$this->view->comments = $this->comments;
|
$this->view->comments = $this->comments;
|
||||||
$this->view->listAllLink = Url::fromPath('monitoring/list/comments')
|
$this->view->listAllLink = Url::fromPath('monitoring/list/comments')
|
||||||
->setQueryString($this->filter->toQueryString());
|
->setQueryString($this->filter->toQueryString());
|
||||||
$this->view->removeAllLink = Url::fromPath('monitoring/comments/remove-all')
|
$this->view->removeAllLink = Url::fromPath('monitoring/comments/delete-all')
|
||||||
->setParams($this->params);
|
->setParams($this->params);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display the form for removing a comment list
|
* Display the form for removing a comment list
|
||||||
*/
|
*/
|
||||||
public function removeAllAction()
|
public function deleteAllAction()
|
||||||
{
|
{
|
||||||
$this->assertPermission('monitoring/command/comment/delete');
|
$this->assertPermission('monitoring/command/comment/delete');
|
||||||
$this->view->comments = $this->comments;
|
|
||||||
$this->view->listAllLink = Url::fromPath('monitoring/list/comments')
|
$listCommentsLink = Url::fromPath('monitoring/list/comments')
|
||||||
->setQueryString($this->filter->toQueryString());
|
->setQueryString('comment_type=(comment|ack)');
|
||||||
$delCommentForm = new DeleteCommentCommandForm();
|
$delCommentForm = new DeleteCommentsCommandForm();
|
||||||
$delCommentForm->setTitle($this->view->translate('Remove all Comments'));
|
$delCommentForm->setTitle($this->view->translate('Remove all Comments'));
|
||||||
$delCommentForm->addDescription(sprintf(
|
$delCommentForm->addDescription(sprintf(
|
||||||
$this->translate('Confirm removal of %d comments.'),
|
$this->translate('Confirm removal of %d comments.'),
|
||||||
count($this->comments)
|
count($this->comments)
|
||||||
));
|
));
|
||||||
$delCommentForm->setObjects($this->comments)
|
$delCommentForm->setComments($this->comments)
|
||||||
->setRedirectUrl(Url::fromPath('monitoring/list/downtimes'))
|
->setRedirectUrl($listCommentsLink)
|
||||||
->handleRequest();
|
->handleRequest();
|
||||||
$this->view->delCommentForm = $delCommentForm;
|
$this->view->delCommentForm = $delCommentForm;
|
||||||
|
$this->view->comments = $this->comments;
|
||||||
|
$this->view->listAllLink = Url::fromPath('monitoring/list/comments')
|
||||||
|
->setQueryString($this->filter->toQueryString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ use Icinga\Module\Monitoring\Controller;
|
|||||||
use Icinga\Module\Monitoring\Object\Service;
|
use Icinga\Module\Monitoring\Object\Service;
|
||||||
use Icinga\Module\Monitoring\Object\Host;
|
use Icinga\Module\Monitoring\Object\Host;
|
||||||
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimeCommandForm;
|
use Icinga\Module\Monitoring\Forms\Command\Object\DeleteDowntimeCommandForm;
|
||||||
|
use Icinga\Module\Monitoring\Command\Object\DeleteDowntimeCommand;
|
||||||
use Icinga\Web\Url;
|
use Icinga\Web\Url;
|
||||||
use Icinga\Web\Widget\Tabextension\DashboardAction;
|
use Icinga\Web\Widget\Tabextension\DashboardAction;
|
||||||
|
|
||||||
@ -81,7 +82,7 @@ class Monitoring_DowntimeController extends Controller
|
|||||||
'label' => $this->translate('Downtime'),
|
'label' => $this->translate('Downtime'),
|
||||||
'url' =>'monitoring/downtimes/show'
|
'url' =>'monitoring/downtimes/show'
|
||||||
)
|
)
|
||||||
)->activate('downtime')->extend(new DashboardAction());
|
)->activate('downtime')->extend(new DashboardAction());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -102,6 +103,13 @@ class Monitoring_DowntimeController extends Controller
|
|||||||
->setParam('service', $this->downtime->service_description);
|
->setParam('service', $this->downtime->service_description);
|
||||||
if ($this->hasPermission('monitoring/command/downtime/delete')) {
|
if ($this->hasPermission('monitoring/command/downtime/delete')) {
|
||||||
$this->view->delDowntimeForm = $this->createDelDowntimeForm();
|
$this->view->delDowntimeForm = $this->createDelDowntimeForm();
|
||||||
|
$this->view->delDowntimeForm->populate(
|
||||||
|
array(
|
||||||
|
'redirect' => Url::fromPath('monitoring/list/downtimes'),
|
||||||
|
'downtime_id' => $this->downtime->id,
|
||||||
|
'downtime_is_service' => $this->isService
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,18 +130,11 @@ class Monitoring_DowntimeController extends Controller
|
|||||||
private function createDelDowntimeForm()
|
private function createDelDowntimeForm()
|
||||||
{
|
{
|
||||||
$this->assertPermission('monitoring/command/downtime/delete');
|
$this->assertPermission('monitoring/command/downtime/delete');
|
||||||
|
|
||||||
$delDowntimeForm = new DeleteDowntimeCommandForm();
|
$delDowntimeForm = new DeleteDowntimeCommandForm();
|
||||||
$delDowntimeForm->setAction(
|
$delDowntimeForm->setAction(
|
||||||
Url::fromPath('monitoring/downtime/show')
|
Url::fromPath('monitoring/downtime/show')
|
||||||
->setParam('downtime_id', $this->downtime->id)
|
->setParam('downtime_id', $this->downtime->id)
|
||||||
);
|
);
|
||||||
$delDowntimeForm->populate(
|
|
||||||
array(
|
|
||||||
'redirect' => Url::fromPath('monitoring/list/downtimes'),
|
|
||||||
'downtime_id' => $this->downtime->id
|
|
||||||
)
|
|
||||||
);
|
|
||||||
$delDowntimeForm->handleRequest();
|
$delDowntimeForm->handleRequest();
|
||||||
return $delDowntimeForm;
|
return $delDowntimeForm;
|
||||||
}
|
}
|
||||||
|
@ -104,14 +104,14 @@ class Monitoring_DowntimesController extends Controller
|
|||||||
$this->view->downtimes = $this->downtimes;
|
$this->view->downtimes = $this->downtimes;
|
||||||
$this->view->listAllLink = Url::fromPath('monitoring/list/downtimes')
|
$this->view->listAllLink = Url::fromPath('monitoring/list/downtimes')
|
||||||
->setQueryString($this->filter->toQueryString());
|
->setQueryString($this->filter->toQueryString());
|
||||||
$this->view->removeAllLink = Url::fromPath('monitoring/downtimes/remove-all')
|
$this->view->removeAllLink = Url::fromPath('monitoring/downtimes/delete-all')
|
||||||
->setParams($this->params);
|
->setParams($this->params);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display the form for removing a downtime list
|
* Display the form for removing a downtime list
|
||||||
*/
|
*/
|
||||||
public function removeAllAction()
|
public function deleteAllAction()
|
||||||
{
|
{
|
||||||
$this->assertPermission('monitoring/command/downtime/delete');
|
$this->assertPermission('monitoring/command/downtime/delete');
|
||||||
$this->view->downtimes = $this->downtimes;
|
$this->view->downtimes = $this->downtimes;
|
||||||
@ -123,9 +123,8 @@ class Monitoring_DowntimesController extends Controller
|
|||||||
$this->translate('Confirm removal of %d downtimes.'),
|
$this->translate('Confirm removal of %d downtimes.'),
|
||||||
count($this->downtimes)
|
count($this->downtimes)
|
||||||
));
|
));
|
||||||
$delDowntimeForm->setDowntimes($this->downtimes)
|
$delDowntimeForm->setRedirectUrl(Url::fromPath('monitoring/list/downtimes'));
|
||||||
->setRedirectUrl(Url::fromPath('monitoring/list/downtimes'))
|
$delDowntimeForm->setDowntimes($this->downtimes)->handleRequest();
|
||||||
->handleRequest();
|
|
||||||
$this->view->delDowntimeForm = $delDowntimeForm;
|
$this->view->delDowntimeForm = $delDowntimeForm;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -295,6 +295,7 @@ class Monitoring_ListController extends Controller
|
|||||||
|
|
||||||
if ($this->Auth()->hasPermission('monitoring/command/downtime/delete')) {
|
if ($this->Auth()->hasPermission('monitoring/command/downtime/delete')) {
|
||||||
$this->view->delDowntimeForm = new DeleteDowntimeCommandForm();
|
$this->view->delDowntimeForm = new DeleteDowntimeCommandForm();
|
||||||
|
$this->view->delDowntimeForm->handleRequest();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -502,6 +503,7 @@ class Monitoring_ListController extends Controller
|
|||||||
|
|
||||||
if ($this->Auth()->hasPermission('monitoring/command/comment/delete')) {
|
if ($this->Auth()->hasPermission('monitoring/command/comment/delete')) {
|
||||||
$this->view->delCommentForm = new DeleteCommentCommandForm();
|
$this->view->delCommentForm = new DeleteCommentCommandForm();
|
||||||
|
$this->view->delCommentForm->handleRequest();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,12 +4,13 @@
|
|||||||
namespace Icinga\Module\Monitoring\Forms\Command\Object;
|
namespace Icinga\Module\Monitoring\Forms\Command\Object;
|
||||||
|
|
||||||
use Icinga\Module\Monitoring\Command\Object\DeleteCommentCommand;
|
use Icinga\Module\Monitoring\Command\Object\DeleteCommentCommand;
|
||||||
|
use Icinga\Module\Monitoring\Forms\Command\CommandForm;
|
||||||
use Icinga\Web\Notification;
|
use Icinga\Web\Notification;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form for deleting host or service comments
|
* Form for deleting host or service comments
|
||||||
*/
|
*/
|
||||||
class DeleteCommentCommandForm extends ObjectsCommandForm
|
class DeleteCommentCommandForm extends CommandForm
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* (non-PHPDoc)
|
* (non-PHPDoc)
|
||||||
@ -26,23 +27,34 @@ class DeleteCommentCommandForm extends ObjectsCommandForm
|
|||||||
*/
|
*/
|
||||||
public function createElements(array $formData = array())
|
public function createElements(array $formData = array())
|
||||||
{
|
{
|
||||||
$this->addElements(array(
|
$this->addElements(
|
||||||
array(
|
array(
|
||||||
'hidden',
|
|
||||||
'comment_id',
|
|
||||||
array(
|
array(
|
||||||
'required' => true,
|
'hidden',
|
||||||
'decorators' => array('ViewHelper')
|
'comment_id',
|
||||||
)
|
array(
|
||||||
),
|
'required' => true,
|
||||||
array(
|
'validators' => array('NotEmpty'),
|
||||||
'hidden',
|
'decorators' => array('ViewHelper')
|
||||||
'redirect',
|
)
|
||||||
|
),
|
||||||
array(
|
array(
|
||||||
'decorators' => array('ViewHelper')
|
'hidden',
|
||||||
|
'comment_is_service',
|
||||||
|
array(
|
||||||
|
'filters' => array('Boolean'),
|
||||||
|
'decorators' => array('ViewHelper')
|
||||||
|
)
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'hidden',
|
||||||
|
'redirect',
|
||||||
|
array(
|
||||||
|
'decorators' => array('ViewHelper')
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
));
|
);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,14 +86,10 @@ class DeleteCommentCommandForm extends ObjectsCommandForm
|
|||||||
*/
|
*/
|
||||||
public function onSuccess()
|
public function onSuccess()
|
||||||
{
|
{
|
||||||
foreach ($this->objects as $object) {
|
$cmd = new DeleteCommentCommand();
|
||||||
/** @var \Icinga\Module\Monitoring\Object\MonitoredObject $object */
|
$cmd->setIsService($this->getElement('comment_is_service')->getValue())
|
||||||
$delComment = new DeleteCommentCommand();
|
->setCommentId($this->getElement('comment_id')->getValue());
|
||||||
$delComment
|
$this->getTransport($this->request)->send($cmd);
|
||||||
->setObject($object)
|
|
||||||
->setCommentId($this->getElement('comment_id')->getValue());
|
|
||||||
$this->getTransport($this->request)->send($delComment);
|
|
||||||
}
|
|
||||||
$redirect = $this->getElement('redirect')->getValue();
|
$redirect = $this->getElement('redirect')->getValue();
|
||||||
if (! empty($redirect)) {
|
if (! empty($redirect)) {
|
||||||
$this->setRedirectUrl($redirect);
|
$this->setRedirectUrl($redirect);
|
||||||
|
@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
||||||
|
|
||||||
|
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 CommandForm
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The comments deleted on success
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $comments;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-PHPDoc)
|
||||||
|
* @see \Zend_Form::init() For the method documentation.
|
||||||
|
*/
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
$this->setAttrib('class', 'inline');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-PHPDoc)
|
||||||
|
* @see \Icinga\Web\Form::createElements() For the method documentation.
|
||||||
|
*/
|
||||||
|
public function createElements(array $formData = array())
|
||||||
|
{
|
||||||
|
$this->addElements(array(
|
||||||
|
array(
|
||||||
|
'hidden',
|
||||||
|
'redirect',
|
||||||
|
array('decorators' => array('ViewHelper'))
|
||||||
|
)
|
||||||
|
));
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-PHPDoc)
|
||||||
|
* @see \Icinga\Web\Form::getSubmitLabel() For the method documentation.
|
||||||
|
*/
|
||||||
|
public function getSubmitLabel()
|
||||||
|
{
|
||||||
|
return $this->translatePlural('Remove', 'Remove All', count($this->downtimes));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-PHPDoc)
|
||||||
|
* @see \Icinga\Web\Form::onSuccess() For the method documentation.
|
||||||
|
*/
|
||||||
|
public function onSuccess()
|
||||||
|
{
|
||||||
|
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)) {
|
||||||
|
$this->setRedirectUrl($redirect);
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
@ -21,7 +21,7 @@ class DeleteDowntimeCommandForm extends CommandForm
|
|||||||
$this->setAttrib('class', 'inline');
|
$this->setAttrib('class', 'inline');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-PHPDoc)
|
* (non-PHPDoc)
|
||||||
* @see \Icinga\Web\Form::createElements() For the method documentation.
|
* @see \Icinga\Web\Form::createElements() For the method documentation.
|
||||||
*/
|
*/
|
||||||
@ -33,6 +33,16 @@ class DeleteDowntimeCommandForm extends CommandForm
|
|||||||
'hidden',
|
'hidden',
|
||||||
'downtime_id',
|
'downtime_id',
|
||||||
array(
|
array(
|
||||||
|
'required' => true,
|
||||||
|
'validators' => array('NotEmpty'),
|
||||||
|
'decorators' => array('ViewHelper')
|
||||||
|
)
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'hidden',
|
||||||
|
'downtime_is_service',
|
||||||
|
array(
|
||||||
|
'filters' => array('Boolean'),
|
||||||
'decorators' => array('ViewHelper')
|
'decorators' => array('ViewHelper')
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
@ -76,19 +86,10 @@ class DeleteDowntimeCommandForm extends CommandForm
|
|||||||
*/
|
*/
|
||||||
public function onSuccess()
|
public function onSuccess()
|
||||||
{
|
{
|
||||||
$id = $this->getElement('downtime_id')->getValue();
|
$cmd = new DeleteDowntimeCommand();
|
||||||
|
$cmd->setDowntimeId($this->getElement('downtime_id')->getValue());
|
||||||
// Presence of downtime id, only delete this specific downtime
|
$cmd->setIsService($this->getElement('downtime_is_service')->getValue());
|
||||||
$firstDowntime = $this->downtimes[0];
|
$this->getTransport($this->request)->send($cmd);
|
||||||
|
|
||||||
$delDowntime = new DeleteDowntimeCommand();
|
|
||||||
$delDowntime->setDowntimeId($id);
|
|
||||||
$delDowntime->setDowntimeType(
|
|
||||||
isset($firstDowntime->service_description) ?
|
|
||||||
DeleteDowntimeCommand::DOWNTIME_TYPE_SERVICE :
|
|
||||||
DeleteDowntimeCommand::DOWNTIME_TYPE_HOST
|
|
||||||
);
|
|
||||||
$this->getTransport($this->request)->send($delDowntime);
|
|
||||||
|
|
||||||
$redirect = $this->getElement('redirect')->getValue();
|
$redirect = $this->getElement('redirect')->getValue();
|
||||||
if (! empty($redirect)) {
|
if (! empty($redirect)) {
|
||||||
|
@ -38,9 +38,7 @@ class DeleteDowntimesCommandForm extends CommandForm
|
|||||||
array(
|
array(
|
||||||
'hidden',
|
'hidden',
|
||||||
'redirect',
|
'redirect',
|
||||||
array(
|
array('decorators' => array('ViewHelper'))
|
||||||
'decorators' => array('ViewHelper')
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
return $this;
|
return $this;
|
||||||
@ -64,11 +62,7 @@ class DeleteDowntimesCommandForm extends CommandForm
|
|||||||
foreach ($this->downtimes as $downtime) {
|
foreach ($this->downtimes as $downtime) {
|
||||||
$delDowntime = new DeleteDowntimeCommand();
|
$delDowntime = new DeleteDowntimeCommand();
|
||||||
$delDowntime->setDowntimeId($downtime->id);
|
$delDowntime->setDowntimeId($downtime->id);
|
||||||
$delDowntime->setDowntimeType(
|
$delDowntime->setIsService(isset($downtime->service_description));
|
||||||
isset($downtime->service_description) ?
|
|
||||||
DeleteDowntimeCommand::DOWNTIME_TYPE_SERVICE :
|
|
||||||
DeleteDowntimeCommand::DOWNTIME_TYPE_HOST
|
|
||||||
);
|
|
||||||
$this->getTransport($this->request)->send($delDowntime);
|
$this->getTransport($this->request)->send($delDowntime);
|
||||||
}
|
}
|
||||||
$redirect = $this->getElement('redirect')->getValue();
|
$redirect = $this->getElement('redirect')->getValue();
|
||||||
@ -86,7 +80,7 @@ class DeleteDowntimesCommandForm extends CommandForm
|
|||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setDowntimes($downtimes)
|
public function setDowntimes(array $downtimes)
|
||||||
{
|
{
|
||||||
$this->downtimes = $downtimes;
|
$this->downtimes = $downtimes;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -18,11 +18,12 @@
|
|||||||
<td>
|
<td>
|
||||||
<?= $this->icon('service', $this->translate('Service')); ?>
|
<?= $this->icon('service', $this->translate('Service')); ?>
|
||||||
<?= $this->link()->service(
|
<?= $this->link()->service(
|
||||||
$this->comment->service_description,
|
$this->comment->service_description,
|
||||||
$this->comment->service_display_name,
|
$this->comment->service_display_name,
|
||||||
$this->comment->host_name,
|
$this->comment->host_name,
|
||||||
$this->comment->host_display_names
|
$this->comment->host_display_name
|
||||||
); ?>
|
);
|
||||||
|
?>
|
||||||
</td>
|
</td>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<th> <?= $this->translate('Host') ?> </th>
|
<th> <?= $this->translate('Host') ?> </th>
|
||||||
@ -31,7 +32,8 @@
|
|||||||
<?= $this->link()->host(
|
<?= $this->link()->host(
|
||||||
$this->comment->host_name,
|
$this->comment->host_name,
|
||||||
$this->comment->host_display_name
|
$this->comment->host_display_name
|
||||||
); ?>
|
);
|
||||||
|
?>
|
||||||
</td>
|
</td>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
</tr>
|
</tr>
|
||||||
@ -55,10 +57,11 @@
|
|||||||
<th><?= $this->translate('Expires') ?></th>
|
<th><?= $this->translate('Expires') ?></th>
|
||||||
<td>
|
<td>
|
||||||
<?= $this->comment->expiration ? sprintf(
|
<?= $this->comment->expiration ? sprintf(
|
||||||
$this->translate('This comment expires on %s at %s.'),
|
$this->translate('This comment expires on %s at %s.'),
|
||||||
date('d.m.y', $this->comment->expiration),
|
date('d.m.y', $this->comment->expiration),
|
||||||
date('H:i', $this->comment->expiration)
|
date('H:i', $this->comment->expiration)
|
||||||
) : $this->translate('This comment does not expire.'); ?>
|
) : $this->translate('This comment does not expire.');
|
||||||
|
?>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
@ -83,8 +83,12 @@ if (count($comments) === 0) {
|
|||||||
<td style="width: 2em" data-base-target="self">
|
<td style="width: 2em" data-base-target="self">
|
||||||
<?php
|
<?php
|
||||||
$delCommentForm = clone $delCommentForm;
|
$delCommentForm = clone $delCommentForm;
|
||||||
$delCommentForm->populate(array('comment_id' => $comment->id, 'redirect' => $this->url));
|
$delCommentForm->populate(
|
||||||
$delCommentForm->setAction($this->url('monitoring/comment/remove', array('comment_id' => $comment->id)));
|
array(
|
||||||
|
'comment_id' => $comment->id,
|
||||||
|
'comment_is_service' => isset($comment->service_description)
|
||||||
|
)
|
||||||
|
);
|
||||||
echo $delCommentForm;
|
echo $delCommentForm;
|
||||||
?>
|
?>
|
||||||
</td>
|
</td>
|
||||||
|
@ -128,8 +128,12 @@ if (count($downtimes) === 0) {
|
|||||||
<td style="width: 2em" data-base-target="self">
|
<td style="width: 2em" data-base-target="self">
|
||||||
<?php
|
<?php
|
||||||
$delDowntimeForm = clone $delDowntimeForm;
|
$delDowntimeForm = clone $delDowntimeForm;
|
||||||
$delDowntimeForm->populate(array('downtime_id' => $downtime->id, 'redirect' => $this->url));
|
$delDowntimeForm->populate(
|
||||||
$delDowntimeForm->setAction($this->url('monitoring/downtime/remove', array('downtime_id' => $downtime->id)));
|
array(
|
||||||
|
'downtime_id' => $downtime->id,
|
||||||
|
'downtime_is_service' => isset($downtime->service_description)
|
||||||
|
)
|
||||||
|
);
|
||||||
echo $delDowntimeForm;
|
echo $delDowntimeForm;
|
||||||
?>
|
?>
|
||||||
</td>
|
</td>
|
||||||
|
@ -48,7 +48,12 @@ foreach ($object->comments as $comment) {
|
|||||||
<td data-base-target="_self">
|
<td data-base-target="_self">
|
||||||
<?php if (isset($delCommentForm)) { // Form is unset if the current user lacks the respective permission
|
<?php if (isset($delCommentForm)) { // Form is unset if the current user lacks the respective permission
|
||||||
$delCommentForm = clone $delCommentForm;
|
$delCommentForm = clone $delCommentForm;
|
||||||
$delCommentForm->populate(array('comment_id' => $comment->id));
|
$delCommentForm->populate(
|
||||||
|
array(
|
||||||
|
'comment_id' => $comment->id,
|
||||||
|
'comment_is_service' => isset($comment->service_description)
|
||||||
|
)
|
||||||
|
);
|
||||||
echo $delCommentForm;
|
echo $delCommentForm;
|
||||||
} ?>
|
} ?>
|
||||||
<span class="sr-only">(<?= $this->translate('Comment'); ?>): </span><?= str_replace(array('\r\n', '\n'), '<br>', $commentText); ?>
|
<span class="sr-only">(<?= $this->translate('Comment'); ?>): </span><?= str_replace(array('\r\n', '\n'), '<br>', $commentText); ?>
|
||||||
|
@ -65,7 +65,12 @@ foreach ($object->downtimes as $downtime) {
|
|||||||
<td data-base-target="_self">
|
<td data-base-target="_self">
|
||||||
<?php if (isset($delDowntimeForm)) { // Form is unset if the current user lacks the respective permission
|
<?php if (isset($delDowntimeForm)) { // Form is unset if the current user lacks the respective permission
|
||||||
$delDowntimeForm = clone $delDowntimeForm;
|
$delDowntimeForm = clone $delDowntimeForm;
|
||||||
$delDowntimeForm->populate(array('downtime_id' => $downtime->id));
|
$delDowntimeForm->populate(
|
||||||
|
array(
|
||||||
|
'downtime_id' => $downtime->id,
|
||||||
|
'downtime_is_service' => $object->getType() === $object::TYPE_SERVICE
|
||||||
|
)
|
||||||
|
);
|
||||||
echo $delDowntimeForm;
|
echo $delDowntimeForm;
|
||||||
} ?>
|
} ?>
|
||||||
<span class="sr-only"><?= $this->translate('Downtime'); ?></span>
|
<span class="sr-only"><?= $this->translate('Downtime'); ?></span>
|
||||||
|
@ -3,20 +3,13 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Monitoring\Command\Object;
|
namespace Icinga\Module\Monitoring\Command\Object;
|
||||||
|
|
||||||
|
use Icinga\Module\Monitoring\Command\IcingaCommand;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a host or service comment
|
* Delete a host or service comment
|
||||||
*/
|
*/
|
||||||
class DeleteCommentCommand extends ObjectCommand
|
class DeleteCommentCommand extends IcingaCommand
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* (non-PHPDoc)
|
|
||||||
* @see \Icinga\Module\Monitoring\Command\Object\ObjectCommand::$allowedObjects For the property documentation.
|
|
||||||
*/
|
|
||||||
protected $allowedObjects = array(
|
|
||||||
self::TYPE_HOST,
|
|
||||||
self::TYPE_SERVICE
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ID of the comment that is to be deleted
|
* ID of the comment that is to be deleted
|
||||||
*
|
*
|
||||||
@ -24,6 +17,13 @@ class DeleteCommentCommand extends ObjectCommand
|
|||||||
*/
|
*/
|
||||||
protected $commentId;
|
protected $commentId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type of the comment, either 'host' or 'service'
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
protected $isService = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the ID of the comment that is to be deleted
|
* Set the ID of the comment that is to be deleted
|
||||||
*
|
*
|
||||||
@ -46,4 +46,27 @@ class DeleteCommentCommand extends ObjectCommand
|
|||||||
{
|
{
|
||||||
return $this->commentId;
|
return $this->commentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the command affects a service comment
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function getIsService()
|
||||||
|
{
|
||||||
|
return $this->isService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether the command affects a service
|
||||||
|
*
|
||||||
|
* @param boolean $value The value, defaults to true
|
||||||
|
*
|
||||||
|
* @return this fluent interface
|
||||||
|
*/
|
||||||
|
public function setIsService($value = true)
|
||||||
|
{
|
||||||
|
$this->isService = (bool) $value;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,16 +10,6 @@ use Icinga\Module\Monitoring\Command\IcingaCommand;
|
|||||||
*/
|
*/
|
||||||
class DeleteDowntimeCommand extends IcingaCommand
|
class DeleteDowntimeCommand extends IcingaCommand
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Downtime for a host
|
|
||||||
*/
|
|
||||||
const DOWNTIME_TYPE_HOST = 'host';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Downtime for a service
|
|
||||||
*/
|
|
||||||
const DOWNTIME_TYPE_SERVICE = 'service';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ID of the downtime that is to be deleted
|
* ID of the downtime that is to be deleted
|
||||||
*
|
*
|
||||||
@ -28,28 +18,30 @@ class DeleteDowntimeCommand extends IcingaCommand
|
|||||||
protected $downtimeId;
|
protected $downtimeId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* If the command affects a service downtime
|
||||||
*
|
*
|
||||||
* @var type
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
protected $downtimeType = self::DOWNTIME_TYPE_HOST;
|
protected $isService = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the downtime type, either host or service
|
* Set if this command affects a service
|
||||||
*
|
*
|
||||||
* @param string $type the downtime type
|
* @param type $value
|
||||||
*/
|
*/
|
||||||
public function setDowntimeType($type)
|
public function setIsService($value = true)
|
||||||
{
|
{
|
||||||
$this->downtimeType = $type;
|
$this->isService = (bool) $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Return whether the command affects a service
|
||||||
*
|
*
|
||||||
* @return type
|
* @return type
|
||||||
*/
|
*/
|
||||||
public function getDowntimeType()
|
public function getIsService()
|
||||||
{
|
{
|
||||||
return $this->downtimeType;
|
return $this->isService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -323,28 +323,18 @@ class IcingaCommandFileCommandRenderer implements IcingaCommandRendererInterface
|
|||||||
|
|
||||||
public function renderDeleteComment(DeleteCommentCommand $command)
|
public function renderDeleteComment(DeleteCommentCommand $command)
|
||||||
{
|
{
|
||||||
if ($command->getObject()->getType() === $command::TYPE_HOST) {
|
|
||||||
$commandString = 'DEL_HOST_COMMENT';
|
|
||||||
} else {
|
|
||||||
$commandString = 'DEL_SVC_COMMENT';
|
|
||||||
}
|
|
||||||
return sprintf(
|
return sprintf(
|
||||||
'%s;%u',
|
'%s;%u',
|
||||||
$commandString,
|
$command->getIsService() ? 'DEL_SVC_COMMENT' : 'DEL_HOST_COMMENT',
|
||||||
$command->getCommentId()
|
$command->getCommentId()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderDeleteDowntime(DeleteDowntimeCommand $command)
|
public function renderDeleteDowntime(DeleteDowntimeCommand $command)
|
||||||
{
|
{
|
||||||
if ($command->getDowntimeType() === 'host') {
|
|
||||||
$commandString = 'DEL_HOST_DOWNTIME';
|
|
||||||
} else {
|
|
||||||
$commandString = 'DEL_SVC_DOWNTIME';
|
|
||||||
}
|
|
||||||
return sprintf(
|
return sprintf(
|
||||||
'%s;%u',
|
'%s;%u',
|
||||||
$commandString,
|
$command->getIsService() ? 'DEL_SVC_DOWNTIME' : 'DEL_HOST_DOWNTIME',
|
||||||
$command->getDowntimeId()
|
$command->getDowntimeId()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ abstract class MonitoredObjectController extends Controller
|
|||||||
->handleRequest();
|
->handleRequest();
|
||||||
$this->view->checkNowForm = $checkNowForm;
|
$this->view->checkNowForm = $checkNowForm;
|
||||||
}
|
}
|
||||||
if ( ! in_array((int) $this->object->state, array(0, 99))) {
|
if (! in_array((int) $this->object->state, array(0, 99))) {
|
||||||
if ((bool) $this->object->acknowledged) {
|
if ((bool) $this->object->acknowledged) {
|
||||||
if ($auth->hasPermission('monitoring/command/remove-acknowledgement')) {
|
if ($auth->hasPermission('monitoring/command/remove-acknowledgement')) {
|
||||||
$removeAckForm = new RemoveAcknowledgementCommandForm();
|
$removeAckForm = new RemoveAcknowledgementCommandForm();
|
||||||
@ -82,9 +82,7 @@ abstract class MonitoredObjectController extends Controller
|
|||||||
$this->view->toggleFeaturesForm = $toggleFeaturesForm;
|
$this->view->toggleFeaturesForm = $toggleFeaturesForm;
|
||||||
if (! empty($this->object->comments) && $auth->hasPermission('monitoring/command/comment/delete')) {
|
if (! empty($this->object->comments) && $auth->hasPermission('monitoring/command/comment/delete')) {
|
||||||
$delCommentForm = new DeleteCommentCommandForm();
|
$delCommentForm = new DeleteCommentCommandForm();
|
||||||
$delCommentForm
|
$delCommentForm->handleRequest();
|
||||||
->setObjects($this->object)
|
|
||||||
->handleRequest();
|
|
||||||
$this->view->delCommentForm = $delCommentForm;
|
$this->view->delCommentForm = $delCommentForm;
|
||||||
}
|
}
|
||||||
if (! empty($this->object->downtimes) && $auth->hasPermission('monitoring/command/downtime/delete')) {
|
if (! empty($this->object->downtimes) && $auth->hasPermission('monitoring/command/downtime/delete')) {
|
||||||
@ -135,16 +133,6 @@ abstract class MonitoredObjectController extends Controller
|
|||||||
*/
|
*/
|
||||||
abstract public function scheduleDowntimeAction();
|
abstract public function scheduleDowntimeAction();
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete a comment
|
|
||||||
*/
|
|
||||||
public function deleteCommentAction()
|
|
||||||
{
|
|
||||||
$this->assertHttpMethod('POST');
|
|
||||||
$this->assertPermission('monitoring/command/comment/delete');
|
|
||||||
$this->handleCommandForm(new DeleteCommentCommandForm());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create tabs
|
* Create tabs
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user