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

    Following from an issue I found that bob was trying to help with, I have noticed I have several Resources in the Database that do not appear in the Manager at all. They were permanently deleted at some point (ie. they are not in the resource tree with a strikethru).

    1. Any idea how this can happen?
    2. Is it safe to manually delete these resources from the modx_site_content table?

    Thanks
    Andy
      • 4172
      • 5,888 Posts
      1. could have some reasons

      for example have no parent or show_in_tree = 1 or hide_children_in_tree of the parent = 0

      2.no, you have also to remove related objects like child-resources or TVs, better use the resource->remove - method
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 51020
        • 670 Posts
        Quote from: Bruno17 at Nov 17, 2017, 06:05 PM
        1. could have some reasons

        for example have no parent or show_in_tree = 1 or hide_children_in_tree of the parent = 0

        2.no, you have also to remove related objects like child-resources or TVs, better use the resource->remove - method

        Thanks. What’s the ‘remove resource’ method?
          • 4172
          • 5,888 Posts
          $removeresources = '1,2,3,4';
          $c = $modx->newQuery('modResource');
          $c->where(array('id:IN'=>explode(',',$removeresources)));
          
          if ($docs = $modx->getCollection('modResource', $c)){
              foreach ($docs as $doc) {
                  $doc->remove();
              }
          }
           
          


          be carefull!
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 3749
            • 24,544 Posts
            Andy, There are several reasons for resources not to show in the tree. That's standard if they were created with the Articles or Collections extras. They could also have their 'show_in_tree' field set to false. Having an invalid parent or being a descendant of a resource with an invalid parent will also hide them.

            As Bruno suggests, it's never a good idea to delete them in the database because they can leave behind orphaned intersects that connect them to TVs and Templates. There might also be children that would still exist but now wouldn't show in the tree. Those would be there forever, cluttering up the DB unless you remove them properly with code like Bruno's.

            You could also remove them safely with the Batcher extra.
              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
              • 51020
              • 670 Posts
              Quote from: BobRay at Nov 18, 2017, 03:04 AM
              Andy, There are several reasons for resources not to show in the tree. That's standard if they were created with the Articles or Collections extras. They could also have their 'show_in_tree' field set to false. Having an invalid parent or being a descendant of a resource with an invalid parent will also hide them.

              As Bruno suggests, it's never a good idea to delete them in the database because they can leave behind orphaned intersects that connect them to TVs and Templates. There might also be children that would still exist but now wouldn't show in the tree. Those would be there forever, cluttering up the DB unless you remove them properly with code like Bruno's.

              You could also remove them safely with the Batcher extra.

              Show in tree is set to 1.
              I've tried batcher, but the resources don't show up there either!
                • 51020
                • 670 Posts
                Quote from: Bruno17 at Nov 17, 2017, 09:38 PM
                $removeresources = '1,2,3,4';
                $c = $modx->newQuery('modResource');
                $c->where(array('id:IN'=>explode(',',$removeresources)));
                
                if ($docs = $modx->getCollection('modResource', $c)){
                    foreach ($docs as $doc) {
                        $doc->remove();
                    }
                }
                 
                


                be carefull!

                Thanks - I ran this utility class too (after backing up!) but it didn't do anything. the resources are still in the database, but not visible in the resource tree.

                  • 51020
                  • 670 Posts
                  Should I just re-install Articles to see if they re-appear?
                    • 4172
                    • 5,888 Posts
                    you modified this line to your needs?
                    $removeresources = '1,2,3,4';
                    
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                      • 51020
                      • 670 Posts
                      Quote from: Bruno17 at Nov 20, 2017, 09:21 AM
                      you modified this line to your needs?
                      $removeresources = '1,2,3,4';
                      

                      Yes I added in the IDs of the 'phantom' resources.