Commit e14d3944753a7314b3c01249ca30e16c40a1139e

Authored by Hayk Nazaryan
1 parent a0d12ea341
Exists in master

fix

Showing 1 changed file with 2 additions and 1 deletions Inline Diff

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