<commit_before><?php

namespace Tecnocreaciones\Bundle\ToolsBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use RuntimeException;

/**
 * Comando para instalar la app
 */
class InstallCommand extends ContainerAwareCommand
{
    protected function configure()
    {
        $this
            ->setName('tec:install')
            ->setDescription('Install the application')
            ->addOption('reinstall',null,  \Symfony\Component\Console\Input\InputOption::VALUE_NONE,'Reinstall app')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $appName = $this->getContainer()->getParameter('tecnocreaciones_tools.app_name');
        $input->setInteractive((boolean)$this->getContainer()->getParameter('tecnocreaciones_tools.credentials.interactive'));
        
        $env = $input->getOption('env');
        $reinstall = $input->getOption('reinstall');
        $parameters = array();
        $parameters = array_merge($parameters,$input->getArguments());
        foreach ($input->getOptions() as $key => $value) {
            if($key == 'reinstall'){
                continue;
            }
            $parameters['--'.$key] = $value;
        }
        $argvInput = new \Symfony\Component\Console\Input\ArrayInput($parameters);
        if($reinstall){
            $this->runCommand('tec:uninstall', $argvInput, $output);
        }
        $text = "";
        $argvInput->setInteractive($input->isInteractive());
        if($input->isInteractive() === false){
            $text .= '<comment>(No interactive mode)</comment>';
        }
        $output->writeln(sprintf('<info>Installing <comment>%s</comment> in environment <comment>"%s"</comment>.</info> %s',$appName,$env,$text));
        $output->writeln('');

        $this
            //->checkStep($input, $output)
            ->setupStep($argvInput, $output)
        ;

        $output->writeln(sprintf('<info><comment>%s</comment> has been successfully installed.</info>',$appName));
        $output->writeln('');
    }

    protected function checkStep(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('<info>Checking system requirements.</info>');

        $fulfilled = true;

        foreach ($this->getContainer()->get('app.requirements') as $collection) {
            $output->writeln(sprintf('<comment>%s</comment>', $collection->getLabel()));
            foreach ($collection as $requirement) {
                $output->write($requirement->getLabel());
                if ($requirement->isFulfilled()) {
                    $output->writeln(' <info>OK</info>');
                } else {
                    if ($requirement->isRequired()) {
                        $fulfilled = false;
                        $output->writeln(' <error>ERROR</error>');
                        $output->writeln(sprintf('<comment>%s</comment>', $requirement->getHelp()));
                    } else {
                        $output->writeln(' <comment>WARNING</comment>');
                    }
                }
            }
        }

        if (!$fulfilled) {
            throw new RuntimeException('Some system requirements are not fulfilled. Please check output messages and fix them.');
        }

        $output->writeln('');

        return $this;
    }

    protected function setupStep(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('<info>Setting up database.</info>');

        $dialog = $this->getHelperSet()->get('dialog');

        $commands = $this->getContainer()->getParameter('tecnocreaciones_tools.commands');
        $commandsCount = count($commands);
        $i = 1;
        foreach ($commands as $command) {
            $output->writeln(sprintf('<comment>*********</comment> Step (%s/%s) - <info>Running command</info> <comment>"%s"</comment> <comment>*********</comment>',$i,$commandsCount,$command));
            $output->writeln('');
            $this->runCommand($command, $input, $output);
            $output->writeln('');
            $output->writeln(sprintf('<comment>*********</comment> <info>Finish command</info> <comment>"%s"</comment> <comment>*********</comment>',$command));
            $output->writeln('');
            $i++;
        }
        
        $createAdmin = (boolean)$this->getContainer()->getParameter('tecnocreaciones_tools.create_admin');
        if($createAdmin === true){
            $output->writeln('<info>Administration setup.</info>');

            $userManager = $this->getContainer()->get('fos_user.user_manager');<commit_msg>Mejorando comando<commit_after><?php

namespace Tecnocreaciones\Bundle\ToolsBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use RuntimeException;

/**
 * Comando para instalar la app
 */
class InstallCommand extends ContainerAwareCommand
{
    protected function configure()
    {
        $this
            ->setName('tec:install')
            ->setDescription('Install the application')
            ->addOption('reinstall',null,  \Symfony\Component\Console\Input\InputOption::VALUE_NONE,'Reinstall app')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $starttime = microtime(true);
        
        $appName = $this->getContainer()->getParameter('tecnocreaciones_tools.app_name');
        $input->setInteractive((boolean)$this->getContainer()->getParameter('tecnocreaciones_tools.credentials.interactive'));
        
        $env = $input->getOption('env');
        $reinstall = $input->getOption('reinstall');
        $parameters = array();
        $parameters = array_merge($parameters,$input->getArguments());
        foreach ($input->getOptions() as $key => $value) {
            if($key == 'reinstall'){
                continue;
            }
            $parameters['--'.$key] = $value;
        }
        $argvInput = new \Symfony\Component\Console\Input\ArrayInput($parameters);
        if($reinstall){
            $this->runCommand('tec:uninstall', $argvInput, $output);
        }
        $text = "";
        $argvInput->setInteractive($input->isInteractive());
        if($input->isInteractive() === false){
            $text .= '<comment>(No interactive mode)</comment>';
        }
        $output->writeln(sprintf('<info>Installing <comment>%s</comment> in environment <comment>"%s"</comment>.</info> %s',$appName,$env,$text));
        $output->writeln('');

        $this
            //->checkStep($input, $output)
            ->setupStep($argvInput, $output)
        ;

        $endtime = microtime(true);
        $timediff = $endtime - $starttime;
        //Time Elapsed: 
        $output->writeln(sprintf('<info><comment>%s</comment> has been successfully installed in <comment>%s seconds</comment></info>',$appName,sprintf('%02d', $timediff)));
        $output->writeln('');
    }

    protected function checkStep(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('<info>Checking system requirements.</info>');

        $fulfilled = true;

        foreach ($this->getContainer()->get('app.requirements') as $collection) {
            $output->writeln(sprintf('<comment>%s</comment>', $collection->getLabel()));
            foreach ($collection as $requirement) {
                $output->write($requirement->getLabel());
                if ($requirement->isFulfilled()) {
                    $output->writeln(' <info>OK</info>');
                } else {
                    if ($requirement->isRequired()) {
                        $fulfilled = false;
                        $output->writeln(' <error>ERROR</error>');
                        $output->writeln(sprintf('<comment>%s</comment>', $requirement->getHelp()));
                    } else {
                        $output->writeln(' <comment>WARNING</comment>');
                    }
                }
            }
        }

        if (!$fulfilled) {
            throw new RuntimeException('Some system requirements are not fulfilled. Please check output messages and fix them.');
        }

        $output->writeln('');

        return $this;
    }

    protected function setupStep(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('<info>Setting up database.</info>');

        $dialog = $this->getHelperSet()->get('dialog');

        $commands = $this->getContainer()->getParameter('tecnocreaciones_tools.commands');
        $commandsCount = count($commands);
        $i = 1;
        foreach ($commands as $command) {
            $starttime = microtime(true);
            $output->writeln(sprintf('<comment>*********</comment> Step (%s/%s) - <info>Running command</info> <comment>"%s"</comment> <comment>*********</comment>',$i,$commandsCount,$command));
            $output->writeln('');
            $this->runCommand($command, $input, $output);
            $output->writeln('');
            $endtime = microtime(true);
            $timediff = $endtime - $starttime;
            $output->writeln(sprintf('<comment>*********</comment> <info>Finish command</info> <comment>"%s"</comment> in %s seconds <comment>*********</comment>',$command,sprintf('%02d', $timediff)));
            $output->writeln('');
            $i++;
        }
        
        $createAdmin = (boolean)$this->getContainer()->getParameter('tecnocreaciones_tools.create_admin');
        if($createAdmin === true){
            $output->writeln('<info>Administration setup.</info>');

            $userManager = $this->getContainer()->get('fos_user.user_manager');
{'fraction_non_alphanumeric': 0.17154255319148937, 'fraction_numerical': 0.0006137479541734861, 'mean_word_length': 2.5734649122807016, 'pattern_counts': {'":': 0, '<': 95, '<?xml version=': 0, '>': 201, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1749675', 'n_tokens_mistral': 2617, 'n_tokens_neox': 2574, 'n_words': 418}