4
4
* Copyright © Magento, Inc. All rights reserved.
5
5
* See COPYING.txt for license details.
6
6
*/
7
+ declare (strict_types=1 );
8
+
7
9
namespace Magento \AdvancedSearch \Controller \Adminhtml \Search \System \Config ;
8
10
9
11
use Magento \Backend \App \Action ;
10
12
use Magento \Backend \App \Action \Context ;
11
13
use Magento \AdvancedSearch \Model \Client \ClientResolver ;
14
+ use Magento \Framework \App \Action \HttpPostActionInterface ;
15
+ use Magento \Framework \Controller \Result \Json ;
12
16
use Magento \Framework \Controller \Result \JsonFactory ;
17
+ use Magento \Framework \Exception \LocalizedException ;
13
18
use Magento \Framework \Filter \StripTags ;
14
19
15
- class TestConnection extends Action
20
+ class TestConnection extends Action implements HttpPostActionInterface
16
21
{
17
22
/**
18
23
* Authorization level of a basic admin session.
19
24
*
20
25
* @see _isAllowed()
21
26
*/
22
- const ADMIN_RESOURCE = 'Magento_CatalogSearch::config_catalog_search ' ;
27
+ public const ADMIN_RESOURCE = 'Magento_Catalog::config_catalog ' ;
23
28
24
29
/**
25
30
* @var ClientResolver
@@ -57,7 +62,7 @@ public function __construct(
57
62
/**
58
63
* Check for connection to server
59
64
*
60
- * @return \Magento\Framework\Controller\Result\ Json
65
+ * @return Json
61
66
*/
62
67
public function execute ()
63
68
{
@@ -69,22 +74,22 @@ public function execute()
69
74
70
75
try {
71
76
if (empty ($ options ['engine ' ])) {
72
- throw new \ Magento \ Framework \ Exception \ LocalizedException (
77
+ throw new LocalizedException (
73
78
__ ('Missing search engine parameter. ' )
74
79
);
75
80
}
76
81
$ response = $ this ->clientResolver ->create ($ options ['engine ' ], $ options )->testConnection ();
77
82
if ($ response ) {
78
83
$ result ['success ' ] = true ;
79
84
}
80
- } catch (\ Magento \ Framework \ Exception \ LocalizedException $ e ) {
85
+ } catch (LocalizedException $ e ) {
81
86
$ result ['errorMessage ' ] = $ e ->getMessage ();
82
87
} catch (\Exception $ e ) {
83
88
$ message = __ ($ e ->getMessage ());
84
89
$ result ['errorMessage ' ] = $ this ->tagFilter ->filter ($ message );
85
90
}
86
91
87
- /** @var \Magento\Framework\Controller\Result\ Json $resultJson */
92
+ /** @var Json $resultJson */
88
93
$ resultJson = $ this ->resultJsonFactory ->create ();
89
94
return $ resultJson ->setData ($ result );
90
95
}
0 commit comments