diff --git a/app/Console/Commands/CheckinLicensesFromAllUsers.php b/app/Console/Commands/CheckinLicensesFromAllUsers.php new file mode 100644 index 000000000000..fac3a92afaaa --- /dev/null +++ b/app/Console/Commands/CheckinLicensesFromAllUsers.php @@ -0,0 +1,94 @@ +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'); + } + + + + + } + + + } +}