We have to remove the depreciated db_query and replace with \Drupal::database()->query()

Comments

Pavan B S created an issue. See original summary.

Pavan B S’s picture

Assigned: Pavan B S » Unassigned
Status: Active » Needs review
StatusFileSize
new1.83 KB

Applying the patch, please review.

jepster_’s picture

Status: Needs review » Needs work

Thanks for the patch.

However, the usage of \Drupal::database()->query(); violates the dependency injection principle. In /src/AccessStorage.php you can see, that I have injected the database connection, which I have previously declared in the permissions_by_term.services.yml file. Please inject this dependency for executing the queries and test. It would be appreciated if you would provided automated tests. See https://www.drupal.org/docs/8/phpunit/running-phpunit-tests and https://api.drupal.org/api/drupal/core!core.api.php/group/testing/8.2.x.

jeetendrakumar’s picture

Assigned: Unassigned » jeetendrakumar
Status: Needs work » Needs review

Please find updated patch file.

jeetendrakumar’s picture

Assigned: jeetendrakumar » Unassigned
StatusFileSize
new3.08 KB

Please find updated patch file.

somersoft’s picture

Updated the #4 patch file so that it uses the generic Connection class, except for in the test where it creates specific MySQL connection. It now works when SQLite database as well.

andypost’s picture

Priority: Normal » Critical
Status: Needs review » Reviewed & tested by the community

The issue is critical because of

+++ b/src/AccessStorage.php
@@ -2,7 +2,7 @@
-use Drupal\Core\Database\Driver\mysql\Connection;
+use Drupal\Core\Database\Connection;

No way to use module with other databases except mysql

+++ b/src/AccessCheck.php
@@ -11,10 +12,18 @@ use Drupal\user\Entity\User;
+   * use Drupal\Core\Database\Connection definition.

should be "The database connection." could be fixed on commit

andypost’s picture

StatusFileSize
new2 KB
new5.07 KB

Fixed codestyle nits

jepster_’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

Thanks for reporting and providing the patch. Have you tried PbT in a different DMS than MySQL? Which one?

andypost’s picture

Status: Postponed (maintainer needs more info) » Reviewed & tested by the community

Sure, that's why I reported and fixed patch - I'm using sqlite a lot.
Imo patch is straightforward and tested.

jepster_’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for reporting and the provided patch! I have polished it a bit and integrated into release 8.x-1.21.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.