All Projects → spinen → laravel-garbage-man

spinen / laravel-garbage-man

Licence: other
Scheduled job to clean out Laravel's soft deleted records at configured interval

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-garbage-man

laravel-geometry
SPINEN's Laravel wrapper over geoPHP
Stars: ✭ 36 (+9.09%)
Mutual labels:  laravel-5-package, spinen
laravel-browser-filter
Laravel middleware to filter routes based on browser types & versions.
Stars: ✭ 20 (-39.39%)
Mutual labels:  laravel-5-package, spinen
devtube
Laravel YouTube and Online Video viewing and download interface.
Stars: ✭ 30 (-9.09%)
Mutual labels:  laravel-5-package
adminlte-laravel-installer
adminlte-laravel-installer . Installer for project acacha/adminlte-laravel
Stars: ✭ 16 (-51.52%)
Mutual labels:  laravel-5-package
laravel-camelcase-json
Convert response JSON key to camelCase
Stars: ✭ 23 (-30.3%)
Mutual labels:  laravel-5-package
lara-block-io
A Laravel Package/Facade for the Block.io API
Stars: ✭ 22 (-33.33%)
Mutual labels:  laravel-5-package
LaravelFtp
Laravel FTP client
Stars: ✭ 15 (-54.55%)
Mutual labels:  laravel-5-package
panichd
Ticketing system for Laravel 5.1 - 8.x. Allows to create new tickets via form only. Includes file attachments, ticket tags, filtering, scheduling and e-mail notifications.
Stars: ✭ 78 (+136.36%)
Mutual labels:  laravel-5-package
laravel-big
Google BigQuery for Laravel
Stars: ✭ 14 (-57.58%)
Mutual labels:  laravel-5-package
aws-rekognition
A Laravel Package/Facade for the AWS Rekognition API
Stars: ✭ 20 (-39.39%)
Mutual labels:  laravel-5-package
docxmustache
laravel 8.x docx template manipulation class, based on mustache templating language
Stars: ✭ 34 (+3.03%)
Mutual labels:  laravel-5-package
model-observers
Make model observers easy
Stars: ✭ 17 (-48.48%)
Mutual labels:  laravel-5-package
domain-enforcement
Laravel 5+ Middleware to enforce a single domain on your application. e.g non-www. to www.
Stars: ✭ 25 (-24.24%)
Mutual labels:  laravel-5-package
smart-schema
A Laravel package to enable auto generation of forms
Stars: ✭ 18 (-45.45%)
Mutual labels:  laravel-5-package
laravel-string-similarities
Compare two string and get a similarity percentage
Stars: ✭ 54 (+63.64%)
Mutual labels:  laravel-5-package
maintenance-mode
An enhanced maintenance mode for Laravel.
Stars: ✭ 117 (+254.55%)
Mutual labels:  laravel-5-package
laravel-jira-rest-client
A Laravel interface for your Atlassians Jira application
Stars: ✭ 37 (+12.12%)
Mutual labels:  laravel-5-package
Base62
PHP Base62 encoder and decoder for integers and big integers with Laravel 5 support.
Stars: ✭ 16 (-51.52%)
Mutual labels:  laravel-5-package
laravel-s3-tools
This Laravel package contains additional functionality not currently in Laravel for interfacing with Amazon's S3 service (including managing versioned objects).
Stars: ✭ 31 (-6.06%)
Mutual labels:  laravel-5-package
laravel-video-api
Laravel (Youtube/Vimeo) Video Data API
Stars: ✭ 53 (+60.61%)
Mutual labels:  laravel-5-package

SPINEN's Laravel Garbage Man

Latest Stable Version Latest Unstable Version Total Downloads License

The soft deletes are great in Laravel to make sure that some deleted data can be recovered. This package allows you to configure an array of models with how many days that you want the soft deleted data to stay in the database.

Build Status

Branch Status Coverage Code Quality
Develop Build Status Code Coverage Scrutinizer Code Quality
Master Build Status Code Coverage Scrutinizer Code Quality

Prerequisite

NOTE: If you need to use < PHP 7.2, please stay with version 1.x

As side from Laravel >= 5.1.10 (5.1.10 is the first version that had the warn method, so that is the minimum for logging), there is 1 package that is required.

Install

Install Garbage Man:

$ composer require spinen/laravel-garbage-man

For >= Laravel 5.5, you are done with the installation

The package uses the auto registration feature of Laravel 5.

Upgrading to 2.x from 1.x

As of Laravel 5.8 (and deprecated in 5.4), the fire() method on the dispatcher contract was removed in favor of dispatch(). Therefore, we have updated our code to use dispatch(). You will need to change fire() to dispatch() in your config/garbageman.php file.

Using the command

The command is registered with laravel as garbageman:purge. You can run it one of 2 ways...

  1. from the command line php artisan garbageman:purge;
  2. via a scheduled task.

To automatically run the script as a scheduled job, then add the following to the schedule method of App\Console\Kernel.php:

$schedule->command('garbageman:purge')
         ->daily();

You can use whatever schedule that you need to keep the records purged out. Just review the list at http://laravel.com/docs/master/scheduling#schedule-frequency-options.

You can also use any of the advanced configuration options of the task scheduler like "Task Output" or "Task Hooks" as listed on the Laravel documentation.

Configuration

Publish the package config file to config/garbageman.php:

$ php artisan vendor:publish

This file is fully documented. You will need to make the changes to that file to suit your needs. There are 3 main configuration items...

  1. Dispatch purge events - Dispatch events on purge of each record.
  2. Logging level - Level to log.
  3. Schedule - Models & number of days to allow the soft deleted record to stay before purging.

Dispatch purge events (dispatch_purge_events)

You may hook into the purge of each record by throwing events before & after deleting of each record. There are 2 events thrown:

  • garbageman.purging:<full/model/name>
  • garbageman.purged:<full/model/name>

The model is passed with each of the events. The "purging" event is thrown just before the actual delete & "purged" is thrown just after the actual deletion.

Please note: This is an expensive operation as it requires a SQL command for each record to delete so that the record can be thrown with the events. Therefore, unless you need to catch the events to perform some other action, leave this false to allow all records per model to get deleted with a single SQL call.

Logging level (logging_level)

The level that log messages are generated, which will display information on the console output and in the logs.

Level Description
0 Emergency: system is unusable
1 Alert: action must be taken immediately
2 Critical: critical conditions
3 Error: error conditions
4 Warning: warning conditions
5 Notice: normal but significant condition
6 (default) Info: informational messages
7 Debug: debug - level messages

There is a key for the console & one for the log. Here is an example...

'logging_level' => [
    'console' => 3,
    'log'     => 6,
],

Alternatively, you can set the levels with environmental variables GARBAGEMAN_CONSOLE_LOG_LEVEL and GARBAGEMAN_LOG_LEVEL.

Schedule (schedule)

The age is in days for each model. Here is an example...

'schedule' => [
    App\ModelOne::class => 14,
    App\ModelTwo::class => 30,
],

This would purge any ModelOnes that were deleted over 14 days ago and any ModelTwos that were deleted over 30 days ago.

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].