optimize reset and ux

This commit is contained in:
team 1
2026-02-15 16:49:43 +01:00
parent c099f72703
commit 402838adfa
4 changed files with 71 additions and 31 deletions

View File

@@ -3,6 +3,8 @@
# ------------------------------------------------------------
parameters:
mto.kernel.dir: '%kernel.project_dir%'
mto.index.chunk_size: 800
mto.index.chunk_overlap: 100
mto.index.embedding_model: 'nomic-embed-text'
@@ -11,6 +13,8 @@ parameters:
mto.vector.python_bin: '/var/www/html/.venv/bin/python3'
mto.vector.ingest_script: '/src/Vector/vector_ingest.py'
mto.vector.data.path: '%kernel.project_dir%/var/knowledge'
mto.vector.timeout: 600
# ------------------------------------------------------------

View File

@@ -14,4 +14,5 @@ final class DashboardController extends AbstractController
{
return $this->render('admin/dashboard/index.html.twig');
}
}

View File

@@ -8,24 +8,21 @@ use App\Entity\IngestJob;
use App\Service\DocumentService;
use App\Service\FormatText;
use App\Service\IngestJobService;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Uid\Uuid;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Uid\Uuid;
#[Route('/admin/documents')]
class DocumentController extends AbstractController
{
public function __construct(
private readonly FormatText $formatText,
)
{
}
#[Route('', name: 'admin_documents')]
public function index(EntityManagerInterface $em): Response
@@ -63,14 +60,14 @@ class DocumentController extends AbstractController
}
#[Route('/new', name: 'admin_document_new')]
public function new(Request $request, DocumentService $documentService): Response
public function new(Request $request, DocumentService $documentService, FormatText $formatText): Response
{
if ($request->isMethod('POST')) {
$file = $request->files->get('file');
$title = $request->request->get('title') ?: $file->getClientOriginalName();
$title = $this->formatText->slugify($title);
$title = $formatText->slugify($title);
if (!$file || !$title) {
$this->addFlash('error', 'Titel und Datei sind erforderlich.');
@@ -111,7 +108,8 @@ class DocumentController extends AbstractController
Request $request,
EntityManagerInterface $em,
DocumentService $documentService
): Response {
): Response
{
$document = $em->getRepository(Document::class)->find($id);
@@ -169,7 +167,8 @@ class DocumentController extends AbstractController
Request $request,
EntityManagerInterface $em,
DocumentService $documentService
): RedirectResponse {
): RedirectResponse
{
if (!$this->isCsrfTokenValid('activate_version', $request->request->get('_token'))) {
throw $this->createAccessDeniedException();
@@ -199,7 +198,8 @@ class DocumentController extends AbstractController
Request $request,
EntityManagerInterface $em,
IngestJobService $jobService,
): ?RedirectResponse {
): ?RedirectResponse
{
$dryRun = false;
if (!$this->isCsrfTokenValid('ingest_version', $request->request->get('_token'))) {
throw $this->createAccessDeniedException();
@@ -265,4 +265,28 @@ class DocumentController extends AbstractController
]);
}
#[Route(
'/reset',
name: 'admin_document_reset',
methods: ['POST']
)]
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');
$sql = '
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE db.document;
SET FOREIGN_KEY_CHECKS = 1;
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE db.document_version;
SET FOREIGN_KEY_CHECKS = 1;
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE db.ingest_job;
SET FOREIGN_KEY_CHECKS = 1;
';
$connection->executeQuery($sql);
return $this->redirectToRoute('admin_dashboard');
}
}

View File

@@ -16,6 +16,17 @@
<hr class="border-secondary">
<form method="post" action="/admin/documents/reset" class="text-danger" onsubmit="return resetSystem()">
<p class="fw-bold">Reset des Systems</p>
<p>Unwiderruflicher Reset des gesamten Systems</p>
<button type="submit" class="btn btn-outline-danger">Reset System</button>
</form>
</div>
</div>
<script>
function resetSystem() {
return confirm('Sind Sie sicher, dass Sie das gesamte System zurücksetzen möchten?');
}
</script>
{% endblock %}