Removing the ability to install 'plugins' via the web interface.
This commit is contained in:
parent
cf415a7c78
commit
e186874eba
2 changed files with 17 additions and 309 deletions
|
|
@ -23,24 +23,6 @@ use PHPCI\Plugin\Util\PluginInformationCollection;
|
|||
*/
|
||||
class PluginController extends \PHPCI\Controller
|
||||
{
|
||||
protected $required = array(
|
||||
'php',
|
||||
'ext-pdo',
|
||||
'ext-pdo_mysql',
|
||||
'block8/b8framework',
|
||||
'ircmaxell/password-compat',
|
||||
'swiftmailer/swiftmailer',
|
||||
'symfony/yaml',
|
||||
'symfony/console',
|
||||
'psr/log',
|
||||
'monolog/monolog',
|
||||
'pimple/pimple',
|
||||
'robmorgan/phinx',
|
||||
);
|
||||
|
||||
protected $canInstall;
|
||||
protected $composerPath;
|
||||
|
||||
/**
|
||||
* List all enabled plugins, installed and recommend packages.
|
||||
* @return string
|
||||
|
|
@ -49,12 +31,8 @@ class PluginController extends \PHPCI\Controller
|
|||
{
|
||||
$this->requireAdmin();
|
||||
|
||||
$this->view->canWrite = is_writable(APPLICATION_PATH . 'composer.json');
|
||||
$this->view->required = $this->required;
|
||||
|
||||
$json = $this->getComposerJson();
|
||||
$this->view->installedPackages = $json['require'];
|
||||
$this->view->suggestedPackages = $json['suggest'];
|
||||
|
||||
$pluginInfo = new PluginInformationCollection();
|
||||
$pluginInfo->add(FilesPluginInformation::newFromDir(
|
||||
|
|
@ -71,49 +49,6 @@ class PluginController extends \PHPCI\Controller
|
|||
return $this->view->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a given package.
|
||||
*/
|
||||
public function remove()
|
||||
{
|
||||
$this->requireAdmin();
|
||||
|
||||
$package = $this->getParam('package', null);
|
||||
$json = $this->getComposerJson();
|
||||
|
||||
$response = new b8\Http\Response\RedirectResponse();
|
||||
|
||||
if (!in_array($package, $this->required)) {
|
||||
unset($json['require'][$package]);
|
||||
$this->setComposerJson($json);
|
||||
|
||||
$response->setHeader('Location', PHPCI_URL . 'plugin?r=' . $package);
|
||||
return $response;
|
||||
}
|
||||
|
||||
$response->setHeader('Location', PHPCI_URL);
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install a given package.
|
||||
*/
|
||||
public function install()
|
||||
{
|
||||
$this->requireAdmin();
|
||||
|
||||
$package = $this->getParam('package', null);
|
||||
$version = $this->getParam('version', '*');
|
||||
|
||||
$json = $this->getComposerJson();
|
||||
$json['require'][$package] = $version;
|
||||
$this->setComposerJson($json);
|
||||
|
||||
$response = new b8\Http\Response\RedirectResponse();
|
||||
$response->setHeader('Location', PHPCI_URL . 'plugin?w=' . $package);
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the json-decoded contents of the composer.json file.
|
||||
* @return mixed
|
||||
|
|
@ -123,83 +58,4 @@ class PluginController extends \PHPCI\Controller
|
|||
$json = file_get_contents(APPLICATION_PATH . 'composer.json');
|
||||
return json_decode($json, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert array to json and save composer.json
|
||||
*
|
||||
* @param $array
|
||||
*/
|
||||
protected function setComposerJson($array)
|
||||
{
|
||||
if (defined('JSON_PRETTY_PRINT')) {
|
||||
$json = json_encode($array, JSON_PRETTY_PRINT);
|
||||
} else {
|
||||
$json = json_encode($array);
|
||||
}
|
||||
|
||||
file_put_contents(APPLICATION_PATH . 'composer.json', $json);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a system binary.
|
||||
* @param $binary
|
||||
* @return null|string
|
||||
*/
|
||||
protected function findBinary($binary)
|
||||
{
|
||||
if (is_string($binary)) {
|
||||
$binary = array($binary);
|
||||
}
|
||||
|
||||
foreach ($binary as $bin) {
|
||||
// Check project root directory:
|
||||
if (is_file(APPLICATION_PATH . $bin)) {
|
||||
return APPLICATION_PATH . $bin;
|
||||
}
|
||||
|
||||
// Check Composer bin dir:
|
||||
if (is_file(APPLICATION_PATH . 'vendor/bin/' . $bin)) {
|
||||
return APPLICATION_PATH . 'vendor/bin/' . $bin;
|
||||
}
|
||||
|
||||
// Use "which"
|
||||
$which = trim(shell_exec('which ' . $bin));
|
||||
|
||||
if (!empty($which)) {
|
||||
return $which;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a search on packagist.org.
|
||||
*/
|
||||
public function packagistSearch()
|
||||
{
|
||||
$searchQuery = $this->getParam('q', '');
|
||||
$http = new \b8\HttpClient();
|
||||
$http->setHeaders(array('User-Agent: PHPCI/1.0 (+https://www.phptesting.org)'));
|
||||
$res = $http->get('https://packagist.org/search.json', array('q' => $searchQuery));
|
||||
|
||||
$response = new b8\Http\Response\JsonResponse();
|
||||
$response->setContent($res['body']);
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up available versions of a given package on packagist.org
|
||||
*/
|
||||
public function packagistVersions()
|
||||
{
|
||||
$name = $this->getParam('p', '');
|
||||
$http = new \b8\HttpClient();
|
||||
$http->setHeaders(array('User-Agent: PHPCI/1.0 (+https://www.phptesting.org)'));
|
||||
$res = $http->get('https://packagist.org/packages/'.$name.'.json');
|
||||
|
||||
$response = new b8\Http\Response\JsonResponse();
|
||||
$response->setContent($res['body']);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue