Skip to content
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
3 changes: 2 additions & 1 deletion client/src/components/Backup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export default {
},
},
created() {
console.log(this.chunkSize)
// console.log(this.chunkSize)

window.backup = {
chunkSize: this.chunkSize
};
Expand Down
719 changes: 363 additions & 356 deletions composer.lock

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions src/Backuper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Itiden\Backup;

use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Pipeline;
use Itiden\Backup\Contracts\Repositories\BackupRepository;
Expand All @@ -29,7 +30,7 @@ public function __construct(
*
* @throws Exceptions\BackupFailed
*/
public function backup(): BackupDto
public function backup(?Authenticatable $user = null): BackupDto
Copy link

Copilot AI May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the backup method's docblock to include the optional 'user' parameter, reflecting the changes in how the user is passed and used.

Copilot uses AI. Check for mistakes.
{
$lock = $this->stateManager->getLock();

Expand Down Expand Up @@ -61,8 +62,6 @@ public function backup(): BackupDto

$metadata = static::addMetaFromZipToBackupMeta($temp_zip_path, $backup);

$user = auth()->user();

if ($user) {
$metadata->setCreatedBy($user);
}
Expand Down
16 changes: 10 additions & 6 deletions src/Http/Controllers/Api/RestoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@
namespace Itiden\Backup\Http\Controllers\Api;

use Illuminate\Container\Attributes\Authenticated;
use Illuminate\Contracts\Cache\Repository;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Http\JsonResponse;
use Itiden\Backup\Exceptions\ActionAlreadyInProgress;
use Itiden\Backup\Jobs\RestoreJob;
use Itiden\Backup\StateManager;
use Statamic\Contracts\Auth\User;

final readonly class RestoreController
{
public function __invoke(string $id, StateManager $stateManager, #[Authenticated] User $user): JsonResponse
{
$stateManager->dispatch(new RestoreJob($id, $user));
public function __invoke(
string $id,
StateManager $stateManager,
#[Authenticated] Authenticatable $user,
): JsonResponse {
$stateManager->dispatch(new RestoreJob(
id: $id,
user: $user,
));

return response()->json(['message' => __('statamic-backup::backup.restore.started')]);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Controllers/Api/StoreBackupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
namespace Itiden\Backup\Http\Controllers\Api;

use Illuminate\Container\Attributes\Authenticated;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Http\JsonResponse;
use Itiden\Backup\Jobs\BackupJob;
use Itiden\Backup\StateManager;
use Statamic\Contracts\Auth\User;

final readonly class StoreBackupController
{
public function __invoke(StateManager $stateManager, #[Authenticated] User $user): JsonResponse
public function __invoke(StateManager $stateManager, #[Authenticated] Authenticatable $user): JsonResponse
{
$stateManager->dispatch(new BackupJob($user));
$stateManager->dispatch(new BackupJob(user: $user));

return response()->json(['message' => __('statamic-backup::backup.backup_started')]);
}
Expand Down
8 changes: 3 additions & 5 deletions src/Jobs/BackupJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Itiden\Backup\Jobs;

use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Cache\Repository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Itiden\Backup\Backuper;
use Itiden\Backup\StateManager;
use Statamic\Contracts\Auth\User;

final class BackupJob implements ShouldQueue
{
Expand All @@ -19,17 +19,15 @@ final class BackupJob implements ShouldQueue
* Create a new job instance.
*/
public function __construct(
private User $user,
private Authenticatable $user,
) {}

/**
* Execute the job.
*/
public function handle(Backuper $backuper, Repository $cache): void
{
auth()->login($this->user); // ugly but it works;

$backuper->backup();
$backuper->backup(user: $this->user);

$cache->forget(StateManager::JOB_QUEUED_KEY);
}
Expand Down
11 changes: 6 additions & 5 deletions src/Jobs/RestoreJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Itiden\Backup\Jobs;

use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Cache\Repository;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Itiden\Backup\Restorer;
use Itiden\Backup\StateManager;
use Statamic\Contracts\Auth\User;

final class RestoreJob implements ShouldQueue
{
Expand All @@ -20,17 +20,18 @@ final class RestoreJob implements ShouldQueue
*/
public function __construct(
private string $id,
private User $user,
private Authenticatable $user,
) {}

/**
* Execute the job.
*/
public function handle(Restorer $backuper, Repository $cache): void
{
auth()->login($this->user); // ugly but it works;

$backuper->restoreFromId($this->id);
$backuper->restoreFromId(
id: $this->id,
user: $this->user,
);

$cache->forget(StateManager::JOB_QUEUED_KEY);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Restorer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Itiden\Backup;

use Exception;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Pipeline;
Expand All @@ -30,23 +31,23 @@ public function __construct(
*
* @throws Exception
*/
public function restoreFromId(string $id): void
public function restoreFromId(string $id, ?Authenticatable $user = null): void
Copy link

Copilot AI May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider updating the method's docblock for restoreFromId to document the new optional 'user' parameter for clarity.

Copilot uses AI. Check for mistakes.
{
$backup = $this->repository->find($id);

if (!$backup) {
throw new RuntimeException("Backup with id {$id} not found.");
}

$this->restore($backup);
$this->restore($backup, $user);
}

/**
* Restore to the given backup.
*
* @throws RestoreFailed
*/
public function restore(BackupDto $backup): void
public function restore(BackupDto $backup, ?Authenticatable $user = null): void
Copy link

Copilot AI May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the restore method's docblock to mention the optional 'user' parameter and describe the change in authentication handling.

Copilot uses AI. Check for mistakes.
{
$lock = $this->stateManager->getLock();

Expand All @@ -70,7 +71,6 @@ public function restore(BackupDto $backup): void

event(new BackupRestored($backup));

$user = auth()->user();
if ($user) {
$backup->getMetadata()->addRestore($user);
}
Expand Down