🐛 Add guard for getVersion fallback

This protects against the current commit being packed and not available
 as an object and against zlib not being available.

More information about commits being packed and thus not available can
be found here: https://git-scm.com/book/en/v2/Git-Internals-Packfiles
This commit is contained in:
Michael Große 2018-09-09 16:12:58 +02:00
parent be2e462d83
commit 56f47fdaf7
No known key found for this signature in database
GPG Key ID: BDD834E001B99EDC
1 changed files with 9 additions and 7 deletions

View File

@ -87,13 +87,15 @@ function getVersionData(){
$subDir = substr($headCommit, 0, 2);
$fileName = substr($headCommit, 2);
$gitCommitObject = DOKU_INC . ".git/objects/$subDir/$fileName";
$commit = zlib_decode(file_get_contents($gitCommitObject));
$committerLine = explode("\n", $commit)[3];
$committerData = explode(' ', $committerLine);
end($committerData);
$ts = prev($committerData);
if ($ts && $date = date('Y-m-d', $ts)) {
$version['date'] = $date;
if (file_exists($gitCommitObject) && method_exists(zlib_decode)) {
$commit = zlib_decode(file_get_contents($gitCommitObject));
$committerLine = explode("\n", $commit)[3];
$committerData = explode(' ', $committerLine);
end($committerData);
$ts = prev($committerData);
if ($ts && $date = date('Y-m-d', $ts)) {
$version['date'] = $date;
}
}
}
}else{