mirror of
https://github.com/standardebooks/web.git
synced 2025-07-06 14:50:39 -04:00
38 lines
927 B
PHP
38 lines
927 B
PHP
<?
|
|
use Safe\DateTimeImmutable;
|
|
|
|
class GitCommit{
|
|
public ?int $GitCommitId = null;
|
|
public ?int $EbookId = null;
|
|
public DateTimeImmutable $Created;
|
|
public string $Message;
|
|
public string $Hash;
|
|
|
|
/**
|
|
* @throws Exceptions\InvalidGitCommitException
|
|
*/
|
|
public static function FromLog(string $unixTimestamp, string $hash, string $message): GitCommit{
|
|
$instance = new GitCommit();
|
|
try{
|
|
$instance->Created = new DateTimeImmutable('@' . $unixTimestamp);
|
|
}
|
|
catch(\Exception){
|
|
throw new Exceptions\InvalidGitCommitException('Invalid timestamp for Git commit.');
|
|
}
|
|
$instance->Message = $message;
|
|
$instance->Hash = $hash;
|
|
return $instance;
|
|
}
|
|
|
|
public function Create(): void{
|
|
Db::Query('
|
|
INSERT into GitCommits (EbookId, Created, Message, Hash)
|
|
values (?,
|
|
?,
|
|
?,
|
|
?)
|
|
', [$this->EbookId, $this->Created, $this->Message, $this->Hash]);
|
|
|
|
$this->GitCommitId = Db::GetLastInsertedId();
|
|
}
|
|
}
|