|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Firesphere\SolrSearch\Compat; |
|
4
|
|
|
|
|
5
|
|
|
use Firesphere\SolrSearch\Indexes\BaseIndex; |
|
6
|
|
|
use Firesphere\SolrSearch\Queries\BaseQuery; |
|
7
|
|
|
use League\Flysystem\Adapter\Local; |
|
8
|
|
|
use SilverStripe\Core\Extension; |
|
9
|
|
|
use Solarium\QueryType\Select\Query\Query; |
|
10
|
|
|
use TractorCow\Fluent\Extension\FluentChangesExtension; |
|
|
|
|
|
|
11
|
|
|
use TractorCow\Fluent\Model\Locale; |
|
|
|
|
|
|
12
|
|
|
use TractorCow\Fluent\State\FluentState; |
|
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
if (!class_exists('TractorCow\\Fluent\\Model\\Locale')) { |
|
15
|
|
|
return; |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class FluentExtension |
|
20
|
|
|
* |
|
21
|
|
|
* @package Firesphere\SolrSearch\Compat |
|
22
|
|
|
* @property DocumentFactory|BaseIndex|SchemaService|FluentExtension $owner |
|
23
|
|
|
*/ |
|
24
|
|
|
class FluentExtension extends Extension |
|
25
|
|
|
{ |
|
26
|
|
|
protected $fieldLocale; |
|
27
|
|
|
/** |
|
28
|
|
|
* Add the needed language copy fields to Solr |
|
29
|
|
|
*/ |
|
30
|
|
|
public function onAfterInit() |
|
31
|
|
|
{ |
|
32
|
|
|
$locales = Locale::get()->exclude(['IsGlobalDefault' => true]); |
|
33
|
|
|
/** @var BaseIndex $owner */ |
|
34
|
|
|
$owner = $this->owner; |
|
35
|
|
|
$copyFields = $owner->getCopyFields(); |
|
36
|
|
|
/** @var Locale $locale */ |
|
37
|
|
|
foreach ($locales as $locale) { |
|
38
|
|
|
foreach ($copyFields as $copyField => $values) { |
|
39
|
|
|
$owner->addCopyField($locale->Locale . $copyField, $values); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function onAfterFieldDefinition($data, $item) |
|
45
|
|
|
{ |
|
46
|
|
|
$locales = Locale::get()->exclude(['IsGlobalDefault' => true]); |
|
47
|
|
|
|
|
48
|
|
|
foreach ($locales as $locale) { |
|
49
|
|
|
$isDest = strpos($item['Destination'], $locale->Locale); |
|
50
|
|
|
if ($isDest === 0 || $item['Destination'] === null) { |
|
51
|
|
|
$copy = $item; |
|
52
|
|
|
$copy['Field'] = $item['Field'] . '_' . $locale->Locale; |
|
53
|
|
|
$data->push($copy); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function onBeforeAddDoc(&$field, &$value) |
|
|
|
|
|
|
59
|
|
|
{ |
|
60
|
|
|
$fluentState = FluentState::singleton(); |
|
61
|
|
|
$locale = $fluentState->getLocale(); |
|
62
|
|
|
/** @var Locale $defaultLocale */ |
|
63
|
|
|
$defaultLocale = Locale::get()->filter(['IsGlobalDefault' => true])->first(); |
|
64
|
|
|
if ($locale !== $defaultLocale->Locale) { |
|
65
|
|
|
$field['name'] .= '_' . $locale; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param BaseQuery $query |
|
71
|
|
|
* @param Query $clientQuery |
|
72
|
|
|
*/ |
|
73
|
|
|
public function onBeforeSearch($query, $clientQuery) |
|
|
|
|
|
|
74
|
|
|
{ |
|
75
|
|
|
$locale = FluentState::singleton()->getLocale(); |
|
76
|
|
|
$defaultLocale = Locale::get()->filter(['IsGlobalDefault' => true])->first(); |
|
77
|
|
|
if ($locale !== $defaultLocale->Locale) { |
|
78
|
|
|
$defaultField = $clientQuery->getQueryDefaultField() ?: '_text'; |
|
79
|
|
|
$clientQuery->setQueryDefaultField($locale . $defaultField); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths