Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
archive_download
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 4
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 conflict_archive
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 update_archive
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 send_response
0.00% covered (danger)
0.00%
0 / 6
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\controller;
15
16use phpbb\exception\http_exception;
17use phpbb\install\helper\config;
18use Symfony\Component\HttpFoundation\BinaryFileResponse;
19use Symfony\Component\HttpFoundation\ResponseHeaderBag;
20
21class archive_download
22{
23    /**
24     * @var config
25     */
26    protected $installer_config;
27
28    /**
29     * Constructor
30     *
31     * @param config $config
32     */
33    public function __construct(config $config)
34    {
35        $this->installer_config = $config;
36        $this->installer_config->load_config();
37    }
38
39    /**
40     * Sends response with the merge conflict archive
41     *
42     * Merge conflicts always have to be resolved manually,
43     * so we use a different archive for that.
44     *
45     * @return BinaryFileResponse
46     */
47    public function conflict_archive()
48    {
49        $filename = $this->installer_config->get('update_file_conflict_archive', '');
50
51        if (empty($filename))
52        {
53            throw new http_exception(404, 'URL_NOT_FOUND');
54        }
55
56        return $this->send_response($filename);
57    }
58
59    /**
60     * Sends response with the updated files' archive
61     *
62     * @return BinaryFileResponse
63     */
64    public function update_archive()
65    {
66        $filename = $this->installer_config->get('update_file_archive', '');
67
68        if (empty($filename))
69        {
70            throw new http_exception(404, 'URL_NOT_FOUND');
71        }
72
73        return $this->send_response($filename);
74    }
75
76    /**
77     * Generates a download response
78     *
79     * @param string    $filename    Path to the file to download
80     *
81     * @return BinaryFileResponse    Response object
82     */
83    private function send_response($filename)
84    {
85        $response = new BinaryFileResponse($filename);
86        $response->setContentDisposition(
87            ResponseHeaderBag::DISPOSITION_ATTACHMENT,
88            basename($filename)
89        );
90
91        return $response;
92    }
93}