Skip to content

Commit

Permalink
[Uploadable] make sure file is not null and exists before adding it t…
Browse files Browse the repository at this point in the history
…o pendingFileRemovals array
  • Loading branch information
JoolsMcFly committed Dec 18, 2024
1 parent 7622db1 commit ebae19a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/Uploadable/UploadableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ public function processFile(AdapterInterface $ea, $object, $action)
*/
public function removeFile($filePath)
{
if (is_file($filePath)) {
if (!is_null($filePath) && is_file($filePath)) {
return @unlink($filePath);
}

Expand Down Expand Up @@ -709,11 +709,14 @@ protected function getPath(ClassMetadata $meta, array $config, $object)
protected function addFileRemoval($meta, $config, $object)
{
if ($config['filePathField']) {
$this->pendingFileRemovals[] = $this->getFilePathFieldValue($meta, $config, $object);
$filename = $this->getFilePathFieldValue($meta, $config, $object);
} else {
$path = $this->getPath($meta, $config, $object);
$fileName = $this->getFileNameFieldValue($meta, $config, $object);
$this->pendingFileRemovals[] = $path.DIRECTORY_SEPARATOR.$fileName;
$filename = $path.DIRECTORY_SEPARATOR.$this->getFileNameFieldValue($meta, $config, $object);

Check warning on line 715 in src/Uploadable/UploadableListener.php

View check run for this annotation

Codecov / codecov/patch

src/Uploadable/UploadableListener.php#L715

Added line #L715 was not covered by tests
}

if (!is_null($filename) && file_exists($filename)) {
$this->pendingFileRemovals[] = $filename;
}
}

Expand Down Expand Up @@ -752,7 +755,7 @@ protected function getPropertyValueFromObject(ClassMetadata $meta, $propertyName
* @param array<string, mixed> $config
* @param object $object
*
* @return string
* @return string|null
*/
protected function getFilePathFieldValue(ClassMetadata $meta, array $config, $object)
{
Expand Down

0 comments on commit ebae19a

Please sign in to comment.