Updates: clean code for whitespace/standards...

...issues as reported by Travis. Add requirement for parent and child host
fields when setting up a Dependency Object (these fields are not necessarily
needed for Templates or Apply Rules). Renamed new table field to
'parent_service_by_name'... which is a bit more descriptive or what that
field is intended for.
This commit is contained in:
Marc DeTrano 2017-08-23 13:39:48 -06:00 committed by Thomas Gelf
parent 6bea1eff41
commit 708edfdebc
12 changed files with 34 additions and 47 deletions

View File

@ -23,7 +23,6 @@ class DependencyController extends ObjectController
$this->db()
);
}
}
protected function loadObject()
@ -54,7 +53,4 @@ class DependencyController extends ObjectController
$form->createApplyRuleFor($this->apply);
}
}
}

View File

@ -99,7 +99,7 @@ class SuggestController extends ActionController
$db = $this->db()->getDbAdapter();
$for_host = $this->getRequest()->getPost('for_host');
if (!empty($for_host)) {
$tmp_host = IcingaHost::load($for_host,$this->db());
$tmp_host = IcingaHost::load($for_host, $this->db());
}
$query = $db->select()->distinct()
@ -107,9 +107,9 @@ class SuggestController extends ActionController
->order('object_name')
->where("object_type IN ('object','apply')");
if (!empty($tmp_host)) {
$query->where('host_id = ?',$tmp_host->id);
$query->where('host_id = ?', $tmp_host->id);
}
$r = array_merge($r,$db->fetchCol($query));
$r = array_merge($r, $db->fetchCol($query));
if (!empty($tmp_host)) {
$resolver = $tmp_host->templateResolver();
foreach ($resolver->fetchResolvedParents() as $template_obj) {
@ -118,7 +118,7 @@ class SuggestController extends ActionController
->order('object_name')
->where("object_type IN ('object','apply')")
->where('host_id = ?', $template_obj->id);
$r = array_merge($r,$db->fetchCol($query));
$r = array_merge($r, $db->fetchCol($query));
}
$matcher = HostApplyMatches::prepare($tmp_host);
@ -127,7 +127,6 @@ class SuggestController extends ActionController
$r[]=$rule->name;
}
}
}
natcasesort($r);
return $r;
@ -288,8 +287,4 @@ class SuggestController extends ActionController
return $db->fetchAll($query);
}
}

View File

@ -14,8 +14,8 @@ class IcingaDependencyForm extends DirectorObjectForm
$this->setupDependencyElements();
}
protected function setupDependencyElements() {
protected function setupDependencyElements()
{
$this->addObjectTypeElement();
if (! $this->hasObjectType()) {
$this->groupMainProperties();
@ -112,7 +112,8 @@ class IcingaDependencyForm extends DirectorObjectForm
return $this;
}
protected function addBooleanElements() {
protected function addBooleanElements()
{
$this->addBoolean(
'disable_checks',
@ -157,6 +158,7 @@ class IcingaDependencyForm extends DirectorObjectForm
'class' => "autosubmit director-suggest",
'data-suggestion-context' => 'hostnames',
'order' => 10,
'required' => $this->isObject(),
'value' => $this->getObject()->get('parent_host')
)
@ -177,10 +179,8 @@ class IcingaDependencyForm extends DirectorObjectForm
'data-suggestion-for-host' => $sent_parent,
'order' => 20,
'value' => $this->getObject()->get('parent_service')
)
);
}
// If configuring Object, allow selection of child host and/or service, otherwise apply rules will determine child object.
@ -196,12 +196,13 @@ class IcingaDependencyForm extends DirectorObjectForm
'class' => "autosubmit director-suggest",
'data-suggestion-context' => 'hostnames',
'order' => 30,
'required' => $this->isObject(),
'value' => $this->getObject()->get('child_host')
)
);
$sent_child=$this->getSentOrObjectValue("child_host");
if (!empty($sent_child)) {
$this->addElement(
'text',
@ -216,11 +217,8 @@ class IcingaDependencyForm extends DirectorObjectForm
'data-suggestion-for-host' => $sent_child,
'order' => 40,
'value' => $this->getObject()->get('child_service')
)
);
}
}
@ -247,6 +245,4 @@ class IcingaDependencyForm extends DirectorObjectForm
$object->object_name = $dependency->object_name;
return $this;
}
}

View File

@ -50,7 +50,6 @@ class IcingaDependencyTable extends IcingaObjectTable
array('apply' => $row->dependency, 'type' => 'apply'),
array('class' => 'icon-plus')
);
} else {
$htm .= '. Related apply rules: <ul class="apply-rules">';
foreach ($extra as $id => $dependency) {

View File

@ -8,7 +8,6 @@ use Icinga\Exception\NotFoundError;
use Icinga\Data\Filter\Filter;
use Icinga\Module\Director\Objects\HostApplyMatches;
class IcingaDependency extends IcingaObject
{
protected $table = 'icinga_dependency';
@ -29,7 +28,7 @@ class IcingaDependency extends IcingaObject
'period_id' => null,
'zone_id' => null,
'assign_filter' => null,
'parent_service_s' => null,
'parent_service_by_name' => null,
);
protected $supportsCustomVars = false;
@ -88,7 +87,6 @@ class IcingaDependency extends IcingaObject
c::renderString($this->getObjectName()),
ucfirst($to)
);
} else {
return parent::renderObjectHeader();
}
@ -114,13 +112,13 @@ class IcingaDependency extends IcingaObject
protected function renderAssignments()
{
if ($this->hasBeenAssignedToServiceApply()) {
$tmpService= $this->getRelatedObject('child_service', $this->child_service_id);
$assigns = $tmpService->assignments()->toConfigString();
$filter = sprintf(
'%s && service.name == "%s"',
trim($assigns), $this->child_service
trim($assigns),
$this->child_service
);
return "\n " . $filter . "\n";
}
@ -128,7 +126,8 @@ class IcingaDependency extends IcingaObject
if ($this->hasBeenAssignedToHostTemplateService()) {
$filter = sprintf(
'assign where "%s" in host.templates && service.name == "%s"',
$this->child_host, $this->child_service
$this->child_host,
$this->child_service
);
return "\n " . $filter . "\n";
}
@ -177,7 +176,9 @@ class IcingaDependency extends IcingaObject
protected function hasBeenAssignedToHostTemplateService()
{
if (!$this->hasBeenAssignedToHostTemplate()) return false;
if (!$this->hasBeenAssignedToHostTemplate()) {
return false;
}
try {
return $this->child_service_id && $this->getRelatedObject(
'child_service',
@ -276,9 +277,9 @@ class IcingaDependency extends IcingaObject
}
//special case for parent service set as plain string for Apply rules
public function renderParent_service_s()
public function renderParent_service_by_name()
{
return "\n parent_service_name = \"" . $this->parent_service_s ."\"\n";
return "\n parent_service_name = \"" . $this->parent_service_by_name ."\"\n";
}
public function isApplyRule()
@ -311,14 +312,14 @@ class IcingaDependency extends IcingaObject
if ($class == "Icinga\Module\Director\Objects\IcingaService" ) {
if ($name == "parent_service_id" && $this->object_type == 'apply' ) { //special case , parent service can be set as simple string for Apply
if ($this->properties['parent_host_id']==null) {
$this->reallySet('parent_service_s', $this->unresolvedRelatedProperties[$name]);
$this->reallySet('parent_service_by_name', $this->unresolvedRelatedProperties[$name]);
$this->reallySet('parent_service_id',null);
unset($this->unresolvedRelatedProperties[$name]);
return;
}
}
$this->reallySet('parent_service_s',null);
$this->reallySet('parent_service_by_name',null);
$host_id_prop=str_replace("service","host",$name);
if (isset($this->properties[$host_id_prop])) {
$obj_key=array("host_id" => $this->properties[$host_id_prop], "object_name" => $this->unresolvedRelatedProperties[$name]);
@ -410,8 +411,8 @@ class IcingaDependency extends IcingaObject
return $object->get('object_name');
} else {
// handle special case for plain string parent service on Dependency Apply rules
if ($key == 'parent_service' && $this->get('parent_service_s') != null) {
return $this->get('parent_service_s');
if ($key == 'parent_service' && $this->get('parent_service_by_name') != null) {
return $this->get('parent_service_by_name');
}
}

View File

@ -2699,7 +2699,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
public function getOnDeleteUrl()
{
$plural= preg_replace('/cys$/','cies', strtolower($this->getShortTableName()) . 's');
$plural= preg_replace('/cys$/', 'cies', strtolower($this->getShortTableName()) . 's');
return 'director/' . $plural;
}

View File

@ -9,7 +9,7 @@ class TemplateActionBar extends DirectorBaseActionBar
protected function assemble()
{
$type = $this->type;
$pltype = preg_replace('/cys$/','cies', $type . 's');
$pltype = preg_replace('/cys$/', 'cies', $type . 's');
$renderTree = $this->url->getParam('render') === 'tree';
$renderParams = $renderTree ? null : ['render' => 'tree'];
$this->add(

View File

@ -306,11 +306,11 @@ abstract class ObjectsController extends ActionController
protected function getPluralType()
{
return preg_replace("/cys$/","cies",$this->getType() . 's');
return preg_replace("/cys$/", "cies", $this->getType() . 's');
}
protected function getPluralBaseType()
{
return preg_replace("/cys$/","cies",$this->getBaseType() . 's');
return preg_replace("/cys$/", "cies", $this->getBaseType() . 's');
}
}

View File

@ -177,7 +177,7 @@ abstract class TemplateController extends CompatController
protected function getPluralType()
{
return preg_replace('/cys$/','cies',$this->template()->getShortTableName() . 's');
return preg_replace('/cys$/', 'cies', $this->template()->getShortTableName() . 's');
}
protected function getTranslatedType()

View File

@ -18,7 +18,7 @@ class ObjectsTabs extends Tabs
$object = IcingaObject::createByType(substr($type, 0, -5));
}
$pltype=strtolower(preg_replace('/cys$/','cies',$type . 's'));
$pltype=strtolower(preg_replace('/cys$/', 'cies', $type . 's'));
if ($auth->hasPermission("director/${pltype}")) {
$this->add('index', array(
'url' => sprintf('director/%s', $pltype),

View File

@ -1,2 +1,2 @@
ALTER TABLE icinga_dependency ADD COLUMN parent_service_s VARCHAR(255);
ALTER TABLE icinga_dependency ADD COLUMN parent_service_by_name VARCHAR(255);

View File

@ -1591,7 +1591,7 @@ CREATE TABLE icinga_dependency (
period_id INT(10) UNSIGNED DEFAULT NULL,
zone_id INT(10) UNSIGNED DEFAULT NULL,
assign_filter TEXT DEFAULT NULL,
parent_service_s VARCHAR(255) DEFAULT NULL,
parent_service_by_name VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (id),
CONSTRAINT icinga_dependency_parent_host
FOREIGN KEY parent_host (parent_host_id)