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

[ticket/13697] Moving filesystem related functions to filesystem service

* Moving filesystem service to \phpbb\filesystem namespace
 * Wraping Symfony's Filesystem component
 * Moving filesystem related functions from includes/functions.php
   into \phpbb\filesystem\filesystem
   Functions moved (and deprecated):
     - phpbb_chmod
     - phpbb_is_writable
     - phpbb_is_absolute
     - phpbb_own_realpath
     - phpbb_realpath
 * Adding interface for filesystem service

PHPBB3-13697
This commit is contained in:
MateBartus
2015-03-12 00:25:00 +01:00
parent f86c5d905b
commit 4bdef6fd21
82 changed files with 1859 additions and 657 deletions

View File

@@ -183,7 +183,10 @@ define('IN_DB_UPDATE', true);
/* @var $migrator \phpbb\db\migrator */
$migrator = $phpbb_container->get('migrator');
$migrator->set_output_handler(new \phpbb\db\log_wrapper_migrator_output_handler($user, new \phpbb\db\html_migrator_output_handler($user), $phpbb_root_path . 'store/migrations_' . time() . '.log'));
/** @var \phpbb\filesystem\filesystem_interface $filesystem */
$filesystem = $phpbb_container->get('filesystem');
$migrator->set_output_handler(new \phpbb\db\log_wrapper_migrator_output_handler($user, new \phpbb\db\html_migrator_output_handler($user), $phpbb_root_path . 'store/migrations_' . time() . '.log', $filesystem));
$migrator->create_migrations_table();

View File

@@ -270,7 +270,7 @@ $config = new \phpbb\config\config(array(
/* @var $symfony_request \phpbb\symfony_request */
$symfony_request = $phpbb_container->get('symfony_request');
/* @var $phpbb_filesystem \phpbb\filesystem */
/* @var $phpbb_filesystem \phpbb\filesystem\filesystem_interface */
$phpbb_filesystem = $phpbb_container->get('filesystem');
/* @var $phpbb_path_helper \phpbb\path_helper */

View File

@@ -96,6 +96,9 @@ class install_convert extends module
/** @var string */
protected $php_ext;
/** @var \phpbb\filesystem\filesystem_interface */
protected $filesystem;
/**
* Variables used while converting, they are accessible from the global variable $convert
*/
@@ -116,6 +119,7 @@ class install_convert extends module
$this->template = $template;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $phpEx;
$this->filesystem = new \phpbb\filesystem\filesystem();
if (!$this->check_phpbb_installed())
{
@@ -859,7 +863,7 @@ class install_convert extends module
$this->p_master->error($user->lang['DEV_NO_TEST_FILE'], __LINE__, __FILE__);
}
if (!$local_path || !phpbb_is_writable($phpbb_root_path . $local_path))
if (!$local_path || !$this->filesystem->is_writable($phpbb_root_path . $local_path))
{
if (!$local_path)
{

View File

@@ -43,9 +43,15 @@ if (!empty($setmodules))
*/
class install_install extends module
{
/**
* @var \phpbb\filesystem\filesystem_interface
*/
protected $filesystem;
function install_install(&$p_master)
{
$this->p_master = &$p_master;
$this->filesystem = new \phpbb\filesystem\filesystem();
}
function main($mode, $sub)
@@ -466,13 +472,29 @@ class install_install extends module
if (!file_exists($phpbb_root_path . $dir))
{
@mkdir($phpbb_root_path . $dir, 0777);
phpbb_chmod($phpbb_root_path . $dir, CHMOD_READ | CHMOD_WRITE);
try
{
$this->filesystem->phpbb_chmod($phpbb_root_path . $dir, CHMOD_READ | CHMOD_WRITE);
}
catch (\phpbb\filesystem\exception\filesystem_exception $e)
{
// Do nothing
}
}
// Now really check
if (file_exists($phpbb_root_path . $dir) && is_dir($phpbb_root_path . $dir))
{
phpbb_chmod($phpbb_root_path . $dir, CHMOD_READ | CHMOD_WRITE);
try
{
$this->filesystem->phpbb_chmod($phpbb_root_path . $dir, CHMOD_READ | CHMOD_WRITE);
}
catch (\phpbb\filesystem\exception\filesystem_exception $e)
{
// Do nothing
}
$exists = true;
}
@@ -514,7 +536,7 @@ class install_install extends module
$write = $exists = true;
if (file_exists($phpbb_root_path . $dir))
{
if (!phpbb_is_writable($phpbb_root_path . $dir))
if (!$this->filesystem->is_writable($phpbb_root_path . $dir))
{
$write = false;
}
@@ -892,7 +914,7 @@ class install_install extends module
$config_data = phpbb_create_config_file_data($data, $available_dbms[$data['dbms']]['DRIVER']);
// Attempt to write out the config file directly. If it works, this is the easiest way to do it ...
if ((file_exists($phpbb_root_path . 'config.' . $phpEx) && phpbb_is_writable($phpbb_root_path . 'config.' . $phpEx)) || phpbb_is_writable($phpbb_root_path))
if ((file_exists($phpbb_root_path . 'config.' . $phpEx) && $this->filesystem->is_writable($phpbb_root_path . 'config.' . $phpEx)) || $this->filesystem->is_writable($phpbb_root_path))
{
// Assume it will work ... if nothing goes wrong below
$written = true;
@@ -914,7 +936,14 @@ class install_install extends module
if ($written)
{
// We may revert back to chmod() if we see problems with users not able to change their config.php file directly
phpbb_chmod($phpbb_root_path . 'config.' . $phpEx, CHMOD_READ);
try
{
$this->filesystem->phpbb_chmod($phpbb_root_path . 'config.' . $phpEx, CHMOD_READ);
}
catch (\phpbb\filesystem\exception\filesystem_exception $e)
{
// Do nothing
}
}
}
@@ -1195,7 +1224,7 @@ class install_install extends module
include($phpbb_root_path . 'includes/constants.' . $phpEx);
}
$finder = new \phpbb\finder(new \phpbb\filesystem(), $phpbb_root_path, null, $phpEx);
$finder = new \phpbb\finder(new \phpbb\filesystem\filesystem(), $phpbb_root_path, null, $phpEx);
$classes = $finder->core_path('phpbb/db/migration/data/')
->get_classes();
@@ -2031,7 +2060,7 @@ class install_install extends module
{
global $config, $phpbb_root_path;
if (!phpbb_is_writable($phpbb_root_path . 'images/avatars/upload/'))
if (!$this->filesystem->is_writable($phpbb_root_path . 'images/avatars/upload/'))
{
$config->set('allow_avatar', 0);
$config->set('allow_avatar_upload', 0);

View File

@@ -55,6 +55,8 @@ class install_update extends module
var $update_to_version;
protected $filesystem;
// Set to false
var $test_update = false;
@@ -87,6 +89,8 @@ class install_update extends module
/* @var $cache \phpbb\cache\service */
$cache = $phpbb_container->get('cache');
$this->filesystem = $phpbb_container->get('filesystem');
$this->tpl_name = 'install_update';
$this->page_title = 'UPDATE_INSTALLATION';
@@ -961,7 +965,7 @@ class install_update extends module
// Now init the connection
if ($update_mode == 'download')
{
if (function_exists('phpbb_is_writable') && !phpbb_is_writable($phpbb_root_path . 'store/'))
if ($this->filesystem->is_writable($phpbb_root_path . 'store/'))
{
trigger_error(sprintf('The directory “%s” is not writable.', $phpbb_root_path . 'store/'), E_USER_ERROR);
}