DownloadsController::homeAction()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 9.376
c 0
b 0
f 0
cc 4
nc 4
nop 2
1
<?php
2
/**
3
 *
4
 * @copyright (c) 2014 phpBB Group
5
 * @license http://opensource.org/licenses/gpl-3.0.php GNU General Public License v3
6
 * @author MichaelC
7
 *
8
 */
9
10
namespace AppBundle\Controller;
11
12
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
13
use AppBundle\Utilities\DownloadManager;
14
use Symfony\Component\HttpFoundation\Request;
15
use AppBundle\Entity\Download;
16
17
class DownloadsController extends Controller
18
{
19
	public function homeAction(Request $request, $branch = '3.1')
20
	{
21
		$downloadManager = $this->get('phpbb.downloadManager');
22
		$downloadManager->setBranch($branch);
23
24
		// Find out if we are updating files and if we are, from what version
25
		$mode = ($request->get('update', 0)) ? 'update' : 'stable';
26
27
		$selected_version = $request->get('version', '');
28
		if (!empty($selected_version) && $mode == 'update')
29
		{
30
			$downloadManager->setUpdate($selected_version);
31
		}
32
33
		$packagesInfo = $downloadManager->generatePackages();
34
35
		$packages = $packagesInfo['packages'];
36
		$versions = $packagesInfo['updateFromVersions'];
37
38
		$templateVariables = array(
39
			'versions' => $versions,
40
			'packages' => $packages,
41
		);
42
43
		$content = $this->renderView('AppBundle::downloads.html.twig', $templateVariables);
44
		$response = new Response($content);
45
46
		// Set caching headers
47
		$response->headers->set('X-Cache-Download-Json', $packagesInfo['caching'][0]);
48
		$response->headers->set('X-Cache-Download-Hashes', $packagesInfo['caching'][1]);
49
		$response->headers->set('X-Cache-Download-Packages', $packagesInfo['caching'][2]);
50
51
		return $response;
52
	}
53
54
	// public function downloadHandlerAction(Request $request, $package)
55
	// {
56
	// 	$download = new Download();
57
	// 	$download->setConfigurableOptions($package, $request->getClientIp());
58
	// 	$em = $this->getDoctrine()->getManager();
59
	// 	$em->persist($download);
60
	// 	$em->flush();
61
62
	// 	return $this->redirect(('https://download.phpbb.com/pub/release/' . $package), 301);
63
	// }
64
65
	// public function downloadRedirectHandlerAction(Request $request, $branch = 'latest')
66
	// {
67
	// 	$downloadManager = $this->get('phpbb.downloadManager');
68
	// 	$branch = ($branch == 'latest') ? '3.1' : $branch;
69
	// 	$downloadManager->setBranch($branch);
70
	// 	return $this->downloadHandlerAction($request, $downloadManager->getMainPackageName);
71
	// }
72
}
73