[ticket/12692] Update the database regularly

PHPBB3-12692
This commit is contained in:
Tristan Darricau 2014-06-17 22:24:45 +02:00 committed by Tristan Darricau
parent c96cc2cb05
commit 54be6b1f62
2 changed files with 42 additions and 8 deletions

View file

@ -84,6 +84,13 @@ class delete extends \phpbb\console\command\command
if (@unlink($thumbnail_path)) if (@unlink($thumbnail_path))
{ {
$thumbnail_deleted[] = $row['attach_id']; $thumbnail_deleted[] = $row['attach_id'];
if (sizeof($thumbnail_deleted) === 250)
{
$this->commit_changes($thumbnail_deleted);
$thumbnail_deleted = array();
}
if ($input->getOption('verbose')) if ($input->getOption('verbose'))
{ {
$output->writeln($this->user->lang('THUMBNAIL_DELETED', $row['real_filename'], $row['physical_filename'])); $output->writeln($this->user->lang('THUMBNAIL_DELETED', $row['real_filename'], $row['physical_filename']));
@ -102,12 +109,22 @@ class delete extends \phpbb\console\command\command
if (!empty($thumbnail_deleted)) if (!empty($thumbnail_deleted))
{ {
$sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' $this->commit_changes($thumbnail_deleted);
SET thumbnail = 0
WHERE ' . $this->db->sql_in_set('attach_id', $thumbnail_deleted);
$this->db->sql_query($sql);
} }
return $return; return $return;
} }
/**
* Commits the changes to the database
*
* @param array $thumbnail_deleted
*/
protected function commit_changes(array $thumbnail_deleted)
{
$sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
SET thumbnail = 0
WHERE ' . $this->db->sql_in_set('attach_id', $thumbnail_deleted);
$this->db->sql_query($sql);
}
} }

View file

@ -106,6 +106,13 @@ class generate extends \phpbb\console\command\command
if (create_thumbnail($source, $destination, $row['mimetype'])) if (create_thumbnail($source, $destination, $row['mimetype']))
{ {
$thumbnail_created[] = (int) $row['attach_id']; $thumbnail_created[] = (int) $row['attach_id'];
if (sizeof($thumbnail_created) === 250)
{
$this->commit_changes($thumbnail_created);
$thumbnail_created = array();
}
if ($input->getOption('verbose')) if ($input->getOption('verbose'))
{ {
$output->writeln($this->user->lang('THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename'])); $output->writeln($this->user->lang('THUMBNAIL_GENERATED', $row['real_filename'], $row['physical_filename']));
@ -124,12 +131,22 @@ class generate extends \phpbb\console\command\command
if (!empty($thumbnail_created)) if (!empty($thumbnail_created))
{ {
$sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' $this->commit_changes($thumbnail_created);
SET thumbnail = 1
WHERE ' . $this->db->sql_in_set('attach_id', $thumbnail_created);
$this->db->sql_query($sql);
} }
return 0; return 0;
} }
/**
* Commits the changes to the database
*
* @param array $thumbnail_created
*/
protected function commit_changes(array $thumbnail_created)
{
$sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
SET thumbnail = 1
WHERE ' . $this->db->sql_in_set('attach_id', $thumbnail_created);
$this->db->sql_query($sql);
}
} }