-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
174 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Aerni\Zipper\Commands; | ||
|
||
use Aerni\Zipper\Jobs\CleanReferenceFilesJob; | ||
use Illuminate\Console\Command; | ||
use Statamic\Console\RunsInPlease; | ||
|
||
class CleanReferenceFilesCommand extends Command | ||
{ | ||
use RunsInPlease; | ||
|
||
protected $signature = 'zipper:clean {--scope=expired}'; | ||
|
||
protected $description = 'Delete old zipper reference files'; | ||
|
||
public function handle() | ||
{ | ||
CleanReferenceFilesJob::dispatch($this->option('scope')); | ||
|
||
$this->info('Successfully dispatched the cleanup job.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Aerni\Zipper\Jobs; | ||
|
||
use Aerni\Zipper\Facades\ZipperStore; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class CleanReferenceFilesJob | ||
{ | ||
use Dispatchable; | ||
use InteractsWithQueue; | ||
use Queueable; | ||
use SerializesModels; | ||
|
||
public function __construct(protected string $scope = 'expired') | ||
{ | ||
// | ||
} | ||
|
||
public function handle(): void | ||
{ | ||
$zips = ZipperStore::all(); | ||
|
||
$zips = match (true) { | ||
($this->scope === 'expired') => $zips->filter(fn ($zip) => $zip->expired()), // Only delete expired reference files | ||
($this->scope === 'all') => $zips->filter(fn ($zip) => $zip->expired() || empty($zip->expiry())), // Delete all reference files excluding unexpired files | ||
($this->scope === 'force') => $zips, // Delete all reference files including unexpired files | ||
default => throw new \Exception('Please provide a valid cleanup scope.') | ||
}; | ||
|
||
$zips->each(fn ($zip) => $zip->deleteReferenceFile()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters