[TASK] Migrate extension install upgrade wizards to new API
[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\ExtensionManagementUtility;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20
21 /**
22 * Installs and downloads EXT:rdct if cache_md5params is filled
23 */
24 class RedirectExtractionUpdate extends AbstractDownloadExtensionUpdate
25 {
26 /**
27 * @var \TYPO3\CMS\Install\Updates\ExtensionModel
28 */
29 protected $extension;
30
31 /**
32 * @var \TYPO3\CMS\Install\Updates\Confirmation
33 */
34 protected $confirmation;
35
36 public function __construct()
37 {
38 $this->extension = new ExtensionModel(
39 'rdct',
40 'Redirects based on &RDCT parameter',
41 '1.0.0',
42 'friendsoftypo3/rdct',
43 'The extension provides redirects based on "cache_md5params" and the GET parameter &RDCT for extensions that still rely on it.'
44 );
45
46 $this->confirmation = new Confirmation(
47 'Are you sure?',
48 'You should install the Redirects extension only if needed. ' . $this->extension->getDescription(),
49 false
50 );
51 }
52
53 /**
54 * Return a confirmation message instance
55 *
56 * @return \TYPO3\CMS\Install\Updates\Confirmation
57 */
58 public function getConfirmation(): Confirmation
59 {
60 return $this->confirmation;
61 }
62
63 /**
64 * Return the identifier for this wizard
65 * This should be the same string as used in the ext_localconf class registration
66 *
67 * @return string
68 */
69 public function getIdentifier(): string
70 {
71 return 'rdctExtension';
72 }
73
74 /**
75 * Return the speaking name of this wizard
76 *
77 * @return string
78 */
79 public function getTitle(): string
80 {
81 return 'Install extension "rdct" from TER if DB table cache_md5params is filled';
82 }
83
84 /**
85 * Return the description for this wizard
86 *
87 * @return string
88 */
89 public function getDescription(): string
90 {
91 return 'The extension "rdct" includes redirects based on the GET parameter &RDCT. The functionality has been extracted to'
92 . ' the TYPO3 Extension Repository. This update downloads the TYPO3 extension from the TER.'
93 . ' Use this if you are dealing with extensions in the instance that rely on this kind of redirects.';
94 }
95
96 /**
97 * Is an update necessary?
98 * Is used to determine whether a wizard needs to be run.
99 *
100 * @return bool
101 */
102 public function updateNecessary(): bool
103 {
104 return !ExtensionManagementUtility::isLoaded('rdct') && $this->checkIfWizardIsRequired();
105 }
106
107 /**
108 * Check if the database table "cache_md5params" exists and if so, if there are entries in the DB table.
109 *
110 * @return bool
111 * @throws \InvalidArgumentException
112 */
113 protected function checkIfWizardIsRequired(): bool
114 {
115 $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
116 $connection = $connectionPool->getConnectionByName('Default');
117 $tableNames = $connection->getSchemaManager()->listTableNames();
118 if (in_array('cache_md5params', $tableNames, true)) {
119 // table is available, now check if there are entries in it
120 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
121 ->getQueryBuilderForTable('cache_md5params');
122 $numberOfEntries = $queryBuilder->count('*')
123 ->from('cache_md5params')
124 ->execute()
125 ->fetchColumn();
126 return (bool)$numberOfEntries;
127 }
128
129 return false;
130 }
131
132 /**
133 * Returns an array of class names of Prerequisite classes
134 * This way a wizard can define dependencies like "database up-to-date" or
135 * "reference index updated"
136 *
137 * @return string[]
138 */
139 public function getPrerequisites(): array
140 {
141 return [
142 DatabaseUpdatedPrerequisite::class
143 ];
144 }
145 }