Problem/Motivation

While doing a config-export on a site running PHP 8.1 we got the following warnings:

 [warning] Undefined property: Drupal\deconfig\DeconfigStorage::$collection DeconfigStorage.php:332
 [warning] Undefined property: Drupal\deconfig\DeconfigStorage::$collection DeconfigStorage.php:332
 [warning] Undefined property: Drupal\deconfig\DeconfigStorage::$collection DeconfigStorage.php:332

The warning is caused by the following code

    if ($success && $this->storage->getCollectionName() != StorageInterface::DEFAULT_COLLECTION) {
      // Remove empty directories.
      if (!(new \FilesystemIterator($this->getCollectionDirectory()))->valid()) {
        $this->getFileSystem()->rmdir($this->getCollectionDirectory());
      }
    }

That seems to come from the following implementation of

deleteAll()

in

core/lib/Drupal/Core/Config/FileStorage.php
  /**
   * {@inheritdoc}
   */
  public function deleteAll($prefix = '') {
    $files = $this->listAll($prefix);
    $success = !empty($files);
    foreach ($files as $name) {
      if (!$this->delete($name) && $success) {
        $success = FALSE;
      }
    }
    if ($success && $this->collection != StorageInterface::DEFAULT_COLLECTION) {
      // Remove empty directories.
      if (!(new \FilesystemIterator($this->getCollectionDirectory()))->valid()) {
        $this->getFileSystem()->rmdir($this->getCollectionDirectory());
      }
    }
    return $success;
  }

As $this->collection is not a valid dereference in DeconfigStorage.php the if-clause fails and the remove-code is never reached.

Steps to reproduce

Do a drush cex using php 8.1

Proposed resolution

As we've been running deconfig without any issues until now, and as the remove-code has never been run it should be safe to remove it altogether.

Remaining tasks

We should probably be aware that the different implementations of the StorageInterface wrapped by DeConfig has their own ways of cleaning up when all config entries are removed. Eg. the DatabaseStorage uses a LIKE statement which is much faster than individual deletes.

CommentFileSizeAuthor
deconfig-remove-rmdir-1.patch588 bytesdanquah

Comments

danquah created an issue. See original summary.

danquah’s picture

Issue summary: View changes
danquah’s picture

Status: Active » Needs review

  • Xen committed d7e1373 on 1.0.x
    Issue #3308549 by danquah: Remove unused cleanup code in deleteAll
    
xen’s picture

Status: Needs review » Fixed

Committed.

Status: Fixed » Closed (fixed)

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