Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
tidy_plupload.php
001 <?php
002 /**
003 *
004 * This file is part of the phpBB Forum Software package.
005 *
006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
007 * @license GNU General Public License, version 2 (GPL-2.0)
008 *
009 * For full copyright and license information, please see
010 * the docs/CREDITS.txt file.
011 *
012 */
013
014 namespace phpbb\cron\task\core;
015
016 /**
017 * Cron task for cleaning plupload's temporary upload directory.
018 */
019 class tidy_plupload extends \phpbb\cron\task\base
020 {
021 /**
022 * How old a file must be (in seconds) before it is deleted.
023 * @var int
024 */
025 protected $max_file_age = 86400;
026
027 /**
028 * How often we run the cron (in seconds).
029 * @var int
030 */
031 protected $cron_frequency = 86400;
032
033 /**
034 * phpBB root path
035 * @var string
036 */
037 protected $phpbb_root_path;
038
039 /**
040 * Config object
041 * @var \phpbb\config\config
042 */
043 protected $config;
044
045 /**
046 * Directory where plupload stores temporary files.
047 * @var string
048 */
049 protected $plupload_upload_path;
050
051 /**
052 * Constructor.
053 *
054 * @param string $phpbb_root_path The root path
055 * @param \phpbb\config\config $config The config
056 */
057 public function __construct($phpbb_root_path, \phpbb\config\config $config)
058 {
059 $this->phpbb_root_path = $phpbb_root_path;
060 $this->config = $config;
061
062 $this->plupload_upload_path = $this->phpbb_root_path . $this->config['upload_path'] . '/plupload';
063 }
064
065 /**
066 * {@inheritDoc}
067 */
068 public function run()
069 {
070 // Remove old temporary file (perhaps failed uploads?)
071 $last_valid_timestamp = time() - $this->max_file_age;
072 try
073 {
074 $iterator = new \DirectoryIterator($this->plupload_upload_path);
075 foreach ($iterator as $file)
076 {
077 if (strpos($file->getBasename(), $this->config['plupload_salt']) !== 0)
078 {
079 // Skip over any non-plupload files.
080 continue;
081 }
082
083 if ($file->getMTime() < $last_valid_timestamp)
084 {
085 @unlink($file->getPathname());
086 }
087 }
088 }
089 catch (\UnexpectedValueException $e)
090 {
091 add_log(
092 'critical',
093 'LOG_PLUPLOAD_TIDY_FAILED',
094 $this->plupload_upload_path,
095 $e->getMessage(),
096 $e->getTraceAsString()
097 );
098 }
099
100 $this->config->set('plupload_last_gc', time(), true);
101 }
102
103 /**
104 * {@inheritDoc}
105 */
106 public function is_runnable()
107 {
108 return !empty($this->config['plupload_salt']) && is_dir($this->plupload_upload_path);
109 }
110
111 /**
112 * {@inheritDoc}
113 */
114 public function should_run()
115 {
116 return $this->config['plupload_last_gc'] < time() - $this->cron_frequency;
117 }
118 }
119