I think this code (about 3/4 of the way down in the NewPublisher snippet) may be the problem:
'createdby' => ($userid>0 ? $userid * -1:0),
It appears to set createdby for all manager users to 0 and makes web users into manager users. There may be some reason for this, but I don’t know what it is.
Try changing it to this:
(don’t forget the final comma)
Note that createdby holds the ID of the user, not the username.
Thanks for quick response BobRay.
I now have got an interesting feature occuring. I changed the line you mentioned and tried a new blog entry as both a manager user and a web user.
The manager user produced the same result but the webuser recorded a createdby entry. Hurray!
However the user it has used is not the correct username. Its the first user created on the site (a manager user).
So it seems that in using just $userid I get the id of the manager user that corresponds to the id of the webuser.
I tried changing $userid to just $user but that didn’t work at all.
Any thoughts?
Is it possible that you were still logged in to the manager (even in another browser window of the same browser) when you created the pages. I think getLoginUserId() will use the Manager ID in that case.
If you need to be a web user, it’s best to log in with a different browser altogether or explicitly log out of the Manager first.
PS: Change it back to $userid and clear the MODx cache and your browser cache/cookies before checking.
I don’t think so because I’ve been trying to fix this problem now for months (keep coming back to it, then leaving it etc)and every time I’ve been logged in as a manager and its never worked.
Whilst trying different solutions on other threads I have read that its a webuser tool so it sort of makes sense that it somehow works if you log in as a webuser. By the way the manager user it records as is not a user I would log in as because its a user created by the person who set up the site and installed modx. I have my own user and wasn’t logged in.
Having said all that I will try again with your suggestions and see what happens.
Again, thanks for your help.
Quote from: davidgroom at Oct 26, 2009, 01:02 PM
. . .and every time I’ve been logged in as a manager and its never worked.
Right, I’m suggesting that you need to *not* be logged in as a manager.
I’m sure your site is fine. I’m just not giving you very good advice.
Maybe there’s some reason for reversing the sign of the ID.
Try
'createdBy' => $userId * -1,
in the NewsPublisher code.
The only difference between manager and web user IDs is that one is always a negative number.
I tried the multiply by -1 yesterday. Just tried it again and it produces no createdby or at least createdby().
I think my question now is what is system info showing me? What I mean is both manager users in the image davidgroom and karenstride have a postive user id. Should they be negative?
Is there a way to find out what the database table holds?
Yes. If you go to cPanel and use PhpMyAdmin, you should be able to browse the site_content table to see what the createdBy field contains (or edit it). You can look at pages created in the Manager by various manager users to see what the normal settings are.
BTW, you can also just put this code on a page (with the Rich Text settting unchecked to keep the RTE out of the picture) and preview the page. It should match what’s in the DB (exept that 0 will be shown as blank):
<p>Created by: [*createdBy*]</p>