Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
336 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@extends('adminlte::page') | ||
|
||
@section('htmlheader_title') | ||
Users migration | ||
@endsection | ||
|
||
|
||
@section('main-content') | ||
<users-migration-dashboard></users-migration-dashboard> | ||
<users-migration></users-migration> | ||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Acacha\Users\Events; | ||
|
||
use Illuminate\Broadcasting\Channel; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Foundation\Events\Dispatchable; | ||
use Illuminate\Broadcasting\InteractsWithSockets; | ||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast; | ||
|
||
/** | ||
* Class UserMigrationStatusUpdated | ||
* | ||
* @package Acacha\Users\Events | ||
*/ | ||
class UserMigrationStatusUpdated implements ShouldBroadcast | ||
{ | ||
use Dispatchable, InteractsWithSockets, SerializesModels; | ||
|
||
/** | ||
* Migrated user. | ||
* | ||
* @var | ||
*/ | ||
public $user; | ||
|
||
/** | ||
* Progress status value. | ||
* | ||
* @var | ||
*/ | ||
public $progress; | ||
|
||
/** | ||
* Create a new event instance. | ||
* | ||
* @param $user | ||
*/ | ||
public function __construct($user, $progress) | ||
{ | ||
$this->user = $user; | ||
$this->progress = $progress; | ||
} | ||
|
||
/** | ||
* Get the channels the event should broadcast on. | ||
* | ||
* @return Channel|array | ||
*/ | ||
public function broadcastOn() | ||
{ | ||
return new Channel('users-migration'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
namespace Acacha\Users\Http\Controllers; | ||
|
||
use Acacha\Users\Events\UserMigrationStatusUpdated; | ||
use Acacha\Users\Http\Requests\UsersMigrationRequest; | ||
|
||
/** | ||
* Class UsersMigrationController. | ||
* | ||
* @package App\Http\Controllers | ||
*/ | ||
class UsersMigrationController extends Controller | ||
{ | ||
/** | ||
* Show users migration. | ||
* | ||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View | ||
*/ | ||
public function index() | ||
{ | ||
$this->authorize('migrate-users'); | ||
$data = []; | ||
return view('acacha_users::users-migration',$data); | ||
} | ||
|
||
/** | ||
* Get total number of users in source migration database. | ||
*/ | ||
public function totalNumberOfUsers() | ||
{ | ||
$this->authorize('migrate-users'); | ||
return [ 'data' => 68 ]; | ||
} | ||
|
||
/** | ||
* Migrate multiple users. | ||
* | ||
*/ | ||
public function migrate(UsersMigrationRequest $request) | ||
{ | ||
$usersToMigrate = $this->usersToMigrateByRequest($request); | ||
dd($usersToMigrate); | ||
$progress= 0; | ||
foreach ($usersToMigrate as $user ) { | ||
event(new UserMigrationStatusUpdated($user, $progress)); | ||
sleep(1); | ||
dump ('User ' . $user . ' migrated!'); | ||
$progress = $progress + 50; | ||
} | ||
event(new UserMigrationStatusUpdated('Finish!', $progress)); | ||
} | ||
|
||
|
||
/** | ||
* Get users to migrate. | ||
* | ||
* @param $request | ||
*/ | ||
protected function usersToMigrateByRequest($request) | ||
{ | ||
if ($users = $request->has('users')) return $this->usersToMigrate($users, $request); | ||
if ($filter = $request->has('filter')) return $this->usersToMigrateByFilter($filter, $request); | ||
return $this->allUsers($request); | ||
} | ||
|
||
/** | ||
* Users to migrate by user id list. | ||
* | ||
* @param $users | ||
*/ | ||
protected function usersToMigrate($users, $request) | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* Users to migrate by filter. | ||
* | ||
* @param $filter | ||
*/ | ||
protected function usersToMigrateByFilter($filter, $request) | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* Get all valid users. | ||
* | ||
* @param $request | ||
* @return \Illuminate\Database\Eloquent\Collection|static[] | ||
*/ | ||
protected function allUsers($request) | ||
{ | ||
return \Scool\EbreEscoolModel\User::all(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Acacha\Users\Http\Requests; | ||
|
||
use Auth; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
/** | ||
* Class MassiveDestroyRequest. | ||
* | ||
* @package Acacha\Users\Http\Requests | ||
*/ | ||
class MassiveDestroyRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return Auth::user()->can('massive-delete-users'); | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'ids' => 'required' | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Acacha\Users\Http\Requests; | ||
|
||
use Auth; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
/** | ||
* Class UsersMigrationRequest. | ||
* | ||
* @package Acacha\Users\Http\Requests | ||
*/ | ||
class UsersMigrationRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return Auth::user()->can('migrate-users'); | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'users.*.id' => 'sometimes|numeric', | ||
'filter' => 'sometimes|in:foo,bar' | ||
]; | ||
} | ||
} |
Oops, something went wrong.