Skip to content

Commit

Permalink
Add Gc command to delete old images, Clear command to delete all images
Browse files Browse the repository at this point in the history
  • Loading branch information
Bradie Tilley committed Jan 30, 2020
1 parent c187f9c commit 0ea3bb5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
4 changes: 3 additions & 1 deletion Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use System\Classes\PluginBase;
use ABWebDevelopers\ImageResize\Classes\Resizer;
use ABWebDevelopers\ImageResize\Commands\ImageResizeClear;
use ABWebDevelopers\ImageResize\Commands\ImageResizeGc;
use Event;

class Plugin extends PluginBase
Expand Down Expand Up @@ -94,6 +95,7 @@ public function boot()
*/
public function register()
{
$this->registerConsoleCommand('imageresize:gc', ImageResizeGc::class);
$this->registerConsoleCommand('imageresize:clear', ImageResizeClear::class);
}

Expand All @@ -102,6 +104,6 @@ public function register()
*/
public function registerSchedule($schedule)
{
$schedule->command('imageresize:clear')->daily();
$schedule->command('imageresize:gc')->daily();
}
}
8 changes: 2 additions & 6 deletions commands/ImageResizeClear.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,18 @@
namespace ABWebDevelopers\ImageResize\Commands;

use ABWebDevelopers\ImageResize\Classes\Resizer;
use ABWebDevelopers\ImageResize\Models\Settings;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Str;

class ImageResizeClear extends Command
{
protected $name = 'imageresize:clear';

protected $description = 'Clear all resized images';
protected $description = 'Clear all resized images.';

public function handle()
{
$minAge = Carbon::now()->modify('-' . Settings::getAgeToDelete());

$deleted = Resizer::clearFiles($minAge);
$deleted = Resizer::clearFiles();

$this->info('Successfully deleted ' . $deleted . ' ' . Str::plural('file', $deleted));
}
Expand Down
25 changes: 25 additions & 0 deletions commands/ImageResizeGc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace ABWebDevelopers\ImageResize\Commands;

use ABWebDevelopers\ImageResize\Classes\Resizer;
use ABWebDevelopers\ImageResize\Models\Settings;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Str;

class ImageResizeGc extends Command
{
protected $name = 'imageresize:gc';

protected $description = 'Garbage collect all old resized images.';

public function handle()
{
$minAge = Carbon::now()->modify('-' . Settings::getAgeToDelete());

$deleted = Resizer::clearFiles($minAge);

$this->info('Successfully deleted ' . $deleted . ' ' . Str::plural('file', $deleted));
}
}

0 comments on commit 0ea3bb5

Please sign in to comment.