Skip to content

Commit

Permalink
Fix file deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
mantas-done committed Jan 4, 2024
1 parent 4f66a67 commit 2d3b4e4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Console/ApmClearCommand.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Done\LaravelAPM\Console;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Date;

class ApmClearCommand extends Command
{
Expand Down Expand Up @@ -39,9 +40,14 @@ public function handle()
$files = \File::allFiles($path);
foreach ($files as $file) {
$filename = $file->getFilename();
$pattern = '/^(apm-[0-9]{4}-[0-9]{2}-[0-9]{2}\.txt)$/';
$pattern = '/^apm-(?<Y>[0-9]{4})-(?<m>[0-9]{2})-(?<d>[0-9]{2})_[0-9]{2}\.txt$/';
preg_match($pattern, $filename, $matches);
if (!empty($matches) && isset($matches[1])) {
if (!isset($matches['Y'])) {
continue; // if file didn't matched our file regex pattern
}
$date = $matches['Y'] . '-' . $matches['m'] . '-' . $matches['d'];
$diff = Date::parse($date)->diffInDays(null, false);
if ($diff >= 2) {
\File::delete($file);
}
}
Expand Down

0 comments on commit 2d3b4e4

Please sign in to comment.