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