Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX] Fix serialization of LazyLoadingProxy and LazyObjectStorage
Due to the dependency of those objects to the DataMapper and its own dependency chain, serialization of those objects lead to error: Serialization of \Closure not allowed. To ommit this issue and to reduce the footprint of the serialization data in general, the data mapper should be omitted and reinitialized via __serialize() and __unserialize() Releases: main, 11.5 Resolves: #97190 Resolves: #92148 Change-Id: If8b78a93308eb14d40080c9cceee95754b785ba8 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/73975 Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: core-ci <typo3@b13.com> Tested-by: Benni Mack <benni@typo3.org> Tested-by: Stefan Bürk <stefan@buerk.tech> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de> Reviewed-by: Benni Mack <benni@typo3.org> Reviewed-by: Stefan Bürk <stefan@buerk.tech>
- Loading branch information
1 parent
971be90
commit bdba25c
Showing
5 changed files
with
182 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
typo3/sysext/extbase/Tests/Functional/Persistence/LazyLoadingProxyTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
namespace TYPO3\CMS\Extbase\Tests\Functional\Persistence; | ||
|
||
use ExtbaseTeam\BlogExample\Domain\Model\Administrator; | ||
use ExtbaseTeam\BlogExample\Domain\Model\Blog; | ||
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder; | ||
use TYPO3\CMS\Core\Database\ConnectionPool; | ||
use TYPO3\CMS\Core\Http\ServerRequest; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy; | ||
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; | ||
|
||
class LazyLoadingProxyTest extends FunctionalTestCase | ||
{ | ||
protected array $coreExtensionsToLoad = ['extbase']; | ||
protected array $testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example']; | ||
|
||
/** | ||
* Sets up this test suite. | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
GeneralUtility::makeInstance(ConnectionPool::class) | ||
->getConnectionForTable('fe_users') | ||
->insert('fe_users', [ | ||
'uid' => 1, | ||
'username' => 'Blog Admin', | ||
'tx_extbase_type' => Administrator::class, | ||
]); | ||
|
||
$request = (new ServerRequest())->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_BE); | ||
$GLOBALS['TYPO3_REQUEST'] = $request; | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function serializeAndUnserialize(): void | ||
{ | ||
$blog = new Blog(); | ||
$blog->_setProperty('administrator', new LazyLoadingProxy($blog, 'administrator', 1)); | ||
|
||
$serialized = serialize($blog->getAdministrator()); | ||
|
||
self::assertFalse(str_contains($serialized, 'dataMapper'), 'Assert that serialized object string does not contain dataMapper'); | ||
|
||
/** @var LazyLoadingProxy $administratorProxy */ | ||
$administratorProxy = unserialize($serialized, ['allowed_classes' => true]); | ||
self::assertInstanceOf(LazyLoadingProxy::class, $administratorProxy, 'Assert that $administratorProxy is an instance of LazyLoadingProxy'); | ||
|
||
/** @var Administrator $administrator */ | ||
$administrator = $administratorProxy->_loadRealInstance(); | ||
self::assertInstanceOf(Administrator::class, $administrator, 'Assert that $administrator is an instance of Administrator'); | ||
|
||
self::assertSame('Blog Admin', $administrator->getUsername()); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
typo3/sysext/extbase/Tests/Functional/Persistence/LazyObjectStorageTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
namespace TYPO3\CMS\Extbase\Tests\Functional\Persistence; | ||
|
||
use ExtbaseTeam\BlogExample\Domain\Model\Blog; | ||
use ExtbaseTeam\BlogExample\Domain\Model\Post; | ||
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder; | ||
use TYPO3\CMS\Core\Http\ServerRequest; | ||
use TYPO3\CMS\Extbase\Persistence\Generic\LazyObjectStorage; | ||
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; | ||
|
||
class LazyObjectStorageTest extends FunctionalTestCase | ||
{ | ||
protected array $coreExtensionsToLoad = ['extbase']; | ||
protected array $testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example']; | ||
|
||
/** | ||
* Sets up this test suite. | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->importCSVDataSet(__DIR__ . '/../Persistence/Fixtures/blogs.csv'); | ||
$this->importCSVDataSet(__DIR__ . '/../Persistence/Fixtures/posts.csv'); | ||
|
||
$request = (new ServerRequest())->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_BE); | ||
$GLOBALS['TYPO3_REQUEST'] = $request; | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function serializeAndUnserialize(): void | ||
{ | ||
$blog = new Blog(); | ||
$blog->_setProperty('uid', 1); | ||
$blog->_setProperty('posts', new LazyObjectStorage($blog, 'posts', 10)); | ||
|
||
$serialized = serialize($blog->getPosts()); | ||
|
||
self::assertFalse(str_contains($serialized, 'dataMapper'), 'Assert that serialized object string does not contain dataMapper'); | ||
|
||
/** @var LazyObjectStorage $postsProxy */ | ||
$postsProxy = unserialize($serialized, ['allowed_classes' => true]); | ||
self::assertInstanceOf(LazyObjectStorage::class, $postsProxy, 'Assert that $postsProxy is an instance of LazyObjectStorage'); | ||
|
||
/** @var Post[] $posts */ | ||
$posts = $postsProxy->toArray(); | ||
|
||
self::assertInstanceOf(Post::class, $posts[0], 'Assert that $posts[0] is an instance of Post'); | ||
self::assertInstanceOf(Post::class, $posts[1], 'Assert that $posts[1] is an instance of Post'); | ||
|
||
self::assertSame('Post1', $posts[0]->getTitle()); | ||
self::assertSame('Post2', $posts[1]->getTitle()); | ||
} | ||
} |