Skip to content

Commit

Permalink
Merge pull request #1806 from spatie/v9-release
Browse files Browse the repository at this point in the history
V9 release
  • Loading branch information
Nielsvanpach authored Jul 2, 2024
2 parents d859659 + 5d82d66 commit f4d54cd
Show file tree
Hide file tree
Showing 96 changed files with 1,048 additions and 366 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: [8.3, 8.2, 8.1]
php: [8.3, 8.2]
laravel: [11.*, 10.*]
stability: [prefer-lowest, prefer-stable]
carbon: [^2.63]
Expand All @@ -26,9 +26,6 @@ jobs:
testbench: 8.*
- laravel: 11.*
testbench: 9.*
exclude:
- laravel: 11.*
php: 8.1

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ composer.lock
vendor
.phpunit.result.cache
.php-cs-fixer.cache
.phpunit.cache
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ We highly appreciate you sending us a postcard from your hometown, mentioning wh

## Installation and usage

This package requires PHP 8.0 and Laravel 8.0 or higher.
This package requires PHP 8.2 and Laravel 10.0 or higher.
You'll find installation instructions and full documentation on https://spatie.be/docs/laravel-backup.

## Using an older version of PHP / Laravel?
Expand Down
3 changes: 2 additions & 1 deletion UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## From v8 to v9

- (All keys in the config file are still snake_cased. Rename any camelCased keys to their snake_cased counterparts)
- Ensure your config/backup.php file is in sync with the latest settings. You can copy paste the missing defaults from this [config file](https://github.com/spatie/laravel-backup/blob/main/config/backup.php).
- All keys in the config file are still snake_cased. Rename any camelCased keys to their snake_cased counterparts

## From v7 to v8

Expand Down
15 changes: 9 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"require": {
"php": "^8.1",
"php": "^8.2",
"ext-zip": "^1.14.0",
"illuminate/console": "^10.10.0|^11.0",
"illuminate/contracts": "^10.10.0|^11.0",
Expand All @@ -32,10 +32,10 @@
"spatie/laravel-signal-aware-command": "^1.2|^2.0",
"spatie/temporary-directory": "^2.0",
"symfony/console": "^6.0|^7.0",
"symfony/finder": "^6.0|^7.0"
"symfony/finder": "^6.0|^7.0",
"ext-pcntl": "*"
},
"require-dev": {
"ext-pcntl": "*",
"composer-runtime-api": "^2.0",
"larastan/larastan": "^2.7.0",
"laravel/slack-notification-channel": "^2.5|^3.0",
Expand All @@ -45,7 +45,8 @@
"pestphp/pest": "^1.20|^2.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.1"
"phpstan/phpstan-phpunit": "^1.1",
"rector/rector": "^1.1"
},
"autoload": {
"psr-4": {
Expand All @@ -61,9 +62,11 @@
}
},
"scripts": {
"test": "vendor/bin/pest",
"test": "vendor/bin/pest --compact",
"format": "vendor/bin/php-cs-fixer fix --allow-risky=yes",
"analyse": "vendor/bin/phpstan analyse"
"analyse": "vendor/bin/phpstan analyse",
"rector": "vendor/bin/rector --dry-run",
"baseline": "./vendor/bin/phpstan analyse --generate-baseline --memory-limit=2G"
},
"suggest": {
"laravel/slack-notification-channel": "Required for sending notifications via Slack"
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Requirements
weight: 3
---

This backup package requires **PHP 8.0**, with the [ZIP module](http://php.net/manual/en/book.zip.php) and **Laravel 9.0 or higher**. It's not compatible with Windows servers.
This backup package requires **PHP 8.2**, with the [ZIP module](http://php.net/manual/en/book.zip.php) and **Laravel 9.0 or higher**. It's not compatible with Windows servers.

If you are using an older version of Laravel, take a look at one of the previous versions of this package.

Expand Down
2 changes: 1 addition & 1 deletion docs/sending-notifications/customizing-the-notifiable.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BackupNotifiable extends Notifiable
{
public function routeNotificationForAnotherNotificationChannel()
{
return config('backup.notifications.another_notification_channel.property');
return $this->config()->notifications->another_notification_channel->property;
}
}

Expand Down
49 changes: 49 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,2 +1,51 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#1 \\$callback of method Illuminate\\\\Support\\\\Collection\\<int,Spatie\\\\Backup\\\\BackupDestination\\\\Backup\\>\\:\\:filter\\(\\) expects \\(callable\\(Spatie\\\\Backup\\\\BackupDestination\\\\Backup, int\\)\\: bool\\)\\|null, Closure\\(string\\)\\: bool given\\.$#"
count: 1
path: src/BackupDestination/BackupCollection.php

-
message: "#^Parameter \\#1 \\$callback of method Illuminate\\\\Support\\\\Collection\\<int,Spatie\\\\Backup\\\\BackupDestination\\\\Backup\\>\\:\\:map\\(\\) expects callable\\(Spatie\\\\Backup\\\\BackupDestination\\\\Backup, int\\)\\: Spatie\\\\Backup\\\\BackupDestination\\\\Backup, Closure\\(string\\)\\: Spatie\\\\Backup\\\\BackupDestination\\\\Backup given\\.$#"
count: 1
path: src/BackupDestination/BackupCollection.php

-
message: "#^Parameter \\#1 \\$callback of method Illuminate\\\\Support\\\\Collection\\<int,int\\>\\:\\:map\\(\\) expects callable\\(int, int\\)\\: string, Closure\\(string\\)\\: non\\-falsy\\-string given\\.$#"
count: 1
path: src/Exceptions/CannotCreateDbDumper.php

-
message: "#^Method Spatie\\\\Backup\\\\Notifications\\\\Channels\\\\Discord\\\\DiscordMessage\\:\\:toArray\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Notifications/Channels/Discord/DiscordMessage.php

-
message: "#^Method Spatie\\\\Backup\\\\Tasks\\\\Backup\\\\FileSelection\\:\\:sanitize\\(\\) return type with generic class Illuminate\\\\Support\\\\Collection does not specify its types\\: TKey, TValue$#"
count: 1
path: src/Tasks/Backup/FileSelection.php

-
message: "#^Method Spatie\\\\Backup\\\\Tasks\\\\Backup\\\\Manifest\\:\\:files\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Tasks/Backup/Manifest.php

-
message: "#^Method Spatie\\\\Backup\\\\Tasks\\\\Backup\\\\Manifest\\:\\:files\\(\\) return type has no value type specified in iterable type array\\|Generator\\.$#"
count: 1
path: src/Tasks/Backup/Manifest.php

-
message: "#^Method Spatie\\\\Backup\\\\Tasks\\\\Backup\\\\Zip\\:\\:add\\(\\) has parameter \\$files with no value type specified in iterable type iterable\\.$#"
count: 1
path: src/Tasks/Backup/Zip.php

-
message: "#^Parameter \\#1 \\$callback of method Illuminate\\\\Support\\\\Collection\\<int,Spatie\\\\Backup\\\\BackupDestination\\\\Backup\\>\\:\\:each\\(\\) expects callable\\(Spatie\\\\Backup\\\\BackupDestination\\\\Backup, int\\)\\: mixed, Closure\\(Spatie\\\\Backup\\\\BackupDestination\\\\BackupCollection\\)\\: void given\\.$#"
count: 1
path: src/Tasks/Cleanup/Strategies/DefaultStrategy.php

-
message: "#^Parameter \\#1 \\$callback of method Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\),Spatie\\\\Backup\\\\Config\\\\MonitoredBackupConfig\\>\\:\\:flatMap\\(\\) expects callable\\(Spatie\\\\Backup\\\\Config\\\\MonitoredBackupConfig, int\\|string\\)\\: \\(array\\<int, Spatie\\\\Backup\\\\Tasks\\\\Monitor\\\\BackupDestinationStatus\\>\\|Illuminate\\\\Support\\\\Collection\\<int, Spatie\\\\Backup\\\\Tasks\\\\Monitor\\\\BackupDestinationStatus\\>\\), Closure\\(array\\)\\: Illuminate\\\\Support\\\\Collection\\<int, Spatie\\\\Backup\\\\Tasks\\\\Monitor\\\\BackupDestinationStatus\\> given\\.$#"
count: 1
path: src/Tasks/Monitor/BackupDestinationStatusFactory.php
4 changes: 2 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ includes:
- phpstan-baseline.neon

parameters:
level: 5
level: 6
paths:
- src
- config
tmpDir: build/phpstan
checkOctaneCompatibility: true
checkModelProperties: true
checkMissingIterableValueType: false
treatPhpDocTypesAsCertain: false

ignoreErrors:
- '#Unsafe usage of new static#'
22 changes: 16 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
backupGlobals="false"
colors="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
>
<testsuites>
<testsuite name="Spatie Test Suite">
<directory>tests</directory>
Expand All @@ -13,4 +18,9 @@
<php>
<env name="APP_NAME" value="mysite"/>
</php>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
38 changes: 38 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\ClassMethod\OptionalParametersAfterRequiredRector;
use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector;
use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
use Rector\CodingStyle\Rector\ArrowFunction\StaticArrowFunctionRector;
use Rector\CodingStyle\Rector\Closure\StaticClosureRector;
use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
use Rector\CodingStyle\Rector\If_\NullableCompareToNullRector;
use Rector\CodingStyle\Rector\Plus\UseIncrementAssignRector;
use Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector;
use Rector\Config\RectorConfig;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\TypeDeclaration\Rector\ArrowFunction\AddArrowFunctionReturnTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector;
use Rector\TypeDeclaration\Rector\Closure\AddClosureVoidReturnTypeWhereNoReturnRector;

return RectorConfig::configure()
->withPaths(['config', 'resources', 'src'])
->withPhpSets(php81: true)
->withPreparedSets(deadCode: true, codingStyle: true, typeDeclarations: true)
->withSkip([
ReturnNeverTypeRector::class,
OptionalParametersAfterRequiredRector::class,
ClosureToArrowFunctionRector::class,
FlipTypeControlToUseExclusiveTypeRector::class,
ExplicitBoolCompareRector::class,
EncapsedStringsToSprintfRector::class,
StaticClosureRector::class,
StaticArrowFunctionRector::class,
UseIncrementAssignRector::class,
PostIncDecToPreIncDecRector::class,
NullableCompareToNullRector::class,
AddArrowFunctionReturnTypeRector::class,
AddClosureVoidReturnTypeWhereNoReturnRector::class,
]);
14 changes: 7 additions & 7 deletions resources/lang/fr/notifications.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

return [
'exception_message' => 'Message de l\'exception : :message',
'exception_trace' => 'Trace de l\'exception : :trace',
'exception_message_title' => 'Message de l\'exception',
'exception_trace_title' => 'Trace de l\'exception',
'exception_message' => "Message de l'exception : :message",
'exception_trace' => "Trace de l'exception : :trace",
'exception_message_title' => "Message de l'exception",
'exception_trace_title' => "Trace de l'exception",

'backup_failed_subject' => 'Échec de la sauvegarde de :application_name',
'backup_failed_body' => 'Important : Une erreur est survenue lors de la sauvegarde de :application_name',
Expand All @@ -27,14 +27,14 @@
'unhealthy_backup_found_subject' => 'Important : Les sauvegardes pour :application_name sont corrompues',
'unhealthy_backup_found_subject_title' => 'Important : Les sauvegardes pour :application_name sont corrompues. :problem',
'unhealthy_backup_found_body' => 'Les sauvegardes pour :application_name sur le disque :disk_name sont corrompues.',
'unhealthy_backup_found_not_reachable' => 'La destination de la sauvegarde n\'est pas accessible. :error',
'unhealthy_backup_found_empty' => 'Il n\'y a aucune sauvegarde pour cette application.',
'unhealthy_backup_found_not_reachable' => "La destination de la sauvegarde n'est pas accessible. :error",
'unhealthy_backup_found_empty' => "Il n'y a aucune sauvegarde pour cette application.",
'unhealthy_backup_found_old' => 'La dernière sauvegarde du :date est considérée trop vieille.',
'unhealthy_backup_found_unknown' => 'Désolé, une raison exacte ne peut être déterminée.',
'unhealthy_backup_found_full' => 'Les sauvegardes utilisent trop d\'espace disque. L\'utilisation actuelle est de :disk_usage alors que la limite autorisée est de :disk_limit.',

'no_backups_info' => 'Aucune sauvegarde n\'a encore été effectuée',
'application_name' => 'Nom de l\'application',
'application_name' => "Nom de l'application",
'backup_name' => 'Nom de la sauvegarde',
'disk' => 'Disque',
'newest_backup_size' => 'Taille de la sauvegarde la plus récente',
Expand Down
10 changes: 5 additions & 5 deletions resources/lang/it/notifications.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

return [
'exception_message' => 'Messaggio dell\'eccezione: :message',
'exception_trace' => 'Traccia dell\'eccezione: :trace',
'exception_message_title' => 'Messaggio dell\'eccezione',
'exception_trace_title' => 'Traccia dell\'eccezione',
'exception_message' => "Messaggio dell'eccezione: :message",
'exception_trace' => "Traccia dell'eccezione: :trace",
'exception_message_title' => "Messaggio dell'eccezione",
'exception_trace_title' => "Traccia dell'eccezione",

'backup_failed_subject' => 'Fallito il backup di :application_name',
'backup_failed_body' => 'Importante: Si è verificato un errore durante il backup di :application_name',
Expand Down Expand Up @@ -34,7 +34,7 @@
'unhealthy_backup_found_full' => 'I backup utilizzano troppa memoria. L\'utilizzo corrente è :disk_usage che è superiore al limite consentito di :disk_limit.',

'no_backups_info' => 'Non sono stati ancora effettuati backup',
'application_name' => 'Nome dell\'applicazione',
'application_name' => "Nome dell'applicazione",
'backup_name' => 'Nome di backup',
'disk' => 'Disco',
'newest_backup_size' => 'Dimensione backup più recente',
Expand Down
1 change: 1 addition & 0 deletions src/BackupDestination/Backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function sizeInBytes(): float
return $this->size;
}

/** @return resource */
public function stream()
{
return throw_unless(
Expand Down
4 changes: 3 additions & 1 deletion src/BackupDestination/BackupCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
use Illuminate\Support\Collection;
use Spatie\Backup\Helpers\File;

/** @extends Collection<int,Backup> */
class BackupCollection extends Collection
{
protected ?float $sizeCache = null;

/** @param array<string> $files */
public static function createFromFiles(?FileSystem $disk, array $files): self
{
return (new static($files))
->filter(fn (string $path) => (new File())->isZipFile($disk, $path))
->map(fn (string $path) => new Backup($disk, $path))
->map(fn (string $path): \Spatie\Backup\BackupDestination\Backup => new Backup($disk, $path))
->sortByDesc(fn (Backup $backup) => $backup->date()->timestamp)
->values();
}
Expand Down
18 changes: 3 additions & 15 deletions src/BackupDestination/BackupDestination.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,11 @@

class BackupDestination
{
protected ?Filesystem $disk;

protected string $diskName;

protected string $backupName;

public ?Exception $connectionError = null;

protected ?BackupCollection $backupCollectionCache = null;

public function __construct(Filesystem $disk = null, string $backupName, string $diskName)
{
$this->disk = $disk;

$this->diskName = $diskName;

$this->backupName = $backupName;
}
public function __construct(protected ?Filesystem $disk, protected string $backupName, protected string $diskName) {}

public function disk(): Filesystem
{
Expand All @@ -49,7 +36,7 @@ public function filesystemType(): string

$filesystemType = last(explode('\\', $adapterClass));

return strtolower($filesystemType);
return strtolower((string) $filesystemType);
}

public static function create(string $diskName, string $backupName): self
Expand Down Expand Up @@ -125,6 +112,7 @@ public function connectionError(): Exception
return $this->connectionError;
}

/** @return array<string, string> */
public function getDiskOptions(): array
{
return config("filesystems.disks.{$this->diskName()}.backup_options") ?? [];
Expand Down
10 changes: 7 additions & 3 deletions src/BackupDestination/BackupDestinationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
namespace Spatie\Backup\BackupDestination;

use Illuminate\Support\Collection;
use Spatie\Backup\Config\Config;

class BackupDestinationFactory
{
public static function createFromArray(array $config): Collection
/**
* @return Collection<int, BackupDestination>
*/
public static function createFromArray(Config $config): Collection
{
return collect($config['destination']['disks'])
->map(fn ($filesystemName) => BackupDestination::create($filesystemName, $config['name']));
return collect($config->backup->destination->disks)
->map(fn (string $filesystemName) => BackupDestination::create($filesystemName, $config->backup->name));
}
}
Loading

0 comments on commit f4d54cd

Please sign in to comment.