Initial import

This commit is contained in:
sas.fajri
2026-05-25 20:01:37 +07:00
commit 710d7c1b97
10371 changed files with 2381698 additions and 0 deletions

View File

@@ -0,0 +1,226 @@
<?php
class Category_packet_upload extends MY_Controller
{
var $url;
function __construct()
{
parent::__construct();
$this->url= "https://devregonline.pramita.co.id/one-api/tools/regonline/r_category_packet";
//$this->url_prod= "https://mobile.pramita.co.id/one-api/tools/regonline/r_category_packet";
}
function step_debug($rows)
{
print_r($rows);
exit();
}
function get_rows($sql, $prm = false)
{
if ($prm) {
$qry = $this->db->query($sql, $prm);
} else {
$qry = $this->db->query($sql);
}
if (!$qry) {
$msg = "Error Query : {$this->db->error()["message"]} | {$this->db->last_query()}\n";
return array("status"=>-1, "message" => $msg);
}
$rows = $qry->result_array();
return array("status" => 0, "data" => $rows);
}
function get_one_row($sql, $prm =false)
{
$resp = $this->get_rows($sql, $prm);
if ($resp["status"] == -1 ) return $resp;
if (count($resp["data"]) == 0) {
return array("status"=> 0, "message" => "No record.");
}
return array("status" => 1, "data" => $resp["data"][0]);
}
function get_max($table) {
$field = strtoupper($table);
$sql = "select max({$field}LastUpdated) LastUpdated, max({$field}Created) Created
from $table";
$resp = $this->get_one_row($sql);
if ($resp["status"] == -1) {
$this->log("Err get max $table |" . $resp["message"]);
exit;
}
if ($resp["status"] == 0) return "1971-01-01 00:00:01";
$max = $resp["data"]["LastUpdated"] > $resp["data"]["Created"] ? $resp["data"]["Created"] : $resp["data"]["LastUpdated"];
return $max;
}
function index() {
$regionalID = $this->get_regional();
$date = $this->get_heartbeat();
$max = $this->get_max("m_packetcategory");
$max2 = $this->get_max("m_packetcategorydetail");
$max = $max > $max2 ? $max : $max2;
$max2 = $this->get_max("m_packetcategorymou");
$max = $max > $max2 ? $max : $max2;
if ($max == "") $max = "1971-01-01 00:00:01";
if ($max < $date) {
$this->log("No Packet Category updated or created neeed to be uploaded");
exit;
}
$result = [];
$sql = "select m_packetcategory.*, $regionalID as M_PacketCategoryS_RegionalID
from m_packetcategory";
$resp = $this->get_rows($sql);
if ($resp["status"] == -1) {
$this->log("Err get m_packetcategory |" . $resp["message"]);
exit;
}
$result["m_packetcategory"] = $resp["data"];
$sql = "select m_packetcategorydetail.*, $regionalID as M_PacketCategoryDetailS_RegionalID
from m_packetcategorydetail";
$resp = $this->get_rows($sql);
if ($resp["status"] == -1) {
$this->log("Err get m_packetcategorydetail |" . $resp["message"]);
exit;
}
$result["m_packetcategorydetail"] = $resp["data"];
$sql = "select m_packetcategorymou.*, $regionalID as M_PacketCategoryMouS_RegionalID
from m_packetcategorymou";
$resp = $this->get_rows($sql);
if ($resp["status"] == -1) {
$this->log("Err get m_packetcategorymou |" . $resp["message"]);
exit;
}
$result["m_packetcategorymou"] = $resp["data"];
$counter_data =0;
$all_name = "";
$rows = $result["m_packetcategory"];
$data = [];
foreach($rows as $r) {
$order = $r["M_PacketCategoryOrder"];
$id = $r["M_PacketCategoryID"];
$name = sprintf("%02d",$order) . "-" . sprintf("%03d",$id) . "-" . $r["M_PacketCategoryImageUrl"];
$real_name = "/home/regional/project/regional/one-media/one-regonline/" . $r["M_PacketCategoryImageUrl"];
if(! file_exists($real_name)) {
$this->log("File $real_name not exists");
} else {
$all_name .= $name;
$data[] = array(
"name" => $name,
"regionalID" => $regionalID,
"categoryID" => $id,
"content" => base64_encode(file_get_contents($real_name))
);
$counter_data++;
}
}
$msg = "Uploaded {$counter_data} image.";
$j_data = json_encode(array(
"data" => $data,
"result" => $result,
"md5" => md5($all_name . $regionalID . "545123")
));
$j_resp = $this->post($this->url, $j_data);
echo "JRESP : $j_resp\n";
$resp = json_decode($j_resp,true);
$json_error = json_last_error_msg();
if (json_last_error() != 0) {
$msg .= " [JSON ERR] $json_error " ;
}
if($resp["status"] == "OK") {
$msg .= " [Success] ";
$this->update_heartbeat("OK","");
} else {
$msg .= " [ERR] " ;
if($resp["message"] != "") $msg .= " " . $resp["message"];
$this->update_heartbeat("ERR",$msg);
}
$this->log($msg);
}
function log($msg) {
$date = date("Y-m-d H:i:s");
echo "$date $msg\n";
}
function get_regional() {
$sql = "select S_RegionalID from s_regional where S_RegionalIsActive= 'Y' and S_RegionalIsDefault= 'Y'";
$resp = $this->get_one_row($sql);
if ($resp["status"] == -1) {
$this->log("Error get reginalID | " . $resp["message"]);
}
if ($resp["status"] == 0) {
$this->log("Error default regional not set.");
}
return $resp["data"]["S_RegionalID"];
}
function get_heartbeat() {
$sql="select * from regonline.heartbeat where heartbeatCode='PACKET_CATEGORY'";
$qry = $this->db->query($sql);
if (!$qry) {
echo date("Y-m-d H:i:s") .
" Err : " .
$this->db->error()["message"] .
"\n";
exit();
}
$rows = $qry->result_array();
if (count($rows) == 0) {
$sql = "insert into regonline.heartbeat(heartbeatCode,heartbeatStatus,heartbeatExecuted,heartbeatMessage)
values('PACKET_CATEGORY','OK','1971-01-01 00:00:01','')";
$qry = $this->db->query($sql);
if (!$qry) {
echo date("Y-m-d H:i:s") .
" Err : " .
$this->db->error()["message"] .
"\n";
exit();
}
return "1971-01-01 00:00:01";
}
return $rows[0]["heartbeatExecuted"];
}
function update_heartbeat( $status, $msg)
{
$type = "PACKET_CATEGORY";
if ($status == "OK") {
$sql = "update regonline.heartbeat set heartbeatExecuted = now(), heartbeatStatus = ? , heartbeatMessage = ?
where heartbeatCode = ?";
$qry = $this->db->query($sql, array($status, $msg, $type));
} else {
$sql = "update regonline.heartbeat set heartbeatStatus = ? , heartbeatMessage = ?
where heartbeatCode = ?";
$qry = $this->db->query($sql, array($status, $msg, $type));
}
if (!$qry) {
echo date("Y-m-d H:i:s") . " \t Error $type : {$this->db->error()['message']}\n";
}
}
function post($url, $data, $timeout = 60, $c_timeout = 5)
{
$zdata = gzcompress($data);
$this->log("Upload to $url : " . ( round(strlen($zdata) / 1024) ) . " kB");
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_POSTFIELDS, $zdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/octet",
"Content-Length: " . strlen($zdata),
]);
$result = curl_exec($ch);
$err_msg = curl_error($ch);
if ($err_msg != "") {
return json_encode([
"status" => "ERR",
"message" => $err_msg,
"url" => $url,
"data" => json_decode($data, true),
]);
}
return $result;
}
}

View File

@@ -0,0 +1,225 @@
<?php
class Category_packet_upload extends MY_Controller
{
var $url;
function __construct()
{
parent::__construct();
$this->url= "https://devregonline.pramita.co.id/one-api/tools/regonline/r_category_packet";
}
function step_debug($rows)
{
print_r($rows);
exit();
}
function get_rows($sql, $prm = false)
{
if ($prm) {
$qry = $this->db->query($sql, $prm);
} else {
$qry = $this->db->query($sql);
}
if (!$qry) {
$msg = "Error Query : {$this->db->error()["message"]} | {$this->db->last_query()}\n";
return array("status"=>-1, "message" => $msg);
}
$rows = $qry->result_array();
return array("status" => 0, "data" => $rows);
}
function get_one_row($sql, $prm =false)
{
$resp = $this->get_rows($sql, $prm);
if ($resp["status"] == -1 ) return $resp;
if (count($resp["data"]) == 0) {
return array("status"=> 0, "message" => "No record.");
}
return array("status" => 1, "data" => $resp["data"][0]);
}
function get_max($table) {
$field = strtoupper($table);
$sql = "select max({$field}LastUpdated) LastUpdated, max({$field}Created) Created
from $table";
$resp = $this->get_one_row($sql);
if ($resp["status"] == -1) {
$this->log("Err get max $table |" . $resp["message"]);
exit;
}
if ($resp["status"] == 0) return "1971-01-01 00:00:01";
$max = $resp["data"]["LastUpdated"] > $resp["data"]["Created"] ? $resp["data"]["Created"] : $resp["data"]["LastUpdated"];
return $max;
}
function index() {
$regionalID = $this->get_regional();
$date = $this->get_heartbeat();
$max = $this->get_max("m_packetcategory");
$max2 = $this->get_max("m_packetcategorydetail");
$max = $max > $max2 ? $max : $max2;
$max2 = $this->get_max("m_packetcategorymou");
$max = $max > $max2 ? $max : $max2;
if ($max == "") $max = "1971-01-01 00:00:01";
if ($max < $date) {
$this->log("No Packet Category updated or created neeed to be uploaded");
exit;
}
$result = [];
$sql = "select m_packetcategory.*, $regionalID as M_PacketCategoryS_RegionalID
from m_packetcategory";
$resp = $this->get_rows($sql);
if ($resp["status"] == -1) {
$this->log("Err get m_packetcategory |" . $resp["message"]);
exit;
}
$result["m_packetcategory"] = $resp["data"];
$sql = "select m_packetcategorydetail.*, $regionalID as M_PacketCategoryDetailS_RegionalID
from m_packetcategorydetail";
$resp = $this->get_rows($sql);
if ($resp["status"] == -1) {
$this->log("Err get m_packetcategorydetail |" . $resp["message"]);
exit;
}
$result["m_packetcategorydetail"] = $resp["data"];
$sql = "select m_packetcategorymou.*, $regionalID as M_PacketCategoryMouS_RegionalID
from m_packetcategorymou";
$resp = $this->get_rows($sql);
if ($resp["status"] == -1) {
$this->log("Err get m_packetcategorymou |" . $resp["message"]);
exit;
}
$result["m_packetcategorymou"] = $resp["data"];
$counter_data =0;
$all_name = "";
$rows = $result["m_packetcategory"];
$data = [];
foreach($rows as $r) {
$order = $r["M_PacketCategoryOrder"];
$id = $r["M_PacketCategoryID"];
$name = sprintf("%02d",$order) . "-" . sprintf("%03d",$id) . "-" . $r["M_PacketCategoryImageUrl"];
$real_name = "/home/regional/project/regional/one-media/one-regonline/" . $r["M_PacketCategoryImageUrl"];
if(! file_exists($real_name)) {
$this->log("File $real_name not exists");
} else {
$all_name .= $name;
$data[] = array(
"name" => $name,
"regionalID" => $regionalID,
"categoryID" => $id,
"content" => base64_encode(file_get_contents($real_name))
);
$counter_data++;
}
}
$msg = "Uploaded {$counter_data} image.";
$j_data = json_encode(array(
"data" => $data,
"result" => $result,
"md5" => md5($all_name . $regionalID . "545123")
));
$j_resp = $this->post($this->url, $j_data);
echo "JRESP : $j_resp\n";
$resp = json_decode($j_resp,true);
$json_error = json_last_error_msg();
if (json_last_error() != 0) {
$msg .= " [JSON ERR] $json_error " ;
}
if($resp["status"] == "OK") {
$msg .= " [Success] ";
$this->update_heartbeat("OK","");
} else {
$msg .= " [ERR] " ;
if($resp["message"] != "") $msg .= " " . $resp["message"];
$this->update_heartbeat("ERR",$msg);
}
$this->log($msg);
}
function log($msg) {
$date = date("Y-m-d H:i:s");
echo "$date $msg\n";
}
function get_regional() {
$sql = "select S_RegionalID from s_regional where S_RegionalIsActive= 'Y' and S_RegionalIsDefault= 'Y'";
$resp = $this->get_one_row($sql);
if ($resp["status"] == -1) {
$this->log("Error get reginalID | " . $resp["message"]);
}
if ($resp["status"] == 0) {
$this->log("Error default regional not set.");
}
return $resp["data"]["S_RegionalID"];
}
function get_heartbeat() {
$sql="select * from regonline.heartbeat where heartbeatCode='PACKET_CATEGORY'";
$qry = $this->db->query($sql);
if (!$qry) {
echo date("Y-m-d H:i:s") .
" Err : " .
$this->db->error()["message"] .
"\n";
exit();
}
$rows = $qry->result_array();
if (count($rows) == 0) {
$sql = "insert into regonline.heartbeat(heartbeatCode,heartbeatStatus,heartbeatExecuted,heartbeatMessage)
values('PACKET_CATEGORY','OK','1971-01-01 00:00:01','')";
$qry = $this->db->query($sql);
if (!$qry) {
echo date("Y-m-d H:i:s") .
" Err : " .
$this->db->error()["message"] .
"\n";
exit();
}
return "1971-01-01 00:00:01";
}
return $rows[0]["heartbeatExecuted"];
}
function update_heartbeat( $status, $msg)
{
$type = "PACKET_CATEGORY";
if ($status == "OK") {
$sql = "update regonline.heartbeat set heartbeatExecuted = now(), heartbeatStatus = ? , heartbeatMessage = ?
where heartbeatCode = ?";
$qry = $this->db->query($sql, array($status, $msg, $type));
} else {
$sql = "update regonline.heartbeat set heartbeatStatus = ? , heartbeatMessage = ?
where heartbeatCode = ?";
$qry = $this->db->query($sql, array($status, $msg, $type));
}
if (!$qry) {
echo date("Y-m-d H:i:s") . " \t Error $type : {$this->db->error()['message']}\n";
}
}
function post($url, $data, $timeout = 60, $c_timeout = 5)
{
$zdata = gzcompress($data);
$this->log("Upload to $url : " . ( round(strlen($zdata) / 1024) ) . " kB");
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_POSTFIELDS, $zdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/octet",
"Content-Length: " . strlen($zdata),
]);
$result = curl_exec($ch);
$err_msg = curl_error($ch);
if ($err_msg != "") {
return json_encode([
"status" => "ERR",
"message" => $err_msg,
"url" => $url,
"data" => json_decode($data, true),
]);
}
return $result;
}
}