Skip to content

Commit 0b56868

Browse files
committed
Prevent the execution of an additional (unnecessary) SQL query
1 parent 8897a3a commit 0b56868

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

wcfsetup/install/files/lib/acp/form/UserRankEditForm.class.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
namespace wcf\acp\form;
44

5-
use wcf\acp\page\UserRankListPage;
65
use CuyZ\Valinor\Mapper\MappingError;
6+
use wcf\acp\page\UserRankListPage;
7+
use wcf\data\IStorableObject;
78
use wcf\data\user\rank\UserRank;
89
use wcf\http\Helper;
910
use wcf\system\exception\IllegalLinkException;
11+
use wcf\system\form\builder\data\processor\CustomFormDataProcessor;
12+
use wcf\system\form\builder\IFormDocument;
1013
use wcf\system\interaction\admin\UserRankInteractions;
1114
use wcf\system\interaction\StandaloneInteractionContextMenuView;
1215
use wcf\system\request\LinkHandler;
@@ -58,6 +61,34 @@ public function readParameters()
5861
}
5962
}
6063

64+
#[\Override]
65+
protected function finalizeForm()
66+
{
67+
parent::finalizeForm();
68+
69+
// The `DeleteInteraction` in `UserRankInteractions` outputs the title and would otherwise execute an additional SQL query.
70+
$this->form->getDataHandler()
71+
->addProcessor(
72+
new CustomFormDataProcessor(
73+
'setRankTitlesFormDataProcessor',
74+
null,
75+
static function (IFormDocument $document, array $data, IStorableObject $object) {
76+
\assert($object instanceof UserRank);
77+
78+
if (\is_array($data['rankTitle'])) {
79+
foreach ($data['rankTitle'] as $languageID => $rankTitle) {
80+
$object->setRankTitle($languageID, $rankTitle);
81+
}
82+
} else {
83+
$object->setRankTitle(null, $data['rankTitle']);
84+
}
85+
86+
return $data;
87+
}
88+
)
89+
);
90+
}
91+
6192
/**
6293
* @inheritDoc
6394
*/

0 commit comments

Comments
 (0)