We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16444
    • 6 Posts
    Hello,

    until now I thought that using "publishedon" is safer than to rely on "pub_date", because it always has a value, i.e. for ordering documents in a list. But in the following case (MODx 1.0.5, but it seems to be also in Revo) this value seems to be incorrect:

    Let’s say the current date: 2011-03-03.
    I create a new document and publish it. So "pub_date" and "publishedon" are set to 2011-03-03. That’s okay.
    Now I think this document should have been published yesterday. So I edit the document, set "pub_date" to 2011-03-02 and save.
    Unfortunately "publishedon" doesn’t change. It is still set to 2011-03-03.

    If I unpublish the document first, then save, then edit and set "pub_date" in the past, then save, "publishedon" will be set to the current time.

    In "manager/processors/save_content_processor.php" on line 463 the script (that’s the save-edit-part) doesn’t bother about "pub_date" being in the past. It always sets "publishedon" to the current time or rather to the value it had before. In the save-new-part on line 296 it’s the same...
    if (!$was_published && $published) {
    	$publishedon = time();
    	$publishedby = $modx->getLoginUserID();
    }
    elseif ($was_published && !$published) {
    	$publishedon = 0;
    	$publishedby = 0;
    } else {
    	$publishedon = 'publishedon';
    	$publishedby = 'publishedby';
    }
    

    I thought it should be
    if (!$was_published && $published) {
    	$publishedon = ($pub_date < time() && $pub_date != 0) ? $pub_date : time();
    	$publishedby = $modx->getLoginUserID();
    }
    elseif ($was_published && !$published) {
    	$publishedon = 0;
    	$publishedby = 0;
    } else {
    	$publishedon = ($pub_date < time() && $pub_date != 0) ? $pub_date : 'publishedon';
    	$publishedby = 'publishedby';
    }
    

    I thought, that if I set "pub_date" in the past "publishedon" will be in the past too.
    Am I thinking in the wrong direction?
      • 16444
      • 6 Posts
      Doesn't anyone have an option on that topic?

      Today I ran into that problem again:
      I have a list of documents sorted by publishedon:
      - Doc #3 (publishedon: 2011-09-15)
      - Doc #2 (publishedon: 2011-08-15)
      - Doc #1 (publishedon: 2011-07-15)

      I unpublished the oldest document, so the list is now:
      - Doc #3 (publishedon: 2011-09-15)
      - Doc #2 (publishedon: 2011-08-15)

      Now I want the unpublished document to be back in the list as the oldest document. So I edited this document and set its publish-date to 2011-07-15. I thought the list should now look like this again:
      - Doc #3 (publishedon: 2011-09-15)
      - Doc #2 (publishedon: 2011-08-15)
      - Doc #1 (publishedon: 2011-07-15)

      but instead it looks like this:
      - Doc #1 (publishedon: 2011-09-27)
      - Doc #3 (publishedon: 2011-09-15)
      - Doc #2 (publishedon: 2011-08-15)

      What am I doing wrong?
        • 3749
        • 24,544 Posts
        I think you may be confused about the purpose of pub_date and publishedon. The pub_date field is only for setting future publication dates when you want the resource to be auto-published. Once the document is published, it has no meaning.

        The publishedon field, OTOH, is set whenever the resource changes from unpublished to published -- however that happens -- as a record of when the resource was published. Once set, it doesn't change unless the resource is unpublished and republished (or you you change it manually).
          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
          • 16444
          • 6 Posts
          Thanks for your answer!
          I read the post about this topic a few days ago on your blog, but still I'm unsatisfied.
          I usually make lists of documents with
          $modx->getActiveChildren(123,'publishedon','DESC','id,pagetitle');
          So I get a list that is already sorted. This doesn't work for my problem above.
          But if I sort the list on "pub_date", it doesn't work for documents which haven't got a pub_date set. They appear at the bottom with the date 1970-01-01.

          Well, is there a better way than to get the documents and sort them manually afterwards?
          $docs = $modx->getActiveChildren(123,'menuindex','ASC','id,pagetitle,pub_date,publishedon');
          foreach($docs as $doc) {
            if($doc['pub_date'] > 0) {
              $newDocs[$doc['pub_date']] = $doc;
            } else {
              $newDocs[$doc['publishedon']] = $doc;
            }
          }
          krsort($newDocs);
          

          It would be much easier to have a field that would be set to the pub_date if it exists or publishedon otherwise. Then I would have a well sorted array of documents with just 1 line instead of 9...