diff --git a/app/Controllers/Items.php b/app/Controllers/Items.php index 9a515292f..63195e8e3 100644 --- a/app/Controllers/Items.php +++ b/app/Controllers/Items.php @@ -917,7 +917,7 @@ class Items extends Secure_Controller */ public function getGenerateCsvFile(): DownloadResponse { - helper('importfile_helper'); + helper('importfile'); $name = 'import_items.csv'; $allowed_locations = $this->stock_location->get_allowed_locations(); $allowed_attributes = $this->attribute->get_definition_names(); @@ -942,7 +942,7 @@ class Items extends Secure_Controller */ public function postImportCsvFile(): void { - helper('importfile_helper'); + helper('importfile'); try { if ($_FILES['file_path']['error'] !== UPLOAD_ERR_OK) { echo json_encode(['success' => false, 'message' => lang('Items.csv_import_failed')]); @@ -1208,9 +1208,7 @@ class Items extends Secure_Controller // Update attribute value if only the case has changed. if (strcasecmp($storedValue, $value) === 0 && $storedValue !== $value) { $attributeId = $this->attribute->saveAttributeValue($value, $attributeData['definition_id'], $itemId, $attributeId, $attributeData['definition_type']); - } - - if (!$this->attribute->saveAttributeLink($itemId, $attributeData['definition_id'], $attributeId)) { + } elseif (!$this->attribute->saveAttributeLink($itemId, $attributeData['definition_id'], $attributeId)) { return false; } } diff --git a/app/Helpers/attribute_helper.php b/app/Helpers/attribute_helper.php index c86aac255..1d6712369 100644 --- a/app/Helpers/attribute_helper.php +++ b/app/Helpers/attribute_helper.php @@ -18,3 +18,16 @@ function getAttributeDataType(string $input): string return $columnMap[$input] ?? 'attribute_value'; } + +/** + * Validates that the provided data type is an allowed attribute value type. + * + * @param string $dataType + * @return void + */ +function validateAttributeValueType(string $dataType): void +{ + if (!in_array($dataType, ATTRIBUTE_VALUE_TYPES, true)) { + throw new InvalidArgumentException('Invalid data type'); + } +} diff --git a/app/Helpers/security_helper.php b/app/Helpers/security_helper.php index f0b761a87..f48b16664 100644 --- a/app/Helpers/security_helper.php +++ b/app/Helpers/security_helper.php @@ -108,16 +108,3 @@ function remove_backup(): void } log_message('info', "File $backup_path has been removed"); } - -/** - * @param string $dataType - * @return void - */ -function validateAttributeValueType(string $dataType): void -{ - if (!in_array($dataType, ATTRIBUTE_VALUE_TYPES, true)) { - throw new InvalidArgumentException('Invalid data type'); - } -} - - diff --git a/app/Models/Attribute.php b/app/Models/Attribute.php index 0f2cdac8a..27eefb294 100644 --- a/app/Models/Attribute.php +++ b/app/Models/Attribute.php @@ -9,6 +9,7 @@ use CodeIgniter\Model; use CodeIgniter\Database\RawSql; use Config\OSPOS; use DateTime; +use InvalidArgumentException; use stdClass; use ReflectionClass; @@ -720,6 +721,7 @@ class Attribute extends Model */ public function getAttributeValueByAttributeId(int $attributeId, string $dataType): string|float|null { + helper('attribute'); validateAttributeValueType($dataType); $builder = $this->db->table('attribute_values'); @@ -1069,6 +1071,7 @@ class Attribute extends Model */ private function updateAttributeValue(int $attributeId, string $dataType, mixed $attributeValue): void { + helper('attribute'); validateAttributeValueType($dataType); // Update the attribute_values table