mirror of
https://github.com/phpbb/phpbb.git
synced 2025-03-25 01:51:21 +01:00
[ticket/15286] Update use storage in avatars
PHPBB3-15286
This commit is contained in:
parent
e564ca6e60
commit
ef43dbdcca
@ -6,9 +6,8 @@ services:
|
||||
- '@config'
|
||||
- '@dbal.conn'
|
||||
- '@dispatcher'
|
||||
- '@filesystem'
|
||||
- '@attachment.resync'
|
||||
- '%core.root_path%'
|
||||
- '@storage.attachment'
|
||||
|
||||
attachment.manager:
|
||||
class: phpbb\attachment\manager
|
||||
@ -38,4 +37,3 @@ services:
|
||||
- '@plupload'
|
||||
- '@storage.attachment'
|
||||
- '@user'
|
||||
- '%core.root_path%'
|
||||
|
@ -309,6 +309,7 @@ else
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Determine the 'presenting'-method
|
||||
if ($download_mode == PHYSICAL_LINK)
|
||||
{
|
||||
|
@ -4438,7 +4438,6 @@ function page_header($page_title = '', $display_online_list = false, $item_id =
|
||||
'T_AVATAR_GALLERY_PATH' => "{$web_path}{$config['avatar_gallery_path']}/",
|
||||
'T_ICONS_PATH' => "{$web_path}{$config['icons_path']}/",
|
||||
'T_RANKS_PATH' => "{$web_path}{$config['ranks_path']}/",
|
||||
'T_UPLOAD_PATH' => "{$web_path}{$config['upload_path']}/",
|
||||
'T_STYLESHEET_LINK' => "{$web_path}styles/" . rawurlencode($user->style['style_path']) . '/theme/stylesheet.css?assets_version=' . $config['assets_version'],
|
||||
'T_STYLESHEET_LANG_LINK'=> "{$web_path}styles/" . rawurlencode($user->style['style_path']) . '/theme/' . $user->lang_name . '/stylesheet.css?assets_version=' . $config['assets_version'],
|
||||
'T_FONT_AWESOME_LINK' => !empty($config['allow_cdn']) && !empty($config['load_font_awesome_url']) ? $config['load_font_awesome_url'] : "{$web_path}assets/css/font-awesome.min.css?assets_version=" . $config['assets_version'],
|
||||
@ -4455,7 +4454,6 @@ function page_header($page_title = '', $display_online_list = false, $item_id =
|
||||
'T_AVATAR_GALLERY' => $config['avatar_gallery_path'],
|
||||
'T_ICONS' => $config['icons_path'],
|
||||
'T_RANKS' => $config['ranks_path'],
|
||||
'T_UPLOAD' => $config['upload_path'],
|
||||
|
||||
'SITE_LOGO_IMG' => $user->img('site_logo'),
|
||||
));
|
||||
|
@ -91,7 +91,6 @@ function adm_page_header($page_title)
|
||||
'T_AVATAR_GALLERY_PATH' => "{$phpbb_root_path}{$config['avatar_gallery_path']}/",
|
||||
'T_ICONS_PATH' => "{$phpbb_root_path}{$config['icons_path']}/",
|
||||
'T_RANKS_PATH' => "{$phpbb_root_path}{$config['ranks_path']}/",
|
||||
'T_UPLOAD_PATH' => "{$phpbb_root_path}{$config['upload_path']}/",
|
||||
'T_FONT_AWESOME_LINK' => !empty($config['allow_cdn']) && !empty($config['load_font_awesome_url']) ? $config['load_font_awesome_url'] : "{$phpbb_root_path}assets/css/font-awesome.min.css?assets_version=" . $config['assets_version'],
|
||||
|
||||
'T_ASSETS_VERSION' => $config['assets_version'],
|
||||
|
@ -1163,7 +1163,7 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count_a
|
||||
|
||||
// Some basics...
|
||||
$attachment['extension'] = strtolower(trim($attachment['extension']));
|
||||
$filename = $phpbb_root_path . $config['upload_path'] . '/' . utf8_basename($attachment['physical_filename']);
|
||||
$filename = utf8_basename($attachment['physical_filename']);
|
||||
|
||||
$upload_icon = '';
|
||||
|
||||
@ -1219,6 +1219,7 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count_a
|
||||
{
|
||||
if ($config['img_link_width'] || $config['img_link_height'])
|
||||
{
|
||||
//
|
||||
$dimension = @getimagesize($filename);
|
||||
|
||||
// If the dimensions could not be determined or the image being 0x0 we display it as a link for safety purposes
|
||||
@ -1283,6 +1284,7 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count_a
|
||||
|
||||
// Macromedia Flash Files
|
||||
case ATTACHMENT_CATEGORY_FLASH:
|
||||
//
|
||||
list($width, $height) = @getimagesize($filename);
|
||||
|
||||
$block_array += array(
|
||||
|
@ -496,7 +496,7 @@ function import_attachment_files($category_name = '')
|
||||
|
||||
$sql = 'SELECT config_value AS upload_path
|
||||
FROM ' . CONFIG_TABLE . "
|
||||
WHERE config_name = 'upload_path'";
|
||||
WHERE config_name = 'storage\\attachment\\config\\path'";
|
||||
$result = $db->sql_query($sql);
|
||||
$config['upload_path'] = $db->sql_fetchfield('upload_path');
|
||||
$db->sql_freeresult($result);
|
||||
|
@ -1442,6 +1442,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll_ary, &$data
|
||||
{
|
||||
global $db, $auth, $user, $config, $phpEx, $phpbb_root_path, $phpbb_container, $phpbb_dispatcher, $phpbb_log, $request;
|
||||
|
||||
$attachment_storage = $phpbb_container->get('storage.avatar');
|
||||
|
||||
$poll = $poll_ary;
|
||||
$data = $data_ary;
|
||||
/**
|
||||
@ -2030,7 +2032,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll_ary, &$data
|
||||
else
|
||||
{
|
||||
// insert attachment into db
|
||||
if (!@file_exists($phpbb_root_path . $config['upload_path'] . '/' . utf8_basename($orphan_rows[$attach_row['attach_id']]['physical_filename'])))
|
||||
if (!$attachment_storage->exists(utf8_basename($orphan_rows[$attach_row['attach_id']]['physical_filename'])))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -1614,6 +1614,8 @@ function submit_pm($mode, $subject, &$data_ary, $put_in_outbox = true)
|
||||
{
|
||||
global $db, $auth, $config, $user, $phpbb_root_path, $phpbb_container, $phpbb_dispatcher, $request;
|
||||
|
||||
$attachment_storage = $phpbb_container->get('storage.attachment');
|
||||
|
||||
// We do not handle erasing pms here
|
||||
if ($mode == 'delete')
|
||||
{
|
||||
@ -1881,7 +1883,7 @@ function submit_pm($mode, $subject, &$data_ary, $put_in_outbox = true)
|
||||
else
|
||||
{
|
||||
// insert attachment into db
|
||||
if (!@file_exists($phpbb_root_path . $config['upload_path'] . '/' . utf8_basename($orphan_rows[$attach_row['attach_id']]['physical_filename'])))
|
||||
if (!$attachment_storage->exists(utf8_basename($orphan_rows[$attach_row['attach_id']]['physical_filename'])))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ namespace phpbb\attachment;
|
||||
use \phpbb\config\config;
|
||||
use \phpbb\db\driver\driver_interface;
|
||||
use \phpbb\event\dispatcher;
|
||||
use \phpbb\filesystem\filesystem;
|
||||
use \phpbb\storage\storage;
|
||||
|
||||
/**
|
||||
* Attachment delete class
|
||||
@ -32,14 +32,11 @@ class delete
|
||||
/** @var dispatcher */
|
||||
protected $dispatcher;
|
||||
|
||||
/** @var filesystem */
|
||||
protected $filesystem;
|
||||
|
||||
/** @var resync */
|
||||
protected $resync;
|
||||
|
||||
/** @var string phpBB root path */
|
||||
protected $phpbb_root_path;
|
||||
/** @var storage */
|
||||
protected $storage;
|
||||
|
||||
/** @var array Attachement IDs */
|
||||
protected $ids;
|
||||
@ -71,18 +68,15 @@ class delete
|
||||
* @param config $config
|
||||
* @param driver_interface $db
|
||||
* @param dispatcher $dispatcher
|
||||
* @param filesystem $filesystem
|
||||
* @param resync $resync
|
||||
* @param string $phpbb_root_path
|
||||
* @param storage $storage
|
||||
*/
|
||||
public function __construct(config $config, driver_interface $db, dispatcher $dispatcher, filesystem $filesystem, resync $resync, $phpbb_root_path)
|
||||
public function __construct(config $config, driver_interface $db, dispatcher $dispatcher, resync $resync, $storage)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->db = $db;
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->filesystem = $filesystem;
|
||||
$this->resync = $resync;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->storage = $storage;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -161,8 +155,8 @@ class delete
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Delete attachments from filesystem
|
||||
$this->remove_from_filesystem();
|
||||
// Delete attachments from storage
|
||||
$this->remove_from_storage();
|
||||
|
||||
// If we do not resync, we do not need to adjust any message, post, topic or user entries
|
||||
if (!$resync)
|
||||
@ -327,9 +321,9 @@ class delete
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete attachments from filesystem
|
||||
* Delete attachments from storage
|
||||
*/
|
||||
protected function remove_from_filesystem()
|
||||
protected function remove_from_storage()
|
||||
{
|
||||
$space_removed = $files_removed = 0;
|
||||
|
||||
@ -388,7 +382,7 @@ class delete
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete attachment from filesystem
|
||||
* Delete attachment from storage
|
||||
*
|
||||
* @param string $filename Filename of attachment
|
||||
* @param string $mode Delete mode
|
||||
@ -412,17 +406,16 @@ class delete
|
||||
}
|
||||
|
||||
$filename = ($mode == 'thumbnail') ? 'thumb_' . utf8_basename($filename) : utf8_basename($filename);
|
||||
$filepath = $this->phpbb_root_path . $this->config['upload_path'] . '/' . $filename;
|
||||
|
||||
try
|
||||
{
|
||||
if ($this->filesystem->exists($filepath))
|
||||
if ($this->storage->exists($filename))
|
||||
{
|
||||
$this->filesystem->remove($this->phpbb_root_path . $this->config['upload_path'] . '/' . $filename);
|
||||
$this->storage->remove($filename);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (\phpbb\filesystem\exception\filesystem_exception $exception)
|
||||
catch (\phpbb\storage\exception\exception $exception)
|
||||
{
|
||||
// Fail is covered by return statement below
|
||||
}
|
||||
|
@ -81,9 +81,8 @@ class upload
|
||||
* @param dispatcher $phpbb_dispatcher
|
||||
* @param plupload $plupload
|
||||
* @param user $user
|
||||
* @param $phpbb_root_path
|
||||
*/
|
||||
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, $phpbb_root_path)
|
||||
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)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
$this->cache = $cache;
|
||||
@ -95,7 +94,6 @@ class upload
|
||||
$this->plupload = $plupload;
|
||||
$this->storage = $storage;
|
||||
$this->user = $user;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -309,26 +307,6 @@ class upload
|
||||
*/
|
||||
protected function check_disk_space()
|
||||
{
|
||||
if ($free_space = @disk_free_space($this->phpbb_root_path . $this->config['upload_path']))
|
||||
{
|
||||
if ($free_space <= $this->file->get('filesize'))
|
||||
{
|
||||
if ($this->auth->acl_get('a_'))
|
||||
{
|
||||
$this->file_data['error'][] = $this->language->lang('ATTACH_DISK_FULL');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->file_data['error'][] = $this->language->lang('ATTACH_QUOTA_REACHED');
|
||||
}
|
||||
$this->file_data['post_attach'] = false;
|
||||
|
||||
$this->file->remove();
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -30,8 +30,6 @@ class phpbb_attachment_delete_test extends \phpbb_database_test_case
|
||||
/** @var \phpbb\attachment\delete */
|
||||
protected $attachment_delete;
|
||||
|
||||
protected $phpbb_root_path;
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/resync.xml');
|
||||
@ -54,9 +52,17 @@ class phpbb_attachment_delete_test extends \phpbb_database_test_case
|
||||
$this->filesystem->expects($this->any())
|
||||
->method('exists')
|
||||
->willReturn(true);
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$local_adapter = new \phpbb\storage\adapter\local($this->filesystem, $phpbb_root_path);
|
||||
$local_adapter->configure(['path' => 'files']);
|
||||
$adapter_factory_mock = $this->getMockBuilder('\phpbb\storage\adapter_factory')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$adapter_factory_mock->expects($this->any())
|
||||
->method('get')
|
||||
->willReturn($local_adapter);
|
||||
$this->storage = new \phpbb\storage\storage($adapter_factory_mock, 'attachment');
|
||||
$this->dispatcher = new \phpbb_mock_event_dispatcher();
|
||||
$this->attachment_delete = new \phpbb\attachment\delete($this->config, $this->db, $this->dispatcher, $this->filesystem, $this->resync, $phpbb_root_path);
|
||||
$this->attachment_delete = new \phpbb\attachment\delete($this->config, $this->db, $this->dispatcher, $this->resync, $this->storage);
|
||||
}
|
||||
|
||||
public function data_attachment_delete()
|
||||
@ -121,7 +127,7 @@ class phpbb_attachment_delete_test extends \phpbb_database_test_case
|
||||
->method('exists')
|
||||
->willReturn($exists_success);
|
||||
|
||||
$this->attachment_delete = new \phpbb\attachment\delete($this->config, $this->db, $this->dispatcher, $this->filesystem, $this->resync, $this->phpbb_root_path);
|
||||
$this->attachment_delete = new \phpbb\attachment\delete($this->config, $this->db, $this->dispatcher, $this->resync, $this->storage);
|
||||
$this->assertSame($expected, $this->attachment_delete->unlink_attachment('foobar'));
|
||||
}
|
||||
}
|
||||
|
@ -157,8 +157,7 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case
|
||||
$this->phpbb_dispatcher,
|
||||
$this->plupload,
|
||||
$this->storage,
|
||||
$this->user,
|
||||
$this->phpbb_root_path
|
||||
$this->user
|
||||
);
|
||||
}
|
||||
|
||||
@ -250,8 +249,7 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case
|
||||
$this->phpbb_dispatcher,
|
||||
$this->plupload,
|
||||
$this->storage,
|
||||
$this->user,
|
||||
$this->phpbb_root_path
|
||||
$this->user
|
||||
);
|
||||
|
||||
$filedata = $this->upload->upload('foobar', 1, true);
|
||||
@ -415,8 +413,7 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case
|
||||
$this->phpbb_dispatcher,
|
||||
$plupload,
|
||||
$this->storage,
|
||||
$this->user,
|
||||
$this->phpbb_root_path
|
||||
$this->user
|
||||
);
|
||||
|
||||
$filedata = $this->upload->upload('foobar', 1, true, '', false, array(
|
||||
|
Loading…
x
Reference in New Issue
Block a user