news
news copied to clipboard
Proxy Class generation broken since 9.2.0
Bug Report
Current Behavior
If i create a new Extension to add new fields like documented in https://docs.typo3.org/p/georgringer/news/9.3/en-us/Tutorials/ExtendNews/ProxyClassGenerator/Index.html I get a ParseError after clearing the cache and reloading the website.
The generated proxy under typo3temp/var/cache/code/news/tx_news_domain_model_news.php looks like:
And the News.php in my newly created Extension for extending looks like:
As you can see the ClassCacheManager merges the function call $this->initStorageObjects(); inside of __construct() to a function parameter of the proxy class constructor.
I managed to boil the issue down to if having an empty constructor in News.php, the merging will also always fail:
But this time a bit different: The constructor of News.php vanishes but the closing curly bracket gets merged and the resulting proxy class looks like:
Further debugging led me to commit fc3daf5517eebf15997bead55724d4fc984a16d4 causing the issue. After I manually copied the contents of ClassCacheManager.php from commit b04cee28008833f461393e8ef8298fdc5d153be1 to news/Classes/Utility/ClassCacheManager.php via FTP to the server and cleared cache afterwards the website started working again.
The reason why I have a constructor inside the extended News Model is barely because TYPO3 dependency injection doesn't instantiate ObjectStorage properties at class construction so the common workaround here is adding for ex. $this->images = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
to __construct() or creating a initStorageObjects function (like the extension_builder does it by default) and call this function from inside __construct().
Expected behavior/output Proxy class should be generated without syntax errors even if the extended model includes a constructor
Environment
- TYPO3 version(s): 11.5
- news version: >= 9.2.0
- PHP version: 7.4, 8.0, 8.1
- Is your TYPO3 installation set up with Composer (Composer Mode): no
- OS: Ubuntu Server
Possible Solution Revert ClassCacheManager to b04cee28008833f461393e8ef8298fdc5d153be1
Additional context Please see the generated proxy classes for reference:
- https://gist.github.com/TheOnlyMarkus/af73b0d6472db4ccb645c1cb2f5a5d3b
- https://gist.github.com/TheOnlyMarkus/3c1ae9c19f94f2b0f5d3b183ad7e8a0e
@stigfaerch can you take a look?
@stigfaerch did you have time to look? The error is still existing. I am currently using an older version of ClassCacheManager to prevent my sites from error 500 after cache clearing.
Please provide some examples, thx
Please see here: https://github.com/TheOnlyMarkus/news_extend
Following code gets generated in typo3temp/var/cache/code/news/tx_news_domain_model_news.php:
Fatal error: Cannot redeclare GeorgRinger\News\Domain\Model\News::initStorageObjects() in typo3temp/var/cache/code/news/tx_news_domain_model_news.php on line 1704
can you confirm that it works with https://github.com/TheOnlyMarkus/news_extend/pull/1? after fixing the lines?
@georgringer unfortunately it doesn't fix the merging error.
Please see tx_news_domain_model_news.php after applying your patch and clearing cache: https://gist.github.com/TheOnlyMarkus/46b2881fca61f773ff67c9ea449f59df
Now there are two definitions of protected function initStorageObjects()
and two $this->initStorageObjects();
inside __construct.