1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-30 02:59:29 +02:00

[ticket/11150] Handle composer context transparently

PHPBB3-11150
This commit is contained in:
Tristan Darricau 2017-04-21 23:11:17 +02:00
parent 69571f9cef
commit 5376f676bf
No known key found for this signature in database
GPG Key ID: 817043C2E29DB881
2 changed files with 47 additions and 57 deletions
phpBB
includes/acp
phpbb/composer

@ -172,13 +172,11 @@ class acp_extensions
/** @var \phpbb\composer\manager $composer_manager */
$composer_manager = $phpbb_container->get('ext.composer.manager');
$this->request->enable_super_globals();
$managed_packages = [];
if ($composer_manager->check_requirements())
{
$managed_packages = $composer_manager->get_managed_packages();
}
$this->request->disable_super_globals();
$this->list_enabled_exts($phpbb_extension_manager, $managed_packages);
$this->list_disabled_exts($phpbb_extension_manager, $managed_packages);
@ -475,9 +473,7 @@ class acp_extensions
try
{
$this->request->enable_super_globals();
$composer_manager->install((array) $extension, $composer_io);
$this->request->disable_super_globals();
}
catch (\phpbb\exception\runtime_exception $e)
{
@ -514,9 +510,7 @@ class acp_extensions
try
{
$this->request->enable_super_globals();
$composer_manager->remove((array) $extension, $composer_io);
$this->request->disable_super_globals();
}
catch (\phpbb\exception\runtime_exception $e)
{
@ -553,9 +547,7 @@ class acp_extensions
try
{
$this->request->enable_super_globals();
$composer_manager->update((array) $extension, $composer_io);
$this->request->disable_super_globals();
}
catch (\phpbb\exception\runtime_exception $e)
{
@ -592,9 +584,7 @@ class acp_extensions
try
{
$this->request->enable_super_globals();
$composer_manager->start_managing($extension, $composer_io);
$this->request->disable_super_globals();
}
catch (\phpbb\exception\runtime_exception $e)
{
@ -684,10 +674,8 @@ class acp_extensions
$start = $this->request->variable('start', 0);
$base_url = $this->u_action;
$this->request->enable_super_globals();
$available_extensions = $manager->get_available_packages();
$managed_packages = $manager->get_managed_packages();
$this->request->disable_super_globals();
$extensions = array_slice($available_extensions, $start, 20);

@ -27,6 +27,7 @@ use phpbb\composer\io\null_io;
use phpbb\config\config;
use phpbb\exception\runtime_exception;
use phpbb\filesystem\filesystem;
use phpbb\request\request;
use Seld\JsonLint\ParsingException;
/**
@ -76,12 +77,18 @@ class installer
*/
private $ext_json_file_backup;
/**
* @var request phpBB request object
*/
private $request;
/**
* @param string $root_path phpBB root path
* @param filesystem $filesystem Filesystem object
* @param request $request phpBB request object
* @param config $config Config object
*/
public function __construct($root_path, filesystem $filesystem, config $config = null)
public function __construct($root_path, filesystem $filesystem, request $request, config $config = null)
{
if ($config)
{
@ -99,6 +106,7 @@ class installer
}
$this->root_path = $root_path;
$this->request = $request;
putenv('COMPOSER_HOME=' . $filesystem->realpath($root_path) . '/store/composer');
}
@ -115,19 +123,9 @@ class installer
*/
public function install(array $packages, $whitelist, IOInterface $io = null)
{
// The composer installers works with a path relative to the current directory
$this->move_to_root();
try
{
$this->wrap(function() use ($packages, $whitelist, $io) {
$this->do_install($packages, $whitelist, $io);
$this->restore_cwd();
}
catch (runtime_exception $e)
{
$this->restore_cwd();
throw $e;
}
});
}
/**
@ -178,7 +176,6 @@ class installer
catch (\Exception $e)
{
$this->restore_ext_json_file();
$this->restore_cwd();
throw new runtime_exception('COMPOSER_CANNOT_INSTALL', [], $e);
}
@ -186,7 +183,6 @@ class installer
if ($result !== 0)
{
$this->restore_ext_json_file();
$this->restore_cwd();
throw new runtime_exception($io->get_composer_error(), []);
}
@ -203,21 +199,9 @@ class installer
*/
public function get_installed_packages($types)
{
// The composer installers works with a path relative to the current directory
$this->move_to_root();
try
{
$result = $this->do_get_installed_packages($types);
$this->restore_cwd();
}
catch (runtime_exception $e)
{
$this->restore_cwd();
throw $e;
}
return $result;
return $this->wrap(function() use ($types) {
return $this->do_get_installed_packages($types);
});
}
/**
@ -275,21 +259,9 @@ class installer
*/
public function get_available_packages($type)
{
// The composer installers works with a path relative to the current directory
$this->move_to_root();
try
{
$result = $this->do_get_available_packages($type);
$this->restore_cwd();
}
catch (runtime_exception $e)
{
$this->restore_cwd();
throw $e;
}
return $result;
return $this->wrap(function() use ($type) {
return $this->do_get_available_packages($type);
});
}
/**
@ -704,4 +676,34 @@ class installer
$this->original_cwd = null;
}
}
/**
* Wraps a callable in order to adjust the context needed by composer
*
* @param callable $callable
*
* @return mixed
*/
protected function wrap(callable $callable)
{
// The composer installers works with a path relative to the current directory
$this->move_to_root();
// The composer installers uses some super globals
$super_globals = $this->request->super_globals_disabled();
$this->request->enable_super_globals();
try
{
return $callable();
}
finally
{
$this->restore_cwd();
if ($super_globals) {
$this->request->disable_super_globals();
}
}
}
}