We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9207 ☆ A M B ☆
    • 2,475 Posts
    Is there perhaps a Module out there that shows stats on if/where a Snippet, Chunk, or Template is used? I know I can write this one myself, but I’m just checking to make sure something like this doesn’t already exist. I’m having to clean up one of my sites... people kept creating new chunks and templates and now nobody knows what’s safe to delete.

    The database query would be really simple for the templates (I’m just trying to avoid the pop-ups that occur when you try to delete a template that’s in use), but the queries for chunks and snippets would be trickier. I could either select a lot of info and regex it in PHP (which might cause a memory error), or I could use the unefficient "WHERE column_name LIKE ’%search_term%’" syntax. It would probably be forgivable considering this report would be run only within a module by managers.
      • 36592
      • 970 Posts
        • 9207 ☆ A M B ☆
        • 2,475 Posts
        Mmm... does that show me where Chunks and Snippets are called?  Can I use {{chunk_names}} for the search text? Bummer that the http://docfinder.trymodx.com/manager/ isn’t working... that would have answered my question.
          • 36592
          • 970 Posts
          Quote from: Everett at Jan 22, 2009, 01:08 AM

          Mmm... does that show me where Chunks and Snippets are called? Can I use {{chunk_names}} for the search text?
          Yes. Installing the module is so simple, so try it !!
            • 9207 ☆ A M B ☆
            • 2,475 Posts
            Ok, I’ve tried DocFinder... it’s useful, but it’s not exactly what I was looking for. So... I’m working on putting together a handful of queries to report on which Templates, TVs, Snippets, and Chunks are in use and which can be deleted. If I can do this correctly, I’ll publish my results as a Module in the repository. I don’t know if I can make it as clean and well-formatted as the DocFinder, but I’ll try my best.
              • 25663 MODX Staff
              • 12,272 Posts
              Thank you so much Everett. This would make for an outstanding "element cleaner" contribution, especially for sites that have been maintained for years but may now have some cruft left over from the process of ongoing development over time.

              What would be really handy is to be able to have checkboxes next to all unused items and a bulk-delete option. I’ve got a site I’d love to use this on and would love to help test it out in any form. Combined with DocFinder and a similar idea for the filesystem and I might actually be able to clean up a few sites I’ve built with relative ease!
                Ryan Thrash, MODX Co-Founder
                Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                • 3749
                • 24,544 Posts
                Don’t forget that they may nested and used in weird places (e.g. snippets inside of snippet calls, inside of chunks, nested elements in the template, snippets in template variables and meta tags, etc.).

                I think I’d start by getting the names of all the elements in the element tables (site_snippets, site_htmlsnippets, etc.), one table at a time, and just search the whole database for those names to get an idea what turns up. A name that appears only once is guaranteed to be an orphan and you don’t have to worry about missing some odd place where it’s used. It will have to be run more than once because, for example, a chunk that’s used in an unused snippet wouldn’t show up as an orphan until after the snippet is deleted.

                It sounds like a fun project. smiley
                  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
                  • 20413
                  • 2,877 Posts
                  For me AjaxSearch finds everything I don’t exclude!
                  http://modxcms.com/forums/index.php/topic,30405.msg186688.html#msg186688

                  I may have some other code conflicting to make this the behaviour but sure I can find
                  what docs and tvs that use a certain snippet... tongue
                    @hawproductions | http://mrhaw.com/

                    Infograph: MODX Advanced Install in 7 steps:
                    http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                    Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                    http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
                    • 9207 ☆ A M B ☆
                    • 2,475 Posts
                    especially for sites that have been maintained for years

                    Lol... or for young sites prematurely handed over to hooligan editors/developers.  I’ve got a site that’s only 6 months old that’s crawling with stuff that might possibly be being used..... somewhere. 

                    Good call on the "bulk delete" option... that’s EXACTLY where I was going with this.

                    Yeah, I’ve got most of the normal places in the database figured out... looking in all parse-able fields in site_content... the template variables are always tricky, but I already worked this out for another Snippet I wrote, so I should be able to adapt it.

                    Whee!  Stay tuned... I’d love it if somebody could help test when it’s done.
                      • 4749
                      • 623 Posts
                      You’ve got a tester in me! grin
                        The MODx has you...
                        Utah Web Design