Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

tidy_plupload.php

Zuletzt modifiziert: 02.04.2025, 15:02 - Dateigröße: 2.66 KiB


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      /** @var \phpbb\log\log_interface */
046      protected $log;
047   
048      /** @var \phpbb\user */
049      protected $user;
050   
051      /**
052      * Directory where plupload stores temporary files.
053      * @var string
054      */
055      protected $plupload_upload_path;
056   
057      /**
058      * Constructor.
059      *
060      * @param string $phpbb_root_path The root path
061      * @param \phpbb\config\config $config The config
062      * @param \phpbb\log\log_interface $log Log
063      * @param \phpbb\user $user User object
064      */
065      public function __construct($phpbb_root_path, \phpbb\config\config $config, \phpbb\log\log_interface $log, \phpbb\user $user)
066      {
067          $this->phpbb_root_path = $phpbb_root_path;
068          $this->config = $config;
069          $this->log = $log;
070          $this->user = $user;
071   
072          $this->plupload_upload_path = $this->phpbb_root_path . $this->config['upload_path'] . '/plupload';
073      }
074   
075      /**
076      * {@inheritDoc}
077      */
078      public function run()
079      {
080          // Remove old temporary file (perhaps failed uploads?)
081          $last_valid_timestamp = time() - $this->max_file_age;
082          try
083          {
084              $iterator = new \DirectoryIterator($this->plupload_upload_path);
085              foreach ($iterator as $file)
086              {
087                  if (strpos($file->getBasename(), $this->config['plupload_salt']) !== 0)
088                  {
089                      // Skip over any non-plupload files.
090                      continue;
091                  }
092   
093                  if ($file->getMTime() < $last_valid_timestamp)
094                  {
095                      @unlink($file->getPathname());
096                  }
097              }
098          }
099          catch (\UnexpectedValueException $e)
100          {
101              $this->log->add('critical', $this->user->data['user_id'], $this->user->ip, 'LOG_PLUPLOAD_TIDY_FAILED', false, array(
102                  $this->plupload_upload_path,
103                  $e->getMessage(),
104                  $e->getTraceAsString()
105              ));
106          }
107   
108          $this->config->set('plupload_last_gc', time(), true);
109      }
110   
111      /**
112      * {@inheritDoc}
113      */
114      public function is_runnable()
115      {
116          return !empty($this->config['plupload_salt']) && is_dir($this->plupload_upload_path);
117      }
118   
119      /**
120      * {@inheritDoc}
121      */
122      public function should_run()
123      {
124          return $this->config['plupload_last_gc'] < time() - $this->cron_frequency;
125      }
126  }
127