Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Doing ::delete, ::deleteAll(), ::rename() on an empty configuration collection results in the different output depending on the backend used.
The consistent methods:
StorageInterface::exists()
- works the same way across storages and collections - if the collection does not exist it will return FALSE.StorageInterface::read()
- works the same way across storages and collections - if the collection does not exist it will return FALSE.StorageInterface::readMultiple()
- works the same way across storages and collections - if the collection does not exist it will return an empty array.StorageInterface::listAll()
- works the same way across storages and collections - if the collection does not exist it will return an empty array.StorageInterface::write()
- works the same way across storages and collections - if the collection does not exist it will create it.
The inconsistent methods:
StorageInterface::delete()
- FileStorage will throw an exception if the collection does not exist where DatabaseStorage will return FALSE.StorageInterface::deleteAll()
- FileStorage will return TRUE if the collection does not exist or is empty where DatabaseStorage will return FALSE.StorageInterface::rename()
- FileStorage will throw an exception if the collection does not exist where DatabaseStorage will return FALSE.
Proposed resolution
Make it consistent...
Remaining tasks
StorageInterface::delete()
- Should return FALSE if collection does not exist.StorageInterface::deleteAll()
- Should return FALSE if the collection does not exist or is emptyStorageInterface::rename()
- Should return FALSE if the collection does not exist or $name does not exist.
Add appropriate test coverage.
User interface changes
API changes
None - some implementations might no longer throw exceptions.
Data model changes
None
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#6 | 3020964-6.patch | 4.83 KB | alexpott |
#6 | 5-6-interdiff.txt | 1.88 KB | alexpott |
#5 | 3020964-5.patch | 3.23 KB | alexpott |
#5 | 2-5-interdiff.txt | 2.69 KB | alexpott |
#2 | 3020964-2.patch | 1.65 KB | alexpott |
Comments
Comment #2
alexpottHere's a test that will pass for DatabaseStorage but not FileStorage.
We need to discuss what's the correct behaviour.
Comment #4
alexpottComment #5
alexpottActually all the fixed methods have the following documentation
Therefore this is bringing the implementation into line with the documentation.
Comment #6
alexpottWe're not testing what we think we're testing ... the
$this->pass()
for the rename testing is not called at all for DatabaseStorageComment #7
bircherI think that makes a lot of sense! And I welcome this change. I had just assumed that the exceptions in FileStorage were allowed since we test for it but then don't
$this->fail()
if they are not thrown. (like in other parts of the same test base class.)The patch looks good too.
Comment #8
catchMake sense. Committed 991fd05 and pushed to 8.7.x. Thanks!