From c0b90c9dfd4ad8577cfc2246020b744407259d31 Mon Sep 17 00:00:00 2001 From: team 1 Date: Mon, 16 Feb 2026 08:58:40 +0100 Subject: [PATCH] add auto ingest by new docs --- src/Controller/Admin/DocumentController.php | 43 +++++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/src/Controller/Admin/DocumentController.php b/src/Controller/Admin/DocumentController.php index cffd794..eef57c7 100644 --- a/src/Controller/Admin/DocumentController.php +++ b/src/Controller/Admin/DocumentController.php @@ -65,12 +65,12 @@ class DocumentController extends AbstractController Request $request, DocumentService $documentService, FormatText $formatText, + IngestJobService $jobService, ParameterBagInterface $params ): Response { if ($request->isMethod('POST')) { - $file = $request->files->get('file'); $title = $request->request->get('title') ?: $file->getClientOriginalName(); $title = $formatText->slugify($title); @@ -96,13 +96,50 @@ class DocumentController extends AbstractController $filePath = $uploadDir . '/' . $newFilename; - $documentService->createDocument( + // Dokument erstellen + $document = $documentService->createDocument( $title, $filePath, $this->getUser() ); - return $this->redirectToRoute('admin_documents'); + // --------------------------------------------------------- + // AUTO-INTEGRATION: gleicher Flow wie "Version aktivieren" + // --------------------------------------------------------- + + $version = $document->getCurrentVersion(); + + $job = $jobService->startJob( + IngestJob::TYPE_DOCUMENT_VERSION_ACTIVATE, + $this->getUser(), + $version->getDocument()->getId(), + $version->getId(), + null, + IngestJob::STATUS_QUEUED + ); + + $projectDir = (string)$this->getParameter('kernel.project_dir'); + $console = $projectDir . '/bin/console'; + + $cmd = sprintf( + '%s %s %s %s > /dev/null 2>&1 &', + escapeshellarg($console), + escapeshellarg('mto:agent:ingest:run'), + escapeshellarg((string)$job->getId()), + escapeshellarg('--no-interaction'), + ); + + if (!function_exists('exec')) { + $jobService->markFailed($job, 'Server configuration does not allow background execution (exec disabled).'); + $this->addFlash('danger', 'Dokument erstellt, aber Ingest konnte nicht asynchron gestartet werden.'); + return $this->redirectToRoute('admin_documents'); + } + + exec($cmd); + + return $this->redirectToRoute('admin_job_show', [ + 'id' => (string)$job->getId(), + ]); } return $this->render('admin/document/new.html.twig');