From 5ffcb7cb6f767a0fe1f95f31cdf98fa0dacd87cd Mon Sep 17 00:00:00 2001 From: Thomas Da Silva Date: Fri, 30 Aug 2024 10:21:59 +0200 Subject: [PATCH 1/2] remove upate line + add popin --- Controller/Admin/ManageErrorUrlController.php | 8 ++ .../backOffice/default/manage-errors-url.html | 132 ++++++++++++------ 2 files changed, 98 insertions(+), 42 deletions(-) diff --git a/Controller/Admin/ManageErrorUrlController.php b/Controller/Admin/ManageErrorUrlController.php index 875601e..669029b 100644 --- a/Controller/Admin/ManageErrorUrlController.php +++ b/Controller/Admin/ManageErrorUrlController.php @@ -9,6 +9,7 @@ use RewriteUrl\Model\RewriteurlRule; use RewriteUrl\Model\RewriteurlRuleQuery; use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Routing\Annotation\Route; use Thelia\Controller\Admin\BaseAdminController; use Thelia\Core\HttpFoundation\JsonResponse; @@ -24,6 +25,13 @@ public function manageErrorUrl(): Response|RedirectResponse { return $this->render('manage-errors-url'); } + + #[Route('/get-rule', name: 'get_value', methods: ['GET'])] + public function getRewriteUrlRuleValue(RequestStack $requestStack): JsonResponse + { + $ruleId = $requestStack->getCurrentRequest()->query->get('rule_id'); + return new JsonResponse(RewriteurlRuleQuery::create()->findOneById($ruleId)?->getRedirectUrl()); + } #[Route('/update/{id}', name: 'update', methods: ['POST'])] public function updateRewriteUrl(ParserContext $parserContext, $id): Response|RedirectResponse diff --git a/templates/backOffice/default/manage-errors-url.html b/templates/backOffice/default/manage-errors-url.html index 3070e45..e6b526a 100644 --- a/templates/backOffice/default/manage-errors-url.html +++ b/templates/backOffice/default/manage-errors-url.html @@ -41,6 +41,7 @@ path='/admin/module/RewriteUrl/manageErrorUrl' label="{intl l='User Agent' d="rewriteurl.bo.default"}" } + {admin_sortable_header current_order=$order @@ -49,6 +50,7 @@ path='/admin/module/RewriteUrl/manageErrorUrl' label="{intl l='Hit Count' d="rewriteurl.bo.default"}" } + {admin_sortable_header current_order=$order @@ -57,6 +59,7 @@ path='/admin/module/RewriteUrl/manageErrorUrl' label="{intl l='Lastest Hit' d="rewriteurl.bo.default"}" } + @@ -66,48 +69,11 @@ {$USER_AGENT} {$COUNT} {$UPDATED_AT|date_format:"%d/%m/%y"} - - - - {form name="rewriteurl_form_update_rewrite_url_form"} -
- {form_hidden_fields form=$form} - - {render_form_field field="success_url" value={url path='/admin/module/RewriteUrl/manageErrorUrl'}} - {render_form_field field="error_url" value={url path='/admin/module/RewriteUrl/manageErrorUrl'}} - - - {if $form_error} -
-
-
{$form_error_message}
-
-
- {/if} - - {ifloop rel="rewriteurl_rule_loop"} - {loop type="generic" name="rewriteurl_rule_loop" table_name="rewriteurl_rule" filters="id:$REWRITEURL_RULE_ID" limit=1} - {form_field form=$form field="rewritten_url"} - - {/form_field} - {/loop} - {/ifloop} - {elseloop rel="rewriteurl_rule_loop"} - {form_field form=$form field="rewritten_url"} - - {/form_field} - {/elseloop} - - - - - - -
- {/form} + + + + + {/loop} @@ -117,6 +83,88 @@ + + + + {/block} {block name="javascript-initialization"} From 0d8e50a5c2859354511ba0ea0685d394b19e594b Mon Sep 17 00:00:00 2001 From: Thomas Da Silva Date: Fri, 30 Aug 2024 12:11:55 +0200 Subject: [PATCH 2/2] WIP Feature Gestion Errors 404 --- Config/config.xml | 1 + Controller/Admin/ManageErrorUrlController.php | 38 +++++++++ Form/ResearchForm.php | 24 ++++++ Loop/RewriteUrlErrorUrlLoop.php | 82 +++++++++++++++++++ .../backOffice/default/manage-errors-url.html | 42 ++++++++-- 5 files changed, 181 insertions(+), 6 deletions(-) create mode 100644 Form/ResearchForm.php create mode 100644 Loop/RewriteUrlErrorUrlLoop.php diff --git a/Config/config.xml b/Config/config.xml index 8f495b2..609a729 100755 --- a/Config/config.xml +++ b/Config/config.xml @@ -8,6 +8,7 @@ + diff --git a/Controller/Admin/ManageErrorUrlController.php b/Controller/Admin/ManageErrorUrlController.php index 669029b..ba439f1 100644 --- a/Controller/Admin/ManageErrorUrlController.php +++ b/Controller/Admin/ManageErrorUrlController.php @@ -4,6 +4,7 @@ use Exception; use Propel\Runtime\Exception\PropelException; +use RewriteUrl\Form\ResearchForm; use RewriteUrl\Form\UpdateRewriteUrlForm; use RewriteUrl\Model\RewriteurlErrorUrlQuery; use RewriteUrl\Model\RewriteurlRule; @@ -32,6 +33,43 @@ public function getRewriteUrlRuleValue(RequestStack $requestStack): JsonResponse $ruleId = $requestStack->getCurrentRequest()->query->get('rule_id'); return new JsonResponse(RewriteurlRuleQuery::create()->findOneById($ruleId)?->getRedirectUrl()); } + + #[Route('/search', name: 'search', methods: ['POST'])] + public function search(ParserContext $parserContext): RedirectResponse|Response + { + $url = "/admin/module/RewriteUrl/manageErrorUrl?"; + $form = $this->createForm(ResearchForm::getName()); + + try { + $data = $this->validateForm($form)->getData(); + + if (null !== $userAgent = $data['user_agent']) { + $url .= "user_agent=" . $userAgent; + } + + if (null !== $data['user_agent'] && null !== $data['url_source']) { + $url .= "&"; + } + + if (null !== $urlSource = $data['url_source']) { + $url .= "url_source=" . $urlSource; + } + + return $this->generateRedirect($url); + } catch (FormValidationException $e) { + $error_message = $this->createStandardFormValidationErrorMessage($e); + } catch (Exception $e) { + $error_message = $e->getMessage(); + } + + $form->setErrorMessage($error_message); + + $parserContext + ->addForm($form) + ->setGeneralError($error_message); + + return $this->generateErrorRedirect($form); + } #[Route('/update/{id}', name: 'update', methods: ['POST'])] public function updateRewriteUrl(ParserContext $parserContext, $id): Response|RedirectResponse diff --git a/Form/ResearchForm.php b/Form/ResearchForm.php new file mode 100644 index 0000000..4bd8739 --- /dev/null +++ b/Form/ResearchForm.php @@ -0,0 +1,24 @@ +formBuilder + ->add('user_agent', TextType::class, [ + 'required' => false, + 'label' => Translator::getInstance()?->trans('User Agent') + ]) + ->add('url_source', TextType::class, [ + 'required' => false, + 'label' => Translator::getInstance()?->trans('URL Source') + ]) + ; + } +} \ No newline at end of file diff --git a/Loop/RewriteUrlErrorUrlLoop.php b/Loop/RewriteUrlErrorUrlLoop.php new file mode 100644 index 0000000..4a6e394 --- /dev/null +++ b/Loop/RewriteUrlErrorUrlLoop.php @@ -0,0 +1,82 @@ +getResultDataCollection() as $rewriteUrlErrorUrl) { + $loopResultRow = new LoopResultRow($rewriteUrlErrorUrl); + + $loopResultRow->set('ID', $rewriteUrlErrorUrl->getId()) + ->set('URL_SOURCE', $rewriteUrlErrorUrl->getUrlSource()) + ->set('COUNT', $rewriteUrlErrorUrl->getCount()) + ->set('USER_AGENT', $rewriteUrlErrorUrl->getUserAgent()) + ->set('REWRITEURL_RULE_ID', $rewriteUrlErrorUrl->getRewriteurlRuleId()) + ->set('REDIRECT_URL', $rewriteUrlErrorUrl->getRewriteurlRule()?->getRedirectUrl()) + ->set('CREATED_AT', $rewriteUrlErrorUrl->getCreatedAt()) + ->set('UPDATED_AT', $rewriteUrlErrorUrl->getUpdatedAt()); + $this->addOutputFields($loopResultRow, $rewriteUrlErrorUrl); + + $loopResult->addRow($loopResultRow); + } + + return $loopResult; + } + + public function buildModelCriteria(): ModelCriteria + { + $search = RewriteUrlErrorUrlQuery::create(); + + if (null !== $id = $this->getId()) { + $search->filterById($id); + } + + if (null !== $userAgent = $this->getUserAgent()) { + $search->filterByUserAgent($userAgent); + } + + if (null !== $userSource = $this->getUrlSource()) { + $search->filterByUrlSource($userSource); + } + + if (null !== $orders = $this->getOrders()) { + [$order, $criteria] = explode(":", $orders); + $search->orderBy($order, $criteria); + } + + return $search; + } + + protected function getArgDefinitions(): ArgumentCollection + { + return new ArgumentCollection( + Argument::createIntTypeArgument('id'), + Argument::createAnyTypeArgument('user_agent'), + Argument::createAnyTypeArgument('url_source'), + Argument::createAnyTypeArgument('orders'), + ); + } +} \ No newline at end of file diff --git a/templates/backOffice/default/manage-errors-url.html b/templates/backOffice/default/manage-errors-url.html index e6b526a..ea20a18 100644 --- a/templates/backOffice/default/manage-errors-url.html +++ b/templates/backOffice/default/manage-errors-url.html @@ -8,19 +8,49 @@ {block name="main-content"} {$order = $smarty.get.order|default:"updated_at:desc"} + {$url_source = $smarty.get.url_source|default:null} + {$user_agent = $smarty.get.user_agent|default:null}
-
+
{intl l="Manage 404 Error URLs" d='rewriteurl.bo.default'}
-
- {intl l="Delete All Errors Urls" d='rewriteurl.bo.default'} +
+
+ +
+ {intl l="Search by Field" d='rewriteurl.bo.default'} +
+ +
+ {form name="rewriteurl_form_research_form"} +
+ {form_hidden_fields form=$form} + +
+ {render_form_field field='url_source'} +
+ +
+ {render_form_field field='user_agent'} +
+ +
+ +
+ + +
+ {/form}
+

@@ -63,14 +93,14 @@ - {loop type="generic" name="rewriteurl_error_url_loop" table_name="rewriteurl_error_url" orders=$order} + {loop type="rewrite_url_error_url" name="rewriteurl_error_url_loop" orders=$order user_agent=$user_agent url_source=$url_source} @@ -109,7 +139,7 @@

{intl l="Edit Rewrite Url"}

{/if} {form_field form=$form field="rewritten_url"} - + {/form_field}
{$URL_SOURCE} {$USER_AGENT} {$COUNT} {$UPDATED_AT|date_format:"%d/%m/%y"} - +