Scripting user attribute updates

Permalink
Goodevening,

I've been spending the last 6 hours on trying to write an userattribute update script. By now, I am lost. Can anyone give me some edits or points in the right direction?

Fullcode of the singlepage;
<?php
$row = 1;
$uid = 1063;
$handle = fopen("gebruikers.csv", "r");
while (($data2 = fgetcsv($handle, 0, ";")) !== FALSE) {
$row++;
$ui = UserInfo::getByID($uid);      
$data = array(
    'uName' => '$data2[0]',
   'uPassword' => '$data2[5]',
   'uEmail' => '6');
$ui->update($data);
$ui->setAttribute('Persnr', $data2[1],
    'Afdeling', $data2[2]);
$uid++;

RobertJNL
 
ScottC replied on at Permalink Reply
ScottC
and you need to find the applicable format for the attribute you are trying to update. I know it is a bit of a bear right now and I am still wrapping my head around it, but if you search through enough of the new code you should be able to figure it out :)
okhayat replied on at Permalink Reply
okhayat
It is always helpful to explain what you're trying to do, what errors are you getting and provide the data input you're passing.
Anyway, I assume you have a file with values like:
test1;user test 1;user test 1 profile data;3;4;password;test1@localhost.com
test2;user test 2;user test 2 profile data;3;4;password;test2@localhost.com
test3;user test 3;user test 3 profile data;3;4;password;test3@localhost.com
test4;user test 4;user test 4 profile data;3;4;password;test4@localhost.com
test5;user test 5;user test 5 profile data;3;4;password;test5@localhost.com
test6;user test 6;user test 6 profile data;3;4;password;test6@localhost.com

3;4 values are just place holders since I didn't know what values you could have.
You want to update the user's attributes Persnr and Afdeling, which again I assume you added to User attributes.
First, in your code, you're enclosing the $data2[] values for username, password, and email with a single quote, which shouldn't be.
Then using '6' for the email, which should be $data2[6].
And finally, using a single line of $ui->setAttribute to update multiple attributes, which should be two as I could figure out.
<?php
$uid = 1063;
$handle = fopen("gebruikers.csv", "r");
while (($data2 = fgetcsv($handle, 0, ";")) !== FALSE) {
  $ui = UserInfo::getByID($uid);
  if ($ui instanceof UserInfo) { // if user is found
    $data = array(
      'uName' => $data2[0],
      'uPassword' => $data2[5],
      'uEmail' => $data2[6]);
    $ui->update($data);
    $ui->setAttribute('Persnr', $data2[1]);
    $ui->setAttribute('Afdeling', $data2[2]);
    echo "User# $uid updated.<br/>";
  } else {

Also, since you have the usernames added already, why not use the getByUserName method instead?

Hope this helps.
RobertJNL replied on at Permalink Reply
RobertJNL
Hi guys,

thank you for your replies on this situation. The attribute data update now works!
The basic user information does not work yet.

Part of the script for updating userdata;
<?php 
$email = "enter" .$uid. "@youremail.nl";
$ui = UserInfo::getByID($uid); 
if ($ui instanceof UserInfo) {
$data = array(
'uName' => $data2[0],
'uPassword' => $data2[5],
'uEmail' => $email);
$ui->update($data);
}?>


Echo of data before $ui->update($data);
Uid: 1063
$data[uName]: 2933
$data[uPassword]: 11-1-1969
$data[uEmail]: enter1063@youremail.nl

When I check the database; none of the above info is added.
Is there someway I can see error feedback on my page? Can anyone see why this does not work?

Thanks again for the help so far.

Robert
RobertJNL replied on at Permalink Reply
RobertJNL
While looking in the function update @ Concrete\model\userinfo.php I notice that the update function checks for uPassword && uPasswordConfirm.

By adding uPasswordConfirm to my $data array all fields get updated accordingly.

Thanks for your help in solving this :) I will now have 350 happy users and finally some hours to my weekend left :) Thanks!

Robert