We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33372
    • 1,611 Posts
    This may be a bug, and if so I guess I should report it to the tracker. But it also might just be something that I’ve done wrong that is causing this. So if anyone has a clue as to why this might happen, please let me know.

    I have a site (in Spanish, although I imagine that’s irrelevant) with several templates and template variables that go with them. One is "Normal" and another is "Proposal". The proposal template has an associated checkbox Template Variable for indicating what type(s) of proposal each is (for sorting).

    Whenever I change a page from the Normal template to the Proposal template, the publish date is replaced with a seemingly-random low number. Since these are all very low for date, they all show up as December 31st, 1969 (and a few seconds) in the Manager and on the site. The numbers in the databsae don’t seem to be related to anything as far as I can see (i.e., they don’t seem to be the contents of some other field).

    This change seems to happen in the manager form itself (the pub_date value is replaced with something like "31-12-1969 19:00:15" after switching templates and before saving the document).

    I’ve never seen this happen before, and I use a lot of different templates and TVs on a bunch of MODx sites...

    THANKS in advance for your ideas and suggestions (I’m off to cut and paste from a mySQL backup).

    UPDATE: OK after cutting and pasting 100 or so dates from the backup to phpMyAdmin, I see that there is a pattern. The mySQL date is being replaced by the day number (1-31) in almost all circumstances. So perhaps this is a bug related to the fact that I’m using different regional options in order to show the dates in Spanish?

    Also: i noticed that about 90% of these also had the publishedon and publishedby fields reversed (time data where the user id should be and vice versa). Now that just seems like a bug to me. Has it been tracked?
      "Things are not what they appear to be; nor are they otherwise." - Buddha

      "Well, gee, Buddha - that wasn't very helpful..." - ZAP

      Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
      • 33372
      • 1,611 Posts
      Hmm...

      It just happened again. This time on another site that’s not in Spanish and has very little going on in the way of Template Variables. So maybe this is a bug.

      Am I the only one who’s seen this happen?
        "Things are not what they appear to be; nor are they otherwise." - Buddha

        "Well, gee, Buddha - that wasn't very helpful..." - ZAP

        Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        I just ran the test on my stock 0.9.2.1 install, and indeed it does do this evil thing. I will check on the 9.9.5 test install.

        Ooh, yes, still does it. Will investigate.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Ok, I think I see where the problem lies. I’ll post this in the bugtracker with my observations; I may be able to fix it but it’s better if other eyes and minds see this.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 33372
            • 1,611 Posts
            You’re everywhere and fixing everything, Susan! Looks like a form field repopulation bug to me (probably a late-night typo). Probably a pretty quick fix that could get added to the 0.95 release.
              "Things are not what they appear to be; nor are they otherwise." - Buddha

              "Well, gee, Buddha - that wasn't very helpful..." - ZAP

              Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              The form data are being saved and returned as-is, and the poor mutate_content file tries to format the pub_date and unpub_date values as it is instructed to do...but the data it is being given are already formatted!

              I’ve posted the bug and its fix in the bugtracker.

              In the file mutate_content.dynamic.action.php, at line 133, replace these lines
              // retain form values if template was changed
              if($formRestored==true||isset($_REQUEST['newtemplate'])) {
              $content = array_merge($content,$_POST);
              $content["content"]=$_POST["ta"];
              if(empty($content["pub_date"])) unset($content["pub_date"]);
              if(empty($content["unpub_date"])) unset($content["unpub_date"]);
              }

              With this:
              // retain form values if template was changed
              // edited to convert pub_date and unpub_date
              // sottwell 02-09-2006
              if($formRestored==true||isset($_REQUEST['newtemplate'])) {
              $content = array_merge($content,$_POST);
              $content["content"]=$_POST["ta"];
              if(empty($content["pub_date"])) {
              unset($content["pub_date"]) ;
              } else {
              $pub_date = $content['pub_date'];
              list($d, $m, $Y, $H, $M, $S) = sscanf($pub_date, "%2d-%2d-%4d %2d:%2d:%2d");
              $pub_date = strtotime("$m/$d/$Y $H:$M:$S");
              $content['pub_date'] = $pub_date;
              }
              if(empty($content["unpub_date"])) {
              unset($content["unpub_date"]);
              } else {
              $unpub_date = $content['unpub_date'];
              list($d, $m, $Y, $H, $M, $S) = sscanf($unpub_date, "%2d-%2d-%4d %2d:%2d:%2d");
              $unpub_date = strtotime("$m/$d/$Y $H:$M:$S");
              $content['unpub_date'] = $unpub_date;
              }
              }


              This converts the human-readable date/times back to timestamps, and now the mutate_content script can happily convert the value it is given. Poor computers...they do exactly what we tell them to do (unlike our teenaged children), and then we malign them for not doing what we wanted them to do!
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org