TT#12661 FaxRecordings add fax retreival from DB

- /api/faxrecordings retreive faxes from the db

Change-Id: I51d2bf49b7806b60ba436a78ca5a6c2e29d986c3
changes/67/12767/5
Kirill Solomko 9 years ago
parent 24ffcb618c
commit 7db5632a38

@ -83,7 +83,7 @@ sub GET :Allow {
my ($content, $ext) = NGCP::Panel::Utils::Fax::get_fax(
c => $c,
filename => $item->filename,
item => $item,
format => $format,
);
last unless $content && $ext;

@ -10,10 +10,9 @@ sub _item_rs {
my ($self, $c) = @_;
my $item_rs = $c->model('DB')->resultset('voip_fax_journal')->search({
filename => { '!=' => '' },
'voip_subscriber.id' => { '!=' => undef },
},{
join => { 'provisioning_voip_subscriber' => 'voip_subscriber' },
join => { voip_fax_data => { provisioning_voip_subscriber => 'voip_subscriber' } },
});
if($c->user->roles eq "admin") {
@ -21,7 +20,8 @@ sub _item_rs {
$item_rs = $item_rs->search({
'contact.reseller_id' => $c->user->reseller_id
},{
join => { provisioning_voip_subscriber => { voip_subscriber => { contract => 'contact' } } }
join => { voip_fax_data => { provisioning_voip_subscriber => { voip_subscriber => { contract => 'contact' } } } }
});
}
return $item_rs;

@ -78,6 +78,9 @@ sub send_fax {
sub get_fax {
my (%args) = @_;
my $c = $args{c};
# mandatory is $item or $filename
# $item - get a stored fax from the db
# $filename - get a stored fax from the spool
#moved here due to CE, as it doesn't carry NGCP::fax
eval { require NGCP::Fax; };
@ -90,23 +93,39 @@ sub get_fax {
}
}
my ($filename, $format) = @{args}{qw(filename format)};
return unless $filename;
my $spool = $c->config->{faxserver}{spool_dir} || return;
my $filepath;
foreach my $dir (qw(completed failed)) {
my $check_path = sprintf "%s/%s/%s", $spool, $dir, $filename;
if (-e $check_path) {
$filepath = $check_path;
last;
}
}
return unless $filepath;
my $content;
my $ext = 'tif';
my ($filename, $format, $item) = @{args}{qw(filename format item)};
return unless $filename || $item;
return unless $item && $item->voip_fax_data->data;
my $tmp_fh;
if ($filename) {
my $spool = $c->config->{faxserver}{spool_dir} || return;
foreach my $dir (qw(completed failed)) {
my $check_path = sprintf "%s/%s/%s", $spool, $dir, $filename;
if (-e $check_path) {
$filepath = $check_path;
last;
}
}
return unless $filepath;
} else {
if ($format) {
($tmp_fh, $filepath) =
File::Temp::tempfile( DIR => $cfg->{spool_dir}."/tmp")
or $self->error("Cannot create temp file: $ERRNO");
binmode $tmp_fh;
close $tmp_fh;
print $tmp_fh $item->voip_fax_data->data;
} else {
return ($item->voip_fax_data->data, $ext);
}
}
if ($format) {
my $client = new NGCP::Fax;
my $fh = $client->convert_file({}, $filepath, $format);

Loading…
Cancel
Save