We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27708 MODX Staff
    • 2,502 Posts
    I started a thread and posted a feature request to Jira for the ability to make it possible to convert pub_date to createdon or time()/now() if there was none entered on save.

    It turns out that there is a publishedon field that, unless one was trolling the site tables, would likely not find. I had no idea it exists and there have been a number of threads over the years trying to solve this problem of displaying items in ditto if there was no explicit pubdate in some and one in others.

    My question is this: Is it accurate to say that the publsihedon field in the site_content table would be accessed via $modx->documentObject[’publishedon’] or $content[’publishedon’] and that its behavior is to be populated on saved if no pub_date is set or be populated when the pub_date was reached?

    If this is true, I’d like to add it to the current documentation and prep a tutorial on how to use Ditto with it.

    Cheers,

    Jay 
      Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
      • 4310
      • 2,310 Posts
      and that its behavior is to be populated on saved if no pub_date is set or be populated when the pub_date was reached
      Not sure it is set to enter anything into the DB by default as my column ’publishedon’ is full of the default value ’0’ even though I rarely use the publish/unpublish TV’s
        • 27708 MODX Staff
        • 2,502 Posts
        It sound then like this is a problem we have 2 fields that work together but neither is forced to have a date.

        Maybe my solution posted in Jira is the solution or published on needs to take a now() value if there is no pub_date.

        In either case it seems like a missing element.

        Cheers,

        Jay
          Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
          • 4041
          • 788 Posts
          The following areas are the only ones I could find where I think the issues originate, there have been discussions regarding this since the early days of MODx:
          (code below from 0962 rc2)

          document.parser.class.inc.php
            function checkPublishStatus() {
             if publishing
            line 529 - SET published=1, publishedon=".time()."
             if unpublishing
            line 535 -  SET published=0, publishedon=0
            
            }
            
            
          save_content.processor.php
          
            line 262 - $publishedon = ($published ? time() : 0);
            
            line 415 - // Set publishedon and publishedby
                          $was_published = $modx->db->getValue("SELECT published FROM $tbl_site_content WHERE id='$id'");
          
                          // Keep original publish state, if change is not permitted
                          if (!$modx->hasPermission('publish_document')) {
                                  $published = $was_published;
                                  $pub_date = 'pub_date';
                                  $unpub_date = 'unpub_date';
                          }
          
                          // If it was changed from unpublished to published
                          if (!$was_published && $published) {
                                  $publishedon = time();
                                  $publishedby = $modx->getLoginUserID();
                          }
                          elseif ($was_published && !$published) {
                                  $publishedon = 0;
                                  $publishedby = 0;
                          } else {
                                  $publishedon = 'publishedon';
                                  $publishedby = 'publishedby';
                          }


          I have no clue as to a fix but at least here is a start point to diagnose it.
            xforum
            http://frsbuilders.net (under construction) forum for evolution
            • 7231
            • 4,205 Posts
            From my testing it seems that publishedon will be set when the document is published and if the document is not published it will be 0. It seemed to be pretty consistent, I tried all sorts of combinations and if published it was always set. Even scheduled docs get a publishedon date set when the doc gets published.
              [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

              Something is happening here, but you don't know what it is.
              Do you, Mr. Jones? - [bob dylan]
              • 27708 MODX Staff
              • 2,502 Posts
              So other than created on there is NEVER a stamp for published documents now. This seems odd. Either publishedon or pub-date should be triggered to have a stamp when documents are published without an explicit pub_date set. This strucure would certainly solve the problem but how is the issue. It seems setting the publishedon to 0 could be replaced with setting it to now()/time() instead.

              I’d be interested to hear from OpenGeek on this and the potential breaks or issues...
                Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
                • 7231
                • 4,205 Posts
                publishedon IS set on publishing:
                line 529 - SET published=1, publishedon=".time()."
                ..
                $publishedon = time();


                I think that it is working as expected, as far as I can tell.
                  [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                  Something is happening here, but you don't know what it is.
                  Do you, Mr. Jones? - [bob dylan]
                  • 3749
                  • 24,544 Posts
                  As far as I can tell, the only documents with publishedon set to 0 are unpublished documents.

                  SmashingRed, do you have a case of a published document with publishedon set to 0 in the db?

                  If so, can you say how to replicate that? Also, is it possible that you set it to 0 in the process of testing it (possibly using = instead of == in an if statement)?
                    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
                    • 7231
                    • 4,205 Posts
                    I think that if you install the demo site there will be some documents with 0 set for publishedon. This may be causing some confusion.
                      [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                      Something is happening here, but you don't know what it is.
                      Do you, Mr. Jones? - [bob dylan]
                      • 3749
                      • 24,544 Posts
                      Quote from: dev_cw at Nov 15, 2008, 03:55 PM

                      I think that if you install the demo site there will be some documents with 0 set for publishedon. This may be causing some confusion.

                      That suggests that it might be possible to create a published document programmatically with publishedon set to 0. That means that if a snippet or plugin creates a new published document, publishedon could fail to be set. I don’t think this is possible in Revolution, but it might be in 0.9.6.
                        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