From 88c36e0e507447ecbf705d8fd7d37ec54b64729c Mon Sep 17 00:00:00 2001 From: Regis Freyd Date: Sun, 29 Aug 2021 16:58:35 -0400 Subject: [PATCH 1/3] fix: fix stop rate manager process not stopping surveys --- app/Jobs/StopRateYourManagerProcess.php | 29 ++++++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/app/Jobs/StopRateYourManagerProcess.php b/app/Jobs/StopRateYourManagerProcess.php index ed8cd0f39..560b8778d 100644 --- a/app/Jobs/StopRateYourManagerProcess.php +++ b/app/Jobs/StopRateYourManagerProcess.php @@ -9,6 +9,7 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; +use App\Models\Company\RateYourManagerSurvey; class StopRateYourManagerProcess implements ShouldQueue { @@ -31,14 +32,30 @@ public function __construct(bool $force = false) public function handle(): void { if ($this->force) { - DB::table('rate_your_manager_surveys') - ->where('active', 1) - ->update(['active' => 0]); + RateYourManagerSurvey::where('active', true) + ->chunk(200, function ($surveys) { + foreach ($surveys as $survey) { + DB::table('rate_your_manager_answers') + ->where('rate_your_manager_survey_id', $survey->id) + ->update(['active' => 0]); + + $survey->active = false; + $survey->save(); + } + }); } else { - DB::table('rate_your_manager_surveys') - ->where('active', 1) + RateYourManagerSurvey::where('active', true) ->where('valid_until_at', '<', Carbon::now()->format('Y-m-d H:i:s')) - ->update(['active' => 0]); + ->chunk(200, function ($surveys) { + foreach ($surveys as $survey) { + DB::table('rate_your_manager_answers') + ->where('rate_your_manager_survey_id', $survey->id) + ->update(['active' => 0]); + + $survey->active = false; + $survey->save(); + } + }); } } } From 88cd76e2e8dc9aadb7862ac7aa3112a7be0b06e7 Mon Sep 17 00:00:00 2001 From: Regis Freyd Date: Sun, 29 Aug 2021 16:59:32 -0400 Subject: [PATCH 2/3] Update StopRateYourManagerProcess.php --- app/Jobs/StopRateYourManagerProcess.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Jobs/StopRateYourManagerProcess.php b/app/Jobs/StopRateYourManagerProcess.php index 560b8778d..1d3a91a94 100644 --- a/app/Jobs/StopRateYourManagerProcess.php +++ b/app/Jobs/StopRateYourManagerProcess.php @@ -36,7 +36,7 @@ public function handle(): void ->chunk(200, function ($surveys) { foreach ($surveys as $survey) { DB::table('rate_your_manager_answers') - ->where('rate_your_manager_survey_id', $survey->id) + ->where('rate_your_manager_survey_id', $survey->id) ->update(['active' => 0]); $survey->active = false; @@ -49,7 +49,7 @@ public function handle(): void ->chunk(200, function ($surveys) { foreach ($surveys as $survey) { DB::table('rate_your_manager_answers') - ->where('rate_your_manager_survey_id', $survey->id) + ->where('rate_your_manager_survey_id', $survey->id) ->update(['active' => 0]); $survey->active = false; From ac7e28c1a3ed8d33e6af6c4bb32ce7aa56d2d761 Mon Sep 17 00:00:00 2001 From: Regis Freyd Date: Sun, 29 Aug 2021 17:00:34 -0400 Subject: [PATCH 3/3] Update StopRateYourManagerProcess.php --- app/Jobs/StopRateYourManagerProcess.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/app/Jobs/StopRateYourManagerProcess.php b/app/Jobs/StopRateYourManagerProcess.php index 1d3a91a94..6a7818ca0 100644 --- a/app/Jobs/StopRateYourManagerProcess.php +++ b/app/Jobs/StopRateYourManagerProcess.php @@ -35,12 +35,7 @@ public function handle(): void RateYourManagerSurvey::where('active', true) ->chunk(200, function ($surveys) { foreach ($surveys as $survey) { - DB::table('rate_your_manager_answers') - ->where('rate_your_manager_survey_id', $survey->id) - ->update(['active' => 0]); - - $survey->active = false; - $survey->save(); + $this->updateSurveys($survey); } }); } else { @@ -48,14 +43,19 @@ public function handle(): void ->where('valid_until_at', '<', Carbon::now()->format('Y-m-d H:i:s')) ->chunk(200, function ($surveys) { foreach ($surveys as $survey) { - DB::table('rate_your_manager_answers') - ->where('rate_your_manager_survey_id', $survey->id) - ->update(['active' => 0]); - - $survey->active = false; - $survey->save(); + $this->updateSurveys($survey); } }); } } + + private function updateSurveys(RateYourManagerSurvey $survey): void + { + DB::table('rate_your_manager_answers') + ->where('rate_your_manager_survey_id', $survey->id) + ->update(['active' => 0]); + + $survey->active = false; + $survey->save(); + } }