Add a dirtiness check to slim down JSON LDAP sync summaries

This commit is contained in:
Brady Wetherington 2020-10-21 15:13:36 -07:00
parent 338106734a
commit fad0ed6d5b

View file

@ -191,21 +191,27 @@ class LdapSync extends Command
]; ];
// Only update the database if is not a dry run // Only update the database if is not a dry run
if (!$this->dryrun) { if (!$this->dryrun) {
if ($user->save()) { if ($user->isDirty()) { //if nothing on the user changed, don't bother trying to save anything nor put anything in the summary
$summary['note'] = ($user->wasRecentlyCreated ? 'CREATED' : 'UPDATED'); if ($user->save()) {
$summary['status'] = 'SUCCESS'; $summary['note'] = ($user->wasRecentlyCreated ? 'CREATED' : 'UPDATED');
} else { $summary['status'] = 'SUCCESS';
$errors = ''; } else {
foreach ($user->getErrors()->getMessages() as $error) { $errors = '';
$errors .= implode(", ",$error); 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; } else {
$summary['status'] = 'ERROR'; $summary = null;
} }
} }
// $summary['note'] = ($user->getOriginal('username') ? 'UPDATED' : 'CREATED'); // this seems, kinda, like, superfluous, relative to the $summary['note'] thing above, yeah? // $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);
}
} }
/** /**