Skip to content

Commit ef43dbd

Browse files
committed
[ticket/15286] Update use storage in avatars
PHPBB3-15286
1 parent e564ca6 commit ef43dbd

12 files changed

Lines changed: 41 additions & 65 deletions

File tree

phpBB/config/default/container/services_attachment.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ services:
66
- '@config'
77
- '@dbal.conn'
88
- '@dispatcher'
9-
- '@filesystem'
109
- '@attachment.resync'
11-
- '%core.root_path%'
10+
- '@storage.attachment'
1211

1312
attachment.manager:
1413
class: phpbb\attachment\manager
@@ -38,4 +37,3 @@ services:
3837
- '@plupload'
3938
- '@storage.attachment'
4039
- '@user'
41-
- '%core.root_path%'

phpBB/download/file.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@
309309
}
310310
else
311311
{
312+
//
312313
// Determine the 'presenting'-method
313314
if ($download_mode == PHYSICAL_LINK)
314315
{

phpBB/includes/functions.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4438,7 +4438,6 @@ function page_header($page_title = '', $display_online_list = false, $item_id =
44384438
'T_AVATAR_GALLERY_PATH' => "{$web_path}{$config['avatar_gallery_path']}/",
44394439
'T_ICONS_PATH' => "{$web_path}{$config['icons_path']}/",
44404440
'T_RANKS_PATH' => "{$web_path}{$config['ranks_path']}/",
4441-
'T_UPLOAD_PATH' => "{$web_path}{$config['upload_path']}/",
44424441
'T_STYLESHEET_LINK' => "{$web_path}styles/" . rawurlencode($user->style['style_path']) . '/theme/stylesheet.css?assets_version=' . $config['assets_version'],
44434442
'T_STYLESHEET_LANG_LINK'=> "{$web_path}styles/" . rawurlencode($user->style['style_path']) . '/theme/' . $user->lang_name . '/stylesheet.css?assets_version=' . $config['assets_version'],
44444443
'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 =
44554454
'T_AVATAR_GALLERY' => $config['avatar_gallery_path'],
44564455
'T_ICONS' => $config['icons_path'],
44574456
'T_RANKS' => $config['ranks_path'],
4458-
'T_UPLOAD' => $config['upload_path'],
44594457

44604458
'SITE_LOGO_IMG' => $user->img('site_logo'),
44614459
));

phpBB/includes/functions_acp.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ function adm_page_header($page_title)
9191
'T_AVATAR_GALLERY_PATH' => "{$phpbb_root_path}{$config['avatar_gallery_path']}/",
9292
'T_ICONS_PATH' => "{$phpbb_root_path}{$config['icons_path']}/",
9393
'T_RANKS_PATH' => "{$phpbb_root_path}{$config['ranks_path']}/",
94-
'T_UPLOAD_PATH' => "{$phpbb_root_path}{$config['upload_path']}/",
9594
'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'],
9695

9796
'T_ASSETS_VERSION' => $config['assets_version'],

phpBB/includes/functions_content.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count_a
11631163

11641164
// Some basics...
11651165
$attachment['extension'] = strtolower(trim($attachment['extension']));
1166-
$filename = $phpbb_root_path . $config['upload_path'] . '/' . utf8_basename($attachment['physical_filename']);
1166+
$filename = utf8_basename($attachment['physical_filename']);
11671167

11681168
$upload_icon = '';
11691169

@@ -1219,6 +1219,7 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count_a
12191219
{
12201220
if ($config['img_link_width'] || $config['img_link_height'])
12211221
{
1222+
//
12221223
$dimension = @getimagesize($filename);
12231224

12241225
// 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
12831284

12841285
// Macromedia Flash Files
12851286
case ATTACHMENT_CATEGORY_FLASH:
1287+
//
12861288
list($width, $height) = @getimagesize($filename);
12871289

12881290
$block_array += array(

phpBB/includes/functions_convert.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ function import_attachment_files($category_name = '')
496496

497497
$sql = 'SELECT config_value AS upload_path
498498
FROM ' . CONFIG_TABLE . "
499-
WHERE config_name = 'upload_path'";
499+
WHERE config_name = 'storage\\attachment\\config\\path'";
500500
$result = $db->sql_query($sql);
501501
$config['upload_path'] = $db->sql_fetchfield('upload_path');
502502
$db->sql_freeresult($result);

phpBB/includes/functions_posting.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll_ary, &$data
14421442
{
14431443
global $db, $auth, $user, $config, $phpEx, $phpbb_root_path, $phpbb_container, $phpbb_dispatcher, $phpbb_log, $request;
14441444

1445+
$attachment_storage = $phpbb_container->get('storage.avatar');
1446+
14451447
$poll = $poll_ary;
14461448
$data = $data_ary;
14471449
/**
@@ -2030,7 +2032,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll_ary, &$data
20302032
else
20312033
{
20322034
// insert attachment into db
2033-
if (!@file_exists($phpbb_root_path . $config['upload_path'] . '/' . utf8_basename($orphan_rows[$attach_row['attach_id']]['physical_filename'])))
2035+
if (!$attachment_storage->exists(utf8_basename($orphan_rows[$attach_row['attach_id']]['physical_filename'])))
20342036
{
20352037
continue;
20362038
}

phpBB/includes/functions_privmsgs.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,8 @@ function submit_pm($mode, $subject, &$data_ary, $put_in_outbox = true)
16141614
{
16151615
global $db, $auth, $config, $user, $phpbb_root_path, $phpbb_container, $phpbb_dispatcher, $request;
16161616

1617+
$attachment_storage = $phpbb_container->get('storage.attachment');
1618+
16171619
// We do not handle erasing pms here
16181620
if ($mode == 'delete')
16191621
{
@@ -1881,7 +1883,7 @@ function submit_pm($mode, $subject, &$data_ary, $put_in_outbox = true)
18811883
else
18821884
{
18831885
// insert attachment into db
1884-
if (!@file_exists($phpbb_root_path . $config['upload_path'] . '/' . utf8_basename($orphan_rows[$attach_row['attach_id']]['physical_filename'])))
1886+
if (!$attachment_storage->exists(utf8_basename($orphan_rows[$attach_row['attach_id']]['physical_filename'])))
18851887
{
18861888
continue;
18871889
}

phpBB/phpbb/attachment/delete.php

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use \phpbb\config\config;
1717
use \phpbb\db\driver\driver_interface;
1818
use \phpbb\event\dispatcher;
19-
use \phpbb\filesystem\filesystem;
19+
use \phpbb\storage\storage;
2020

2121
/**
2222
* Attachment delete class
@@ -32,14 +32,11 @@ class delete
3232
/** @var dispatcher */
3333
protected $dispatcher;
3434

35-
/** @var filesystem */
36-
protected $filesystem;
37-
3835
/** @var resync */
3936
protected $resync;
4037

41-
/** @var string phpBB root path */
42-
protected $phpbb_root_path;
38+
/** @var storage */
39+
protected $storage;
4340

4441
/** @var array Attachement IDs */
4542
protected $ids;
@@ -71,18 +68,15 @@ class delete
7168
* @param config $config
7269
* @param driver_interface $db
7370
* @param dispatcher $dispatcher
74-
* @param filesystem $filesystem
7571
* @param resync $resync
76-
* @param string $phpbb_root_path
72+
* @param storage $storage
7773
*/
78-
public function __construct(config $config, driver_interface $db, dispatcher $dispatcher, filesystem $filesystem, resync $resync, $phpbb_root_path)
74+
public function __construct(config $config, driver_interface $db, dispatcher $dispatcher, resync $resync, $storage)
7975
{
8076
$this->config = $config;
8177
$this->db = $db;
8278
$this->dispatcher = $dispatcher;
83-
$this->filesystem = $filesystem;
84-
$this->resync = $resync;
85-
$this->phpbb_root_path = $phpbb_root_path;
79+
$this->storage = $storage;
8680
}
8781

8882
/**
@@ -161,8 +155,8 @@ public function delete($mode, $ids, $resync = true)
161155
return 0;
162156
}
163157

164-
// Delete attachments from filesystem
165-
$this->remove_from_filesystem();
158+
// Delete attachments from storage
159+
$this->remove_from_storage();
166160

167161
// If we do not resync, we do not need to adjust any message, post, topic or user entries
168162
if (!$resync)
@@ -327,9 +321,9 @@ protected function delete_attachments_from_db()
327321
}
328322

329323
/**
330-
* Delete attachments from filesystem
324+
* Delete attachments from storage
331325
*/
332-
protected function remove_from_filesystem()
326+
protected function remove_from_storage()
333327
{
334328
$space_removed = $files_removed = 0;
335329

@@ -388,7 +382,7 @@ protected function remove_from_filesystem()
388382
}
389383

390384
/**
391-
* Delete attachment from filesystem
385+
* Delete attachment from storage
392386
*
393387
* @param string $filename Filename of attachment
394388
* @param string $mode Delete mode
@@ -412,17 +406,16 @@ public function unlink_attachment($filename, $mode = 'file', $entry_removed = fa
412406
}
413407

414408
$filename = ($mode == 'thumbnail') ? 'thumb_' . utf8_basename($filename) : utf8_basename($filename);
415-
$filepath = $this->phpbb_root_path . $this->config['upload_path'] . '/' . $filename;
416409

417410
try
418411
{
419-
if ($this->filesystem->exists($filepath))
412+
if ($this->storage->exists($filename))
420413
{
421-
$this->filesystem->remove($this->phpbb_root_path . $this->config['upload_path'] . '/' . $filename);
414+
$this->storage->remove($filename);
422415
return true;
423416
}
424417
}
425-
catch (\phpbb\filesystem\exception\filesystem_exception $exception)
418+
catch (\phpbb\storage\exception\exception $exception)
426419
{
427420
// Fail is covered by return statement below
428421
}

phpBB/phpbb/attachment/upload.php

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,8 @@ class upload
8181
* @param dispatcher $phpbb_dispatcher
8282
* @param plupload $plupload
8383
* @param user $user
84-
* @param $phpbb_root_path
8584
*/
86-
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)
85+
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)
8786
{
8887
$this->auth = $auth;
8988
$this->cache = $cache;
@@ -95,7 +94,6 @@ public function __construct(auth $auth, service $cache, config $config, \phpbb\f
9594
$this->plupload = $plupload;
9695
$this->storage = $storage;
9796
$this->user = $user;
98-
$this->phpbb_root_path = $phpbb_root_path;
9997
}
10098

10199
/**
@@ -309,26 +307,6 @@ protected function check_attach_quota()
309307
*/
310308
protected function check_disk_space()
311309
{
312-
if ($free_space = @disk_free_space($this->phpbb_root_path . $this->config['upload_path']))
313-
{
314-
if ($free_space <= $this->file->get('filesize'))
315-
{
316-
if ($this->auth->acl_get('a_'))
317-
{
318-
$this->file_data['error'][] = $this->language->lang('ATTACH_DISK_FULL');
319-
}
320-
else
321-
{
322-
$this->file_data['error'][] = $this->language->lang('ATTACH_QUOTA_REACHED');
323-
}
324-
$this->file_data['post_attach'] = false;
325-
326-
$this->file->remove();
327-
328-
return false;
329-
}
330-
}
331-
332310
return true;
333311
}
334312

0 commit comments

Comments
 (0)