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

ZERO-162 Added moduleConfig to get block information. Deleted unnecessary code.

parent 7d3ea934
No related branches found
No related tags found
1 merge request!46ZERO-162-changes
Pipeline #91872 canceled
...@@ -2,6 +2,21 @@ ...@@ -2,6 +2,21 @@
declare(strict_types=1); 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; namespace Firegento\ContentProvisioning\Model\Console;
use Firegento\ContentProvisioning\Model\Query\GetBlockEntryList as GetBlockEntryList; use Firegento\ContentProvisioning\Model\Query\GetBlockEntryList as GetBlockEntryList;
...@@ -10,7 +25,6 @@ use Firegento\ContentProvisioning\Model\Query\GetFilesContentInformation; ...@@ -10,7 +25,6 @@ use Firegento\ContentProvisioning\Model\Query\GetFilesContentInformation;
use Firegento\ContentProvisioning\Model\RenderChangedBlockList; use Firegento\ContentProvisioning\Model\RenderChangedBlockList;
use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\LocalizedException;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
...@@ -107,38 +121,4 @@ class BlockListCommand extends Command ...@@ -107,38 +121,4 @@ class BlockListCommand extends Command
$files = $this->GetFilesContentInformation->execute(); $files = $this->GetFilesContentInformation->execute();
return $this->getChangedBlocksIdentifier->execute($files); 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;
}
} }
...@@ -19,6 +19,7 @@ declare(strict_types=1); ...@@ -19,6 +19,7 @@ declare(strict_types=1);
namespace Firegento\ContentProvisioning\Model\Query; namespace Firegento\ContentProvisioning\Model\Query;
use Firegento\ContentProvisioning\Model\Config\Data;
use Magento\Framework\Module\ModuleList; use Magento\Framework\Module\ModuleList;
use Magento\Framework\Module\Dir; use Magento\Framework\Module\Dir;
use Magento\Framework\Filesystem\Driver\File; use Magento\Framework\Filesystem\Driver\File;
...@@ -41,19 +42,27 @@ class GetFilesContentInformation ...@@ -41,19 +42,27 @@ class GetFilesContentInformation
*/ */
private File $fileDriver; private File $fileDriver;
/**
* @var Data
*/
private Data $moduleConfig;
/** /**
* @param ModuleList $moduleList * @param ModuleList $moduleList
* @param Dir $moduleDirReader * @param Dir $moduleDirReader
* @param File $fileDriver * @param File $fileDriver
* @param Data $moduleConfig
*/ */
public function __construct( public function __construct(
ModuleList $moduleList, ModuleList $moduleList,
Dir $moduleDirReader, Dir $moduleDirReader,
File $fileDriver File $fileDriver,
Data $moduleConfig
) { ) {
$this->moduleList = $moduleList; $this->moduleList = $moduleList;
$this->moduleDirReader = $moduleDirReader; $this->moduleDirReader = $moduleDirReader;
$this->fileDriver = $fileDriver; $this->fileDriver = $fileDriver;
$this->moduleConfig = $moduleConfig;
} }
/** /**
...@@ -66,32 +75,12 @@ class GetFilesContentInformation ...@@ -66,32 +75,12 @@ class GetFilesContentInformation
return $this->getBlockInformation($this->getContentProvisioningFiles()); return $this->getBlockInformation($this->getContentProvisioningFiles());
} }
/**
* @return mixed
*/
public function getContentProvisioningFiles() public function getContentProvisioningFiles()
{ {
$files = []; return $this->moduleConfig->getList()['blocks'];
$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;
} }
/** /**
...@@ -104,26 +93,16 @@ class GetFilesContentInformation ...@@ -104,26 +93,16 @@ class GetFilesContentInformation
public function getBlockInformation(array $files): array public function getBlockInformation(array $files): array
{ {
$results = []; $results = [];
foreach ($files as $fileName => $fileContent) { foreach ($files as $fileName => $fileData) {
try { $results[] = [
$xml = new \SimpleXMLElement($fileContent); 'identifier' => (string)$fileData['identifier'],
'title' => $fileData['title'],
foreach ($xml->block as $block) { 'key' => (string)$fileData['key'],
$stores = (string)(isset($block->stores->store) && $block->stores->store->attributes() ? 'content' => (string)$fileData['content'],
$block->stores->store->attributes()->code : null); 'stores' => implode(", ", $fileData['stores']),
$results[] = [ 'is_active' => (string)$fileData['is_active'] ? 'yes' : 'no',
'identifier' => (string)$block['identifier'], 'is_maintained' => (string)$fileData['is_maintained'] ? 'yes' : 'no'
'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; return $results;
} }
......
...@@ -19,6 +19,7 @@ declare(strict_types=1); ...@@ -19,6 +19,7 @@ declare(strict_types=1);
namespace Firegento\ContentProvisioning\Model; namespace Firegento\ContentProvisioning\Model;
use Firegento\ContentProvisioning\Model\Query\GetExistsInDbValueByKey; use Firegento\ContentProvisioning\Model\Query\GetExistsInDbValueByKey;
use Symfony\Component\Console\Helper\Table;
class RenderChangedBlockList class RenderChangedBlockList
{ {
......
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