67 lines
2.1 KiB
PHP
67 lines
2.1 KiB
PHP
<?php
|
|
namespace ProVM\Common\Command;
|
|
|
|
use ProVM\Common\Service\Communicator;
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
|
|
#[AsCommand(
|
|
name: 'attachments:decrypt',
|
|
description: 'Decrypt attachments pending',
|
|
hidden: false
|
|
)]
|
|
class DecryptPdf extends Command
|
|
{
|
|
public function __construct(Communicator $communicator, string $name = null)
|
|
{
|
|
$this->setCommunicator($communicator);
|
|
parent::__construct($name);
|
|
}
|
|
|
|
protected Communicator $communicator;
|
|
public function getCommunicator(): Communicator
|
|
{
|
|
return $this->communicator;
|
|
}
|
|
public function setCommunicator(Communicator $communicator): DecryptPdf
|
|
{
|
|
$this->communicator = $communicator;
|
|
return $this;
|
|
}
|
|
|
|
protected function getAttachments(): array
|
|
{
|
|
$response = $this->getCommunicator()->get('/attachments/pending');
|
|
return \Safe\json_decode($response->getBody()->getContents())->attachments;
|
|
}
|
|
protected function decrypt(string $attachment): bool
|
|
{
|
|
$response = $this->getCommunicator()->put('/attachments/decrypt', ['attachments' => [$attachment]]);
|
|
return \Safe\json_decode($response->getBody()->getContents())->status;
|
|
}
|
|
|
|
public function execute(InputInterface $input, OutputInterface $output)
|
|
{
|
|
$io = new SymfonyStyle($input, $output);
|
|
$io->title('Decrypt Attachments');
|
|
|
|
$io->section('Grabbing Attachments');
|
|
$attachments = $this->getAttachments();
|
|
$io->text('Found ' . count($attachments) . ' attachments.');
|
|
$io->section('Decrypting Attachments');
|
|
foreach ($attachments as $attachment) {
|
|
$status = $this->decrypt($attachment);
|
|
if ($status) {
|
|
$io->success("{$attachment} decrypted correctly.");
|
|
} else {
|
|
$io->error("Problem decrypting {$attachment}.");
|
|
}
|
|
}
|
|
$io->success('Done.');
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
} |