Skip to content
Snippets Groups Projects
Unverified Commit d467479e authored by Vadim Justus's avatar Vadim Justus Committed by GitHub
Browse files

Merge pull request #26 from deiserh/7-added_add_by_key_command

Added command to add blocks and pages by key to resolve #7 
parents c3f9816f 958e54c1
No related branches found
No related tags found
No related merge requests found
<?php
declare(strict_types=1);
namespace Firegento\ContentProvisioning\Model\Console;
use Firegento\ContentProvisioning\Model\Command\ApplyBlockEntry;
use Firegento\ContentProvisioning\Model\Query\GetBlockEntryByKey;
use Firegento\ContentProvisioning\Model\Query\GetBlockEntryList\Proxy as GetBlockEntryList;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class AddBlockCommand extends Command
{
const ARG_BLOCK_KEY = 'key';
/**
* @var GetBlockEntryByKey
*/
private $getBlockEntryByKey;
/**
* @var ApplyBlockEntry
*/
private $applyBlockEntry;
/**
* @param GetBlockEntryList $getBlockEntryByKey
* @param string|null $name
*/
public function __construct(
GetBlockEntryByKey $getBlockEntryByKey,
ApplyBlockEntry $applyBlockEntry,
string $name = null
) {
parent::__construct($name);
$this->getBlockEntryByKey = $getBlockEntryByKey;
$this->applyBlockEntry = $applyBlockEntry;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$key = $input->getArgument(self::ARG_BLOCK_KEY);
$block = $this->getBlockEntryByKey->get($key);
$this->applyBlockEntry->execute($block);
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('content-provisioning:block:apply');
$this->setDescription('Add a block by key');
$this->addArgument(
self::ARG_BLOCK_KEY,
InputArgument::REQUIRED,
'The key of the block to apply.'
);
parent::configure();
}
}
<?php
declare(strict_types=1);
namespace Firegento\ContentProvisioning\Model\Console;
use Firegento\ContentProvisioning\Model\Command\ApplyPageEntry;
use Firegento\ContentProvisioning\Model\Query\GetPageEntryByKey;
use Firegento\ContentProvisioning\Model\Query\GetPageEntryList\Proxy as GetPageEntryList;
use Firegento\ContentProvisioning\Model\Query\GetPagesByPageEntry\Proxy as GetPagesByPageEntry;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class AddPageCommand extends Command
{
const ARG_PAGE_KEY = 'key';
/**
* @var GetPageEntryByKey
*/
private $getPageEntryByKey;
/**
* @var ApplyPageEntry
*/
private $applyPageEntry;
/**
* @param GetPageEntryList $getAllContentEntries
* @param GetPagesByPageEntry $getPagesByPageEntry
* @param string|null $name
*/
public function __construct(
GetPageEntryByKey $getPageEntryByKey,
ApplyPageEntry $applyPageEntry,
string $name = null
) {
parent::__construct($name);
$this->getPageEntryByKey = $getPageEntryByKey;
$this->applyPageEntry = $applyPageEntry;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$key = $input->getArgument(self::ARG_PAGE_KEY);
$page = $this->getPageEntryByKey->get($key);
$this->applyPageEntry->execute($page);
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('content-provisioning:page:apply');
$this->setDescription('Add a page by key');
$this->addArgument(
self::ARG_PAGE_KEY,
InputArgument::REQUIRED,
'The key of the page to apply.'
);
parent::configure();
}
}
<?php
declare(strict_types=1);
namespace Firegento\ContentProvisioning\Model\Query;
use Firegento\ContentProvisioning\Api\ConfigurationInterface;
use Firegento\ContentProvisioning\Api\Data\BlockEntryInterface;
use Firegento\ContentProvisioning\Api\Data\BlockEntryInterfaceFactory;
use Magento\Framework\Exception\NotFoundException;
class GetBlockEntryByKey
{
/**
* @var ConfigurationInterface
*/
private $configuration;
/**
* @var BlockEntryInterfaceFactory
*/
private $blockEntryFactory;
/**
* @param ConfigurationInterface $configuration
* @param BlockEntryInterfaceFactory $blockEntryFactory
*/
public function __construct(
ConfigurationInterface $configuration,
BlockEntryInterfaceFactory $blockEntryFactory
) {
$this->configuration = $configuration;
$this->blockEntryFactory = $blockEntryFactory;
}
/**
* @return BlockEntryInterface[]
* @throws NotFoundException
*/
public function get(string $key)
{
$blocks = $this->configuration->getList()['blocks'] ?? [];
if (!array_key_exists($key, $blocks)) {
throw new NotFoundException(__('Block with key %1 not found.', $key));
}
$item = $this->blockEntryFactory->create(['data' => $blocks[$key]]);
return $item;
}
}
<?php
declare(strict_types=1);
namespace Firegento\ContentProvisioning\Model\Query;
use Firegento\ContentProvisioning\Api\ConfigurationInterface;
use Firegento\ContentProvisioning\Api\Data\PageEntryInterface;
use Firegento\ContentProvisioning\Api\Data\PageEntryInterfaceFactory;
use Magento\Framework\Exception\NotFoundException;
class GetPageEntryByKey
{
/**
* @var ConfigurationInterface
*/
private $configuration;
/**
* @var PageEntryInterfaceFactory
*/
private $pageEntryFactory;
/**
* @param ConfigurationInterface $configuration
* @param PageEntryInterfaceFactory $pageEntryFactory
*/
public function __construct(
ConfigurationInterface $configuration,
PageEntryInterfaceFactory $pageEntryFactory
) {
$this->configuration = $configuration;
$this->pageEntryFactory = $pageEntryFactory;
}
/**
* @param string $key
*
* @return PageEntryInterface
* @throws NotFoundException
*/
public function get(string $key)
{
$pages = $this->configuration->getList()['pages'] ?? [];
if (!array_key_exists($key, $pages)) {
throw new NotFoundException(__('Page with key %1 not found.', $key));
}
$item = $this->pageEntryFactory->create(['data' => $pages[$key]]);
return $item;
}
}
......@@ -85,6 +85,8 @@
<argument name="commands" xsi:type="array">
<item name="contentProvisioning.PageList" xsi:type="object">Firegento\ContentProvisioning\Model\Console\PageListCommand</item>
<item name="contentProvisioning.BlockList" xsi:type="object">Firegento\ContentProvisioning\Model\Console\BlockListCommand</item>
<item name="contentProvisioning.PageAdd" xsi:type="object">Firegento\ContentProvisioning\Model\Console\AddPageCommand</item>
<item name="contentProvisioning.BlockAdd" xsi:type="object">Firegento\ContentProvisioning\Model\Console\AddBlockCommand</item>
</argument>
</arguments>
</type>
......
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