Skip to content
Snippets Groups Projects
Commit 5e1c5de7 authored by Eduarda Lentz Rodrigues da Silva's avatar Eduarda Lentz Rodrigues da Silva
Browse files

ZERO-162 Updated model and cron files

parent efa9d6d7
No related branches found
No related tags found
1 merge request!46ZERO-162-changes
......@@ -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.");
......
......@@ -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);
}
}
......@@ -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) {
......
......@@ -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();
......
......@@ -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;
......
......@@ -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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment