1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 05:50:42 +02:00

[ticket/16891] Do not change an extension status in the middle of a request

When enabling an extension, it should be considered as not being enabled for
the entire request as if the "enabled" flag is switch during the request, the
extension will stay not loaded (same when disabling an extension).

Example when it can be an issue today : if the router is called for the first
time after enabling the extension and if the extension uses a custom route
loader (like phpbb/pages) then the router will fail because the custom route
will be found but the custom loader will not be loaded and available.

PHPBB3-16891
This commit is contained in:
Tristan Darricau
2021-10-21 20:17:17 +02:00
parent 99734fc648
commit b28b94b1f1
9 changed files with 115 additions and 4 deletions

View File

@@ -30,9 +30,11 @@ class manager
protected $cache;
protected $php_ext;
protected $extensions;
protected $recently_changed_ext_status;
protected $extension_table;
protected $phpbb_root_path;
protected $cache_name;
protected $router;
/**
* Creates a manager and loads information from database
@@ -47,7 +49,7 @@ class manager
* @param \phpbb\cache\service $cache A cache instance or null
* @param string $cache_name The name of the cache variable, defaults to _ext
*/
public function __construct(ContainerInterface $container, \phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\filesystem\filesystem_interface $filesystem, $extension_table, $phpbb_root_path, $php_ext = 'php', \phpbb\cache\service $cache = null, $cache_name = '_ext')
public function __construct(ContainerInterface $container, \phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\filesystem\filesystem_interface $filesystem, \phpbb\routing\router $router, $extension_table, $phpbb_root_path, $php_ext = 'php', \phpbb\cache\service $cache = null, $cache_name = '_ext')
{
$this->cache = $cache;
$this->cache_name = $cache_name;
@@ -56,6 +58,7 @@ class manager
$this->db = $db;
$this->extension_table = $extension_table;
$this->filesystem = $filesystem;
$this->router = $router;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
@@ -238,6 +241,12 @@ class manager
'ext_state' => serialize($state),
);
if ($active)
{
$this->recently_changed_ext_status[$name] = false;
$this->router->without_cache();
}
$this->update_state($name, $extension_data, $this->is_configured($name) ? 'update' : 'insert');
if ($active)
@@ -287,6 +296,12 @@ class manager
$state = $extension->disable_step($old_state);
$active = ($state !== false);
if (!$active)
{
$this->recently_changed_ext_status[$name] = true;
$this->router->without_cache();
}
$extension_data = array(
'ext_active' => $active,
'ext_state' => serialize($state),
@@ -499,6 +514,13 @@ class manager
*/
public function is_enabled($name)
{
// The extension has just been enabled and so is not loaded. When asking if it is enabled or
// not we should answer no to stay consistent with the status at the beginning of the request.
if (isset($this->recently_changed_ext_status[$name]))
{
return $this->recently_changed_ext_status[$name];
}
return isset($this->extensions[$name]['ext_active']) && $this->extensions[$name]['ext_active'];
}
@@ -510,6 +532,13 @@ class manager
*/
public function is_disabled($name)
{
// The extension has just been disabled and so is still loaded. When asking if it is disabled or
// not we should answer yes to stay consistent with the status at the beginning of the request.
if (isset($this->recently_changed_ext_status[$name]))
{
return $this->recently_changed_ext_status[$name];
}
return isset($this->extensions[$name]['ext_active']) && !$this->extensions[$name]['ext_active'];
}