63 lines
2.1 KiB
PHP
63 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Modules\ShopFloor\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 = 'shopfloor';
|
|
|
|
public function index()
|
|
{
|
|
if (! auth()->user()->can('superadmin')) {
|
|
abort(403);
|
|
}
|
|
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']);
|
|
Artisan::call('module:migrate', ['module' => 'ShopFloor', '--force' => true]);
|
|
System::addProperty($this->module_name.'_version', config('shopfloor.module_version', '1.0.0'));
|
|
DB::commit();
|
|
$output = ['success' => 1, 'msg' => __('shopfloor::lang.module_installed')];
|
|
} catch (\Exception $e) {
|
|
DB::rollBack();
|
|
$output = ['success' => false, 'msg' => $e->getMessage()];
|
|
}
|
|
|
|
return redirect()->action([\App\Http\Controllers\Install\ModulesController::class, 'index'])->with('status', $output);
|
|
}
|
|
|
|
public function update()
|
|
{
|
|
if (! auth()->user()->can('superadmin')) {
|
|
abort(403);
|
|
}
|
|
$version = config('shopfloor.module_version', '1.0.0');
|
|
$current = System::getProperty($this->module_name.'_version');
|
|
if (! Comparator::greaterThan($version, (string) $current)) {
|
|
abort(404);
|
|
}
|
|
Artisan::call('module:migrate', ['module' => 'ShopFloor', '--force' => true]);
|
|
System::setProperty($this->module_name.'_version', $version);
|
|
|
|
return redirect()->back()->with(['status' => ['success' => 1, 'msg' => __('shopfloor::lang.module_updated')]]);
|
|
}
|
|
}
|