From fad0ed6d5b0d9e3bfd3579771547c862b1df8635 Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Wed, 21 Oct 2020 15:13:36 -0700 Subject: [PATCH] Add a dirtiness check to slim down JSON LDAP sync summaries --- app/Console/Commands/LdapSync.php | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/app/Console/Commands/LdapSync.php b/app/Console/Commands/LdapSync.php index 89a6208e5f..16f04f16be 100644 --- a/app/Console/Commands/LdapSync.php +++ b/app/Console/Commands/LdapSync.php @@ -191,21 +191,27 @@ class LdapSync extends Command ]; // Only update the database if is not a dry run if (!$this->dryrun) { - if ($user->save()) { - $summary['note'] = ($user->wasRecentlyCreated ? 'CREATED' : 'UPDATED'); - $summary['status'] = 'SUCCESS'; - } else { - $errors = ''; - foreach ($user->getErrors()->getMessages() as $error) { - $errors .= implode(", ",$error); + if ($user->isDirty()) { //if nothing on the user changed, don't bother trying to save anything nor put anything in the summary + if ($user->save()) { + $summary['note'] = ($user->wasRecentlyCreated ? 'CREATED' : 'UPDATED'); + $summary['status'] = 'SUCCESS'; + } else { + $errors = ''; + foreach ($user->getErrors()->getMessages() as $error) { + $errors .= implode(", ",$error); + } + $summary['note'] = $snipeUser->getDN().' was not imported. REASON: '.$errors; + $summary['status'] = 'ERROR'; } - $summary['note'] = $snipeUser->getDN().' was not imported. REASON: '.$errors; - $summary['status'] = 'ERROR'; + } else { + $summary = null; } } // $summary['note'] = ($user->getOriginal('username') ? 'UPDATED' : 'CREATED'); // this seems, kinda, like, superfluous, relative to the $summary['note'] thing above, yeah? - $this->summary->push($summary); + if($summary) { //if the $user wasn't dirty, $summary was set to null so that we will skip the following push() + $this->summary->push($summary); + } } /**