2 namespace TYPO3\CMS\Core\DataHandling
;
5 * This file is part of the TYPO3 CMS project.
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Backend\Utility\BackendUtility
;
18 use TYPO3\CMS\Core\Database\DatabaseConnection
;
19 use TYPO3\CMS\Core\Messaging\FlashMessage
;
20 use TYPO3\CMS\Core\Utility\GeneralUtility
;
21 use TYPO3\CMS\Core\Versioning\VersionState
;
24 * The main data handler class which takes care of correctly updating and inserting records.
25 * This class was formerly known as TCEmain.
27 * This is the TYPO3 Core Engine class for manipulation of the database
28 * This class is used by eg. the tce_db.php script which provides an the interface for POST forms to this class.
31 * - $GLOBALS['TCA'] must exist
32 * - $GLOBALS['LANG'] must exist
34 * tce_db.php for further comments and SYNTAX! Also see document 'TYPO3 Core API' for details.
36 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
40 // *********************
41 // Public variables you can configure before using the class:
42 // *********************
44 * If TRUE, the default log-messages will be stored. This should not be necessary if the locallang-file for the
45 * log-display is properly configured. So disabling this will just save some database-space as the default messages are not saved.
49 public $storeLogMessages = TRUE;
52 * If TRUE, actions are logged to sys_log.
56 public $enableLogging = TRUE;
59 * If TRUE, the datamap array is reversed in the order, which is a nice thing if you're creating a whole new
64 public $reverseOrder = FALSE;
67 * If TRUE, only fields which are different from the database values are saved! In fact, if a whole input array
68 * is similar, it's not saved then.
72 public $checkSimilar = TRUE;
75 * If TRUE, incoming values in the data-array have their slashes stripped. ALWAYS SET THIS TO ZERO and supply an
76 * unescaped data array instead. This switch may totally disappear in future versions of this class!
80 public $stripslashes_values = TRUE;
83 * This will read the record after having updated or inserted it. If anything is not properly submitted an error
84 * is written to the log. This feature consumes extra time by selecting records
88 public $checkStoredRecords = TRUE;
91 * If set, values '' and 0 will equal each other when the stored records are checked.
95 public $checkStoredRecords_loose = TRUE;
98 * If this is set, then a page is deleted by deleting the whole branch under it (user must have
99 * delete permissions to it all). If not set, then the page is deleted ONLY if it has no branch.
103 public $deleteTree = FALSE;
106 * If set, then the 'hideAtCopy' flag for tables will be ignored.
110 public $neverHideAtCopy = FALSE;
113 * If set, then the TCE class has been instantiated during an import action of a T3D
117 public $isImporting = FALSE;
120 * If set, then transformations are NOT performed on the input.
124 public $dontProcessTransformations = FALSE;
127 * If set, .vDEFbase values are unset in flexforms.
131 public $clear_flexFormData_vDEFbase = FALSE;
134 * TRUE: (traditional) Updates when record is saved. For flexforms, updates if change is made to the localized value.
135 * FALSE: Will not update anything.
136 * "FORCE_FFUPD" (string): Like TRUE, but will force update to the FlexForm Field
140 public $updateModeL10NdiffData = TRUE;
143 * If TRUE, the translation diff. fields will in fact be reset so that they indicate that all needs to change again!
144 * It's meant as the opposite of declaring the record translated.
148 public $updateModeL10NdiffDataClear = FALSE;
151 * If TRUE, workspace restrictions are bypassed on edit an create actions (process_datamap()).
152 * YOU MUST KNOW what you do if you use this feature!
156 public $bypassWorkspaceRestrictions = FALSE;
159 * If TRUE, file handling of attached files (addition, deletion etc) is bypassed - the value is saved straight away.
160 * YOU MUST KNOW what you are doing with this feature!
164 public $bypassFileHandling = FALSE;
167 * If TRUE, access check, check for deleted etc. for records is bypassed.
168 * YOU MUST KNOW what you are doing if you use this feature!
172 public $bypassAccessCheckForRecords = FALSE;
175 * Comma-separated list. This list of tables decides which tables will be copied. If empty then none will.
176 * If '*' then all will (that the user has permission to of course)
180 public $copyWhichTables = '*';
183 * If 0 then branch is NOT copied.
184 * If 1 then pages on the 1st level is copied.
185 * If 2 then pages on the second level is copied ... and so on
189 public $copyTree = 0;
192 * [table][fields]=value: New records are created with default values and you can set this array on the
193 * form $defaultValues[$table][$field] = $value to override the default values fetched from TCA.
194 * If ->setDefaultsFromUserTS is called UserTSconfig default values will overrule existing values in this array
195 * (thus UserTSconfig overrules externally set defaults which overrules TCA defaults)
199 public $defaultValues = array();
202 * [table][fields]=value: You can set this array on the form $overrideValues[$table][$field] = $value to
203 * override the incoming data. You must set this externally. You must make sure the fields in this array are also
204 * found in the table, because it's not checked. All columns can be set by this array!
208 public $overrideValues = array();
211 * [filename]=alternative_filename: Use this array to force another name onto a file.
212 * Eg. if you set ['/tmp/blablabal'] = 'my_file.txt' and '/tmp/blablabal' is set for a certain file-field,
213 * then 'my_file.txt' will be used as the name instead.
217 public $alternativeFileName = array();
220 * Array [filename]=alternative_filepath: Same as alternativeFileName but with relative path to the file
224 public $alternativeFilePath = array();
227 * If entries are set in this array corresponding to fields for update, they are ignored and thus NOT updated.
228 * You could set this array from a series of checkboxes with value=0 and hidden fields before the checkbox with 1.
229 * Then an empty checkbox will disable the field.
233 public $data_disableFields = array();
236 * Use this array to validate suggested uids for tables by setting [table]:[uid]. This is a dangerous option
237 * since it will force the inserted record to have a certain UID. The value just have to be TRUE, but if you set
238 * it to "DELETE" it will make sure any record with that UID will be deleted first (raw delete).
239 * The option is used for import of T3D files when synchronizing between two mirrored servers.
240 * As a security measure this feature is available only for Admin Users (for now)
244 public $suggestedInsertUids = array();
247 * Object. Call back object for FlexForm traversal. Useful when external classes wants to use the
248 * iteration functions inside DataHandler for traversing a FlexForm structure.
254 // *********************
255 // Internal variables (mapping arrays) which can be used (read-only) from outside
256 // *********************
258 * Contains mapping of auto-versionized records.
262 public $autoVersionIdMap = array();
265 * 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
269 public $substNEWwithIDs = array();
272 * Like $substNEWwithIDs, but where each old "NEW..." id is mapped to the table it was from.
276 public $substNEWwithIDs_table = array();
279 * Holds the tables and there the ids of newly created child records from IRRE
283 public $newRelatedIDs = array();
286 * This array is the sum of all copying operations in this class. May be READ from outside, thus partly public.
290 public $copyMappingArray_merged = array();
293 * A map between input file name and final destination for files being attached to records.
297 public $copiedFileMap = array();
300 * Contains [table][id][field] of fiels where RTEmagic images was copied. Holds old filename as key and new filename as value.
304 public $RTEmagic_copyIndex = array();
307 * Errors are collected in this variable.
311 public $errorLog = array();
314 // *********************
315 // Internal Variables, do not touch.
316 // *********************
318 // Variables set in init() function:
321 * The user-object the script uses. If not set from outside, this is set to the current global $BE_USER.
323 * @var \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
328 * Will be set to uid of be_user executing this script
335 * Will be set to username of be_user executing this script
342 * Will be set if user is admin
349 * Can be overridden from $GLOBALS['TYPO3_CONF_VARS']
353 public $defaultPermissions = array(
354 'user' => 'show,edit,delete,new,editcontent',
355 'group' => 'show,edit,new,editcontent',
360 * 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.
364 public $exclude_array;
367 * Data submitted from the form view, used to control behaviours,
368 * e.g. this is used to activate/deactive fields and thus store NULL values
372 protected $control = array();
375 * Set with incoming data array
379 public $datamap = array();
382 * Set with incoming cmd array
386 public $cmdmap = array();
394 public $pMap = array(
407 * Integer: The interval between sorting numbers used with tables with a 'sorting' field defined. Min 1
411 public $sortIntervals = 256;
413 // Internal caching arrays
415 * Used by function checkRecordUpdateAccess() to store whether a record is updateable or not.
419 public $recUpdateAccessCache = array();
422 * User by function checkRecordInsertAccess() to store whether a record can be inserted on a page id
426 public $recInsertAccessCache = array();
429 * Caching array for check of whether records are in a webmount
433 public $isRecordInWebMount_Cache = array();
436 * Caching array for page ids in webmounts
440 public $isInWebMount_Cache = array();
443 * Caching for collecting TSconfig for page ids
447 public $cachedTSconfig = array();
450 * Used for caching page records in pageInfo()
454 public $pageCache = array();
457 * Array caching workspace access for BE_USER
461 public $checkWorkspaceCache = array();
465 * For accumulation of MM relations that must be written after new records are created.
469 public $dbAnalysisStore = array();
472 * For accumulation of files which must be deleted after processing of all input content
476 public $removeFilesStore = array();
479 * Uploaded files, set by process_uploads()
483 public $uploadedFileArray = array();
486 * Used for tracking references that might need correction after operations
490 public $registerDBList = array();
493 * Used for tracking references that might need correction in pid field after operations (e.g. IRRE)
497 public $registerDBPids = array();
500 * Used by the copy action to track the ids of new pages so subpages are correctly inserted!
501 * THIS is internally cleared for each executed copy operation! DO NOT USE THIS FROM OUTSIDE!
502 * Read from copyMappingArray_merged instead which is accumulating this information.
504 * NOTE: This is used by some outside scripts (e.g. hooks), as the results in $copyMappingArray_merged
505 * are only available after an action has been completed.
509 public $copyMappingArray = array();
512 * Array used for remapping uids and values at the end of process_datamap
516 public $remapStack = array();
519 * Array used for remapping uids and values at the end of process_datamap
520 * (e.g. $remapStackRecords[<table>][<uid>] = <index in $remapStack>)
524 public $remapStackRecords = array();
527 * Array used for checking whether new children need to be remapped
531 protected $remapStackChildIds = array();
534 * Array used for executing addition actions after remapping happened (set processRemapStack())
538 protected $remapStackActions = array();
541 * Array used for executing post-processing on the reference index
545 protected $remapStackRefIndex = array();
548 * Array used for additional calls to $this->updateRefIndex
552 public $updateRefIndexStack = array();
555 * Tells, that this DataHandler instance was called from \TYPO3\CMS\Impext\ImportExport.
556 * This variable is set by \TYPO3\CMS\Impext\ImportExport
560 public $callFromImpExp = FALSE;
563 * Array for new flexform index mapping
567 public $newIndexMap = array();
571 * basicFileFunctions object
572 * For "singleton" file-manipulation object
574 * @var \TYPO3\CMS\Core\Utility\File\BasicFileUtility
579 * Set to "currentRecord" during checking of values.
583 public $checkValue_currentRecord = array();
586 * A signal flag used to tell file processing that autoversioning has happend and hence certain action should be applied.
590 public $autoVersioningUpdate = FALSE;
593 * Disable delete clause
597 protected $disableDeleteClause = FALSE;
602 protected $checkModifyAccessListHookObjects;
607 protected $version_remapMMForVersionSwap_reg;
610 * The outer most instance of \TYPO3\CMS\Core\DataHandling\DataHandler:
611 * This object instantiates itself on versioning and localization ...
613 * @var \TYPO3\CMS\Core\DataHandling\DataHandler
615 protected $outerMostInstance = NULL;
618 * Internal cache for collecting records that should trigger cache clearing
622 protected static $recordsToClearCacheFor = array();
626 * @param array $control
628 public function setControl(array $control) {
629 $this->control
= $control;
634 * For details, see 'TYPO3 Core API' document.
635 * This function does not start the processing of data, but merely initializes the object
637 * @param array $data Data to be modified or inserted in the database
638 * @param array $cmd Commands to copy, move, delete, localize, versionize records.
639 * @param object $altUserObject An alternative userobject you can set instead of the default, which is $GLOBALS['BE_USER']
642 public function start($data, $cmd, $altUserObject = '') {
643 // Initializing BE_USER
644 $this->BE_USER
= is_object($altUserObject) ?
$altUserObject : $GLOBALS['BE_USER'];
645 $this->userid
= $this->BE_USER
->user
['uid'];
646 $this->username
= $this->BE_USER
->user
['username'];
647 $this->admin
= $this->BE_USER
->user
['admin'];
648 if ($this->BE_USER
->uc
['recursiveDelete']) {
649 $this->deleteTree
= 1;
651 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['explicitConfirmationOfTranslation'] && $this->updateModeL10NdiffData
=== TRUE) {
652 $this->updateModeL10NdiffData
= FALSE;
654 // Initializing default permissions for pages
655 $defaultPermissions = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPermissions'];
656 if (isset($defaultPermissions['user'])) {
657 $this->defaultPermissions
['user'] = $defaultPermissions['user'];
659 if (isset($defaultPermissions['group'])) {
660 $this->defaultPermissions
['group'] = $defaultPermissions['group'];
662 if (isset($defaultPermissions['everybody'])) {
663 $this->defaultPermissions
['everybody'] = $defaultPermissions['everybody'];
665 // generates the excludelist, based on TCA/exclude-flag and non_exclude_fields for the user:
666 $this->exclude_array
= $this->admin ?
array() : $this->getExcludeListArray();
667 // Setting the data and cmd arrays
668 if (is_array($data)) {
670 $this->datamap
= $data;
672 if (is_array($cmd)) {
674 $this->cmdmap
= $cmd;
679 * Function that can mirror input values in datamap-array to other uid numbers.
680 * 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]
682 * @param array $mirror This array has the syntax $mirror[table_name][uid] = [list of uids to copy data-value TO!]
685 public function setMirror($mirror) {
686 if (is_array($mirror)) {
687 foreach ($mirror as $table => $uid_array) {
688 if (isset($this->datamap
[$table])) {
689 foreach ($uid_array as $id => $uidList) {
690 if (isset($this->datamap
[$table][$id])) {
691 $theIdsInArray = GeneralUtility
::trimExplode(',', $uidList, TRUE);
692 foreach ($theIdsInArray as $copyToUid) {
693 $this->datamap
[$table][$copyToUid] = $this->datamap
[$table][$id];
703 * Initializes default values coming from User TSconfig
705 * @param array $userTS User TSconfig array
708 public function setDefaultsFromUserTS($userTS) {
709 if (is_array($userTS)) {
710 foreach ($userTS as $k => $v) {
711 $k = substr($k, 0, -1);
712 if ($k && is_array($v) && isset($GLOBALS['TCA'][$k])) {
713 if (is_array($this->defaultValues
[$k])) {
714 $this->defaultValues
[$k] = array_merge($this->defaultValues
[$k], $v);
716 $this->defaultValues
[$k] = $v;
724 * Processing of uploaded files.
725 * 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.
727 * @param array $postFiles $_FILES array
730 public function process_uploads($postFiles) {
731 if (is_array($postFiles)) {
733 if ($this->BE_USER
->workspace
!== 0 && $this->BE_USER
->workspaceRec
['freeze']) {
734 $this->newlog('All editing in this workspace has been frozen!', 1);
737 $subA = reset($postFiles);
738 if (is_array($subA)) {
739 if (is_array($subA['name']) && is_array($subA['type']) && is_array($subA['tmp_name']) && is_array($subA['size'])) {
740 // Initialize the uploadedFilesArray:
741 $this->uploadedFileArray
= array();
743 foreach ($subA as $key => $values) {
744 $this->process_uploads_traverseArray($this->uploadedFileArray
, $values, $key);
747 $this->uploadedFileArray
= $subA;
754 * Traverse the upload array if needed to rearrange values.
756 * @param array $outputArr $this->uploadedFileArray passed by reference
757 * @param array $inputArr Input array ($_FILES parts)
758 * @param string $keyToSet The current $_FILES array key to set on the outermost level.
761 * @see process_uploads()
763 public function process_uploads_traverseArray(&$outputArr, $inputArr, $keyToSet) {
764 if (is_array($inputArr)) {
765 foreach ($inputArr as $key => $value) {
766 $this->process_uploads_traverseArray($outputArr[$key], $inputArr[$key], $keyToSet);
769 $outputArr[$keyToSet] = $inputArr;
773 /*********************************************
777 *********************************************/
779 * Hook: processDatamap_afterDatabaseOperations
780 * (calls $hookObj->processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, $this);)
782 * Note: When using the hook after INSERT operations, you will only get the temporary NEW... id passed to your hook as $id,
783 * but you can easily translate it to the real uid of the inserted record using the $this->substNEWwithIDs array.
785 * @param object $hookObjectsArr (reference) Array with hook objects
786 * @param string $status (reference) Status of the current operation, 'new' or 'update
787 * @param string $table (refrence) The table currently processing data for
788 * @param string $id (reference) The record uid currently processing data for, [integer] or [string] (like 'NEW...')
789 * @param array $fieldArray (reference) The field array of a record
792 public function hook_processDatamap_afterDatabaseOperations(&$hookObjectsArr, &$status, &$table, &$id, &$fieldArray) {
793 // Process hook directly:
794 if (!isset($this->remapStackRecords
[$table][$id])) {
795 foreach ($hookObjectsArr as $hookObj) {
796 if (method_exists($hookObj, 'processDatamap_afterDatabaseOperations')) {
797 $hookObj->processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, $this);
801 $this->remapStackRecords
[$table][$id]['processDatamap_afterDatabaseOperations'] = array(
803 'fieldArray' => $fieldArray,
804 'hookObjectsArr' => $hookObjectsArr
810 * Gets the 'checkModifyAccessList' hook objects.
811 * The first call initializes the accordant objects.
813 * @return array The 'checkModifyAccessList' hook objects (if any)
815 protected function getCheckModifyAccessListHookObjects() {
816 if (!isset($this->checkModifyAccessListHookObjects
)) {
817 $this->checkModifyAccessListHookObjects
= array();
818 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'])) {
819 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkModifyAccessList'] as $classData) {
820 $hookObject = GeneralUtility
::getUserObj($classData);
821 if (!$hookObject instanceof \TYPO3\CMS\Core\DataHandling\DataHandlerCheckModifyAccessListHookInterface
) {
822 throw new \
UnexpectedValueException('$hookObject must implement interface \\TYPO3\\CMS\\Core\\DataHandling\\DataHandlerCheckModifyAccessListHookInterface', 1251892472);
824 $this->checkModifyAccessListHookObjects
[] = $hookObject;
828 return $this->checkModifyAccessListHookObjects
;
831 /*********************************************
835 *********************************************/
837 * Processing the data-array
838 * Call this function to process the data-array set by start()
842 public function process_datamap() {
843 $this->controlActiveElements();
845 // Keep versionized(!) relations here locally:
846 $registerDBList = array();
847 $this->registerElementsToBeDeleted();
848 $this->datamap
= $this->unsetElementsToBeDeleted($this->datamap
);
850 if ($this->BE_USER
->workspace
!== 0 && $this->BE_USER
->workspaceRec
['freeze']) {
851 $this->newlog('All editing in this workspace has been frozen!', 1);
854 // First prepare user defined objects (if any) for hooks which extend this function:
855 $hookObjectsArr = array();
856 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'])) {
857 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'] as $classRef) {
858 $hookObject = GeneralUtility
::getUserObj($classRef);
859 if (method_exists($hookObject, 'processDatamap_beforeStart')) {
860 $hookObject->processDatamap_beforeStart($this);
862 $hookObjectsArr[] = $hookObject;
865 // 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.
866 $orderOfTables = array();
868 if (isset($this->datamap
['pages'])) {
869 $orderOfTables[] = 'pages';
871 $orderOfTables = array_unique(array_merge($orderOfTables, array_keys($this->datamap
)));
872 // Process the tables...
873 foreach ($orderOfTables as $table) {
875 // - table is set in $GLOBALS['TCA'],
876 // - table is NOT readOnly
877 // - the table is set with content in the data-array (if not, there's nothing to process...)
878 // - permissions for tableaccess OK
879 $modifyAccessList = $this->checkModifyAccessList($table);
880 if (!$modifyAccessList) {
882 $this->log($table, $id, 2, 0, 1, 'Attempt to modify table \'%s\' without permission', 1, array($table));
884 if (isset($GLOBALS['TCA'][$table]) && !$this->tableReadOnly($table) && is_array($this->datamap
[$table]) && $modifyAccessList) {
885 if ($this->reverseOrder
) {
886 $this->datamap
[$table] = array_reverse($this->datamap
[$table], 1);
888 // For each record from the table, do:
889 // $id is the record uid, may be a string if new records...
890 // $incomingFieldArray is the array of fields
891 foreach ($this->datamap
[$table] as $id => $incomingFieldArray) {
892 if (is_array($incomingFieldArray)) {
893 // Handle native date/time fields
894 $dateTimeFormats = $GLOBALS['TYPO3_DB']->getDateTimeFormats($table);
895 foreach ($GLOBALS['TCA'][$table]['columns'] as $column => $config) {
896 if (isset($incomingFieldArray[$column])) {
897 if (isset($config['config']['dbType']) && GeneralUtility
::inList('date,datetime', $config['config']['dbType'])) {
898 $emptyValue = $dateTimeFormats[$config['config']['dbType']]['empty'];
899 $format = $dateTimeFormats[$config['config']['dbType']]['format'];
900 $incomingFieldArray[$column] = $incomingFieldArray[$column] ?
gmdate($format, $incomingFieldArray[$column]) : $emptyValue;
904 // Hook: processDatamap_preProcessFieldArray
905 foreach ($hookObjectsArr as $hookObj) {
906 if (method_exists($hookObj, 'processDatamap_preProcessFieldArray')) {
907 $hookObj->processDatamap_preProcessFieldArray($incomingFieldArray, $table, $id, $this);
910 // ******************************
911 // Checking access to the record
912 // ******************************
913 $createNewVersion = FALSE;
914 $recordAccess = FALSE;
916 $this->autoVersioningUpdate
= FALSE;
917 // Is it a new record? (Then Id is a string)
918 if (!\TYPO3\CMS\Core\Utility\MathUtility
::canBeInterpretedAsInteger($id)) {
919 // Get a fieldArray with default values
920 $fieldArray = $this->newFieldArray($table);
921 // A pid must be set for new records.
922 if (isset($incomingFieldArray['pid'])) {
924 $pid_value = $incomingFieldArray['pid'];
925 // Checking and finding numerical pid, it may be a string-reference to another value
928 if (strstr($pid_value, 'NEW')) {
929 if ($pid_value[0] === '-') {
931 $pid_value = substr($pid_value, 1);
935 // Trying to find the correct numerical value as it should be mapped by earlier processing of another new record.
936 if (isset($this->substNEWwithIDs
[$pid_value])) {
937 if ($negFlag === 1) {
938 $old_pid_value = $this->substNEWwithIDs
[$pid_value];
940 $pid_value = (int)($negFlag * $this->substNEWwithIDs
[$pid_value]);
945 $pid_value = (int)$pid_value;
946 // The $pid_value is now the numerical pid at this point
948 $sortRow = $GLOBALS['TCA'][$table]['ctrl']['sortby'];
949 // Points to a page on which to insert the element, possibly in the top of the page
950 if ($pid_value >= 0) {
951 // If this table is sorted we better find the top sorting number
953 $fieldArray[$sortRow] = $this->getSortNumber($table, 0, $pid_value);
955 // The numerical pid is inserted in the data array
956 $fieldArray['pid'] = $pid_value;
958 // points to another record before ifself
959 // If this table is sorted we better find the top sorting number
961 // Because $pid_value is < 0, getSortNumber returns an array
962 $tempArray = $this->getSortNumber($table, 0, $pid_value);
963 $fieldArray['pid'] = $tempArray['pid'];
964 $fieldArray[$sortRow] = $tempArray['sortNumber'];
966 // Here we fetch the PID of the record that we point to...
967 $tempdata = $this->recordInfo($table, abs($pid_value), 'pid');
968 $fieldArray['pid'] = $tempdata['pid'];
973 $theRealPid = $fieldArray['pid'];
974 // Now, check if we may insert records on this pid.
975 if ($theRealPid >= 0) {
976 // Checks if records can be inserted on this $pid.
977 $recordAccess = $this->checkRecordInsertAccess($table, $theRealPid);
979 $this->addDefaultPermittedLanguageIfNotSet($table, $incomingFieldArray);
980 $recordAccess = $this->BE_USER
->recordEditAccessInternals($table, $incomingFieldArray, TRUE);
981 if (!$recordAccess) {
982 $this->newlog('recordEditAccessInternals() check failed. [' . $this->BE_USER
->errorMsg
. ']', 1);
983 } elseif (!$this->bypassWorkspaceRestrictions
) {
984 // Workspace related processing:
985 // If LIVE records cannot be created in the current PID due to workspace restrictions, prepare creation of placeholder-record
986 if ($res = $this->BE_USER
->workspaceAllowLiveRecordsInPID($theRealPid, $table)) {
988 $recordAccess = FALSE;
989 $this->newlog('Stage for versioning root point and users access level did not allow for editing', 1);
992 // So, if no live records were allowed, we have to create a new version of this record:
993 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
994 $createNewVersion = TRUE;
996 $recordAccess = FALSE;
997 $this->newlog('Record could not be created in this workspace in this branch', 1);
1003 debug('Internal ERROR: pid should not be less than zero!');
1005 // Yes new record, change $record_status to 'insert'
1008 // Nope... $id is a number
1009 $fieldArray = array();
1010 $recordAccess = $this->checkRecordUpdateAccess($table, $id, $incomingFieldArray, $hookObjectsArr);
1011 if (!$recordAccess) {
1012 $propArr = $this->getRecordProperties($table, $id);
1013 $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']);
1015 // Next check of the record permissions (internals)
1016 $recordAccess = $this->BE_USER
->recordEditAccessInternals($table, $id);
1017 if (!$recordAccess) {
1018 $propArr = $this->getRecordProperties($table, $id);
1019 $this->newlog('recordEditAccessInternals() check failed. [' . $this->BE_USER
->errorMsg
. ']', 1);
1021 // Here we fetch the PID of the record that we point to...
1022 $tempdata = $this->recordInfo($table, $id, 'pid' . ($GLOBALS['TCA'][$table]['ctrl']['versioningWS'] ?
',t3ver_wsid,t3ver_stage' : ''));
1023 $theRealPid = $tempdata['pid'];
1024 // Use the new id of the versionized record we're trying to write to:
1025 // (This record is a child record of a parent and has already been versionized.)
1026 if ($this->autoVersionIdMap
[$table][$id]) {
1027 // For the reason that creating a new version of this record, automatically
1028 // created related child records (e.g. "IRRE"), update the accordant field:
1029 $this->getVersionizedIncomingFieldArray($table, $id, $incomingFieldArray, $registerDBList);
1030 // Use the new id of the copied/versionized record:
1031 $id = $this->autoVersionIdMap
[$table][$id];
1032 $recordAccess = TRUE;
1033 $this->autoVersioningUpdate
= TRUE;
1034 } elseif (!$this->bypassWorkspaceRestrictions
&& ($errorCode = $this->BE_USER
->workspaceCannotEditRecord($table, $tempdata))) {
1035 $recordAccess = FALSE;
1036 // Versioning is required and it must be offline version!
1037 // Check if there already is a workspace version
1038 $WSversion = BackendUtility
::getWorkspaceVersionOfRecord($this->BE_USER
->workspace
, $table, $id, 'uid,t3ver_oid');
1040 $id = $WSversion['uid'];
1041 $recordAccess = TRUE;
1042 } elseif ($this->BE_USER
->workspaceAllowAutoCreation($table, $id, $theRealPid)) {
1043 $tce = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler
::class);
1044 /** @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */
1045 $tce->stripslashes_values
= 0;
1046 // Setting up command for creating a new version of the record:
1048 $cmd[$table][$id]['version'] = array(
1051 // Default is to create a version of the individual records... element versioning that is.
1052 'label' => 'Auto-created for WS #' . $this->BE_USER
->workspace
1054 $tce->start(array(), $cmd);
1055 $tce->process_cmdmap();
1056 $this->errorLog
= array_merge($this->errorLog
, $tce->errorLog
);
1057 // If copying was successful, share the new uids (also of related children):
1058 if ($tce->copyMappingArray
[$table][$id]) {
1059 foreach ($tce->copyMappingArray
as $origTable => $origIdArray) {
1060 foreach ($origIdArray as $origId => $newId) {
1061 $this->uploadedFileArray
[$origTable][$newId] = $this->uploadedFileArray
[$origTable][$origId];
1062 $this->autoVersionIdMap
[$origTable][$origId] = $newId;
1065 \TYPO3\CMS\Core\Utility\ArrayUtility
::mergeRecursiveWithOverrule($this->RTEmagic_copyIndex
, $tce->RTEmagic_copyIndex
);
1066 // See where RTEmagic_copyIndex is used inside fillInFieldArray() for more information...
1067 // Update registerDBList, that holds the copied relations to child records:
1068 $registerDBList = array_merge($registerDBList, $tce->registerDBList
);
1069 // For the reason that creating a new version of this record, automatically
1070 // created related child records (e.g. "IRRE"), update the accordant field:
1071 $this->getVersionizedIncomingFieldArray($table, $id, $incomingFieldArray, $registerDBList);
1072 // Use the new id of the copied/versionized record:
1073 $id = $this->autoVersionIdMap
[$table][$id];
1074 $recordAccess = TRUE;
1075 $this->autoVersioningUpdate
= TRUE;
1077 $this->newlog('Could not be edited in offline workspace in the branch where found (failure state: \'' . $errorCode . '\'). Auto-creation of version failed!', 1);
1080 $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);
1085 // The default is 'update'
1088 // If access was granted above, proceed to create or update record:
1089 if ($recordAccess) {
1090 // Here the "pid" is set IF NOT the old pid was a string pointing to a place in the subst-id array.
1091 list($tscPID) = BackendUtility
::getTSCpid($table, $id, $old_pid_value ?
$old_pid_value : $fieldArray['pid']);
1092 $TSConfig = $this->getTCEMAIN_TSconfig($tscPID);
1093 if ($status == 'new' && $table == 'pages' && is_array($TSConfig['permissions.'])) {
1094 $fieldArray = $this->setTSconfigPermissions($fieldArray, $TSConfig['permissions.']);
1096 // Processing of all fields in incomingFieldArray and setting them in $fieldArray
1097 $fieldArray = $this->fillInFieldArray($table, $id, $fieldArray, $incomingFieldArray, $theRealPid, $status, $tscPID);
1098 if ($createNewVersion) {
1099 // create a placeholder array with already processed field content
1100 $newVersion_placeholderFieldArray = $fieldArray;
1102 // NOTICE! All manipulation beyond this point bypasses both "excludeFields" AND possible "MM" relations / file uploads to field!
1103 // Forcing some values unto field array:
1104 // NOTICE: This overriding is potentially dangerous; permissions per field is not checked!!!
1105 $fieldArray = $this->overrideFieldArray($table, $fieldArray);
1106 if ($createNewVersion) {
1107 $newVersion_placeholderFieldArray = $this->overrideFieldArray($table, $newVersion_placeholderFieldArray);
1109 // Setting system fields
1110 if ($status == 'new') {
1111 if ($GLOBALS['TCA'][$table]['ctrl']['crdate']) {
1112 $fieldArray[$GLOBALS['TCA'][$table]['ctrl']['crdate']] = $GLOBALS['EXEC_TIME'];
1113 if ($createNewVersion) {
1114 $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['crdate']] = $GLOBALS['EXEC_TIME'];
1117 if ($GLOBALS['TCA'][$table]['ctrl']['cruser_id']) {
1118 $fieldArray[$GLOBALS['TCA'][$table]['ctrl']['cruser_id']] = $this->userid
;
1119 if ($createNewVersion) {
1120 $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['cruser_id']] = $this->userid
;
1123 } elseif ($this->checkSimilar
) {
1124 // Removing fields which are equal to the current value:
1125 $fieldArray = $this->compareFieldArrayWithCurrentAndUnset($table, $id, $fieldArray);
1127 if ($GLOBALS['TCA'][$table]['ctrl']['tstamp'] && count($fieldArray)) {
1128 $fieldArray[$GLOBALS['TCA'][$table]['ctrl']['tstamp']] = $GLOBALS['EXEC_TIME'];
1129 if ($createNewVersion) {
1130 $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['tstamp']] = $GLOBALS['EXEC_TIME'];
1133 // Set stage to "Editing" to make sure we restart the workflow
1134 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
1135 $fieldArray['t3ver_stage'] = 0;
1137 // Hook: processDatamap_postProcessFieldArray
1138 foreach ($hookObjectsArr as $hookObj) {
1139 if (method_exists($hookObj, 'processDatamap_postProcessFieldArray')) {
1140 $hookObj->processDatamap_postProcessFieldArray($status, $table, $id, $fieldArray, $this);
1143 // Performing insert/update. If fieldArray has been unset by some userfunction (see hook above), don't do anything
1144 // Kasper: Unsetting the fieldArray is dangerous; MM relations might be saved already and files could have been uploaded that are now "lost"
1145 if (is_array($fieldArray)) {
1146 if ($status == 'new') {
1147 // This creates a new version of the record with online placeholder and offline version
1148 if ($createNewVersion) {
1149 $newVersion_placeholderFieldArray['t3ver_label'] = 'INITIAL PLACEHOLDER';
1150 // Setting placeholder state value for temporary record
1151 $newVersion_placeholderFieldArray['t3ver_state'] = (string)new VersionState(VersionState
::NEW_PLACEHOLDER
);
1152 // Setting workspace - only so display of place holders can filter out those from other workspaces.
1153 $newVersion_placeholderFieldArray['t3ver_wsid'] = $this->BE_USER
->workspace
;
1154 $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['label']] = $this->getPlaceholderTitleForTableLabel($table);
1155 // Saving placeholder as 'original'
1156 $this->insertDB($table, $id, $newVersion_placeholderFieldArray, FALSE);
1157 // For the actual new offline version, set versioning values to point to placeholder:
1158 $fieldArray['pid'] = -1;
1159 $fieldArray['t3ver_oid'] = $this->substNEWwithIDs
[$id];
1160 $fieldArray['t3ver_id'] = 1;
1161 // Setting placeholder state value for version (so it can know it is currently a new version...)
1162 $fieldArray['t3ver_state'] = (string)new VersionState(VersionState
::NEW_PLACEHOLDER_VERSION
);
1163 $fieldArray['t3ver_label'] = 'First draft version';
1164 $fieldArray['t3ver_wsid'] = $this->BE_USER
->workspace
;
1165 // When inserted, $this->substNEWwithIDs[$id] will be changed to the uid of THIS version and so the interface will pick it up just nice!
1166 $phShadowId = $this->insertDB($table, $id, $fieldArray, TRUE, 0, TRUE);
1168 // Processes fields of the placeholder record:
1169 $this->triggerRemapAction($table, $id, array($this, 'placeholderShadowing'), array($table, $phShadowId));
1170 // Hold auto-versionized ids of placeholders:
1171 $this->autoVersionIdMap
[$table][$this->substNEWwithIDs
[$id]] = $phShadowId;
1174 $this->insertDB($table, $id, $fieldArray, FALSE, $incomingFieldArray['uid']);
1177 $this->updateDB($table, $id, $fieldArray);
1178 $this->placeholderShadowing($table, $id);
1181 // Hook: processDatamap_afterDatabaseOperations
1182 // Note: When using the hook after INSERT operations, you will only get the temporary NEW... id passed to your hook as $id,
1183 // but you can easily translate it to the real uid of the inserted record using the $this->substNEWwithIDs array.
1184 $this->hook_processDatamap_afterDatabaseOperations($hookObjectsArr, $status, $table, $id, $fieldArray);
1190 // Process the stack of relations to remap/correct
1191 $this->processRemapStack();
1192 $this->dbAnalysisStoreExec();
1193 $this->removeRegisteredFiles();
1194 // Hook: processDatamap_afterAllOperations
1195 // Note: When this hook gets called, all operations on the submitted data have been finished.
1196 foreach ($hookObjectsArr as $hookObj) {
1197 if (method_exists($hookObj, 'processDatamap_afterAllOperations')) {
1198 $hookObj->processDatamap_afterAllOperations($this);
1201 if ($this->isOuterMostInstance()) {
1202 $this->processClearCacheQueue();
1203 $this->resetElementsToBeDeleted();
1208 * Fix shadowing of data in case we are editing a offline version of a live "New" placeholder record:
1210 * @param string $table Table name
1211 * @param int $id Record uid
1214 public function placeholderShadowing($table, $id) {
1215 if ($liveRec = BackendUtility
::getLiveVersionOfRecord($table, $id, '*')) {
1216 if (VersionState
::cast($liveRec['t3ver_state'])->indicatesPlaceholder()) {
1217 $justStoredRecord = BackendUtility
::getRecord($table, $id);
1218 $newRecord = array();
1219 $shadowCols = $GLOBALS['TCA'][$table]['ctrl']['shadowColumnsForNewPlaceholders'];
1220 $shadowCols .= ',' . $GLOBALS['TCA'][$table]['ctrl']['languageField'];
1221 $shadowCols .= ',' . $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
1222 $shadowCols .= ',' . $GLOBALS['TCA'][$table]['ctrl']['type'];
1223 $shadowCols .= ',' . $GLOBALS['TCA'][$table]['ctrl']['label'];
1224 $shadowColumns = array_unique(GeneralUtility
::trimExplode(',', $shadowCols, TRUE));
1225 foreach ($shadowColumns as $fieldName) {
1226 if ((string)$justStoredRecord[$fieldName] !== (string)$liveRec[$fieldName] && isset($GLOBALS['TCA'][$table]['columns'][$fieldName]) && $fieldName !== 'uid' && $fieldName !== 'pid') {
1227 $newRecord[$fieldName] = $justStoredRecord[$fieldName];
1230 if (count($newRecord)) {
1231 $this->newlog2('Shadowing done on fields <i>' . implode(',', array_keys($newRecord)) . '</i> in placeholder record ' . $table . ':' . $liveRec['uid'] . ' (offline version UID=' . $id . ')', $table, $liveRec['uid'], $liveRec['pid']);
1232 $this->updateDB($table, $liveRec['uid'], $newRecord);
1239 * Create a placeholder title for the label field that does match the field requirements
1241 * @param string $table The table name
1242 * @return string placeholder value
1244 protected function getPlaceholderTitleForTableLabel($table) {
1245 $labelPlaceholder = '[PLACEHOLDER, WS#' . $this->BE_USER
->workspace
. ']';
1246 $labelField = $GLOBALS['TCA'][$table]['ctrl']['label'];
1247 if (!isset($GLOBALS['TCA'][$table]['columns'][$labelField]['config']['eval'])) {
1248 return $labelPlaceholder;
1250 $evalCodesArray = GeneralUtility
::trimExplode(',', $GLOBALS['TCA'][$table]['columns'][$labelField]['config']['eval'], TRUE);
1251 $transformedLabel = $this->checkValue_input_Eval($labelPlaceholder, $evalCodesArray, '');
1252 return isset($transformedLabel['value']) ?
$transformedLabel['value'] : $labelPlaceholder;
1256 * Filling in the field array
1257 * $this->exclude_array is used to filter fields if needed.
1259 * @param string $table Table name
1260 * @param int $id Record ID
1261 * @param array $fieldArray Default values, Preset $fieldArray with 'pid' maybe (pid and uid will be not be overridden anyway)
1262 * @param array $incomingFieldArray Is which fields/values you want to set. There are processed and put into $fieldArray if OK
1263 * @param int $realPid The real PID value of the record. For updates, this is just the pid of the record. For new records this is the PID of the page where it is inserted.
1264 * @param string $status Is 'new' or 'update'
1265 * @param int $tscPID TSconfig PID
1266 * @return array Field Array
1268 public function fillInFieldArray($table, $id, $fieldArray, $incomingFieldArray, $realPid, $status, $tscPID) {
1270 $originalLanguageRecord = NULL;
1271 $originalLanguage_diffStorage = NULL;
1272 $diffStorageFlag = FALSE;
1273 // Setting 'currentRecord' and 'checkValueRecord':
1274 if (strstr($id, 'NEW')) {
1275 // Must have the 'current' array - not the values after processing below...
1276 $currentRecord = ($checkValueRecord = $fieldArray);
1277 // IF $incomingFieldArray is an array, overlay it.
1278 // The point is that when new records are created as copies with flex type fields there might be a field containing information about which DataStructure to use and without that information the flexforms cannot be correctly processed.... This should be OK since the $checkValueRecord is used by the flexform evaluation only anyways...
1279 if (is_array($incomingFieldArray) && is_array($checkValueRecord)) {
1280 \TYPO3\CMS\Core\Utility\ArrayUtility
::mergeRecursiveWithOverrule($checkValueRecord, $incomingFieldArray);
1283 // We must use the current values as basis for this!
1284 $currentRecord = ($checkValueRecord = $this->recordInfo($table, $id, '*'));
1285 // This is done to make the pid positive for offline versions; Necessary to have diff-view for pages_language_overlay in workspaces.
1286 BackendUtility
::fixVersioningPid($table, $currentRecord);
1287 // Get original language record if available:
1288 if (is_array($currentRecord) && $GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField'] && $GLOBALS['TCA'][$table]['ctrl']['languageField'] && $currentRecord[$GLOBALS['TCA'][$table]['ctrl']['languageField']] > 0 && $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] && (int)$currentRecord[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] > 0) {
1289 $lookUpTable = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerTable'] ?
: $table;
1290 $originalLanguageRecord = $this->recordInfo($lookUpTable, $currentRecord[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']], '*');
1291 BackendUtility
::workspaceOL($lookUpTable, $originalLanguageRecord);
1292 $originalLanguage_diffStorage = unserialize($currentRecord[$GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField']]);
1295 $this->checkValue_currentRecord
= $checkValueRecord;
1296 // In the following all incoming value-fields are tested:
1297 // - Are the user allowed to change the field?
1298 // - Is the field uid/pid (which are already set)
1299 // - perms-fields for pages-table, then do special things...
1300 // - If the field is nothing of the above and the field is configured in TCA, the fieldvalues are evaluated by ->checkValue
1301 // If everything is OK, the field is entered into $fieldArray[]
1302 foreach ($incomingFieldArray as $field => $fieldValue) {
1303 if (!in_array(($table . '-' . $field), $this->exclude_array
) && !$this->data_disableFields
[$table][$id][$field]) {
1304 // The field must be editable.
1305 // Checking if a value for language can be changed:
1306 $languageDeny = $GLOBALS['TCA'][$table]['ctrl']['languageField'] && (string)$GLOBALS['TCA'][$table]['ctrl']['languageField'] === (string)$field && !$this->BE_USER
->checkLanguageAccess($fieldValue);
1307 if (!$languageDeny) {
1308 // Stripping slashes - will probably be removed the day $this->stripslashes_values is removed as an option...
1309 if ($this->stripslashes_values
) {
1310 if (is_array($fieldValue)) {
1311 GeneralUtility
::stripSlashesOnArray($fieldValue);
1313 $fieldValue = stripslashes($fieldValue);
1320 // Nothing happens, already set
1322 case 'perms_userid':
1324 case 'perms_groupid':
1330 case 'perms_everybody':
1331 // Permissions can be edited by the owner or the administrator
1332 if ($table == 'pages' && ($this->admin ||
$status == 'new' ||
$this->pageInfo($id, 'perms_userid') == $this->userid
)) {
1333 $value = (int)$fieldValue;
1335 case 'perms_userid':
1336 $fieldArray[$field] = $value;
1338 case 'perms_groupid':
1339 $fieldArray[$field] = $value;
1342 if ($value >= 0 && $value < pow(2, 5)) {
1343 $fieldArray[$field] = $value;
1360 case 't3ver_tstamp':
1361 // t3ver_label is not here because it CAN be edited as a regular field!
1364 if (isset($GLOBALS['TCA'][$table]['columns'][$field])) {
1365 // Evaluating the value
1366 $res = $this->checkValue($table, $field, $fieldValue, $id, $status, $realPid, $tscPID);
1367 if (array_key_exists('value', $res)) {
1368 $fieldArray[$field] = $res['value'];
1370 // Add the value of the original record to the diff-storage content:
1371 if ($this->updateModeL10NdiffData
&& $GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField']) {
1372 $originalLanguage_diffStorage[$field] = $this->updateModeL10NdiffDataClear ?
'' : $originalLanguageRecord[$field];
1373 $diffStorageFlag = TRUE;
1375 // If autoversioning is happening we need to perform a nasty hack. The case is parallel to a similar hack inside checkValue_group_select_file().
1376 // When a copy or version is made of a record, a search is made for any RTEmagic* images in fields having the "images" soft reference parser applied.
1377 // That should be TRUE for RTE fields. If any are found they are duplicated to new names and the file reference in the bodytext is updated accordingly.
1378 // However, with auto-versioning the submitted content of the field will just overwrite the corrected values. This leaves a) lost RTEmagic files and b) creates a double reference to the old files.
1379 // The only solution I can come up with is detecting when auto versioning happens, then see if any RTEmagic images was copied and if so make a stupid string-replace of the content !
1380 if ($this->autoVersioningUpdate
=== TRUE) {
1381 if (is_array($this->RTEmagic_copyIndex
[$table][$id][$field])) {
1382 foreach ($this->RTEmagic_copyIndex
[$table][$id][$field] as $oldRTEmagicName => $newRTEmagicName) {
1383 $fieldArray[$field] = str_replace(' src="' . $oldRTEmagicName . '"', ' src="' . $newRTEmagicName . '"', $fieldArray[$field]);
1387 } elseif ($GLOBALS['TCA'][$table]['ctrl']['origUid'] === $field) {
1388 // Allow value for original UID to pass by...
1389 $fieldArray[$field] = $fieldValue;
1395 // Add diff-storage information:
1396 if ($diffStorageFlag && !isset($fieldArray[$GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField']])) {
1397 // If the field is set it would probably be because of an undo-operation - in which case we should not update the field of course...
1398 $fieldArray[$GLOBALS['TCA'][$table]['ctrl']['transOrigDiffSourceField']] = serialize($originalLanguage_diffStorage);
1400 // Checking for RTE-transformations of fields:
1401 $types_fieldConfig = BackendUtility
::getTCAtypes($table, $currentRecord);
1402 $theTypeString = BackendUtility
::getTCAtypeValue($table, $currentRecord);
1403 if (is_array($types_fieldConfig)) {
1404 foreach ($types_fieldConfig as $vconf) {
1405 // Write file configuration:
1406 // inserted array_merge($currentRecord,$fieldArray) 170502
1407 $eFile = \TYPO3\CMS\Core\Html\RteHtmlParser
::evalWriteFile($vconf['spec']['static_write'], array_merge($currentRecord, $fieldArray));
1408 // RTE transformations:
1409 if (!$this->dontProcessTransformations
) {
1410 if (isset($fieldArray[$vconf['field']])) {
1411 // Look for transformation flag:
1412 switch ((string)$incomingFieldArray[('_TRANSFORM_' . $vconf['field'])]) {
1414 $RTEsetup = $this->BE_USER
->getTSConfig('RTE', BackendUtility
::getPagesTSconfig($tscPID));
1415 $thisConfig = BackendUtility
::RTEsetup($RTEsetup['properties'], $table, $vconf['field'], $theTypeString);
1416 // Set alternative relative path for RTE images/links:
1417 $RTErelPath = is_array($eFile) ?
dirname($eFile['relEditFile']) : '';
1418 // Get RTE object, draw form and set flag:
1419 $RTEobj = BackendUtility
::RTEgetObj();
1420 if (is_object($RTEobj)) {
1421 $fieldArray[$vconf['field']] = $RTEobj->transformContent('db', $fieldArray[$vconf['field']], $table, $vconf['field'], $currentRecord, $vconf['spec'], $thisConfig, $RTErelPath, $currentRecord['pid']);
1423 debug('NO RTE OBJECT FOUND!');
1429 // Write file configuration:
1430 if (is_array($eFile)) {
1431 $mixedRec = array_merge($currentRecord, $fieldArray);
1432 $SW_fileContent = GeneralUtility
::getUrl($eFile['editFile']);
1433 $parseHTML = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Html\RteHtmlParser
::class);
1434 /** @var $parseHTML \TYPO3\CMS\Core\Html\RteHtmlParser */
1435 $parseHTML->init('', '');
1436 $eFileMarker = $eFile['markerField'] && trim($mixedRec[$eFile['markerField']]) ?
trim($mixedRec[$eFile['markerField']]) : '###TYPO3_STATICFILE_EDIT###';
1437 // Must replace the marker if present in content!
1438 $insertContent = str_replace($eFileMarker, '', $mixedRec[$eFile['contentField']]);
1439 $SW_fileNewContent = $parseHTML->substituteSubpart($SW_fileContent, $eFileMarker, LF
. $insertContent . LF
, 1, 1);
1440 GeneralUtility
::writeFile($eFile['editFile'], $SW_fileNewContent);
1442 if (!strstr($id, 'NEW') && $eFile['statusField']) {
1443 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . (int)$id, array(
1444 $eFile['statusField'] => $eFile['relEditFile'] . ' updated ' . date('d-m-Y H:i:s') . ', bytes ' . strlen($mixedRec[$eFile['contentField']])
1447 } elseif ($eFile && is_string($eFile)) {
1448 $this->log($table, $id, 2, 0, 1, 'Write-file error: \'%s\'', 13, array($eFile), $realPid);
1452 // Return fieldArray
1456 /*********************************************
1458 * Evaluation of input values
1460 ********************************************/
1462 * Evaluates a value according to $table/$field settings.
1463 * This function is for real database fields - NOT FlexForm "pseudo" fields.
1464 * NOTICE: Calling this function expects this: 1) That the data is saved! (files are copied and so on) 2) That files registered for deletion IS deleted at the end (with ->removeRegisteredFiles() )
1466 * @param string $table Table name
1467 * @param string $field Field name
1468 * @param string $value Value to be evaluated. Notice, this is the INPUT value from the form. The original value (from any existing record) must be manually looked up inside the function if needed - or taken from $currentRecord array.
1469 * @param string $id The record-uid, mainly - but not exclusively - used for logging
1470 * @param string $status 'update' or 'new' flag
1471 * @param int $realPid The real PID value of the record. For updates, this is just the pid of the record. For new records this is the PID of the page where it is inserted. If $realPid is -1 it means that a new version of the record is being inserted.
1472 * @param int $tscPID tscPID
1473 * @return array Returns the evaluated $value as key "value" in this array. Can be checked with isset($res['value']) ...
1475 public function checkValue($table, $field, $value, $id, $status, $realPid, $tscPID) {
1478 $recFID = $table . ':' . $id . ':' . $field;
1479 // Processing special case of field pages.doktype
1480 if (($table === 'pages' ||
$table === 'pages_language_overlay') && $field === 'doktype') {
1481 // If the user may not use this specific doktype, we issue a warning
1482 if (!($this->admin || GeneralUtility
::inList($this->BE_USER
->groupData
['pagetypes_select'], $value))) {
1483 $propArr = $this->getRecordProperties($table, $id);
1484 $this->log($table, $id, 5, 0, 1, 'You cannot change the \'doktype\' of page \'%s\' to the desired value.', 1, array($propArr['header']), $propArr['event_pid']);
1487 if ($status == 'update') {
1488 // This checks 1) if we should check for disallowed tables and 2) if there are records from disallowed tables on the current page
1489 $onlyAllowedTables = isset($GLOBALS['PAGES_TYPES'][$value]['onlyAllowedTables']) ?
$GLOBALS['PAGES_TYPES'][$value]['onlyAllowedTables'] : $GLOBALS['PAGES_TYPES']['default']['onlyAllowedTables'];
1490 if ($onlyAllowedTables) {
1491 $theWrongTables = $this->doesPageHaveUnallowedTables($id, $value);
1492 if ($theWrongTables) {
1493 $propArr = $this->getRecordProperties($table, $id);
1494 $this->log($table, $id, 5, 0, 1, '\'doktype\' of page \'%s\' could not be changed because the page contains records from disallowed tables; %s', 2, array($propArr['header'], $theWrongTables), $propArr['event_pid']);
1500 // Get current value:
1501 $curValueRec = $this->recordInfo($table, $id, $field);
1502 $curValue = $curValueRec[$field];
1503 // Getting config for the field
1504 $tcaFieldConf = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
1505 // Preform processing:
1506 $res = $this->checkValue_SW($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $realPid, $recFID, $field, $this->uploadedFileArray
[$table][$id][$field], $tscPID);
1511 * Branches out evaluation of a field value based on its type as configured in $GLOBALS['TCA']
1512 * Can be called for FlexForm pseudo fields as well, BUT must not have $field set if so.
1514 * @param array $res The result array. The processed value (if any!) is set in the "value" key.
1515 * @param string $value The value to set.
1516 * @param array $tcaFieldConf Field configuration from $GLOBALS['TCA']
1517 * @param string $table Table name
1518 * @param int $id Return UID
1519 * @param [type] $curValue
1520 * @param [type] $status
1521 * @param int $realPid The real PID value of the record. For updates, this is just the pid of the record. For new records this is the PID of the page where it is inserted. If $realPid is -1 it means that a new version of the record is being inserted.
1522 * @param [type] $recFID
1523 * @param string $field Field name. Must NOT be set if the call is for a flexform field (since flexforms are not allowed within flexforms).
1524 * @param [type] $uploadedFiles
1525 * @param [type] $tscPID
1526 * @param array $additionalData Additional data to be forwarded to sub-processors
1527 * @return array Returns the evaluated $value as key "value" in this array.
1529 public function checkValue_SW($res, $value, $tcaFieldConf, $table, $id, $curValue, $status, $realPid, $recFID, $field, $uploadedFiles, $tscPID, array $additionalData = NULL) {
1530 // Convert to NULL value if defined in TCA
1531 if ($value === NULL && !empty($tcaFieldConf['eval']) && GeneralUtility
::inList($tcaFieldConf['eval'], 'null')) {
1532 $res = array('value' => NULL);
1536 $PP = array($table, $id, $curValue, $status, $realPid, $recFID, $tscPID);
1537 switch ($tcaFieldConf['type']) {
1539 $res = $this->checkValue_text($res, $value, $tcaFieldConf, $PP, $field);
1544 $res['value'] = $value;
1547 $res = $this->checkValue_input($res, $value, $tcaFieldConf, $PP, $field);
1550 $res = $this->checkValue_check($res, $value, $tcaFieldConf, $PP, $field);
1553 $res = $this->checkValue_radio($res, $value, $tcaFieldConf, $PP);
1558 $res = $this->checkValue_group_select($res, $value, $tcaFieldConf, $PP, $uploadedFiles, $field);
1561 $res = $this->checkValue_inline($res, $value, $tcaFieldConf, $PP, $field, $additionalData);
1564 // FlexForms are only allowed for real fields.
1566 $res = $this->checkValue_flex($res, $value, $tcaFieldConf, $PP, $uploadedFiles, $field);
1576 * Evaluate "text" type values.
1578 * @param array $res The result array. The processed value (if any!) is set in the "value" key.
1579 * @param string $value The value to set.
1580 * @param array $tcaFieldConf Field configuration from TCA
1581 * @param array $PP Additional parameters in a numeric array: $table,$id,$curValue,$status,$realPid,$recFID
1582 * @param string $field Field name
1583 * @return array Modified $res array
1585 public function checkValue_text($res, $value, $tcaFieldConf, $PP, $field = '') {
1586 $evalCodesArray = GeneralUtility
::trimExplode(',', $tcaFieldConf['eval'], TRUE);
1587 $res = $this->checkValue_text_Eval($value, $evalCodesArray, $tcaFieldConf['is_in']);
1592 * Evaluate "input" type values.
1594 * @param array $res The result array. The processed value (if any!) is set in the "value" key.
1595 * @param string $value The value to set.
1596 * @param array $tcaFieldConf Field configuration from TCA
1597 * @param array $PP Additional parameters in a numeric array: $table,$id,$curValue,$status,$realPid,$recFID
1598 * @param string $field Field name
1599 * @return array Modified $res array
1601 public function checkValue_input($res, $value, $tcaFieldConf, $PP, $field = '') {
1602 list($table, $id, $curValue, $status, $realPid, $recFID) = $PP;
1603 // Handle native date/time fields
1604 $dateTimeFormats = $GLOBALS['TYPO3_DB']->getDateTimeFormats($table);
1605 if (isset($tcaFieldConf['dbType']) && GeneralUtility
::inList('date,datetime', $tcaFieldConf['dbType'])) {
1606 // Convert the date/time into a timestamp for the sake of the checks
1607 $emptyValue = $dateTimeFormats[$tcaFieldConf['dbType']]['empty'];
1608 $format = $dateTimeFormats[$tcaFieldConf['dbType']]['format'];
1609 // At this point in the processing, the timestamps are still based on UTC
1610 $timeZone = new \
DateTimeZone('UTC');
1611 $dateTime = \DateTime
::createFromFormat('!' . $format, $value, $timeZone);
1612 $value = $value === $emptyValue ?
0 : $dateTime->getTimestamp();
1614 // Secures the string-length to be less than max.
1615 if ((int)$tcaFieldConf['max'] > 0) {
1616 $value = $GLOBALS['LANG']->csConvObj
->substr($GLOBALS['LANG']->charSet
, $value, 0, (int)$tcaFieldConf['max']);
1618 // Checking range of value:
1619 if ($tcaFieldConf['range'] && $value != $tcaFieldConf['checkbox'] && (int)$value !== (int)$tcaFieldConf['default']) {
1620 if (isset($tcaFieldConf['range']['upper']) && (int)$value > (int)$tcaFieldConf['range']['upper']) {
1621 $value = $tcaFieldConf['range']['upper'];
1623 if (isset($tcaFieldConf['range']['lower']) && (int)$value < (int)$tcaFieldConf['range']['lower']) {
1624 $value = $tcaFieldConf['range']['lower'];
1627 // Process evaluation settings:
1628 $evalCodesArray = GeneralUtility
::trimExplode(',', $tcaFieldConf['eval'], TRUE);
1629 $res = $this->checkValue_input_Eval($value, $evalCodesArray, $tcaFieldConf['is_in']);
1630 // Process UNIQUE settings:
1631 // Field is NOT set for flexForms - which also means that uniqueInPid and unique is NOT available for flexForm fields! Also getUnique should not be done for versioning and if PID is -1 ($realPid<0) then versioning is happening...
1632 if ($field && $realPid >= 0) {
1633 if ($res['value'] && in_array('uniqueInPid', $evalCodesArray)) {
1634 $res['value'] = $this->getUnique($table, $field, $res['value'], $id, $realPid);
1636 if ($res['value'] && in_array('unique', $evalCodesArray)) {
1637 $res['value'] = $this->getUnique($table, $field, $res['value'], $id);
1640 // Handle native date/time fields
1641 if (isset($tcaFieldConf['dbType']) && GeneralUtility
::inList('date,datetime', $tcaFieldConf['dbType'])) {
1642 // Convert the timestamp back to a date/time
1643 $emptyValue = $dateTimeFormats[$tcaFieldConf['dbType']]['empty'];
1644 $format = $dateTimeFormats[$tcaFieldConf['dbType']]['format'];
1645 $res['value'] = $res['value'] ?
date($format, $res['value']) : $emptyValue;
1651 * Evaluates 'check' type values.
1653 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
1654 * @param string $value The value to set.
1655 * @param array $tcaFieldConf Field configuration from TCA
1656 * @param array $PP Additional parameters in a numeric array: $table,$id,$curValue,$status,$realPid,$recFID
1657 * @param string $field Field name
1658 * @return array Modified $res array
1660 public function checkValue_check($res, $value, $tcaFieldConf, $PP, $field = '') {
1661 list($table, $id, $curValue, $status, $realPid, $recFID) = $PP;
1662 $itemC = count($tcaFieldConf['items']);
1666 $maxV = pow(2, $itemC) - 1;
1670 if ($value > $maxV) {
1673 if ($field && $realPid >= 0 && $value > 0 && !empty($tcaFieldConf['eval'])) {
1674 $evalCodesArray = GeneralUtility
::trimExplode(',', $tcaFieldConf['eval'], TRUE);
1675 $otherRecordsWithSameValue = array();
1676 $maxCheckedRecords = 0;
1677 if (in_array('maximumRecordsCheckedInPid', $evalCodesArray)) {
1678 $otherRecordsWithSameValue = $this->getRecordsWithSameValue($table, $id, $field, $value, $realPid);
1679 $maxCheckedRecords = (int)$tcaFieldConf['validation']['maximumRecordsCheckedInPid'];
1681 if (in_array('maximumRecordsChecked', $evalCodesArray)) {
1682 $otherRecordsWithSameValue = $this->getRecordsWithSameValue($table, $id, $field, $value);
1683 $maxCheckedRecords = (int)$tcaFieldConf['validation']['maximumRecordsChecked'];
1686 // there are more than enough records with value "1" in the DB
1687 // if so, set this value to "0" again
1688 if ($maxCheckedRecords && count($otherRecordsWithSameValue) >= $maxCheckedRecords) {
1690 $this->log($table, $id, 5, 0, 1, 'Could not activate checkbox for field "%s". A total of %s record(s) can have this checkbox activated. Uncheck other records first in order to activate the checkbox of this record.', -1, array($GLOBALS['LANG']->sL(BackendUtility
::getItemLabel($table, $field)), $maxCheckedRecords));
1693 $res['value'] = $value;
1698 * Evaluates 'radio' type values.
1700 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
1701 * @param string $value The value to set.
1702 * @param array $tcaFieldConf Field configuration from TCA
1703 * @param array $PP Additional parameters in a numeric array: $table,$id,$curValue,$status,$realPid,$recFID
1704 * @return array Modified $res array
1706 public function checkValue_radio($res, $value, $tcaFieldConf, $PP) {
1707 list($table, $id, $curValue, $status, $realPid, $recFID) = $PP;
1708 if (is_array($tcaFieldConf['items'])) {
1709 foreach ($tcaFieldConf['items'] as $set) {
1710 if ((string)$set[1] === (string)$value) {
1711 $res['value'] = $value;
1720 * Evaluates 'group' or 'select' type values.
1722 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
1723 * @param string $value The value to set.
1724 * @param array $tcaFieldConf Field configuration from TCA
1725 * @param array $PP Additional parameters in a numeric array: $table,$id,$curValue,$status,$realPid,$recFID
1726 * @param array $uploadedFiles
1727 * @param string $field Field name
1728 * @return array Modified $res array
1730 public function checkValue_group_select($res, $value, $tcaFieldConf, $PP, $uploadedFiles, $field) {
1731 list($table, $id, $curValue, $status, $realPid, $recFID) = $PP;
1732 // Detecting if value sent is an array and if so, implode it around a comma:
1733 if (is_array($value)) {
1734 $value = implode(',', $value);
1736 // This converts all occurencies of '{' to the byte 123 in the string - this is needed in very rare cases where filenames with special characters (like ???, umlaud etc) gets sent to the server as HTML entities instead of bytes. The error is done only by MSIE, not Mozilla and Opera.
1737 // Anyways, this should NOT disturb anything else:
1738 $value = $this->convNumEntityToByteValue($value);
1739 // When values are sent as group or select they come as comma-separated values which are exploded by this function:
1740 $valueArray = $this->checkValue_group_select_explodeSelectGroupValue($value);
1741 // If not multiple is set, then remove duplicates:
1742 if (!$tcaFieldConf['multiple']) {
1743 $valueArray = array_unique($valueArray);
1745 // If an exclusive key is found, discard all others:
1746 if ($tcaFieldConf['type'] == 'select' && $tcaFieldConf['exclusiveKeys']) {
1747 $exclusiveKeys = GeneralUtility
::trimExplode(',', $tcaFieldConf['exclusiveKeys']);
1748 foreach ($valueArray as $kk => $vv) {
1749 // $vv is the item key!
1750 if (in_array($vv, $exclusiveKeys)) {
1751 $valueArray = array($kk => $vv);
1756 // This could be a good spot for parsing the array through a validation-function which checks if the values are alright (except that database references are not in their final form - but that is the point, isn't it?)
1757 // NOTE!!! Must check max-items of files before the later check because that check would just leave out filenames if there are too many!!
1758 $valueArray = $this->applyFiltersToValues($tcaFieldConf, $valueArray);
1759 // Checking for select / authMode, removing elements from $valueArray if any of them is not allowed!
1760 if ($tcaFieldConf['type'] == 'select' && $tcaFieldConf['authMode']) {
1761 $preCount = count($valueArray);
1762 foreach ($valueArray as $kk => $vv) {
1763 if (!$this->BE_USER
->checkAuthMode($table, $field, $vv, $tcaFieldConf['authMode'])) {
1764 unset($valueArray[$kk]);
1767 // During the check it turns out that the value / all values were removed - we respond by simply returning an empty array so nothing is written to DB for this field.
1768 if ($preCount && !count($valueArray)) {
1773 if ($tcaFieldConf['type'] == 'group') {
1774 switch ($tcaFieldConf['internal_type']) {
1775 case 'file_reference':
1778 $valueArray = $this->checkValue_group_select_file($valueArray, $tcaFieldConf, $curValue, $uploadedFiles, $status, $table, $id, $recFID);
1781 $valueArray = $this->checkValue_group_select_processDBdata($valueArray, $tcaFieldConf, $id, $status, 'group', $table, $field);
1785 // For select types which has a foreign table attached:
1786 if ($tcaFieldConf['type'] == 'select' && $tcaFieldConf['foreign_table']) {
1787 // check, if there is a NEW... id in the value, that should be substituded later
1788 if (strpos($value, 'NEW') !== FALSE) {
1789 $this->remapStackRecords
[$table][$id] = array('remapStackIndex' => count($this->remapStack
));
1790 $this->addNewValuesToRemapStackChildIds($valueArray);
1791 $this->remapStack
[] = array(
1792 'func' => 'checkValue_group_select_processDBdata',
1793 'args' => array($valueArray, $tcaFieldConf, $id, $status, 'select', $table, $field),
1794 'pos' => array('valueArray' => 0, 'tcaFieldConf' => 1, 'id' => 2, 'table' => 5),
1797 $unsetResult = TRUE;
1799 $valueArray = $this->checkValue_group_select_processDBdata($valueArray, $tcaFieldConf, $id, $status, 'select', $table, $field);
1802 if (!$unsetResult) {
1803 $newVal = $this->checkValue_checkMax($tcaFieldConf, $valueArray);
1804 $res['value'] = implode(',', $newVal);
1806 unset($res['value']);
1812 * Applies the filter methods from a column's TCA configuration to a value array.
1814 * @param array $tcaFieldConfiguration
1815 * @param array $values
1816 * @return array|mixed
1817 * @throws \RuntimeException
1819 protected function applyFiltersToValues(array $tcaFieldConfiguration, array $values) {
1820 if (empty($tcaFieldConfiguration['filter']) ||
!is_array($tcaFieldConfiguration['filter'])) {
1823 foreach ($tcaFieldConfiguration['filter'] as $filter) {
1824 if (empty($filter['userFunc'])) {
1827 $parameters = $filter['parameters'] ?
: array();
1828 $parameters['values'] = $values;
1829 $parameters['tcaFieldConfig'] = $tcaFieldConfiguration;
1830 $values = GeneralUtility
::callUserFunction($filter['userFunc'], $parameters, $this);
1831 if (!is_array($values)) {
1832 throw new \
RuntimeException('Failed calling filter userFunc.', 1336051942);
1839 * Handling files for group/select function
1841 * @param array $valueArray Array of incoming file references. Keys are numeric, values are files (basically, this is the exploded list of incoming files)
1842 * @param array $tcaFieldConf Configuration array from TCA of the field
1843 * @param string $curValue Current value of the field
1844 * @param array $uploadedFileArray Array of uploaded files, if any
1845 * @param string $status Status ("update" or ?)
1846 * @param string $table tablename of record
1847 * @param int $id UID of record
1848 * @param string $recFID Field identifier ([table:uid:field:....more for flexforms?]
1849 * @return array Modified value array
1850 * @see checkValue_group_select()
1852 public function checkValue_group_select_file($valueArray, $tcaFieldConf, $curValue, $uploadedFileArray, $status, $table, $id, $recFID) {
1853 // If file handling should NOT be bypassed, do processing:
1854 if (!$this->bypassFileHandling
) {
1855 // If any files are uploaded, add them to value array
1856 // Numeric index means that there are multiple files
1857 if (isset($uploadedFileArray[0])) {
1858 $uploadedFiles = $uploadedFileArray;
1860 // There is only one file
1861 $uploadedFiles = array($uploadedFileArray);
1863 foreach ($uploadedFiles as $uploadedFileArray) {
1864 if (!empty($uploadedFileArray['name']) && $uploadedFileArray['tmp_name'] !== 'none') {
1865 $valueArray[] = $uploadedFileArray['tmp_name'];
1866 $this->alternativeFileName
[$uploadedFileArray['tmp_name']] = $uploadedFileArray['name'];
1869 // Creating fileFunc object.
1870 if (!$this->fileFunc
) {
1871 $this->fileFunc
= GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Utility\File\BasicFileUtility
::class);
1872 $this->include_filefunctions
= 1;
1874 // Setting permitted extensions.
1875 $all_files = array();
1876 $all_files['webspace']['allow'] = $tcaFieldConf['allowed'];
1877 $all_files['webspace']['deny'] = $tcaFieldConf['disallowed'] ?
: '*';
1878 $all_files['ftpspace'] = $all_files['webspace'];
1879 $this->fileFunc
->init('', $all_files);
1881 // If there is an upload folder defined:
1882 if ($tcaFieldConf['uploadfolder'] && $tcaFieldConf['internal_type'] == 'file') {
1883 // If filehandling should NOT be bypassed, do processing:
1884 if (!$this->bypassFileHandling
) {
1886 $propArr = $this->getRecordProperties($table, $id);
1887 // Get destrination path:
1888 $dest = $this->destPathFromUploadFolder($tcaFieldConf['uploadfolder']);
1889 // If we are updating:
1890 if ($status == 'update') {
1891 // Traverse the input values and convert to absolute filenames in case the update happens to an autoVersionized record.
1892 // Background: This is a horrible workaround! The problem is that when a record is auto-versionized the files of the record get copied and therefore get new names which is overridden with the names from the original record in the incoming data meaning both lost files and double-references!
1893 // The only solution I could come up with (except removing support for managing files when autoversioning) was to convert all relative files to absolute names so they are copied again (and existing files deleted). This should keep references intact but means that some files are copied, then deleted after being copied _again_.
1894 // Actually, the same problem applies to database references in case auto-versioning would include sub-records since in such a case references are remapped - and they would be overridden due to the same principle then.
1895 // Illustration of the problem comes here:
1896 // We have a record 123 with a file logo.gif. We open and edit the files header in a workspace. So a new version is automatically made.
1897 // The versions uid is 456 and the file is copied to "logo_01.gif". But the form data that we sent was based on uid 123 and hence contains the filename "logo.gif" from the original.
1898 // The file management code below will do two things: First it will blindly accept "logo.gif" as a file attached to the record (thus creating a double reference) and secondly it will find that "logo_01.gif" was not in the incoming filelist and therefore should be deleted.
1899 // If we prefix the incoming file "logo.gif" with its absolute path it will be seen as a new file added. Thus it will be copied to "logo_02.gif". "logo_01.gif" will still be deleted but since the files are the same the difference is zero - only more processing and file copying for no reason. But it will work.
1900 if ($this->autoVersioningUpdate
=== TRUE) {
1901 foreach ($valueArray as $key => $theFile) {
1902 // If it is an already attached file...
1903 if ($theFile === basename($theFile)) {
1904 $valueArray[$key] = PATH_site
. $tcaFieldConf['uploadfolder'] . '/' . $theFile;
1908 // Finding the CURRENT files listed, either from MM or from the current record.
1909 $theFileValues = array();
1910 // If MM relations for the files also!
1911 if ($tcaFieldConf['MM']) {
1912 $dbAnalysis = $this->createRelationHandlerInstance();
1913 /** @var $dbAnalysis \TYPO3\CMS\Core\Database\RelationHandler */
1914 $dbAnalysis->start('', 'files', $tcaFieldConf['MM'], $id);
1915 foreach ($dbAnalysis->itemArray
as $item) {
1917 $theFileValues[] = $item['id'];
1921 $theFileValues = GeneralUtility
::trimExplode(',', $curValue, TRUE);
1923 $currentFilesForHistory = implode(',', $theFileValues);
1924 // DELETE files: If existing files were found, traverse those and register files for deletion which has been removed:
1925 if (count($theFileValues)) {
1926 // Traverse the input values and for all input values which match an EXISTING value, remove the existing from $theFileValues array (this will result in an array of all the existing files which should be deleted!)
1927 foreach ($valueArray as $key => $theFile) {
1928 if ($theFile && !strstr(GeneralUtility
::fixWindowsFilePath($theFile), '/')) {
1929 $theFileValues = GeneralUtility
::removeArrayEntryByValue($theFileValues, $theFile);
1932 // This array contains the filenames in the uploadfolder that should be deleted:
1933 foreach ($theFileValues as $key => $theFile) {
1934 $theFile = trim($theFile);
1935 if (@is_file
(($dest . '/' . $theFile))) {
1936 $this->removeFilesStore
[] = $dest . '/' . $theFile;
1937 } elseif ($theFile) {
1938 $this->log($table, $id, 5, 0, 1, 'Could not delete file \'%s\' (does not exist). (%s)', 10, array($dest . '/' . $theFile, $recFID), $propArr['event_pid']);
1943 // Traverse the submitted values:
1944 foreach ($valueArray as $key => $theFile) {
1946 $maxSize = (int)$tcaFieldConf['max_size'];
1947 // Must be cleared. Else a faulty fileref may be inserted if the below code returns an error!
1949 // a FAL file was added, now resolve the file object and get the absolute path
1950 // @todo in future versions this needs to be modified to handle FAL objects natively
1951 if (!empty($theFile) && \TYPO3\CMS\Core\Utility\MathUtility
::canBeInterpretedAsInteger($theFile)) {
1952 $fileObject = \TYPO3\CMS\Core\
Resource\ResourceFactory
::getInstance()->getFileObject($theFile);
1953 $theFile = $fileObject->getForLocalProcessing(FALSE);
1955 // NEW FILES? If the value contains '/' it indicates, that the file
1956 // is new and should be added to the uploadsdir (whether its absolute or relative does not matter here)
1957 if (strstr(GeneralUtility
::fixWindowsFilePath($theFile), '/')) {
1958 // Check various things before copying file:
1959 // File and destination must exist
1960 if (@is_dir
($dest) && (@is_file
($theFile) || @is_uploaded_file
($theFile))) {
1962 if (is_uploaded_file($theFile) && $theFile == $uploadedFileArray['tmp_name']) {
1963 $fileSize = $uploadedFileArray['size'];
1965 $fileSize = filesize($theFile);
1968 if (!$maxSize ||
$fileSize <= $maxSize * 1024) {
1969 // Prepare filename:
1970 $theEndFileName = isset($this->alternativeFileName
[$theFile]) ?
$this->alternativeFileName
[$theFile] : $theFile;
1971 $fI = GeneralUtility
::split_fileref($theEndFileName);
1972 // Check for allowed extension:
1973 if ($this->fileFunc
->checkIfAllowed($fI['fileext'], $dest, $theEndFileName)) {
1974 $theDestFile = $this->fileFunc
->getUniqueName($this->fileFunc
->cleanFileName($fI['file']), $dest);
1975 // If we have a unique destination filename, then write the file:
1977 GeneralUtility
::upload_copy_move($theFile, $theDestFile);
1978 // Hook for post-processing the upload action
1979 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processUpload'])) {
1980 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processUpload'] as $classRef) {
1981 $hookObject = GeneralUtility
::getUserObj($classRef);
1982 if (!$hookObject instanceof \TYPO3\CMS\Core\DataHandling\DataHandlerProcessUploadHookInterface
) {
1983 throw new \
UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Core\\DataHandling\\DataHandlerProcessUploadHookInterface', 1279962349);
1985 $hookObject->processUpload_postProcessAction($theDestFile, $this);
1988 $this->copiedFileMap
[$theFile] = $theDestFile;
1990 if (!@is_file
($theDestFile)) {
1991 $this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: The destination path (%s) may be write protected. Please make it write enabled!. (%s)', 16, array($theFile, dirname($theDestFile), $recFID), $propArr['event_pid']);
1994 $this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: No destination file (%s) possible!. (%s)', 11, array($theFile, $theDestFile, $recFID), $propArr['event_pid']);
1997 $this->log($table, $id, 5, 0, 1, 'File extension \'%s\' not allowed. (%s)', 12, array($fI['fileext'], $recFID), $propArr['event_pid']);
2000 $this->log($table, $id, 5, 0, 1, 'Filesize (%s) of file \'%s\' exceeds limit (%s). (%s)', 13, array(GeneralUtility
::formatSize($fileSize), $theFile, GeneralUtility
::formatSize($maxSize * 1024), $recFID), $propArr['event_pid']);
2003 $this->log($table, $id, 5, 0, 1, 'The destination (%s) or the source file (%s) does not exist. (%s)', 14, array($dest, $theFile, $recFID), $propArr['event_pid']);
2005 // If the destination file was created, we will set the new filename in
2006 // the value array, otherwise unset the entry in the value array!
2007 if (@is_file
($theDestFile)) {
2008 $info = GeneralUtility
::split_fileref($theDestFile);
2009 // The value is set to the new filename
2010 $valueArray[$key] = $info['file'];
2012 // The value is set to the new filename
2013 unset($valueArray[$key]);
2018 // If MM relations for the files, we will set the relations as MM records and change the valuearray to contain a single entry with a count of the number of files!
2019 if ($tcaFieldConf['MM']) {
2020 /** @var $dbAnalysis \TYPO3\CMS\Core\Database\RelationHandler */
2021 $dbAnalysis = $this->createRelationHandlerInstance();
2023 $dbAnalysis->tableArray
['files'] = array();
2024 foreach ($valueArray as $key => $theFile) {
2026 $dbAnalysis->itemArray
[]['id'] = $theFile;
2028 if ($status == 'update') {
2029 $dbAnalysis->writeMM($tcaFieldConf['MM'], $id, 0);
2030 $newFiles = implode(',', $dbAnalysis->getValueArray());
2031 list(, , $recFieldName) = explode(':', $recFID);
2032 if ($currentFilesForHistory != $newFiles) {
2033 $this->mmHistoryRecords
[$table . ':' . $id]['oldRecord'][$recFieldName] = $currentFilesForHistory;
2034 $this->mmHistoryRecords
[$table . ':' . $id]['newRecord'][$recFieldName] = $newFiles;
2036 $this->mmHistoryRecords
[$table . ':' . $id]['oldRecord'][$recFieldName] = '';
2037 $this->mmHistoryRecords
[$table . ':' . $id]['newRecord'][$recFieldName] = '';
2040 $this->dbAnalysisStore
[] = array($dbAnalysis, $tcaFieldConf['MM'], $id, 0);
2042 $valueArray = $dbAnalysis->countItems();
2045 if (count($valueArray)) {
2046 // If filehandling should NOT be bypassed, do processing:
2047 if (!$this->bypassFileHandling
) {
2049 $propArr = $this->getRecordProperties($table, $id);
2050 foreach ($valueArray as &$theFile) {
2051 // FAL handling: it's a UID, thus it is resolved to the absolute path
2052 if (!empty($theFile) && \TYPO3\CMS\Core\Utility\MathUtility
::canBeInterpretedAsInteger($theFile)) {
2053 $fileObject = \TYPO3\CMS\Core\
Resource\ResourceFactory
::getInstance()->getFileObject($theFile);
2054 $theFile = $fileObject->getForLocalProcessing(FALSE);
2056 if ($this->alternativeFilePath
[$theFile]) {
2057 // If alernative File Path is set for the file, then it was an import
2058 // don't import the file if it already exists
2059 if (@is_file
((PATH_site
. $this->alternativeFilePath
[$theFile]))) {
2060 $theFile = PATH_site
. $this->alternativeFilePath
[$theFile];
2061 } elseif (@is_file
($theFile)) {
2062 $dest = dirname(PATH_site
. $this->alternativeFilePath
[$theFile]);
2063 if (!@is_dir
($dest)) {
2064 GeneralUtility
::mkdir_deep(PATH_site
, dirname($this->alternativeFilePath
[$theFile]) . '/');
2067 $maxSize = (int)$tcaFieldConf['max_size'];
2069 // Must be cleared. Else a faulty fileref may be inserted if the below code returns an error!
2071 $fileSize = filesize($theFile);
2073 if (!$maxSize ||
$fileSize <= $maxSize * 1024) {
2074 // Prepare filename:
2075 $theEndFileName = isset($this->alternativeFileName
[$theFile]) ?
$this->alternativeFileName
[$theFile] : $theFile;
2076 $fI = GeneralUtility
::split_fileref($theEndFileName);
2077 // Check for allowed extension:
2078 if ($this->fileFunc
->checkIfAllowed($fI['fileext'], $dest, $theEndFileName)) {
2079 $theDestFile = PATH_site
. $this->alternativeFilePath
[$theFile];
2082 GeneralUtility
::upload_copy_move($theFile, $theDestFile);
2083 $this->copiedFileMap
[$theFile] = $theDestFile;
2085 if (!@is_file
($theDestFile)) {
2086 $this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: The destination path (%s) may be write protected. Please make it write enabled!. (%s)', 16, array($theFile, dirname($theDestFile), $recFID), $propArr['event_pid']);
2089 $this->log($table, $id, 5, 0, 1, 'Copying file \'%s\' failed!: No destination file (%s) possible!. (%s)', 11, array($theFile, $theDestFile, $recFID), $propArr['event_pid']);
2092 $this->log($table, $id, 5, 0, 1, 'File extension \'%s\' not allowed. (%s)', 12, array($fI['fileext'], $recFID), $propArr['event_pid']);
2095 $this->log($table, $id, 5, 0, 1, 'Filesize (%s) of file \'%s\' exceeds limit (%s). (%s)', 13, array(GeneralUtility
::formatSize($fileSize), $theFile, GeneralUtility
::formatSize($maxSize * 1024), $recFID), $propArr['event_pid']);
2097 // If the destination file was created, we will set the new filename in the value array, otherwise unset the entry in the value array!
2098 if (@is_file
($theDestFile)) {
2099 // The value is set to the new filename
2100 $theFile = $theDestFile;
2102 // The value is set to the new filename
2107 $theFile = GeneralUtility
::fixWindowsFilePath($theFile);
2108 if (GeneralUtility
::isFirstPartOfStr($theFile, PATH_site
)) {
2109 $theFile = \TYPO3\CMS\Core\Utility\PathUtility
::stripPathSitePrefix($theFile);
2120 * Evaluates 'flex' type values.
2122 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
2123 * @param string $value The value to set.
2124 * @param array $tcaFieldConf Field configuration from TCA
2125 * @param array $PP Additional parameters in a numeric array: $table,$id,$curValue,$status,$realPid,$recFID
2126 * @param array $uploadedFiles Uploaded files for the field
2127 * @param string $field Field name
2128 * @return array Modified $res array
2130 public function checkValue_flex($res, $value, $tcaFieldConf, $PP, $uploadedFiles, $field) {
2131 list($table, $id, $curValue, $status, $realPid, $recFID) = $PP;
2133 if (is_array($value)) {
2134 // This value is necessary for flex form processing to happen on flexform fields in page records when they are copied.
2135 // The problem is, that when copying a page, flexfrom XML comes along in the array for the new record - but since $this->checkValue_currentRecord does not have a uid or pid for that sake, the \TYPO3\CMS\Backend\Utility\BackendUtility::getFlexFormDS() function returns no good DS. For new records we do know the expected PID so therefore we send that with this special parameter. Only active when larger than zero.
2136 $newRecordPidValue = $status == 'new' ?
$realPid : 0;
2137 // Get current value array:
2138 $dataStructArray = BackendUtility
::getFlexFormDS($tcaFieldConf, $this->checkValue_currentRecord
, $table, $field, TRUE, $newRecordPidValue);
2139 $currentValueArray = GeneralUtility
::xml2array($curValue);
2140 if (!is_array($currentValueArray)) {
2141 $currentValueArray = array();
2143 if (is_array($currentValueArray['meta']['currentLangId'])) {
2144 unset($currentValueArray['meta']['currentLangId']);
2146 // Remove all old meta for languages...
2147 // Evaluation of input values:
2148 $value['data'] = $this->checkValue_flex_procInData($value['data'], $currentValueArray['data'], $uploadedFiles['data'], $dataStructArray, $PP);
2149 // Create XML and convert charsets from input value:
2150 $xmlValue = $this->checkValue_flexArray2Xml($value, TRUE);
2151 // If we wanted to set UTF fixed:
2152 // $storeInCharset='utf-8';
2153 // $currentCharset=$GLOBALS['LANG']->charSet;
2154 // $xmlValue = $GLOBALS['LANG']->csConvObj->conv($xmlValue,$currentCharset,$storeInCharset,1);
2155 $storeInCharset = $GLOBALS['LANG']->charSet
;
2156 // Merge them together IF they are both arrays:
2157 // Here we convert the currently submitted values BACK to an array, then merge the two and then BACK to XML again. This is needed to ensure the charsets are the same (provided that the current value was already stored IN the charset that the new value is converted to).
2158 if (is_array($currentValueArray)) {
2159 $arrValue = GeneralUtility
::xml2array($xmlValue);
2161 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkFlexFormValue'])) {
2162 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['checkFlexFormValue'] as $classRef) {
2163 $hookObject = GeneralUtility
::getUserObj($classRef);
2164 if (method_exists($hookObject, 'checkFlexFormValue_beforeMerge')) {
2165 $hookObject->checkFlexFormValue_beforeMerge($this, $currentValueArray, $arrValue);
2170 \TYPO3\CMS\Core\Utility\ArrayUtility
::mergeRecursiveWithOverrule($currentValueArray, $arrValue);
2171 $xmlValue = $this->checkValue_flexArray2Xml($currentValueArray, TRUE);
2173 // Action commands (sorting order and removals of elements)
2174 $actionCMDs = GeneralUtility
::_GP('_ACTION_FLEX_FORMdata');
2175 if (is_array($actionCMDs[$table][$id][$field]['data'])) {
2176 $arrValue = GeneralUtility
::xml2array($xmlValue);
2177 $this->_ACTION_FLEX_FORMdata($arrValue['data'], $actionCMDs[$table][$id][$field]['data']);
2178 $xmlValue = $this->checkValue_flexArray2Xml($arrValue, TRUE);
2180 // Create the value XML:
2182 $res['value'] .= $xmlValue;
2185 $res['value'] = $value;
2192 * Converts an array to FlexForm XML
2194 * @param array $array Array with FlexForm data
2195 * @param bool $addPrologue If set, the XML prologue is returned as well.
2196 * @return string Input array converted to XML
2198 public function checkValue_flexArray2Xml($array, $addPrologue = FALSE) {
2199 /** @var $flexObj \TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools */
2200 $flexObj = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools
::class);
2201 return $flexObj->flexArray2Xml($array, $addPrologue);
2205 * Actions for flex form element (move, delete)
2207 * @param array &$valueArrayToRemoveFrom by reference
2208 * @param array $deleteCMDS
2211 public function _ACTION_FLEX_FORMdata(&$valueArray, $actionCMDs) {
2212 if (is_array($valueArray) && is_array($actionCMDs)) {
2213 foreach ($actionCMDs as $key => $value) {
2214 if ($key == '_ACTION') {
2215 // First, check if there are "commands":
2216 if (current($actionCMDs[$key]) !== '') {
2217 asort($actionCMDs[$key]);
2218 $newValueArray = array();
2219 foreach ($actionCMDs[$key] as $idx => $order) {
2220 if (substr($idx, 0, 3) == 'ID-') {
2221 $idx = $this->newIndexMap
[$idx];
2223 // Just one reflection here: It is clear that when removing elements from a flexform, then we will get lost files unless we act on this delete operation by traversing and deleting files that were referred to.
2224 if ($order != 'DELETE') {
2225 $newValueArray[$idx] = $valueArray[$idx];
2227 unset($valueArray[$idx]);
2229 $valueArray = GeneralUtility
::array_merge($newValueArray, $valueArray);
2231 } elseif (is_array($actionCMDs[$key]) && isset($valueArray[$key])) {
2232 $this->_ACTION_FLEX_FORMdata($valueArray[$key], $actionCMDs[$key]);
2239 * Evaluates 'inline' type values.
2240 * (partly copied from the select_group function on this issue)
2242 * @param array $res The result array. The processed value (if any!) is set in the 'value' key.
2243 * @param string $value The value to set.
2244 * @param array $tcaFieldConf Field configuration from TCA
2245 * @param array $PP Additional parameters in a numeric array: $table,$id,$curValue,$status,$realPid,$recFID
2246 * @param string $field Field name
2247 * @param array $additionalData Additional data to be forwarded to sub-processors
2248 * @return array Modified $res array
2250 public function checkValue_inline($res, $value, $tcaFieldConf, $PP, $field, array $additionalData = NULL) {
2251 list($table, $id, $curValue, $status, $realPid, $recFID) = $PP;
2252 if (!$tcaFieldConf['foreign_table']) {
2253 // Fatal error, inline fields should always have a foreign_table defined
2256 // When values are sent they come as comma-separated values which are exploded by this function:
2257 $valueArray = GeneralUtility
::trimExplode(',', $value);
2258 // Remove duplicates: (should not be needed)
2259 $valueArray = array_unique($valueArray);
2260 // Example for received data:
2261 // $value = 45,NEW4555fdf59d154,12,123
2262 // We need to decide whether we use the stack or can save the relation directly.
2263 if (strpos($value, 'NEW') !== FALSE ||
!\TYPO3\CMS\Core\Utility\MathUtility
::canBeInterpretedAsInteger($id)) {
2264 $this->remapStackRecords
[$table][$id] = array('remapStackIndex' => count($this->remapStack
));
2265 $this->addNewValuesToRemapStackChildIds($valueArray);
2266 $this->remapStack
[] = array(
2267 'func' => 'checkValue_inline_processDBdata',
2268 'args' => array($valueArray, $tcaFieldConf, $id, $status, $table, $field, $additionalData),
2269 'pos' => array('valueArray' => 0, 'tcaFieldConf' => 1, 'id' => 2, 'table' => 4),
2270 'additionalData' => $additionalData,
2273 unset($res['value']);
2274 } elseif ($value || \TYPO3\CMS\Core\Utility\MathUtility
::canBeInterpretedAsInteger($id)) {
2275 $res['value'] = $this->checkValue_inline_processDBdata($valueArray, $tcaFieldConf, $id, $status, $table, $field, $additionalData);
2281 * Checks if a fields has more items than defined via TCA in maxitems.
2282 * If there are more items than allowd, the item list is truncated to the defined number.
2284 * @param array $tcaFieldConf Field configuration from TCA
2285 * @param array $valueArray Current value array of items
2286 * @return array The truncated value array of items
2288 public function checkValue_checkMax($tcaFieldConf, $valueArray) {
2289 // BTW, checking for min and max items here does NOT make any sense when MM is used because the above function calls will just return an array with a single item (the count) if MM is used... Why didn't I perform the check before? Probably because we could not evaluate the validity of record uids etc... Hmm...
2290 $valueArrayC = count($valueArray);
2291 // NOTE to the comment: It's not really possible to check for too few items, because you must then determine first, if the field is actual used regarding the CType.
2292 $maxI = isset($tcaFieldConf['maxitems']) ?
(int)$tcaFieldConf['maxitems'] : 1;
2293 if ($valueArrayC > $maxI) {
2294 $valueArrayC = $maxI;
2296 // Checking for not too many elements
2297 // Dumping array to list
2299 foreach ($valueArray as $nextVal) {
2300 if ($valueArrayC == 0) {
2304 $newVal[] = $nextVal;
2309 /*********************************************
2311 * Helper functions for evaluation functions.
2313 ********************************************/
2315 * Gets a unique value for $table/$id/$field based on $value
2317 * @param string $table Table name
2318 * @param string $field Field name for which $value must be unique
2319 * @param string $value Value string.
2320 * @param int $id UID to filter out in the lookup (the record itself...)
2321 * @param int $newPid If set, the value will be unique for this PID
2322 * @return string Modified value (if not-unique). Will be the value appended with a number (until 100, then the function just breaks).
2324 public function getUnique($table, $field, $value, $id, $newPid = 0) {
2329 $whereAdd .= ' AND pid=' . (int)$newPid;
2331 $whereAdd .= ' AND pid>=0';
2333 // "AND pid>=0" for versioning
2334 $whereAdd .= $this->deleteClause($table);
2335 // If the field is configured in TCA, proceed:
2336 if (is_array($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]['columns'][$field])) {
2337 // Look for a record which might already have the value:
2338 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, $field . '=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($value, $table) . ' AND uid<>' . (int)$id . $whereAdd);
2340 // For as long as records with the test-value existing, try again (with incremented numbers appended).
2341 while ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) {
2342 $newValue = $value . $counter;
2343 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, $field . '=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($newValue, $table) . ' AND uid<>' . (int)$id . $whereAdd);
2345 if ($counter > 100) {
2349 $GLOBALS['TYPO3_DB']->sql_free_result($res);
2350 // If the new value is there:
2351 $value = strlen($newValue) ?
$newValue : $value;
2357 * gets all records that have the same value in a field
2358 * excluding the given uid
2360 * @param string $tableName Table name
2361 * @param int $uid UID to filter out in the lookup (the record itself...)
2362 * @param string $fieldName Field name for which $value must be unique
2363 * @param string $value Value string.
2364 * @param int $pageId If set, the value will be unique for this PID
2367 public function getRecordsWithSameValue($tableName, $uid, $fieldName, $value, $pageId = 0) {
2369 if (!empty($GLOBALS['TCA'][$tableName]['columns'][$fieldName])) {
2372 $pageId = (int)$pageId;
2373 $whereStatement = ' AND uid <> ' . $uid . ' AND ' . ($pageId ?
'pid = ' . $pageId : 'pid >= 0');
2374 $result = BackendUtility
::getRecordsByField($tableName, $fieldName, $value, $whereStatement);
2380 * @param string $value The field value to be evaluated
2381 * @param array $evalArray Array of evaluations to traverse.
2382 * @param string $is_in The "is_in" value of the field configuration from TCA
2385 public function checkValue_text_Eval($value, $evalArray, $is_in) {
2389 foreach ($evalArray as $func) {
2392 $value = trim($value);
2400 $evalObj = GeneralUtility
::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func] . ':&' . $func);
2401 if (is_object($evalObj) && method_exists($evalObj, 'evaluateFieldValue')) {
2402 $value = $evalObj->evaluateFieldValue($value, $is_in, $set);
2407 $res['value'] = $value;
2413 * Evaluation of 'input'-type values based on 'eval' list
2415 * @param string $value Value to evaluate
2416 * @param array $evalArray Array of evaluations to traverse.
2417 * @param string $is_in Is-in string for 'is_in' evaluation
2418 * @return array Modified $value in key 'value' or empty array
2420 public function checkValue_input_Eval($value, $evalArray, $is_in) {
2424 foreach ($evalArray as $func) {
2433 $value = (int)$value;
2438 $value = (int)$value;
2439 if ($value > 0 && !$this->dontProcessTransformations
) {
2440 $value -= date('Z', $value);
2444 $value = preg_replace('/[^0-9,\\.-]/', '', $value);
2445 $negative = $value[0] === '-';
2446 $value = strtr($value, array(',' => '.', '-' => ''));
2447 if (strpos($value, '.') === FALSE) {
2450 $valueArray = explode('.', $value);
2451 $dec = array_pop($valueArray);
2452 $value = join('', $valueArray) . '.' . $dec;
2456 $value = number_format($value, 2, '.', '');
2459 if (strlen($value) != 32) {
2464 $value = trim($value);
2467 $value = $GLOBALS['LANG']->csConvObj
->conv_case($GLOBALS['LANG']->charSet
, $value, 'toUpper');
2470 $value = $GLOBALS['LANG']->csConvObj
->conv_case($GLOBALS['LANG']->charSet
, $value, 'toLower');
2473 if (!isset($value) ||
$value === '') {
2478 $c = strlen($value);
2481 for ($a = 0; $a < $c; $a++
) {
2482 $char = substr($value, $a, 1);
2483 if (strpos($is_in, $char) !== FALSE) {
2491 $value = str_replace(' ', '', $value);
2494 $value = preg_replace('/[^a-zA-Z]/', '', $value);
2497 $value = preg_replace('/[^0-9]/', '', $value);
2500 $value = preg_replace('/[^a-zA-Z0-9]/', '', $value);
2503 $value = preg_replace('/[^a-zA-Z0-9_-]/', '', $value);
2506 if (!preg_match('/^[a-z0-9.\\-]*$/i', $value)) {
2507 $value = GeneralUtility
::idnaEncode($value);
2511 $this->checkValue_input_ValidateEmail($value, $set);
2514 $evalObj = GeneralUtility
::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func] . ':&' . $func);
2515 if (is_object($evalObj) && method_exists($evalObj, 'evaluateFieldValue')) {
2516 $value = $evalObj->evaluateFieldValue($value, $is_in, $set);
2521 $res['value'] = $value;
2527 * If $value is not a valid e-mail address,
2528 * $set will be set to false and a flash error
2529 * message will be added
2531 * @param string $value Value to evaluate
2532 * @param bool $set TRUE if an update should be done
2533 * @throws \InvalidArgumentException
2534 * @throws \TYPO3\CMS\Core\Exception
2537 protected function checkValue_input_ValidateEmail($value, &$set) {
2538 if (GeneralUtility
::validEmail($value)) {
2543 /** @var FlashMessage $message */
2544 $message = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage
::class,
2545 sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:error.invalidEmail'), $value),
2546 '', // header is optional
2547 FlashMessage
::ERROR
,
2548 TRUE // whether message should be stored in session
2550 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
2551 $flashMessageService = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService
::class);
2552 $flashMessageService->getMessageQueueByIdentifier()->enqueue($message);
2556 * Returns data for group/db and select fields
2558 * @param array $valueArray Current value array
2559 * @param array $tcaFieldConf TCA field config
2560 * @param int $id Record id, used for look-up of MM relations (local_uid)
2561 * @param string $status Status string ('update' or 'new')
2562 * @param string $type The type, either 'select', 'group' or 'inline'
2563 * @param string $currentTable Table name, needs to be passed to \TYPO3\CMS\Core\Database\RelationHandler
2564 * @param string $currentField field name, needs to be set for writing to sys_history
2565 * @return array Modified value array
2567 public function checkValue_group_select_processDBdata($valueArray, $tcaFieldConf, $id, $status, $type, $currentTable, $currentField) {
2568 $tables = $type == 'group' ?
$tcaFieldConf['allowed'] : $tcaFieldConf['foreign_table'] . ',' . $tcaFieldConf['neg_foreign_table'];
2569 $prep = $type == 'group' ?
$tcaFieldConf['prepend_tname'] : $tcaFieldConf['neg_foreign_table'];
2570 $newRelations = implode(',', $valueArray);
2571 /** @var $dbAnalysis \TYPO3\CMS\Core\Database\RelationHandler */
2572 $dbAnalysis = $this->createRelationHandlerInstance();
2573 $dbAnalysis->registerNonTableValues
= $tcaFieldConf['allowNonIdValues'] ?
1 : 0;
2574 $dbAnalysis->start($newRelations, $tables, '', 0, $currentTable, $tcaFieldConf);
2575 if ($tcaFieldConf['MM']) {
2576 if ($status == 'update') {
2577 /** @var $oldRelations_dbAnalysis \TYPO3\CMS\Core\Database\RelationHandler */
2578 $oldRelations_dbAnalysis = $this->createRelationHandlerInstance();
2579 $oldRelations_dbAnalysis->registerNonTableValues
= $tcaFieldConf['allowNonIdValues'] ?
1 : 0;
2580 // Db analysis with $id will initialize with the existing relations
2581 $oldRelations_dbAnalysis->start('', $tables, $tcaFieldConf['MM'], $id, $currentTable, $tcaFieldConf);
2582 $oldRelations = implode(',', $oldRelations_dbAnalysis->getValueArray());
2583 $dbAnalysis->writeMM($tcaFieldConf['MM'], $id, $prep);
2584 if ($oldRelations != $newRelations) {
2585 $this->mmHistoryRecords
[$currentTable . ':' . $id]['oldRecord'][$currentField] = $oldRelations;
2586 $this->mmHistoryRecords
[$currentTable . ':' . $id]['newRecord'][$currentField] = $newRelations;
2588 $this->mmHistoryRecords
[$currentTable . ':' . $id]['oldRecord'][$currentField] = '';
2589 $this->mmHistoryRecords
[$currentTable . ':' . $id]['newRecord'][$currentField] = '';
2592 $this->dbAnalysisStore
[] = array($dbAnalysis, $tcaFieldConf['MM'], $id, $prep, $currentTable);
2594 $valueArray = $dbAnalysis->countItems();
2596 $valueArray = $dbAnalysis->getValueArray($prep);
2597 if ($type == 'select' && $prep) {
2598 $valueArray = $dbAnalysis->convertPosNeg($valueArray, $tcaFieldConf['foreign_table'], $tcaFieldConf['neg_foreign_table']);
2601 // Here we should see if 1) the records exist anymore, 2) which are new and check if the BE_USER has read-access to the new ones.
2606 * Explodes the $value, which is a list of files/uids (group select)
2608 * @param string $value Input string, comma separated values. For each part it will also be detected if a '|' is found and the first part will then be used if that is the case. Further the value will be rawurldecoded.
2609 * @return array The value array.
2611 public function checkValue_group_select_explodeSelectGroupValue($value) {
2612 $valueArray = GeneralUtility
::trimExplode(',', $value, TRUE);
2613 foreach ($valueArray as &$newVal) {
2614 $temp = explode('|', $newVal, 2);
2615 $newVal = str_replace(',', '', str_replace('|', '', rawurldecode($temp[0])));
2622 * Starts the processing the input data for flexforms. This will traverse all sheets / languages and for each it will traverse the sub-structure.
2623 * See checkValue_flex_procInData_travDS() for more details.
2624 * WARNING: Currently, it traverses based on the actual _data_ array and NOT the _structure_. This means that values for non-valid fields, lKey/vKey/sKeys will be accepted! For traversal of data with a call back function you should rather use \TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools
2626 * @param array $dataPart The 'data' part of the INPUT flexform data
2627 * @param array $dataPart_current The 'data' part of the CURRENT flexform data
2628 * @param array $uploadedFiles The uploaded files for the 'data' part of the INPUT flexform data
2629 * @param array $dataStructArray Data structure for the form (might be sheets or not). Only values in the data array which has a configuration in the data structure will be processed.
2630 * @param array $pParams A set of parameters to pass through for the calling of the evaluation functions
2631 * @param string $callBackFunc Optional call back function, see checkValue_flex_procInData_travDS() DEPRICATED, use \TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools instead for traversal!
2632 * @return array The modified 'data' part.
2633 * @see checkValue_flex_procInData_travDS()
2635 public function checkValue_flex_procInData($dataPart, $dataPart_current, $uploadedFiles, $dataStructArray, $pParams, $callBackFunc = '') {
2636 if (is_array($dataPart)) {
2637 foreach ($dataPart as $sKey => $sheetDef) {
2638 list($dataStruct, $actualSheet) = GeneralUtility
::resolveSheetDefInDS($dataStructArray, $sKey);
2639 if (is_array($dataStruct) && $actualSheet == $sKey && is_array($sheetDef)) {
2640 foreach ($sheetDef as $lKey => $lData) {
2641 $this->checkValue_flex_procInData_travDS($dataPart[$sKey][$lKey], $dataPart_current[$sKey][$lKey], $uploadedFiles[$sKey][$lKey], $dataStruct['ROOT']['el'], $pParams, $callBackFunc, $sKey . '/' . $lKey . '/');
2650 * Processing of the sheet/language data array
2651 * When it finds a field with a value the processing is done by ->checkValue_SW() by default but if a call back function name is given that method in this class will be called for the processing instead.
2653 * @param array $dataValues New values (those being processed): Multidimensional Data array for sheet/language, passed by reference!
2654 * @param array $dataValues_current Current values: Multidimensional Data array. May be empty array() if not needed (for callBackFunctions)
2655 * @param array $uploadedFiles Uploaded files array for sheet/language. May be empty array() if not needed (for callBackFunctions)
2656 * @param array $DSelements Data structure which fits the data array
2657 * @param array $pParams A set of parameters to pass through for the calling of the evaluation functions / call back function
2658 * @param string $callBackFunc Call back function, default is checkValue_SW(). If $this->callBackObj is set to an object, the callback function in that object is called instead.
2659 * @param string $structurePath
2661 * @see checkValue_flex_procInData()
2663 public function checkValue_flex_procInData_travDS(&$dataValues, $dataValues_current, $uploadedFiles, $DSelements, $pParams, $callBackFunc, $structurePath) {
2664 if (is_array($DSelements)) {
2665 // For each DS element:
2666 foreach ($DSelements as $key => $dsConf) {
2668 if ($DSelements[$key]['type'] == 'array') {
2669 if (is_array($dataValues[$key]['el'])) {
2670 if ($DSelements[$key]['section']) {
2671 $newIndexCounter = 0;
2672 foreach ($dataValues[$key]['el'] as $ik => $el) {
2673 if (is_array($el)) {
2674 if (!is_array($dataValues_current[$key]['el'])) {
2675 $dataValues_current[$key]['el'] = array();
2678 if (is_array($dataValues[$key]['el'][$ik][$theKey]['el'])) {
2679 $this->checkValue_flex_procInData_travDS($dataValues[$key]['el'][$ik][$theKey]['el'], is_array($dataValues_current[$key]['el'][$ik]) ?
$dataValues_current[$key]['el'][$ik][$theKey]['el'] : array(), $uploadedFiles[$key]['el'][$ik][$theKey]['el'], $DSelements[$key]['el'][$theKey]['el'], $pParams, $callBackFunc, $structurePath . $key . '/el/' . $ik . '/' . $theKey . '/el/');
2680 // If element is added dynamically in the flexform of TCEforms, we map the ID-string to the next numerical index we can have in that particular section of elements:
2681 // The fact that the order changes is not important since order is controlled by a separately submitted index.