<commit_before><?php

namespace Oro\Bundle\InstallerBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader;
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Oro\Bundle\InstallerBundle\CommandExecutor;

class LoadFixturesCommand extends ContainerAwareCommand
{
    /**
     * @inheritdoc
     */
    protected function configure()
    {
        $this->setName('oro:package:fixtures:load')
            ->setDescription('Load data fixtures from specified package(s) to your database.')
            ->addArgument(
                'package',
                InputArgument::IS_ARRAY | InputArgument::REQUIRED,
                'Package directories'
            );
    }

    /**
     * @inheritdoc
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        // prepare directories of specified packages
        $packageDirectories = $input->getArgument('package');
        foreach ($packageDirectories as $key => $packageDir) {
            $packageDirectories[$key] = realpath($packageDir) . DIRECTORY_SEPARATOR;
        }

        // a function which allows filter fixtures by the given packages
        $filterByPackage = function ($path) use (&$packageDirectories) {
            foreach ($packageDirectories as $packageDir) {
                if (stripos($path, $packageDir) === 0) {
                    return true;
                }
            }

            return false;
        };

        // prepare data fixture loader
        // we should load only fixtures from the specified packages
        $container   = $this->getContainer();
        $loader      = new ContainerAwareLoader($container);
        $hasFixtures = false;
        foreach ($container->get('kernel')->getBundles() as $bundle) {
            $fixtureDir = $bundle->getPath() . '/DataFixtures/ORM';
            if (is_dir($fixtureDir) && $filterByPackage($fixtureDir)) {
                $loader->loadFromDirectory($fixtureDir);
                $hasFixtures = true;
            }
            break;
        }

        // load data fixtures
        if ($hasFixtures) {
            $output->writeln('Loading data ...');
            $executor = new ORMExecutor($container->get('doctrine.orm.entity_manager'));
            $executor->setLogger(
                function ($message) use ($output) {
                    $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', $message));
                }
            );
            $executor->execute($loader->getFixtures(), true);
        }

        // load workflow definitions
        $this->loadWorkflowDefinitions($input, $output);
    }

    /**
     * @param InputInterface  $input
     * @param OutputInterface $output
     */
    protected function loadWorkflowDefinitions(InputInterface $input, OutputInterface $output)
    {
        $commandExecutor = new CommandExecutor(<commit_msg>BAP-2709: Create command to load workflows.yml  - fixed filter by fixtures<commit_after><?php

namespace Oro\Bundle\InstallerBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader;
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Oro\Bundle\InstallerBundle\CommandExecutor;

class LoadFixturesCommand extends ContainerAwareCommand
{
    /**
     * @inheritdoc
     */
    protected function configure()
    {
        $this->setName('oro:package:fixtures:load')
            ->setDescription('Load data fixtures from specified package(s) to your database.')
            ->addArgument(
                'package',
                InputArgument::IS_ARRAY | InputArgument::REQUIRED,
                'Package directories'
            );
    }

    /**
     * @inheritdoc
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        // prepare directories of specified packages
        $packageDirectories = $input->getArgument('package');
        foreach ($packageDirectories as $key => $packageDir) {
            $packageDirectories[$key] = realpath($packageDir) . DIRECTORY_SEPARATOR;
        }

        // a function which allows filter fixtures by the given packages
        $filterByPackage = function ($path) use (&$packageDirectories) {
            foreach ($packageDirectories as $packageDir) {
                if (stripos($path, $packageDir) === 0) {
                    return true;
                }
            }

            return false;
        };

        // prepare data fixture loader
        // we should load only fixtures from the specified packages
        $container   = $this->getContainer();
        $loader      = new ContainerAwareLoader($container);
        $hasFixtures = false;
        foreach ($container->get('kernel')->getBundles() as $bundle) {
            $fixtureDir = $bundle->getPath() . DIRECTORY_SEPARATOR . 'DataFixtures' . DIRECTORY_SEPARATOR . 'ORM';
            if (is_dir($fixtureDir) && $filterByPackage($fixtureDir)) {
                $loader->loadFromDirectory($fixtureDir);
                $hasFixtures = true;
            }
            break;
        }

        // load data fixtures
        if ($hasFixtures) {
            $output->writeln('Loading data ...');
            $executor = new ORMExecutor($container->get('doctrine.orm.entity_manager'));
            $executor->setLogger(
                function ($message) use ($output) {
                    $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', $message));
                }
            );
            $executor->execute($loader->getFixtures(), true);
        }

        // load workflow definitions
        $this->loadWorkflowDefinitions($input, $output);
    }

    /**
     * @param InputInterface  $input
     * @param OutputInterface $output
     */
    protected function loadWorkflowDefinitions(InputInterface $input, OutputInterface $output)
    {
        $commandExecutor = new CommandExecutor(
{'fraction_non_alphanumeric': 0.11347853535353536, 'fraction_numerical': 0.000946969696969697, 'mean_word_length': 2.3352631578947367, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 47, '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': '3833790', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1592, 'n_words': 341}