adding user class
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
Module : /App/Update.php
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : June 14th, 2013.
|
||||
Last Modified : August 22nd, 2026.
|
||||
|
||||
(c) 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Webapp\App;
|
||||
|
||||
use \flight\Engine;
|
||||
|
||||
/**
|
||||
* Class Update
|
||||
*
|
||||
* Update Otomatis Aplikasi berbasis GIT.
|
||||
*
|
||||
* @license MIT, https://www.3fonia.com
|
||||
* @copyright Copyright (c) 2008-2026, Siau Pheng <[email protected]>
|
||||
*
|
||||
* @package Webapp\App
|
||||
*/
|
||||
|
||||
final class Update {
|
||||
private Array $__conf = [];
|
||||
private Bool $is_git = false;
|
||||
protected Engine $app;
|
||||
|
||||
/**
|
||||
* @param Engine $app
|
||||
*/
|
||||
public function __construct(Engine $app){
|
||||
$this->app = $app;
|
||||
$this->__conf = $app->session()->get('WEB_APP');
|
||||
$this->current();
|
||||
}
|
||||
|
||||
public function current(): void {
|
||||
if (defined('PROJECT_ROOT')) chdir(PROJECT_ROOT);
|
||||
try {
|
||||
$output = shell_exec("git log -1 --pretty=format:\"%H||%s||%ci\" --abbrev-commit 2>&1");
|
||||
if ($output) {
|
||||
$_ainfo = explode("||", $output);
|
||||
$this->__conf['GIT_SHA1'] = $_ainfo[0] ?? '';
|
||||
$this->__conf['GIT_DATE'] = $_ainfo[2] ?? '';
|
||||
$this->is_git = true;
|
||||
}
|
||||
$output = shell_exec("git config --get remote.origin.url 2>&1");
|
||||
if ($output) {
|
||||
$output = str_replace(["http://","https://",".git"], "", $output);
|
||||
$_ainfo = explode("/", trim($output));
|
||||
$this->__conf['GIT_OWNER'] = $_ainfo[1] ?? '';
|
||||
$this->__conf['GIT_REPO'] = $_ainfo[2] ?? '';
|
||||
}
|
||||
$output = shell_exec("git branch --show-current 2>&1");
|
||||
if ($output) {
|
||||
$this->__conf['GIT_BRANCH'] = $output;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
}
|
||||
|
||||
public function check(): array {
|
||||
$_ainfo['cur_version'] = $this->__conf['APP_BUILD'];
|
||||
$_ainfo['cur_sha'] = substr($this->__conf['GIT_SHA1'], 0, 10);
|
||||
$_ainfo['cur_sha1'] = $this->__conf['GIT_SHA1'];
|
||||
$_ainfo['cur_date'] = $this->__conf['GIT_DATE'];
|
||||
$_ainfo['svr_status'] = 0;
|
||||
$_ainfo['svr_message'] = "Server Offline";
|
||||
$_ainfo['new_sha'] = 'check git config';
|
||||
$_ainfo['new_sha1'] = $this->__conf['GIT_SHA1'];
|
||||
$_ainfo['new_date'] = '';
|
||||
$_ainfo['new_message'] = 'check git config';
|
||||
|
||||
if (!$this->is_git || empty($this->__conf['GIT_OWNER']) || empty($this->__conf['GIT_REPO'])) return $_ainfo;
|
||||
|
||||
try {
|
||||
$_url = "https://git.trifonia.cloud/api/v1/repos/".$this->__conf['GIT_OWNER']."/".$this->__conf['GIT_REPO']."/commits?limit=1";
|
||||
$_conten = file_get_contents($_url);
|
||||
$ajson = json_decode($_conten, true);
|
||||
|
||||
if (count($ajson) > 0) {
|
||||
$_ainfo['new_sha'] = substr($ajson[0]['sha'], 0, 10);
|
||||
$_ainfo['new_sha1'] = $ajson[0]['sha'];
|
||||
$_ainfo['new_date'] = date("Y-m-d H:i:s O", strtotime($ajson[0]['created']));
|
||||
$_ainfo['new_message'] = $ajson[0]['commit']['message'];
|
||||
$_ainfo['svr_status'] = 1;
|
||||
$_ainfo['svr_message'] = "Server Online";
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
return $_ainfo;
|
||||
}
|
||||
|
||||
public function go(): array {
|
||||
$_branch = $this->__conf['GIT_BRANCH'] ?? "main";
|
||||
if (defined('PROJECT_ROOT')) {
|
||||
chdir(PROJECT_ROOT);
|
||||
$output = shell_exec("git reset --hard HEAD && git pull origin {$_branch} 2>&1");
|
||||
return ['success'=>true,'message'=>$output];
|
||||
} else return ['success'=>false,'message'=>"Tanpa PROJECT_ROOT !"];
|
||||
}
|
||||
|
||||
public function mysql() {
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user