1 | <?php |
||
23 | class UpdateManager extends AbstractManager |
||
24 | { |
||
25 | const UPDATES_ENDPOINT = '/check.json'; |
||
26 | const CORE_ENDPOINT = '/core.json'; |
||
27 | const LATEST_VERSION_ENDPOINT = '/latest_version.json'; |
||
28 | |||
29 | const RESOURCE_CORE = 'core'; |
||
30 | |||
31 | /** |
||
32 | * Available updates channels. |
||
33 | * |
||
34 | * @var array |
||
35 | */ |
||
36 | private $channels = array('default', 'security', 'nightly'); |
||
37 | |||
38 | /** |
||
39 | * Latest update. |
||
40 | * |
||
41 | * @var UpdatePackage |
||
42 | */ |
||
43 | private $latestUpdate; |
||
44 | |||
45 | /** |
||
46 | * List of available updates. |
||
47 | * |
||
48 | * @var array |
||
49 | */ |
||
50 | private $availableUpdates = array(); |
||
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | public function getAvailableUpdates($channel = '') |
||
56 | { |
||
57 | $response = $this->client->call( |
||
58 | self::UPDATES_ENDPOINT, |
||
59 | array( |
||
60 | 'coreVersion' => $this->getCurrentVersion(), |
||
61 | 'channel' => in_array($channel, $this->channels) ? $channel : $this->channels[0], |
||
62 | ) |
||
63 | ); |
||
64 | |||
65 | $response = $this->parseJson($response); |
||
66 | if (isset($response['_items']) && !empty($response['_items'])) { |
||
67 | foreach ($response['_items'] as $key => $resource) { |
||
68 | foreach ($resource as $value) { |
||
69 | $this->availableUpdates[$key][] = new UpdatePackage($value); |
||
70 | } |
||
71 | } |
||
72 | } |
||
73 | |||
74 | if (empty($this->availableUpdates)) { |
||
75 | throw new NotFoundHttpException('No update packages available.'); |
||
76 | } |
||
77 | |||
78 | return $this->availableUpdates; |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * {@inheritdoc} |
||
83 | */ |
||
84 | public function getCurrentVersion() |
||
88 | |||
89 | /** |
||
90 | * Gets the latest version. |
||
91 | * |
||
92 | * @return string|null Latest version |
||
93 | */ |
||
94 | public function getLatestVersion() |
||
101 | |||
102 | /** |
||
103 | * {@inheritdoc} |
||
104 | */ |
||
105 | public function getLatestUpdate() |
||
114 | |||
115 | /** |
||
116 | * Downloads core updates to the directory |
||
117 | * defined in the config.yml. Defaults to: cache. |
||
118 | */ |
||
119 | public function downloadCoreUpdates() |
||
125 | |||
126 | /** |
||
127 | * Downloads available updates to the app instance |
||
128 | * (see temp_dir configuration option), by default to app's cache folder. |
||
129 | * |
||
130 | * @param string $resource Resource type (e.g. core, plugin etc.) |
||
131 | * |
||
132 | * @throws UnprocessableEntityHttpException When resource doesn't exist |
||
133 | */ |
||
134 | public function download($resource) |
||
149 | |||
150 | /** |
||
151 | * Apply available updates to the app by given resource. |
||
152 | * |
||
153 | * @param string $resource Resource type (e.g. core, plugin etc.) |
||
154 | * |
||
155 | * @throws UnprocessableEntityHttpException When resource doesn't exist |
||
156 | */ |
||
157 | public function applyUpdates($resource) |
||
172 | |||
173 | /** |
||
174 | * Updates the core by calling Updater "update" command. |
||
175 | * |
||
176 | * @throws NotFoundHttpException When update package not found |
||
177 | * @throws \RuntimeException When upgrading failed |
||
178 | */ |
||
179 | public function updateCore() |
||
209 | |||
210 | private function cleanUp($packagePath) |
||
216 | |||
217 | private function parseJson($jsonString) |
||
226 | } |
||
227 |