[TASK] Migrate extension install upgrade wizards to new API
[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 \TYPO3\CMS\Install\Updates\Confirmation
29 */
30 protected $confirmation;
31
32 public function __construct()
33 {
34 $this->extension = new ExtensionModel(
35 'form_legacy',
36 'Legacy form extension for TYPO3 v7 compatibility',
37 '8.7.0',
38 'friendsoftypo3/form-legacy',
39 'Provides an additional backwards-compatibility layer with legacy functionality for sites that used the form extension in TYPO3 v7.'
40 );
41
42 $this->confirmation = new Confirmation(
43 'Are you really sure, you want to install EXT:form_legacy?',
44 'You should install EXT:form_legacy only if you really need it.'
45 . 'This update wizard checked all content elements and found at least one not deleted element based'
46 . 'on the old form module. It is advised to manually convert those elements from the old form implementation'
47 . 'to the new implementation of EXT:form. EXT:form_legacy should be unloaded and removed afterwards.',
48 true
49 );
50 }
51
52 /**
53 * Return a confirmation message instance
54 *
55 * @return \TYPO3\CMS\Install\Updates\Confirmation
56 */
57 public function getConfirmation(): Confirmation
58 {
59 return $this->confirmation;
60 }
61
62 /**
63 * Return the identifier for this wizard
64 * This should be the same string as used in the ext_localconf class registration
65 *
66 * @return string
67 */
68 public function getIdentifier(): string
69 {
70 return 'formLegacyExtractionUpdate';
71 }
72
73 /**
74 * Return the speaking name of this wizard
75 *
76 * @return string
77 */
78 public function getTitle(): string
79 {
80 return 'Install extension "form_legacy"';
81 }
82
83 /**
84 * Return the description for this wizard
85 *
86 * @return string
87 */
88 public function getDescription(): string
89 {
90 return 'The extension "form" was rewritten in TYPO3 v8 and follows a new approach.'
91 . 'This update downloads the old implementation of the form extension as known from TYPO3 v7 from the TER.';
92 }
93
94 /**
95 * Is an update necessary?
96 * Is used to determine whether a wizard needs to be run.
97 *
98 * @return bool
99 */
100 public function updateNecessary(): bool
101 {
102 $updateNeeded = false;
103
104 if (!ExtensionManagementUtility::isLoaded('form_legacy')) {
105 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
106 $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
107 $count = $queryBuilder
108 ->count('*')
109 ->from('tt_content')
110 ->where($queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('mailform')))
111 ->execute()
112 ->fetchColumn(0);
113 if ($count > 0) {
114 $updateNeeded = true;
115 }
116 }
117 return $updateNeeded;
118 }
119
120 /**
121 * Returns an array of class names of Prerequisite classes
122 * This way a wizard can define dependencies like "database up-to-date" or
123 * "reference index updated"
124 *
125 * @return string[]
126 */
127 public function getPrerequisites(): array
128 {
129 return [
130 DatabaseUpdatedPrerequisite::class
131 ];
132 }
133 }