We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26903
    • 1,336 Posts
    Having done this now and got it back working I’m a little clearer on my context dilemma. In my connector for the change template request I instantiate a new modx object with the ’connector’ context. I have to do this as I then go on and do this :-
    $modx->getRequest();
    $modx->request->sanitizeRequest();
    $modx->request->handleRequest(array('processors_path' => $docmanager_processors,
                                        'location' => 'processors'));
    


    Ok, I have to use the ’connector’ context here so I instantiate the modconnectorrequest/response class, this invokes my processor code, I can’t do this in either the ’mgr’ context or any other that I can see at the mo because I’ll get modmanagerrequest/response or modrequest/response.

    So, in my processor code what’s the best way to get to another context? I need to get to contexts that hold resources, specifically documents in my case, that’s why I used the switch context above so I could get the child id’s etc from the modxclass api which needs the resourcemap of the context the resource is in, not the ’connector’ context. I dont want to manipulate these as such, just read data from them.

    Ok, it does seem to work however, the modx object in the connector is transient, so I can change templates and doc-id ranges one after the other and press ’change’ without ill effect.

    I know you guys are working on this, I hope the above is a little clearer and helps.
      Use MODx, or the cat gets it!
      • 26903
      • 1,336 Posts
      Ok guys, bit more feedback from my end, may be useful even if you are halfway through this, updated to svn 4730 :-

      I used to do this in my connector
      $modx->initialize('connector');
      , this fails on line 49 of modcontextclass, probably because as the svn comment says the connector context has gone. So, i’ve changed it to now do this
      $modx->initialize('mgr');
      . This fails because we instantiate modmanagerrequest/response class, as opposed to modconnectorrequest/response class, hence my back end processor code is no longer called and we end up in an error situation.

      Just thinking aloud here, no matter what context the connector is called in,’mgr’ sounds good if we are in the manager of course, until my back end processor code is executed I’ll never know what contexts I’m going to need, because this code examines the input parameters, doc id’s in my case, only then will I ever know which context to switch to/load/manipulate. So, which context we start in is not that important, as long as it gets the processor code executed.

      Just to clarify further, I’m entering this docid ’10**’, which means ’apply the template change to all children, immediate or otherwise’, that’s why I use the getchildid’s API to first get the children which only works if you are in the context the start doc is in.
        Use MODx, or the cat gets it!
        • 22303 MODX Staff
        • 10,725 Posts
        All connectors should be including connectors/index.php which handles the initialization of the calling context. It will default to mgr if you do not provide a request parameter called ctx with the value of the target context you want to execute in.
          • 22303 MODX Staff
          • 10,725 Posts
          Quote from: shamblett at Feb 06, 2009, 03:29 AM

          Just thinking aloud here, no matter what context the connector is called in,’mgr’ sounds good if we are in the manager of course, until my back end processor code is executed I’ll never know what contexts I’m going to need, because this code examines the input parameters, doc id’s in my case, only then will I ever know which context to switch to/load/manipulate. So, which context we start in is not that important, as long as it gets the processor code executed.

          Just to clarify further, I’m entering this docid ’10**’, which means ’apply the template change to all children, immediate or otherwise’, that’s why I use the getchildid’s API to first get the children which only works if you are in the context the start doc is in.
          The context being executed should never be switched in this. You are misunderstanding the use of contexts here. You can loaded contextual data manually if you need to work with it, but getChildIds() is a context specific function and not meant to be used in management interfaces like you are constructing. You can load specific context data without switching contexts (check out makeUrl() now to see the kinds of challenges managing data from multiple contexts is going to present to the component you’ve chosen to work on). But it’s absolutely imperative that you do not switch to the contexts of the documents you are managing; that would be bypassing your security into the mgr context.
            • 34017
            • 898 Posts
            How could one use the $modx->getChildIds then in a module/plugin (or any custom context)?
              Chuck the Trukk
              ProWebscape.com :: Nashville-WebDesign.com
              - - - - - - - -
              What are TV's? Here's some info below.
              http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
              http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008
              • 22303 MODX Staff
              • 10,725 Posts
              Quote from: ChuckTrukk at Feb 06, 2009, 12:02 PM

              How could one use the $modx->getChildIds then in a module/plugin (or any custom context)?
              What I am saying is you can use it in any front-end context script. It’s just not meant as a content management function. It’s purpose is to get faster access to that data in front-end scripts, period.

              getChildIds() only returns child Resources of Resources that are published, not deleted, and in the current context’s alias/url structure. In a management component, you need to consider unpublished Resources, deleted Resources, the primary context of the Resource, and much more. In upcoming versions, you’ll also need to consider Resources that are shared in multiple contexts, versioning of all Element content (which will include Resource content and meta-data fields like pagetitle, longtitle, introtext, etc.), and other new capabilities.

              It might be that we need to extend getChildIds() and getParentIds() and getTree() for content management purposes, but for now you can provide your own functions to work with the data as is appropriate for the management task being performed. Then we can take a look at how we can make these functions work for content management tasks moving forward.
                • 26903
                • 1,336 Posts
                Sorry I disagree here, when at the mo(I know its fluid) as a ’3rd party manager component provider’ can I execute my code? I can’t use it in the front end script because first I have to load my back end processor to analyze my input parameters, which at the mo I can’t do because I can’t get to it any more.(see below)

                I can’t instantiate a modx object in the right context because at the time(when the connector fires) I don’t know what context it will need until I’ve checked the params, this seems to me to be wrong, but not fatal. I can assume ’mgr’ but this doesn’t work(see below).

                Sorry to be blunt here but please explain how I get to execute my back end processor code, then get to see any context I like. Don’t forget that my ’action’ for the processor is the name of the file, not a number, so modmangerresponse will always fail here.


                  Use MODx, or the cat gets it!
                  • 28215
                  • 4,149 Posts
                  Quote from: shamblett at Feb 06, 2009, 02:55 PM

                  I can’t instantiate a modx object in the right context because at the time(when the connector fires) I don’t know what context it will need until I’ve checked the params, this seems to me to be wrong, but not fatal. I can assume ’mgr’ but this doesn’t work(see below).
                  You should be just able to include the connectors/index.php file to instantiate the correct context.


                  Sorry to be blunt here but please explain how I get to execute my back end processor code, then get to see any context I like. Don’t forget that my ’action’ for the processor is the name of the file, not a number, so modmangerresponse will always fail here.
                  If I’m understanding you as you’re saying in your custom form there’s a field with name="action", then you’re doing it wrong - ’action’ as a REQUEST param is reserved in MODx Revolution. You need to change that REQUEST param to another name.

                  Your manager page must be hooked to a modAction, referenced by $_REQUEST[’action’], which is how MODx knows what file to reach.
                    shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                    • 26903
                    • 1,336 Posts
                    You should be just able to include the connectors/index.php file to instantiate the correct context.


                    Ok, will this get my processor code to work? How can the ’connector’ possibly know what contexts I will need in my code at the back end? How can it ever be correct?
                    My ’action’ is the name of my processor e.g. chanegetemplate, so it can invoke the correct processor file in my custom directory, its not a number, so modmangerresponse will fail here all the time.

                    I check the $_REQUEST params in my processor code, not in my connector, if i need to do this in the connector, whats the point of it?

                    Reminder, this all worked until yesterday.

                    I’ll zip the code up and post it so you can see what I’m doing here, it may help.

                      Use MODx, or the cat gets it!
                      • 26903
                      • 1,336 Posts
                      BTW my $_REQUEST params are template id and doc id string, and
                      $_REQUEST[’action’],which is how MODx knows what file to reach.
                      won’t work in the modmangerresponse class as it needs an integer so it can map this to an action, not a file to include.
                        Use MODx, or the cat gets it!