File tree Expand file tree Collapse file tree 4 files changed +15
-17
lines changed
Expand file tree Collapse file tree 4 files changed +15
-17
lines changed Original file line number Diff line number Diff line change 44
55namespace Itiden \Backup ;
66
7+ use Illuminate \Contracts \Auth \Authenticatable ;
78use Illuminate \Support \Facades \File ;
89use Illuminate \Support \Facades \Pipeline ;
910use Itiden \Backup \Contracts \Repositories \BackupRepository ;
@@ -29,7 +30,7 @@ public function __construct(
2930 *
3031 * @throws Exceptions\BackupFailed
3132 */
32- public function backup (): BackupDto
33+ public function backup (? Authenticatable $ user = null ): BackupDto
3334 {
3435 $ lock = $ this ->stateManager ->getLock ();
3536
@@ -61,8 +62,6 @@ public function backup(): BackupDto
6162
6263 $ metadata = static ::addMetaFromZipToBackupMeta ($ temp_zip_path , $ backup );
6364
64- $ user = auth ()->user ();
65-
6665 if ($ user ) {
6766 $ metadata ->setCreatedBy ($ user );
6867 }
Original file line number Diff line number Diff line change 44
55namespace Itiden \Backup \Jobs ;
66
7+ use Illuminate \Contracts \Auth \Authenticatable ;
78use Illuminate \Contracts \Cache \Repository ;
89use Illuminate \Contracts \Queue \ShouldQueue ;
910use Illuminate \Foundation \Queue \Queueable ;
1011use Itiden \Backup \Backuper ;
1112use Itiden \Backup \StateManager ;
12- use Statamic \Contracts \Auth \User ;
1313
1414final class BackupJob implements ShouldQueue
1515{
@@ -19,17 +19,15 @@ final class BackupJob implements ShouldQueue
1919 * Create a new job instance.
2020 */
2121 public function __construct (
22- private User $ user ,
22+ private Authenticatable $ user ,
2323 ) {}
2424
2525 /**
2626 * Execute the job.
2727 */
2828 public function handle (Backuper $ backuper , Repository $ cache ): void
2929 {
30- auth ()->login ($ this ->user ); // ugly but it works;
31-
32- $ backuper ->backup ();
30+ $ backuper ->backup (user: $ this ->user );
3331
3432 $ cache ->forget (StateManager::JOB_QUEUED_KEY );
3533 }
Original file line number Diff line number Diff line change 44
55namespace Itiden \Backup \Jobs ;
66
7+ use Illuminate \Contracts \Auth \Authenticatable ;
78use Illuminate \Contracts \Cache \Repository ;
89use Illuminate \Contracts \Queue \ShouldQueue ;
910use Illuminate \Foundation \Queue \Queueable ;
1011use Itiden \Backup \Restorer ;
1112use Itiden \Backup \StateManager ;
12- use Statamic \Contracts \Auth \User ;
1313
1414final class RestoreJob implements ShouldQueue
1515{
@@ -20,17 +20,18 @@ final class RestoreJob implements ShouldQueue
2020 */
2121 public function __construct (
2222 private string $ id ,
23- private User $ user ,
23+ private Authenticatable $ user ,
2424 ) {}
2525
2626 /**
2727 * Execute the job.
2828 */
2929 public function handle (Restorer $ backuper , Repository $ cache ): void
3030 {
31- auth ()->login ($ this ->user ); // ugly but it works;
32-
33- $ backuper ->restoreFromId ($ this ->id );
31+ $ backuper ->restoreFromId (
32+ id: $ this ->id ,
33+ user: $ this ->user ,
34+ );
3435
3536 $ cache ->forget (StateManager::JOB_QUEUED_KEY );
3637 }
Original file line number Diff line number Diff line change 55namespace Itiden \Backup ;
66
77use Exception ;
8+ use Illuminate \Contracts \Auth \Authenticatable ;
89use Illuminate \Support \Facades \Artisan ;
910use Illuminate \Support \Facades \File ;
1011use Illuminate \Support \Facades \Pipeline ;
@@ -30,23 +31,23 @@ public function __construct(
3031 *
3132 * @throws Exception
3233 */
33- public function restoreFromId (string $ id ): void
34+ public function restoreFromId (string $ id, ? Authenticatable $ user = null ): void
3435 {
3536 $ backup = $ this ->repository ->find ($ id );
3637
3738 if (!$ backup ) {
3839 throw new RuntimeException ("Backup with id {$ id } not found. " );
3940 }
4041
41- $ this ->restore ($ backup );
42+ $ this ->restore ($ backup, $ user );
4243 }
4344
4445 /**
4546 * Restore to the given backup.
4647 *
4748 * @throws RestoreFailed
4849 */
49- public function restore (BackupDto $ backup ): void
50+ public function restore (BackupDto $ backup, ? Authenticatable $ user = null ): void
5051 {
5152 $ lock = $ this ->stateManager ->getLock ();
5253
@@ -70,7 +71,6 @@ public function restore(BackupDto $backup): void
7071
7172 event (new BackupRestored ($ backup ));
7273
73- $ user = auth ()->user ();
7474 if ($ user ) {
7575 $ backup ->getMetadata ()->addRestore ($ user );
7676 }
You can’t perform that action at this time.
0 commit comments