I exported user data from one CWIS site to another.
Exported and imported the APUsers and APUserPrivileges tables. The receiving site only had one user, so I only had to modify the data in the export for one user and one set of privileges to avoid clashes.
The new users appear on the /index.php?P=UserList page, but if I click Edit on any user but the pre-existing one, I get
No user was found.
Please return to the user editing page and re-enter the user name.
What am I missing?
Not all of the user information is stored in APUsers and APUserPrivileges. There is also additional information in the Resources table. At the least, CWIS exepcts a Resource object to exist corresponding to each user.
The simplest thing to do might be a little script, run from the command line with '
php myscript.php
' that gets all the UserIds out of APUsers and tries to get aCWUser
object for each of them (withnew CWUser($UserId)
). If the resulting object hasStatus()
of U_NOSUCHUSER, then do$Resource = Resource::Create(MetadataSchema::SCHEMAID_USER);
$Resource->Set("UserId", $TargetUserId);
I *think* that should take care of it.
Note, though, that this will lose any information you have stored in custom fields in the User schema.
I'm getting a user object, but not sure how to get status.
$myUser = new CWUser($UserId);
$myUser->Status() is what you're after.
Ah, thanks!
Well, it didn't fail or log any errors. But it also didn't appear to work.
Still getting (upon clicking edit buttion):
No user was found.
Please return to the user editing page and re-enter the user name.
Is there a "right" way to import users?
The supported way to import/export users is to use "Export User Accounts" and "Import User Accounts" on the "System Administration Page" (left-hand column under "User Administration").
Unfortunately, there was actually a bug in the Import code in CWIS 3.2.0. I've attached a fixed version of ImportUsersExecute.php which can replace the version currently in 'pages'.
Note, though, that this code checks the APUsers table before adding a user, so your previous DB manipulation will foil the import.
Also, looking at the code you've pasted above, I think the problem is that you mixed $TargetUserId and $UserId (I realize I did this in my hand-wavy explanation of how to fix the problem; I should have been more consistent). If you query your Resource table for the SchemaId=1 (the User schema), I'd wager that you'll find a number of resources with a NULL UserId1, indicating that they aren't actually associated with a user.
Your best bet is probably to clean up the database and use the official Import/Export mechanism if you can.
I was able to fix this by deleting user resource records that had negative ids. The users appear to work now.
I have the same problem with a CWIS site where I imported users exported from another CWIS site (both on 3.2.0). I tried replacing the ImportUsersExecute.php file with the one attached in this thread before doing the import, but it still didn't create users with matching Resource records, so that bug isn't fixed. Can you provide the little CLI PHP script that I can run to fix my installation? Or at least tell me what files I need to include before the code fragment above to make those objects available? Thanks!
Is it possible that you imported, updated pages/ImportUsersExecute, then re-imported? If so, then the first import created entries in the APUsers table that would prevent the second import from creating the corresponding Resources.
The attached script can be run inside your CWIS root with
php fix_user_resource.php
to create Resources for any entries in the APUsers table that lack them.<p>I believe that I started with a completely clean install, but it was so long ago now that I can't be certain. There was no attachment to your previous message, can you repost it? Thanks!</p>
Sorry about that... when I uploaded the attachment, I neglected to mark it as visible.