Browse Source

Added database backup and restore feature

pull/3/head
Nafies Luthfi 8 years ago
parent
commit
f7e0373e48
  1. 52
      app/Http/Requests/BackupUploadRequest.php
  2. 3
      resources/lang/en/app.php
  3. 27
      resources/lang/en/backup.php
  4. 3
      resources/lang/id/app.php
  5. 27
      resources/lang/id/backup.php
  6. 8
      resources/views/backups/index.blade.php
  7. 6
      resources/views/layouts/app.blade.php
  8. 1
      resources/views/layouts/partials/nav.blade.php

52
app/Http/Requests/BackupUploadRequest.php

@ -0,0 +1,52 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class BackupUploadRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return auth()->check();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'backup_file' => 'required|sql_gz',
];
}
public function messages()
{
return [
'backup_file.sql_gz' => 'Invalid file type, must be <strong>.gz</strong> file',
];
}
protected function getValidatorInstance()
{
$validator = parent::getValidatorInstance();
$validator->addImplicitExtension('sql_gz', function ($attribute, $value, $parameters) {
if ($value) {
return $value->getClientOriginalExtension() == 'gz';
}
return false;
});
return $validator;
}
}

3
resources/lang/en/app.php

@ -33,4 +33,7 @@ return [
'select_from_existing_males' => 'Select from Existing Males',
'select_from_existing_females' => 'Select from Existing Females',
'select_from_existing_couples' => 'Select from Existing Couples',
'restore' => 'Restore',
'download' => 'Download',
'delete' => 'Delete',
];

27
resources/lang/en/backup.php

@ -0,0 +1,27 @@
<?php
return [
// Labels
'index_title' => 'Database Backup Manager',
'list' => 'Backup File List',
'actions' => 'Actions',
'empty' => 'No backup file available.',
// Actions
'create' => 'Create Backup File',
'delete' => 'Delete this backup file',
'sure_to_delete_file' => 'Are you sure to delete this file <strong>":filename"</strong>?',
'confirm_delete' => 'YES, please delete this file!',
'cancel_delete' => 'Cancel Delete',
'restore' => 'Restore database from file',
'sure_to_restore' => 'Are you sure to restore database with this backup file "<strong>:filename</strong>"? <br><br>Please make sure your <strong>current database has been backed up</strong>.',
'confirm_restore' => 'YES, Restore Database!',
'cancel_restore' => 'Cancel Restore',
'download' => 'Download this file',
'upload' => 'Upload Backup File',
// Attributes
'file_name' => 'File Name',
'file_size' => 'File Size',
'created_at' => 'Created at',
];

3
resources/lang/id/app.php

@ -33,4 +33,7 @@ return [
'select_from_existing_males' => 'Pilih dari Pria terdaftar',
'select_from_existing_females' => 'Pilih dari Wanita terdaftar',
'select_from_existing_couples' => 'Pilih Pasangan Pernikahan',
'restore' => 'Restore',
'download' => 'Download',
'delete' => 'Hapus',
];

27
resources/lang/id/backup.php

@ -0,0 +1,27 @@
<?php
return [
// Labels
'index_title' => 'Database Backup Manager',
'list' => 'Daftar File Backup',
'actions' => 'Pilihan',
'empty' => 'Belum ada file backup.',
// Actions
'create' => 'Buat File Backup',
'delete' => 'Hapus file backup ini',
'sure_to_delete_file' => 'Anda yakin akan menghapus file <strong>":filename"</strong> ini?',
'confirm_delete' => 'YA, silakan hapus file ini!',
'cancel_delete' => 'Batal Hapus',
'restore' => 'Restore database dari file',
'sure_to_restore' => 'Anda yakin akan me-restore database dengan file backup ini "<strong>:filename</strong>"? <br><br>Harap dipastikan <strong>database saat ini sudah di-backup</strong>.',
'confirm_restore' => 'YA, Restore Database!',
'cancel_restore' => 'Batal Restore',
'download' => 'Download file ini',
'upload' => 'Upload File Backup',
// Attributes
'file_name' => 'Name File',
'file_size' => 'Ukuran File',
'created_at' => 'Dibuat pada',
];

8
resources/views/backups/index.blade.php

@ -3,7 +3,7 @@
@section('title',trans('backup.index_title'))
@section('content')
<h1 class="page-header">{{ trans('backup.index_title') }}</h1>
<h3 class="page-header">{{ trans('backup.index_title') }}</h3>
<div class="row">
<div class="col-md-8">
<div class="panel panel-default table-responsive">
@ -27,15 +27,15 @@
<a href="{{ route('backups.index', ['action' => 'restore', 'file_name' => $backup->getFilename()]) }}"
id="restore_{{ str_replace('.gz', '', $backup->getFilename()) }}"
class="btn btn-warning btn-xs"
title="{{ trans('backup.restore') }}">Restore</i></a>
title="{{ trans('backup.restore') }}">{{ trans('app.restore') }}</i></a>
<a href="{{ route('backups.download', [$backup->getFilename()]) }}"
id="download_{{ str_replace('.gz', '', $backup->getFilename()) }}"
class="btn btn-info btn-xs"
title="{{ trans('backup.download') }}">Download</a>
title="{{ trans('backup.download') }}">{{ trans('app.download') }}</a>
<a href="{{ route('backups.index', ['action' => 'delete', 'file_name' => $backup->getFilename()]) }}"
id="del_{{ str_replace('.gz', '', $backup->getFilename()) }}"
class="btn btn-danger btn-xs"
title="{{ trans('backup.delete') }}">Delete</a>
title="{{ trans('backup.delete') }}">{{ trans('app.delete') }}</a>
</td>
</tr>
@empty

6
resources/views/layouts/app.blade.php

@ -24,12 +24,6 @@
@include('layouts.partials.nav')
<div class="container">
{{-- {{ dump(get_class_methods(url())) }} --}}
{{-- {{ url()->current().'?lang=en' }} --}}
{{-- {{ dump(get_class_methods(Route::current())) }} --}}
{{-- {{ dump(Route::current()->parameters()) }} --}}
{{-- {{ dump(url(Route::getName(), ['query' => 'recent', 'order' => 'desc'])) }} --}}
{{-- {{ dump(Route::current()->setParameter('lang', 'id')) }} --}}
@yield('content')
</div>
</div>

1
resources/views/layouts/partials/nav.blade.php

@ -38,6 +38,7 @@
</a>
<ul class="dropdown-menu" role="menu">
<li><a href="{{ route('backups.index') }}">{{ trans('backup.list') }}</a></li>
<li><a href="{{ route('profile') }}">{{ trans('app.my_profile') }}</a></li>
<li>
<a href="{{ route('logout') }}"

Loading…
Cancel
Save