osticket-plugin-archiver icon indicating copy to clipboard operation
osticket-plugin-archiver copied to clipboard

Advanced Export fail

Open clonemeagain opened this issue 8 years ago • 7 comments

If you've tried this, you'll find that the archive function doesn't work, but everything else is peachy.

Considering that's sorta the whole point, it's a bit critical, hence the "Not ready" for use statement.

  • [x] Figure out why the PDF export is blank, I think it's debugging statements.. almost there.
  • [ ] Gather all info for Advanced export, still missing stuff.
  • [ ] Figure out attachments in Advanced export

clonemeagain avatar Jun 27 '17 07:06 clonemeagain

Turns out the PDF was missing a constant.. fixed.

Still trying to decipher the attachments.. yay Does work now though.

clonemeagain avatar Jun 28 '17 01:06 clonemeagain

This code seems to work for me, hope it helps.

class ArchiverPlugin extends Plugin {
    ...
    private function archive(Ticket $ticket) {
        ...
            // start dumping attachments:
            foreach ( $ticket->getThread ()->getEntries('') as $_entry ) {
                $entry = $ticket->getThread ()->getEntry($_entry['id']);
                foreach( $entry->getAttachments () as $a ){
                    $file = new AttachmentFile($a['attach_id']);
                    $this->copyFile ( $file, "$folder/attachment_{$a['name']}" );
                }
            }
        ...
    }
    ...
}

cornernote avatar Jun 17 '21 02:06 cornernote

Also this line won't work like you expect, because slugify replaces / with -:

$folder = $path . @Format::slugify ( "/$dept/$user/{$ticket->getSubject ()}_{$ticket->getNumber ()}" );

Should be like this:

$folder = $path 
    . '/' . @Format::slugify ($dept);
    . '/' . @Format::slugify ($user);
    . '/' . @Format::slugify ("{$ticket->getSubject ()}_{$ticket->getNumber ()}");

cornernote avatar Jun 17 '21 03:06 cornernote

While I'm here...

ArchiverPlugin::copyFile should wrap $file->open() in a try/catch to prevent an exception if the file can't be loaded (say you manually deleted some files before finding this plugin).

    private function copyFile(AttachmentFile $file, $dest) {
        try {
            $bk = $file->open ();
        } catch ( Exception $e ) {
            $this->log ( "Errors were encountered loading attachment" );
            return;
        }
        //  $bk = $file->open ();
        ...
    }

cornernote avatar Jun 17 '21 03:06 cornernote

You up for a PR mate? Seem to know what you're doing.

clonemeagain avatar Jun 17 '21 03:06 clonemeagain

In retrospect, probably would have been easier than dumping code into comments :)

cornernote avatar Jun 17 '21 03:06 cornernote

p.s. I enjoyed your colourful comments throughout the code :)

cornernote avatar Jun 17 '21 03:06 cornernote