0

I use Loggable to backup changes in Entities. The default AbstractLogEntry does not have enough columns for my needs. Thats why i extended the class and added extra getters and setters.

See the code below

/**
 * EmployeeBackup
 *
 * @ORM\Table(name="employee_backup")
 * @ORM\Entity(repositoryClass="Gedmo\Loggable\Entity\Repository\LogEntryRepository")
 *
 */
class EmployeeBackup extends AbstractLogEntry
{
    /**
     * @var int
     *
     * @ORM\Column(name="division_id", type="integer", unique=true)
     */
    private $divisionId;

    /**
     * @return int
     */
    public function getDivisionId(): int
    {
        return $this->divisionId;
    }

    /**
     * @param string $divisionId
     */
    public function setDivisionId(string $divisionId): void
    {
        $this->divisionId = $divisionId;
    }


}

The extension is using the class above. So it works.

But now i need to set the divisionId when a new version is stored.

I tried the code below

$loggable = new LoggableListener();
$loggable->setDivision($division);
$evm->addEventSubscriber($loggable);

And this is what i get:

Attempted to call an undefined method named "setDivision" of class "Gedmo\Loggable\LoggableListener".

And thats true because LoggableListener does not have a setDivision function. My question is: Do i need to override the listener and if so, how do i do that?

Thanks ;)

Puya Sarmidani
  • 1,226
  • 9
  • 26
  • 1
    you must extend `Gedmo/Loggable/LoggableListener`, adding setDivision function. Check setUsername function in the file. `createLogEntry` must be overriden too, for saving division. – SilvioQ Nov 30 '18 at 12:51
  • I did the same thing but used `prePersistLogEntry` as it was mentioned in https://github.com/Atlantic18/DoctrineExtensions/issues/204 . Thanks for the suggestion – Puya Sarmidani Nov 30 '18 at 13:20
  • @PuyaSarmidani Could you explain me how to extends `Gedmo/Loggable/LoggableListener` ? – Nguyen Nhut Tien Nov 10 '22 at 06:57

0 Answers0