[ Index ]

PHP Cross Reference of phpBB-3.3.2-deutsch

title

Body

[close]

/phpbb/cron/task/core/ -> tidy_plupload.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  namespace phpbb\cron\task\core;
  15  
  16  /**
  17  * Cron task for cleaning plupload's temporary upload directory.
  18  */
  19  class tidy_plupload extends \phpbb\cron\task\base
  20  {
  21      /**
  22      * How old a file must be (in seconds) before it is deleted.
  23      * @var int
  24      */
  25      protected $max_file_age = 86400;
  26  
  27      /**
  28      * How often we run the cron (in seconds).
  29      * @var int
  30      */
  31      protected $cron_frequency = 86400;
  32  
  33      /**
  34      * phpBB root path
  35      * @var string
  36      */
  37      protected $phpbb_root_path;
  38  
  39      /**
  40      * Config object
  41      * @var \phpbb\config\config
  42      */
  43      protected $config;
  44  
  45      /** @var \phpbb\log\log_interface */
  46      protected $log;
  47  
  48      /** @var \phpbb\user */
  49      protected $user;
  50  
  51      /**
  52      * Directory where plupload stores temporary files.
  53      * @var string
  54      */
  55      protected $plupload_upload_path;
  56  
  57      /**
  58      * Constructor.
  59      *
  60      * @param string $phpbb_root_path The root path
  61      * @param \phpbb\config\config $config The config
  62      * @param \phpbb\log\log_interface $log Log
  63      * @param \phpbb\user $user User object
  64      */
  65  	public function __construct($phpbb_root_path, \phpbb\config\config $config, \phpbb\log\log_interface $log, \phpbb\user $user)
  66      {
  67          $this->phpbb_root_path = $phpbb_root_path;
  68          $this->config = $config;
  69          $this->log = $log;
  70          $this->user = $user;
  71  
  72          $this->plupload_upload_path = $this->phpbb_root_path . $this->config['upload_path'] . '/plupload';
  73      }
  74  
  75      /**
  76      * {@inheritDoc}
  77      */
  78  	public function run()
  79      {
  80          // Remove old temporary file (perhaps failed uploads?)
  81          $last_valid_timestamp = time() - $this->max_file_age;
  82          try
  83          {
  84              $iterator = new \DirectoryIterator($this->plupload_upload_path);
  85              foreach ($iterator as $file)
  86              {
  87                  if (strpos($file->getBasename(), $this->config['plupload_salt']) !== 0)
  88                  {
  89                      // Skip over any non-plupload files.
  90                      continue;
  91                  }
  92  
  93                  if ($file->getMTime() < $last_valid_timestamp)
  94                  {
  95                      @unlink($file->getPathname());
  96                  }
  97              }
  98          }
  99          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  }


Generated: Wed Nov 11 20:28:18 2020 Cross-referenced by PHPXref 0.7.1