Files
.github
app
Abstracts
Commands
Module.php
Http
Listeners
View
BulkAction.php
Event.php
Export.php
Factory.php
Import.php
ImportMultipleSheets.php
Job.php
JobShouldQueue.php
Model.php
Notification.php
Observer.php
Report.php
Widget.php
Builders
BulkActions
Classifiers
Console
Events
Exceptions
Exports
Http
Imports
Interfaces
Jobs
Listeners
Models
Notifications
Observers
Providers
Relations
Reports
Scopes
Traits
Utilities
View
Widgets
bootstrap
config
database
modules
overrides
public
resources
routes
storage
tests
.editorconfig
.env.example
.env.testing
.gitattributes
.gitignore
.htaccess
LICENSE.txt
README.md
SECURITY.md
artisan
composer.json
composer.lock
index.php
manifest.json
nginx.example.com.conf
package-lock.json
package.json
phpunit.xml
presets.js
safelist.txt
serviceworker.js
tailwind.config.js
web.config
webpack.mix.js
akaunting/app/Abstracts/Commands/Module.php
2021-09-07 10:33:34 +03:00

79 lines
1.9 KiB
PHP

<?php
namespace App\Abstracts\Commands;
use App\Models\Module\Module as Model;
use App\Models\Module\ModuleHistory as ModelHistory;
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 = company_id();
company($this->company_id)->makeCurrent();
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)) {
company($this->old_company_id)->makeCurrent();
}
}
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;
}
ModelHistory::create([
'company_id' => $this->company_id,
'module_id' => $this->model->id,
'version' => $this->module->get('version'),
'description' => trans('modules.' . $action, ['module' => $this->alias]),
'created_from' => source_name(),
'created_by' => user_id(),
]);
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return [
['alias', InputArgument::REQUIRED, 'Module alias.'],
['company', InputArgument::REQUIRED, 'Company ID.'],
];
}
}