@@ -122,6 +122,32 @@ function settings_diff($expected, $current)
122122$ database_reference_data = aggiornamentiMergeDatabaseReferenceData ($ data , $ file_to_check_database );
123123$ data = $ database_reference_data ['data ' ];
124124$ premium_fields = $ database_reference_data ['premium_fields ' ];
125+ $ premium_foreign_keys = $ database_reference_data ['premium_foreign_keys ' ];
126+
127+ // Rimuovi i campi premium dai dati di riferimento prima del controllo
128+ // Questo garantisce che il confronto avvenga solo con i campi standard definiti nel file mysql.json della root
129+ foreach ($ premium_fields as $ table => $ fields ) {
130+ if (isset ($ data [$ table ])) {
131+ foreach ($ fields as $ field_name => $ premium_info ) {
132+ // Salta le chiavi esterne (vengono gestite separatamente)
133+ if ($ field_name === 'foreign_keys ' ) {
134+ continue ;
135+ }
136+ // Rimuovi il campo premium dai dati di riferimento
137+ unset($ data [$ table ][$ field_name ]);
138+ }
139+ }
140+ }
141+
142+ // Rimuovi le chiavi esterne premium dai dati di riferimento prima del controllo
143+ foreach ($ premium_foreign_keys as $ table => $ fks ) {
144+ if (isset ($ data [$ table ]['foreign_keys ' ])) {
145+ foreach ($ fks as $ fk_name => $ premium_info ) {
146+ // Rimuovi la chiave esterna premium dai dati di riferimento
147+ unset($ data [$ table ]['foreign_keys ' ][$ fk_name ]);
148+ }
149+ }
150+ }
125151
126152if (empty ($ data )) {
127153 echo '
@@ -150,7 +176,7 @@ function settings_diff($expected, $current)
150176}
151177
152178// Funzione helper per raggruppare gli errori per tabella
153- function groupErrorsByTable ($ results , $ results_added , $ premium_fields , $ data )
179+ function groupErrorsByTable ($ results , $ results_added , $ premium_fields , $ premium_foreign_keys , $ data )
154180{
155181 $ grouped = [];
156182
@@ -203,6 +229,11 @@ function groupErrorsByTable($results, $results_added, $premium_fields, $data)
203229 // Processa le chiavi esterne
204230 $ expected_fks = $ data [$ table ]['foreign_keys ' ] ?? [];
205231 foreach ($ foreign_keys as $ name => $ diff ) {
232+ // Salta le chiavi esterne premium
233+ if (isset ($ premium_foreign_keys [$ table ][$ name ])) {
234+ continue ;
235+ }
236+
206237 if (is_array ($ diff ) && isset ($ diff ['expected ' ])) {
207238 $ grouped [$ table ]['chiavi_esterne_mancanti ' ][$ name ] = $ diff ;
208239 } elseif (is_array ($ diff ) && isset ($ diff ['current ' ])) {
@@ -256,6 +287,11 @@ function groupErrorsByTable($results, $results_added, $premium_fields, $data)
256287 // Processa le chiavi esterne non previste
257288 $ expected_fks = $ data [$ table ]['foreign_keys ' ] ?? [];
258289 foreach ($ foreign_keys as $ name => $ diff ) {
290+ // Salta le chiavi esterne premium
291+ if (isset ($ premium_foreign_keys [$ table ][$ name ])) {
292+ continue ;
293+ }
294+
259295 if (is_array ($ diff ) && isset ($ diff ['current ' ])) {
260296 if (!IntegrityChecker::foreignKeyExistsByContent ($ diff ['current ' ], $ expected_fks )) {
261297 $ grouped [$ table ]['chiavi_esterne_non_previste ' ][$ name ] = $ diff ;
@@ -537,7 +573,7 @@ function renderUnifiedTable($errors, $table, $data, &$query_conflitti)
537573}
538574
539575// Raggruppa gli errori per tabella
540- $ grouped_errors = groupErrorsByTable ($ results , $ results_added , $ premium_fields , $ data );
576+ $ grouped_errors = groupErrorsByTable ($ results , $ results_added , $ premium_fields , $ premium_foreign_keys , $ data );
541577
542578if (!empty ($ grouped_errors )) {
543579 echo '
@@ -551,6 +587,9 @@ function renderUnifiedTable($errors, $table, $data, &$query_conflitti)
551587 </div>
552588</div> ' ;
553589
590+ // Prepara un array per tracciare quali tabelle hanno già una card
591+ $ tables_with_card = [];
592+
554593 foreach ($ grouped_errors as $ table => $ errors ) {
555594 // Calcola i conteggi
556595 $ danger_count = count ($ errors ['campi_mancanti ' ] ?? []) + count ($ errors ['chiavi_mancanti ' ] ?? []) + count ($ errors ['chiavi_esterne_mancanti ' ] ?? []);
@@ -563,12 +602,22 @@ function renderUnifiedTable($errors, $table, $data, &$query_conflitti)
563602 continue ;
564603 }
565604
605+ // Aggiungi i campi premium e le chiavi esterne premium ai conteggi
606+ $ premium_fields_count = isset ($ premium_fields [$ table ]) ? count (array_filter (array_keys ($ premium_fields [$ table ]), function ($ k ) { return $ k !== 'foreign_keys ' ; })) : 0 ;
607+ $ premium_fks_count = isset ($ premium_foreign_keys [$ table ]) ? count ($ premium_foreign_keys [$ table ]) : 0 ;
608+
609+ // Aggiorna i conteggi se ci sono elementi premium
610+ if ($ premium_fields_count > 0 || $ premium_fks_count > 0 ) {
611+ $ info_count += $ premium_fields_count + $ premium_fks_count ;
612+ $ error_count = $ danger_count + $ warning_count + $ info_count ;
613+ }
614+
566615 $ badge_html = Utils::generateBadgeHtml ($ danger_count , $ warning_count , $ info_count );
567616 $ border_color = Utils::determineBorderColor ($ danger_count , $ warning_count );
568617
569618 echo '
570619<div class="mb-3">
571- <div class="d-flex align-items-center justify-content-between p-2 module-aggiornamenti db-section-header" style="border-left-color: ' .$ border_color .';" onclick="$(this).next().slideToggle();">
620+ <div class="d-flex align-items-center justify-content-between p-2 module-aggiornamenti db-section-header" style="border-left-color: ' .$ border_color .';" onclick="$(this).next().slideToggle(); return false; ">
572621 <div>
573622 <strong> ' .$ table .'</strong>
574623 ' .$ badge_html .'
@@ -587,85 +636,66 @@ function renderUnifiedTable($errors, $table, $data, &$query_conflitti)
587636 echo renderUnifiedTable ($ errors , $ table , $ data , $ query_conflitti );
588637 }
589638
590- echo '
591- </div>
592- </div> ' ;
593- }
594-
595- // Visualizza i campi dei moduli premium raggruppati per tabella
596- $ campi_modulo_premium = [];
597- if ($ results_added ) {
598- foreach ($ results_added as $ table => $ errors ) {
599- if (!empty ($ errors )) {
600- if (array_key_exists ('current ' , $ errors ) && $ errors ['current ' ] == null ) {
601- continue ;
602- }
603-
604- foreach ($ errors as $ name => $ diff ) {
605- if (!isset ($ diff ['key ' ]) && $ name != 'foreign_keys ' ) {
606- if (isset ($ premium_fields [$ table ][$ name ])) {
607- $ premium_info = $ premium_fields [$ table ][$ name ];
608- $ campi_modulo_premium [] = [
609- 'tabella ' => $ table ,
610- 'campo ' => $ name ,
611- 'origine ' => $ premium_info ,
612- 'valore ' => $ diff ['expected ' ] ?? '' ,
613- ];
614- }
615- }
616- }
617- }
618- }
619- }
620-
621- if (!empty ($ campi_modulo_premium )) {
622- // Raggruppa per tabella
623- $ campi_premium_per_tabella = [];
624- foreach ($ campi_modulo_premium as $ campo ) {
625- if (!isset ($ campi_premium_per_tabella [$ campo ['tabella ' ]])) {
626- $ campi_premium_per_tabella [$ campo ['tabella ' ]] = [];
627- }
628- $ campi_premium_per_tabella [$ campo ['tabella ' ]][] = $ campo ;
629- }
630-
631- foreach ($ campi_premium_per_tabella as $ tabella => $ campi ) {
639+ // Aggiungi i campi premium e le chiavi esterne premium alla fine della tabella se esistono
640+ $ premium_fields_count = isset ($ premium_fields [$ table ]) ? count (array_filter (array_keys ($ premium_fields [$ table ]), function ($ k ) { return $ k !== 'foreign_keys ' ; })) : 0 ;
641+ $ premium_fks_count = isset ($ premium_foreign_keys [$ table ]) ? count ($ premium_foreign_keys [$ table ]) : 0 ;
642+
643+ if ($ premium_fields_count > 0 || $ premium_fks_count > 0 ) {
632644 echo '
633- <div class="mb-3">
634- <div class="d-flex align-items-center justify-content-between p-2 module-aggiornamenti db-section-header-dynamic" style="border-left-color: #007bff;" onclick="$(this).next().slideToggle();">
635- <div>
636- <strong> ' .$ tabella .' ( ' .tr ('Campi premium ' ).')</strong>
637- <span class="badge badge-primary ml-2"> ' .count ($ campi ).'</span>
638- </div>
639- <i class="fa fa-chevron-down"></i>
640- </div>
641- <div class="module-aggiornamenti db-section-content">
642645 <div class="table-responsive">
643- <table class="table table-hover table-striped table-sm mb-2 ">
646+ <table class="table table-hover table-striped table-sm">
644647 <thead class="thead-light">
645648 <tr>
646649 <th> ' .tr ('Campo ' ).'</th>
647650 <th> ' .tr ('Componente ' ).'</th>
648651 </tr>
649652 </thead>
650- <tbody> ' ;
651- foreach ($ campi as $ campo ) {
652- $ origine = $ campo ['origine ' ];
653- $ origine_type = is_array ($ origine ) ? ($ origine ['type ' ] ?? 'module ' ) : 'module ' ;
654- $ origine_name = is_array ($ origine ) ? ($ origine ['name ' ] ?? '' ) : $ origine ;
655- $ origine_label = ($ origine_type === 'plugin ' ) ? 'Campo plugin ' : 'Campo modulo ' ;
656- echo '
657- <tr>
658- <td class="column-name"> ' .$ campo ['campo ' ].'</td>
659- <td><span class="badge badge-primary"> ' .$ origine_label .$ origine_name .'</span></td>
660- </tr> ' ;
653+ <tbody> ' ;
654+
655+ // Aggiungi i campi premium
656+ if (isset ($ premium_fields [$ table ]) && !empty ($ premium_fields [$ table ])) {
657+ foreach ($ premium_fields [$ table ] as $ field_name => $ premium_info ) {
658+ // Salta le chiavi esterne (vengono gestite qui sotto)
659+ if ($ field_name === 'foreign_keys ' ) {
660+ continue ;
661+ }
662+ $ origine_type = is_array ($ premium_info ) ? ($ premium_info ['type ' ] ?? 'module ' ) : 'module ' ;
663+ $ origine_name = is_array ($ premium_info ) ? ($ premium_info ['name ' ] ?? '' ) : $ premium_info ;
664+ $ origine_label = ($ origine_type === 'plugin ' ) ? 'Campo plugin ' : 'Campo modulo ' ;
665+ echo '
666+ <tr>
667+ <td class="column-name"> ' .$ field_name .'</td>
668+ <td><span class="badge badge-primary"> ' .$ origine_label .$ origine_name .'</span></td>
669+ </tr> ' ;
670+ }
661671 }
672+
673+ // Aggiungi le chiavi esterne premium
674+ if (isset ($ premium_foreign_keys [$ table ]) && !empty ($ premium_foreign_keys [$ table ])) {
675+ foreach ($ premium_foreign_keys [$ table ] as $ fk_name => $ premium_info ) {
676+ $ origine_type = is_array ($ premium_info ) ? ($ premium_info ['type ' ] ?? 'module ' ) : 'module ' ;
677+ $ origine_name = is_array ($ premium_info ) ? ($ premium_info ['name ' ] ?? '' ) : $ premium_info ;
678+ $ origine_label = ($ origine_type === 'plugin ' ) ? 'Chiave esterna plugin ' : 'Chiave esterna modulo ' ;
679+ echo '
680+ <tr>
681+ <td class="column-name"> ' .$ fk_name .'</td>
682+ <td><span class="badge badge-primary"> ' .$ origine_label .$ origine_name .'</span></td>
683+ </tr> ' ;
684+ }
685+ }
686+
662687 echo '
663- </tbody>
664- </table>
665- </div>
688+ </tbody>
689+ </table>
690+ </div> ' ;
691+ }
692+
693+ echo '
666694 </div>
667695</div> ' ;
668- }
696+
697+ // Segna questa tabella come già processata
698+ $ tables_with_card [$ table ] = true ;
669699 }
670700} else {
671701 echo '
@@ -706,6 +736,88 @@ function buttonRestore(button, loadingResult) {
706736</script> ' ;
707737}
708738
739+ // Visualizza le tabelle che hanno solo elementi premium (senza altri errori)
740+ foreach ($ premium_fields as $ table => $ fields ) {
741+ // Salta se questa tabella è già stata processata
742+ if (isset ($ tables_with_card [$ table ])) {
743+ continue ;
744+ }
745+
746+ // Controlla se ci sono campi premium (escludendo le chiavi esterne)
747+ $ premium_fields_count = count (array_filter (array_keys ($ fields ), function ($ k ) { return $ k !== "foreign_keys " ; }));
748+ $ premium_fks_count = isset ($ premium_foreign_keys [$ table ]) ? count ($ premium_foreign_keys [$ table ]) : 0 ;
749+
750+ if ($ premium_fields_count == 0 && $ premium_fks_count == 0 ) {
751+ continue ;
752+ }
753+
754+ echo '
755+ <div class="mb-3">
756+ <div class="d-flex align-items-center justify-content-between p-2 module-aggiornamenti db-section-header-dynamic" style="border-left-color: #007bff;" onclick="$(this).next().slideToggle(); return false;">
757+ <div>
758+ <strong> ' .$ table .'</strong>
759+ <span class="badge badge-primary ml-2"> ' .($ premium_fields_count + $ premium_fks_count ).'</span>
760+ </div>
761+ <i class="fa fa-chevron-down"></i>
762+ </div>
763+ <div class="module-aggiornamenti db-section-content" style="display: none;"> ' ;
764+
765+ // Aggiungi i campi premium e le chiavi esterne premium in una sola tabella
766+ if ($ premium_fields_count > 0 || $ premium_fks_count > 0 ) {
767+ echo '
768+ <div class="table-responsive">
769+ <table class="table table-hover table-striped table-sm">
770+ <thead class="thead-light">
771+ <tr>
772+ <th> ' .tr ('Campo ' ).'</th>
773+ <th> ' .tr ('Componente ' ).'</th>
774+ </tr>
775+ </thead>
776+ <tbody> ' ;
777+
778+ // Aggiungi i campi premium
779+ if ($ premium_fields_count > 0 ) {
780+ foreach ($ fields as $ field_name => $ premium_info ) {
781+ // Salta le chiavi esterne (vengono gestite qui sotto)
782+ if ($ field_name === 'foreign_keys ' ) {
783+ continue ;
784+ }
785+ $ origine_type = is_array ($ premium_info ) ? ($ premium_info ['type ' ] ?? 'module ' ) : 'module ' ;
786+ $ origine_name = is_array ($ premium_info ) ? ($ premium_info ['name ' ] ?? '' ) : $ premium_info ;
787+ $ origine_label = ($ origine_type === 'plugin ' ) ? 'Campo plugin ' : 'Campo modulo ' ;
788+ echo '
789+ <tr>
790+ <td class="column-name"> ' .$ field_name .'</td>
791+ <td><span class="badge badge-primary"> ' .$ origine_label .$ origine_name .'</span></td>
792+ </tr> ' ;
793+ }
794+ }
795+
796+ // Aggiungi le chiavi esterne premium
797+ if ($ premium_fks_count > 0 && isset ($ premium_foreign_keys [$ table ])) {
798+ foreach ($ premium_foreign_keys [$ table ] as $ fk_name => $ premium_info ) {
799+ $ origine_type = is_array ($ premium_info ) ? ($ premium_info ['type ' ] ?? 'module ' ) : 'module ' ;
800+ $ origine_name = is_array ($ premium_info ) ? ($ premium_info ['name ' ] ?? '' ) : $ premium_info ;
801+ $ origine_label = ($ origine_type === 'plugin ' ) ? 'Chiave esterna plugin ' : 'Chiave esterna modulo ' ;
802+ echo '
803+ <tr>
804+ <td class="column-name"> ' .$ fk_name .'</td>
805+ <td><span class="badge badge-primary"> ' .$ origine_label .$ origine_name .'</span></td>
806+ </tr> ' ;
807+ }
808+ }
809+
810+ echo '
811+ </tbody>
812+ </table>
813+ </div> ' ;
814+ }
815+
816+ echo '
817+ </div>
818+ </div> ' ;
819+ }
820+
709821// Log dell'esecuzione del controllo database
710822OperationLog::setInfo ('id_module ' , $ id_module );
711823OperationLog::setInfo ('options ' , json_encode (['controllo_name ' => 'Controllo database ' ], JSON_UNESCAPED_UNICODE ));
0 commit comments