mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 12:12:48 +01:00
Merge proposal PDF fix
This commit is contained in:
parent
b818ff95b6
commit
d543cfcc3f
@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Jobs\Job;
|
||||
use App\Libraries\CurlUtils;
|
||||
use Utils;
|
||||
|
||||
class ConvertProposalToPdf extends Job
|
||||
{
|
||||
@ -14,11 +14,36 @@ class ConvertProposalToPdf extends Job
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$proposal = $this->proposal;
|
||||
$url = $proposal->getHeadlessLink();
|
||||
if (! env('PHANTOMJS_CLOUD_KEY') && ! env('PHANTOMJS_BIN_PATH')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Utils::isTravis()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$proposal = $this->proposal;
|
||||
$link = $proposal->getLink(true, true);
|
||||
$phantomjsSecret = env('PHANTOMJS_SECRET');
|
||||
$phantomjsLink = sprintf('%s?phantomjs=true&phantomjs_secret=%s', $link, $phantomjsSecret);
|
||||
$filename = sprintf('%s/storage/app/%s.pdf', base_path(), strtolower(str_random(RANDOM_KEY_LENGTH)));
|
||||
$pdf = CurlUtils::renderPDF($url, $filename);
|
||||
|
||||
try {
|
||||
$pdf = CurlUtils::renderPDF($phantomjsLink, $filename);
|
||||
|
||||
if (! $pdf && ($key = env('PHANTOMJS_CLOUD_KEY'))) {
|
||||
$url = "http://api.phantomjscloud.com/api/browser/v2/{$key}/?request=%7Burl:%22{$link}?phantomjs=true%26phantomjs_secret={$phantomjsSecret}%22,renderType:%22pdf%22%7D";
|
||||
$pdf = CurlUtils::get($url);
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
Utils::logError("PhantomJS - Failed to load {$phantomjsLink}: {$exception->getMessage()}");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $pdf || strlen($pdf) < 200) {
|
||||
Utils::logError("PhantomJS - Invalid response {$phantomjsLink}: {$pdf}");
|
||||
return false;
|
||||
}
|
||||
|
||||
return $pdf;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user