8cfa42594aded54d813eb3dfa69bc34d7f26c1f3
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / File / InitUpdateWizard.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2012 Tolleiv Nietsch <info@tolleiv.de>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Upgrade wizard which creates all sys_file* tables. Required to ensure that all
27 * other FAL migration wizards can run properly.
28 *
29 * @package TYPO3
30 * @author Tolleiv Nietsch <info@tolleiv.de>
31 * @license http://www.gnu.org/copyleft/gpl.html
32 */
33 class Tx_Install_Updates_File_InitUpdateWizard extends Tx_Install_Updates_Base {
34 /**
35 * @var string
36 */
37 protected $title = 'Initialize FAL tables';
38
39 /**
40 * @var t3lib_install_Sql
41 */
42 protected $installerSql;
43
44 /**
45 * Creates this object.
46 */
47 public function __construct() {
48 $this->installerSql = t3lib_div::makeInstance('t3lib_install_Sql');
49 }
50
51 /**
52 * Checks if an update is needed
53 *
54 * @param string &$description: The description for the update
55 * @return boolean TRUE if an update is needed, FALSE otherwise
56 */
57 public function checkForUpdate(&$description) {
58 $description = 'Create the tables which are required for the file abstraction layer.';
59 return count($this->getRequiredUpdates()) > 0;
60 }
61
62 /**
63 * Performs the database update.
64 *
65 * @param array &$dbQueries: queries done in this update
66 * @param mixed &$customMessages: custom messages
67 * @return boolean TRUE on success, FALSE on error
68 */
69 public function performUpdate(&$dbQueries, &$customMessages) {
70 $updates = $this->getRequiredUpdates();
71 foreach ($updates as $update) {
72 $GLOBALS['TYPO3_DB']->admin_query($update);
73 $dbQueries[] = $update;
74 }
75 return TRUE;
76 }
77
78
79 /**
80 * Determine all create table statements which create the sys_file* tables
81 *
82 * @return array
83 */
84 protected function getRequiredUpdates() {
85 $requiredUpdates = array();
86
87 $fileContent = t3lib_div::getUrl(PATH_t3lib . 'stddb/tables.sql');
88 $FDfile = $this->installerSql->getFieldDefinitions_fileContent($fileContent);
89 $FDdb = $this->installerSql->getFieldDefinitions_database(TYPO3_db);
90 $diff = $this->installerSql->getDatabaseExtra($FDfile, $FDdb);
91 $update_statements = $this->installerSql->getUpdateSuggestions($diff);
92
93 foreach ((array) $update_statements['create_table'] as $string) {
94 if (preg_match('/^CREATE TABLE sys_file($|_)/', $string)) {
95 $requiredUpdates[] = $string;
96 }
97 }
98
99 return $requiredUpdates;
100 }
101 }
102
103 ?>