update git, upgraded

This commit is contained in:
2026-03-03 15:26:00 +07:00
parent 3e26d1bfaf
commit d72a842a1b
2 changed files with 47 additions and 24 deletions
+1 -1
View File
@@ -584,7 +584,7 @@ var FoniaJS = {
var arrData = [], objComp = {}; var arrData = [], objComp = {};
if ('string' !== typeof aparam) arrData = this.RequestParam(aparam); if ('string' !== typeof aparam) arrData = this.RequestParam(aparam);
objComp = { objComp = {
//preventEnter: false, preventEnter: true,
resolverSettings: { resolverSettings: {
url: turl, url: turl,
extraData: arrData.reduce(function(o, val) { var t = val.split('='); o[t[0]] = t[1]; return o; }, {}) extraData: arrData.reduce(function(o, val) { var t = val.split('='); o[t[0]] = t[1]; return o; }, {})
+46 -23
View File
@@ -6,7 +6,7 @@
Desc. : v4 - Class Update Aplikasi Otomatis Desc. : v4 - Class Update Aplikasi Otomatis
Created By : Siau Pheng (siaupheng@3fonia.com). Created By : Siau Pheng (siaupheng@3fonia.com).
Created Date : June 14th, 2013. Created Date : June 14th, 2013.
Last Modified : February 13th, 2026. Last Modified : March 3rd, 2026.
(c) 2013 - 2026, 3FONIA Software; WWW.3FONIA.COM. (c) 2013 - 2026, 3FONIA Software; WWW.3FONIA.COM.
@@ -17,36 +17,60 @@ declare(strict_types=1);
namespace siaupheng\fonia3\Web; namespace siaupheng\fonia3\Web;
final class Update { final class Update {
protected $__web_app = []; protected $__conf = [];
protected $__linkdb = null; protected $is_git = false;
public function __construct($db = null){ public function __construct(){
if (is_resource($db)) { $this->__linkdb = $db; } $this->__conf = $_SESSION['__WEB_APP'];
else { $this->__linkdb = new \siaupheng\fonia3\DB\MySQL(); } $this->get_current();
$this->__web_app = $_SESSION['__WEB_APP']; }
$this->__linkdb->Query("SELECT GIT_SHA1,GIT_DATE FROM app_config WHERE REG_ID='".$this->__web_app['APP_CODE']."' LIMIT 1");
if ($this->__linkdb->Next()) $this->__web_app = array_merge($this->__web_app, $this->__linkdb->AllRow()); public function get_current() {
$_target = $this->__conf['REAL_PATH'];
if (isset($_target)) chdir($_target);
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_update() { public function check_update() {
$_ainfo['cur_version'] = $this->__web_app['APP_BUILD']; $_ainfo['cur_version'] = $this->__conf['APP_BUILD'];
$_ainfo['cur_sha'] = substr($this->__web_app['GIT_SHA1'], 0, 10); $_ainfo['cur_sha'] = substr($this->__conf['GIT_SHA1'], 0, 10);
$_ainfo['cur_sha1'] = $this->__web_app['GIT_SHA1']; $_ainfo['cur_sha1'] = $this->__conf['GIT_SHA1'];
$_ainfo['cur_date'] = $this->__web_app['GIT_DATE']; $_ainfo['cur_date'] = $this->__conf['GIT_DATE'];
$_ainfo['svr_status'] = 0; $_ainfo['svr_status'] = 0;
$_ainfo['svr_message'] = "Server Offline"; $_ainfo['svr_message'] = "Server Offline";
if (empty($this->__web_app['GIT_OWNER']) || empty($this->__web_app['GIT_REPO'])) return $_ainfo; if (!$this->is_git) return $_ainfo;
try { try {
$_url = "https://git.trifonia.cloud/api/v1/repos/".$this->__web_app['GIT_OWNER']."/".$this->__web_app['GIT_REPO']."/commits?limit=1"; $_url = "https://git.trifonia.cloud/api/v1/repos/".$this->__conf['GIT_OWNER']."/".$this->__conf['GIT_REPO']."/commits?limit=1";
$_conten = file_get_contents($_url); $_conten = file_get_contents($_url);
$ajson = json_decode($_conten, true); $ajson = json_decode($_conten, true);
if (count($ajson) > 0) { if (count($ajson) > 0) {
$_ainfo['new_sha'] = substr($ajson[0]['sha'], 0, 10); $_ainfo['new_sha'] = substr($ajson[0]['sha'], 0, 10);
$_ainfo['new_sha1'] = $ajson[0]['sha']; $_ainfo['new_sha1'] = $ajson[0]['sha'];
$_ainfo['new_date'] = date("d-m-Y H:i:s", strtotime($ajson[0]['created'])); $_ainfo['new_date'] = date("Y-m-d H:i:s O", strtotime($ajson[0]['created']));
$_ainfo['new_message'] = $ajson[0]['commit']['message']; $_ainfo['new_message'] = $ajson[0]['commit']['message'];
$_ainfo['svr_status'] = 1; $_ainfo['svr_status'] = 1;
$_ainfo['svr_message'] = "Server Online"; $_ainfo['svr_message'] = "Server Online";
@@ -56,15 +80,14 @@ final class Update {
return $_ainfo; return $_ainfo;
} }
public function go_update($new_sha1, $new_date) { public function go_update() {
$_target = $this->__web_app['REAL_PATH']; $_target = $this->__conf['REAL_PATH'];
$_branch = "main"; $_branch = $this->__conf['GIT_BRANCH'] ?? "main";
if (isset($_target)) { if (isset($_target)) {
chdir($_target); chdir($_target);
$output = shell_exec("cd {$_target} && git reset --hard HEAD && git pull origin {$_branch} 2>&1"); $output = shell_exec("git reset --hard HEAD && git pull origin {$_branch} 2>&1");
$this->__linkdb->Query("UPDATE app_config SET GIT_SHA1='".$new_sha1."',GIT_DATE='".$new_date."' WHERE REG_ID='".$this->__web_app['APP_CODE']."' LIMIT 1"); return ['success'=>true,'message'=>$output];
return ['status'=>true,'message'=>$output]; } else return ['success'=>false,'message'=>"Tanpa REAL_PATH !"];
} else return ['status'=>false,'message'=>"Tanpa REAL_PATH !"];
} }
public function update_mysql() { public function update_mysql() {