/** * Execute the console command. * @return void */ public function fire() { $this->output->writeln('Hello world!'); $crmusers = CRMUser::isNotUpdated()->isHaveEmail()->get(); echo "Processing Users: \n"; $crmusers->each(function ($user) { $validator = \Validator::make(['email' => $user->email], ['email' => 'email']); if ($validator->fails()) { echo $user->email . " not valid email! [-]" . "\n"; } else { $cmsuser = CMSUser::firstOrNew(['username' => $user->email]); echo $user->email . " "; $cmsuser->fill($user->toArray()); if (!$cmsuser->is_activated) { $pass = str_random(12); $cmsuser->password = $pass; $cmsuser->password_confirmation = $pass; echo ": " . $pass; } $user->is_updated = true; $user->save(); $cmsuser->save(); if (!$cmsuser->is_activated) { $code = implode('!', [$cmsuser->id, $cmsuser->getActivationCode()]); $link = Page::url('personal', ['code' => $code]); $data = ['name' => $cmsuser->name, 'link' => $link, 'code' => $code]; Mail::send('abnmt.mrc::mail.activate', $data, function ($message) use($cmsuser) { $message->to($cmsuser->email, $cmsuser->name); }); } // if (!$cmsuser->is_activated) { // try { $cmsuser->attemptActivation($cmsuser->activation_code);} catch (\Exception $e) {echo " EXCEPTION!";} // } // \Mail::sendTo($this, 'backend::mail.invite', [ // 'name' => $user->name, // 'email' => '*****@*****.**', // 'password' => $pass, // ]); echo " [+]\n"; } }); echo "\n"; $cmsusers = CMSUser::count(); // echo "\n"; // print_r($crmusers); // echo "\n"; // print_r($cmsusers); // echo "\n"; }
/** * Update Courses from CRM */ public function onUpdateFromCrm() { $crmusers = CRMUser::isNotUpdated()->isHaveEmail()->get(); if (count($crmusers) == 0) { Flash::info("No Users for Create/Update"); return; // return ['#flashMessages' => $this->makePartial('message', ['messages' => ['Success']])]; } $messages = []; $crmusers->each(function ($user) use(&$messages) { $validator = \Validator::make(['email' => $user->email], ['email' => 'email']); if ($validator->fails()) { $messages[] = "[–] " . $user->email . " not valid email!"; } else { $cmsuser = User::firstOrNew(['username' => $user->email]); $cmsuser->fill($user->toArray()); if (!$cmsuser->is_activated) { $pass = str_random(12); $cmsuser->password = $pass; $cmsuser->password_confirmation = $pass; $messages[] = "[+] " . $user->email . ' ' . $pass ?: ''; } else { $messages[] = "[^] " . $user->email; } $user->is_updated = true; $user->save(); $cmsuser->save(); if (!$cmsuser->is_activated && is_null($cmsuser->activation_code)) { $code = implode('!', [$cmsuser->id, $cmsuser->getActivationCode()]); $link = Page::url('profile/activate', ['code' => $code]); $data = ['name' => $cmsuser->name, 'link' => $link, 'code' => $code]; Mail::send('abnmt.mrc::mail.activate', $data, function ($message) use($cmsuser) { $message->to($cmsuser->email, $cmsuser->name); }); } } }); Flash::success("Users is update"); return ['#flashMessages' => $this->makePartial('message', ['messages' => $messages])]; }