All Projects → geofmureithi → F3 Softerase

geofmureithi / F3 Softerase

Licence: gpl-3.0
Instead of removing records from your database, the SoftErase Trait will store records in a trashed state, and deleted records can be restored.

Labels

Projects that are alternatives of or similar to F3 Softerase

toolkit
some useful library of the php
Stars: ✭ 15 (+150%)
Mutual labels:  trait
yii2-db
Database extensions for Yii 2.0 Framework 📦
Stars: ✭ 19 (+216.67%)
Mutual labels:  trait
Num
A collection of numeric types and traits for Rust.
Stars: ✭ 592 (+9766.67%)
Mutual labels:  trait
treelike
A trait to abstract over common tree functionality
Stars: ✭ 33 (+450%)
Mutual labels:  trait
track-who
Laravel Traits for tracking who's done what to your models
Stars: ✭ 29 (+383.33%)
Mutual labels:  trait
rememberable
Laravel Traits for fast integration of model caching
Stars: ✭ 28 (+366.67%)
Mutual labels:  trait
zipcode
ZipCode Cep do Brazil
Stars: ✭ 43 (+616.67%)
Mutual labels:  trait
Laravel Imageup
Auto Image & file upload, resize and crop for Laravel eloquent model using Intervention image
Stars: ✭ 646 (+10666.67%)
Mutual labels:  trait
userstamps
A simple package to insert and load userstamps for a model automatically, it provides an eloquent trait to use in models..
Stars: ✭ 34 (+466.67%)
Mutual labels:  trait
Laravel Ban
Laravel Ban simplify blocking and banning Eloquent models.
Stars: ✭ 572 (+9433.33%)
Mutual labels:  trait
versioning
Prevents update conflicts in Laravel
Stars: ✭ 35 (+483.33%)
Mutual labels:  trait
pipe-trait
Make it possible to chain regular functions
Stars: ✭ 22 (+266.67%)
Mutual labels:  trait
Laravel Model Settings
Model Settings for your Laravel app
Stars: ✭ 409 (+6716.67%)
Mutual labels:  trait
awesome-landlord
A simple, single database multi-tenancy solution for Laravel 5.2+
Stars: ✭ 41 (+583.33%)
Mutual labels:  trait
Befriended
Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.
Stars: ✭ 596 (+9833.33%)
Mutual labels:  trait
sep-pay
Pay.ir Payment Package for Laravel 5.3+
Stars: ✭ 17 (+183.33%)
Mutual labels:  trait
php-traits
A collection of (more or less) useful traits for PHP7.2+
Stars: ✭ 17 (+183.33%)
Mutual labels:  trait
Doctrinebehaviors
Doctrine2 behavior traits
Stars: ✭ 782 (+12933.33%)
Mutual labels:  trait
Derive more
Some more derive(Trait) options
Stars: ✭ 647 (+10683.33%)
Mutual labels:  trait
Mixin
Mixin is a trait/mixin and bytecode weaving framework for Java using ASM
Stars: ✭ 557 (+9183.33%)
Mutual labels:  trait

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.

##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

Installation

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

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!

SoftErase API

deleteTime

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

bypass

bool Whether to bypass softerase. Set true and records are deleted permanently

notDeletedFilter()

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

forceErase()

Force a hard (normal) erase. @return bool

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

erase()

Perform a soft erase. @return bool

$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

$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

$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

Books::onlyErased($mapper);

NOTE

Also note that load(), erase(), save() and find() are defined in the trait

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

FAQ

Can I use it on php 5.3?

No. Traits are ony supported from php 5.4 onward.

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].