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

    Firstly...sorry if this has been asked before...I tried searching but with no luck...

    So I have a website built in MODX and have had one for a while now. I have many old TV's, Chunks, Snippets and Templates that arent being used anymore. Does anyone know of a plugin/extra that might be able to archive these away somewhere...instead of just deleting them?

    I had thought of perhaps just creating a category called "archived" or something and just sticking it in there however we have scripts that will run through chunks and only get certain ones and other things like that.

    Preferably would like to just tick a box or something and then it moves said chunk/TV/snippet/template to a separate part of the DB.

    Thanks in advance!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You could set them to be static, then save the files in an archive. Then you could delete the snippets in the Manager.
        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
        • 3749
        • 24,544 Posts
        You could also just put them in the category and put something like this in the loops of the scripts:

        $categoryId = 12; /* Set to the ID of your archive category */
        
        if ($snippet->get('category') == $categoryId) {
            continue;
        }
        

          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
          • 42596
          • 45 Posts
          Hey guys,

          Thanks for that, I really like the ideas. I have a load of templates and thought maybe it would be could to omit any templates in the archived category from the template selection in each resource using that code?

          I have been looking into this and thought I might use a plugin with OnDocFormPrerender but have no idea what I would use to actually access the template drop down menu?

            • 42596
            • 45 Posts
            Further to my previous post i was thinking about doing something like this:

            <?php
            $tplObj = $modx->getCollection('modTemplate');
            
            foreach ($tplObj as $tpl) {
                if($tpl->get('category') == 70){
                    continue;
                }
            }
            
            $modx->$resource->set('modTemplate', $tplObj);


            Although im not sure im using continue correctly here....
              • 3749
              • 24,544 Posts
              The Template selector is done in JavaScript. It gets the list from an Ajax call to the template getList processor, so you'd have to rewrite or override the MODX template getList processor: core\model\modx\processors\element\template\getlist.class.php

              You could possibly set the values in the Template selector drop-down with JavaScript that runs after the MODX processor is finished, by unbinding the drop-down's onclick function and adding your own, but it would be very difficult.

              FYI, in your code, $modx->resource is usually not set in the Manager, so it would be just $resource. Resources have a 'template' field but not the field you're using, so set() would fail, and if it didn't, you'd be seeing the resource's template to an array, which would also fail. wink
                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
                • 42596
                • 45 Posts
                Thanks again for the help...was looking for how that list was created for ages yesterday!

                I think perhaps I might just end up creating different user types where content editors cant see the archived category. Hopefully would be the easiest way around this...

                  • 42596
                  • 45 Posts
                  Update...So I think I will go with the archive category route and then i found this:

                  http://rtfm.modx.com/revolution/2.x/administering-your-site/security/security-tutorials/restricting-an-element-from-users

                  ...to hide that category from anyone who doesnt need to see it.

                  Thats all fine and dandy but I also found a plugin (written by you, Bob) called orphans which would be an incredible help except it doesnt seem to work...well, that is to say, it doesnt work on sites that I have with multiple contexts...or at least that is the only major difference between the sites that it does work on and the sites it doesnt...I have one website with 4 contexts and the orphans plugin has just had a loading screen for over an hour now...trying on a site where there is only one context it works almost instantly. I do have a third website with multiple contexts and it just gives a loading icon for ages as well....

                  It might not be the contexts but like I said thats the only difference I can think of. The two sites I have with many contexts are quit a lot bigger than the single context websites though...can you think of anything that might be causing conflicts?

                  Nothing comes up in the error log either so not too sure what could be causing it...

                  Thanks again for all your help!

                  P.S I'm using Revolution 2.3.2 on all of these sites. [ed. note: cleanboy last edited this post 11 years, 7 months ago.]
                    • 3749
                    • 24,544 Posts
                    See if making yourself a sudo user lets Orphans work on the multi-context sites.
                      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
                      • 42596
                      • 45 Posts
                      Didnt work Im afraid sad

                      Thanks anyway...I'm sure I'll figure something out...