Batch 6a: application controllers base
This commit is contained in:
136
application/controllers/tools/Ucopy.php
Normal file
136
application/controllers/tools/Ucopy.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
ini_set('display_errors', '1');
|
||||
ini_set('display_startup_errors', '1');
|
||||
error_reporting(E_ALL);
|
||||
|
||||
class Ucopy extends MY_Controller
|
||||
{
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function log() {
|
||||
$xdb = $this->load->database("onedev",true);
|
||||
$pwd = $xdb->password;
|
||||
|
||||
$temp_file = tempnam(sys_get_temp_dir(), '-log-db') . ".sql";
|
||||
if ( file_exists($temp_file) ) unlink($temp_file);
|
||||
$cmd = "mysqldump --triggers --routines --no-data -u root -p$pwd one_log > $temp_file";
|
||||
exec($cmd);
|
||||
if (file_exists($temp_file)) {
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Disposition: attachment; filename="'.basename($temp_file).'"');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate');
|
||||
header('Pragma: public');
|
||||
header('Content-Length: ' . filesize($temp_file));
|
||||
readfile($temp_file);
|
||||
unlink($temp_file);
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function update($mcuCode) {
|
||||
$sql = "update mcu_offline_prepare set McuOfflinePrepareIsDownloaded = 'Y'
|
||||
where McuOfflinePrepareCode = ?";
|
||||
$query = $this->db->query($sql,array($mcuCode));
|
||||
if (! $query) {
|
||||
echo "ERR| MCU Code : $mcuCode is not found !";
|
||||
echo $this->db->error()->message;
|
||||
exit;
|
||||
}
|
||||
echo "OK |MCU Offline $mcuCode sudah ter download !";
|
||||
}
|
||||
|
||||
function info($branchCode,$mcuCode) {
|
||||
$sql = "select * from m_branch where M_BranchIsActive = 'Y' and M_BranchCode = ? and M_BranchIsDefault = 'Y'";
|
||||
$query = $this->db->query($sql,array($branchCode));
|
||||
if (! $query) {
|
||||
echo "ERR|$branchCode is not the default branch !";
|
||||
echo $this->db->error()->message;
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "ERR|$branchCode is not the default branch !";
|
||||
echo $this->db->error()->message;
|
||||
exit;
|
||||
}
|
||||
$branchName = $rows[0]["M_BranchName"];
|
||||
$sql = "select M_CompanyName, McuOfflinePrepareStartDate, McuOfflinePrepareEndDate , McuOfflinePrepareIsDownloaded
|
||||
from mcu_offline_prepare join m_company on McuOfflinePrepareM_CompanyID = M_CompanyID
|
||||
where McuOfflinePrepareCode = ? and McuOfflinePrepareIsActive = 'Y'";
|
||||
$query = $this->db->query($sql, array($mcuCode));
|
||||
if (! $query) {
|
||||
echo "ERR|Kode MCU $mcuCode tidak ada";
|
||||
echo $this->db->error()->message;
|
||||
exit;
|
||||
}
|
||||
$rows = $query->result_array();
|
||||
if (count($rows) == 0) {
|
||||
echo "ERR|Kode MCU $mcuCode tidak ada";
|
||||
exit;
|
||||
}
|
||||
if ( $rows[0]["McuOfflinePrepareIsDownloaded"] == "Y" ) {
|
||||
echo "ERR|Kode MCU $mcuCode sudah di download.";
|
||||
exit;
|
||||
}
|
||||
$startDate = $rows[0]["McuOfflinePrepareStartDate"];
|
||||
$endDate = $rows[0]["McuOfflinePrepareEndDate"];
|
||||
$companyName = $rows[0]["M_CompanyName"];
|
||||
echo "OK|Cabang\t\t: $branchName\nKode MCU\t: $mcuCode\nCompany\t\t: $companyName\nStart\t\t: $startDate\nEnd\t\t: $endDate";
|
||||
}
|
||||
|
||||
function db() {
|
||||
$xdb = $this->load->database("onedev",true);
|
||||
$pwd = $xdb->password;
|
||||
|
||||
$temp_c = tempnam(sys_get_temp_dir(), 'temp_c') . ".sql";
|
||||
$xname = tempnam(sys_get_temp_dir(), 'temp_c');
|
||||
if ( file_exists($temp_c) ) unlink($temp_c);
|
||||
|
||||
// add routines
|
||||
$cmd = "mysqldump --skip-triggers -u root -p$pwd one > $temp_c";
|
||||
exec($cmd);
|
||||
|
||||
$cmd = "gzip $temp_c";
|
||||
exec($cmd);
|
||||
//$temp_c = str_replace(".sql","",$temp_c);
|
||||
$temp_c .= ".gz";
|
||||
//print_r(file_exists($temp_c));
|
||||
if (file_exists($temp_c)) {
|
||||
$xname = str_replace(".sql","",basename($temp_c));
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Disposition: attachment; filename="'.$xname.'"');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate');
|
||||
header('Pragma: public');
|
||||
header('Content-Length: ' . filesize($temp_c));
|
||||
readfile($temp_c);
|
||||
unlink($temp_c);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function app() {
|
||||
$temp_file = tempnam(sys_get_temp_dir(), 'x-copy-tar') . "tar.gz";
|
||||
if ( file_exists($temp_file) ) unlink($temp_file);
|
||||
$cmd="tar --exclude=database.php --exclude-vcs -zcf $temp_file -C /home/one/project/one one-api one-ui -C /home/one/project/birt one";
|
||||
exec($cmd);
|
||||
if (file_exists($temp_file)) {
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Disposition: attachment; filename="'.basename($temp_file).'"');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate');
|
||||
header('Pragma: public');
|
||||
header('Content-Length: ' . filesize($temp_file));
|
||||
readfile($temp_file);
|
||||
unlink($temp_file);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user