v2 first commit
This commit is contained in:
412
overrides/Illuminate/Translation/MessageSelector.php
Normal file
412
overrides/Illuminate/Translation/MessageSelector.php
Normal file
@ -0,0 +1,412 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Translation;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class MessageSelector
|
||||
{
|
||||
/**
|
||||
* Select a proper translation string based on the given number.
|
||||
*
|
||||
* @param string $line
|
||||
* @param int $number
|
||||
* @param string $locale
|
||||
* @return mixed
|
||||
*/
|
||||
public function choose($line, $number, $locale)
|
||||
{
|
||||
$segments = explode('|', $line);
|
||||
|
||||
if (($value = $this->extract($segments, $number)) !== null) {
|
||||
return trim($value);
|
||||
}
|
||||
|
||||
$segments = $this->stripConditions($segments);
|
||||
|
||||
$pluralIndex = $this->getPluralIndex($locale, $number);
|
||||
|
||||
if (count($segments) === 1 || ! isset($segments[$pluralIndex])) {
|
||||
return $segments[0];
|
||||
}
|
||||
|
||||
return $segments[$pluralIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract a translation string using inline conditions.
|
||||
*
|
||||
* @param array $segments
|
||||
* @param int $number
|
||||
* @return mixed
|
||||
*/
|
||||
private function extract($segments, $number)
|
||||
{
|
||||
foreach ($segments as $part) {
|
||||
if (! is_null($line = $this->extractFromString($part, $number))) {
|
||||
return $line;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the translation string if the condition matches.
|
||||
*
|
||||
* @param string $part
|
||||
* @param int $number
|
||||
* @return mixed
|
||||
*/
|
||||
private function extractFromString($part, $number)
|
||||
{
|
||||
preg_match('/^[\{\[]([^\[\]\{\}]*)[\}\]](.*)/s', $part, $matches);
|
||||
|
||||
if (count($matches) !== 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
$condition = $matches[1];
|
||||
|
||||
$value = $matches[2];
|
||||
|
||||
if (Str::contains($condition, ',')) {
|
||||
[$from, $to] = explode(',', $condition, 2);
|
||||
|
||||
if ($to === '*' && $number >= $from) {
|
||||
return $value;
|
||||
} elseif ($from === '*' && $number <= $to) {
|
||||
return $value;
|
||||
} elseif ($number >= $from && $number <= $to) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $condition == $number ? $value : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip the inline conditions from each segment, just leaving the text.
|
||||
*
|
||||
* @param array $segments
|
||||
* @return array
|
||||
*/
|
||||
private function stripConditions($segments)
|
||||
{
|
||||
return collect($segments)->map(function ($part) {
|
||||
return preg_replace('/^[\{\[]([^\[\]\{\}]*)[\}\]]/', '', $part);
|
||||
})->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the index to use for pluralization.
|
||||
*
|
||||
* The plural rules are derived from code of the Zend Framework (2010-09-25), which
|
||||
* is subject to the new BSD license (http://framework.zend.com/license/new-bsd)
|
||||
* Copyright (c) 2005-2010 - Zend Technologies USA Inc. (http://www.zend.com)
|
||||
*
|
||||
* @param string $locale
|
||||
* @param int $number
|
||||
* @return int
|
||||
*/
|
||||
public function getPluralIndex($locale, $number)
|
||||
{
|
||||
switch ($locale) {
|
||||
case 'az':
|
||||
case 'az-AZ':
|
||||
case 'bo':
|
||||
case 'bo-CN':
|
||||
case 'bo-IN':
|
||||
case 'dz':
|
||||
case 'dz-BT':
|
||||
case 'id':
|
||||
case 'id-ID':
|
||||
case 'ja':
|
||||
case 'ja-JP':
|
||||
case 'jv':
|
||||
case 'ka':
|
||||
case 'ka-GE':
|
||||
case 'km':
|
||||
case 'km-KH':
|
||||
case 'kn':
|
||||
case 'kn-IN':
|
||||
case 'ko':
|
||||
case 'ko-KR':
|
||||
case 'ms':
|
||||
case 'ms-MY':
|
||||
case 'th':
|
||||
case 'th-TH':
|
||||
case 'vi':
|
||||
case 'vi-VN':
|
||||
case 'zh':
|
||||
case 'zh-CN':
|
||||
case 'zh-HK':
|
||||
case 'zh-SG':
|
||||
case 'zh-TW':
|
||||
return 0;
|
||||
case 'af':
|
||||
case 'af-ZA':
|
||||
case 'bn':
|
||||
case 'bn-BD':
|
||||
case 'bn-IN':
|
||||
case 'bg':
|
||||
case 'bg-BG':
|
||||
case 'ca':
|
||||
case 'ca-AD':
|
||||
case 'ca-ES':
|
||||
case 'ca-FR':
|
||||
case 'ca-IT':
|
||||
case 'da':
|
||||
case 'da-DK':
|
||||
case 'de':
|
||||
case 'de-AT':
|
||||
case 'de-BE':
|
||||
case 'de-CH':
|
||||
case 'de-DE':
|
||||
case 'de-LI':
|
||||
case 'de-LU':
|
||||
case 'el':
|
||||
case 'el-CY':
|
||||
case 'el-GR':
|
||||
case 'en':
|
||||
case 'en-AG':
|
||||
case 'en-AU':
|
||||
case 'en-BW':
|
||||
case 'en-CA':
|
||||
case 'en-DK':
|
||||
case 'en-GB':
|
||||
case 'en-HK':
|
||||
case 'en-IE':
|
||||
case 'en-IN':
|
||||
case 'en-NG':
|
||||
case 'en-NZ':
|
||||
case 'en-PH':
|
||||
case 'en-SG':
|
||||
case 'en-US':
|
||||
case 'en-ZA':
|
||||
case 'en-ZM':
|
||||
case 'en-ZW':
|
||||
case 'eo':
|
||||
case 'eo-US':
|
||||
case 'es':
|
||||
case 'es-AR':
|
||||
case 'es-BO':
|
||||
case 'es-CL':
|
||||
case 'es-CO':
|
||||
case 'es-CR':
|
||||
case 'es-CU':
|
||||
case 'es-DO':
|
||||
case 'es-EC':
|
||||
case 'es-ES':
|
||||
case 'es-GT':
|
||||
case 'es-HN':
|
||||
case 'es-MX':
|
||||
case 'es-NI':
|
||||
case 'es-PA':
|
||||
case 'es-PE':
|
||||
case 'es-PR':
|
||||
case 'es-PY':
|
||||
case 'es-SV':
|
||||
case 'es-US':
|
||||
case 'es-UY':
|
||||
case 'es-VE':
|
||||
case 'et':
|
||||
case 'et-EE':
|
||||
case 'eu':
|
||||
case 'eu-ES':
|
||||
case 'eu-FR':
|
||||
case 'fa':
|
||||
case 'fa-IR':
|
||||
case 'fi':
|
||||
case 'fi-FI':
|
||||
case 'fo':
|
||||
case 'fo-FO':
|
||||
case 'fur':
|
||||
case 'fur-IT':
|
||||
case 'fy':
|
||||
case 'fy-DE':
|
||||
case 'fy-NL':
|
||||
case 'gl':
|
||||
case 'gl-ES':
|
||||
case 'gu':
|
||||
case 'gu-IN':
|
||||
case 'ha':
|
||||
case 'ha-NG':
|
||||
case 'he':
|
||||
case 'he-IL':
|
||||
case 'hu':
|
||||
case 'hu-HU':
|
||||
case 'is':
|
||||
case 'is-IS':
|
||||
case 'it':
|
||||
case 'it-CH':
|
||||
case 'it-IT':
|
||||
case 'ku':
|
||||
case 'ku-TR':
|
||||
case 'lb':
|
||||
case 'lb-LU':
|
||||
case 'ml':
|
||||
case 'ml-IN':
|
||||
case 'mn':
|
||||
case 'mn-MN':
|
||||
case 'mr':
|
||||
case 'mr-IN':
|
||||
case 'nah':
|
||||
case 'nb':
|
||||
case 'nb-NO':
|
||||
case 'ne':
|
||||
case 'ne-NP':
|
||||
case 'nl':
|
||||
case 'nl-AW':
|
||||
case 'nl-BE':
|
||||
case 'nl-NL':
|
||||
case 'nn':
|
||||
case 'nn-NO':
|
||||
case 'no':
|
||||
case 'om':
|
||||
case 'om-ET':
|
||||
case 'om-KE':
|
||||
case 'or':
|
||||
case 'or-IN':
|
||||
case 'pa':
|
||||
case 'pa-IN':
|
||||
case 'pa-PK':
|
||||
case 'pap':
|
||||
case 'pap-AN':
|
||||
case 'pap-AW':
|
||||
case 'pap-CW':
|
||||
case 'ps':
|
||||
case 'ps-AF':
|
||||
case 'pt':
|
||||
case 'pt-PT':
|
||||
case 'so':
|
||||
case 'so-DJ':
|
||||
case 'so-ET':
|
||||
case 'so-KE':
|
||||
case 'so-SO':
|
||||
case 'sq':
|
||||
case 'sq-AL':
|
||||
case 'sq-MK':
|
||||
case 'sv':
|
||||
case 'sv-FI':
|
||||
case 'sv-SE':
|
||||
case 'sw':
|
||||
case 'sw-KE':
|
||||
case 'sw-TZ':
|
||||
case 'ta':
|
||||
case 'ta-IN':
|
||||
case 'ta-LK':
|
||||
case 'te':
|
||||
case 'te-IN':
|
||||
case 'tk':
|
||||
case 'tk-TM':
|
||||
case 'tr':
|
||||
case 'tr-CY':
|
||||
case 'tr-TR':
|
||||
case 'ur':
|
||||
case 'ur-IN':
|
||||
case 'ur-PK':
|
||||
case 'zu':
|
||||
case 'zu-ZA':
|
||||
return ($number == 1) ? 0 : 1;
|
||||
case 'am':
|
||||
case 'am-ET':
|
||||
case 'bh':
|
||||
case 'fil':
|
||||
case 'fil-PH':
|
||||
case 'fr':
|
||||
case 'fr-BE':
|
||||
case 'fr-CA':
|
||||
case 'fr-CH':
|
||||
case 'fr-FR':
|
||||
case 'fr-LU':
|
||||
case 'gun':
|
||||
case 'hi':
|
||||
case 'hi-IN':
|
||||
case 'hy':
|
||||
case 'hy-AM':
|
||||
case 'ln':
|
||||
case 'ln-CD':
|
||||
case 'mg':
|
||||
case 'mg-MG':
|
||||
case 'nso':
|
||||
case 'nso-ZA':
|
||||
case 'pt-BR':
|
||||
case 'ti':
|
||||
case 'ti-ER':
|
||||
case 'ti-ET':
|
||||
case 'wa':
|
||||
case 'wa-BE':
|
||||
case 'xbr':
|
||||
return (($number == 0) || ($number == 1)) ? 0 : 1;
|
||||
case 'be':
|
||||
case 'be-BY':
|
||||
case 'bs':
|
||||
case 'bs-BA':
|
||||
case 'hr':
|
||||
case 'hr-HR':
|
||||
case 'ru':
|
||||
case 'ru-RU':
|
||||
case 'ru-UA':
|
||||
case 'sr':
|
||||
case 'sr-ME':
|
||||
case 'sr-RS':
|
||||
case 'uk':
|
||||
case 'uk-UA':
|
||||
return (($number % 10 == 1) && ($number % 100 != 11)) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2);
|
||||
case 'cs':
|
||||
case 'cs-CZ':
|
||||
case 'sk':
|
||||
case 'sk-SK':
|
||||
return ($number == 1) ? 0 : ((($number >= 2) && ($number <= 4)) ? 1 : 2);
|
||||
case 'ga':
|
||||
case 'ga-IE':
|
||||
return ($number == 1) ? 0 : (($number == 2) ? 1 : 2);
|
||||
case 'lt':
|
||||
case 'lt-LT':
|
||||
return (($number % 10 == 1) && ($number % 100 != 11)) ? 0 : ((($number % 10 >= 2) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2);
|
||||
case 'sl':
|
||||
case 'sl-SI':
|
||||
return ($number % 100 == 1) ? 0 : (($number % 100 == 2) ? 1 : ((($number % 100 == 3) || ($number % 100 == 4)) ? 2 : 3));
|
||||
case 'mk':
|
||||
case 'mk-MK':
|
||||
return ($number % 10 == 1) ? 0 : 1;
|
||||
case 'mt':
|
||||
case 'mt-MT':
|
||||
return ($number == 1) ? 0 : ((($number == 0) || (($number % 100 > 1) && ($number % 100 < 11))) ? 1 : ((($number % 100 > 10) && ($number % 100 < 20)) ? 2 : 3));
|
||||
case 'lv':
|
||||
case 'lv-LV':
|
||||
return ($number == 0) ? 0 : ((($number % 10 == 1) && ($number % 100 != 11)) ? 1 : 2);
|
||||
case 'pl':
|
||||
case 'pl-PL':
|
||||
return ($number == 1) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 12) || ($number % 100 > 14))) ? 1 : 2);
|
||||
case 'cy':
|
||||
case 'cy-GB':
|
||||
return ($number == 1) ? 0 : (($number == 2) ? 1 : ((($number == 8) || ($number == 11)) ? 2 : 3));
|
||||
case 'ro':
|
||||
case 'ro-RO':
|
||||
return ($number == 1) ? 0 : ((($number == 0) || (($number % 100 > 0) && ($number % 100 < 20))) ? 1 : 2);
|
||||
case 'ar':
|
||||
case 'ar-AE':
|
||||
case 'ar-BH':
|
||||
case 'ar-DZ':
|
||||
case 'ar-EG':
|
||||
case 'ar-IN':
|
||||
case 'ar-IQ':
|
||||
case 'ar-JO':
|
||||
case 'ar-KW':
|
||||
case 'ar-LB':
|
||||
case 'ar-LY':
|
||||
case 'ar-MA':
|
||||
case 'ar-OM':
|
||||
case 'ar-QA':
|
||||
case 'ar-SA':
|
||||
case 'ar-SD':
|
||||
case 'ar-SS':
|
||||
case 'ar-SY':
|
||||
case 'ar-TN':
|
||||
case 'ar-YE':
|
||||
return ($number == 0) ? 0 : (($number == 1) ? 1 : (($number == 2) ? 2 : ((($number % 100 >= 3) && ($number % 100 <= 10)) ? 3 : ((($number % 100 >= 11) && ($number % 100 <= 99)) ? 4 : 5))));
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
82
overrides/akaunting/module/Commands/DeleteCommand.php
Normal file
82
overrides/akaunting/module/Commands/DeleteCommand.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Akaunting\Module\Commands;
|
||||
|
||||
use App\Models\Module\Module;
|
||||
use App\Models\Module\ModuleHistory;
|
||||
use Artisan;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class DeleteCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'module:delete {alias} {company_id}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
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'),
|
||||
'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));
|
||||
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
$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.'),
|
||||
);
|
||||
}
|
||||
}
|
82
overrides/akaunting/module/Commands/DisableCommand.php
Normal file
82
overrides/akaunting/module/Commands/DisableCommand.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Akaunting\Module\Commands;
|
||||
|
||||
use App\Models\Module\Module;
|
||||
use App\Models\Module\ModuleHistory;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class DisableCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'module:disable {alias} {company_id}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Disable 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;
|
||||
}
|
||||
|
||||
if ($model->enabled == 1) {
|
||||
$model->enabled = 0;
|
||||
$model->save();
|
||||
|
||||
$module = module($alias);
|
||||
|
||||
// Add history
|
||||
$data = [
|
||||
'company_id' => $company_id,
|
||||
'module_id' => $model->id,
|
||||
'category' => $module->get('category'),
|
||||
'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.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.'),
|
||||
);
|
||||
}
|
||||
}
|
82
overrides/akaunting/module/Commands/EnableCommand.php
Normal file
82
overrides/akaunting/module/Commands/EnableCommand.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Akaunting\Module\Commands;
|
||||
|
||||
use App\Models\Module\Module;
|
||||
use App\Models\Module\ModuleHistory;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class EnableCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'module:enable {alias} {company_id}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Enable 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;
|
||||
}
|
||||
|
||||
if ($model->enabled == 0) {
|
||||
$model->enabled = 1;
|
||||
$model->save();
|
||||
|
||||
$module = module($alias);
|
||||
|
||||
// Add history
|
||||
$data = [
|
||||
'company_id' => $company_id,
|
||||
'module_id' => $model->id,
|
||||
'category' => $module->get('category'),
|
||||
'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.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.'),
|
||||
);
|
||||
}
|
||||
}
|
95
overrides/akaunting/module/Commands/InstallCommand.php
Normal file
95
overrides/akaunting/module/Commands/InstallCommand.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace Akaunting\Module\Commands;
|
||||
|
||||
use App\Models\Module\Module;
|
||||
use App\Models\Module\ModuleHistory;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
class InstallCommand extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'module:install {alias} {company_id}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Install the specified module.';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$alias = Str::kebab($this->argument('alias'));
|
||||
$company_id = $this->argument('company_id');
|
||||
|
||||
$old_company_id = session('company_id');
|
||||
|
||||
// Set company id
|
||||
session(['company_id' => $company_id]);
|
||||
|
||||
$request = [
|
||||
'company_id' => $company_id,
|
||||
'alias' => strtolower($alias),
|
||||
'enabled' => '1',
|
||||
];
|
||||
|
||||
$model = Module::create($request);
|
||||
|
||||
$module = module($alias);
|
||||
|
||||
// Add history
|
||||
$data = [
|
||||
'company_id' => $company_id,
|
||||
'module_id' => $model->id,
|
||||
'category' => $module->get('category'),
|
||||
'version' => $module->get('version'),
|
||||
'description' => trans('modules.installed', ['module' => $module->get('alias')]),
|
||||
];
|
||||
|
||||
ModuleHistory::create($data);
|
||||
|
||||
// Clear cache
|
||||
$this->call('cache:clear');
|
||||
|
||||
// Update database
|
||||
$this->call('migrate', ['--force' => true]);
|
||||
|
||||
// Trigger event
|
||||
event(new \App\Events\Module\Installed($alias, $company_id));
|
||||
|
||||
// Unset company id
|
||||
session()->forget('company_id');
|
||||
|
||||
// Set company id
|
||||
if (!empty($old_company_id)) {
|
||||
session(['company_id' => $old_company_id]);
|
||||
}
|
||||
|
||||
$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.'),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user