Files
ltsecurityinc/app/code/Plumrocket/GlobalPrivacyControl/Setup/Patch/Data/CreateWellKnownFIle.php
T

102 lines
2.8 KiB
PHP

<?php
/**
* @package Plumrocket_GlobalPrivacyControl
* @copyright Copyright (c) 2025 Plumrocket Inc.
* @license https://plumrocket.com/license End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\GlobalPrivacyControl\Setup\Patch\Data;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Framework\App\Cache\Manager as CacheManager;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Stdlib\DateTime\DateTime;
use Plumrocket\GlobalPrivacyControl\Helper\Config;
use Plumrocket\GlobalPrivacyControl\Service\WellKnownFileManager;
use Psr\Log\LoggerInterface;
class CreateWellKnownFIle implements DataPatchInterface
{
/**
* @var \Plumrocket\GlobalPrivacyControl\Service\WellKnownFileManager
*/
private $wellKnownFileManager;
/**
* @var \Magento\Framework\App\Config\Storage\WriterInterface
*/
private $configWriter;
/**
* @var \Magento\Framework\Stdlib\DateTime\DateTime
*/
private $dateTime;
/**
* @var \Magento\Framework\App\Cache\Manager
*/
private $cacheManager;
/**
* @var \Psr\Log\LoggerInterface
*/
private $logger;
/**
* @param \Plumrocket\GlobalPrivacyControl\Service\WellKnownFileManager $wellKnownFileManager
* @param \Magento\Framework\App\Config\Storage\WriterInterface $configWriter
* @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime
* @param \Magento\Framework\App\Cache\Manager $cacheManager
* @param \Psr\Log\LoggerInterface $logger
*/
public function __construct(
WellKnownFileManager $wellKnownFileManager,
WriterInterface $configWriter,
DateTime $dateTime,
CacheManager $cacheManager,
LoggerInterface $logger
) {
$this->wellKnownFileManager = $wellKnownFileManager;
$this->configWriter = $configWriter;
$this->dateTime = $dateTime;
$this->cacheManager = $cacheManager;
$this->logger = $logger;
}
/**
* @inheirtDoc
*/
public function apply(): CreateWellKnownFIle
{
$date = $this->dateTime->gmtDate('Y-m-d');
$this->configWriter->save(Config::XML_PATH_WELL_KNOWN_LAST_UPDATE_DATE, $date);
$this->cacheManager->clean(['config']);
try {
$this->wellKnownFileManager->create();
} catch (\Throwable $e) {
$this->logger->error('[Plumrocket_GlobalPrivacyControl] Failed to update .well-known file: ' . $e->getMessage(), ['exception' => $e]);
}
return $this;
}
/**
* @inheirtDoc
*/
public static function getDependencies(): array
{
return [];
}
/**
* @inheirtDoc
*/
public function getAliases(): array
{
return [];
}
}