add auto ingest by new docs
This commit is contained in:
@@ -65,12 +65,12 @@ class DocumentController extends AbstractController
|
|||||||
Request $request,
|
Request $request,
|
||||||
DocumentService $documentService,
|
DocumentService $documentService,
|
||||||
FormatText $formatText,
|
FormatText $formatText,
|
||||||
|
IngestJobService $jobService,
|
||||||
ParameterBagInterface $params
|
ParameterBagInterface $params
|
||||||
): Response
|
): Response
|
||||||
{
|
{
|
||||||
if ($request->isMethod('POST')) {
|
if ($request->isMethod('POST')) {
|
||||||
|
|
||||||
|
|
||||||
$file = $request->files->get('file');
|
$file = $request->files->get('file');
|
||||||
$title = $request->request->get('title') ?: $file->getClientOriginalName();
|
$title = $request->request->get('title') ?: $file->getClientOriginalName();
|
||||||
$title = $formatText->slugify($title);
|
$title = $formatText->slugify($title);
|
||||||
@@ -96,13 +96,50 @@ class DocumentController extends AbstractController
|
|||||||
|
|
||||||
$filePath = $uploadDir . '/' . $newFilename;
|
$filePath = $uploadDir . '/' . $newFilename;
|
||||||
|
|
||||||
$documentService->createDocument(
|
// Dokument erstellen
|
||||||
|
$document = $documentService->createDocument(
|
||||||
$title,
|
$title,
|
||||||
$filePath,
|
$filePath,
|
||||||
$this->getUser()
|
$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');
|
return $this->render('admin/document/new.html.twig');
|
||||||
|
|||||||
Reference in New Issue
Block a user