bingo-soft /
jabe
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Jabe\Impl\Cmd; |
||
| 4 | |||
| 5 | use Jabe\Impl\Context\Context; |
||
| 6 | use Jabe\Impl\Interceptor\{ |
||
| 7 | CommandInterface, |
||
| 8 | CommandContext |
||
| 9 | }; |
||
| 10 | |||
| 11 | class DeleteJobsCmd implements CommandInterface |
||
| 12 | { |
||
| 13 | protected $jobIds = []; |
||
| 14 | protected $cascade; |
||
| 15 | |||
| 16 | public function __construct($jobIds, ?bool $cascade = false) |
||
| 17 | { |
||
| 18 | if (is_string($jobIds)) { |
||
| 19 | $this->jobIds[] = $jobIds; |
||
| 20 | } elseif (is_array($jobIds)) { |
||
| 21 | $this->jobIds = $jobIds; |
||
| 22 | } |
||
| 23 | $this->cascade = $cascade; |
||
| 24 | } |
||
| 25 | |||
| 26 | public function execute(CommandContext $commandContext) |
||
| 27 | { |
||
| 28 | $jobToDelete = null; |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 29 | foreach ($this->jobIds as $jobId) { |
||
| 30 | $jobToDelete = Context::getCommandContext() |
||
| 31 | ->getJobManager() |
||
| 32 | ->findJobById($jobId); |
||
| 33 | |||
| 34 | if ($jobToDelete !== null) { |
||
| 35 | // When given job doesn't exist, ignore |
||
| 36 | $jobToDelete->delete(); |
||
| 37 | |||
| 38 | if ($this->cascade) { |
||
| 39 | $commandContext |
||
| 40 | ->getHistoricJobLogManager() |
||
| 41 | ->deleteHistoricJobLogByJobId($this->jobId); |
||
|
0 ignored issues
–
show
|
|||
| 42 | } |
||
| 43 | } |
||
| 44 | } |
||
| 45 | return null; |
||
| 46 | } |
||
| 47 | } |
||
| 48 |