diff --git a/Model/Console/BlockListCommand.php b/Model/Console/BlockListCommand.php index a1995fe3a87ff6d78fcd1fdf324e5ff4e63384c4..19af88f72504b26751d19c7ed90378eb3fd6cb9b 100644 --- a/Model/Console/BlockListCommand.php +++ b/Model/Console/BlockListCommand.php @@ -2,6 +2,21 @@ declare(strict_types=1); +/** + * Copyright (c) 2024 TechDivision GmbH + * All rights reserved + * + * This product includes proprietary software developed at TechDivision GmbH, Germany + * For more information see https://www.techdivision.com/ + * + * To obtain a valid license for using this software please contact us at + * license@techdivision.com + * + * @copyright Copyright (c) 2024 TechDivision GmbH (https://www.techdivision.com) + * @author TechDivision Team Zero <zero@techdivision.com> + * @link https://www.techdivision.com/ + */ + namespace Firegento\ContentProvisioning\Model\Console; use Firegento\ContentProvisioning\Model\Query\GetBlockEntryList as GetBlockEntryList; @@ -10,7 +25,6 @@ use Firegento\ContentProvisioning\Model\Query\GetFilesContentInformation; use Firegento\ContentProvisioning\Model\RenderChangedBlockList; use Magento\Framework\Exception\LocalizedException; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -107,38 +121,4 @@ class BlockListCommand extends Command $files = $this->GetFilesContentInformation->execute(); return $this->getChangedBlocksIdentifier->execute($files); } - - /** - * Return array with block information from content_provisioning file - * @param array $files - * @return array - * @throws \Exception - * @SuppressWarnings(PHPMD.UnusedLocalVariable) - */ - public function getBlockInformation(array $files): array - { - $results = []; - foreach ($files as $fileName => $fileContent) { - try { - $xml = new \SimpleXMLElement($fileContent); - - foreach ($xml->block as $block) { - $stores = (string)(isset($block->stores->store) && $block->stores->store->attributes() ? - $block->stores->store->attributes()->code : null); - $results[] = [ - 'identifier' => (string)$block['identifier'], - 'key' => (string)$block['key'], - 'content' => (string)$block->content, - 'stores' => $stores, - 'is_active' => (string)$block['active'] ? 'yes' : 'no', - 'is_maintained' => (string)$block['maintained'] ? 'yes' : 'no', - 'title' => $block->title - ]; - } - } catch (LocalizedException $e) { - error_log($e->getMessage()); - } - } - return $results; - } } diff --git a/Model/Query/GetFilesContentInformation.php b/Model/Query/GetFilesContentInformation.php index e11f08cfd952cf50ab1ed5dbb9dc5ab7c24ab8e1..366909b4fb6524f728453cadf66e27c019d48bfd 100644 --- a/Model/Query/GetFilesContentInformation.php +++ b/Model/Query/GetFilesContentInformation.php @@ -19,6 +19,7 @@ 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; @@ -41,19 +42,27 @@ class GetFilesContentInformation */ 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 + File $fileDriver, + Data $moduleConfig ) { $this->moduleList = $moduleList; $this->moduleDirReader = $moduleDirReader; $this->fileDriver = $fileDriver; + $this->moduleConfig = $moduleConfig; } /** @@ -66,32 +75,12 @@ class GetFilesContentInformation return $this->getBlockInformation($this->getContentProvisioningFiles()); } + /** + * @return mixed + */ public function getContentProvisioningFiles() { - $files = []; - $modules = $this->moduleList->getAll(); - - foreach ($modules as $moduleName => $moduleData) { - try { - $modulePath = $this->moduleDirReader->getDir($moduleName); - - // only app/code modules - if (!str_contains($modulePath, 'app/code')) { - continue; - } - - $moduleEtcPath = $this->moduleDirReader->getDir($moduleName, Dir::MODULE_ETC_DIR); - $provisionFilePath = $moduleEtcPath . DIRECTORY_SEPARATOR . 'content_provisioning.xml'; - - if ($this->fileDriver->isExists($provisionFilePath)) { - $content = $this->fileDriver->fileGetContents($provisionFilePath); - $files[$moduleName] = $content; - } - } catch (LocalizedException $e) { - return 'ERROR: ' . $e->getMessage(); - } - } - return $files; + return $this->moduleConfig->getList()['blocks']; } /** @@ -104,26 +93,16 @@ class GetFilesContentInformation public function getBlockInformation(array $files): array { $results = []; - foreach ($files as $fileName => $fileContent) { - try { - $xml = new \SimpleXMLElement($fileContent); - - foreach ($xml->block as $block) { - $stores = (string)(isset($block->stores->store) && $block->stores->store->attributes() ? - $block->stores->store->attributes()->code : null); - $results[] = [ - 'identifier' => (string)$block['identifier'], - 'key' => (string)$block['key'], - 'content' => (string)$block->content, - 'stores' => $stores, - 'is_active' => (string)$block['active'] ? 'yes' : 'no', - 'is_maintained' => (string)$block['maintained'] ? 'yes' : 'no', - 'title' => $block->title - ]; - } - } catch (LocalizedException $e) { - error_log($e->getMessage()); - } + foreach ($files as $fileName => $fileData) { + $results[] = [ + 'identifier' => (string)$fileData['identifier'], + 'title' => $fileData['title'], + 'key' => (string)$fileData['key'], + 'content' => (string)$fileData['content'], + 'stores' => implode(", ", $fileData['stores']), + 'is_active' => (string)$fileData['is_active'] ? 'yes' : 'no', + 'is_maintained' => (string)$fileData['is_maintained'] ? 'yes' : 'no' + ]; } return $results; } diff --git a/Model/RenderChangedBlockList.php b/Model/RenderChangedBlockList.php index 402f82a93c1d2beab68c294234b33a0c732d896f..9c4c130e7e7ce459d3ff89153f32dd1cf46bd7b9 100644 --- a/Model/RenderChangedBlockList.php +++ b/Model/RenderChangedBlockList.php @@ -19,6 +19,7 @@ declare(strict_types=1); namespace Firegento\ContentProvisioning\Model; use Firegento\ContentProvisioning\Model\Query\GetExistsInDbValueByKey; +use Symfony\Component\Console\Helper\Table; class RenderChangedBlockList {