? ? Pending

User tests: Successful: Unsuccessful:

avatar laoneo
laoneo
23 Jul 2020

Summary of Changes

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.

Testing Instructions

On the command line execute the following command in the joomla root:
php cli/finder_indexer.php --purge

Actual result BEFORE applying this Pull Request

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 { …}
  }
}

Expected result AFTER applying this Pull Request

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

Documentation Changes Required

None, as it is not documented in the potential issues doc that JModelLegacy::getInstanceis not working for namespaced components.

avatar laoneo laoneo - open - 23 Jul 2020
avatar laoneo laoneo - change - 23 Jul 2020
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 23 Jul 2020
Category Libraries
avatar laoneo laoneo - change - 24 Jul 2020
Labels Added: ?
avatar laoneo
laoneo - comment - 24 Jul 2020

@SharkyKZ added Path::clean, can you check if it works now as expected?

avatar SharkyKZ
SharkyKZ - comment - 24 Jul 2020

Works fine now. Do you want to move Path::clean() calls out of the loop?

avatar particthistle particthistle - test_item - 25 Jul 2020 - Tested successfully
avatar particthistle
particthistle - comment - 25 Jul 2020

I have tested this item successfully on fdb82ea


Results when patch applied:
image

This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30172.

avatar laoneo
laoneo - comment - 25 Jul 2020

@wilsonge did only some code styling and cosmetics since the last test.

avatar laoneo laoneo - change - 25 Jul 2020
The description was changed
avatar laoneo laoneo - edited - 25 Jul 2020
avatar alikon
alikon - comment - 25 Jul 2020

i were in the middle of the test while you applied the suggestion from @SharkyKZ.... micro optimization matters ?

avatar alikon alikon - test_item - 25 Jul 2020 - Tested successfully
avatar alikon
alikon - comment - 25 Jul 2020

I have tested this item successfully on 759854a


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30172.

avatar alikon alikon - change - 25 Jul 2020
Status Pending Ready to Commit
avatar alikon
alikon - comment - 25 Jul 2020

therefore i'm confident to set this 1 as rtc


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30172.

avatar wilsonge wilsonge - change - 25 Jul 2020
Labels Added: ?
avatar wilsonge wilsonge - change - 25 Jul 2020
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
avatar wilsonge wilsonge - close - 25 Jul 2020
avatar wilsonge wilsonge - merge - 25 Jul 2020
avatar wilsonge
wilsonge - comment - 25 Jul 2020

Thanks @laoneo for this :)

Add a Comment

Login with GitHub to post a comment