Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding default implementation of TemporaryDirectory #1846

Merged
merged 5 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/BackupServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Spatie\Backup\Tasks\Cleanup\CleanupStrategy;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Spatie\TemporaryDirectory\TemporaryDirectory;

class BackupServiceProvider extends PackageServiceProvider
{
Expand Down Expand Up @@ -49,6 +50,7 @@ public function packageRegistered(): void
$this->app->singleton(ConsoleOutput::class);

$this->app->bind(CleanupStrategy::class, config('backup.cleanup.strategy'));
$this->app->bind('backup-temporary-project', fn () => new TemporaryDirectory(config('backup.temporary_directory') ?? storage_path('app/backup-temp')));

$this->registerDiscordChannel();

Expand Down
9 changes: 6 additions & 3 deletions src/Tasks/Backup/BackupJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Exception;
use Generator;
use Illuminate\Console\Command;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Support\Collection;
use Spatie\Backup\BackupDestination\BackupDestination;
use Spatie\Backup\Config\Config;
Expand Down Expand Up @@ -42,6 +43,9 @@ class BackupJob

protected bool $signals = true;

/**
* @throws BindingResolutionException
*/
public function __construct(protected Config $config)
{
$this
Expand All @@ -50,6 +54,7 @@ public function __construct(protected Config $config)
->setDefaultFilename();

$this->backupDestinations = new Collection;
$this->temporaryDirectory = app()->make('backup-temporary-project');
}

public function dontBackupFilesystem(): self
Expand Down Expand Up @@ -146,9 +151,7 @@ public function setBackupDestinations(Collection $backupDestinations): self
/** @throws Exception */
public function run(): void
{
$temporaryDirectoryPath = $this->config->backup->temporaryDirectory ?? storage_path('app/backup-temp');

$this->temporaryDirectory = (new TemporaryDirectory($temporaryDirectoryPath))
$this->temporaryDirectory
->name('temp')
->force()
->create()
Expand Down