1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-12 03:34:04 +02:00

[ticket/11150] Enforce enable on install and purge on remove options

PHPBB3-11150
This commit is contained in:
Tristan Darricau
2015-09-15 12:33:19 +02:00
committed by Tristan Darricau
parent 8f1d254191
commit 46972aa4c7
6 changed files with 125 additions and 18 deletions

View File

@@ -17,8 +17,8 @@ use Composer\IO\IOInterface;
use phpbb\cache\driver\driver_interface;
use phpbb\composer\exception\managed_with_clean_error_exception;
use phpbb\composer\exception\managed_with_enable_error_exception;
use phpbb\composer\exception\managed_with_error_exception;
use phpbb\composer\exception\runtime_exception;
use phpbb\config\config;
use phpbb\extension\manager as ext_manager;
use phpbb\filesystem\exception\filesystem_exception;
use phpbb\filesystem\filesystem;
@@ -43,6 +43,16 @@ class extension_manager extends manager
*/
private $enabled_extensions;
/**
* @var bool Enables extensions when installing them?
*/
private $enable_on_install = false;
/**
* @var bool Purges extensions data when removing them?
*/
private $purge_on_remove = false;
/**
* @param installer $installer Installer object
* @param driver_interface $cache Cache object
@@ -50,12 +60,19 @@ class extension_manager extends manager
* @param filesystem $filesystem Filesystem object
* @param string $package_type Composer type of managed packages
* @param string $exception_prefix Exception prefix to use
* @param config $config Config object
*/
public function __construct(installer $installer, driver_interface $cache, ext_manager $extension_manager, filesystem $filesystem, $package_type, $exception_prefix)
public function __construct(installer $installer, driver_interface $cache, ext_manager $extension_manager, filesystem $filesystem, $package_type, $exception_prefix, config $config = null)
{
$this->extension_manager = $extension_manager;
$this->filesystem = $filesystem;
if ($config)
{
$this->enable_on_install = (bool) $config['exts_composer_enable_on_install'];
$this->purge_on_remove = (bool) $config['exts_composer_purge_on_remove'];
}
parent::__construct($installer, $cache, $package_type, $exception_prefix);
}
@@ -71,6 +88,32 @@ class extension_manager extends manager
}
}
/**
* {@inheritdoc}
*/
public function post_install(array $packages, IOInterface $io = null)
{
if ($this->enable_on_install)
{
$io->writeError('ENABLING_EXTENSIONS', true, 1);
foreach ($packages as $package)
{
try
{
$this->extension_manager->enable($package);
}
catch (\phpbb\exception\runtime_exception $e)
{
$io->writeError([$e->getMessage(), $e->get_parameters()], true, 4);
}
catch (\Exception $e)
{
$io->writeError($e->getMessage(), true, 4);
}
}
}
}
/**
* {@inheritdoc}
*/
@@ -143,14 +186,25 @@ class extension_manager extends manager
*/
public function pre_remove(array $packages, IOInterface $io = null)
{
$io->writeError('DISABLING_EXTENSIONS', true, 1);
if ($this->purge_on_remove)
{
$io->writeError('DISABLING_EXTENSIONS', true, 1);
}
foreach ($packages as $package)
{
try
{
if ($this->extension_manager->is_enabled($package))
{
$this->extension_manager->disable($package);
if ($this->purge_on_remove)
{
$this->extension_manager->purge($package);
}
else
{
$this->extension_manager->disable($package);
}
}
}
catch (\phpbb\exception\runtime_exception $e)
@@ -227,4 +281,26 @@ class extension_manager extends manager
}
}
}
/**
* Enable the extensions when installing
*
* Warning: Only the explicitly required extensions will be enabled
*
* @param bool $enable
*/
public function set_enable_on_install($enable)
{
$this->enable_on_install = $enable;
}
/**
* Purge the extension when disabling it
*
* @param bool $purge
*/
public function set_purge_on_remove($purge)
{
$this->purge_on_remove = $purge;
}
}

View File

@@ -222,9 +222,11 @@ class installer
foreach ($installed_packages as $package)
{
if (array_key_exists($package->getName(), $required_links) && in_array($package->getType(), $types, true))
if (in_array($package->getType(), $types, true))
{
$installed[$package->getName()] = $required_links[$package->getName()]->getPrettyConstraint();
$version = array_key_exists($package->getName(), $required_links) ?
$required_links[$package->getName()]->getPrettyConstraint() : '*';
$installed[$package->getName()] = $version;
}
}