We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44665
    • 60 Posts
    sebastian-marinescu Reply #1, 8 years, 4 months ago
    Hi MODx-Community,

    so I'm working on my nice, abstract, do-it-all Website-Package.

    I encountered some things I don't really get how MODx works underneath:

    • In my package I had x Chunks. Now I deleted 2 and there are x-2 Chunks. After updating the package the 2 not-anymore-packaged Chunks were still there. Doesn't the vehicle get rid of that by itself? Do I have to resolve/validate old Chunks by myself? Or do I really have to (what I did) uninstall and re-install it manually?

    Also I'm confused what PRESERVE_KEYS really does. Could someone explain it in his/hers own words? Maybe with an example would be great smiley

    Thanks in advance. I'll post more questions regarding Transport-Package-Building here when they come to my mind.

    With best regards,
    Sebastian
      • 3749
      • 24,544 Posts
      If the ID of an object in your package is 2, with PRESERVE_KEYS, MODX will try to install it with its ID set to 2. If there's already an object of that type with that ID, you have a collision. In that case, I'm fairly certain that the object is not installed at all, though I've never tested it.

      The only time you want PRESERVE_KEYS on is when you're installing to an empty site and want to make sure the related-object IDs are all correct (e.g., the 'parent' field of a resource really points to the parent you want). If it's not an empty site, you often want to find the parent by pagetitle and set the child's 'parent' field in a resolver. BTW, MyComponent handles all the relationships automatically by auto-creating the resolvers for you.

      When you install objects in a package, they stay installed until the package is uninstalled. Installing a new package with fewer objects won't remove them. You can delete them manually, or you can do it in a resolver. For chunks, that would look like this:

      $chunk = $modx->getObject('modChunk', array('name' => 'MyChunk'));
      
      if ($chunk) {
          $chunk->remove();
      }
        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