Forums

Resolved
0 votes
Hi

Is there anyway to get Account import to modify existing users?
Friday, November 13 2015, 09:47 AM
Share this post:
Responses (4)
  • Accepted Answer

    Friday, November 13 2015, 02:28 PM - #Permalink
    Resolved
    0 votes
    Hi Duncan,

    Looking at the import script, if a user exists, we do catch that exception (and report it in the status table), and then set group memberships, but nothing else...so, to answer your question...in the current version, only group membership are updated.

    What info are you looking to update? It looks quite trivial to add support for updating...Here's some code from the account-import script located in /usr/sbin/

    try {
    $user->add($user_info, $password);
    } catch (Validation_Exception $e) {
    // TODO - Should be using User_Already_Exists_Exception but that is not the obj thrown
    // in the User_Driver
    $msg = preg_replace("/\\.$/", "", clearos_exception_message($e));
    $user_no++;
    update_status(1, $user_no / $total * 100, $msg . ' (' . $user_info['core']['username'] . ')');
    continue;
    } catch (Group_Not_Found_Exception $e) {
    update_status(0, $user_no / $total * 100, $msg . '...');
    // Not fatal...just means some plugins were not installed
    $msg = preg_replace("/\\.$/", "", clearos_exception_message($e));
    update_status(1, $user_no / $total * 100, $msg);
    }


    As you can see from the 'TODO', it looks like we wanted to provide update, but something upstream wasn't letting us do it cleanly. Theoretically, all that's needed to support update is this modification, placed just above the "TODO" tag:

    $user->update($user_info);


    Anyone have cycles to test? Perhaps in v7, we may even be throwing the User_Already_Exists_Exception and this could be handled very cleanly without scraping the error message.

    B.
    The reply is currently minimized Show
  • Accepted Answer

    Friday, November 13 2015, 02:47 PM - #Permalink
    Resolved
    0 votes
    Hi Ben

    Thanks for the reply.

    What I was looking to do was change all users in one group to another. So if group updates work on existing users then that is great (is this behaviour only in 7.x or also in 6.6?)

    Thinking about it however I could also use it to do multiple password resets and plugin changes.

    Rgds


    Duncan
    The reply is currently minimized Show
  • Accepted Answer

    Friday, November 13 2015, 03:00 PM - #Permalink
    Resolved
    0 votes
    Everything I stated is applicable to v6 and v7.

    B
    The reply is currently minimized Show
  • Accepted Answer

    Friday, November 13 2015, 03:51 PM - #Permalink
    Resolved
    0 votes
    Hi Ben

    I have just a test, by importing an existing user but changing the group. But the user remained unchanged.

    Form3 is the users current group and grad20 is a new group I wish to add the user to.

    I tried with and without the existing users group.

    After import user (testuser) still only belonged to form3.

    An I missing something?

    Thanks
    The reply is currently minimized Show
Your Reply