66use wcf \data \attachment \AdministrativeAttachment ;
77use wcf \data \attachment \AdministrativeAttachmentList ;
88use wcf \data \DatabaseObject ;
9+ use wcf \data \object \type \ObjectTypeCache ;
910use wcf \event \gridView \admin \AttachmentGridViewInitialized ;
11+ use wcf \system \database \util \PreparedStatementConditionBuilder ;
1012use wcf \system \gridView \AbstractGridView ;
1113use wcf \system \gridView \GridViewColumn ;
1214use 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