diff --git a/config/services.yaml b/config/services.yaml index a468fe7..eca9290 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -15,6 +15,11 @@ parameters: mto.vector.ingest_script: '/src/Vector/vector_ingest.py' mto.vector.data.path: '%kernel.project_dir%/var/knowledge' + mto.vector.data.upload.path: '%mto.vector.data.path%/uploads' + mto.vector.data.ndjson.path: '%mto.vector.data.path%/index.ndjson' + mto.vector.data.vector_index.path: '%mto.vector.data.path%/vector.index' + mto.vector.data.vector_index_meta_json.path: '%mto.vector.data.path%/vector.index.meta.json' + mto.vector.timeout: 600 # ------------------------------------------------------------ diff --git a/src/Controller/Admin/DocumentController.php b/src/Controller/Admin/DocumentController.php index 9e62de1..46435ac 100644 --- a/src/Controller/Admin/DocumentController.php +++ b/src/Controller/Admin/DocumentController.php @@ -19,6 +19,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Uid\Uuid; +use function function_exists; #[Route('/admin/documents')] class DocumentController extends AbstractController @@ -60,7 +61,12 @@ class DocumentController extends AbstractController } #[Route('/new', name: 'admin_document_new')] - public function new(Request $request, DocumentService $documentService, FormatText $formatText): Response + public function new( + Request $request, + DocumentService $documentService, + FormatText $formatText, + ParameterBagInterface $params + ): Response { if ($request->isMethod('POST')) { @@ -74,7 +80,7 @@ class DocumentController extends AbstractController return $this->redirectToRoute('admin_document_new'); } - $uploadDir = $this->getParameter('kernel.project_dir') . '/var/knowledge/uploads'; + $uploadDir = $params->get('mto.vector.data.upload.path'); if (!is_dir($uploadDir)) { mkdir($uploadDir, 0777, true); @@ -107,7 +113,8 @@ class DocumentController extends AbstractController string $id, Request $request, EntityManagerInterface $em, - DocumentService $documentService + DocumentService $documentService, + ParameterBagInterface $params ): Response { @@ -126,7 +133,7 @@ class DocumentController extends AbstractController return $this->redirectToRoute('admin_document_version_new', ['id' => $id]); } - $uploadDir = $this->getParameter('kernel.project_dir') . '/var/knowledge/uploads'; + $uploadDir = $params->get('mto.vector.data.upload.path'); if (!is_dir($uploadDir)) { mkdir($uploadDir, 0777, true); @@ -250,7 +257,7 @@ class DocumentController extends AbstractController ); // Best effort: wenn exec deaktiviert ist, sauber abbrechen. - if (!\function_exists('exec')) { + if (!function_exists('exec')) { $jobService->markFailed($job, 'Server configuration does not allow background execution (exec disabled).'); $this->addFlash('error', 'Ingest konnte nicht asynchron gestartet werden (exec deaktiviert).'); return $this->redirectToRoute('admin_document_show', [ @@ -272,9 +279,16 @@ class DocumentController extends AbstractController )] public function resetCompleteSystem(ParameterBagInterface $params, Connection $connection): ?RedirectResponse { - @unlink($params->get('mto.vector.data.path') . '/index.ndjson'); - @unlink($params->get('mto.vector.data.path') . '/vector.index'); - @unlink($params->get('mto.vector.data.path') . '/vector.index.meta.json'); + if (!function_exists('exec')) { + $this->addFlash('danger', 'Der Reset konnte nicht gestartet werden (exec deaktiviert).'); + return $this->redirectToRoute('admin_dashboard'); + } + + @unlink($params->get('mto.vector.data.ndjson.path')); + @unlink($params->get('mto.vector.data.vector_index.path')); + @unlink($params->get('mto.vector.data.vector_index_meta_json.path')); + exec('rm -rf ' . $params->get('mto.vector.data.upload.path')); + $sql = ' SET FOREIGN_KEY_CHECKS = 0; TRUNCATE TABLE db.document; @@ -287,6 +301,8 @@ class DocumentController extends AbstractController SET FOREIGN_KEY_CHECKS = 1; '; $connection->executeQuery($sql); + + $this->addFlash('success', 'Das System wurde erfolgreich zurückgesetzt.'); return $this->redirectToRoute('admin_dashboard'); } } diff --git a/templates/admin/dashboard/index.html.twig b/templates/admin/dashboard/index.html.twig index 0504c5d..6246e77 100644 --- a/templates/admin/dashboard/index.html.twig +++ b/templates/admin/dashboard/index.html.twig @@ -16,11 +16,21 @@
-
+

Reset des Systems

Unwiderruflicher Reset des gesamten Systems

- - + {% for label, messages in app.flashes %} + {% for message in messages %} + + {% endfor %} + {% endfor %} +
+ + +
+
diff --git a/templates/admin/job/show.html.twig b/templates/admin/job/show.html.twig index 28a6f41..f185bcc 100644 --- a/templates/admin/job/show.html.twig +++ b/templates/admin/job/show.html.twig @@ -86,21 +86,21 @@ - {% if job.errorMessage %} -
- Fehler:
- {{ job.errorMessage }} -
- {% endif %} + {% if job.errorMessage %} +
+ Fehler:
+ {{ job.errorMessage }} +
+ {% endif %} - {% if job.logPath %} -
- Log Datei:
- {{ job.logPath }} -
- {% endif %} + {% if job.logPath %} +
+ Log Datei:
+ {{ job.logPath }} +
+ {% endif %} - +