aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2013-10-13 16:00:43 -0700
committerNils Adermann <naderman@naderman.de>2013-10-13 16:00:43 -0700
commit5927f0dbf2cd6bfe2db19f5703703af43cea64c8 (patch)
tree3ff52cd3062bb4e856f4eeadb070777baff17cfa
parentb9ca3dc35495412bd25c2cdfe2db402976eefc14 (diff)
parentbeda12c05526aebcc6c968d97030f2b691ab1718 (diff)
downloadforums-5927f0dbf2cd6bfe2db19f5703703af43cea64c8.tar
forums-5927f0dbf2cd6bfe2db19f5703703af43cea64c8.tar.gz
forums-5927f0dbf2cd6bfe2db19f5703703af43cea64c8.tar.bz2
forums-5927f0dbf2cd6bfe2db19f5703703af43cea64c8.tar.xz
forums-5927f0dbf2cd6bfe2db19f5703703af43cea64c8.zip
Merge pull request #1582 from bantu/feature/plupload/cron
[ticket/10929] Cron Job for Plupload Upload Directory Cleaning
-rw-r--r--phpBB/config/cron_tasks.yml10
-rw-r--r--phpBB/language/en/acp/common.php2
-rw-r--r--phpBB/phpbb/cron/task/core/tidy_plupload.php124
3 files changed, 136 insertions, 0 deletions
diff --git a/phpBB/config/cron_tasks.yml b/phpBB/config/cron_tasks.yml
index 109c9684f9..fd3aea85dc 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' => '<strong>User role edited</strong><br />» %s',
'LOG_U_ROLE_REMOVED' => '<strong>User role removed</strong><br />» %s',
+ 'LOG_PLUPLOAD_TIDY_FAILED' => '<strong>Unable to open %1$s for tidying, check permissions.</strong><br />Exception: %2$s<br />Trace: %3$s',
+
'LOG_PROFILE_FIELD_ACTIVATE' => '<strong>Profile field activated</strong><br />» %s',
'LOG_PROFILE_FIELD_CREATE' => '<strong>Profile field added</strong><br />» %s',
'LOG_PROFILE_FIELD_DEACTIVATE' => '<strong>Profile field deactivated</strong><br />» %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..09e9dfa6b4
--- /dev/null
+++ b/phpBB/phpbb/cron/task/core/tidy_plupload.php
@@ -0,0 +1,124 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+namespace phpbb\cron\task\core;
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+/**
+* Cron task for cleaning plupload's temporary upload directory.
+*
+* @package phpBB3
+*/
+class tidy_plupload extends \phpbb\cron\task\base
+{
+ /**
+ * How old a file must be (in seconds) before it is deleted.
+ * @var int
+ */
+ protected $max_file_age = 86400;
+
+ /**
+ * How often we run the cron (in seconds).
+ * @var int
+ */
+ protected $cron_frequency = 86400;
+
+ /**
+ * phpBB root path
+ * @var string
+ */
+ protected $phpbb_root_path;
+
+ /**
+ * Config object
+ * @var \phpbb\config\config
+ */
+ protected $config;
+
+ /**
+ * Directory where plupload stores temporary files.
+ * @var string
+ */
+ protected $plupload_upload_path;
+
+ /**
+ * Constructor.
+ *
+ * @param string $phpbb_root_path The root path
+ * @param \phpbb\config\config $config The config
+ */
+ public function __construct($phpbb_root_path, \phpbb\config\config $config)
+ {
+ $this->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;
+ }
+}