1
0
mirror of https://github.com/e107inc/e107.git synced 2025-03-14 01:19:44 +01:00

Add a version filter to e_file_inspector::getPathIterator()

This commit is contained in:
Nick Liu 2020-03-23 13:37:46 -05:00
parent 0494000356
commit bb1c32489c
No known key found for this signature in database
GPG Key ID: 1167C5F9C9897637
3 changed files with 28 additions and 5 deletions

View File

@ -48,9 +48,10 @@ interface e_file_inspector_interface
/**
* Return an Iterator that can enumerate every path in the image database
*
* @param $version string|null Provide a PHP-standardized version to limit the paths to that version
* @return Iterator
*/
public function getPathIterator();
public function getPathIterator($version = null);
/**
* Get all the known file integrity hashes for the provided path

View File

@ -31,11 +31,24 @@ class e_file_inspector_sqlphar extends e_file_inspector
/**
* @inheritDoc
*/
public function getPathIterator()
public function getPathIterator($version = null)
{
$statement = $this->coreImage->query(
"SELECT path FROM file_hashes ORDER BY path ASC;"
);
$addVersionWhere = "";
$inputParameters = [];
if (!empty($version))
{
$addVersionWhere = "WHERE versions.version_string = ?";
$inputParameters[] = $version;
}
$statement = $this->coreImage->prepare("
SELECT path
FROM file_hashes
LEFT JOIN versions ON versions.version_id = file_hashes.release_version
$addVersionWhere
ORDER BY path ASC;
");
$statement->setFetchMode(PDO::FETCH_COLUMN, 0);
$statement->execute($inputParameters);
return new IteratorIterator($statement);
}

View File

@ -39,6 +39,15 @@ class e_file_inspectorTest extends \Codeception\Test\Unit
$this->assertNotEmpty($actualVersion);
}
public function testGetPathIterator()
{
$iterator = $this->e_integrity->getPathIterator();
$this->assertGreaterThanOrEqual(1, iterator_count($iterator));
$iterator = $this->e_integrity->getPathIterator("0.0.1-fakeNonExistentVersion");
$this->assertEquals(0, iterator_count($iterator));
}
public function testValidate()
{
$result = $this->e_integrity->validate("index.php");