Accessing TRAC attachments with php script

20 views Asked by At

We are in process of migrating off of TRAC issue tracker. One piece that is proving hard to work around is exporting or even accessing attachment files from a PHP script.

For example, when a user clicks a filename in trac it takes them to a page

https://example.com/trac/attachment/ticket/12345/somerandomfile.txt

This page then shows a viewer with the file shown inside the viewer. There is not a direct link to the file anywhere. Searching the filesystem for somerandomfile.txt yields no results.

There is not a path in the trac attachment table. Attachments on the filesystem appear to be stored in a trac/files/attachments/ticket/ folder, with a ton of subfolders that look a little like:

drwxrwx---. 3 apache apache  54 Oct 14  2014 ed2
drwxrwxr-x. 3 apache apache  54 Jun 27  2016 efe
drwxrwxr-x. 3 apache apache  54 Apr 27  2016 f03
drwxr-xr-x. 3 apache apache  54 Sep  5  2023 f23
drwxr-xr-x. 3 apache apache  54 May 16  2022 f27
etc

Inside one of those folders, f27 for example, is the following:

ll trac/files/attachments/ticket/f27/f272a53b0ef1c576ff83d5cbdb2278970c863fb8/

-rw-r--r--. 1 apache webdev 136822 May 16  2022 3ae453533caeb7abb4a407d28beb556d58e8db04.png

I found a script that exports attachments to a dedicated trac/$ticketID/ folder, however it is very slow running and seems to have stopped altogether. The script uses trac-admin for the exporting process.

Is there a simpler/better/faster way to directly access trac's attachment files via PHP?

0

There are 0 answers