86 lines
2.8 KiB
PHP
86 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace Modules\SupplyChain\Http\Controllers;
|
|
|
|
use App\System;
|
|
use Composer\Semver\Comparator;
|
|
use Illuminate\Routing\Controller;
|
|
use Illuminate\Support\Facades\Artisan;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class InstallController extends Controller
|
|
{
|
|
protected $module_name = 'supplychain';
|
|
|
|
protected $appVersion;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->appVersion = config('supplychain.module_version', '1.0.0');
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
if (! auth()->user()->can('superadmin')) {
|
|
abort(403, 'Unauthorized action.');
|
|
}
|
|
|
|
if (! empty(System::getProperty($this->module_name.'_version'))) {
|
|
abort(404);
|
|
}
|
|
|
|
return view('install.install-module')->with([
|
|
'action_url' => action([self::class, 'install']),
|
|
'intruction_type' => 'uf',
|
|
]);
|
|
}
|
|
|
|
public function install()
|
|
{
|
|
try {
|
|
DB::beginTransaction();
|
|
request()->validate(['license_code' => 'required', 'login_username' => 'required']);
|
|
DB::statement('SET default_storage_engine=INNODB;');
|
|
Artisan::call('module:migrate', ['module' => 'SupplyChain', '--force' => true]);
|
|
System::addProperty($this->module_name.'_version', $this->appVersion);
|
|
DB::commit();
|
|
$output = ['success' => 1, 'msg' => __('supplychain::lang.module_installed')];
|
|
} catch (\Exception $e) {
|
|
DB::rollBack();
|
|
\Log::emergency('File:'.$e->getFile().'Line:'.$e->getLine().'Message:'.$e->getMessage());
|
|
$output = ['success' => false, 'msg' => $e->getMessage()];
|
|
}
|
|
|
|
return redirect()->action([\App\Http\Controllers\Install\ModulesController::class, 'index'])->with('status', $output);
|
|
}
|
|
|
|
public function uninstall()
|
|
{
|
|
if (! auth()->user()->can('superadmin')) {
|
|
abort(403, 'Unauthorized action.');
|
|
}
|
|
|
|
System::removeProperty($this->module_name.'_version');
|
|
|
|
return redirect()->back()->with(['status' => ['success' => true, 'msg' => __('supplychain::lang.success')]]);
|
|
}
|
|
|
|
public function update()
|
|
{
|
|
if (! auth()->user()->can('superadmin')) {
|
|
abort(403, 'Unauthorized action.');
|
|
}
|
|
|
|
$current = System::getProperty($this->module_name.'_version');
|
|
if (! Comparator::greaterThan($this->appVersion, (string) $current)) {
|
|
abort(404);
|
|
}
|
|
|
|
DB::statement('SET default_storage_engine=INNODB;');
|
|
Artisan::call('module:migrate', ['module' => 'SupplyChain', '--force' => true]);
|
|
System::setProperty($this->module_name.'_version', $this->appVersion);
|
|
|
|
return redirect()->back()->with(['status' => ['success' => 1, 'msg' => __('supplychain::lang.module_updated', ['version' => $this->appVersion])]]);
|
|
}
|
|
}
|