Fix: {{advice}} prints as-is (no Hindi/AI conversion); fix Schema Diff truncation

This commit is contained in:
DevSoftTech Server 2026-04-16 12:31:42 +05:30
parent 5ce3461a0c
commit 1084ef8875
3 changed files with 28 additions and 19 deletions

View File

@ -3253,18 +3253,9 @@ class Opd extends BaseController
$tokens['investigation'] = $formatBlock('Investigation Advised', (string) ($tokens['investigation_raw'] ?? ''));
$tokens['Prescriber_Remarks'] = $formatBlock('Remarks', (string) ($tokens['Prescriber_Remarks_raw'] ?? ''));
$adviceRaw = trim((string) ($tokens['advice_raw'] ?? ''));
$adviceLocalText = trim((string) ($tokens['advice_local'] ?? ''));
// Print advice exactly as typed — no AI/Hindi conversion applied.
if ($adviceRaw !== '') {
$advLabelHtml = '<span style="font-weight:700;font-size:13px;line-height:1.35;">सलाह (Advice) :</span>';
$adviceHtml = '<div style="margin-bottom:4px;">';
if ($adviceLocalText !== '') {
$adviceHtml .= $advLabelHtml . ' <span lang="hi">' . $adviceLocalText . '</span>';
$adviceHtml .= '<div style="font-size:10px;color:#666;margin-top:1px;">(Advice: ' . $adviceRaw . ')</div>';
} else {
$adviceHtml .= $advLabelHtml . ' ' . $adviceRaw;
}
$adviceHtml .= '</div>';
$tokens['advice'] = $adviceHtml;
$tokens['advice'] = nl2br(htmlspecialchars($adviceRaw, ENT_QUOTES, 'UTF-8'));
} else {
$tokens['advice'] = '';
}

View File

@ -180,9 +180,13 @@ class Setup extends BaseController
$maxRuntimeSeconds = 5;
}
// For analyze: run to full completion — no time or table-count truncation.
$analyzeMaxRuntime = $action === 'analyze' ? PHP_INT_MAX : $maxRuntimeSeconds;
$analyzeMaxTables = $action === 'analyze' ? 0 : -1; // 0 = unlimited override
$startedAt = microtime(true);
$syncResult = $this->buildSchemaSyncPlan($startedAt, $maxRuntimeSeconds);
$syncResult = $this->buildSchemaSyncPlan($startedAt, $analyzeMaxRuntime, $analyzeMaxTables);
if ($action === 'apply' && empty($syncResult['errors']) && !empty($syncResult['sql'])) {
$maxApplyStatements = (int) env('setup.sync.max_apply_statements_per_run', 75);
if ($maxApplyStatements <= 0) {
@ -695,7 +699,7 @@ class Setup extends BaseController
/**
* @return array<string, mixed>
*/
private function buildSchemaSyncPlan(float $startedAt, int $maxRuntimeSeconds): array
private function buildSchemaSyncPlan(float $startedAt, int $maxRuntimeSeconds, int $maxTablesOverride = -1): array
{
$errors = [];
$sql = [];
@ -724,9 +728,14 @@ class Setup extends BaseController
$masterTables = $masterSchema['tables'] ?? [];
$clientTables = array_flip($client->listTables());
$maxTables = (int) env('setup.sync.max_tables_per_run', 0);
if ($maxTables < 0) {
$maxTables = 0;
// $maxTablesOverride >= 0 takes precedence over the .env setting (0 = unlimited).
if ($maxTablesOverride >= 0) {
$maxTables = $maxTablesOverride;
} else {
$maxTables = (int) env('setup.sync.max_tables_per_run', 0);
if ($maxTables < 0) {
$maxTables = 0;
}
}
$processedTables = 0;
$truncated = false;

View File

@ -180,11 +180,20 @@
<div class="form-group">
<label>Generated SQL</label>
<textarea class="form-control" rows="14" readonly><?php
<?php
$sqlLines = $sync_result['sql'] ?? [];
$totalSqlLines = is_array($sqlLines) ? count($sqlLines) : 0;
$displayLimit = 2000;
?>
<?php if ($totalSqlLines > $displayLimit) : ?>
<div class="alert alert-warning" style="margin-bottom:4px;">
Showing first <?= $displayLimit ?> of <?= $totalSqlLines ?> statements.
Use <strong>Apply Sync to Client DB</strong> to execute all statements.
</div>
<?php endif; ?>
<textarea class="form-control" rows="14" readonly><?php
if (is_array($sqlLines)) {
$sqlLines = array_slice($sqlLines, 0, 300);
echo esc(implode("\n", $sqlLines));
echo esc(implode("\n", array_slice($sqlLines, 0, $displayLimit)));
}
?></textarea>
</div>