Newer
Older
<?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 Exception;
use Psr\Log\LoggerInterface;
class GetDbBlockIds
{
/**
* @var GetBlockEntryByKey
*/
private GetBlockEntryByKey $getBlockEntryByKey;
/**
* @var GetBlocksByBlockEntry
*/
private GetBlocksByBlockEntry $getBlocksByBlockEntry;
/**
* @param GetBlockEntryByKey $getBlockEntryByKey
* @param GetBlocksByBlockEntry $getBlocksByBlockEntry
* @param LoggerInterface $logger
*/
public function __construct(
GetBlockEntryByKey $getBlockEntryByKey,
GetBlocksByBlockEntry $getBlocksByBlockEntry,
LoggerInterface $logger
) {
$this->getBlockEntryByKey = $getBlockEntryByKey;
$this->getBlocksByBlockEntry = $getBlocksByBlockEntry;
$this->logger = $logger;
}
/**
* Return block IDs from database
* @param string $key
* @return string
*/
public function execute(string $key): string
{
$blockEntry = $this->getBlockEntryByKey->get($key);
try {
$ids = [];
foreach ($this->getBlocksByBlockEntry->execute($blockEntry) as $block) {
$ids[] = $block->getId();
}
return implode(', ', $ids) . ')';
} catch (Exception $e) {
return $this->logger->error($e->getMessage());