Remove unused code
This commit is contained in:
parent
734bdc7b78
commit
fd2ceacfe2
6 changed files with 0 additions and 691 deletions
|
@ -1,98 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Services\Schedules;
|
||||
|
||||
use Cron\CronExpression;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Pterodactyl\Services\Schedules\Tasks\TaskCreationService;
|
||||
use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
|
||||
|
||||
class ScheduleCreationService
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Schedules\Tasks\TaskCreationService
|
||||
*/
|
||||
protected $taskCreationService;
|
||||
|
||||
/**
|
||||
* ScheduleCreationService constructor.
|
||||
*
|
||||
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||
* @param \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface $repository
|
||||
* @param \Pterodactyl\Services\Schedules\Tasks\TaskCreationService $taskCreationService
|
||||
*/
|
||||
public function __construct(
|
||||
ConnectionInterface $connection,
|
||||
ScheduleRepositoryInterface $repository,
|
||||
TaskCreationService $taskCreationService
|
||||
) {
|
||||
$this->connection = $connection;
|
||||
$this->repository = $repository;
|
||||
$this->taskCreationService = $taskCreationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new schedule for a specific server.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @param array $data
|
||||
* @param array $tasks
|
||||
* @return \Pterodactyl\Models\Schedule
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Schedule\Task\TaskIntervalTooLongException
|
||||
*/
|
||||
public function handle(Server $server, array $data, array $tasks = [])
|
||||
{
|
||||
$data = array_merge($data, [
|
||||
'server_id' => $server->id,
|
||||
'next_run_at' => $this->getCronTimestamp($data),
|
||||
]);
|
||||
|
||||
$this->connection->beginTransaction();
|
||||
$schedule = $this->repository->create($data);
|
||||
|
||||
foreach ($tasks as $index => $task) {
|
||||
$this->taskCreationService->handle($schedule, [
|
||||
'time_interval' => array_get($task, 'time_interval'),
|
||||
'time_value' => array_get($task, 'time_value'),
|
||||
'sequence_id' => $index + 1,
|
||||
'action' => array_get($task, 'action'),
|
||||
'payload' => array_get($task, 'payload'),
|
||||
], false);
|
||||
}
|
||||
|
||||
$this->connection->commit();
|
||||
|
||||
return $schedule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a DateTime object after parsing the cron data provided.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \DateTime
|
||||
*/
|
||||
private function getCronTimestamp(array $data)
|
||||
{
|
||||
$formattedCron = sprintf('%s %s %s * %s',
|
||||
array_get($data, 'cron_minute', '*'),
|
||||
array_get($data, 'cron_hour', '*'),
|
||||
array_get($data, 'cron_day_of_month', '*'),
|
||||
array_get($data, 'cron_day_of_week', '*')
|
||||
);
|
||||
|
||||
return CronExpression::factory($formattedCron)->getNextRunDate();
|
||||
}
|
||||
}
|
|
@ -1,110 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Services\Schedules;
|
||||
|
||||
use Cron\CronExpression;
|
||||
use Pterodactyl\Models\Schedule;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Pterodactyl\Contracts\Repository\TaskRepositoryInterface;
|
||||
use Pterodactyl\Services\Schedules\Tasks\TaskCreationService;
|
||||
use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
|
||||
|
||||
class ScheduleUpdateService
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Schedules\Tasks\TaskCreationService
|
||||
*/
|
||||
private $taskCreationService;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\TaskRepositoryInterface
|
||||
*/
|
||||
private $taskRepository;
|
||||
|
||||
/**
|
||||
* ScheduleUpdateService constructor.
|
||||
*
|
||||
* @param \Illuminate\Database\ConnectionInterface $connection
|
||||
* @param \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface $repository
|
||||
* @param \Pterodactyl\Services\Schedules\Tasks\TaskCreationService $taskCreationService
|
||||
* @param \Pterodactyl\Contracts\Repository\TaskRepositoryInterface $taskRepository
|
||||
*/
|
||||
public function __construct(
|
||||
ConnectionInterface $connection,
|
||||
ScheduleRepositoryInterface $repository,
|
||||
TaskCreationService $taskCreationService,
|
||||
TaskRepositoryInterface $taskRepository
|
||||
) {
|
||||
$this->connection = $connection;
|
||||
$this->repository = $repository;
|
||||
$this->taskCreationService = $taskCreationService;
|
||||
$this->taskRepository = $taskRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing schedule by deleting all current tasks and re-inserting the
|
||||
* new values.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Schedule $schedule
|
||||
* @param array $data
|
||||
* @param array $tasks
|
||||
* @return \Pterodactyl\Models\Schedule
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Schedule\Task\TaskIntervalTooLongException
|
||||
*/
|
||||
public function handle(Schedule $schedule, array $data, array $tasks): Schedule
|
||||
{
|
||||
$data = array_merge($data, [
|
||||
'next_run_at' => $this->getCronTimestamp($data),
|
||||
]);
|
||||
|
||||
$this->connection->beginTransaction();
|
||||
|
||||
$schedule = $this->repository->update($schedule->id, $data);
|
||||
$this->taskRepository->deleteWhere([['schedule_id', '=', $schedule->id]]);
|
||||
|
||||
foreach ($tasks as $index => $task) {
|
||||
$this->taskCreationService->handle($schedule, [
|
||||
'time_interval' => array_get($task, 'time_interval'),
|
||||
'time_value' => array_get($task, 'time_value'),
|
||||
'sequence_id' => $index + 1,
|
||||
'action' => array_get($task, 'action'),
|
||||
'payload' => array_get($task, 'payload'),
|
||||
], false);
|
||||
}
|
||||
|
||||
$this->connection->commit();
|
||||
|
||||
return $schedule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a DateTime object after parsing the cron data provided.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \DateTime
|
||||
*/
|
||||
private function getCronTimestamp(array $data)
|
||||
{
|
||||
$formattedCron = sprintf('%s %s %s * %s',
|
||||
array_get($data, 'cron_minute', '*'),
|
||||
array_get($data, 'cron_hour', '*'),
|
||||
array_get($data, 'cron_day_of_month', '*'),
|
||||
array_get($data, 'cron_day_of_week', '*')
|
||||
);
|
||||
|
||||
return CronExpression::factory($formattedCron)->getNextRunDate();
|
||||
}
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Services\Schedules\Tasks;
|
||||
|
||||
use Webmozart\Assert\Assert;
|
||||
use Pterodactyl\Models\Schedule;
|
||||
use Pterodactyl\Contracts\Repository\TaskRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Service\Schedule\Task\TaskIntervalTooLongException;
|
||||
|
||||
class TaskCreationService
|
||||
{
|
||||
const MAX_INTERVAL_TIME_SECONDS = 900;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\TaskRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* TaskCreationService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Contracts\Repository\TaskRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(TaskRepositoryInterface $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new task that is assigned to a schedule.
|
||||
*
|
||||
* @param int|\Pterodactyl\Models\Schedule $schedule
|
||||
* @param array $data
|
||||
* @param bool $returnModel
|
||||
* @return bool|\Pterodactyl\Models\Task
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Service\Schedule\Task\TaskIntervalTooLongException
|
||||
*/
|
||||
public function handle($schedule, array $data, $returnModel = true)
|
||||
{
|
||||
Assert::true(($schedule instanceof Schedule || is_digit($schedule)),
|
||||
'First argument passed to handle must be numeric or instance of \Pterodactyl\Models\Schedule, received %s.'
|
||||
);
|
||||
|
||||
$schedule = ($schedule instanceof Schedule) ? $schedule->id : $schedule;
|
||||
$delay = $data['time_interval'] === 'm' ? $data['time_value'] * 60 : $data['time_value'];
|
||||
if ($delay > self::MAX_INTERVAL_TIME_SECONDS) {
|
||||
throw new TaskIntervalTooLongException(trans('exceptions.tasks.chain_interval_too_long'));
|
||||
}
|
||||
|
||||
$repository = ($returnModel) ? $this->repository : $this->repository->withoutFreshModel();
|
||||
$task = $repository->create([
|
||||
'schedule_id' => $schedule,
|
||||
'sequence_id' => $data['sequence_id'],
|
||||
'action' => $data['action'],
|
||||
'payload' => $data['payload'],
|
||||
'time_offset' => $delay,
|
||||
], false);
|
||||
|
||||
return $task;
|
||||
}
|
||||
}
|
Reference in a new issue