-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Checkin license from all users cli tool #8327
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f1a6308
Check for Auth::user before trying to log id (for cli)
snipe e0f6f9b
Artisan command to check in licenses from all users
snipe 0291323
Use the user as the target
snipe 134e8e6
Moved user email nulling until after the save
snipe 29f3a5c
Use more verbose annotation for Auth::user if/else
snipe 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 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,95 @@ | ||
<?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); | ||
$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'); | ||
} | ||
|
||
|
||
|
||
|
||
} | ||
|
||
|
||
} | ||
} |
This file contains 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
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.
Excellent! This seems a little bit safer.