mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-01 14:30:32 +02:00
Merge pull request #6753 from rubencm/ticket/17361
[ticket/17361] Improve storage
This commit is contained in:
@@ -38,4 +38,13 @@ class storage_attachment extends migration
|
||||
['config.remove', ['upload_path']],
|
||||
];
|
||||
}
|
||||
|
||||
public function revert_data()
|
||||
{
|
||||
return [
|
||||
['config.remove', ['storage\\attachment\\provider']],
|
||||
['config.remove', ['storage\\attachment\\config\\path']],
|
||||
['config.add', ['upload_path', 'files']],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -38,4 +38,13 @@ class storage_avatar extends migration
|
||||
['config.remove', ['avatar_path']],
|
||||
];
|
||||
}
|
||||
|
||||
public function revert_data()
|
||||
{
|
||||
return [
|
||||
['config.remove', ['storage\\avatar\\provider']],
|
||||
['config.remove', ['storage\\avatar\\config\\path']],
|
||||
['config.add', ['avatar_path', 'images/avatars/upload']],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -45,6 +45,15 @@ class storage_backup extends migration
|
||||
];
|
||||
}
|
||||
|
||||
public function revert_schema()
|
||||
{
|
||||
return [
|
||||
'drop_tables' => [
|
||||
$this->table_prefix . 'backups',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function update_data()
|
||||
{
|
||||
return [
|
||||
@@ -52,4 +61,12 @@ class storage_backup extends migration
|
||||
['config.add', ['storage\\backup\\config\\path', 'store']],
|
||||
];
|
||||
}
|
||||
|
||||
public function revert_data()
|
||||
{
|
||||
return [
|
||||
['config.remove', ['storage\\backup\\provider']],
|
||||
['config.remove', ['storage\\backup\\config\\path']],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
64
phpBB/phpbb/db/migration/data/v400/storage_backup_data.php
Normal file
64
phpBB/phpbb/db/migration/data/v400/storage_backup_data.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?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 storage_backup_data extends migration
|
||||
{
|
||||
public static function depends_on()
|
||||
{
|
||||
return [
|
||||
'\phpbb\db\migration\data\v400\storage_backup',
|
||||
];
|
||||
}
|
||||
|
||||
public function update_data()
|
||||
{
|
||||
return [
|
||||
['custom', [[$this, 'update_backup_data']]],
|
||||
];
|
||||
}
|
||||
|
||||
public function update_backup_data()
|
||||
{
|
||||
$methods = ['sql', 'sql.gz', 'sql.bz2'];
|
||||
|
||||
$dir = $this->phpbb_root_path . 'store/';
|
||||
$handle = @opendir($dir);
|
||||
|
||||
if ($handle)
|
||||
{
|
||||
while (($file = readdir($handle)) !== false)
|
||||
{
|
||||
if (preg_match('#^backup_(\d{10,})_(?:[a-z\d]{16}|[a-z\d]{32})\.(sql(?:\.(?:gz|bz2))?)$#i', $file, $matches))
|
||||
{
|
||||
if (in_array($matches[2], $methods))
|
||||
{
|
||||
$insert_ary = [
|
||||
'filename' => $file,
|
||||
];
|
||||
|
||||
$sql = 'INSERT INTO ' . $this->table_prefix . 'backups ' . $this->db->sql_build_array('INSERT', $insert_ary);
|
||||
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
closedir($handle);
|
||||
}
|
||||
}
|
||||
}
|
@@ -14,11 +14,12 @@
|
||||
namespace phpbb\db\migration\data\v400;
|
||||
|
||||
use phpbb\db\migration\container_aware_migration;
|
||||
use phpbb\storage\exception\storage_exception;
|
||||
use phpbb\storage\storage;
|
||||
use phpbb\storage\file_tracker;
|
||||
|
||||
class storage_track extends container_aware_migration
|
||||
{
|
||||
private const BATCH_SIZE = 100;
|
||||
|
||||
public function effectively_installed()
|
||||
{
|
||||
return $this->db_tools->sql_table_exists($this->tables['storage']);
|
||||
@@ -30,6 +31,7 @@ class storage_track extends container_aware_migration
|
||||
'\phpbb\db\migration\data\v400\storage_attachment',
|
||||
'\phpbb\db\migration\data\v400\storage_avatar',
|
||||
'\phpbb\db\migration\data\v400\storage_backup',
|
||||
'\phpbb\db\migration\data\v400\storage_backup_data',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -70,15 +72,15 @@ class storage_track extends container_aware_migration
|
||||
|
||||
public function track_avatars()
|
||||
{
|
||||
/** @var storage $storage */
|
||||
$storage = $this->container->get('storage.avatar');
|
||||
/** @var file_tracker $file_tracker */
|
||||
$file_tracker = $this->container->get('storage.file_tracker');
|
||||
|
||||
$sql = 'SELECT user_avatar
|
||||
FROM ' . USERS_TABLE . "
|
||||
WHERE user_avatar_type = 'avatar.driver.upload'";
|
||||
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
$files = [];
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$avatar_group = false;
|
||||
@@ -93,76 +95,96 @@ class storage_track extends container_aware_migration
|
||||
$ext = substr(strrchr($filename, '.'), 1);
|
||||
$filename = (int) $filename;
|
||||
|
||||
try
|
||||
$filename = $this->config['avatar_salt'] . '_' . ($avatar_group ? 'g' : '') . $filename . '.' . $ext;
|
||||
$files[] = [
|
||||
'file_path' => $filename,
|
||||
'filesize' => filesize($this->phpbb_root_path . $this->config['storage\\avatar\\config\\path'] . '/' . $filename),
|
||||
];
|
||||
|
||||
if (count($files) >= self::BATCH_SIZE)
|
||||
{
|
||||
$storage->track_file($this->config['avatar_salt'] . '_' . ($avatar_group ? 'g' : '') . $filename . '.' . $ext);
|
||||
}
|
||||
catch (storage_exception $e)
|
||||
{
|
||||
// If file doesn't exist, don't track it
|
||||
$file_tracker->track_files('avatar', $files);
|
||||
$files = [];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($files))
|
||||
{
|
||||
$file_tracker->track_files('avatar', $files);
|
||||
}
|
||||
|
||||
$this->db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
public function track_attachments()
|
||||
{
|
||||
/** @var storage $storage */
|
||||
$storage = $this->container->get('storage.attachment');
|
||||
/** @var file_tracker $file_tracker */
|
||||
$file_tracker = $this->container->get('storage.file_tracker');
|
||||
|
||||
$sql = 'SELECT physical_filename, thumbnail
|
||||
FROM ' . ATTACHMENTS_TABLE;
|
||||
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
$files = [];
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
try
|
||||
{
|
||||
$storage->track_file($row['physical_filename']);
|
||||
}
|
||||
catch (storage_exception $e)
|
||||
{
|
||||
// If file doesn't exist, don't track it
|
||||
}
|
||||
$files[] = [
|
||||
'file_path' => $row['physical_filename'],
|
||||
'filesize' => filesize($this->phpbb_root_path . $this->config['storage\\attachment\\config\\path'] . '/' . $row['physical_filename']),
|
||||
];
|
||||
|
||||
if ($row['thumbnail'] == 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
$storage->track_file('thumb_' . $row['physical_filename']);
|
||||
}
|
||||
catch (storage_exception $e)
|
||||
{
|
||||
// If file doesn't exist, don't track it
|
||||
}
|
||||
$files[] = [
|
||||
'file_path' => 'thumb_' . $row['physical_filename'],
|
||||
'filesize' => filesize($this->phpbb_root_path . $this->config['storage\\attachment\\config\\path'] . '/thumb_' . $row['physical_filename']),
|
||||
];
|
||||
}
|
||||
|
||||
if (count($files) >= self::BATCH_SIZE)
|
||||
{
|
||||
$file_tracker->track_files('attachment', $files);
|
||||
$files = [];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($files))
|
||||
{
|
||||
$file_tracker->track_files('attachment', $files);
|
||||
}
|
||||
|
||||
$this->db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
public function track_backups()
|
||||
{
|
||||
/** @var storage $storage */
|
||||
$storage = $this->container->get('storage.backup');
|
||||
/** @var file_tracker $file_tracker */
|
||||
$file_tracker = $this->container->get('storage.file_tracker');
|
||||
|
||||
$sql = 'SELECT filename
|
||||
FROM ' . BACKUPS_TABLE;
|
||||
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
$files = [];
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
try
|
||||
$files[] = [
|
||||
'file_path' => $row['filename'],
|
||||
'filesize' => filesize($this->phpbb_root_path . $this->config['storage\\backup\\config\\path'] . '/' . $row['filename']),
|
||||
];
|
||||
|
||||
if (count($files) >= self::BATCH_SIZE)
|
||||
{
|
||||
$storage->track_file($row['filename']);
|
||||
}
|
||||
catch (storage_exception $e)
|
||||
{
|
||||
// If file doesn't exist, don't track it
|
||||
$file_tracker->track_files('backup', $files);
|
||||
$files = [];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($files))
|
||||
{
|
||||
$file_tracker->track_files('backup', $files);
|
||||
}
|
||||
|
||||
$this->db->sql_freeresult($result);
|
||||
}
|
||||
}
|
||||
|
48
phpBB/phpbb/db/migration/data/v400/storage_track_index.php
Normal file
48
phpBB/phpbb/db/migration/data/v400/storage_track_index.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?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\container_aware_migration;
|
||||
|
||||
class storage_track_index extends container_aware_migration
|
||||
{
|
||||
public static function depends_on()
|
||||
{
|
||||
return [
|
||||
'\phpbb\db\migration\data\v400\storage_track',
|
||||
];
|
||||
}
|
||||
|
||||
public function update_schema()
|
||||
{
|
||||
return [
|
||||
'add_unique_index' => [
|
||||
$this->table_prefix . 'storage' => [
|
||||
'uidx_storage' => ['file_path', 'storage'],
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function revert_schema()
|
||||
{
|
||||
return [
|
||||
'drop_keys' => [
|
||||
$this->table_prefix . 'storage' => [
|
||||
'uidx_storage',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user