We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42082
    • 72 Posts
    Hi again yall, I recently created a category inside another category in my chunks section. Then I created an chunk and assigned it to the category. The category showed up but then later on decided to disappear. The category still exists as I can go into categories in the element tree and it is there but it does not show up in my chunks list.My question is why is my category not showing up where I created it (the chunks list)? And though all my chunks are still in the category because my site on the front end still is working I cannot access them even in the Category section of the element tree.

    Thanks all,
    Modxnooby
      • 4172
      • 5,888 Posts
      which version of Revo are you working with?
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 42082
        • 72 Posts
        I am using modx Revo 2.2.10 and thank you for the reply.

        thanks again,
        Modxnooby

          • 3749
          • 24,544 Posts
          That sounds like a perfect case for SiteCheck: http://bobsguides.com/sitecheck-tutorial.html.

          The odds are that some resources have an invalid category and/or some categories have an invalid parent.
            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
            • 42082
            • 72 Posts
            oh ok,
            Um is there something wrong with my category list in my element tree? I mean is it supposed to show the chunks and stuff that are in each category? Also, How can a resource or some other element's category effect the category that is not showing up.

            Thanks for the replies,
            Modxnooby
              • 3749
              • 24,544 Posts
              In the database, the category table has a parent field which holds the ID of the category's parent (IOW, the category it's under in the tree). All elements, including chunks, have a 'category' field that stores the ID of the category they're in.

              Sometimes those fields get bogus information stored in them, so the parent ID or the category ID is pointing to a category that doesn't exist. When that happens, they no long show up in the tree although they still exist.

              You can fix them manually in the DB if you can find them or SiteCheck will fix them for you (and possibly some other problems as well).
                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
                • 42082
                • 72 Posts
                Hi Bob thanks so much for your help on this. I could not have done it with out Modx_categories and I found the id for the category I needed to find that was not showing. Then I found It and changed the parent to a category that was one level up instead of the current category it was under. So It was set to parent = 77 so I changed it to parent = 50. Then I went under the Modx_categories_closure table and deleted the table that connected the 79 category (the one that was not showing up) to the 77 category. And I changed the depth column to 1 on category 50s row to 1 instead of 2. Now my 77 category is showing! But the 79 is still not. So I went under Modx_site_htmlsnippets and searched for any chunks in the 79 category but the weird thing was there was none.

                What does that mean? Is that the bogus info you where talking about?

                Thanks,
                Modxnooby
                  • 3749
                  • 24,544 Posts
                  The category won't show up in the chunks part of the tree if it has no chunks in it.

                  I never mess with the categories_closure table directly, because changing a category's location in the tree often requires rebuilding a number of closures. When you change the parent in code and save the category, this is done automatically. That's why I use SiteCheck. wink

                  FYI, here's the code that rebuilds the categories_closure when the parent changes:

                     /**
                       * Rebuild closure table records for this instance, i.e. parent changed.
                       */
                      public function rebuildClosure() {
                          /* first remove old tree path */
                          $this->xpdo->removeCollection('modCategoryClosure',array(
                              'descendant' => $this->get('id'),
                              'ancestor:!=' => $this->get('id'),
                          ));
                  
                          /* now create new tree path from new parent */
                          $newParentId = $this->get('parent');
                          $c = $this->xpdo->newQuery('modCategoryClosure');
                          $c->where(array(
                              'descendant' => $newParentId,
                          ));
                          $c->sortby('depth','DESC');
                          $ancestors= $this->xpdo->getCollection('modCategoryClosure',$c);
                          $grandParents = array();
                          foreach ($ancestors as $ancestor) {
                              $depth = $ancestor->get('depth');
                              $grandParentId = $ancestor->get('ancestor');
                              /* if already has a depth, inc by 1 */
                              if ($depth > 0) $depth++;
                              /* if is the new parent node, set depth to 1 */
                              if ($grandParentId == $newParentId && $newParentId != 0) { $depth = 1; }
                              if ($grandParentId != 0) {
                                  $grandParents[] = $grandParentId;
                              }
                  
                              $cl = $this->xpdo->newObject('modCategoryClosure');
                              $cl->set('ancestor',$ancestor->get('ancestor'));
                              $cl->set('descendant',$this->get('id'));
                              $cl->set('depth',$depth);
                              $cl->save();
                          }
                          /* if parent is root, make sure to set the root closure */
                          if ($newParentId == 0) {
                              $cl = $this->xpdo->newObject('modCategoryClosure');
                              $cl->set('ancestor',0);
                              $cl->set('descendant',$this->get('id'));
                              $cl->save();
                          }
                      }
                    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
                    • 40568
                    • 20 Posts
                    Had same issue. BobRay suggestion worked for me. Thanks!


                    Quote from: BobRay at Oct 31, 2013, 10:42 PM
                    In the database, the category table has a parent field which holds the ID of the category's parent (IOW, the category it's under in the tree). All elements, including chunks, have a 'category' field that stores the ID of the category they're in.

                    Sometimes those fields get bogus information stored in them, so the parent ID or the category ID is pointing to a category that doesn't exist. When that happens, they no long show up in the tree although they still exist.

                    You can fix them manually in the DB if you can find them or SiteCheck will fix them for you (and possibly some other problems as well).
                      • 4172
                      • 5,888 Posts
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!