User tests: Successful: Unsuccessful:
The legacy way to load a model is JModelLegacy::getInstance
which is widely used in Joomla 3. This doesn't work anymore for components which are namespaced in Joomla 4 as models are loaded there through the component MVC factory. This pr adds a functionality to also load namespaced models the old way. The following code works both on J3 and J4 with this patch, without, the model can't be found on J4.
JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_contact/models', 'ContactModel');
$model = JModelLegacy::getInstance('Contact', 'ContactModel', ['ignore_request' => true]);
Additionally it fixes the indexer purge task on the command line.
On the command line execute the following command in the joomla root:
php cli/finder_indexer.php --purge
The following error is printed:
Smart Search INDEXER
============================
Saving filters
- number of saved filters: 0
Clear index
Error {#191
#message: "Call to a member function purge() on bool"
#code: 0
#file: "/var/www/html/Projects/cms4/cli/finder_indexer.php"
#line: 360
trace: {
/var/www/html/Projects/cms4/cli/finder_indexer.php:360 {
FinderCli->purge()^
› // Attempt to purge the index.
› $return = $model->purge();
›
}
/var/www/html/Projects/cms4/cli/finder_indexer.php:183 { …}
/var/www/html/Projects/cms4/libraries/src/Application/CliApplication.php:241 { …}
/var/www/html/Projects/cms4/cli/finder_indexer.php:514 { …}
}
}
The purging process doesn't fail:
Smart Search INDEXER
============================
Saving filters
- number of saved filters: 0
Clear index
- index clear successful
Starting Indexer
Setting up Smart Search plugins
Setup 5 items in 0.293 seconds.
* Processed batch 1 in 0.411 seconds.
* Skipping pause, as previous batch had a very low processing time (0.411s < 1s)
Restoring filters
- number of filters restored: 0
Total Processing Time: 0.705 seconds.
Peak memory usage: 16,777,216 bytes
None, as it is not documented in the potential issues doc that JModelLegacy::getInstance
is not working for namespaced components.
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
Labels |
Added:
?
|
Works fine now. Do you want to move Path::clean()
calls out of the loop?
I have tested this item
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30172.
I have tested this item
Status | Pending | ⇒ | Ready to Commit |
therefore i'm confident to set this 1 as rtc
Labels |
Added:
?
|
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2020-07-25 11:30:29 |
Closed_By | ⇒ | wilsonge |
@SharkyKZ added Path::clean, can you check if it works now as expected?