We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25317
    • 122 Posts
    Is there a script about which can change document creation dates?

    I don’t really want to edit the database directly, but might have to else.

    Thanks.
      • 18397
      • 3,250 Posts
      Yes!
      Here is one by Ralph that I modded to work as a module. I think it works fine with x9...

      // ChangeCreatedonDate -- Works with all version of modx
      // Created By: Ralph Dahlgren
      // Last Updated: 2005-09-14
      // Changes the createdon and editedon dates and author settings of a document
      
      $header = '
      <html>
      <head>
      	<title>MODx</title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      	<link rel="stylesheet" type="text/css" href="media/style/MODx/style.css?" />
      	<script type="text/javascript" language="JavaScript" src="media/script/cb2.js"></script>
      </head>
      <body>
      <br />
      <br />
      <br />
      <div class="sectionHeader"><img src="media/images/misc/dot.gif" alt="." /> Results</div><div class="sectionBody">
        ';
      $footer = ' 
      	</div>
      	</body>
      	</html>
      ';
      
        if( isset($_POST['submit']) && is_numeric($_POST['docid']) && isset($_POST['newdate']) ){
          $tbl = $modx->dbConfig['dbase'].".".$modx->dbConfig['table_prefix'];
          $sql = "UPDATE ".$tbl."site_content SET ";
          if($_POST['modCreatedon']) $sql .= "createdon=".strtotime($_POST['newdate']).", ";
          if($_POST['modEditedon']) $sql .= "editedon=".strtotime($_POST['newdate'])." ";
          $sql .= "WHERE id=".$_POST['docid'].";";
          
          if(!$modx->dbQuery($sql)){
            $output = "".$header."Update failed... Check your document ID and Date/Time format and try again...".$footer."";
          } else {
            $output = "".$header."Document Date/Time/Author were successful updated...".$footer."";
          }
        } else {
          $output = '
      <html>
      <head>
      	<title>MODx</title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      	<link rel="stylesheet" type="text/css" href="media/style/MODx/style.css?" />
      	<script type="text/javascript" language="JavaScript" src="media/script/cb2.js"></script>
      </head>
      <body>
      <br />
      <br />
      <br />
      <div class="sectionHeader"><img src="media/images/misc/dot.gif" alt="." /> Update Document Info</div><div class="sectionBody">
          <p>This form allows you to change the createdon and editedon dates of a specific document based on its document ID. The documents author reference will automatically be changed to that of the user submitting this information.</p>
          <form name="modCreatedon" id="modCreatedon" method="post" action="">
          <p><label>ID of document to be modified:</label>
          <input type="text" name="docid" id="docid" value="" />
           (ex: 123 - Must be numeric and must exist)</p>
          <p><label>New createdon/editedon date:</label>
          <input type="text" name="newdate" id="newdate" value="" />
           (See examples below)</p>
          
          <p><label>Change createdon date:</label>
          <input type="checkbox" name="modCreatedon" id="modCreatedon" checked="checked" value="true" /></p>
          <p><label>Change editedon date:</label>
          <input type="checkbox" name="modEditedon" id="modEditedon" checked="checked" value="true" /></p>
             
          <p>Date Examples:</p>
          <ul>
            <li>19 Dec 1994 9:20pm</li>
            <li>December 19th, 1994</li>
            <li>12/19/1994 21:20:00 (Hyphens cannot be used with this format)</li>
            <li>19941219 2120 </li>
            <li>1994/12/19 or 1994-12-19</li>
            <li>now, yesterday, Monday, or last Friday</li>
            <li>+2 days or -1 week [minute(s),hour(s),day(s),month(s),year(s) from the current time]</li>
          </ul>
          <p>Time values are optional and will default to 00:00:00 if ommitted.</p>
          <p>Some Date/Time formats cannot contain commas or they will produce a NULL timestamp value.</p>
          <p>Visit <a href="http://www.gnu.org/software/tar/manual/html_chapter/tar_7.html" target="_blank"> http://www.gnu.org/software/tar/manual/html_chapter/tar_7.html</a> for more information about formatting.</p>
          <input type="submit" name="submit" id="submit" value="Submit" />
          <input type="reset" name="reset" id="reset" value="Reset" />
          </form>
      	</div>
      	</body>
      	</html>
          ';
        }
        echo $output;
      
      
        • 26435
        • 1,193 Posts
        cool! Thanks. I have also been thinking about a tool like this.

        -sD-
          Husband, Father, Brother, Son, Programmer, Atheist, Nurse, Friend, Lover, Fighter.
          All of the above... in no specific order.


          I send pointless little messages
          • 32241
          • 1,495 Posts
          How do we use this, paste all the code to plugin and on which event that this thing should listen to (I couldn’t find any event listening in the code as well)? And what is this thing does? Does it enabled manager to change the date in the edit mode, is that correct?

          Hope somebody can help me out in understanding the benefit.

          Thank you mark for the code, and Ralph Dahlgren for making it up.

          Regards,
          Wendy Novianto
            Wendy Novianto
            [font=Verdana]PT DJAMOER Technology Media
            [font=Verdana]Xituz Media
            • 25317
            • 122 Posts
            Quote from: wendy at Dec 06, 2005, 06:04 AM

            Hope somebody can help me out in understanding the benefit.
            Well the benefit to me is that I can change the creation date of news items so they are listed in the order I wish them to be. For example, historical news items I wanted to be shown as created on those dates.

            It also allows me to re-use old document IDs should I choose to, when date dependent snippets are used.

            I’m also not too sure how the module is used. I did try Ralphs version before, but it didn’t work with Modx.

            Thanks for the code.

            Edit: Oh I see. Just run it from the Modules page. Sweet! grin

              • 32241
              • 1,495 Posts
              Oh I get it now.

              I thought it is a plugin. My bad...

              Thanks
                Wendy Novianto
                [font=Verdana]PT DJAMOER Technology Media
                [font=Verdana]Xituz Media
              • Now all we need to do is to make the publish dates manually editable so we can tweak publish dates/times without having to worry about being forced to make a million clicks in the pop-up calendar.
                  Ryan Thrash, MODX Co-Founder
                  Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                  • 32241
                  • 1,495 Posts
                  I wonder, why don’t we use aJS calendar for picking calendar?

                  Here is one good free calendar out there http://www.dynarch.com/

                  I used them for my company, and it works like a charm. It’s not that heavy weight as well.

                  Looking forward to see this being listed as future suggesiton.

                  Thanks


                  Regards,
                  Wendy Novianto
                    Wendy Novianto
                    [font=Verdana]PT DJAMOER Technology Media
                    [font=Verdana]Xituz Media
                  • It is a JS popup calendar already!
                      Ryan Thrash, MODX Co-Founder
                      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                      • 4095
                      • 372 Posts
                      Keeping in mind the problem with changing dates by multipul months or years requires many mouse clicks

                      http://modxcms.com/bugs/task/44
                        [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
                        Admin Sandbox Login: sandbox Password: castle