Skip to content

Commit 72a878c

Browse files
author
roadiz-ci
committed
refactor: Removed base RozierApp class when possible, added LogTrail service for publishing message in session and logger
1 parent 68d35f1 commit 72a878c

22 files changed

+51
-609
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"require": {
3434
"php": ">=8.2",
3535
"ext-zip": "*",
36-
"doctrine/orm": "~2.19.0",
36+
"doctrine/orm": "~2.20.0",
3737
"jms/serializer": "^3.9.0",
3838
"league/flysystem": "^3.0",
3939
"ramsey/uuid": "^4.7",

src/Controllers/CacheController.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public function deleteDoctrineCache(Request $request): Response
4747
*/
4848
return $this->redirectToRoute('adminHomePage');
4949
}
50-
$this->prepareBaseAssignation();
5150
$this->assignation['form'] = $form->createView();
5251

5352
return $this->render('@RoadizRozier/cache/deleteDoctrine.html.twig', $this->assignation);
@@ -74,7 +73,6 @@ public function deleteAssetsCache(Request $request): Response
7473
return $this->redirectToRoute('adminHomePage');
7574
}
7675

77-
$this->prepareBaseAssignation();
7876
$this->assignation['form'] = $form->createView();
7977

8078
return $this->render('@RoadizRozier/cache/deleteAssets.html.twig', $this->assignation);

src/Controllers/Documents/DocumentsController.php

Lines changed: 0 additions & 275 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,19 @@
1515
use RZ\Roadiz\CoreBundle\Entity\Document;
1616
use RZ\Roadiz\CoreBundle\Entity\Folder;
1717
use RZ\Roadiz\CoreBundle\Entity\TagTranslationDocuments;
18-
use RZ\Roadiz\CoreBundle\Entity\Translation;
1918
use RZ\Roadiz\CoreBundle\EntityHandler\DocumentHandler;
2019
use RZ\Roadiz\CoreBundle\Explorer\ExplorerItemFactoryInterface;
21-
use RZ\Roadiz\CoreBundle\ListManager\SessionListFilters;
2220
use RZ\Roadiz\Documents\Events\DocumentCreatedEvent;
2321
use RZ\Roadiz\Documents\Events\DocumentDeletedEvent;
2422
use RZ\Roadiz\Documents\Events\DocumentFileUpdatedEvent;
25-
use RZ\Roadiz\Documents\Events\DocumentInFolderEvent;
26-
use RZ\Roadiz\Documents\Events\DocumentOutFolderEvent;
2723
use RZ\Roadiz\Documents\Events\DocumentUpdatedEvent;
2824
use RZ\Roadiz\Documents\Exceptions\APINeedsAuthentificationException;
2925
use RZ\Roadiz\Documents\MediaFinders\EmbedFinderFactory;
3026
use RZ\Roadiz\Documents\MediaFinders\EmbedFinderInterface;
3127
use RZ\Roadiz\Documents\MediaFinders\RandomImageFinder;
3228
use RZ\Roadiz\Documents\Models\DocumentInterface;
33-
use Symfony\Component\Form\ClickableInterface;
3429
use Symfony\Component\Form\Extension\Core\Type\FileType;
3530
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
36-
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
37-
use Symfony\Component\Form\Extension\Core\Type\TextType;
3831
use Symfony\Component\Form\Form;
3932
use Symfony\Component\Form\FormError;
4033
use Symfony\Component\Form\FormInterface;
@@ -80,103 +73,6 @@ public function __construct(
8073
) {
8174
}
8275

83-
/**
84-
* @throws RuntimeError
85-
*/
86-
public function indexAction(Request $request, ?int $folderId = null): Response
87-
{
88-
$this->denyAccessUnlessGranted('ROLE_ACCESS_DOCUMENTS');
89-
90-
/** @var Translation $translation */
91-
$translation = $this->em()
92-
->getRepository(Translation::class)
93-
->findDefault();
94-
95-
$prefilters = [
96-
'raw' => false,
97-
];
98-
99-
if (
100-
null !== $folderId
101-
&& $folderId > 0
102-
) {
103-
$folder = $this->em()
104-
->find(Folder::class, $folderId);
105-
106-
$prefilters['folders'] = [$folder];
107-
$this->assignation['folder'] = $folder;
108-
}
109-
110-
$type = $request->query->get('type', null);
111-
if (\is_string($type) && '' !== trim($type)) {
112-
$prefilters['mimeType'] = trim($type);
113-
$this->assignation['mimeType'] = trim($type);
114-
}
115-
116-
$embedPlatform = $request->query->get('embedPlatform', null);
117-
if (\is_string($embedPlatform) && '' !== trim($embedPlatform)) {
118-
$prefilters['embedPlatform'] = trim($embedPlatform);
119-
$this->assignation['embedPlatform'] = trim($embedPlatform);
120-
}
121-
$this->assignation['availablePlatforms'] = $this->documentPlatforms;
122-
123-
/*
124-
* Handle bulk folder form
125-
*/
126-
$joinFolderForm = $this->buildLinkFoldersForm();
127-
$joinFolderForm->handleRequest($request);
128-
if ($joinFolderForm->isSubmitted() && $joinFolderForm->isValid()) {
129-
$data = $joinFolderForm->getData();
130-
$submitFolder = $joinFolderForm->get('submitFolder');
131-
$submitUnfolder = $joinFolderForm->get('submitUnfolder');
132-
if ($submitFolder instanceof ClickableInterface && $submitFolder->isClicked()) {
133-
$msg = $this->joinFolder($data);
134-
} elseif ($submitUnfolder instanceof ClickableInterface && $submitUnfolder->isClicked()) {
135-
$msg = $this->leaveFolder($data);
136-
} else {
137-
$msg = $this->getTranslator()->trans('wrong.request');
138-
}
139-
140-
$this->publishConfirmMessage($request, $msg);
141-
142-
return $this->redirectToRoute(
143-
'documentsHomePage',
144-
['folderId' => $folderId]
145-
);
146-
}
147-
$this->assignation['joinFolderForm'] = $joinFolderForm->createView();
148-
149-
/*
150-
* Manage get request to filter list
151-
*/
152-
$listManager = $this->createEntityListManager(
153-
Document::class,
154-
$prefilters,
155-
['createdAt' => 'DESC']
156-
);
157-
$listManager->setDisplayingNotPublishedNodes(true);
158-
$listManager->setItemPerPage(static::DEFAULT_ITEM_PER_PAGE);
159-
160-
/*
161-
* Stored in session
162-
*/
163-
$sessionListFilter = new SessionListFilters('documents_item_per_page');
164-
$sessionListFilter->handleItemPerPage($request, $listManager);
165-
166-
$listManager->handle();
167-
168-
$this->assignation['filters'] = $listManager->getAssignation();
169-
$this->assignation['documents'] = $listManager->getEntities();
170-
$this->assignation['translation'] = $translation;
171-
$this->assignation['thumbnailFormat'] = $this->thumbnailFormat;
172-
173-
return $this->render($this->getListingTemplate($request), $this->assignation);
174-
}
175-
176-
/**
177-
* @throws RuntimeError
178-
* @throws FilesystemException
179-
*/
18076
public function adjustAction(Request $request, int $documentId): Response
18177
{
18278
$this->denyAccessUnlessGranted('ROLE_ACCESS_DOCUMENTS');
@@ -258,10 +154,6 @@ public function adjustAction(Request $request, int $documentId): Response
258154
return $this->render('@RoadizRozier/documents/adjust.html.twig', $this->assignation);
259155
}
260156

261-
/**
262-
* @throws FilesystemException
263-
* @throws RuntimeError
264-
*/
265157
public function editAction(Request $request, int $documentId): Response
266158
{
267159
$this->denyAccessUnlessGranted('ROLE_ACCESS_DOCUMENTS');
@@ -339,11 +231,6 @@ public function editAction(Request $request, int $documentId): Response
339231
return $this->render('@RoadizRozier/documents/edit.html.twig', $this->assignation);
340232
}
341233

342-
/**
343-
* Return an deletion form for requested document.
344-
*
345-
* @throws RuntimeError
346-
*/
347234
public function deleteAction(Request $request, int $documentId): Response
348235
{
349236
$this->denyAccessUnlessGranted('ROLE_ACCESS_DOCUMENTS_DELETE');
@@ -393,11 +280,6 @@ public function deleteAction(Request $request, int $documentId): Response
393280
return $this->render('@RoadizRozier/documents/delete.html.twig', $this->assignation);
394281
}
395282

396-
/**
397-
* Return an deletion form for multiple docs.
398-
*
399-
* @throws RuntimeError
400-
*/
401283
public function bulkDeleteAction(Request $request): Response
402284
{
403285
$this->denyAccessUnlessGranted('ROLE_ACCESS_DOCUMENTS_DELETE');
@@ -445,8 +327,6 @@ public function bulkDeleteAction(Request $request): Response
445327

446328
/**
447329
* Embed external document page.
448-
*
449-
* @throws RuntimeError
450330
*/
451331
public function embedAction(Request $request, ?int $folderId = null): Response
452332
{
@@ -782,152 +662,6 @@ private function buildUploadForm(?int $folderId = null): FormInterface
782662
return $builder->getForm();
783663
}
784664

785-
private function buildLinkFoldersForm(): FormInterface
786-
{
787-
$builder = $this->createNamedFormBuilder('folderForm')
788-
->add('documentsId', HiddenType::class, [
789-
'attr' => ['class' => 'document-id-bulk-folder'],
790-
'constraints' => [
791-
new NotNull(),
792-
new NotBlank(),
793-
],
794-
])
795-
->add('folderPaths', TextType::class, [
796-
'label' => false,
797-
'attr' => [
798-
'class' => 'rz-folder-autocomplete',
799-
'placeholder' => 'list.folders.to_link',
800-
],
801-
'constraints' => [
802-
new NotNull(),
803-
new NotBlank(),
804-
],
805-
])
806-
->add('submitFolder', SubmitType::class, [
807-
'label' => false,
808-
'attr' => [
809-
'class' => 'uk-button uk-button-primary',
810-
'title' => 'link.folders',
811-
'data-uk-tooltip' => '{animation:true}',
812-
],
813-
])
814-
->add('submitUnfolder', SubmitType::class, [
815-
'label' => false,
816-
'attr' => [
817-
'class' => 'uk-button',
818-
'title' => 'unlink.folders',
819-
'data-uk-tooltip' => '{animation:true}',
820-
],
821-
]);
822-
823-
return $builder->getForm();
824-
}
825-
826-
/**
827-
* @return string Status message
828-
*/
829-
private function joinFolder(array $data): string
830-
{
831-
$msg = $this->getTranslator()->trans('no_documents.linked_to.folders');
832-
833-
if (
834-
!empty($data['documentsId'])
835-
&& !empty($data['folderPaths'])
836-
) {
837-
$documentsIds = explode(',', $data['documentsId']);
838-
839-
$documents = $this->em()
840-
->getRepository(Document::class)
841-
->findBy([
842-
'id' => $documentsIds,
843-
]);
844-
845-
$folderPaths = explode(',', $data['folderPaths']);
846-
$folderPaths = array_filter($folderPaths);
847-
848-
foreach ($folderPaths as $path) {
849-
/** @var Folder $folder */
850-
$folder = $this->em()
851-
->getRepository(Folder::class)
852-
->findOrCreateByPath($path);
853-
854-
/*
855-
* Add each selected documents
856-
*/
857-
foreach ($documents as $document) {
858-
$folder->addDocument($document);
859-
}
860-
}
861-
862-
$this->em()->flush();
863-
$msg = $this->getTranslator()->trans('documents.linked_to.folders');
864-
865-
/*
866-
* Dispatch events
867-
*/
868-
foreach ($documents as $document) {
869-
$this->dispatchEvent(
870-
new DocumentInFolderEvent($document)
871-
);
872-
}
873-
}
874-
875-
return $msg;
876-
}
877-
878-
/**
879-
* @return string Status message
880-
*/
881-
private function leaveFolder(array $data): string
882-
{
883-
$msg = $this->getTranslator()->trans('no_documents.removed_from.folders');
884-
885-
if (
886-
!empty($data['documentsId'])
887-
&& !empty($data['folderPaths'])
888-
) {
889-
$documentsIds = explode(',', $data['documentsId']);
890-
891-
$documents = $this->em()
892-
->getRepository(Document::class)
893-
->findBy([
894-
'id' => $documentsIds,
895-
]);
896-
897-
$folderPaths = explode(',', $data['folderPaths']);
898-
$folderPaths = array_filter($folderPaths);
899-
900-
foreach ($folderPaths as $path) {
901-
/** @var Folder $folder */
902-
$folder = $this->em()
903-
->getRepository(Folder::class)
904-
->findByPath($path);
905-
906-
if (null !== $folder) {
907-
/*
908-
* Add each selected documents
909-
*/
910-
foreach ($documents as $document) {
911-
$folder->removeDocument($document);
912-
}
913-
}
914-
}
915-
$this->em()->flush();
916-
$msg = $this->getTranslator()->trans('documents.removed_from.folders');
917-
918-
/*
919-
* Dispatch events
920-
*/
921-
foreach ($documents as $document) {
922-
$this->dispatchEvent(
923-
new DocumentOutFolderEvent($document)
924-
);
925-
}
926-
}
927-
928-
return $msg;
929-
}
930-
931665
/**
932666
* @return DocumentInterface|array<DocumentInterface>
933667
*
@@ -1037,13 +771,4 @@ private function uploadDocument(FormInterface $data, ?int $folderId = null): ?Do
1037771

1038772
return null;
1039773
}
1040-
1041-
private function getListingTemplate(Request $request): string
1042-
{
1043-
if ('1' === $request->query->get('list')) {
1044-
return '@RoadizRozier/documents/list-table.html.twig';
1045-
}
1046-
1047-
return '@RoadizRozier/documents/list.html.twig';
1048-
}
1049774
}

0 commit comments

Comments
 (0)