44 * Copyright © Magento, Inc. All rights reserved.
55 * See COPYING.txt for license details.
66 */
7+ declare (strict_types=1 );
8+
79namespace Magento \AdvancedSearch \Controller \Adminhtml \Search \System \Config ;
810
911use Magento \Backend \App \Action ;
1012use Magento \Backend \App \Action \Context ;
1113use Magento \AdvancedSearch \Model \Client \ClientResolver ;
14+ use Magento \Framework \App \Action \HttpPostActionInterface ;
15+ use Magento \Framework \Controller \Result \Json ;
1216use Magento \Framework \Controller \Result \JsonFactory ;
17+ use Magento \Framework \Exception \LocalizedException ;
1318use Magento \Framework \Filter \StripTags ;
1419
15- class TestConnection extends Action
20+ class TestConnection extends Action implements HttpPostActionInterface
1621{
1722 /**
1823 * Authorization level of a basic admin session.
1924 *
2025 * @see _isAllowed()
2126 */
22- const ADMIN_RESOURCE = 'Magento_CatalogSearch::config_catalog_search ' ;
27+ public const ADMIN_RESOURCE = 'Magento_Catalog::config_catalog ' ;
2328
2429 /**
2530 * @var ClientResolver
@@ -57,7 +62,7 @@ public function __construct(
5762 /**
5863 * Check for connection to server
5964 *
60- * @return \Magento\Framework\Controller\Result\ Json
65+ * @return Json
6166 */
6267 public function execute ()
6368 {
@@ -69,22 +74,22 @@ public function execute()
6974
7075 try {
7176 if (empty ($ options ['engine ' ])) {
72- throw new \ Magento \ Framework \ Exception \ LocalizedException (
77+ throw new LocalizedException (
7378 __ ('Missing search engine parameter. ' )
7479 );
7580 }
7681 $ response = $ this ->clientResolver ->create ($ options ['engine ' ], $ options )->testConnection ();
7782 if ($ response ) {
7883 $ result ['success ' ] = true ;
7984 }
80- } catch (\ Magento \ Framework \ Exception \ LocalizedException $ e ) {
85+ } catch (LocalizedException $ e ) {
8186 $ result ['errorMessage ' ] = $ e ->getMessage ();
8287 } catch (\Exception $ e ) {
8388 $ message = __ ($ e ->getMessage ());
8489 $ result ['errorMessage ' ] = $ this ->tagFilter ->filter ($ message );
8590 }
8691
87- /** @var \Magento\Framework\Controller\Result\ Json $resultJson */
92+ /** @var Json $resultJson */
8893 $ resultJson = $ this ->resultJsonFactory ->create ();
8994 return $ resultJson ->setData ($ result );
9095 }
0 commit comments