From cdc0805fc4608885009425b0e8d3a791768003e5 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Thu, 10 Mar 2022 12:07:07 -0600 Subject: [PATCH] Sanitize dates input in the importer before saving --- app/Importer/AssetImporter.php | 2 ++ app/Importer/LicenseImporter.php | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/Importer/AssetImporter.php b/app/Importer/AssetImporter.php index 9f635cd3fd..7fe5231985 100644 --- a/app/Importer/AssetImporter.php +++ b/app/Importer/AssetImporter.php @@ -97,10 +97,12 @@ class AssetImporter extends ItemImporter $item['rtd_location_id'] = $this->item['location_id']; } + $item['last_audit_date'] = null; if (isset($this->item['last_audit_date'])) { $item['last_audit_date'] = $this->item['last_audit_date']; } + $item['next_audit_date'] = null; if (isset($this->item['next_audit_date'])) { $item['next_audit_date'] = $this->item['next_audit_date']; } diff --git a/app/Importer/LicenseImporter.php b/app/Importer/LicenseImporter.php index 94adbd5ee5..c68a90a2bb 100644 --- a/app/Importer/LicenseImporter.php +++ b/app/Importer/LicenseImporter.php @@ -47,14 +47,22 @@ class LicenseImporter extends ItemImporter $license = new License; } $asset_tag = $this->item['asset_tag'] = $this->findCsvMatch($row, 'asset_tag'); // used for checkout out to an asset. - $this->item['expiration_date'] = $this->findCsvMatch($row, 'expiration_date'); + + $this->item['expiration_date'] = null; + if ($this->findCsvMatch($row, 'expiration_date') != '') { + $this->item['expiration_date'] = date('Y-m-d 00:00:01', strtotime($this->findCsvMatch($row, 'expiration_date'))); + } $this->item['license_email'] = $this->findCsvMatch($row, 'license_email'); $this->item['license_name'] = $this->findCsvMatch($row, 'license_name'); $this->item['maintained'] = $this->findCsvMatch($row, 'maintained'); $this->item['purchase_order'] = $this->findCsvMatch($row, 'purchase_order'); $this->item['reassignable'] = $this->findCsvMatch($row, 'reassignable'); $this->item['seats'] = $this->findCsvMatch($row, 'seats'); - $this->item['termination_date'] = $this->findCsvMatch($row, 'termination_date'); + + $this->item['termination_date'] = null; + if ($this->findCsvMatch($row, 'termination_date') != '') { + $this->item['termination_date'] = date('Y-m-d 00:00:01', strtotime($this->findCsvMatch($row, 'termination_date'))); + } if ($editingLicense) { $license->update($this->sanitizeItemForUpdating($license));