-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Fixed #18409 - command line option to purge signatures #18437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,132 @@ | ||
| <?php | ||
|
|
||
| namespace App\Console\Commands; | ||
|
|
||
| use App\Models\CheckoutAcceptance; | ||
| use Carbon\Carbon; | ||
| use Illuminate\Console\Command; | ||
| use Illuminate\Support\Facades\Storage; | ||
|
|
||
| class PurgeEulaPDFs extends Command | ||
| { | ||
| /** | ||
| * The name and signature of the console command. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $signature = 'snipeit:purge-eula-pdfs | ||
| {--older-than-days= : The number of days we should delete before } | ||
| {--force : Skip the interactive yes/no prompt for confirmation} | ||
| {--dryrun : Show the records that would be deleted but don\'t update the database or delete files from disk} | ||
| {--with-output : Display the results in a table in your console}'; | ||
|
|
||
| /** | ||
| * The console command description. | ||
| * | ||
| * @var string | ||
| */ | ||
| protected $description = 'This purges signature files and EULAs from the system if they are older than the date passed with --older-than-days=.'; | ||
|
|
||
| /** | ||
| * Execute the console command. | ||
| */ | ||
| public function handle() | ||
| { | ||
|
|
||
| $before = $this->option('older-than-days'); | ||
|
|
||
| if (($before=='') || (!is_numeric($before))) { | ||
| return $this->error('ERROR: You must pass a valid number for --older-than-days (example: snipeit:purge-eula-pdfs --older-than-days=365.)'); | ||
| } | ||
|
|
||
| $interval_date = Carbon::now()->subDays($before); | ||
| $signature_path = 'private_uploads/signatures/'; | ||
| $eula_path = 'private_uploads/eula-pdfs/'; | ||
|
|
||
| if (!Storage::exists($eula_path)) { | ||
| $this->fail('The storage directory "'.$eula_path.'" does not exist. No EULA files will be deleted.'); | ||
| } | ||
|
|
||
| if (!Storage::exists($signature_path)) { | ||
| $this->fail('The storage directory "'.$signature_path.'" does not exist. No signature files will be deleted.'); | ||
| } | ||
|
|
||
|
|
||
| if ($this->option('dryrun')) { | ||
| $this->info('This script is being run with the --dryrun option. No files or records will be deleted.'); | ||
|
|
||
| } | ||
| $acceptances = CheckoutAcceptance::HasFiles()->where('updated_at','<', $interval_date)->with('assignedTo')->get(); | ||
|
|
||
| if (!$this->option('force')) { | ||
| if ($this->confirm("\n****************************************************\nTHIS WILL DELETE ALL OF THE SIGNATURES AND EULA PDF FILES SINCE '.$interval_date.'. \nThere is NO undo! \n****************************************************\n\nDo you wish to continue? No backsies! [y|N]")) { | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| if ($acceptances->count() == 0) { | ||
| return $this->warn('There are no item acceptances with signatures or EULA PDFs from before '.$interval_date); | ||
| } | ||
|
|
||
| $this->info(number_format($acceptances->count()) . ' EULA PDFs from before '.$interval_date.' will be purged'); | ||
|
|
||
| if (!$this->option('with-output')) { | ||
| $this->info('Run this command with the --with-output option to see the full list in the console.'); | ||
| } else { | ||
| $this->table( | ||
| [ | ||
| trans('general.user'), | ||
| trans('general.type'), | ||
| trans('general.item'), | ||
| trans('general.category'), | ||
| trans('general.accepted_date'), | ||
| trans('general.declined_date'), | ||
| trans('general.signature'), | ||
| trans('general.filename'), | ||
|
|
||
| ], | ||
| $acceptances->map(fn($acceptance) => [ | ||
| trans('general.user') => $acceptance->assignedTo->display_name, | ||
| trans('general.type') => $acceptance->display_checkoutable_type, | ||
| trans('general.item') => $acceptance->checkoutable_type::find($acceptance->checkoutable_id)->display_name, | ||
| trans('general.category') => $acceptance->checkoutable_category_name, | ||
| trans('general.accepted_date') => $acceptance->accepted_at, | ||
| trans('general.declined_date') => $acceptance->declined_at, | ||
| trans('general.signature') => $acceptance->signature_filename, | ||
| trans('general.filename') => $acceptance->stored_eula_file, | ||
| ]) | ||
| ); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| foreach ($acceptances as $acceptance) { | ||
|
|
||
| $signature_file = $signature_path.$acceptance->signature_filename; | ||
| $eula_file = $eula_path.$acceptance->stored_eula_file; | ||
|
|
||
| if (Storage::exists($signature_file)) { | ||
| if (!$this->option('dryrun')) { | ||
| Storage::delete($signature_file); | ||
| } | ||
| } else { | ||
| $this->error('The file "'. $signature_file.'" does not exist.'); | ||
| } | ||
|
|
||
|
|
||
| if (Storage::exists($eula_file)) { | ||
| if (!$this->option('dryrun')) { | ||
| Storage::delete($eula_file); | ||
| } | ||
| } else { | ||
| $this->error('The file "'.$eula_file.'" does not exist.'); | ||
| } | ||
|
|
||
| if (!$this->option('dryrun')) { | ||
| $acceptance->delete(); | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The output of this line is weird because it's wrapped in
".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handled, ty!