joomla-cms
joomla-cms copied to clipboard
[5.2] [database] CHG deprecated getQuery(true) with createQuery()
Pull Request for deprecated getQuery(true) in joomla-cms because of framework database
Summary of Changes
Replaced all fuction calls getQuery(true) with createQuery() but only in database related context.
Note: There is also a getQuery(true) functionality in Joomla\CMS\Uri\Uri that must remain untouched.
Testing Instructions
No extraordinary test instructions necessary.
Actual result BEFORE applying this Pull Request
Multiple php warnings (when enabled) resulting in e.g.
2023-11-14T12:20:46+00:00 WARNING 127.0.0.1 deprecated Since joomla/database 2.2.0: The parameter $new is deprecated and will be removed in 4.0, use Joomla\Database\DatabaseDriver::createQuery() instead. - [ROOT]/libraries/vendor/symfony/deprecation-contracts/function.php - Line 25
Expected result AFTER applying this Pull Request
These warnings with "parameter $new" are gone.
Link to documentations
- [X] No documentation changes for docs.joomla.org needed
- [X] No documentation changes for manual.joomla.org needed
Remember to change your mindset using the createQuery() to start building a query for the database, like:
$db = $this->getDatabase();
$query = $db->createQuery()
->select([$db->quotename('enabled'), $db->quoteName('params')])
->from($db->quoteName('#__extensions'))
->where($db->quoteName('folder') . ' = ' . $db->quote('actionlog'))
->where($db->quoteName('element') . ' = ' . $db->quote('joomla'));
$db->setQuery($query);
@tkuschel As soon as I applied the Patch, (logging was turned off at that moment on purpose), the site crashed magnificently :(
Error UndefinedMethodError
HTTP 500 Whoops, looks like something went wrong.
Attempted to call an undefined method named "isAutostart" of class "Joomla\Component\Guidedtours\Administrator\Model\TourModel".
Symfony\Component\ErrorHandler\Error
UndefinedMethodError
in /home/lights/public_html/plugins/system/guidedtours/src/Extension/GuidedTours.php (line 172)
'Tour', 'Administrator', ['ignore_request' => true] ); if ($tourModel->isAutostart('joomla-welcome')) { $tour = $this->getTour('joomla-welcome'); $doc->addScriptOptions('com_guidedtours.autotour', $tour->id); // Set autostart to '0' to avoid it to autostart again
in /home/lights/public_html/libraries/vendor/joomla/event/src/Dispatcher.php -> onBeforeCompileHead (line 454)
Dispatcher->dispatch('onBeforeCompileHead', object(BeforeCompileHeadEvent))
in /home/lights/public_html/libraries/src/Document/Renderer/Html/MetasRenderer.php (line 62)
MetasRenderer->render(null, array(), null)
in /home/lights/public_html/libraries/src/Document/HtmlDocument.php (line 575)
HtmlDocument->getBuffer('metas', null, array())
in /home/lights/public_html/libraries/src/Document/HtmlDocument.php (line 894)
HtmlDocument->_renderTemplate()
in /home/lights/public_html/libraries/src/Document/HtmlDocument.php (line 647)
HtmlDocument->render(false, array('template' => 'atum', 'directory' => '/home/lights/public_html/administrator/templates', 'debug' => true, 'csp_nonce' => null, 'templateInherits' => '', 'params' => object(Registry), 'file' => 'error.php'))
in /home/lights/public_html/libraries/src/Document/ErrorDocument.php (line 139)
ErrorDocument->render(false, array('template' => 'atum', 'directory' => '/home/lights/public_html/administrator/templates', 'debug' => true, 'csp_nonce' => null, 'templateInherits' => '', 'params' => object(Registry), 'file' => 'error.php'))
in /home/lights/public_html/libraries/src/Error/Renderer/HtmlRenderer.php (line 70)
HtmlRenderer->render(object(Error))
in /home/lights/public_html/libraries/src/Exception/ExceptionHandler.php (line 136)
ExceptionHandler::render(object(Error))
in /home/lights/public_html/libraries/src/Exception/ExceptionHandler.php (line 73)
ExceptionHandler::handleException(object(Error))
in /home/lights/public_html/libraries/src/Application/CMSApplication.php (line 336)
CMSApplication->execute()
in /home/lights/public_html/administrator/includes/app.php (line 58)
require_once('/home/lights/public_html/administrator/includes/app.php')
in /home/lights/public_html/administrator/index.php (line 32)
Error
Call to undefined method Joomla\Component\Guidedtours\Administrator\Model\TourModel::isAutostart()
;(
Any way to revert the patch and uncrash my test site please? ;) lol
Thanks.
This pull request has been automatically rebased to 5.2-dev.
@tkuschel Thank you for this PR! We would like to merge it in Joomla 5.2. Could you please fix the conflicts for 5.2?
The createQuery() method seems just a shortcut to call getQuery() : https://github.com/joomla-framework/database/blob/56aa950aad3676702e71e84fa2014bf6e659b0b9/src/DatabaseDriver.php#L557
I don't see the getQuery() method as deprecated
The
createQuery()method seems just a shortcut to callgetQuery(): https://github.com/joomla-framework/database/blob/56aa950aad3676702e71e84fa2014bf6e659b0b9/src/DatabaseDriver.php#L557I don't see the
getQuery()method as deprecated
The parameter $new is deprecated.
@tkuschel can you solve the conflicts? As Peter wrote, we'd like to see this in 5.2, but for that it would have to be ready and testable.
I'm sorry that I'm only now able to join in again, but unfortunately I've been very ill and have been absent for a long time.
@xillibit yes it seem to be just a shortcut to call getQuery(true) but it isn't. The function getQuery(false) or simply getQuery() does exactly what a “get” describes, it fetches the current query.
The library changed this to be more clear: to create a query object aka createQuery().
I don't know if this is described in Joomla documentation, like how to design an SQL query?
I fixed the conflicts, @Hackwar @pe7er @HLeithner
Sorry, I have seen, that there are some code for reworking too! - Please do not check until the following is also to be changed:
$db = Factory::getDbo();
I will clone the 5.2-dev branch again, and fix that too - causing troubles.
Sorry, I have seen, that there are some code for reworking too! - Please do not check until the following is also to be changed:
$db = Factory::getDbo();I will clone the 5.2-dev branch again, and fix that too - causing troubles.
Please don't, just do the createQuery() thing. Fixing Factory::getDbo(); is a much more complicated thing and should be done in a proper way.