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

    there’s a little bug in Revo 2.1.2, so that I’m not able to save a few documents with the same pagetitle in the same subfolder (I’m using the Extra Autofolders). I’ve seen that this bug is already reported.

    Now I need a fast workaround, so I can insert all my content.

    My idea was, to automatically set the ID of the Resource as the value of the Resource-Alias. I don’t need friendly URLS in this subfolders, because that are only PDF-Attachements.

    Is there an easy solution with an on-safe snippet or something. Or can I disable the friendly URLs for one folder?

    Thanks in advance an sorry for my bad english smiley

    Greetings from Germany


    ---
    ModX Revolution 2.1.2, Traditional
      • 3749
      • 24,544 Posts
      You definitely don’t want to be setting resource IDs. How about appending a timestamp to the pagetitle in a plugin attached to OnBeforeDocFormSave with something like this:

      <?php
      
      $title = $resource->get('pagetitle');
      $resource->set('pagetitle', $title . time() );
        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
        • 646
        • 5 Posts
        Yes … that would exactly meet the desired purpose. The main thing there is a clear alias.
        Unfortunately, my skills are not good enough for writting such a plugin.

        Can someone give me help or is there already a solution for something like this.

        Thanks again … and thanks for your fast response.

        ++
        ;) too fast … i will give it a try

          • 3749
          • 24,544 Posts
          Try just creating a new plugin called AddTime and pasting this code into it. On the Plugin’s System Events tab, check OnBeforeDocFormSave and save the plugin. I amended it so it only executes when creating a new document. Otherwise, it will add the time again every time you save a resource.

          You probably only want it to work on docs with a certain parent, rather than all docs on the site. The second test should take care of that. Change 12 to the ID of the appropriate parent resource. It will only work on immediate children of that resource. Let me know if you want to test for multiple parents (and provide their ID numbers).

          I just tested it and it works.

          <?php
          if ($mode != modSystemEvent::MODE_NEW) return;
          
          if ($resource->get('parent') != 12) return;
          
          $title = $resource->get('pagetitle');
          $resource->set('pagetitle', $title . time() );
          return;
            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
            • 646
            • 5 Posts
            -
              • 3749
              • 24,544 Posts
              Change 12 to the ID of the appropriate template (shown in parentheses in the Element tree).

              Just don’t forget to set the template before saving each resource. wink


              <?php
              if ($mode != modSystemEvent::MODE_NEW) return;
              
              if ($resource->get('template') != 12) return;
              
              $title = $resource->get('pagetitle');
              $resource->set('pagetitle', $title . time() );
              return;
                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
                • 646
                • 5 Posts
                Perfect … works very well!!!

                Here’s the code I#m working with.

                <?php
                if ($mode != modSystemEvent::MODE_NEW) return;
                
                if ($resource->get('template') != 14) return;
                
                $title = $resource->get('alias');
                $time = $resource->get('createdon',' %d_%m_%Y %s');
                $resource->set('alias', $title . $time );
                return;


                Thanks a lot BobRay!!!
                  • 17723
                  • 221 Posts
                  @BobRay: I've used the plugin that You shared and it deosn't work on Revo 2.2.7?
                  I've changed the template id and selected OnBeforeDocFormSave and still I get this message:
                  Resource 83 is already using the URI katowice.html. Please enter a unique alias or use Freeze URI to manually override it.

                  Here is this code:
                  <?php
                  if ($mode != modSystemEvent::MODE_NEW) return;
                   
                  if ($resource->get('template') != 1) return;
                   
                  $title = $resource->get('alias');
                  $time = $resource->get('createdon',' %d_%m_%Y %s');
                  $resource->set('alias', $title . $time );
                  return;


                  Did something significantly changed in Revo 2.2.7 ?

                    Lucas from AroundCyprus.net
                    • 3749
                    • 24,544 Posts
                    It might have. Do you have the auto-alias system setting on? That could be an issue.

                    I don't see why it wouldn't work, since that should be a unique alias.

                    You may have to change it to set the actual uri and set uri_override to true;

                    Something like this:

                    if ($mode != modSystemEvent::MODE_NEW) return;
                      
                    if ($resource->get('template') != 1) return;
                      
                    $title = $resource->get('alias');
                    $time = $resource->get('createdon',' %d_%m_%Y %s');
                    $alias = $title . $time;
                    $resource->set('uri', $alias);
                    $resource->set('uri_override', 1);
                    $resource->save();
                    return;
                      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
                      • 17723
                      • 221 Posts
                      Thanks Bob, but unfortunately still it doesn't work.
                      It seam like the alias is being checked for duplicated even before OnBeforeFormSave event occurs.

                      I've checked if the plugin works for generating and writing other fields ex longtitle, and it worked fine.
                        Lucas from AroundCyprus.net