From b15041f60b3f389abd9f8aec587c4931959fda2e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 7 Jul 2021 13:19:19 +1000 Subject: [PATCH 1/2] Fixes for portal domain --- .../Requests/Company/UpdateCompanyRequest.php | 15 ++++- tests/Unit/UrlTest.php | 59 +++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 tests/Unit/UrlTest.php diff --git a/app/Http/Requests/Company/UpdateCompanyRequest.php b/app/Http/Requests/Company/UpdateCompanyRequest.php index dd7222f13552..c98814bf43a1 100644 --- a/app/Http/Requests/Company/UpdateCompanyRequest.php +++ b/app/Http/Requests/Company/UpdateCompanyRequest.php @@ -67,8 +67,8 @@ class UpdateCompanyRequest extends Request { $input = $this->all(); - // if(array_key_exists('portal_domain', $input) && strlen($input['portal_domain']) > 1) - // $input['portal_domain'] = str_replace("http:", "https:", $input['portal_domain']); + if(array_key_exists('portal_domain', $input) && strlen($input['portal_domain']) > 1) + $input['portal_domain'] = $this->addScheme($input['portal_domain']); if (array_key_exists('settings', $input)) { $input['settings'] = $this->filterSaveableSettings($input['settings']); @@ -105,4 +105,15 @@ class UpdateCompanyRequest extends Request return $settings; } + + private function addScheme($url, $scheme = 'https://') + { + + $url = str_replace("http://", "", $url); + + $url = parse_url($url, PHP_URL_SCHEME) === null ? $scheme . $url : $url; + + return rtrim($url, '/'); + + } } diff --git a/tests/Unit/UrlTest.php b/tests/Unit/UrlTest.php new file mode 100644 index 000000000000..e3a4f64050b2 --- /dev/null +++ b/tests/Unit/UrlTest.php @@ -0,0 +1,59 @@ +assertEquals("https://google.com", $this->addScheme($url)); + } + + public function testNoSchemeAndTrailingSlash() + { + $url = 'google.com/'; + + $this->assertEquals("https://google.com", $this->addScheme($url)); + } + + + public function testNoSchemeAndTrailingSlashAndHttp() + { + $url = 'http://google.com/'; + + $this->assertEquals("https://google.com", $this->addScheme($url)); + } + + private function addScheme($url, $scheme = 'https://') + { + + $url = str_replace("http://", "", $url); + + $url = parse_url($url, PHP_URL_SCHEME) === null ? $scheme . $url : $url; + + return rtrim($url, '/'); + + } + +} \ No newline at end of file From b1866039704423158d2abe8d492d276a222c9d8a Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 7 Jul 2021 16:55:11 +1000 Subject: [PATCH 2/2] Fixes for pdf creation --- app/Jobs/Entity/CreateEntityPdf.php | 2 +- app/Mail/Engine/InvoiceEmailEngine.php | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Jobs/Entity/CreateEntityPdf.php b/app/Jobs/Entity/CreateEntityPdf.php index e28c288fc457..82037a4fadff 100644 --- a/app/Jobs/Entity/CreateEntityPdf.php +++ b/app/Jobs/Entity/CreateEntityPdf.php @@ -86,7 +86,7 @@ class CreateEntityPdf implements ShouldQueue $this->contact = $invitation->contact; - $this->disk = $disk; + $this->disk = Ninja::isHosted() ? config('filesystems.default') : $disk; // $this->disk = $disk ?? config('filesystems.default'); } diff --git a/app/Mail/Engine/InvoiceEmailEngine.php b/app/Mail/Engine/InvoiceEmailEngine.php index c8ace469cef8..a0a8630364c5 100644 --- a/app/Mail/Engine/InvoiceEmailEngine.php +++ b/app/Mail/Engine/InvoiceEmailEngine.php @@ -12,6 +12,7 @@ namespace App\Mail\Engine; use App\DataMapper\EmailTemplateDefaults; +use App\Jobs\Entity\CreateEntityPdf; use App\Models\Account; use App\Utils\HtmlEngine; use App\Utils\Ninja; @@ -111,13 +112,13 @@ class InvoiceEmailEngine extends BaseEmailEngine if ($this->client->getSetting('pdf_email_attachment') !== false && $this->invoice->company->account->hasFeature(Account::FEATURE_PDF_ATTACHMENT)) { + CreateEntityPdf::dispatchNow($invitation); + if(Ninja::isHosted()) $this->setAttachments([$this->invoice->pdf_file_path($this->invitation, 'url', true)]); else $this->setAttachments([$this->invoice->pdf_file_path($this->invitation)]); - // $this->setAttachments(['path' => $this->invoice->pdf_file_path(), 'name' => basename($this->invoice->pdf_file_path())]); - } //attach third party documents