Skip to content

Commit

Permalink
Add Artisan command for installing the package.
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-mironchik committed Jan 11, 2020
1 parent 4fd356c commit 5a0c111
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 44 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

All notable changes to `laravel-backup-panel` will be documented in this file

## 1.3.0 - 2020-01-11

- add Artisan command for installing the package

## 1.2.0 - 2020-01-09

- resemble look and functionality of Spatie's Laravel Nova Backup tool
Expand Down
62 changes: 19 additions & 43 deletions README.md
Expand Up @@ -3,11 +3,13 @@
[![Latest Version on Packagist](https://img.shields.io/packagist/v/pavel-mironchik/laravel-backup-panel.svg?style=flat-square)](https://packagist.org/packages/pavel-mironchik/laravel-backup-panel)
[![Build Status](https://img.shields.io/travis/pavel-mironchik/laravel-backup-panel/master.svg?style=flat-square)](https://travis-ci.org/pavel-mironchik/laravel-backup-panel)
[![Quality Score](https://img.shields.io/scrutinizer/g/pavel-mironchik/laravel-backup-panel.svg?style=flat-square)](https://scrutinizer-ci.com/g/pavel-mironchik/laravel-backup-panel)
[![StyleCI](https://github.styleci.io/repos/231844000/shield?branch=master)](https://github.styleci.io/repos/231844000)
[![Total Downloads](https://img.shields.io/packagist/dt/pavel-mironchik/laravel-backup-panel.svg?style=flat-square)](https://packagist.org/packages/pavel-mironchik/laravel-backup-panel)

Laravel Backup Panel provides a dashboard for [spatie/laravel-backup](https://github.com/spatie/laravel-backup) package.
It lets you:
- check health of your backups
- create a backup (full | only database | only files)
- check the health of your backups
- list all backups
- download a backup
- delete a backup
Expand All @@ -26,50 +28,40 @@ Make sure you meet [the requirements for installing spatie/laravel-backup](https

First you must install [spatie/laravel-backup](https://docs.spatie.be/laravel-backup) into your Laravel app.
The installation instructions are [here](https://docs.spatie.be/laravel-backup/v6/installation-and-setup).
When successfull running `php artisan backup:run` on the terminal should create a backup and `php artisan backup:list` should return a list with an overview of all backup disks.
When successful, running `php artisan backup:run` on the terminal should create a backup and `php artisan backup:list` should return a list with an overview of all backup disks.

You can install the package via composer:
You may use composer to install Laravel Backup Panel into your project:

```bash
$ composer require pavel-mironchik/laravel-backup-panel
```

Then publish assets:
After installing, publish it resources using provided Artisan command:

```bash
$ php artisan vendor:publish --tag=laravel-backup-panel-assets
$ php artisan laravel-backup-panel:install
```

By default, you will only be able to access the dashboard in the `local` environment.
To change that:
This will place assets into `public/laravel_backup_panel` directory, add config file `config/laravel_backup_panel.php`, and register service provider `app/Providers/LaravelBackupPanelServiceProvider.php`.

### Upgrading

1. Publish the `LaravelBackupPanelServiceProvider`
When upgrading the package, do not forget to re-publish assets:

```bash
$ php artisan vendor:publish --tag=laravel-backup-panel-provider
$ php artisan vendor:publish --tag=laravel-backup-panel-assets --force
```

2. Add it to the list of application providers in your `app.php` file (anywhere below `EventServiceProvider`)

```php
'providers' => [

...
## Configuration

/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\LaravelBackupPanelServiceProvider::class,
Laravel Backup Panel exposes a dashboard at `/backup`. Change it in `config/laravel_backup_panel.php` file:

...
],
```php
'path' => 'backup',
```

3. Modify authorization gate in your provider
By default, you will only be able to access the dashboard in the `local` environment.
To change that, modify authorization gate in the `app/Providers/LaravelBackupPanelServiceProvider.php`:

```php
/**
Expand All @@ -83,28 +75,12 @@ protected function gate()
{
Gate::define('viewLaravelBackupPanel', function ($user) {
return in_array($user->email, [
'admin@your-site.com'
'admin@your-site.com',
]);
});
}
```

### Upgrading

When upgrading the package, do not forget to re-publish assets:

```bash
$ php artisan vendor:publish --tag=laravel-backup-panel-assets --force
```

## Configuration

Default value of the URI path where Laravel Backup Panel will be accessible from is `backup`. To change it you must publish config file:

```bash
$ php artisan vendor:publish --tag=laravel-backup-panel-config
```

## Usage

Open `http://your-site/backup`. You'll see a dashboard and controls to use.
Expand Down
3 changes: 2 additions & 1 deletion TODO.md
Expand Up @@ -4,6 +4,7 @@
- Allow to restore a backup (not certainly)
- Add tests
- Provide an output for backup command
- Artisan commands for installing/upgrading the package
- Realtime updates (using events and websockets)
- Allow to change settings of spatie/laravel-backup package from interface - add/remove disks, etc. (not certainly)
- Test spatie/laravel-backup settings
- Refactoring :)
80 changes: 80 additions & 0 deletions src/Console/InstallCommand.php
@@ -0,0 +1,80 @@
<?php

namespace PavelMironchik\LaravelBackupPanel\Console;

use Illuminate\Console\Command;
use Illuminate\Console\DetectsApplicationNamespace;
use Illuminate\Support\Str;

class InstallCommand extends Command
{
use DetectsApplicationNamespace;

/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'laravel-backup-panel:install';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Install all of the Laravel Backup Panel resources';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->comment('Publishing Laravel Backup Panel service provider...');
$this->callSilent('vendor:publish', ['--tag' => 'laravel-backup-panel-provider']);

$this->comment('Publishing Laravel Backup Panel assets...');
$this->callSilent('vendor:publish', ['--tag' => 'laravel-backup-panel-assets']);

$this->comment('Publishing Laravel Backup Panel configuration...');
$this->callSilent('vendor:publish', ['--tag' => 'laravel-backup-panel-config']);

$this->registerServiceProvider();

$this->info('Laravel Backup Panel resources installed successfully.');
}

protected function registerServiceProvider()
{
$namespace = Str::replaceLast('\\', '', $this->getAppNamespace());

$appConfig = file_get_contents(config_path('app.php'));

if (Str::contains($appConfig, $namespace.'\\Providers\\LaravelBackupPanelServiceProvider::class')) {
return;
}

file_put_contents(config_path('app.php'), str_replace(
"{$namespace}\\Providers\EventServiceProvider::class,".PHP_EOL,
"{$namespace}\\Providers\EventServiceProvider::class,".PHP_EOL." {$namespace}\Providers\LaravelBackupPanelServiceProvider::class,".PHP_EOL,
$appConfig
));

file_put_contents(app_path('Providers/LaravelBackupPanelServiceProvider.php'), str_replace(
"namespace App\Providers;",
"namespace {$namespace}\Providers;",
file_get_contents(app_path('Providers/LaravelBackupPanelServiceProvider.php'))
));
}
}
4 changes: 4 additions & 0 deletions src/LaravelBackupPanelServiceProvider.php
Expand Up @@ -26,6 +26,10 @@ public function boot()
$this->publishes([
__DIR__.'/../stubs/LaravelBackupPanelServiceProvider.php.stub' => app_path('Providers/LaravelBackupPanelServiceProvider.php'),
], 'laravel-backup-panel-provider');

$this->commands([
Console\InstallCommand::class,
]);
}

Route::group([
Expand Down

0 comments on commit 5a0c111

Please sign in to comment.