Commit 22cfe6af by zeecostorage

sync user

parent 717543df
...@@ -23,6 +23,9 @@ use App\Mail\StatusReject; ...@@ -23,6 +23,9 @@ use App\Mail\StatusReject;
use Mail; use Mail;
use Curl; use Curl;
use Auth; use Auth;
use App\User as Users;
use Portal\Timesheet\Model\Urole as Aclrole;
use Portal\Timesheet\Model\Staff_info as StaffInfo;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
...@@ -38,10 +41,68 @@ class UsersController extends Controller ...@@ -38,10 +41,68 @@ class UsersController extends Controller
public function syncNewUsers() public function syncNewUsers()
{ {
// Run command manual // Run command manual
$output = shell_exec('php /www/html/timesheet3f/artisan migrate:user-cron 2>&1'); // $output = shell_exec('php /www/html/timesheet3f/artisan migrate:user-cron 2>&1');
// Log the output for debugging // // Log the output for debugging
\Log::info("migrate:user-cron output: " . $output); // \Log::info("migrate:user-cron output: " . $output);
$migrateuser = DB::connection('mysql')->table('migrate_user')->where('id',1)->first();
// dump($migrateuser);
$user = DB::connection('mysql2')
->table('users')
->join('staff_info','staff_info.fk_users','=','users.id')
->where('users.id','>',$migrateuser->userid)
->select('users.id','users.email','users.fullname','users.staff_id','staff_info.fk_lkp_country','staff_info.fk_lkp_state','staff_info.ic_no','staff_info.email')
->get();
// dd($user);
if($user){
foreach ($user as $key => $value){
$new = new Users;
$new->name = strtoupper($value->fullname);
$new->email = $value->email;
$new->status = 'ACTIVE';
$new->timezone = 'UTC';
$new->meta = NULL;
$new->email_verified_at = NULL;
$new->password = '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm'; //secret
$new->password_last_set = NULL;
$new->u_staffID = $value->staff_id;
$new->save();
$role = new Aclrole;
$role->user_id = $new->id;
$role->role_id = 5;
$role->save();
$saveinfo = new StaffInfo;
$saveinfo->fk_lkp_country = $value->fk_lkp_country;
$saveinfo->fk_lkp_state = $value->fk_lkp_state;
$saveinfo->fk_users = $new->id;
$saveinfo->ic_no = $value->ic_no;
$saveinfo->email = $value->email;
$saveinfo->staff_id = $value->staff_id;
$saveinfo->fullname = strtoupper($value->fullname);
$saveinfo->status = 1;
$saveinfo->save();
//update migrate user
$updmigrate = DB::connection('mysql')->table('migrate_user')->where('id',1)
->update(['userid' => $value->id]);
// $updmigrate->userid = $value->id;
// $updmigrate->save();
}//endforeach
} //end if user
return redirect('users/list')->withSuccess('Senarai staff telah dikemaskini'); return redirect('users/list')->withSuccess('Senarai staff telah dikemaskini');
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment