#StackBounty: #system-installation #users #reinstall Set up users, during install, based on directories in /home

Bounty: 50

Are there any Gnu/Linux installers that will look at an old /home partition, and set up the users based on the directories in the root of this partition?

So if I install a new Gnu/Linux, and keep my old /home, the /home partition will be full of files owned by various users and groups. I also need to set up a load of users, these users need to match the ones from the old system, so that the file in /home have the correct ownership. The root of the /home partition have a directory for each user, that is owned by that user, and their primary group.

Therefore it should be possible to scan this directory, and create a user/primary-group for each directory that is found.

  • Are there any tools that already do this?
  • Are they used in any Gnu/Linux installed?
  • Does Debian do this?

(I am about to install a new Debian.)


Get this bounty!!!

#StackBounty: #7 #users #hooks Modified user record during presave hook not saving properly

Bounty: 50

A project I am working on has a bug where an array field on the user object is getting duplicated values. To fix this bug, I am implementing the hook_user_presave hook in one of our custom modules to strip out any duplicated values in the array before saving. Essentially, here is my code:

function my_module_user_presave(&$edit, $account, $category) {
    watchdog('ARRAY BEFORE MODIFICATION', '<pre>' . print_r($edit['field_some_array'], true) . '</pre>');
    $array_field = $edit['field_some_array']['und'];
    $new_array_field = [];
    for ($i = 0; $i < count($array_field); $i++) {
        $item_exists = false;
        for ($j = 0; $j < count($new_array_field); $j++) {
            if ($array_field[$i]['target_id'] == $new_array_field[$j]['target_id']) {
                $item_exists = true;
            }
        }
        if (!$item_exists) {
            array_push($new_array_field, $array_field[$i]);
        }
    }
    $edit['field_some_array']['und'] = $new_array_field;
    watchdog('ARRAY AFTER MODIFICATION', '<pre>' . print_r($edit['field_some_array'], true) . '</pre>');
}

You notice that there is two watchdogs, and I can confirm that when these are printed out they show the expected results: $edit[field_some_array] has duplicates in the first watchdog log and then does not have duplicates in the second watchdog log.

However, when this actually saves, the duplicate values still exist…

In Drupal’s own documentation it specifically states: $edit: The array of form values submitted by the user. Assign values to this array to save changes in the database. This tells me that whatever is in $edit will be saved to the database, however, this is not the case I am seeing.

Is there another step you have to take for your changes to $edit to actually take place? Is Drupal’s documentation incorrect? Is this just some random bug?

EDIT: The array is an array of Entity References, for what it’s worth


Get this bounty!!!

#StackBounty: #views #users Changing a Profile type Machine Name broke the Admin/People search

Bounty: 50

I’m working on a Drupal 7 website in which there are several Profile types.
As part of a task, I had to change the “Label Name” and the “Machine Name” of one of them: specifically Professional Courses was changed in Professional School.

Later on, I’ve realised that this substitution have broken the search in the Admin/People page. Precisely, if the Administrator, from the Admin/People page, searches the users with the Profile type just mentioned, the search shows no results.

I’ve discovered that the View managing this page (Admin/People), has kept the old Machine Name in the query, which means that role has been cut out.

I’ve tried to fix this error by changing the query using the following code inside a views_pre_execute function in a custom module I’ve developed:

$query = db_select('users', NULL);
$query->condition('users.uid', array('0'), 'NOT IN');
$query->fields('users', array('uid', 'name', 'mail', 'status', 'created', 'access'));
$query->addJoin('INNER', 'profile', NULL, 'users.uid = profile.uid AND (profile.type IN ( 'master_school', 'employee', 'summer_school', 'professional_courses', 'digital_friend', 'phd_school', 'professional_school' ))');
$query->orderBy('users.access', 'DESC');
$query->range(0, 100);

$view->build_info['query'] = $query;

However, this code changes the query inside the View, but didn’t fix the problem.

How can I fix this bug? Should I go back to the old Machine Name?
Thanks!

P.S. I’m using Profile2 and Administration Views modules.


Get this bounty!!!

#StackBounty: #8 #users #forms Custom user login in Facebook Auth modules

Bounty: 50

I try to run Facebook Login on my Drupal 8 site. I run it by Social API module and with Simple FB Connect, but both module generate user name from first and last name on Facebook. My user will not be happy with using real name, but I don’t want to give them options to change username whenever they want.

For code examples I use Simple FB Connect, but the same logic is in Social API modules.

User go to path user/simple-fb-connect and is redirected by Drupalsimple_fb_connectControllerSimpleFbConnectController->redirectToFb(), and when he is back, go to user/simple-fb-connect/return which is handle by Drupalsimple_fb_connectControllerSimpleFbConnectController->returnFromFb().

It checks permissions, get data from FB and then if email not exist in DB, registers user:

[...]
    // If there was no existing user, try to create a new user.
    $fbid = $fb_profile->getField('id');
    $fb_profile_pic = $this->fbManager->getFbProfilePic();
    if ($drupal_user = $this->userManager->createUser($fb_profile->getField('name'), $email, $fbid, $fb_profile_pic)) {
[...]

The main question is: How I can replace $fb_profile->getField('name') with custom, provided by user string ? I think about:

  1. Replace simple link on login with form contains textfield and submit button, which send POST/GET data to user/simple-fb-connect. There store it Session, and use on returnFromFb() function to create user.

But I can’t always show an additional field (eg. on homepage), and I don’t know if user want to register or just login. It kills idea, just click, and get account.

  1. After back from FB, show users one-time form, which they can’t skip, and access page, before they fill it, like post-login registration in normal FB integrations, on which they can fill additional data, but only once per account.

But there I have no idea how to even start. Maybe I can replace function returnFromFb() code creating new user with register form, and after submit create user. Or leave module code in peace and base it on events from the module. But how I can lock page for user who don’t fill this and secure it to be fill just one time (maybe boolean field on user entity?).

  1. The simplest way, just leave it as it is, use display name and hide login, but I don’t want to store user names and last names in database.

Thanks for help!

PS. I tried to ask the creators, but it looks like the modules work like they should work.


Get this bounty!!!