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
ftp_file_updater
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 7
132
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 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 close
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 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 / 6
0.00% covered (danger)
0.00%
0 / 1
20
 update_file
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 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 FTP updates
20 */
21class ftp_file_updater implements file_updater_interface
22{
23    /**
24     * @var \transfer|null
25     */
26    protected $transfer;
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->transfer            = 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     * Initialize FTP connection
60     *
61     * @param string    $method
62     * @param string    $host
63     * @param string    $user
64     * @param string    $pass
65     * @param string    $path
66     * @param int        $port
67     * @param int        $timeout
68     */
69    public function init($method, $host, $user, $pass, $path, $port, $timeout)
70    {
71        $this->update_helper->include_file('includes/functions_transfer.' . $this->php_ext);
72        $this->transfer = new $method($host, $user, $pass, $path, $port, $timeout);
73        $this->transfer->open_session();
74    }
75
76    /**
77     * Close FTP session
78     */
79    public function close()
80    {
81        $this->transfer->close_session();
82    }
83
84    /**
85     * {@inheritdoc}
86     */
87    public function delete_file($path_to_file)
88    {
89        $this->transfer->delete_file($path_to_file);
90    }
91
92    /**
93     * {@inheritdoc}
94     */
95    public function create_new_file($path_to_file_to_create, $source, $create_from_content = false)
96    {
97        $dirname = dirname($path_to_file_to_create);
98
99        if ($dirname && !file_exists($this->phpbb_root_path . $dirname))
100        {
101            $this->transfer->make_dir($dirname);
102        }
103
104        if ($create_from_content)
105        {
106            $this->transfer->write_file($path_to_file_to_create, $source);
107        }
108        else
109        {
110            $this->transfer->copy_file($path_to_file_to_create, $source);
111        }
112    }
113
114    /**
115     * {@inheritdoc}
116     */
117    public function update_file($path_to_file_to_update, $source, $create_from_content = false)
118    {
119        if ($create_from_content)
120        {
121            $this->transfer->write_file($path_to_file_to_update, $source);
122        }
123        else
124        {
125            $this->transfer->copy_file($path_to_file_to_update, $source);
126        }
127    }
128
129    /**
130     * {@inheritdoc}
131     */
132    public function get_method_name()
133    {
134        return 'ftp';
135    }
136}