Skip to content

Commit 900781d

Browse files
Fix all timestamp -> id leftovers
1 parent 5e08e19 commit 900781d

File tree

10 files changed

+47
-47
lines changed

10 files changed

+47
-47
lines changed

client/src/components/Listing.vue

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,22 @@
3838
v-if="canDownload.isPermitted"
3939
:disabled="!canDownload.isPossible"
4040
:text="__('statamic-backup::backup.download.label')"
41-
:redirect="download_url(backup.timestamp)"
41+
:redirect="download_url(backup.id)"
4242
/>
4343
<span v-if="canRestore.isPermitted && canRestore.isPossible">
4444
<hr class="divider" />
4545
<dropdown-item
4646
:disabled="!canRestore.isPossible"
4747
:text="__('statamic-backup::backup.restore.label')"
48-
@click="initiateRestore(backup.timestamp, backup.name)"
48+
@click="initiateRestore(backup.id, backup.name)"
4949
/>
5050
</span>
5151
<span v-if="canDestroy.isPermitted && canDestroy.isPossible">
5252
<hr class="divider" />
5353
<dropdown-item
5454
:text="__('statamic-backup::backup.destroy.label')"
5555
dangerous="true"
56-
@click="initiateDestroy(backup.timestamp, backup.name)"
56+
@click="initiateDestroy(backup.id, backup.name)"
5757
/>
5858
</span>
5959
</dropdown-list>
@@ -118,7 +118,7 @@ export default {
118118
columns: this.initialColumns,
119119
confirmingRestore: false,
120120
confirmingDestroy: false,
121-
activeTimestamp: null,
121+
activeId: null,
122122
activeName: null,
123123
};
124124
},
@@ -140,22 +140,22 @@ export default {
140140
},
141141
},
142142
methods: {
143-
download_url(timestamp) {
144-
return cp_url("api/backups/download/" + timestamp);
143+
download_url(id) {
144+
return cp_url("api/backups/download/" + id);
145145
},
146-
restore_url(timestamp) {
147-
return cp_url("api/backups/restore/" + timestamp);
146+
restore_url(id) {
147+
return cp_url("api/backups/restore/" + id);
148148
},
149-
destroy_url(timestamp) {
150-
return cp_url("api/backups/" + timestamp);
149+
destroy_url(id) {
150+
return cp_url("api/backups/" + id);
151151
},
152-
initiateDestroy(timestamp, name) {
153-
this.activeTimestamp = timestamp;
152+
initiateDestroy(id, name) {
153+
this.activeId = id;
154154
this.activeName = name;
155155
this.confirmingDestroy = true;
156156
},
157-
initiateRestore(timestamp, name) {
158-
this.activeTimestamp = timestamp;
157+
initiateRestore(id, name) {
158+
this.activeId = id;
159159
this.activeName = name;
160160
this.confirmingRestore = true;
161161
},
@@ -166,7 +166,7 @@ export default {
166166
167167
this.$store.dispatch('backup-provider/setStatus', 'restore_in_progress');
168168
this.$axios
169-
.post(this.restore_url(this.activeTimestamp))
169+
.post(this.restore_url(this.activeId))
170170
.then(({ data }) => {
171171
this.$toast.info(__(data.message));
172172
this.$emit("onRestored");
@@ -181,15 +181,15 @@ export default {
181181
})
182182
.finally(() => {
183183
this.activeName = null;
184-
this.activeTimestamp = null;
184+
this.activeId = null;
185185
});
186186
},
187187
destroy() {
188188
if (!this.canDestroy.isPossible) return console.warn("Cannot destroy backups.");
189189
190190
this.confirmingDestroy = false;
191191
this.$axios
192-
.delete(this.destroy_url(this.activeTimestamp))
192+
.delete(this.destroy_url(this.activeId))
193193
.then(({ data }) => {
194194
this.$toast.success(__(data.message));
195195
this.$emit("onDestroyed");
@@ -204,7 +204,7 @@ export default {
204204
})
205205
.finally(() => {
206206
this.activeName = null;
207-
this.activeTimestamp = null;
207+
this.activeId = null;
208208
});
209209
},
210210
},

routes/cp.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@
4242
->middleware('can:create backups')
4343
->name('store');
4444

45-
Route::delete('/{timestamp}', DestroyBackupController::class)
45+
Route::delete('/{id}', DestroyBackupController::class)
4646
->middleware('can:delete backups')
4747
->name('destroy');
4848

49-
Route::get('/download/{timestamp}', DownloadBackupController::class)
49+
Route::get('/download/{id}', DownloadBackupController::class)
5050
->middleware('can:download backups')
5151
->name('download');
5252

53-
Route::post('/restore/{timestamp}', RestoreController::class)
53+
Route::post('/restore/{id}', RestoreController::class)
5454
->middleware('can:restore backups')
5555
->name('restore');
5656
});

src/Http/Controllers/Api/DestroyBackupController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
final readonly class DestroyBackupController
1212
{
13-
public function __invoke(string $timestamp, BackupRepository $repo): JsonResponse|RedirectResponse
13+
public function __invoke(string $id, BackupRepository $repo): JsonResponse|RedirectResponse
1414
{
15-
$backup = $repo->remove($timestamp);
15+
$backup = $repo->remove($id);
1616

1717
return response()->json(['message' => __('statamic-backup::backup.destroy.success', [
1818
'name' => $backup->name,

src/Http/Controllers/Api/RestoreController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
use Illuminate\Contracts\Cache\Repository;
99
use Illuminate\Http\JsonResponse;
1010
use Itiden\Backup\Exceptions\ActionAlreadyInProgress;
11-
use Itiden\Backup\Jobs\RestoreFromTimestampJob;
11+
use Itiden\Backup\Jobs\RestoreJob;
1212
use Itiden\Backup\StateManager;
1313
use Statamic\Contracts\Auth\User;
1414

1515
final readonly class RestoreController
1616
{
17-
public function __invoke(string $timestamp, StateManager $stateManager, #[Authenticated] User $user): JsonResponse
17+
public function __invoke(string $id, StateManager $stateManager, #[Authenticated] User $user): JsonResponse
1818
{
19-
$stateManager->dispatch(new RestoreFromTimestampJob($timestamp, $user));
19+
$stateManager->dispatch(new RestoreJob($id, $user));
2020

2121
return response()->json(['message' => __('statamic-backup::backup.restore.started')]);
2222
}

src/Http/Controllers/DownloadBackupController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
/**
1414
* Handle the incoming request.
1515
*/
16-
public function __invoke(string $timestamp, BackupRepository $repo): StreamedResponse
16+
public function __invoke(string $id, BackupRepository $repo): StreamedResponse
1717
{
18-
$backup = $repo->find($timestamp);
18+
$backup = $repo->find($id);
1919

2020
$backup
2121
->getMetadata()
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
use Itiden\Backup\Restorer;
1010
use Statamic\Contracts\Auth\User;
1111

12-
final class RestoreFromTimestampJob implements ShouldQueue
12+
final class RestoreJob implements ShouldQueue
1313
{
1414
use Queueable;
1515

1616
/**
1717
* Create a new job instance.
1818
*/
1919
public function __construct(
20-
private string $timestamp,
20+
private string $id,
2121
private User $user,
2222
) {
2323
}
@@ -28,6 +28,6 @@ public function __construct(
2828
public function handle(Restorer $backuper): void
2929
{
3030
auth()->login($this->user); // ugly but it works;
31-
$backuper->restoreFromId($this->timestamp);
31+
$backuper->restoreFromId($this->id);
3232
}
3333
}

tests/Feature/PreventsSimultaneousActionsTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Illuminate\Support\Facades\Bus;
66
use Itiden\Backup\Jobs\BackupJob;
77
use Itiden\Backup\Jobs\RestoreFromPathJob;
8-
use Itiden\Backup\Jobs\RestoreFromTimestampJob;
8+
use Itiden\Backup\Jobs\RestoreJob;
99
use Statamic\Contracts\Auth\User;
1010

1111
use function Itiden\Backup\Tests\user;
@@ -39,14 +39,14 @@
3939
actingAs($user);
4040

4141
postJson(cp_route('api.itiden.backup.restore', [
42-
'timestamp' => now()->timestamp,
42+
'id' => now()->timestamp,
4343
]));
4444

4545
postJson(cp_route('api.itiden.backup.restore', [
46-
'timestamp' => now()->timestamp,
46+
'id' => now()->timestamp,
4747
]))->assertServerError();
4848

49-
Bus::assertDispatchedTimes(RestoreFromTimestampJob::class, 1);
49+
Bus::assertDispatchedTimes(RestoreJob::class, 1);
5050
});
5151

5252
it('prevents other actions when something is queued', function (): void {
@@ -59,16 +59,16 @@
5959
actingAs($user);
6060

6161
postJson(cp_route('api.itiden.backup.restore', [
62-
'timestamp' => now()->timestamp,
62+
'id' => now()->timestamp,
6363
]));
6464

6565
postJson(cp_route('api.itiden.backup.store'))->assertServerError();
6666

6767
postJson(cp_route('api.itiden.backup.restore', [
68-
'timestamp' => now()->timestamp,
68+
'id' => now()->timestamp,
6969
]))->assertServerError();
7070

7171
Bus::assertNotDispatched(BackupJob::class);
72-
Bus::assertDispatchedTimes(RestoreFromTimestampJob::class, 1);
72+
Bus::assertDispatchedTimes(RestoreJob::class, 1);
7373
});
7474
});

tests/Feature/RestoreBackupTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
use function Pest\Laravel\postJson;
1616

1717
describe('api:restore', function (): void {
18-
it('cant restore by timestamp by a guest', function (): void {
19-
$response = postJson(cp_route('api.itiden.backup.restore', 'timestamp'));
18+
it('cant restore by id by a guest', function (): void {
19+
$response = postJson(cp_route('api.itiden.backup.restore', 'id'));
2020

2121
expect($response->status())->toBe(Response::HTTP_UNAUTHORIZED);
2222
});
2323

24-
it('cant restore by timestamp by a user without permissons a backup', function (): void {
24+
it('cant restore by id by a user without permissons a backup', function (): void {
2525
actingAs(user());
2626

27-
$response = postJson(cp_route('api.itiden.backup.restore', 'timestamp'));
27+
$response = postJson(cp_route('api.itiden.backup.restore', 'id'));
2828

2929
expect($response->status())->toBe(Response::HTTP_FORBIDDEN);
3030
});
@@ -38,12 +38,12 @@
3838

3939
actingAs($user);
4040

41-
$response = postJson(cp_route('api.itiden.backup.restore', 'timestamp'));
41+
$response = postJson(cp_route('api.itiden.backup.restore', 'id'));
4242

4343
expect($response->status())->toBe(Response::HTTP_INTERNAL_SERVER_ERROR);
4444
});
4545

46-
it('can restore by timestamp', function (): void {
46+
it('can restore by id', function (): void {
4747
$backup = Backuper::backup();
4848

4949
$user = user();

tests/Unit/BackupRepositoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
expect($backups->first())->toBeInstanceOf(BackupDto::class);
2121
});
2222

23-
it('can get backup by timestamp', function (): void {
23+
it('can get backup by id', function (): void {
2424
$backup = Backuper::backup();
2525
$foundBackup = app(BackupRepository::class)->find($backup->id);
2626

@@ -29,7 +29,7 @@
2929
expect($foundBackup)->toEqual($backup);
3030
});
3131

32-
it('returns null when timestamp doesnt exist', function (): void {
32+
it('returns null when id doesnt exist', function (): void {
3333
$backup = app(BackupRepository::class)->find('1234567890');
3434
expect($backup)->toBeNull();
3535
});

tests/Unit/RestorerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use function Itiden\Backup\Tests\user;
1616

1717
describe('restorer', function (): void {
18-
it('can restore from timestamp', function (): void {
18+
it('can restore from id', function (): void {
1919
$backup = Backuper::backup();
2020

2121
File::cleanDirectory(fixtures_path('content/collections'));

0 commit comments

Comments
 (0)