Skip to content

Commit 37053be

Browse files
committed
update database object classes
1 parent 457507f commit 37053be

File tree

2 files changed

+6
-56
lines changed

2 files changed

+6
-56
lines changed

files/lib/data/discord/bot/DiscordBot.class.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace wcf\data\discord\bot;
44

55
use wcf\data\DatabaseObject;
6+
use wcf\data\file\File;
67
use wcf\system\cache\builder\DiscordGuildChannelCacheBuilder;
78
use wcf\system\discord\DiscordApi;
89

@@ -25,6 +26,7 @@
2526
* @property-read string|null $clientSecret
2627
* @property-read string|null $publicKey
2728
* @property-read int $botTime
29+
* @property-read int|null $webhookIconID
2830
*/
2931
final class DiscordBot extends DatabaseObject
3032
{
@@ -53,9 +55,9 @@ public function getWebhookIconUploadFileLocations(): array
5355
{
5456
$files = [];
5557

56-
$filename = \sprintf('%simages/discord_webhook/%s.png', WCF_DIR, $this->botID);
57-
if (\file_exists($filename)) {
58-
$files[] = $filename;
58+
if ($this->webhookIconID !== null) {
59+
$file = new File($this->webhookIconID);
60+
$files[] = $file->getPath();
5961
}
6062

6163
return $files;

files/lib/data/discord/bot/DiscordBotAction.class.php

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use wcf\system\cache\builder\DiscordGuildChannelsCacheBuilder;
88
use wcf\system\exception\AJAXException;
99
use wcf\system\exception\PermissionDeniedException;
10-
use wcf\system\file\upload\UploadFile;
1110
use wcf\system\WCF;
1211

1312
/**
@@ -47,13 +46,7 @@ public function create()
4746
unset($this->parameters['data']['useApplicationCommands']);
4847
}
4948

50-
$discordBot = parent::create();
51-
52-
if (isset($this->parameters['webhookIcon']) && \is_array($this->parameters['webhookIcon'])) {
53-
$this->processWebhookIcon($discordBot->botID);
54-
}
55-
56-
return $discordBot;
49+
return parent::create();
5750
}
5851

5952
#[Override]
@@ -67,34 +60,6 @@ public function update()
6760
}
6861

6962
parent::update();
70-
71-
foreach ($this->getObjects() as $object) {
72-
if (isset($this->parameters['webhookIcon']) && \is_array($this->parameters['webhookIcon'])) {
73-
if ($this->parameters['webhookIcon'] === '') {
74-
$filename = \sprintf('%simages/discord_webhook/%s.png', WCF_DIR, $object->botID);
75-
if (\file_exists($filename)) {
76-
\unlink($filename);
77-
}
78-
} else {
79-
$this->processWebhookIcon($object->botID);
80-
}
81-
}
82-
}
83-
}
84-
85-
#[Override]
86-
public function delete()
87-
{
88-
$returnValues = parent::delete();
89-
90-
foreach ($this->getObjects() as $object) {
91-
$filename = \sprintf('%simages/discord_webhook/%s.png', WCF_DIR, $object->botID);
92-
if (\file_exists($filename)) {
93-
\unlink($filename);
94-
}
95-
}
96-
97-
return $returnValues;
9863
}
9964

10065
#[Override]
@@ -103,23 +68,6 @@ protected function resetCache()
10368
DiscordGuildChannelsCacheBuilder::getInstance()->reset();
10469
}
10570

106-
/**
107-
* verarbeitet hochgeladenes Icon
108-
*
109-
* @param mixed $botID
110-
* @return void
111-
*/
112-
protected function processWebhookIcon(int $botID)
113-
{
114-
$iconFile = \reset($this->parameters['webhookIcon']);
115-
if ($iconFile instanceof UploadFile && !$iconFile->isProcessed()) {
116-
$filename = \sprintf('%simages/discord_webhook/%s.png', WCF_DIR, $botID);
117-
118-
\rename($iconFile->getLocation(), $filename);
119-
$iconFile->setProcessed($filename);
120-
}
121-
}
122-
12371
/**
12472
* validiert die Methode getBotToken
12573
*

0 commit comments

Comments
 (0)