A free open source IT asset/license management system
Artisan command to check in licenses from all users
snipee0f6f9b83972
diff --git a/app/Console/Commands/CheckinLicensesFromAllUsers.php b/app/Console/Commands/CheckinLicensesFromAllUsers.phpnew file mode 100644index 0000000000..fac3a92afa--- /dev/null+++ b/app/Console/Commands/CheckinLicensesFromAllUsers.php@@ -0,0 +1,94 @@+<?php++namespace App\Console\Commands;++use App\Models\LicenseSeat;+use Illuminate\Console\Command;+use App\Models\User;+use App\Models\License;+use Illuminate\Database\Eloquent\Model;++class CheckinLicensesFromAllUsers extends Command+{+ /**+ * The name and signature of the console command.+ *+ * @var string+ */+ protected $signature = 'snipeit:checkin-from-all {--license_id=} {--notify}';++ /**+ * The console command description.+ *+ * @var string+ */+ protected $description = 'Checks in licenses from all users';++ /**+ * Create a new command instance.+ *+ * @return void+ */+ public function __construct()+ {+ parent::__construct();+ }++ /**+ * Execute the console command.+ *+ * @return mixed+ */+ public function handle()+ {++ $license_id = $this->option('license_id');+ $notify = $this->option('notify');++ if (!$license_id) {+ $this->error('ERROR: License ID is required.');+ return false;+ }+++ if (!$license = License::where('id','=',$license_id)->first()) {+ $this->error('Invalid license ID');+ return false;+ }++ $this->info('Checking in ALL seats for '.$license->name);+++ $licenseSeats = LicenseSeat::where('license_id', '=', $license_id)+ ->whereNotNull('assigned_to')+ ->with('user')+ ->get();++ $this->info(' There are ' .$licenseSeats->count(). ' seats checked out: ');++ if (!$notify) {+ $this->info('No mail will be sent.');+ }++ foreach ($licenseSeats as $seat) {+ $this->info($seat->user->username .' has a license seat for '.$license->name);++ if (!$notify) {+ $seat->user->email = null;+ }++ $seat->assigned_to = null;++ if ($seat->save()) {+ // Log the checkin+ $seat->logCheckin($license, 'Checked in via cli tool');+ }+++++ }+++ }+}