gestione gare pubbliche
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

62 righe
1.8 KiB

<?php
namespace App\Console\Commands\Database\Tenant;
use App\Models\Main\Tenant;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Config;
class InstallCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'tenantdb:install
{--database : The database connection to use}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create the migration repository';
/**
* The repository instance.
*
* @var \Illuminate\Database\Migrations\MigrationRepositoryInterface
*/
protected $repository;
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
if (\file_exists(\dirname(base_path()) . "/config.json")) {
$this->config = \json_decode(\file_get_contents(\dirname(base_path()) . "/config.json"), 1);
$options = ['--path' => 'database/migrations/tenant', '--database' => 'mysql-tenant'];
if(!empty( $this->option('database'))) { $options['--database'] = $this->option('database'); }
Tenant::whereNotNull('dominio')->where('dominio','<>','')->where('db','S')->chunk(10, function($tenants) use ($options) {
foreach($tenants as $tenant) {
Config::set('database.connections.mysql-tenant.database', "{$this->config["prefix_db"]}_ente{$tenant->codice}");
DB::purge('mysql-tenant');
$this->info("Processing: {$tenant->denominazione}");
$this->call('migrate:install', $options);
}
});
}
}
}