mirror of
https://github.com/e107inc/e107.git
synced 2025-07-12 10:36:20 +02:00
FileInspector progress bar
This commit is contained in:
@ -11,8 +11,28 @@
|
|||||||
*/
|
*/
|
||||||
ob_implicit_flush(true);
|
ob_implicit_flush(true);
|
||||||
|
|
||||||
|
if(!empty($_GET['action']) && $_GET['action'] === 'progress' && !empty($_GET['scan']))
|
||||||
|
{
|
||||||
|
$e_ROOT = realpath(__DIR__ . '/..');
|
||||||
|
|
||||||
|
if ((substr($e_ROOT,-1) !== '/') && (substr($e_ROOT,-1) !== '\\') )
|
||||||
|
{
|
||||||
|
$e_ROOT .= DIRECTORY_SEPARATOR; // Should function correctly on both windows and Linux now.
|
||||||
|
}
|
||||||
|
|
||||||
|
define('e_ROOT', $e_ROOT);
|
||||||
|
|
||||||
|
$content = file_get_contents(e_ROOT.'file-inspector-progress_'.filter_var($_GET['scan']));
|
||||||
|
echo trim($content);
|
||||||
|
// echo rand(70,100);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
require_once('../class2.php');
|
require_once('../class2.php');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
e107::coreLan('fileinspector', true);
|
e107::coreLan('fileinspector', true);
|
||||||
|
|
||||||
if(!getperms('Y'))
|
if(!getperms('Y'))
|
||||||
@ -137,14 +157,7 @@ class fileinspector_admin extends e_admin_dispatcher
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($_GET['action']) && $_GET['action'] === 'progress')
|
|
||||||
{
|
|
||||||
echo rand(70,100);
|
|
||||||
// XXX FIXME - progress meter.
|
|
||||||
// echo (int) e107::getSession()->get('file-inspector-progress');
|
|
||||||
// echo 100;
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!empty($_GET['action']) && $_GET['action'] === 'begin')
|
if(!empty($_GET['action']) && $_GET['action'] === 'begin')
|
||||||
{
|
{
|
||||||
@ -214,7 +227,7 @@ class fileinspector_ui extends e_admin_ui
|
|||||||
|
|
||||||
$source = e_SELF."?mode=main&action=begin&".http_build_query($_GET);
|
$source = e_SELF."?mode=main&action=begin&".http_build_query($_GET);
|
||||||
$target = '#results-container';
|
$target = '#results-container';
|
||||||
$interval = 1000;
|
$interval = 500;
|
||||||
|
|
||||||
$text = $frm->open('runit');
|
$text = $frm->open('runit');
|
||||||
$text .= $frm->progressBar('inspector-progress', 0);
|
$text .= $frm->progressBar('inspector-progress', 0);
|
||||||
@ -222,7 +235,7 @@ class fileinspector_ui extends e_admin_ui
|
|||||||
// $text .= '<button id="start-render" type="button" data-loading-icon="fa-spinner" data-loading-target="#start-render" class="e-ajax btn-sm btn btn-primary" data-src="'.$source.'" data-target="#results-container">Other</button>';
|
// $text .= '<button id="start-render" type="button" data-loading-icon="fa-spinner" data-loading-target="#start-render" class="e-ajax btn-sm btn btn-primary" data-src="'.$source.'" data-target="#results-container">Other</button>';
|
||||||
|
|
||||||
|
|
||||||
$text .= '<a id="start-render" class="btn btn-primary e-progress e-ajax " data-src="'.$source.'" data-target="'.$target.'" data-loading-icon="fa-spinner" data-progress-interval="'.$interval.'" data-progress-target="inspector-progress" data-progress="' . e_SELF.'?mode=main&action=progress" data-progress-mode="0" data-progress-show="1" data-loading-target="#fi-loading-target" ><span id="fi-loading-target"></span> Begin</a>';
|
$text .= '<a id="start-render" class="btn btn-primary e-progress e-ajax " data-src="'.$source.'" data-target="'.$target.'" data-loading-icon="fa-spinner" data-progress-interval="'.$interval.'" data-progress-target="inspector-progress" data-progress="' . e_SELF.'?mode=main&action=progress&scan='.filter_var($_GET['scan']).'" data-progress-mode="0" data-progress-show="1" data-loading-target="#fi-loading-target" ><span id="fi-loading-target"></span> Begin</a>';
|
||||||
$text .= ' <a data-progress-target="inspector-progress" class="btn btn-danger e-progress-cancel" >'.LAN_CANCEL.'</a>';
|
$text .= ' <a data-progress-target="inspector-progress" class="btn btn-danger e-progress-cancel" >'.LAN_CANCEL.'</a>';
|
||||||
|
|
||||||
|
|
||||||
@ -271,6 +284,7 @@ class file_inspector {
|
|||||||
var $results = 0;
|
var $results = 0;
|
||||||
private $totalFiles = 0;
|
private $totalFiles = 0;
|
||||||
private $progress_units = 0;
|
private $progress_units = 0;
|
||||||
|
private $progressPercentage = 0;
|
||||||
private $langs = array();
|
private $langs = array();
|
||||||
private $lang_short = array();
|
private $lang_short = array();
|
||||||
private $iconTag = array();
|
private $iconTag = array();
|
||||||
@ -285,7 +299,8 @@ class file_inspector {
|
|||||||
'regex' => 0,
|
'regex' => 0,
|
||||||
'mod' => '',
|
'mod' => '',
|
||||||
'num' => 0,
|
'num' => 0,
|
||||||
'line' => 0
|
'line' => 0,
|
||||||
|
'scan' => null // progress identifier
|
||||||
);
|
);
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
@ -308,7 +323,7 @@ class file_inspector {
|
|||||||
$lng = e107::getLanguage();
|
$lng = e107::getLanguage();
|
||||||
$langs = $lng->installed();
|
$langs = $lng->installed();
|
||||||
|
|
||||||
|
$this->sendProgress(200);
|
||||||
|
|
||||||
// if(isset($_GET['begin']))
|
// if(isset($_GET['begin']))
|
||||||
{
|
{
|
||||||
@ -569,10 +584,9 @@ class file_inspector {
|
|||||||
|
|
||||||
$foot = "
|
$foot = "
|
||||||
<div class='buttons-bar center'>
|
<div class='buttons-bar center'>
|
||||||
".$frm->admin_button('scan', LAN_GO, 'other').
|
".$frm->admin_button('scan', md5(time()), 'other', LAN_GO).
|
||||||
$frm->hidden('mode','main').
|
$frm->hidden('mode','main').
|
||||||
$frm->hidden('action','run')."
|
$frm->hidden('action','run')."
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>";
|
</div>";
|
||||||
@ -590,7 +604,9 @@ class file_inspector {
|
|||||||
protected function inspect($baseDir)
|
protected function inspect($baseDir)
|
||||||
{
|
{
|
||||||
$this->inspect_existing($baseDir);
|
$this->inspect_existing($baseDir);
|
||||||
|
$this->sendProgress(100);
|
||||||
$this->inspect_missing(array_keys($this->files));
|
$this->inspect_missing(array_keys($this->files));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function inspect_existing($baseDir)
|
private function inspect_existing($baseDir)
|
||||||
@ -600,11 +616,15 @@ class file_inspector {
|
|||||||
|
|
||||||
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($baseDir));
|
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($baseDir));
|
||||||
$index = 0;
|
$index = 0;
|
||||||
|
|
||||||
|
$this->sendProgress(50);
|
||||||
|
|
||||||
foreach ($iterator as $file)
|
foreach ($iterator as $file)
|
||||||
{
|
{
|
||||||
$this->sendProgress($index++, $this->totalFiles);
|
|
||||||
if ($file->isDir()) continue;
|
if ($file->isDir()) continue;
|
||||||
|
|
||||||
|
|
||||||
$absolutePath = $file->getRealPath();
|
$absolutePath = $file->getRealPath();
|
||||||
$relativePath = preg_replace("/^" . preg_quote($absoluteBase . "/", "/") . "/", "", $absolutePath);
|
$relativePath = preg_replace("/^" . preg_quote($absoluteBase . "/", "/") . "/", "", $absolutePath);
|
||||||
|
|
||||||
@ -614,10 +634,13 @@ class file_inspector {
|
|||||||
$this->fileSizes[$relativePath] = filesize($absolutePath);
|
$this->fileSizes[$relativePath] = filesize($absolutePath);
|
||||||
$this->updateFileSizeCounter($absolutePath, $this->files[$relativePath]);
|
$this->updateFileSizeCounter($absolutePath, $this->files[$relativePath]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->sendProgress(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function inspect_missing($existingPaths)
|
private function inspect_missing($existingPaths)
|
||||||
{
|
{
|
||||||
|
$this->sendProgress(50);
|
||||||
$dbIterator = $this->coreImage->getPathIterator($this->coreImageVersion);
|
$dbIterator = $this->coreImage->getPathIterator($this->coreImageVersion);
|
||||||
$dbPaths = iterator_to_array($dbIterator);
|
$dbPaths = iterator_to_array($dbIterator);
|
||||||
$dbPaths = array_map(function ($defaultPath)
|
$dbPaths = array_map(function ($defaultPath)
|
||||||
@ -627,8 +650,10 @@ class file_inspector {
|
|||||||
$missingPaths = array_diff($dbPaths, $existingPaths);
|
$missingPaths = array_diff($dbPaths, $existingPaths);
|
||||||
foreach ($missingPaths as $relativePath)
|
foreach ($missingPaths as $relativePath)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->files[$relativePath] = $this->coreImage->validate($relativePath);
|
$this->files[$relativePath] = $this->coreImage->validate($relativePath);
|
||||||
}
|
}
|
||||||
|
$this->sendProgress(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function updateFileSizeCounter($absolutePath, $validationCode)
|
private function updateFileSizeCounter($absolutePath, $validationCode)
|
||||||
@ -636,8 +661,10 @@ class file_inspector {
|
|||||||
$status = $this->getStatusForValidationCode($validationCode);
|
$status = $this->getStatusForValidationCode($validationCode);
|
||||||
$category = $this->statusToLegacyCountCategory($status);
|
$category = $this->statusToLegacyCountCategory($status);
|
||||||
$fileSize = filesize($absolutePath);
|
$fileSize = filesize($absolutePath);
|
||||||
|
// $this->sendProgress();
|
||||||
$this->count[$category]['size'] += $fileSize;
|
$this->count[$category]['size'] += $fileSize;
|
||||||
|
|
||||||
|
|
||||||
if ($validationCode & e_file_inspector::VALIDATED_PATH_VERSION &&
|
if ($validationCode & e_file_inspector::VALIDATED_PATH_VERSION &&
|
||||||
$validationCode & e_file_inspector::VALIDATED_FILE_EXISTS)
|
$validationCode & e_file_inspector::VALIDATED_FILE_EXISTS)
|
||||||
$this->count['core']['size'] += $fileSize;
|
$this->count['core']['size'] += $fileSize;
|
||||||
@ -669,6 +696,7 @@ class file_inspector {
|
|||||||
$nestedFiles = [];
|
$nestedFiles = [];
|
||||||
foreach ($this->files as $relativePath => $validation)
|
foreach ($this->files as $relativePath => $validation)
|
||||||
{
|
{
|
||||||
|
$this->sendProgress(0.4);
|
||||||
if ($this->displayAllowed($validation))
|
if ($this->displayAllowed($validation))
|
||||||
self::array_set($nestedFiles, $relativePath, $validation);
|
self::array_set($nestedFiles, $relativePath, $validation);
|
||||||
}
|
}
|
||||||
@ -957,13 +985,16 @@ class file_inspector {
|
|||||||
$status = $this->getStatusForValidationCode($validationCode);
|
$status = $this->getStatusForValidationCode($validationCode);
|
||||||
$category = $this->statusToLegacyCountCategory($status);
|
$category = $this->statusToLegacyCountCategory($status);
|
||||||
$this->count[$category]['num']++;
|
$this->count[$category]['num']++;
|
||||||
|
$this->totalFiles++;
|
||||||
|
$this->sendProgress(0.4);
|
||||||
if ($validationCode & e_file_inspector::VALIDATED_PATH_VERSION &&
|
if ($validationCode & e_file_inspector::VALIDATED_PATH_VERSION &&
|
||||||
$validationCode & e_file_inspector::VALIDATED_FILE_EXISTS)
|
$validationCode & e_file_inspector::VALIDATED_FILE_EXISTS)
|
||||||
$this->count['core']['num']++;
|
$this->count['core']['num']++;
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->sendProgress($this->totalFiles, $this->totalFiles);
|
//
|
||||||
|
|
||||||
echo "<div style='display:block;height:30px'> </div>";
|
echo "<div style='display:block;height:30px'> </div>";
|
||||||
|
|
||||||
@ -1098,7 +1129,7 @@ class file_inspector {
|
|||||||
foreach ($this->files as $relativePath => $validation)
|
foreach ($this->files as $relativePath => $validation)
|
||||||
{
|
{
|
||||||
if (!$this->displayAllowed($validation)) continue;
|
if (!$this->displayAllowed($validation)) continue;
|
||||||
$this->sendProgress(50, $this->totalFiles);
|
$this->sendProgress(0.8);
|
||||||
list($icon, $title) = $this->getGlyphForValidationCode($validation);
|
list($icon, $title) = $this->getGlyphForValidationCode($validation);
|
||||||
$text .= '<tr><td class="text-left f" title="'.$title.'">';
|
$text .= '<tr><td class="text-left f" title="'.$title.'">';
|
||||||
$text .= "$icon ";
|
$text .= "$icon ";
|
||||||
@ -1122,9 +1153,11 @@ class file_inspector {
|
|||||||
$text .= "</table>
|
$text .= "</table>
|
||||||
</div><br />";
|
</div><br />";
|
||||||
|
|
||||||
echo e107::getMessage()->render();
|
// echo e107::getMessage()->render();
|
||||||
echo $text;
|
|
||||||
|
|
||||||
|
// $this->sendProgress($this->totalFiles, $this->totalFiles);
|
||||||
|
$this->sendProgress($this->totalFiles);
|
||||||
|
echo $text;
|
||||||
|
|
||||||
//$ns->tablerender(FR_LAN_1.'...', $text);
|
//$ns->tablerender(FR_LAN_1.'...', $text);
|
||||||
|
|
||||||
@ -1163,23 +1196,23 @@ class file_inspector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function sendProgress($rand,$total)
|
function sendProgress($increment=1)
|
||||||
{
|
{
|
||||||
if($this->progress_units <40 && ($rand != $total))
|
if(empty($this->options['scan']))
|
||||||
{
|
{
|
||||||
$this->progress_units++;
|
return null;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
else
|
$this->progress_units = $this->progress_units + $increment;
|
||||||
{
|
|
||||||
$this->progress_units = 0;
|
$rand = (int) $this->progress_units;
|
||||||
}
|
$total = (int) $this->totalFiles;
|
||||||
|
|
||||||
$inc = round(($rand / $total) * 100);
|
$inc = round(($rand / $total) * 100);
|
||||||
|
|
||||||
if($inc == 0)
|
if($inc == 0)
|
||||||
{
|
{
|
||||||
return;
|
// return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1188,8 +1221,21 @@ class file_inspector {
|
|||||||
$inc = 100;
|
$inc = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
e107::getSession()->set('file-inspector-progress',$inc);
|
if (($inc > 5) && $inc % 5 !== 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( $this->progressPercentage === $inc)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->progressPercentage = $inc;
|
||||||
|
|
||||||
|
// file_put_contents(e_ROOT.'file-inspector-total_'.$this->options['scan'],$total."\n",FILE_APPEND);
|
||||||
|
file_put_contents(e_ROOT.'file-inspector-progress_'.$this->options['scan'],$inc);
|
||||||
|
// file_put_contents(e_ROOT.'file-inspector-files_'.$this->options['scan'],$rand."\n",FILE_APPEND);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
@ -502,7 +502,7 @@ $(document).ready(function()
|
|||||||
clearInterval(progresspump);
|
clearInterval(progresspump);
|
||||||
$("#"+target).closest('.progress').removeClass("active");
|
$("#"+target).closest('.progress').removeClass("active");
|
||||||
|
|
||||||
$("#"+target).html("Done");
|
|
||||||
|
|
||||||
if(hide !== 'undefined')
|
if(hide !== 'undefined')
|
||||||
{
|
{
|
||||||
@ -514,6 +514,7 @@ $(document).ready(function()
|
|||||||
$('#'+show).show('slow');
|
$('#'+show).show('slow');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$("#"+target).html("Done");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user