1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-10 18:54:08 +02:00

[ticket/11150] Add extension:start-managing command

PHPBB3-11150
This commit is contained in:
Tristan Darricau
2015-09-11 18:01:56 +02:00
committed by Tristan Darricau
parent 779c9c8552
commit 00229c20f0
12 changed files with 331 additions and 32 deletions

View File

@@ -13,8 +13,13 @@
namespace phpbb\composer;
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\extension\manager as ext_manager;
use phpbb\filesystem\exception\filesystem_exception;
use phpbb\filesystem\filesystem;
/**
* Class to safely manage extensions through composer.
@@ -26,15 +31,22 @@ class extension_manager extends manager
*/
protected $extension_manager;
/**
* @var \phpbb\filesystem\filesystem
*/
protected $filesystem;
/**
* @param installer $installer Installer object
* @param ext_manager $extension_manager phpBB extension manager
* @param filesystem $filesystem Filesystem object
* @param string $package_type Composer type of managed packages
* @param string $exception_prefix Exception prefix to use
*/
public function __construct(installer $installer, ext_manager $extension_manager, $package_type, $exception_prefix)
public function __construct(installer $installer, ext_manager $extension_manager, filesystem $filesystem, $package_type, $exception_prefix)
{
$this->extension_manager = $extension_manager;
$this->filesystem = $filesystem;
parent::__construct($installer, $package_type, $exception_prefix);
}
@@ -60,4 +72,66 @@ class extension_manager extends manager
$this->do_install($packages);
}
/**
* {@inheritdoc}
*/
public function start_managing($package)
{
if (!$this->extension_manager->is_available($package))
{
throw new runtime_exception($this->exception_prefix, 'NOT_INSTALLED', [$package]);
}
if ($this->is_managed($package))
{
throw new runtime_exception($this->exception_prefix, 'ALREADY_MANAGED', [$package]);
}
$enabled = false;
if ($this->extension_manager->is_enabled($package))
{
$enabled = true;
$this->extension_manager->disable($package);
}
$ext_path = $this->extension_manager->get_extension_path($package);
$backup_path = rtrim($ext_path, '/') . '__backup__';
try
{
$this->filesystem->rename($ext_path, $backup_path);
}
catch (filesystem_exception $e)
{
throw new runtime_exception($this->exception_prefix, 'CANNOT_MANAGE_FILESYSTEM_ERROR', [$package], $e);
}
try
{
$this->install((array) $package);
$this->filesystem->remove($backup_path);
}
catch (runtime_exception $e)
{
$this->filesystem->rename($backup_path, $ext_path);
throw new runtime_exception($this->exception_prefix, 'CANNOT_MANAGE_INSTALL_ERROR', [$package], $e);
}
catch (filesystem_exception $e)
{
throw new managed_with_clean_error_exception($this->exception_prefix, 'MANAGED_WITH_CLEAN_ERROR', [$package, $backup_path], $e);
}
if ($enabled)
{
try
{
$this->extension_manager->enable($package);
}
catch (\Exception $e)
{
throw new managed_with_enable_error_exception($this->exception_prefix, 'MANAGED_WITH_ENABLE_ERROR', [$package], $e);
}
}
}
}