From 67530d132ac6eb1eae74bd184014bcc7c6b7d082 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 17 Jul 2013 02:42:24 +0200 Subject: [PATCH 1/2] [feature/plupload/cron] Add cronjob for cleaning plupload temporary directory. PHPBB3-10929 --- phpBB/config/cron_tasks.yml | 10 ++ phpBB/language/en/acp/common.php | 2 + phpBB/phpbb/cron/task/core/tidy_plupload.php | 122 +++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 phpBB/phpbb/cron/task/core/tidy_plupload.php diff --git a/phpBB/config/cron_tasks.yml b/phpBB/config/cron_tasks.yml index 109c9684f9..a39c3b5767 100644 --- a/phpBB/config/cron_tasks.yml +++ b/phpBB/config/cron_tasks.yml @@ -65,6 +65,16 @@ services: tags: - { name: cron.task } + cron.task.core.tidy_plupload: + class: phpbb_cron_task_core_tidy_plupload + arguments: + - %core.root_path% + - @config + calls: + - [set_name, [cron.task.core.tidy_plupload]] + tags: + - { name: cron.task } + cron.task.core.tidy_search: class: phpbb\cron\task\core\tidy_search arguments: diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php index 9c470efcd9..77a7618ce0 100644 --- a/phpBB/language/en/acp/common.php +++ b/phpBB/language/en/acp/common.php @@ -666,6 +666,8 @@ $lang = array_merge($lang, array( 'LOG_U_ROLE_EDIT' => 'User role edited
» %s', 'LOG_U_ROLE_REMOVED' => 'User role removed
» %s', + 'LOG_PLUPLOAD_TIDY_FAILED' => 'Unable to open %1$s for tidying, check permissions.
Exception: %2$s
Trace: %3$s', + 'LOG_PROFILE_FIELD_ACTIVATE' => 'Profile field activated
» %s', 'LOG_PROFILE_FIELD_CREATE' => 'Profile field added
» %s', 'LOG_PROFILE_FIELD_DEACTIVATE' => 'Profile field deactivated
» %s', diff --git a/phpBB/phpbb/cron/task/core/tidy_plupload.php b/phpBB/phpbb/cron/task/core/tidy_plupload.php new file mode 100644 index 0000000000..be447d54a5 --- /dev/null +++ b/phpBB/phpbb/cron/task/core/tidy_plupload.php @@ -0,0 +1,122 @@ +phpbb_root_path = $phpbb_root_path; + $this->config = $config; + + $this->plupload_upload_path = $this->phpbb_root_path . $this->config['upload_path'] . '/plupload'; + } + + /** + * {@inheritDoc} + */ + public function run() + { + // Remove old temporary file (perhaps failed uploads?) + $last_valid_timestamp = time() - $this->max_file_age; + try + { + $iterator = new DirectoryIterator($this->plupload_upload_path); + foreach ($iterator as $file) + { + if (strpos($file->getBasename(), $this->config['plupload_salt']) !== 0) + { + // Skip over any non-plupload files. + continue; + } + + if ($file->getMTime() < $last_valid_timestamp) + { + @unlink($file->getPathname()); + } + } + } + catch (UnexpectedValueException $e) + { + add_log( + 'critical', + 'LOG_PLUPLOAD_TIDY_FAILED', + $this->plupload_upload_path, + $e->getMessage(), + $e->getTraceAsString() + ); + } + + $this->config->set('plupload_last_gc', time(), true); + } + + /** + * {@inheritDoc} + */ + public function is_runnable() + { + return !empty($this->config['plupload_salt']) && is_dir($this->plupload_upload_path); + } + + /** + * {@inheritDoc} + */ + public function should_run() + { + return $this->config['plupload_last_gc'] < time() - $this->cron_frequency; + } +} From beda12c05526aebcc6c968d97030f2b691ab1718 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Fri, 11 Oct 2013 15:51:33 +0200 Subject: [PATCH 2/2] [feature/plupload/cron] Namespacification PHPBB3-10929 --- phpBB/config/cron_tasks.yml | 2 +- phpBB/phpbb/cron/task/core/tidy_plupload.php | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/phpBB/config/cron_tasks.yml b/phpBB/config/cron_tasks.yml index a39c3b5767..fd3aea85dc 100644 --- a/phpBB/config/cron_tasks.yml +++ b/phpBB/config/cron_tasks.yml @@ -66,7 +66,7 @@ services: - { name: cron.task } cron.task.core.tidy_plupload: - class: phpbb_cron_task_core_tidy_plupload + class: phpbb\cron\task\core\tidy_plupload arguments: - %core.root_path% - @config diff --git a/phpBB/phpbb/cron/task/core/tidy_plupload.php b/phpBB/phpbb/cron/task/core/tidy_plupload.php index be447d54a5..09e9dfa6b4 100644 --- a/phpBB/phpbb/cron/task/core/tidy_plupload.php +++ b/phpBB/phpbb/cron/task/core/tidy_plupload.php @@ -7,6 +7,8 @@ * */ +namespace phpbb\cron\task\core; + /** * @ignore */ @@ -20,7 +22,7 @@ if (!defined('IN_PHPBB')) * * @package phpBB3 */ -class phpbb_cron_task_core_tidy_plupload extends phpbb_cron_task_base +class tidy_plupload extends \phpbb\cron\task\base { /** * How old a file must be (in seconds) before it is deleted. @@ -42,7 +44,7 @@ class phpbb_cron_task_core_tidy_plupload extends phpbb_cron_task_base /** * Config object - * @var phpbb_config + * @var \phpbb\config\config */ protected $config; @@ -56,9 +58,9 @@ class phpbb_cron_task_core_tidy_plupload extends phpbb_cron_task_base * Constructor. * * @param string $phpbb_root_path The root path - * @param phpbb_config $config The config + * @param \phpbb\config\config $config The config */ - public function __construct($phpbb_root_path, phpbb_config $config) + public function __construct($phpbb_root_path, \phpbb\config\config $config) { $this->phpbb_root_path = $phpbb_root_path; $this->config = $config; @@ -75,7 +77,7 @@ class phpbb_cron_task_core_tidy_plupload extends phpbb_cron_task_base $last_valid_timestamp = time() - $this->max_file_age; try { - $iterator = new DirectoryIterator($this->plupload_upload_path); + $iterator = new \DirectoryIterator($this->plupload_upload_path); foreach ($iterator as $file) { if (strpos($file->getBasename(), $this->config['plupload_salt']) !== 0) @@ -90,7 +92,7 @@ class phpbb_cron_task_core_tidy_plupload extends phpbb_cron_task_base } } } - catch (UnexpectedValueException $e) + catch (\UnexpectedValueException $e) { add_log( 'critical',