news icon indicating copy to clipboard operation
news copied to clipboard

Wrong filepath when extending classes

Open dennismetz opened this issue 4 years ago • 3 comments

Bug Report

Current Behavior I'm extending the class "GeorgRinger\News\Domain\Model\Dto\Search" since further versions. Now, with version 8.x i'm getting an error when im trying to save an element that the given file couldn't be found. Debug: "path_to_project\typo3conf\ext\news\Classes\Utility\ClassCacheManager.php in Line: 70: path_to_project/typo3conf/ext/news/Classes/GeorgRinger\News\Domain\Model\Dto\Search.php"

"Given file "path_to_project/typo3conf/ext/news/Classes/GeorgRinger\News\Domain\Model\Dto\Search.php" does not exist" - but the file exists, it's just not found because of the wrong path (...GeorgRinger\News...).

Expected behavior/output Find the file, extend News, no error in backend

Environment

  • TYPO3 version(s): 9.5.14 and 9.5.16
  • news version: 8.0.0 and 8.1.0
  • Is your TYPO3 installation set up with Composer (Composer Mode): no
  • OS: Windows 10 (local), Linux (live, dev)

Possible Solution

Additional context Some information: Extending news in own extension. Code in localconf:

$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['GeorgRinger\News\Controller\NewsController'] = [ 'className' => 'VENDOR\PROJECT\Controller\NewsController' ];

$GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['classes']['GeorgRinger\News\Domain\Model\Dto\Search'] = [ 'className' => 'VENDOR\PROJECT\Domain\Model\Dto\Search' ];

$GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['classes']['Domain/Model/News/Dto/'][] = 'news_PROJECT';

dennismetz avatar Apr 29 '20 07:04 dennismetz

Error still occours in version 8.3.x of news.

dennismetz avatar May 26 '20 08:05 dennismetz

@dennismetz can you explain your possible solutions?

georgringer avatar May 26 '20 19:05 georgringer

If i understand this correcty you have to override classes in your localconf like this:

$GLOBALS['TYPO3_CONF_VARS']['EXT']['news']['classes']['GeorgRinger\News\Domain\Model\Dto\Search'] = [
	'className' => 'Project\\Vendor\\Domain\\Model\\Dto\\Search'
];

In "news/Classes/Utility/ClassCacheManager.php" you're checking in "reBuild()" if the file exists - but its not because of "GeorgRinger\News" in the array (and so in the filepath).

But without the "GeorgRinger\News" you get the following error in TYPO3:

Class GeorgRinger\News\Domain\Model\Category does not exist. Reflection failed.

And with it you get the wrong path in ClassCacheManager:

$path = ExtensionManagementUtility::extPath('news') . $classPath . $key . '.php';

DUMP: 
..../typo3conf/ext/news/Classes/GeorgRinger\News\Domain\Model\Dto\Search.php

I would check if the string "$key" begins with "GeorgRinger\News" and remove the part like this: (Works for me)

$removeVendor = "GeorgRinger\News\\";
$key = \str_replace( $removeVendor, '', $key);
$path = ExtensionManagementUtility::extPath('news') . $classPath . $key . '.php';

Hope this helps

dennismetz avatar May 27 '20 07:05 dennismetz

I have never seen problems with that in the wild and don't plan to change things, therefore closing the issue to cleanup the issue tracker

georgringer avatar May 17 '24 06:05 georgringer