Command masks: Add validator and change validation flow

refs #4355
This commit is contained in:
Marius Hein 2013-07-18 13:46:12 +02:00
parent e9c9c9de87
commit 89e7fa6b2d
12 changed files with 336 additions and 99 deletions

View File

@ -94,6 +94,22 @@ abstract class Form extends \Zend_Form
*/
abstract protected function create();
/**
* Method called before validation
*/
protected function preValid(array $data)
{
}
/**
* Method called after validation
* @param array $data
* @param bool &$isValid
*/
protected function postValid(array $data, &$isValid)
{
}
/**
* Setter for request
* @param \Zend_Controller_Request_Abstract $request The request object of a session
@ -139,20 +155,24 @@ abstract class Form extends \Zend_Form
*/
public function isValid($data)
{
$check = null;
$checkData = null;
// Elements must be there to validate
$this->buildForm();
if ($data === null) {
$check = $this->getRequest()->getParams();
$checkData = $this->getRequest()->getParams();
} elseif ($data instanceof \Zend_Controller_Request_Abstract) {
$check = $data->getParams();
$checkData = $data->getParams();
} else {
$check = $data;
$checkData = $data;
}
return parent::isValid($check);
$this->preValid($checkData);
$checkValue = parent::isValid($checkData);
$this->postValid($checkData, $checkValue);
return $checkValue;
}
/**

View File

@ -1,4 +1,6 @@
<?php
// @codingStandardsIgnoreStart
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
@ -26,9 +28,11 @@
*/
// {{{ICINGA_LICENSE_HEADER}}}
use Icinga\Application\Benchmark;
use Icinga\Backend;
use Icinga\Application\Config;
use Icinga\Authentication\Manager;
use Icinga\Web\Form;
use Icinga\Web\ModuleActionController;
use Icinga\Protocol\Commandpipe\Comment;
use Icinga\Protocol\Commandpipe\CommandPipe;
@ -55,9 +59,62 @@ class Monitoring_CommandController extends ModuleActionController
const DEFAULT_VIEW_SCRIPT = 'renderform';
/**
* @var \Icinga\Protocol\Commandpipe\CommandPipe
* Command target
* @var CommandPipe
*/
public $target;
private $target;
/**
* Current form working on
* @var Form
*/
private $form;
/**
* Setter for form
* @param Form $form
*/
public function setForm($form)
{
$this->form = $form;
}
/**
* Getter for form
* @return Form
*/
public function getForm()
{
return $this->form;
}
/**
* Test if we have a valid form object
* @return bool
*/
public function issetForm()
{
return $this->getForm() !== null && ($this->getForm() instanceof Form);
}
/**
* Post dispatch method
*
* When we have a form put it into the view
*/
public function postDispatch()
{
if ($this->issetForm()) {
if ($this->getRequest()->isPost() && $this->getForm()->isValid(null) === true) {
$this->_helper->viewRenderer->setNoRender(true);
$this->_helper->layout()->disableLayout();
}
$this->view->form = $this->getForm();
}
parent::postDispatch();
}
/**
* Controller configuration
@ -66,9 +123,6 @@ class Monitoring_CommandController extends ModuleActionController
public function init()
{
if ($this->_request->isPost()) {
// Save time and memory. We're only working on post
$this->_helper->viewRenderer->setNoRender(true);
$this->_helper->layout()->disableLayout();
$instance = $this->_request->getPost("instance");
@ -152,9 +206,9 @@ class Monitoring_CommandController extends ModuleActionController
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Disable active checks'));
$form->addNote(t('Disable active checks for this object.'));
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -169,9 +223,9 @@ class Monitoring_CommandController extends ModuleActionController
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Enable active checks'));
$form->addNote(t('Enable active checks for this object.'));
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -185,9 +239,9 @@ class Monitoring_CommandController extends ModuleActionController
$form = new RescheduleNextCheck();
$form->setRequest($this->getRequest());
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -204,9 +258,9 @@ class Monitoring_CommandController extends ModuleActionController
$form->setRequest($this->getRequest());
$form->setType($type);
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -221,9 +275,9 @@ class Monitoring_CommandController extends ModuleActionController
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Stop obsessing'));
$form->addNote(t('Stop obsessing over this object.'));
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -238,9 +292,9 @@ class Monitoring_CommandController extends ModuleActionController
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Start obsessing'));
$form->addNote(t('Start obsessing over this object.'));
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -255,9 +309,9 @@ class Monitoring_CommandController extends ModuleActionController
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Stop accepting passive checks'));
$form->addNote(t('Passive checks for this object will be omitted.'));
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -272,9 +326,9 @@ class Monitoring_CommandController extends ModuleActionController
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Start accepting passive checks'));
$form->addNote(t('Passive checks for this object will be accepted.'));
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -289,9 +343,9 @@ class Monitoring_CommandController extends ModuleActionController
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Disable notifications'));
$form->addNote(t('Notifications for this object will be disabled.'));
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -306,9 +360,9 @@ class Monitoring_CommandController extends ModuleActionController
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Enable notifications'));
$form->addNote(t('Notifications for this object will be enabled.'));
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -321,9 +375,9 @@ class Monitoring_CommandController extends ModuleActionController
{
$form = new CustomNotification();
$form->setRequest($this->getRequest());
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -337,9 +391,9 @@ class Monitoring_CommandController extends ModuleActionController
$form = new ScheduleDowntime();
$form->setRequest($this->getRequest());
$form->setWithChildren(false);
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -353,9 +407,9 @@ class Monitoring_CommandController extends ModuleActionController
$form = new ScheduleDowntime();
$form->setRequest($this->getRequest());
$form->setWithChildren(true);
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -370,9 +424,9 @@ class Monitoring_CommandController extends ModuleActionController
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Remove downtime(s)'));
$form->addNote(t('Remove downtime(s) from this host and its services.'));
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -387,9 +441,9 @@ class Monitoring_CommandController extends ModuleActionController
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Disable notifications'));
$form->addNote(t('Notifications for this host and its services will be disabled.'));
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -404,9 +458,9 @@ class Monitoring_CommandController extends ModuleActionController
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Enable notifications'));
$form->addNote(t('Notifications for this host and its services will be enabled.'));
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -422,9 +476,9 @@ class Monitoring_CommandController extends ModuleActionController
$form->setWithChildren(true);
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -439,9 +493,9 @@ class Monitoring_CommandController extends ModuleActionController
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Disable active checks'));
$form->addNote(t('Disable active checks for this host and its services.'));
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -456,9 +510,9 @@ class Monitoring_CommandController extends ModuleActionController
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Enable active checks'));
$form->addNote(t('Enable active checks for this host and its services.'));
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -473,9 +527,9 @@ class Monitoring_CommandController extends ModuleActionController
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Disable event handler'));
$form->addNote(t('Disable event handler for this object.'));
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -490,9 +544,9 @@ class Monitoring_CommandController extends ModuleActionController
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Enable event handler'));
$form->addNote(t('Enable event handler for this object.'));
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -507,9 +561,9 @@ class Monitoring_CommandController extends ModuleActionController
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Disable flapping detection'));
$form->addNote(t('Disable flapping detection for this object.'));
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -524,9 +578,9 @@ class Monitoring_CommandController extends ModuleActionController
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Enable flapping detection'));
$form->addNote(t('Enable flapping detection for this object.'));
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -540,9 +594,9 @@ class Monitoring_CommandController extends ModuleActionController
$form = new CommentForm();
$form->setRequest($this->getRequest());
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -557,9 +611,9 @@ class Monitoring_CommandController extends ModuleActionController
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Reset attributes'));
$form->addNote(t('Reset modified attributes to its default.'));
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -573,9 +627,9 @@ class Monitoring_CommandController extends ModuleActionController
$form = new Acknowledge();
$form->setRequest($this->getRequest());
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -590,9 +644,9 @@ class Monitoring_CommandController extends ModuleActionController
$form->setRequest($this->getRequest());
$form->setSubmitLabel(t('Remove problem acknowledgement'));
$form->addNote(t('Remove problem acknowledgement for this object.'));
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -606,9 +660,9 @@ class Monitoring_CommandController extends ModuleActionController
$form = new DelayNotification();
$form->setRequest($this->getRequest());
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
@ -627,10 +681,12 @@ class Monitoring_CommandController extends ModuleActionController
$form->setFieldLabel(t('Downtime id'));
$form->addNote(t('Delete a single downtime with the id shown above'));
$this->view->form = $form;
$this->setForm($form);
if ($form->isValid(null) && $this->getRequest()->isPost()) {
if ($this->getRequest()->isPost() && $form->isValid(null)) {
throw new \Icinga\Exception\ProgrammingError('Command sender not implemented: '. __FUNCTION__);
}
}
}
// @codingStandardsIgnoreStop

View File

@ -31,12 +31,23 @@ namespace Monitoring\Form\Command;
use Icinga\Web\Form;
use Icinga\Web\Form\Element\Note;
use \Zend_Form_Element_Hidden;
use \Zend_Validate_Date;
/**
* Class AbstractCommand
*/
abstract class AbstractCommand extends Form
{
/**
* Default date format
*/
const DEFAULT_DATE_FORMAT = 'Y-m-d H:i:s';
/**
* Default format for validation
*/
const DEFAULT_DATE_VALIDATION = 'yyyy-MM-dd hh:ii:ss';
/**
* Label for submit button
*
@ -197,8 +208,9 @@ abstract class AbstractCommand extends Form
$authorField = new Zend_Form_Element_Hidden(
array(
'name' => 'author',
'label' => t('Author name'),
'value' => $authorName,
'label' => t('Author name')
'required' => true
)
);
@ -213,4 +225,34 @@ abstract class AbstractCommand extends Form
return $authorField;
}
/**
* Getter for date format
* TODO(mh): Should be user preferences
* @return string
*/
protected function getDateFormat()
{
return self::DEFAULT_DATE_FORMAT;
}
/**
* Getter for date validation format
* @return string
*/
protected function getDateValidationFormat()
{
return self::DEFAULT_DATE_VALIDATION;
}
/**
* Create a new date validator
* @return Zend_Validate_Date
*/
protected function createDateTimeValidator()
{
$validator = new Zend_Validate_Date();
$validator->setFormat($this->getDateValidationFormat());
return $validator;
}
}

View File

@ -51,7 +51,8 @@ class Acknowledge extends AbstractCommand
'comment',
array(
'label' => t('Comment'),
'rows' => 4
'rows' => 4,
'required' => true
)
);
@ -68,8 +69,7 @@ class Acknowledge extends AbstractCommand
'checkbox',
'expire',
array(
'label' => t('Use expire time'),
'value' => false
'label' => t('Use expire time')
)
);
@ -81,7 +81,7 @@ class Acknowledge extends AbstractCommand
array(
'name' => 'expiretime',
'label' => t('Expire time'),
'value' => $now->format('Y-m-d H:i:s')
'value' => $now->format($this->getDateFormat())
)
);
@ -128,4 +128,17 @@ class Acknowledge extends AbstractCommand
parent::create();
}
/**
* Add validator for dependent fields
* @param array $data
*/
protected function preValid(array $data)
{
if (isset($data['expire']) && $data['expire'] === '1') {
$expireTime = $this->getElement('expiretime');
$expireTime->setRequired(true);
$expireTime->addValidator($this->createDateTimeValidator(), true);
}
}
}

View File

@ -43,7 +43,8 @@ class Comment extends AbstractCommand
'comment',
array(
'label' => t('Comment'),
'rows' => 4
'rows' => 4,
'required' => true
)
);

View File

@ -31,7 +31,7 @@ namespace Monitoring\Form\Command;
/**
* Simple confirmation form
*
* Exist to make the abstract form concrete.
* Exist to make the abstract available as concrete class
*/
class Confirmation extends AbstractCommand
{

View File

@ -96,6 +96,13 @@ class ConfirmationWithIdentifier extends Confirmation
$fieldLabel = $this->getFieldLabel();
$hiddenField = new Zend_Form_Element_Hidden($this->getFieldName());
$hiddenField->setValue($value);
$hiddenField->setRequired(true);
$hiddenField->addValidator(
'digits',
true
);
$hiddenField->removeDecorator('Label');
$hiddenField->addDecorator(

View File

@ -48,7 +48,8 @@ class CustomNotification extends AbstractCommand
'comment',
array(
'label' => t('Comment'),
'rows' => 4
'rows' => 4,
'required' => true
)
);

View File

@ -33,6 +33,10 @@ namespace Monitoring\Form\Command;
*/
class DelayNotification extends AbstractCommand
{
/**
* Biggest value for minutes
*/
const MAX_VALUE = 1440;
/**
* Interface method to build the form
* @see Form::create()
@ -45,7 +49,18 @@ class DelayNotification extends AbstractCommand
array(
'label' => t('Notification delay'),
'style' => 'width: 80px;',
'value' => 0
'value' => 0,
'required' => true,
'validators' => array(
array(
'between',
true,
array(
'min' => 1,
'max' => self::MAX_VALUE
)
)
)
)
);

View File

@ -54,6 +54,9 @@ class RescheduleNextCheck extends WithChildrenCommand
)
);
$dateElement->setRequired(true);
$dateElement->addValidator($this->createDateTimeValidator(), true);
$this->addElement($dateElement);
$checkBox = new Zend_Form_Element_Checkbox(

View File

@ -32,6 +32,8 @@ use Icinga\Web\Form\Element\DateTime;
use \DateTime as PhpDateTime;
use \DateInterval;
use \Zend_Form_Element_Text;
use \Zend_Validate_GreaterThan;
use \Zend_Validate_Digits;
/**
* Form for any ScheduleDowntime command
@ -44,12 +46,6 @@ class ScheduleDowntime extends WithChildrenCommand
*/
const DEFAULT_ENDTIME_INTERVAL = 'PT1H';
/**
* Default time format
* TODO(mh): Should be configurable on a central place (#4424)
*/
const DEFAULT_DATE_FORMAT = 'Y-m-d H:i:s';
/**
* Type constant for fixed downtimes
*/
@ -69,11 +65,11 @@ class ScheduleDowntime extends WithChildrenCommand
$out = array();
$dateTimeObject = new PhpDateTime();
$out[] = $dateTimeObject->format(self::DEFAULT_DATE_FORMAT);
$out[] = $dateTimeObject->format($this->getDateFormat());
$dateInterval = new DateInterval(self::DEFAULT_ENDTIME_INTERVAL);
$dateTimeObject->add($dateInterval);
$out[] = $dateTimeObject->format(self::DEFAULT_DATE_FORMAT);
$out[] = $dateTimeObject->format($this->getDateFormat());
return $out;
}
@ -103,7 +99,8 @@ class ScheduleDowntime extends WithChildrenCommand
'comment',
array(
'label' => t('Comment'),
'rows' => 4
'rows' => 4,
'required' => true
)
);
@ -111,7 +108,22 @@ class ScheduleDowntime extends WithChildrenCommand
'text',
'triggered',
array(
'label' => t('Triggered by')
'label' => t('Triggered by'),
'value' => 0,
'required' => true,
'validators' => array(
array(
'Digits',
true
),
array(
'GreaterThan',
true,
array(
'min' => -1
)
)
)
)
);
@ -124,6 +136,8 @@ class ScheduleDowntime extends WithChildrenCommand
'value' => $timestampStart
)
);
$dateTimeStart->setRequired(true);
$dateTimeStart->addValidator($this->createDateTimeValidator(), true);
$dateTimeEnd = new DateTime(
array(
@ -132,6 +146,8 @@ class ScheduleDowntime extends WithChildrenCommand
'value' => $timestampEnd
)
);
$dateTimeEnd->setRequired(true);
$dateTimeEnd->addValidator($this->createDateTimeValidator(), true);
$this->addElements(array($dateTimeStart, $dateTimeEnd));
@ -140,7 +156,17 @@ class ScheduleDowntime extends WithChildrenCommand
'type',
array(
'label' => t('Downtime type'),
'multiOptions' => $this->getDowntimeTypeOptions()
'multiOptions' => $this->getDowntimeTypeOptions(),
'required' => true,
'validators' => array(
array(
'InArray',
true,
array(
array_keys($this->getDowntimeTypeOptions())
)
)
)
)
);
@ -188,6 +214,19 @@ class ScheduleDowntime extends WithChildrenCommand
0 => t('Do nothing with child objects'),
1 => t('Schedule triggered downtime for all child objects'),
2 => t('Schedule non-triggered downtime for all child objects')
),
'validators' => array(
array(
'Digits',
true
),
array(
'InArray',
true,
array(
array(0, 1, 2)
)
)
)
)
);
@ -199,4 +238,29 @@ class ScheduleDowntime extends WithChildrenCommand
parent::create();
}
/**
* Change validators at runtime
* @param array $data
*/
protected function preValid(array $data)
{
/*
* Other values needed when downtime type change to flexible
*/
if (isset($data['type']) && $data['type'] === self::TYPE_FLEXIBLE) {
$greaterThanValidator = new Zend_Validate_GreaterThan(-1);
$digitsValidator = new Zend_Validate_Digits();
$hours = $this->getElement('hours');
$hours->setRequired(true);
$hours->addValidator($digitsValidator, true);
$hours->addValidator($greaterThanValidator, true);
$minutes = $this->getElement('minutes');
$minutes->setRequired(true);
$minutes->addValidator($digitsValidator, true);
$minutes->addValidator($greaterThanValidator, true);
}
}
}

View File

@ -122,7 +122,21 @@ class SubmitPassiveCheckResult extends AbstractCommand
'pluginstate',
array(
'label' => t('Plugin state'),
'multiOptions' => $this->getOptions()
'multiOptions' => $this->getOptions(),
'required' => true,
'validators' => array(
array(
'Digits',
true
),
array(
'InArray',
true,
array(
array_keys($this->getOptions())
)
)
)
)
);
@ -131,7 +145,8 @@ class SubmitPassiveCheckResult extends AbstractCommand
'checkoutput',
array(
'label' => t('Check output'),
'rows' => 2
'rows' => 2,
'required' => true
)
);