1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 20:58:30 +01:00

File Inspector now shows the old e107 version of core files

Bugfixes related to this change:

* e_file_inspector: During validation, the checksum is now calculated,
  even if the file is old.
* e_file_inspector_json: Strip the "v" from the beginning of version
  numbers in the database to make them proper PHP-standardized versions.
This commit is contained in:
Nick Liu 2020-03-27 16:00:39 -05:00
parent 09d3d2b166
commit b4f55049f8
No known key found for this signature in database
GPG Key ID: 1167C5F9C9897637
3 changed files with 32 additions and 1 deletions

View File

@ -618,6 +618,7 @@ class file_inspector {
if ($level === 0) $relativePath = '';
$rowId = str_replace(" ", "%20", $relativePath);
list($icon, $title) = $this->getGlyphForValidationCode($validationCode);
$oldVersion = $this->getOldVersionOfPath($relativePath, $validationCode);
$html .= "<div class=\"d\" title=\"$title\" style=\"margin-left: " . ($level * 8) . "px\">";
$html .= "<span onclick=\"ec('$rowId')\">";
$html .= $this->getTreeActionImageForFile($tree, $fileName, $rowId, $hide);
@ -634,6 +635,7 @@ class file_inspector {
{
$html .= '<span style="float:right">';
$html .= isset($this->fileSizes[$relativePath]) ? $this->parsesize($this->fileSizes[$relativePath]) : '';
$html .= $oldVersion ? " (v$oldVersion)" : "";
$html .= '</span>';
}
$html .= "</div>";
@ -1008,6 +1010,8 @@ class file_inspector {
$text .= htmlspecialchars($relativePath);
$text .= '</td><td class="s">';
$text .= isset($this->fileSizes[$relativePath]) ? $this->parsesize($this->fileSizes[$relativePath]) : '';
$oldVersion = $this->getOldVersionOfPath($relativePath, $validation);
$text .= $oldVersion ? " (v$oldVersion)" : "";
$text .= '</td>';
$text .= '</tr>';
}
@ -1333,6 +1337,27 @@ i.fa-folder-open-o, i.fa-times-circle-o { cursor:pointer }
echo $text;
}
/**
* Get the PHP-standard version of the hash of the relative path
*
* @todo FIXME performance: This method checksums old files a second time.
* @param string $relativePath Relative path to checksum
* @param int $validationCode e_file_inspector validation bits
* @return false|string
*/
private function getOldVersionOfPath($relativePath, $validationCode)
{
$oldVersion = false;
if (($validationCode & e_file_inspector::VALIDATED_HASH_EXISTS) &&
!($validationCode & e_file_inspector::VALIDATED_HASH_CURRENT))
{
$dbChecksums = $this->coreImage->getChecksums($relativePath);
$actualChecksum = $this->coreImage->checksumPath(e_BASE . $relativePath);
$oldVersion = array_search($actualChecksum, $dbChecksums);
}
return $oldVersion;
}
}
function fileinspector_adminmenu() //FIXME - has problems when navigation is on the LEFT instead of the right.

View File

@ -71,7 +71,7 @@ abstract class e_file_inspector implements e_file_inspector_interface
$absolutePath = realpath(e_BASE . $path);
$dbChecksums = $this->getChecksums($path);
$dbChecksum = $this->getChecksum($path, $version);
$actualChecksum = $dbChecksum ? $this->checksumPath($absolutePath) : null;
$actualChecksum = !empty($dbChecksums) ? $this->checksumPath($absolutePath) : null;
if (!empty($dbChecksums)) $bits |= self::VALIDATED_PATH_KNOWN;
if ($dbChecksum !== false) $bits |= self::VALIDATED_PATH_VERSION;

View File

@ -63,6 +63,7 @@ class e_file_inspector_json extends e_file_inspector
/**
* Flatten a multi-dimensional associative array with slashes.
* Excludes the second-to-last level of depth from flattening.
* Also removes the leading "v" from all version keys.
*
* Based on Illuminate\Support\Arr::dot()
*
@ -84,6 +85,11 @@ class e_file_inspector_json extends e_file_inspector
}
else
{
foreach ($value as $versionWithV => $checksum)
{
$value[ltrim($versionWithV, 'v')] = $checksum;
unset($value[$versionWithV]);
}
$results[$prepend . $key] = $value;
}
}