1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Superdesk Web Publisher Updater Bundle. |
5
|
|
|
* |
6
|
|
|
* Copyright 2015 Sourcefabric z.u. and contributors. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please see the |
9
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @copyright 2015 Sourcefabric z.ú. |
12
|
|
|
* @license http://www.superdesk.org/license |
13
|
|
|
*/ |
14
|
|
|
namespace SWP\UpdaterBundle\Controller; |
15
|
|
|
|
16
|
|
|
use FOS\RestBundle\Controller\FOSRestController; |
17
|
|
|
use Nelmio\ApiDocBundle\Annotation\ApiDoc; |
18
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
19
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
20
|
|
|
use FOS\RestBundle\View\View; |
21
|
|
|
|
22
|
|
|
class UpdaterController extends FOSRestController |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Downloads all available updates to the server on which current |
26
|
|
|
* app instance is running. Downloaded update packages, by default will be saved |
27
|
|
|
* to 'app/cache/{env}' directory, until defined differently in bundle config. |
28
|
|
|
* |
29
|
|
|
* @ApiDoc( |
30
|
|
|
* resource=true, |
31
|
|
|
* description="Downloads updates", |
32
|
|
|
* statusCodes={ |
33
|
|
|
* 200="Returned on success.", |
34
|
|
|
* 404="Returned when file could not be found at specified url." |
35
|
|
|
* } |
36
|
|
|
* ) |
37
|
|
|
* @Route("/api/updates/download/{resource}", options={"expose"=true}) |
38
|
|
|
* @Method("GET") |
39
|
|
|
*/ |
40
|
|
|
public function downloadAction($resource) |
41
|
|
|
{ |
42
|
|
|
$updater = $this->container->get('swp_updater.manager'); |
43
|
|
|
$downloadedUpdates = $updater->download($resource); |
44
|
|
|
|
45
|
|
|
return $this->handleView(View::create(array( |
46
|
|
|
'_status' => 'OK', |
47
|
|
|
'_items' => $downloadedUpdates, |
48
|
|
|
), 200)); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Installs all available updates for given resource (e.g. core, plugin etc). |
53
|
|
|
* If the updating process fails, it rollback all the changes and throws |
54
|
|
|
* Exception with status code 500. |
55
|
|
|
* |
56
|
|
|
* @ApiDoc( |
57
|
|
|
* resource=true, |
58
|
|
|
* description="Installs all available updates.", |
59
|
|
|
* statusCodes={ |
60
|
|
|
* 200="Returned on success.", |
61
|
|
|
* 404="Returned when fupdate package could not be found.", |
62
|
|
|
* 422="Returned when given resource doesn't exist.", |
63
|
|
|
* 500="Returned when instance could not be updated." |
64
|
|
|
* } |
65
|
|
|
* ) |
66
|
|
|
* @Route("/api/updates/install/{resource}", options={"expose"=true}) |
67
|
|
|
* @Method("POST") |
68
|
|
|
*/ |
69
|
|
|
public function installAction($resource) |
70
|
|
|
{ |
71
|
|
|
$updater = $this->container->get('swp_updater.manager'); |
72
|
|
|
$updater->applyUpdates($resource); |
73
|
|
|
|
74
|
|
|
return $this->handleView(View::create(array( |
75
|
|
|
'_status' => 'OK', |
76
|
|
|
'_items' => $updater->getAvailableUpdates(), |
77
|
|
|
'previous_version' => $updater->getCurrentVersion(), |
78
|
|
|
'current_version' => $updater->getLatestVersion(), |
79
|
|
|
), 200)); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Gets all availbale updates which can be downloaded and installed. |
84
|
|
|
* Updates can be fetched by diffrent channels: security, default, nightly. |
85
|
|
|
* * security - security updates, |
86
|
|
|
* * default - default updates (stable ones), |
87
|
|
|
* * nightly - not stable updates. |
88
|
|
|
* |
89
|
|
|
* @ApiDoc( |
90
|
|
|
* resource=true, |
91
|
|
|
* description="Gets all availbale updates.", |
92
|
|
|
* statusCodes={ |
93
|
|
|
* 200="Returned when updates are available.", |
94
|
|
|
* 404="Returned when updates are not available." |
95
|
|
|
* } |
96
|
|
|
* ) |
97
|
|
|
* @Route("/api/updates/{channel}", options={"expose"=true}) |
98
|
|
|
* @Method("GET") |
99
|
|
|
*/ |
100
|
|
|
public function getAction($channel = '') |
101
|
|
|
{ |
102
|
|
|
$updater = $this->container->get('swp_updater.manager'); |
103
|
|
|
|
104
|
|
|
return $this->handleView(View::create(array( |
105
|
|
|
'_items' => $updater->getAvailableUpdates($channel), |
106
|
|
|
), 200)); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Gets the latest available update package which can be applied |
111
|
|
|
* to the current application. |
112
|
|
|
* |
113
|
|
|
* @ApiDoc( |
114
|
|
|
* resource=true, |
115
|
|
|
* description="Gets the latest available update package." |
116
|
|
|
* ) |
117
|
|
|
* @Route("/api/updates/latest/", options={"expose"=true}) |
118
|
|
|
* @Method("GET") |
119
|
|
|
*/ |
120
|
|
|
public function latestAction() |
121
|
|
|
{ |
122
|
|
|
$updater = $this->container->get('swp_updater.manager'); |
123
|
|
|
|
124
|
|
|
return $this->handleView(View::create($updater->getLatestUpdate(), 200)); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|