[TASK] Re-work/simplify copyright header in PHP files - Part 2
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / InitUpdateWizard.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 /**
18 * Upgrade wizard which creates all sys_file* tables. Required to ensure that all
19 * other FAL migration wizards can run properly.
20 *
21 * @author Tolleiv Nietsch <info@tolleiv.de>
22 */
23 class InitUpdateWizard extends AbstractUpdate {
24
25 /**
26 * @var string
27 */
28 protected $title = 'Initialize database tables for the File Abstraction Layer (FAL)';
29
30 /**
31 * @var \TYPO3\CMS\Install\Service\SqlSchemaMigrationService
32 */
33 protected $installerSql;
34
35 /**
36 * Creates this object.
37 */
38 public function __construct() {
39 $this->installerSql = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Install\\Service\\SqlSchemaMigrationService');
40 }
41
42 /**
43 * Checks if an update is needed
44 *
45 * @param string &$description The description for the update
46 * @return boolean TRUE if an update is needed, FALSE otherwise
47 */
48 public function checkForUpdate(&$description) {
49 $description = 'Create the database tables which are required for the File Abstraction Layer in order to work. Do this as the first step for all further wizards related to FAL.';
50 return count($this->getRequiredUpdates()) > 0;
51 }
52
53 /**
54 * Performs the database update.
55 *
56 * @param array &$dbQueries Queries done in this update
57 * @param mixed &$customMessages Custom messages
58 * @return boolean TRUE on success, FALSE on error
59 */
60 public function performUpdate(array &$dbQueries, &$customMessages) {
61 $updates = $this->getRequiredUpdates();
62 foreach ($updates as $update) {
63 $GLOBALS['TYPO3_DB']->admin_query($update);
64 $dbQueries[] = $update;
65 }
66 return TRUE;
67 }
68
69 /**
70 * Determine all create table statements which create the sys_file* tables
71 *
72 * @return array
73 */
74 protected function getRequiredUpdates() {
75 $requiredUpdates = array();
76 $fileContent = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl(
77 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('core'). 'ext_tables.sql'
78 );
79 $FDfile = $this->installerSql->getFieldDefinitions_fileContent($fileContent);
80 $FDdb = $this->installerSql->getFieldDefinitions_database(TYPO3_db);
81 $diff = $this->installerSql->getDatabaseExtra($FDfile, $FDdb);
82 $update_statements = $this->installerSql->getUpdateSuggestions($diff);
83 foreach ((array) $update_statements['create_table'] as $string) {
84 if (preg_match('/^CREATE TABLE sys_file($|_)?/', $string)) {
85 $requiredUpdates[] = $string;
86 }
87 }
88 return $requiredUpdates;
89 }
90
91 }