Skip to content

Commit 8ab1c59

Browse files
added output
1 parent 5696ca2 commit 8ab1c59

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

src/Command/ScheduleSystemTasksCommand.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
9999
}
100100

101101
foreach ($this->taskRepository->findSystemTasks() as $task) {
102-
if (!in_array($task->getSystemKey(), array_keys($this->systemTasks))) {
103-
$this->disableTask($task);
102+
if (!in_array($task->getSystemKey(), array_keys($this->systemTasks)) && ($this->disableTask($task))) {
103+
$output->writeln(
104+
sprintf(' * System-task "%s" was <comment>disabled</comment>', $task->getSystemKey())
105+
);
104106
}
105107
}
106108

@@ -118,17 +120,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
118120
private function processSystemTask($systemKey, array $systemTask, OutputInterface $output)
119121
{
120122
if (!$systemTask['enabled']) {
121-
$this->disableSystemTask($systemKey);
122-
123-
$output->writeln(sprintf(' * System-task "%s" was <info>disabled</info>.', $systemKey));
123+
if ($this->disableSystemTask($systemKey)) {
124+
$output->writeln(sprintf(' * System-task "%s" was <comment>disabled</comment>', $systemKey));
125+
}
124126

125127
return;
126128
}
127129

128130
if ($task = $this->taskRepository->findBySystemKey($systemKey)) {
129131
$this->updateTask($systemKey, $systemTask, $task);
130132

131-
$output->writeln(sprintf(' * System-task "%s" was <info>updated</info>.', $systemKey));
133+
$output->writeln(sprintf(' * System-task "%s" was <info>updated</info>', $systemKey));
132134

133135
return;
134136
}
@@ -142,32 +144,39 @@ private function processSystemTask($systemKey, array $systemTask, OutputInterfac
142144

143145
$builder->schedule();
144146

145-
$output->writeln(sprintf(' * System-task "%s" was <info>created</info>.', $systemKey));
147+
$output->writeln(sprintf(' * System-task "%s" was <info>created</info>', $systemKey));
146148
}
147149

148150
/**
149151
* Disable task identified by system-key.
150152
*
151153
* @param string $systemKey
154+
*
155+
* @return bool
152156
*/
153157
private function disableSystemTask($systemKey)
154158
{
155159
if (!$task = $this->taskRepository->findBySystemKey($systemKey)) {
156-
return;
160+
return false;
157161
}
158162

159163
$this->disableTask($task);
164+
165+
return true;
160166
}
161167

162168
/**
163169
* Disable given task identified.
164170
*
165171
* @param TaskInterface $task
172+
*
173+
* @return bool
166174
*/
167175
public function disableTask(TaskInterface $task)
168176
{
169177
$task->setInterval($task->getInterval(), $task->getFirstExecution(), new \DateTime());
170-
$this->abortPending($task);
178+
179+
return $this->abortPending($task);
171180
}
172181

173182
/**
@@ -201,14 +210,18 @@ private function updateTask($systemKey, array $systemTask, TaskInterface $task)
201210
* Abort pending execution for given task.
202211
*
203212
* @param TaskInterface $task
213+
*
214+
* @return bool
204215
*/
205216
private function abortPending(TaskInterface $task)
206217
{
207218
if (!$execution = $this->taskExecutionRepository->findPending($task)) {
208-
return;
219+
return false;
209220
}
210221

211222
$execution->setStatus(TaskStatus::ABORTED);
212223
$this->taskExecutionRepository->save($execution);
224+
225+
return true;
213226
}
214227
}

0 commit comments

Comments
 (0)