This commit is contained in:
Duidev Software House
2025-11-10 05:06:23 +07:00
parent 0520d51179
commit 8f079b9f6c
9 changed files with 766 additions and 263 deletions
@@ -10,9 +10,7 @@ use ZipArchive;
class JsonTransferController extends Controller
{
protected $exportPath = 'database/seeders/data/';
public function index()
{
public function index(){
//POSTGRESS
$tables = DB::select("SELECT tablename FROM pg_tables WHERE schemaname = 'public'");
$tableNames = array_map(fn($t) => $t->tablename, $tables);
@@ -32,9 +30,7 @@ class JsonTransferController extends Controller
}
return view('backup', compact('tableInfo'));
}
public function generate()
{
public function generate(){
$exportPath = base_path($this->exportPath);
if (!is_dir($exportPath)) {
mkdir($exportPath, 0777, true);
@@ -74,10 +70,7 @@ class JsonTransferController extends Controller
return redirect()->back()->with('success', 'Semua tabel berhasil diekspor tanpa kehabisan memori.');
}
public function downloadTable($table)
{
public function downloadTable($table){
$file = base_path($this->exportPath . $table . '.json');
if (!file_exists($file)) {
@@ -86,9 +79,7 @@ class JsonTransferController extends Controller
return response()->download($file);
}
public function downloadAll()
{
public function downloadAll(){
$zipFile = base_path('database/seeders/data/all_json.zip');
$zip = new ZipArchive;
@@ -103,8 +94,7 @@ class JsonTransferController extends Controller
return response()->download($zipFile);
}
public function importTable($table)
{
public function importTable($table){
$path = base_path($this->exportPath . $table . '.json');
if (!file_exists($path)) {
return redirect()->back()->with('error', "File JSON untuk tabel $table tidak ditemukan.");
@@ -128,5 +118,21 @@ class JsonTransferController extends Controller
return redirect()->back()->with('error', "Gagal import tabel $table: " . $e->getMessage());
}
}
public function pull(Request $request){
if (session('previlage') !== 'developer') {
abort(403, 'Akses ditolak. Anda tidak memiliki izin untuk menjalankan git pull.');
}
$gitPath = '/var/www/html/lis/';
// Jalankan git pull
$output = shell_exec("cd {$gitPath} && git pull 2>&1");
// Simpan log siapa yang menjalankan (opsional)
if (auth()->check()) {
Log::info('Git pull executed by user: ' . auth()->user()->email);
}
return back()->with('git_output', $output);
}
}