2017 © Pedro Peláez
 

library f3-softerase

Soft Erases for PHP Fat-Free Framework ORM

image

acemureithi/f3-softerase

Soft Erases for PHP Fat-Free Framework ORM

  • Wednesday, May 18, 2016
  • by acemureithi
  • Repository
  • 1 Watchers
  • 0 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 33 % Grown

The README.md

F3 SoftErase

Instead of removing records from your database, the SoftErase Trait will store records in a trashed state, and deleted records can be restored., (*1)

System Requirements

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)

Installation

To install, copy the /lib/db/softerase.php file to the /lib/db/. OR use Composer and run composer require acemureithi/f3-softerase, (*3)

Getting Started

  • Define your class
class Book extends \DB\SQL\Mapper{ //Also Works for JIG not tested on Mongo
    use \DB\SoftErase; // The SoftErase Trait
}
  • Use it!
$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)

SoftErase API

deleteTime

String The Field to store the time of erasing.(Timestamp), (*5)

bypass

bool Whether to bypass softerase. Set true and records are deleted permanently, (*6)

notDeletedFilter()

Get the (not Deleted) Filter. @return array|null, (*7)

forceErase()

Force a hard (normal) erase. @return bool, (*8)

$mapper->load(array('title = ?','50 Shades'));
$mapper->forceErase(); //hard Erase

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()

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()

erased()

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

SoftErase::onlyErased($mapper)

Cursor instance that includes only soft erases. @return array, (*12)

Books::onlyErased($mapper);

NOTE

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)

FAQ

Can I use it on php 5.3?

No. Traits are ony supported from php 5.4 onward., (*15)

Any Db Changes Needed?

Yes, especially SQL Databases, add a field deleted_at (or how you define it in the $deleteTime variable) to avoid field missing errors, (*16)

The Versions

18/05 2016

dev-master

9999999-dev https://github.com/acemureithi/f3-softerase

Soft Erases for PHP Fat-Free Framework ORM

  Sources   Download

GPL-3.0

f3 soft delete fatfree soft erase