[BUGFIX] SQL error in install tool if no root page available
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / NotInMenuUpdate.php
1 <?php
2 namespace TYPO3\CMS\Install\Updates;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Sebastian Kurfürst <sebastian@garbage-group.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 not in menu pages.
32 * Used by the update wizard in the install tool.
33 *
34 * @author Sebastian Kurfürst <sebastian@garbage-group.de>
35 * @author Steffen Kamper <info@sk-typo3.de>
36 */
37 class NotInMenuUpdate extends AbstractUpdate {
38
39 /**
40 * @var string
41 */
42 protected $title = 'Update Pages with Doktype "Not in menu"';
43
44 /**
45 * Checks if an update is needed
46 *
47 * @param string &$description The description for the update
48 * @return boolean Whether an update is needed (TRUE) or not (FALSE)
49 */
50 public function checkForUpdate(&$description) {
51 $result = FALSE;
52 $description = 'Removes the deprecated pages doktype "Not in menu". It sets the successing flag "Not in menu" for the corresponding pages instead.';
53 if ($this->versionNumber >= 4002000) {
54 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', 'doktype=5', '', '', '1');
55 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
56 $result = TRUE;
57 }
58 $GLOBALS['TYPO3_DB']->sql_free_result($res);
59 }
60 return $result;
61 }
62
63 /**
64 * Performs the database update. Changes the doktype from 5 ("not in menu") to 1 (standard) and sets the "nav_hide" flag to 1
65 *
66 * @param array &$dbQueries Queries done in this update
67 * @param mixed &$customMessages Custom messages
68 * @return boolean Whether it worked (TRUE) or not (FALSE)
69 */
70 public function performUpdate(array &$dbQueries, &$customMessages) {
71 $result = FALSE;
72 if ($this->versionNumber >= 4002000) {
73 $updateArray = array(
74 'doktype' => 1,
75 'nav_hide' => 1
76 );
77 $res = $GLOBALS['TYPO3_DB']->exec_UPDATEquery('pages', 'doktype=5', $updateArray);
78 $dbQueries[] = str_replace(chr(10), ' ', $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery);
79 if ($GLOBALS['TYPO3_DB']->sql_error()) {
80 $customMessages = 'SQL-ERROR: ' . htmlspecialchars($GLOBALS['TYPO3_DB']->sql_error());
81 } else {
82 $result = TRUE;
83 }
84 }
85 return $result;
86 }
87
88 }
89
90 ?>