From 7cd6d5b1a6efd0b4365b72298f952b4a83c0ae8a Mon Sep 17 00:00:00 2001 From: ARCANEDEV Date: Tue, 29 Sep 2020 03:02:46 +0100 Subject: [PATCH 1/5] Starting the next major release --- .editorconfig | 10 +- composer.json | 29 ++- config/backups.php | 14 -- config/policies.php | 12 + config/sidebar.php | 21 ++ config/sidebar/main.php | 18 -- phpunit.xml.dist | 32 +-- resources/lang/en/sidebar.php | 7 - resources/lang/en/statuses.php | 79 ------- resources/lang/fr/sidebar.php | 7 - resources/lang/fr/statuses.php | 79 ------- .../views/admin/statuses/index.blade.php | 223 ------------------ resources/views/admin/statuses/show.blade.php | 130 ---------- src/BackupsServiceProvider.php | 56 ++--- src/Console/InstallCommand.php | 16 +- src/Console/PublishCommand.php | 8 +- src/Database/DatabaseSeeder.php | 35 +++ src/Database/Seeders/PermissionsSeeder.php | 33 +++ .../Seeders/RolesSeeder.php} | 25 +- src/Http/Controllers/Admin/Controller.php | 32 --- src/Http/Controllers/Controller.php | 26 ++ .../{Admin => }/StatusesController.php | 69 +++--- src/Http/Routes/AbstractRouteRegistrar.php | 34 +++ src/Http/Routes/StatusesRoutes.php | 40 ++-- src/Policies/StatusesPolicy.php | 104 ++++++-- src/Providers/AuthServiceProvider.php | 31 +++ .../AuthorizationServiceProvider.php | 28 --- src/Providers/CommandServiceProvider.php | 29 --- src/Providers/PackagesServiceProvider.php | 40 ---- src/Providers/RouteServiceProvider.php | 52 +--- src/Seeds/DatabaseSeeder.php | 27 --- src/Seeds/PermissionsTableSeeder.php | 73 ------ src/Services/BackupService.php | 113 +++++++++ src/Services/BackupStatuses.php | 92 -------- tests/Feature/.gitkeep | 0 tests/Unit/.gitkeep | 0 translations/fr.json | 10 + views/statuses/index.blade.php | 223 ++++++++++++++++++ views/statuses/show.blade.php | 128 ++++++++++ 39 files changed, 922 insertions(+), 1063 deletions(-) delete mode 100644 config/backups.php create mode 100644 config/policies.php create mode 100644 config/sidebar.php delete mode 100644 config/sidebar/main.php delete mode 100644 resources/lang/en/sidebar.php delete mode 100644 resources/lang/en/statuses.php delete mode 100644 resources/lang/fr/sidebar.php delete mode 100644 resources/lang/fr/statuses.php delete mode 100644 resources/views/admin/statuses/index.blade.php delete mode 100644 resources/views/admin/statuses/show.blade.php create mode 100644 src/Database/DatabaseSeeder.php create mode 100644 src/Database/Seeders/PermissionsSeeder.php rename src/{Seeds/RolesTableSeeder.php => Database/Seeders/RolesSeeder.php} (53%) delete mode 100644 src/Http/Controllers/Admin/Controller.php create mode 100644 src/Http/Controllers/Controller.php rename src/Http/Controllers/{Admin => }/StatusesController.php (50%) create mode 100644 src/Http/Routes/AbstractRouteRegistrar.php create mode 100644 src/Providers/AuthServiceProvider.php delete mode 100644 src/Providers/AuthorizationServiceProvider.php delete mode 100644 src/Providers/CommandServiceProvider.php delete mode 100644 src/Providers/PackagesServiceProvider.php delete mode 100644 src/Seeds/DatabaseSeeder.php delete mode 100644 src/Seeds/PermissionsTableSeeder.php create mode 100644 src/Services/BackupService.php delete mode 100644 src/Services/BackupStatuses.php create mode 100644 tests/Feature/.gitkeep create mode 100644 tests/Unit/.gitkeep create mode 100644 translations/fr.json create mode 100644 views/statuses/index.blade.php create mode 100644 views/statuses/show.blade.php diff --git a/.editorconfig b/.editorconfig index 042d009..6537ca4 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,15 +1,15 @@ -# This file is for unifying the coding style for different editors and IDEs -# editorconfig.org - root = true [*] -end_of_line = lf charset = utf-8 +end_of_line = lf +insert_final_newline = true indent_style = space indent_size = 4 trim_trailing_whitespace = true -insert_final_newline = true [*.md] +trim_trailing_whitespace = false + +[*.{yml,yaml}] indent_size = 2 diff --git a/composer.json b/composer.json index 6140c17..5231c83 100644 --- a/composer.json +++ b/composer.json @@ -14,14 +14,12 @@ "type": "library", "license": "MIT", "require": { - "php": ">=7.0", - "arcanesoft/auth": "~3.0", - "arcanesoft/core": "~2.6", - "spatie/laravel-backup": "~5.0" + "php": "^7.3", + "arcanedev/laravel-backup": "^3.0", + "arcanesoft/foundation": "@dev" }, "require-dev": { - "phpunit/phpunit": "~6.0", - "phpunit/phpcov": "~4.0" + "phpunit/phpunit": "^9.3" }, "autoload": { "psr-4": { @@ -33,7 +31,20 @@ "Arcanesoft\\Backups\\Tests\\": "tests/" } }, - "scripts": { - "testbench": "composer require --dev \"orchestra/testbench=~3.5.0\"" - } + "extra": { + "laravel": { + "providers": [ + "Arcanesoft\\Backups\\BackupsServiceProvider" + ] + }, + "arcanesoft": { + "install": "Arcanesoft\\Backups\\Console\\InstallCommand", + "publish": "Arcanesoft\\Backups\\Console\\PublishCommand" + } + }, + "config": { + "sort-packages": true + }, + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/config/backups.php b/config/backups.php deleted file mode 100644 index 154350a..0000000 --- a/config/backups.php +++ /dev/null @@ -1,14 +0,0 @@ - [ - 'prefix' => 'backups', - ], - -]; diff --git a/config/policies.php b/config/policies.php new file mode 100644 index 0000000..96336c8 --- /dev/null +++ b/config/policies.php @@ -0,0 +1,12 @@ + [ + [ + 'name' => 'foundation::backups', + 'title' => 'Backups', + 'icon' => 'fas fa-fw fa-database', + 'route' => 'admin::backups.statuses.index', + 'roles' => [], + 'permissions' => [ + 'admin::backups.statuses.index', + ], + ], + ], + +]; diff --git a/config/sidebar/main.php b/config/sidebar/main.php deleted file mode 100644 index 55a974e..0000000 --- a/config/sidebar/main.php +++ /dev/null @@ -1,18 +0,0 @@ - 'backups::sidebar.backups', - 'name' => 'backups-statuses', - 'route' => 'admin::backups.statuses.index', - 'icon' => 'fa fa-fw fa-database', - 'roles' => [Role::ADMINISTRATOR], - 'permissions' => [ - StatusesPolicy::PERMISSION_LIST, - ], - 'children' => [ - // - ], -]; diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 9cc7cf2..b08327f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,28 +1,22 @@ - - ./tests/ + ./tests/ - - - ./src/ - - - - - - - + + + ./src + + + + + + + diff --git a/resources/lang/en/sidebar.php b/resources/lang/en/sidebar.php deleted file mode 100644 index cfbf178..0000000 --- a/resources/lang/en/sidebar.php +++ /dev/null @@ -1,7 +0,0 @@ - 'Backups', - -]; diff --git a/resources/lang/en/statuses.php b/resources/lang/en/statuses.php deleted file mode 100644 index 07bbc40..0000000 --- a/resources/lang/en/statuses.php +++ /dev/null @@ -1,79 +0,0 @@ - [ - 'name' => 'Name', - 'disk' => 'Disk', - 'reachable' => 'Reachable', - 'healthy' => 'Healthy', - 'number_of_backups' => '# of backups', - 'newest_backup' => 'Newest backup', - 'used_storage' => 'Used storage', - - 'date' => 'Date', - 'path' => 'Path', - 'size' => 'Size', - ], - - /* ----------------------------------------------------------------- - | Titles - | ----------------------------------------------------------------- - */ - - 'titles' => [ - 'backups' => 'Backups', - 'monitor-status' => 'Monitor Status', - 'monitor-statuses-list' => 'List of Monitor Statuses', - ], - - /* ----------------------------------------------------------------- - | Actions - | ----------------------------------------------------------------- - */ - - 'actions' => [ - 'run-backups' => 'Run Backups', - 'clear-backups' => 'Clear Backups', - ], - - /* ----------------------------------------------------------------- - | Messages - | ----------------------------------------------------------------- - */ - - 'messages' => [ - 'created' => [ - 'title' => 'Backups created !', - 'message' => 'The Backups was created successfully !', - ], - - 'cleared' => [ - 'title' => 'Backups cleared !', - 'message' => 'The Backups was cleared successfully !', - ], - ], - - /* ----------------------------------------------------------------- - | Modals - | ----------------------------------------------------------------- - */ - - 'modals' => [ - 'backup' => [ - 'title' => 'Backup all', - 'message' => 'Are you sure you want to run the backups ?', - ], - - 'clear' => [ - 'title' => 'Clear all backups', - 'message' => 'Are you sure you want to clear all the backups ?', - ], - ], - -]; diff --git a/resources/lang/fr/sidebar.php b/resources/lang/fr/sidebar.php deleted file mode 100644 index 0b1f166..0000000 --- a/resources/lang/fr/sidebar.php +++ /dev/null @@ -1,7 +0,0 @@ - 'Sauvegardes', - -]; diff --git a/resources/lang/fr/statuses.php b/resources/lang/fr/statuses.php deleted file mode 100644 index 24cb7f0..0000000 --- a/resources/lang/fr/statuses.php +++ /dev/null @@ -1,79 +0,0 @@ - [ - 'name' => 'Nom', - 'disk' => 'Disque', - 'reachable' => 'Accessible', - 'healthy' => 'Sain', - 'number_of_backups' => 'Nbr de sauvegardes', - 'newest_backup' => 'La plus récente sauvegarde', - 'used_storage' => 'Stockage utilisé', - - 'date' => 'Date', - 'path' => 'Chemin', - 'size' => 'Taille', - ], - - /* ----------------------------------------------------------------- - | Titles - | ----------------------------------------------------------------- - */ - - 'titles' => [ - 'backups' => 'Sauvegardes', - 'monitor-status' => 'Statut du moniteur', - 'monitor-statuses-list' => 'Liste des statuts du moniteur', - ], - - /* ----------------------------------------------------------------- - | Actions - | ----------------------------------------------------------------- - */ - - 'actions' => [ - 'run-backups' => 'Exécuter les sauvegardes', - 'clear-backups' => 'Nettoyer les sauvegardes', - ], - - /* ----------------------------------------------------------------- - | Messages - | ----------------------------------------------------------------- - */ - - 'messages' => [ - 'created' => [ - 'title' => 'Sauvegardes créées !', - 'message' => 'Les sauvegardes ont été créées avec succès !', - ], - - 'cleared' => [ - 'title' => 'Sauvegardes effacées !', - 'message' => 'Les sauvegardes ont été effacées avec succès!', - ], - ], - - /* ----------------------------------------------------------------- - | Modals - | ----------------------------------------------------------------- - */ - - 'modals' => [ - 'backup' => [ - 'title' => 'Sauvegarder tout', - 'message' => 'Êtes-vous sûr de vouloir exécuter la sauvegarde des base de données ?', - ], - - 'clear' => [ - 'title' => 'Effacer toutes les sauvegardes', - 'message' => 'Êtes-vous sûr de vouloir nettoyer toutes les anciennes sauvegardes ?', - ], - ], - -]; diff --git a/resources/views/admin/statuses/index.blade.php b/resources/views/admin/statuses/index.blade.php deleted file mode 100644 index dd5de60..0000000 --- a/resources/views/admin/statuses/index.blade.php +++ /dev/null @@ -1,223 +0,0 @@ -@section('header') -

{{ trans('backups::statuses.titles.backups') }} {{ trans('backups::statuses.titles.monitor-statuses-list') }}

-@endsection - -@section('content') -
-
-

{{ trans('backups::statuses.titles.monitor-statuses-list') }}

-
- @can(Arcanesoft\Backups\Policies\StatusesPolicy::PERMISSION_CREATE) - - {{ trans('backups::statuses.actions.run-backups') }} - - @endcan - - @can(Arcanesoft\Backups\Policies\StatusesPolicy::PERMISSION_DELETE) - - {{ trans('backups::statuses.actions.clear-backups') }} - - @endcan -
-
-
-
- - - - - - - - - - - - - - - @forelse($statuses as $index => $status) - - - - - - - - - - - @empty - @endforelse - -
{{ trans('backups::statuses.attributes.disk') }}{{ trans('backups::statuses.attributes.name') }}{{ trans('backups::statuses.attributes.reachable') }}{{ trans('backups::statuses.attributes.healthy') }}{{ trans('backups::statuses.attributes.number_of_backups') }}{{ trans('backups::statuses.attributes.newest_backup') }}{{ trans('backups::statuses.attributes.used_storage') }}{{ trans('core::generals.actions') }}
- {{ $status->diskName() }} - - {{ $status->backupName() }} - - @if ($status->isReachable()) - Yes - @else - No - @endif - - @if ($status->isHealthy()) - Yes - @else - No - @endif - - @if ($status->isReachable()) - {{ label_count($status->amountOfBackups()) }} - @else - / - @endif - - @if ($status->isReachable()) - {{ $status->dateOfNewestBackup() ?: 'No backups present' }} - @else - / - @endif - - @if ($status->isReachable()) - {{ $status->humanReadableUsedStorage() }} - @else - / - @endif - - @can(Arcanesoft\Backups\Policies\StatusesPolicy::PERMISSION_SHOW) - {{ ui_link_icon('show', route('admin::backups.statuses.show', [$index])) }} - @endcan -
-
-
-
-@endsection - -@section('modals') - @can(Arcanesoft\Backups\Policies\StatusesPolicy::PERMISSION_CREATE) - - @endcan - - @can(Arcanesoft\Backups\Policies\StatusesPolicy::PERMISSION_DELETE) - - @endcan -@endsection - -@section('scripts') - {{-- RUN BACKUPS MODAL --}} - @can(Arcanesoft\Backups\Policies\StatusesPolicy::PERMISSION_CREATE) - - @endcan - - {{-- CLEAR BACKUPS MODAL --}} - @can(Arcanesoft\Backups\Policies\StatusesPolicy::PERMISSION_DELETE) - - @endcan -@endsection diff --git a/resources/views/admin/statuses/show.blade.php b/resources/views/admin/statuses/show.blade.php deleted file mode 100644 index 77e22cb..0000000 --- a/resources/views/admin/statuses/show.blade.php +++ /dev/null @@ -1,130 +0,0 @@ -@section('header') -

{{ trans('backups::statuses.titles.backups') }} {{ trans('backups::statuses.titles.monitor-status') }}

-@endsection - -@section('content') -
-
-
-
-

{{ trans('backups::statuses.titles.monitor-status') }}

-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{{ trans('backups::statuses.attributes.name') }} : - {{ $status->backupName() }} -
{{ trans('backups::statuses.attributes.disk') }} : - {{ $status->diskName() }} -
{{ trans('backups::statuses.attributes.reachable') }} : - @if ($status->isReachable()) - Yes - @else - No - @endif -
{{ trans('backups::statuses.attributes.healthy') }} : - @if ($status->isHealthy()) - Yes - @else - No - @endif -
{{ trans('backups::statuses.attributes.number_of_backups') }} : - @if ($status->isReachable()) - {{ label_count($status->amountOfBackups()) }} - @else - / - @endif -
{{ trans('backups::statuses.attributes.newest_backup') }} : - @if ($status->isReachable()) - {{ $status->dateOfNewestBackup() ?: 'null' }} - @else - / - @endif -
{{ trans('backups::statuses.attributes.used_storage') }} : - @if ($status->isReachable()) - {{ $status->humanReadableUsedStorage() }} - @else - / - @endif -
-
-
-
-
- -
-
-
-

{{ trans('backups::statuses.titles.backups') }}

-
-
-
- - - - - - - - - - @forelse ($backups as $backup) - - - - - - @empty - - - - @endforelse - -
{{ trans('backups::statuses.attributes.date') }}{{ trans('backups::statuses.attributes.path') }}{{ trans('backups::statuses.attributes.size') }}
- {{ $backup->date() }} - - {{ $backup->path() }} - - - {{ Spatie\Backup\Helpers\Format::humanReadableSize($backup->size()) }} - -
- There is no backups for the time being -
-
-
-
-
-
-@endsection - -@section('scripts') -@endsection diff --git a/src/BackupsServiceProvider.php b/src/BackupsServiceProvider.php index 9fcab48..6687dcd 100644 --- a/src/BackupsServiceProvider.php +++ b/src/BackupsServiceProvider.php @@ -1,6 +1,11 @@ -registerConfig(); - $this->registerSidebarItems(); $this->registerProviders([ - Providers\PackagesServiceProvider::class, - Providers\AuthorizationServiceProvider::class, + Providers\AuthServiceProvider::class, Providers\RouteServiceProvider::class, ]); - $this->registerConsoleServiceProvider(Providers\CommandServiceProvider::class); + + $this->registerCommands([ + PublishCommand::class, + ]); } /** * Boot the service provider. */ - public function boot() + public function boot(): void { - parent::boot(); - - // Publishes - $this->publishConfig(); - $this->publishViews(); - $this->publishTranslations(); - $this->publishSidebarItems(); - } + $this->loadTranslations(); + $this->loadViews(); - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return [ - // - ]; + if ($this->app->runningInConsole()) { + $this->publishConfig(); + $this->publishTranslations(); + $this->publishViews(); + } } } diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php index 35aad9b..f2cc400 100644 --- a/src/Console/InstallCommand.php +++ b/src/Console/InstallCommand.php @@ -1,7 +1,11 @@ -call('db:seed', ['--class' => DatabaseSeeder::class]); + $this->seed(DatabaseSeeder::class); } } diff --git a/src/Console/PublishCommand.php b/src/Console/PublishCommand.php index 2ea8923..d06adcf 100644 --- a/src/Console/PublishCommand.php +++ b/src/Console/PublishCommand.php @@ -1,7 +1,11 @@ - + */ +class DatabaseSeeder extends Seeder +{ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- + */ + + /** + * Get the seeders. + * + * @return array + */ + public function seeders(): array + { + return [ + PermissionsSeeder::class, + RolesSeeder::class, + ]; + } +} diff --git a/src/Database/Seeders/PermissionsSeeder.php b/src/Database/Seeders/PermissionsSeeder.php new file mode 100644 index 0000000..7eb5f6a --- /dev/null +++ b/src/Database/Seeders/PermissionsSeeder.php @@ -0,0 +1,33 @@ + + */ +class PermissionsSeeder extends Seeder +{ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- + */ + + /** + * Run the database seeds. + */ + public function run(): void + { + $this->seed([ + 'name' => 'Backups', + 'slug' => 'backups', + 'description' => 'backups permissions group', + ], $this->getPermissionsFromPolicyManager('admin::backups.')); + } +} diff --git a/src/Seeds/RolesTableSeeder.php b/src/Database/Seeders/RolesSeeder.php similarity index 53% rename from src/Seeds/RolesTableSeeder.php rename to src/Database/Seeders/RolesSeeder.php index f434437..106d7df 100644 --- a/src/Seeds/RolesTableSeeder.php +++ b/src/Database/Seeders/RolesSeeder.php @@ -1,14 +1,18 @@ - */ -class RolesTableSeeder extends RolesSeeder +class RolesSeeder extends Seeder { /* ----------------------------------------------------------------- | Main Methods @@ -18,9 +22,9 @@ class RolesTableSeeder extends RolesSeeder /** * Run the database seeds. */ - public function run() + public function run(): void { - $this->seed([ + $this->seedMany([ [ 'name' => 'Backups Manager', 'description' => 'The Backups manager role.', @@ -28,9 +32,10 @@ public function run() ], ]); - $this->syncAdminRole(); - $this->syncRoles([ - 'backups-manager' => 'backups.', + $this->syncRolesWithPermissions([ + 'backups-manager' => [ + 'admin::backups.*', + ], ]); } } diff --git a/src/Http/Controllers/Admin/Controller.php b/src/Http/Controllers/Admin/Controller.php deleted file mode 100644 index ba57ea7..0000000 --- a/src/Http/Controllers/Admin/Controller.php +++ /dev/null @@ -1,32 +0,0 @@ - - */ -abstract class Controller extends AdminController -{ - /* ----------------------------------------------------------------- - | Traits - | ----------------------------------------------------------------- - */ - - use Notifyable; - - /* ----------------------------------------------------------------- - | Properties - | ----------------------------------------------------------------- - */ - - /** - * The view namespace. - * - * @var string - */ - protected $viewNamespace = 'backups'; -} diff --git a/src/Http/Controllers/Controller.php b/src/Http/Controllers/Controller.php new file mode 100644 index 0000000..1755de3 --- /dev/null +++ b/src/Http/Controllers/Controller.php @@ -0,0 +1,26 @@ + + */ +abstract class Controller extends BaseController +{ + /* ----------------------------------------------------------------- + | Properties + | ----------------------------------------------------------------- + */ + + /** + * The view namespace. + * + * @var string + */ + protected $viewNamespace = 'backups'; +} diff --git a/src/Http/Controllers/Admin/StatusesController.php b/src/Http/Controllers/StatusesController.php similarity index 50% rename from src/Http/Controllers/Admin/StatusesController.php rename to src/Http/Controllers/StatusesController.php index d064078..9ad6450 100644 --- a/src/Http/Controllers/Admin/StatusesController.php +++ b/src/Http/Controllers/StatusesController.php @@ -1,14 +1,18 @@ - */ class StatusesController extends Controller @@ -18,7 +22,15 @@ class StatusesController extends Controller | ----------------------------------------------------------------- */ - use JsonResponses; + use HasNotifications; + + /* ----------------------------------------------------------------- + | Properties + | ----------------------------------------------------------------- + */ + + /** @var \Arcanesoft\Backups\Services\BackupService */ + protected $backupService; /* ----------------------------------------------------------------- | Constructor @@ -28,12 +40,14 @@ class StatusesController extends Controller /** * StatusesController constructor. */ - public function __construct() + public function __construct(BackupService $backupService) { parent::__construct(); - $this->setCurrentPage('backups-statuses'); - $this->addBreadcrumbRoute(trans('backups::statuses.titles.backups'), 'admin::backups.statuses.index'); + $this->setCurrentSidebarItem('foundation::backups'); + $this->addBreadcrumbRoute(__('Backups'), 'admin::backups.statuses.index'); + + $this->backupService = $backupService; } /* ----------------------------------------------------------------- @@ -43,55 +57,56 @@ public function __construct() public function index() { - $this->authorize(StatusesPolicy::PERMISSION_LIST); + $this->authorize(StatusesPolicy::ability('index')); - $statuses = BackupStatuses::all(); + $statuses = $this->backupService->statuses(); - $this->setTitle($title = trans('backups::statuses.titles.monitor-statuses-list')); + $this->setTitle($title = __('List of Monitor Statuses')); $this->addBreadcrumb($title); - return $this->view('admin.statuses.index', compact('statuses')); + return $this->view('statuses.index', compact('statuses')); } public function show($index) { - $this->authorize(StatusesPolicy::PERMISSION_SHOW); + $this->authorize(StatusesPolicy::ability('show')); - if (is_null($status = BackupStatuses::getStatus($index))) - self::pageNotFound(); + $status = $this->backupService->getStatus($index); - $backups = $status->backupDestination()->backups(); + abort_if(is_null($status), 404); - $this->setTitle($title = trans('backups::statuses.titles.monitor-status')); + $this->setTitle($title = __('Monitor Status')); $this->addBreadcrumb($title); - return $this->view('admin.statuses.show', compact('status', 'backups')); + return $this->view('statuses.show', compact('status')); } public function backup() { - $this->authorize(StatusesPolicy::PERMISSION_CREATE); + $this->authorize(StatusesPolicy::ability('create')); - if (BackupStatuses::runBackups()) { - return $this->jsonResponseSuccess([ + if ($this->backupService->runBackups()) { + return static::jsonResponseSuccess([ 'message' => $this->transNotification('created'), ]); } - return $this->jsonResponseError(['message' => 'There is an error while running the backups.']); + return static::jsonResponseError([ + 'message' => 'There is an error while running the backups.' + ]); } public function clear() { - $this->authorize(StatusesPolicy::PERMISSION_DELETE); + $this->authorize(StatusesPolicy::ability('clean')); - if (BackupStatuses::clearBackups()) { - return $this->jsonResponseSuccess([ + if ($this->backupService->clearBackups()) { + return static::jsonResponseSuccess([ 'message' => $this->transNotification('cleared'), ]); } - return $this->jsonResponseError(['message' => 'There is an error while running the backups.']); + return static::jsonResponseError(['message' => 'There is an error while running the backups.']); } /* ----------------------------------------------------------------- @@ -114,7 +129,7 @@ protected function transNotification($action, array $replace = [], array $contex $message = trans("backups::statuses.messages.{$action}.message", $replace); Log::info($message, $context); - $this->notifySuccess($message, $title); + static::notifySuccess($title, $message); return $message; } diff --git a/src/Http/Routes/AbstractRouteRegistrar.php b/src/Http/Routes/AbstractRouteRegistrar.php new file mode 100644 index 0000000..57c50ad --- /dev/null +++ b/src/Http/Routes/AbstractRouteRegistrar.php @@ -0,0 +1,34 @@ + + */ +abstract class AbstractRouteRegistrar extends AdminRouteRegistrar +{ + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- + */ + + /** + * Group routes under a module stack. + * + * @param \Closure $callback + */ + protected function moduleGroup(Closure $callback): void + { + $this->prefix('backups') + ->name('backups.') + ->group($callback); + } +} diff --git a/src/Http/Routes/StatusesRoutes.php b/src/Http/Routes/StatusesRoutes.php index 418cf5d..8400013 100644 --- a/src/Http/Routes/StatusesRoutes.php +++ b/src/Http/Routes/StatusesRoutes.php @@ -1,6 +1,10 @@ - */ -class StatusesRoutes extends RouteRegistrar +class StatusesRoutes extends AbstractRouteRegistrar { /* ----------------------------------------------------------------- | Main Methods @@ -18,22 +22,28 @@ class StatusesRoutes extends RouteRegistrar /** * Map the routes for the application. */ - public function map() + public function map(): void { - $this->prefix('statuses')->as('statuses.')->group(function () { - $this->get('/', 'StatusesController@index') - ->name('index'); // admin::backups.statuses.index + $this->adminGroup(function () { + $this->prefix('statuses')->as('statuses.')->group(function () { + // admin::backups.statuses.index + $this->get('/', [StatusesController::class, 'index']) + ->name('index'); - $this->post('backup', 'StatusesController@backup') - ->middleware('ajax') - ->name('backup'); // admin::backups.statuses.backup + // admin::backups.statuses.backup + $this->post('backup', [StatusesController::class, 'backup']) + ->middleware(['ajax']) + ->name('backup'); - $this->post('clear', 'StatusesController@clear') - ->middleware('ajax') - ->name('clear'); // admin::backups.statuses.clear + // admin::backups.statuses.clear + $this->post('clear', [StatusesController::class, 'clear']) + ->middleware(['ajax']) + ->name('clear'); - $this->get('{index}', 'StatusesController@show') - ->name('show'); // admin::backups.statuses.clear + // admin::backups.statuses.clear + $this->get('{index}', [StatusesController::class, 'show']) + ->name('show'); + }); }); } } diff --git a/src/Policies/StatusesPolicy.php b/src/Policies/StatusesPolicy.php index 754c66e..6675b23 100644 --- a/src/Policies/StatusesPolicy.php +++ b/src/Policies/StatusesPolicy.php @@ -1,7 +1,11 @@ -setMetas([ + 'category' => 'Statuses', + ]); + + return [ + + // admin::backups.statuses.index + $this->makeAbility('index')->setMetas([ + 'name' => 'Show all backup statuses', + 'description' => 'Ability to list all backup statuses', + ]), + + // admin::backups.statuses.show + $this->makeAbility('show')->setMetas([ + 'name' => 'Show a backup status', + 'description' => 'Ability to show a backup status', + ]), + + // admin::backups.statuses.create + $this->makeAbility('create')->setMetas([ + 'name' => 'Create a backup', + 'description' => 'Ability to create a backup', + ]), + + // admin::backups.statuses.clean + $this->makeAbility('clean')->setMetas([ + 'name' => 'Clean backups', + 'description' => 'Ability to clean old backups', + ]), + + ]; + } /* ----------------------------------------------------------------- | Abilities @@ -29,48 +83,48 @@ class StatusesPolicy extends Policy /** * Allow to list all the backups. * - * @param \Arcanesoft\Contracts\Auth\Models\User $user + * @param \Arcanesoft\Foundation\Auth\Models\Administrator|mixed $administrator * - * @return bool + * @return \Illuminate\Auth\Access\Response|bool|void */ - public function listPolicy(User $user) + public function index(Administrator $administrator) { - return $user->may(static::PERMISSION_LIST); + // } /** * Allow to display a backup. * - * @param \Arcanesoft\Contracts\Auth\Models\User $user + * @param \Arcanesoft\Foundation\Auth\Models\Administrator|mixed $administrator * - * @return bool + * @return \Illuminate\Auth\Access\Response|bool|void */ - public function showPolicy(User $user) + public function show(Administrator $administrator) { - return $user->may(static::PERMISSION_SHOW); + // } /** * Allow to create a backup. * - * @param \Arcanesoft\Contracts\Auth\Models\User $user + * @param \Arcanesoft\Foundation\Auth\Models\Administrator|mixed $administrator * - * @return bool + * @return \Illuminate\Auth\Access\Response|bool|void */ - public function createPolicy(User $user) + public function create(Administrator $administrator) { - return $user->may(static::PERMISSION_CREATE); + // } /** - * Allow to delete a backup. + * Allow to clean backups. * - * @param \Arcanesoft\Contracts\Auth\Models\User $user + * @param \Arcanesoft\Foundation\Auth\Models\Administrator|mixed $administrator * - * @return bool + * @return \Illuminate\Auth\Access\Response|bool|void */ - public function deletePolicy(User $user) + public function clean(Administrator $administrator) { - return $user->may(static::PERMISSION_DELETE); + // } } diff --git a/src/Providers/AuthServiceProvider.php b/src/Providers/AuthServiceProvider.php new file mode 100644 index 0000000..1b1537c --- /dev/null +++ b/src/Providers/AuthServiceProvider.php @@ -0,0 +1,31 @@ + + */ +class AuthServiceProvider extends ServiceProvider +{ + /* ----------------------------------------------------------------- + | Getters + | ----------------------------------------------------------------- + */ + + /** + * Get policy's classes. + * + * @return iterable + */ + public function policyClasses(): iterable + { + return $this->app->get('config')->get('arcanesoft.backups.policies', []); + } +} diff --git a/src/Providers/AuthorizationServiceProvider.php b/src/Providers/AuthorizationServiceProvider.php deleted file mode 100644 index b73898f..0000000 --- a/src/Providers/AuthorizationServiceProvider.php +++ /dev/null @@ -1,28 +0,0 @@ - - */ -class AuthorizationServiceProvider extends ServiceProvider -{ - /* ----------------------------------------------------------------- - | Main Methods - | ----------------------------------------------------------------- - */ - - /** - * Register any application authentication / authorization services. - */ - public function boot() - { - parent::registerPolicies(); - - $this->defineMany(StatusesPolicy::class, StatusesPolicy::policies()); - } -} diff --git a/src/Providers/CommandServiceProvider.php b/src/Providers/CommandServiceProvider.php deleted file mode 100644 index 4e8e73c..0000000 --- a/src/Providers/CommandServiceProvider.php +++ /dev/null @@ -1,29 +0,0 @@ - - */ -class CommandServiceProvider extends ServiceProvider -{ - /* ----------------------------------------------------------------- - | Properties - | ----------------------------------------------------------------- - */ - - /** - * The commands to be registered. - * - * @var array - */ - protected $commands = [ - InstallCommand::class, - PublishCommand::class, - ]; -} diff --git a/src/Providers/PackagesServiceProvider.php b/src/Providers/PackagesServiceProvider.php deleted file mode 100644 index 836a65d..0000000 --- a/src/Providers/PackagesServiceProvider.php +++ /dev/null @@ -1,40 +0,0 @@ - - */ -class PackagesServiceProvider extends ServiceProvider -{ - /* ----------------------------------------------------------------- - | Main Methods - | ----------------------------------------------------------------- - */ - - /** - * Register the service provider. - */ - public function register() - { - parent::register(); - - $this->registerSpatieBackupPackage(); - } - - /* ----------------------------------------------------------------- - | Other Methods - | ----------------------------------------------------------------- - */ - - /** - * Register Spatie backup package. - */ - private function registerSpatieBackupPackage() - { - $this->registerProvider(\Spatie\Backup\BackupServiceProvider::class); - } -} diff --git a/src/Providers/RouteServiceProvider.php b/src/Providers/RouteServiceProvider.php index 557b5ff..745ec3b 100644 --- a/src/Providers/RouteServiceProvider.php +++ b/src/Providers/RouteServiceProvider.php @@ -1,7 +1,11 @@ -adminGroup(function () { - $this->mapAdminRoutes(); - }); - } - - /** - * Define the admin routes for the application. + * Get the registered routes. + * + * @return array */ - private function mapAdminRoutes() + public function routeClasses(): array { - $this->name('backups.') - ->prefix($this->config()->get('arcanesoft.backups.route.prefix', 'backups')) - ->group(function () { - Routes\StatusesRoutes::register(); - }); + return [ + Routes\StatusesRoutes::class + ]; } } diff --git a/src/Seeds/DatabaseSeeder.php b/src/Seeds/DatabaseSeeder.php deleted file mode 100644 index 2fd46b4..0000000 --- a/src/Seeds/DatabaseSeeder.php +++ /dev/null @@ -1,27 +0,0 @@ - - */ -class DatabaseSeeder extends Seeder -{ - /* ----------------------------------------------------------------- - | Properties - | ----------------------------------------------------------------- - */ - - /** - * Seeders collection. - * - * @var array - */ - protected $seeds = [ - PermissionsTableSeeder::class, - RolesTableSeeder::class, - ]; -} diff --git a/src/Seeds/PermissionsTableSeeder.php b/src/Seeds/PermissionsTableSeeder.php deleted file mode 100644 index 972cbc0..0000000 --- a/src/Seeds/PermissionsTableSeeder.php +++ /dev/null @@ -1,73 +0,0 @@ - - */ -class PermissionsTableSeeder extends PermissionsSeeder -{ - /* ----------------------------------------------------------------- - | Main Methods - | ----------------------------------------------------------------- - */ - - /** - * Run the database seeds. - */ - public function run() - { - $this->seed([ - [ - 'group' => [ - 'name' => 'Backups', - 'slug' => 'backups', - 'description' => 'backups permissions group', - ], - 'permissions' => array_merge( - $this->getStatusesPermissions() - ), - ], - ]); - } - - /* ----------------------------------------------------------------- - | Other Methods - | ----------------------------------------------------------------- - */ - - /** - * Get the Statuses permissions. - * - * @return array - */ - private function getStatusesPermissions() - { - return [ - [ - 'name' => 'Statuses - List all backups', - 'description' => 'Allow to list all posts.', - 'slug' => StatusesPolicy::PERMISSION_LIST, - ], - [ - 'name' => 'Statuses - View a backup', - 'description' => 'Allow to display a post.', - 'slug' => StatusesPolicy::PERMISSION_SHOW, - ], - [ - 'name' => 'Statuses - Create a backup', - 'description' => 'Allow to create a post.', - 'slug' => StatusesPolicy::PERMISSION_CREATE, - ], - [ - 'name' => 'Statuses - Delete a backup', - 'description' => 'Allow to delete a post.', - 'slug' => StatusesPolicy::PERMISSION_DELETE, - ], - ]; - } -} diff --git a/src/Services/BackupService.php b/src/Services/BackupService.php new file mode 100644 index 0000000..d413726 --- /dev/null +++ b/src/Services/BackupService.php @@ -0,0 +1,113 @@ + + */ +class BackupService +{ + /* ----------------------------------------------------------------- + | Properties + | ----------------------------------------------------------------- + */ + + /** @var \Arcanedev\LaravelBackup\Actions\Backup\BackupAction */ + protected $backupAction; + + /** @var \Arcanedev\LaravelBackup\Actions\Cleanup\CleanAction */ + protected $cleanAction; + + /* ----------------------------------------------------------------- + | Constructor + | ----------------------------------------------------------------- + */ + + /** + * BackupService constructor. + * + * @param \Arcanedev\LaravelBackup\Actions\Backup\BackupAction $backupAction + * @param \Arcanedev\LaravelBackup\Actions\Cleanup\CleanAction $cleanAction + */ + public function __construct(BackupAction $backupAction, CleanAction $cleanAction) + { + $this->backupAction = $backupAction; + $this->cleanAction = $cleanAction; + } + + /* ----------------------------------------------------------------- + | Main Methods + | ----------------------------------------------------------------- + */ + + /** + * Get all the statuses. + * + * @return \Arcanedev\LaravelBackup\Entities\BackupDestinationStatus[]|\Arcanedev\LaravelBackup\Entities\BackupDestinationStatusCollection + */ + public function statuses(): BackupDestinationStatusCollection + { + return BackupDestinationStatusCollection::makeFromConfig(); + } + + /** + * Get a status by index. + * + * @param int $index + * + * @return \Spatie\Backup\Tasks\Monitor\BackupDestinationStatus|null + */ + public function getStatus($index): ?BackupDestinationStatus + { + return $this->statuses()->get($index); + } + + /** + * Run the backups. + * + * @param string|null $disk + * + * @return bool + */ + public function runBackups($disk = null): bool + { + try { + $this->backupAction->execute([ + // + ]); + + return true; + } + catch (\Exception $ex) { + return false; + } + } + + /** + * Clean the backups. + * + * @return bool + */ + public function clearBackups(): bool + { + try { + $this->cleanAction->execute([ + // + ]); + + return true; + } + catch (\Exception $ex) { + return false; + } + } +} diff --git a/src/Services/BackupStatuses.php b/src/Services/BackupStatuses.php deleted file mode 100644 index 79e30f7..0000000 --- a/src/Services/BackupStatuses.php +++ /dev/null @@ -1,92 +0,0 @@ - - */ -class BackupStatuses -{ - /* ----------------------------------------------------------------- - | Main Methods - | ----------------------------------------------------------------- - */ - - /** - * Get all the statuses. - * - * @return \Illuminate\Support\Collection - */ - public static function all() - { - return BackupDestinationStatusFactory::createForMonitorConfig(config('laravel-backup.monitorBackups')); - } - - /** - * Get a status by index. - * - * @param int $index - * - * @return \Spatie\Backup\Tasks\Monitor\BackupDestinationStatus|null - */ - public static function getStatus($index) - { - return static::all()->get($index); - } - - /** - * Run the backups. - * - * @param string|null $disk - * - * @return bool - */ - public static function runBackups($disk = null) - { - try { - $backupJob = BackupJobFactory::createFromArray(config('laravel-backup')); - - if ( ! is_null($disk)) { - $backupJob->onlyBackupTo($disk); - } - - $backupJob->run(); - } - catch (\Exception $ex) { - return false; - } - - return true; - } - - /** - * Clean the backups. - * - * @return bool - */ - public static function clearBackups() - { - try { - $config = config('laravel-backup'); - - $backupDestinations = BackupDestinationFactory::createFromArray($config['backup']); - - $strategy = app($config['cleanup']['strategy']); - - $disableNotification = false; // TODO: Create a config for this - - (new CleanupJob($backupDestinations, $strategy, $disableNotification))->run(); - } - catch (\Exception $ex) { - return false; - } - - return true; - } -} diff --git a/tests/Feature/.gitkeep b/tests/Feature/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/Unit/.gitkeep b/tests/Unit/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/translations/fr.json b/translations/fr.json new file mode 100644 index 0000000..b3f78a2 --- /dev/null +++ b/translations/fr.json @@ -0,0 +1,10 @@ +{ + "Backups": "Sauvegardes", + "Monitor Statuses": "Surveiller les états", + "List of Monitor Statuses": "Liste des états du moniteur", + "Disk": "Disque", + "Reachable": "Accessible", + "Healthy": "Sain", + "Newest Backup": "Dernière sauvegarde", + "Used Storage": "Stockage utilisé" +} diff --git a/views/statuses/index.blade.php b/views/statuses/index.blade.php new file mode 100644 index 0000000..cc54ab8 --- /dev/null +++ b/views/statuses/index.blade.php @@ -0,0 +1,223 @@ +@extends(arcanesoft\foundation()->template()) + +@section('page-title') + @lang('Backups') +@endsection + +@section('content') +
+
+
+ @lang('Monitor Statuses') +
+ @can(Arcanesoft\Backups\Policies\StatusesPolicy::ability('create')) + + @lang('Run Backup') + + @endcan + + @can(Arcanesoft\Backups\Policies\StatusesPolicy::ability('delete')) + + @endcan +
+
+
+ + + + + + + + + + + + + + + @forelse($statuses as $index => $status) + backupDestination() + ?> + + + + + + + + + + + @empty + @endforelse + +
@lang('Disk')@lang('Name')@lang('Reachable')@lang('Healthy')@lang('Backups')@lang('Newest Backup')@lang('Used Storage')@lang('Actions')
{{ $destination->diskName() }}{{ $destination->backupName() }} + @if ($destination->isReachable()) + @lang('Yes') + @else + @lang('No') + @endif + + @if ($status->isHealthy()) + @lang('Yes') + @else + @lang('No') + @endif + + @if ($destination->isReachable()) + {{ arcanesoft\ui\count_pill($destination->backups()->count()) }} + @else + - + @endif + + @if ($destination->isReachable() && $destination->newestBackup()) + {{ $destination->newestBackup()->date()->diffForHumans() ?: 'No backups present' }} + @else + - + @endif + + {{ $destination->isReachable() ? $destination->humanReadableUsedStorage() : '-' }} + + @can(Arcanesoft\Backups\Policies\StatusesPolicy::ability('show')) + {{ arcanesoft\ui\action_link_icon('show', route('admin::backups.statuses.show', [$index]))->size('sm') }} + @endcan +
+
+@endsection + +{{-- CREATE BACKUP MODAL/SCRIPT --}} +@can(Arcanesoft\Backups\Policies\StatusesPolicy::ability('create')) + @push('modals') + + @endpush + + @push('scripts') + + @endpush +@endcan + + +@can(Arcanesoft\Backups\Policies\StatusesPolicy::ability('delete')) + @push('modals') + + @endpush + + @push('scripts') + + @endpush +@endcan diff --git a/views/statuses/show.blade.php b/views/statuses/show.blade.php new file mode 100644 index 0000000..f63ecef --- /dev/null +++ b/views/statuses/show.blade.php @@ -0,0 +1,128 @@ +@extends(arcanesoft\foundation()->template()) + +@section('page-title') + @lang('Backups') +@endsection + +backupDestination() +?> + +@section('content') +
+
+
+
@lang('Monitor Status')
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
@lang('Name') : + {{ $destination->backupName() }} +
@lang('Disk') : + {{ $destination->diskName() }} +
@lang('Reachable') : + @if ($destination->isReachable()) + @lang('Yes') + @else + @lang('No') + @endif +
@lang('Healthy') : + @if ($status->isHealthy()) + @lang('Yes') + @else + @lang('No') + @endif +
@lang('Backups') : + @if ($destination->isReachable()) + {{ arcanesoft\ui\count_pill($destination->backups()->count()) }} + @else + - + @endif +
@lang('Newest Backup') : + @if ($destination->isReachable() && $destination->newestBackup()) + {{ $destination->newestBackup()->date()->diffForHumans() ?: 'null' }} + @else + - + @endif +
@lang('Used Storage') : + + {{ $destination->isReachable() ? $destination->humanReadableUsedStorage() : '-' }} + +
+
+
+ +
+
+
+ @lang('Backups') +
+
+
+ + + + + + + + + + @forelse ($destination->backups() as $backup) + + + + + + + @empty + + + + @endforelse + +
@lang('Date')@lang('Path')@lang('Size')
+ {{ $backup->date() }} + + {{ $backup->path() }} + + + {{ $backup->humanReadableSize() }} + +
There is no backups for the time being
+
+
+
+
+
+@endsection + +@section('scripts') +@endsection From f852d787fd5785c1e96a76de32a1eb06b853f58d Mon Sep 17 00:00:00 2001 From: ARCANEDEV Date: Wed, 21 Oct 2020 11:39:30 +0100 Subject: [PATCH 2/5] WIP --- .gitattributes | 22 +-- .gitignore | 4 +- .travis.yml | 28 ---- LICENSE.md | 2 +- composer.json | 7 + src/BackupsServiceProvider.php | 1 - src/Console/InstallCommand.php | 1 - src/Console/PublishCommand.php | 1 - src/Database/DatabaseSeeder.php | 1 - src/Database/Seeders/PermissionsSeeder.php | 1 - src/Database/Seeders/RolesSeeder.php | 1 - src/Http/Controllers/Controller.php | 3 +- src/Http/Controllers/StatusesController.php | 4 +- src/Policies/StatusesPolicy.php | 1 - src/Providers/AuthServiceProvider.php | 3 +- src/Providers/RouteServiceProvider.php | 1 - src/Services/BackupService.php | 18 ++- tests/TestCase.php | 7 +- .../{ => Unit}/BackupsServiceProviderTest.php | 8 +- views/statuses/index.blade.php | 126 ++++++++--------- views/statuses/show.blade.php | 131 ++++++++---------- 21 files changed, 173 insertions(+), 198 deletions(-) delete mode 100644 .travis.yml rename tests/{ => Unit}/BackupsServiceProviderTest.php (94%) diff --git a/.gitattributes b/.gitattributes index c8d6ba3..2b7b41d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,9 +1,13 @@ -/_docs export-ignore -/tests export-ignore -/.editorconfig export-ignore -/.gitattributes export-ignore -/.gitignore export-ignore -/.scrutinizer.yml export-ignore -/.travis.yml export-ignore -/CONTRIBUTING.md export-ignore -/phpunit.xml.dist export-ignore +* text=auto + +/.github export-ignore +/_docs export-ignore +/tests export-ignore +.editorconfig export-ignore +.gitattributes export-ignore +.gitignore export-ignore +.scrutinizer.yml export-ignore +.travis.yml export-ignore +phpcs.xml.dist export-ignore +phpunit.xml.dist export-ignore +CONTRIBUTING.md export-ignore diff --git a/.gitignore b/.gitignore index 697e972..8c59329 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /build/ /vendor/ -composer.lock -composer.phar +/composer.phar +/composer.lock diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 03a87c5..0000000 --- a/.travis.yml +++ /dev/null @@ -1,28 +0,0 @@ -language: php - -sudo: false - -php: - - 7.0 - - 7.1 - - nightly - -matrix: - allow_failures: - - php: nightly - -env: - - TESTBENCH_VERSION=3.5.* - -before_script: - - travis_retry composer self-update - - travis_retry composer require --prefer-source --no-interaction --dev "orchestra/testbench:${TESTBENCH_VERSION}" - -script: - - composer validate - - mkdir -p build/logs - - vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover - -after_script: - - if [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi - - if [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi diff --git a/LICENSE.md b/LICENSE.md index 8ec448c..6e66795 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2017 | ARCANEDEV - Backups +Copyright (c) 2017-2020 | ARCANEDEV - Backups Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/composer.json b/composer.json index 5231c83..71f8d9a 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,14 @@ "Arcanesoft\\Backups\\Tests\\": "tests/" } }, + "scripts": { + "test": "phpunit", + "test:dox": "phpunit --testdox" + }, "extra": { + "branch-alias": { + "dev-develop": "4.x-dev" + }, "laravel": { "providers": [ "Arcanesoft\\Backups\\BackupsServiceProvider" diff --git a/src/BackupsServiceProvider.php b/src/BackupsServiceProvider.php index 6687dcd..df10bf4 100644 --- a/src/BackupsServiceProvider.php +++ b/src/BackupsServiceProvider.php @@ -10,7 +10,6 @@ /** * Class BackupsServiceProvider * - * @package Arcanesoft\Backups * @author ARCANEDEV */ class BackupsServiceProvider extends PackageServiceProvider diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php index f2cc400..ef80cd6 100644 --- a/src/Console/InstallCommand.php +++ b/src/Console/InstallCommand.php @@ -10,7 +10,6 @@ /** * Class InstallCommand * - * @package Arcanesoft\Backups\Console * @author ARCANEDEV */ class InstallCommand extends Command diff --git a/src/Console/PublishCommand.php b/src/Console/PublishCommand.php index d06adcf..3f1e6d6 100644 --- a/src/Console/PublishCommand.php +++ b/src/Console/PublishCommand.php @@ -10,7 +10,6 @@ /** * Class PublishCommand * - * @package Arcanesoft\Backups\Console * @author ARCANEDEV */ class PublishCommand extends Command diff --git a/src/Database/DatabaseSeeder.php b/src/Database/DatabaseSeeder.php index a301f2b..f9e9813 100644 --- a/src/Database/DatabaseSeeder.php +++ b/src/Database/DatabaseSeeder.php @@ -10,7 +10,6 @@ /** * Class DatabaseSeeder * - * @package Arcanesoft\Backups\Database * @author ARCANEDEV */ class DatabaseSeeder extends Seeder diff --git a/src/Database/Seeders/PermissionsSeeder.php b/src/Database/Seeders/PermissionsSeeder.php index 7eb5f6a..789abb7 100644 --- a/src/Database/Seeders/PermissionsSeeder.php +++ b/src/Database/Seeders/PermissionsSeeder.php @@ -9,7 +9,6 @@ /** * Class PermissionsSeeder * - * @package Arcanesoft\Backups\Database\Seeders * @author ARCANEDEV */ class PermissionsSeeder extends Seeder diff --git a/src/Database/Seeders/RolesSeeder.php b/src/Database/Seeders/RolesSeeder.php index 106d7df..752a98c 100644 --- a/src/Database/Seeders/RolesSeeder.php +++ b/src/Database/Seeders/RolesSeeder.php @@ -9,7 +9,6 @@ /** * Class RolesSeeder * - * @package Arcanesoft\Backups\Database\Seeders * @author ARCANEDEV */ class RolesSeeder extends Seeder diff --git a/src/Http/Controllers/Controller.php b/src/Http/Controllers/Controller.php index 1755de3..9bb6613 100644 --- a/src/Http/Controllers/Controller.php +++ b/src/Http/Controllers/Controller.php @@ -1,5 +1,7 @@ */ abstract class Controller extends BaseController diff --git a/src/Http/Controllers/StatusesController.php b/src/Http/Controllers/StatusesController.php index 9ad6450..152686f 100644 --- a/src/Http/Controllers/StatusesController.php +++ b/src/Http/Controllers/StatusesController.php @@ -12,7 +12,6 @@ /** * Class StatusesController * - * @package Arcanesoft\Backups\Http\Controllers * @author ARCANEDEV */ class StatusesController extends Controller @@ -129,7 +128,8 @@ protected function transNotification($action, array $replace = [], array $contex $message = trans("backups::statuses.messages.{$action}.message", $replace); Log::info($message, $context); - static::notifySuccess($title, $message); + + $this->notifySuccess($title, $message); return $message; } diff --git a/src/Policies/StatusesPolicy.php b/src/Policies/StatusesPolicy.php index 6675b23..f6f0e46 100644 --- a/src/Policies/StatusesPolicy.php +++ b/src/Policies/StatusesPolicy.php @@ -10,7 +10,6 @@ /** * Class StatusesPolicy * - * @package Arcanesoft\Backups\Policies * @author ARCANEDEV */ class StatusesPolicy extends Policy diff --git a/src/Providers/AuthServiceProvider.php b/src/Providers/AuthServiceProvider.php index 1b1537c..d0e28a7 100644 --- a/src/Providers/AuthServiceProvider.php +++ b/src/Providers/AuthServiceProvider.php @@ -7,9 +7,8 @@ use Arcanesoft\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; /** - * Class AuthorizationServiceProvider + * Class AuthServiceProvider * - * @package Arcanesoft\Backups\Providers * @author ARCANEDEV */ class AuthServiceProvider extends ServiceProvider diff --git a/src/Providers/RouteServiceProvider.php b/src/Providers/RouteServiceProvider.php index 745ec3b..8d02204 100644 --- a/src/Providers/RouteServiceProvider.php +++ b/src/Providers/RouteServiceProvider.php @@ -10,7 +10,6 @@ /** * Class RouteServiceProvider * - * @package Arcanesoft\Backups\Providers * @author ARCANEDEV */ class RouteServiceProvider extends ServiceProvider diff --git a/src/Services/BackupService.php b/src/Services/BackupService.php index d413726..e6ef195 100644 --- a/src/Services/BackupService.php +++ b/src/Services/BackupService.php @@ -9,9 +9,8 @@ use Arcanedev\LaravelBackup\Entities\{BackupDestinationStatus, BackupDestinationStatusCollection}; /** - * Class BackupStatuses + * Class BackupService * - * @package Arcanesoft\Backups\Services * @author ARCANEDEV */ class BackupService @@ -64,7 +63,7 @@ public function statuses(): BackupDestinationStatusCollection * * @param int $index * - * @return \Spatie\Backup\Tasks\Monitor\BackupDestinationStatus|null + * @return \Arcanedev\LaravelBackup\Entities\BackupDestinationStatus|null */ public function getStatus($index): ?BackupDestinationStatus { @@ -80,10 +79,17 @@ public function getStatus($index): ?BackupDestinationStatus */ public function runBackups($disk = null): bool { + $options = [ + 'filename' => null, + 'only-db' => false, + 'db-name' => [], + 'only-files' => false, + 'only-to-disk' => $disk, + 'disable-notifications' => false, + ]; + try { - $this->backupAction->execute([ - // - ]); + $this->backupAction->execute($options); return true; } diff --git a/tests/TestCase.php b/tests/TestCase.php index 52df8a2..3720a80 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,11 +1,14 @@ - */ abstract class TestCase extends BaseTestCase diff --git a/tests/BackupsServiceProviderTest.php b/tests/Unit/BackupsServiceProviderTest.php similarity index 94% rename from tests/BackupsServiceProviderTest.php rename to tests/Unit/BackupsServiceProviderTest.php index 13cdf6a..4e2bc78 100644 --- a/tests/BackupsServiceProviderTest.php +++ b/tests/Unit/BackupsServiceProviderTest.php @@ -1,11 +1,15 @@ - */ class BackupsServiceProviderTest extends TestCase diff --git a/views/statuses/index.blade.php b/views/statuses/index.blade.php index cc54ab8..b6b32f1 100644 --- a/views/statuses/index.blade.php +++ b/views/statuses/index.blade.php @@ -5,36 +5,36 @@ @endsection @section('content') -
-
+ +
@lang('Monitor Statuses')
@can(Arcanesoft\Backups\Policies\StatusesPolicy::ability('create')) - + @lang('Run Backup') @endcan @can(Arcanesoft\Backups\Policies\StatusesPolicy::ability('delete')) - @endcan
-
- + + - - - - - - - - + @lang('Disk') + @lang('Name') + @lang('Reachable') + @lang('Healthy') + @lang('Backups') + @lang('Newest Backup') + @lang('Used Storage') + @lang('Actions') @@ -44,100 +44,99 @@ $destination = $status->backupDestination() ?> - - - + + - - - - @empty @endforelse -
@lang('Disk')@lang('Name')@lang('Reachable')@lang('Healthy')@lang('Backups')@lang('Newest Backup')@lang('Used Storage')@lang('Actions')
{{ $destination->diskName() }}{{ $destination->backupName() }} + {{ $destination->diskName() }}{{ $destination->backupName() }} @if ($destination->isReachable()) - @lang('Yes') + @lang('Yes') @else - @lang('No') + @lang('No') @endif + @if ($status->isHealthy()) - @lang('Yes') + @lang('Yes') @else - @lang('No') + @lang('No') @endif + @if ($destination->isReachable()) {{ arcanesoft\ui\count_pill($destination->backups()->count()) }} @else - - + - @endif + @if ($destination->isReachable() && $destination->newestBackup()) - {{ $destination->newestBackup()->date()->diffForHumans() ?: 'No backups present' }} + {{ $destination->newestBackup()->date()->diffForHumans() ?: 'No backups present' }} @else - - + - @endif - {{ $destination->isReachable() ? $destination->humanReadableUsedStorage() : '-' }} + + {{ $destination->isReachable() ? $destination->humanReadableUsedStorage() : '-' }} @can(Arcanesoft\Backups\Policies\StatusesPolicy::ability('show')) - {{ arcanesoft\ui\action_link_icon('show', route('admin::backups.statuses.show', [$index]))->size('sm') }} + + + @endcan
-
+ + @endsection {{-- CREATE BACKUP MODAL/SCRIPT --}} @can(Arcanesoft\Backups\Policies\StatusesPolicy::ability('create')) @push('modals') - + + {{ form()->open(['route' => 'admin::backups.statuses.backup', 'method' => 'POST', 'id' => 'run-backups-form', 'autocomplete' => 'off']) }} + + + @lang('Run Backup') + + + + @lang('Are you sure you want to run the backup ?') + + + + + + {{ form()->close() }} + @endpush @push('scripts') @endpush @@ -158,65 +130,32 @@ class="btn btn-sm btn-light" data-toggle="tooltip" title="@lang('Show')"> @can(Arcanesoft\Backups\Policies\StatusesPolicy::ability('delete')) @push('modals') - + + + + @lang('Cleanup Backups') + + @lang('Are you sure you want to cleanup the backups ?') + + + + + + @endpush @push('scripts') - @endpush diff --git a/views/statuses/show.blade.php b/views/statuses/show.blade.php index cc76a6a..f15ba1b 100644 --- a/views/statuses/show.blade.php +++ b/views/statuses/show.blade.php @@ -16,15 +16,15 @@ @lang('Monitor Status') - @lang('Name') + {{ $destination->backupName() }} - @lang('Disk') + {{ $destination->diskName() }} - @lang('Reachable') + @if ($destination->isReachable()) @lang('Yes') @@ -34,7 +34,7 @@ - @lang('Healthy') + @if ($status->isHealthy()) @lang('Yes') @@ -44,17 +44,17 @@ - @lang('Backups') + @if ($destination->isReachable()) - {{ arcanesoft\ui\count_pill($destination->backups()->count()) }} + @else - @endif - @lang('Newest Backup') + @if ($destination->isReachable() && $destination->newestBackup()) {{ $destination->newestBackup()->date()->diffForHumans() ?: 'null' }} @@ -64,7 +64,7 @@ - @lang('Used Storage') + {{ $destination->isReachable() ? $destination->humanReadableUsedStorage() : '-' }} @@ -80,9 +80,9 @@ - @lang('Date') - @lang('Path') - @lang('Size') + + + @@ -110,6 +110,3 @@ @endsection - -@section('scripts') -@endsection From 2b1870f1c3d6924966e132d28abc99ccb864d452 Mon Sep 17 00:00:00 2001 From: ARCANEDEV Date: Tue, 8 Jun 2021 20:23:34 +0100 Subject: [PATCH 4/5] WIP --- composer.json | 7 ++++--- config/sidebar.php | 2 +- src/Policies/StatusesPolicy.php | 10 +++++----- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 71f8d9a..3f7b8fd 100644 --- a/composer.json +++ b/composer.json @@ -14,11 +14,12 @@ "type": "library", "license": "MIT", "require": { - "php": "^7.3", - "arcanedev/laravel-backup": "^3.0", - "arcanesoft/foundation": "@dev" + "php": "^7.3|^8.0", + "arcanedev/laravel-backup": "^3.2", + "arcanesoft/foundation": "^4.0" }, "require-dev": { + "orchestra/testbench-core": "^6.0", "phpunit/phpunit": "^9.3" }, "autoload": { diff --git a/config/sidebar.php b/config/sidebar.php index 3c83e0a..d043e5f 100644 --- a/config/sidebar.php +++ b/config/sidebar.php @@ -1,6 +1,6 @@ Date: Fri, 13 Aug 2021 14:56:13 +0100 Subject: [PATCH 5/5] WIP --- views/statuses/index.blade.php | 156 ++++++++++++++++----------------- views/statuses/show.blade.php | 48 +++++----- 2 files changed, 99 insertions(+), 105 deletions(-) diff --git a/views/statuses/index.blade.php b/views/statuses/index.blade.php index 3ecd16a..c055939 100644 --- a/views/statuses/index.blade.php +++ b/views/statuses/index.blade.php @@ -1,15 +1,13 @@ -@extends(arcanesoft\foundation()->template()) + + @section('page-title') + @lang('Backups') + @endsection -@section('page-title') - @lang('Backups') -@endsection - -@section('content')
@lang('Monitor Statuses') -
+
@can(Arcanesoft\Backups\Policies\StatusesPolicy::ability('create')) @lang('Run Backup') @@ -34,7 +32,7 @@ - + @@ -48,41 +46,39 @@ {{ $destination->backupName() }} @if ($destination->isReachable()) - @lang('Yes') + @else - @lang('No') + @endif @if ($status->isHealthy()) - @lang('Yes') + @else - @lang('No') + @endif @if ($destination->isReachable()) @else - - + @endif @if ($destination->isReachable() && $destination->newestBackup()) {{ $destination->newestBackup()->date()->diffForHumans() ?: 'No backups present' }} @else - - + @endif - {{ $destination->isReachable() ? $destination->humanReadableUsedStorage() : '-' }} + - + @can(Arcanesoft\Backups\Policies\StatusesPolicy::ability('show')) - - - + @endcan @@ -91,72 +87,72 @@ class="btn btn-sm btn-light" data-toggle="tooltip" title="@lang('Show')"> -@endsection -{{-- CREATE BACKUP MODAL/SCRIPT --}} -@can(Arcanesoft\Backups\Policies\StatusesPolicy::ability('create')) - @push('modals') - - - - @lang('Run Backup') - - @lang('Are you sure you want to run the backup ?') - - - - - - - @endpush + {{-- CREATE BACKUP MODAL/SCRIPT --}} + @can(Arcanesoft\Backups\Policies\StatusesPolicy::ability('create')) + @push('modals') + + + + @lang('Run Backup') + + @lang('Are you sure you want to run the backup ?') + + + + + + + @endpush - @push('scripts') - - @endpush -@endcan + runBackupsForm.onSubmit('POST', () => { + runBackupsModal.hide() + location.reload() + }) + + @endpush + @endcan -@can(Arcanesoft\Backups\Policies\StatusesPolicy::ability('delete')) - @push('modals') - - - - @lang('Cleanup Backups') - - @lang('Are you sure you want to cleanup the backups ?') - - - - - - - @endpush + @can(Arcanesoft\Backups\Policies\StatusesPolicy::ability('delete')) + @push('modals') + + + + @lang('Cleanup Backups') + + @lang('Are you sure you want to cleanup the backups ?') + + + + + + + @endpush - @push('scripts') - - @endpush -@endcan + clearBackupsForm.onSubmit('POST', () => { + clearBackupsModal.hide() + location.reload() + }) + + @endpush + @endcan + diff --git a/views/statuses/show.blade.php b/views/statuses/show.blade.php index f15ba1b..0f99fa7 100644 --- a/views/statuses/show.blade.php +++ b/views/statuses/show.blade.php @@ -1,15 +1,13 @@ -@extends(arcanesoft\foundation()->template()) - -@section('page-title') - @lang('Backups') -@endsection - backupDestination() ?> -@section('content') + + @section('page-title') + @lang('Backups') + @endsection +
@@ -17,56 +15,56 @@ - {{ $destination->backupName() }} + {{ $destination->backupName() }} - {{ $destination->diskName() }} + {{ $destination->diskName() }} - + @if ($destination->isReachable()) - @lang('Yes') + @else - @lang('No') + @endif - + @if ($status->isHealthy()) - @lang('Yes') + @else - @lang('No') + @endif - + @if ($destination->isReachable()) @else - - + @endif - + @if ($destination->isReachable() && $destination->newestBackup()) - {{ $destination->newestBackup()->date()->diffForHumans() ?: 'null' }} + {{ $destination->newestBackup()->date()->diffForHumans() ?: 'null' }} @else - - + @endif - - {{ $destination->isReachable() ? $destination->humanReadableUsedStorage() : '-' }} + + @@ -82,7 +80,7 @@ - + @@ -95,7 +93,7 @@ {{ $backup->path() }} - + {{ $backup->humanReadableSize() }} @@ -109,4 +107,4 @@
-@endsection +