[ Index ]

PHP Cross Reference of phpBB-3.1.12-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      /**
  46      * Directory where plupload stores temporary files.
  47      * @var string
  48      */
  49      protected $plupload_upload_path;
  50  
  51      /**
  52      * Constructor.
  53      *
  54      * @param string $phpbb_root_path The root path
  55      * @param \phpbb\config\config $config The config
  56      */
  57  	public function __construct($phpbb_root_path, \phpbb\config\config $config)
  58      {
  59          $this->phpbb_root_path = $phpbb_root_path;
  60          $this->config = $config;
  61  
  62          $this->plupload_upload_path = $this->phpbb_root_path . $this->config['upload_path'] . '/plupload';
  63      }
  64  
  65      /**
  66      * {@inheritDoc}
  67      */
  68  	public function run()
  69      {
  70          // Remove old temporary file (perhaps failed uploads?)
  71          $last_valid_timestamp = time() - $this->max_file_age;
  72          try
  73          {
  74              $iterator = new \DirectoryIterator($this->plupload_upload_path);
  75              foreach ($iterator as $file)
  76              {
  77                  if (strpos($file->getBasename(), $this->config['plupload_salt']) !== 0)
  78                  {
  79                      // Skip over any non-plupload files.
  80                      continue;
  81                  }
  82  
  83                  if ($file->getMTime() < $last_valid_timestamp)
  84                  {
  85                      @unlink($file->getPathname());
  86                  }
  87              }
  88          }
  89          catch (\UnexpectedValueException $e)
  90          {
  91              add_log(
  92                  'critical',
  93                  'LOG_PLUPLOAD_TIDY_FAILED',
  94                  $this->plupload_upload_path,
  95                  $e->getMessage(),
  96                  $e->getTraceAsString()
  97              );
  98          }
  99  
 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  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1