Akaunting/overrides/akaunting/laravel-module/Commands/DisableCommand.php

60 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2018-05-21 15:10:43 +00:00
<?php
2019-11-16 07:21:14 +00:00
namespace Akaunting\Module\Commands;
2018-05-21 15:10:43 +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\Disabled;
2018-05-21 15:10:43 +00:00
2020-06-12 08:51:37 +00:00
class DisableCommand extends Command
2018-05-21 15:10:43 +00:00
{
/**
2018-05-21 18:54:32 +00:00
* The name and signature of the console command.
*
* @var string
*/
2020-06-11 20:32:13 +00:00
protected $signature = 'module:disable {alias} {company} {locale=en-GB}';
2018-05-21 15:10:43 +00:00
/**
2018-05-21 18:54:32 +00:00
* The console command description.
*
* @var string
*/
2018-05-21 15:10:43 +00:00
protected $description = 'Disable the specified module.';
/**
2018-05-21 18:54:32 +00:00
* Execute the console command.
*
* @return mixed
*/
2018-05-21 15:10:43 +00:00
public function handle()
{
2020-06-11 20:32:13 +00:00
$this->prepare();
2018-05-21 15:17:54 +00:00
2023-11-03 14:05:40 +00:00
if (! $this->getModel()) {
2020-06-11 20:32:13 +00:00
$this->info("Module [{$this->alias}] not found.");
2023-11-03 14:05:40 +00:00
2020-06-11 20:32:13 +00:00
return;
}
2018-05-21 15:10:43 +00:00
2020-11-13 12:37:46 +00:00
if (!$this->model->enabled) {
2020-06-11 20:32:13 +00:00
$this->comment("Module [{$this->alias}] is already disabled.");
2023-11-03 14:05:40 +00:00
2018-05-21 15:17:54 +00:00
return;
}
2020-06-11 20:32:13 +00:00
$this->changeRuntime();
2018-05-21 15:10:43 +00:00
2020-06-11 20:32:13 +00:00
// Update db
2020-11-13 12:37:46 +00:00
$this->model->enabled = false;
2020-06-11 20:32:13 +00:00
$this->model->save();
2018-05-21 15:17:54 +00:00
2020-06-11 20:32:13 +00:00
$this->createHistory('disabled');
2018-05-21 15:17:54 +00:00
2020-06-11 20:40:24 +00:00
event(new Disabled($this->alias, $this->company_id));
2018-05-21 15:10:43 +00:00
2020-06-11 20:32:13 +00:00
$this->revertRuntime();
2019-11-16 07:21:14 +00:00
2020-06-11 20:32:13 +00:00
$this->info("Module [{$this->alias}] disabled.");
2018-05-21 15:10:43 +00:00
}
}