-
-
Notifications
You must be signed in to change notification settings - Fork 476
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html --> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" | ||
colors="true" | ||
bootstrap="tests/bootstrap.php" | ||
> | ||
<php> | ||
<ini name="display_errors" value="1" /> | ||
<ini name="error_reporting" value="-1" /> | ||
<server name="APP_ENV" value="test" force="true" /> | ||
<server name="SHELL_VERBOSITY" value="-1" /> | ||
<ini name="display_errors" value="1"/> | ||
<ini name="error_reporting" value="-1"/> | ||
<server name="APP_ENV" value="test" force="true"/> | ||
<server name="SHELL_VERBOSITY" value="-1"/> | ||
</php> | ||
|
||
<testsuites> | ||
<testsuite name="Project Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<coverage> | ||
<coverage/> | ||
<source> | ||
<include> | ||
<directory suffix=".php">src</directory> | ||
</include> | ||
</coverage> | ||
|
||
</source> | ||
</phpunit> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,12 @@ | |
use App\Entity\User; | ||
use App\Util\DoctrineTrait; | ||
use Doctrine\Bundle\DoctrineBundle\Attribute\AsEntityListener; | ||
use Doctrine\DBAL\Types\Types; | ||
use Doctrine\ORM\EntityManager; | ||
use Doctrine\Persistence\Event\LifecycleEventArgs; | ||
use Doctrine\ORM\Event\PreUpdateEventArgs; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
use Symfony\Bridge\Doctrine\Types\UlidType; | ||
use Symfony\Bundle\SecurityBundle\Security; | ||
|
||
#[AsEntityListener(event: 'postPersist', entity: Package::class)] | ||
|
@@ -45,9 +47,7 @@ public function __construct( | |
*/ | ||
public function postPersist(Package $package, LifecycleEventArgs $event): void | ||
{ | ||
$record = AuditRecord::packageCreated($package, $this->getUser()); | ||
$this->getEM()->persist($record); | ||
$this->getEM()->flush(); | ||
$this->insert(AuditRecord::packageCreated($package, $this->getUser())); | ||
} | ||
|
||
/** | ||
|
@@ -63,7 +63,7 @@ public function preRemove(Package $package, LifecycleEventArgs $event): void | |
public function preUpdate(Package $package, PreUpdateEventArgs $event): void | ||
{ | ||
if ($event->hasChangedField('repository')) { | ||
// buffering things to be flushed in postUpdate as flushing here results in an infinite loop | ||
// buffering things to be inserted in postUpdate once we can confirm it is done | ||
$this->buffered[] = AuditRecord::canonicalUrlChange($package, $this->getUser(), $event->getOldValue('repository')); | ||
} | ||
} | ||
|
@@ -75,9 +75,8 @@ public function postUpdate(Package $package, LifecycleEventArgs $event): void | |
{ | ||
if ($this->buffered) { | ||
foreach ($this->buffered as $record) { | ||
$this->getEM()->persist($record); | ||
$this->insert($record); | ||
} | ||
$this->getEM()->flush(); | ||
$this->buffered = []; | ||
} | ||
} | ||
|
@@ -88,4 +87,21 @@ private function getUser(): User|null | |
|
||
return $user instanceof User ? $user : null; | ||
} | ||
|
||
private function insert(AuditRecord $record): void | ||
{ | ||
$this->getEM()->getConnection()->insert('audit_log', [ | ||
Check failure on line 93 in src/EventListener/PackageListener.php GitHub Actions / PHPStan
Check failure on line 93 in src/EventListener/PackageListener.php GitHub Actions / PHPStan
|
||
'id' => $record->id, | ||
'datetime' => $record->datetime, | ||
'type' => $record->type->value, | ||
'attributes' => $record->attributes, | ||
'userId' => $record->userId, | ||
'vendor' => $record->vendor, | ||
'packageId' => $record->packageId, | ||
], [ | ||
'id' => UlidType::NAME, | ||
'datetime' => Types::DATETIME_IMMUTABLE, | ||
'attributes' => Types::JSON | ||
]); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
staabm
|
||
} | ||
} |
@staabm any clue if the warnings above are fixable as I pass custom types here? Or should I rather just put this in the baseline?