Fixed a bug in FormFlashFile::moveTo() not deleting the old file

This commit is contained in:
Matias Griese
2019-01-29 18:12:38 +02:00
parent 1321e582d5
commit ad7fdd5c2b
2 changed files with 16 additions and 4 deletions

View File

@@ -3,6 +3,8 @@
1. [](#improved) 1. [](#improved)
* Improved `$page->forms()` call, added `$page->addForms()` * Improved `$page->forms()` call, added `$page->addForms()`
1. [](#bugfix)
* Fixed a bug in `FormFlashFile::moveTo()` not deleting the old file
# v1.6.0-beta.8 # v1.6.0-beta.8
## 01/25/2019 ## 01/25/2019

View File

@@ -61,7 +61,7 @@ class FormFlashFile implements UploadedFileInterface, \JsonSerializable
throw new \RuntimeException(\sprintf('Uploaded file could not be moved to %s', $targetPath)); throw new \RuntimeException(\sprintf('Uploaded file could not be moved to %s', $targetPath));
} }
$this->flash->removeFile($this->field, $this->upload['tmp_name']); $this->flash->removeFile($this->getClientFilename(), $this->field);
} }
public function getSize() public function getSize()
@@ -100,7 +100,7 @@ class FormFlashFile implements UploadedFileInterface, \JsonSerializable
public function getDestination() public function getDestination()
{ {
return $this->upload['path']; return $this->upload['path'] ?? '';
} }
public function jsonSerialize() public function jsonSerialize()
@@ -108,9 +108,15 @@ class FormFlashFile implements UploadedFileInterface, \JsonSerializable
return $this->upload; return $this->upload;
} }
public function getTmpFile() : string public function getTmpFile() : ?string
{ {
return $this->flash->getTmpDir() . '/' . $this->upload['tmp_name']; $tmpName = $this->upload['tmp_name'] ?? null;
if (!$tmpName) {
return null;
}
return $this->flash->getTmpDir() . '/' . $tmpName;
} }
public function __debugInfo() public function __debugInfo()
@@ -134,6 +140,10 @@ class FormFlashFile implements UploadedFileInterface, \JsonSerializable
if ($this->moved) { if ($this->moved) {
throw new \RuntimeException('Cannot retrieve stream after it has already been moved'); throw new \RuntimeException('Cannot retrieve stream after it has already been moved');
} }
if (!$this->getTmpFile()) {
throw new \RuntimeException('Cannot retrieve stream as the file was not uploaded');
}
} }
/** /**