|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2011 Susanne Moog <typo3@susanne-moog.de> 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 for the split of css styled content templates. Used by the update wizard in the install tool. 00030 * 00031 * @author Susanne Moog <typo3@susanne-moog.de> 00032 * @version $Id: class.tx_coreupdates_cscsplit.php 10120 2011-01-18 20:03:36Z ohader $ 00033 */ 00034 class tx_coreupdates_cscsplit extends Tx_Install_Updates_Base { 00035 protected $title = 'Split TypoScript Templates from CSS Styled Content'; 00036 00037 /** 00038 * Function which checks if update is needed. Called in the beginning of an update process. 00039 * 00040 * @param string pointer to description for the update 00041 * @return boolean true if update is needs to be performed, false otherwise. 00042 */ 00043 function checkForUpdate(&$description) { 00044 $templates = $this->getTemplatesWithCsc($dbQueries, $customMessages); 00045 $templates = $this->findUpdateableTemplatesWithCsc($templates); 00046 if (count($templates)) { 00047 $description = '<p>Run this wizard if you use CSS styled content in your templates, as the inclusion of the static templates changed. </p>' . 00048 '<p>You are currently using CSS styled content in <strong>' . count($templates) . ' templates</strong> (including deleted and hidden),' . 00049 ' so if you did not run this wizard before, <strong>do it now</strong>.</p>' . 00050 '<p>The wizard will automatically choose the right template according to your compatibility version. So if you want to ' . 00051 'change the rendering back to an older version, you will have to use the changeCompatibilityVersion wizard above ' . 00052 'first, and then return back to this one.</p>'; 00053 return true; 00054 } 00055 return false; 00056 } 00057 00058 /** 00059 * Performs the update itself 00060 * 00061 * @param array pointer where to insert all DB queries made, so they can be shown to the user if wanted 00062 * @param string pointer to output custom messages 00063 * @return boolean true if update succeeded, false otherwise 00064 */ 00065 function performUpdate(&$dbQueries, &$customMessages) { 00066 $templates = $this->getTemplatesWithCsc($dbQueries, $customMessages); 00067 $templates = $this->findUpdateableTemplatesWithCsc($templates); 00068 $this->updateCscTemplates($templates, $dbQueries, $customMessages); 00069 if ($customMessages) { 00070 return false; 00071 } else { 00072 return true; 00073 } 00074 } 00075 00076 /** 00077 * Gets the templates that include the static css styled content template 00078 * 00079 * @param array pointer where to insert all DB queries made, so they can be shown to the user if wanted 00080 * @param string pointer to output custom messages 00081 * @return array uid and inclusion string for the templates, that include csc 00082 */ 00083 function getTemplatesWithCsc(&$dbQueries, &$customMessages) { 00084 $fields = 'uid, include_static_file'; 00085 $table = 'sys_template'; 00086 $where = 'include_static_file LIKE "%EXT:css_styled_content/static/%"'; 00087 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where); 00088 00089 $dbQueries[] = str_replace(chr(10), ' ', $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery); 00090 00091 if ($GLOBALS['TYPO3_DB']->sql_error()) { 00092 $customMessages = 'SQL-ERROR: ' . htmlspecialchars($GLOBALS['TYPO3_DB']->sql_error()); 00093 } 00094 00095 $templates = array(); 00096 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00097 $templates[] = $row; 00098 } 00099 return $templates; 00100 } 00101 00102 /** 00103 * Take a list of templates and filter them if they need an update or not 00104 * 00105 * @param array uid and inclusion string for the templates, that include csc 00106 * @return array uid and inclusion string for the templates, that include csc and need an update 00107 */ 00108 function findUpdateableTemplatesWithCsc($allTemplates) { 00109 $compatVersion = t3lib_div::int_from_ver($GLOBALS['TYPO3_CONF_VARS']['SYS']['compat_version']); 00110 $currentVersion = t3lib_div::int_from_ver(TYPO3_branch); 00111 00112 $templatesCount = count($allTemplates); 00113 $updateableTemplates = array(); 00114 for ($i = 0; $i < $templatesCount; $i++) { 00115 $templateNeedsUpdate = false; 00116 $includedTemplates = explode(',', $allTemplates[$i]['include_static_file']); 00117 $includedTemplatesCount = count($includedTemplates); 00118 // loop through every entry in the "include static file" 00119 for ($j = 0; $j < $includedTemplatesCount; $j++) { 00120 if (strpos($includedTemplates[$j], 'css_styled_content') !== false) { 00121 if ($compatVersion <= t3lib_div::int_from_ver('3.8')) { 00122 if ($includedTemplates[$j] != 'EXT:css_styled_content/static/v3.8/') { 00123 $includedTemplates[$j] = 'EXT:css_styled_content/static/v3.8/'; 00124 $templateNeedsUpdate = true; 00125 } 00126 } elseif ($compatVersion <= t3lib_div::int_from_ver('4.1')) { 00127 if ($includedTemplates[$j] != 'EXT:css_styled_content/static/v3.9/') { 00128 $includedTemplates[$j] = 'EXT:css_styled_content/static/v3.9/'; 00129 $templateNeedsUpdate = true; 00130 } 00131 } elseif ($compatVersion <= t3lib_div::int_from_ver('4.2')) { 00132 if ($includedTemplates[$j] != 'EXT:css_styled_content/static/v4.2/') { 00133 $includedTemplates[$j] = 'EXT:css_styled_content/static/v4.2/'; 00134 $templateNeedsUpdate = true; 00135 } 00136 } elseif ($compatVersion <= t3lib_div::int_from_ver('4.3')) { 00137 if ($includedTemplates[$j] != 'EXT:css_styled_content/static/v4.3/') { 00138 $includedTemplates[$j] = 'EXT:css_styled_content/static/v4.3/'; 00139 $templateNeedsUpdate = true; 00140 } 00141 } elseif ($compatVersion <= t3lib_div::int_from_ver('4.4')) { 00142 if ($includedTemplates[$j] != 'EXT:css_styled_content/static/v4.4/') { 00143 $includedTemplates[$j] = 'EXT:css_styled_content/static/v4.4/'; 00144 $templateNeedsUpdate = true; 00145 } 00146 } elseif ($compatVersion === $currentVersion || $compatVersion > '4.5') { 00147 if ($includedTemplates[$j] != 'EXT:css_styled_content/static/') { 00148 $includedTemplates[$j] = 'EXT:css_styled_content/static/'; 00149 $templateNeedsUpdate = true; 00150 } 00151 } 00152 } 00153 } 00154 $allTemplates[$i]['include_static_file'] = implode(',', $includedTemplates); 00155 if ($templateNeedsUpdate) { 00156 $updateableTemplates[] = $allTemplates[$i]; 00157 } 00158 } 00159 return $updateableTemplates; 00160 } 00161 00162 00163 /** 00164 * updates the template records to include the new css styled content templates, according to the current compat version 00165 * 00166 * @param array template records to update, fetched by getTemplates() and filtered by 00167 * @param array pointer where to insert all DB queries made, so they can be shown to the user if wanted 00168 * @param string pointer to output custom messages 00169 */ 00170 function updateCscTemplates($templates, &$dbQueries, &$customMessages) { 00171 foreach ($templates as $template) { 00172 $table = 'sys_template'; 00173 $where = 'uid =' . $template['uid']; 00174 $field_values = array( 00175 'include_static_file' => $template['include_static_file'] 00176 ); 00177 00178 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, $where, $field_values); 00179 $dbQueries[] = str_replace(chr(10), ' ', $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery); 00180 00181 if ($GLOBALS['TYPO3_DB']->sql_error()) { 00182 $customMessages = 'SQL-ERROR: ' . htmlspecialchars($GLOBALS['TYPO3_DB']->sql_error()); 00183 } 00184 } 00185 } 00186 } 00187 ?>
1.8.0