Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement strategy provider logic #25

Open
wants to merge 32 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
96b038f
Refactore Console Command Directory
Jun 1, 2019
3599a7f
Introduce Entry Builder Buisness Logic
Jun 1, 2019
d73af81
Add Builder Logic and refactore Strategies
Jun 1, 2019
4bf7ebb
Initialize integration tests for export functionality
vadimjustus Jun 1, 2019
df92771
Merge branch '13-export-cli-command' of https://github.com/magento-ha…
vadimjustus Jun 1, 2019
34e3310
Add Config Generation
Jun 1, 2019
e95d5a2
Finalize integration test for block export
vadimjustus Jun 1, 2019
f303ce3
Merge branch '13-export-cli-command' of https://github.com/magento-ha…
vadimjustus Jun 1, 2019
cc7f4d9
Update strategy logic and
vadimjustus Jun 1, 2019
f5e3e7a
Imporve integration tests for export functionality
vadimjustus Jun 1, 2019
1e9a146
Merge branch 'develop' into 13-export-cli-command
vadimjustus Jun 1, 2019
91623da
Implement export strategy logic
vadimjustus Jun 2, 2019
493da32
Introduce a xml generator chain
Jun 2, 2019
c229e4c
Update integration tests
vadimjustus Jun 2, 2019
3b8eb46
Merge branch '13-export-cli-command' of https://github.com/magento-ha…
vadimjustus Jun 2, 2019
f9b0fb9
Fix xpath selection for sub-nodes in generators
vadimjustus Jun 2, 2019
708a4d9
Remove old _files from integration tests
vadimjustus Jun 2, 2019
4b0817c
Add page export integration test
vadimjustus Jun 2, 2019
612a325
[#13] Generate Generator
Jun 2, 2019
3aaab5c
Configure DI for generators
vadimjustus Jun 2, 2019
3a306dd
Add BlockNodeGenerator and casting services classes
vadimjustus Jun 2, 2019
314db78
Make it possible to remove childnodes of xml
Jun 2, 2019
db994c2
Finalize block and page node generator
vadimjustus Jun 2, 2019
4fc4e01
Implement content generator
vadimjustus Jun 2, 2019
e5d1ca9
Implement StoresGenerator
Jun 2, 2019
305fd9c
Use getNodeByKey service class in order to avoid duplicate code
vadimjustus Jun 2, 2019
6297488
Chance sort order of generators
Jun 2, 2019
63f10a6
Add Design and Custom Design Generator and add to page chain generation
Jun 2, 2019
bf93937
Cast Int to String to dont confuse the tests
Jun 2, 2019
487b469
Add Title Generator and fix wrong date in integration test
Jun 2, 2019
39c884a
Oops forgot to add title generator to di.xml
Jun 2, 2019
abc835e
Implement Seo Generator
Jun 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Api/Data/BlockEntryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

interface BlockEntryInterface extends BlockInterface, EntryInterface
{

}
16 changes: 16 additions & 0 deletions Api/ExportInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);

namespace Firegento\ContentProvisioning\Api;

use Firegento\ContentProvisioning\Api\Data\EntryInterface;

interface ExportInterface
{
/**
* @param StrategyInterface $strategy
* @param EntryInterface $entry
* @return void
*/
public function execute(StrategyInterface $strategy, EntryInterface $entry): void;
}
32 changes: 32 additions & 0 deletions Api/StrategyInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);

namespace Firegento\ContentProvisioning\Api;

interface StrategyInterface
{
/**
* @return string
*/
public function getXmlPath(): string;

/**
* @return string
*/
public function getContentDirectoryPath(): string;

/**
* @return string
*/
public function getMediaDirectoryPath(): string;

/**
* @return string
*/
public function getContentNamespacePath(): string;

/**
* @return string
*/
public function getMediaNamespacePath(): string;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace Firegento\ContentProvisioning\Model\Console;
namespace Firegento\ContentProvisioning\Console;

use Firegento\ContentProvisioning\Model\Command\ApplyBlockEntry;
use Firegento\ContentProvisioning\Model\Query\GetBlockEntryByKey;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace Firegento\ContentProvisioning\Model\Console;
namespace Firegento\ContentProvisioning\Console;

use Firegento\ContentProvisioning\Model\Command\ApplyPageEntry;
use Firegento\ContentProvisioning\Model\Query\GetPageEntryByKey;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace Firegento\ContentProvisioning\Model\Console;
namespace Firegento\ContentProvisioning\Console;

use Firegento\ContentProvisioning\Api\Data\BlockEntryInterface;
use Firegento\ContentProvisioning\Model\Query\GetBlockEntryList\Proxy as GetBlockEntryList;
Expand All @@ -25,17 +25,18 @@ class BlockListCommand extends Command
private $getBlocksByBlockEntry;

/**
* @param GetBlockEntryList $getAllBlockEntries
* @param GetBlockEntryList $getAllBlockEntries
* @param GetBlocksByBlockEntry $getBlocksByBlockEntry
* @param string|null $name
* @param string|null $name
*/
public function __construct(
GetBlockEntryList $getAllBlockEntries,
GetBlockEntryList $getAllBlockEntries,
GetBlocksByBlockEntry $getBlocksByBlockEntry,
string $name = null
string $name = null
) {
parent::__construct($name);
$this->getAllBlockEntries = $getAllBlockEntries;

$this->getAllBlockEntries = $getAllBlockEntries;
$this->getBlocksByBlockEntry = $getBlocksByBlockEntry;
}

Expand Down
94 changes: 94 additions & 0 deletions Console/ExportCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php
declare(strict_types=1);

namespace Firegento\ContentProvisioning\Console;

use Firegento\ContentProvisioning\Api\ExportInterface;
use Firegento\ContentProvisioning\Model\EntryBuilder;
use Firegento\ContentProvisioning\Model\Strategy\ExportToModule;
use Firegento\ContentProvisioning\Model\Strategy\ExportToModuleFactory;
use Firegento\ContentProvisioning\Model\Strategy\ExportToVar;
use Firegento\ContentProvisioning\Model\Strategy\ExportToVarFactory;
use Magento\Framework\Exception\InputException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NotFoundException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class ExportCommand extends Command
{
/**
* @var EntryBuilder
*/
private $entryBuilder;

/**
* @var ExportToModuleFactory
*/
private $exportToModuleFactory;

/**
* @var ExportToVarFactory
*/
private $exportToVarFactory;

/**
* @var ExportInterface
*/
private $export;

/**
* @param EntryBuilder $entryBuilder
* @param ExportInterface $export
* @param ExportToModuleFactory $exportToModuleFactory
* @param ExportToVarFactory $exportToVarFactory
* @param string $name
*/
public function __construct(
EntryBuilder $entryBuilder,
ExportInterface $export,
ExportToModuleFactory $exportToModuleFactory,
ExportToVarFactory $exportToVarFactory,
string $name
) {
parent::__construct($name);

$this->entryBuilder = $entryBuilder;
$this->exportToModuleFactory = $exportToModuleFactory;
$this->exportToVarFactory = $exportToVarFactory;
$this->export = $export;
}

/**
* @inheritdoc
*/
protected function configure()
{
parent::configure();
}

/**
* {@inheritdoc}
* @throws NotFoundException
* @throws InputException
* @throws LocalizedException
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$moduleName = $input->getArgument('module');
$cmsType = $input->getArgument('cms_type');
$identifier = $input->getArgument('identifier');

switch ($input->getArgument('strategy')) {
case 'var':
$strategy = $this->exportToVarFactory->create(['data' => ['moduleName' => $moduleName]]);
break;
default:
$strategy = $this->exportToModuleFactory->create(['data' => ['moduleName' => $moduleName]]);
}

$entry = $this->entryBuilder->build($cmsType, $identifier);
$this->export->execute($strategy, $entry);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace Firegento\ContentProvisioning\Model\Console;
namespace Firegento\ContentProvisioning\Console;

use Firegento\ContentProvisioning\Api\Data\EntryInterface;
use Firegento\ContentProvisioning\Api\Data\PageEntryInterface;
Expand All @@ -26,18 +26,19 @@ class PageListCommand extends Command
private $getPagesByPageEntry;

/**
* @param GetPageEntryList $getAllContentEntries
* @param GetPageEntryList $getAllContentEntries
* @param GetPagesByPageEntry $getPagesByPageEntry
* @param string|null $name
* @param string|null $name
*/
public function __construct(
GetPageEntryList $getAllContentEntries,
GetPageEntryList $getAllContentEntries,
GetPagesByPageEntry $getPagesByPageEntry,
string $name = null
string $name = null
) {
parent::__construct($name);

$this->getAllContentEntries = $getAllContentEntries;
$this->getPagesByPageEntry = $getPagesByPageEntry;
$this->getPagesByPageEntry = $getPagesByPageEntry;
}

/**
Expand Down
55 changes: 55 additions & 0 deletions Model/Builder/Block.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);

namespace Firegento\ContentProvisioning\Model\Builder;

use Firegento\ContentProvisioning\Api\Data\BlockEntryInterface;
use Firegento\ContentProvisioning\Api\Data\BlockEntryInterfaceFactory;
use Magento\Cms\Api\BlockRepositoryInterface;
use Magento\Cms\Api\Data\BlockInterface;
use Magento\Cms\Model\Block as MageCmsBlock;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\Exception\LocalizedException;

class Block
{
/**
* @var BlockRepositoryInterface
*/
private $blockRepository;
/**
* @var BlockEntryInterfaceFactory
*/
private $blockEntryInterfaceFactory;
/**
* @var SearchCriteriaBuilder
*/
private $searchCriteriaBuilder;

public function __construct(
BlockRepositoryInterface $blockRepository,
BlockEntryInterfaceFactory $blockEntryInterfaceFactory,
SearchCriteriaBuilder $searchCriteriaBuilder
) {
$this->blockRepository = $blockRepository;
$this->blockEntryInterfaceFactory = $blockEntryInterfaceFactory;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
}

/**
* @param string $identifier
* @return BlockEntryInterface
* @throws LocalizedException
*/
public function build(string $identifier): BlockEntryInterface
{
$searchCriteria = $this->searchCriteriaBuilder
->addFilter('identifier', $identifier, 'eq')
->create();

/** @var BlockInterface|MageCmsBlock $block */
$block = $this->blockRepository->getList($searchCriteria);

return $this->blockEntryInterfaceFactory->create(['data' => $block->getData()]);
}
}
55 changes: 55 additions & 0 deletions Model/Builder/Page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);

namespace Firegento\ContentProvisioning\Model\Builder;

use Firegento\ContentProvisioning\Api\Data\PageEntryInterface;
use Firegento\ContentProvisioning\Api\Data\PageEntryInterfaceFactory;
use Magento\Cms\Api\Data\PageInterface;
use Magento\Cms\Api\PageRepositoryInterface;
use Magento\Cms\Model\Page as MageCmsPage;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\Exception\LocalizedException;

class Page
{
/**
* @var PageRepositoryInterface
*/
private $pageRepository;
/**
* @var PageEntryInterfaceFactory
*/
private $pageEntryInterfaceFactory;
/**
* @var SearchCriteriaBuilder
*/
private $searchCriteriaBuilder;

public function __construct(
PageRepositoryInterface $pageRepository,
PageEntryInterfaceFactory $pageEntryInterfaceFactory,
SearchCriteriaBuilder $searchCriteriaBuilder
) {
$this->pageRepository = $pageRepository;
$this->pageEntryInterfaceFactory = $pageEntryInterfaceFactory;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
}

/**
* @param string $identifier
* @return PageEntryInterface
* @throws LocalizedException
*/
public function build(string $identifier): PageEntryInterface
{
$searchCriteria = $this->searchCriteriaBuilder
->addFilter('identifier', $identifier, 'eq')
->create();

/** @var PageInterface|MageCmsPage $page */
$page = array_shift($this->pageRepository->getList($searchCriteria)->getItems());

return $this->pageEntryInterfaceFactory->create(['data' => $page->getData()]);
}
}
Loading