|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2011 Christian Kuhn <lolli@schwarzbu.ch> 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00027 00028 /** 00029 * Contains the update class to split existing image_link field by comma and 00030 * switch to newlines. 00031 * 00032 * @author Christian Kuhn <lolli@schwarzbu.ch> 00033 */ 00034 class tx_coreupdates_imagelink extends Tx_Install_Updates_Base { 00035 00036 protected $title = 'Update Existing image links'; 00037 00038 00039 /** 00040 * Checks if an update is needed 00041 * 00042 * @param string &$description: The description for the update 00043 * @return boolean True if an update is needed, false otherwise 00044 */ 00045 public function checkForUpdate(&$description) { 00046 $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.'; 00047 00048 $result = FALSE; 00049 if ($this->versionNumber >= 4005000) { 00050 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 00051 'uid', 00052 'tt_content', 00053 'image_link!="" AND image_link LIKE "%,%" AND image_link NOT LIKE "%\\n%"', 00054 '', 00055 '', 00056 '1' 00057 ); 00058 if($GLOBALS['TYPO3_DB']->sql_num_rows($res)) { 00059 $result = TRUE; 00060 } 00061 $GLOBALS['TYPO3_DB']->sql_free_result($res); 00062 } 00063 00064 return $result; 00065 } 00066 00067 /** 00068 * Performs the database update. 00069 * 00070 * @param array &$dbQueries: queries done in this update 00071 * @param mixed &$customMessages: custom messages 00072 * @return boolean True on success, false on error 00073 */ 00074 public function performUpdate(&$dbQueries, &$customMessages) { 00075 $result = TRUE; 00076 if($this->versionNumber >= 4005000) { 00077 $affectedRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( 00078 'uid, image_link', 00079 'tt_content', 00080 'image_link!="" AND image_link LIKE "%,%" AND image_link NOT LIKE "%\\n%"' 00081 ); 00082 00083 foreach ($affectedRows as $row) { 00084 $newImageLink = t3lib_div::trimExplode(',', $row['image_link']); 00085 $newImageLink = implode(LF, $newImageLink); 00086 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tt_content', 'uid=' . $row['uid'], array('image_link' => $newImageLink)); 00087 $dbQueries[] = str_replace(LF, ' ', $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery); 00088 if ($GLOBALS['TYPO3_DB']->sql_error()) { 00089 $customMessages = 'SQL-ERROR: ' . htmlspecialchars($GLOBALS['TYPO3_DB']->sql_error()); 00090 $result = $result & FALSE; 00091 } 00092 } 00093 } 00094 00095 return $result; 00096 } 00097 } 00098 ?>
1.8.0