diff --git a/Cron/InconsistenciesInBlockEmail.php b/Cron/InconsistenciesInBlockEmail.php index a3915deabae78e78bc35ef7499a93361a1c12fe0..ce51355a2f5fc607b303757d7088aa9f1824c50b 100644 --- a/Cron/InconsistenciesInBlockEmail.php +++ b/Cron/InconsistenciesInBlockEmail.php @@ -98,7 +98,7 @@ class InconsistenciesInBlockEmail { $changedBlocks = $this->blockList->getChangedEntries(); if ($changedBlocks) { - $emailMessage = $this->renderChangedBlockList->renderValuesForEmail($changedBlocks); + $emailMessage = $this->renderChangedBlockList->getValuesForEmail($changedBlocks); $this->sendEmail($emailMessage); } else { $this->logger->info("No changed blocks found."); diff --git a/Model/Console/BlockListCommand.php b/Model/Console/BlockListCommand.php index 19af88f72504b26751d19c7ed90378eb3fd6cb9b..d7731c3b335aee3fe2d9cd1179a116938bbf6238 100644 --- a/Model/Console/BlockListCommand.php +++ b/Model/Console/BlockListCommand.php @@ -19,8 +19,8 @@ declare(strict_types=1); namespace Firegento\ContentProvisioning\Model\Console; -use Firegento\ContentProvisioning\Model\Query\GetBlockEntryList as GetBlockEntryList; -use Firegento\ContentProvisioning\Model\Query\GetChangedBlocksIdentifier; +use Firegento\ContentProvisioning\Model\Query\GetBlockEntryList; +use Firegento\ContentProvisioning\Model\Query\GetChangedBlockIdentifiers; use Firegento\ContentProvisioning\Model\Query\GetFilesContentInformation; use Firegento\ContentProvisioning\Model\RenderChangedBlockList; use Magento\Framework\Exception\LocalizedException; @@ -42,9 +42,9 @@ class BlockListCommand extends Command private GetBlockEntryList $getAllBlockEntries; /** - * @var GetChangedBlocksIdentifier + * @var GetChangedBlockIdentifiers */ - private GetChangedBlocksIdentifier $getChangedBlocksIdentifier; + private GetChangedBlockIdentifiers $getChangedBlocksIdentifier; /** * @var RenderChangedBlockList @@ -54,24 +54,24 @@ class BlockListCommand extends Command /** * @var GetFilesContentInformation */ - private GetFilesContentInformation $GetFilesContentInformation; + private GetFilesContentInformation $getFilesContentInformation; /** * @param GetBlockEntryList $getAllBlockEntries * @param GetFilesContentInformation $getFilesContentInformation - * @param GetChangedBlocksIdentifier $getChangedBlocksIdentifier + * @param GetChangedBlockIdentifiers $getChangedBlocksIdentifier * @param RenderChangedBlockList $renderChangedBlockList * @param string|null $name */ public function __construct( GetBlockEntryList $getAllBlockEntries, GetFilesContentInformation $getFilesContentInformation, - GetChangedBlocksIdentifier $getChangedBlocksIdentifier, + GetChangedBlockIdentifiers $getChangedBlocksIdentifier, RenderChangedBlockList $renderChangedBlockList, string $name = null ) { $this->getAllBlockEntries = $getAllBlockEntries; - $this->GetFilesContentInformation = $getFilesContentInformation; + $this->getFilesContentInformation = $getFilesContentInformation; $this->getChangedBlocksIdentifier = $getChangedBlocksIdentifier; $this->renderChangedBlockList = $renderChangedBlockList; parent::__construct($name); @@ -118,7 +118,7 @@ class BlockListCommand extends Command */ public function getChangedEntries(): ?array { - $files = $this->GetFilesContentInformation->execute(); + $files = $this->getFilesContentInformation->execute(); return $this->getChangedBlocksIdentifier->execute($files); } } diff --git a/Model/Query/GetChangedBlockIdentifiers.php b/Model/Query/GetChangedBlockIdentifiers.php index 888706095528f94a539ccf221a6b50d1db557eac..8240d1663183ffa69f47b69a58e5c72d97f7f3e2 100644 --- a/Model/Query/GetChangedBlockIdentifiers.php +++ b/Model/Query/GetChangedBlockIdentifiers.php @@ -18,9 +18,9 @@ declare(strict_types=1); namespace Firegento\ContentProvisioning\Model\Query; -use Firegento\ContentProvisioning\Model\Query\GetBlockEntryByKey; +use Magento\Framework\Exception\LocalizedException; -class GetChangedBlocksIdentifier +class GetChangedBlockIdentifiers { /** * @var GetBlockEntryByKey @@ -40,9 +40,9 @@ class GetChangedBlocksIdentifier * Return array with changed blocks identifier * * @param array $filesPath - * @return array + * @return array|string */ - public function execute(array $filesPath): array + public function execute(array $filesPath) { $changedBlocks = []; foreach ($filesPath as $file) { diff --git a/Model/Query/GetDbBlockIds.php b/Model/Query/GetDbBlockIds.php index c27c4d64ea72f5c3173489c005644e8ea0a8dd52..af4e5ee99fc97d20867745bf904d6608d82e7569 100644 --- a/Model/Query/GetDbBlockIds.php +++ b/Model/Query/GetDbBlockIds.php @@ -20,7 +20,7 @@ namespace Firegento\ContentProvisioning\Model\Query; use Magento\Framework\Exception\LocalizedException; -class GetDbBlockDataByKey +class GetDbBlockIds { /** * @var GetBlockEntryByKey @@ -45,7 +45,7 @@ class GetDbBlockDataByKey } /** - * Prepare items array by transforming all configured entries into content entry data models + * Return block IDs from database * @param string $key * @return string */ @@ -58,10 +58,6 @@ class GetDbBlockDataByKey $ids[] = $block->getId(); } - if (empty($ids)) { - return 'Nothing found'; - } - return implode(', ', $ids) . ')'; } catch (LocalizedException $noSuchEntityException) { return 'ERROR: ' . $noSuchEntityException->getMessage(); diff --git a/Model/Query/GetFilesContentInformation.php b/Model/Query/GetFilesContentInformation.php index 366909b4fb6524f728453cadf66e27c019d48bfd..acd815b25dd0338ab2ecdf1e8d7be5e7f612e7e1 100644 --- a/Model/Query/GetFilesContentInformation.php +++ b/Model/Query/GetFilesContentInformation.php @@ -20,88 +20,41 @@ declare(strict_types=1); namespace Firegento\ContentProvisioning\Model\Query; use Firegento\ContentProvisioning\Model\Config\Data; -use Magento\Framework\Module\ModuleList; -use Magento\Framework\Module\Dir; -use Magento\Framework\Filesystem\Driver\File; use Magento\Framework\Exception\LocalizedException; class GetFilesContentInformation { - /** - * @var ModuleList - */ - private ModuleList $moduleList; - - /** - * @var Dir - */ - private Dir $moduleDirReader; - - /** - * @var File - */ - private File $fileDriver; - /** * @var Data */ private Data $moduleConfig; /** - * @param ModuleList $moduleList - * @param Dir $moduleDirReader - * @param File $fileDriver * @param Data $moduleConfig */ public function __construct( - ModuleList $moduleList, - Dir $moduleDirReader, - File $fileDriver, Data $moduleConfig ) { - $this->moduleList = $moduleList; - $this->moduleDirReader = $moduleDirReader; - $this->fileDriver = $fileDriver; $this->moduleConfig = $moduleConfig; } /** - * @return array|string - * @SuppressWarnings(PHPMD.UnusedLocalVariable) - * @throws \Exception - */ - public function execute() - { - return $this->getBlockInformation($this->getContentProvisioningFiles()); - } - - /** - * @return mixed - */ - public function getContentProvisioningFiles() - { - return $this->moduleConfig->getList()['blocks']; - } - - /** - * Return array with block information from content_provisioning file - * @param array $files * @return array - * @throws \Exception * @SuppressWarnings(PHPMD.UnusedLocalVariable) + * @throws \Exception */ - public function getBlockInformation(array $files): array + public function execute(): array { $results = []; - foreach ($files as $fileName => $fileData) { + foreach ($this->moduleConfig->getList()['blocks'] as $fileData) { $results[] = [ - 'identifier' => (string)$fileData['identifier'], + 'identifier' => $fileData['identifier'], 'title' => $fileData['title'], - 'key' => (string)$fileData['key'], - 'content' => (string)$fileData['content'], + 'key' => $fileData['key'], + 'content' => $fileData['content'], 'stores' => implode(", ", $fileData['stores']), - 'is_active' => (string)$fileData['is_active'] ? 'yes' : 'no', - 'is_maintained' => (string)$fileData['is_maintained'] ? 'yes' : 'no' + 'is_active' => $fileData['is_active'], + 'is_maintained' => $fileData['is_maintained'] ]; } return $results; diff --git a/Model/RenderChangedBlockList.php b/Model/RenderChangedBlockList.php index 9c4c130e7e7ce459d3ff89153f32dd1cf46bd7b9..e797ddac0ace755d7eb22f7d9edc8e9c99228208 100644 --- a/Model/RenderChangedBlockList.php +++ b/Model/RenderChangedBlockList.php @@ -18,20 +18,25 @@ declare(strict_types=1); namespace Firegento\ContentProvisioning\Model; -use Firegento\ContentProvisioning\Model\Query\GetExistsInDbValueByKey; +use Firegento\ContentProvisioning\ViewModel\ChangedBlockDataProvider; use Symfony\Component\Console\Helper\Table; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; class RenderChangedBlockList { /** - * @var GetExistsInDbValueByKey + * @var ChangedBlockDataProvider */ - private GetExistsInDbValueByKey $getExistsInDbValue; + private ChangedBlockDataProvider $changedBlockDataProvider; + /** + * @param ChangedBlockDataProvider $changedBlockDataProvider + */ public function __construct( - GetExistsInDbValueByKey $getExistsInDbValue + ChangedBlockDataProvider $changedBlockDataProvider ) { - $this->getExistsInDbValue = $getExistsInDbValue; + $this->changedBlockDataProvider = $changedBlockDataProvider; } /** @@ -39,30 +44,11 @@ class RenderChangedBlockList * @param InputInterface $input * @param OutputInterface $output * @param array $entries - * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function renderTable(InputInterface $input, OutputInterface $output, array $entries) { - $table = new Table($output); - $table->setHeaders(['Key', 'Identifier', 'Stores', 'Maintained', 'Active', 'Title', 'in DB (IDs)']); - - foreach ($entries as $entry) { - $table->addRow( - [ - $entry['key'], - $entry['identifier'], - (!empty($entry['stores'])) ? (is_array($entry['stores']) ? - implode(', ', $entry['stores']) : $entry['stores']) : "null", - $entry['is_maintained'], - $entry['is_active'], - $entry['title'], - $this->getExistsInDbValue->execute($entry['key']), - ] - ); - } - - $table->render($output); + $this->changedBlockDataProvider->execute($input, $output, $entries); } /** @@ -70,14 +56,12 @@ class RenderChangedBlockList * @param array $entries * @return string */ - public function renderValuesForEmail(array $entries): string + public function getValuesForEmail(array $entries): string { $entriesList = []; foreach ($entries as $entry) { - $entriesList[] = "key: " . $entry['key']; - $entriesList[] = "identifier: " . $entry['identifier']; + $entriesList[] = "key: " . $entry['key'] . ", identifier: " . $entry['identifier']; } - $separatedEntries = implode(", ", $entriesList); - return $separatedEntries; + return implode(PHP_EOL, $entriesList); } }