diff --git a/app/Jobs/Entity/CreateEntityPdf.php b/app/Jobs/Entity/CreateEntityPdf.php index eaff1cb6cb..fe4b0ccccd 100644 --- a/app/Jobs/Entity/CreateEntityPdf.php +++ b/app/Jobs/Entity/CreateEntityPdf.php @@ -224,7 +224,9 @@ class CreateEntityPdf implements ShouldQueue $this->company = null; $this->client = null; $this->contact = null; - + $maker = null; + $state = null; + return $file_path; } diff --git a/app/Jobs/Entity/CreateRawPdf.php b/app/Jobs/Entity/CreateRawPdf.php index 0f4bf410f4..a0108d7a5a 100644 --- a/app/Jobs/Entity/CreateRawPdf.php +++ b/app/Jobs/Entity/CreateRawPdf.php @@ -200,6 +200,8 @@ class CreateRawPdf implements ShouldQueue } if ($pdf) { + $maker =null; + $state = null; return $pdf; } diff --git a/app/Jobs/Entity/EmailEntity.php b/app/Jobs/Entity/EmailEntity.php index ac5a894de3..017e3802c0 100644 --- a/app/Jobs/Entity/EmailEntity.php +++ b/app/Jobs/Entity/EmailEntity.php @@ -131,6 +131,14 @@ class EmailEntity implements ShouldQueue $nmo = null; $this->invitation = null; + $this->company = null; + $this->entity_string = null; + $this->entity = null; + $this->settings = null; + $this->reminder_template = null; + $this->html_engine = null; + $this->template_data = null; + $this->email_entity_builder = null; } private function resolveEntityString() :string diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index f350674197..0f5d240033 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -129,9 +129,13 @@ class NinjaMailerJob implements ShouldQueue LightLogs::create(new EmailSuccess($this->nmo->company->company_key)) ->send(); + + nlog('Using ' . ((int) (memory_get_usage(true) / (1024 * 1024))) . 'MB '); + $this->nmo = null; $this->company = null; - + gc_collect_cycles(); + } catch (\Exception | \RuntimeException | \Google\Service\Exception $e) { nlog("error failed with {$e->getMessage()}"); @@ -169,7 +173,16 @@ class NinjaMailerJob implements ShouldQueue /* Don't send postmark failures to Sentry */ if(Ninja::isHosted() && (!$e instanceof ClientException)) app('sentry')->captureException($e); + + $message = null; + $this->nmo = null; + $this->company = null; + gc_collect_cycles(); + } + + + } /* Switch statement to handle failure notifications */ @@ -191,6 +204,7 @@ class NinjaMailerJob implements ShouldQueue if ($this->nmo->to_user instanceof ClientContact) $this->logMailError($message, $this->nmo->to_user->client); + } private function setMailDriver() diff --git a/app/Jobs/Vendor/CreatePurchaseOrderPdf.php b/app/Jobs/Vendor/CreatePurchaseOrderPdf.php index 8e6316e14a..6c7b8693ff 100644 --- a/app/Jobs/Vendor/CreatePurchaseOrderPdf.php +++ b/app/Jobs/Vendor/CreatePurchaseOrderPdf.php @@ -213,6 +213,9 @@ class CreatePurchaseOrderPdf implements ShouldQueue info($maker->getCompiledHTML()); } + $maker = null; + $state = null; + return $pdf; } diff --git a/app/Libraries/MultiDB.php b/app/Libraries/MultiDB.php index 30fbddd44b..8de41eaf97 100644 --- a/app/Libraries/MultiDB.php +++ b/app/Libraries/MultiDB.php @@ -515,17 +515,10 @@ class MultiDB { /* This will set the database connection for the request */ config(['database.default' => $database]); - - // for some reason this breaks everything _hard_ - // DB::purge($database); - // DB::reconnect($database); } public static function setDefaultDatabase() { config(['database.default' => config('ninja.db.default')]); - - // DB::purge(config('ninja.db.default')); - // DB::reconnect(config('ninja.db.default')); } } diff --git a/app/Repositories/ActivityRepository.php b/app/Repositories/ActivityRepository.php index 623fd33f29..40dad7cd16 100644 --- a/app/Repositories/ActivityRepository.php +++ b/app/Repositories/ActivityRepository.php @@ -60,7 +60,7 @@ class ActivityRepository extends BaseRepository $activity->save(); //rate limiter - // $this->createBackup($entity, $activity); + $this->createBackup($entity, $activity); } /** @@ -167,8 +167,13 @@ class ActivityRepository extends BaseRepository $maker = new PdfMakerService($state); - return $maker->design($template) + $html = $maker->design($template) ->build() ->getCompiledHTML(true); + + $maker = null; + $state = null; + + return $html; } } diff --git a/app/Services/Client/Statement.php b/app/Services/Client/Statement.php index 0185167aa8..2a91f7096f 100644 --- a/app/Services/Client/Statement.php +++ b/app/Services/Client/Statement.php @@ -108,6 +108,9 @@ class Statement \DB::connection(config('database.default'))->rollBack(); } + $maker = null; + $state = null; + return $pdf; } diff --git a/app/Services/Invoice/GenerateDeliveryNote.php b/app/Services/Invoice/GenerateDeliveryNote.php index c6a40d0578..f60c9cd876 100644 --- a/app/Services/Invoice/GenerateDeliveryNote.php +++ b/app/Services/Invoice/GenerateDeliveryNote.php @@ -107,6 +107,9 @@ class GenerateDeliveryNote Storage::disk($this->disk)->put($file_path, $pdf); + $maker = null; + $state = null; + return $file_path; } } diff --git a/app/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php index f627a0a007..03e5e686a2 100644 --- a/app/Services/PdfMaker/Design.php +++ b/app/Services/PdfMaker/Design.php @@ -712,6 +712,8 @@ class Design extends BaseDesign $elements[] = $element; } + $document = null; + return $elements; } diff --git a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php index d4dd374630..94607c9de9 100644 --- a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php +++ b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php @@ -234,44 +234,11 @@ trait DesignHelpers }); "; - // Unminified version, just for the reference. - // By default all table headers are hidden with HTML `hidden` property. - // This will check for table data values & if they're not empty it will remove hidden from the column itself. - - /* -document.addEventListener('DOMContentLoaded', function() { - document.querySelectorAll("#product-table > tbody > tr > td, #task-table > tbody > tr > td, #delivery-note-table > tbody > tr > td").forEach(e => { - if ("" !== e.innerText) { - let t = e.getAttribute("data-ref").slice(0, -3); - document.querySelector(`th[data-ref="${t}-th"]`).removeAttribute("hidden"); - } - }); - - document.querySelectorAll("#product-table > tbody > tr > td, #task-table > tbody > tr > td, #delivery-note-table > tbody > tr > td").forEach(e => { - let t = e.getAttribute("data-ref").slice(0, -3); - t = document.querySelector(`th[data-ref="${t}-th"]`); - - if (!t.hasAttribute('hidden')) { - return; - } - - if ("" == e.innerText) { - e.setAttribute('hidden', 'true'); - } - }); -}, false); - */ - $javascript = 'document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll("#product-table > tbody > tr > td, #task-table > tbody > tr > td, #delivery-note-table > tbody > tr > td").forEach(t=>{if(""!==t.innerText){let e=t.getAttribute("data-ref").slice(0,-3);document.querySelector(`th[data-ref="${e}-th"]`).removeAttribute("hidden")}}),document.querySelectorAll("#product-table > tbody > tr > td, #task-table > tbody > tr > td, #delivery-note-table > tbody > tr > td").forEach(t=>{let e=t.getAttribute("data-ref").slice(0,-3);(e=document.querySelector(`th[data-ref="${e}-th"]`)).hasAttribute("hidden")&&""==t.innerText&&t.setAttribute("hidden","true")})},!1);'; // Previously we've been decoding the HTML on the backend and XML parsing isn't good options because it requires, // strict & valid HTML to even output/decode. Decoding is now done on the frontend with this piece of Javascript. - /** - document.addEventListener('DOMContentLoaded', function() { - document.querySelectorAll(`[data-state="encoded-html"]`).forEach((element) => element.innerHTML = element.innerText) - }, false); - */ $html_decode = 'document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll(`[data-state="encoded-html"]`).forEach(e=>e.innerHTML=e.innerText)},!1);'; return ['element' => 'div', 'elements' => [ @@ -391,17 +358,6 @@ document.addEventListener('DOMContentLoaded', function() { return $converter->convert($markdown); } - // public function processMarkdownOnLineItems(array &$items): void - // { - // foreach ($items as $key => $item) { - // foreach ($item as $variable => $value) { - // $item[$variable] = DesignHelpers::parseMarkdownToHtml($value ?? ''); - // } - - // $items[$key] = $item; - // } - // } - public function processNewLines(array &$items): void { foreach ($items as $key => $item) { diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index f38e8ca9de..6dafa174d9 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -895,6 +895,10 @@ html { $dom->appendChild($container); - return $dom->saveHTML(); + $html = $dom->saveHTML(); + + $dom = null; + + return $html; } } diff --git a/app/Utils/Number.php b/app/Utils/Number.php index f424dd5c73..783b5eeb55 100644 --- a/app/Utils/Number.php +++ b/app/Utils/Number.php @@ -137,6 +137,8 @@ class Number public static function formatMoney($value, $entity) :string { + $value = floatval($value); + $currency = $entity->currency(); $thousand = $currency->thousand_separator;