1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-04 05:37:32 +02: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
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 * 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 * @return Iterator
*/ */
public function getPathIterator(); public function getPathIterator($version = null);
/** /**
* Get all the known file integrity hashes for the provided path * 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 * @inheritDoc
*/ */
public function getPathIterator() public function getPathIterator($version = null)
{ {
$statement = $this->coreImage->query( $addVersionWhere = "";
"SELECT path FROM file_hashes ORDER BY path ASC;" $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); return new IteratorIterator($statement);
} }

View File

@@ -39,6 +39,15 @@ class e_file_inspectorTest extends \Codeception\Test\Unit
$this->assertNotEmpty($actualVersion); $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() public function testValidate()
{ {
$result = $this->e_integrity->validate("index.php"); $result = $this->e_integrity->validate("index.php");