<commit_before><?php

namespace Orchestra\Tenanti\Console;

use InvalidArgumentException;
use Illuminate\Console\ConfirmableTrait;
use Illuminate\Contracts\Console\Kernel;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class QueuedCommand extends BaseCommand
{
    use ConfirmableTrait;

    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'tenanti:queue';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Running tenanti action command using queue.';

    /**
     * List of valid actions.
     *
     * @var array
     */
    protected $actions = ['install', 'migrate', 'rollback', 'reset', 'refresh'];

    /**
     * Execute the console command.
     *
     * @param  \Illuminate\Contracts\Console\Kernel  $kernel
     *
     * @return void
     */
    public function handle(Kernel $kernel)
    {
        if (! $this->confirmToProceed()) {
            return;
        }

        $driver   = $this->getDriver();
        $action   = $this->argument('action');
        $database = $this->option('database');
        $queue    = $this->option('queue');

        if (! in_array($action, $this->actions)) {
            throw new InvalidArgumentException("Action [{$action}] is not available for this command.");
        }

        $command    = "tenanti:{$action}";
        $parameters = ['driver' => $driver, '--database' => $database, '--force' => true, '--queue' => $queue];

        $migrator = $this->tenant->driver($driver);

        $migrator->executeByChunk(function ($entities) use ($kernel, $command, $parameters) {
            foreach ($entities as $entity) {
                $parameters['--id'] = $entity->getKey();
                $kernel->queue($command, $parameters);
            }
        });
    }

    /**<commit_msg>Queue option is not available at the moment.<commit_after><?php

namespace Orchestra\Tenanti\Console;

use InvalidArgumentException;
use Illuminate\Console\ConfirmableTrait;
use Illuminate\Contracts\Console\Kernel;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class QueuedCommand extends BaseCommand
{
    use ConfirmableTrait;

    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'tenanti:queue';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Running tenanti action command using queue.';

    /**
     * List of valid actions.
     *
     * @var array
     */
    protected $actions = ['install', 'migrate', 'rollback', 'reset', 'refresh'];

    /**
     * Execute the console command.
     *
     * @param  \Illuminate\Contracts\Console\Kernel  $kernel
     *
     * @return void
     */
    public function handle(Kernel $kernel)
    {
        if (! $this->confirmToProceed()) {
            return;
        }

        $driver   = $this->getDriver();
        $action   = $this->argument('action');
        $database = $this->option('database');
        $queue    = $this->option('queue');

        if (! in_array($action, $this->actions)) {
            throw new InvalidArgumentException("Action [{$action}] is not available for this command.");
        }

        $command    = "tenanti:{$action}";
        $parameters = ['driver' => $driver, '--database' => $database, '--force' => true];

        $migrator = $this->tenant->driver($driver);

        $migrator->executeByChunk(function ($entities) use ($kernel, $command, $parameters) {
            foreach ($entities as $entity) {
                $parameters['--id'] = $entity->getKey();
                $kernel->queue($command, $parameters);
            }
        });
    }

    /**
{'fraction_non_alphanumeric': 0.14905362776025236, 'fraction_numerical': 0.0, 'mean_word_length': 2.331873905429072, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, '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': '1855770', 'n_tokens_mistral': 1064, 'n_tokens_neox': 1063, 'n_words': 243}