Move git functions out of ApplicationBase
This commit is contained in:
parent
94ffbf0e9f
commit
5878a4c16c
7 changed files with 40 additions and 45 deletions
|
@ -6,6 +6,7 @@ date_default_timezone_set('UTC');
|
||||||
require_once __DIR__ . '/vendor/autoload.php';
|
require_once __DIR__ . '/vendor/autoload.php';
|
||||||
require_once __DIR__ . '/src/changelog.php';
|
require_once __DIR__ . '/src/changelog.php';
|
||||||
require_once __DIR__ . '/src/colour.php';
|
require_once __DIR__ . '/src/colour.php';
|
||||||
|
require_once __DIR__ . '/src/git.php';
|
||||||
require_once __DIR__ . '/src/manage.php';
|
require_once __DIR__ . '/src/manage.php';
|
||||||
require_once __DIR__ . '/src/news.php';
|
require_once __DIR__ . '/src/news.php';
|
||||||
require_once __DIR__ . '/src/perms.php';
|
require_once __DIR__ . '/src/perms.php';
|
||||||
|
|
|
@ -91,7 +91,10 @@ switch ($_GET['v'] ?? null) {
|
||||||
} else {
|
} else {
|
||||||
$postChange = $db->prepare('
|
$postChange = $db->prepare('
|
||||||
INSERT INTO `msz_changelog_changes`
|
INSERT INTO `msz_changelog_changes`
|
||||||
(`change_log`, `change_text`, `action_id`, `user_id`, `change_created`)
|
(
|
||||||
|
`change_log`, `change_text`, `action_id`,
|
||||||
|
`user_id`, `change_created`, `change_time_filter`
|
||||||
|
)
|
||||||
VALUES
|
VALUES
|
||||||
(:log, :text, :action, :user, :created)
|
(:log, :text, :action, :user, :created)
|
||||||
');
|
');
|
||||||
|
@ -143,7 +146,9 @@ switch ($_GET['v'] ?? null) {
|
||||||
|
|
||||||
if ($changeId > 0) {
|
if ($changeId > 0) {
|
||||||
$getChange = $db->prepare('
|
$getChange = $db->prepare('
|
||||||
SELECT `change_id`, `change_log`, `change_text`, `user_id`, `action_id`, `change_created`
|
SELECT
|
||||||
|
`change_id`, `change_log`, `change_text`, `user_id`,
|
||||||
|
`action_id`, `change_created`
|
||||||
FROM `msz_changelog_changes`
|
FROM `msz_changelog_changes`
|
||||||
WHERE `change_id` = :change_id
|
WHERE `change_id` = :change_id
|
||||||
');
|
');
|
||||||
|
|
|
@ -254,8 +254,8 @@ class Application extends ApplicationBase
|
||||||
$this->templatingInstance->addFilter('md', 'parse_markdown');
|
$this->templatingInstance->addFilter('md', 'parse_markdown');
|
||||||
$this->templatingInstance->addFilter('bbcode', 'parse_bbcode');
|
$this->templatingInstance->addFilter('bbcode', 'parse_bbcode');
|
||||||
|
|
||||||
$this->templatingInstance->addFunction('git_hash', [Application::class, 'gitCommitHash']);
|
$this->templatingInstance->addFunction('git_commit_hash');
|
||||||
$this->templatingInstance->addFunction('git_branch', [Application::class, 'gitBranch']);
|
$this->templatingInstance->addFunction('git_branch');
|
||||||
$this->templatingInstance->addFunction('csrf_token', 'tmp_csrf_token');
|
$this->templatingInstance->addFunction('csrf_token', 'tmp_csrf_token');
|
||||||
$this->templatingInstance->addFunction('perms_check');
|
$this->templatingInstance->addFunction('perms_check');
|
||||||
|
|
||||||
|
|
|
@ -15,12 +15,6 @@ abstract class ApplicationBase
|
||||||
*/
|
*/
|
||||||
private static $instance = null;
|
private static $instance = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* Holds all the loaded modules.
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $modules = [];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the currently active instance of ApplicationBase
|
* Gets the currently active instance of ApplicationBase
|
||||||
* @return ApplicationBase
|
* @return ApplicationBase
|
||||||
|
@ -45,33 +39,4 @@ abstract class ApplicationBase
|
||||||
|
|
||||||
self::$instance = $this;
|
self::$instance = $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets info from the current git commit.
|
|
||||||
* @param string $format Follows the format of the pretty flag on the git log command
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function gitCommitInfo(string $format): string
|
|
||||||
{
|
|
||||||
return trim(shell_exec(sprintf('git log --pretty="%s" -n1 HEAD', $format)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the hash of the current commit.
|
|
||||||
* @param bool $long Whether to fetch the long hash or the shorter one.
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function gitCommitHash(bool $long = false): string
|
|
||||||
{
|
|
||||||
return self::gitCommitInfo($long ? '%H' : '%h');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the name of the current branch.
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public static function gitBranch(): string
|
|
||||||
{
|
|
||||||
return trim(shell_exec('git rev-parse --abbrev-ref HEAD'));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
24
src/git.php
Normal file
24
src/git.php
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
define('MSZ_GIT_FORMAT_HASH_DATE_TIME', '%cd');
|
||||||
|
define('MSZ_GIT_FORMAT_HASH_SHORT', '%h');
|
||||||
|
define('MSZ_GIT_FORMAT_HASH_LONG', '%H');
|
||||||
|
|
||||||
|
function git_commit_info(string $format, string $args = ''): string
|
||||||
|
{
|
||||||
|
return trim(shell_exec(sprintf("git log --pretty=\"%s\" {$args} -n1 HEAD", $format)));
|
||||||
|
}
|
||||||
|
|
||||||
|
function git_commit_hash(bool $long = false): string
|
||||||
|
{
|
||||||
|
return git_commit_info($long ? MSZ_GIT_FORMAT_HASH_LONG : MSZ_GIT_FORMAT_HASH_SHORT);
|
||||||
|
}
|
||||||
|
|
||||||
|
function git_commit_time(): int
|
||||||
|
{
|
||||||
|
return strtotime(git_commit_info(MSZ_GIT_FORMAT_HASH_DATE_TIME));
|
||||||
|
}
|
||||||
|
|
||||||
|
function git_branch(): string
|
||||||
|
{
|
||||||
|
return trim(shell_exec('git rev-parse --abbrev-ref HEAD'));
|
||||||
|
}
|
|
@ -65,10 +65,10 @@
|
||||||
<footer class="footer">
|
<footer class="footer">
|
||||||
{{ 'https://flash.moe'|html_link('Flashwave', 'footer__link')|raw }} 2013-{{
|
{{ 'https://flash.moe'|html_link('Flashwave', 'footer__link')|raw }} 2013-{{
|
||||||
''|date('Y') }} /
|
''|date('Y') }} /
|
||||||
<span title="{{ git_hash(true) }}">
|
<span title="{{ git_commit_hash(true) }}">
|
||||||
{{ git_branch() }} # {{ git_hash() }}
|
{{ git_branch() }} # {{ git_commit_hash() }}
|
||||||
</span>
|
</span>
|
||||||
{# link('https://github.com/flashwave/misuzu/tree/' ~ git_branch(), git_branch(), 'footer__link') }} # {{ link('https://github.com/flashwave/misuzu/commit/' ~ git_hash(true), git_hash(), 'footer__link') #}
|
{# link('https://github.com/flashwave/misuzu/tree/' ~ git_branch(), git_branch(), 'footer__link') }} # {{ link('https://github.com/flashwave/misuzu/commit/' ~ git_commit_hash(true), git_commit_hash(), 'footer__link') #}
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
<script src="/js/libraries.js" charset="utf-8"></script>
|
<script src="/js/libraries.js" charset="utf-8"></script>
|
||||||
|
|
|
@ -67,10 +67,10 @@
|
||||||
<div class="footer__copyright">
|
<div class="footer__copyright">
|
||||||
{{ 'https://flash.moe'|html_link('Flashwave', 'footer__copyright__link')|raw }} 2013-{{
|
{{ 'https://flash.moe'|html_link('Flashwave', 'footer__copyright__link')|raw }} 2013-{{
|
||||||
''|date('Y') }} /
|
''|date('Y') }} /
|
||||||
<span title="{{ git_hash(true) }}">
|
<span title="{{ git_commit_hash(true) }}">
|
||||||
{{ git_branch() }} # {{ git_hash() }}
|
{{ git_branch() }} # {{ git_commit_hash() }}
|
||||||
</span>
|
</span>
|
||||||
{# link('https://github.com/flashwave/misuzu/tree/' ~ git_branch(), git_branch(), 'footer__copyright__link') }} # {{ link('https://github.com/flashwave/misuzu/commit/' ~ git_hash(true), git_hash(), 'footer__copyright__link') #}
|
{# link('https://github.com/flashwave/misuzu/tree/' ~ git_branch(), git_branch(), 'footer__copyright__link') }} # {{ link('https://github.com/flashwave/misuzu/commit/' ~ git_commit_hash(true), git_commit_hash(), 'footer__copyright__link') #}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="footer__links">
|
<div class="footer__links">
|
||||||
|
|
Loading…
Add table
Reference in a new issue