Fallback to phantomjscloud

This commit is contained in:
Hillel Coren 2017-06-04 17:54:50 +03:00
parent 1bf072ca27
commit 27ee08d541
5 changed files with 52 additions and 14 deletions

View File

@ -91,7 +91,7 @@ class ClientPortalController extends BaseController
];
$invoice->invoice_fonts = $account->getFontsData();
if ($design = $account->getCustomDesign($invoice->getDesignId())) {
if ($design = $account->getCustomDesign($invoice->invoice_design_id)) {
$invoice->invoice_design->javascript = $design;
} else {
$invoice->invoice_design->javascript = $invoice->invoice_design->pdfmake;

View File

@ -594,11 +594,6 @@ class Invoice extends EntityModel implements BalanceAffecting
return $this->is_recurring ? trans('texts.recurring') : $this->invoice_number;
}
public function getDesignId()
{
return $this->isQuote() ? $this->quote_design_id : $this->invoice_design_id;
}
/**
* @return string
*/
@ -1258,14 +1253,12 @@ class Invoice extends EntityModel implements BalanceAffecting
$pdfString = CurlUtils::phantom('GET', $link . '?phantomjs=true&phantomjs_secret=' . env('PHANTOMJS_SECRET'));
}
if (! $pdfString && (Utils::isNinja() || ! env('PHANTOMJS_BIN_PATH'))) {
if ($key = env('PHANTOMJS_CLOUD_KEY')) {
if (Utils::isNinjaDev()) {
$link = env('TEST_LINK');
}
$url = "http://api.phantomjscloud.com/api/browser/v2/{$key}/?request=%7Burl:%22{$link}?phantomjs=true%22,renderType:%22html%22%7D";
$pdfString = CurlUtils::get($url);
if (! $pdfString && ($key = env('PHANTOMJS_CLOUD_KEY'))) {
if (Utils::isNinjaDev()) {
$link = env('TEST_LINK');
}
$url = "http://api.phantomjscloud.com/api/browser/v2/{$key}/?request=%7Burl:%22{$link}?phantomjs=true%22,renderType:%22html%22%7D";
$pdfString = CurlUtils::get($url);
}
$pdfString = strip_tags($pdfString);

44
config/pdf.php Normal file
View File

@ -0,0 +1,44 @@
<?php
return [
'phantomjs' => [
/*
|--------------------------------------------------------------------------
| PhantomJS Secret
|--------------------------------------------------------------------------
|
| This enables the PhantomJS request to bypass client authorization.
|
*/
'secret' => env('PHANTOMJS_SECRET'),
/*
|--------------------------------------------------------------------------
| PhantomJS Bin Path
|--------------------------------------------------------------------------
|
| The path to the local PhantomJS binary.
| For example: /usr/local/bin/phantomjs
| You can run which phantomjs to determine the value
|
*/
'bin_path' => env('PHANTOMJS_BIN_PATH'),
/*
|--------------------------------------------------------------------------
| PhantomJS Cloud Key
|--------------------------------------------------------------------------
|
| Key for the https://phantomjscloud.com service
|
*/
'cloud_key' => env('PHANTOMJS_CLOUD_KEY')
]
];

View File

@ -2262,6 +2262,7 @@ $LANG = array(
'empty' => 'Empty',
'load_design' => 'Load Design',
'accepted_card_logos' => 'Accepted Card Logos',
'phantomjs_local_and_cloud' => 'Using local PhantomJS, falling back to phantomjscloud.com',
);

View File

@ -47,7 +47,7 @@
{!! Former::checkbox('pdf_email_attachment')
->text(trans('texts.enable'))
->value(1)
->help( ! Utils::isNinja() ? (env('PHANTOMJS_BIN_PATH') ? 'phantomjs_local' : trans('texts.phantomjs_help', [
->help( ! Utils::isNinja() ? (config('pdf.phantomjs.bin_path') ? (config('pdf.phantomjs.cloud_key') ? 'phantomjs_local_and_cloud' : 'phantomjs_local') : trans('texts.phantomjs_help', [
'link_phantom' => link_to('https://phantomjscloud.com/', 'phantomjscloud.com', ['target' => '_blank']),
'link_docs' => link_to('http://docs.invoiceninja.com/en/latest/configure.html#phantomjs', 'PhantomJS', ['target' => '_blank'])
])) : false) !!}