[BUGFIX] SQL error in install tool if no root page available
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / FlagsFromSpriteUpdate.php
1 <?php
2 namespace TYPO3\CMS\Install\Updates;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 Ernesto Baschny <ernst@cron-it.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * Contains the update class for transitioning from ".gif" flags to sprites
32 *
33 * @author Ernesto Baschny <ernst@cron-it.de>
34 */
35 class FlagsFromSpriteUpdate extends AbstractUpdate {
36
37 /**
38 * @var string
39 */
40 protected $title = 'Update Graphics, Using Sprites for sys_language Records';
41
42 /**
43 * Checks if an update is needed
44 *
45 * @param string &$description The description for the update
46 * @return boolean Whether an update is needed (TRUE) or not (FALSE)
47 */
48 public function checkForUpdate(&$description) {
49 $result = FALSE;
50 $description = 'Removes the ".gif" suffix from entries in sys_language, because flags now come from a sprite provided by t3skin and not individual .gif files.';
51 if ($this->versionNumber >= 4005000) {
52 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'sys_language', 'flag LIKE \'%.gif\'', '', '', '1');
53 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
54 $result = TRUE;
55 }
56 $GLOBALS['TYPO3_DB']->sql_free_result($res);
57 }
58 return $result;
59 }
60
61 /**
62 * Performs the database update. Changes the flags from ".gif" to flag without suffix
63 *
64 * @param array &$dbQueries Queries done in this update
65 * @param mixed &$customMessages Custom messages
66 * @return boolean Whether it worked (TRUE) or not (FALSE)
67 */
68 public function performUpdate(array &$dbQueries, &$customMessages) {
69 $result = FALSE;
70 if ($this->versionNumber >= 4005000) {
71 $sql = 'UPDATE sys_language SET flag=REPLACE(flag, \'.gif\', \'\') WHERE flag LIKE \'%.gif\'';
72 $res = $GLOBALS['TYPO3_DB']->sql_query($sql);
73 $dbQueries[] = $sql;
74 if ($GLOBALS['TYPO3_DB']->sql_error()) {
75 $customMessages = 'SQL-ERROR: ' . htmlspecialchars($GLOBALS['TYPO3_DB']->sql_error());
76 } else {
77 $result = TRUE;
78 }
79 $sql = 'UPDATE sys_language SET flag=\'multiple\' WHERE flag=\'multi-language\'';
80 $res = $GLOBALS['TYPO3_DB']->sql_query($sql);
81 $dbQueries[] = $sql;
82 if ($GLOBALS['TYPO3_DB']->sql_error()) {
83 $customMessages = 'SQL-ERROR: ' . htmlspecialchars($GLOBALS['TYPO3_DB']->sql_error());
84 } else {
85 $result = TRUE;
86 }
87 }
88 return $result;
89 }
90
91 }
92
93 ?>