11c9f35447be8155f964724fd875794a80731698
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / FormLegacyExtractionUpdate.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\Database\ConnectionPool;
18 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
19 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22 /**
23 * Installs and downloads EXT:form_legacy if needed
24 */
25 class FormLegacyExtractionUpdate extends AbstractDownloadExtensionUpdate
26 {
27 /**
28 * @var string
29 */
30 protected $title = 'Install extension "form_legacy" from TER';
31
32 /**
33 * @var string
34 */
35 protected $extensionKey = 'form_legacy';
36
37 /**
38 * @var array
39 */
40 protected $extensionDetails = [
41 'form_legacy' => [
42 'title' => 'Legacy form extension for TYPO3 v7 compatibility',
43 'description' => 'Provides an additional backwards-compatibility layer with legacy functionality for sites that used the form extension in TYPO3 v7.',
44 'versionString' => '8.7.0',
45 'composerName' => 'friendsoftypo3/form-legacy',
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)
56 {
57 $description = 'The extension "form" was rewritten in TYPO3 v8 and follows a new approach.'
58 . 'This update downloads the old implementation of the form extension as known from TYPO3 v7 from the TER.';
59
60 $updateNeeded = false;
61
62 if (!$this->isWizardDone() && !ExtensionManagementUtility::isLoaded('form_legacy')) {
63 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
64 $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
65 $count = $queryBuilder
66 ->count('*')
67 ->from('tt_content')
68 ->where($queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('mailform')))
69 ->execute()
70 ->fetchColumn(0);
71 if ($count > 0) {
72 $updateNeeded = true;
73 }
74 }
75
76 return $updateNeeded;
77 }
78
79 /**
80 * Second step: Ask user to install the extension
81 *
82 * @param string $inputPrefix input prefix, all names of form fields have to start with this. Append custom name in [ ... ]
83 * @return string HTML output
84 */
85 public function getUserInput($inputPrefix)
86 {
87 return '
88 <div class="panel panel-danger">
89 <div class="panel-heading">Are you really sure?</div>
90 <div class="panel-body">
91 <p>You should install EXT:form_legacy only if you really need it.</p>
92 <p>This update wizard checked all content elements and found at least one not deleted element based
93 on the old form module. It is advised to manually convert those elements from the old form implementation
94 to the new implementation of EXT:form. EXT:form_legacy should be unloaded and removed afterwards.</p>
95 <p>Are you really sure, you want to install EXT:form_legacy?</p>
96 <div class="btn-group clearfix" data-toggle="buttons">
97 <label class="btn btn-default active">
98 <input type="radio" name="' . $inputPrefix . '[install]" value="0" checked="checked" /> no, don\'t install
99 </label>
100 <label class="btn btn-default">
101 <input type="radio" name="' . $inputPrefix . '[install]" value="1" /> yes, please install
102 </label>
103 </div>
104 </div>
105 </div>
106 ';
107 }
108
109 /**
110 * Performs the update if EXT:form_legacy should be installed.
111 *
112 * @param array $databaseQueries Queries done in this update
113 * @param string $customMessage Custom message
114 * @return bool
115 */
116 public function performUpdate(array &$databaseQueries, &$customMessage)
117 {
118 $requestParams = GeneralUtility::_GP('install');
119 if (!isset($requestParams['values']['formLegacyExtractionUpdate']['install'])) {
120 return false;
121 }
122 $install = (int)$requestParams['values']['formLegacyExtractionUpdate']['install'];
123
124 if ($install === 1) {
125 // user decided to install extension, install and mark wizard as done
126 $updateSuccessful = $this->installExtension($this->extensionKey, $customMessage);
127 if ($updateSuccessful) {
128 $this->markWizardAsDone();
129 return true;
130 }
131 } else {
132 // user decided to not install extension, mark wizard as done
133 $this->markWizardAsDone();
134 return true;
135 }
136 return $updateSuccessful;
137 }
138 }