namespace wcf\acp\form;
use wcf\data\reaction\type\ReactionType;
use wcf\data\reaction\type\ReactionTypeAction;
-use wcf\data\reaction\type\ReactionTypeEditor;
use wcf\data\reaction\type\ReactionTypeList;
use wcf\form\AbstractFormBuilderForm;
-use wcf\system\file\upload\UploadFile;
use wcf\system\form\builder\container\FormContainer;
use wcf\system\form\builder\field\IsDisabledFormField;
use wcf\system\form\builder\field\RadioButtonFormField;
$iconContainer
]);
}
-
- /**
- * @inheritDoc
- */
- public function saved() {
- $this->saveImage($this->objectAction->getReturnValues()['returnValues']);
-
- parent::saved();
- }
-
- /**
- * Save the image for a reaction type.
- *
- * @param ReactionType $reactionType
- */
- protected function saveImage(ReactionType $reactionType) {
- $files = $this->uploadFormField->getValue();
-
- /** @var UploadFile $file */
- $file = array_pop($files);
- if (!$file->isProcessed()) {
- $fileName = $reactionType->reactionTypeID . '-' . $file->getFilename();
-
- rename($file->getLocation(), WCF_DIR . '/images/reaction/' . $fileName);
- $file->setProcessed(WCF_DIR . '/images/reaction/' . $fileName);
-
- $reactionTypeEditor = new ReactionTypeEditor($reactionType);
- $reactionTypeEditor->update([
- 'iconFile' => $fileName
- ]);
- }
- }
}
<?php
namespace wcf\acp\form;
use wcf\data\reaction\type\ReactionType;
-use wcf\form\AbstractFormBuilderForm;
use wcf\system\exception\IllegalLinkException;
use wcf\system\file\upload\UploadFile;
]);
}
}
-
- /**
- * @inheritDoc
- */
- public function saved() {
- // remove removed files
- foreach ($this->uploadFormField->getRemovedFiles(true) as $file) {
- @unlink($file->getLocation());
- }
-
- $this->saveImage($this->formObject);
-
- AbstractFormBuilderForm::saved();
- }
}
use wcf\data\ISortableAction;
use wcf\system\exception\PermissionDeniedException;
use wcf\system\exception\UserInputException;
+use wcf\system\file\upload\UploadFile;
use wcf\system\language\I18nHandler;
use wcf\system\WCF;
$updateData['title'] = 'wcf.reactionType.title' . $reactionType->reactionTypeID;
}
+ // image
+ if (isset($this->parameters['iconFile']) && is_array($this->parameters['iconFile'])) {
+ $iconFile = reset($this->parameters['iconFile']);
+ if (!($iconFile instanceof UploadFile)) {
+ throw new \InvalidArgumentException("The parameter 'image' is no instance of '". UploadFile::class ."', instance of '". get_class($iconFile) ."' given.");
+ }
+
+ // save new image
+ if (!$iconFile->isProcessed()) {
+ $fileName = $reactionType->reactionTypeID . '-' . $iconFile->getFilename();
+
+ rename($iconFile->getLocation(), WCF_DIR . '/images/reaction/' . $fileName);
+ $iconFile->setProcessed(WCF_DIR . '/images/reaction/' . $fileName);
+
+ $updateData['iconFile'] = $fileName;
+ }
+ }
+
if (!empty($updateData)) {
$reactionTypeEditor->update($updateData);
}
public function update() {
parent::update();
- // i18n
foreach ($this->getObjects() as $object) {
+ $updateData = [];
+
+ // i18n
if (isset($this->parameters['title_i18n'])) {
I18nHandler::getInstance()->save(
$this->parameters['title_i18n'],
1
);
- $object->update([
- 'title' => 'wcf.reactionType.title' . $object->reactionTypeID
- ]);
+ $updateData['title'] = 'wcf.reactionType.title' . $object->reactionTypeID;
+ }
+
+ // delete orphaned images
+ if (isset($this->parameters['iconFile_removedFiles']) && is_array($this->parameters['iconFile_removedFiles'])) {
+ /** @var UploadFile $file */
+ foreach ($this->parameters['iconFile_removedFiles'] as $file) {
+ @unlink($file->getLocation());
+ }
}
+
+ // image
+ if (isset($this->parameters['iconFile']) && is_array($this->parameters['iconFile'])) {
+ $iconFile = reset($this->parameters['iconFile']);
+ if (!($iconFile instanceof UploadFile)) {
+ throw new \InvalidArgumentException("The parameter 'image' is no instance of '". UploadFile::class ."', instance of '". get_class($iconFile) ."' given.");
+ }
+
+ // save new image
+ if (!$iconFile->isProcessed()) {
+ $fileName = $object->reactionTypeID . '-' . $iconFile->getFilename();
+
+ rename($iconFile->getLocation(), WCF_DIR . '/images/reaction/' . $fileName);
+ $iconFile->setProcessed(WCF_DIR . '/images/reaction/' . $fileName);
+
+ $updateData['iconFile'] = $fileName;
+ }
+ }
+
+ if (!empty($updateData)) {
+ $object->update($updateData);
+ }
}
}