Skip to content
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

Update LdapSync.php #15911

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Update LdapSync.php #15911

wants to merge 1 commit into from

Conversation

Fiala06
Copy link

@Fiala06 Fiala06 commented Dec 2, 2024

My first pull request. Hope I'm doing this correctly.

Fix for duplicate entries preventing the sync from continuing.

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '13178-6' for key 'PRIMARY' (Connection: mysql, SQL: insert into users_groups (group_id, user_id) values (6, 13178))

Description

Was getting a duplicate error which would prevent the sync from completing.

The command I'm using is

LDAP_BASE_DN=OU="_Student Accounts,OU=_District-Delegated,DC=xxx,DC=xxx,DC=xxx,DC=xxx" php artisan snipeit:ldap-sync --verbose

The output:

Illuminate\Database\UniqueConstraintViolationException

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '13178-6' for key 'PRIMARY' (Connection: mysql, SQL: insert into users_groups (group_id, user_id) values (6, 13178))

at vendor/laravel/framework/src/Illuminate/Database/Connection.php:824
820▕ // message to include the bindings with SQL, which will make this exception a
821▕ // lot more helpful to the developer instead of just the database's errors.
822▕ catch (Exception $e) {
823▕ if ($this->isUniqueConstraintError($e)) {
➜ 824▕ throw new UniqueConstraintViolationException(
825▕ $this->getName(), $query, $this->prepareBindings($bindings), $e
826▕ );
827▕ }
828▕

1 vendor/laravel/framework/src/Illuminate/Database/MySqlConnection.php:45
PDOException::("SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '13178-6' for key 'PRIMARY'")

2 vendor/laravel/framework/src/Illuminate/Database/MySqlConnection.php:45
PDOStatement::execute()

3 vendor/laravel/framework/src/Illuminate/Database/Connection.php:816
Illuminate\Database\MySqlConnection::Illuminate\Database{closure}()

4 vendor/laravel/framework/src/Illuminate/Database/Connection.php:783
Illuminate\Database\Connection::runQueryCallback()

5 vendor/laravel/framework/src/Illuminate/Database/MySqlConnection.php:50
Illuminate\Database\Connection::run()

6 vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:3500
Illuminate\Database\MySqlConnection::insert()

7 vendor/laravel/framework/src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php:277
Illuminate\Database\Query\Builder::insert()

8 app/Console/Commands/LdapSync.php:427
Illuminate\Database\Eloquent\Relations\BelongsToMany::attach()

9 vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:36
App\Console\Commands\LdapSync::handle()

10 vendor/laravel/framework/src/Illuminate/Container/Util.php:41
Illuminate\Container\BoundMethod::Illuminate\Container{closure}()

11 vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:93
Illuminate\Container\Util::unwrapIfClosure()

12 vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:37
Illuminate\Container\BoundMethod::callBoundMethod()

13 vendor/laravel/framework/src/Illuminate/Container/Container.php:662
Illuminate\Container\BoundMethod::call()

14 vendor/laravel/framework/src/Illuminate/Console/Command.php:211
Illuminate\Container\Container::call()

15 vendor/symfony/console/Command/Command.php:326
Illuminate\Console\Command::execute()

16 vendor/laravel/framework/src/Illuminate/Console/Command.php:181
Symfony\Component\Console\Command\Command::run()

17 vendor/symfony/console/Application.php:1096
Illuminate\Console\Command::run()

18 vendor/symfony/console/Application.php:324
Symfony\Component\Console\Application::doRunCommand()

19 vendor/symfony/console/Application.php:175
Symfony\Component\Console\Application::doRun()

20 vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:201
Symfony\Component\Console\Application::run()

21 artisan:35
Illuminate\Foundation\Console\Kernel::handle()

Fixes # (issue)

Type of change

Please delete options that are not relevant.

How Has This Been Tested?

  • Test A - Added to my own local code and was able to successfully run a full ldap sync. Before it would stop with an error and and users after that wouldn't be synced over.

Test Configuration:

  • PHP version: 8.1.2-1
  • MySQL version: 10.6.18-MariaDB-0ubuntu0.22.04.1
  • Webserver version
  • OS version: Ubuntu 22.04

Checklist:

Fix for duplicate entries preventing the sync from continuing. 

  SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '13178-6' for key 'PRIMARY' (Connection: mysql, SQL: insert into users_groups (group_id, user_id) values (6, 13178))
@Fiala06 Fiala06 requested a review from snipe as a code owner December 2, 2024 19:25
Copy link

welcome bot commented Dec 2, 2024

💖 Thanks for this pull request! 💖

We use semantic commit messages to streamline the release process and easily generate changelogs between versions. Before your pull request can be merged, you should update your pull request title to start with a semantic prefix if it doesn't have one already.

Examples of commit messages with semantic prefixes:

  • Fixed #<issue number>: don't overwrite prevent_default if default wasn't prevented
  • Added #<issue number>: add checkout functionality to assets
  • Improved Asset Checkout: use new notification method for checkout

Things that will help get your PR across the finish line:

  • Document any user-facing changes you've made.
  • Include tests when adding/changing behavior.
  • Include screenshots and animated GIFs whenever possible.

We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.

Copy link

what-the-diff bot commented Dec 2, 2024

PR Summary

  • Improved User Verification
    A new check has been introduced to ensure a user isn't unnecessarily added multiple times to the default group in the Lightweight Directory Access Protocol (LDAP), preventing potential confusion and system clutter.

  • Updated Asset Allocation
    When a user is created or updated, their associated assets' locations are now altered based on the user's current location leading to better accuracy and user-experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant