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