mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
INCOMPLETE: Added restore and upload methods for backups
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
05c6254fdc
commit
96f76e1f6b
|
@ -11,7 +11,6 @@ use App\Models\Setting;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Notifications\FirstAdminNotification;
|
use App\Notifications\FirstAdminNotification;
|
||||||
use App\Notifications\MailTest;
|
use App\Notifications\MailTest;
|
||||||
use Artisan;
|
|
||||||
use Auth;
|
use Auth;
|
||||||
use Crypt;
|
use Crypt;
|
||||||
use DB;
|
use DB;
|
||||||
|
@ -22,6 +21,8 @@ use Image;
|
||||||
use Input;
|
use Input;
|
||||||
use Redirect;
|
use Redirect;
|
||||||
use Response;
|
use Response;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Illuminate\Support\Facades\Artisan;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This controller handles all actions related to Settings for
|
* This controller handles all actions related to Settings for
|
||||||
|
@ -1136,6 +1137,98 @@ class SettingsController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uploads a backup file
|
||||||
|
*
|
||||||
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
|
*
|
||||||
|
* @since [v6.0]
|
||||||
|
*
|
||||||
|
* @return Redirect
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function postUploadBackup(Request $request) {
|
||||||
|
|
||||||
|
$max_file_size = Helper::file_upload_max_size();
|
||||||
|
|
||||||
|
$rules = [
|
||||||
|
'file' => 'required|mimes:zip|max:'.$max_file_size,
|
||||||
|
];
|
||||||
|
|
||||||
|
$validator = \Validator::make($request->all(), $rules);
|
||||||
|
|
||||||
|
if ($validator->passes()) {
|
||||||
|
|
||||||
|
if ($request->hasFile('file')) {
|
||||||
|
|
||||||
|
$upload_filename = 'uploaded-'.date('U').'-'.Str::slug(pathinfo($request->file('file')->getClientOriginalName(), PATHINFO_FILENAME)).'.zip';
|
||||||
|
|
||||||
|
Storage::putFileAs('app/backups', $request->file('file'), $upload_filename);
|
||||||
|
|
||||||
|
return redirect()->route('settings.backups.index')->with('success', 'File uploaded');
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return redirect()->route('settings.backups.index')->with('error', 'No file uploaded');
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return redirect()->route('settings.backups.index')->withErrors($request->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restore the backup file.
|
||||||
|
*
|
||||||
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
|
*
|
||||||
|
* @since [v6.0]
|
||||||
|
*
|
||||||
|
* @return View
|
||||||
|
*/
|
||||||
|
public function postRestore($filename = null)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (! config('app.lock_passwords')) {
|
||||||
|
$path = 'app/backups';
|
||||||
|
|
||||||
|
if (Storage::exists($path.'/'.$filename)) {
|
||||||
|
|
||||||
|
// grab the user's info so we can make sure they exist in the system
|
||||||
|
$user = User::find(Auth::user()->id);
|
||||||
|
|
||||||
|
// run the restore command
|
||||||
|
Artisan::call('snipeit:restore',
|
||||||
|
[
|
||||||
|
'--force' => true,
|
||||||
|
'--no-progress' => true,
|
||||||
|
'filename' => storage_path($path).'/'.$filename
|
||||||
|
]);
|
||||||
|
|
||||||
|
$output = Artisan::output();
|
||||||
|
|
||||||
|
|
||||||
|
// If it's greater than 300, it probably worked
|
||||||
|
if (strlen($output) > 300) {
|
||||||
|
return redirect()->route('settings.backups.index')->with('success', 'Your system has been restored.');
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return redirect()->route('settings.backups.index')->with('error', $output);
|
||||||
|
|
||||||
|
}
|
||||||
|
//dd($output);
|
||||||
|
|
||||||
|
// insert the user if they are not there in the old one
|
||||||
|
// log the user out
|
||||||
|
} else {
|
||||||
|
return redirect()->route('settings.backups.index')->with('error', trans('admin/settings/message.backup.file_not_found'));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return redirect()->route('settings.backups.index')->with('error', trans('general.feature_disabled'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a form to allow a super admin to update settings.
|
* Return a form to allow a super admin to update settings.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue