1<?php 2namespace 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 17use TYPO3\CMS\Core\Database\ConnectionPool; 18use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction; 19use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; 20use TYPO3\CMS\Core\Utility\GeneralUtility; 21 22/** 23 * Installs and downloads EXT:form_legacy if needed 24 * @internal This class is only meant to be used within EXT:install and is not part of the TYPO3 Core API. 25 */ 26class FormLegacyExtractionUpdate extends AbstractDownloadExtensionUpdate 27{ 28 /** 29 * @var \TYPO3\CMS\Install\Updates\Confirmation 30 */ 31 protected $confirmation; 32 33 public function __construct() 34 { 35 $this->extension = new ExtensionModel( 36 'form_legacy', 37 'Legacy form extension for TYPO3 v7 compatibility', 38 '8.7.0', 39 'friendsoftypo3/form-legacy', 40 'Provides an additional backwards-compatibility layer with legacy functionality for sites that used the form extension in TYPO3 v7.' 41 ); 42 43 $this->confirmation = new Confirmation( 44 'Are you really sure, you want to install EXT:form_legacy?', 45 'You should install EXT:form_legacy only if you really need it.' 46 . 'This update wizard checked all content elements and found at least one not deleted element based' 47 . 'on the old form module. It is advised to manually convert those elements from the old form implementation' 48 . 'to the new implementation of EXT:form. EXT:form_legacy should be unloaded and removed afterwards.', 49 true 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 'formLegacyExtractionUpdate'; 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 "form_legacy"'; 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 "form" was rewritten in TYPO3 v8 and follows a new approach.' 92 . 'This update downloads the old implementation of the form extension as known from TYPO3 v7 from the TER.'; 93 } 94 95 /** 96 * Is an update necessary? 97 * Is used to determine whether a wizard needs to be run. 98 * 99 * @return bool 100 */ 101 public function updateNecessary(): bool 102 { 103 $updateNeeded = false; 104 105 if (!ExtensionManagementUtility::isLoaded('form_legacy')) { 106 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content'); 107 $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class)); 108 $count = $queryBuilder 109 ->count('*') 110 ->from('tt_content') 111 ->where($queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('mailform'))) 112 ->execute() 113 ->fetchColumn(0); 114 if ($count > 0) { 115 $updateNeeded = true; 116 } 117 } 118 return $updateNeeded; 119 } 120 121 /** 122 * Returns an array of class names of Prerequisite classes 123 * This way a wizard can define dependencies like "database up-to-date" or 124 * "reference index updated" 125 * 126 * @return string[] 127 */ 128 public function getPrerequisites(): array 129 { 130 return [ 131 DatabaseUpdatedPrerequisite::class 132 ]; 133 } 134} 135