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 empty
  • StorageInterface::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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
FileSize
1.65 KB

Here's a test that will pass for DatabaseStorage but not FileStorage.

We need to discuss what's the correct behaviour.

Status: Needs review » Needs work

The last submitted patch, 2: 3020964-2.patch, failed testing. View results

alexpott’s picture

Issue summary: View changes
alexpott’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
2.69 KB
3.23 KB

Actually all the fixed methods have the following documentation

   * @return bool
   *   TRUE on success, FALSE otherwise.

Therefore this is bringing the implementation into line with the documentation.

alexpott’s picture

We're not testing what we think we're testing ... the $this->pass() for the rename testing is not called at all for DatabaseStorage

bircher’s picture

Status: Needs review » Reviewed & tested by the community

I 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.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Make sense. Committed 991fd05 and pushed to 8.7.x. Thanks!

  • catch committed 991fd05 on 8.7.x
    Issue #3020964 by alexpott: Empty collection config CRUD operations are...

Status: Fixed » Closed (fixed)

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