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.
| Comment | File | Size | Author |
|---|---|---|---|
| deconfig-remove-rmdir-1.patch | 588 bytes | danquah |
Comments
Comment #2
danquah commentedComment #3
danquah commentedComment #5
xen commentedCommitted.