This commit is contained in:
@ -575,12 +575,16 @@ function qdb_dev_persist_submission(
|
||||
$answeredAt = $completedAt;
|
||||
$answerInsert = $pdo->prepare(
|
||||
'INSERT INTO client_answer (clientCode, questionID, answerOptionID, freeTextValue, numericValue, answeredAt)
|
||||
VALUES (:cc, :qid, :aoid, :ftv, :nv, :at)
|
||||
ON CONFLICT(clientCode, questionID) DO UPDATE SET
|
||||
answerOptionID = excluded.answerOptionID,
|
||||
freeTextValue = excluded.freeTextValue,
|
||||
numericValue = excluded.numericValue,
|
||||
answeredAt = excluded.answeredAt'
|
||||
VALUES (:cc, :qid, :aoid, :ftv, :nv, :at) '
|
||||
. qdb_upsert_update(
|
||||
['clientCode', 'questionID'],
|
||||
[
|
||||
'answerOptionID' => 'excluded.answerOptionID',
|
||||
'freeTextValue' => 'excluded.freeTextValue',
|
||||
'numericValue' => 'excluded.numericValue',
|
||||
'answeredAt' => 'excluded.answeredAt',
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
foreach ($answers as $a) {
|
||||
@ -645,13 +649,17 @@ function qdb_dev_persist_submission(
|
||||
|
||||
$pdo->prepare(
|
||||
'INSERT INTO completed_questionnaire (clientCode, questionnaireID, assignedByCoach, status, startedAt, completedAt, sumPoints)
|
||||
VALUES (:cc, :qn, :abc, \'completed\', :sa, :ca, :sp)
|
||||
ON CONFLICT(clientCode, questionnaireID) DO UPDATE SET
|
||||
assignedByCoach = excluded.assignedByCoach,
|
||||
status = \'completed\',
|
||||
startedAt = COALESCE(excluded.startedAt, startedAt),
|
||||
completedAt = excluded.completedAt,
|
||||
sumPoints = excluded.sumPoints'
|
||||
VALUES (:cc, :qn, :abc, \'completed\', :sa, :ca, :sp) '
|
||||
. qdb_upsert_update(
|
||||
['clientCode', 'questionnaireID'],
|
||||
[
|
||||
'assignedByCoach' => 'excluded.assignedByCoach',
|
||||
'status' => "'completed'",
|
||||
'startedAt' => 'COALESCE(excluded.startedAt, startedAt)',
|
||||
'completedAt' => 'excluded.completedAt',
|
||||
'sumPoints' => 'excluded.sumPoints',
|
||||
]
|
||||
)
|
||||
)->execute([
|
||||
':cc' => $clientCode,
|
||||
':qn' => $qnID,
|
||||
@ -863,7 +871,7 @@ function qdb_wipe_all_data_except_admins(PDO $pdo): array
|
||||
try {
|
||||
// Interview data references clients/coaches; coach references supervisor.
|
||||
// Disable FK checks for this bulk wipe (same pattern as questionnaire delete).
|
||||
$pdo->exec('PRAGMA foreign_keys = OFF');
|
||||
qdb_set_foreign_keys($pdo, false);
|
||||
|
||||
$deleted['client_answers'] = (int)$pdo->exec('DELETE FROM client_answer');
|
||||
if (qdb_table_exists($pdo, 'client_answer_submission')) {
|
||||
@ -891,14 +899,14 @@ function qdb_wipe_all_data_except_admins(PDO $pdo): array
|
||||
$users->execute();
|
||||
$deleted['users'] = $users->rowCount();
|
||||
|
||||
$pdo->exec('PRAGMA foreign_keys = ON');
|
||||
qdb_set_foreign_keys($pdo, true);
|
||||
$pdo->commit();
|
||||
} catch (Throwable $e) {
|
||||
if ($pdo->inTransaction()) {
|
||||
$pdo->rollBack();
|
||||
}
|
||||
try {
|
||||
$pdo->exec('PRAGMA foreign_keys = ON');
|
||||
qdb_set_foreign_keys($pdo, true);
|
||||
} catch (Throwable $ignored) {
|
||||
}
|
||||
throw $e;
|
||||
|
||||
Reference in New Issue
Block a user