36 lines
1.1 KiB
PHP
36 lines
1.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\SeventeenTrack\Model;
|
|
|
|
use Magento\AdminNotification\Model\Inbox;
|
|
use Magento\Framework\App\CacheInterface;
|
|
|
|
class SyncFailureNotifier
|
|
{
|
|
private const CACHE_PREFIX = 'esun_17track_notification_';
|
|
private const CACHE_LIFETIME = 86400;
|
|
|
|
public function __construct(
|
|
private readonly Inbox $inbox,
|
|
private readonly CacheInterface $cache
|
|
) {
|
|
}
|
|
|
|
public function notify(?int $code, string $message): void
|
|
{
|
|
$identifier = self::CACHE_PREFIX . hash('sha256', (string)$code . '|' . $message);
|
|
if ($this->cache->load($identifier) !== false) {
|
|
return;
|
|
}
|
|
$title = in_array($code, [-18019907, -18019908], true)
|
|
? (string)__('17TRACK quota is exhausted')
|
|
: (string)__('17TRACK synchronization requires attention');
|
|
$this->inbox->addCritical(
|
|
$title,
|
|
(string)__('%1 Check Stores > Configuration > Esun > 17TRACK.', $message)
|
|
);
|
|
$this->cache->save('1', $identifier, [], self::CACHE_LIFETIME);
|
|
}
|
|
}
|