added listener to install extra modules
This commit is contained in:
parent
a1f0f624ee
commit
5fa882b4e3
@ -12,5 +12,6 @@
|
||||
"requires": [],
|
||||
"reports": [],
|
||||
"widgets": [],
|
||||
"settings": []
|
||||
"settings": [],
|
||||
"extra-modules": {}
|
||||
}
|
||||
|
@ -10,15 +10,19 @@ class Installed extends Event
|
||||
|
||||
public $company_id;
|
||||
|
||||
public $locale;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $alias
|
||||
* @param $company_id
|
||||
* @param $locale
|
||||
*/
|
||||
public function __construct($alias, $company_id)
|
||||
public function __construct($alias, $company_id, $locale)
|
||||
{
|
||||
$this->alias = $alias;
|
||||
$this->company_id = $company_id;
|
||||
$this->locale = $locale;
|
||||
}
|
||||
}
|
||||
|
41
app/Jobs/Install/DownloadModule.php
Normal file
41
app/Jobs/Install/DownloadModule.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Install;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Utilities\Console;
|
||||
|
||||
class DownloadModule extends Job
|
||||
{
|
||||
protected $alias;
|
||||
|
||||
protected $company_id;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $alias
|
||||
* @param $company_id
|
||||
*/
|
||||
public function __construct($alias, $company_id = null)
|
||||
{
|
||||
$this->alias = $alias;
|
||||
$this->company_id = $company_id ?: session('company_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$command = "module:download {$this->alias} {$this->company_id}";
|
||||
|
||||
$result = Console::run($command);
|
||||
|
||||
if ($result !== true) {
|
||||
throw new \Exception($result);
|
||||
}
|
||||
}
|
||||
}
|
48
app/Listeners/Module/InstallExtraModules.php
Normal file
48
app/Listeners/Module/InstallExtraModules.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Module;
|
||||
|
||||
use App\Events\Module\Installed as Event;
|
||||
use App\Jobs\Install\DownloadModule;
|
||||
use App\Jobs\Install\InstallModule;
|
||||
use App\Traits\Jobs;
|
||||
|
||||
class InstallExtraModules
|
||||
{
|
||||
use Jobs;
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
$module = module($event->alias);
|
||||
|
||||
$extra_modules = $module->get('extra-modules');
|
||||
|
||||
if (empty($extra_modules)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($extra_modules as $alias => $level) {
|
||||
// Don't install if the module is "suggested"
|
||||
if ($level != 'required') {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$this->dispatch(new DownloadModule($alias, $event->company_id));
|
||||
|
||||
$this->dispatch(new InstallModule($alias, $event->company_id, $event->locale));
|
||||
} catch (\Exception $e) {
|
||||
logger($e->getMessage());
|
||||
|
||||
// Stop the propagation of event if the required module failed to install
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -69,6 +69,7 @@ class Event extends Provider
|
||||
'App\Listeners\Menu\AddPortalItems',
|
||||
],
|
||||
'App\Events\Module\Installed' => [
|
||||
'App\Listeners\Module\InstallExtraModules',
|
||||
'App\Listeners\Module\FinishInstallation',
|
||||
],
|
||||
];
|
||||
|
@ -11,5 +11,6 @@
|
||||
"requires": [],
|
||||
"reports": [],
|
||||
"widgets": [],
|
||||
"settings": []
|
||||
"settings": [],
|
||||
"extra-modules": {}
|
||||
}
|
||||
|
@ -12,5 +12,6 @@
|
||||
"requires": [],
|
||||
"reports": [],
|
||||
"widgets": [],
|
||||
"settings": []
|
||||
"settings": [],
|
||||
"extra-modules": {}
|
||||
}
|
||||
|
@ -97,5 +97,6 @@
|
||||
"attributes": {},
|
||||
"rules": "required|integer"
|
||||
}
|
||||
]
|
||||
],
|
||||
"extra-modules": {}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ class InstallCommand extends Command
|
||||
|
||||
$this->createHistory('installed');
|
||||
|
||||
event(new Installed($this->alias, $this->company_id));
|
||||
event(new Installed($this->alias, $this->company_id, $this->locale));
|
||||
|
||||
$this->revertRuntime();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user