1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Thinktomorrow\Chief\App\Console; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Collection; |
6
|
|
|
use Thinktomorrow\Chief\Plugins\TranslationsExport\Document\TranslationsExportDocument; |
|
|
|
|
7
|
|
|
use Thinktomorrow\Chief\Site\Urls\UrlRecord; |
8
|
|
|
use Thinktomorrow\Chief\Site\Visitable\Visitable; |
9
|
|
|
|
10
|
|
|
class TranslationsExportCommand extends BaseCommand |
11
|
|
|
{ |
12
|
|
|
protected $signature = 'chief:translations-export |
13
|
|
|
{locale : the origin locale} |
14
|
|
|
{--target= : the locales for which you want to provde a column}'; |
15
|
|
|
protected $description = 'Export page text content for translations'; |
16
|
|
|
|
17
|
|
|
public function __construct() |
18
|
|
|
{ |
19
|
|
|
parent::__construct(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function handle(): void |
23
|
|
|
{ |
24
|
|
|
$locales = config('chief.locales'); |
25
|
|
|
$locale = $this->argument('locale'); |
26
|
|
|
|
27
|
|
|
if (! in_array($locale, $locales)) { |
28
|
|
|
throw new \InvalidArgumentException('Passed locale ' . $locale .' is not found as Chief locale. Available locales are ' . implode(',', $locales)); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$targetLocales = $locales; |
32
|
|
|
unset($targetLocales[array_search($locale, $targetLocales)]); |
33
|
|
|
|
34
|
|
|
if ($this->option('target')) { |
35
|
|
|
$targetLocales = explode(',', $this->option('target')); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$models = $this->getAllModels($locale); |
39
|
|
|
|
40
|
|
|
$models = $models->random(1); |
41
|
|
|
|
42
|
|
|
(new TranslationsExportDocument($models, $locale, $targetLocales)) |
43
|
|
|
->store('test.xlsx'); |
44
|
|
|
|
45
|
|
|
$this->info('Finished export. File available at ...'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
private function getAllModels(string $locale): Collection |
49
|
|
|
{ |
50
|
|
|
return UrlRecord::allOnlineModels($locale) |
51
|
|
|
// In case the url is not found or present for given locale. |
52
|
|
|
->reject(function (Visitable $model) use ($locale) { |
53
|
|
|
return ! $model->url($locale); |
54
|
|
|
}); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
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