e31db5d22f94c517cc3e0ecb8ffc78484ff28089
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / RedirectExtractionUpdate.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\Utility\GeneralUtility;
19
20 /**
21 * Installs and downloads EXT:rdct if cache_md5params is filled
22 */
23 class RedirectExtractionUpdate extends AbstractDownloadExtensionUpdate
24 {
25 /**
26 * @var string
27 */
28 protected $title = 'Install extension "rdct" from TER if DB table cache_md5params is filled';
29
30 /**
31 * @var string
32 */
33 protected $extensionKey = 'rdct';
34
35 /**
36 * @var array
37 */
38 protected $extensionDetails = [
39 'rdct' => [
40 'title' => 'Redirects based on &RDCT parameter',
41 'description' => 'Provides redirects based on "cache_md5params" and the GET parameter &RDCT for extensions that still rely on it.',
42 'versionString' => '1.0.0',
43 'composerName' => 'friendsoftypo3/rdct',
44 ],
45 ];
46
47 /**
48 * Checks if an update is needed
49 *
50 * @param string $description The description for the update
51 * @return bool Whether an update is needed (true) or not (false)
52 */
53 public function checkForUpdate(&$description)
54 {
55 $description = 'The extension "rdct" includes redirects based on the GET parameter &RDCT. The functionality has been extracted to'
56 . ' the TYPO3 Extension Repository. This update downloads the TYPO3 extension from the TER.'
57 . ' Use this if you are dealing with extensions in the instance that rely on this kind of redirects.';
58
59 $updateNeeded = false;
60
61 // Check if table exists and table is not empty, and the wizard has not been run already
62 if ($this->checkIfWizardIsRequired() && !$this->isWizardDone()) {
63 $updateNeeded = true;
64 }
65
66 return $updateNeeded;
67 }
68
69 /**
70 * Second step: Ask user to install the extension
71 *
72 * @param string $inputPrefix input prefix, all names of form fields have to start with this. Append custom name in [ ... ]
73 * @return string HTML output
74 */
75 public function getUserInput($inputPrefix)
76 {
77 return '
78 <div class="panel panel-danger">
79 <div class="panel-heading">Are you really sure?</div>
80 <div class="panel-body">
81 <p>You should install EXT:rdct only if you really need it.</p>
82 <p>If you have never heard of index.php?RDCT then we are 99% confident that you don\'t need to install this extension.</p>
83 <p>Are you really sure, you want to install EXT:rdct?</p>
84 <div class="btn-group clearfix" data-toggle="buttons">
85 <label class="btn btn-default active">
86 <input type="radio" name="' . $inputPrefix . '[install]" value="0" checked="checked" /> no, don\'t install
87 </label>
88 <label class="btn btn-default">
89 <input type="radio" name="' . $inputPrefix . '[install]" value="1" /> yes, please install
90 </label>
91 </div>
92 </div>
93 </div>
94 ';
95 }
96
97 /**
98 * Performs the update if EXT:rdct should be installed.
99 *
100 * @param array $databaseQueries Queries done in this update
101 * @param string $customMessage Custom message
102 * @return bool
103 */
104 public function performUpdate(array &$databaseQueries, &$customMessage)
105 {
106 $requestParams = GeneralUtility::_GP('install');
107 if (!isset($requestParams['values']['rdctExtension']['install'])) {
108 return false;
109 }
110 $install = (int)$requestParams['values']['rdctExtension']['install'];
111
112 $updateSuccessful = true;
113 if ($install === 1) {
114 // user decided to install extension, install and mark wizard as done
115 $updateSuccessful = $this->installExtension($this->extensionKey, $customMessage);
116 }
117 if ($updateSuccessful) {
118 $this->markWizardAsDone();
119 }
120 return $updateSuccessful;
121 }
122
123 /**
124 * Check if the database table "cache_md5params" exists and if so, if there are entries in the DB table.
125 *
126 * @return bool
127 * @throws \InvalidArgumentException
128 */
129 protected function checkIfWizardIsRequired(): bool
130 {
131 $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
132 $connection = $connectionPool->getConnectionByName('Default');
133 $tableNames = $connection->getSchemaManager()->listTableNames();
134 if (in_array('cache_md5params', $tableNames, true)) {
135 // table is available, now check if there are entries in it
136 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
137 ->getQueryBuilderForTable('cache_md5params');
138 $numberOfEntries = $queryBuilder->count('*')
139 ->from('cache_md5params')
140 ->execute()
141 ->fetchColumn();
142 return (bool)$numberOfEntries;
143 }
144
145 return false;
146 }
147 }