Fixed bug #16426: Link field for images is too short to provide links for every image...
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / updates / class.tx_coreupdates_imagelink.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2011 Christian Kuhn <lolli@schwarzbu.ch>
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 2 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 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Contains the update class to split existing image_link field by comma and
30 * switch to newlines.
31 *
32 * @author Christian Kuhn <lolli@schwarzbu.ch>
33 */
34 class tx_coreupdates_imagelink extends Tx_Install_Updates_Base {
35
36 protected $title = 'Update Existing image links';
37
38
39 /**
40 * Checks if an update is needed
41 *
42 * @param string &$description: The description for the update
43 * @return boolean True if an update is needed, false otherwise
44 */
45 public function checkForUpdate(&$description) {
46 $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.';
47
48 $result = FALSE;
49 if ($this->versionNumber >= 4005000) {
50 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
51 'uid',
52 'tt_content',
53 'image_link!="" AND image_link LIKE "%,%" AND image_link NOT LIKE "%\\n%"',
54 '',
55 '',
56 '1'
57 );
58 if($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
59 $result = TRUE;
60 }
61 $GLOBALS['TYPO3_DB']->sql_free_result($res);
62 }
63
64 return $result;
65 }
66
67 /**
68 * Performs the database update.
69 *
70 * @param array &$dbQueries: queries done in this update
71 * @param mixed &$customMessages: custom messages
72 * @return boolean True on success, false on error
73 */
74 public function performUpdate(&$dbQueries, &$customMessages) {
75 $result = TRUE;
76 if($this->versionNumber >= 4005000) {
77 $affectedRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
78 'uid, image_link',
79 'tt_content',
80 'image_link!="" AND image_link LIKE "%,%" AND image_link NOT LIKE "%\\n%"'
81 );
82
83 foreach ($affectedRows as $row) {
84 $newImageLink = t3lib_div::trimExplode(',', $row['image_link']);
85 $newImageLink = implode(chr(10), $newImageLink);
86 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tt_content', 'uid=' . $row['uid'], array('image_link' => $newImageLink));
87 $dbQueries[] = str_replace(chr(10), ' ', $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery);
88 if ($GLOBALS['TYPO3_DB']->sql_error()) {
89 $customMessages = 'SQL-ERROR: ' . htmlspecialchars($GLOBALS['TYPO3_DB']->sql_error());
90 $result = $result & FALSE;
91 }
92 }
93 }
94
95 return $result;
96 }
97 }
98 ?>