[BUGFIX] SQL error in install tool if no root page available
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / ImagelinkUpdate.php
1 <?php
2 namespace TYPO3\CMS\Install\Updates;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011-2013 Christian Kuhn <lolli@schwarzbu.ch>
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 to split existing image_link field by comma and
32 * switch to newlines.
33 *
34 * @author Christian Kuhn <lolli@schwarzbu.ch>
35 */
36 class ImagelinkUpdate extends AbstractUpdate {
37
38 /**
39 * @var string
40 */
41 protected $title = 'Update Existing image links';
42
43 /**
44 * Checks if an update is needed
45 *
46 * @param string &$description The description for the update
47 * @return boolean TRUE if an update is needed, FALSE otherwise
48 */
49 public function checkForUpdate(&$description) {
50 $description = 'Since TYPO3 4.5 links to images of "Image" and "Text with image" content elements are separated by newline and not by comma anymore. This update converts existing comma separated links to the new form.';
51 $result = FALSE;
52 if ($this->versionNumber >= 4005000) {
53 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
54 'uid',
55 'tt_content',
56 'image_link<>\'\' AND image_link LIKE \'%,%\' AND image_link NOT LIKE \'%\\n%\'',
57 '',
58 '',
59 '1'
60 );
61 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
62 $result = TRUE;
63 }
64 $GLOBALS['TYPO3_DB']->sql_free_result($res);
65 }
66 return $result;
67 }
68
69 /**
70 * Performs the database update.
71 *
72 * @param array &$dbQueries Queries done in this update
73 * @param mixed &$customMessages Custom messages
74 * @return boolean TRUE on success, FALSE on error
75 */
76 public function performUpdate(array &$dbQueries, &$customMessages) {
77 $result = TRUE;
78 if ($this->versionNumber >= 4005000) {
79 $affectedRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
80 'uid, image_link',
81 'tt_content',
82 'image_link<>\'\' AND image_link LIKE \'%,%\' AND image_link NOT LIKE \'%\\n%\''
83 );
84 foreach ($affectedRows as $row) {
85 $newImageLink = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $row['image_link']);
86 $newImageLink = implode(LF, $newImageLink);
87 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tt_content', 'uid=' . $row['uid'], array('image_link' => $newImageLink));
88 $dbQueries[] = str_replace(LF, ' ', $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery);
89 if ($GLOBALS['TYPO3_DB']->sql_error()) {
90 $customMessages = 'SQL-ERROR: ' . htmlspecialchars($GLOBALS['TYPO3_DB']->sql_error());
91 $result = $result & FALSE;
92 }
93 }
94 }
95 return $result;
96 }
97
98 }
99
100 ?>