PR-5.3-dev Pending

User tests: Successful: Unsuccessful:

avatar heelc29
heelc29
2 Mar 2025

Summary of Changes

Code in MVCFactory to set database to model is not working at the moment because BaseDatabaseModel do not implement DatabaseAwareInterface

if ($model instanceof DatabaseAwareInterface) {
try {
$model->setDatabase($this->getDatabase());
} catch (DatabaseNotFoundException $e) {
@trigger_error(\sprintf('Database must be set, this will not be caught anymore in 5.0.'), E_USER_DEPRECATED);
$model->setDatabase(Factory::getContainer()->get(DatabaseInterface::class));
}
}

Deprecate DatabaseModelInterface and should removed together with libraries/src/MVC/Model/DatabaseAwareTrait.php so is J6.0 ok or should both removed with J7.0?

Testing Instructions

disable following code and open backend

/**
* @deprecated 4.3 will be Removed in 6.0
* Database instance is injected through the setter function,
* subclasses should not use the db instance in constructor anymore
*/
$db = \array_key_exists('dbo', $config) ? $config['dbo'] : Factory::getDbo();
if ($db) {
@trigger_error(\sprintf('Database is not available in constructor in 6.0.'), E_USER_DEPRECATED);
$this->setDatabase($db);
// Is needed, when models use the deprecated MVC DatabaseAwareTrait, as the trait is overriding the local functions
$this->setDbo($db);
}

Actual result BEFORE applying this Pull Request

500 error
if debug enabled:
image

Expected result AFTER applying this Pull Request

no 500 error when visit backend or frontend

Link to documentations

Please select:

  • No documentation changes for docs.joomla.org needed
  • Pull Request link for manual.joomla.org: TBD
avatar heelc29 heelc29 - open - 2 Mar 2025
avatar heelc29 heelc29 - change - 2 Mar 2025
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 2 Mar 2025
Category Libraries Front End Plugins
avatar heelc29 heelc29 - change - 2 Mar 2025
Labels Added: PR-5.3-dev
avatar exlemor
exlemor - comment - 15 Mar 2025

@heelc29 - I have done this 3 times too be sure I wasn't reporting incorrectly... but I can't replicate the BEFORE condition..

I have debug mode on, cleared cache every time to be sure etc etc after having deleted lines 100-113 in [joomla-cms/libraries/src/MVC/Model/BaseDatabaseModel.php and the backend loads fine...

On 5.3.0 ßeta 2, PHP 8.3.19, MariaDB 10.6.15 if that matters.

So, what am I doing wrong?

avatar heelc29 heelc29 - change - 15 Mar 2025
The description was changed
avatar heelc29 heelc29 - edited - 15 Mar 2025
avatar heelc29
heelc29 - comment - 15 Mar 2025

@heelc29 - I have done this 3 times too be sure I wasn't reporting incorrectly... but I can't replicate the BEFORE condition..

I have debug mode on, cleared cache every time to be sure etc etc after having deleted lines 100-113 in [joomla-cms/libraries/src/MVC/Model/BaseDatabaseModel.php and the backend loads fine...

On 5.3.0 ßeta 2, PHP 8.3.19, MariaDB 10.6.15 if that matters.

So, what am I doing wrong?

@exlemor I don't now. I just tried again
image

Result is still the same
image

avatar joomla-cms-bot joomla-cms-bot - change - 14 Jul 2025
Category Libraries Front End Plugins Administration com_workflow Libraries Front End Plugins
avatar exlemor
exlemor - comment - 23 Aug 2025

@heelc29 - it appears that the code has evolved and is no longer as the same so I can't test this PR ;(

joomla-cms/libraries/src/MVC/Factory/MVCFactory.php
Lines 170 to 177

 if ($model instanceof DatabaseAwareInterface) { 
     try { 
         $model->setDatabase($this->getDatabase()); 
     } catch (DatabaseNotFoundException $e) { 
         @trigger_error(\sprintf('Database must be set, this will not be caught anymore in 5.0.'), E_USER_DEPRECATED); 
         $model->setDatabase(Factory::getContainer()->get(DatabaseInterface::class)); 
     } 
 }

is not what I have in my file :/

if ($model instanceof DatabaseAwareInterface) {
            try {
                $model->setDatabase($this->getDatabase());
            } catch (DatabaseNotFoundException) {
                @trigger_error('Database must be set, this will not be caught anymore in 5.0.', E_USER_DEPRECATED);
                $model->setDatabase(Factory::getContainer()->get(DatabaseInterface::class));
            }
        }

(I'm on Joomla_5.3.4-dev - built on 23 August 2025 00:29:58 UTC)

avatar heelc29
heelc29 - comment - 23 Aug 2025

it appears that the code has evolved and is no longer as the same so I can't test this PR ;(

@exlemor Sorry, I don't follow. The code from MVCFactory is for informational purposes only and is not part of the test. The differences you describe are also very minor (missing variable in catch, unnecessary sprintf removed). The relevant code for this pull request is in BaseDatabaseModel.

Add a Comment

Login with GitHub to post a comment