Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
compression_file_updater
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 7
110
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 init
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
6
 close
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 delete_file
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 create_new_file
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 update_file
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_method_name
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
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
14namespace phpbb\install\helper\file_updater;
15
16use phpbb\install\helper\update_helper;
17
18/**
19 * File updater for generating archive with updated files
20 */
21class compression_file_updater implements file_updater_interface
22{
23    /**
24     * @var \compress_zip|\compress_tar|null
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        if ($this->compress !== null)
90        {
91            $this->compress->close();
92        }
93    }
94
95    /**
96     * {@inheritdoc}
97     */
98    public function delete_file($path_to_file)
99    {
100        // We do absolutely nothing here, as this function is called when a file should be
101        // removed from the filesystem, but since this is an archive generator, it clearly
102        // cannot do that.
103    }
104
105    /**
106     * {@inheritdoc}
107     */
108    public function create_new_file($path_to_file_to_create, $source, $create_from_content = false)
109    {
110        if ($create_from_content)
111        {
112            $this->compress->add_data($source, $path_to_file_to_create);
113        }
114        else
115        {
116            $this->compress->add_custom_file($source, $path_to_file_to_create);
117        }
118    }
119
120    /**
121     * {@inheritdoc}
122     */
123    public function update_file($path_to_file_to_update, $source, $create_from_content = false)
124    {
125        // Both functions are identical here
126        $this->create_new_file($path_to_file_to_update, $source, $create_from_content);
127    }
128
129    /**
130     * {@inheritdoc}
131     */
132    public function get_method_name()
133    {
134        return 'compression';
135    }
136}