We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 53177
    • 14 Posts
    I'll pose this question to the community in hopes I can find an answer. I've been looking exhaustively for the answer but can't seem to find one that appeases my question. Any help is appreciated.


    Scenario:

    We are building a suite of 15 sites or a single organization. Each site sits on a different domain, and thus lives in a different context within a single MODX installation.

    We are building the site locally, but we have to push it to the pre-deployment server for the purposes of collaborating and demonstrating functionality with the client.

    We are finding a REAL challenge when deploying a site, due to the massive dependence MODX has to its database.

    When working with 15 different contexts, you can imagine it's REALLY painful to have to update all 15 context variables for "http_host" or "base_url" everytime we push the site and the database from local to the PDS.

    I've attempted to create a system setting (like: "master_domain"), and then USE that system setting inside the context variable when it specifies things like "base_url" or "http_host" (which both require the full URL of the context). The object of doing this would be so I can use that system setting INSIDE another context setting, so I only have to change it once, system-wide.

    As such, I've set such context settings (like "base_url" and "http_host") to "subdomain.[[++master_domain]]" in an attempt to create an output like "subdomain.master_domain.com"

    But, it seems to break the system (even though I know Modx WILL parse system variables within a context variable, which I have tested on several occasions).

    Hopefully this isn't too confusing... But I'm running out of ideas.
      • 3749
      • 24,544 Posts
      First, (if you haven't already) try flushing all sessions, and manually deleting all files in the core/cache directory before testing.

      Second, are you sure it's not breaking the system because your settings aren't correct? That is, if you replace the tags manually, does everything work correctly?


      Third, if you're sure the tags are correct, replacing them manually fixes things, and they are already in place, and the master_domain Context Setting has been set for each context, I would write a small PHP utility snippet to replace them. Something like this (off the top of my head, and untested):

      $searchString = '[[++master_domain]]';
      
      // Try it on one or two contexts
      
      $contexts = $modx->getCollection('modContext', array('key' => 'SomeActualTestContext'));
      
      // If it works, replace that line with this one: $contexts = $modx->getCollection('modContext');
      
      
      foreach ($contexts as $context) {
          $key = $context->get('key');
          $masterDomainSettingObject = $modx->getObject('modContextSetting', array('key' => 'master_domain'));
          $masterDomain = $masterDomainSettingObject->get('value');
      
          $settings = $context->getSettings();
          foreach ($settings as $setting) {
              $value = $setting->get('value');
              if (strpos($value, $searchString) !== false) {
                  $value = str_replace($searchString, $masterDomain, $value);
                  $setting->set('value', $value);
                  $setting->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