Download the PHP package andanteproject/soft-deletable-bundle without Composer
On this page you can find all versions of the php package andanteproject/soft-deletable-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download andanteproject/soft-deletable-bundle
More information about andanteproject/soft-deletable-bundle
Files in andanteproject/soft-deletable-bundle
Package soft-deletable-bundle
Short Description A Symfony Bundle to handle soft deletable with Doctrine Entities
License MIT
Informations about the package soft-deletable-bundle
Soft Deletable Bundle
Symfony Bundle - AndanteProject
Simple Symfony Bundle to handle soft delete for doctrine entities. So your entities "are not going to be deleted for real from the database". 🙌
Requirements
Symfony 4.x-5.x and PHP 7.4.
Install
Via Composer:
Features
- No configuration required to be ready to go but fully customizabile;
deleteAt
property is as a?\DateTimeImmutable
;- You can disable the filter runtime even for just some entities;
- No annotation required;
- Works like magic ✨.
Basic usage
After install, make sure you have the bundle registered in your symfony bundles list (config/bundles.php
):
This should have been done automagically if you are using Symfony Flex. Otherwise, just register it by yourself.
Let's suppose we have a App\Entity\Article
doctrine entity we want to enable to soft-deletion.
All you have to do is to implement Andante\SoftDeletableBundle\SoftDeletable\SoftDeletableInterface
and use Andante\SoftDeletableBundle\SoftDeletable\SoftDeletableTrait
trait.
Make sure to update you database schema following your doctrine workflow (bin/console doctrine:schema:update --force
if you are a badass devil guy or with a migration if you choosed the be a better developer!).
You shoud see a new column named deleted_at
(doctrine naming strategy.
Congrats! You're done! 🎉
From now on, when you delete your entity, it will be not hard-deleted from the database.
For example, let's suppose to save a new Article
:
And so we will have it on our database.
id | title | ... | deleted_at |
---|---|---|---|
1 | Free 🍕 for everyone! | ... | NULL |
But, if you delete it with Doctrine, the row will still be there but with the deleted_at
populated with the date of its delation.
id | title | ... | deleted_at |
---|---|---|---|
1 | Free 🍕 for everyone! | ... | 2021-01-01 10:30:00 |
And the entity will be no more available from your app queries. (Is there a way I can restore them?)
Gosh, what are you doing to my poor entities?! 🤭
No entity was mistreated while using this bundle 🙌.
We suggest you to use Andante\SoftDeletableBundle\SoftDeletable\SoftDeletableTrait
trait to make your life easier. It does nothing special under the hood:
it adds a \DateTimeImmutable deletedAt
property to your entity mapped with our deleted_at
doctrine type and a getter/setter to handle it.
But, for whatever reason, you are free to do it yourself (implementing SoftDeletableInterface
is mandatory instead).
Usage with no trait
This allows you to, for instance, to have a different name for your property (E.g. deleted
instead of deletedAt
).
But you will need to explicit this in bundle configuration.
Disabling soft-delete filter
You can disable the filter entirely runtime by doing this to your Entity Manager.
If you want you can also disable the filter for just one or more entities by doing this:
Configuration (completely optional)
This bundle is build thinking how to save you time and follow best practices as close as possible.
This means you can even ignore to have a andante_soft_deletable.yaml
config file in your application.
However, for whatever reason (legacy code?), use the bundle configuration to change most of the behaviors as your needs.
Please note
- This bundle does not handle direct DQL queries;
- The default setting of
deleted_date_aware
isfalse
. The filter is going to exclude whatever row with aNOT NULL
deleted date. If you want to exclude only rows with adeletedAt
date in the past and still retrieving the ones with future dates, you need to setdeleted_date_aware
totrue
.
Built with love ❤️ by AndanteProject team.
All versions of soft-deletable-bundle with dependencies
symfony/framework-bundle Version ^4.4 | ^5.0 | ^6.0
doctrine/common Version ^2.13 || ^3.0
doctrine/event-manager Version ^1.0