update
This commit is contained in:
@@ -95,40 +95,39 @@ class JsonTransferController extends Controller
|
||||
return response()->download($zipFile);
|
||||
}
|
||||
public function importTable($table) {
|
||||
|
||||
$path = base_path($this->exportPath . $table . '.json');
|
||||
if (!file_exists($path)) {
|
||||
return back()->with('error', "File JSON untuk tabel $table tidak ditemukan.");
|
||||
}
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
DB::table($table)->truncate();
|
||||
DB::statement("TRUNCATE TABLE $table RESTART IDENTITY CASCADE");
|
||||
|
||||
$items = Items::fromFile($path);
|
||||
$items = Items::fromFile($path);
|
||||
$chunk = [];
|
||||
|
||||
$chunk = [];
|
||||
foreach ($items as $row) {
|
||||
$row = json_decode(json_encode($row), true);
|
||||
$chunk[] = $row;
|
||||
foreach ($items as $row) {
|
||||
$data = (array) $row;
|
||||
unset($data['id']);
|
||||
$chunk[] = (array) $row;
|
||||
|
||||
if (count($chunk) >= 200) {
|
||||
DB::table($table)->insert($chunk);
|
||||
$chunk = [];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($chunk)) {
|
||||
if (count($chunk) >= 50) {
|
||||
|
||||
DB::table($table)->insert($chunk);
|
||||
$chunk = [];
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
return back()->with('success', "Import berhasil!");
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return back()->with('error', $e->getMessage());
|
||||
unset($row);
|
||||
}
|
||||
|
||||
if (!empty($chunk)) {
|
||||
DB::table($table)->insert($chunk);
|
||||
}
|
||||
|
||||
return back()->with('success', 'Import berhasil!');
|
||||
}
|
||||
|
||||
|
||||
public function pull(Request $request){
|
||||
if (session('previlage') !== 'developer') {
|
||||
abort(403, 'Akses ditolak. Anda tidak memiliki izin untuk menjalankan git pull.');
|
||||
|
||||
Reference in New Issue
Block a user