Skip to content

Commit

Permalink
Task: Add workflow lowest php version (#7)
Browse files Browse the repository at this point in the history
* Task: Add workflow lowest php version

* Task: Add workflow lowest php version

* Task: Add workflow lowest php version

* Task: Add workflow lowest php version

* Disable OpenSearch client logger for Pimcore X

* Disable OpenSearch client logger for Pimcore X

* Fix Pimcore X support

* Fix codeception

* Add TODO hint

---------

Co-authored-by: markus-moser <markus.moser@pimcore.com>
  • Loading branch information
robertSt7 and markus-moser committed Feb 27, 2024
1 parent 94d0388 commit 0f3229d
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/codeception.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ env:
PIMCORE_PROJECT_ROOT: ${{ github.workspace }}
APP_ENV: test
PIMCORE_TEST: 1
SYMFONY_DEPRECATIONS_HELPER: weak # TODO remove when remove support for Pimcore 10

jobs:
codeception-tests:
Expand All @@ -27,6 +28,7 @@ jobs:
strategy:
matrix:
include:
- { php-version: 8.0, dependencies: lowest, pimcore_version: "", experimental: false }
- { php-version: 8.1, dependencies: lowest, pimcore_version: "", experimental: false }
- { php-version: 8.2, dependencies: highest, pimcore_version: "", experimental: false }

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
strategy:
matrix:
include:
- { php-version: "8.0", dependencies: "lowest", experimental: false }
- { php-version: "8.1", dependencies: "lowest", experimental: false }
- { php-version: "8.2", dependencies: "highest", experimental: false }
- { php-version: "8.2", dependencies: "highest", pimcore_version: "11.x-dev as 11.99.9", experimental: true }
Expand Down
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@
"opensearch-project/opensearch-php": "^2.2.0"
},
"require-dev": {
"roave/security-advisories": "dev-latest",
"codeception/codeception": "^5.0.10",
"codeception/codeception": "^4.1.12 || ^5.0.10",
"codeception/phpunit-wrapper": "^9",
"codeception/module-asserts": "^2",
"codeception/module-symfony": "^3.1.1",
"codeception/module-symfony": "^1.6.0 || ^3.1.1",
"phpstan/phpstan": "^1.10.5",
"phpstan/phpstan-symfony": "^1.2.20",
"phpunit/phpunit": "10.2.7",
"phpunit/phpunit": "^9.3 || 10.2.7",
"nyholm/psr7": "^1",
"symfony/phpunit-bridge": "^6",
"fakerphp/faker": "^1.23"
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ parameters:
- phpstan-bootstrap.php
excludePaths:
- src/Tests/*
- src/LogHandler/Filter404Handler.php # TODO remove when remove support for Pimcore 10

includes:
- phpstan-baseline.neon
57 changes: 31 additions & 26 deletions src/LogHandler/Filter404Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,41 @@
use Monolog\Handler\AbstractHandler;
use Monolog\Level;
use Monolog\LogRecord;
use Pimcore\Version;

/**
* Ignores warning messages for 404 errors as they are spamming the logs
*
* @internal
*/
final class Filter404Handler extends AbstractHandler
{
private bool $ignoreNextResponseWarning = false;
// TODO remove if when remove support for Pimcore 10
if(Version::getMajorVersion() >= 11) {

public function isHandling(LogRecord $record): bool
/**
* Ignores warning messages for 404 errors as they are spamming the logs
*
* @internal
*/
final class Filter404Handler extends AbstractHandler
{
$ignore =
$record->level === Level::Warning
&& ($record->context['HTTP code'] ?? null) === 404;

if ($ignore) {
$this->ignoreNextResponseWarning = true;
} else {
$ignore = $this->ignoreNextResponseWarning
&& $record->level === Level::Warning
&& $record->message === 'Response';
$this->ignoreNextResponseWarning = false;
private bool $ignoreNextResponseWarning = false;

public function isHandling(LogRecord $record): bool
{
$ignore =
$record->level === Level::Warning
&& ($record->context['HTTP code'] ?? null) === 404;

if ($ignore) {
$this->ignoreNextResponseWarning = true;
} else {
$ignore = $this->ignoreNextResponseWarning
&& $record->level === Level::Warning
&& $record->message === 'Response';
$this->ignoreNextResponseWarning = false;
}

return $ignore;
}

return $ignore;
}

public function handle(LogRecord $record): bool
{
return $this->isHandling($record);
public function handle(LogRecord $record): bool
{
return $this->isHandling($record);
}
}
}
12 changes: 8 additions & 4 deletions src/OpenSearchClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use OpenSearch\Client;
use OpenSearch\ClientBuilder;
use Pimcore\Bundle\OpenSearchClientBundle\LogHandler\Filter404Handler;
use Pimcore\Version;
use Psr\Log\LoggerInterface;

/**
Expand All @@ -29,11 +30,14 @@ public static function createOpenSearchClient(LoggerInterface $logger, array $co
$clientBuilder = new ClientBuilder();
$clientBuilder->setHosts($config['hosts']);

if (!$config['log_404_errors'] && $logger instanceof Logger) {
$logger->pushHandler(new Filter404Handler());
}
// TODO remove if when remove support for Pimcore 10
if (Version::getMajorVersion() >= 11) {
if (!$config['log_404_errors'] && $logger instanceof Logger) {
$logger->pushHandler(new Filter404Handler());
}

$clientBuilder->setLogger($logger);
$clientBuilder->setLogger($logger);
}

if (isset($config['username'], $config['password'])) {
$clientBuilder->setBasicAuthentication($config['username'], $config['password']);
Expand Down

0 comments on commit 0f3229d

Please sign in to comment.