[BUGFIX] Update tstamp on writeForeignField if any foreign value has changed. (IRRE)
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Database / RelationHandler.php
index e95c550..737664f 100644 (file)
@@ -931,6 +931,25 @@ class RelationHandler
                 }
                 // Update accordant fields in the database:
                 if (!empty($updateValues)) {
+                    // Update tstamp if any foreign field value has changed
+                    if (!empty($GLOBALS['TCA'][$table]['ctrl']['tstamp'])) {
+                        $currentRow = BackendUtility::getRecord($table, $uid, implode(',', array_keys($updateValues)) , '', true);
+                        $needTstampUpdate = false;
+                        if (empty($currentRow)) {
+                            $needTstampUpdate = true;
+                        } else {
+                            foreach ($currentRow as $field => $curValue) {
+                                if ((string)$curValue !== (string)$updateValues[$field]) {
+                                    $needTstampUpdate = true;
+                                    break;
+                                }
+                            }
+                        }
+                        if ($needTstampUpdate) {
+                            $updateValues[$GLOBALS['TCA'][$table]['ctrl']['tstamp']] = $GLOBALS['EXEC_TIME'];
+                        }
+                    }
+
                     $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . (int)$uid, $updateValues);
                     $this->updateRefIndex($table, $uid);
                 }