We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20847
    • 7 Posts
    Example:

    I have:
    - A document "A" with template "TA".
    - A document "B" with template "TB".
    - A template variable "TV" associated to "TA" and "TB".

    - "A" has the value "TRUE" in "TV"
    - "B" has the value "TRUE" in "TV"

    If I remove the association between "TA" and "TV" I supposed that I’d have an empty value in "TV" for "A", but the value is still in the database, and the only way to remove it is by hand.

    The same result if you change from one template to another with different TV associations.

    This is an annoying issue when you have a big website. I would like, in example, this feature when you empty the trash bin. It seems to me very rational.

    Looking for a solution I’ve tried to write a complex SQL query, here is my attempt. It doesn’t work and removes more than expected, don’t use it.

    /* It doesn't work and removes more than expected!! */
    
    SELECT
       site_tmplvar_contentvalues.id,
       site_content.id,
       site_tmplvars.name,
       site_tmplvar_contentvalues.value
    FROM
       site_content,
       site_tmplvars,
       site_tmplvar_templates,
       site_tmplvar_contentvalues
    WHERE
       site_content.id = site_tmplvar_contentvalues.contentid
       AND
       (
          site_tmplvar_templates.tmplvarid = site_tmplvar_contentvalues.tmplvarid
          AND
          site_tmplvar_templates.templateid != site_content.template
       )
       AND
       site_tmplvars.id = site_tmplvar_contentvalues.tmplvarid
    LIMIT 10;
    
    /* tmp table */
    
    CREATE TABLE tmptable
    SELECT
       site_tmplvar_contentvalues.*
    FROM
       site_content,
       site_tmplvars,
       site_tmplvar_templates,
       site_tmplvar_contentvalues
    WHERE
       site_content.id = site_tmplvar_contentvalues.contentid
       AND
       (
          site_tmplvar_templates.tmplvarid = site_tmplvar_contentvalues.tmplvarid
          AND
          site_tmplvar_templates.templateid != site_content.template
       )
       AND
       site_tmplvars.id = site_tmplvar_contentvalues.tmplvarid;
    
    /* delete */
    
    DELETE FROM
       site_tmplvar_contentvalues
    USING
       site_tmplvar_contentvalues
    INNER JOIN
       tmptable
    ON
       site_tmplvar_contentvalues.id = tmptable.id;
    
    /* drop */
    
    ALTER tmptable DROP;
    


    Any help will be appreciated.

    Thank you.
      "The beautiful thing about learning is nobody can take it away from you." - B.B. King
      • 33968
      • 863 Posts
      I’ve come across this same problem. I’ve removed TV access from one of my templates, but all data from those ’unlinked’ TVs still remains in the database.
      It’s causing issues as these values are showing up in site search, Ditto, etc. Some kind of ’Refresh TV data’ button would be great on the TV editing page to remove the ’trash’ from the database.

      Pain in the ass!!
        • 3749
        • 24,544 Posts
        Would you file that as a request using the Bugs & Requests link at the top of this page?
          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