From 5d50b77dccce9a6e0b654e65ed2aeeb97830a45d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 16 May 2024 10:34:38 +1000 Subject: [PATCH 1/4] Add type_id property to filterable --- app/Http/Controllers/ImportController.php | 3 +++ app/Services/Template/TemplateService.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ImportController.php b/app/Http/Controllers/ImportController.php index b2fa825cf63b..b325dd4e3dae 100644 --- a/app/Http/Controllers/ImportController.php +++ b/app/Http/Controllers/ImportController.php @@ -169,6 +169,9 @@ class ImportController extends Controller $enc = mb_detect_encoding($data, mb_list_encodings(), true); + nlog("env"); + nlog($enc); + if($enc !== false) { $data = mb_convert_encoding($data, "UTF-8", $enc); } diff --git a/app/Services/Template/TemplateService.php b/app/Services/Template/TemplateService.php index 89482765fade..8d64912bf0d4 100644 --- a/app/Services/Template/TemplateService.php +++ b/app/Services/Template/TemplateService.php @@ -126,7 +126,7 @@ class TemplateService $allowedTags = ['if', 'for', 'set', 'filter']; $allowedFilters = ['escape', 'e', 'upper', 'lower', 'capitalize', 'filter', 'length', 'merge','format_currency','map', 'join', 'first', 'date','sum']; $allowedFunctions = ['range', 'cycle', 'constant', 'date',]; - $allowedProperties = []; + $allowedProperties = ['type_id']; $allowedMethods = ['img','t']; $policy = new \Twig\Sandbox\SecurityPolicy($allowedTags, $allowedFilters, $allowedFunctions, $allowedProperties, $allowedMethods); From 716bd6669e96a9585f536a7a2e6e26d4f80ea5c2 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 16 May 2024 11:46:54 +1000 Subject: [PATCH 2/4] Ensure line items as cast to arrays for twig templates --- app/Http/Controllers/ImportController.php | 11 +++---- app/Import/Providers/BaseImport.php | 40 +++++++++++++++++++++++ app/Jobs/Mail/NinjaMailerJob.php | 2 -- app/Services/Template/TemplateService.php | 2 +- 4 files changed, 45 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/ImportController.php b/app/Http/Controllers/ImportController.php index b325dd4e3dae..7c8e393ad1c9 100644 --- a/app/Http/Controllers/ImportController.php +++ b/app/Http/Controllers/ImportController.php @@ -167,14 +167,11 @@ class ImportController extends Controller private function convertEncoding($data) { - $enc = mb_detect_encoding($data, mb_list_encodings(), true); + // $enc = mb_detect_encoding($data, mb_list_encodings(), true); - nlog("env"); - nlog($enc); - - if($enc !== false) { - $data = mb_convert_encoding($data, "UTF-8", $enc); - } + // if($enc !== false) { + // $data = mb_convert_encoding($data, "UTF-8", $enc); + // } return $data; } diff --git a/app/Import/Providers/BaseImport.php b/app/Import/Providers/BaseImport.php index 9411aa79e381..38294e82a6f4 100644 --- a/app/Import/Providers/BaseImport.php +++ b/app/Import/Providers/BaseImport.php @@ -937,4 +937,44 @@ class BaseImport return $data; } + + private function convertData(array $data): array + { + + // List of encodings to check against + $encodings = [ + 'UTF-8', + 'ISO-8859-1', // Latin-1 + 'ISO-8859-2', // Latin-2 + 'WINDOWS-1252', // CP1252 + 'SHIFT-JIS', + 'EUC-JP', + 'GB2312', + 'GBK', + 'BIG5', + 'ISO-2022-JP', + 'KOI8-R', + 'KOI8-U', + 'WINDOWS-1251', // CP1251 + 'UTF-16', + 'UTF-32', + 'ASCII' + ]; + + foreach ($data as $key => $value) { + // Only process strings + if (is_string($value)) { + // Detect the encoding of the string + $detectedEncoding = mb_detect_encoding($value, $encodings, true); + + // If encoding is detected and it's not UTF-8, convert it to UTF-8 + if ($detectedEncoding && $detectedEncoding !== 'UTF-8') { + $array[$key] = mb_convert_encoding($value, 'UTF-8', $detectedEncoding); + } + } + } + + return $data; + } + } diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 22a9069c5ac8..7abfdbc29c12 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -77,8 +77,6 @@ class NinjaMailerJob implements ShouldQueue /*Set the correct database*/ MultiDB::setDb($this->nmo->company->db); -nlog("nn"); - /* Serializing models from other jobs wipes the primary key */ $this->company = Company::query()->where('company_key', $this->nmo->company->company_key)->first(); diff --git a/app/Services/Template/TemplateService.php b/app/Services/Template/TemplateService.php index 8d64912bf0d4..ac7ecf4e4611 100644 --- a/app/Services/Template/TemplateService.php +++ b/app/Services/Template/TemplateService.php @@ -605,7 +605,7 @@ class TemplateService $item->tax_amount = Number::formatMoney($item->tax_amount_raw, $client_or_vendor); $item->product_cost = Number::formatMoney($item->product_cost_raw, $client_or_vendor); - return $item; + return (array)$item; })->toArray(); } From b57ec227f765f48b20797129b60a20888d59ec14 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 16 May 2024 11:55:00 +1000 Subject: [PATCH 3/4] Fixes for encoding characters in imports --- app/Http/Controllers/ImportController.php | 42 +++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/app/Http/Controllers/ImportController.php b/app/Http/Controllers/ImportController.php index 7c8e393ad1c9..187e4a3ff476 100644 --- a/app/Http/Controllers/ImportController.php +++ b/app/Http/Controllers/ImportController.php @@ -233,8 +233,50 @@ class ImportController extends Controller } } + return $this->convertData($data); + } + + + + private function convertData(array $data): array + { + + // List of encodings to check against + $encodings = [ + 'UTF-8', + 'ISO-8859-1', // Latin-1 + 'ISO-8859-2', // Latin-2 + 'WINDOWS-1252', // CP1252 + 'SHIFT-JIS', + 'EUC-JP', + 'GB2312', + 'GBK', + 'BIG5', + 'ISO-2022-JP', + 'KOI8-R', + 'KOI8-U', + 'WINDOWS-1251', // CP1251 + 'UTF-16', + 'UTF-32', + 'ASCII' + ]; + + foreach ($data as $key => $value) { + // Only process strings + if (is_string($value)) { + // Detect the encoding of the string + $detectedEncoding = mb_detect_encoding($value, $encodings, true); + + // If encoding is detected and it's not UTF-8, convert it to UTF-8 + if ($detectedEncoding && $detectedEncoding !== 'UTF-8') { + $array[$key] = mb_convert_encoding($value, 'UTF-8', $detectedEncoding); + } + } + } + return $data; } + /** * Returns the best delimiter From f23f79cf56304c0ee4ceeab973959b8a7b9b1266 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 16 May 2024 14:56:45 +1000 Subject: [PATCH 4/4] v5.8.57 --- VERSION.txt | 2 +- config/ninja.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 0e6854f58efa..01959b109939 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.8.56 \ No newline at end of file +5.8.57 \ No newline at end of file diff --git a/config/ninja.php b/config/ninja.php index 94445f5394ed..6e51fe7c3b08 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -17,8 +17,8 @@ return [ 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), - 'app_version' => env('APP_VERSION', '5.8.56'), - 'app_tag' => env('APP_TAG', '5.8.56'), + 'app_version' => env('APP_VERSION', '5.8.57'), + 'app_tag' => env('APP_TAG', '5.8.57'), 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', false),