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();
if (version_compare($version, '2.8.2', '>=')
&& version_compare($version, '2.10.2', '<')
if ($version === null || (version_compare($version, '2.8.2', '>=')
&& version_compare($version, '2.10.2', '<'))
) {
$this->client->disconnect();
$this->client->setKeepAlive(false);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -55,7 +55,7 @@ class ActivityLogTable extends ZfQueryBasedTable
return $this::tr([
$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]);
}