mirror of
https://github.com/getformwork/formwork.git
synced 2025-01-29 11:31:19 +01:00
Add Backup
controller
This commit is contained in:
parent
eae4460add
commit
be5c1220df
@ -1,6 +1,11 @@
|
||||
admin.manage: Manage
|
||||
admin.panel: Administration Panel
|
||||
admin.view-site: View Site
|
||||
backup.backup: Backup
|
||||
backup.error.cannot-download: Cannot download backup. %s
|
||||
backup.error.cannot-download.invalid-filename: Invalid backup file.
|
||||
backup.error.cannot-make: Cannot make backup. %s
|
||||
backup.ready: Backup ready. Starting download...
|
||||
cache.clear: Clear Cache
|
||||
cache.cleared: Cache cleared
|
||||
dashboard.dashboard: Dashboard
|
||||
|
@ -1,6 +1,11 @@
|
||||
admin.manage: Gestione
|
||||
admin.panel: Pannello di Amministrazione
|
||||
admin.view-site: Visualizza sito
|
||||
backup.backup: Esegui backup
|
||||
backup.error.cannot-download: Impossibile scaricare il backup. %s
|
||||
backup.error.cannot-download.invalid-filename: File di backup non valido.
|
||||
backup.error.cannot-make: Impossibile eseguire il backup. %s
|
||||
backup.ready: Backup pronto. Inizio a scaricare...
|
||||
cache.clear: Svuota cache
|
||||
cache.cleared: Cache svuotata
|
||||
dashboard.dashboard: Riepilogo
|
||||
|
@ -165,6 +165,19 @@ class Admin
|
||||
array(new Controllers\Authentication(), 'logout')
|
||||
);
|
||||
|
||||
// Backup
|
||||
$this->router->add(
|
||||
'XHR',
|
||||
'POST',
|
||||
'/backup/make/',
|
||||
array(new Controllers\Backup(), 'make')
|
||||
);
|
||||
$this->router->add(
|
||||
'POST',
|
||||
'/backup/download/{backup}/',
|
||||
array(new Controllers\Backup(), 'download')
|
||||
);
|
||||
|
||||
// Cache
|
||||
$this->router->add(
|
||||
'XHR',
|
||||
|
44
admin/src/Controllers/Backup.php
Normal file
44
admin/src/Controllers/Backup.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Formwork\Admin\Controllers;
|
||||
|
||||
use Formwork\Admin\Backupper;
|
||||
use Formwork\Admin\Utils\JSONResponse;
|
||||
use Formwork\Core\Formwork;
|
||||
use Formwork\Router\RouteParams;
|
||||
use Formwork\Utils\FileSystem;
|
||||
use Formwork\Utils\HTTPResponse;
|
||||
use RuntimeException;
|
||||
|
||||
class Backup extends AbstractController
|
||||
{
|
||||
public function make()
|
||||
{
|
||||
$backupper = new Backupper();
|
||||
try {
|
||||
$file = $backupper->backup();
|
||||
$filename = FileSystem::basename($file);
|
||||
JSONResponse::success($this->label('backup.ready'), 200, array(
|
||||
'filename' => $filename,
|
||||
'uri' => $this->uri('/backup/download/' . urlencode(base64_encode($filename)) . '/')
|
||||
))->send();
|
||||
} catch (RuntimeException $e) {
|
||||
JSONResponse::error($this->label('backup.error.cannot-make'), 500)->send();
|
||||
}
|
||||
}
|
||||
|
||||
public function download(RouteParams $params)
|
||||
{
|
||||
$file = Formwork::instance()->option('backup.path') . base64_decode($params->get('backup'));
|
||||
try {
|
||||
if (FileSystem::exists($file) && FileSystem::isFile($file)) {
|
||||
HTTPResponse::download($file);
|
||||
} else {
|
||||
throw new RuntimeException($this->label('backup.error.cannot-download.invalid-filename'));
|
||||
}
|
||||
} catch (RuntimeException $e) {
|
||||
$this->notify($this->label('backup.error.cannot-download', $e->getMessage()), 'error');
|
||||
$this->redirectToReferer(302, true, '/dashboard/');
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user