|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yajra\CMS\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use Yajra\CMS\DataTables\ExtensionsDataTable; |
|
7
|
|
|
use Yajra\CMS\Repositories\Extension\Repository; |
|
8
|
|
|
|
|
9
|
|
|
class ExtensionsController extends Controller |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @var \Yajra\CMS\Repositories\Extension\Repository |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $repository; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* ExtensionsController constructor. |
|
18
|
|
|
* |
|
19
|
|
|
* @param \Yajra\CMS\Repositories\Extension\Repository $repository |
|
20
|
|
|
*/ |
|
21
|
|
|
public function __construct(Repository $repository) |
|
22
|
|
|
{ |
|
23
|
|
|
$this->authorizePermissionResource('extension'); |
|
24
|
|
|
$this->repository = $repository; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Display extensions resource. |
|
29
|
|
|
* |
|
30
|
|
|
* @param \Yajra\CMS\DataTables\ExtensionsDataTable $dataTable |
|
31
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
|
32
|
|
|
*/ |
|
33
|
|
|
public function index(ExtensionsDataTable $dataTable) |
|
34
|
|
|
{ |
|
35
|
|
|
return $dataTable->render('administrator.extensions.index'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function store(Request $request) |
|
39
|
|
|
{ |
|
40
|
|
|
$extension = $this->repository->findOrFail($request->get('id')); |
|
41
|
|
|
$extension->enabled = ! $extension->enabled; |
|
42
|
|
|
$extension->save(); |
|
43
|
|
|
|
|
44
|
|
|
$response = 'cms::extension.' . ($extension->enabled ? 'enabled' : 'disabled'); |
|
45
|
|
|
|
|
46
|
|
|
return $this->notifySuccess(trans($response)); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Uninstall an extension. |
|
51
|
|
|
* |
|
52
|
|
|
* @param string $id |
|
53
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
54
|
|
|
*/ |
|
55
|
|
|
public function destroy($id) |
|
56
|
|
|
{ |
|
57
|
|
|
$extension = $this->repository->findOrFail($id); |
|
58
|
|
|
if ($extension->protected) { |
|
59
|
|
|
return $this->notifyError(trans('cms::extension.protected')); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
if ($this->repository->uninstall($id)) { |
|
63
|
|
|
flash()->success(trans('cms::extension.deleted', compact('id'))); |
|
|
|
|
|
|
64
|
|
|
} else { |
|
65
|
|
|
flash()->error(trans('cms::extension.error', compact('id'))); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return back(); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.