<commit_before><?php

namespace Soda\Cms\Console;

use Dotenv\Dotenv;
use Illuminate\Console\Command;

class Setup extends Command {

    protected $signature = 'soda:setup {--s|no-seed : Skip database seeding} {--m|no-migrate : Skip database migration} {--e|no-env : Skip environment variable setup} {--d|no-database : Skip database environment variable setup}';
    protected $description = 'Initial setup command for the Soda Framework';
    protected $except = [];

    public function handle() {
        if (!$this->option('no-env')) {
            $this->updateEnv();
        }

        if (!$this->option('no-migrate')) {
            $this->migrate();
        }

        if (!$this->option('no-seed')) {
            $this->seed();
        }
    }

    protected function updateEnv() {
        $environment_file_path = base_path('.env');

        if (file_exists($environment_file_path)) {
            $contents = file_get_contents($environment_file_path);
            if (!$this->option('no-database')) {
                $base_name = str_slug(basename(base_path()));
                if($base_name == 'src') {
                    $base_name = str_slug(basename(base_path('../')));
                }
                $db_host = $this->ask('Database host', 'localhost');
                $db_name = $this->ask('Database table name', $base_name);
                $db_user = $this->ask('Database user', 'root');
                $db_pass = $this->ask('Database password', false);

                $contents = str_replace('DB_HOST=127.0.0.1', 'DB_HOST='.$db_host, $contents);
                $contents = str_replace('DB_DATABASE=homestead', 'DB_DATABASE='.$db_name, $contents);
                $contents = str_replace('DB_USERNAME=homestead', 'DB_USERNAME='.$db_user, $contents);
                $contents = str_replace('DB_PASSWORD=secret', 'DB_PASSWORD='.$db_pass, $contents);
            }

            $contents = str_replace('CACHE_DRIVER=file', 'CACHE_DRIVER=array', $contents);
            $contents = str_replace('SESSION_DRIVER=file', 'SESSION_DRIVER=database', $contents);
            file_put_contents($environment_file_path, $contents);
        }


        (new Dotenv($this->laravel->environmentPath(), $this->laravel->environmentFile()))->overload();
    }

    protected function migrate() {
        $this->call('session:table');
        $this->call('migrate', [
            '--path' => '/vendor/soda-framework/cms/database/migrations',
        ]);
    }

    protected function seed() {
        $this->call('db:seed', [
            '--class' => 'SodaSeeder',
        ]);
    }
}<commit_msg>Shell exec so app env is reloaded<commit_after><?php

namespace Soda\Cms\Console;

use Dotenv\Dotenv;
use Illuminate\Console\Command;

class Setup extends Command {

    protected $signature = 'soda:setup {--s|no-seed : Skip database seeding} {--m|no-migrate : Skip database migration} {--e|no-env : Skip environment variable setup} {--d|no-database : Skip database environment variable setup}';
    protected $description = 'Initial setup command for the Soda Framework';
    protected $except = [];

    public function handle() {
        if (!$this->option('no-env')) {
            $this->updateEnv();
        }

        if (!$this->option('no-migrate')) {
            $this->migrate();
        }

        if (!$this->option('no-seed')) {
            $this->seed();
        }
    }

    protected function updateEnv() {
        $environment_file_path = base_path('.env');

        if (file_exists($environment_file_path)) {
            $contents = file_get_contents($environment_file_path);
            if (!$this->option('no-database')) {
                $base_name = str_slug(basename(base_path()));
                if($base_name == 'src') {
                    $base_name = str_slug(basename(base_path('../')));
                }
                $db_host = $this->ask('Database host', 'localhost');
                $db_name = $this->ask('Database table name', $base_name);
                $db_user = $this->ask('Database user', 'root');
                $db_pass = $this->ask('Database password', false);

                $contents = str_replace('DB_HOST=127.0.0.1', 'DB_HOST='.$db_host, $contents);
                $contents = str_replace('DB_DATABASE=homestead', 'DB_DATABASE='.$db_name, $contents);
                $contents = str_replace('DB_USERNAME=homestead', 'DB_USERNAME='.$db_user, $contents);
                $contents = str_replace('DB_PASSWORD=<PASSWORD>', 'DB_PASSWORD='.$db_pass, $contents);
            }

            $contents = str_replace('CACHE_DRIVER=file', 'CACHE_DRIVER=array', $contents);
            $contents = str_replace('SESSION_DRIVER=file', 'SESSION_DRIVER=database', $contents);
            file_put_contents($environment_file_path, $contents);
        }

        (new Dotenv($this->laravel->environmentPath(), $this->laravel->environmentFile()))->overload();
    }

    protected function migrate() {
        $this->call('session:table');
        // Shell exec so our config is reloaded.
        shell_exec('php artisan migrate --path=/vendor/soda-framework/cms/database/migrations');
    }

    protected function seed() {
        // Shell exec so our config is reloaded.
        shell_exec('php artisan db:seed --class=SodaSeeder');
    }
}
{'fraction_non_alphanumeric': 0.15900056785917094, 'fraction_numerical': 0.002271436683702442, 'mean_word_length': 2.527369826435247, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '4785022', 'n_tokens_mistral': 1570, 'n_tokens_neox': 1529, 'n_words': 286}