From 100bc4b7775155139ae6fdaf9be0986aac0f15c6 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 6 Dec 2021 23:03:06 +0100 Subject: [PATCH] library: php8-related cleanup --- application/controllers/SyncruleController.php | 2 +- .../Objects/IcingaScheduledDowntimeRange.php | 2 +- .../Director/Objects/IcingaTimePeriodRange.php | 2 +- library/Director/Objects/ObjectApplyMatches.php | 2 +- .../Director/Web/Form/IcingaObjectFieldLoader.php | 2 +- library/Director/Web/Table/ActivityLogTable.php | 12 +++++++++++- .../Director/Web/Table/BranchActivityTable.php | 7 ++++++- library/Director/Web/Table/SyncRunTable.php | 15 +++++++++------ library/Director/Web/Widget/ActivityLogInfo.php | 8 +++----- 9 files changed, 34 insertions(+), 18 deletions(-) diff --git a/application/controllers/SyncruleController.php b/application/controllers/SyncruleController.php index 727e5cbf..482f35cc 100644 --- a/application/controllers/SyncruleController.php +++ b/application/controllers/SyncruleController.php @@ -546,7 +546,7 @@ class SyncruleController extends ActionController $run = SyncRun::load($runId, $this->db()); $this->content()->add(new SyncRunDetails($run)); } - SyncRunTable::create($rule)->renderTo($this); + (new SyncRunTable($rule))->renderTo($this); } /** diff --git a/library/Director/Objects/IcingaScheduledDowntimeRange.php b/library/Director/Objects/IcingaScheduledDowntimeRange.php index c2984e5a..6280990b 100644 --- a/library/Director/Objects/IcingaScheduledDowntimeRange.php +++ b/library/Director/Objects/IcingaScheduledDowntimeRange.php @@ -29,7 +29,7 @@ class IcingaScheduledDowntimeRange extends DbObject return false; } - if ((int) strftime('%w', $now) !== $weekDay) { + if ((int) date('w', $now) !== $weekDay) { return false; } diff --git a/library/Director/Objects/IcingaTimePeriodRange.php b/library/Director/Objects/IcingaTimePeriodRange.php index aadb7554..55c1a3ee 100644 --- a/library/Director/Objects/IcingaTimePeriodRange.php +++ b/library/Director/Objects/IcingaTimePeriodRange.php @@ -29,7 +29,7 @@ class IcingaTimePeriodRange extends DbObject return false; } - if ((int) strftime('%w', $now) !== $weekDay) { + if ((int) date('w', $now) !== $weekDay) { return false; } diff --git a/library/Director/Objects/ObjectApplyMatches.php b/library/Director/Objects/ObjectApplyMatches.php index ee6e6c85..018c8802 100644 --- a/library/Director/Objects/ObjectApplyMatches.php +++ b/library/Director/Objects/ObjectApplyMatches.php @@ -172,7 +172,7 @@ abstract class ObjectApplyMatches $col = $filter->getColumn(); $type = static::$type; - if (substr($col, 0, strlen($type) + 1) === "${type}.") { + if ($type && substr($col, 0, strlen($type) + 1) === "${type}.") { $filter->setColumn($col = substr($col, strlen($type) + 1)); } diff --git a/library/Director/Web/Form/IcingaObjectFieldLoader.php b/library/Director/Web/Form/IcingaObjectFieldLoader.php index 1c041bbe..c900edf6 100644 --- a/library/Director/Web/Form/IcingaObjectFieldLoader.php +++ b/library/Director/Web/Form/IcingaObjectFieldLoader.php @@ -329,7 +329,7 @@ class IcingaObjectFieldLoader if (array_key_exists($col, $elements)) { $el = $elements[$col]; $existingClass = $el->getAttrib('class'); - if (strlen($existingClass)) { + if ($existingClass !== null && strlen($existingClass)) { $el->setAttrib('class', $existingClass . ' autosubmit'); } else { $el->setAttrib('class', 'autosubmit'); diff --git a/library/Director/Web/Table/ActivityLogTable.php b/library/Director/Web/Table/ActivityLogTable.php index 034a7aea..b9463c83 100644 --- a/library/Director/Web/Table/ActivityLogTable.php +++ b/library/Director/Web/Table/ActivityLogTable.php @@ -2,6 +2,7 @@ namespace Icinga\Module\Director\Web\Table; +use gipfl\Format\LocalTimeFormat; use Icinga\Module\Director\Util; use ipl\Html\BaseHtmlElement; use gipfl\IcingaWeb2\Link; @@ -32,6 +33,15 @@ class ActivityLogTable extends ZfQueryBasedTable 'action', ); + /** @var LocalTimeFormat */ + protected $timeFormat; + + public function __construct($db) + { + parent::__construct($db); + $this->timeFormat = new LocalTimeFormat(); + } + public function assemble() { $this->getAttributes()->add('class', 'activity-log'); @@ -55,7 +65,7 @@ class ActivityLogTable extends ZfQueryBasedTable return $this::tr([ $this::td($this->makeLink($row))->setSeparator(' '), - $this::td(date('H:i:s', $row->ts_change_time)) + $this::td($this->timeFormat->getTime($row->ts_change_time)) ])->addAttributes(['class' => $action]); } diff --git a/library/Director/Web/Table/BranchActivityTable.php b/library/Director/Web/Table/BranchActivityTable.php index 45692d7a..42dc3e67 100644 --- a/library/Director/Web/Table/BranchActivityTable.php +++ b/library/Director/Web/Table/BranchActivityTable.php @@ -2,6 +2,7 @@ namespace Icinga\Module\Director\Web\Table; +use gipfl\Format\LocalTimeFormat; use Icinga\Module\Director\Db; use Icinga\Module\Director\Db\Branch\BranchActivity; use Icinga\Module\Director\Util; @@ -19,10 +20,14 @@ class BranchActivityTable extends ZfQueryBasedTable /** @var ?UuidInterface */ protected $objectUuid; + /** @var LocalTimeFormat */ + protected $timeFormat; + public function __construct(UuidInterface $branchUuid, $db, UuidInterface $objectUuid = null) { $this->branchUuid = $branchUuid; $this->objectUuid = $objectUuid; + $this->timeFormat = new LocalTimeFormat(); parent::__construct($db); } @@ -38,7 +43,7 @@ class BranchActivityTable extends ZfQueryBasedTable $activity = BranchActivity::fromDbRow($row); return $this::tr([ $this::td($this->makeBranchLink($activity))->setSeparator(' '), - $this::td(strftime('%H:%M:%S', $ts)) + $this::td($this->timeFormat->getTime($ts)) ])->addAttributes(['class' => ['action-' . $activity->getAction(), 'branched']]); } diff --git a/library/Director/Web/Table/SyncRunTable.php b/library/Director/Web/Table/SyncRunTable.php index 9c161235..e08aad79 100644 --- a/library/Director/Web/Table/SyncRunTable.php +++ b/library/Director/Web/Table/SyncRunTable.php @@ -2,6 +2,7 @@ namespace Icinga\Module\Director\Web\Table; +use gipfl\Format\LocalTimeFormat; use Icinga\Module\Director\Objects\SyncRule; use gipfl\IcingaWeb2\Link; use gipfl\IcingaWeb2\Table\ZfQueryBasedTable; @@ -11,14 +12,16 @@ class SyncRunTable extends ZfQueryBasedTable /** @var SyncRule */ protected $rule; - public static function create(SyncRule $rule) + protected $timeFormat; + + public function __construct(SyncRule $rule) { - $table = new static($rule->getConnection()); - $table->getAttributes() + parent::__construct($rule->getConnection()); + $this->timeFormat = new LocalTimeFormat(); + $this->getAttributes() ->set('data-base-target', '_self') ->add('class', 'history'); - $table->rule = $rule; - return $table; + $this->rule = $rule; } public function renderRow($row) @@ -28,7 +31,7 @@ class SyncRunTable extends ZfQueryBasedTable return $this::tr([ $this::td($this->makeSummary($row)), $this::td(new Link( - strftime('%H:%M:%S', $time), + $this->timeFormat->getTime($time), 'director/syncrule/history', [ 'id' => $row->rule_id, diff --git a/library/Director/Web/Widget/ActivityLogInfo.php b/library/Director/Web/Widget/ActivityLogInfo.php index f1a1956e..bb2aea3a 100644 --- a/library/Director/Web/Widget/ActivityLogInfo.php +++ b/library/Director/Web/Widget/ActivityLogInfo.php @@ -2,8 +2,7 @@ namespace Icinga\Module\Director\Web\Widget; -use gipfl\Diff\HtmlRenderer\SideBySideDiff; -use gipfl\Diff\PhpDiff; +use gipfl\Json\JsonString; use ipl\Html\HtmlDocument; use ipl\Html\HtmlElement; use Icinga\Date\DateFormatter; @@ -21,7 +20,6 @@ use gipfl\Translation\TranslationHelper; use gipfl\IcingaWeb2\Url; use gipfl\IcingaWeb2\Widget\NameValueTable; use gipfl\IcingaWeb2\Widget\Tabs; -use ipl\Html\ValidHtml; class ActivityLogInfo extends HtmlDocument { @@ -223,7 +221,7 @@ class ActivityLogInfo extends HtmlDocument { if ($this->oldProperties === null) { if (property_exists($this->entry, 'old_properties')) { - $this->oldProperties = json_decode($this->entry->old_properties); + $this->oldProperties = JsonString::decodeOptional($this->entry->old_properties); } if ($this->oldProperties === null) { $this->oldProperties = new \stdClass; @@ -237,7 +235,7 @@ class ActivityLogInfo extends HtmlDocument { if ($this->newProperties === null) { if (property_exists($this->entry, 'new_properties')) { - $this->newProperties = json_decode($this->entry->new_properties); + $this->newProperties = JsonString::decodeOptional($this->entry->new_properties); } if ($this->newProperties === null) { $this->newProperties = new \stdClass;