Skip to content
Snippets Groups Projects

ZERO-162-changes

Open Eduarda Lentz Rodrigues da Silva requested to merge ZERO-162-changes into develop
Compare and Show latest version
13 files
+ 90
77
Compare changes
  • Side-by-side
  • Inline
Files
13
@@ -19,13 +19,14 @@ declare(strict_types=1);
namespace Firegento\ContentProvisioning\Cron;
use Firegento\ContentProvisioning\Model\Console\BlockListCommand;
use Firegento\ContentProvisioning\Model\Query\GetChangedBlockIdentifiers;
use Firegento\ContentProvisioning\Model\Query\GetFilesContentInformation;
use Magento\Framework\Mail\Message;
use Psr\Log\LoggerInterface;
use Magento\Framework\Mail\TransportInterfaceFactory;
use Magento\Framework\App\Config\ScopeConfigInterface;
class InconsistenciesInBlockEmailTest
class InconsistenciesInCmsBlock
{
public const EMAIL_SUBJECT = "Inconsistencies in CMS block";
@@ -38,11 +39,6 @@ class InconsistenciesInBlockEmailTest
*/
private LoggerInterface $logger;
/**
* @var BlockListCommand
*/
private BlockListCommand $blockList;
/**
* @var TransportInterfaceFactory
*/
@@ -58,25 +54,38 @@ class InconsistenciesInBlockEmailTest
*/
private ScopeConfigInterface $scopeConfig;
/**
* @var GetChangedBlockIdentifiers
*/
private GetChangedBlockIdentifiers $getChangedBlockIdentifier;
/**
* @var GetFilesContentInformation
*/
private GetFilesContentInformation $getFilesContentInformation;
/**
* @param LoggerInterface $logger
* @param BlockListCommand $blockList
* @param TransportInterfaceFactory $mailTransportFactory
* @param Message $message
* @param ScopeConfigInterface $scopeConfig
* @param GetFilesContentInformation $getFilesContentInformation
* @param GetChangedBlockIdentifiers $getChangedBlockIdentifier
*/
public function __construct(
LoggerInterface $logger,
BlockListCommand $blockList,
TransportInterfaceFactory $mailTransportFactory,
Message $message,
ScopeConfigInterface $scopeConfig
ScopeConfigInterface $scopeConfig,
GetFilesContentInformation $getFilesContentInformation,
GetChangedBlockIdentifiers $getChangedBlockIdentifier
) {
$this->logger = $logger;
$this->blockList = $blockList;
$this->mailTransportFactory = $mailTransportFactory;
$this->message = $message;
$this->scopeConfig = $scopeConfig;
$this->getFilesContentInformation = $getFilesContentInformation;
$this->getChangedBlockIdentifier = $getChangedBlockIdentifier;
}
/**
@@ -87,15 +96,30 @@ class InconsistenciesInBlockEmailTest
*/
public function execute(): void
{
$changedBlocks = $this->blockList->getChangedEntries();
if ($changedBlocks) {
$emailMessage = $this->blockList->renderValuesForEmail($changedBlocks);
$filesContentInformation = $this->getFilesContentInformation->execute();
$changedBlocksIdentifier = $this->getChangedBlockIdentifier->execute($filesContentInformation);
if ($changedBlocksIdentifier) {
$emailMessage = $this->getValuesForEmail($changedBlocksIdentifier);
$this->sendEmail($emailMessage);
} else {
$this->logger->info("No changed blocks found.");
}
}
/**
* Transform array values into a string to be displayed in the email
* @param array $entries
* @return string
*/
public function getValuesForEmail(array $entries): string
{
$entriesList = [];
foreach ($entries as $entry) {
$entriesList[] = "key: " . $entry['key'] . ", identifier: " . $entry['identifier'];
}
return implode(PHP_EOL, $entriesList);
}
/**
* @param string $message
* @return void
Loading