mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-21 07:51:33 +02:00
[ticket/15311] Use cache directory if can't use system temp
PHPBB3-15311
This commit is contained in:
2
phpBB/phpbb/cache/driver/file.php
vendored
2
phpBB/phpbb/cache/driver/file.php
vendored
@@ -35,7 +35,7 @@ class file extends \phpbb\cache\driver\base
|
||||
global $phpbb_container;
|
||||
|
||||
$this->cache_dir = !is_null($cache_dir) ? $cache_dir : $phpbb_container->getParameter('core.cache_dir');
|
||||
$this->filesystem = new \phpbb\filesystem\filesystem();
|
||||
$this->filesystem = new \phpbb\filesystem\filesystem('');
|
||||
|
||||
if (!is_dir($this->cache_dir))
|
||||
{
|
||||
|
@@ -402,7 +402,7 @@ class installer
|
||||
*/
|
||||
public function check_requirements()
|
||||
{
|
||||
$filesystem = new \phpbb\filesystem\filesystem();
|
||||
$filesystem = new \phpbb\filesystem\filesystem('');
|
||||
|
||||
return $filesystem->is_writable([
|
||||
$this->root_path . $this->composer_filename,
|
||||
|
@@ -21,6 +21,10 @@ use phpbb\db\extractor\exception\extractor_not_initialized_exception;
|
||||
*/
|
||||
abstract class base_extractor implements extractor_interface
|
||||
{
|
||||
/**
|
||||
* @var \phpbb\filesystem\filesystem
|
||||
*/
|
||||
protected $filesystem;
|
||||
|
||||
/**
|
||||
* @var \phpbb\request\request_interface
|
||||
@@ -83,8 +87,9 @@ abstract class base_extractor implements extractor_interface
|
||||
* @param \phpbb\request\request_interface $request
|
||||
* @param \phpbb\db\driver\driver_interface $db
|
||||
*/
|
||||
public function __construct(\phpbb\request\request_interface $request, \phpbb\db\driver\driver_interface $db)
|
||||
public function __construct(\phpbb\filesystem\filesystem $filesystem, \phpbb\request\request_interface $request, \phpbb\db\driver\driver_interface $db)
|
||||
{
|
||||
$this->filesystem = $filesystem;
|
||||
$this->request = $request;
|
||||
$this->db = $db;
|
||||
$this->fp = null;
|
||||
@@ -158,7 +163,7 @@ abstract class base_extractor implements extractor_interface
|
||||
|
||||
if ($store === true)
|
||||
{
|
||||
$file = sys_get_temp_dir() . '/' . $filename . $ext;
|
||||
$file = $this->filesystem->get_temp_dir() . '/' . $filename . $ext;
|
||||
|
||||
$this->fp = $open($file, 'w');
|
||||
|
||||
|
@@ -17,6 +17,7 @@ use bantu\IniGetWrapper\IniGetWrapper;
|
||||
use phpbb\config\config;
|
||||
use phpbb\files\factory;
|
||||
use phpbb\files\filespec;
|
||||
use phpbb\filesystem\filesystem;
|
||||
use phpbb\language\language;
|
||||
use phpbb\request\request_interface;
|
||||
|
||||
@@ -28,6 +29,15 @@ class remote extends base
|
||||
/** @var factory Files factory */
|
||||
protected $factory;
|
||||
|
||||
/** @var filesystem Filesystem */
|
||||
protected $filesystem;
|
||||
|
||||
/** @var language */
|
||||
protected $language;
|
||||
|
||||
/** @var IniGetWrapper */
|
||||
protected $php_ini;
|
||||
|
||||
/** @var request_interface */
|
||||
protected $request;
|
||||
|
||||
@@ -39,15 +49,17 @@ class remote extends base
|
||||
*
|
||||
* @param config $config phpBB config
|
||||
* @param factory $factory Files factory
|
||||
* @param filesystem $filesystem Filesystem
|
||||
* @param language $language Language class
|
||||
* @param IniGetWrapper $php_ini ini_get() wrapper
|
||||
* @param request_interface $request Request object
|
||||
* @param string $phpbb_root_path phpBB root path
|
||||
*/
|
||||
public function __construct(config $config, factory $factory, language $language, IniGetWrapper $php_ini, request_interface $request, $phpbb_root_path)
|
||||
public function __construct(config $config, factory $factory, filesystem $filesystem, language $language, IniGetWrapper $php_ini, request_interface $request, $phpbb_root_path)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->factory = $factory;
|
||||
$this->filesystem = $filesystem;
|
||||
$this->language = $language;
|
||||
$this->php_ini = $php_ini;
|
||||
$this->request = $request;
|
||||
@@ -139,7 +151,7 @@ class remote extends base
|
||||
|
||||
$data = $response->getBody();
|
||||
|
||||
$filename = tempnam(sys_get_temp_dir(), unique_id() . '-');
|
||||
$filename = tempnam($this->filesystem->get_temp_dir(), unique_id() . '-');
|
||||
|
||||
if (!($fp = @fopen($filename, 'wb')))
|
||||
{
|
||||
|
@@ -17,6 +17,7 @@ use bantu\IniGetWrapper\IniGetWrapper;
|
||||
use phpbb\config\config;
|
||||
use phpbb\files\factory;
|
||||
use phpbb\files\filespec;
|
||||
use phpbb\filesystem\filesystem;
|
||||
use phpbb\language\language;
|
||||
use phpbb\request\request_interface;
|
||||
|
||||
@@ -28,6 +29,15 @@ class remote_storage extends base
|
||||
/** @var factory Files factory */
|
||||
protected $factory;
|
||||
|
||||
/** @var filesystem Filesystem */
|
||||
protected $filesystem;
|
||||
|
||||
/** @var language */
|
||||
protected $language;
|
||||
|
||||
/** @var IniGetWrapper */
|
||||
protected $php_ini;
|
||||
|
||||
/** @var request_interface */
|
||||
protected $request;
|
||||
|
||||
@@ -39,15 +49,17 @@ class remote_storage extends base
|
||||
*
|
||||
* @param config $config phpBB config
|
||||
* @param factory $factory Files factory
|
||||
* @param filesystem $filesystem Filesystem
|
||||
* @param language $language Language class
|
||||
* @param IniGetWrapper $php_ini ini_get() wrapper
|
||||
* @param request_interface $request Request object
|
||||
* @param string $phpbb_root_path phpBB root path
|
||||
*/
|
||||
public function __construct(config $config, factory $factory, language $language, IniGetWrapper $php_ini, request_interface $request, $phpbb_root_path)
|
||||
public function __construct(config $config, factory $factory, filesystem $filesystem, language $language, IniGetWrapper $php_ini, request_interface $request, $phpbb_root_path)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->factory = $factory;
|
||||
$this->filesystem = $filesystem;
|
||||
$this->language = $language;
|
||||
$this->php_ini = $php_ini;
|
||||
$this->request = $request;
|
||||
@@ -138,7 +150,7 @@ class remote_storage extends base
|
||||
|
||||
$data = $response->getBody();
|
||||
|
||||
$filename = tempnam(sys_get_temp_dir(), unique_id() . '-');
|
||||
$filename = tempnam($this->filesystem->get_temp_dir(), unique_id() . '-');
|
||||
|
||||
if (!($fp = @fopen($filename, 'wb')))
|
||||
{
|
||||
|
@@ -42,14 +42,25 @@ class filesystem implements filesystem_interface
|
||||
*/
|
||||
protected $symfony_filesystem;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $cache_temp_dir;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $temp_dir;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct($cache_temp_dir)
|
||||
{
|
||||
$this->chmod_info = array();
|
||||
$this->symfony_filesystem = new \Symfony\Component\Filesystem\Filesystem();
|
||||
$this->working_directory = null;
|
||||
$this->cache_temp_dir = $cache_temp_dir;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -742,4 +753,33 @@ class filesystem implements filesystem_interface
|
||||
{
|
||||
return helper::resolve_path($path, $prefix, $absolute, $return_array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a temporary directory to write files
|
||||
*
|
||||
* @return string returns the directory
|
||||
*/
|
||||
public function get_temp_dir()
|
||||
{
|
||||
if (!isset($this->temp_dir))
|
||||
{
|
||||
$tmp_dir = (function_exists('sys_get_temp_dir')) ? sys_get_temp_dir() : '';
|
||||
|
||||
// Prevent trying to write to system temp dir in case of open_basedir
|
||||
// restrictions being in effect
|
||||
if (empty($tmp_dir) || !@file_exists($tmp_dir) || !@is_writable($tmp_dir))
|
||||
{
|
||||
$tmp_dir = $this->cache_temp_dir;
|
||||
|
||||
if (!is_dir($tmp_dir))
|
||||
{
|
||||
$this->filesystem->mkdir($tmp_dir, 0777);
|
||||
}
|
||||
}
|
||||
|
||||
$this->temp_dir = helper::realpath($tmp_dir);
|
||||
}
|
||||
|
||||
return $this->temp_dir;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user