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
2 files
+ 10
7
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 86
0
<?php
declare(strict_types=1);
/**
* Copyright (c) 2025 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) 2025 TechDivision GmbH (https://www.techdivision.com)
* @author TechDivision Team Zero <zero@techdivision.com>
* @link https://www.techdivision.com/
*/
namespace Firegento\ContentProvisioning\Model\Query;
use Psr\Log\LoggerInterface;
use Exception;
use Firegento\ContentProvisioning\Model\DTO\CmsBlockDto;
class GetChangedBlockIdentifiers
{
/**
* @var GetCmsBlockByIdentifier
*/
private GetCmsBlockByIdentifier $getCmsBlockByIdentifier;
/**
* @var LoggerInterface
*/
private LoggerInterface $logger;
/**
* @var GetDbCmsBlockContent
*/
private GetDbCmsBlockContent $getDbCmsBlockContent;
/**
* @param GetCmsBlockByIdentifier $getCmsBlockByIdentifier
* @param LoggerInterface $logger
* @param GetDbCmsBlockContent $getDbCmsBlockContent
*/
public function __construct(
GetCmsBlockByIdentifier $getCmsBlockByIdentifier,
LoggerInterface $logger,
GetDbCmsBlockContent $getDbCmsBlockContent
) {
$this->getCmsBlockByIdentifier = $getCmsBlockByIdentifier;
$this->logger = $logger;
$this->getDbCmsBlockContent = $getDbCmsBlockContent;
}
/**
* Return array with changed blocks identifier
*
* @param CmsBlockDto[] $cmsBlockPaths
* @return array
*/
public function execute(array $cmsBlockPaths): array
{
$changedBlocks = [];
foreach ($cmsBlockPaths as $cmsBlock) {
try {
// Get Block content and Store(s) from code
$codeFileContent = $cmsBlock->getContent();
$codeStoresCode = $cmsBlock->getStoreCodes();
// Get all blocks with this identifier from database
$dbBlocks = $this->getCmsBlockByIdentifier->execute($cmsBlock->getIdentifier());
$dbBlockContent = $this->getDbCmsBlockContent->execute($dbBlocks, $codeStoresCode);
} catch (Exception $e) {
$this->logger->error($e->getMessage());
return [];
}
if (!empty($dbBlockContent[0]) && $codeFileContent !== $dbBlockContent[0]) {
$changedBlocks[] = $cmsBlock;
}
}
return $changedBlocks;
}
}
Loading