Map old LDAP users to new on server change

I don’t know if this is safe or not, but I did the following to get this working without issue (apparently). Note that my install is small and at home so I just logged in with the duplicate accounts to get the appropriate ldap_dn/directory_uuid/ldap_dn/ldap_dn_hash values, but you could get these yourself from the new LDAP server to script this out (hash is S256). Credit to: LDAP Migration with different DN - :information_source: Support - Nextcloud community. Users in the old and new LDAP server have the same username/uid/sAMAccountName/etc.

If the users on the new LDAP server have logged in, they will have accounts created in the oc_ldap_user_mapping table. We need to replace some values in the direcotry_uuid and ldap_dn_hash fields as they have UNIQUE KEY constraints - this step isn’t required if the users have not logged in from the new server:

UPDATE oc_ldap_user_mapping SET directory_uuid = 'TEMP_<new ldap server directory_uuid>', ldap_dn_hash = '_<new ldap server ldap_dn_hash (remove first charater due to field length constraint)>' WHERE owncloud_name = 'erin_<random int for new directory user>';

We can then populate the entries for the old LDAP server with the new server details:

UPDATE oc_ldap_user_mapping SET ldap_dn = '<new ldap server dn>', directory_uuid = '<new ldap server directory_uuid>', ldap_dn_hash = '<new ldap server ldap_dn_hash>' WHERE owncloud_name = '<username>';