We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 52064
    • 120 Posts
    Situation:
    Modx multi host
    Extra: babel
    Sudo User.
    Clear all cache.

    Plugin OnHandleRequest
    $allContext = $modx->getCollection('modContext');


    If load page on primary host pluto.it
    Result of code is full list of contexts

    If load page on secondary host pippo.it
    Result of code is list of contexts excluding those with pippo.it in http_host!!!

    Any ideas on howto resolve the problem?

    It looks like modx applies some filter...


    This question has been answered by BobRay. See the first response.

      FerX - Developer at Eracom s.r.l.
    • discuss.answer
      • 3749
      • 24,544 Posts
      I think there are some cases where MODX enforces permissions even for sudo users. If that's the case, it could be a permissions issue.

      getCollection() calls loadCollection, which has this comment above the function:

      /* Custom collection loader that forces access policy checking. */


      I don't see what else could cause this because normally, getCollection() called with no criteria should just get all the contexts in the modx_context table.

      You should be able to cheat with code like this:

      $query = $modx->newQuery('modContext');
      $rowCollection = array();
      if ($query->prepare() && $query->stmt->execute()) {
          $rowCollection = $query->stmt->fetchAll(PDO:FETCH_ASSOC);
      }


      You won't an array of modContext *objects*, just an array of arrays containing the fields and their values (see example below).

      Of course, you could also mess with the user's permissions to "load, list, and view' contexts while in a particular context, but that might involve some trial and error. [ed. note: BobRay last edited this post 6 years, 9 months ago.]
        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
        • 52064
        • 120 Posts
        thanks Bob,
        Surely it is as you say, a problem of permits.

        ps: Your script has always been false.
          FerX - Developer at Eracom s.r.l.
          • 3749
          • 24,544 Posts
          LOL. I got that code from a post by Jason Coward (OpenGeek). There's a typo, so it's a comfort to see that he's not totally infallible. wink

          It should be
          PDO:FETCH_ASSOC


          (fixed above)

          I tested it and it does return an array of contexts, each with an array of fields:

          Array
          (
              [0] => Array
                  (
                      [modContext_key] => web
                      [modContext_name] => 
                      [modContext_description] => The default front-end context for your web site.
                      [modContext_rank] => 0
                  )
          
              [1] => Array
                  (
                      [modContext_key] => mgr
                      [modContext_name] => 
                      [modContext_description] => The default manager or administration context for content management activity.
                      [modContext_rank] => 0
                  )
          }
            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