Skip to content

Commit 2b4f01b

Browse files
committed
feat: add checker of failed mails for FroshTools
1 parent 40e719d commit 2b4f01b

5 files changed

Lines changed: 109 additions & 0 deletions

File tree

phpstan.neon.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
parameters:
22
level: max
3+
stubFiles:
4+
- stubs/Frosh/Tools/Components/Health/HealthCollection.stub
5+
- stubs/Frosh/Tools/Components/Health/SettingsResult.stub
6+
- stubs/Frosh/Tools/Components/Health/Checker/CheckerInterface.stub
37
paths:
48
- src
59
type_coverage:

src/Services/FroshToolsChecker.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Frosh\MailArchive\Services;
4+
5+
use Frosh\MailArchive\Content\MailArchive\MailArchiveEntity;
6+
use Frosh\Tools\Components\Health\Checker\CheckerInterface;
7+
use Frosh\Tools\Components\Health\HealthCollection;
8+
use Frosh\Tools\Components\Health\SettingsResult;
9+
use Shopware\Core\Framework\Api\Context\SystemSource;
10+
use Shopware\Core\Framework\Context;
11+
use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
12+
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
13+
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
14+
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
15+
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
16+
17+
if (\interface_exists(CheckerInterface::class) &&
18+
\class_exists(HealthCollection::class) &&
19+
\class_exists(SettingsResult::class)) {
20+
#[AutoconfigureTag('frosh_tools.health_checker')]
21+
class FroshToolsChecker implements CheckerInterface
22+
{
23+
/**
24+
* @param EntityRepository<EntityCollection<MailArchiveEntity>> $froshMailArchiveRepository
25+
*/
26+
public function __construct(
27+
private readonly EntityRepository $froshMailArchiveRepository,
28+
) {}
29+
30+
public function collect(HealthCollection $collection): void
31+
{
32+
$criteria = new Criteria();
33+
$criteria->addFilter(new EqualsFilter('transportState', MailSender::TRANSPORT_STATE_FAILED));
34+
35+
$count = $this->froshMailArchiveRepository->searchIds($criteria, new Context(new SystemSource()))->getTotal();
36+
37+
$result = new SettingsResult();
38+
$result->assign([
39+
'id' => 'frosh_mail_archive_failed',
40+
'snippet' => 'Failed mails in MailArchive',
41+
'current' => (string) $count,
42+
'recommended' => '0',
43+
'state' => $count === 0 ? SettingsResult::GREEN : SettingsResult::ERROR,
44+
]);
45+
46+
$collection->add($result);
47+
}
48+
}
49+
} else {
50+
class FroshToolsChecker {}
51+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Frosh\Tools\Components\Health\Checker;
6+
7+
use Frosh\Tools\Components\Health\HealthCollection;
8+
9+
interface CheckerInterface
10+
{
11+
public function collect(HealthCollection $collection): void;
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Frosh\Tools\Components\Health;
6+
7+
use Shopware\Core\Framework\Struct\Collection;
8+
9+
/**
10+
* @extends Collection<SettingsResult>
11+
*/
12+
class HealthCollection extends Collection
13+
{
14+
protected function getExpectedClass(): ?string {}
15+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Frosh\Tools\Components\Health;
6+
7+
use Shopware\Core\Framework\Struct\Struct;
8+
9+
class SettingsResult extends Struct
10+
{
11+
public const GREEN = 'STATE_OK';
12+
public const WARNING = 'STATE_WARNING';
13+
public const ERROR = 'STATE_ERROR';
14+
public const INFO = 'STATE_INFO';
15+
16+
public string $current;
17+
18+
public string $recommended;
19+
20+
public string $state;
21+
22+
public ?string $url = null;
23+
24+
protected string $id;
25+
26+
protected string $snippet;
27+
}

0 commit comments

Comments
 (0)