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