6c7fc89a08aa8a541ebe3c936804948b311e6473
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / AdminPanelInstall.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Install\Updates;
5
6 /*
7 * This file is part of the TYPO3 CMS project.
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22 /**
23 * Installs EXT:adminpanel
24 */
25 class AdminPanelInstall extends AbstractDownloadExtensionUpdate
26 {
27 /**
28 * @var string
29 */
30 protected $title = 'Install extension "adminpanel"';
31
32 /**
33 * @var string
34 */
35 protected $extensionKey = 'adminpanel';
36
37 /**
38 * @var array
39 */
40 protected $extensionDetails = [
41 'adminpanel' => [
42 'title' => 'TYPO3 Admin Panel',
43 'description' => 'The TYPO3 admin panel provides a panel with additional functionality in the frontend (Debugging, Caching, Preview...)',
44 'versionString' => '9.2',
45 'composerName' => 'typo3/cms-adminpanel',
46 ],
47 ];
48
49 /**
50 * Checks if an update is needed
51 *
52 * @param string $description The description for the update
53 * @return bool Whether an update is needed (true) or not (false)
54 */
55 public function checkForUpdate(&$description): bool
56 {
57 $description = 'The TYPO3 admin panel was extracted to an own extension. This update installs the extension.';
58
59 if (ExtensionManagementUtility::isLoaded('adminpanel')) {
60 $this->markWizardAsDone();
61 }
62
63 $updateNeeded = false;
64 if (!$this->isWizardDone()) {
65 $updateNeeded = true;
66 }
67 return $updateNeeded;
68 }
69
70 /**
71 * Second step: Ask user to install the extension
72 *
73 * @param string $inputPrefix input prefix, all names of form fields have to start with this. Append custom name in [ ... ]
74 * @return string HTML output
75 */
76 public function getUserInput($inputPrefix)
77 {
78 return '
79 <div class="panel panel-danger">
80 <div class="panel-heading">Are you really sure?</div>
81 <div class="panel-body">
82 <p>You should install EXT:adminpanel only if you really need it.</p>
83 <p>This update wizard cannot check if the extension was installed before the update.</p>
84 <p>Are you really sure, you want to install EXT:adminpanel?</p>
85 <div class="btn-group clearfix" data-toggle="buttons">
86 <label class="btn btn-default active">
87 <input type="radio" name="' . $inputPrefix . '[install]" value="0" checked="checked" /> no, don\'t install
88 </label>
89 <label class="btn btn-default">
90 <input type="radio" name="' . $inputPrefix . '[install]" value="1" /> yes, please install
91 </label>
92 </div>
93 </div>
94 </div>
95 ';
96 }
97
98 /**
99 * Performs the update
100 *
101 * @param array $databaseQueries Queries done in this update
102 * @param string $customMessage Custom message
103 * @return bool
104 */
105 public function performUpdate(array &$databaseQueries, &$customMessage): bool
106 {
107 $requestParams = GeneralUtility::_GP('install');
108 if (!isset($requestParams['values']['adminpanelExtension']['install'])) {
109 return false;
110 }
111 $install = (int)$requestParams['values']['adminpanelExtension']['install'];
112
113 if ($install === 1) {
114 // user decided to install extension, install and mark wizard as done
115 $updateSuccessful = $this->installExtension($this->extensionKey, $customMessage);
116 if ($updateSuccessful) {
117 $this->markWizardAsDone();
118 return true;
119 }
120 } else {
121 // user decided to not install extension, mark wizard as done
122 $this->markWizardAsDone();
123 return true;
124 }
125 return $updateSuccessful;
126 }
127 }