Skip to content

Commit 63cab4c

Browse files
authored
feat: add checker of failed mails for FroshTools (#103)
1 parent 941a561 commit 63cab4c

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
"shopware/core": "~6.6.0 || ~6.7.0",
4444
"zbateson/mail-mime-parser": "^3.0"
4545
},
46+
"require-dev": {
47+
"frosh/tools": ">2.0.0"
48+
},
4649
"config": {
4750
"allow-plugins": {
4851
"symfony/runtime": true

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+
}

0 commit comments

Comments
 (0)