Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] BaseDatabaseModel should implement DatabaseAwareInterface #45060

Open
wants to merge 1 commit into
base: 5.3-dev
Choose a base branch
from

Conversation

heelc29
Copy link
Contributor

@heelc29 heelc29 commented Mar 2, 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

@heelc29 heelc29 force-pushed the 5.3/mvc/basedatabasemodel/databaseaware branch from 2b1627c to 7cde6d9 Compare March 2, 2025 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants