fixed columns bind
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
// "Nessuna corrispondenza": azzera il valore grezzo nei record importati, senza salvare binding.
|
||||
// "Nessuna corrispondenza": azzera il valore importato (custom o fixed) e rimuove il binding. Ritorna JSON.
|
||||
|
||||
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
|
||||
require_once __DIR__ . '/class/db-functions.php';
|
||||
@@ -23,8 +23,9 @@ if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
exit;
|
||||
}
|
||||
|
||||
$mappingId = intval($_POST['mapping_id'] ?? 0);
|
||||
$jsonValue = (string) ($_POST['json_value'] ?? '');
|
||||
$kind = ($_POST['kind'] ?? 'custom') === 'fixed' ? 'fixed' : 'custom';
|
||||
$templateId = intval($_POST['template_id'] ?? 0);
|
||||
$jsonValue = (string) ($_POST['json_value'] ?? '');
|
||||
|
||||
$datadbIds = [];
|
||||
if (isset($_POST['datadb_ids'])) {
|
||||
@@ -34,19 +35,35 @@ if (isset($_POST['datadb_ids'])) {
|
||||
}
|
||||
}
|
||||
|
||||
if ($mappingId <= 0 || $jsonValue === '') {
|
||||
if ($jsonValue === '') {
|
||||
http_response_code(422);
|
||||
echo json_encode(['success' => false, 'error' => 'Missing required parameters']);
|
||||
echo json_encode(['success' => false, 'error' => 'Missing json_value']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$pdo = DBHandlerSelect::getInstance()->getConnection();
|
||||
$cleared = binding_apply_to_details($pdo, $mappingId, '', $datadbIds);
|
||||
|
||||
// Rimuovo un eventuale binding gia' salvato (es. auto-collegato) per coerenza.
|
||||
$del = $pdo->prepare("DELETE FROM json_lims_binding WHERE mapping_id = ? AND json_value = ?");
|
||||
$del->execute([$mappingId, $jsonValue]);
|
||||
if ($kind === 'fixed') {
|
||||
$fixedKey = trim($_POST['fixed_field_key'] ?? '');
|
||||
$column = binding_fixed_column($fixedKey);
|
||||
if ($fixedKey === '' || !binding_fixed_is_list($fixedKey) || !$column || $templateId <= 0) {
|
||||
http_response_code(422);
|
||||
echo json_encode(['success' => false, 'error' => 'Invalid fixed field']);
|
||||
exit;
|
||||
}
|
||||
$cleared = !empty($datadbIds) ? binding_apply_to_datadb($pdo, $column, null, $datadbIds) : 0;
|
||||
binding_delete_target($pdo, binding_target_fixed($templateId, $fixedKey), $jsonValue);
|
||||
} else {
|
||||
$mappingId = intval($_POST['mapping_id'] ?? 0);
|
||||
if ($mappingId <= 0) {
|
||||
http_response_code(422);
|
||||
echo json_encode(['success' => false, 'error' => 'Missing mapping_id']);
|
||||
exit;
|
||||
}
|
||||
$cleared = !empty($datadbIds) ? binding_apply_to_details($pdo, $mappingId, '', $datadbIds) : 0;
|
||||
binding_delete_target($pdo, binding_target_custom($mappingId), $jsonValue);
|
||||
}
|
||||
|
||||
echo json_encode(['success' => true, 'cleared_rows' => $cleared]);
|
||||
} catch (Exception $e) {
|
||||
|
||||
Reference in New Issue
Block a user