We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14197
    • 35 Posts
    When I unbind TVs from templates, though these TVs disappear in the manager interface for related documents, but these documents’ previous stored TV values are still in site_tmplvar_contentvalues table, anybody know how to deal with the situation?
      • 5340
      • 1,624 Posts
      You can create your own sql script that deletes all those rows based on TV ID.
        • 14197
        • 35 Posts
        Cipa, the senario is more complicated than that.

        I noticed if you delete the tv definition itself, then all tv values will be deleted, but if you only unbind tv from a template, then all tv values associated with documents of that template will not be deleted by default,so deleting by tv id is not gonna work.
          • 5340
          • 1,624 Posts
          Get the id of the TV
          Get the id of the template you will unbind the TV from

          With the above look up all the documents that have the template ID above. See modx_site_content

          Use the TV id with the list of document ids to delete rows from modx_site_tmplvar_contentvalues

          For more info get familiar with the following tables

          # modx_site_content
          # modx_site_tmplvars
          # modx_site_tmplvar_access
          # modx_site_tmplvar_contentvalues


          PS: I didn’t test this so make sure you make backups smiley
            • 14197
            • 35 Posts
            Thanks Cipa smiley I guess I will have to write my own SQL to do this job then. I was a little surprised to see this when optimizing my website performance. I have about several hundreds such ghost records, it’s not a big deal but ideally could be fixed and would benefit those who really want to make their modx sites tight and fast...
            • This issue sounds like it certainly merits a bug report. (Please! laugh)
                Ryan Thrash, MODX Co-Founder
                Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                • 5340
                • 1,624 Posts
                I’m not sure this is really a bug.

                For example I can (by mistake) unlink a TV from Template. If this is a bug then the content in the TV will be lost for all documents using that template. There is no going back if you don’t have a backup.

                I think this should be done more like a module to clean the tables. The module can check for unused TVs and Templates and somehow delete them.