What isn't working? Error? It's not running at all? It deletes the wrong users?
Apr 7, 2022
18
Level 12
Schedule task isn't working properly
Hey!
I have a schedule task that is running this code every minute (just for test purposes, it is actually running it daily)
$users = DB::table('users')
->where('is_company', 1)
->where('email_verified_at', null)
->whereDate('created_at', '<', Carbon\Carbon::now()->subDays(1))
->get();
if($users) {
foreach($users as $user) {
$company = DB::table('companies')->where('user_id', $user->id)->first();
DB::table('websites')->where('id', $company->website_id)->update(['claimed' => 0]);
DB::table('users')->where('id', $user->id)->delete();
}
}
But it's not working properly. I double checked if where() & whereDate() criterias of the expected user to be deleted are OK and they are. The user is registered on 2022-04-06 10:53:22 - and the current date is 2022-04-07 around 18:00. The is_company column of the user is set to 1 and its email_verified_at column is also set to null. Is there something wrong with this code? Any idea why it isn't working?
Please or to participate in this conversation.