[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/phpbb/install/helper/file_updater/ -> compression_file_updater.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\install\helper\file_updater;
  15  
  16  use phpbb\install\helper\update_helper;
  17  
  18  /**
  19   * File updater for generating archive with updated files
  20   */
  21  class compression_file_updater implements file_updater_interface
  22  {
  23      /**
  24       * @var \compress
  25       */
  26      protected $compress;
  27  
  28      /**
  29       * @var update_helper
  30       */
  31      protected $update_helper;
  32  
  33      /**
  34       * @var string
  35       */
  36      protected $phpbb_root_path;
  37  
  38      /**
  39       * @var string
  40       */
  41      protected $php_ext;
  42  
  43      /**
  44       * Constructor
  45       *
  46       * @param update_helper    $update_helper
  47       * @param string        $phpbb_root_path
  48       * @param string        $php_ext
  49       */
  50  	public function __construct(update_helper $update_helper, $phpbb_root_path, $php_ext)
  51      {
  52          $this->compress            = null;
  53          $this->update_helper    = $update_helper;
  54          $this->phpbb_root_path    = $phpbb_root_path;
  55          $this->php_ext            = $php_ext;
  56      }
  57  
  58      /**
  59       * Set the compression method
  60       *
  61       * @param string    $method    Compression method's file extension
  62       *
  63       * @return string    Archive's filename
  64       */
  65  	public function init($method)
  66      {
  67          $this->update_helper->include_file('includes/functions_compress.' . $this->php_ext);
  68  
  69          $archive_filename = 'update_archive_' . time() . '_' . uniqid();
  70          $path = $this->phpbb_root_path . 'store/' . $archive_filename . '' . $method;
  71  
  72          if ($method === '.zip')
  73          {
  74              $this->compress = new \compress_zip('w', $path);
  75          }
  76          else
  77          {
  78              $this->compress = new \compress_tar('w', $path, $method);
  79          }
  80  
  81          return $path;
  82      }
  83  
  84      /**
  85       * Close archive writing process
  86       */
  87  	public function close()
  88      {
  89          $this->compress->close();
  90      }
  91  
  92      /**
  93       * {@inheritdoc}
  94       */
  95  	public function delete_file($path_to_file)
  96      {
  97          // We do absolutely nothing here, as this function is called when a file should be
  98          // removed from the filesystem, but since this is an archive generator, it clearly
  99          // cannot do that.
 100      }
 101  
 102      /**
 103       * {@inheritdoc}
 104       */
 105  	public function create_new_file($path_to_file_to_create, $source, $create_from_content = false)
 106      {
 107          if ($create_from_content)
 108          {
 109              $this->compress->add_data($source, $path_to_file_to_create);
 110          }
 111          else
 112          {
 113              $this->compress->add_custom_file($source, $path_to_file_to_create);
 114          }
 115      }
 116  
 117      /**
 118       * {@inheritdoc}
 119       */
 120  	public function update_file($path_to_file_to_update, $source, $create_from_content = false)
 121      {
 122          // Both functions are identical here
 123          $this->create_new_file($path_to_file_to_update, $source, $create_from_content);
 124      }
 125  
 126      /**
 127       * {@inheritdoc}
 128       */
 129  	public function get_method_name()
 130      {
 131          return 'compression';
 132      }
 133  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1