Segnalazione se sul server sembrano mancare file rispetto a quanto previsto a DB

This commit is contained in:
Luca 2020-06-25 17:56:59 +02:00
parent 0e5a38aee9
commit de0b040ded
3 changed files with 55 additions and 2 deletions

View File

@ -154,6 +154,9 @@ switch (filter('op')) {
'description' => $description,
'size' => $size,
'formattedSize' => FileSystem::formatBytes($size),
'count' => (FileSystem::folderCount($dir)? : 0),
'dbSize' => (($description == "Allegati") ? $dbo->fetchOne("SELECT SUM(`size`) AS dbsize FROM zz_files")["dbsize"] : ""),
'dbCount' => (($description == "Allegati") ? $dbo->fetchOne("SELECT COUNT(`id`) AS dbcount FROM zz_files")["dbcount"] : ""),
];
}

View File

@ -11,6 +11,8 @@ echo '
echo '
<script>
function formatBytes(a,b=2){if(0===a)return"0 Bytes";const c=0>b?0:b,d=Math.floor(Math.log(a)/Math.log(1024));return parseFloat((a/Math.pow(1024,d)).toFixed(c))+" "+["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][d]}
$(document).ready(function() {
$.ajax({
url: globals.rootdir + "/actions.php",
@ -35,7 +37,30 @@ function crea_grafico(values){
values.forEach(function(element) {
$data.push(element.size);
$labels.push(element.description + " (" + element.formattedSize + ")")
//Segnalazione se sul server sembrano mancare file rispetto a quanto previsto a DB
if (element.dbSize!==""){
if (element.size<element.dbSize){
var diff = (element.dbSize-element.size);
if (diff>1000){
$("#message").append("<div class=\"label label-warning\" ><i class=\"fa fa-exclamation-triangle\" aria-hidden=\"true\"></i> "+formatBytes(diff)+" di file mancanti per allegati.</div>");
}
}
}
//Segnalazione se sul server sembrano mancare file rispetto a quanto previsto a DB
if (element.dbCount!==""){
if (element.count<element.dbCount){
var diff = (element.dbCount-element.count);
$("#message").append("<div class=\"label label-warning\" ><i class=\"fa fa-exclamation-triangle\" aria-hidden=\"true\"></i> "+diff+" di file mancanti per allegati.</div>");
}
}
$labels.push(element.description + " (" + element.formattedSize + ")" + " [" + element.count + "]" )
});
options = {
@ -83,4 +108,4 @@ function crea_grafico(values){
<div class="chart-container" style="width:25em;">
<canvas id="chart"></canvas>
</div>';
</div><div id="message" ></div>';

View File

@ -59,6 +59,31 @@ class FileSystem
return $total;
}
/**
* Restituisce il numero di file contenuti in una cartella indicata.
*
* @param string $path
*
* @return int
*/
public static function folderCount($path)
{
$total = 0;
$path = realpath($path);
if ($path !== false && $path != '' && file_exists($path)) {
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object) {
$count += 1;
}
}
return $count;
}
/**
* Individua la dimensione del file indicato.
*