User tests: Successful: Unsuccessful:
Pull Request for pr #37095.
The function in the deprecated Joomla\CMS\MVC\Model\DatabaseAwareTrait
must have the same signature as the functions in the BaseDatabaseModel
. Additionally it ensures, when a model is using that trait and extending the BaseDatabaseModel
that the database is available as the functions in the trait are overloading the ones from the class. Actually this is not needed as the BaseDatabaseModel
is using in 4.1 the MVC trait and in 4.2 the DB package trait.
Install the free version of akeeba backup and open the control panel of it in the back end.
It crashes with the following error:
Compile Error: Declaration of Joomla\CMS\MVC\Model\DatabaseAwareTrait::getDbo() must be compatible with Joomla\CMS\MVC\Model\BaseDatabaseModel::getDbo(): Joomla\Database\DatabaseInterface
It works normally.
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
@laoneo The use of the DatabaseAwareTrait in the ControlpanelModel is a leftover from an older version of the code. That model had started as extending from BaseModel and implementing the DatabaseAwareTrait. It was converted to extend from BaseDatabaseModel (even though it really doesn't quite fit into what BaseDatabaseModel is supposed to do) and I forgot to remove the usage of the trait.
The UpdatesModel does not use the trait, though, it simply extends from BaseDatabaseModel.
Perhaps you meant the UpgradeModel which extends from BaseModel and uses DatabaseAwareTrait? This model is loaded from the installation script in the postflight event. At this point I may not be able to pass an MVCFactoryInterface (if it's a clean installation, not an update) but I definitely need access to Joomla's database. I could either pepper my model with Factory::getContainer()->get('DatabaseDriver') or use the DatabaseAwareTrait and set the DB object once. I chose the latter because it reduces the number of places I will have to change something when inevitably a future version of Joomla changes the way we access the DB driver object. Sure, it took 15 years to go from JFactory::getDbo() to Factory::getContainer()->get('DatabaseDriver') but here I am, having had to do that change in hundreds of places across dozens of extensions
Thanks for the explanation.
Labels |
Added:
Release Blocker
?
|
Category | Libraries | ⇒ | Libraries Unit Tests |
Labels |
Added:
?
|
Status | Pending | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-04-25 21:22:55 |
Closed_By | ⇒ | roland-d |
Thanks guys.
@nikosdion any reason you explicitly load the MVC DatabaseAwareTrait in the control panel and update model?