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

Merge pull request #4916 from rubencm/ticket/15311

[ticket/15311] Use storage in backups
This commit is contained in:
Marc Alexander
2018-06-07 22:18:03 +02:00
19 changed files with 346 additions and 90 deletions

View File

@@ -21,6 +21,7 @@ use \phpbb\language\language;
use \phpbb\mimetype\guesser;
use \phpbb\plupload\plupload;
use \phpbb\storage\storage;
use \phpbb\filesystem\temp;
use \phpbb\user;
/**
@@ -55,6 +56,9 @@ class upload
/** @var storage */
protected $storage;
/** @var temp */
protected $temp;
/** @var user */
protected $user;
@@ -80,9 +84,10 @@ class upload
* @param guesser $mimetype_guesser
* @param dispatcher $phpbb_dispatcher
* @param plupload $plupload
* @param temp $temp
* @param user $user
*/
public function __construct(auth $auth, service $cache, config $config, \phpbb\files\upload $files_upload, language $language, guesser $mimetype_guesser, dispatcher $phpbb_dispatcher, plupload $plupload, storage $storage, user $user)
public function __construct(auth $auth, service $cache, config $config, \phpbb\files\upload $files_upload, language $language, guesser $mimetype_guesser, dispatcher $phpbb_dispatcher, plupload $plupload, storage $storage, temp $temp, user $user)
{
$this->auth = $auth;
$this->cache = $cache;
@@ -93,6 +98,7 @@ class upload
$this->phpbb_dispatcher = $phpbb_dispatcher;
$this->plupload = $plupload;
$this->storage = $storage;
$this->temp = $temp;
$this->user = $user;
}
@@ -234,7 +240,7 @@ class upload
{
$source = $this->file->get('filename');
$destination_name = 'thumb_' . $this->file->get('realname');
$destination = sys_get_temp_dir() . '/' . $destination_name;
$destination = $this->temp->get_dir() . '/' . $destination_name;
if (create_thumbnail($source, $destination, $this->file->get('mimetype')))
{

View File

@@ -22,9 +22,9 @@ use phpbb\db\extractor\exception\extractor_not_initialized_exception;
abstract class base_extractor implements extractor_interface
{
/**
* @var string phpBB root path
* @var \phpbb\filesystem\temp
*/
protected $phpbb_root_path;
protected $temp;
/**
* @var \phpbb\request\request_interface
@@ -84,13 +84,13 @@ abstract class base_extractor implements extractor_interface
/**
* Constructor
*
* @param string $phpbb_root_path
* @param \phpbb\filesystem\temp $temp
* @param \phpbb\request\request_interface $request
* @param \phpbb\db\driver\driver_interface $db
*/
public function __construct($phpbb_root_path, \phpbb\request\request_interface $request, \phpbb\db\driver\driver_interface $db)
public function __construct(\phpbb\filesystem\temp $temp, \phpbb\request\request_interface $request, \phpbb\db\driver\driver_interface $db)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->temp = $temp;
$this->request = $request;
$this->db = $db;
$this->fp = null;
@@ -164,13 +164,13 @@ abstract class base_extractor implements extractor_interface
if ($store === true)
{
$file = $this->phpbb_root_path . 'store/' . $filename . $ext;
$file = $this->temp->get_dir() . '/' . $filename . $ext;
$this->fp = $open($file, 'w');
if (!$this->fp)
{
trigger_error('FILE_WRITE_FAIL', E_USER_ERROR);
throw new \phpbb\exception\runtime_exception('FILE_WRITE_FAIL');
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\db\migration\data\v330;
class storage_backup extends \phpbb\db\migration\migration
{
public function update_schema()
{
return array(
'add_tables' => array(
$this->table_prefix . 'backups' => array(
'COLUMNS' => array(
'backup_id' => array('UINT', null, 'auto_increment'),
'filename' => array('VCHAR', ''),
),
'PRIMARY_KEY' => 'backup_id',
),
),
);
}
public function update_data()
{
return array(
array('config.add', array('storage\\backup\\provider', \phpbb\storage\provider\local::class)),
array('config.add', array('storage\\backup\\config\\path', 'store')),
);
}
}

View File

@@ -17,6 +17,7 @@ use bantu\IniGetWrapper\IniGetWrapper;
use phpbb\config\config;
use phpbb\files\factory;
use phpbb\files\filespec;
use phpbb\filesystem\temp;
use phpbb\language\language;
use phpbb\request\request_interface;
@@ -28,30 +29,36 @@ class remote extends base
/** @var factory Files factory */
protected $factory;
/** @var filesystem Filesystem temp */
protected $temp;
/** @var language */
protected $language;
/** @var IniGetWrapper */
protected $php_ini;
/** @var request_interface */
protected $request;
/** @var string phpBB root path */
protected $phpbb_root_path;
/**
* Construct a form upload type
*
* @param config $config phpBB config
* @param factory $factory Files factory
* @param temp $temp Filesystem temp
* @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, temp $temp, language $language, IniGetWrapper $php_ini, request_interface $request)
{
$this->config = $config;
$this->factory = $factory;
$this->temp = $temp;
$this->language = $language;
$this->php_ini = $php_ini;
$this->request = $request;
$this->phpbb_root_path = $phpbb_root_path;
}
/**
@@ -139,7 +146,7 @@ class remote extends base
$data = $response->getBody();
$filename = tempnam(sys_get_temp_dir(), unique_id() . '-');
$filename = tempnam($this->temp->get_dir(), unique_id() . '-');
if (!($fp = @fopen($filename, 'wb')))
{

View File

@@ -17,6 +17,7 @@ use bantu\IniGetWrapper\IniGetWrapper;
use phpbb\config\config;
use phpbb\files\factory;
use phpbb\files\filespec;
use phpbb\filesystem\temp;
use phpbb\language\language;
use phpbb\request\request_interface;
@@ -28,30 +29,36 @@ class remote_storage extends base
/** @var factory Files factory */
protected $factory;
/** @var temp Filesystem temp */
protected $temp;
/** @var language */
protected $language;
/** @var IniGetWrapper */
protected $php_ini;
/** @var request_interface */
protected $request;
/** @var string phpBB root path */
protected $phpbb_root_path;
/**
* Construct a form upload type
*
* @param config $config phpBB config
* @param factory $factory Files factory
* @param temp $temp Filesystem temp
* @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, temp $temp, language $language, IniGetWrapper $php_ini, request_interface $request)
{
$this->config = $config;
$this->factory = $factory;
$this->temp = $temp;
$this->language = $language;
$this->php_ini = $php_ini;
$this->request = $request;
$this->phpbb_root_path = $phpbb_root_path;
}
/**
@@ -138,7 +145,7 @@ class remote_storage extends base
$data = $response->getBody();
$filename = tempnam(sys_get_temp_dir(), unique_id() . '-');
$filename = tempnam($this->temp->get_dir(), unique_id() . '-');
if (!($fp = @fopen($filename, 'wb')))
{

View File

@@ -0,0 +1,54 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\filesystem;
class temp
{
/**
* @var string Temporary directory path
*/
protected $temp_dir;
/**
* Constructor
*/
public function __construct($filesystem, $cache_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 = $cache_temp_dir;
if (!is_dir($tmp_dir))
{
$filesystem->mkdir($tmp_dir, 0777);
}
}
$this->temp_dir = helper::realpath($tmp_dir);
}
/**
* Get a temporary directory to write files
*
* @return string returns the directory
*/
public function get_dir()
{
return $this->temp_dir;
}
}