Problem/Motivation
Calling \Drupal::service('locale.storage')->deleteStrings()
never seems to work.
It fails with this error:
Drupal\Core\Database\InvalidQueryException Calling Drupal\Core\Database\Query\Condition::condition() without an array compatible operator is not supported. See https://www.drupal.org/node/3350985.
The problem is that dbDelete() loops on provided values and adds a condition to the query for each value but it uses a =
condition so it only works with scalar values.
deleteStrings() calls dbDelete() with an array of LIDs as value, so it tries to add a query condition with the =
operator and an array as value, which does not work.
(This method does not seem to be used by core itself.)
Steps to reproduce
\Drupal::service('locale.storage')->deleteStrings(['lid' => 1]);
Proposed resolution
StringDatabaseStorage::dbDelete()
should use an IN condition.
This way StringDatabaseStorage::deleteStrings()
can call it with multiple LIDs and they will all be deleted.
In order to keep compatibility with other methods that call dbDelete(), we can check if the value is scalar and create an array that contains only this scalar value that we use in the IN condition.