Reset is_processing state of a schedule when toggling active/inactive; closes #2425
This commit is contained in:
parent
57457f0e9c
commit
2d01c7b988
2 changed files with 60 additions and 11 deletions
|
@ -120,15 +120,27 @@ class ScheduleController extends ClientApiController
|
|||
*/
|
||||
public function update(UpdateScheduleRequest $request, Server $server, Schedule $schedule)
|
||||
{
|
||||
$this->repository->update($schedule->id, [
|
||||
$active = (bool) $request->input('is_active');
|
||||
|
||||
$data = [
|
||||
'name' => $request->input('name'),
|
||||
'cron_day_of_week' => $request->input('day_of_week'),
|
||||
'cron_day_of_month' => $request->input('day_of_month'),
|
||||
'cron_hour' => $request->input('hour'),
|
||||
'cron_minute' => $request->input('minute'),
|
||||
'is_active' => (bool) $request->input('is_active'),
|
||||
'is_active' => $active,
|
||||
'next_run_at' => $this->getNextRunAt($request),
|
||||
]);
|
||||
];
|
||||
|
||||
// Toggle the processing state of the scheduled task when it is enabled or disabled so that an
|
||||
// invalid state can be reset without manual database intervention.
|
||||
//
|
||||
// @see https://github.com/pterodactyl/panel/issues/2425
|
||||
if ($schedule->is_active !== $active) {
|
||||
$data['is_processing'] = false;
|
||||
}
|
||||
|
||||
$this->repository->update($schedule->id, $data);
|
||||
|
||||
return $this->fractal->item($schedule->refresh())
|
||||
->transformWith($this->getTransformer(ScheduleTransformer::class))
|
||||
|
|
|
@ -9,6 +9,20 @@ use Pterodactyl\Tests\Integration\Api\Client\ClientApiIntegrationTestCase;
|
|||
|
||||
class UpdateServerScheduleTest extends ClientApiIntegrationTestCase
|
||||
{
|
||||
/**
|
||||
* The data to use when updating a schedule.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $updateData = [
|
||||
'name' => 'Updated Schedule Name',
|
||||
'minute' => '5',
|
||||
'hour' => '*',
|
||||
'day_of_week' => '*',
|
||||
'day_of_month' => '*',
|
||||
'is_active' => false,
|
||||
];
|
||||
|
||||
/**
|
||||
* Test that a schedule can be updated.
|
||||
*
|
||||
|
@ -24,14 +38,7 @@ class UpdateServerScheduleTest extends ClientApiIntegrationTestCase
|
|||
$expected = Utilities::getScheduleNextRunDate('5', '*', '*', '*');
|
||||
|
||||
$response = $this->actingAs($user)
|
||||
->postJson("/api/client/servers/{$server->uuid}/schedules/{$schedule->id}", [
|
||||
'name' => 'Updated Schedule Name',
|
||||
'minute' => '5',
|
||||
'hour' => '*',
|
||||
'day_of_week' => '*',
|
||||
'day_of_month' => '*',
|
||||
'is_active' => false,
|
||||
]);
|
||||
->postJson("/api/client/servers/{$server->uuid}/schedules/{$schedule->id}", $this->updateData);
|
||||
|
||||
$schedule = $schedule->refresh();
|
||||
|
||||
|
@ -74,6 +81,36 @@ class UpdateServerScheduleTest extends ClientApiIntegrationTestCase
|
|||
->assertForbidden();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the "is_processing" field gets reset to false when the schedule is enabled
|
||||
* or disabled so that an invalid state can be more easily fixed.
|
||||
*
|
||||
* @see https://github.com/pterodactyl/panel/issues/2425
|
||||
*/
|
||||
public function testScheduleIsProcessingIsSetToFalseWhenActiveStateChanges()
|
||||
{
|
||||
[$user, $server] = $this->generateTestAccount();
|
||||
|
||||
/** @var \Pterodactyl\Models\Schedule $schedule */
|
||||
$schedule = factory(Schedule::class)->create([
|
||||
'server_id' => $server->id,
|
||||
'is_active' => true,
|
||||
'is_processing' => true,
|
||||
]);
|
||||
|
||||
$this->assertTrue($schedule->is_active);
|
||||
$this->assertTrue($schedule->is_processing);
|
||||
|
||||
$response = $this->actingAs($user)
|
||||
->postJson("/api/client/servers/{$server->uuid}/schedules/{$schedule->id}", $this->updateData);
|
||||
|
||||
$schedule = $schedule->refresh();
|
||||
|
||||
$response->assertOk();
|
||||
$this->assertFalse($schedule->is_active);
|
||||
$this->assertFalse($schedule->is_processing);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue