Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using #2907

Open
chanondb opened this issue Jan 2, 2025 · 0 comments
Open

Using #2907

chanondb opened this issue Jan 2, 2025 · 0 comments

Comments

@chanondb
Copy link

chanondb commented Jan 2, 2025

Environment

Package

show

$ composer show --latest gedmo/doctrine-extensions
composer show --latest gedmo/doctrine-extensions
name     : gedmo/doctrine-extensions
descrip. : Doctrine behavioral extensions
keywords : Blameable, behaviors, doctrine, extensions, gedmo, loggable, nestedset, odm, orm, sluggable, sortable, timestampable, translatable, tree, uploadable
versions : * v3.17.1
released : 2024-10-07, 2 months ago
latest   : v3.17.1 released 2024-10-07, 2 months ago
type     : library
license  : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage : http://gediminasm.org/
source   : [git] https://github.com/doctrine-extensions/DoctrineExtensions.git eabb45018c5a4362b46c5beae3881261da89f900
dist     : [zip] https://api.github.com/repos/doctrine-extensions/DoctrineExtensions/zipball/eabb45018c5a4362b46c5beae3881261da89f900 eabb45018c5a4362b46c5beae3881261da89f900
path     : /Users/chanondb/symfony/dip-2024/vendor/gedmo/doctrine-extensions
names    : gedmo/doctrine-extensions

support
email : gediminas.morkevicius@gmail.com
issues : https://github.com/doctrine-extensions/DoctrineExtensions/issues
source : https://github.com/doctrine-extensions/DoctrineExtensions/tree/v3.17.1
wiki : https://github.com/Atlantic18/DoctrineExtensions/tree/main/doc

autoload
psr-4
Gedmo\ => src/

requires
behat/transliterator ^1.2
doctrine/collections ^1.2 || ^2.0
doctrine/common ^2.13 || ^3.0
doctrine/deprecations ^1.0
doctrine/event-manager ^1.2 || ^2.0
doctrine/persistence ^2.2 || ^3.0
php ^7.4 || ^8.0
psr/cache ^1 || ^2 || ^3
psr/clock ^1
symfony/cache ^5.4 || ^6.0 || ^7.0

requires (dev)
doctrine/annotations ^1.13 || ^2.0
doctrine/cache ^1.11 || ^2.0
doctrine/dbal ^3.7 || ^4.0
doctrine/doctrine-bundle ^2.3
doctrine/mongodb-odm ^2.3
doctrine/orm ^2.14.0 || ^3.0
friendsofphp/php-cs-fixer ^3.14.0
nesbot/carbon ^2.71 || ^3.0
phpstan/phpstan ^1.11
phpstan/phpstan-doctrine ^1.4
phpstan/phpstan-phpunit ^1.4
phpunit/phpunit ^9.6
rector/rector ^1.1
symfony/console ^5.4 || ^6.0 || ^7.0
symfony/doctrine-bridge ^5.4 || ^6.0 || ^7.0
symfony/phpunit-bridge ^6.0 || ^7.0
symfony/uid ^5.4 || ^6.0 || ^7.0
symfony/yaml ^5.4 || ^6.0 || ^7.0

suggests
doctrine/mongodb-odm to use the extensions with the MongoDB ODM
doctrine/orm to use the extensions with the ORM

conflicts
doctrine/annotations <1.13 || >=3.0
doctrine/dbal <3.7 || >=5.0
doctrine/mongodb-odm <2.3 || >=3.0
doctrine/orm <2.14.0 || 2.16.0 || 2.16.1 || >=4.0
</p>
</details>

#### Doctrine packages

<details><summary>show</summary>
<p>

$ composer show --latest 'doctrine/*'
Direct dependencies required in composer.json:
doctrine/dbal 3.9.3 4.2.1 Powerful PHP database abstraction l...
doctrine/doctrine-bundle 2.13.1 2.13.1 Symfony DoctrineBundle
doctrine/doctrine-migrations-bundle 3.3.1 3.3.1 Symfony DoctrineMigrationsBundle
doctrine/orm 3.3.0 3.3.1 Object-Relational-Mapper for PHP

Transitive dependencies not required in composer.json:
doctrine/cache 2.2.0 2.2.0 PHP Doctrine Cache library is a pop...
doctrine/collections 2.2.2 2.2.2 PHP Doctrine Collections library th...
doctrine/common 3.4.5 3.5.0 PHP Doctrine Common project is a li...
doctrine/deprecations 1.1.3 1.1.4 A small layer on top of trigger_err...
doctrine/event-manager 2.0.1 2.0.1 The Doctrine Event Manager is a sim...
doctrine/inflector 2.0.10 2.0.10 PHP Doctrine Inflector is a small l...
doctrine/instantiator 2.0.0 2.0.0 A small, lightweight utility to ins...
doctrine/lexer 3.0.1 3.0.1 PHP Doctrine Lexer parser library t...
doctrine/migrations 3.8.2 3.8.2 PHP Doctrine Migrations project off...
doctrine/persistence 3.4.0 4.0.0 The Doctrine Persistence project is...
doctrine/sql-formatter 1.5.1 1.5.1 a PHP SQL highlighting library

PHP version

$ php -v
php -v
PHP 8.3.13 (cli) (built: Oct 22 2024 18:39:14) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.13, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.13, Copyright (c), by Zend Technologies

Subject

Duplicate logEntry when using Gedmo Loggable with Blammable, Timestampable

Minimal repository with the bug

Steps to reproduce

stof_doctrine_extensions:
    default_locale: th_TH
    orm:
        default:
            timestampable: true
            blameable: true
            sluggable: true
            loggable: true
            
services:
    gedmo.listener.loggable:
        class: Gedmo\Loggable\LoggableListener
        tags:
            - { name: doctrine.event_subscriber, connection: default }

Example of our Entitty class

#[Gedmo\Loggable(logEntryClass: "App\Entity\LogEntry")]
//#[ApiResource(operations: [new Get(), new Put(), new Delete()])]
class TbReportpurchase{

    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    #[ORM\Column(name:'id',type: 'integer')]
    private ?int $id = null;

    #[ORM\Column(name:'human',length:255, nullable: true)]
    #[ApiProperty]
    #[Gedmo\Versioned]
    private ?string $human = null;

    #[ORM\Column(name:'created_at',type: Types::DATETIME_MUTABLE, nullable: true)]
    #[ApiProperty]
    #[Gedmo\Timestampable(on: 'create')]
    private ?\DateTimeInterface $createdAt = null;

    #[ORM\Column(name:'updated_at',type: Types::DATETIME_MUTABLE, nullable: true)]
    #[ApiProperty]
    #[Gedmo\Timestampable]
    private ?\DateTimeInterface $updatedAt = null;


    #[ORM\ManyToOne]
    #[ORM\JoinColumn(name:'created_by',nullable: false)]
    #[ApiProperty]
    #[Gedmo\Blameable(on: 'create')]
    private ?TbUser $createdBy = null;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(name:'updated_by',nullable: false)]
    #[ApiProperty]
    #[Gedmo\Blameable()]
    private ?TbUser $updatedBy = null;



    public function setUpdatedAt(?\DateTimeInterface $updatedAt): void
    {
        $this->updatedAt = $updatedAt;
    }

    public function getUpdatedAt(): ?\DateTimeInterface
    {
        return $this->updatedAt;
    }

    public function setCreatedAt(?\DateTimeInterface $createdAt): void
    {
        $this->createdAt = $createdAt;
    }

    public function getCreatedAt(): ?\DateTimeInterface
    {
        return $this->createdAt;
    }

    public function setCreatedBy(?TbUser $createdBy): static
    {
        $this->createdBy = $createdBy;

        return $this;
    }

    public function getCreatedBy(): ?TbUser
    {
        return $this->createdBy;
    }

    public function getUpdatedBy(): ?TbUser
    {
        return $this->updatedBy;
    }

    public function setUpdatedBy(?TbUser $updatedBy): static
    {
        $this->updatedBy = $updatedBy;

        return $this;
    }
}

and our LogEntry

<?php

namespace App\Entity;

use App\Repository\LogEntryRepository;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Loggable\Entity\MappedSuperclass\AbstractLogEntry;

#[ORM\Entity(repositoryClass: LogEntryRepository::class)]
#[ORM\Table(options: ['row_format' => 'DYNAMIC'])]
#[ORM\Index(name: 'log_class_lookup_idx', columns: ['object_class'])]
#[ORM\Index(name: 'log_date_lookup_idx', columns: ['logged_at'])]
#[ORM\Index(name: 'log_user_lookup_idx', columns: ['username'])]
#[ORM\Index(name: 'log_version_lookup_idx', columns: ['object_id', 'object_class', 'version'])]
class LogEntry extends AbstractLogEntry
{
    /*
     * All required columns are mapped through inherited superclass
     */
}

New function in Controller

 #[Route('/{id}/new', name: 'app_bo_report_purchase_new', methods: ['GET', 'POST'])]
    public function new(Request $request,TbPurchase $tbPurchase, EntityManagerInterface $entityManager): Response
    {   

        
        $tbReportpurchase = new TbReportpurchase();

        $tbReportpurchase->setPurchase($tbPurchase);
        $tbReportpurchase->setSite($tbPurchase->getSite());

        $form = $this->createForm(TbReportpurchaseType::class, $tbReportpurchase);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
           
            $entityManager->persist($tbReportpurchase);
            $entityManager->flush();
            $this->addFlash('success', 'Success create');

            return $this->redirectToRoute('app_bo_report_purchase_index', [], Response::HTTP_SEE_OTHER);
        }
        
        return $this->render('bo/report_purchase/new.html.twig', [
            'tb_reportpurchase' => $tbReportpurchase,
            'tbPurchase'=>$tbPurchase,
            'form' => $form,
        ]);
    }

Expected results

It should show only single record of logentry with username.

Actual results

But we got duplicate logentry as attached.
Did I config something wrong?
Screenshot 2568-01-02 at 21 26 42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant