Add a test to make sure FlaggingStorage::loadIsFlaggedMultiple() actually supports multiple entities

Created on 2 April 2020, almost 5 years ago
Updated 19 October 2024, 3 months ago

Problem/Motivation

While building some custom code I came across FlaggingStorage::loadIsFlaggedMultiple() which seemed to do exactly what I needed; pass it an array of entities, and the method will return all the flaggings on those entities. However, I was greeted with this nasty exception:

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens: SELECT f.entity_id AS entity_id, f.flag_id AS flag_id, f.global AS global
FROM
{flagging} f
WHERE (entity_type = :db_condition_placeholder_0) AND (entity_id = :db_condition_placeholder_1:db_condition_placeholder_2) AND ((global = :db_condition_placeholder_3) OR (uid = :db_condition_placeholder_4)); Array
(
    [:db_condition_placeholder_0] => node
    [:db_condition_placeholder_1] => 1
    [:db_condition_placeholder_2] => 2
    [:db_condition_placeholder_3] => 1
    [:db_condition_placeholder_4] => 1
)


/app/web/core/lib/Drupal/Core/Database/Connection.php:695
/app/web/core/lib/Drupal/Core/Database/Connection.php:659
/app/web/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php:357
/app/web/core/lib/Drupal/Core/Database/Query/Select.php:510
/app/web/modules/contrib/flag/src/Entity/Storage/FlaggingStorage.php:122
/app/web/modules/contrib/flag/tests/src/Kernel/FlaggingStorageTest.php:110

This was before the originally proposed fix was actually added in the project. However, the patch for this issue also includes a test to make sure it continues to work which might still be a useful addition.

Proposed resolution

Add a test to verify the solution.

Remaining tasks

  • Review
  • Commit

User interface changes

None.

API changes

FlaggingStorage::loadIsFlaggedMultiple() will actually work as advertised.

Data model changes

None.

๐Ÿ› Bug report
Status

Needs work

Component

Flag core

Created by

๐Ÿ‡ณ๐Ÿ‡ฑNetherlands eelkeblok Netherlands ๐Ÿ‡ณ๐Ÿ‡ฑ

Live updates comments and jobs are added and updated live.
  • Needs reroll

    The patch will have to be re-rolled with new suggestions/changes described in the comments in the issue.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024