Feature PR-5.2-dev Pending

User tests: Successful: Unsuccessful:

avatar tkuschel
tkuschel
14 Nov 2023

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

  • No documentation changes for docs.joomla.org needed
  • 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);
avatar tkuschel tkuschel - open - 14 Nov 2023
avatar tkuschel tkuschel - change - 14 Nov 2023
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 14 Nov 2023
Category Administration com_admin com_associations com_banners com_categories com_checkin com_config
avatar tkuschel tkuschel - change - 14 Nov 2023
The description was changed
avatar tkuschel tkuschel - edited - 14 Nov 2023
avatar tkuschel tkuschel - change - 14 Nov 2023
The description was changed
avatar tkuschel tkuschel - edited - 14 Nov 2023
avatar HLeithner HLeithner - change - 14 Nov 2023
Title
[5.0][database] CHG deprecated getQuery(true) with createQuery()
[5.1][database] CHG deprecated getQuery(true) with createQuery()
avatar HLeithner HLeithner - edited - 14 Nov 2023
avatar exlemor
exlemor - comment - 21 Apr 2024

@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.

avatar HLeithner
HLeithner - comment - 24 Apr 2024

This pull request has been automatically rebased to 5.2-dev.

avatar HLeithner HLeithner - change - 24 Apr 2024
Title
[5.1][database] CHG deprecated getQuery(true) with createQuery()
[5.2] [database] CHG deprecated getQuery(true) with createQuery()
avatar HLeithner HLeithner - edited - 24 Apr 2024
avatar pe7er
pe7er - comment - 8 May 2024

@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?

avatar xillibit
xillibit - comment - 10 May 2024

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

avatar HLeithner
HLeithner - comment - 13 May 2024

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 parameter $new is deprecated.

avatar Hackwar
Hackwar - comment - 24 Jul 2024

@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.

avatar tkuschel tkuschel - change - 1 Sep 2024
Labels Added: Feature PR-5.2-dev
avatar tkuschel
tkuschel - comment - 1 Sep 2024

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

avatar tkuschel
tkuschel - comment - 1 Sep 2024

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.

avatar joomla-cms-bot joomla-cms-bot - change - 1 Sep 2024
Category Administration com_admin com_associations com_banners com_categories com_checkin com_config Administration com_admin com_associations com_banners com_categories
avatar tkuschel tkuschel - close - 2 Sep 2024
avatar tkuschel tkuschel - change - 2 Sep 2024
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2024-09-02 00:11:46
Closed_By tkuschel
avatar HLeithner
HLeithner - comment - 2 Sep 2024

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.

Add a Comment

Login with GitHub to post a comment