37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Symfony\Component\Process\Process;
|
|
|
|
class ImportTerritoryWorkbook extends Command
|
|
{
|
|
protected $signature = 'geo:import-workbook {--inspect : Inspect the authorised workbook without database writes} {--python=python : Python executable}';
|
|
|
|
protected $description = 'Inspect and idempotently import the authorised cartography workbook, preserving existing IDs';
|
|
|
|
public function handle(): int
|
|
{
|
|
if (! app()->environment('local', 'testing')) {
|
|
$this->error('Local/testing only.');
|
|
|
|
return self::FAILURE;
|
|
}
|
|
foreach ([[strval($this->option('python')), base_path('tools/prepare-territory-workbook.py')],
|
|
...($this->option('inspect') ? [] : [[PHP_BINARY, base_path('tools/import-territory-workbook.php')]])] as $command) {
|
|
$process = new Process($command, base_path());
|
|
$process->setTimeout(300);
|
|
$process->run();
|
|
$this->output->write($process->getOutput());
|
|
if (! $process->isSuccessful()) {
|
|
$this->error($process->getErrorOutput());
|
|
|
|
return self::FAILURE;
|
|
}
|
|
}
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|