diff --git a/src/Controller/ScheduledTaskController.php b/src/Controller/ScheduledTaskController.php
index 37462d4..46630af 100644
--- a/src/Controller/ScheduledTaskController.php
+++ b/src/Controller/ScheduledTaskController.php
@@ -14,6 +14,7 @@
use Shopware\Core\Framework\MessageQueue\ScheduledTask\Scheduler\TaskRunner;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
+use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
@@ -52,6 +53,30 @@ public function runTask(string $id, Context $context): JsonResponse
return new JsonResponse(null, Response::HTTP_NO_CONTENT);
}
+ #[Route(path: '/scheduled-task/schedule/{id}', name: 'api.frosh.tools.scheduled.task.schedule', methods: ['POST'])]
+ public function scheduleTask(Request $request, string $id, Context $context): JsonResponse
+ {
+ $scheduledTask = $this->fetchTask($id, $context);
+
+ if (!$scheduledTask instanceof ScheduledTaskEntity) {
+ return new JsonResponse(null, Response::HTTP_NOT_FOUND);
+ }
+
+ $data = [
+ 'id' => $id,
+ 'status' => ScheduledTaskDefinition::STATUS_SCHEDULED,
+ ];
+
+ $immediately = $request->request->has('immediately') && $request->request->get('immediately', false);
+ if ($immediately) {
+ $data['nextExecutionTime'] = new \DateTime();
+ }
+
+ $this->scheduledTaskRepository->update([$data], $context);
+
+ return new JsonResponse(null, Response::HTTP_NO_CONTENT);
+ }
+
#[Route(path: '/scheduled-tasks/register', name: 'api.frosh.tools.scheduled.tasks.register', methods: ['POST'])]
public function registerTasks(): JsonResponse
{
diff --git a/src/Resources/app/administration/src/api/frosh-tools.js b/src/Resources/app/administration/src/api/frosh-tools.js
index 0c15c94..cfdeb25 100644
--- a/src/Resources/app/administration/src/api/frosh-tools.js
+++ b/src/Resources/app/administration/src/api/frosh-tools.js
@@ -66,6 +66,21 @@ class FroshTools extends ApiService {
});
}
+ scheduleScheduledTask(id, immediately = false) {
+ const apiRoute = `${this.getApiBasePath()}/scheduled-task/schedule/${id}`;
+ return this.httpClient.post(
+ apiRoute,
+ {
+ 'immediately': immediately
+ },
+ {
+ headers: this.getBasicHeaders()
+ }
+ ).then((response) => {
+ return ApiService.handleResponse(response);
+ });
+ }
+
scheduledTasksRegister() {
const apiRoute = `${this.getApiBasePath()}/scheduled-tasks/register`;
return this.httpClient.post(
diff --git a/src/Resources/app/administration/src/module/frosh-tools/component/frosh-tools-tab-scheduled/index.js b/src/Resources/app/administration/src/module/frosh-tools/component/frosh-tools-tab-scheduled/index.js
index 7426ca6..2217c61 100644
--- a/src/Resources/app/administration/src/module/frosh-tools/component/frosh-tools-tab-scheduled/index.js
+++ b/src/Resources/app/administration/src/module/frosh-tools/component/frosh-tools-tab-scheduled/index.js
@@ -104,6 +104,28 @@ Component.register('frosh-tools-tab-scheduled', {
this.createdComponent();
},
+ async scheduleTask(item, immediately = false) {
+ this.isLoading = true;
+
+ try {
+ this.createNotificationInfo({
+ message: this.$tc('frosh-tools.scheduledTaskScheduleStarted', 0, {'name': item.name})
+ })
+ await this.froshToolsService.scheduleScheduledTask(item.id, immediately);
+ this.createNotificationSuccess({
+ message: this.$tc('frosh-tools.scheduledTaskScheduleSucceed', 0, {'name': item.name})
+ })
+ } catch (e) {
+ this.createNotificationError({
+ message: this.$tc('frosh-tools.scheduledTaskScheduleFailed', 0, {'name': item.name})
+ })
+
+ this.taskError = e.response.data;
+ }
+
+ this.createdComponent();
+ },
+
async registerScheduledTasks() {
this.isLoading = true;
diff --git a/src/Resources/app/administration/src/module/frosh-tools/component/frosh-tools-tab-scheduled/template.twig b/src/Resources/app/administration/src/module/frosh-tools/component/frosh-tools-tab-scheduled/template.twig
index 18b373b..0725be3 100644
--- a/src/Resources/app/administration/src/module/frosh-tools/component/frosh-tools-tab-scheduled/template.twig
+++ b/src/Resources/app/administration/src/module/frosh-tools/component/frosh-tools-tab-scheduled/template.twig
@@ -47,6 +47,12 @@
{{ $tc('frosh-tools.runManually') }}
+
+ {{ $tc('frosh-tools.setToScheduled') }}
+
+
+ {{ $tc('frosh-tools.setToScheduledImmediately') }}
+
diff --git a/src/Resources/app/administration/src/module/frosh-tools/snippet/de-DE.json b/src/Resources/app/administration/src/module/frosh-tools/snippet/de-DE.json
index ac9d49b..611b94a 100644
--- a/src/Resources/app/administration/src/module/frosh-tools/snippet/de-DE.json
+++ b/src/Resources/app/administration/src/module/frosh-tools/snippet/de-DE.json
@@ -77,6 +77,11 @@
"scheduledTaskStarted": "Die geplante Aufgabe für \"{name}\" wurde gestartet",
"scheduledTaskSucceed": "Die geplante Aufgabe für \"{name}\" war erfolgreich",
"scheduledTaskFailed": "Die geplante Aufgabe für \"{name}\" ist fehlgeschlagen",
+ "setToScheduled": "auf geplant setzen",
+ "setToScheduledImmediately": "auf sofort geplant setzen",
+ "scheduledTaskScheduleStarted": "Die geplante Aufgabe für \"{name}\" wird auf geplant gesetzt",
+ "scheduledTaskScheduleSucceed": "Die geplante Aufgabe für \"{name}\" wurde auf geplant gesetzt",
+ "scheduledTaskScheduleFailed": "Die geplante Aufgabe für \"{name}\" konnte nicht auf geplant gesetzt werden",
"scheduledTasksRegisterStarted": "Registriere geplante Aufgaben",
"scheduledTasksRegisterSucceed": "Geplante Aufgaben registriert",
"scheduledTasksRegisterFailed": "Es ist ein Fehler beim Registrieren aufgetreten",
diff --git a/src/Resources/app/administration/src/module/frosh-tools/snippet/en-GB.json b/src/Resources/app/administration/src/module/frosh-tools/snippet/en-GB.json
index 7b22676..19ce8c5 100644
--- a/src/Resources/app/administration/src/module/frosh-tools/snippet/en-GB.json
+++ b/src/Resources/app/administration/src/module/frosh-tools/snippet/en-GB.json
@@ -77,6 +77,11 @@
"scheduledTaskStarted": "The scheduled task execution for \"{name}\" started",
"scheduledTaskSucceed": "The scheduled task execution for \"{name}\" succeed",
"scheduledTaskFailed": "The scheduled task execution for \"{name}\" failed",
+ "setToScheduled": "Set task status to scheduled",
+ "setToScheduledImmediately": "Set task status to scheduled immediately",
+ "scheduledTaskScheduleStarted": "The scheduled task for \"{name}\" is being scheduled",
+ "scheduledTaskScheduleSucceed": "The scheduled task for \"{name}\" has been scheduled",
+ "scheduledTaskScheduleFailed": "The scheduled task for \"{name}\" could not be scheduled",
"scheduledTasksRegisterStarted": "Register scheduled tasks",
"scheduledTasksRegisterSucceed": "Scheduled tasks registered",
"scheduledTasksRegisterFailed": "Scheduled tasks registration failed",