-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathUserTouAcceptanceJob.php
More file actions
40 lines (36 loc) · 1.49 KB
/
UserTouAcceptanceJob.php
File metadata and controls
40 lines (36 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
namespace App\Jobs;
use App\TermsOfUseVersion;
use App\User;
use App\UserTermsOfUseAcceptance;
use Illuminate\Bus\Batchable;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Log;
use Throwable;
/**
* Bug: T401165 https://phabricator.wikimedia.org/T401165
* Job to record Terms of Use acceptance for all preexisting users.
* This job should only be run ONCE to seed the data for terms of use users have agreed to before we started tracking it explicitly.
* This job iterates through all users and creates a UserTermsOfUseAcceptance record
* for each, using the latest (only) Terms of Use version and the user's creation date as ToU acceptance date.
* Errors during processing are logged and the job is marked as failed if accepting the terms of use for any user fails.
*/
class UserTouAcceptanceJob extends Job {
use Batchable;
use Dispatchable;
public function handle(): void {
$users = User::all();
foreach ($users as $user) {
try {
UserTermsOfUseAcceptance::create([
'user_id' => $user->id,
'tou_version' => TermsOfUseVersion::latestActiveVersion()->version,
'tou_accepted_at' => $user->created_at,
]);
} catch (Throwable $exception) {
Log::error("Failure processing user {$user->email} for UserTouAcceptanceJob: {$exception->getMessage()}");
$this->fail($exception);
}
}
}
}