Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| AdvancedSearchChecker | |
100.00% |
8 / 8 |
|
100.00% |
4 / 4 |
6 | |
100.00% |
1 / 1 |
| isEnabled | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| ping | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| getFeatureFlagChecker | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getSearchService | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2020-2022 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\tao\model\AdvancedSearch; |
| 24 | |
| 25 | use oat\tao\model\search\SearchProxy; |
| 26 | use oat\tao\model\search\SearchInterface; |
| 27 | use oat\oatbox\service\ConfigurableService; |
| 28 | use oat\tao\model\featureFlag\FeatureFlagChecker; |
| 29 | use oat\tao\model\featureFlag\FeatureFlagCheckerInterface; |
| 30 | use oat\taoAdvancedSearch\model\SearchEngine\Driver\Elasticsearch\ElasticSearch; |
| 31 | |
| 32 | // @TODO Move to the AdvancedSearch extension and deprecate this one. |
| 33 | class AdvancedSearchChecker extends ConfigurableService |
| 34 | { |
| 35 | public function isEnabled(): bool |
| 36 | { |
| 37 | $featureFlagEnabled = $this->getFeatureFlagChecker()->isEnabled( |
| 38 | FeatureFlagCheckerInterface::FEATURE_FLAG_ADVANCED_SEARCH_DISABLED |
| 39 | ); |
| 40 | |
| 41 | return !$featureFlagEnabled && $this->getSearchService()->supportCustomIndex(); |
| 42 | } |
| 43 | |
| 44 | public function ping(): bool |
| 45 | { |
| 46 | $advancedSearch = $this->getSearchService()->getAdvancedSearch(); |
| 47 | |
| 48 | return $advancedSearch instanceof ElasticSearch && $advancedSearch->ping(); |
| 49 | } |
| 50 | |
| 51 | private function getFeatureFlagChecker(): FeatureFlagCheckerInterface |
| 52 | { |
| 53 | return $this->getServiceLocator()->get(FeatureFlagChecker::class); |
| 54 | } |
| 55 | |
| 56 | private function getSearchService(): SearchInterface |
| 57 | { |
| 58 | return $this->getServiceLocator()->get(SearchProxy::SERVICE_ID); |
| 59 | } |
| 60 | } |