Skip to content

Commit

Permalink
fix: fix stop rate manager process not stopping surveys (#1286)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss committed Aug 30, 2021
1 parent 5968928 commit 6a47a6b
Showing 1 changed file with 23 additions and 6 deletions.
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();
}
}

0 comments on commit 6a47a6b

Please sign in to comment.