Director: some fixes for PHP v8.1

refs #2435
This commit is contained in:
Thomas Gelf 2021-11-24 11:56:18 +01:00
parent cb16733420
commit 6786cc768f
11 changed files with 35 additions and 8 deletions

View File

@ -47,8 +47,8 @@ class CoreApi implements DeploymentApiInterface
{ {
$version = $this->getVersion(); $version = $this->getVersion();
if (version_compare($version, '2.8.2', '>=') if ($version === null || (version_compare($version, '2.8.2', '>=')
&& version_compare($version, '2.10.2', '<') && version_compare($version, '2.10.2', '<'))
) { ) {
$this->client->disconnect(); $this->client->disconnect();
$this->client->setKeepAlive(false); $this->client->setKeepAlive(false);

View File

@ -8,7 +8,11 @@ class Json
{ {
public static function encode($mixed, $flags = null) public static function encode($mixed, $flags = null)
{ {
if ($flags === null) {
$result = \json_encode($mixed);
} else {
$result = \json_encode($mixed, $flags); $result = \json_encode($mixed, $flags);
}
if ($result === false && json_last_error() !== JSON_ERROR_NONE) { if ($result === false && json_last_error() !== JSON_ERROR_NONE) {
throw JsonEncodeException::forLastJsonError(); throw JsonEncodeException::forLastJsonError();

View File

@ -89,6 +89,7 @@ class CustomVariableDictionary extends CustomVariable implements Countable
return $keys; return $keys;
} }
#[\ReturnTypeWillChange]
public function count() public function count()
{ {
return count($this->value); return count($this->value);

View File

@ -69,6 +69,7 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer
} }
} }
#[\ReturnTypeWillChange]
public function count() public function count()
{ {
$count = 0; $count = 0;
@ -81,11 +82,13 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer
return $count; return $count;
} }
#[\ReturnTypeWillChange]
public function rewind() public function rewind()
{ {
$this->position = 0; $this->position = 0;
} }
#[\ReturnTypeWillChange]
public function current() public function current()
{ {
if (! $this->valid()) { if (! $this->valid()) {
@ -95,16 +98,19 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer
return $this->vars[$this->idx[$this->position]]; return $this->vars[$this->idx[$this->position]];
} }
#[\ReturnTypeWillChange]
public function key() public function key()
{ {
return $this->idx[$this->position]; return $this->idx[$this->position];
} }
#[\ReturnTypeWillChange]
public function next() public function next()
{ {
++$this->position; ++$this->position;
} }
#[\ReturnTypeWillChange]
public function valid() public function valid()
{ {
return array_key_exists($this->position, $this->idx); return array_key_exists($this->position, $this->idx);

View File

@ -60,7 +60,7 @@ class DaemonProcessState
protected function refreshMessage() protected function refreshMessage()
{ {
$messageParts = []; $messageParts = [];
if (\strlen($this->state)) { if ($this->state !== null && \strlen($this->state)) {
$messageParts[] = $this->state; $messageParts[] = $this->state;
} }
foreach ($this->components as $component => $message) { foreach ($this->components as $component => $message) {

View File

@ -782,7 +782,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
private function setUnresolvedRelation($key, $value) private function setUnresolvedRelation($key, $value)
{ {
if (strlen($value) === 0) { if ($value === null || strlen($value) === 0) {
unset($this->unresolvedRelatedProperties[$key . '_id']); unset($this->unresolvedRelatedProperties[$key . '_id']);
return parent::set($key . '_id', null); return parent::set($key . '_id', null);
} }

View File

@ -37,11 +37,13 @@ class IcingaObjectGroups implements Iterator, Countable, IcingaConfigRenderer
} }
} }
#[\ReturnTypeWillChange]
public function count() public function count()
{ {
return count($this->groups); return count($this->groups);
} }
#[\ReturnTypeWillChange]
public function rewind() public function rewind()
{ {
$this->position = 0; $this->position = 0;
@ -52,6 +54,7 @@ class IcingaObjectGroups implements Iterator, Countable, IcingaConfigRenderer
return $this->modified; return $this->modified;
} }
#[\ReturnTypeWillChange]
public function current() public function current()
{ {
if (! $this->valid()) { if (! $this->valid()) {
@ -61,16 +64,19 @@ class IcingaObjectGroups implements Iterator, Countable, IcingaConfigRenderer
return $this->groups[$this->idx[$this->position]]; return $this->groups[$this->idx[$this->position]];
} }
#[\ReturnTypeWillChange]
public function key() public function key()
{ {
return $this->idx[$this->position]; return $this->idx[$this->position];
} }
#[\ReturnTypeWillChange]
public function next() public function next()
{ {
++$this->position; ++$this->position;
} }
#[\ReturnTypeWillChange]
public function valid() public function valid()
{ {
return array_key_exists($this->position, $this->idx); return array_key_exists($this->position, $this->idx);

View File

@ -36,11 +36,13 @@ class IcingaObjectImports implements Iterator, Countable, IcingaConfigRenderer
$this->object = $object; $this->object = $object;
} }
#[\ReturnTypeWillChange]
public function count() public function count()
{ {
return count($this->imports); return count($this->imports);
} }
#[\ReturnTypeWillChange]
public function rewind() public function rewind()
{ {
$this->position = 0; $this->position = 0;
@ -61,6 +63,7 @@ class IcingaObjectImports implements Iterator, Countable, IcingaConfigRenderer
* @return IcingaObject|null * @return IcingaObject|null
* @throws \Icinga\Exception\NotFoundError * @throws \Icinga\Exception\NotFoundError
*/ */
#[\ReturnTypeWillChange]
public function current() public function current()
{ {
if (! $this->valid()) { if (! $this->valid()) {
@ -72,16 +75,19 @@ class IcingaObjectImports implements Iterator, Countable, IcingaConfigRenderer
); );
} }
#[\ReturnTypeWillChange]
public function key() public function key()
{ {
return $this->idx[$this->position]; return $this->idx[$this->position];
} }
#[\ReturnTypeWillChange]
public function next() public function next()
{ {
++$this->position; ++$this->position;
} }
#[\ReturnTypeWillChange]
public function valid() public function valid()
{ {
return array_key_exists($this->position, $this->idx); return array_key_exists($this->position, $this->idx);

View File

@ -2,6 +2,7 @@
namespace Icinga\Module\Director\Web\Controller; namespace Icinga\Module\Director\Web\Controller;
use gipfl\Translation\StaticTranslator;
use Icinga\Application\Benchmark; use Icinga\Application\Benchmark;
use Icinga\Data\Paginatable; use Icinga\Data\Paginatable;
use Icinga\Exception\NotFoundError; use Icinga\Exception\NotFoundError;
@ -17,7 +18,6 @@ use Icinga\Web\UrlParams;
use InvalidArgumentException; use InvalidArgumentException;
use gipfl\IcingaWeb2\Translator; use gipfl\IcingaWeb2\Translator;
use gipfl\IcingaWeb2\Link; use gipfl\IcingaWeb2\Link;
use gipfl\Translation\TranslationHelper;
use gipfl\IcingaWeb2\Widget\ControlsAndContent; use gipfl\IcingaWeb2\Widget\ControlsAndContent;
use gipfl\IcingaWeb2\Controller\Extension\ControlsAndContentHelper; use gipfl\IcingaWeb2\Controller\Extension\ControlsAndContentHelper;
use gipfl\IcingaWeb2\Zf1\SimpleViewRenderer; use gipfl\IcingaWeb2\Zf1\SimpleViewRenderer;
@ -60,7 +60,7 @@ abstract class ActionController extends Controller implements ControlsAndContent
protected function initializeTranslator() protected function initializeTranslator()
{ {
TranslationHelper::setTranslator(new Translator('director')); StaticTranslator::set(new Translator('director'));
} }
public function getAuth() public function getAuth()

View File

@ -155,6 +155,10 @@ abstract class QuickBaseForm extends Zend_Form implements ValidHtml
protected function valueIsEmpty($value) protected function valueIsEmpty($value)
{ {
if ($value === null) {
return true;
}
if (is_array($value)) { if (is_array($value)) {
return empty($value); return empty($value);
} }

View File

@ -55,7 +55,7 @@ class ActivityLogTable extends ZfQueryBasedTable
return $this::tr([ return $this::tr([
$this::td($this->makeLink($row))->setSeparator(' '), $this::td($this->makeLink($row))->setSeparator(' '),
$this::td(strftime('%H:%M:%S', $row->ts_change_time)) $this::td(date('H:i:s', $row->ts_change_time))
])->addAttributes(['class' => $action]); ])->addAttributes(['class' => $action]);
} }