|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2010-2011 Kai Vogel (kai.vogel(at)speedprogs.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 /** 00030 * Contains the update for group access lists, adds all excludeable FlexForm fields. Used by the update wizard in the install tool. 00031 * 00032 * @author Kai Vogel <kai.vogel(at)speedprogs.de> 00033 */ 00034 class tx_coreupdates_addflexformstoacl extends Tx_Install_Updates_Base { 00035 protected $title = 'Add Excludable FlexForm Fields to Group Access Lists'; 00036 00037 /** 00038 * Checks if FlexForm fields are missing in group access lists. 00039 * 00040 * @param string &$description The description for the update 00041 * @return boolean Whether an update is required (true) or not (false) 00042 */ 00043 public function checkForUpdate(&$description) { 00044 $description = ' 00045 <br />TYPO3 4.5 introduced the possibility to exclude FlexForm fields like normal fields in group access control lists (ACL). 00046 All excludeable fields will be hidden for non-admins if you do not add them to the ACL of each user group manually or with 00047 this update wizard. 00048 '; 00049 00050 // Check access lists 00051 if (!$this->getGroupAddFields()) { 00052 return FALSE; 00053 } 00054 00055 return TRUE; 00056 } 00057 00058 /** 00059 * Get user confirmation 00060 * 00061 * @param string $inputPrefix The input prefix, all names of form fields have to start with this 00062 * @return string HTML output 00063 */ 00064 public function getUserInput($inputPrefix) { 00065 $description = ' 00066 <br />You are about to update group access control lists to include excludable FlexForm fields. Each backend group will be checked 00067 and only those that already have entries in the access control lists will be updated. 00068 '; 00069 00070 return $description; 00071 } 00072 00073 /** 00074 * Performs the action of the UpdateManager 00075 * 00076 * @param array &$dbQueries Queries done in this update 00077 * @param mixed &$customMessages Custom messages 00078 * @return boolean Whether update was successful or not 00079 */ 00080 public function performUpdate(array &$dbQueries, &$customMessages) { 00081 // Get additional FlexForm fields for group access lists 00082 $addFields = $this->getGroupAddFields(); 00083 if (empty($addFields)) { 00084 $customMessages = 'No missing FlexForm fields found!'; 00085 return FALSE; 00086 } 00087 00088 return $this->updateGroupAccessLists($addFields, $dbQueries, $customMessages); 00089 } 00090 00091 /** 00092 * Get all FlexForm fields which must be added to group access lists 00093 * 00094 * @return array Additional FlexForm fields for ACL 00095 */ 00096 protected function getGroupAddFields() { 00097 $addFields = array(); 00098 $contentTable = (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']) ? $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'] : 'tt_content'); 00099 00100 // Initialize TCA if not loaded yet 00101 if (empty($GLOBALS['TCA'])) { 00102 $this->pObj->includeTCA(); 00103 } 00104 00105 // Get all access lists from groups which are allowed to select or modify the content-table 00106 $search = $GLOBALS['TYPO3_DB']->escapeStrForLike($contentTable, 'be_groups'); 00107 $where = 'deleted = 0 AND non_exclude_fields IS NOT NULL AND non_exclude_fields != ""'; 00108 $where .= ' AND (tables_select LIKE "%' . $search . '%" OR tables_modify LIKE "%' . $search . '%")'; 00109 $accessLists = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid, non_exclude_fields', 'be_groups', $where); 00110 if(empty($accessLists)) { 00111 return array(); 00112 } 00113 00114 // Get all excludeable FlexForm fields from content-table 00115 $flexExcludeFields = array(); 00116 $flexFormArray = t3lib_BEfunc::getRegisteredFlexForms($contentTable); 00117 if (!empty($flexFormArray) && is_array($flexFormArray)) { 00118 foreach ($flexFormArray as $tableField => $flexForms) { 00119 // Get all sheets 00120 foreach ($flexForms as $flexFormIdentifier => $flexFormConfig) { 00121 // Get all excludeable fields in sheet 00122 foreach ($flexFormConfig['ds']['sheets'] as $sheetName => $sheet) { 00123 if (empty($sheet['ROOT']['el']) || !is_array($sheet['ROOT']['el'])) { 00124 continue; 00125 } 00126 foreach ($sheet['ROOT']['el'] as $fieldName => $field) { 00127 if (empty($field['TCEforms']['exclude'])) { 00128 continue; 00129 } 00130 $flexExcludeFields[] = $contentTable . ':' . $tableField . ';' . $flexFormIdentifier . ';' . $sheetName . ';' . $fieldName; 00131 } 00132 } 00133 } 00134 } 00135 } 00136 if (empty($flexExcludeFields)) { 00137 return array(); 00138 } 00139 00140 // Get FlexForm fields from access lists 00141 foreach ($accessLists as $accessList) { 00142 $nonExcludeFields = t3lib_div::trimExplode(',', $accessList['non_exclude_fields']); 00143 if (empty($nonExcludeFields)) { 00144 continue; 00145 } 00146 // Add FlexForm fields only if the field was not already selected by a user 00147 $nonExcludeFields = array_diff($flexExcludeFields, $nonExcludeFields); 00148 if (!empty($nonExcludeFields) && $nonExcludeFields == $flexExcludeFields) { 00149 $addFields[$accessList['uid']] = $nonExcludeFields; 00150 } 00151 } 00152 00153 return $addFields; 00154 } 00155 00156 /** 00157 * Update Backend user groups, add FlexForm fields to access list 00158 * 00159 * @param array $addFields All missing FlexForm fields by groups 00160 * @param array &$dbQueries Queries done in this update 00161 * @param mixed &$customMessages Custom messages 00162 * @return boolean Whether update was successful or not 00163 */ 00164 protected function updateGroupAccessLists(array $addFields, array &$dbQueries, &$customMessages) { 00165 foreach ($addFields as $groupUID => $flexExcludeFields) { 00166 // First get current fields 00167 $result = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('non_exclude_fields', 'be_groups', 'uid=' . (int) $groupUID); 00168 if (!isset($result['non_exclude_fields'])) { 00169 continue; 00170 } 00171 $nonExcludeFields = $result['non_exclude_fields']; 00172 00173 // Now add new ones 00174 $flexExcludeFields = implode(',', $flexExcludeFields); 00175 $nonExcludeFields = trim($nonExcludeFields . ',' . $flexExcludeFields, ', '); 00176 00177 // Finally override with new fields 00178 $GLOBALS['TYPO3_DB']->exec_UPDATEquery( 00179 'be_groups', 00180 'uid=' . (int) $groupUID, 00181 array('non_exclude_fields' => $nonExcludeFields) 00182 ); 00183 00184 // Get last executed query 00185 $dbQueries[] = str_replace(chr(10), ' ', $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery); 00186 00187 // Check for errors 00188 if ($GLOBALS['TYPO3_DB']->sql_error()) { 00189 $customMessages = 'SQL-ERROR: ' . htmlspecialchars($GLOBALS['TYPO3_DB']->sql_error()); 00190 return FALSE; 00191 } 00192 } 00193 00194 return TRUE; 00195 } 00196 00197 } 00198 00199 ?>
1.8.0