osticket-plugin-archiver
osticket-plugin-archiver copied to clipboard
Advanced Export fail
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
Turns out the PDF was missing a constant.. fixed.
Still trying to decipher the attachments.. yay Does work now though.
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']}" );
}
}
...
}
...
}
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 ()}");
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 ();
...
}
You up for a PR mate? Seem to know what you're doing.
In retrospect, probably would have been easier than dumping code into comments :)
p.s. I enjoyed your colourful comments throughout the code :)