diff --git a/application/tables/ActivityLogTable.php b/application/tables/ActivityLogTable.php index 00db39cd..8ea86504 100644 --- a/application/tables/ActivityLogTable.php +++ b/application/tables/ActivityLogTable.php @@ -16,7 +16,8 @@ class ActivityLogTable extends QuickTable 'id' => 'l.id', 'change_time' => 'l.change_time', 'author' => 'l.author', - 'action' => "CONCAT(l.action_name || ' ' || REPLACE(l.object_type, 'icinga_', '') || ' \"' || l.object_name || '\"')" + 'action' => "CONCAT(l.action_name || ' ' || REPLACE(l.object_type, 'icinga_', '')" + . " || ' \"' || l.object_name || '\"')" ); } @@ -24,8 +25,8 @@ class ActivityLogTable extends QuickTable { return $this->url( 'director/show/activitylog', - array_merge(array('id' => $row->id), $this->extraParams - )); + array_merge(array('id' => $row->id), $this->extraParams) + ); } public function getTitles() diff --git a/application/tables/IcingaEndpointTable.php b/application/tables/IcingaEndpointTable.php index 5816d33e..e66f7358 100644 --- a/application/tables/IcingaEndpointTable.php +++ b/application/tables/IcingaEndpointTable.php @@ -16,7 +16,8 @@ class IcingaEndpointTable extends IcingaObjectTable 'id' => 'e.id', 'endpoint' => 'e.object_name', 'object_type' => 'e.object_type', - 'host' => "(CASE WHEN e.host IS NULL THEN NULL ELSE CONCAT(e.host || ':' || COALESCE(e.port, 5665)) END)", + 'host' => "(CASE WHEN e.host IS NULL THEN NULL ELSE" + . " CONCAT(e.host || ':' || COALESCE(e.port, 5665)) END)", 'zone' => 'z.object_name', ); } diff --git a/configuration.php b/configuration.php index 61645f53..d0decbe6 100644 --- a/configuration.php +++ b/configuration.php @@ -16,7 +16,6 @@ $this->provideRestriction( $this->translate('Allow to use only these db resources (comma separated list)') ); - $this->provideConfigTab('config', array( 'title' => 'Configuration', 'url' => 'settings' @@ -43,4 +42,3 @@ $section->add($this->translate('Config')) ->setUrl('director/list/deploymentlog') ->setPriority(902) ->setRenderer('ConfigHealthItemRenderer'); - diff --git a/library/Director/Core/RestApiClient.php b/library/Director/Core/RestApiClient.php index 1c863d68..3886819e 100644 --- a/library/Director/Core/RestApiClient.php +++ b/library/Director/Core/RestApiClient.php @@ -159,6 +159,7 @@ class RestApiClient } curl_setopt_array($curl, $opts); + // TODO: request headers, validate status code Benchmark::measure('Rest Api, sending ' . $url); $res = curl_exec($curl); @@ -236,7 +237,7 @@ class RestApiClient $str = substr($this->readBuffer, $offset, $pos); $decoded = json_decode($str); if ($decoded === false) { - throw new Exception('Got invalid JSON: ' . $str); + throw new Exception('Got invalid JSON: ' . $str); } // printf("Processing %s bytes\n", strlen($str)); diff --git a/library/Director/CoreBeta/Stream.php b/library/Director/CoreBeta/Stream.php index c8d1c0a1..5add9a38 100644 --- a/library/Director/CoreBeta/Stream.php +++ b/library/Director/CoreBeta/Stream.php @@ -14,5 +14,4 @@ abstract class Stream { $this->stream = $stream; } - } diff --git a/library/Director/CustomVariable/CustomVariable.php b/library/Director/CustomVariable/CustomVariable.php index 3ee08f28..de96518f 100644 --- a/library/Director/CustomVariable/CustomVariable.php +++ b/library/Director/CustomVariable/CustomVariable.php @@ -165,7 +165,7 @@ abstract class CustomVariable implements IcingaConfigRenderer public static function fromDbRow($row) { - switch($row->format) { + switch ($row->format) { case 'string': $var = new CustomVariableString($row->varname, $row->varvalue); break; @@ -194,7 +194,10 @@ abstract class CustomVariable implements IcingaConfigRenderer return $this->toConfigString(); } catch (Exception $e) { trigger_error($e); - $previousHandler = set_exception_handler(function () {}); + $previousHandler = set_exception_handler( + function () { + } + ); restore_error_handler(); call_user_func($previousHandler, $e); die(); diff --git a/library/Director/CustomVariable/CustomVariableBoolean.php b/library/Director/CustomVariable/CustomVariableBoolean.php index 347e208e..50fbc9f7 100644 --- a/library/Director/CustomVariable/CustomVariableBoolean.php +++ b/library/Director/CustomVariable/CustomVariableBoolean.php @@ -38,7 +38,7 @@ class CustomVariableBoolean extends CustomVariable $this->value = $value; return $this; - } + } public function toConfigString() { diff --git a/library/Director/CustomVariable/CustomVariableNull.php b/library/Director/CustomVariable/CustomVariableNull.php index 9a4bf45d..1685fb99 100644 --- a/library/Director/CustomVariable/CustomVariableNull.php +++ b/library/Director/CustomVariable/CustomVariableNull.php @@ -37,7 +37,7 @@ class CustomVariableNull extends CustomVariable } return $this; - } + } public function toConfigString() { diff --git a/library/Director/CustomVariable/CustomVariableNumber.php b/library/Director/CustomVariable/CustomVariableNumber.php index d5ae5ccb..04440875 100644 --- a/library/Director/CustomVariable/CustomVariableNumber.php +++ b/library/Director/CustomVariable/CustomVariableNumber.php @@ -51,7 +51,7 @@ class CustomVariableNumber extends CustomVariable $this->value = $value; return $this; - } + } public function toConfigString() { diff --git a/library/Director/CustomVariable/CustomVariableString.php b/library/Director/CustomVariable/CustomVariableString.php index fdd73804..bda99a75 100644 --- a/library/Director/CustomVariable/CustomVariableString.php +++ b/library/Director/CustomVariable/CustomVariableString.php @@ -32,7 +32,7 @@ class CustomVariableString extends CustomVariable } return $this; - } + } public function toConfigString() { diff --git a/library/Director/CustomVariable/CustomVariables.php b/library/Director/CustomVariable/CustomVariables.php index 0223564f..26d06ded 100644 --- a/library/Director/CustomVariable/CustomVariables.php +++ b/library/Director/CustomVariable/CustomVariables.php @@ -269,7 +269,10 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer return $this->toConfigString(); } catch (Exception $e) { trigger_error($e); - $previousHandler = set_exception_handler(function () {}); + $previousHandler = set_exception_handler( + function () { + } + ); restore_error_handler(); call_user_func($previousHandler, $e); die(); diff --git a/library/Director/Data/Db/DbObject.php b/library/Director/Data/Db/DbObject.php index 4d70fc91..00296323 100644 --- a/library/Director/Data/Db/DbObject.php +++ b/library/Director/Data/Db/DbObject.php @@ -130,7 +130,9 @@ abstract class DbObject * * @return void */ - protected function beforeInit() {} + protected function beforeInit() + { + } /** * Wird ausgeführt, nachdem mittels ::factory() ein neues Objekt erstellt @@ -138,7 +140,9 @@ abstract class DbObject * * @return void */ - protected function onFactory() {} + protected function onFactory() + { + } /** * Wird ausgeführt, nachdem mittels ::factory() ein neues Objekt erstellt @@ -146,7 +150,9 @@ abstract class DbObject * * @return void */ - protected function onLoadFromDb() {} + protected function onLoadFromDb() + { + } /** * Wird ausgeführt, bevor ein Objekt abgespeichert wird. Die Operation @@ -154,14 +160,18 @@ abstract class DbObject * * @return void */ - protected function beforeStore() {} + protected function beforeStore() + { + } /** * Wird ausgeführt, nachdem ein Objekt erfolgreich gespeichert worden ist * * @return void */ - protected function onStore() {} + protected function onStore() + { + } /** * Wird ausgeführt, nachdem ein Objekt erfolgreich der Datenbank hinzu- @@ -169,7 +179,9 @@ abstract class DbObject * * @return void */ - protected function onInsert() {} + protected function onInsert() + { + } /** * Wird ausgeführt, nachdem bestehendes Objekt erfolgreich der Datenbank @@ -177,7 +189,9 @@ abstract class DbObject * * @return void */ - protected function onUpdate() {} + protected function onUpdate() + { + } /** * Wird ausgeführt, bevor ein Objekt gelöscht wird. Die Operation wird @@ -185,7 +199,9 @@ abstract class DbObject * * @return void */ - protected function beforeDelete() {} + protected function beforeDelete() + { + } /** * Wird ausgeführt, nachdem bestehendes Objekt erfolgreich aud der @@ -193,7 +209,9 @@ abstract class DbObject * * @return void */ - protected function onDelete() {} + protected function onDelete() + { + } /** * Set database connection @@ -394,7 +412,10 @@ abstract class DbObject { $props = array(); foreach (array_keys($this->modifiedProperties) as $key) { - if ($key === $this->autoincKeyName) continue; + if ($key === $this->autoincKeyName) { + continue; + } + $props[$key] = $this->properties[$key]; } return $props; @@ -475,9 +496,8 @@ abstract class DbObject $id[$key] = $this->properties[$key]; } return $id; - } else { - if (isset($this->properties[$this->keyName])) - { + } else { + if (isset($this->properties[$this->keyName])) { return $this->properties[$this->keyName]; } } @@ -491,8 +511,7 @@ abstract class DbObject */ public function getAutoincId() { - if (isset($this->properties[$this->autoincKeyName])) - { + if (isset($this->properties[$this->autoincKeyName])) { return $this->properties[$this->autoincKeyName]; } return null; diff --git a/library/Director/Db.php b/library/Director/Db.php index b1b0eb77..424e9f02 100644 --- a/library/Director/Db.php +++ b/library/Director/Db.php @@ -162,7 +162,7 @@ class Db extends DbConnection array( 'prev' => 'lt.id', 'next' => 'gt.id' - ) + ) )->join( array('lt' => $smaller), null, @@ -227,9 +227,13 @@ class Db extends DbConnection public function getLastActivityChecksum() { if ($this->getDbType() === 'pgsql') { - $select = "SELECT checksum FROM (SELECT * FROM (SELECT 1 AS pos, LOWER(ENCODE(checksum, 'hex')) AS checksum FROM director_activity_log ORDER BY change_time DESC LIMIT 1) a UNION SELECT 2 AS pos, '' AS checksum) u ORDER BY pos LIMIT 1"; + $select = "SELECT checksum FROM (SELECT * FROM (SELECT 1 AS pos, LOWER(ENCODE(checksum, 'hex')) AS checksum" + . " FROM director_activity_log ORDER BY change_time DESC LIMIT 1) a" + . " UNION SELECT 2 AS pos, '' AS checksum) u ORDER BY pos LIMIT 1"; } else { - $select = "SELECT checksum FROM (SELECT * FROM (SELECT 1 AS pos, LOWER(HEX(checksum)) AS checksum FROM director_activity_log ORDER BY change_time DESC LIMIT 1) a UNION SELECT 2 AS pos, '' AS checksum) u ORDER BY pos LIMIT 1"; + $select = "SELECT checksum FROM (SELECT * FROM (SELECT 1 AS pos, LOWER(HEX(checksum)) AS checksum" + . " FROM director_activity_log ORDER BY change_time DESC LIMIT 1) a" + . " UNION SELECT 2 AS pos, '' AS checksum) u ORDER BY pos LIMIT 1"; } return $this->db()->fetchOne($select); diff --git a/library/Director/Db/Migrations.php b/library/Director/Db/Migrations.php index 7872aef3..169c104a 100644 --- a/library/Director/Db/Migrations.php +++ b/library/Director/Db/Migrations.php @@ -41,12 +41,12 @@ class Migrations } public function hasPendingMigrations() - { + { return $this->countPendingMigrations() > 0; } public function countPendingMigrations() - { + { return count($this->listPendingMigrations()); } @@ -92,7 +92,10 @@ class Migrations $versions = array(); foreach (new DirectoryIterator($this->getMigrationsDir()) as $file) { - if($file->isDot()) continue; + if ($file->isDot()) { + continue; + } + $filename = $file->getFilename(); if (preg_match('/^upgrade_(\d+)\.sql$/', $filename, $match)) { $versions[] = $match[1]; diff --git a/library/Director/Hook/ImportSourceHook.php b/library/Director/Hook/ImportSourceHook.php index d2dfcc0d..dc404646 100644 --- a/library/Director/Hook/ImportSourceHook.php +++ b/library/Director/Hook/ImportSourceHook.php @@ -64,7 +64,8 @@ abstract class ImportSourceHook return $this; } - public function getSetting($name, $default = null) { + public function getSetting($name, $default = null) + { if (array_key_exists($name, $this->settings)) { return $this->settings[$name]; } else { diff --git a/library/Director/IcingaConfig/IcingaConfig.php b/library/Director/IcingaConfig/IcingaConfig.php index 84529c10..56585186 100644 --- a/library/Director/IcingaConfig/IcingaConfig.php +++ b/library/Director/IcingaConfig/IcingaConfig.php @@ -276,8 +276,7 @@ class IcingaConfig $this->db->commit(); } catch (Exception $e) { $this->db->rollBack(); -throw $e; - var_dump($e->getMessage()); + throw $e; } return $this; @@ -373,10 +372,18 @@ throw $e; $zones = array(); $endpoints = array(); foreach (IcingaHost::prefetchAll($this->connection) as $host) { - if ($host->object_type !== 'object') continue; - if ($host->getResolvedProperty('has_agent') !== 'y') continue; + if ($host->object_type !== 'object') { + continue; + } + + if ($host->getResolvedProperty('has_agent') !== 'y') { + continue; + } + $name = $host->object_name; - if (IcingaEndpoint::exists($name, $this->connection)) continue; + if (IcingaEndpoint::exists($name, $this->connection)) { + continue; + } $props = array( 'object_name' => $name, @@ -411,18 +418,24 @@ throw $e; protected function createFileForObjects($type, $objects) { Benchmark::measure(sprintf('Generating %d %s', count($objects), $type)); - if (empty($objects)) return $this; + if (empty($objects)) { + return $this; + } + $masterZone = $this->connection->getMasterZoneName(); $globalZone = $this->connection->getDefaultGlobalZoneName(); $file = null; foreach ($objects as $object) { - if ($object->disabled === 'y') continue; + if ($object->disabled === 'y') { + continue; + } if ($object->isExternal()) { if ($type === 'zone') { $this->zoneMap[$object->id] = $object->object_name; } + continue; } elseif ($object->isTemplate()) { $filename = strtolower($type) . '_templates'; @@ -557,6 +570,7 @@ throw $e; } // TODO: wipe unused files - // DELETE f FROM director_generated_file f left join director_generated_config_file cf ON f.checksum = cf.file_checksum WHERE cf.file_checksum IS NULL; - + // DELETE f FROM director_generated_file f + // LEFT JOIN director_generated_config_file cf ON f.checksum = cf.file_checksum + // WHERE cf.file_checksum IS NULL; } diff --git a/library/Director/Import/Sync.php b/library/Director/Import/Sync.php index 3062981e..1ac59119 100644 --- a/library/Director/Import/Sync.php +++ b/library/Director/Import/Sync.php @@ -455,7 +455,9 @@ class Sync ) as $object) { if ($object instanceof IcingaService) { - if (! $object->host_id) continue; + if (! $object->host_id) { + continue; + } } $key = $this->fillVariables( @@ -502,7 +504,9 @@ class Sync $imports = array(); foreach ($this->syncProperties as $p) { - if ($p->source_id !== $sourceId) continue; + if ($p->source_id !== $sourceId) { + continue; + } $prop = $p->destination_field; $val = $this->fillVariables($p->source_expression, $row); diff --git a/library/Director/KickstartHelper.php b/library/Director/KickstartHelper.php index 3aa98047..abe08f27 100644 --- a/library/Director/KickstartHelper.php +++ b/library/Director/KickstartHelper.php @@ -16,11 +16,11 @@ class KickstartHelper protected $apiUser; protected $config = array( - 'endpoint' => null, - 'host' => null, - 'port' => null, - 'username' => null, - 'password' => null, + 'endpoint' => null, + 'host' => null, + 'port' => null, + 'username' => null, + 'password' => null, ); public function __construct(Db $db) diff --git a/library/Director/Objects/IcingaArguments.php b/library/Director/Objects/IcingaArguments.php index 8d9e85e1..3d1697c8 100644 --- a/library/Director/Objects/IcingaArguments.php +++ b/library/Director/Objects/IcingaArguments.php @@ -261,7 +261,10 @@ class IcingaArguments implements Iterator, Countable, IcingaConfigRenderer return $this->toConfigString(); } catch (Exception $e) { trigger_error($e); - $previousHandler = set_exception_handler(function () {}); + $previousHandler = set_exception_handler( + function () { + } + ); restore_error_handler(); if ($previousHandler !== null) { call_user_func($previousHandler, $e); diff --git a/library/Director/Objects/IcingaCommand.php b/library/Director/Objects/IcingaCommand.php index 646a26fd..2d57e9f4 100644 --- a/library/Director/Objects/IcingaCommand.php +++ b/library/Director/Objects/IcingaCommand.php @@ -31,9 +31,19 @@ class IcingaCommand extends IcingaObject protected static $pluginDir; + /** + * Render the 'medhods_execute' property as 'execute' + * + * Execute is a reserved word in SQL, column name was prefixed + * + * Avoid complaints for method names with underscore: + * @codingStandardsIgnoreStart + * + * @return string + */ protected function renderMethods_execute() { - // Execute is a reserved word in SQL, column name was prefixed + // @codingStandardsIgnoreEnd return c::renderKeyValue('execute', $this->methods_execute); } diff --git a/library/Director/Objects/IcingaEndpoint.php b/library/Director/Objects/IcingaEndpoint.php index ba16681e..92169673 100644 --- a/library/Director/Objects/IcingaEndpoint.php +++ b/library/Director/Objects/IcingaEndpoint.php @@ -58,13 +58,31 @@ class IcingaEndpoint extends IcingaObject return new CoreApi($client); } + /** + * Use duration time renderer helper + * + * Avoid complaints for method names with underscore: + * @codingStandardsIgnoreStart + * + * @return string + */ protected function renderLog_duration() { + // @codingStandardsIgnoreEnd return $this->renderPropertyAsSeconds('log_duration'); } + /** + * Internal property, will not be rendered + * + * Avoid complaints for method names with underscore: + * @codingStandardsIgnoreStart + * + * @return string + */ protected function renderApiuser_id() { + // @codingStandardsIgnoreEnd return ''; } } diff --git a/library/Director/Objects/IcingaHost.php b/library/Director/Objects/IcingaHost.php index f693a445..ebae4d96 100644 --- a/library/Director/Objects/IcingaHost.php +++ b/library/Director/Objects/IcingaHost.php @@ -112,18 +112,37 @@ class IcingaHost extends IcingaObject return $this->getResolvedProperty('check_command_id') !== null; } + /** + * Internal property, will not be rendered + * + * Avoid complaints for method names with underscore: + * @codingStandardsIgnoreStart + * + * @return string + */ protected function renderHas_Agent() { return ''; } + /** + * Internal property, will not be rendered + * + * @return string + */ protected function renderMaster_should_connect() { return ''; } + /** + * Internal property, will not be rendered + * + * @return string + */ protected function renderAccept_config() { + // @codingStandardsIgnoreEnd return ''; } } diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index 8e3fa1ce..f82774b1 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -483,7 +483,9 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer $origins = $object->$getOrigins(); foreach ($object->$getInherited() as $key => $value) { - if (in_array($key, $blacklist)) continue; + if (in_array($key, $blacklist)) { + continue; + } // $vals[$name]->$key = $value; $vals['_MERGED_']->$key = $value; $vals['_INHERITED_']->$key = $value; @@ -500,7 +502,9 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer } foreach ($this->$get() as $key => $value) { - if ($value === null) continue; + if ($value === null) { + continue; + } // $vals[$this->object_name]->$key = $value; $vals['_MERGED_']->$key = $value; @@ -807,8 +811,12 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer foreach ($this->properties as $key => $value) { - if ($value === null) continue; - if (in_array($key, $blacklist)) continue; + if ($value === null) { + continue; + } + if (in_array($key, $blacklist)) { + continue; + } $method = 'render' . ucfirst($key); if (method_exists($this, $method)) { @@ -821,8 +829,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer c::renderBoolean($value) ); } - } elseif ( - substr($key, -3) === '_id' + } elseif (substr($key, -3) === '_id' && $this->hasRelation($relKey = substr($key, 0, -3)) ) { $out .= $this->renderRelationProperty($relKey, $value); @@ -949,9 +956,17 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer ); } + /** + * We do not render zone properties, objects are stored to zone dirs + * + * Avoid complaints for method names with underscore: + * @codingStandardsIgnoreStart + * + * @return string + */ protected function renderZone_id() { - // We do not render zone properties, objects are stored to zone dirs + // @codingStandardsIgnoreEnd return ''; } @@ -1194,11 +1209,17 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer } if ($skipDefaults) { - if (empty($props['imports'])) unset($props['imports']); - if (array_key_exists('vars', $props)) { - if (count((array) $props['vars']) === 0) unset($props['vars']); + if (empty($props['imports'])) { + unset($props['imports']); + } + if (array_key_exists('vars', $props)) { + if (count((array) $props['vars']) === 0) { + unset($props['vars']); + } + } + if (empty($props['groups'])) { + unset($props['groups']); } - if (empty($props['groups'])) unset($props['groups']); } ksort($props); @@ -1278,7 +1299,10 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer return $this->toConfigString(); } catch (Exception $e) { trigger_error($e); - $previousHandler = set_exception_handler(function () {}); + $previousHandler = set_exception_handler( + function () { + } + ); restore_error_handler(); if ($previousHandler !== null) { call_user_func($previousHandler, $e); diff --git a/library/Director/Objects/IcingaObjectGroups.php b/library/Director/Objects/IcingaObjectGroups.php index 7d08e6f2..479cd2c5 100644 --- a/library/Director/Objects/IcingaObjectGroups.php +++ b/library/Director/Objects/IcingaObjectGroups.php @@ -317,7 +317,10 @@ class IcingaObjectGroups implements Iterator, Countable, IcingaConfigRenderer return $this->toConfigString(); } catch (Exception $e) { trigger_error($e); - $previousHandler = set_exception_handler(function () {}); + $previousHandler = set_exception_handler( + function () { + } + ); restore_error_handler(); if ($previousHandler !== null) { call_user_func($previousHandler, $e); diff --git a/library/Director/Objects/IcingaObjectImports.php b/library/Director/Objects/IcingaObjectImports.php index c321604a..fd1e2945 100644 --- a/library/Director/Objects/IcingaObjectImports.php +++ b/library/Director/Objects/IcingaObjectImports.php @@ -300,7 +300,10 @@ class IcingaObjectImports implements Iterator, Countable, IcingaConfigRenderer return $this->toConfigString(); } catch (Exception $e) { trigger_error($e); - $previousHandler = set_exception_handler(function () {}); + $previousHandler = set_exception_handler( + function () { + } + ); restore_error_handler(); if ($previousHandler !== null) { call_user_func($previousHandler, $e); diff --git a/library/Director/Objects/IcingaService.php b/library/Director/Objects/IcingaService.php index ae4220b7..eb2dea41 100644 --- a/library/Director/Objects/IcingaService.php +++ b/library/Director/Objects/IcingaService.php @@ -78,32 +78,70 @@ class IcingaService extends IcingaObject ); } + /** + * Render host_id as host_name + * + * Avoid complaints for method names with underscore: + * @codingStandardsIgnoreStart + * + * @return string + */ public function renderHost_id() { + // @codingStandardsIgnoreEnd return $this->renderRelationProperty('host', $this->host_id, 'host_name'); } protected function renderCustomExtensions() { - if ($this->command_endpoint_id !== null) return ''; - if ($this->object_type !== 'object') return ''; - if ($this->getResolvedProperty('use_agent') !== 'y') return ''; + if ($this->command_endpoint_id !== null + || $this->object_type !== 'object' + || $this->getResolvedProperty('use_agent') !== 'y') { + return ''; + } return $this->renderRelationProperty('host', $this->host_id, 'command_endpoint'); } + /** + * Do not render internal property + * + * Avoid complaints for method names with underscore: + * @codingStandardsIgnoreStart + * + * @return string + */ public function renderUse_agent() { + // @codingStandardsIgnoreEnd return ''; } + /** + * Use duration time renderer helper + * + * Avoid complaints for method names with underscore: + * @codingStandardsIgnoreStart + * + * @return string + */ protected function renderCheck_Interval() { + // @codingStandardsIgnoreEnd return $this->renderPropertyAsSeconds('check_interval'); } + /** + * Use duration time renderer helper + * + * Avoid complaints for method names with underscore: + * @codingStandardsIgnoreStart + * + * @return string + */ protected function renderRetry_Interval() { + // @codingStandardsIgnoreEnd return $this->renderPropertyAsSeconds('retry_interval'); } diff --git a/library/Director/Objects/IcingaTimePeriodRanges.php b/library/Director/Objects/IcingaTimePeriodRanges.php index 4e20195d..7e17b7f3 100644 --- a/library/Director/Objects/IcingaTimePeriodRanges.php +++ b/library/Director/Objects/IcingaTimePeriodRanges.php @@ -237,7 +237,10 @@ class IcingaTimePeriodRanges implements Iterator, Countable, IcingaConfigRendere return $this->toConfigString(); } catch (Exception $e) { trigger_error($e); - $previousHandler = set_exception_handler(function () {}); + $previousHandler = set_exception_handler( + function () { + } + ); restore_error_handler(); if ($previousHandler !== null) { call_user_func($previousHandler, $e); diff --git a/library/Director/Objects/IcingaUser.php b/library/Director/Objects/IcingaUser.php index 4732414b..a7f9053c 100644 --- a/library/Director/Objects/IcingaUser.php +++ b/library/Director/Objects/IcingaUser.php @@ -25,8 +25,7 @@ class IcingaUser extends IcingaObject protected $supportsImports = true; - protected function renderEnable_notifications() - { - return $this->renderBooleanProperty('enable_notifications'); - } + protected $booleans = array( + 'enable_notifications'x => 'enable_notifications' + ); } diff --git a/library/Director/Objects/ImportSource.php b/library/Director/Objects/ImportSource.php index 4b4d117b..8cdc12ca 100644 --- a/library/Director/Objects/ImportSource.php +++ b/library/Director/Objects/ImportSource.php @@ -34,5 +34,4 @@ class ImportSource extends DbObjectWithSettings ->order('priority DESC') ); } - } diff --git a/library/Director/Objects/SyncProperty.php b/library/Director/Objects/SyncProperty.php index ec916032..13abc16e 100644 --- a/library/Director/Objects/SyncProperty.php +++ b/library/Director/Objects/SyncProperty.php @@ -13,20 +13,31 @@ class SyncProperty extends DbObject protected $autoincKeyName = 'id'; protected $defaultProperties = array( - 'id' => null, - 'rule_id' => null, - 'source_id' => null, + 'id' => null, + 'rule_id' => null, + 'source_id' => null, 'source_expression' => null, - 'destination_field' => null, - 'priority' => null, - 'filter_expression' => null, - 'merge_policy' => null + 'destination_field' => null, + 'priority' => null, + 'filter_expression' => null, + 'merge_policy' => null ); + /** + * Virtual property for source_column + * + * Internally we always use an expression. Form indirectly uses this + * + * Avoid complaints for method names with underscore: + * @codingStandardsIgnoreStart + * + * @return self + */ public function setSource_column($value) { + // @codingStandardsIgnoreEnd $this->source_expression = '${' . $value . '}'; - return $this; + return $this; } public function sourceIsSingleColumn() diff --git a/library/Director/Objects/SyncRule.php b/library/Director/Objects/SyncRule.php index 7cce6cb4..f26bd043 100644 --- a/library/Director/Objects/SyncRule.php +++ b/library/Director/Objects/SyncRule.php @@ -14,12 +14,12 @@ class SyncRule extends DbObject protected $autoincKeyName = 'id'; protected $defaultProperties = array( - 'id' => null, - 'rule_name' => null, - 'object_type' => null, + 'id' => null, + 'rule_name' => null, + 'object_type' => null, 'update_policy' => null, - 'purge_existing' => null, - 'filter_expression' => null, + 'purge_existing' => null, + 'filter_expression' => null, ); private $filter; diff --git a/library/Director/PlainObjectRenderer.php b/library/Director/PlainObjectRenderer.php index 19f9278c..8257357f 100644 --- a/library/Director/PlainObjectRenderer.php +++ b/library/Director/PlainObjectRenderer.php @@ -44,7 +44,9 @@ class PlainObjectRenderer protected static function renderArray($array, $prefix = '') { - if (empty($array)) return '[]'; + if (empty($array)) { + return '[]'; + } $vals = array(); @@ -60,7 +62,10 @@ class PlainObjectRenderer { $vals = array(); $hash = (array) $hash; - if (empty($hash)) return '{}'; + if (empty($hash)) { + return '{}'; + } + ksort($hash); foreach ($hash as $key => $val) { $vals[] = $prefix diff --git a/library/Director/Util.php b/library/Director/Util.php index aa449ae5..142ca13c 100644 --- a/library/Director/Util.php +++ b/library/Director/Util.php @@ -63,7 +63,7 @@ class Util $out = ''; - for($i = 1; $i <= $blocks; $i++) { + for ($i = 1; $i <= $blocks; $i++) { // $i encoded as 4 bytes, big endian. $last = $salt . pack('N', $i); // first iteration diff --git a/library/Director/Web/Controller/ActionController.php b/library/Director/Web/Controller/ActionController.php index 338bb772..d71724c2 100644 --- a/library/Director/Web/Controller/ActionController.php +++ b/library/Director/Web/Controller/ActionController.php @@ -69,7 +69,7 @@ abstract class ActionController extends Controller protected function sendJson($object) { $this->getResponse()->setHeader('Content-Type', 'application/json', true); - $this->_helper->layout()->disableLayout(); + $this->_helper->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); if (version_compare(PHP_VERSION, '5.4.0') >= 0) { echo json_encode($object, JSON_PRETTY_PRINT) . "\n"; @@ -89,36 +89,60 @@ abstract class ActionController extends Controller protected function setConfigTabs() { - $this->view->tabs = Widget::create('tabs')->add('deploymentlog', array( - 'label' => $this->translate('Deployments'), - 'url' => 'director/list/deploymentlog') - )->add('generatedconfig', array( - 'label' => $this->translate('Configs'), - 'url' => 'director/list/generatedconfig') - )->add('activitylog', array( - 'label' => $this->translate('Activity Log'), - 'url' => 'director/list/activitylog') - )->add('datalist', array( - 'label' => $this->translate('Data lists'), - 'url' => 'director/list/datalist') - )->add('datafield', array( - 'label' => $this->translate('Data fields'), - 'url' => 'director/list/datafield') + $this->view->tabs = Widget::create('tabs')->add( + 'deploymentlog', + array( + 'label' => $this->translate('Deployments'), + 'url' => 'director/list/deploymentlog' + ) + )->add( + 'generatedconfig', + array( + 'label' => $this->translate('Configs'), + 'url' => 'director/list/generatedconfig' + ) + )->add( + 'activitylog', + array( + 'label' => $this->translate('Activity Log'), + 'url' => 'director/list/activitylog' + ) + )->add( + 'datalist', + array( + 'label' => $this->translate('Data lists'), + 'url' => 'director/list/datalist' + ) + )->add( + 'datafield', + array( + 'label' => $this->translate('Data fields'), + 'url' => 'director/list/datafield' + ) ); return $this->view->tabs; } protected function setImportTabs() { - $this->view->tabs = Widget::create('tabs')->add('importsource', array( - 'label' => $this->translate('Import source'), - 'url' => 'director/list/importsource') - )->add('importrun', array( - 'label' => $this->translate('Import history'), - 'url' => 'director/list/importrun') - )->add('syncrule', array( - 'label' => $this->translate('Sync rule'), - 'url' => 'director/list/syncrule') + $this->view->tabs = Widget::create('tabs')->add( + 'importsource', + array( + 'label' => $this->translate('Import source'), + 'url' => 'director/list/importsource' + ) + )->add( + 'importrun', + array( + 'label' => $this->translate('Import history'), + 'url' => 'director/list/importrun' + ) + )->add( + 'syncrule', + array( + 'label' => $this->translate('Sync rule'), + 'url' => 'director/list/syncrule' + ) ); return $this->view->tabs; } diff --git a/library/Director/Web/Controller/ObjectController.php b/library/Director/Web/Controller/ObjectController.php index 0ed4884c..867018f5 100644 --- a/library/Director/Web/Controller/ObjectController.php +++ b/library/Director/Web/Controller/ObjectController.php @@ -103,12 +103,13 @@ abstract class ObjectController extends ActionController $this->view->title = sprintf($this->translate('Modify %s'), ucfirst($ltype)); $this->view->form->handleRequest(); - $this->view->actionLinks = $this->view->icon('paste') . ' ' - . $this->view->qlink( - sprintf($this->translate('Clone'), $this->translate(ucfirst($ltype))), - 'director/' . $ltype .'/clone', - array('name' => $object->object_name) - ); + $this->view->actionLinks = $this->view->icon('paste') + . ' ' + . $this->view->qlink( + sprintf($this->translate('Clone'), $this->translate(ucfirst($ltype))), + 'director/' . $ltype .'/clone', + array('name' => $object->object_name) + ); $this->render('object/form', null, true); } @@ -149,12 +150,13 @@ abstract class ObjectController extends ActionController ); $this->view->form->handleRequest(); - $this->view->actionLinks = $this->view->icon('left-big') . ' ' + $this->view->actionLinks = $this->view->icon('left-big') + . ' ' . $this->view->qlink( - sprintf($this->translate('back'), $this->translate(ucfirst($ltype))), - 'director/' . $ltype, - array('name' => $this->object->object_name) - ); + sprintf($this->translate('back'), $this->translate(ucfirst($ltype))), + 'director/' . $ltype, + array('name' => $this->object->object_name) + ); $this->render('object/form', null, true); } diff --git a/library/Director/Web/Controller/ObjectsController.php b/library/Director/Web/Controller/ObjectsController.php index f7559b6e..f8dac9d0 100644 --- a/library/Director/Web/Controller/ObjectsController.php +++ b/library/Director/Web/Controller/ObjectsController.php @@ -94,12 +94,13 @@ abstract class ObjectsController extends ActionController $addTitle = $this->translate('Add %s'); } - $this->view->addLink = $this->view->icon('plus') . ' ' - . $this->view->qlink( - sprintf($addTitle, $this->translate(ucfirst($ltype))), - 'director/' . $ltype .'/add', - $addParams - ); + $this->view->addLink = $this->view->icon('plus') + . ' ' + . $this->view->qlink( + sprintf($addTitle, $this->translate(ucfirst($ltype))), + 'director/' . $ltype .'/add', + $addParams + ); $this->view->title = $this->translate('Icinga ' . ucfirst($ltype)); $table = $this->loadTable($table)->setConnection($this->db()); @@ -151,7 +152,7 @@ abstract class ObjectsController extends ActionController array('Group', 'Period', 'Argument', 'ApiUser'), str_replace( 'template', - '', + '', substr($this->getRequest()->getControllerName(), 0, -1) ) ); diff --git a/library/Director/Web/Form/DirectorObjectForm.php b/library/Director/Web/Form/DirectorObjectForm.php index a379b828..65ece753 100644 --- a/library/Director/Web/Form/DirectorObjectForm.php +++ b/library/Director/Web/Form/DirectorObjectForm.php @@ -347,13 +347,15 @@ abstract class DirectorObjectForm extends QuickForm } // TODO: handle structured vars - if (! is_string($value)) continue; + if (! is_string($value)) { + continue; + } // Show inheritance information in case we inherited this var: if (isset($inherited->$key)) { - $this->addCustomVar($key, $value, $inherited->$key, $origins->$key); + $this->addCustomVar($key, $value, $inherited->$key, $origins->$key); } else { - $this->addCustomVar($key, $value); + $this->addCustomVar($key, $value); } } @@ -674,7 +676,10 @@ abstract class DirectorObjectForm extends QuickForm $label = $this->translate('Delete'); } - $el = $this->createElement('submit', $label)->setLabel($label)->setDecorators(array('ViewHelper')); //->removeDecorator('Label'); + $el = $this->createElement('submit', $label) + ->setLabel($label) + ->setDecorators(array('ViewHelper')); + //->removeDecorator('Label'); $this->deleteButtonName = $el->getName(); $this->addElement($el); @@ -689,7 +694,9 @@ abstract class DirectorObjectForm extends QuickForm public function shouldBeDeleted() { - if (! $this->hasDeleteButton()) return false; + if (! $this->hasDeleteButton()) { + return false; + } $name = $this->deleteButtonName; return $this->getSentValue($name) === $this->getElement($name)->getLabel(); @@ -878,24 +885,34 @@ abstract class DirectorObjectForm extends QuickForm protected function addCheckExecutionElements() { - $this->addElement('text', 'check_interval', array( - 'label' => $this->translate('Check interval'), - 'description' => $this->translate('Your regular check interval') - )); + $this->addElement( + 'text', + 'check_interval', + array( + 'label' => $this->translate('Check interval'), + 'description' => $this->translate('Your regular check interval') + ) + ); - $this->addElement('text', 'retry_interval', array( - 'label' => $this->translate('Retry interval'), - 'description' => $this->translate('Retry interval, will be applied after a state change unless the next hard state is reached') - )); + $this->addElement( + 'text', + 'retry_interval', + array( + 'label' => $this->translate('Retry interval'), + 'description' => $this->translate( + 'Retry interval, will be applied after a state change unless the next hard state is reached' + ) + ) + ); $this->optionalBoolean( - 'enable_active_checks', + 'enable_active_checks', $this->translate('Execute active checks'), $this->translate('Whether to actively check this object') ); $this->optionalBoolean( - 'enable_passive_checks', + 'enable_passive_checks', $this->translate('Accept passive checks'), $this->translate('Whether to accept passive check results for this object') ); diff --git a/library/Director/Web/Table/QuickTable.php b/library/Director/Web/Table/QuickTable.php index 0feec8fe..cc8fe1fa 100644 --- a/library/Director/Web/Table/QuickTable.php +++ b/library/Director/Web/Table/QuickTable.php @@ -98,7 +98,7 @@ abstract class QuickTable implements Paginatable $value = '
' . $this->view()->escape(print_r($val, 1)) . ''; } else { $value = $this->view()->escape($val); - } + } } $htm .= '