60 lines
1.3 KiB
PHP
60 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire;
|
|
|
|
use Livewire\Component;
|
|
use Symfony\Component\Process\Process;
|
|
|
|
class DownloadForm extends Component
|
|
{
|
|
public $output='start me';
|
|
|
|
public $buttonText = 'Start';
|
|
|
|
public function mount() {
|
|
auth()->loginUsingId(1);
|
|
$this->buttonText = __('Start');
|
|
}
|
|
|
|
public function start()
|
|
{
|
|
$this->buttonText = __('Downloading...');
|
|
|
|
// Commands to run
|
|
$projectFolder = base_path('../');
|
|
|
|
$command = [
|
|
sprintf('%srunpython.sh', $projectFolder ),
|
|
];
|
|
|
|
// Convert commands array to a single string
|
|
|
|
$process = new Process($command);
|
|
$process->setTimeout(3600); // stel een geschikte timeout in
|
|
$process->start();
|
|
|
|
try {
|
|
$myOutput = [];
|
|
$process->wait(function ($type, $buffer) use (&$myOutput){
|
|
$this->stream(to: 'output', content: $buffer);
|
|
$myOutput[] = $buffer;
|
|
});
|
|
$this->output = collect($myOutput)->join('<BR>');
|
|
|
|
} catch (ProcessFailedException $exception) {
|
|
|
|
logger('error', $exception->getMessage());
|
|
echo $exception->getMessage();
|
|
}
|
|
$this->buttonText = __('Done');
|
|
}
|
|
|
|
|
|
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.download-form');
|
|
}
|
|
}
|