[BUGFIX] Fix automatic core updater
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Controller / Action / Ajax / CoreUpdateIsUpdateAvailable.php
1 <?php
2 namespace TYPO3\CMS\Install\Controller\Action\Ajax;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Christian Kuhn <lolli@schwarzbu.ch>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Check if a younger version is available
29 */
30 class CoreUpdateIsUpdateAvailable extends AbstractCoreUpdate {
31
32 /**
33 * Executes the action
34 *
35 * @return array Rendered content
36 */
37 protected function executeAction() {
38 $status = array();
39 if ($this->coreVersionService->isInstalledVersionAReleasedVersion()) {
40 $isDevelopmentUpdateAvailable = $this->coreVersionService->isYoungerPatchDevelopmentReleaseAvailable();
41 $isUpdateAvailable = $this->coreVersionService->isYoungerPatchReleaseAvailable();
42 $isUpdateSecurityRelevant = $this->coreVersionService->isUpdateSecurityRelevant();
43
44 if (!$isUpdateAvailable && !$isDevelopmentUpdateAvailable) {
45 $status = $this->getMessage('notice', 'No regular update available');
46 } elseif ($isUpdateAvailable) {
47 $newVersion = $this->coreVersionService->getYoungestPatchRelease();
48 if ($isUpdateSecurityRelevant) {
49 $status = $this->getMessage('warning', 'Update to security relevant released version ' . $newVersion . ' is available!');
50 $action = $this->getAction('Update now', 'updateRegular');
51 } else {
52 $status = $this->getMessage('info', 'Update to regular released version ' . $newVersion . ' is available!');
53 $action = $this->getAction('Update now', 'updateRegular');
54 }
55 } elseif ($isDevelopmentUpdateAvailable) {
56 $newVersion = $this->coreVersionService->getYoungestPatchDevelopmentRelease();
57 $status = $this->getMessage('info', 'Update to development release ' . $newVersion . ' is available!');
58 $action = $this->getAction('Update now', 'updateDevelopment');
59 }
60 } else {
61 $status = $this->getMessage('warning', 'Current version is a development version and can not be updated');
62 }
63
64 $this->view->assign('success', TRUE);
65 $this->view->assign('status', array($status));
66 if (isset($action)) {
67 $this->view->assign('action', $action);
68 }
69
70 return $this->view->render();
71 }
72
73 /**
74 * @param string $severity
75 * @param string $title
76 * @param string $message
77 * @return \TYPO3\CMS\Install\Status\StatusInterface
78 */
79 protected function getMessage($severity, $title, $message = '') {
80 /** @var $statusMessage \TYPO3\CMS\Install\Status\StatusInterface */
81 $statusMessage = $this->objectManager->get('TYPO3\\CMS\\Install\\Status\\' . ucfirst($severity) . 'Status');
82 $statusMessage->setTitle($title);
83 $statusMessage->setMessage($message);
84
85 return $statusMessage;
86 }
87
88 /**
89 * @param string $title
90 * @param string $action
91 * @return array
92 */
93 protected function getAction($title, $action) {
94 return array(
95 'title' => $title,
96 'action' => $action,
97 );
98 }
99 }