harden reset system
This commit is contained in:
@@ -15,6 +15,11 @@ parameters:
|
|||||||
mto.vector.ingest_script: '/src/Vector/vector_ingest.py'
|
mto.vector.ingest_script: '/src/Vector/vector_ingest.py'
|
||||||
|
|
||||||
mto.vector.data.path: '%kernel.project_dir%/var/knowledge'
|
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
|
mto.vector.timeout: 600
|
||||||
|
|
||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ use Symfony\Component\HttpFoundation\Response;
|
|||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
use Symfony\Component\Uid\Uuid;
|
use Symfony\Component\Uid\Uuid;
|
||||||
|
use function function_exists;
|
||||||
|
|
||||||
#[Route('/admin/documents')]
|
#[Route('/admin/documents')]
|
||||||
class DocumentController extends AbstractController
|
class DocumentController extends AbstractController
|
||||||
@@ -60,7 +61,12 @@ class DocumentController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[Route('/new', name: 'admin_document_new')]
|
#[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')) {
|
if ($request->isMethod('POST')) {
|
||||||
|
|
||||||
@@ -74,7 +80,7 @@ class DocumentController extends AbstractController
|
|||||||
return $this->redirectToRoute('admin_document_new');
|
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)) {
|
if (!is_dir($uploadDir)) {
|
||||||
mkdir($uploadDir, 0777, true);
|
mkdir($uploadDir, 0777, true);
|
||||||
@@ -107,7 +113,8 @@ class DocumentController extends AbstractController
|
|||||||
string $id,
|
string $id,
|
||||||
Request $request,
|
Request $request,
|
||||||
EntityManagerInterface $em,
|
EntityManagerInterface $em,
|
||||||
DocumentService $documentService
|
DocumentService $documentService,
|
||||||
|
ParameterBagInterface $params
|
||||||
): Response
|
): Response
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -126,7 +133,7 @@ class DocumentController extends AbstractController
|
|||||||
return $this->redirectToRoute('admin_document_version_new', ['id' => $id]);
|
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)) {
|
if (!is_dir($uploadDir)) {
|
||||||
mkdir($uploadDir, 0777, true);
|
mkdir($uploadDir, 0777, true);
|
||||||
@@ -250,7 +257,7 @@ class DocumentController extends AbstractController
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Best effort: wenn exec deaktiviert ist, sauber abbrechen.
|
// 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).');
|
$jobService->markFailed($job, 'Server configuration does not allow background execution (exec disabled).');
|
||||||
$this->addFlash('error', 'Ingest konnte nicht asynchron gestartet werden (exec deaktiviert).');
|
$this->addFlash('error', 'Ingest konnte nicht asynchron gestartet werden (exec deaktiviert).');
|
||||||
return $this->redirectToRoute('admin_document_show', [
|
return $this->redirectToRoute('admin_document_show', [
|
||||||
@@ -272,9 +279,16 @@ class DocumentController extends AbstractController
|
|||||||
)]
|
)]
|
||||||
public function resetCompleteSystem(ParameterBagInterface $params, Connection $connection): ?RedirectResponse
|
public function resetCompleteSystem(ParameterBagInterface $params, Connection $connection): ?RedirectResponse
|
||||||
{
|
{
|
||||||
@unlink($params->get('mto.vector.data.path') . '/index.ndjson');
|
if (!function_exists('exec')) {
|
||||||
@unlink($params->get('mto.vector.data.path') . '/vector.index');
|
$this->addFlash('danger', 'Der Reset konnte nicht gestartet werden (exec deaktiviert).');
|
||||||
@unlink($params->get('mto.vector.data.path') . '/vector.index.meta.json');
|
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 = '
|
$sql = '
|
||||||
SET FOREIGN_KEY_CHECKS = 0;
|
SET FOREIGN_KEY_CHECKS = 0;
|
||||||
TRUNCATE TABLE db.document;
|
TRUNCATE TABLE db.document;
|
||||||
@@ -287,6 +301,8 @@ class DocumentController extends AbstractController
|
|||||||
SET FOREIGN_KEY_CHECKS = 1;
|
SET FOREIGN_KEY_CHECKS = 1;
|
||||||
';
|
';
|
||||||
$connection->executeQuery($sql);
|
$connection->executeQuery($sql);
|
||||||
|
|
||||||
|
$this->addFlash('success', 'Das System wurde erfolgreich zurückgesetzt.');
|
||||||
return $this->redirectToRoute('admin_dashboard');
|
return $this->redirectToRoute('admin_dashboard');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,11 +16,21 @@
|
|||||||
|
|
||||||
<hr class="border-secondary">
|
<hr class="border-secondary">
|
||||||
|
|
||||||
<form method="post" action="/admin/documents/reset" class="text-danger" onsubmit="return resetSystem()">
|
<div class="text-light">
|
||||||
<p class="fw-bold">Reset des Systems</p>
|
<p class="fw-bold">Reset des Systems</p>
|
||||||
<p>Unwiderruflicher Reset des gesamten Systems</p>
|
<p>Unwiderruflicher Reset des gesamten Systems</p>
|
||||||
<button type="submit" class="btn btn-outline-danger">Reset System</button>
|
{% for label, messages in app.flashes %}
|
||||||
</form>
|
{% for message in messages %}
|
||||||
|
<div class="alert alert-{{ label }} alert-{{ label}} fade show" role="alert">
|
||||||
|
{{ message }}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
||||||
|
<form method="post" action="/admin/documents/reset" onsubmit="return resetSystem()">
|
||||||
|
|
||||||
|
<button type="submit" class="btn btn-outline-danger">Reset System</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -86,21 +86,21 @@
|
|||||||
|
|
||||||
<div id="job-error" class="alert alert-danger mt-3" style="display:none;"></div>
|
<div id="job-error" class="alert alert-danger mt-3" style="display:none;"></div>
|
||||||
|
|
||||||
{% if job.errorMessage %}
|
{% if job.errorMessage %}
|
||||||
<div class="alert alert-danger mt-3">
|
<div class="alert alert-danger mt-3">
|
||||||
<strong>Fehler:</strong><br>
|
<strong>Fehler:</strong><br>
|
||||||
{{ job.errorMessage }}
|
{{ job.errorMessage }}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if job.logPath %}
|
{% if job.logPath %}
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
<strong>Log Datei:</strong><br>
|
<strong>Log Datei:</strong><br>
|
||||||
<code>{{ job.logPath }}</code>
|
<code>{{ job.logPath }}</code>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|||||||
Reference in New Issue
Block a user