Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion application/forms/ChannelForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@

use DateTime;
use Icinga\Exception\Http\HttpNotFoundException;
use Icinga\Module\Notifications\Model\Channel;
use Icinga\Module\Notifications\Model\AvailableChannelType;
use Icinga\Module\Notifications\Model\Channel;
use Icinga\Module\Notifications\Model\Contact;
use Icinga\Module\Notifications\Model\RuleEscalationRecipient;
use Icinga\Web\Session;
use ipl\Html\Attributes;
use ipl\Html\Contract\FormSubmitElement;
use ipl\Html\FormElement\BaseFormElement;
use ipl\Html\FormElement\FieldsetElement;
use ipl\Html\HtmlElement;
use ipl\I18n\GettextTranslator;
use ipl\I18n\StaticTranslator;
use ipl\Sql\Connection;
Expand Down Expand Up @@ -267,6 +269,24 @@ protected function createConfigElements(string $type, string $config): void
$elementsConfig = json_decode($config, true);

if (empty($elementsConfig)) {
$this->prependHtml(
HtmlElement::create(
'ul',
Attributes::create(['class' => 'errors']),
HtmlElement::create(
'li',
null,
sprintf(
$this->translate(
'Could not decode options for type \'%s\'.'
. ' Check if your database\'s character set is correctly configured.'
),
$type
)
)
)
);

return;
}

Expand Down Expand Up @@ -449,4 +469,20 @@ private function fetchDbValues(): array
'config' => json_decode($channel->config, true) ?? []
];
}

/**
* Validate all elements
*
* @return $this
*/
public function validate(): self
{
parent::validate();

if (! $this->hasElement('config')) {
$this->isValid = false;
}

return $this;
}
}
7 changes: 7 additions & 0 deletions library/Notifications/Common/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@
. ",NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'";
}

if (empty($config->charset)) {
$config->charset = match ($config->db) {
'mysql' => 'utf8mb4',

Check failure on line 87 in library/Notifications/Common/Database.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Syntax error, unexpected T_DOUBLE_ARROW on line 87

Check failure on line 87 in library/Notifications/Common/Database.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.4 on ubuntu-latest

Syntax error, unexpected T_DOUBLE_ARROW on line 87

Check failure on line 87 in library/Notifications/Common/Database.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Syntax error, unexpected T_DOUBLE_ARROW on line 87
default => 'utf8',
};
}

$db = new Connection($config);

Check failure on line 92 in library/Notifications/Common/Database.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Syntax error, unexpected T_VARIABLE on line 92

Check failure on line 92 in library/Notifications/Common/Database.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.4 on ubuntu-latest

Syntax error, unexpected T_VARIABLE on line 92

Check failure on line 92 in library/Notifications/Common/Database.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Syntax error, unexpected T_VARIABLE on line 92

$adapter = $db->getAdapter();

Expand Down Expand Up @@ -133,7 +140,7 @@
if (! empty($candidates)) {
$select->columns(array_keys($candidates));
}
});

Check failure on line 143 in library/Notifications/Common/Database.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.3 on ubuntu-latest

Syntax error, unexpected '}', expecting EOF on line 143

Check failure on line 143 in library/Notifications/Common/Database.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.4 on ubuntu-latest

Syntax error, unexpected '}', expecting EOF on line 143

Check failure on line 143 in library/Notifications/Common/Database.php

View workflow job for this annotation

GitHub Actions / phpstan / Static analysis with phpstan and php 7.2 on ubuntu-latest

Syntax error, unexpected '}', expecting EOF on line 143
}

$db->getQueryBuilder()
Expand Down
Loading