/
ManageController.php
200 lines (166 loc) · 5.3 KB
/
ManageController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
/**
* @package Joomla.Administrator
* @subpackage com_installer
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Installer\Administrator\Controller;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\Response\JsonResponse;
use Joomla\CMS\Router\Route;
use Joomla\Component\Installer\Administrator\Model\ManageModel;
use Joomla\Input\Input;
use Joomla\Utilities\ArrayHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Installer Manage Controller
*
* @since 1.6
*/
class ManageController extends BaseController
{
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
* @param MVCFactoryInterface $factory The factory.
* @param CMSApplication $app The Application for the dispatcher
* @param Input $input Input
*
* @since 1.6
*/
public function __construct($config = [], MVCFactoryInterface $factory = null, $app = null, $input = null)
{
parent::__construct($config, $factory, $app, $input);
$this->registerTask('unpublish', 'publish');
$this->registerTask('publish', 'publish');
}
/**
* Enable/Disable an extension (if supported).
*
* @return void
*
* @throws \Exception
*
* @since 1.6
*/
public function publish()
{
// Check for request forgeries.
$this->checkToken();
$ids = (array) $this->input->get('cid', [], 'int');
$values = ['publish' => 1, 'unpublish' => 0];
$task = $this->getTask();
$value = ArrayHelper::getValue($values, $task, 0, 'int');
// Remove zero values resulting from input filter
$ids = array_filter($ids);
if (empty($ids)) {
$this->setMessage(Text::_('COM_INSTALLER_ERROR_NO_EXTENSIONS_SELECTED'), 'warning');
} else {
/** @var ManageModel $model */
$model = $this->getModel('manage');
// Change the state of the records.
if (!$model->publish($ids, $value)) {
$this->setMessage(implode('<br>', $model->getErrors()), 'warning');
} else {
if ($value == 1) {
$ntext = 'COM_INSTALLER_N_EXTENSIONS_PUBLISHED';
} else {
$ntext = 'COM_INSTALLER_N_EXTENSIONS_UNPUBLISHED';
}
$this->setMessage(Text::plural($ntext, \count($ids)));
}
}
$this->setRedirect(Route::_('index.php?option=com_installer&view=manage', false));
}
/**
* Remove an extension (Uninstall).
*
* @return void
*
* @throws \Exception
*
* @since 1.5
*/
public function remove()
{
// Check for request forgeries.
$this->checkToken();
$eid = (array) $this->input->get('cid', [], 'int');
// Remove zero values resulting from input filter
$eid = array_filter($eid);
if (!empty($eid)) {
/** @var ManageModel $model */
$model = $this->getModel('manage');
$model->remove($eid);
}
$this->setRedirect(Route::_('index.php?option=com_installer&view=manage', false));
}
/**
* Refreshes the cached metadata about an extension.
*
* Useful for debugging and testing purposes when the XML file might change.
*
* @return void
*
* @since 1.6
*/
public function refresh()
{
// Check for request forgeries.
$this->checkToken();
$uid = (array) $this->input->get('cid', [], 'int');
// Remove zero values resulting from input filter
$uid = array_filter($uid);
if (!empty($uid)) {
/** @var ManageModel $model */
$model = $this->getModel('manage');
$model->refresh($uid);
}
$this->setRedirect(Route::_('index.php?option=com_installer&view=manage', false));
}
/**
* Load the changelog for a given extension. Outputs HTML encoded in JSON.
*
* @return void
*
* @since 4.0.0
*/
public function loadChangelog()
{
/** @var ManageModel $model */
$model = $this->getModel('manage');
$eid = $this->input->get('eid', 0, 'int');
$source = $this->input->get('source', 'manage', 'string');
if (!$eid) {
return;
}
$output = $model->loadChangelog($eid, $source);
echo (new JsonResponse($output));
}
/**
* Load the changelog for a given extension. Outputs HTML.
*
* @return void
*
* @since 5.1.0
*/
public function loadChangelogRaw()
{
/** @var ManageModel $model */
$model = $this->getModel('manage');
$eid = $this->input->get('eid', 0, 'int');
$source = $this->input->get('source', 'manage', 'string');
if (!$eid) {
return;
}
echo $model->loadChangelog($eid, $source);
}
}