optimize reset and ux
This commit is contained in:
@@ -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');
|
||||
$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.');
|
||||
@@ -107,11 +104,12 @@ class DocumentController extends AbstractController
|
||||
|
||||
#[Route('/{id}/version/new', name: 'admin_document_version_new', requirements: ['id' => '[0-9a-fA-F\-]{36}'])]
|
||||
public function newVersion(
|
||||
string $id,
|
||||
Request $request,
|
||||
string $id,
|
||||
Request $request,
|
||||
EntityManagerInterface $em,
|
||||
DocumentService $documentService
|
||||
): Response {
|
||||
DocumentService $documentService
|
||||
): Response
|
||||
{
|
||||
|
||||
$document = $em->getRepository(Document::class)->find($id);
|
||||
|
||||
@@ -165,11 +163,12 @@ class DocumentController extends AbstractController
|
||||
methods: ['POST']
|
||||
)]
|
||||
public function activateVersion(
|
||||
string $versionId,
|
||||
Request $request,
|
||||
string $versionId,
|
||||
Request $request,
|
||||
EntityManagerInterface $em,
|
||||
DocumentService $documentService
|
||||
): RedirectResponse {
|
||||
DocumentService $documentService
|
||||
): RedirectResponse
|
||||
{
|
||||
|
||||
if (!$this->isCsrfTokenValid('activate_version', $request->request->get('_token'))) {
|
||||
throw $this->createAccessDeniedException();
|
||||
@@ -195,11 +194,12 @@ class DocumentController extends AbstractController
|
||||
methods: ['POST']
|
||||
)]
|
||||
public function ingestVersion(
|
||||
string $versionId,
|
||||
Request $request,
|
||||
string $versionId,
|
||||
Request $request,
|
||||
EntityManagerInterface $em,
|
||||
IngestJobService $jobService,
|
||||
): ?RedirectResponse {
|
||||
IngestJobService $jobService,
|
||||
): ?RedirectResponse
|
||||
{
|
||||
$dryRun = false;
|
||||
if (!$this->isCsrfTokenValid('ingest_version', $request->request->get('_token'))) {
|
||||
throw $this->createAccessDeniedException();
|
||||
@@ -238,14 +238,14 @@ class DocumentController extends AbstractController
|
||||
);
|
||||
|
||||
// Hintergrundprozess starten (Provider-kompatibel, kein Worker/Daemon)
|
||||
$projectDir = (string) $this->getParameter('kernel.project_dir');
|
||||
$console = $projectDir . '/bin/console';
|
||||
$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((string)$job->getId()),
|
||||
escapeshellarg('--no-interaction'),
|
||||
);
|
||||
|
||||
@@ -261,8 +261,32 @@ class DocumentController extends AbstractController
|
||||
exec($cmd);
|
||||
|
||||
return $this->redirectToRoute('admin_job_show', [
|
||||
'id' => (string) $job->getId(),
|
||||
'id' => (string)$job->getId(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[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');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user