diff --git a/composer.json b/composer.json index 7cf8fde..b0c00fa 100644 --- a/composer.json +++ b/composer.json @@ -32,6 +32,7 @@ "scienta/doctrine-json-functions": "^6.3", "setasign/fpdf": "^1.8", "setasign/fpdi": "^2.5", + "spatie/blink": "^1.4", "spatie/icalendar-generator": "^2.5", "symfony/apache-pack": "^1.0", "symfony/asset": "6.4.*", diff --git a/composer.lock b/composer.lock index 1bc2382..5756f2a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "52ec6ca4d15ec27e3586b5bab26b528c", + "content-hash": "0bd1cb4a8201fb9558138001813bec5a", "packages": [ { "name": "beberlei/doctrineextensions", @@ -3371,6 +3371,68 @@ ], "time": "2025-02-05T13:22:35+00:00" }, + { + "name": "spatie/blink", + "version": "1.4.0", + "source": { + "type": "git", + "url": "https://github.com/spatie/blink.git", + "reference": "d2c12b84ba04d4c5b53d701cc09810bf7e5d546f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/blink/zipball/d2c12b84ba04d4c5b53d701cc09810bf7e5d546f", + "reference": "d2c12b84ba04d4c5b53d701cc09810bf7e5d546f", + "shasum": "" + }, + "require": { + "php": "^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\Blink\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "homepage": "https://spatie.be", + "role": "Developer" + } + ], + "description": "Cache that expires in the blink of an eye", + "homepage": "https://github.com/spatie/blink", + "keywords": [ + "Blink", + "cache", + "caching", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/blink/issues", + "source": "https://github.com/spatie/blink/tree/1.4.0" + }, + "funding": [ + { + "url": "https://spatie.be/open-source/support-us", + "type": "custom" + }, + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2023-07-19T18:28:44+00:00" + }, { "name": "spatie/enum", "version": "3.13.0", diff --git a/src/Command/StampUploadsCommand.php b/src/Command/StampUploadsCommand.php index 16d78ad..35000df 100644 --- a/src/Command/StampUploadsCommand.php +++ b/src/Command/StampUploadsCommand.php @@ -6,8 +6,10 @@ namespace App\Command; use App\Entity\Disposition; use App\Entity\Upload; +use App\Entity\User; use App\Service\Pdf\InvoiceApprover; use Doctrine\ORM\EntityManagerInterface; +use Spatie\Blink\Blink; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\ProgressBar; @@ -42,8 +44,24 @@ class StampUploadsCommand extends Command $progressBar = new ProgressBar($output, count($dispositions)); $progressBar->start(); + $blink = new Blink(); + $userRepository = $this->entityManager->getRepository(User::class); foreach ($dispositions as $disposition) { + /** @var Disposition $disposition */ + $upload = $disposition->getDocumentByType(Upload::TYPE_INVOICE); + if (null === $upload->getApprovedBy()) { + $email = $upload->getUpdatedBy(); + if ($blink->has($email)) { + $approvingUser = $blink->get($email); + } else { + $approvingUser = $userRepository->findOneBy(['email' => $email]); + $blink->put($email, $approvingUser); + } + if (null !== $approvingUser) { + $upload->setApprovedBy($approvingUser->getInitials()); + } + } $this->invoiceApprover->render($disposition); $progressBar->advance(); }