Actions
Bug #97636
closedWarning when trying to update not existing file properties with File::updateProperties
Start date:
2022-05-16
Due date:
% Done:
0%
Estimated time:
TYPO3 Version:
11
PHP Version:
8.1
Tags:
Complexity:
no-brainer
Is Regression:
Sprint Focus:
Description
We want to add custom properties to a \TYPO3\CMS\Core\Resource\File. However, as these properties may not exist, a warning is thrown.
PHP Warning: Undefined array key "alternative" in typo3/sysext/core/Classes/Resource/File.php line 184
The problematic code:
foreach ($properties as $key => $value) {
if ($this->properties[$key] !== $value) {
if (!in_array($key, $this->updatedProperties)) {
$this->updatedProperties[] = $key;
}
$this->properties[$key] = $value;
}
}
The simplest fix might be to change
$this->properties[$key] !== $value
to
$this->properties[$key] ?? null !== $value
or replace the whole code with something like this (untested):
$this->updatedProperties = array_merge($this->updatedProperties, array_keys(array_diff_assoc($this->properties, $properties)));
$this->properties = array_merge($this->properties, $properties);
Actions