Blame view

app/Console/Commands/ResetData.php 4.73 KB
e2907a576   Hayk Nazaryan   workers fixes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  <?php
  
  namespace App\Console\Commands;
  
  use App\Models\Ad_employer;
  use App\Models\Ad_jobs;
  use App\Models\ad_response;
  use App\Models\Answer;
  use App\Models\Chat;
  use App\Models\Contacts;
  use App\Models\Dop_info;
  use App\Models\Employer;
  use App\Models\EmployerAutoliftOption;
  use App\Models\employers_main;
  use App\Models\Flot;
  use App\Models\Group_user;
  use App\Models\Group_works;
  use App\Models\Like_vacancy;
  use App\Models\Like_worker;
  use App\Models\Media;
  use App\Models\Message;
  use App\Models\MessagesRequests;
  use App\Models\PrevCompany;
  use App\Models\ResponseWork;
  use App\Models\Static_ad;
  use App\Models\Static_worker;
  use App\Models\Title_worker;
  use App\Models\User;
  use App\Models\WorkerAutoliftOption;
  use Illuminate\Console\Command;
  use Illuminate\Support\Facades\Hash;
  
  class ResetData extends Command
  {
      /**
       * The name and signature of the console command.
       *
       * @var string
       */
      protected $signature = 'reset:data';
  
      /**
       * The console command description.
       *
       * @var string
       */
      protected $description = 'Command description';
  
      /**
       * Execute the console command.
       *
       * @return int
       */
      public function handle()
      {
          $users = User::query()
              ->whereHas('workers')
              ->where('is_bd', 0)
              ->where('created_at', '<', '2024-11-30 00:00:00')
              ->whereNotIn('email', [
                  'vkontakte@rekamore.su',
e14d39447   Hayk Nazaryan   fix
62
63
                  '2anketa@rekamore.su',
                  'integralal@mail.ru'
e2907a576   Hayk Nazaryan   workers fixes
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
              ])
              ->get();
  
          foreach ($users as $user) {
              Answer::query()->where(['user_id' => $user->id])->delete();
  
              Chat::query()->where(['user_id' => $user->id])->delete();
              Chat::query()->where(['to_user_id' => $user->id])->delete();
              Message::query()->where(['user_id' => $user->id])->delete();
              Message::query()->where(['to_user_id' => $user->id])->delete();
              MessagesRequests::query()->where(['user_id' => $user->id])->delete();
  
              Group_user::query()->where(['user_id' => $user->id])->get()->map(function ($groupUser) {
                  Group_works::query()->where(['group_user_id' => $groupUser->id])->delete();
                  $groupUser->delete();
              });
  
              Like_vacancy::query()->where(['user_id' => (string)$user->id])->delete();
              Like_worker::query()->where(['user_id' => (string)$user->id])->delete();
              Media::query()->where(['user_id' => $user->id])->delete();
              Static_worker::query()->where(['user_id' => $user->id])->delete();
  
  //            $user->employers()->get()->map(function ($employer) {
  //                Answer::query()->where(['employer_id' => $employer->id])->delete();
  //
  //                Ad_employer::query()->where(['employer_id' => $employer->id])->get()->map(function ($adEmployer) {
  //                    Ad_jobs::query()->where(['ad_employer_id' => $adEmployer->id])->delete();
  //                    ad_response::query()->where(['ad_employer_id' => $adEmployer->id])->delete();
  //                    Static_ad::query()->where(['ad_employer_id' => $adEmployer->id])->delete();
  //                    Like_vacancy::query()->where(['code_record' => $adEmployer->id])->delete();
  //
  //                    $adEmployer->delete();
  //                });
  //
  //                Contacts::query()->where(['employer_id' => $employer->id])->delete();
  //                employers_main::query()->where(['employer_id' => $employer->id])->delete();
  //                EmployerAutoliftOption::query()->where(['employer_id' => $employer->id])->delete();
  //
  //                Flot::query()->where(['employer_id' => $employer->id])->delete();
  //
  //                $employer->delete();
  //            });
  
              $user->workers()->get()->map(function ($worker) {
                  Dop_info::query()->where(['worker_id' => $worker->id])->delete();
                  PrevCompany::query()->where(['worker_id' => $worker->id])->delete();
                  ResponseWork::query()->where(['worker_id' => $worker->id])->delete();
                  Like_worker::query()->where(['code_record' => $worker->id])->delete();
                  Title_worker::query()->where(['worker_id' => $worker->id])->delete();
                  WorkerAutoliftOption::query()->where(['worker_id' => $worker->id])->delete();
                  $worker->delete();
              });
  
              $user->delete();
  
          }
  
          User::query()->where('password', 1234567890)->get()->map(function ($userBd) {
              $password = $userBd->password;
  
              $userBd->update([
                  'password' => Hash::make($password),
                  'pubpassword' => base64_encode($password),
a0d12ea34   Hayk Nazaryan   add prod db
127
                  'email_verified_at' => now()
e2907a576   Hayk Nazaryan   workers fixes
128
129
130
131
132
133
              ]);
          });
  
          return Command::SUCCESS;
      }
  }