[BUGFIX] Exclude computed field names on fetching record overlays 58/42158/5
authorAlbrecht Köhnlein <typo3@bestof1983.de>
Fri, 31 Jul 2015 08:12:23 +0000 (10:12 +0200)
committerOliver Hader <oliver.hader@typo3.org>
Tue, 18 Aug 2015 19:03:20 +0000 (21:03 +0200)
During versioning, the dynamic fields _ORIG_pid and _ORIG_uid are added
to $row, but they do not exist in database and cause an SQL error.

Resolves: #68643
Releases: master, 6.2
Change-Id: I33a56b2071a04b5224821805e60722ce8dd3dd14
Reviewed-on: http://review.typo3.org/42158
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
typo3/sysext/frontend/Classes/Page/PageRepository.php

index d5d81a8..a3f753e 100644 (file)
@@ -139,6 +139,21 @@ class PageRepository {
        );
 
        /**
+        * Computed properties that are added to database rows.
+        *
+        * @var array
+        */
+       protected $computedPropertyNames = array(
+               '_LOCALIZED_UID',
+               '_MP_PARAM',
+               '_ORIG_uid',
+               '_ORIG_pid',
+               '_PAGES_OVERLAY',
+               '_PAGES_OVERLAY_UID',
+               '_PAGES_OVERLAY_LANGUAGE',
+       );
+
+       /**
         * Named constants for "magic numbers" of the field doktype
         */
        const DOKTYPE_DEFAULT = 1;
@@ -1179,7 +1194,9 @@ class PageRepository {
                        $movePldSwap = $this->movePlhOL($table, $row);
                        // implode(',',array_keys($row)) = Using fields from original record to make
                        // sure no additional fields are selected. This is best for eg. getPageOverlay()
-                       if ($wsAlt = $this->getWorkspaceVersionOfRecord($this->versioningWorkspaceId, $table, $row['uid'], implode(',', array_keys($row)), $bypassEnableFieldsCheck)) {
+                       // Computed properties are excluded since those would lead to SQL errors.
+                       $fieldNames = implode(',', array_keys($this->purgeComputedProperties($row)));
+                       if ($wsAlt = $this->getWorkspaceVersionOfRecord($this->versioningWorkspaceId, $table, $row['uid'], $fieldNames, $bypassEnableFieldsCheck)) {
                                if (is_array($wsAlt)) {
                                        // Always fix PID (like in fixVersioningPid() above). [This is usually not
                                        // the important factor for versioning OL]
@@ -1429,6 +1446,22 @@ class PageRepository {
        }
 
        /**
+        * Purges computed properties from database rows,
+        * such as _ORIG_uid or _ORIG_pid for instance.
+        *
+        * @param array $row
+        * @return array
+        */
+       protected function purgeComputedProperties(array $row) {
+               foreach ($this->computedPropertyNames as $computedPropertyName) {
+                       if (array_key_exists($computedPropertyName, $row)) {
+                               unset($row[$computedPropertyName]);
+                       }
+               }
+               return $row;
+       }
+
+       /**
         * Determine if a field needs an overlay
         *
         * @param string $table TCA tablename