2017-11-01 16:43:42 +00:00
|
|
|
<?php
|
|
|
|
|
|
2019-11-16 07:21:14 +00:00
|
|
|
namespace Akaunting\Module\Commands;
|
2017-11-01 16:43:42 +00:00
|
|
|
|
2020-06-12 08:51:37 +00:00
|
|
|
use App\Abstracts\Commands\Module as Command;
|
2020-06-11 20:40:24 +00:00
|
|
|
use App\Events\Module\Installed;
|
2020-06-11 20:32:13 +00:00
|
|
|
use App\Models\Module\Module as Model;
|
2017-11-01 16:43:42 +00:00
|
|
|
|
2020-06-12 08:51:37 +00:00
|
|
|
class InstallCommand extends Command
|
2017-11-01 16:43:42 +00:00
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* The name and signature of the console command.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2020-02-03 15:57:31 +00:00
|
|
|
protected $signature = 'module:install {alias} {company} {locale=en-GB}';
|
2017-11-01 16:43:42 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The console command description.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $description = 'Install the specified module.';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Execute the console command.
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
public function handle()
|
|
|
|
|
{
|
2020-06-11 20:32:13 +00:00
|
|
|
$this->prepare();
|
2020-02-03 15:57:31 +00:00
|
|
|
|
2020-07-01 06:02:19 +00:00
|
|
|
if ($this->getModel()) {
|
|
|
|
|
$this->comment("Module [{$this->alias}] is already installed.");
|
2023-11-03 14:05:40 +00:00
|
|
|
|
2020-07-01 06:02:19 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-11 20:32:13 +00:00
|
|
|
$this->changeRuntime();
|
2019-12-03 12:41:56 +00:00
|
|
|
|
2020-06-11 20:32:13 +00:00
|
|
|
// Create db
|
|
|
|
|
$this->model = Model::create([
|
|
|
|
|
'company_id' => $this->company_id,
|
|
|
|
|
'alias' => $this->alias,
|
2019-11-16 07:21:14 +00:00
|
|
|
'enabled' => '1',
|
2021-09-07 07:33:34 +00:00
|
|
|
'created_from' => source_name(),
|
|
|
|
|
'created_by' => user_id(),
|
2019-12-03 12:41:56 +00:00
|
|
|
]);
|
2018-05-09 19:22:02 +00:00
|
|
|
|
2020-06-11 20:32:13 +00:00
|
|
|
$this->createHistory('installed');
|
2020-02-07 11:37:22 +00:00
|
|
|
|
2020-12-24 22:45:30 +00:00
|
|
|
event(new Installed($this->alias, $this->company_id, $this->locale));
|
2017-11-02 09:07:15 +00:00
|
|
|
|
2020-06-11 20:32:13 +00:00
|
|
|
$this->revertRuntime();
|
2018-12-25 13:49:37 +00:00
|
|
|
|
2020-06-12 08:57:18 +00:00
|
|
|
$this->info("Module [{$this->alias}] installed!");
|
2017-11-01 16:43:42 +00:00
|
|
|
}
|
|
|
|
|
}
|