diff --git a/libraries/classes/Command/WriteGitRevisionCommand.php b/libraries/classes/Command/WriteGitRevisionCommand.php index 6dc944b5f6..d661648266 100644 --- a/libraries/classes/Command/WriteGitRevisionCommand.php +++ b/libraries/classes/Command/WriteGitRevisionCommand.php @@ -117,7 +117,7 @@ PHP; } $commitDetails = $this->gitCli( - 'show -s --pretty=\'tree %T%nparent %P%nauthor %an <%ae> %at%ncommitter %cn <%ce> %ct%n%B\'' + 'show -s --pretty=\'tree %T%nparent %P%nauthor %an <%ae> %at%ncommitter %cn <%ce> %ct%n%n%B\'' ); if ($commitDetails === null) { return null; diff --git a/libraries/classes/Footer.php b/libraries/classes/Footer.php index 075644a39f..1515592c51 100644 --- a/libraries/classes/Footer.php +++ b/libraries/classes/Footer.php @@ -11,7 +11,6 @@ use PhpMyAdmin\ConfigStorage\Relation; use Traversable; use function basename; -use function file_exists; use function in_array; use function is_array; use function is_object; @@ -71,22 +70,6 @@ class Footer $this->relation = new Relation($dbi); } - /** - * @return array - * @psalm-return array{revision: string, revisionUrl: string, branch: string, branchUrl: string}|[] - */ - private function getGitRevisionInfo(): array - { - $info = []; - - if (@file_exists(ROOT_PATH . 'revision-info.php')) { - /** @psalm-suppress MissingFile,UnresolvableInclude */ - $info = include ROOT_PATH . 'revision-info.php'; - } - - return is_array($info) ? $info : []; - } - /** * Remove recursions and iterator objects from an object * @@ -288,7 +271,8 @@ class Footer $scripts = $this->scripts->getDisplay(); if ($GLOBALS['cfg']['DBG']['demo']) { - $gitRevisionInfo = $this->getGitRevisionInfo(); + $git = new Git(true, ROOT_PATH); + $gitRevisionInfo = $git->getGitRevisionInfo(); } $footer = Config::renderFooter(); diff --git a/libraries/classes/Git.php b/libraries/classes/Git.php index 4208465c60..1dcdee92f1 100644 --- a/libraries/classes/Git.php +++ b/libraries/classes/Git.php @@ -547,6 +547,44 @@ class Git return trim($commonDirContents); } + /** + * @return array>|null + * @psalm-return array{ + * revision: string, + * revisionHash: string, + * revisionUrl: string, + * branch: string, + * branchUrl: string, + * message: string, + * author: array{ + * name: string, + * email: string, + * date: string + * }, + * committer: array{ + * name: string, + * email: string, + * date: string + * } + * }|null + */ + public function getGitRevisionInfo(): ?array + { + if (@file_exists($this->baseDir . 'revision-info.php')) { + /** @var array{ revision: string, revisionHash: string, revisionUrl: string, branch: string, branchUrl: string, message: string, author: array{ name: string, email: string, date: string }, committer: array{ name: string, email: string, date: string }}|null $info */ + /** @psalm-suppress MissingFile,UnresolvableInclude */ + $info = include $this->baseDir . 'revision-info.php'; + + if (! is_array($info)) { + return null; + } + + return $info; + } + + return null; + } + /** * detects Git revision, if running inside repo */ @@ -562,10 +600,9 @@ class Git // Special name to indicate the use of the config file if ($gitFolder === 'revision-info.php') { - /** @psalm-suppress MissingFile,UnresolvableInclude */ - $info = include $this->baseDir . 'revision-info.php'; + $info = $this->getGitRevisionInfo(); - if (! is_array($info)) { + if ($info === null) { return null; } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 462384e1fd..eda2195c65 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -17950,11 +17950,6 @@ parameters: count: 4 path: libraries/classes/Footer.php - - - message: "#^Method PhpMyAdmin\\\\Footer\\:\\:getGitRevisionInfo\\(\\) should return array\\ but returns array\\.$#" - count: 1 - path: libraries/classes/Footer.php - - message: "#^Method PhpMyAdmin\\\\Footer\\:\\:removeRecursion\\(\\) has parameter \\$stack with no value type specified in iterable type array\\.$#" count: 1 @@ -19470,21 +19465,6 @@ parameters: count: 1 path: libraries/classes/Git.php - - - message: "#^Cannot access offset 'date' on mixed\\.$#" - count: 2 - path: libraries/classes/Git.php - - - - message: "#^Cannot access offset 'email' on mixed\\.$#" - count: 2 - path: libraries/classes/Git.php - - - - message: "#^Cannot access offset 'name' on mixed\\.$#" - count: 2 - path: libraries/classes/Git.php - - message: "#^Cannot access offset 1 on array\\|false\\.$#" count: 2 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 47ff2d32a5..9e4af00b5d 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -6763,12 +6763,6 @@ $params - - is_array($info) ? $info : [] - - - array{revision: string, revisionUrl: string, branch: string, branchUrl: string}|[] - $db $table @@ -6783,8 +6777,7 @@ (string) $GLOBALS['table'] (string) $_REQUEST['no_history'] - - is_array($info) + is_scalar($GLOBALS['db']) is_scalar($GLOBALS['table']) isset($GLOBALS['db']) && is_scalar($GLOBALS['db']) @@ -6793,9 +6786,6 @@ ! isset($dbi) - - [] - @@ -7575,14 +7565,6 @@ $offset + ($position * 20) $offset + ($position * 4) - - $info['author']['date'] - $info['author']['email'] - $info['author']['name'] - $info['committer']['date'] - $info['committer']['email'] - $info['committer']['name'] - $commit $end @@ -7621,6 +7603,9 @@ $packOffsets[1] json_decode((string) $is_found) + + $info + $_SESSION['PMA_VERSION_COMMITDATA_' . $hash] diff --git a/test/classes/Command/WriteGitRevisionCommandTest.php b/test/classes/Command/WriteGitRevisionCommandTest.php index 189d1a5e9c..3c88e15857 100644 --- a/test/classes/Command/WriteGitRevisionCommandTest.php +++ b/test/classes/Command/WriteGitRevisionCommandTest.php @@ -39,7 +39,7 @@ class WriteGitRevisionCommandTest extends AbstractTestCase ['describe --always'], ['log -1 --format="%H"'], ['symbolic-ref -q HEAD'], - ['show -s --pretty=\'tree %T%nparent %P%nauthor %an <%ae> %at%ncommitter %cn <%ce> %ct%n%B\''] + ['show -s --pretty=\'tree %T%nparent %P%nauthor %an <%ae> %at%ncommitter %cn <%ce> %ct%n%n%B\''] ) ->willReturnOnConsecutiveCalls( 'RELEASE_5_1_0-638-g1c018e2a6c', diff --git a/test/classes/GitTest.php b/test/classes/GitTest.php index b6bc7e420f..7ddbdaaa42 100644 --- a/test/classes/GitTest.php +++ b/test/classes/GitTest.php @@ -483,6 +483,48 @@ PHP; self::assertIsString($commit['committer']['date']); } + /** + * Test for getGitRevisionInfo with a revision-info.php file + * + * @group git-revision + */ + public function testGetGitRevisionInfo(): void + { + self::assertNull($this->object->getGitRevisionInfo()); + + file_put_contents( + $this->testDir . 'revision-info.php', + $this->getRevisionInfoTestData() + ); + + self::assertSame([ + 'revision' => 'RELEASE_5_2_1-1086-g97b9895908', + 'revisionHash' => '97b9895908f281b62c985857798281a0b3e5d1e6', + 'revisionUrl' => + 'https://github.com/phpmyadmin/phpmyadmin/commit/97b9895908f281b62c985857798281a0b3e5d1e6', + 'branch' => 'QA_5_2', + 'branchUrl' => 'https://github.com/phpmyadmin/phpmyadmin/tree/QA_5_2', + 'message' => 'Currently translated at 61.4% (2105 of 3428 strings) ' + . ' [ci skip] Translation: phpMyAdmin/5.2' + . ' Translate-URL: https://hosted.weblate.org/projects/phpmyadmin/5-2/fi/' + . ' Signed-off-by: John Doe ', + 'author' => [ + 'name' => 'John Doe', + 'email' => 'john.doe@example.org', + 'date' => '2024-12-17 09:21:24 +0000', + ], + 'committer' => [ + 'name' => 'Hosted Weblate', + 'email' => 'hosted@weblate.org', + 'date' => '2024-12-18 10:00:32 +0000', + ], + + ], $this->object->getGitRevisionInfo()); + + // Delete the dataset + unlink($this->testDir . 'revision-info.php'); + } + /** * Test for checkGitRevision */