mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-07-25 22:27:05 -04:00
Resolve review comments
- Move validation function to attribute_helper.php - Removed extra line in security_helper.php - Corrected some calls to helper() that included `_helper` Signed-off-by: objec <objecttothis@gmail.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user