Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

osTicket v1.10 (stable) and Maintenance Release v1.9.15 are now available! Go get it now

Import attachment file

Hi all!
I have a php script that imports tickets from our old ticket system.
The script includes "main.inc.php" and uses the function from Ticket class.
The files I want to "connect" to the tickets and osTicket are on the same server.
I have installed and activated this plugin: Storage :: Attachments on the Filesystem.
I want to insert these file using the backend created by the plugin (F) but without upload files with a POST call (just giving the path).
I was unable to find the right function from the classes contained in these file: class.attachments.php, class.file.php;
can you suggest me the right function?

osTicket version is 1.9.5.1

Thanks!

Comments

  • Have you taken a look at /include/class.attachment.php?

    note: that's totally a guess.
  • Yes,
    in class.attachment.php file I found the GenericAttachments class that has a couple of useful methods: upload and save.
    the upload function takes two parameters:
    1. (array) $files - it's an array of associative arrays with key "id" and "inline"
    2. (bool) $inline - I don't understand what "inline" means here but I have found it also in the ost_attachments table of the db.

    The save function it's quite the same but it takes only one file (with "id" and "inline").

    I don't know how can I use these methods without an id.

    Now i'm looking into include/class.file.php and maybe I've found the right function


  • So,
    in include/class.file.php I've found the save method of the AttachmentFile class. This method create a record in the ost_file table with the default backend (in my case the one created from the Filesystem plugin).
    I've tried and it works but now, how can I attach this file to the ticket?
    the things I have are the file id and the ticket object.

    There is the save method of the GenericAttachments class that could do what I want (partly) but I need to instanciate the object before I can use this method.
    The constructor take the "object id" and "type" but I don't know where I can get this informations
  • Ok, I resolved.
    After the insertion of the file in the database (ost_file table) with the method save of the AttachmentFile class I had to get a message of the ticket and then use the saveAttachment($file_id) method of the ThreadEntry class.
    here is the code:
                    $file_path[$k] = "path/to/file.txt";
                    $finfo = new finfo(FILEINFO_MIME_TYPE);
                    $type = $finfo->file($file_path[$k]);
                    $info=array(
                        'size' => filesize($file_path[$k]),
                        'name' => basename($file_path[$k]),
                        'data' => file_get_contents($file_path[$k]),
                        'type' => $type
                    );
                    if(($file_id=AttachmentFile::save($info))){
                        $thread_id=$ticket->getMessages()[0]['id'];
                        ThreadEntry::lookup($thread_id)->saveAttachment($file_id);
                     }
Sign In or Register to comment.