diff --git a/app/Http/Controllers/Modules/Item.php b/app/Http/Controllers/Modules/Item.php
index 158b2b81d..c1e58412c 100644
--- a/app/Http/Controllers/Modules/Item.php
+++ b/app/Http/Controllers/Modules/Item.php
@@ -5,7 +5,9 @@ namespace App\Http\Controllers\Modules;
use App\Abstracts\Http\Controller;
use App\Models\Module\Module;
use App\Traits\Modules;
+use File;
use Illuminate\Http\Request;
+use Illuminate\Support\Str;
class Item extends Controller
{
@@ -79,24 +81,41 @@ class Item extends Controller
$steps = [];
$name = $request['name'];
+ $alias = $request['alias'];
- // Download
- $steps[] = [
- 'text' => trans('modules.installation.download', ['module' => $name]),
- 'url' => route('apps.download')
- ];
+ $module_path = config('module.paths.modules') . '/' . Str::studly($alias);
- // Unzip
- $steps[] = [
- 'text' => trans('modules.installation.unzip', ['module' => $name]),
- 'url' => route('apps.unzip')
- ];
+ if (!File::isDirectory($module_path)) {
+ // Download
+ $steps[] = [
+ 'text' => trans('modules.installation.download', ['module' => $name]),
+ 'url' => route('apps.download')
+ ];
- // Download
- $steps[] = [
- 'text' => trans('modules.installation.install', ['module' => $name]),
- 'url' => route('apps.install')
- ];
+ // Unzip
+ $steps[] = [
+ 'text' => trans('modules.installation.unzip', ['module' => $name]),
+ 'url' => route('apps.unzip')
+ ];
+
+ // Copy
+ $steps[] = [
+ 'text' => trans('modules.installation.file_copy', ['module' => $name]),
+ 'url' => route('apps.copy')
+ ];
+
+ // Install
+ $steps[] = [
+ 'text' => trans('modules.installation.install', ['module' => $name]),
+ 'url' => route('apps.install')
+ ];
+ } else {
+ // Install
+ $steps[] = [
+ 'text' => trans('modules.installation.install', ['module' => $name]),
+ 'url' => route('apps.install')
+ ];
+ }
return response()->json([
'success' => true,
@@ -149,11 +168,27 @@ class Item extends Controller
*
* @return Response
*/
- public function install(Request $request)
+ public function copy(Request $request)
{
$path = $request['path'];
- $json = $this->installModule($path);
+ $json = $this->copyModule($path);
+
+ return response()->json($json);
+ }
+
+ /**
+ * Show the form for viewing the specified resource.
+ *
+ * @param $request
+ *
+ * @return Response
+ */
+ public function install(Request $request)
+ {
+ $alias = $request['alias'];
+
+ $json = $this->installModule($alias);
if ($json['success']) {
$message = trans('modules.installed', ['module' => $json['data']['name']]);
diff --git a/app/Traits/Modules.php b/app/Traits/Modules.php
index 2bb37598f..2686e7c78 100644
--- a/app/Traits/Modules.php
+++ b/app/Traits/Modules.php
@@ -390,7 +390,7 @@ trait Modules
];
}
- public function installModule($path)
+ public function copyModule($path)
{
$temp_path = storage_path('app/temp/' . $path);
@@ -425,13 +425,26 @@ trait Modules
event(new \App\Events\Module\Copied($module->alias, session('company_id')));
+ return [
+ 'success' => true,
+ 'error' => false,
+ 'message' => null,
+ 'data' => [
+ 'path' => $path,
+ 'alias' => $module->alias,
+ ],
+ ];
+ }
+
+ public function installModule($alias)
+ {
$company_id = session('company_id');
$locale = app()->getLocale();
- $command = "module:install {$module->alias} {$company_id} {$locale}";
+ $command = "module:install {$alias} {$company_id} {$locale}";
if (true !== $result = Console::run($command)) {
- $message = !empty($result) ? $result : trans('modules.errors.finish', ['module' => $module->alias]);
+ $message = !empty($result) ? $result : trans('modules.errors.finish', ['module' => $alias]);
return [
'success' => false,
@@ -443,13 +456,13 @@ trait Modules
return [
'success' => true,
- 'redirect' => route('apps.app.show', $module->alias),
+ 'redirect' => route('apps.app.show', $alias),
'error' => false,
'message' => null,
'data' => [
- 'path' => $path,
- 'name' => module($module->alias)->getName(),
- 'alias' => $module->alias,
+ 'path' => '',
+ 'name' => module($alias)->getName(),
+ 'alias' => $alias,
],
];
}
diff --git a/resources/assets/js/views/modules/item.js b/resources/assets/js/views/modules/item.js
index 6abd2c51b..b6d5163d0 100644
--- a/resources/assets/js/views/modules/item.js
+++ b/resources/assets/js/views/modules/item.js
@@ -52,6 +52,7 @@ const app = new Vue({
steps_total: 0,
total: 0,
path: '',
+ alias: '',
version: '',
status: 'success',
html: ''
@@ -98,7 +99,8 @@ const app = new Vue({
this.faq = true;
},
- async onInstall(path, name, version) {
+ async onInstall(path, alias, name, version) {
+ this.installation.alias = alias;
this.installation.show = true;
this.installation.total = 0;
this.installation.path = path;
@@ -106,6 +108,7 @@ const app = new Vue({
let steps_promise = Promise.resolve(axios.post(url + '/apps/steps', {
name: name,
+ alias: alias,
version: version
}));
@@ -136,6 +139,7 @@ const app = new Vue({
this.installation.html = ' ' + data['text'] + ' ';
let step_promise = Promise.resolve(axios.post(data.url, {
+ alias: this.installation.alias,
version: this.installation.version,
path: this.installation.path,
}));
diff --git a/resources/views/modules/item/show.blade.php b/resources/views/modules/item/show.blade.php
index 8a8d2f8a1..686905e69 100644
--- a/resources/views/modules/item/show.blade.php
+++ b/resources/views/modules/item/show.blade.php
@@ -233,7 +233,7 @@
@else
@can('create-modules-item')
@if ($module->install)
-