Skip to content

Instantly share code, notes, and snippets.

@bwaidelich
Last active September 22, 2022 16:19
Show Gist options
  • Save bwaidelich/9617211 to your computer and use it in GitHub Desktop.
Save bwaidelich/9617211 to your computer and use it in GitHub Desktop.
A simple example showing how doctrine behaviors (in this chase soft-deleteable) can be used within TYPO3 Flow.
{
...
"require": {
"typo3/flow": "2.0.*",
"gedmo/doctrine-extensions": "2.3.*"
},
...
}
TYPO3:
Flow:
# disable reflection for non psr-0 compliant 3rd party packages
object:
excludeClasses:
'gedmo.doctrineextensions' : ['Gedmo\\.*']
# register soft deletable filter & event listeners
persistence:
doctrine:
filters:
soft-deletable: 'Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter'
eventListeners:
-
events: ['onFlush', 'loadClassMetadata']
listener: 'Gedmo\SoftDeleteable\SoftDeleteableListener'
<?php
namespace Your\Package\Domain\Model;
use TYPO3\Flow\Annotations as Flow;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* Trait for soft-deletable entities.
* Usage:
*
* * Add @Gedmo\SoftDeleteable(fieldName="deletedAt") annotation to your entity
* * add "use SoftDeletableTrait;" to your entity
*/
trait SoftDeletableTrait {
/**
* DateTime when this entity was deleted (used for "Soft-Delete behaviour")
*
* @var \DateTime
* @ORM\Column(nullable=true)
*/
protected $deletedAt;
/**
* @return \DateTime
*/
public function getDeletedAt() {
return $this->deletedAt;
}
/**
* @param \DateTime $deletedAt
* @return void
*/
public function setDeletedAt(\DateTime $deletedAt) {
$this->deletedAt = $deletedAt;
}
}
<?php
namespace Your\Package\Domain\Model;
use TYPO3\Flow\Annotations as Flow;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* Some Entity
*
* @Flow\Entity
* @Gedmo\SoftDeleteable(fieldName="deletedAt")
*/
class SomeEntity {
use SoftDeletableTrait;
/** ..other properties ..*/
}
?>
@Wirone
Copy link

Wirone commented Feb 13, 2015

Anyone knows how to mix softdeleteable and blameable in proper way? I want to update deleted_by field when "removing" entity.

@KatharinaSt
Copy link

As I stumbled upon it:
Please notice the different spellings of "deleteable" and "deletable" (with/without additional "e") in the example. ;-)

@BossBele
Copy link

BossBele commented Sep 22, 2022

Adding @Gedmo\SoftDeleteable(fieldName="deletedAt") annotation to your entity to every entity is quite a hustle 😅

While using 'deletedAt' column name for soft deletion, one can use the SoftDeleteableEntity which doesn't require annotations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment