library/Director: fix PSR2 complaints

This commit is contained in:
Thomas Gelf 2016-02-26 11:58:37 +01:00
parent 586c043290
commit 4bc5afb2f8
39 changed files with 388 additions and 155 deletions

View File

@ -16,7 +16,8 @@ class ActivityLogTable extends QuickTable
'id' => 'l.id', 'id' => 'l.id',
'change_time' => 'l.change_time', 'change_time' => 'l.change_time',
'author' => 'l.author', '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( return $this->url(
'director/show/activitylog', 'director/show/activitylog',
array_merge(array('id' => $row->id), $this->extraParams array_merge(array('id' => $row->id), $this->extraParams)
)); );
} }
public function getTitles() public function getTitles()

View File

@ -16,7 +16,8 @@ class IcingaEndpointTable extends IcingaObjectTable
'id' => 'e.id', 'id' => 'e.id',
'endpoint' => 'e.object_name', 'endpoint' => 'e.object_name',
'object_type' => 'e.object_type', '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', 'zone' => 'z.object_name',
); );
} }

View File

@ -16,7 +16,6 @@ $this->provideRestriction(
$this->translate('Allow to use only these db resources (comma separated list)') $this->translate('Allow to use only these db resources (comma separated list)')
); );
$this->provideConfigTab('config', array( $this->provideConfigTab('config', array(
'title' => 'Configuration', 'title' => 'Configuration',
'url' => 'settings' 'url' => 'settings'
@ -43,4 +42,3 @@ $section->add($this->translate('Config'))
->setUrl('director/list/deploymentlog') ->setUrl('director/list/deploymentlog')
->setPriority(902) ->setPriority(902)
->setRenderer('ConfigHealthItemRenderer'); ->setRenderer('ConfigHealthItemRenderer');

View File

@ -159,6 +159,7 @@ class RestApiClient
} }
curl_setopt_array($curl, $opts); curl_setopt_array($curl, $opts);
// TODO: request headers, validate status code
Benchmark::measure('Rest Api, sending ' . $url); Benchmark::measure('Rest Api, sending ' . $url);
$res = curl_exec($curl); $res = curl_exec($curl);
@ -236,7 +237,7 @@ class RestApiClient
$str = substr($this->readBuffer, $offset, $pos); $str = substr($this->readBuffer, $offset, $pos);
$decoded = json_decode($str); $decoded = json_decode($str);
if ($decoded === false) { if ($decoded === false) {
throw new Exception('Got invalid JSON: ' . $str); throw new Exception('Got invalid JSON: ' . $str);
} }
// printf("Processing %s bytes\n", strlen($str)); // printf("Processing %s bytes\n", strlen($str));

View File

@ -14,5 +14,4 @@ abstract class Stream
{ {
$this->stream = $stream; $this->stream = $stream;
} }
} }

View File

@ -165,7 +165,7 @@ abstract class CustomVariable implements IcingaConfigRenderer
public static function fromDbRow($row) public static function fromDbRow($row)
{ {
switch($row->format) { switch ($row->format) {
case 'string': case 'string':
$var = new CustomVariableString($row->varname, $row->varvalue); $var = new CustomVariableString($row->varname, $row->varvalue);
break; break;
@ -194,7 +194,10 @@ abstract class CustomVariable implements IcingaConfigRenderer
return $this->toConfigString(); return $this->toConfigString();
} catch (Exception $e) { } catch (Exception $e) {
trigger_error($e); trigger_error($e);
$previousHandler = set_exception_handler(function () {}); $previousHandler = set_exception_handler(
function () {
}
);
restore_error_handler(); restore_error_handler();
call_user_func($previousHandler, $e); call_user_func($previousHandler, $e);
die(); die();

View File

@ -38,7 +38,7 @@ class CustomVariableBoolean extends CustomVariable
$this->value = $value; $this->value = $value;
return $this; return $this;
} }
public function toConfigString() public function toConfigString()
{ {

View File

@ -37,7 +37,7 @@ class CustomVariableNull extends CustomVariable
} }
return $this; return $this;
} }
public function toConfigString() public function toConfigString()
{ {

View File

@ -51,7 +51,7 @@ class CustomVariableNumber extends CustomVariable
$this->value = $value; $this->value = $value;
return $this; return $this;
} }
public function toConfigString() public function toConfigString()
{ {

View File

@ -32,7 +32,7 @@ class CustomVariableString extends CustomVariable
} }
return $this; return $this;
} }
public function toConfigString() public function toConfigString()
{ {

View File

@ -269,7 +269,10 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer
return $this->toConfigString(); return $this->toConfigString();
} catch (Exception $e) { } catch (Exception $e) {
trigger_error($e); trigger_error($e);
$previousHandler = set_exception_handler(function () {}); $previousHandler = set_exception_handler(
function () {
}
);
restore_error_handler(); restore_error_handler();
call_user_func($previousHandler, $e); call_user_func($previousHandler, $e);
die(); die();

View File

@ -130,7 +130,9 @@ abstract class DbObject
* *
* @return void * @return void
*/ */
protected function beforeInit() {} protected function beforeInit()
{
}
/** /**
* Wird ausgeführt, nachdem mittels ::factory() ein neues Objekt erstellt * Wird ausgeführt, nachdem mittels ::factory() ein neues Objekt erstellt
@ -138,7 +140,9 @@ abstract class DbObject
* *
* @return void * @return void
*/ */
protected function onFactory() {} protected function onFactory()
{
}
/** /**
* Wird ausgeführt, nachdem mittels ::factory() ein neues Objekt erstellt * Wird ausgeführt, nachdem mittels ::factory() ein neues Objekt erstellt
@ -146,7 +150,9 @@ abstract class DbObject
* *
* @return void * @return void
*/ */
protected function onLoadFromDb() {} protected function onLoadFromDb()
{
}
/** /**
* Wird ausgeführt, bevor ein Objekt abgespeichert wird. Die Operation * Wird ausgeführt, bevor ein Objekt abgespeichert wird. Die Operation
@ -154,14 +160,18 @@ abstract class DbObject
* *
* @return void * @return void
*/ */
protected function beforeStore() {} protected function beforeStore()
{
}
/** /**
* Wird ausgeführt, nachdem ein Objekt erfolgreich gespeichert worden ist * Wird ausgeführt, nachdem ein Objekt erfolgreich gespeichert worden ist
* *
* @return void * @return void
*/ */
protected function onStore() {} protected function onStore()
{
}
/** /**
* Wird ausgeführt, nachdem ein Objekt erfolgreich der Datenbank hinzu- * Wird ausgeführt, nachdem ein Objekt erfolgreich der Datenbank hinzu-
@ -169,7 +179,9 @@ abstract class DbObject
* *
* @return void * @return void
*/ */
protected function onInsert() {} protected function onInsert()
{
}
/** /**
* Wird ausgeführt, nachdem bestehendes Objekt erfolgreich der Datenbank * Wird ausgeführt, nachdem bestehendes Objekt erfolgreich der Datenbank
@ -177,7 +189,9 @@ abstract class DbObject
* *
* @return void * @return void
*/ */
protected function onUpdate() {} protected function onUpdate()
{
}
/** /**
* Wird ausgeführt, bevor ein Objekt gelöscht wird. Die Operation wird * Wird ausgeführt, bevor ein Objekt gelöscht wird. Die Operation wird
@ -185,7 +199,9 @@ abstract class DbObject
* *
* @return void * @return void
*/ */
protected function beforeDelete() {} protected function beforeDelete()
{
}
/** /**
* Wird ausgeführt, nachdem bestehendes Objekt erfolgreich aud der * Wird ausgeführt, nachdem bestehendes Objekt erfolgreich aud der
@ -193,7 +209,9 @@ abstract class DbObject
* *
* @return void * @return void
*/ */
protected function onDelete() {} protected function onDelete()
{
}
/** /**
* Set database connection * Set database connection
@ -394,7 +412,10 @@ abstract class DbObject
{ {
$props = array(); $props = array();
foreach (array_keys($this->modifiedProperties) as $key) { foreach (array_keys($this->modifiedProperties) as $key) {
if ($key === $this->autoincKeyName) continue; if ($key === $this->autoincKeyName) {
continue;
}
$props[$key] = $this->properties[$key]; $props[$key] = $this->properties[$key];
} }
return $props; return $props;
@ -475,9 +496,8 @@ abstract class DbObject
$id[$key] = $this->properties[$key]; $id[$key] = $this->properties[$key];
} }
return $id; return $id;
} else { } else {
if (isset($this->properties[$this->keyName])) if (isset($this->properties[$this->keyName])) {
{
return $this->properties[$this->keyName]; return $this->properties[$this->keyName];
} }
} }
@ -491,8 +511,7 @@ abstract class DbObject
*/ */
public function getAutoincId() public function getAutoincId()
{ {
if (isset($this->properties[$this->autoincKeyName])) if (isset($this->properties[$this->autoincKeyName])) {
{
return $this->properties[$this->autoincKeyName]; return $this->properties[$this->autoincKeyName];
} }
return null; return null;

View File

@ -162,7 +162,7 @@ class Db extends DbConnection
array( array(
'prev' => 'lt.id', 'prev' => 'lt.id',
'next' => 'gt.id' 'next' => 'gt.id'
) )
)->join( )->join(
array('lt' => $smaller), array('lt' => $smaller),
null, null,
@ -227,9 +227,13 @@ class Db extends DbConnection
public function getLastActivityChecksum() public function getLastActivityChecksum()
{ {
if ($this->getDbType() === 'pgsql') { 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 { } 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); return $this->db()->fetchOne($select);

View File

@ -41,12 +41,12 @@ class Migrations
} }
public function hasPendingMigrations() public function hasPendingMigrations()
{ {
return $this->countPendingMigrations() > 0; return $this->countPendingMigrations() > 0;
} }
public function countPendingMigrations() public function countPendingMigrations()
{ {
return count($this->listPendingMigrations()); return count($this->listPendingMigrations());
} }
@ -92,7 +92,10 @@ class Migrations
$versions = array(); $versions = array();
foreach (new DirectoryIterator($this->getMigrationsDir()) as $file) { foreach (new DirectoryIterator($this->getMigrationsDir()) as $file) {
if($file->isDot()) continue; if ($file->isDot()) {
continue;
}
$filename = $file->getFilename(); $filename = $file->getFilename();
if (preg_match('/^upgrade_(\d+)\.sql$/', $filename, $match)) { if (preg_match('/^upgrade_(\d+)\.sql$/', $filename, $match)) {
$versions[] = $match[1]; $versions[] = $match[1];

View File

@ -64,7 +64,8 @@ abstract class ImportSourceHook
return $this; return $this;
} }
public function getSetting($name, $default = null) { public function getSetting($name, $default = null)
{
if (array_key_exists($name, $this->settings)) { if (array_key_exists($name, $this->settings)) {
return $this->settings[$name]; return $this->settings[$name];
} else { } else {

View File

@ -276,8 +276,7 @@ class IcingaConfig
$this->db->commit(); $this->db->commit();
} catch (Exception $e) { } catch (Exception $e) {
$this->db->rollBack(); $this->db->rollBack();
throw $e; throw $e;
var_dump($e->getMessage());
} }
return $this; return $this;
@ -373,10 +372,18 @@ throw $e;
$zones = array(); $zones = array();
$endpoints = array(); $endpoints = array();
foreach (IcingaHost::prefetchAll($this->connection) as $host) { foreach (IcingaHost::prefetchAll($this->connection) as $host) {
if ($host->object_type !== 'object') continue; if ($host->object_type !== 'object') {
if ($host->getResolvedProperty('has_agent') !== 'y') continue; continue;
}
if ($host->getResolvedProperty('has_agent') !== 'y') {
continue;
}
$name = $host->object_name; $name = $host->object_name;
if (IcingaEndpoint::exists($name, $this->connection)) continue; if (IcingaEndpoint::exists($name, $this->connection)) {
continue;
}
$props = array( $props = array(
'object_name' => $name, 'object_name' => $name,
@ -411,18 +418,24 @@ throw $e;
protected function createFileForObjects($type, $objects) protected function createFileForObjects($type, $objects)
{ {
Benchmark::measure(sprintf('Generating %d %s', count($objects), $type)); Benchmark::measure(sprintf('Generating %d %s', count($objects), $type));
if (empty($objects)) return $this; if (empty($objects)) {
return $this;
}
$masterZone = $this->connection->getMasterZoneName(); $masterZone = $this->connection->getMasterZoneName();
$globalZone = $this->connection->getDefaultGlobalZoneName(); $globalZone = $this->connection->getDefaultGlobalZoneName();
$file = null; $file = null;
foreach ($objects as $object) { foreach ($objects as $object) {
if ($object->disabled === 'y') continue; if ($object->disabled === 'y') {
continue;
}
if ($object->isExternal()) { if ($object->isExternal()) {
if ($type === 'zone') { if ($type === 'zone') {
$this->zoneMap[$object->id] = $object->object_name; $this->zoneMap[$object->id] = $object->object_name;
} }
continue; continue;
} elseif ($object->isTemplate()) { } elseif ($object->isTemplate()) {
$filename = strtolower($type) . '_templates'; $filename = strtolower($type) . '_templates';
@ -557,6 +570,7 @@ throw $e;
} }
// TODO: wipe unused files // 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;
} }

View File

@ -455,7 +455,9 @@ class Sync
) as $object) { ) as $object) {
if ($object instanceof IcingaService) { if ($object instanceof IcingaService) {
if (! $object->host_id) continue; if (! $object->host_id) {
continue;
}
} }
$key = $this->fillVariables( $key = $this->fillVariables(
@ -502,7 +504,9 @@ class Sync
$imports = array(); $imports = array();
foreach ($this->syncProperties as $p) { foreach ($this->syncProperties as $p) {
if ($p->source_id !== $sourceId) continue; if ($p->source_id !== $sourceId) {
continue;
}
$prop = $p->destination_field; $prop = $p->destination_field;
$val = $this->fillVariables($p->source_expression, $row); $val = $this->fillVariables($p->source_expression, $row);

View File

@ -16,11 +16,11 @@ class KickstartHelper
protected $apiUser; protected $apiUser;
protected $config = array( protected $config = array(
'endpoint' => null, 'endpoint' => null,
'host' => null, 'host' => null,
'port' => null, 'port' => null,
'username' => null, 'username' => null,
'password' => null, 'password' => null,
); );
public function __construct(Db $db) public function __construct(Db $db)

View File

@ -261,7 +261,10 @@ class IcingaArguments implements Iterator, Countable, IcingaConfigRenderer
return $this->toConfigString(); return $this->toConfigString();
} catch (Exception $e) { } catch (Exception $e) {
trigger_error($e); trigger_error($e);
$previousHandler = set_exception_handler(function () {}); $previousHandler = set_exception_handler(
function () {
}
);
restore_error_handler(); restore_error_handler();
if ($previousHandler !== null) { if ($previousHandler !== null) {
call_user_func($previousHandler, $e); call_user_func($previousHandler, $e);

View File

@ -31,9 +31,19 @@ class IcingaCommand extends IcingaObject
protected static $pluginDir; 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() protected function renderMethods_execute()
{ {
// Execute is a reserved word in SQL, column name was prefixed // @codingStandardsIgnoreEnd
return c::renderKeyValue('execute', $this->methods_execute); return c::renderKeyValue('execute', $this->methods_execute);
} }

View File

@ -58,13 +58,31 @@ class IcingaEndpoint extends IcingaObject
return new CoreApi($client); return new CoreApi($client);
} }
/**
* Use duration time renderer helper
*
* Avoid complaints for method names with underscore:
* @codingStandardsIgnoreStart
*
* @return string
*/
protected function renderLog_duration() protected function renderLog_duration()
{ {
// @codingStandardsIgnoreEnd
return $this->renderPropertyAsSeconds('log_duration'); 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() protected function renderApiuser_id()
{ {
// @codingStandardsIgnoreEnd
return ''; return '';
} }
} }

View File

@ -112,18 +112,37 @@ class IcingaHost extends IcingaObject
return $this->getResolvedProperty('check_command_id') !== null; 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() protected function renderHas_Agent()
{ {
return ''; return '';
} }
/**
* Internal property, will not be rendered
*
* @return string
*/
protected function renderMaster_should_connect() protected function renderMaster_should_connect()
{ {
return ''; return '';
} }
/**
* Internal property, will not be rendered
*
* @return string
*/
protected function renderAccept_config() protected function renderAccept_config()
{ {
// @codingStandardsIgnoreEnd
return ''; return '';
} }
} }

View File

@ -483,7 +483,9 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
$origins = $object->$getOrigins(); $origins = $object->$getOrigins();
foreach ($object->$getInherited() as $key => $value) { foreach ($object->$getInherited() as $key => $value) {
if (in_array($key, $blacklist)) continue; if (in_array($key, $blacklist)) {
continue;
}
// $vals[$name]->$key = $value; // $vals[$name]->$key = $value;
$vals['_MERGED_']->$key = $value; $vals['_MERGED_']->$key = $value;
$vals['_INHERITED_']->$key = $value; $vals['_INHERITED_']->$key = $value;
@ -500,7 +502,9 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
} }
foreach ($this->$get() as $key => $value) { foreach ($this->$get() as $key => $value) {
if ($value === null) continue; if ($value === null) {
continue;
}
// $vals[$this->object_name]->$key = $value; // $vals[$this->object_name]->$key = $value;
$vals['_MERGED_']->$key = $value; $vals['_MERGED_']->$key = $value;
@ -807,8 +811,12 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
foreach ($this->properties as $key => $value) { foreach ($this->properties as $key => $value) {
if ($value === null) continue; if ($value === null) {
if (in_array($key, $blacklist)) continue; continue;
}
if (in_array($key, $blacklist)) {
continue;
}
$method = 'render' . ucfirst($key); $method = 'render' . ucfirst($key);
if (method_exists($this, $method)) { if (method_exists($this, $method)) {
@ -821,8 +829,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
c::renderBoolean($value) c::renderBoolean($value)
); );
} }
} elseif ( } elseif (substr($key, -3) === '_id'
substr($key, -3) === '_id'
&& $this->hasRelation($relKey = substr($key, 0, -3)) && $this->hasRelation($relKey = substr($key, 0, -3))
) { ) {
$out .= $this->renderRelationProperty($relKey, $value); $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() protected function renderZone_id()
{ {
// We do not render zone properties, objects are stored to zone dirs // @codingStandardsIgnoreEnd
return ''; return '';
} }
@ -1194,11 +1209,17 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
} }
if ($skipDefaults) { if ($skipDefaults) {
if (empty($props['imports'])) unset($props['imports']); if (empty($props['imports'])) {
if (array_key_exists('vars', $props)) { unset($props['imports']);
if (count((array) $props['vars']) === 0) unset($props['vars']); }
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); ksort($props);
@ -1278,7 +1299,10 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
return $this->toConfigString(); return $this->toConfigString();
} catch (Exception $e) { } catch (Exception $e) {
trigger_error($e); trigger_error($e);
$previousHandler = set_exception_handler(function () {}); $previousHandler = set_exception_handler(
function () {
}
);
restore_error_handler(); restore_error_handler();
if ($previousHandler !== null) { if ($previousHandler !== null) {
call_user_func($previousHandler, $e); call_user_func($previousHandler, $e);

View File

@ -317,7 +317,10 @@ class IcingaObjectGroups implements Iterator, Countable, IcingaConfigRenderer
return $this->toConfigString(); return $this->toConfigString();
} catch (Exception $e) { } catch (Exception $e) {
trigger_error($e); trigger_error($e);
$previousHandler = set_exception_handler(function () {}); $previousHandler = set_exception_handler(
function () {
}
);
restore_error_handler(); restore_error_handler();
if ($previousHandler !== null) { if ($previousHandler !== null) {
call_user_func($previousHandler, $e); call_user_func($previousHandler, $e);

View File

@ -300,7 +300,10 @@ class IcingaObjectImports implements Iterator, Countable, IcingaConfigRenderer
return $this->toConfigString(); return $this->toConfigString();
} catch (Exception $e) { } catch (Exception $e) {
trigger_error($e); trigger_error($e);
$previousHandler = set_exception_handler(function () {}); $previousHandler = set_exception_handler(
function () {
}
);
restore_error_handler(); restore_error_handler();
if ($previousHandler !== null) { if ($previousHandler !== null) {
call_user_func($previousHandler, $e); call_user_func($previousHandler, $e);

View File

@ -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() public function renderHost_id()
{ {
// @codingStandardsIgnoreEnd
return $this->renderRelationProperty('host', $this->host_id, 'host_name'); return $this->renderRelationProperty('host', $this->host_id, 'host_name');
} }
protected function renderCustomExtensions() protected function renderCustomExtensions()
{ {
if ($this->command_endpoint_id !== null) return ''; if ($this->command_endpoint_id !== null
if ($this->object_type !== 'object') return ''; || $this->object_type !== 'object'
if ($this->getResolvedProperty('use_agent') !== 'y') return ''; || $this->getResolvedProperty('use_agent') !== 'y') {
return '';
}
return $this->renderRelationProperty('host', $this->host_id, 'command_endpoint'); 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() public function renderUse_agent()
{ {
// @codingStandardsIgnoreEnd
return ''; return '';
} }
/**
* Use duration time renderer helper
*
* Avoid complaints for method names with underscore:
* @codingStandardsIgnoreStart
*
* @return string
*/
protected function renderCheck_Interval() protected function renderCheck_Interval()
{ {
// @codingStandardsIgnoreEnd
return $this->renderPropertyAsSeconds('check_interval'); return $this->renderPropertyAsSeconds('check_interval');
} }
/**
* Use duration time renderer helper
*
* Avoid complaints for method names with underscore:
* @codingStandardsIgnoreStart
*
* @return string
*/
protected function renderRetry_Interval() protected function renderRetry_Interval()
{ {
// @codingStandardsIgnoreEnd
return $this->renderPropertyAsSeconds('retry_interval'); return $this->renderPropertyAsSeconds('retry_interval');
} }

View File

@ -237,7 +237,10 @@ class IcingaTimePeriodRanges implements Iterator, Countable, IcingaConfigRendere
return $this->toConfigString(); return $this->toConfigString();
} catch (Exception $e) { } catch (Exception $e) {
trigger_error($e); trigger_error($e);
$previousHandler = set_exception_handler(function () {}); $previousHandler = set_exception_handler(
function () {
}
);
restore_error_handler(); restore_error_handler();
if ($previousHandler !== null) { if ($previousHandler !== null) {
call_user_func($previousHandler, $e); call_user_func($previousHandler, $e);

View File

@ -25,8 +25,7 @@ class IcingaUser extends IcingaObject
protected $supportsImports = true; protected $supportsImports = true;
protected function renderEnable_notifications() protected $booleans = array(
{ 'enable_notifications'x => 'enable_notifications'
return $this->renderBooleanProperty('enable_notifications'); );
}
} }

View File

@ -34,5 +34,4 @@ class ImportSource extends DbObjectWithSettings
->order('priority DESC') ->order('priority DESC')
); );
} }
} }

View File

@ -13,20 +13,31 @@ class SyncProperty extends DbObject
protected $autoincKeyName = 'id'; protected $autoincKeyName = 'id';
protected $defaultProperties = array( protected $defaultProperties = array(
'id' => null, 'id' => null,
'rule_id' => null, 'rule_id' => null,
'source_id' => null, 'source_id' => null,
'source_expression' => null, 'source_expression' => null,
'destination_field' => null, 'destination_field' => null,
'priority' => null, 'priority' => null,
'filter_expression' => null, 'filter_expression' => null,
'merge_policy' => 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) public function setSource_column($value)
{ {
// @codingStandardsIgnoreEnd
$this->source_expression = '${' . $value . '}'; $this->source_expression = '${' . $value . '}';
return $this; return $this;
} }
public function sourceIsSingleColumn() public function sourceIsSingleColumn()

View File

@ -14,12 +14,12 @@ class SyncRule extends DbObject
protected $autoincKeyName = 'id'; protected $autoincKeyName = 'id';
protected $defaultProperties = array( protected $defaultProperties = array(
'id' => null, 'id' => null,
'rule_name' => null, 'rule_name' => null,
'object_type' => null, 'object_type' => null,
'update_policy' => null, 'update_policy' => null,
'purge_existing' => null, 'purge_existing' => null,
'filter_expression' => null, 'filter_expression' => null,
); );
private $filter; private $filter;

View File

@ -44,7 +44,9 @@ class PlainObjectRenderer
protected static function renderArray($array, $prefix = '') protected static function renderArray($array, $prefix = '')
{ {
if (empty($array)) return '[]'; if (empty($array)) {
return '[]';
}
$vals = array(); $vals = array();
@ -60,7 +62,10 @@ class PlainObjectRenderer
{ {
$vals = array(); $vals = array();
$hash = (array) $hash; $hash = (array) $hash;
if (empty($hash)) return '{}'; if (empty($hash)) {
return '{}';
}
ksort($hash); ksort($hash);
foreach ($hash as $key => $val) { foreach ($hash as $key => $val) {
$vals[] = $prefix $vals[] = $prefix

View File

@ -63,7 +63,7 @@ class Util
$out = ''; $out = '';
for($i = 1; $i <= $blocks; $i++) { for ($i = 1; $i <= $blocks; $i++) {
// $i encoded as 4 bytes, big endian. // $i encoded as 4 bytes, big endian.
$last = $salt . pack('N', $i); $last = $salt . pack('N', $i);
// first iteration // first iteration

View File

@ -69,7 +69,7 @@ abstract class ActionController extends Controller
protected function sendJson($object) protected function sendJson($object)
{ {
$this->getResponse()->setHeader('Content-Type', 'application/json', true); $this->getResponse()->setHeader('Content-Type', 'application/json', true);
$this->_helper->layout()->disableLayout(); $this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true); $this->_helper->viewRenderer->setNoRender(true);
if (version_compare(PHP_VERSION, '5.4.0') >= 0) { if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
echo json_encode($object, JSON_PRETTY_PRINT) . "\n"; echo json_encode($object, JSON_PRETTY_PRINT) . "\n";
@ -89,36 +89,60 @@ abstract class ActionController extends Controller
protected function setConfigTabs() protected function setConfigTabs()
{ {
$this->view->tabs = Widget::create('tabs')->add('deploymentlog', array( $this->view->tabs = Widget::create('tabs')->add(
'label' => $this->translate('Deployments'), 'deploymentlog',
'url' => 'director/list/deploymentlog') array(
)->add('generatedconfig', array( 'label' => $this->translate('Deployments'),
'label' => $this->translate('Configs'), 'url' => 'director/list/deploymentlog'
'url' => 'director/list/generatedconfig') )
)->add('activitylog', array( )->add(
'label' => $this->translate('Activity Log'), 'generatedconfig',
'url' => 'director/list/activitylog') array(
)->add('datalist', array( 'label' => $this->translate('Configs'),
'label' => $this->translate('Data lists'), 'url' => 'director/list/generatedconfig'
'url' => 'director/list/datalist') )
)->add('datafield', array( )->add(
'label' => $this->translate('Data fields'), 'activitylog',
'url' => 'director/list/datafield') 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; return $this->view->tabs;
} }
protected function setImportTabs() protected function setImportTabs()
{ {
$this->view->tabs = Widget::create('tabs')->add('importsource', array( $this->view->tabs = Widget::create('tabs')->add(
'label' => $this->translate('Import source'), 'importsource',
'url' => 'director/list/importsource') array(
)->add('importrun', array( 'label' => $this->translate('Import source'),
'label' => $this->translate('Import history'), 'url' => 'director/list/importsource'
'url' => 'director/list/importrun') )
)->add('syncrule', array( )->add(
'label' => $this->translate('Sync rule'), 'importrun',
'url' => 'director/list/syncrule') 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; return $this->view->tabs;
} }

View File

@ -103,12 +103,13 @@ abstract class ObjectController extends ActionController
$this->view->title = sprintf($this->translate('Modify %s'), ucfirst($ltype)); $this->view->title = sprintf($this->translate('Modify %s'), ucfirst($ltype));
$this->view->form->handleRequest(); $this->view->form->handleRequest();
$this->view->actionLinks = $this->view->icon('paste') . ' ' $this->view->actionLinks = $this->view->icon('paste')
. $this->view->qlink( . ' '
sprintf($this->translate('Clone'), $this->translate(ucfirst($ltype))), . $this->view->qlink(
'director/' . $ltype .'/clone', sprintf($this->translate('Clone'), $this->translate(ucfirst($ltype))),
array('name' => $object->object_name) 'director/' . $ltype .'/clone',
); array('name' => $object->object_name)
);
$this->render('object/form', null, true); $this->render('object/form', null, true);
} }
@ -149,12 +150,13 @@ abstract class ObjectController extends ActionController
); );
$this->view->form->handleRequest(); $this->view->form->handleRequest();
$this->view->actionLinks = $this->view->icon('left-big') . ' ' $this->view->actionLinks = $this->view->icon('left-big')
. ' '
. $this->view->qlink( . $this->view->qlink(
sprintf($this->translate('back'), $this->translate(ucfirst($ltype))), sprintf($this->translate('back'), $this->translate(ucfirst($ltype))),
'director/' . $ltype, 'director/' . $ltype,
array('name' => $this->object->object_name) array('name' => $this->object->object_name)
); );
$this->render('object/form', null, true); $this->render('object/form', null, true);
} }

View File

@ -94,12 +94,13 @@ abstract class ObjectsController extends ActionController
$addTitle = $this->translate('Add %s'); $addTitle = $this->translate('Add %s');
} }
$this->view->addLink = $this->view->icon('plus') . ' ' $this->view->addLink = $this->view->icon('plus')
. $this->view->qlink( . ' '
sprintf($addTitle, $this->translate(ucfirst($ltype))), . $this->view->qlink(
'director/' . $ltype .'/add', sprintf($addTitle, $this->translate(ucfirst($ltype))),
$addParams 'director/' . $ltype .'/add',
); $addParams
);
$this->view->title = $this->translate('Icinga ' . ucfirst($ltype)); $this->view->title = $this->translate('Icinga ' . ucfirst($ltype));
$table = $this->loadTable($table)->setConnection($this->db()); $table = $this->loadTable($table)->setConnection($this->db());
@ -151,7 +152,7 @@ abstract class ObjectsController extends ActionController
array('Group', 'Period', 'Argument', 'ApiUser'), array('Group', 'Period', 'Argument', 'ApiUser'),
str_replace( str_replace(
'template', 'template',
'', '',
substr($this->getRequest()->getControllerName(), 0, -1) substr($this->getRequest()->getControllerName(), 0, -1)
) )
); );

View File

@ -347,13 +347,15 @@ abstract class DirectorObjectForm extends QuickForm
} }
// TODO: handle structured vars // TODO: handle structured vars
if (! is_string($value)) continue; if (! is_string($value)) {
continue;
}
// Show inheritance information in case we inherited this var: // Show inheritance information in case we inherited this var:
if (isset($inherited->$key)) { if (isset($inherited->$key)) {
$this->addCustomVar($key, $value, $inherited->$key, $origins->$key); $this->addCustomVar($key, $value, $inherited->$key, $origins->$key);
} else { } else {
$this->addCustomVar($key, $value); $this->addCustomVar($key, $value);
} }
} }
@ -674,7 +676,10 @@ abstract class DirectorObjectForm extends QuickForm
$label = $this->translate('Delete'); $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->deleteButtonName = $el->getName();
$this->addElement($el); $this->addElement($el);
@ -689,7 +694,9 @@ abstract class DirectorObjectForm extends QuickForm
public function shouldBeDeleted() public function shouldBeDeleted()
{ {
if (! $this->hasDeleteButton()) return false; if (! $this->hasDeleteButton()) {
return false;
}
$name = $this->deleteButtonName; $name = $this->deleteButtonName;
return $this->getSentValue($name) === $this->getElement($name)->getLabel(); return $this->getSentValue($name) === $this->getElement($name)->getLabel();
@ -878,24 +885,34 @@ abstract class DirectorObjectForm extends QuickForm
protected function addCheckExecutionElements() protected function addCheckExecutionElements()
{ {
$this->addElement('text', 'check_interval', array( $this->addElement(
'label' => $this->translate('Check interval'), 'text',
'description' => $this->translate('Your regular check interval') 'check_interval',
)); array(
'label' => $this->translate('Check interval'),
'description' => $this->translate('Your regular check interval')
)
);
$this->addElement('text', 'retry_interval', array( $this->addElement(
'label' => $this->translate('Retry interval'), 'text',
'description' => $this->translate('Retry interval, will be applied after a state change unless the next hard state is reached') '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( $this->optionalBoolean(
'enable_active_checks', 'enable_active_checks',
$this->translate('Execute active checks'), $this->translate('Execute active checks'),
$this->translate('Whether to actively check this object') $this->translate('Whether to actively check this object')
); );
$this->optionalBoolean( $this->optionalBoolean(
'enable_passive_checks', 'enable_passive_checks',
$this->translate('Accept passive checks'), $this->translate('Accept passive checks'),
$this->translate('Whether to accept passive check results for this object') $this->translate('Whether to accept passive check results for this object')
); );

View File

@ -98,7 +98,7 @@ abstract class QuickTable implements Paginatable
$value = '<pre>' . $this->view()->escape(print_r($val, 1)) . '</pre>'; $value = '<pre>' . $this->view()->escape(print_r($val, 1)) . '</pre>';
} else { } else {
$value = $this->view()->escape($val); $value = $this->view()->escape($val);
} }
} }
$htm .= ' <td>' . $value . "</td>\n"; $htm .= ' <td>' . $value . "</td>\n";
@ -352,7 +352,11 @@ abstract class QuickTable implements Paginatable
} }
} }
} else { } else {
$str .= $this->whereToSql($this->mapFilterColumn($filter->getColumn()), $filter->getSign(), $filter->getExpression()); $str .= $this->whereToSql(
$this->mapFilterColumn($filter->getColumn()),
$filter->getSign(),
$filter->getExpression()
);
} }
return $str; return $str;

View File

@ -21,4 +21,3 @@ $this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\Pro
$this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierStripDomain'); $this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierStripDomain');
$this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierSubstring'); $this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierSubstring');
$this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierUppercase'); $this->provideHook('director/PropertyModifier', $prefix . 'PropertyModifier\\PropertyModifierUppercase');