refactored module commands
This commit is contained in:
parent
72cfdf14b2
commit
b54c9b1ecc
77
app/Abstracts/Commands/Module.php
Normal file
77
app/Abstracts/Commands/Module.php
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Abstracts\Commands;
|
||||||
|
|
||||||
|
use App\Models\Module\Module as Model;
|
||||||
|
use App\Models\Module\ModuleHistory;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
|
||||||
|
abstract class Module extends Command
|
||||||
|
{
|
||||||
|
protected function prepare()
|
||||||
|
{
|
||||||
|
$this->alias = Str::kebab($this->argument('alias'));
|
||||||
|
$this->company_id = $this->argument('company');
|
||||||
|
$this->locale = $this->argument('locale');
|
||||||
|
|
||||||
|
$this->module = module($this->alias);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function changeRuntime()
|
||||||
|
{
|
||||||
|
$this->old_company_id = session('company_id');
|
||||||
|
|
||||||
|
session(['company_id' => $this->company_id]);
|
||||||
|
|
||||||
|
app()->setLocale($this->locale);
|
||||||
|
|
||||||
|
// Disable model cache
|
||||||
|
config(['laravel-model-caching.enabled' => false]);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function revertRuntime()
|
||||||
|
{
|
||||||
|
session()->forget('company_id');
|
||||||
|
|
||||||
|
if (!empty($this->old_company_id)) {
|
||||||
|
session(['company_id' => $this->old_company_id]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getModel()
|
||||||
|
{
|
||||||
|
$this->model = Model::companyId($this->company_id)->alias($this->alias)->first();
|
||||||
|
|
||||||
|
return $this->model;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createHistory($action)
|
||||||
|
{
|
||||||
|
if (empty($this->model)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ModuleHistory::create([
|
||||||
|
'company_id' => $this->company_id,
|
||||||
|
'module_id' => $this->model->id,
|
||||||
|
'category' => $this->module->get('category'),
|
||||||
|
'version' => $this->module->get('version'),
|
||||||
|
'description' => trans('modules.' . $action, ['module' => $this->alias]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the console command arguments.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function getArguments()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['alias', InputArgument::REQUIRED, 'Module alias.'],
|
||||||
|
['company', InputArgument::REQUIRED, 'Company ID.'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
53
app/Console/Commands/UninstallModule.php
Normal file
53
app/Console/Commands/UninstallModule.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Abstracts\Commands\Module;
|
||||||
|
|
||||||
|
class UninstallModule extends Module
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'module:uninstall {alias} {company} {locale=en-GB}';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Uninstall the specified module.';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$this->prepare();
|
||||||
|
|
||||||
|
if (!$this->getModel()) {
|
||||||
|
$this->info("Module [{$this->alias}] not found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->changeRuntime();
|
||||||
|
|
||||||
|
// Delete db
|
||||||
|
$this->model->delete();
|
||||||
|
|
||||||
|
$this->createHistory('uninstalled');
|
||||||
|
|
||||||
|
event(new \App\Events\Module\Uninstalled($this->alias, $this->company_id));
|
||||||
|
|
||||||
|
// Delete files
|
||||||
|
$this->module->delete();
|
||||||
|
|
||||||
|
$this->revertRuntime();
|
||||||
|
|
||||||
|
$this->info("Module [{$this->alias}] uninstalled.");
|
||||||
|
}
|
||||||
|
}
|
22
app/Events/Install/UpdateCacheCleared.php
Normal file
22
app/Events/Install/UpdateCacheCleared.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events\Install;
|
||||||
|
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class UpdateCacheCleared
|
||||||
|
{
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
|
public $company_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @param $company_id
|
||||||
|
*/
|
||||||
|
public function __construct($company_id)
|
||||||
|
{
|
||||||
|
$this->company_id = $company_id;
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,7 @@ namespace App\Events\Module;
|
|||||||
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
class Deleted
|
class Copied
|
||||||
{
|
{
|
||||||
use SerializesModels;
|
use SerializesModels;
|
||||||
|
|
26
app/Events/Module/Uninstalled.php
Normal file
26
app/Events/Module/Uninstalled.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events\Module;
|
||||||
|
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class Uninstalled
|
||||||
|
{
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
|
public $alias;
|
||||||
|
|
||||||
|
public $company_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @param $alias
|
||||||
|
* @param $company_id
|
||||||
|
*/
|
||||||
|
public function __construct($alias, $company_id)
|
||||||
|
{
|
||||||
|
$this->alias = $alias;
|
||||||
|
$this->company_id = $company_id;
|
||||||
|
}
|
||||||
|
}
|
@ -38,7 +38,7 @@ class Item extends Controller
|
|||||||
$module = $this->getModule($alias);
|
$module = $this->getModule($alias);
|
||||||
|
|
||||||
if (empty($module)) {
|
if (empty($module)) {
|
||||||
return redirect('apps/home')->send();
|
return redirect()->route('apps.home.index')->send();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->moduleExists($alias) && ($model = Module::alias($alias)->first())) {
|
if ($this->moduleExists($alias) && ($model = Module::alias($alias)->first())) {
|
||||||
@ -169,102 +169,39 @@ class Item extends Controller
|
|||||||
{
|
{
|
||||||
$json = $this->uninstallModule($alias);
|
$json = $this->uninstallModule($alias);
|
||||||
|
|
||||||
$module = Module::alias($alias)->first();
|
if ($json['success']) {
|
||||||
|
$message = trans('modules.uninstalled', ['module' => $json['data']['name']]);
|
||||||
|
|
||||||
$data = [
|
flash($message)->success();
|
||||||
'company_id' => session('company_id'),
|
}
|
||||||
'module_id' => $module->id,
|
|
||||||
'category' => $json['data']['category'],
|
|
||||||
'version' => $json['data']['version'],
|
|
||||||
'description' => trans('modules.uninstalled', ['module' => $json['data']['name']]),
|
|
||||||
];
|
|
||||||
|
|
||||||
ModuleHistory::create($data);
|
return redirect()->route('apps.app.show', $alias)->send();
|
||||||
|
|
||||||
$module->delete();
|
|
||||||
|
|
||||||
$message = trans('modules.uninstalled', ['module' => $json['data']['name']]);
|
|
||||||
|
|
||||||
flash($message)->success();
|
|
||||||
|
|
||||||
return redirect('apps/' . $alias)->send();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update($alias)
|
|
||||||
{
|
|
||||||
$json = $this->updateModule($alias);
|
|
||||||
|
|
||||||
$module = Module::alias($alias)->first();
|
|
||||||
|
|
||||||
$data = [
|
|
||||||
'company_id' => session('company_id'),
|
|
||||||
'module_id' => $module->id,
|
|
||||||
'category' => $json['data']['category'],
|
|
||||||
'version' => $json['data']['version'],
|
|
||||||
'description' => trans_choice('modules.updated', $json['data']['name']),
|
|
||||||
];
|
|
||||||
|
|
||||||
ModuleHistory::create($data);
|
|
||||||
|
|
||||||
$message = trans('modules.updated', ['module' => $json['data']['name']]);
|
|
||||||
|
|
||||||
flash($message)->success();
|
|
||||||
|
|
||||||
return redirect('apps/' . $alias)->send();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function enable($alias)
|
public function enable($alias)
|
||||||
{
|
{
|
||||||
$json = $this->enableModule($alias);
|
$json = $this->enableModule($alias);
|
||||||
|
|
||||||
$module = Module::alias($alias)->first();
|
if ($json['success']) {
|
||||||
|
$message = trans('modules.enabled', ['module' => $json['data']['name']]);
|
||||||
|
|
||||||
$data = [
|
flash($message)->success();
|
||||||
'company_id' => session('company_id'),
|
}
|
||||||
'module_id' => $module->id,
|
|
||||||
'category' => $json['data']['category'],
|
|
||||||
'version' => $json['data']['version'],
|
|
||||||
'description' => trans('modules.enabled', ['module' => $json['data']['name']]),
|
|
||||||
];
|
|
||||||
|
|
||||||
$module->enabled = 1;
|
return redirect()->route('apps.app.show', $alias)->send();
|
||||||
|
|
||||||
$module->save();
|
|
||||||
|
|
||||||
ModuleHistory::create($data);
|
|
||||||
|
|
||||||
$message = trans('modules.enabled', ['module' => $json['data']['name']]);
|
|
||||||
|
|
||||||
flash($message)->success();
|
|
||||||
|
|
||||||
return redirect('apps/' . $alias)->send();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function disable($alias)
|
public function disable($alias)
|
||||||
{
|
{
|
||||||
$json = $this->disableModule($alias);
|
$json = $this->disableModule($alias);
|
||||||
|
|
||||||
$module = Module::alias($alias)->first();
|
if ($json['success']) {
|
||||||
|
$message = trans('modules.disabled', ['module' => $json['data']['name']]);
|
||||||
|
|
||||||
$data = [
|
flash($message)->success();
|
||||||
'company_id' => session('company_id'),
|
}
|
||||||
'module_id' => $module->id,
|
|
||||||
'category' => $json['data']['category'],
|
|
||||||
'version' => $json['data']['version'],
|
|
||||||
'description' => trans('modules.disabled', ['module' => $json['data']['name']]),
|
|
||||||
];
|
|
||||||
|
|
||||||
$module->enabled = 0;
|
return redirect()->route('apps.app.show', $alias)->send();
|
||||||
|
|
||||||
$module->save();
|
|
||||||
|
|
||||||
ModuleHistory::create($data);
|
|
||||||
|
|
||||||
$message = trans('modules.disabled', ['module' => $json['data']['name']]);
|
|
||||||
|
|
||||||
flash($message)->success();
|
|
||||||
|
|
||||||
return redirect('apps/' . $alias)->send();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reviews($alias, Request $request)
|
public function reviews($alias, Request $request)
|
||||||
@ -292,11 +229,11 @@ class Item extends Controller
|
|||||||
{
|
{
|
||||||
$documentation = $this->getDocumentation($alias);
|
$documentation = $this->getDocumentation($alias);
|
||||||
|
|
||||||
if (empty($documentation)) {
|
$back = route('apps.app.show', $alias);
|
||||||
return redirect('apps/' . $alias)->send();
|
|
||||||
}
|
|
||||||
|
|
||||||
$back = 'apps/' . $alias;
|
if (empty($documentation)) {
|
||||||
|
return redirect()->route($back)->send();
|
||||||
|
}
|
||||||
|
|
||||||
return view('modules.item.documentation', compact('documentation', 'back'));
|
return view('modules.item.documentation', compact('documentation', 'back'));
|
||||||
}
|
}
|
||||||
|
45
app/Listeners/Module/ClearCache.php
Normal file
45
app/Listeners/Module/ClearCache.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners\Module;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
|
class ClearCache
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param $event
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle($event)
|
||||||
|
{
|
||||||
|
if (config('module.cache.enabled')) {
|
||||||
|
Cache::forget(config('module.cache.key'));
|
||||||
|
}
|
||||||
|
|
||||||
|
Cache::forget('apps.notifications');
|
||||||
|
Cache::forget('apps.suggestions');
|
||||||
|
Cache::forget('apps.installed.' . $event->company_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register the listeners for the subscriber.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Events\Dispatcher $dispatcher
|
||||||
|
*/
|
||||||
|
public function subscribe($dispatcher)
|
||||||
|
{
|
||||||
|
$events = [
|
||||||
|
'App\Events\Install\UpdateCacheCleared',
|
||||||
|
'App\Events\Module\Copied',
|
||||||
|
'App\Events\Module\Enabled',
|
||||||
|
'App\Events\Module\Disabled',
|
||||||
|
'App\Events\Module\Uninstalled',
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($events as $event) {
|
||||||
|
$dispatcher->listen($event, 'App\Listeners\Module\ClearCache@handle');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
app/Listeners/Module/FinishInstallation.php
Normal file
27
app/Listeners/Module/FinishInstallation.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Listeners\Module;
|
||||||
|
|
||||||
|
use App\Events\Module\Installed as Event;
|
||||||
|
use App\Traits\Permissions;
|
||||||
|
use Artisan;
|
||||||
|
|
||||||
|
class FinishInstallation
|
||||||
|
{
|
||||||
|
use Permissions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the event.
|
||||||
|
*
|
||||||
|
* @param $event
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handle(Event $event)
|
||||||
|
{
|
||||||
|
$module = module($event->alias);
|
||||||
|
|
||||||
|
Artisan::call('migrate', ['--force' => true]);
|
||||||
|
|
||||||
|
$this->attachDefaultModulePermissions($module);
|
||||||
|
}
|
||||||
|
}
|
@ -73,6 +73,9 @@ class Event extends Provider
|
|||||||
'App\Events\Menu\PortalCreated' => [
|
'App\Events\Menu\PortalCreated' => [
|
||||||
'App\Listeners\Menu\AddPortalItems',
|
'App\Listeners\Menu\AddPortalItems',
|
||||||
],
|
],
|
||||||
|
'App\Events\Module\Installed' => [
|
||||||
|
'App\Listeners\Module\FinishInstallation',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -81,6 +84,7 @@ class Event extends Provider
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $subscribe = [
|
protected $subscribe = [
|
||||||
|
'App\Listeners\Module\ClearCache',
|
||||||
'App\Listeners\Report\AddDate',
|
'App\Listeners\Report\AddDate',
|
||||||
'App\Listeners\Report\AddAccounts',
|
'App\Listeners\Report\AddAccounts',
|
||||||
'App\Listeners\Report\AddCustomers',
|
'App\Listeners\Report\AddCustomers',
|
||||||
|
@ -425,17 +425,11 @@ trait Modules
|
|||||||
File::copyDirectory($temp_path, $module_path);
|
File::copyDirectory($temp_path, $module_path);
|
||||||
File::deleteDirectory($temp_path);
|
File::deleteDirectory($temp_path);
|
||||||
|
|
||||||
$data = [
|
event(new \App\Events\Module\Copied($module->alias, session('company_id')));
|
||||||
'path' => $path,
|
|
||||||
'name' => Str::studly($module->alias),
|
|
||||||
'alias' => $module->alias,
|
|
||||||
];
|
|
||||||
|
|
||||||
$company_id = session('company_id');
|
$company_id = session('company_id');
|
||||||
$locale = app()->getLocale();
|
$locale = app()->getLocale();
|
||||||
|
|
||||||
$this->clearModulesCache();
|
|
||||||
|
|
||||||
$command = "module:install {$module->alias} {$company_id} {$locale}";
|
$command = "module:install {$module->alias} {$company_id} {$locale}";
|
||||||
|
|
||||||
if (true !== $result = Console::run($command)) {
|
if (true !== $result = Console::run($command)) {
|
||||||
@ -454,29 +448,44 @@ trait Modules
|
|||||||
'redirect' => route('apps.app.show', $module->alias),
|
'redirect' => route('apps.app.show', $module->alias),
|
||||||
'error' => false,
|
'error' => false,
|
||||||
'message' => null,
|
'message' => null,
|
||||||
'data' => $data,
|
'data' => [
|
||||||
|
'path' => $path,
|
||||||
|
'name' => module($module->alias)->getName(),
|
||||||
|
'alias' => $module->alias,
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function uninstallModule($alias)
|
public function uninstallModule($alias)
|
||||||
{
|
{
|
||||||
$module = module($alias);
|
$module = module($alias);
|
||||||
|
$name = $module->getName();
|
||||||
|
$category = $module->get('category');
|
||||||
|
$version = $module->get('version');
|
||||||
|
|
||||||
$data = [
|
$company_id = session('company_id');
|
||||||
'name' => $module->getName(),
|
$locale = app()->getLocale();
|
||||||
'category' => $module->get('category'),
|
|
||||||
'version' => $module->get('version'),
|
|
||||||
];
|
|
||||||
|
|
||||||
$module->delete();
|
$command = "module:uninstall {$alias} {$company_id} {$locale}";
|
||||||
|
|
||||||
$this->clearModulesCache();
|
if (true !== $result = Console::run($command)) {
|
||||||
|
return [
|
||||||
|
'success' => false,
|
||||||
|
'error' => true,
|
||||||
|
'message' => $result,
|
||||||
|
'data' => null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'error' => false,
|
'error' => false,
|
||||||
'message' => null,
|
'message' => null,
|
||||||
'data' => $data,
|
'data' => [
|
||||||
|
'name' => $name,
|
||||||
|
'category' => $category,
|
||||||
|
'version' => $version,
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -484,21 +493,29 @@ trait Modules
|
|||||||
{
|
{
|
||||||
$module = module($alias);
|
$module = module($alias);
|
||||||
|
|
||||||
$data = [
|
$company_id = session('company_id');
|
||||||
'name' => $module->getName(),
|
$locale = app()->getLocale();
|
||||||
'category' => $module->get('category'),
|
|
||||||
'version' => $module->get('version'),
|
|
||||||
];
|
|
||||||
|
|
||||||
$module->enable();
|
$command = "module:enable {$alias} {$company_id} {$locale}";
|
||||||
|
|
||||||
$this->clearModulesCache();
|
if (true !== $result = Console::run($command)) {
|
||||||
|
return [
|
||||||
|
'success' => false,
|
||||||
|
'error' => true,
|
||||||
|
'message' => $result,
|
||||||
|
'data' => null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'error' => false,
|
'error' => false,
|
||||||
'message' => null,
|
'message' => null,
|
||||||
'data' => $data,
|
'data' => [
|
||||||
|
'name' => $module->getName(),
|
||||||
|
'category' => $module->get('category'),
|
||||||
|
'version' => $module->get('version'),
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -506,21 +523,29 @@ trait Modules
|
|||||||
{
|
{
|
||||||
$module = module($alias);
|
$module = module($alias);
|
||||||
|
|
||||||
$data = [
|
$company_id = session('company_id');
|
||||||
'name' => $module->getName(),
|
$locale = app()->getLocale();
|
||||||
'category' => $module->get('category'),
|
|
||||||
'version' => $module->get('version'),
|
|
||||||
];
|
|
||||||
|
|
||||||
$module->disable();
|
$command = "module:disable {$alias} {$company_id} {$locale}";
|
||||||
|
|
||||||
$this->clearModulesCache($alias);
|
if (true !== $result = Console::run($command)) {
|
||||||
|
return [
|
||||||
|
'success' => false,
|
||||||
|
'error' => true,
|
||||||
|
'message' => $result,
|
||||||
|
'data' => null,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'error' => false,
|
'error' => false,
|
||||||
'message' => null,
|
'message' => null,
|
||||||
'data' => $data,
|
'data' => [
|
||||||
|
'name' => $module->getName(),
|
||||||
|
'category' => $module->get('category'),
|
||||||
|
'version' => $module->get('version'),
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -638,15 +663,4 @@ trait Modules
|
|||||||
|
|
||||||
return $data['query']['page'];
|
return $data['query']['page'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function clearModulesCache()
|
|
||||||
{
|
|
||||||
if (config('module.cache.enabled')) {
|
|
||||||
Cache::forget(config('module.cache.key'));
|
|
||||||
}
|
|
||||||
|
|
||||||
Cache::forget('apps.notifications');
|
|
||||||
Cache::forget('apps.suggestions');
|
|
||||||
Cache::forget('apps.installed.' . session('company_id'));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Utilities;
|
namespace App\Utilities;
|
||||||
|
|
||||||
|
use App\Events\Install\UpdateCacheCleared;
|
||||||
use App\Events\Install\UpdateCopied;
|
use App\Events\Install\UpdateCopied;
|
||||||
use App\Events\Install\UpdateDownloaded;
|
use App\Events\Install\UpdateDownloaded;
|
||||||
use App\Events\Install\UpdateUnzipped;
|
use App\Events\Install\UpdateUnzipped;
|
||||||
@ -22,9 +23,8 @@ class Updater
|
|||||||
{
|
{
|
||||||
Cache::forget('updates');
|
Cache::forget('updates');
|
||||||
Cache::forget('versions');
|
Cache::forget('versions');
|
||||||
Cache::forget('apps.notifications');
|
|
||||||
Cache::forget('apps.suggestions');
|
event(new UpdateCacheCleared(session('company_id')));
|
||||||
Cache::forget('apps.installed.' . session('company_id'));
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -2,21 +2,16 @@
|
|||||||
|
|
||||||
namespace Akaunting\Module\Commands;
|
namespace Akaunting\Module\Commands;
|
||||||
|
|
||||||
use App\Models\Module\Module;
|
use App\Console\Commands\UninstallModule;
|
||||||
use App\Models\Module\ModuleHistory;
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Illuminate\Support\Facades\Cache;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
|
||||||
|
|
||||||
class DeleteCommand extends Command
|
class DeleteCommand extends UninstallModule
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The name and signature of the console command.
|
* The name and signature of the console command.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'module:delete {alias} {company_id}';
|
protected $signature = 'module:delete {alias} {company} {locale=en-GB}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
@ -24,61 +19,4 @@ class DeleteCommand extends Command
|
|||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $description = 'Delete the specified module.';
|
protected $description = 'Delete the specified module.';
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the console command.
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$alias = Str::kebab($this->argument('alias'));
|
|
||||||
$company_id = $this->argument('company_id');
|
|
||||||
|
|
||||||
$model = Module::alias($alias)->companyId($company_id)->first();
|
|
||||||
|
|
||||||
if (!$model) {
|
|
||||||
$this->info("Module [{$alias}] not found.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$module = module($alias);
|
|
||||||
$module->delete();
|
|
||||||
|
|
||||||
$model->enabled = 0;
|
|
||||||
$model->save();
|
|
||||||
|
|
||||||
// Add history
|
|
||||||
$data = [
|
|
||||||
'company_id' => $company_id,
|
|
||||||
'module_id' => $model->id,
|
|
||||||
'category' => $module->get('category', 'payment-method'),
|
|
||||||
'version' => $module->get('version'),
|
|
||||||
'description' => trans('modules.deleted', ['module' => $module->get('alias')]),
|
|
||||||
];
|
|
||||||
|
|
||||||
ModuleHistory::create($data);
|
|
||||||
|
|
||||||
// Trigger event
|
|
||||||
event(new \App\Events\Module\Deleted($alias, $company_id));
|
|
||||||
|
|
||||||
if (config('module.cache.enabled')) {
|
|
||||||
Cache::forget(config('module.cache.key'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->info("Module [{$alias}] deleted.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the console command arguments.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function getArguments()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
array('alias', InputArgument::REQUIRED, 'Module alias.'),
|
|
||||||
array('company_id', InputArgument::REQUIRED, 'Company ID.'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,20 +2,16 @@
|
|||||||
|
|
||||||
namespace Akaunting\Module\Commands;
|
namespace Akaunting\Module\Commands;
|
||||||
|
|
||||||
use App\Models\Module\Module;
|
use App\Abstracts\Commands\Module;
|
||||||
use App\Models\Module\ModuleHistory;
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
|
||||||
|
|
||||||
class DisableCommand extends Command
|
class DisableCommand extends Module
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The name and signature of the console command.
|
* The name and signature of the console command.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'module:disable {alias} {company_id}';
|
protected $signature = 'module:disable {alias} {company} {locale=en-GB}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
@ -31,52 +27,30 @@ class DisableCommand extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$alias = Str::kebab($this->argument('alias'));
|
$this->prepare();
|
||||||
$company_id = $this->argument('company_id');
|
|
||||||
|
|
||||||
$model = Module::alias($alias)->companyId($company_id)->first();
|
if (!$this->getModel()) {
|
||||||
|
$this->info("Module [{$this->alias}] not found.");
|
||||||
if (!$model) {
|
|
||||||
$this->info("Module [{$alias}] not found.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($model->enabled == 1) {
|
if ($this->model->enabled == 0) {
|
||||||
$model->enabled = 0;
|
$this->comment("Module [{$this->alias}] is already disabled.");
|
||||||
$model->save();
|
return;
|
||||||
|
|
||||||
$module = module($alias);
|
|
||||||
|
|
||||||
// Add history
|
|
||||||
$data = [
|
|
||||||
'company_id' => $company_id,
|
|
||||||
'module_id' => $model->id,
|
|
||||||
'category' => $module->get('category', 'payment-method'),
|
|
||||||
'version' => $module->get('version'),
|
|
||||||
'description' => trans('modules.disabled', ['module' => $module->get('alias')]),
|
|
||||||
];
|
|
||||||
|
|
||||||
ModuleHistory::create($data);
|
|
||||||
|
|
||||||
// Trigger event
|
|
||||||
event(new \App\Events\Module\Disabled($alias, $company_id));
|
|
||||||
|
|
||||||
$this->info("Module [{$alias}] disabled.");
|
|
||||||
} else {
|
|
||||||
$this->comment("Module [{$alias}] is already disabled.");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$this->changeRuntime();
|
||||||
* Get the console command arguments.
|
|
||||||
*
|
// Update db
|
||||||
* @return array
|
$this->model->enabled = 0;
|
||||||
*/
|
$this->model->save();
|
||||||
protected function getArguments()
|
|
||||||
{
|
$this->createHistory('disabled');
|
||||||
return array(
|
|
||||||
array('alias', InputArgument::REQUIRED, 'Module alias.'),
|
event(new \App\Events\Module\Disabled($this->alias, $this->company_id));
|
||||||
array('company_id', InputArgument::REQUIRED, 'Company ID.'),
|
|
||||||
);
|
$this->revertRuntime();
|
||||||
|
|
||||||
|
$this->info("Module [{$this->alias}] disabled.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,20 +2,16 @@
|
|||||||
|
|
||||||
namespace Akaunting\Module\Commands;
|
namespace Akaunting\Module\Commands;
|
||||||
|
|
||||||
use App\Models\Module\Module;
|
use App\Abstracts\Commands\Module;
|
||||||
use App\Models\Module\ModuleHistory;
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
|
||||||
|
|
||||||
class EnableCommand extends Command
|
class EnableCommand extends Module
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The name and signature of the console command.
|
* The name and signature of the console command.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'module:enable {alias} {company_id}';
|
protected $signature = 'module:enable {alias} {company} {locale=en-GB}';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
@ -31,52 +27,30 @@ class EnableCommand extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$alias = Str::kebab($this->argument('alias'));
|
$this->prepare();
|
||||||
$company_id = $this->argument('company_id');
|
|
||||||
|
|
||||||
$model = Module::alias($alias)->companyId($company_id)->first();
|
if (!$this->getModel()) {
|
||||||
|
$this->info("Module [{$this->alias}] not found.");
|
||||||
if (!$model) {
|
|
||||||
$this->info("Module [{$alias}] not found.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($model->enabled == 0) {
|
if ($this->model->enabled == 1) {
|
||||||
$model->enabled = 1;
|
$this->comment("Module [{$this->alias}] is already enabled.");
|
||||||
$model->save();
|
return;
|
||||||
|
|
||||||
$module = module($alias);
|
|
||||||
|
|
||||||
// Add history
|
|
||||||
$data = [
|
|
||||||
'company_id' => $company_id,
|
|
||||||
'module_id' => $model->id,
|
|
||||||
'category' => $module->get('category', 'payment-method'),
|
|
||||||
'version' => $module->get('version'),
|
|
||||||
'description' => trans('modules.enabled', ['module' => $module->get('alias')]),
|
|
||||||
];
|
|
||||||
|
|
||||||
ModuleHistory::create($data);
|
|
||||||
|
|
||||||
// Trigger event
|
|
||||||
event(new \App\Events\Module\Enabled($alias, $company_id));
|
|
||||||
|
|
||||||
$this->info("Module [{$alias}] enabled.");
|
|
||||||
} else {
|
|
||||||
$this->comment("Module [{$alias}] is already enabled.");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$this->changeRuntime();
|
||||||
* Get the console command arguments.
|
|
||||||
*
|
// Update db
|
||||||
* @return array
|
$this->model->enabled = 1;
|
||||||
*/
|
$this->model->save();
|
||||||
protected function getArguments()
|
|
||||||
{
|
$this->createHistory('enabled');
|
||||||
return array(
|
|
||||||
array('alias', InputArgument::REQUIRED, 'Module alias.'),
|
event(new \App\Events\Module\Enabled($this->alias, $this->company_id));
|
||||||
array('company_id', InputArgument::REQUIRED, 'Company ID.'),
|
|
||||||
);
|
$this->revertRuntime();
|
||||||
|
|
||||||
|
$this->info("Module [{$this->alias}] enabled.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,18 +2,11 @@
|
|||||||
|
|
||||||
namespace Akaunting\Module\Commands;
|
namespace Akaunting\Module\Commands;
|
||||||
|
|
||||||
use App\Models\Module\Module;
|
use App\Abstracts\Commands\Module;
|
||||||
use App\Models\Module\ModuleHistory;
|
use App\Models\Module\Module as Model;
|
||||||
use App\Traits\Permissions;
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Illuminate\Support\Facades\Cache;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
|
||||||
|
|
||||||
class InstallCommand extends Command
|
class InstallCommand extends Module
|
||||||
{
|
{
|
||||||
use Permissions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name and signature of the console command.
|
* The name and signature of the console command.
|
||||||
*
|
*
|
||||||
@ -35,65 +28,23 @@ class InstallCommand extends Command
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$alias = Str::kebab($this->argument('alias'));
|
$this->prepare();
|
||||||
$company_id = $this->argument('company');
|
|
||||||
$locale = $this->argument('locale');
|
|
||||||
|
|
||||||
$old_company_id = session('company_id');
|
$this->changeRuntime();
|
||||||
|
|
||||||
session(['company_id' => $company_id]);
|
// Create db
|
||||||
|
$this->model = Model::create([
|
||||||
app()->setLocale($locale);
|
'company_id' => $this->company_id,
|
||||||
|
'alias' => $this->alias,
|
||||||
$module = module($alias);
|
|
||||||
|
|
||||||
$model = Module::create([
|
|
||||||
'company_id' => $company_id,
|
|
||||||
'alias' => $alias,
|
|
||||||
'enabled' => '1',
|
'enabled' => '1',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
ModuleHistory::create([
|
$this->createHistory('installed');
|
||||||
'company_id' => $company_id,
|
|
||||||
'module_id' => $model->id,
|
|
||||||
'category' => $module->get('category', 'payment-method'),
|
|
||||||
'version' => $module->get('version'),
|
|
||||||
'description' => trans('modules.installed', ['module' => $alias]),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (config('module.cache.enabled')) {
|
event(new \App\Events\Module\Installed($this->alias, $this->company_id));
|
||||||
Cache::forget(config('module.cache.key'));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disable model cache during installation
|
$this->revertRuntime();
|
||||||
config(['laravel-model-caching.enabled' => false]);
|
|
||||||
|
|
||||||
// Update database
|
|
||||||
$this->call('migrate', ['--force' => true]);
|
|
||||||
|
|
||||||
event(new \App\Events\Module\Installed($alias, $company_id));
|
|
||||||
|
|
||||||
$this->attachDefaultModulePermissions($module);
|
|
||||||
|
|
||||||
session()->forget('company_id');
|
|
||||||
|
|
||||||
if (!empty($old_company_id)) {
|
|
||||||
session(['company_id' => $old_company_id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->info('Module installed!');
|
$this->info('Module installed!');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the console command arguments.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function getArguments()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
array('alias', InputArgument::REQUIRED, 'Module alias.'),
|
|
||||||
array('company_id', InputArgument::REQUIRED, 'Company ID.'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
<div class="card-footer">
|
<div class="card-footer">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<a href="{{ url($back) }}" class="btn btn-white header-button-top"><span class="fas fa-arrow-left"></span> {{ trans('modules.back') }}</a>
|
<a href="{{ url($back) }}" class="btn btn-white header-button-top"><span class="fas fa-arrow-left"></span> {{ trans('modules.back') }}</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user