2015-12-14 22:37:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
2016-01-15 02:16:58 +00:00
|
|
|
use App\Models\User;
|
2016-01-15 07:28:34 +00:00
|
|
|
use DB;
|
2016-04-02 13:16:09 +00:00
|
|
|
use Exception;
|
2015-12-14 22:37:46 +00:00
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Support\Facades\Artisan;
|
2017-01-06 03:04:08 +00:00
|
|
|
use MediaCache;
|
2015-12-14 22:37:46 +00:00
|
|
|
|
|
|
|
class Init extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-01-15 02:16:58 +00:00
|
|
|
protected $signature = 'koel:init';
|
2015-12-14 22:37:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-01-15 02:16:58 +00:00
|
|
|
protected $description = 'Install or upgrade Koel';
|
2015-12-14 22:37:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2016-01-15 02:16:58 +00:00
|
|
|
try {
|
|
|
|
DB::connection();
|
2016-04-02 13:16:09 +00:00
|
|
|
} catch (Exception $e) {
|
2016-01-15 02:16:58 +00:00
|
|
|
$this->error('Unable to connect to database.');
|
|
|
|
$this->error('Please fill valid database credentials into .env and rerun this command.');
|
2015-12-14 22:37:46 +00:00
|
|
|
|
2016-01-15 02:16:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-01-15 07:28:34 +00:00
|
|
|
|
2016-01-15 02:16:58 +00:00
|
|
|
$this->comment('Attempting to install or upgrade Koel.');
|
|
|
|
$this->comment('Remember, you can always install/upgrade manually following the guide here:');
|
2017-03-01 11:06:07 +00:00
|
|
|
$this->info('📙 '.config('koel.misc.docs_url').PHP_EOL);
|
2015-12-14 22:37:46 +00:00
|
|
|
|
2016-08-21 15:19:03 +00:00
|
|
|
if (!config('app.key')) {
|
2016-01-15 02:16:58 +00:00
|
|
|
$this->info('Generating app key');
|
|
|
|
Artisan::call('key:generate');
|
|
|
|
} else {
|
|
|
|
$this->comment('App key exists -- skipping');
|
|
|
|
}
|
2015-12-14 22:37:46 +00:00
|
|
|
|
2016-08-21 15:19:03 +00:00
|
|
|
if (!config('jwt.secret')) {
|
2016-01-15 02:16:58 +00:00
|
|
|
$this->info('Generating JWT secret');
|
|
|
|
Artisan::call('koel:generate-jwt-secret');
|
|
|
|
} else {
|
|
|
|
$this->comment('JWT secret exists -- skipping');
|
|
|
|
}
|
2016-01-15 07:28:34 +00:00
|
|
|
|
2016-01-15 02:16:58 +00:00
|
|
|
$this->info('Migrating database');
|
2015-12-14 22:37:46 +00:00
|
|
|
Artisan::call('migrate', ['--force' => true]);
|
2017-01-06 03:04:08 +00:00
|
|
|
// Clean the media cache, just in case we did any media-related migration
|
|
|
|
MediaCache::clear();
|
2015-12-14 22:37:46 +00:00
|
|
|
|
2016-01-15 02:16:58 +00:00
|
|
|
if (!User::count()) {
|
|
|
|
$this->info('Seeding initial data');
|
|
|
|
Artisan::call('db:seed', ['--force' => true]);
|
|
|
|
} else {
|
|
|
|
$this->comment('Data seeded -- skipping');
|
|
|
|
}
|
2015-12-14 22:37:46 +00:00
|
|
|
|
2017-03-27 10:09:05 +00:00
|
|
|
$this->info('Compiling front-end stuff');
|
2016-12-02 09:39:31 +00:00
|
|
|
system('yarn install');
|
2015-12-14 22:37:46 +00:00
|
|
|
|
2016-08-16 15:12:11 +00:00
|
|
|
$this->comment(PHP_EOL.'🎆 Success! You can now run Koel from localhost with `php artisan serve`.');
|
2016-01-15 02:16:58 +00:00
|
|
|
$this->comment('Again, for more configuration guidance, refer to');
|
2017-03-01 11:06:07 +00:00
|
|
|
$this->info('📙 '.config('koel.misc.docs_url'));
|
|
|
|
$this->comment('Thanks for using Koel. You rock!');
|
2015-12-14 22:37:46 +00:00
|
|
|
}
|
|
|
|
}
|