Skip to content

Commit 5b42fd2

Browse files
committed
feat: generazione views.json
1 parent a9d95fb commit 5b42fd2

6 files changed

Lines changed: 64 additions & 1 deletion

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ mysql.json
9595
mysql_8_3.json
9696
mariadb_10_x.json
9797
settings.json
98+
views.json
9899

99100
/tests/_log/*
100101
/tests/_temp/*

docker/Dockerfile.dev

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ RUN touch /var/www/html/manifest.json \
5151
/var/www/html/mysql_8_3.json \
5252
/var/www/html/mysql.json \
5353
/var/www/html/checksum.json \
54-
/var/www/html/settings.json
54+
/var/www/html/settings.json \
55+
/var/www/html/views.json
5556

5657
RUN curl -sS https://getcomposer.org/installer | php
5758
RUN git config --global --add safe.directory /var/www/html

gulpfile.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ export function release(done) {
541541
'!mysql_8_3.json',
542542
'!mariadb_10_x.json',
543543
'!settings.json',
544+
'!views.json',
544545
'!manifest.json',
545546
'!.idea/**',
546547
'!.git/**',
@@ -616,6 +617,14 @@ export function release(done) {
616617
bufferStream.push(null);
617618
archive.append(bufferStream, { name: 'settings.json' });
618619

620+
// Aggiunta del file per il controllo delle viste
621+
bufferStream = new Readable();
622+
bufferStream.push(shell.exec('php update/views.php', {
623+
silent: true
624+
}).stdout);
625+
bufferStream.push(null);
626+
archive.append(bufferStream, { name: 'views.json' });
627+
619628
// Aggiunta del commit corrente nel file REVISION
620629
bufferStream = new Readable();
621630
bufferStream.push(shell.exec('git rev-parse --short HEAD', {

include/init/requirements.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@
344344
'mysql.json' => tr('Necessario per il controllo integrità con database MySQL 8.0.x'),
345345
'checksum.json' => tr('Necessario per il controllo integrità dei files del gestionale'),
346346
'settings.json' => tr('Necessario per il controllo delle impostazioni del gestionale'),
347+
'views.json' => tr('Necessario per il controllo delle viste del database'),
347348
];
348349

349350
$files = [];

src/Update.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,46 @@ public static function getSettings()
445445
return $settings;
446446
}
447447

448+
public static function getViews()
449+
{
450+
$views_all = database()->fetchArray('SELECT zv.`name`, zv.`id_module`, zv.`query`, zm.`name` as module_name FROM `zz_views` zv LEFT JOIN `zz_modules` zm ON zv.`id_module` = zm.`id`');
451+
452+
foreach ($views_all as $view) {
453+
$module_key = $view['module_name'] ?: 'module_' . $view['id_module'];
454+
455+
// Normalizza la query rimuovendo i tag <br> per il confronto standard
456+
$normalized_query = self::normalizeViewQuery($view['query']);
457+
458+
$views[$module_key][$view['name']] = $normalized_query;
459+
}
460+
461+
return $views;
462+
}
463+
464+
/**
465+
* Normalizza una query di vista rimuovendo elementi che non dovrebbero essere considerati come differenze
466+
*
467+
* @param string $query
468+
* @return string
469+
*/
470+
private static function normalizeViewQuery($query)
471+
{
472+
// Rimuovi tutti i tag BR (tutte le varianti)
473+
$query = preg_replace('/<br\s*\/?>/i', '', $query);
474+
475+
// Normalizza spazi multipli
476+
$query = preg_replace('/\s+/', ' ', $query);
477+
478+
// Normalizza virgolette
479+
$query = str_replace(['"', "'", '`'], "'", $query);
480+
481+
// Normalizza entità HTML comuni
482+
$query = html_entity_decode($query, ENT_QUOTES | ENT_HTML5, 'UTF-8');
483+
484+
return trim($query);
485+
}
486+
487+
448488
/**
449489
* Controlla la presenza di aggiornamenti e prepara il database per la procedura.
450490
*/

update/views.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
error_reporting(0);
4+
5+
$skip_permissions = true;
6+
include_once __DIR__.'/../core.php';
7+
8+
$info = Update::getViews();
9+
$response = json_encode($info);
10+
11+
echo $response;

0 commit comments

Comments
 (0)