mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
Merge pull request #6664 from rubencm/ticket/17357
[ticket/17357] Remove file_info from storage
This commit is contained in:
commit
96df4d1284
17 changed files with 123 additions and 287 deletions
|
@ -70,8 +70,6 @@ services:
|
|||
shared: false
|
||||
arguments:
|
||||
- '@filesystem'
|
||||
- '@upload_imagesize'
|
||||
- '@mimetype.guesser'
|
||||
- '%core.root_path%'
|
||||
tags:
|
||||
- { name: storage.adapter }
|
||||
|
@ -90,6 +88,7 @@ services:
|
|||
- '@cache'
|
||||
- '@config'
|
||||
- '@dbal.conn'
|
||||
- '@mimetype.extension_guesser'
|
||||
- '@storage.avatar'
|
||||
- '@symfony_request'
|
||||
|
||||
|
@ -102,6 +101,7 @@ services:
|
|||
- '@content.visibility'
|
||||
- '@dbal.conn'
|
||||
- '@event_dispatcher'
|
||||
- '@mimetype.extension_guesser'
|
||||
- '@language'
|
||||
- '@request'
|
||||
- '@storage.attachment'
|
||||
|
|
|
@ -173,8 +173,6 @@ class acp_attachments
|
|||
|
||||
'img_max_width' => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
|
||||
'img_max_height' => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
|
||||
'img_link_width' => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
|
||||
'img_link_height' => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int:0', 'type' => false, 'method' => false, 'explain' => false,),
|
||||
|
||||
'allow_attachments' => array('lang' => 'ALLOW_ATTACHMENTS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
|
||||
'allow_pm_attach' => array('lang' => 'ALLOW_PM_ATTACHMENTS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
|
||||
|
@ -197,7 +195,6 @@ class acp_attachments
|
|||
'img_max' => array('lang' => 'MAX_IMAGE_SIZE', 'validate' => 'int:0:9999', 'type' => 'dimension:0:9999', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
|
||||
'img_strip_metadata' => array('lang' => 'IMAGE_STRIP_METADATA', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
|
||||
'img_quality' => array('lang' => 'IMAGE_QUALITY', 'validate' => 'int:50:90', 'type' => 'number:50:90', 'explain' => true, 'append' => ' %'),
|
||||
'img_link' => array('lang' => 'IMAGE_LINK_SIZE', 'validate' => 'int:0:9999', 'type' => 'dimension:0:9999', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -1234,19 +1234,7 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count_a
|
|||
{
|
||||
if ($config['img_display_inlined'])
|
||||
{
|
||||
if ($config['img_link_width'] || $config['img_link_height'])
|
||||
{
|
||||
try
|
||||
{
|
||||
$file_info = $storage_attachment->file_info($filename);
|
||||
|
||||
$display_cat = ($file_info->image_width <= $config['img_link_width'] && $file_info->image_height <= $config['img_link_height']) ? attachment_category::IMAGE : attachment_category::NONE;
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$display_cat = attachment_category::NONE;
|
||||
}
|
||||
}
|
||||
$display_cat = attachment_category::IMAGE;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -361,8 +361,6 @@ class phpbb_questionnaire_phpbb_data_provider
|
|||
'hot_threshold' => true,
|
||||
'img_create_thumbnail' => true,
|
||||
'img_display_inlined' => true,
|
||||
'img_link_height' => true,
|
||||
'img_link_width' => true,
|
||||
'img_max_height' => true,
|
||||
'img_max_thumb_width' => true,
|
||||
'img_max_width' => true,
|
||||
|
|
|
@ -1676,8 +1676,6 @@ function phpbb_import_attach_config()
|
|||
$config->set('img_display_inlined', $attach_config['img_display_inlined']);
|
||||
$config->set('img_max_width', $attach_config['img_max_width']);
|
||||
$config->set('img_max_height', $attach_config['img_max_height']);
|
||||
$config->set('img_link_width', $attach_config['img_link_width']);
|
||||
$config->set('img_link_height', $attach_config['img_link_height']);
|
||||
$config->set('img_create_thumbnail', $attach_config['img_create_thumbnail']);
|
||||
$config->set('img_max_thumb_width', 400);
|
||||
$config->set('img_min_thumb_filesize', $attach_config['img_min_thumb_filesize']);
|
||||
|
|
|
@ -155,8 +155,6 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('hot_threshold', '2
|
|||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('icons_path', 'images/icons');
|
||||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('img_create_thumbnail', '0');
|
||||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('img_display_inlined', '1');
|
||||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('img_link_height', '0');
|
||||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('img_link_width', '0');
|
||||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('img_max_height', '0');
|
||||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('img_max_thumb_width', '400');
|
||||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('img_max_width', '0');
|
||||
|
|
|
@ -111,8 +111,6 @@ $lang = array_merge($lang, array(
|
|||
'GO_TO_EXTENSIONS' => 'Go to extension management screen',
|
||||
'GROUP_NAME' => 'Group name',
|
||||
|
||||
'IMAGE_LINK_SIZE' => 'Image link dimensions',
|
||||
'IMAGE_LINK_SIZE_EXPLAIN' => 'Display image attachment as an inline text link if image is larger than this. To disable this behaviour, set the values to 0px by 0px.',
|
||||
'IMAGE_QUALITY' => 'Quality of uploaded image attachments (JPEG only)',
|
||||
'IMAGE_QUALITY_EXPLAIN' => 'Specify value between 50% (smaller file size) and 90% (higher quality). Quality higher than 90% increases filesize and is disabled. Setting only applies if maximum image dimensions are set to a value other than 0px by 0px.',
|
||||
'IMAGE_STRIP_METADATA' => 'Strip image metadata (JPEG only)',
|
||||
|
|
41
phpBB/phpbb/db/migration/data/v400/remove_img_link.php
Normal file
41
phpBB/phpbb/db/migration/data/v400/remove_img_link.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?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\v400;
|
||||
|
||||
use phpbb\db\migration\migration;
|
||||
|
||||
class remove_img_link extends migration
|
||||
{
|
||||
public function effectively_installed()
|
||||
{
|
||||
return !$this->config->offsetExists('img_link_width')
|
||||
&& !$this->config->offsetExists('img_link_height');
|
||||
}
|
||||
|
||||
public static function depends_on()
|
||||
{
|
||||
return [
|
||||
'\phpbb\db\migration\data\v400\dev'
|
||||
];
|
||||
}
|
||||
|
||||
public function update_data()
|
||||
{
|
||||
return [
|
||||
['config.remove', ['img_link_width']],
|
||||
['config.remove', ['img_link_height']],
|
||||
];
|
||||
}
|
||||
}
|
|
@ -20,7 +20,7 @@ interface adapter_interface
|
|||
/**
|
||||
* Set adapter parameters
|
||||
*
|
||||
* @param array options Storage-specific options.
|
||||
* @param array $options options Storage-specific options.
|
||||
*/
|
||||
public function configure(array $options): void;
|
||||
|
||||
|
@ -82,13 +82,15 @@ interface adapter_interface
|
|||
public function copy(string $path_orig, string $path_dest): void;
|
||||
|
||||
/**
|
||||
* Get direct link
|
||||
* Get file size in bytes
|
||||
*
|
||||
* @param string $path The file
|
||||
*
|
||||
* @return string Returns link.
|
||||
* @return int Size in bytes.
|
||||
*
|
||||
* @throws storage_exception When unable to retrieve file size
|
||||
*/
|
||||
public function get_link(string $path): string;
|
||||
public function file_size(string $path): int;
|
||||
|
||||
/**
|
||||
* Get space available in bytes
|
||||
|
|
|
@ -18,8 +18,6 @@ use phpbb\storage\exception\storage_exception;
|
|||
use phpbb\filesystem\exception\filesystem_exception;
|
||||
use phpbb\filesystem\filesystem;
|
||||
use phpbb\filesystem\helper as filesystem_helper;
|
||||
use phpbb\mimetype\guesser;
|
||||
use FastImageSize\FastImageSize;
|
||||
|
||||
/**
|
||||
* Experimental
|
||||
|
@ -33,20 +31,6 @@ class local implements adapter_interface, stream_interface
|
|||
*/
|
||||
protected $filesystem;
|
||||
|
||||
/**
|
||||
* FastImageSize
|
||||
*
|
||||
* @var FastImageSize
|
||||
*/
|
||||
protected $imagesize;
|
||||
|
||||
/**
|
||||
* Mimetype Guesser component
|
||||
*
|
||||
* @var guesser
|
||||
*/
|
||||
protected $mimetype_guesser;
|
||||
|
||||
/**
|
||||
* @var string path
|
||||
*/
|
||||
|
@ -77,15 +61,11 @@ class local implements adapter_interface, stream_interface
|
|||
* Constructor
|
||||
*
|
||||
* @param filesystem $filesystem
|
||||
* @param FastImageSize $imagesize
|
||||
* @param guesser $mimetype_guesser
|
||||
* @param string $phpbb_root_path
|
||||
*/
|
||||
public function __construct(filesystem $filesystem, FastImageSize $imagesize, guesser $mimetype_guesser, string $phpbb_root_path)
|
||||
public function __construct(filesystem $filesystem, string $phpbb_root_path)
|
||||
{
|
||||
$this->filesystem = $filesystem;
|
||||
$this->imagesize = $imagesize;
|
||||
$this->mimetype_guesser = $mimetype_guesser;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
}
|
||||
|
||||
|
@ -294,15 +274,9 @@ class local implements adapter_interface, stream_interface
|
|||
}
|
||||
|
||||
/**
|
||||
* Get file size
|
||||
*
|
||||
* @param string $path The file
|
||||
*
|
||||
* @return array Properties
|
||||
*
|
||||
* @throws storage_exception When cannot get size
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function file_size(string $path): array
|
||||
public function file_size(string $path): int
|
||||
{
|
||||
$size = @filesize($this->root_path . $this->get_path($path) . $this->get_filename($path));
|
||||
|
||||
|
@ -311,72 +285,7 @@ class local implements adapter_interface, stream_interface
|
|||
throw new storage_exception('STORAGE_CANNOT_GET_FILESIZE');
|
||||
}
|
||||
|
||||
return ['size' => $size];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file mimetype
|
||||
*
|
||||
* @param string $path The file
|
||||
*
|
||||
* @return array Properties
|
||||
*/
|
||||
public function file_mimetype(string $path): array
|
||||
{
|
||||
return ['mimetype' => $this->mimetype_guesser->guess($this->root_path . $this->get_path($path) . $this->get_filename($path))];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get image dimensions
|
||||
*
|
||||
* @param string $path The file
|
||||
*
|
||||
* @return array Properties
|
||||
*/
|
||||
protected function image_dimensions(string $path): array
|
||||
{
|
||||
$size = $this->imagesize->getImageSize($this->root_path . $this->get_path($path) . $this->get_filename($path));
|
||||
|
||||
// For not supported types like swf
|
||||
if ($size === false)
|
||||
{
|
||||
$imsize = getimagesize($this->root_path . $this->get_path($path) . $this->get_filename($path));
|
||||
$size = ['width' => $imsize[0], 'height' => $imsize[1]];
|
||||
}
|
||||
|
||||
return ['image_width' => $size['width'], 'image_height' => $size['height']];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get image width
|
||||
*
|
||||
* @param string $path The file
|
||||
*
|
||||
* @return array Properties
|
||||
*/
|
||||
public function file_image_width(string $path): array
|
||||
{
|
||||
return $this->image_dimensions($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get image height
|
||||
*
|
||||
* @param string $path The file
|
||||
*
|
||||
* @return array Properties
|
||||
*/
|
||||
public function file_image_height(string $path): array
|
||||
{
|
||||
return $this->image_dimensions($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_link(string $path): string
|
||||
{
|
||||
return generate_board_url() . '/' . $this->path . $path;
|
||||
return $size;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,6 +22,7 @@ use phpbb\db\driver\driver_interface;
|
|||
use phpbb\event\dispatcher_interface;
|
||||
use phpbb\exception\http_exception;
|
||||
use phpbb\language\language;
|
||||
use phpbb\mimetype\extension_guesser;
|
||||
use phpbb\request\request;
|
||||
use phpbb\storage\storage;
|
||||
use phpbb\user;
|
||||
|
@ -66,15 +67,16 @@ class attachment extends controller
|
|||
* @param content_visibility $content_visibility
|
||||
* @param driver_interface $db
|
||||
* @param dispatcher_interface $dispatcher
|
||||
* @param extension_guesser $extension_guesser
|
||||
* @param language $language
|
||||
* @param request $request
|
||||
* @param storage $storage
|
||||
* @param symfony_request $symfony_request
|
||||
* @param user $user
|
||||
*/
|
||||
public function __construct(auth $auth, service $cache, config $config, content_visibility $content_visibility, driver_interface $db, dispatcher_interface $dispatcher, language $language, request $request, storage $storage, symfony_request $symfony_request, user $user)
|
||||
public function __construct(auth $auth, service $cache, config $config, content_visibility $content_visibility, driver_interface $db, dispatcher_interface $dispatcher, extension_guesser $extension_guesser, language $language, request $request, storage $storage, symfony_request $symfony_request, user $user)
|
||||
{
|
||||
parent::__construct($cache, $db, $storage, $symfony_request);
|
||||
parent::__construct($cache, $db, $extension_guesser, $storage, $symfony_request);
|
||||
|
||||
$this->auth = $auth;
|
||||
$this->config = $config;
|
||||
|
|
|
@ -16,6 +16,7 @@ namespace phpbb\storage\controller;
|
|||
use phpbb\cache\service;
|
||||
use phpbb\config\config;
|
||||
use phpbb\db\driver\driver_interface;
|
||||
use phpbb\mimetype\extension_guesser;
|
||||
use phpbb\storage\storage;
|
||||
use Symfony\Component\HttpFoundation\Request as symfony_request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
@ -39,12 +40,13 @@ class avatar extends controller
|
|||
* @param service $cache
|
||||
* @param config $config
|
||||
* @param driver_interface $db
|
||||
* @param extension_guesser $extension_guesser
|
||||
* @param storage $storage
|
||||
* @param symfony_request $symfony_request
|
||||
*/
|
||||
public function __construct(service $cache, config $config, driver_interface $db, storage $storage, symfony_request $symfony_request)
|
||||
public function __construct(service $cache, config $config, driver_interface $db, extension_guesser $extension_guesser, storage $storage, symfony_request $symfony_request)
|
||||
{
|
||||
parent::__construct($cache, $db, $storage, $symfony_request);
|
||||
parent::__construct($cache, $db , $extension_guesser, $storage, $symfony_request);
|
||||
|
||||
$this->config = $config;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ namespace phpbb\storage\controller;
|
|||
use phpbb\cache\service;
|
||||
use phpbb\db\driver\driver_interface;
|
||||
use phpbb\exception\http_exception;
|
||||
use phpbb\mimetype\extension_guesser;
|
||||
use phpbb\storage\exception\storage_exception;
|
||||
use phpbb\storage\storage;
|
||||
use Symfony\Component\HttpFoundation\Request as symfony_request;
|
||||
|
@ -33,6 +34,9 @@ class controller
|
|||
/** @var driver_interface */
|
||||
protected $db;
|
||||
|
||||
/** @var extension_guesser */
|
||||
protected $extension_guesser;
|
||||
|
||||
/** @var storage */
|
||||
protected $storage;
|
||||
|
||||
|
@ -47,10 +51,11 @@ class controller
|
|||
* @param storage $storage
|
||||
* @param symfony_request $symfony_request
|
||||
*/
|
||||
public function __construct(service $cache, driver_interface $db, storage $storage, symfony_request $symfony_request)
|
||||
public function __construct(service $cache, driver_interface $db, extension_guesser $extension_guesser, storage $storage, symfony_request $symfony_request)
|
||||
{
|
||||
$this->cache = $cache;
|
||||
$this->db = $db;
|
||||
$this->extension_guesser = $extension_guesser;
|
||||
$this->storage = $storage;
|
||||
$this->symfony_request = $symfony_request;
|
||||
}
|
||||
|
@ -124,14 +129,12 @@ class controller
|
|||
*/
|
||||
protected function prepare(StreamedResponse $response, string $file): void
|
||||
{
|
||||
$file_info = $this->storage->file_info($file);
|
||||
|
||||
// Add Content-Type header
|
||||
if (!$response->headers->has('Content-Type'))
|
||||
{
|
||||
try
|
||||
{
|
||||
$content_type = $file_info->get('mimetype');
|
||||
$content_type = $this->extension_guesser->guess($file);
|
||||
}
|
||||
catch (storage_exception $e)
|
||||
{
|
||||
|
@ -146,7 +149,7 @@ class controller
|
|||
{
|
||||
try
|
||||
{
|
||||
$response->headers->set('Content-Length', $file_info->get('size'));
|
||||
$response->headers->set('Content-Length', $this->storage->file_size($file));
|
||||
}
|
||||
catch (storage_exception $e)
|
||||
{
|
||||
|
|
|
@ -1,85 +0,0 @@
|
|||
<?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\storage;
|
||||
|
||||
use phpbb\storage\exception\storage_exception;
|
||||
use phpbb\storage\adapter\adapter_interface;
|
||||
|
||||
class file_info
|
||||
{
|
||||
/**
|
||||
* @var adapter_interface
|
||||
*/
|
||||
protected $adapter;
|
||||
|
||||
/**
|
||||
* Path of the file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $path;
|
||||
|
||||
/**
|
||||
* Stores the properties of $path file, so dont have to be consulted multiple times.
|
||||
* For example, when you need the width of an image, using getimagesize() you get
|
||||
* both dimensions, so you store both here, and when you get the height, you dont have
|
||||
* to call getimagesize() again
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $properties;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param adapter_interface $adapter
|
||||
* @param string $path
|
||||
*/
|
||||
public function __construct(adapter_interface $adapter, $path)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
$this->path = $path;
|
||||
$this->properties = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Load propertys lazily
|
||||
*
|
||||
* @param string $name The property name.
|
||||
*
|
||||
* @return string Returns the property value
|
||||
*/
|
||||
public function get($name)
|
||||
{
|
||||
if (!isset($this->properties[$name]))
|
||||
{
|
||||
if (!method_exists($this->adapter, 'file_' . $name))
|
||||
{
|
||||
throw new storage_exception('STORAGE_METHOD_NOT_IMPLEMENTED');
|
||||
}
|
||||
|
||||
$this->properties = array_merge($this->properties, call_user_func([$this->adapter, 'file_' . $name], $this->path));
|
||||
}
|
||||
|
||||
return $this->properties[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias of \phpbb\storage\file_info->get()
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
return $this->get($name);
|
||||
}
|
||||
}
|
|
@ -63,7 +63,7 @@ class storage
|
|||
* @param string $storage_name
|
||||
* @param string $storage_table
|
||||
*/
|
||||
public function __construct(db $db, cache $cache, adapter_factory $factory, $storage_name, $storage_table)
|
||||
public function __construct(db $db, cache $cache, adapter_factory $factory, string $storage_name, string $storage_table)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->cache = $cache;
|
||||
|
@ -77,7 +77,7 @@ class storage
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_name()
|
||||
public function get_name(): string
|
||||
{
|
||||
return $this->storage_name;
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ class storage
|
|||
*
|
||||
* @return adapter_interface
|
||||
*/
|
||||
protected function get_adapter()
|
||||
protected function get_adapter(): mixed
|
||||
{
|
||||
if ($this->adapter === null)
|
||||
{
|
||||
|
@ -106,7 +106,7 @@ class storage
|
|||
* @throws storage_exception When the file already exists
|
||||
* When the file cannot be written
|
||||
*/
|
||||
public function put_contents($path, $content)
|
||||
public function put_contents(string $path, string $content): void
|
||||
{
|
||||
if ($this->exists($path))
|
||||
{
|
||||
|
@ -128,7 +128,7 @@ class storage
|
|||
* When cannot read file contents
|
||||
*
|
||||
*/
|
||||
public function get_contents($path)
|
||||
public function get_contents(string $path): string
|
||||
{
|
||||
if (!$this->exists($path))
|
||||
{
|
||||
|
@ -146,7 +146,7 @@ class storage
|
|||
*
|
||||
* @return bool Returns true if the file/directory exist, false otherwise
|
||||
*/
|
||||
public function exists($path, $full_check = false)
|
||||
public function exists(string $path, bool $full_check = false): bool
|
||||
{
|
||||
return ($this->is_tracked($path) && (!$full_check || $this->get_adapter()->exists($path)));
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ class storage
|
|||
* @throws storage_exception When removal fails
|
||||
* When the file doesn't exist
|
||||
*/
|
||||
public function delete($path)
|
||||
public function delete(string $path): void
|
||||
{
|
||||
if (!$this->exists($path))
|
||||
{
|
||||
|
@ -180,7 +180,7 @@ class storage
|
|||
* When target exists
|
||||
* When file/directory cannot be renamed
|
||||
*/
|
||||
public function rename($path_orig, $path_dest)
|
||||
public function rename(string $path_orig, string $path_dest): void
|
||||
{
|
||||
if (!$this->exists($path_orig))
|
||||
{
|
||||
|
@ -206,7 +206,7 @@ class storage
|
|||
* When target exists
|
||||
* When the file cannot be copied
|
||||
*/
|
||||
public function copy($path_orig, $path_dest)
|
||||
public function copy(string $path_orig, string $path_dest): void
|
||||
{
|
||||
if (!$this->exists($path_orig))
|
||||
{
|
||||
|
@ -232,7 +232,7 @@ class storage
|
|||
* When unable to open file
|
||||
*
|
||||
*/
|
||||
public function read_stream($path)
|
||||
public function read_stream(string $path)
|
||||
{
|
||||
if (!$this->exists($path))
|
||||
{
|
||||
|
@ -266,7 +266,7 @@ class storage
|
|||
* @throws storage_exception When the file exist
|
||||
* When target file cannot be created
|
||||
*/
|
||||
public function write_stream($path, $resource)
|
||||
public function write_stream(string $path, $resource): void
|
||||
{
|
||||
if ($this->exists($path))
|
||||
{
|
||||
|
@ -298,7 +298,7 @@ class storage
|
|||
* @param string $path The target file
|
||||
* @param bool $update Update file size when already tracked
|
||||
*/
|
||||
public function track_file($path, $update = false)
|
||||
public function track_file(string $path, bool $update = false): void
|
||||
{
|
||||
if (!$this->get_adapter()->exists($path))
|
||||
{
|
||||
|
@ -319,20 +319,15 @@ class storage
|
|||
|
||||
if (!$row)
|
||||
{
|
||||
// Don't call the file_info method, because it check's if the file is tracked
|
||||
// and is not (for now). This method check if the file exists using the adapter
|
||||
// at the beginning.
|
||||
$file = new file_info($this->get_adapter(), $path);
|
||||
$sql_ary['filesize'] = $file->size;
|
||||
$sql_ary['filesize'] = $this->get_adapter()->file_size($path);
|
||||
|
||||
$sql = 'INSERT INTO ' . $this->storage_table . $this->db->sql_build_array('INSERT', $sql_ary);
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
else if ($update)
|
||||
{
|
||||
$file = $this->file_info($path);
|
||||
$sql = 'UPDATE ' . $this->storage_table . '
|
||||
SET filesize = ' . $file->size . '
|
||||
SET filesize = ' . $this->get_adapter()->file_size($path) . '
|
||||
WHERE ' . $this->db->sql_build_array('SELECT', $sql_ary);
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
|
@ -368,7 +363,7 @@ class storage
|
|||
*
|
||||
* @return bool True if file is tracked
|
||||
*/
|
||||
public function is_tracked($path)
|
||||
public function is_tracked(string $path): bool
|
||||
{
|
||||
$sql_ary = array(
|
||||
'file_path' => $path,
|
||||
|
@ -381,7 +376,7 @@ class storage
|
|||
$row = $this->db->sql_fetchrow($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
return ($row) ? true : false;
|
||||
return $row !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -390,7 +385,7 @@ class storage
|
|||
* @param string $path_orig The original file/direcotry
|
||||
* @param string $path_dest The target file/directory
|
||||
*/
|
||||
protected function track_rename($path_orig, $path_dest)
|
||||
protected function track_rename(string $path_orig, string $path_dest): void
|
||||
{
|
||||
$sql = 'UPDATE ' . $this->storage_table . "
|
||||
SET file_path = '" . $this->db->sql_escape($path_dest) . "'
|
||||
|
@ -400,36 +395,28 @@ class storage
|
|||
}
|
||||
|
||||
/**
|
||||
* Get file info
|
||||
* Get file size in bytes
|
||||
*
|
||||
* @param string $path The file
|
||||
*
|
||||
* @return \phpbb\storage\file_info Returns file_info object
|
||||
* @throws storage_exception When the adapter doesn't implement the method
|
||||
* When the file doesn't exist
|
||||
* @return int Size in bytes.
|
||||
*
|
||||
* @throws storage_exception When unable to retrieve file size
|
||||
*/
|
||||
public function file_info($path)
|
||||
public function file_size(string $path): int
|
||||
{
|
||||
if (!$this->exists($path))
|
||||
{
|
||||
throw new storage_exception('STORAGE_FILE_NO_EXIST', $path);
|
||||
}
|
||||
$sql_ary = array(
|
||||
'file_path' => $path,
|
||||
'storage' => $this->get_name(),
|
||||
);
|
||||
|
||||
return new file_info($this->get_adapter(), $path);
|
||||
}
|
||||
$sql = 'SELECT filesize FROM ' . $this->storage_table . '
|
||||
WHERE ' . $this->db->sql_build_array('SELECT', $sql_ary);
|
||||
$result = $this->db->sql_query($sql);
|
||||
$row = $this->db->sql_fetchrow($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
/**
|
||||
* Get direct link
|
||||
*
|
||||
* @param string $path The file
|
||||
*
|
||||
* @return string Returns link.
|
||||
*
|
||||
*/
|
||||
public function get_link($path)
|
||||
{
|
||||
return $this->get_adapter()->get_link($path);
|
||||
return $row !== false && !empty($row['filesize']) ? $row['filesize'] : $this->get_adapter()->file_size($path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -437,7 +424,7 @@ class storage
|
|||
*
|
||||
* @return int Size in bytes
|
||||
*/
|
||||
public function get_size()
|
||||
public function get_size(): int
|
||||
{
|
||||
$total_size = $this->cache->get('_storage_' . $this->get_name() . '_totalsize');
|
||||
|
||||
|
@ -462,7 +449,7 @@ class storage
|
|||
*
|
||||
* @return int Number of files
|
||||
*/
|
||||
public function get_num_files()
|
||||
public function get_num_files(): int
|
||||
{
|
||||
$number_files = $this->cache->get('_storage_' . $this->get_name() . '_numfiles');
|
||||
|
||||
|
@ -493,4 +480,5 @@ class storage
|
|||
{
|
||||
return $this->get_adapter()->free_space();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -86,16 +86,16 @@ class phpbb_attachment_delete_test extends \phpbb_database_test_case
|
|||
public function data_attachment_unlink()
|
||||
{
|
||||
return array(
|
||||
array(true, true, true),
|
||||
array(true, false, false),
|
||||
array(true, true, false, true),
|
||||
array(true, true),
|
||||
array(false, false),
|
||||
array(true, false, true),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider data_attachment_unlink
|
||||
*/
|
||||
public function test_attachment_delete_success($remove_success, $exists_success, $expected, $throw_exception = false)
|
||||
public function test_attachment_delete_success($exists_success, $expected, $throw_exception = false)
|
||||
{
|
||||
$this->storage = $this->createMock('\phpbb\storage\storage');
|
||||
if ($throw_exception)
|
||||
|
@ -107,8 +107,7 @@ class phpbb_attachment_delete_test extends \phpbb_database_test_case
|
|||
else
|
||||
{
|
||||
$this->storage->expects($this->any())
|
||||
->method('delete')
|
||||
->willReturn($remove_success);
|
||||
->method('delete');
|
||||
}
|
||||
$this->storage->expects($this->any())
|
||||
->method('exists')
|
||||
|
|
|
@ -33,8 +33,6 @@ class phpbb_local_test_case extends phpbb_test_case
|
|||
|
||||
$this->adapter = new local(
|
||||
$this->filesystem,
|
||||
new FastImageSize(),
|
||||
new guesser(array(new extension_guesser)),
|
||||
$phpbb_root_path
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue