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.2] [database] CHG deprecated getQuery(true) with createQuery() #42344

Closed
wants to merge 7 commits into from

Conversation

tkuschel
Copy link
Contributor

@tkuschel tkuschel commented Nov 14, 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);

@HLeithner HLeithner changed the base branch from 5.0-dev to 5.1-dev November 14, 2023 17:46
@HLeithner HLeithner changed the title [5.0][database] CHG deprecated getQuery(true) with createQuery() [5.1][database] CHG deprecated getQuery(true) with createQuery() Nov 14, 2023
@exlemor
Copy link

exlemor commented Apr 21, 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.

@HLeithner HLeithner changed the base branch from 5.1-dev to 5.2-dev April 24, 2024 09:07
@HLeithner
Copy link
Member

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

@HLeithner HLeithner changed the title [5.1][database] CHG deprecated getQuery(true) with createQuery() [5.2] [database] CHG deprecated getQuery(true) with createQuery() Apr 24, 2024
@pe7er pe7er self-assigned this May 8, 2024
@pe7er
Copy link
Contributor

pe7er commented May 8, 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?

@xillibit
Copy link
Contributor

xillibit commented May 10, 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

@HLeithner
Copy link
Member

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.

@Hackwar
Copy link
Member

Hackwar commented Jul 24, 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.

mabdelaziz77 and others added 5 commits August 30, 2024 07:35
* Fixed: Consistency of "unpublished" -icon colours #43375

Fixed the icon colour of the unpublished articles in the associated articles list.

* Replaced other instances of icon-times with icon-unpublish

* Changed icon-folder to icon-archive

* Changed icon-check to icon-publish

---------

Co-authored-by: Quy <[email protected]>
* fix default language value for taxonomy rows

* fix default value for other taxonomy methods
@tkuschel
Copy link
Contributor Author

tkuschel commented Sep 1, 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

@zero-24 zero-24 removed their request for review September 1, 2024 23:26
@tkuschel
Copy link
Contributor Author

tkuschel commented Sep 1, 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.

@tkuschel tkuschel closed this Sep 2, 2024
@tkuschel tkuschel deleted the 5.2-dev-42344 branch September 2, 2024 00:11
@HLeithner
Copy link
Member

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.

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.