Setting user attributes using a tools file in 5.7.
I'm building a new version (using 18.104.22.168) of an existing site, which current version is using 22.214.171.124 and has about 300 users. I migrated users successfully by exporting and importing the Users table via phpMyAdmin and modifying the data order to match 5.7. Now I'm trying to get the user attributes migrated, too, so that the users would have as smooth transition as possible.
I export/imported the UserSearchIndexAttributes table to the new site so that I got the attribute values there and now I need to get those attributes set correctly (i.e. into AttributeKeys, -Types and -Values tables)... My idea is to create a file into tools directory so that by running it I would loop through all users, take the needed attribute's value from the UserSearchIndexAttributes table and use UserInfo setAttribute() function to add it. I've managed to print the UserInfo object of the selected user and also the value queried from db, but the $ui->setAttribute('my_handle','value-from-db') returns error "Call to a member function setAttribute() on a non-object" even though I could successfully print_r($ui) one line before? Here's my code for the tools file (with hard-coded uID to test with so no looping through users yet):
namespace Concrete\Core\User; use Loader; $db = Loader::db(); $q = $db->Execute('SELECT ak_subscribe_bu FROM UserSearchIndexAttributes WHERE uID = 11'); $row = $q->fetchRow(); echo VALUE: '.$row['ak_subscribe_bu'].'<br>'; $ui = UserInfo::getByID(11); print_r($ui); $ui->setAttribute('ak_subscribe_bu', $row['ak_subscribe_bu']); exit;
So both the echo and print_r give expected results so $ui isn't non-object at least to my understanding... Any ideas why the setAttribute doesn't work? Or do you have other ideas how I could achieve this? I don't yet understand the 5.7. system much at all so maybe I'm trying this in a totally wrong way.. Site cache is off btw.
Any help appreciated,
I am afraid I don't know of a solution to your problem.
I am commenting because I think others will be interested in your experience with migrating a site with a large number of users.
There will be an add-on online this week or at the beginning of the next week for exactly that purpose.
Could you post here the link to the addon once it's published?
Sure I will post the link as soon as it's online.