Skip to content

Commit 4bfad0e

Browse files
committed
feat: verifica SQL mode compatibile prima di avviare installazione
1 parent b1f7991 commit 4bfad0e

1 file changed

Lines changed: 51 additions & 4 deletions

File tree

include/init/configuration.php

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,24 @@
115115
exit;
116116
}
117117

118+
// Verifica SQL mode (ONLY_FULL_GROUP_BY deve essere disabilitato)
119+
if (!empty(post('test_sqlmode'))) {
120+
ob_end_clean();
121+
if ($dbo->isConnected()) {
122+
$result = $dbo->fetchOne('SELECT @@GLOBAL.sql_mode AS sql_mode');
123+
$sql_mode = $result['sql_mode'] ?? '';
124+
$has_only_full_group_by = stripos($sql_mode, 'ONLY_FULL_GROUP_BY') !== false;
125+
echo json_encode([
126+
'connected' => true,
127+
'ok' => !$has_only_full_group_by,
128+
'sql_mode' => $sql_mode,
129+
]);
130+
} else {
131+
echo json_encode(['connected' => false, 'ok' => false, 'sql_mode' => '']);
132+
}
133+
exit;
134+
}
135+
118136
// Creazione della configurazione
119137
if ($dbo->isConnected()) {
120138
$new_config = file_get_contents(base_dir().'/config.example.php');
@@ -350,12 +368,41 @@ function updateNavigationButtons(currentStep) {
350368
$("#install").on("click", function(){
351369
352370
if($(this).closest("form").parsley().validate()){
353-
prev_html = $("#install").html();
354-
$("#install").html("<i class=\'fa fa-spinner fa-pulse fa-fw\'></i> '.tr('Attendere').'...");
355-
$("#install").prop("disabled", true);
371+
var $installBtn = $("#install");
372+
var prev_html_install = $installBtn.html();
373+
$installBtn.html("<i class=\'fa fa-spinner fa-pulse fa-fw\'></i> '.tr('Attendere').'...");
374+
$installBtn.prop("disabled", true);
356375
$("#test").prop("disabled", true);
357376
358-
$("#config-form").submit();
377+
// Prima verifica SQL mode
378+
$(this).closest("form").ajaxSubmit({
379+
url: "'.base_path_osm().'/index.php",
380+
data: { test_sqlmode: 1 },
381+
type: "post",
382+
success: function(data) {
383+
var result;
384+
try { result = JSON.parse(data.trim()); } catch(e) { result = null; }
385+
386+
if (result && result.connected && !result.ok) {
387+
// ONLY_FULL_GROUP_BY è attivo: blocca e avvisa
388+
$installBtn.html(prev_html_install);
389+
$installBtn.prop("disabled", false);
390+
$("#test").prop("disabled", false);
391+
swal(
392+
"'.tr('Configurazione MySQL incompatibile').'",
393+
"'.addslashes(tr('La SQL mode del server MySQL contiene ONLY_FULL_GROUP_BY, incompatibile con OpenSTAManager.') . "\n\n" . tr('Aggiungi nel file my.ini nella sezione [mysqld]:') . "\n\nsql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION\n\n" . tr('Poi riavvia MySQL e riprova.')).'",
394+
"error"
395+
);
396+
} else {
397+
// SQL mode OK (o non connesso: lascia proseguire)
398+
$("#config-form").submit();
399+
}
400+
},
401+
error: function() {
402+
// In caso di errore AJAX, lascia proseguire (il server gestirà)
403+
$("#config-form").submit();
404+
}
405+
});
359406
}
360407
361408
});

0 commit comments

Comments
 (0)