|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: Mark |
|
5
|
|
|
* Date: 23/05/2016 |
|
6
|
|
|
* Time: 19:32. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace App\Plugins\Products; |
|
10
|
|
|
|
|
11
|
|
|
use App\Plugins\PluginEngine; |
|
12
|
|
|
use App\Classes\Repositories\PluginRepository; |
|
13
|
|
|
use App\Classes\Interfaces\Installable; |
|
14
|
|
|
use Illuminate\Support\Facades\DB; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class AdminController. |
|
18
|
|
|
*/ |
|
19
|
|
|
class BackendController extends PluginEngine |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var PluginRepository |
|
23
|
|
|
*/ |
|
24
|
|
|
private $plugins; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* BackendController constructor. |
|
28
|
|
|
* @param PluginRepository $plugins |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct(PluginRepository $plugins) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->plugins = $plugins; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Display a list of products available and disable, enable option for super admins. |
|
37
|
|
|
*/ |
|
38
|
|
|
public function index() |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->make('index')->with('products', $this->plugins->all()); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Steps required for the application install. |
|
45
|
|
|
* Usually defined for logging & new sql entries. |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $plugin_name |
|
48
|
|
|
* @return mixed |
|
|
|
|
|
|
49
|
|
|
*/ |
|
50
|
|
View Code Duplication |
public function install(string $plugin_name) |
|
|
|
|
|
|
51
|
|
|
{ |
|
52
|
|
|
$plugin = $this->plugins->whereName($plugin_name); |
|
53
|
|
|
|
|
54
|
|
|
if ($plugin->enabled == false) |
|
55
|
|
|
{ |
|
56
|
|
|
\DB::transaction( function () use ($plugin) |
|
57
|
|
|
{ |
|
58
|
|
|
if ($plugin->handler instanceof Installable) |
|
59
|
|
|
{ |
|
60
|
|
|
$plugin->handler->install(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$plugin->enabled = true; |
|
64
|
|
|
|
|
65
|
|
|
$plugin->save(); |
|
|
|
|
|
|
66
|
|
|
}, 5); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return response()->redirectToRoute('products.index'); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Steps required for the application uninstall. |
|
74
|
|
|
* Usually defined for logging & new sql entries. |
|
75
|
|
|
* |
|
76
|
|
|
* @param string $plugin_name |
|
77
|
|
|
* @return mixed |
|
|
|
|
|
|
78
|
|
|
*/ |
|
79
|
|
View Code Duplication |
public function uninstall(string $plugin_name) |
|
|
|
|
|
|
80
|
|
|
{ |
|
81
|
|
|
$plugin = $this->plugins->whereName($plugin_name); |
|
82
|
|
|
|
|
83
|
|
|
if ($plugin->enabled == true) |
|
84
|
|
|
{ |
|
85
|
|
|
\DB::transaction( function () use ($plugin) |
|
86
|
|
|
{ |
|
87
|
|
|
if ($plugin->handler instanceof Installable) |
|
88
|
|
|
{ |
|
89
|
|
|
$plugin->handler->uninstall(); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
$plugin->enabled = false; |
|
93
|
|
|
|
|
94
|
|
|
$plugin->save(); |
|
|
|
|
|
|
95
|
|
|
}, 5); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return response()->redirectToRoute('products.index'); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.