3 namespace App\Console\Commands;
5 use App\Models\DiscordBotCommand;
7 use Illuminate\Console\Command;
8 use Illuminate\Database\Eloquent\Builder;
10 class SyncAvatars extends Command
13 * The name and signature of the console command.
17 protected $signature = 'sync:avatars';
20 * The console command description.
24 protected $description = 'Resync outdated avatars';
27 * Execute the console command.
31 public function handle()
33 $users = User::whereNotNull('avatar')
34 ->where(function (Builder $query) {
35 $query->whereNull('avatar_cached');
36 $query->orWhereColumn('avatar_cached', '<', 'updated_at');
37 $query->orWhere('avatar_cached', '<', now()->subtract(30, 'days'));
41 foreach ($users as $user) {
43 DiscordBotCommand::syncUser($user->id);
44 } catch (\Exception $e) {
45 $this->error('error syncing avatar of user '.$user->id.': '.$e->getMessage());