<commit_before><?php

namespace Laraflock\MultiTenant\Commands;

use DB;
use File;
use HynMe\Framework\Exceptions\TenantPropertyException;
use HynMe\Webserver\Helpers\ServerConfigurationHelper;
use Illuminate\Console\Command;
use Laraflock\MultiTenant\Contracts\HostnameRepositoryContract;
use Laraflock\MultiTenant\Contracts\TenantRepositoryContract;
use Laraflock\MultiTenant\Contracts\WebsiteRepositoryContract;
use Laraflock\MultiTenant\Tenant\DatabaseConnection;

class SetupCommand extends Command
{
    /**
     * @var string
     */
    protected $signature = 'multi-tenant:setup
        {--tenant= : Name of the first tenant}
        {--email= : Email address of the first tenant}
        {--hostname= : Domain- or hostname for the first tenant website}
        {--webserver= : Hook into webserver (nginx|apache|no)}';

    /**
     * @var string
     */
    protected $description = 'Final configuration step for hyn multi tenancy packages';

    /**
     * @var ServerConfigurationHelper
     */
    protected $helper;

    /**
     * @var HostnameRepositoryContract
     */
    protected $hostname;
    /**
     * @var WebsiteRepositoryContract
     */
    protected $website;
    /**
     * @var TenantRepositoryContract
     */
    protected $tenant;

    /**
     * @var array
     */
    protected $configuration;

    /**
     * @var int
     */
    protected $step = 1;

    /**
     * @param HostnameRepositoryContract $hostname
     * @param WebsiteRepositoryContract  $website
     * @param TenantRepositoryContract   $tenant
     */
    public function __construct(
        HostnameRepositoryContract $hostname,
        WebsiteRepositoryContract $website,
        TenantRepositoryContract $tenant
    ) {
        parent::__construct();

        $this->hostname = $hostname;
        $this->website = $website;
        $this->tenant = $tenant;

        $this->helper = new ServerConfigurationHelper();
    }

    /**
     * Handles the set up.
     */
    public function handle()
    {
        $this->configuration = config('webserver');

        $name = $this->option('tenant');
        $email = $this->option('email');
        $hostname = $this->option('hostname');

        if (empty($name)) {
            throw new TenantPropertyException('No tenant name given; use --tenant');
        }

        if (empty($email)) {
            throw new TenantPropertyException('No tenant email given; use --email');
        }

        if (empty($hostname)) {
            throw new TenantPropertyException('No tenant hostname given; use --hostname');
        }

        $this->comment('Welcome to hyn multi tenancy.');
        $this->comment('First off, migrations for the packages will run.');

        $this->runMigrations();

        $tenantDirectory = config('multi-tenant.tenant-directory') ? config('multi-tenant.tenant-directory') : storage_path('multi-tenant');

        if (!File::isDirectory($tenantDirectory) && File::makeDirectory($tenantDirectory, 0755, true)) {
            $this->comment("The directory to hold your tenant websites has been created under {$tenantDirectory}.");
        }

        $webserver = null;

        // Setup webserver
        if ($this->helper) {

            // creates directories
            $this->helper->createDirectories();

            $webserver = $this->option('webserver') ?: 'no';

            if ($webserver != 'no') {
                $webserverConfiguration = array_get($this->configuration, $webserver);
                $webserverClass = array_get($webserverConfiguration, 'class');
            } else {
                $webserver = null;<commit_msg>run dashboard setup before running migrations, to prevent laravel default user table to be generated<commit_after><?php

namespace Laraflock\MultiTenant\Commands;

use DB;
use File;
use HynMe\Framework\Exceptions\TenantPropertyException;
use HynMe\Webserver\Helpers\ServerConfigurationHelper;
use Illuminate\Console\Command;
use Laraflock\MultiTenant\Contracts\HostnameRepositoryContract;
use Laraflock\MultiTenant\Contracts\TenantRepositoryContract;
use Laraflock\MultiTenant\Contracts\WebsiteRepositoryContract;
use Laraflock\MultiTenant\Tenant\DatabaseConnection;

class SetupCommand extends Command
{
    /**
     * @var string
     */
    protected $signature = 'multi-tenant:setup
        {--tenant= : Name of the first tenant}
        {--email= : Email address of the first tenant}
        {--hostname= : Domain- or hostname for the first tenant website}
        {--webserver= : Hook into webserver (nginx|apache|no)}';

    /**
     * @var string
     */
    protected $description = 'Final configuration step for hyn multi tenancy packages';

    /**
     * @var ServerConfigurationHelper
     */
    protected $helper;

    /**
     * @var HostnameRepositoryContract
     */
    protected $hostname;
    /**
     * @var WebsiteRepositoryContract
     */
    protected $website;
    /**
     * @var TenantRepositoryContract
     */
    protected $tenant;

    /**
     * @var array
     */
    protected $configuration;

    /**
     * @var int
     */
    protected $step = 1;

    /**
     * @param HostnameRepositoryContract $hostname
     * @param WebsiteRepositoryContract  $website
     * @param TenantRepositoryContract   $tenant
     */
    public function __construct(
        HostnameRepositoryContract $hostname,
        WebsiteRepositoryContract $website,
        TenantRepositoryContract $tenant
    ) {
        parent::__construct();

        $this->hostname = $hostname;
        $this->website = $website;
        $this->tenant = $tenant;

        $this->helper = new ServerConfigurationHelper();
    }

    /**
     * Handles the set up.
     */
    public function handle()
    {
        $this->configuration = config('webserver');

        $name = $this->option('tenant');
        $email = $this->option('email');
        $hostname = $this->option('hostname');

        if (empty($name)) {
            throw new TenantPropertyException('No tenant name given; use --tenant');
        }

        if (empty($email)) {
            throw new TenantPropertyException('No tenant email given; use --email');
        }

        if (empty($hostname)) {
            throw new TenantPropertyException('No tenant hostname given; use --hostname');
        }

        $this->comment('Welcome to hyn multi tenancy.');

        // If the dashboard is installed we need to prevent default laravel migrations
        // so we run the dashboard setup command before running any migrations
        if(class_exists('HynMe\ManagementInterface\ManagementInterfaceServiceProvider'))
        {
            $this->info('The management interface will be installed first.');
            $this->call('dashboard:setup');
        }


        // now we will run all migrations
        $this->comment('First off, migrations for the packages will run.');

        $this->runMigrations();

        $tenantDirectory = config('multi-tenant.tenant-directory') ? config('multi-tenant.tenant-directory') : storage_path('multi-tenant');

        if (!File::isDirectory($tenantDirectory) && File::makeDirectory($tenantDirectory, 0755, true)) {
            $this->comment("The directory to hold your tenant websites has been created under {$tenantDirectory}.");
        }

        $webserver = null;

        // Setup webserver
        if ($this->helper) {

            // creates directories
            $this->helper->createDirectories();

            $webserver = $this->option('webserver') ?: 'no';

            if ($webserver != 'no') {
                $webserverConfiguration = array_get($this->configuration, $webserver);
                $webserverClass = array_get($webserverConfiguration, 'class');
            } else {
                $webserver = null;
{'fraction_non_alphanumeric': 0.11838206878783976, 'fraction_numerical': 0.001288161793121216, 'mean_word_length': 2.5355191256830603, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '2109261', 'n_tokens_mistral': 2060, 'n_tokens_neox': 2052, 'n_words': 503}