-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Backport command for exporting node types from the database to …
…yaml files Backport command for exporting node types from the database to yaml files
- Loading branch information
1 parent
e84e8f1
commit 2a5dfc0
Showing
22 changed files
with
267 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
lib/RoadizCoreBundle/src/Console/NodeTypesExportFilesCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\CoreBundle\Console; | ||
|
||
use Doctrine\ORM\EntityNotFoundException; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
use RZ\Roadiz\CoreBundle\Entity\NodeType; | ||
use RZ\Roadiz\CoreBundle\NodeType\NodesTypesFilesExporter; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
final class NodeTypesExportFilesCommand extends Command | ||
{ | ||
public function __construct( | ||
private readonly ManagerRegistry $managerRegistry, | ||
private readonly NodesTypesFilesExporter $nodesTypesGenerator, | ||
?string $name = null, | ||
) { | ||
parent::__construct($name); | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
$this->setName('nodetypes:export-files') | ||
->setDescription('Migrate database node-types to YAML files.') | ||
->addArgument('node-type', InputArgument::OPTIONAL, 'Only export specified node type.') | ||
; | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$io = new SymfonyStyle($input, $output); | ||
|
||
try { | ||
if ($nodeType = $input->getArgument('node-type')) { | ||
$nodeTypes = $this->managerRegistry | ||
->getRepository(NodeType::class) | ||
->findBy(['name' => $nodeType]) | ||
; | ||
} else { | ||
/** @var NodeType[] $nodeTypes */ | ||
$nodeTypes = $this->managerRegistry | ||
->getRepository(NodeType::class) | ||
->findAll(); | ||
} | ||
|
||
if (0 === count($nodeTypes)) { | ||
$io->error('No available node-types…'); | ||
|
||
return Command::SUCCESS; | ||
} | ||
|
||
foreach ($nodeTypes as $nt) { | ||
$nodesTypesPath = $this->nodesTypesGenerator->generate($nt); | ||
if (null !== $nodesTypesPath) { | ||
$io->writeln('* Node Type <info>'.$nodesTypesPath.'</info> has been generated.'); | ||
} | ||
} | ||
|
||
return Command::SUCCESS; | ||
} catch (EntityNotFoundException) { | ||
$io->warning('You already use YAML files for your node-types.'); | ||
|
||
return Command::SUCCESS; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.