/** * Get backup for restore action * * @return mixed * @throws ApplicationException */ private function getBackupForRestore() { $checked = post('checked'); if (count($checked) !== 1) { throw new ApplicationException(trans('renatio.backupmanager::lang.restore.invalid_check')); } try { return Backup::findOrFail($checked[0]); } catch (ModelNotFoundException $ex) { throw new ApplicationException(trans('renatio.backupmanager::lang.restore.invalid_check')); } }
/** * Unzip backup file * * @param $id * @return $this * @throws ApplicationException */ private function unzipBackup($id) { $backup = Backup::findOrFail($id); $filePath = $this->getBackupFromStorage($backup); $zip = new ZipArchive(); $res = $zip->open($filePath); if ($res === true) { $zip->extractTo(storage_path('temp'), ['db/dump.sql']); $zip->close(); $backup->deleteNotLocalFile(); } else { throw new ApplicationException(trans('renatio.backupmanager::lang.restore.open_error')); } return $this; }