From 7db5632a384a7ccd0e6bae00198854d950a20157 Mon Sep 17 00:00:00 2001 From: Kirill Solomko Date: Thu, 20 Apr 2017 10:04:01 +0200 Subject: [PATCH] TT#12661 FaxRecordings add fax retreival from DB - /api/faxrecordings retreive faxes from the db Change-Id: I51d2bf49b7806b60ba436a78ca5a6c2e29d986c3 --- .../Panel/Controller/API/FaxRecordingsItem.pm | 2 +- lib/NGCP/Panel/Role/API/FaxRecordings.pm | 6 +-- lib/NGCP/Panel/Utils/Fax.pm | 45 +++++++++++++------ 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/lib/NGCP/Panel/Controller/API/FaxRecordingsItem.pm b/lib/NGCP/Panel/Controller/API/FaxRecordingsItem.pm index ece94d379f..09fd0accf2 100644 --- a/lib/NGCP/Panel/Controller/API/FaxRecordingsItem.pm +++ b/lib/NGCP/Panel/Controller/API/FaxRecordingsItem.pm @@ -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; diff --git a/lib/NGCP/Panel/Role/API/FaxRecordings.pm b/lib/NGCP/Panel/Role/API/FaxRecordings.pm index e8b5a89609..f444fe6848 100644 --- a/lib/NGCP/Panel/Role/API/FaxRecordings.pm +++ b/lib/NGCP/Panel/Role/API/FaxRecordings.pm @@ -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; diff --git a/lib/NGCP/Panel/Utils/Fax.pm b/lib/NGCP/Panel/Utils/Fax.pm index f38e1b6ff0..140a258a03 100644 --- a/lib/NGCP/Panel/Utils/Fax.pm +++ b/lib/NGCP/Panel/Utils/Fax.pm @@ -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);