mirror of
https://github.com/e107inc/e107.git
synced 2025-06-09 04:28:29 +02:00
File inspector - improved detection of old files.
This commit is contained in:
parent
0ed1a9ae5f
commit
a908c9fc8e
@ -635,7 +635,7 @@ class file_inspector {
|
|||||||
|
|
||||||
private function updateFileSizeCounter($absolutePath, $validationCode)
|
private function updateFileSizeCounter($absolutePath, $validationCode)
|
||||||
{
|
{
|
||||||
$status = $this->getStatusForValidationCode($validationCode);
|
$status = e_file_inspector::getStatusForValidationCode($validationCode);
|
||||||
$category = $this->statusToLegacyCountCategory($status);
|
$category = $this->statusToLegacyCountCategory($status);
|
||||||
$fileSize = filesize($absolutePath);
|
$fileSize = filesize($absolutePath);
|
||||||
$this->count[$category]['size'] += $fileSize;
|
$this->count[$category]['size'] += $fileSize;
|
||||||
@ -774,30 +774,7 @@ class file_inspector {
|
|||||||
private function getGlyphForValidationCode($validationCodeOrArray)
|
private function getGlyphForValidationCode($validationCodeOrArray)
|
||||||
{
|
{
|
||||||
if (is_array($validationCodeOrArray)) return $this->getWorstGlyphForFolder($validationCodeOrArray);
|
if (is_array($validationCodeOrArray)) return $this->getWorstGlyphForFolder($validationCodeOrArray);
|
||||||
return $this->glyph['file_' . $this->getStatusForValidationCode($validationCodeOrArray)];
|
return $this->glyph['file_' . e_file_inspector::getStatusForValidationCode($validationCodeOrArray)];
|
||||||
}
|
|
||||||
|
|
||||||
private function getStatusForValidationCode($validationCode)
|
|
||||||
{
|
|
||||||
$status = 'unknown';
|
|
||||||
if ($validationCode & e_file_inspector::VALIDATED)
|
|
||||||
$status = 'check';
|
|
||||||
elseif (!($validationCode & e_file_inspector::VALIDATED_FILE_EXISTS))
|
|
||||||
$status = 'missing';
|
|
||||||
elseif (!($validationCode & e_file_inspector::VALIDATED_FILE_SECURITY))
|
|
||||||
$status = 'warning';
|
|
||||||
elseif (!($validationCode & e_file_inspector::VALIDATED_PATH_KNOWN))
|
|
||||||
$status = 'unknown';
|
|
||||||
elseif (!($validationCode & e_file_inspector::VALIDATED_PATH_VERSION))
|
|
||||||
$status = 'old';
|
|
||||||
elseif (!($validationCode & e_file_inspector::VALIDATED_HASH_CALCULABLE))
|
|
||||||
$status = 'uncalc';
|
|
||||||
elseif (!($validationCode & e_file_inspector::VALIDATED_HASH_CURRENT))
|
|
||||||
if ($validationCode & e_file_inspector::VALIDATED_HASH_EXISTS)
|
|
||||||
$status = 'old';
|
|
||||||
else
|
|
||||||
$status = 'fail';
|
|
||||||
return $status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getStatusRank($status)
|
private function getStatusRank($status)
|
||||||
@ -836,7 +813,7 @@ class file_inspector {
|
|||||||
$worstStatusRank = -PHP_INT_MAX;
|
$worstStatusRank = -PHP_INT_MAX;
|
||||||
array_walk_recursive($treeFolder, function ($value) use (&$worstStatus, &$worstStatusRank)
|
array_walk_recursive($treeFolder, function ($value) use (&$worstStatus, &$worstStatusRank)
|
||||||
{
|
{
|
||||||
$currentStatus = $this->getStatusForValidationCode($value);
|
$currentStatus = e_file_inspector::getStatusForValidationCode($value);
|
||||||
$currentStatusRank = $this->getStatusRank($currentStatus);
|
$currentStatusRank = $this->getStatusRank($currentStatus);
|
||||||
if ($currentStatusRank > $worstStatusRank)
|
if ($currentStatusRank > $worstStatusRank)
|
||||||
{
|
{
|
||||||
@ -856,7 +833,7 @@ class file_inspector {
|
|||||||
$validationCode & e_file_inspector::VALIDATED_PATH_VERSION)
|
$validationCode & e_file_inspector::VALIDATED_PATH_VERSION)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
$status = $this->getStatusForValidationCode($validationCode);
|
$status = e_file_inspector::getStatusForValidationCode($validationCode);
|
||||||
$return = true;
|
$return = true;
|
||||||
switch ($status)
|
switch ($status)
|
||||||
{
|
{
|
||||||
@ -956,7 +933,7 @@ class file_inspector {
|
|||||||
|
|
||||||
array_walk_recursive($this->files, function ($validationCode)
|
array_walk_recursive($this->files, function ($validationCode)
|
||||||
{
|
{
|
||||||
$status = $this->getStatusForValidationCode($validationCode);
|
$status = e_file_inspector::getStatusForValidationCode($validationCode);
|
||||||
$category = $this->statusToLegacyCountCategory($status);
|
$category = $this->statusToLegacyCountCategory($status);
|
||||||
$this->count[$category]['num']++;
|
$this->count[$category]['num']++;
|
||||||
if ($validationCode & e_file_inspector::VALIDATED_PATH_VERSION &&
|
if ($validationCode & e_file_inspector::VALIDATED_PATH_VERSION &&
|
||||||
|
@ -120,6 +120,34 @@ abstract class e_file_inspector implements e_file_inspector_interface
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert validation code to string.
|
||||||
|
* @param $validationCode
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getStatusForValidationCode($validationCode)
|
||||||
|
{
|
||||||
|
$status = 'unknown';
|
||||||
|
if ($validationCode & self::VALIDATED)
|
||||||
|
$status = 'check';
|
||||||
|
elseif (!($validationCode & self::VALIDATED_FILE_EXISTS))
|
||||||
|
$status = 'missing';
|
||||||
|
elseif (!($validationCode & self::VALIDATED_FILE_SECURITY))
|
||||||
|
$status = 'warning';
|
||||||
|
elseif (!($validationCode & self::VALIDATED_PATH_KNOWN))
|
||||||
|
$status = 'unknown';
|
||||||
|
elseif (!($validationCode & self::VALIDATED_PATH_VERSION))
|
||||||
|
$status = 'old';
|
||||||
|
elseif (!($validationCode & self::VALIDATED_HASH_CALCULABLE))
|
||||||
|
$status = 'uncalc';
|
||||||
|
elseif (!($validationCode & self::VALIDATED_HASH_CURRENT))
|
||||||
|
if ($validationCode & self::VALIDATED_HASH_EXISTS)
|
||||||
|
$status = 'old';
|
||||||
|
else
|
||||||
|
$status = 'fail';
|
||||||
|
return $status;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare the provided database for reading or writing
|
* Prepare the provided database for reading or writing
|
||||||
*
|
*
|
||||||
@ -176,7 +204,7 @@ abstract class e_file_inspector implements e_file_inspector_interface
|
|||||||
*/
|
*/
|
||||||
private function log($relativePath, $status)
|
private function log($relativePath, $status)
|
||||||
{
|
{
|
||||||
if($status !== 218 || empty($relativePath)) // deprecated-file status code - find better way to check this.
|
if(empty($relativePath) || self::getStatusForValidationCode($status) !== 'old') // deprecated-file status
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user