User tests: Successful: Unsuccessful:
Fixes error when running Finder CLI.
Install Testing Sample Data or create some articles with tags.
Run php cli/finder_indexer.php
Symfony\Component\ErrorHandler\Error\UndefinedMethodError^ {#688
#message: "Attempted to call an undefined method named "getMenu" of class "FinderCli"."
#code: 0
#file: "C:\wamp\www\joomla-cms\components\com_tags\src\Helper\RouteHelper.php"
#line: 157
trace: {
C:\wamp\www\joomla-cms\components\com_tags\src\Helper\RouteHelper.php:157 {
Joomla\Component\Tags\Site\Helper\RouteHelper::_findItem($needles = null)^
› $app = Factory::getApplication();
› $menus = $app->getMenu('site');
› $language = $needles['language'] ?? '*';
}
C:\wamp\www\joomla-cms\components\com_tags\src\Helper\RouteHelper.php:104 { …}
C:\wamp\www\joomla-cms\plugins\finder\tags\tags.php:232 { …}
C:\wamp\www\joomla-cms\administrator\components\com_finder\src\Indexer\Adapter.php:247 { …}
C:\wamp\www\joomla-cms\libraries\src\Plugin\CMSPlugin.php:285 { …}
C:\wamp\www\joomla-cms\libraries\vendor\joomla\event\src\Dispatcher.php:495 { …}
C:\wamp\www\joomla-cms\libraries\src\Application\EventAware.php:111 { …}
C:\wamp\www\joomla-cms\cli\finder_indexer.php:266 { …}
C:\wamp\www\joomla-cms\cli\finder_indexer.php:194 { …}
C:\wamp\www\joomla-cms\libraries\src\Application\CliApplication.php:241 { …}
C:\wamp\www\joomla-cms\cli\finder_indexer.php:514 { …}
}
}
No errors.
How is that going to fix the issue though? Console application doesn't have getMenu()
method either.
Then there needs to be a type check.
The getMenu()
method is only defined as part of CMSWebApplicationInterface
so there should be a type check for that and an appropriate workaround if the type does not match. Pulling an application instance out of the container is a red flag.
Or, just skip going through the application and directly call AbstractMenu::getInstance()
. Abusing Factory::getContainer()
is just wrong though.
Category | ⇒ | com_tags Front End |
Title |
|
Switched to AbstractMenu::getInstance()
. Thanks.
Labels |
Added:
?
|
Any explanation on why getting it from the container is wrong?
Factory::getContainer()
isn't intended to be a replacement for any existing factory singletons or static instance methods. Sooner or later, the right thing to do would be have dependencies correctly injected into services, which the container helps with orchestrating. So calls to Factory::getContainer()
really should be few and far between, and if you're thinking about using it then maybe you need to be looking for another approach to whatever you're intending to accomplish.
Unfortunately, a lot of the core architecture still isn't in a great place to handle dependency injection for one reason or another (static methods accessing globals, classes randomly instantiated in places where there isn't a sane way to support injection, core still being designed around a lazy load paradigm meaning if you're trying to use something that doesn't originate out of the Joomla\CMS
namespace you're stuck trying to load those services yourself in some form, etc.), so the container was added as a global in the factory to help write code that assists in the migration to a proper service oriented infrastructure.
Well, I just needed to get a specific application instance for now. Joomla\CMS\Factory::getApplication()
no longer supports this in 4.0 and Joomla\CMS\Application\CMSApplication::getInstance()
is deprecated with Joomla\CMS\Factory::getContainer()->get()
as replacement so I used that.
I have tested this item
Result Output:
Smart Search INDEXER
Starting Indexer
Setting up Smart Search plugins
Setup 31 items in 0.066 seconds.
I have tested this item
Status | New | ⇒ | Ready to Commit |
RTC.
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2020-07-20 20:07:30 |
Closed_By | ⇒ | richard67 | |
Labels |
Added:
?
|
Thanks!
This isn’t a proper fix. Last I knew the finder CLI wasn’t booting up the environment correctly and that still needs to be addressed (like making it a proper console command would be a good idea).