2022-01-03 10:33:48 +01:00
|
|
|
<?php
|
2020-04-12 00:26:44 +02:00
|
|
|
|
|
|
|
namespace App\Initialize;
|
|
|
|
|
2023-02-13 00:14:51 +01:00
|
|
|
use App\Actions\InsertMemberAction;
|
2023-02-07 02:45:15 +01:00
|
|
|
use App\Actions\PullCoursesAction;
|
2023-02-07 01:38:27 +01:00
|
|
|
use App\Actions\PullMembershipsAction;
|
2023-02-13 00:14:51 +01:00
|
|
|
use App\Nami\Api\CompleteMemberToRedisJob;
|
2023-02-07 23:55:46 +01:00
|
|
|
use App\Setting\NamiSettings;
|
2022-09-02 00:45:39 +02:00
|
|
|
use DB;
|
2023-02-13 00:14:51 +01:00
|
|
|
use Illuminate\Bus\Batch;
|
2023-02-07 23:55:46 +01:00
|
|
|
use Illuminate\Console\Command;
|
2023-02-13 00:14:51 +01:00
|
|
|
use Illuminate\Support\Facades\Bus;
|
|
|
|
use Illuminate\Support\Facades\Redis;
|
2023-02-07 23:55:46 +01:00
|
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
2022-02-12 16:16:56 +01:00
|
|
|
use Zoomyboy\LaravelNami\Api;
|
2023-02-12 22:37:49 +01:00
|
|
|
use Zoomyboy\LaravelNami\Data\MemberEntry as NamiMember;
|
2021-04-10 01:39:39 +02:00
|
|
|
|
2022-03-11 20:19:17 +01:00
|
|
|
class InitializeMembers
|
|
|
|
{
|
2023-02-07 23:55:46 +01:00
|
|
|
use AsAction;
|
2022-01-03 10:33:48 +01:00
|
|
|
|
2023-02-08 00:14:59 +01:00
|
|
|
public string $commandSignature = 'member:pull';
|
2020-04-12 00:26:44 +02:00
|
|
|
|
2023-02-07 23:55:46 +01:00
|
|
|
public function handle(Api $api): void
|
2022-02-12 16:16:56 +01:00
|
|
|
{
|
2020-04-12 00:26:44 +02:00
|
|
|
$allMembers = collect([]);
|
2023-02-13 00:14:51 +01:00
|
|
|
Redis::delete('members');
|
2020-04-12 00:26:44 +02:00
|
|
|
|
2023-02-13 00:14:51 +01:00
|
|
|
$jobs = $api->search([])->map(function (NamiMember $member) use ($api) {
|
|
|
|
return new CompleteMemberToRedisJob($api, $member->groupId, $member->id);
|
|
|
|
})->toArray();
|
2023-02-07 23:23:15 +01:00
|
|
|
|
2023-02-13 00:14:51 +01:00
|
|
|
$batch = Bus::batch($jobs)
|
|
|
|
->finally(function (Batch $batch) {
|
|
|
|
dd(Redis::get('members'));
|
|
|
|
})
|
|
|
|
->dispatch();
|
|
|
|
// $localMember = InsertMemberAction::run();
|
|
|
|
// })->catch(function (Batch $batch, Throwable $e) {
|
|
|
|
// // First batch job failure detected...
|
|
|
|
// })->finally(function (Batch $batch) {
|
|
|
|
// // The batch has finished executing...
|
|
|
|
// })
|
|
|
|
|
|
|
|
// app(PullMembershipsAction::class)->handle($localMember);
|
|
|
|
// app(PullCoursesAction::class)->handle($localMember);
|
2022-01-03 10:33:48 +01:00
|
|
|
}
|
2022-09-02 00:45:39 +02:00
|
|
|
|
|
|
|
public function restore(): void
|
|
|
|
{
|
|
|
|
DB::table('payments')->delete();
|
|
|
|
DB::table('course_members')->delete();
|
|
|
|
DB::table('memberships')->delete();
|
|
|
|
DB::table('members')->delete();
|
|
|
|
}
|
2023-02-07 23:55:46 +01:00
|
|
|
|
|
|
|
public function asCommand(Command $command): int
|
|
|
|
{
|
|
|
|
$this->handle(app(NamiSettings::class)->login());
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-04-12 00:26:44 +02:00
|
|
|
}
|