Skip to content
This repository has been archived by the owner on Feb 8, 2025. It is now read-only.

fix: fix stop rate manager process not stopping surveys #1286

Merged
merged 3 commits into from
Aug 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions app/Jobs/StopRateYourManagerProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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) {
$this->updateSurveys($survey);
}
});
} 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) {
$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();
}
}