*/
public $uploads = [];
+ /**
+ * @var (null|UploadField)[]
+ * @since 5.3
+ */
+ public $removedUploads = [];
+
/**
* @var UploadField[]
* @since 5.3
// codemirror scroll offset
if (isset($_POST['scrollOffsets']) && is_array($_POST['scrollOffsets'])) $this->scrollOffsets = ArrayUtil::toIntegerArray($_POST['scrollOffsets']);
- $this->uploads = [];
+ $this->uploads = $this->removedUploads = [];
foreach (array_keys($this->getUploadFields()) as $field) {
$removedFiles = UploadHandler::getInstance()->getRemovedFiledByFieldId($field);
if (!empty($removedFiles)) {
- $this->uploads[$field] = null;
+ $this->removedUploads = array_merge($this->removedUploads, $removedFiles);
}
$files = UploadHandler::getInstance()->getFilesByFieldId($field);
'apiVersion' => $this->apiVersion
]),
'uploads' => $this->uploads,
+ 'removedUploads' => $this->removedUploads,
'customAssets' => $this->customAssets,
'tmpHash' => $this->tmpHash,
'variables' => $this->variables,
'apiVersion' => $this->apiVersion
]),
'uploads' => $this->uploads,
+ 'removedUploads' => $this->removedUploads,
'customAssets' => $this->customAssets,
'tmpHash' => $this->tmpHash,
'variables' => $this->variables,
/** @var \wcf\system\file\upload\UploadFile $file */
$file = $this->parameters['uploads'][$type];
- if ($style->getVariable($type) && file_exists($style->getAssetPath().basename($style->getVariable($type)))) {
- if (!$file || $style->getAssetPath().basename($style->getVariable($type)) !== $file->getLocation()) {
- unlink($style->getAssetPath().basename($style->getVariable($type)));
- }
- }
-
- if ($file !== null) {
+ // Only save file, if it is not proccessed.
+ if ($file !== null && !$file->isProcessed()) {
$fileLocation = $file->getLocation();
$extension = pathinfo($file->getFilename(), PATHINFO_EXTENSION);
$newName = $type.'-'.\bin2hex(\random_bytes(4)).'.'.$extension;
$this->parameters['variables'][$type] = $newName;
$file->setProcessed($newLocation);
}
- else {
+ else if ($file === null) {
$this->parameters['variables'][$type] = '';
}
}
}
+ foreach ($this->parameters['removedUploads'] as $removedUpload) {
+ if (file_exists($removedUpload->getLocation())) {
+ unlink($removedUpload->getLocation());
+ }
+ }
+
$sql = "SELECT variableID, variableName, defaultValue
FROM wcf".WCF_N."_style_variable";
$statement = WCF::getDB()->prepareStatement($sql);