Файловый менеджер - Редактировать - /var/www/vhosts/aviointeriors.dev1.mndrn.cloud/app/update/Commands.tar
Назад
ExpiredAccountsCommand.php 0000644 00000005510 15233524356 0011665 0 ustar 00 <?php namespace App\Console\Commands; use Illuminate\Console\Command; use App\Models\User; use Carbon\Carbon; use App\Models\EmailQueue; use Illuminate\Support\Str; class ExpiredAccountsCommand extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'check_expired_users'; /** * The console command description. * * @var string */ protected $description = 'This script check expired users and block them'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } function checkExpired(){ echo "\n\n CHECKING EXPIRED ACCOUNTS!\n\n"; // Calcolo un anno fa da oggi $data = Carbon::now()->subYear(); echo "\n ".$data." checking an year ago from now ...\n"; // prendo gli utenti $users_first_renewal = User::where([ ['created_at', '<=', $data], ['renew_date', '=', NULL], ['expired', '=', 0], ])->get(); $users_next_renewal = User::where([ ['expired', '=', 0], ['renew_date', '<=', $data] ])->get(); echo "\n ".(count($users_first_renewal) + count($users_next_renewal))." expired accounts.\n\n"; foreach ($users_first_renewal as $k => $v) { $token = Str::random(64); echo "\n Disabling -> ".$v->first_name." ".$v->last_name." (".$v->email.")\n"; $v->active = 0; $v->expired = 1; $v->renewal_token = $token; $v->save(); $mail = EmailQueue::create([ 'label' => 'Account expired 12', 'type' => '2', 'user_id' => $v->id, 'info' => $v->first_name.' '.$v->last_name.': account expired! It will be deactivated. ', 'to' => $v->email ]); } foreach ($users_next_renewal as $k => $v) { $token = Str::random(64); echo "\n Disabling -> ".$v->first_name." ".$v->last_name." (".$v->email.")\n"; $v->active = 0; $v->expired = 1; $v->renewal_token = $token; $v->save(); $mail = EmailQueue::create([ 'label' => 'Account expired 12', 'type' => '2', 'user_id' => $v->id, 'info' => $v->first_name.' '.$v->last_name.': account expired! It will be deactivated. ', 'to' => $v->email ]); } echo "\n\n All Done!\n\n"; } /** * Execute the console command. * * @return mixed */ public function handle() { # $ctrl = new MailQueueController(); # echo $ctrl->sendEmails(); return $this->checkExpired(); } } .gitkeep 0000644 00000000000 15233524356 0006173 0 ustar 00 EmailQueueCommand.php 0000644 00000014615 15233524356 0010627 0 ustar 00 <?php namespace App\Console\Commands; use Illuminate\Console\Command; use App\Models\User; use App\Models\EmailQueue; use Carbon\Carbon; use Illuminate\Support\Facades\Mail; class EmailQueueCommand extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'sendemails'; /** * The console command description. * * @var string */ protected $description = 'This script send queued emails.'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } function sendEmails(){ echo "\n\n SCANNING EMAILS TO SEND!\n\n"; $emails = EmailQueue::where('send_at', NULL)->get(); $count = count($emails); echo "\n ".$count." waiting to be sent.\n\n"; foreach ($emails as $k => $v) { $emails = ['test.sito@external.aviointeriors.it', 'a.bellamio@mandarino.agency', 'f.quagliotto@mandarino.agency', 'a.zerbinati@mandarino.agency', $v->to]; // NEW USER if ($v->type == 0) { echo "\n NEW_USER: ".$v->to."\n"; // ADMIN Mail::send('email.userRegistration', [ 'info' => $v->info, 'email' => $v->to ], function($message) use($emails){ $message->to($emails); $message->subject('Aviointeriors - New user registration'); }); // USER Mail::send('email.userRegistrationWelcome', [ 'info' => $v->info, 'email' => $v->to ], function($message) use($emails){ $message->to($emails); $message->subject('Aviointeriors - New user registration'); }); $v->send_at = Carbon::now(); $v->save(); } // NEW COMPANY if ($v->type == 1) { echo "\n NEW_COMPANY: ".$v->to."\n"; Mail::send('email.companyCreation', [ 'info' => $v->info, 'email' => $v->to ], function($message) use($emails){ $message->to($emails); $message->subject('Aviointeriors - New company creation after user registration'); }); $v->send_at = Carbon::now(); $v->save(); } // ACCOUNT EXPIRED 12 if ($v->type == 2) { echo "\n ACCOUNT_EXPIRED: ".$v->to."\n"; $user = User::where('email', $v->to)->first(); if ($user) { Mail::send('email.expiredAccount12', [ 'info' => $v->info, 'email' => $v->to, 'token' => 'https://aviointeriors.dev1.mndrn.cloud/user/#/renew/'.$user->renewal_token ], function($message) use($emails){ $message->to($emails); $message->subject('Aviointeriors - Your account has expired'); }); $v->send_at = Carbon::now(); $v->save(); }else{ echo "\n ACCOUNT_EXPIRED [FAILED]: ".$v->to."\n"; } } // INACTIVE PNs if ($v->type == 3) { echo "\n INACTIVE_PN: ".$v->to."\n"; Mail::send('email.inactivePn', [ 'info' => $v->info, 'email' => $v->to ], function($message) use($emails){ $message->to($emails); $message->subject('Aviointeriors - Inactive Part Number (s)'); }); $v->send_at = Carbon::now(); $v->save(); } // PN DELETED if ($v->type == 4) { echo "\n PN_DELETED: ".$v->to."\n"; Mail::send('email.pnDeleted', [ 'info' => $v->info, 'email' => $v->to ], function($message) use($emails){ $message->to($emails); $message->subject('Aviointeriors - Part Number (s) deleted'); }); $v->send_at = Carbon::now(); $v->save(); } // PN MODIFIED if ($v->type == 5) { echo "\n PN_MODIFIED: ".$v->to."\n"; // Decode the JSON info $mail_info = json_decode($v->info, true); // Debug info echo "\n DEBUG INFO: "; echo "\n Info JSON: ".$v->info; echo "\n Decoded Info: "; print_r($mail_info); echo "\n"; Mail::send('email.pnModified', [ 'info' => $v->info, 'mail_info' => $mail_info, 'email' => $v->to ], function($message) use($emails){ $message->to($emails); $message->subject('Aviointeriors - Part Number modified'); }); $v->send_at = Carbon::now(); $v->save(); } } echo "\n All done!\n\n"; #var_dump($emails);die(); } function testMailEntry() { $user = new \stdClass(); $user->id = 10; $user->first_name = 'Andrea'; $user->last_name = 'Zeta'; $user->email = 'andreazerbinati@gmail.com'; $company = new \stdClass(); $company->name = 'Zeta company TEST'; $mail = EmailQueue::create([ 'label' => 'New Company', 'type' => '1', 'user_id' => $user->id, 'info' => $user->first_name.' '.$user->last_name.' created a company '.$company->name.'.', 'to' => $user->email ]); var_dump($mail); } /** * Execute the console command. * * @return mixed */ public function handle() { # $ctrl = new MailQueueController(); # echo $ctrl->sendEmails(); # return $this->testMailEntry(); return $this->sendEmails(); } }
| ver. 1.4 |
Github
|
.
| PHP 8.2.5 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка