Skip to content

Commit

Permalink
Merge pull request #2 from ARCANEDEV/develop
Browse files Browse the repository at this point in the history
WIP
  • Loading branch information
arcanedev-maroc authored Mar 8, 2020
2 parents a5f8760 + a2206e3 commit 5fef69c
Show file tree
Hide file tree
Showing 88 changed files with 2,317 additions and 432 deletions.
2 changes: 1 addition & 1 deletion .docker/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ RUN docker-php-ext-install \
COPY --from=composer /usr/bin/composer /usr/bin/composer

# Copy PHP config file
COPY config/php-dev.ini /usr/local/etc/php/php.ini
COPY config/php.ini /usr/local/etc/php/php.ini
File renamed without changes.
10 changes: 5 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://editorconfig.org

root = true

[*]
charset = utf-8
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2
15 changes: 15 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
* text=auto

/.docker export-ignore
/.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
CONTRIBUTING.md export-ignore
CODE_OF_CONDUCT.md export-ignore
docker-compose.yml export-ignore
phpunit.xml.dist export-ignore
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
build
/build
/vendor
/tests/temp/
composer.lock
vendor
.phpunit.result.cache
/tests/temp/
34 changes: 34 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
filter:
excluded_paths: [tests/*, vendor/*]

checks:
php:
code_rating: true
remove_extra_empty_lines: true
remove_php_closing_tag: true
remove_trailing_whitespace: true
fix_use_statements:
remove_unused: true
preserve_multiple: false
preserve_blanklines: true
order_alphabetically: true
fix_php_opening_tag: true
fix_linefeed: true
fix_line_ending: true
fix_identation_4spaces: true
fix_doc_comments: true

tools:
external_code_coverage:
timeout: 600
runs: 6
php_code_sniffer:
enabled: true
config:
standard: PSR2
filter:
paths: ['src']
php_loc:
enabled: true
php_cpd:
enabled: true
26 changes: 15 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@
"type": "library",
"license": "MIT",
"require": {
"php": ">=7.2.0",
"ext-json": "*",
"ext-zip": "*",
"arcanedev/support": "^5.0"
"php": "^7.2.0",
"ext-json": "*",
"ext-zip": "*",
"arcanedev/support": "^5.1.1",
"illuminate/pipeline": "^6.4.1",
"league/flysystem": "^1.0.49"
},
"require-dev": {
"laravel/slack-notification-channel": "^1.0",
"league/flysystem-aws-s3-v3": "^1.0",
"mockery/mockery": "^1.0",
"laravel/slack-notification-channel": "^2.0",
"league/flysystem-aws-s3-v3": "^1.0.1",
"mockery/mockery": "^1.3.1",
"orchestra/testbench": "^4.0",
"phpunit/phpcov": "^6.0",
"phpunit/phpunit": "^8.0"
"phpunit/phpunit": "^8.4|^9.0"
},
"autoload": {
"psr-4": {
Expand All @@ -40,8 +41,11 @@
"extra": {
"laravel": {
"providers": [
"Arcanedev\\LaravelBackup\\BackupServiceProvider"
"Arcanedev\\LaravelBackup\\BackupServiceProvider",
"Arcanedev\\LaravelBackup\\Providers\\DeferredServiceProvider"
]
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
92 changes: 91 additions & 1 deletion config/backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
*/

'destination' => [

'filename-prefix' => '',

'disks' => [
'local',
],

],

/* -----------------------------------------------------------------
Expand Down Expand Up @@ -49,6 +51,16 @@
],

'temporary-directory' => storage_path('app/_backup-temp'),

'tasks' => [
Arcanedev\LaravelBackup\Actions\Backup\Tasks\CheckOptions::class,
Arcanedev\LaravelBackup\Actions\Backup\Tasks\CheckBackupDestinations::class,
Arcanedev\LaravelBackup\Actions\Backup\Tasks\CreateTemporaryDirectory::class,
Arcanedev\LaravelBackup\Actions\Backup\Tasks\PrepareFilesToBackup::class,
Arcanedev\LaravelBackup\Actions\Backup\Tasks\CreateBackupFile::class,
Arcanedev\LaravelBackup\Actions\Backup\Tasks\MoveBackupToDisks::class,
],

],

/* -----------------------------------------------------------------
Expand Down Expand Up @@ -96,6 +108,11 @@
],
],

'tasks' => [
Arcanedev\LaravelBackup\Actions\Cleanup\Tasks\CheckBackupDestinations::class,
Arcanedev\LaravelBackup\Actions\Cleanup\Tasks\ApplyCleanupStrategy::class,
],

],

/* -----------------------------------------------------------------
Expand All @@ -104,6 +121,7 @@
*/

'monitor' => [

'destinations' => [
[
'name' => env('APP_NAME', 'laravel-backup'),
Expand All @@ -125,6 +143,11 @@
],
*/
],

'tasks' => [
Arcanedev\LaravelBackup\Actions\Monitor\Tasks\CheckBackupsHealth::class,
],

],

/* -----------------------------------------------------------------
Expand All @@ -133,7 +156,74 @@
*/

'notifications' => [
//

'supported' => [
Arcanedev\LaravelBackup\Notifications\BackupWasSuccessfulNotification::class => ['mail'],
Arcanedev\LaravelBackup\Notifications\BackupHasFailedNotification::class => ['mail'],

Arcanedev\LaravelBackup\Notifications\CleanupWasSuccessfulNotification::class => ['mail'],
Arcanedev\LaravelBackup\Notifications\CleanupHasFailedNotification::class => ['mail'],

Arcanedev\LaravelBackup\Notifications\HealthyBackupsWasFoundNotification::class => ['mail'],
Arcanedev\LaravelBackup\Notifications\UnhealthyBackupsWasFoundNotification::class => ['mail'],
],

/*
* Here you can specify the notifiable to which the notifications should be sent. The default
* notifiable will use the variables specified in this config file.
*/
'notifiable' => Arcanedev\LaravelBackup\Entities\Notifiable::class,

'mail' => [
'to' => '[email protected]',
'from' => [
'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
'name' => env('MAIL_FROM_NAME', 'Example'),
],
],

'slack' => [
'webhook_url' => '',

/* If this is set to null the default channel of the webhook will be used. */
'channel' => null,
'username' => null,
'icon' => null,
],

],

/* -----------------------------------------------------------------
| Events
| -----------------------------------------------------------------
*/

'events' => [

// Backup Action
Arcanedev\LaravelBackup\Events\BackupActionWasSuccessful::class => [
Arcanedev\LaravelBackup\Listeners\SendBackupWasSuccessfulNotification::class,
],
Arcanedev\LaravelBackup\Events\BackupActionHasFailed::class => [
Arcanedev\LaravelBackup\Listeners\SendBackupHasFailedNotification::class
],

// Cleanup Action
Arcanedev\LaravelBackup\Events\CleanupActionWasSuccessful::class => [
Arcanedev\LaravelBackup\Listeners\SendCleanupWasSuccessfulNotification::class
],
Arcanedev\LaravelBackup\Events\CleanupActionHasFailed::class => [
Arcanedev\LaravelBackup\Listeners\SendCleanupHasFailedNotification::class
],

// Monitor Action
Arcanedev\LaravelBackup\Events\HealthyBackupsWasFound::class => [
Arcanedev\LaravelBackup\Listeners\SendHealthyBackupWasFoundNotification::class
],
Arcanedev\LaravelBackup\Events\UnhealthyBackupsWasFound::class => [
Arcanedev\LaravelBackup\Listeners\SendUnhealthyBackupWasFoundNotification::class
],

],

];
34 changes: 31 additions & 3 deletions src/Actions/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,39 @@ abstract class Action extends Pipeline
*/

/**
* Run the task.
* Execute the action.
*
* @param array $options
*
* @return mixed
* @return \Arcanedev\LaravelBackup\Actions\Passable|mixed
*/
abstract public function run(array $options);
public function execute(array $options)
{
return $this
->send($this->makePassable($options))
->then(function (Passable $passable) {
return $this->handleOnSuccess($passable);
});
}

/**
* Make the passable.
*
* @param array $options
*
* @return \Arcanedev\LaravelBackup\Actions\Passable|mixed
*/
abstract protected function makePassable(array $options);

/**
* Handle the passable on success.
*
* @param \Arcanedev\LaravelBackup\Actions\Passable|mixed $passable
*
* @return \Arcanedev\LaravelBackup\Actions\Passable|mixed
*/
protected function handleOnSuccess($passable)
{
return $passable;
}
}
49 changes: 30 additions & 19 deletions src/Actions/Backup/BackupAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Arcanedev\LaravelBackup\Actions\Backup;

use Arcanedev\LaravelBackup\Actions\Action;
use Arcanedev\LaravelBackup\Events\BackupActionHasFailed;
use Arcanedev\LaravelBackup\Events\{BackupActionHasFailed, BackupActionWasSuccessful};
use Exception;

/**
Expand All @@ -28,39 +28,50 @@ class BackupAction extends Action
*/
protected function pipes(): array
{
return [
Tasks\CheckOptions::class,
Tasks\CheckBackupDestinations::class,
Tasks\CreateTemporaryDirectory::class,
Tasks\PrepareFilesToBackup::class,
Tasks\CreateBackupFile::class,
Tasks\MoveBackupToDisks::class,
Tasks\SendNotification::class,
];
return $this->container['config']['backup.backup.tasks'];
}

/* -----------------------------------------------------------------
| Other Methods
| -----------------------------------------------------------------
*/

/**
* Run the task.
* Make the passable object.
*
* @param array $options
*
* @return mixed
* @return \Arcanedev\LaravelBackup\Actions\Backup\BackupPassable
*/
public function run(array $options)
protected function makePassable(array $options): BackupPassable
{
$config = array_merge(
config('backup.backup', []), compact('options')
$options = array_merge(
config('backup.backup', []),
compact('options')
);

return $this->send(new BackupPassable($config))
->thenReturn();
return new BackupPassable($options);
}

/**
* Handle the passable on success.
*
* @param \Arcanedev\LaravelBackup\Actions\Backup\BackupPassable|mixed $passable
*
* @return \Arcanedev\LaravelBackup\Actions\Backup\BackupPassable|mixed
*/
protected function handleOnSuccess($passable)
{
event(new BackupActionWasSuccessful($passable));

return parent::handleOnSuccess($passable);
}

/**
* Handle the given exception.
*
* @param mixed $passable
* @param \Exception $e
* @param \Arcanedev\LaravelBackup\Actions\Backup\BackupPassable|mixed $passable
* @param \Exception $e
*
* @return mixed|void
*
Expand Down
Loading

0 comments on commit 5fef69c

Please sign in to comment.