From 27ee08d541c7104b89154dbce4accbedeacc2901 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 4 Jun 2017 17:54:50 +0300 Subject: [PATCH] Fallback to phantomjscloud --- .../Controllers/ClientPortalController.php | 2 +- app/Models/Invoice.php | 17 +++---- config/pdf.php | 44 +++++++++++++++++++ resources/lang/en/texts.php | 1 + .../views/accounts/email_settings.blade.php | 2 +- 5 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 config/pdf.php diff --git a/app/Http/Controllers/ClientPortalController.php b/app/Http/Controllers/ClientPortalController.php index 66e68cb9d819..db8f5ce8f918 100644 --- a/app/Http/Controllers/ClientPortalController.php +++ b/app/Http/Controllers/ClientPortalController.php @@ -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; diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index dd477149b094..4ca53d2731c7 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -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); diff --git a/config/pdf.php b/config/pdf.php new file mode 100644 index 000000000000..06391a5db97d --- /dev/null +++ b/config/pdf.php @@ -0,0 +1,44 @@ + [ + + /* + |-------------------------------------------------------------------------- + | 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') + + ] + +]; diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index b0139e845c3e..b8f5c83925aa 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -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', ); diff --git a/resources/views/accounts/email_settings.blade.php b/resources/views/accounts/email_settings.blade.php index 1d987b937911..9053d0f02418 100644 --- a/resources/views/accounts/email_settings.blade.php +++ b/resources/views/accounts/email_settings.blade.php @@ -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) !!}