Licitator 1.0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

121 lines
5.1 KiB

<?php
namespace Prometeo\CommandsBundle\Commands;
use Symfony\Component\Console\Command\Command as ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\KernelInterface;
class TemplateToFiles extends ContainerAwareCommand
{
private $em;
public function __construct(ContainerInterface $container)
{
parent::__construct();
$this->em = $container->get('doctrine')->getManager();
}
/**
* {@inheritdoc}
*/
public function configure(): void
{
$this->setName('prometeo:databasetemplate:files');
$this->addArgument(
'folder',
InputArgument::OPTIONAL,
'File with routes to capture'
)
;
}
/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output): void
{
$name = $input->getArgument('folder');
/** @var KernelInterface $kernel */
$kernel = $this->getApplication()->getKernel();
$rootDir = $kernel->getContainer()->getParameter('kernel.root_dir');
$templatesDir=$rootDir.'/../templates/database/templates/';
$templatesPdfDir=$rootDir.'/../templates/database/templates/pdf/';
$templatesMailDir=$rootDir.'/../templates/database/templates/mail/';
$externalsDir=$rootDir.'/../templates/database/externals/';
$componentDir=$rootDir.'/../templates/database/components/';
//Comprobar si existe el directorio database, sino crearlo.
$output->writeln('Comporbando directorio-->'.$rootDir.'/../templates/database'."\n" );
if (!is_dir($dir = $rootDir.'/../templates/database')) {
mkdir($rootDir.'/../templates/database');
}
if (!is_dir($dir = $rootDir.'/../templates/database/templates')) {
mkdir($rootDir.'/../templates/database/templates');
}
if (!is_dir($dir = $rootDir.'/../templates/database/templates/pdf')) {
mkdir($rootDir.'/../templates/database/templates/pdf');
}
if (!is_dir($dir = $rootDir.'/../templates/database/templates/mail')) {
mkdir($rootDir.'/../templates/database/templates/mail');
}
if (!is_dir($dir = $rootDir.'/../templates/database/externals')) {
mkdir($rootDir.'/../templates/database/externals');
}
if (!is_dir($dir = $rootDir.'/../templates/database/components')) {
mkdir($rootDir.'/../templates/database/components');
}
$templates = $this->em->getRepository('App:Template')->findAll();
$externals = $this->em->getRepository('App:External')->findAll();
$components = $this->em->getRepository('App:Component')->findAll();
foreach($templates as $template){
$this->makeFolders($template->getFilename(),$templatesDir );
file_put_contents($templatesDir.$template->getFilename(), $template->getStyle().$template->getJavascript().$template->getSource() );
$output->writeln('Creada plantilla-->'.$templatesDir.$template->getFilename()."\n" );
if(!empty($template->getPdffilename())){
$this->makeFolders($template->getPdffilename(),$templatesPdfDir );
file_put_contents($templatesPdfDir.$template->getPdffilename(), $template->getPdftwig() );
$output->writeln('Creada plantilla-->'.$templatesPdfDir.$template->getPdffilename()."\n" );
}
if(!empty($template->getEmailfilename())){
$this->makeFolders($template->getEmailfilename(),$templatesMailDir );
file_put_contents($templatesMailDir.$template->getEmailfilename(), $template->getEmailtwig() );
$output->writeln('Creada plantilla-->'.$templatesMailDir.$template->getEmailfilename()."\n" );
}
}
foreach($externals as $external){
$this->makeFolders($external->getFilename(),$externalsDir );
file_put_contents($externalsDir.$external->getFilename(), $external->getSource() );
$output->writeln('Creada plantilla-->'.$externalsDir.$external->getFilename()."\n" );
}
foreach($components as $component){
$this->makeFolders($component->getFilename(),$componentDir );
file_put_contents($componentDir.$component->getFilename(), $component->getSource() );
$output->writeln('Creada plantilla-->'.$componentDir.$component->getFilename()."\n" );
}
$output->writeln($name );
}
public function makeFolders($filepath, $base){
$directories = explode( '/', $filepath );
$file = array_pop( $directories );
foreach( $directories as $dir )
{
$path = sprintf( '%s/%s', $base, $dir );
if(!is_dir($path)){
mkdir( $path );
chmod( $path, 777 );
}
$base = $path;
}
}
}