Repository: DamienHarper/auditor (php)

Issue:
Incorrect primary key name on render
vendor/damienharper/auditor/src/Provider/Doctrine/Auditing/Transaction/AuditTrait::summarize
the method uses the actual name of the primary key (in my case the "code" field - $pkName variable) 

vendor/damienharper/auditor-bundle/src/Resources/views/Audit/helpers/helper.html.twig:58-59
`{% set subject = target.class~'#'~target.id %}
        {{ direction }} <code><a href="{{ path('dh_auditor_show_entity_history', { 'entity': helper.namespaceToParam(target.class), 'id': target.id }) }}">{{ subject }}</a></code>`
        but when rendering, we use the "id" field, but in my case it is not there, there is a "code" field
        

Pull request:
Add pkName::summarize to AuditTrait
To fix #112 I need to make 2 PRs.
1. Auditor PR - added pkName to ’summarize’ method to possible detect primary key. After entity is stored, impossible to get the key, it can be changed, it used directy in twig template and so on
2. Have a new tag of this package
3. Auditor-bundle PR - fix  helper.twig::summarize method and use the field. https://github.com/DamienHarper/auditor-bundle/pull/328

Also I added an Entity I'll use in Auditor-bundle - it's primary key is not `id`. Needed to write test where.

Patch:
diff --git a/src/Provider/Doctrine/Auditing/Transaction/AuditTrait.php b/src/Provider/Doctrine/Auditing/Transaction/AuditTrait.php
index 7706197..24d7f7e 100644
--- a/src/Provider/Doctrine/Auditing/Transaction/AuditTrait.php
+++ b/src/Provider/Doctrine/Auditing/Transaction/AuditTrait.php
@@ -209,6 +209,10 @@ trait AuditTrait
             $label = DoctrineHelper::getRealClassName($entity).(null === $pkValue ? '' : '#'.$pkValue);
         }
 
+        if ('id' !== $pkName) {
+            $extra['pkName'] = $pkName;
+        }
+
         return [
             $pkName => $pkValue,
             'class' => $meta->name,


Test patch:
diff --git a/tests/Provider/Doctrine/Fixtures/Issue112/DummyEntity.php b/tests/Provider/Doctrine/Fixtures/Issue112/DummyEntity.php
new file mode 100644
index 0000000..bdaab0e
--- /dev/null
+++ b/tests/Provider/Doctrine/Fixtures/Issue112/DummyEntity.php
@@ -0,0 +1,36 @@
+<?php
+
+declare(strict_types=1);
+
+namespace DH\Auditor\Tests\Provider\Doctrine\Fixtures\Issue112;
+
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * @ORM\Entity
+ * @ORM\Table(name="author")
+ */
+#[ORM\Entity]
+#[ORM\Table(name: 'author')]
+class DummyEntity
+{
+    /**
+     * @ORM\Id
+     * @ORM\Column(type="integer", options={"unsigned": true})
+     * @ORM\GeneratedValue(strategy="IDENTITY")
+     */
+    #[ORM\Id]
+    #[ORM\Column(type: 'integer', options: ['unsigned' => true])]
+    #[ORM\GeneratedValue(strategy: 'IDENTITY')]
+    protected int $primaryKey;
+
+    public function getPrimaryKey(): int
+    {
+        return $this->primaryKey;
+    }
+
+    public function setPrimaryKey(int $primaryKey): void
+    {
+        $this->primaryKey = $primaryKey;
+    }
+}
diff --git a/tests/Provider/Doctrine/Issues/Issue112Test.php b/tests/Provider/Doctrine/Issues/Issue112Test.php
new file mode 100644
index 0000000..1bd9cc2
--- /dev/null
+++ b/tests/Provider/Doctrine/Issues/Issue112Test.php
@@ -0,0 +1,35 @@
+<?php
+
+declare(strict_types=1);
+
+namespace DH\Auditor\Tests\Provider\Doctrine\Issues;
+
+use DH\Auditor\Provider\Doctrine\Auditing\Transaction\AuditTrait;
+use DH\Auditor\Tests\Provider\Doctrine\Fixtures\Issue112\DummyEntity;
+use DH\Auditor\Tests\Provider\Doctrine\Traits\Schema\DefaultSchemaSetupTrait;
+use PHPUnit\Framework\TestCase;
+
+/**
+ * @internal
+ *
+ * @small
+ */
+final class Issue112Test extends TestCase
+{
+    use AuditTrait;
+    use DefaultSchemaSetupTrait;
+
+    /**
+     * @throws \Doctrine\ORM\Mapping\MappingException
+     * @throws \Doctrine\DBAL\Exception
+     * @throws \DH\Auditor\Exception\MappingException
+     */
+    public function testSummarizeWithUnusualPK(): void
+    {
+        $entityManager = $this->createEntityManager();
+        $entity = new DummyEntity();
+        $entity->setPrimaryKey(2);
+        $data = $this->summarize($entityManager, $entity);
+        self::assertSame('primaryKey', $data['pkName']);
+    }
+}