PageRenderTime 71ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/t3lib/class.t3lib_tcemain.php

https://github.com/andreaswolf/typo3-tceforms
PHP | 7085 lines | 4581 code | 643 blank | 1861 comment | 1047 complexity | 045c1a13fbd34f0f6beaaf0e90c98cfc MD5 | raw file
Possible License(s): Apache-2.0, BSD-2-Clause, LGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /***************************************************************
  3. * Copyright notice
  4. *
  5. * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
  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. * Contains the TYPO3 Core Engine
  29. *
  30. * $Id$
  31. * Revised for TYPO3 3.9 October 2005 by Kasper Skårhøj
  32. *
  33. * @author Kasper Skårhøj <kasperYYYY@typo3.com>
  34. */
  35. /**
  36. * [CLASS/FUNCTION INDEX of SCRIPT]
  37. *
  38. *
  39. *
  40. * 242: class t3lib_TCEmain
  41. * 367: function start($data,$cmd,$altUserObject='')
  42. * 406: function setMirror($mirror)
  43. * 431: function setDefaultsFromUserTS($userTS)
  44. * 454: function process_uploads($postFiles)
  45. * 492: function process_uploads_traverseArray(&$outputArr,$inputArr,$keyToSet)
  46. *
  47. * SECTION: PROCESSING DATA
  48. * 528: function process_datamap()
  49. * 886: function placeholderShadowing($table,$id)
  50. * 929: function fillInFieldArray($table,$id,$fieldArray,$incomingFieldArray,$realPid,$status,$tscPID)
  51. *
  52. * SECTION: Evaluation of input values
  53. * 1152: function checkValue($table,$field,$value,$id,$status,$realPid,$tscPID)
  54. * 1212: function checkValue_SW($res,$value,$tcaFieldConf,$table,$id,$curValue,$status,$realPid,$recFID,$field,$uploadedFiles,$tscPID)
  55. * 1261: function checkValue_input($res,$value,$tcaFieldConf,$PP,$field='')
  56. * 1299: function checkValue_check($res,$value,$tcaFieldConf,$PP)
  57. * 1322: function checkValue_radio($res,$value,$tcaFieldConf,$PP)
  58. * 1348: function checkValue_group_select($res,$value,$tcaFieldConf,$PP,$uploadedFiles,$field)
  59. * 1458: function checkValue_group_select_file($valueArray,$tcaFieldConf,$curValue,$uploadedFileArray,$status,$table,$id,$recFID)
  60. * 1632: function checkValue_flex($res,$value,$tcaFieldConf,$PP,$uploadedFiles,$field)
  61. * 1709: function checkValue_flexArray2Xml($array, $addPrologue=FALSE)
  62. * 1721: function _DELETE_FLEX_FORMdata(&$valueArrayToRemoveFrom,$deleteCMDS)
  63. * 1743: function _MOVE_FLEX_FORMdata(&$valueArrayToMoveIn, $moveCMDS, $direction)
  64. * 1783: function checkValue_inline($res,$value,$tcaFieldConf,$PP,$field)
  65. * 1825: function checkValue_checkMax($tcaFieldConf, $valueArray)
  66. *
  67. * SECTION: Helper functions for evaluation functions.
  68. * 1877: function getUnique($table,$field,$value,$id,$newPid=0)
  69. * 1915: function checkValue_input_Eval($value,$evalArray,$is_in)
  70. * 2012: function checkValue_group_select_processDBdata($valueArray,$tcaFieldConf,$id,$status,$type,$currentTable)
  71. * 2058: function checkValue_group_select_explodeSelectGroupValue($value)
  72. * 2082: function checkValue_flex_procInData($dataPart,$dataPart_current,$uploadedFiles,$dataStructArray,$pParams,$callBackFunc='')
  73. * 2121: function checkValue_flex_procInData_travDS(&$dataValues,$dataValues_current,$uploadedFiles,$DSelements,$pParams,$callBackFunc,$structurePath)
  74. *
  75. * SECTION: PROCESSING COMMANDS
  76. * 2267: function process_cmdmap()
  77. *
  78. * SECTION: Cmd: Copying
  79. * 2407: function copyRecord($table,$uid,$destPid,$first=0,$overrideValues=array(),$excludeFields='')
  80. * 2529: function copyPages($uid,$destPid)
  81. * 2583: function copySpecificPage($uid,$destPid,$copyTablesArray,$first=0)
  82. * 2617: function copyRecord_raw($table,$uid,$pid,$overrideArray=array())
  83. * 2681: function rawCopyPageContent($old_pid,$new_pid,$copyTablesArray)
  84. * 2705: function insertNewCopyVersion($table,$fieldArray,$realPid)
  85. * 2757: function copyRecord_procBasedOnFieldType($table,$uid,$field,$value,$row,$conf,$realDestPid)
  86. * 2836: function copyRecord_flexFormCallBack($pParams, $dsConf, $dataValue, $dataValue_ext1, $dataValue_ext2)
  87. * 2864: function copyRecord_procFilesRefs($conf, $uid, $value)
  88. *
  89. * SECTION: Cmd: Moving, Localizing
  90. * 2933: function moveRecord($table,$uid,$destPid)
  91. * 3128: function moveRecord_procFields($table,$uid,$destPid)
  92. * 3148: function moveRecord_procBasedOnFieldType($table,$uid,$destPid,$field,$value,$conf)
  93. * 3182: function localize($table,$uid,$language)
  94. *
  95. * SECTION: Cmd: Deleting
  96. * 3296: function deleteAction($table, $id)
  97. * 3343: function deleteEl($table, $uid, $noRecordCheck=FALSE, $forceHardDelete=FALSE)
  98. * 3360: function deleteVersionsForRecord($table, $uid, $forceHardDelete)
  99. * 3382: function undeleteRecord($table,$uid)
  100. * 3399: function deleteRecord($table,$uid, $noRecordCheck=FALSE, $forceHardDelete=FALSE,$undeleteRecord=FALSE)
  101. * 3512: function deleteRecord_flexFormCallBack($dsArr, $dataValue, $PA, $structurePath, &$pObj)
  102. * 3539: function deletePages($uid,$force=FALSE,$forceHardDelete=FALSE)
  103. * 3567: function deleteSpecificPage($uid,$forceHardDelete=FALSE)
  104. * 3592: function canDeletePage($uid)
  105. * 3619: function cannotDeleteRecord($table,$id)
  106. * 3638: function deleteRecord_procFields($table, $uid, $undeleteRecord = false)
  107. * 3661: function deleteRecord_procBasedOnFieldType($table, $uid, $field, $value, $conf, $undeleteRecord = false)
  108. *
  109. * SECTION: Cmd: Versioning
  110. * 3722: function versionizeRecord($table,$id,$label,$delete=FALSE,$versionizeTree=-1)
  111. * 3798: function versionizePages($uid,$label,$versionizeTree)
  112. * 3861: function version_swap($table,$id,$swapWith,$swapIntoWS=0)
  113. * 4032: function version_clearWSID($table,$id)
  114. * 4066: function version_setStage($table,$id,$stageId,$comment='')
  115. *
  116. * SECTION: Cmd: Helper functions
  117. * 4111: function remapListedDBRecords()
  118. * 4192: function remapListedDBRecords_flexFormCallBack($pParams, $dsConf, $dataValue, $dataValue_ext1, $dataValue_ext2)
  119. * 4219: function remapListedDBRecords_procDBRefs($conf, $value, $MM_localUid, $table)
  120. * 4265: function remapListedDBRecords_procInline($conf, $value, $uid, $table)
  121. *
  122. * SECTION: Access control / Checking functions
  123. * 4308: function checkModifyAccessList($table)
  124. * 4320: function isRecordInWebMount($table,$id)
  125. * 4334: function isInWebMount($pid)
  126. * 4348: function checkRecordUpdateAccess($table,$id)
  127. * 4372: function checkRecordInsertAccess($insertTable,$pid,$action=1)
  128. * 4406: function isTableAllowedForThisPage($page_uid, $checkTable)
  129. * 4439: function doesRecordExist($table,$id,$perms)
  130. * 4504: function doesRecordExist_pageLookUp($id, $perms)
  131. * 4530: function doesBranchExist($inList,$pid,$perms,$recurse)
  132. * 4564: function tableReadOnly($table)
  133. * 4576: function tableAdminOnly($table)
  134. * 4590: function destNotInsideSelf($dest,$id)
  135. * 4622: function getExcludeListArray()
  136. * 4645: function doesPageHaveUnallowedTables($page_uid,$doktype)
  137. *
  138. * SECTION: Information lookup
  139. * 4694: function pageInfo($id,$field)
  140. * 4714: function recordInfo($table,$id,$fieldList)
  141. * 4735: function getRecordProperties($table,$id,$noWSOL=FALSE)
  142. * 4751: function getRecordPropertiesFromRow($table,$row)
  143. *
  144. * SECTION: Storing data to Database Layer
  145. * 4794: function updateDB($table,$id,$fieldArray)
  146. * 4846: function insertDB($table,$id,$fieldArray,$newVersion=FALSE,$suggestedUid=0,$dontSetNewIdIndex=FALSE)
  147. * 4919: function checkStoredRecord($table,$id,$fieldArray,$action)
  148. * 4956: function setHistory($table,$id,$logId)
  149. * 4989: function clearHistory($maxAgeSeconds=604800,$table)
  150. * 5003: function updateRefIndex($table,$id)
  151. *
  152. * SECTION: Misc functions
  153. * 5035: function getSortNumber($table,$uid,$pid)
  154. * 5108: function resorting($table,$pid,$sortRow, $return_SortNumber_After_This_Uid)
  155. * 5139: function setTSconfigPermissions($fieldArray,$TSConfig_p)
  156. * 5156: function newFieldArray($table)
  157. * 5188: function addDefaultPermittedLanguageIfNotSet($table,&$incomingFieldArray)
  158. * 5212: function overrideFieldArray($table,$data)
  159. * 5228: function compareFieldArrayWithCurrentAndUnset($table,$id,$fieldArray)
  160. * 5274: function assemblePermissions($string)
  161. * 5291: function rmComma($input)
  162. * 5301: function convNumEntityToByteValue($input)
  163. * 5323: function destPathFromUploadFolder($folder)
  164. * 5333: function deleteClause($table)
  165. * 5349: function getTCEMAIN_TSconfig($tscPID)
  166. * 5364: function getTableEntries($table,$TSconfig)
  167. * 5377: function getPID($table,$uid)
  168. * 5390: function dbAnalysisStoreExec()
  169. * 5406: function removeRegisteredFiles()
  170. * 5418: function removeCacheFiles()
  171. * 5432: function int_pageTreeInfo($CPtable,$pid,$counter, $rootID)
  172. * 5453: function compileAdminTables()
  173. * 5470: function fixUniqueInPid($table,$uid)
  174. * 5506: function fixCopyAfterDuplFields($table,$uid,$prevUid,$update, $newData=array())
  175. * 5531: function extFileFields($table)
  176. * 5552: function getUniqueFields($table)
  177. * 5577: function isReferenceField($conf)
  178. * 5588: function getInlineFieldType($conf)
  179. * 5611: function getCopyHeader($table,$pid,$field,$value,$count,$prevTitle='')
  180. * 5640: function prependLabel($table)
  181. * 5657: function resolvePid($table,$pid)
  182. * 5687: function clearPrefixFromValue($table,$value)
  183. * 5702: function extFileFunctions($table,$field,$filelist,$func)
  184. * 5732: function noRecordsFromUnallowedTables($inList)
  185. * 5758: function notifyStageChange($stat,$stageId,$table,$id,$comment)
  186. * 5853: function notifyStageChange_getEmails($listOfUsers,$noTablePrefix=FALSE)
  187. *
  188. * SECTION: Clearing cache
  189. * 5899: function clear_cache($table,$uid)
  190. * 6009: function clear_cacheCmd($cacheCmd)
  191. *
  192. * SECTION: Logging
  193. * 6113: function log($table,$recuid,$action,$recpid,$error,$details,$details_nr=-1,$data=array(),$event_pid=-1,$NEWid='')
  194. * 6130: function newlog($message, $error=0)
  195. * 6140: function printLogErrorMessages($redirect)
  196. *
  197. * SECTION: Internal (do not use outside Core!)
  198. * 6202: function internal_clearPageCache()
  199. *
  200. * TOTAL FUNCTIONS: 126
  201. * (This index is automatically created/updated by the extension "extdeveval")
  202. *
  203. */
  204. /**
  205. * This is the TYPO3 Core Engine class for manipulation of the database
  206. * This class is used by eg. the tce_db.php script which provides an the interface for POST forms to this class.
  207. *
  208. * Dependencies:
  209. * - $GLOBALS['TCA'] must exist
  210. * - $GLOBALS['LANG'] must exist
  211. *
  212. * tce_db.php for further comments and SYNTAX! Also see document 'TYPO3 Core API' for details.
  213. *
  214. * @author Kasper Skårhøj <kasperYYYY@typo3.com>
  215. * @package TYPO3
  216. * @subpackage t3lib
  217. */
  218. class t3lib_TCEmain {
  219. // *********************
  220. // Public variables you can configure before using the class:
  221. // *********************
  222. var $storeLogMessages = TRUE; // Boolean: If true, the default log-messages will be stored. This should not be necessary if the locallang-file for the log-display is properly configured. So disabling this will just save some database-space as the default messages are not saved.
  223. var $enableLogging = TRUE; // Boolean: If true, actions are logged to sys_log.
  224. var $reverseOrder = FALSE; // Boolean: If true, the datamap array is reversed in the order, which is a nice thing if you're creating a whole new bunch of records.
  225. var $checkSimilar = TRUE; // Boolean: If true, only fields which are different from the database values are saved! In fact, if a whole input array is similar, it's not saved then.
  226. var $stripslashes_values = TRUE; // Boolean: If true, incoming values in the data-array have their slashes stripped. ALWAYS SET THIS TO ZERO and supply an unescaped data array instead. This switch may totally disappear in future versions of this class!
  227. var $checkStoredRecords = TRUE; // Boolean: This will read the record after having updated or inserted it. If anything is not properly submitted an error is written to the log. This feature consumes extra time by selecting records
  228. var $checkStoredRecords_loose = TRUE; // Boolean: If set, values '' and 0 will equal each other when the stored records are checked.
  229. var $deleteTree = FALSE; // Boolean. If this is set, then a page is deleted by deleting the whole branch under it (user must have deletepermissions to it all). If not set, then the page is deleted ONLY if it has no branch
  230. var $neverHideAtCopy = FALSE; // Boolean. If set, then the 'hideAtCopy' flag for tables will be ignored.
  231. var $dontProcessTransformations = FALSE; // Boolean: If set, then transformations are NOT performed on the input.
  232. var $clear_flexFormData_vDEFbase = FALSE; // Boolean: If set, .vDEFbase values are unset in flexforms.
  233. var $updateModeL10NdiffData = TRUE; // Boolean/Mixed: TRUE: (traditional) Updates when record is saved. For flexforms, updates if change is made to the localized value. FALSE: Will not update anything. "FORCE_FFUPD" (string): Like TRUE, but will force update to the FlexForm Field
  234. var $updateModeL10NdiffDataClear = FALSE; // Boolean: If true, the translation diff. fields will in fact be reset so that they indicate that all needs to change again! It's meant as the opposite of declaring the record translated.
  235. var $bypassWorkspaceRestrictions = FALSE; // Boolean: If true, workspace restrictions are bypassed on edit an create actions (process_datamap()). YOU MUST KNOW what you do if you use this feature!
  236. var $bypassFileHandling = FALSE; // Boolean: If true, file handling of attached files (addition, deletion etc) is bypassed - the value is saved straight away. YOU MUST KNOW what you are doing with this feature!
  237. var $bypassAccessCheckForRecords = FALSE; // Boolean: If true, access check, check for deleted etc. for records is bypassed. YOU MUST KNOW what you are doing if you use this feature!
  238. var $copyWhichTables = '*'; // String. Comma-list. This list of tables decides which tables will be copied. If empty then none will. If '*' then all will (that the user has permission to of course)
  239. var $copyTree = 0; // Integer. If 0 then branch is NOT copied. If 1 then pages on the 1st level is copied. If 2 then pages on the second level is copied ... and so on
  240. var $defaultValues = array(); // Array [table][fields]=value: New records are created with default values and you can set this array on the form $defaultValues[$table][$field] = $value to override the default values fetched from TCA. If ->setDefaultsFromUserTS is called UserTSconfig default values will overrule existing values in this array (thus UserTSconfig overrules externally set defaults which overrules TCA defaults)
  241. var $overrideValues = array(); // Array [table][fields]=value: You can set this array on the form $overrideValues[$table][$field] = $value to override the incoming data. You must set this externally. You must make sure the fields in this array are also found in the table, because it's not checked. All columns can be set by this array!
  242. var $alternativeFileName = array(); // Array [filename]=alternative_filename: Use this array to force another name onto a file. Eg. if you set ['/tmp/blablabal'] = 'my_file.txt' and '/tmp/blablabal' is set for a certain file-field, then 'my_file.txt' will be used as the name instead.
  243. var $alternativeFilePath = array(); // Array [filename]=alternative_filepath: Same as alternativeFileName but with relative path to the file
  244. var $data_disableFields = array(); // If entries are set in this array corresponding to fields for update, they are ignored and thus NOT updated. You could set this array from a series of checkboxes with value=0 and hidden fields before the checkbox with 1. Then an empty checkbox will disable the field.
  245. var $suggestedInsertUids = array(); // Use this array to validate suggested uids for tables by setting [table]:[uid]. This is a dangerous option since it will force the inserted record to have a certain UID. The value just have to be true, but if you set it to "DELETE" it will make sure any record with that UID will be deleted first (raw delete). The option is used for import of T3D files when synchronizing between two mirrored servers. As a security measure this feature is available only for Admin Users (for now)
  246. var $callBackObj; // Object. Call back object for flex form traversation. Useful when external classes wants to use the iteration functions inside tcemain for traversing a FlexForm structure.
  247. // *********************
  248. // Internal variables (mapping arrays) which can be used (read-only) from outside
  249. // *********************
  250. var $autoVersionIdMap = array(); // Contains mapping of auto-versionized records.
  251. var $substNEWwithIDs = array(); // When new elements are created, this array contains a map between their "NEW..." string IDs and the eventual UID they got when stored in database
  252. var $substNEWwithIDs_table = array(); // Like $substNEWwithIDs, but where each old "NEW..." id is mapped to the table it was from.
  253. var $newRelatedIDs = array(); // Holds the tables and there the ids of newly created child records from IRRE
  254. var $copyMappingArray_merged = array(); // This array is the sum of all copying operations in this class. May be READ from outside, thus partly public.
  255. var $copiedFileMap = array(); // A map between input file name and final destination for files being attached to records.
  256. var $RTEmagic_copyIndex = array(); // Contains [table][id][field] of fiels where RTEmagic images was copied. Holds old filename as key and new filename as value.
  257. var $errorLog = array(); // Errors are collected in this variable.
  258. // *********************
  259. // Internal Variables, do not touch.
  260. // *********************
  261. // Variables set in init() function:
  262. /**
  263. * The user-object the script uses. If not set from outside, this is set to the current global $BE_USER.
  264. *
  265. * @var t3lib_beUserAuth
  266. */
  267. var $BE_USER;
  268. var $userid; // will be set to uid of be_user executing this script
  269. var $username; // will be set to username of be_user executing this script
  270. var $admin; // will be set if user is admin
  271. var $defaultPermissions = array( // Can be overridden from $TYPO3_CONF_VARS
  272. 'user' => 'show,edit,delete,new,editcontent',
  273. 'group' => 'show,edit,new,editcontent',
  274. 'everybody' => ''
  275. );
  276. var $exclude_array; // The list of <table>-<fields> that cannot be edited by user. This is compiled from TCA/exclude-flag combined with non_exclude_fields for the user.
  277. var $datamap = array(); // Set with incoming data array
  278. var $cmdmap = array(); // Set with incoming cmd array
  279. // Internal static:
  280. var $pMap = array( // Permission mapping
  281. 'show' => 1, // 1st bit
  282. 'edit' => 2, // 2nd bit
  283. 'delete' => 4, // 3rd bit
  284. 'new' => 8, // 4th bit
  285. 'editcontent' => 16 // 5th bit
  286. );
  287. var $sortIntervals = 256; // Integer: The interval between sorting numbers used with tables with a 'sorting' field defined. Min 1
  288. // Internal caching arrays
  289. var $recUpdateAccessCache = array(); // Used by function checkRecordUpdateAccess() to store whether a record is updateable or not.
  290. var $recInsertAccessCache = array(); // User by function checkRecordInsertAccess() to store whether a record can be inserted on a page id
  291. var $isRecordInWebMount_Cache = array(); // Caching array for check of whether records are in a webmount
  292. var $isInWebMount_Cache = array(); // Caching array for page ids in webmounts
  293. var $cachedTSconfig = array(); // Caching for collecting TSconfig for page ids
  294. var $pageCache = array(); // Used for caching page records in pageInfo()
  295. var $checkWorkspaceCache = array(); // Array caching workspace access for BE_USER
  296. // Other arrays:
  297. var $dbAnalysisStore = array(); // For accumulation of MM relations that must be written after new records are created.
  298. var $removeFilesStore = array(); // For accumulation of files which must be deleted after processing of all input content
  299. var $uploadedFileArray = array(); // Uploaded files, set by process_uploads()
  300. var $registerDBList = array(); // Used for tracking references that might need correction after operations
  301. var $registerDBPids = array(); // Used for tracking references that might need correction in pid field after operations (e.g. IRRE)
  302. var $copyMappingArray = array(); // Used by the copy action to track the ids of new pages so subpages are correctly inserted! THIS is internally cleared for each executed copy operation! DO NOT USE THIS FROM OUTSIDE! Read from copyMappingArray_merged instead which is accumulating this information.
  303. var $remapStack = array(); // array used for remapping uids and values at the end of process_datamap
  304. var $remapStackRecords = array(); // array used for remapping uids and values at the end of process_datamap (e.g. $remapStackRecords[<table>][<uid>] = <index in $remapStack>)
  305. protected $remapStackChildIds = array(); // array used for checking whether new children need to be remapped
  306. protected $remapStackActions = array(); // array used for executing addition actions after remapping happened (sett processRemapStack())
  307. protected $remapStackRefIndex = array(); // array used for executing post-processing on the reference index
  308. var $updateRefIndexStack = array(); // array used for additional calls to $this->updateRefIndex
  309. var $callFromImpExp = FALSE; // tells, that this TCEmain was called from tx_impext - this variable is set by tx_impexp
  310. var $newIndexMap = array(); // Array for new flexform index mapping
  311. // Various
  312. /**
  313. * basicFileFunctions object
  314. *
  315. * @var t3lib_basicFileFunctions
  316. */
  317. var $fileFunc; // For "singleTon" file-manipulation object
  318. var $checkValue_currentRecord = array(); // Set to "currentRecord" during checking of values.
  319. var $autoVersioningUpdate = FALSE; // A signal flag used to tell file processing that autoversioning has happend and hence certain action should be applied.
  320. protected $disableDeleteClause = FALSE; // Disable delete clause
  321. protected $checkModifyAccessListHookObjects;
  322. /**
  323. * Initializing.
  324. * For details, see 'TYPO3 Core API' document.
  325. * This function does not start the processing of data, but merely initializes the object
  326. *
  327. * @param array Data to be modified or inserted in the database
  328. * @param array Commands to copy, move, delete, localize, versionize records.
  329. * @param object An alternative userobject you can set instead of the default, which is $GLOBALS['BE_USER']
  330. * @return void
  331. */
  332. public function start($data, $cmd, $altUserObject = '') {
  333. // Initializing BE_USER
  334. $this->BE_USER = is_object($altUserObject) ? $altUserObject : $GLOBALS['BE_USER'];
  335. $this->userid = $this->BE_USER->user['uid'];
  336. $this->username = $this->BE_USER->user['username'];
  337. $this->admin = $this->BE_USER->user['admin'];
  338. if ($this->BE_USER->uc['recursiveDelete']) {
  339. $this->deleteTree = 1;
  340. }
  341. if ($GLOBALS['TYPO3_CONF_VARS']['BE']['explicitConfirmationOfTranslation'] && $this->updateModeL10NdiffData === TRUE) {
  342. $this->updateModeL10NdiffData = FALSE;
  343. }
  344. // Initializing default permissions for pages
  345. $defaultPermissions = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPermissions'];
  346. if (isset($defaultPermissions['user'])) {
  347. $this->defaultPermissions['user'] = $defaultPermissions['user'];
  348. }
  349. if (isset($defaultPermissions['group'])) {
  350. $this->defaultPermissions['group'] = $defaultPermissions['group'];
  351. }
  352. if (isset($defaultPermissions['everybody'])) {
  353. $this->defaultPermissions['everybody'] = $defaultPermissions['everybody'];
  354. }
  355. // generates the excludelist, based on TCA/exclude-flag and non_exclude_fields for the user:
  356. $this->exclude_array = $this->admin ? array() : $this->getExcludeListArray();
  357. // Setting the data and cmd arrays
  358. if (is_array($data)) {
  359. reset($data);
  360. $this->datamap = $data;
  361. }
  362. if (is_array($cmd)) {
  363. reset($cmd);
  364. $this->cmdmap = $cmd;
  365. }
  366. }
  367. /**
  368. * Function that can mirror input values in datamap-array to other uid numbers.
  369. * Example: $mirror[table][11] = '22,33' will look for content in $this->datamap[table][11] and copy it to $this->datamap[table][22] and $this->datamap[table][33]
  370. *
  371. * @param array This array has the syntax $mirror[table_name][uid] = [list of uids to copy data-value TO!]
  372. * @return void
  373. */
  374. function setMirror($mirror) {
  375. if (is_array($mirror)) {
  376. foreach ($mirror as $table => $uid_array) {
  377. if (isset($this->datamap[$table])) {
  378. reset($uid_array);
  379. foreach ($uid_array as $id => $uidList) {
  380. if (isset($this->datamap[$table][$id])) {
  381. $theIdsInArray = t3lib_div::trimExplode(',', $uidList, 1);
  382. foreach ($theIdsInArray as $copyToUid) {
  383. $this->datamap[$table][$copyToUid] = $this->datamap[$table][$id];
  384. }
  385. }
  386. }
  387. }
  388. }
  389. }
  390. }
  391. /**
  392. * Initializes default values coming from User TSconfig
  393. *
  394. * @param array User TSconfig array
  395. * @return void
  396. */
  397. function setDefaultsFromUserTS($userTS) {
  398. global $TCA;
  399. if (is_array($userTS)) {
  400. foreach ($userTS as $k => $v) {
  401. $k = substr($k, 0, -1);
  402. if ($k && is_array($v) && isset($TCA[$k])) {
  403. if (is_array($this->defaultValues[$k])) {
  404. $this->defaultValues[$k] = array_merge($this->defaultValues[$k], $v);
  405. } else {
  406. $this->defaultValues[$k] = $v;
  407. }
  408. }
  409. }
  410. }
  411. }
  412. /**
  413. * Processing of uploaded files.
  414. * It turns out that some versions of PHP arranges submitted data for files different if sent in an array. This function will unify this so the internal array $this->uploadedFileArray will always contain files arranged in the same structure.
  415. *
  416. * @param array $_FILES array
  417. * @return void
  418. */
  419. function process_uploads($postFiles) {
  420. if (is_array($postFiles)) {
  421. // Editing frozen:
  422. if ($this->BE_USER->workspace !== 0 && $this->BE_USER->workspaceRec['freeze']) {
  423. $this->newlog('All editing in this workspace has been frozen!', 1);
  424. return FALSE;
  425. }
  426. reset($postFiles);
  427. $subA = current($postFiles);
  428. if (is_array($subA)) {
  429. if (is_array($subA['name']) && is_array($subA['type']) && is_array($subA['tmp_name']) && is_array($subA['size'])) {
  430. // Initialize the uploadedFilesArray:
  431. $this->uploadedFileArray = array();
  432. // For each entry:
  433. foreach ($subA as $key => $values) {
  434. $this->process_uploads_traverseArray($this->uploadedFileArray, $values, $key);
  435. }
  436. } else {
  437. $this->uploadedFileArray = $subA;
  438. }
  439. }
  440. }
  441. }
  442. /**
  443. * Traverse the upload array if needed to rearrange values.
  444. *
  445. * @param array $this->uploadedFileArray passed by reference
  446. * @param array Input array ($_FILES parts)
  447. * @param string The current $_FILES array key to set on the outermost level.
  448. * @return void
  449. * @access private
  450. * @see process_uploads()
  451. */
  452. function process_uploads_traverseArray(&$outputArr, $inputArr, $keyToSet) {
  453. if (is_array($inputArr)) {
  454. foreach ($inputArr as $key => $value) {
  455. $this->process_uploads_traverseArray($outputArr[$key], $inputArr[$key], $keyToSet);
  456. }
  457. } else {
  458. $outputArr[$keyToSet] = $inputArr;
  459. }
  460. }
  461. /*********************************************
  462. *
  463. * HOOKS
  464. *
  465. *********************************************/
  466. /**
  467. * Hook: processDatamap_afterDatabaseOperations
  468. * (calls $hookObj->processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, $this);)
  469. *
  470. * Note: When using the hook after INSERT operations, you will only get the temporary NEW... id passed to your hook as $id,
  471. * but you can easily translate it to the real uid of the inserted record using the $this->substNEWwithIDs array.
  472. *
  473. * @param object $hookObjectsArr: (reference) Array with hook objects
  474. * @param string $status: (reference) Status of the current operation, 'new' or 'update
  475. * @param string $table: (refrence) The table currently processing data for
  476. * @param string $id: (reference) The record uid currently processing data for, [integer] or [string] (like 'NEW...')
  477. * @param array $fieldArray: (reference) The field array of a record
  478. * @return void
  479. */
  480. function hook_processDatamap_afterDatabaseOperations(&$hookObjectsArr, &$status, &$table, &$id, &$fieldArray) {
  481. // Process hook directly:
  482. if (!isset($this->remapStackRecords[$table][$id])) {
  483. foreach ($hookObjectsArr as $hookObj) {
  484. if (method_exists($hookObj, 'processDatamap_afterDatabaseOperations')) {
  485. $hookObj->processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, $this);
  486. }
  487. }
  488. // If this record is in remapStack (e.g. when using IRRE), values will be updated/remapped later on. So the hook will also be called later:
  489. } else {
  490. $this->remapStackRecords[$table][$id]['processDatamap_afterDatabaseOperations'] = array(
  491. 'status' => $status,
  492. 'fieldArray' => $fieldArray,
  493. 'hookObjectsArr' => $hookObjectsArr,
  494. );
  495. }
  496. }
  497. /**
  498. * Gets the 'checkModifyAccessList' hook objects.
  499. * The first call initializes the accordant objects.
  500. *
  501. * @return array The 'checkModifyAccessList' hook objects (if any)
  502. */
  503. protected function getCheckModifyAccessListHookObjects() {
  504. if (!isset($this->checkModifyAccessListHookObjects)) {
  505. $this->checkModifyAccessListHookObjects = array();
  506. if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'])) {
  507. foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'] as $classData) {
  508. $hookObject = t3lib_div::getUserObj($classData);
  509. if (!($hookObject instanceof t3lib_TCEmain_checkModifyAccessListHook)) {
  510. throw new UnexpectedValueException('$hookObject must implement interface t3lib_TCEmain_checkModifyAccessListHook', 1251892472);
  511. }
  512. $this->checkModifyAccessListHookObjects[] = $hookObject;
  513. }
  514. }
  515. }
  516. return $this->checkModifyAccessListHookObjects;
  517. }
  518. /*********************************************
  519. *
  520. * PROCESSING DATA
  521. *
  522. *********************************************/
  523. /**
  524. * Processing the data-array
  525. * Call this function to process the data-array set by start()
  526. *
  527. * @return void
  528. */
  529. public function process_datamap() {
  530. global $TCA, $TYPO3_CONF_VARS;
  531. // Keep versionized(!) relations here locally:
  532. $registerDBList = array();
  533. // Editing frozen:
  534. if ($this->BE_USER->workspace !== 0 && $this->BE_USER->workspaceRec['freeze']) {
  535. $this->newlog('All editing in this workspace has been frozen!', 1);
  536. return FALSE;
  537. }
  538. // First prepare user defined objects (if any) for hooks which extend this function:
  539. $hookObjectsArr = array();
  540. if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'])) {
  541. foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'] as $classRef) {
  542. $hookObjectsArr[] = t3lib_div::getUserObj($classRef);
  543. }
  544. }
  545. // Organize tables so that the pages-table is always processed first. This is required if you want to make sure that content pointing to a new page will be created.
  546. $orderOfTables = array();
  547. if (isset($this->datamap['pages'])) { // Set pages first.
  548. $orderOfTables[] = 'pages';
  549. }
  550. $orderOfTables = array_unique(array_merge($orderOfTables, array_keys($this->datamap)));
  551. // Process the tables...
  552. foreach ($orderOfTables as $table) {
  553. /* Check if
  554. - table is set in $TCA,
  555. - table is NOT readOnly
  556. - the table is set with content in the data-array (if not, there's nothing to process...)
  557. - permissions for tableaccess OK
  558. */
  559. $modifyAccessList = $this->checkModifyAccessList($table);
  560. if (!$modifyAccessList) {
  561. $id = 0;
  562. $this->log($table, $id, 2, 0, 1, "Attempt to modify table '%s' without permission", 1, array($table));
  563. }
  564. if (isset($TCA[$table]) && !$this->tableReadOnly($table) && is_array($this->datamap[$table]) && $modifyAccessList) {
  565. if ($this->reverseOrder) {
  566. $this->datamap[$table] = array_reverse($this->datamap[$table], 1);
  567. }
  568. // For each record from the table, do:
  569. // $id is the record uid, may be a string if new records...
  570. // $incomingFieldArray is the array of fields
  571. foreach ($this->datamap[$table] as $id => $incomingFieldArray) {
  572. if (is_array($incomingFieldArray)) {
  573. // Hook: processDatamap_preProcessFieldArray
  574. foreach ($hookObjectsArr as $hookObj) {
  575. if (method_exists($hookObj, 'processDatamap_preProcessFieldArray')) {
  576. $hookObj->processDatamap_preProcessFieldArray($incomingFieldArray, $table, $id, $this);
  577. }
  578. }
  579. // ******************************
  580. // Checking access to the record
  581. // ******************************
  582. $createNewVersion = FALSE;
  583. $recordAccess = FALSE;
  584. $old_pid_value = '';
  585. $this->autoVersioningUpdate = FALSE;
  586. if (!t3lib_div::testInt($id)) { // Is it a new record? (Then Id is a string)
  587. $fieldArray = $this->newFieldArray($table); // Get a fieldArray with default values
  588. if (isset($incomingFieldArray['pid'])) { // A pid must be set for new records.
  589. // $value = the pid
  590. $pid_value = $incomingFieldArray['pid'];
  591. // Checking and finding numerical pid, it may be a string-reference to another value
  592. $OK = 1;
  593. if (strstr($pid_value, 'NEW')) { // If a NEW... id
  594. if (substr($pid_value, 0, 1) == '-') {
  595. $negFlag = -1;
  596. $pid_value = substr($pid_value, 1);
  597. } else {
  598. $negFlag = 1;
  599. }
  600. if (isset($this->substNEWwithIDs[$pid_value])) { // Trying to find the correct numerical value as it should be mapped by earlier processing of another new record.
  601. if ($negFlag === 1) {
  602. $old_pid_value = $this->substNEWwithIDs[$pid_value];
  603. }
  604. $pid_value = intval($negFlag * $this->substNEWwithIDs[$pid_value]);
  605. } else {
  606. $OK = 0;
  607. } // If not found in the substArray we must stop the process...
  608. } elseif ($pid_value >= 0 && $this->BE_USER->workspace !== 0 && $TCA[$table]['ctrl']['versioning_followPages']) { // PID points to page, the workspace is an offline space and the table follows page during versioning: This means we must check if the PID page has a version in the workspace with swapmode set to 0 (zero = page+content) and if so, change the pid to the uid of that version.
  609. if ($WSdestPage = t3lib_BEfunc::getWorkspaceVersionOfRecord($this->BE_USER->workspace, 'pages', $pid_value, 'uid,t3ver_swapmode')) { // Looks for workspace version of page.
  610. if ($WSdestPage['t3ver_swapmode'] == 0) { // if swapmode is zero, then change pid value.
  611. $pid_value = $WSdestPage['uid'];
  612. }
  613. }
  614. }
  615. $pid_value = intval($pid_value);
  616. // The $pid_value is now the numerical pid at this point
  617. if ($OK) {
  618. $sortRow = $TCA[$table]['ctrl']['sortby'];
  619. if ($pid_value >= 0) { // Points to a page on which to insert the element, possibly in the top of the page
  620. if ($sortRow) { // If this table is sorted we better find the top sorting number
  621. $fieldArray[$sortRow] = $this->getSortNumber($table, 0, $pid_value);
  622. }
  623. $fieldArray['pid'] = $pid_value; // The numerical pid is inserted in the data array
  624. } else { // points to another record before ifself
  625. if ($sortRow) { // If this table is sorted we better find the top sorting number
  626. $tempArray = $this->getSortNumber($table, 0, $pid_value); // Because $pid_value is < 0, getSortNumber returns an array
  627. $fieldArray['pid'] = $tempArray['pid'];
  628. $fieldArray[$sortRow] = $tempArray['sortNumber'];
  629. } else { // Here we fetch the PID of the record that we point to...
  630. $tempdata = $this->recordInfo($table, abs($pid_value), 'pid');
  631. $fieldArray['pid'] = $tempdata['pid'];
  632. }
  633. }
  634. }
  635. }
  636. $theRealPid = $fieldArray['pid'];
  637. // Now, check if we may insert records on this pid.
  638. if ($theRealPid >= 0) {
  639. $recordAccess = $this->checkRecordInsertAccess($table, $theRealPid); // Checks if records can be inserted on this $pid.
  640. if ($recordAccess) {
  641. $this->addDefaultPermittedLanguageIfNotSet($table, $incomingFieldArray);
  642. $recordAccess = $this->BE_USER->recordEditAccessInternals($table, $incomingFieldArray, TRUE);
  643. if (!$recordAccess) {
  644. $this->newlog("recordEditAccessInternals() check failed. [" . $this->BE_USER->errorMsg . "]", 1);
  645. } elseif (!$this->bypassWorkspaceRestrictions) {
  646. // Workspace related processing:
  647. if ($res = $this->BE_USER->workspaceAllowLiveRecordsInPID($theRealPid, $table)) { // If LIVE records cannot be created in the current PID due to workspace restrictions, prepare creation of placeholder-record
  648. if ($res < 0) {
  649. $recordAccess = FALSE;
  650. $this->newlog('Stage for versioning root point and users access level did not allow for editing', 1);
  651. }
  652. } else { // So, if no live records were allowed, we have to create a new version of this record:
  653. if ($TCA[$table]['ctrl']['versioningWS']) {
  654. $createNewVersion = TRUE;
  655. } else {
  656. $recordAccess = FALSE;
  657. $this->newlog('Record could not be created in this workspace in this branch', 1);
  658. }
  659. }
  660. }
  661. }
  662. } else {
  663. debug('Internal ERROR: pid should not be less than zero!');
  664. }
  665. $status = 'new'; // Yes new record, change $record_status to 'insert'
  666. } else { // Nope... $id is a number
  667. $fieldArray = array();
  668. $recordAccess = $this->checkRecordUpdateAccess($table, $id, $incomingFieldArray, $hookObjectsArr);
  669. if (!$recordAccess) {
  670. $propArr = $this->getRecordProperties($table, $id);
  671. $this->log($table, $id, 2, 0, 1, "Attempt to modify record '%s' (%s) without permission. Or non-existing page.", 2, array($propArr['header'], $table . ':' . $id), $propArr['event_pid']);
  672. } else { // Next check of the record permissions (internals)
  673. $recordAccess = $this->BE_USER->recordEditAccessInternals($table, $id);
  674. if (!$recordAccess) {
  675. $propArr = $this->getRecordProperties($table, $id);
  676. $this->newlog("recordEditAccessInternals() check failed. [" . $this->BE_USER->errorMsg . "]", 1);
  677. } else { // Here we fetch the PID of the record that we point to...
  678. $tempdata = $this->recordInfo($table, $id, 'pid' . ($TCA[$table]['ctrl']['versioningWS'] ? ',t3ver_wsid,t3ver_stage' : ''));
  679. $theRealPid = $tempdata['pid'];
  680. // Use the new id of the versionized record we're trying to write to:
  681. // (This record is a child record of a parent and has already been versionized.)
  682. if ($this->autoVersionIdMap[$table][$id]) {
  683. // For the reason that creating a new version of this record, automatically
  684. // created related child records (e.g. "IRRE"), update the accordant field:
  685. $this->getVersionizedIncomingFieldArray($table, $id, $incomingFieldArray, $registerDBList);
  686. // Use the new id of the copied/versionized record:
  687. $id = $this->autoVersionIdMap[$table][$id];
  688. $recordAccess = TRUE;
  689. $this->autoVersioningUpdate = TRUE;
  690. // Checking access in case of offline workspace:
  691. } elseif (!$this->bypassWorkspaceRestrictions && $errorCode = $this->BE_USER->workspaceCannotEditRecord($table, $tempdata)) {
  692. $recordAccess = FALSE; // Versioning is required and it must be offline version!
  693. // Auto-creation of version: In offline workspace, test if versioning is enabled and look for workspace version of input record. If there is no versionized record found we will create one and save to that.
  694. if ($this->BE_USER->workspaceAllowAutoCreation($table, $id, $theRealPid)) {
  695. $tce = t3lib_div::makeInstance('t3lib_TCEmain');
  696. /* @var $tce t3lib_TCEmain */
  697. $tce->stripslashes_values = 0;
  698. // Setting up command for creating a new version of the record:
  699. $cmd = array();
  700. $cmd[$table][$id]['version'] = array(
  701. 'action' => 'new',
  702. 'treeLevels' => -1, // Default is to create a version of the individual records... element versioning that is.
  703. 'label' => 'Auto-created for WS #' . $this->BE_USER->workspace
  704. );
  705. $tce->start(array(), $cmd);
  706. $tce->process_cmdmap();
  707. $this->errorLog = array_merge($this->errorLog, $tce->errorLog);
  708. // If copying was successful, share the new uids (also of related children):
  709. if ($tce->copyMappingArray[$table][$id]) {
  710. foreach ($tce->copyMappingArray as $origTable => $origIdArray) {
  711. foreach ($origIdArray as $origId => $newId) {
  712. $this->uploadedFileArray[$origTable][$newId] = $this->uploadedFileArray[$origTable][$origId];
  713. $this->autoVersionIdMap[$origTable][$origId] = $newId;
  714. }
  715. }
  716. $this->RTEmagic_copyIndex = t3lib_div::array_merge_recursive_overrule($this->RTEmagic_copyIndex, $tce->RTEmagic_copyIndex); // See where RTEmagic_copyIndex is used inside fillInFieldArray() for more information...
  717. // Update registerDBList, that holds the copied relations to child records:
  718. $registerDBList = array_merge($registerDBList, $tce->registerDBList);
  719. // For the reason that creating a new version of this record, automatically
  720. // created related child records (e.g. "IRRE"), update the accordant field:
  721. $this->getVersionizedIncomingFieldArray($table, $id, $incomingFieldArray, $registerDBList);
  722. // Use the new id of the copied/versionized record:
  723. $id = $this->autoVersionIdMap[$table][$id];
  724. $recordAccess = TRUE;
  725. $this->autoVersioningUpdate = TRUE;
  726. } else {
  727. $this->newlog("Could not be edited in offline workspace in the branch where found (failure state: '" . $errorCode . "'). Auto-creation of version failed!", 1);
  728. }
  729. } else {
  730. $this->newlog("Could not be edited in offline workspace in the branch where found (failure state: '" . $errorCode . "'). Auto-creation of version not allowed in workspace!", 1);
  731. }
  732. }
  733. }
  734. }
  735. $status = 'update'; // the default is 'update'
  736. }
  737. // If access was granted above, proceed to create or update record:
  738. if ($recordAccess) {
  739. list($tscPID) = t3lib_BEfunc::getTSCpid($table, $id, $old_pid_value ? $old_pid_value : $fieldArray['pid']); // Here the "pid" is set IF NOT the old pid was a string pointing to a place in the subst-id array.
  740. $TSConfig = $this->getTCEMAIN_TSconfig($tscPID);
  741. if ($status == 'new' && $table == 'pages' && is_array($TSConfig['permissions.'])) {
  742. $fieldArray = $this->setTSconfigPermissions($fieldArray, $TSConfig['permissions.']);
  743. }
  744. if ($createNewVersion) {
  745. $newVersion_placeholderFieldArray = $fieldArray;
  746. }
  747. // Processing of all fields in incomingFieldArray and setting them in $fieldArray
  748. $fieldArray = $this->fillInFieldArray($table, $id, $fieldArray, $incomingFieldArray, $theRealPid, $status, $tscPID);
  749. // NOTICE! All manipulation beyond this point bypasses both "excludeFields" AND possible "MM" relations / file uploads to field!
  750. // Forcing some values unto field array:
  751. $fieldArray = $this->overrideFieldArray($table, $fieldArray); // NOTICE: This overriding is potentially dangerous; permissions per field is not checked!!!
  752. if ($createNewVersion) {
  753. $newVersion_placeholderFieldArray = $this->overrideFieldArray($table, $newVersion_placeholderFieldArray);
  754. }
  755. // Setting system fields
  756. if ($status == 'new') {
  757. if ($TCA[$table]['ctrl']['crdate']) {
  758. $fieldArray[$TCA[$table]['ctrl']['crdate']] = $GLOBALS['EXEC_TIME'];
  759. if ($createNewVersion) {
  760. $newVersion_placeholderFieldArray[$TCA[$table]['ctrl']['crdate']] = $GLOBALS['EXEC_TIME'];
  761. }
  762. }
  763. if ($TCA[$table]['ctrl']['cruser_id']) {
  764. $fieldArray[$TCA[$table]['ctrl']['cruser_id']] = $this->userid;
  765. if ($createNewVersion) {
  766. $newVersion_placeholderFieldArray[$TCA[$table]['ctrl']['cruser_id']] = $this->userid;
  767. }
  768. }
  769. } elseif ($this->checkSimilar) { // Removing fields which are equal to the current value:
  770. $fieldArray = $this->compareFieldArrayWithCurrentAndUnset($table, $id, $fieldArray);
  771. }
  772. if ($TCA[$table]['ctrl']['tstamp'] && count($fieldArray)) {
  773. $fieldArray[$TCA[$table]['ctrl']['tstamp']] = $GLOBALS['EXEC_TIME'];
  774. if ($createNewVersion) {
  775. $newVersion_placeholderFieldArray[$TCA[$table]['ctrl']['tstamp']] = $GLOBALS['EXEC_TIME'];
  776. }
  777. }
  778. if ($TCA[$table]['ctrl']['versioningWS']) {
  779. $fieldArray['t3ver_stage'] = 0;
  780. }
  781. // Hook: processDatamap_postProcessFieldArray
  782. foreach ($hookObjectsArr as $hookObj) {
  783. if (method_exists($hookObj, 'processDatamap_postProcessFieldArray')) {
  784. $hookObj->processDatamap_postProcessFieldArray($status, $table, $id, $fieldArray, $this);
  785. }
  786. }
  787. // Performing insert/update. If fieldArray has been unset by some userfunction (see hook above), don't do anything
  788. // Kasper: Unsetting the fieldArray is dangerous; MM relations might be saved already and files could have been uploaded that are now "lost"
  789. if (is_array($fieldArray)) {
  790. if ($status == 'new') {
  791. if ($createNewVersion) { // This creates a new version of the record with online placeholder and offline version
  792. $versioningType = $table === 'pages' ? $this->BE_USER->workspaceVersioningTypeGetClosest(t3lib_div::intInRange($TYPO3_CONF_VARS['BE']['newPagesVersioningType'], -1, 1)) : -1;
  793. if ($this->BE_USER->workspaceVersioningTypeAccess($versioningType)) {
  794. $newVersion_placeholderFieldArray['t3ver_label'] = 'INITIAL PLACEHOLDER';
  795. $newVersion_placeholderFieldArray['t3ver_state'] = 1; // Setting placeholder state value for temporary record
  796. $newVersion_placeholderFieldArray['t3ver_wsid'] = $this->BE_USER->workspace; // Setting workspace - only so display of place holders can filter out those from other workspaces.
  797. $newVersion_placeholderFieldArray[$TCA[$table]['ctrl']['label']] = '[PLACEHOLDER, WS#' . $this->BE_USER->workspace . ']';
  798. $this->insertDB($table, $id, $newVersion_placeholderFieldArray, FALSE); // Saving placeholder as 'original'
  799. // For the actual new offline version, set versioning values to point to placeholder:
  800. $fieldArray['pid'] = -1;
  801. $fieldArray['t3ver_oid'] = $this->substNEWwithIDs[$id];
  802. $fieldArray['t3ver_id'] = 1;
  803. $fieldArray['t3ver_state'] = -1; // Setting placeholder state value for version (so it can know it is currently a new version...)
  804. $fieldArray['t3ver_label'] = 'First draft version';
  805. $fieldArray['t3ver_wsid'] = $this->BE_USER->workspace;
  806. if ($table === 'pages') { // Swap mode set to "branch" so we can build branches for pages.
  807. $fieldArray['t3ver_swapmode'] = $versioningType;
  808. }
  809. $phShadowId = $this->insertDB($table, $id, $fieldArray, TRUE, 0, TRUE); // When inserted, $this->substNEWwithIDs[$id] will be changed to the uid of THIS version and so the interface will pick it up just nice!
  810. if ($phShadowId) {
  811. // Processes fields of the placeholder record:
  812. $this->triggerRemapAction(
  813. $table,
  814. $id,
  815. array($this, 'placeholderShadowing'),
  816. array($table, $phShadowId)
  817. );
  818. // Hold auto-versionized ids of placeholders:
  819. $this->autoVersionIdMap[$table][$this->substNEWwithIDs[$id]] = $phShadowId;
  820. }
  821. } else {
  822. $this->newlog('Versioning type "' . $versioningType . '" was not allowed, so could not create new record.', 1);
  823. }
  824. } else {
  825. $this->insertDB($table, $id, $fieldArray, FALSE, $incomingFieldArray['uid']);
  826. }
  827. } else {
  828. $this->updateDB($table, $id, $fieldArray);
  829. $this->placeholderShadowing($table, $id);
  830. }
  831. }
  832. /*
  833. * Hook: processDatamap_afterDatabaseOperations
  834. *
  835. * Note: When using the hook after INSERT operations, you will only get the temporary NEW... id passed to your hook as $id,
  836. * but you can easily translate it to the real uid of the inserted record using the $this->substNEWwithIDs array.
  837. */
  838. $this->hook_processDatamap_afterDatabaseOperations($hookObjectsArr, $status, $table, $id, $fieldArray);
  839. } // if ($recordAccess) {
  840. } // if (is_array($incomingFieldArray)) {
  841. }
  842. }
  843. }
  844. // Process the stack of relations to remap/correct
  845. $this->processRemapStack();
  846. $this->dbAnalysisStoreExec();
  847. $this->removeRegisteredFiles();
  848. /*
  849. * Hook: processDatamap_afterAllOperations
  850. *
  851. * Note: When this hook gets called, all operations on the submitted data have been finished.
  852. */
  853. foreach ($hookObjectsArr as $hookObj) {
  854. if (method_exists($hookObj, 'processDatamap_afterAllOperations')) {
  855. $hookObj->processDatamap_afterAllOperations($this);
  856. }
  857. }
  858. }
  859. /**
  860. * Fix shadowing of data in case we are editing a offline version of a live "New" placeholder record:
  861. *
  862. * @param string Table name
  863. * @param integer Record uid
  864. * @return void
  865. */
  866. function placeholderShadowing($table, $id) {
  867. global $TCA;

Large files files are truncated, but you can click here to view the full file