We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6720
    • 6 Posts
    I can’t get newspublisher to store the CreatedBy field when creating a document. I thought at first it was ditto not pulling the uname back but it definately is newspublisher. I’ve read various issues around this but no thread comes to a simple sensible conclusion.

    I’ve tried logging in as manager users and web users and neither type cause the document to be created with a createdby.

    I set everything up for blogging as per the basic blog for modx sitehttp://wiki.modxcms.com/index.php/Basic_Blog

    If I comment on a blog Jot manages to record the uname.

    Does anyone have any ideas of what I could try?
      • 3749
      • 24,544 Posts
      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:

      'createdby'     => $userid ,

      (don’t forget the final comma)

      Note that createdby holds the ID of the user, not the username.



        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 6720
        • 6 Posts
        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?
          • 3749
          • 24,544 Posts
          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.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 6720
            • 6 Posts
            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.
              • 3749
              • 24,544 Posts
              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.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 6720
                • 6 Posts
                ok I logged out of any manager user, cleared the cache etc.

                Then I logged in as my webuser and created a document and again when I checked in a manager user the document created was created by a manager user.

                I got that manager user to login to check the id and looked in reports/system info to see the user ids. Both my webuser and the manager user have the same id (id=4). Allthough the webuser has the web icon next to the 4.



                Is my site setup incorrectly?
                  • 3749
                  • 24,544 Posts
                  I’m sure your site is fine. I’m just not giving you very good advice. tongue

                  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.
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 6720
                    • 6 Posts
                    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?
                      • 3749
                      • 24,544 Posts
                      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>
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting