Merge branch 'fbrendel-monit_validations'

This commit is contained in:
Ad Schellevis 2019-03-01 10:45:57 +01:00
commit 86a5013c15

View File

@ -73,8 +73,22 @@ class Monit extends BaseModel
$parentNode = $node->getParentNode();
// perform plugin specific validations
switch ($parentNode->getInternalXMLTagName()) {
case 'test':
// test node validations
switch ($node->getInternalXMLTagName()) {
case 'type':
$testUuid = $parentNode->getAttribute('uuid');
if ($node->isFieldChanged() && $this->isTestServiceRelated($testUuid)) {
$messages->appendMessage(new \Phalcon\Validation\Message(
gettext("Cannot change the type. Test is linked to a service."),
$key
));
}
break;
}
break;
case 'service':
// service type node validations
// service node validations
switch ($node->getInternalXMLTagName()) {
case 'tests':
// test dependencies defined in $this->testSyntax
@ -186,4 +200,20 @@ class Monit extends BaseModel
{
return @unlink("/tmp/monit.dirty");
}
/**
* determine if services have links to this test node
* @param uuid of the test node
* @return bool
*/
public function isTestServiceRelated($testUUID = null)
{
$serviceNodes = $this->service->getNodes();
foreach ($this->service->iterateItems() as $serviceNode) {
if (in_array($testUUID, explode(',', (string)$serviceNode->tests))) {
return true;
}
}
return false;
}
}