add document dele and rebuild faiss index
This commit is contained in:
@@ -411,4 +411,80 @@ class DocumentController extends AbstractController
|
||||
$this->addFlash('success', 'Das System wurde erfolgreich zurückgesetzt.');
|
||||
return $this->redirectToRoute('admin_dashboard');
|
||||
}
|
||||
|
||||
#[Route(
|
||||
'/{id}/delete',
|
||||
name: 'admin_document_delete',
|
||||
requirements: ['id' => '[0-9a-fA-F\-]{36}'],
|
||||
methods: ['POST']
|
||||
)]
|
||||
public function deleteDocument(
|
||||
string $id,
|
||||
Request $request,
|
||||
EntityManagerInterface $em,
|
||||
DocumentService $documentService,
|
||||
IngestJobService $jobService,
|
||||
): RedirectResponse
|
||||
{
|
||||
if (!$this->isCsrfTokenValid('delete_document', $request->request->get('_token'))) {
|
||||
throw $this->createAccessDeniedException();
|
||||
}
|
||||
|
||||
try {
|
||||
$uuid = Uuid::fromString($id);
|
||||
} catch (\Exception $e) {
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
|
||||
$document = $em->getRepository(Document::class)->find($uuid);
|
||||
|
||||
if (!$document) {
|
||||
throw $this->createNotFoundException();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// 1) Delete-Job anlegen (QUEUED)
|
||||
// ---------------------------------------------------------
|
||||
$job = $jobService->startJob(
|
||||
IngestJob::TYPE_DOCUMENT_DELETE,
|
||||
$this->getUser(),
|
||||
$document->getId(),
|
||||
null,
|
||||
null,
|
||||
IngestJob::STATUS_QUEUED
|
||||
);
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// 2) Hard Delete in DB
|
||||
// ---------------------------------------------------------
|
||||
$documentService->delete($document);
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// 3) Hintergrundprozess starten
|
||||
// ---------------------------------------------------------
|
||||
$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 gelöscht, aber Index-Bereinigung konnte nicht asynchron gestartet werden.');
|
||||
return $this->redirectToRoute('admin_documents');
|
||||
}
|
||||
|
||||
exec($cmd);
|
||||
|
||||
$this->addFlash('success', 'Dokument gelöscht. Index-Bereinigung läuft im Hintergrund.');
|
||||
|
||||
return $this->redirectToRoute('admin_job_show', [
|
||||
'id' => (string)$job->getId(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user