Skip to content

Commit

Permalink
Remove contract and adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
jonerickson authored and freekmurze committed Jan 13, 2025
1 parent 1608698 commit b56beaa
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 34 deletions.
11 changes: 0 additions & 11 deletions src/Adapters/TemporaryDirectoryAdapter.php

This file was deleted.

4 changes: 1 addition & 3 deletions src/BackupServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
use Illuminate\Notifications\ChannelManager;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Notification;
use Spatie\Backup\Adapters\TemporaryDirectoryAdapter;
use Spatie\Backup\Commands\BackupCommand;
use Spatie\Backup\Commands\CleanupCommand;
use Spatie\Backup\Commands\ListCommand;
use Spatie\Backup\Commands\MonitorCommand;
use Spatie\Backup\Config\Config;
use Spatie\Backup\Contracts\TemporaryDirectory as TemporaryDirectoryContract;
use Spatie\Backup\Events\BackupZipWasCreated;
use Spatie\Backup\Helpers\ConsoleOutput;
use Spatie\Backup\Listeners\EncryptBackupArchive;
Expand Down Expand Up @@ -52,7 +50,7 @@ public function packageRegistered(): void
$this->app->singleton(ConsoleOutput::class);

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

$this->registerDiscordChannel();

Expand Down
5 changes: 2 additions & 3 deletions src/Commands/BackupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Exception;
use Illuminate\Contracts\Console\Isolatable;
use Spatie\Backup\Config\Config;
use Spatie\Backup\Contracts\TemporaryDirectory;
use Spatie\Backup\Events\BackupHasFailed;
use Spatie\Backup\Exceptions\BackupFailed;
use Spatie\Backup\Exceptions\InvalidCommand;
Expand All @@ -20,7 +19,7 @@ class BackupCommand extends BaseCommand implements Isolatable

protected $description = 'Run the backup.';

public function __construct(protected Config $config, protected TemporaryDirectory $temporaryDirectory)
public function __construct(protected Config $config)
{
parent::__construct();
}
Expand All @@ -38,7 +37,7 @@ public function handle(): int
try {
$this->guardAgainstInvalidOptions();

$backupJob = BackupJobFactory::createFromConfig($this->config, $this->temporaryDirectory);
$backupJob = BackupJobFactory::createFromConfig($this->config);

if ($this->option('only-db')) {
$backupJob->dontBackupFilesystem();
Expand Down
12 changes: 0 additions & 12 deletions src/Contracts/TemporaryDirectory.php

This file was deleted.

11 changes: 9 additions & 2 deletions src/Tasks/Backup/BackupJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
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;
use Spatie\Backup\Contracts\TemporaryDirectory;
use Spatie\Backup\Events\BackupManifestWasCreated;
use Spatie\Backup\Events\BackupWasSuccessful;
use Spatie\Backup\Events\BackupZipWasCreated;
Expand All @@ -21,13 +21,16 @@
use Spatie\DbDumper\Databases\Sqlite;
use Spatie\DbDumper\DbDumper;
use Spatie\SignalAwareCommand\Facades\Signal;
use Spatie\TemporaryDirectory\TemporaryDirectory;

class BackupJob
{
public const FILENAME_FORMAT = 'Y-m-d-H-i-s.\z\i\p';

protected FileSelection $fileSelection;

protected TemporaryDirectory $temporaryDirectory;

/** @var Collection<string, DbDumper> */
protected Collection $dbDumpers;

Expand All @@ -40,14 +43,18 @@ class BackupJob

protected bool $signals = true;

public function __construct(protected Config $config, protected TemporaryDirectory $temporaryDirectory)
/**
* @throws BindingResolutionException
*/
public function __construct(protected Config $config)
{
$this
->dontBackupFilesystem()
->dontBackupDatabases()
->setDefaultFilename();

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

public function dontBackupFilesystem(): self
Expand Down
5 changes: 2 additions & 3 deletions src/Tasks/Backup/BackupJobFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
use Spatie\Backup\BackupDestination\BackupDestinationFactory;
use Spatie\Backup\Config\Config;
use Spatie\Backup\Config\SourceFilesConfig;
use Spatie\Backup\Contracts\TemporaryDirectory;
use Spatie\DbDumper\DbDumper;

class BackupJobFactory
{
public static function createFromConfig(Config $config, TemporaryDirectory $temporaryDirectory): BackupJob
public static function createFromConfig(Config $config): BackupJob
{
return (new BackupJob($config, $temporaryDirectory))
return (new BackupJob($config))
->setFileSelection(static::createFileSelection($config->backup->source->files))
->setDbDumpers(static::createDbDumpers($config->backup->source->databases))
->setBackupDestinations(BackupDestinationFactory::createFromArray($config));
Expand Down

0 comments on commit b56beaa

Please sign in to comment.