Skip to content

Commit 48ddf8d

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

5 files changed

Lines changed: 101 additions & 0 deletions

File tree

phpstan.neon.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
parameters:
22
level: max
3+
scanDirectories:
4+
- stubs
35
paths:
46
- src
57
type_coverage:

src/Services/FroshToolsChecker.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
#[AutoconfigureTag('frosh_tools.health_checker')]
18+
class FroshToolsChecker implements CheckerInterface
19+
{
20+
/**
21+
* @param EntityRepository<EntityCollection<MailArchiveEntity>> $froshMailArchiveRepository
22+
*/
23+
public function __construct(
24+
private readonly EntityRepository $froshMailArchiveRepository,
25+
) {}
26+
27+
public function collect(HealthCollection $collection): void
28+
{
29+
$criteria = new Criteria();
30+
$criteria->addFilter(new EqualsFilter('transportState', MailSender::TRANSPORT_STATE_FAILED));
31+
32+
$count = $this->froshMailArchiveRepository->searchIds($criteria, new Context(new SystemSource()))->getTotal();
33+
34+
$result = new SettingsResult();
35+
$result->assign([
36+
'id' => 'frosh_mail_archive_failed',
37+
'snippet' => 'Failed mails in MailArchive',
38+
'current' => (string) $count,
39+
'recommended' => '0',
40+
'state' => $count === 0 ? SettingsResult::GREEN : SettingsResult::ERROR,
41+
]);
42+
43+
$collection->add($result);
44+
}
45+
}
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)