diff --git a/app/Console/Commands/CheckinLicensesFromAllUsers.php b/app/Console/Commands/CheckinLicensesFromAllUsers.php new file mode 100644 index 000000000000..bcd8583eafa4 --- /dev/null +++ b/app/Console/Commands/CheckinLicensesFromAllUsers.php @@ -0,0 +1,95 @@ +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); + $seat->assigned_to = null; + + if ($seat->save()) { + + // Override the email address so we don't notify on checkin + if (!$notify) { + $seat->user->email = null; + } + + // Log the checkin + $seat->logCheckin($seat->user, 'Checked in via cli tool'); + } + + + + + } + + + } +} diff --git a/app/Models/Loggable.php b/app/Models/Loggable.php index 71a4e298c194..612e4f65cd0c 100644 --- a/app/Models/Loggable.php +++ b/app/Models/Loggable.php @@ -41,8 +41,9 @@ public function logCheckout($note, $target /* What are we checking out to? */) $settings = Setting::getSettings(); $log = new Actionlog; $log = $this->determineLogItemType($log); - if(Auth::user()) + if (Auth::user()) { $log->user_id = Auth::user()->id; + } if (!isset($target)) { throw new \Exception('All checkout logs require a target.'); @@ -144,7 +145,11 @@ public function logCheckin($target, $note) $log->location_id = null; $log->note = $note; - $log->user_id = Auth::user()->id; + + if (Auth::user()) { + $log->user_id = Auth::user()->id; + } + $log->logaction('checkin from'); $params = [