From bb1c32489c2f7fd14c88d228d312f805999e13be Mon Sep 17 00:00:00 2001 From: Nick Liu Date: Mon, 23 Mar 2020 13:37:46 -0500 Subject: [PATCH] Add a version filter to e_file_inspector::getPathIterator() --- e107_handlers/e_file_inspector_interface.php | 3 ++- e107_handlers/e_file_inspector_sqlphar.php | 21 +++++++++++++++---- .../tests/unit/e_file_inspectorTest.php | 9 ++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/e107_handlers/e_file_inspector_interface.php b/e107_handlers/e_file_inspector_interface.php index 1e370b83f..f05a95631 100644 --- a/e107_handlers/e_file_inspector_interface.php +++ b/e107_handlers/e_file_inspector_interface.php @@ -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 diff --git a/e107_handlers/e_file_inspector_sqlphar.php b/e107_handlers/e_file_inspector_sqlphar.php index b76f850c4..b48bc5e4d 100644 --- a/e107_handlers/e_file_inspector_sqlphar.php +++ b/e107_handlers/e_file_inspector_sqlphar.php @@ -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); } diff --git a/e107_tests/tests/unit/e_file_inspectorTest.php b/e107_tests/tests/unit/e_file_inspectorTest.php index 49808d0b9..c006d8f60 100644 --- a/e107_tests/tests/unit/e_file_inspectorTest.php +++ b/e107_tests/tests/unit/e_file_inspectorTest.php @@ -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");