mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
[ticket/17361] Use storage in commands create and delete thumbnail
PHPBB-17361
This commit is contained in:
parent
6d9a8ae8af
commit
a8399c1431
4 changed files with 98 additions and 51 deletions
|
@ -284,20 +284,21 @@ services:
|
|||
console.command.thumbnail.delete:
|
||||
class: phpbb\console\command\thumbnail\delete
|
||||
arguments:
|
||||
- '@config'
|
||||
- '@user'
|
||||
- '@dbal.conn'
|
||||
- '%core.root_path%'
|
||||
- '@language'
|
||||
- '@storage.attachment'
|
||||
tags:
|
||||
- { name: console.command }
|
||||
|
||||
console.command.thumbnail.generate:
|
||||
class: phpbb\console\command\thumbnail\generate
|
||||
arguments:
|
||||
- '@config'
|
||||
- '@user'
|
||||
- '@dbal.conn'
|
||||
- '@cache'
|
||||
- '@language'
|
||||
- '@storage.attachment'
|
||||
- '%core.root_path%'
|
||||
- '%core.php_ext%'
|
||||
tags:
|
||||
|
@ -307,6 +308,7 @@ services:
|
|||
class: phpbb\console\command\thumbnail\recreate
|
||||
arguments:
|
||||
- '@user'
|
||||
- '@language'
|
||||
tags:
|
||||
- { name: console.command }
|
||||
|
||||
|
|
|
@ -12,6 +12,11 @@
|
|||
*/
|
||||
namespace phpbb\console\command\thumbnail;
|
||||
|
||||
use phpbb\db\driver\driver_interface;
|
||||
use phpbb\language\language;
|
||||
use phpbb\storage\exception\storage_exception;
|
||||
use phpbb\storage\storage;
|
||||
use phpbb\user;
|
||||
use Symfony\Component\Console\Command\Command as symfony_command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
@ -20,15 +25,20 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
|||
class delete extends \phpbb\console\command\command
|
||||
{
|
||||
/**
|
||||
* @var \phpbb\config\config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var \phpbb\db\driver\driver_interface
|
||||
* @var driver_interface
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* @var language
|
||||
*/
|
||||
protected $language;
|
||||
|
||||
/**
|
||||
* @var storage
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* phpBB root path
|
||||
* @var string
|
||||
|
@ -38,16 +48,16 @@ class delete extends \phpbb\console\command\command
|
|||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \phpbb\config\config $config The config
|
||||
* @param \phpbb\user $user The user object (used to get language information)
|
||||
* @param \phpbb\db\driver\driver_interface $db Database connection
|
||||
* @param string $phpbb_root_path Root path
|
||||
* @param user $user The user object (used to get language information)
|
||||
* @param driver_interface $db Database connection
|
||||
* @param language $language Language
|
||||
* @param storage $storage Storage
|
||||
*/
|
||||
public function __construct(\phpbb\config\config $config, \phpbb\user $user, \phpbb\db\driver\driver_interface $db, $phpbb_root_path)
|
||||
public function __construct(user $user, driver_interface $db, language $language, storage $storage)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->db = $db;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->language = $language;
|
||||
$this->storage = $storage;
|
||||
|
||||
parent::__construct($user);
|
||||
}
|
||||
|
@ -61,7 +71,7 @@ class delete extends \phpbb\console\command\command
|
|||
{
|
||||
$this
|
||||
->setName('thumbnail:delete')
|
||||
->setDescription($this->user->lang('CLI_DESCRIPTION_THUMBNAIL_DELETE'))
|
||||
->setDescription($this->language->lang('CLI_DESCRIPTION_THUMBNAIL_DELETE'))
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -79,7 +89,7 @@ class delete extends \phpbb\console\command\command
|
|||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$io->section($this->user->lang('CLI_THUMBNAIL_DELETING'));
|
||||
$io->section($this->language->lang('CLI_THUMBNAIL_DELETING'));
|
||||
|
||||
$sql = 'SELECT COUNT(*) AS nb_missing_thumbnails
|
||||
FROM ' . ATTACHMENTS_TABLE . '
|
||||
|
@ -90,7 +100,7 @@ class delete extends \phpbb\console\command\command
|
|||
|
||||
if ($nb_missing_thumbnails === 0)
|
||||
{
|
||||
$io->warning($this->user->lang('CLI_THUMBNAIL_NOTHING_TO_DELETE'));
|
||||
$io->warning($this->language->lang('CLI_THUMBNAIL_NOTHING_TO_DELETE'));
|
||||
return symfony_command::SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -101,7 +111,7 @@ class delete extends \phpbb\console\command\command
|
|||
|
||||
$progress = $this->create_progress_bar($nb_missing_thumbnails, $io, $output);
|
||||
|
||||
$progress->setMessage($this->user->lang('CLI_THUMBNAIL_DELETING'));
|
||||
$progress->setMessage($this->language->lang('CLI_THUMBNAIL_DELETING'));
|
||||
|
||||
$progress->start();
|
||||
|
||||
|
@ -109,10 +119,10 @@ class delete extends \phpbb\console\command\command
|
|||
$return = symfony_command::SUCCESS;
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$thumbnail_path = $this->phpbb_root_path . $this->config['upload_path'] . '/thumb_' . $row['physical_filename'];
|
||||
|
||||
if (@unlink($thumbnail_path))
|
||||
try
|
||||
{
|
||||
$this->storage->delete('thumb_' . $row['physical_filename']);
|
||||
|
||||
$thumbnail_deleted[] = $row['attach_id'];
|
||||
|
||||
if (count($thumbnail_deleted) === 250)
|
||||
|
@ -121,12 +131,11 @@ class delete extends \phpbb\console\command\command
|
|||
$thumbnail_deleted = array();
|
||||
}
|
||||
|
||||
$progress->setMessage($this->user->lang('CLI_THUMBNAIL_DELETED', $row['real_filename'], $row['physical_filename']));
|
||||
}
|
||||
else
|
||||
{
|
||||
$progress->setMessage($this->language->lang('CLI_THUMBNAIL_DELETED', $row['real_filename'], $row['physical_filename']));
|
||||
} catch (storage_exception $e) {
|
||||
$return = symfony_command::FAILURE;
|
||||
$progress->setMessage('<error>' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . '</error>');
|
||||
$progress->setMessage('<error>' . $this->language->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . '</error>');
|
||||
|
||||
}
|
||||
|
||||
$progress->advance();
|
||||
|
@ -141,7 +150,7 @@ class delete extends \phpbb\console\command\command
|
|||
$progress->finish();
|
||||
|
||||
$io->newLine(2);
|
||||
$io->success($this->user->lang('CLI_THUMBNAIL_DELETING_DONE'));
|
||||
$io->success($this->language->lang('CLI_THUMBNAIL_DELETING_DONE'));
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,11 @@
|
|||
|
||||
namespace phpbb\console\command\thumbnail;
|
||||
|
||||
use phpbb\cache\service;
|
||||
use phpbb\db\driver\driver_interface;
|
||||
use phpbb\language\language;
|
||||
use phpbb\storage\storage;
|
||||
use phpbb\user;
|
||||
use Symfony\Component\Console\Command\Command as symfony_command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
@ -20,21 +25,27 @@ use Symfony\Component\Console\Style\SymfonyStyle;
|
|||
|
||||
class generate extends \phpbb\console\command\command
|
||||
{
|
||||
/**
|
||||
* @var \phpbb\config\config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var \phpbb\db\driver\driver_interface
|
||||
* @var driver_interface
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* @var \phpbb\cache\service
|
||||
* @var service
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* @var language
|
||||
*/
|
||||
protected $language;
|
||||
|
||||
/**
|
||||
* @var storage
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* phpBB root path
|
||||
* @var string
|
||||
|
@ -51,18 +62,20 @@ class generate extends \phpbb\console\command\command
|
|||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \phpbb\config\config $config The config
|
||||
* @param \phpbb\user $user The user object (used to get language information)
|
||||
* @param \phpbb\db\driver\driver_interface $db Database connection
|
||||
* @param \phpbb\cache\service $cache The cache service
|
||||
* @param user $user The user object (used to get language information)
|
||||
* @param driver_interface $db Database connection
|
||||
* @param service $cache The cache service
|
||||
* @param language $language Language
|
||||
* @param storage $storage Storage
|
||||
* @param string $phpbb_root_path Root path
|
||||
* @param string $php_ext PHP extension
|
||||
*/
|
||||
public function __construct(\phpbb\config\config $config, \phpbb\user $user, \phpbb\db\driver\driver_interface $db, \phpbb\cache\service $cache, $phpbb_root_path, $php_ext)
|
||||
public function __construct(user $user, driver_interface $db, service $cache, language $language, storage $storage, string $phpbb_root_path, string $php_ext)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->db = $db;
|
||||
$this->cache = $cache;
|
||||
$this->language = $language;
|
||||
$this->storage = $storage;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->php_ext = $php_ext;
|
||||
|
||||
|
@ -78,7 +91,7 @@ class generate extends \phpbb\console\command\command
|
|||
{
|
||||
$this
|
||||
->setName('thumbnail:generate')
|
||||
->setDescription($this->user->lang('CLI_DESCRIPTION_THUMBNAIL_GENERATE'))
|
||||
->setDescription($this->language->lang('CLI_DESCRIPTION_THUMBNAIL_GENERATE'))
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -96,7 +109,7 @@ class generate extends \phpbb\console\command\command
|
|||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$io->section($this->user->lang('CLI_THUMBNAIL_GENERATING'));
|
||||
$io->section($this->language->lang('CLI_THUMBNAIL_GENERATING'));
|
||||
|
||||
$sql = 'SELECT COUNT(*) AS nb_missing_thumbnails
|
||||
FROM ' . ATTACHMENTS_TABLE . '
|
||||
|
@ -107,7 +120,7 @@ class generate extends \phpbb\console\command\command
|
|||
|
||||
if ($nb_missing_thumbnails === 0)
|
||||
{
|
||||
$io->warning($this->user->lang('CLI_THUMBNAIL_NOTHING_TO_GENERATE'));
|
||||
$io->warning($this->language->lang('CLI_THUMBNAIL_NOTHING_TO_GENERATE'));
|
||||
return symfony_command::SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -125,7 +138,7 @@ class generate extends \phpbb\console\command\command
|
|||
|
||||
$progress = $this->create_progress_bar($nb_missing_thumbnails, $io, $output);
|
||||
|
||||
$progress->setMessage($this->user->lang('CLI_THUMBNAIL_GENERATING'));
|
||||
$progress->setMessage($this->language->lang('CLI_THUMBNAIL_GENERATING'));
|
||||
|
||||
$progress->start();
|
||||
|
||||
|
@ -134,11 +147,15 @@ class generate extends \phpbb\console\command\command
|
|||
{
|
||||
if (isset($extensions[$row['extension']]['display_cat']) && $extensions[$row['extension']]['display_cat'] == \phpbb\attachment\attachment_category::IMAGE)
|
||||
{
|
||||
$source = $this->phpbb_root_path . $this->config['upload_path'] . '/' . $row['physical_filename'];
|
||||
$destination = $this->phpbb_root_path . $this->config['upload_path'] . '/thumb_' . $row['physical_filename'];
|
||||
$source = tempnam(sys_get_temp_dir(), 'thumbnail_source');
|
||||
$destination = tempnam(sys_get_temp_dir(), 'thumbnail_destination');
|
||||
|
||||
file_put_contents($source, $this->storage->read($row['physical_filename']));
|
||||
|
||||
if (create_thumbnail($source, $destination, $row['mimetype']))
|
||||
{
|
||||
$this->storage->write('thumb_' . $row['physical_filename'], fopen($destination, 'rb'));
|
||||
|
||||
$thumbnail_created[] = (int) $row['attach_id'];
|
||||
|
||||
if (count($thumbnail_created) === 250)
|
||||
|
@ -147,11 +164,11 @@ class generate extends \phpbb\console\command\command
|
|||
$thumbnail_created = array();
|
||||
}
|
||||
|
||||
$progress->setMessage($this->user->lang('CLI_THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename']));
|
||||
$progress->setMessage($this->language->lang('CLI_THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename']));
|
||||
}
|
||||
else
|
||||
{
|
||||
$progress->setMessage('<info>' . $this->user->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . '</info>');
|
||||
$progress->setMessage('<info>' . $this->language->lang('CLI_THUMBNAIL_SKIPPED', $row['real_filename'], $row['physical_filename']) . '</info>');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,7 +184,7 @@ class generate extends \phpbb\console\command\command
|
|||
$progress->finish();
|
||||
|
||||
$io->newLine(2);
|
||||
$io->success($this->user->lang('CLI_THUMBNAIL_GENERATING_DONE'));
|
||||
$io->success($this->language->lang('CLI_THUMBNAIL_GENERATING_DONE'));
|
||||
|
||||
return symfony_command::SUCCESS;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
*/
|
||||
namespace phpbb\console\command\thumbnail;
|
||||
|
||||
use phpbb\language\language;
|
||||
use phpbb\user;
|
||||
use Symfony\Component\Console\Command\Command as symfony_command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
|
@ -19,6 +21,23 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||
|
||||
class recreate extends \phpbb\console\command\command
|
||||
{
|
||||
/**
|
||||
* @var language
|
||||
*/
|
||||
protected $language;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param language $language Language
|
||||
*/
|
||||
public function __construct(user $user, language $language)
|
||||
{
|
||||
$this->language = $language;
|
||||
|
||||
parent::__construct($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the command name and description
|
||||
*
|
||||
|
@ -28,7 +47,7 @@ class recreate extends \phpbb\console\command\command
|
|||
{
|
||||
$this
|
||||
->setName('thumbnail:recreate')
|
||||
->setDescription($this->user->lang('CLI_DESCRIPTION_THUMBNAIL_RECREATE'))
|
||||
->setDescription($this->language->lang('CLI_DESCRIPTION_THUMBNAIL_RECREATE'))
|
||||
;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue