feat: mark a library document for a specific purpose
This commit is contained in:
1 parent
cb2d64f2cd
commit
19364df2db
8 files changed
+249
-6
No files matched your search
@@ -2,11 +2,14 @@
|
||||
|
||||
namespace App\Controller\Administrative\System\Document;
|
||||
|
||||
use App\Config\UploadToken;
|
||||
use App\Entity\Upload;
|
||||
use App\Htmx\HxRedirectResponse;
|
||||
use App\Repository\UploadRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\EnumType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
@@ -18,6 +21,7 @@ class EditController extends AbstractController
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly UploadRepository $uploadRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -26,6 +30,7 @@ class EditController extends AbstractController
|
||||
public function index(Upload $upload, Request $request): Response
|
||||
{
|
||||
$nameBefore = $upload->getDisplayName();
|
||||
$tokenBefore = $upload->getToken();
|
||||
|
||||
$form = $this
|
||||
->createFormBuilder($upload)
|
||||
@@ -35,19 +40,37 @@ class EditController extends AbstractController
|
||||
'placeholder' => $upload->getOriginalFilename(),
|
||||
],
|
||||
])
|
||||
->add('token', EnumType::class, [
|
||||
'label' => 'Verwendung',
|
||||
'class' => UploadToken::class,
|
||||
'required' => false,
|
||||
'placeholder' => 'keine besondere Verwendung',
|
||||
'choice_label' => fn (UploadToken $token) => $token->label(),
|
||||
'help' => 'Eine Verwendung gehört immer zu genau einem Dokument. Wird sie hier gesetzt, verliert das bisherige Dokument sie.',
|
||||
])
|
||||
->getForm()
|
||||
;
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->entityManager->flush();
|
||||
$this->addFlash('success', 'Das Dokument wurden umbenannt');
|
||||
// The column is unique, so taking a slot has to free it first - otherwise the flush
|
||||
// dies on the index. Moving rather than refusing is what staff mean by assigning it:
|
||||
// "this is the handout now".
|
||||
$previousHolderId = null === $upload->getToken()
|
||||
? null
|
||||
: $this->uploadRepository->releaseToken($upload->getToken(), $upload);
|
||||
|
||||
$this->logger->info('Rename document', [
|
||||
$this->entityManager->flush();
|
||||
$this->addFlash('success', 'Das Dokument wurde aktualisiert');
|
||||
|
||||
$this->logger->info('Edit document', [
|
||||
'document_id' => $upload->getId(),
|
||||
'document_filename' => $upload->getOriginalFilename(),
|
||||
'document_name_before' => $nameBefore,
|
||||
'document_name_after' => $upload->getDisplayName(),
|
||||
'document_token_before' => $tokenBefore?->value,
|
||||
'document_token_after' => $upload->getToken()?->value,
|
||||
'document_token_taken_from' => $previousHolderId,
|
||||
]);
|
||||
|
||||
return new HxRedirectResponse($this->generateUrl('app_administrative_system_document_index'));
|
||||
|
||||
Reference in new issue
Block a user