dev-master
9999999-dev https://github.com/acemureithi/f3-softeraseSoft Erases for PHP Fat-Free Framework ORM
GPL-3.0
f3 soft delete fatfree soft erase
Soft Erases for PHP Fat-Free Framework ORM
Instead of removing records from your database, the SoftErase Trait will store records in a trashed state, and deleted records can be restored., (*1)
SoftErase requires at least Fat-Free v3.* and PHP 5.4+.
It is also required to have a deleted_at
field for all SQL databases, (*2)
To install, copy the /lib/db/softerase.php
file to the /lib/db/
.
OR use Composer and run composer require acemureithi/f3-softerase
, (*3)
class Book extends \DB\SQL\Mapper{ //Also Works for JIG not tested on Mongo use \DB\SoftErase; // The SoftErase Trait }
$db = new \DB\SQL('mysql:host=localhost;port=3306;dbname={db}', 'username', 'password'); $table = 'books'; $mapper = new Book($mysql, $table); $mapper->book = "The day of the jackal"; $mapper->author = "Cant Remember"; $mapper->save(); $mapper->erase(); //"Record was soft erased" $mapper->restore(); //Record is back! $mapper->forceErase(); //Okay Goodbye We cannot restore you anymore
And thats it!, (*4)
String The Field to store the time of erasing.(Timestamp), (*5)
bool Whether to bypass softerase. Set true and records are deleted permanently, (*6)
Get the (not Deleted) Filter.
@return array|null
, (*7)
Force a hard (normal) erase.
@return bool
, (*8)
$mapper->load(array('title = ?','50 Shades')); $mapper->forceErase(); //hard Erase
Perform a soft erase.
@return bool
, (*9)
$mapper->load(array('title = ?','50 Shades')); $mapper->erase(); //Record not permanently deleted but does not show up in find() and load()
Restore a soft-erased record.
@return bool|null
, (*10)
$mapper->load(array('title = ?','50 Shades')); $mapper->erase(); //Record not permanently deleted but does not show up in find() and load() $mapper->restore(); //Restores the record now record is in find() and load()
Determine if the instance has been soft-deleted.
@return bool
, (*11)
$mapper->load(array('title = ?','50 Shades')); $mapper->erase(); //Record not permanently deleted but does not show up in find() and load() $mapper->erased(); //True
Cursor instance that includes only soft erases.
@return array
, (*12)
Books::onlyErased($mapper);
Also note that load(), erase(), save() and find() are defined in the trait, (*13)
This trait should be usabe with any class that extends \DB\Cursor
and that includes \DB\SQL\Mapper
, \DB\Mongo\Mapper
, \DB\Jig\Mapper
and also \DB\Cortex
, (*14)
No. Traits are ony supported from php 5.4 onward., (*15)
Yes, especially SQL
Databases, add a field deleted_at
(or how you define it in the $deleteTime variable) to avoid field missing errors, (*16)
Soft Erases for PHP Fat-Free Framework ORM
GPL-3.0
f3 soft delete fatfree soft erase