Using soft deletes in CMPs

Client (or myself) deletes something and wants it back from me, but hosting backup was too old, so I was screwed. Is it your story too? Continue reading ;)

modObjectSoftRemoveProcessor

If you spot something similar in scenario above, maybe you might want to start using soft deletes in your extras (CMPs). SoftRemoveProcessor do the job for you with minimal effort.

Just create modObjectSoftRemoveProcessor.class.php somewhere in your's processors folder and include it in file where you will be creating softRemoveProcessor. Create processors class as usual but now you will be extending modObjectSoftRemoveProcessor class.

Soft remove processor has a few new settings, that you can overwrite.

  • $useDeletedOn
  • $deletedOnField
  • $useDeletedBy
  • $deletedByField
  • $useDeleted
  • $deletedField

useDeletedOn and deletedOnField

These variables are used for letting processor know if you want to store time and date, when item was removed (mark as removed). If variable useDeletedOn is set to 'true' time and date is stored to column from variable deletedOnField. Defaults are set to true and 'deletedon'.

useDeletedBy and deletedByField

These variables are used for letting processor know if you want to store id of user that removed (mark as removed) item. If variable useDeletedBy is set to 'true' id of user is stored to column from variable deletedByField. Defaults are set to true and 'deletedby'.

useDeleted and deletedField

These variables are used for letting processor know if you want to mark deleted items. If variable useDeleted is set to 'true', deleted rows will have true in column from variable deletedField. Defaults are set to true and 'deleted'.

Summary

If you want to use soft remove processors with minimal call, just add to your scheme columns with names 'deletedon', 'deletedby' and 'deleted'.

It's not necessary to use all three columns, only one column can fit your needs.

If you will set 'useDeleted', 'useDeletedBy' and 'useDeletedOn' you will get an error message.

Here is pull request, so maybe one time it will straight in core.

Post By John Peca MODX