Commit b0574d0f76669989ee46696a9f46b87f11929b6a
1 parent
1625d67034
Exists in
master
autolift fixes
Showing 3 changed files with 48 additions and 112 deletions Side-by-side Diff
app/Console/Commands/RemoveOldUsers.php
... | ... | @@ -1,105 +0,0 @@ |
1 | -<?php | |
2 | - | |
3 | -namespace App\Console\Commands; | |
4 | - | |
5 | -use Illuminate\Console\Command; | |
6 | -use Illuminate\Support\Facades\DB; | |
7 | - | |
8 | -class RemoveOldUsers extends Command | |
9 | -{ | |
10 | - /** | |
11 | - * The name and signature of the console command. | |
12 | - * | |
13 | - * @var string | |
14 | - */ | |
15 | - protected $signature = 'users:remove-old'; | |
16 | - | |
17 | - /** | |
18 | - * The console command description. | |
19 | - * | |
20 | - * @var string | |
21 | - */ | |
22 | - protected $description = 'Remove old users and related data'; | |
23 | - | |
24 | - /** | |
25 | - * Execute the console command. | |
26 | - */ | |
27 | - public function handle() | |
28 | - { | |
29 | - $date = '2024-11-30 00:00:00'; | |
30 | - | |
31 | - $users = DB::table('users') | |
32 | - ->where('created_at', '<', $date) | |
33 | - ->pluck('id'); | |
34 | - | |
35 | - if ($users->isEmpty()) { | |
36 | - $this->info('No users to delete.'); | |
37 | - return 0; | |
38 | - } | |
39 | - | |
40 | - $this->info('Found ' . $users->count() . ' users to delete.'); | |
41 | - | |
42 | - $userRelatedTables = [ | |
43 | - 'answers', | |
44 | - 'chats', | |
45 | - 'employers', | |
46 | - 'group_users', | |
47 | - 'group_works', | |
48 | -// 'like_vacancy', | |
49 | -// 'like_worker', | |
50 | - 'media', | |
51 | - 'messages', | |
52 | - 'messages_requests', | |
53 | - 'static_workers', | |
54 | - 'workers', | |
55 | - ]; | |
56 | - | |
57 | - $workerEmployerRelatedTables = [ | |
58 | - 'ad_employers' => 'employer_id', | |
59 | - 'answers' => 'employer_id', | |
60 | - 'employers_mains' => 'employer_id', | |
61 | - 'employer_autolift_options' => 'employer_id', | |
62 | - 'flots' => 'employer_id', | |
63 | - 'place_works' => 'worker_id', | |
64 | - 'prev_company' => 'worker_id', | |
65 | - 'response_works' => 'worker_id', | |
66 | - 'sertifications' => 'worker_id', | |
67 | - 'title_workers' => 'worker_id', | |
68 | - 'worker_autolift_options' => 'worker_id', | |
69 | - ]; | |
70 | - | |
71 | - try { | |
72 | - DB::beginTransaction(); | |
73 | - | |
74 | - foreach ($userRelatedTables as $table) { | |
75 | - DB::table($table)->whereIn('user_id', $users)->delete(); | |
76 | - $this->info("Removed related records from table: $table"); | |
77 | - } | |
78 | - | |
79 | - $workerIds = DB::table('workers')->whereIn('user_id', $users)->pluck('id'); | |
80 | - $employerIds = DB::table('employers')->whereIn('user_id', $users)->pluck('id'); | |
81 | - | |
82 | - foreach ($workerEmployerRelatedTables as $table => $column) { | |
83 | - DB::table($table)->whereIn($column, str_contains($column, 'worker') ? $workerIds : $employerIds)->delete(); | |
84 | - $this->info("Removed related records for table: $table"); | |
85 | - } | |
86 | - foreach (['like_vacancy', 'like_worker'] as $table) { | |
87 | - DB::table($table)->whereIn('user_id', $users->map(fn($id) => (string)$id))->delete(); | |
88 | - DB::table($table)->whereIn('user_id', $users->map(fn($id) => (string)$id))->delete(); | |
89 | - $this->info("Removed related records from table: $table (VARCHAR user_id)"); | |
90 | - } | |
91 | - DB::table('workers')->whereIn('id', $workerIds)->delete(); | |
92 | - DB::table('employers')->whereIn('id', $employerIds)->delete(); | |
93 | - DB::table('users')->whereIn('id', $users)->delete(); | |
94 | - | |
95 | - DB::commit(); | |
96 | - $this->info('All related data and users have been removed successfully.'); | |
97 | - } catch (\Exception $e) { | |
98 | - DB::rollBack(); | |
99 | - $this->error('An error occurred: ' . $e->getMessage()); | |
100 | - } | |
101 | - | |
102 | - return 0; | |
103 | - } | |
104 | - | |
105 | -} |
app/Console/Commands/ResetAdDate.php
... | ... | @@ -0,0 +1,37 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace App\Console\Commands; | |
4 | + | |
5 | +use App\Models\Employer; | |
6 | +use App\Models\Worker; | |
7 | +use Illuminate\Console\Command; | |
8 | +use Illuminate\Support\Facades\DB; | |
9 | + | |
10 | +class ResetAdDate extends Command | |
11 | +{ | |
12 | + /** | |
13 | + * The name and signature of the console command. | |
14 | + * | |
15 | + * @var string | |
16 | + */ | |
17 | + protected $signature = 'reset:ads'; | |
18 | + | |
19 | + /** | |
20 | + * The console command description. | |
21 | + * | |
22 | + * @var string | |
23 | + */ | |
24 | + protected $description = 'Command description'; | |
25 | + | |
26 | + /** | |
27 | + * Execute the console command. | |
28 | + * | |
29 | + * @return int | |
30 | + */ | |
31 | + public function handle() | |
32 | + { | |
33 | + DB::table('ad_employers') | |
34 | + ->update(['updated_at' => '2024-12-22 12:00']); | |
35 | + | |
36 | + } | |
37 | +} |
app/Http/Controllers/EmployerController.php
... | ... | @@ -31,6 +31,7 @@ use Illuminate\Http\RedirectResponse; |
31 | 31 | use Illuminate\Http\Request; |
32 | 32 | use Illuminate\Support\Facades\Auth; |
33 | 33 | use Illuminate\Support\Facades\Cache; |
34 | +use Illuminate\Support\Facades\DB; | |
34 | 35 | use Illuminate\Support\Facades\Hash; |
35 | 36 | use Illuminate\Support\Facades\Log; |
36 | 37 | use Illuminate\Support\Facades\Mail; |
... | ... | @@ -861,14 +862,17 @@ class EmployerController extends Controller |
861 | 862 | ); |
862 | 863 | |
863 | 864 | foreach ($request->get('vacancies') as $vacancy) { |
864 | - if ($vacancy['autolift_site']) { | |
865 | - Ad_employer::query() | |
866 | - ->where('id', $vacancy['id']) | |
867 | - ->update([ | |
868 | - 'autolift_site' => $vacancy['autolift_site'] === 'true', //they're arriving as strings | |
869 | - 'autosend_tg' => $vacancy['autosend_tg'] === 'true', | |
870 | - ]); | |
865 | + $data = [ | |
866 | + 'autolift_site' => $vacancy['autolift_site'] === 'true', | |
867 | + 'autosend_tg' => $vacancy['autosend_tg'] === 'true', | |
868 | + ]; | |
869 | + | |
870 | + if ($vacancy['autolift_site'] === 'true') { | |
871 | + $data['updated_at'] = now(); | |
871 | 872 | } |
873 | + | |
874 | + DB::table('ad_employers')->where('id', $vacancy['id']) | |
875 | + ->update($data); | |
872 | 876 | } |
873 | 877 | |
874 | 878 | return response(['success' => true]); |