2020-12-24 02:16:00 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs\Install;
|
|
|
|
|
|
|
|
use App\Abstracts\Job;
|
2022-02-14 18:00:44 +03:00
|
|
|
use App\Traits\Modules;
|
2020-12-24 02:16:00 +03:00
|
|
|
use App\Utilities\Console;
|
|
|
|
|
|
|
|
class EnableModule extends Job
|
|
|
|
{
|
2022-02-14 18:00:44 +03:00
|
|
|
use Modules;
|
|
|
|
|
2020-12-24 02:16:00 +03:00
|
|
|
protected $alias;
|
|
|
|
|
|
|
|
protected $company_id;
|
|
|
|
|
|
|
|
protected $locale;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @param $alias
|
|
|
|
* @param $company_id
|
|
|
|
* @param $locale
|
|
|
|
*/
|
2020-12-25 12:08:15 +03:00
|
|
|
public function __construct($alias, $company_id, $locale = null)
|
2020-12-24 02:16:00 +03:00
|
|
|
{
|
|
|
|
$this->alias = $alias;
|
2020-12-25 12:08:15 +03:00
|
|
|
$this->company_id = $company_id;
|
2021-06-15 14:46:18 +03:00
|
|
|
$this->locale = $locale ?: company($company_id)->locale;
|
2020-12-24 02:16:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2022-02-14 18:00:44 +03:00
|
|
|
$this->authorize();
|
|
|
|
|
2020-12-24 02:16:00 +03:00
|
|
|
$command = "module:enable {$this->alias} {$this->company_id} {$this->locale}";
|
|
|
|
|
|
|
|
$result = Console::run($command);
|
|
|
|
|
|
|
|
if ($result !== true) {
|
|
|
|
throw new \Exception($result);
|
|
|
|
}
|
|
|
|
}
|
2022-02-14 18:00:44 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if this action is applicable.
|
|
|
|
*/
|
|
|
|
public function authorize(): void
|
|
|
|
{
|
|
|
|
if (! $this->moduleExists($this->alias)) {
|
|
|
|
throw new \Exception("Module [{$this->alias}] not found.");
|
|
|
|
}
|
|
|
|
}
|
2020-12-24 02:16:00 +03:00
|
|
|
}
|