Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Cleaner Laravel Package

lamoda/cleaner

Lamoda Cleaner is a PHP library for purging old data from various storages, primarily databases. Includes configurable DB cleaners such as a Doctrine DBAL cleaner that runs parameterized cleanup queries to delete outdated records.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require lamoda/cleaner
    

    Add to providers in config/app.php:

    Lamoda\Cleaner\CleanerServiceProvider::class,
    
  2. Publish Config

    php artisan vendor:publish --provider="Lamoda\Cleaner\CleanerServiceProvider" --tag="config"
    

    Locate config at config/cleaner.php.

  3. First Use Case Define a cleanup rule in config/cleaner.php:

    'rules' => [
        'logs' => [
            'driver' => 'filesystem',
            'path' => storage_path('logs'),
            'extension' => 'log',
            'older_than_days' => 30,
        ],
    ],
    

    Run cleanup via Artisan:

    php artisan cleaner:run
    

Implementation Patterns

Rule Definition

Define rules in config/cleaner.php under the rules key:

'rules' => [
    'database' => [
        'driver' => 'database',
        'table' => 'failed_jobs',
        'older_than_days' => 7,
        'batch_size' => 1000,
    ],
    's3_old_files' => [
        'driver' => 's3',
        'bucket' => 'my-bucket',
        'prefix' => 'old-files/',
        'older_than_days' => 90,
    ],
],

Dynamic Rules via Code

Extend functionality programmatically:

use Lamoda\Cleaner\Cleaner;

// In a service or command
$cleaner = app(Cleaner::class);
$cleaner->addRule('temp_files', [
    'driver' => 'filesystem',
    'path' => sys_get_temp_dir(),
    'older_than_days' => 1,
]);

Integration with Scheduling

Add to app/Console/Kernel.php:

protected function schedule(Schedule $schedule)
{
    $schedule->command('cleaner:run')->daily();
}

Custom Drivers

Extend Lamoda\Cleaner\Contracts\CleanerDriver:

namespace App\Cleaner;

use Lamoda\Cleaner\Contracts\CleanerDriver;

class CustomDriver implements CleanerDriver
{
    public function clean(array $config): int
    {
        // Custom logic
        return 42; // Items deleted
    }
}

Register in config/cleaner.php:

'drivers' => [
    'custom' => \App\Cleaner\CustomDriver::class,
],

Gotchas and Tips

Debugging

  • Dry Run: Use --dry-run flag to preview deletions:
    php artisan cleaner:run --dry-run
    
  • Verbose Output: Add -v for detailed logs:
    php artisan cleaner:run -v
    

Configuration Quirks

  • Path Handling: Ensure path in filesystem rules is absolute (e.g., storage_path('logs')).
  • S3 Permissions: Verify AWS credentials and bucket permissions for S3 driver.
  • Database Transactions: Large deletions may hit transaction limits; adjust batch_size or wrap in transactions.

Extension Points

  • Pre/Post Hooks: Bind events in CleanerServiceProvider:
    $this->app->booting(function () {
        event(new \Lamoda\Cleaner\Events\CleaningStarted());
    });
    
  • Custom Validation: Override validateConfig in a custom driver for rule-specific checks.

Pitfalls

  • Archived Package: No updates since 2021; fork or maintain locally if critical.
  • No Soft Deletes: Driver deletes permanently; ensure backups exist.
  • Performance: Avoid running on large datasets without testing. Monitor with --dry-run first.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
aimeos/prisma
besmartand-pro/php-quality-config
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views