[BUGFIX] Exclude some vars from serialization 23/36723/5
authorHelmut Hummel <helmut.hummel@typo3.org>
Fri, 6 Feb 2015 20:52:46 +0000 (21:52 +0100)
committerAlexander Opitz <opitz.alexander@googlemail.com>
Tue, 10 Feb 2015 13:49:12 +0000 (14:49 +0100)
This voids the serialization of TSFE and currentFile with the
ContentObjectRenderer in UserInternalContentObject.

Releases: master
Resolves: #64916
Change-Id: I2ce74ee0960d33b39dec51c2f6150d79a113d5fe
Reviewed-on: http://review.typo3.org/36723
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
Reviewed-by: Alexander Opitz <opitz.alexander@googlemail.com>
Tested-by: Alexander Opitz <opitz.alexander@googlemail.com>
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php

index 2683781..be490f8 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Frontend\ContentObject;
  */
 
 use TYPO3\CMS\Core\Imaging\GraphicalFunctions;
+use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Versioning\VersionState;
@@ -554,6 +555,49 @@ class ContentObjectRenderer {
        }
 
        /**
+        * Prevent several objects from being serialized.
+        * If currentFile is set, it is either a File or a FileReference object. As the object itself can't be serialized,
+        * we have store a hash and restore the object in __wakeup()
+        *
+        * @return array
+        */
+       public function __sleep() {
+               $vars = get_object_vars($this);
+               unset($vars['typoScriptFrontendController']);
+               if ($this->currentFile instanceof \TYPO3\CMS\Core\Resource\FileReference) {
+                       $this->currentFile = 'FileReference:' . $this->currentFile->getUid();
+               } elseif ($this->currentFile instanceof \TYPO3\CMS\Core\Resource\File) {
+                       $this->currentFile = 'File:' . $this->currentFile->getIdentifier();
+               } else {
+                       unset($vars['currentFile']);
+               }
+               return array_keys($vars);
+       }
+
+       /**
+        * Restore currentFile from hash.
+        * If currentFile references a File, the identifier equals file identifier.
+        * If it references a FileReference the identifier equals the uid of the reference.
+        */
+       public function __wakeup() {
+               if (isset($GLOBALS['TSFE'])) {
+                       $this->typoScriptFrontendController = $GLOBALS['TSFE'];
+               }
+               if ($this->currentFile !== NULL && is_string($this->currentFile)) {
+                       list($objectType, $identifier) = explode(':', $this->currentFile, 2);
+                       try {
+                               if ($objectType === 'File') {
+                                       $this->currentFile = ResourceFactory::getInstance()->retrieveFileOrFolderObject($identifier);
+                               } elseif ($objectType === 'FileReference') {
+                                       $this->currentFile = ResourceFactory::getInstance()->getFileReferenceObject($identifier);
+                               }
+                       } catch (\TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException $e) {
+                               $this->currentFile = NULL;
+                       }
+               }
+       }
+
+       /**
         * Allow injecting content object class map.
         *
         * This method is private API, please use configuration