1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* This file is part of Scout Extended. |
7
|
|
|
* |
8
|
|
|
* (c) Algolia Team <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Algolia\ScoutExtended\Console\Commands; |
15
|
|
|
|
16
|
|
|
use function count; |
17
|
|
|
use Illuminate\Console\Command; |
18
|
|
|
use Algolia\AlgoliaSearch\Index; |
|
|
|
|
19
|
|
|
use Algolia\ScoutExtended\Algolia; |
20
|
|
|
use Algolia\ScoutExtended\Helpers\SearchableFinder; |
21
|
|
|
use Algolia\ScoutExtended\Searchable\RecordsCounter; |
22
|
|
|
use Algolia\AlgoliaSearch\Exceptions\NotFoundException; |
|
|
|
|
23
|
|
|
|
24
|
|
|
final class ReImportCommand extends Command |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
|
|
protected $signature = 'scout:reimport {searchable? : The name of the searchable}'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
protected $description = 'Reimport the given searchable into the search index'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
private static $prefix = 'temp'; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
public function handle( |
45
|
|
|
Algolia $algolia, |
46
|
|
|
SearchableFinder $searchableModelsFinder, |
47
|
|
|
RecordsCounter $recordsCounter |
|
|
|
|
48
|
|
|
): void { |
49
|
|
|
$searchables = $searchableModelsFinder->fromCommand($this); |
50
|
|
|
|
51
|
|
|
$config = config(); |
52
|
|
|
|
53
|
|
|
$scoutPrefix = $config->get('scout.prefix'); |
54
|
|
|
$scoutSynchronous = $config->get('scout.synchronous', false); |
55
|
|
|
|
56
|
|
|
$this->output->text('🔎 Importing: <info>['.implode(',', $searchables).']</info>'); |
57
|
|
|
$this->output->newLine(); |
58
|
|
|
$this->output->progressStart(count($searchables) * 3); |
59
|
|
|
|
60
|
|
|
foreach ($searchables as $searchable) { |
61
|
|
|
$index = $algolia->index($searchable); |
62
|
|
|
$temporaryName = $this->getTemporaryIndexName($index); |
63
|
|
|
|
64
|
|
|
tap($this->output)->progressAdvance()->text("Creating temporary index <info>{$temporaryName}</info>"); |
65
|
|
|
|
66
|
|
|
$algolia->client()->copyIndex($index->getIndexName(), $temporaryName, [ |
67
|
|
|
'scope' => [ |
68
|
|
|
'settings', |
69
|
|
|
'synonyms', |
70
|
|
|
'rules', |
71
|
|
|
], |
72
|
|
|
])->wait(); |
73
|
|
|
|
74
|
|
|
tap($this->output)->progressAdvance()->text("Importing records to index <info>{$temporaryName}</info>"); |
75
|
|
|
|
76
|
|
|
try { |
77
|
|
|
$config->set('scout.prefix', self::$prefix.'_'.$scoutPrefix); |
78
|
|
|
$config->set('scout.synchronous', true); |
79
|
|
|
$searchable::makeAllSearchable(); |
80
|
|
|
} finally { |
81
|
|
|
$config->set('scout.prefix', $scoutPrefix); |
82
|
|
|
$config->set('scout.synchronous', $scoutSynchronous); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
tap($this->output)->progressAdvance()->text("Replacing index <info>{$index->getIndexName()}</info> by index <info>{$temporaryName}</info>"); |
86
|
|
|
|
87
|
|
|
$algolia->client()->moveIndex($temporaryName, $index->getIndexName())->wait(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
tap($this->output)->success('All ['.implode(',', $searchables).'] records have been imported')->newLine(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Get a temporary index name. |
95
|
|
|
* |
96
|
|
|
* @param \Algolia\AlgoliaSearch\Index $index |
97
|
|
|
* |
98
|
|
|
* @return string |
99
|
|
|
*/ |
100
|
|
|
private function getTemporaryIndexName(Index $index): string |
101
|
|
|
{ |
102
|
|
|
return self::$prefix.'_'.$index->getIndexName(); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
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