Skip to content

Commit a3b619c

Browse files
committed
Fix issue that private attachments were not being filtered out from the attachment grid view
This behavior was accidentally removed during the migration to grid view.
1 parent fe2e567 commit a3b619c

2 files changed

Lines changed: 68 additions & 9 deletions

File tree

wcfsetup/install/files/lib/acp/page/AttachmentListPage.class.php

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace wcf\acp\page;
44

5+
use wcf\data\object\type\ObjectTypeCache;
56
use wcf\page\AbstractGridViewPage;
7+
use wcf\system\database\util\PreparedStatementConditionBuilder;
68
use wcf\system\gridView\admin\AttachmentGridView;
79
use wcf\system\WCF;
810

@@ -48,14 +50,34 @@ public function assignVariables()
4850
*/
4951
private function getAttachmentStats(): array
5052
{
51-
$sql = "SELECT COUNT(*) AS count,
52-
COALESCE(SUM(file.fileSize), 0) AS size,
53-
COALESCE(SUM(downloads), 0) AS downloads
54-
FROM wcf1_attachment attachment
53+
$objectTypeIDs = [];
54+
foreach (ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.attachment.objectType') as $objectType) {
55+
if (!$objectType->private) {
56+
$objectTypeIDs[] = $objectType->objectTypeID;
57+
}
58+
}
59+
60+
if ($objectTypeIDs === []) {
61+
return [
62+
'count' => 0,
63+
'size' => 0,
64+
'downloads' => 0,
65+
];
66+
}
67+
68+
$conditionBuilder = new PreparedStatementConditionBuilder();
69+
$conditionBuilder->add('attachment.objectTypeID IN (?)', [$objectTypeIDs]);
70+
$conditionBuilder->add('attachment.tmpHash = ?', ['']);
71+
72+
$sql = "SELECT COUNT(*) AS count,
73+
COALESCE(SUM(file.fileSize), 0) AS size,
74+
COALESCE(SUM(downloads), 0) AS downloads
75+
FROM wcf1_attachment attachment
5576
LEFT JOIN wcf1_file file
56-
ON (file.fileID = attachment.fileID)";
77+
ON (file.fileID = attachment.fileID)
78+
" . $conditionBuilder;
5779
$statement = WCF::getDB()->prepare($sql);
58-
$statement->execute();
80+
$statement->execute($conditionBuilder->getParameters());
5981

6082
return $statement->fetchArray();
6183
}

wcfsetup/install/files/lib/system/gridView/admin/AttachmentGridView.class.php

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
use wcf\data\attachment\AdministrativeAttachment;
77
use wcf\data\attachment\AdministrativeAttachmentList;
88
use wcf\data\DatabaseObject;
9+
use wcf\data\object\type\ObjectTypeCache;
910
use wcf\event\gridView\admin\AttachmentGridViewInitialized;
11+
use wcf\system\database\util\PreparedStatementConditionBuilder;
1012
use wcf\system\gridView\AbstractGridView;
1113
use wcf\system\gridView\GridViewColumn;
1214
use wcf\system\gridView\GridViewRowLink;
@@ -190,13 +192,23 @@ public function render(mixed $value, DatabaseObject $row): string
190192
*/
191193
private function getAvailableFileTypes(): array
192194
{
195+
$objectTypeIDs = $this->getAvailableObjectTypeIDs();
196+
if ($objectTypeIDs === []) {
197+
return [];
198+
}
199+
200+
$conditionBuilder = new PreparedStatementConditionBuilder();
201+
$conditionBuilder->add('attachment.fileID IS NOT NULL');
202+
$conditionBuilder->add('attachment.objectTypeID IN (?)', [$objectTypeIDs]);
203+
$conditionBuilder->add('attachment.tmpHash = ?', ['']);
204+
193205
$sql = "SELECT DISTINCT file_table.mimeType
194206
FROM wcf1_attachment attachment
195207
LEFT JOIN wcf1_file file_table
196208
ON (file_table.fileID = attachment.fileID)
197-
WHERE attachment.fileID IS NOT NULL";
209+
" . $conditionBuilder;
198210
$statement = WCF::getDB()->prepare($sql);
199-
$statement->execute();
211+
$statement->execute($conditionBuilder->getParameters());
200212
$fileTypes = $statement->fetchAll(\PDO::FETCH_COLUMN);
201213

202214
\sort($fileTypes);
@@ -213,12 +225,37 @@ public function isAccessible(): bool
213225
#[\Override]
214226
protected function createObjectList(): AdministrativeAttachmentList
215227
{
216-
return new AdministrativeAttachmentList();
228+
$list = new AdministrativeAttachmentList();
229+
230+
$objectTypeIDs = $this->getAvailableObjectTypeIDs();
231+
if ($objectTypeIDs !== []) {
232+
$list->getConditionBuilder()->add('attachment.objectTypeID IN (?)', [$objectTypeIDs]);
233+
} else {
234+
$list->getConditionBuilder()->add('1=0');
235+
}
236+
$list->getConditionBuilder()->add('attachment.tmpHash = ?', ['']);
237+
238+
return $list;
217239
}
218240

219241
#[\Override]
220242
protected function getInitializedEvent(): AttachmentGridViewInitialized
221243
{
222244
return new AttachmentGridViewInitialized($this);
223245
}
246+
247+
/**
248+
* @return list<int>
249+
*/
250+
private function getAvailableObjectTypeIDs(): array
251+
{
252+
$objectTypeIDs = [];
253+
foreach (ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.attachment.objectType') as $objectType) {
254+
if (!$objectType->private) {
255+
$objectTypeIDs[] = $objectType->objectTypeID;
256+
}
257+
}
258+
259+
return $objectTypeIDs;
260+
}
224261
}

0 commit comments

Comments
 (0)