Bladeren bron

Add script to archive testers

Alan Lam 3 jaren geleden
bovenliggende
commit
45b277e323
1 gewijzigde bestanden met toevoegingen van 31 en 0 verwijderingen
  1. 31 0
      tasks/archive_testers.php

+ 31 - 0
tasks/archive_testers.php

@@ -0,0 +1,31 @@
+<?php /** @noinspection PhpUnhandledExceptionInspection */
+
+use Carbon\CarbonImmutable;
+
+require "../initialise.php";
+
+$date = CarbonImmutable::now()->subYears(23)->toDateString();
+
+$users = User::query([
+	"level" => User::LEVEL_TESTER,
+	"date_of_birth" => Constraint::lessThan($date),
+	"archived" => "0"
+]);
+
+$user_count = count($users);
+$archived_count = 0;
+
+foreach($users as $user) {
+	if($user->date_of_birth === "0000-00-00") {
+		continue;
+	}
+
+	$archived_count++;
+
+	echo sprintf("%s (%s) archived.\n", $user->getDisplayName(), $user->date_of_birth);
+
+	$user->archived = 1;
+	$user->commit();
+}
+
+echo "Users archived: $archived_count\n";