We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    I’m probably off base here, but I was looking at the runProcessor() code and I’m wondering if it might make sense to reverse things in the array_merge().

    I would think that if the user is sending fields in the $scriptProperties array, we’d want them to take precedence over fields in the $_POST array.

    For example, if a form is submitted and you want to massage the $_POST values, say date and TV values, before running resource/create or resource/update, it seems more intuitive to me to put them in the $scriptProperties array rather than modifying the $_POST array directly (which you might want unchanged in some situations).

      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
      • 22303 MODX Staff
      • 10,725 Posts
      In general, I would want the user input to override my set configuration, so I don’t agree the merge should be reversed.

      That said, IMO, it should only be using scriptProperties directly, and the developer should decide how they want to deal with user input from GPC vars or CLI and just pass the scriptProperties pre-merged as needed. IOW, there should be no expectation in this method of GPC variables being available for merging. This will give users full control over such matters.
        • 3749
        • 24,544 Posts
        I’m not sure I’m following you. Are you suggesting taking the $_POST array out of the processing in runProcessor() altogether? That would match what I was expecting to find there. I was surprised to find the $_POST being used at that level.

        At present, pre-merging the $scriptProperties won’t do anything if the $_POST array is unchanged, no?
          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
          • 22303 MODX Staff
          • 10,725 Posts
          Quote from: BobRay at Dec 13, 2010, 02:07 AM

          I’m not sure I’m following you. Are you suggesting taking the $_POST array out of the processing in runProcessor() altogether? That would match what I was expecting to find there. I was surprised to find the $_POST being used at that level.
          Correct, it should simply accept the scriptProperties and leave them alone IMO.

          Quote from: BobRay at Dec 13, 2010, 02:07 AM

          At present, pre-merging the $scriptProperties won’t do anything if the $_POST array is unchanged, no?
          Correct, the $_GET and $_POST (and $_FILES) would override the scriptProperties...
            • 3749
            • 24,544 Posts
            Quote from: OpenGeek at Dec 13, 2010, 08:05 AM

            Quote from: BobRay at Dec 13, 2010, 02:07 AM

            I’m not sure I’m following you. Are you suggesting taking the $_POST array out of the processing in runProcessor() altogether? That would match what I was expecting to find there. I was surprised to find the $_POST being used at that level.
            Correct, it should simply accept the scriptProperties and leave them alone IMO.

            We’re on the same page, then. It should be more secure that way as well.

            How about calling it $fields in runProcessor() instead of $scriptProperties?
              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
              • 28215
              • 4,149 Posts
              Because that’d be against the standards we’ve set (similar to Snippets), and $fields is improper, since the values passed in may not always be "fields".
                shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                • 3749
                • 24,544 Posts
                Quote from: splittingred at Dec 13, 2010, 08:47 PM

                Because that’d be against the standards we’ve set (similar to Snippets), and $fields is improper, since the values passed in may not always be "fields".

                They won’t necessarily be script properties either, from the point of view of the caller. I just thought it was confusing since users will most often call them from a snippet and in most cases, they’re not sending along the snippet’s $scriptProperties array. If FormIt or Login end up calling processors, they’re not going to send their $scriptProperties array in the call. Also, the processors don’t have any default properties or property sets associated with them (that I know of), so you’re not sending *their* script properties either.

                Maybe there’s something I’m not getting, but to me $scriptProperties makes sense for objects that have properties, such as snippets, but using it elsewhere dilutes the meaning semantically to something like: "any array used by a script."

                It’s always better if function argument names make sense on both ends, but if that’s not possible, they shouldn’t be named for something else that you’re already using in a snippet, IMO.
                  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
                  • 11055 ☆ A M B ☆
                  • 3,112 Posts
                  Sorry for jumping in the middle of discussion...
                  Are you guys talking about this?

                  <?php // highlight
                  
                  $scriptProperties['name'] = $modx->getOption('name', $scriptProperties, $_POST['name']);
                  
                    Rico
                    Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                    MODx is great, but knowing how to use it well makes it perfect!

                    www.virtudraft.com

                    Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

                    Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

                    Maintainter/contributor of Babel

                    Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
                    • 3749
                    • 24,544 Posts
                    Quote from: goldsky at Dec 13, 2010, 10:34 PM

                    Sorry for jumping in the middle of discussion...
                    Are you guys talking about this?

                    <?php // highlight
                    
                    $scriptProperties['name'] = $modx->getOption('name', $scriptProperties, $_POST['name']);
                    


                    No, we’re talking about the arguments to the MODx class’s runProcessor() method.
                      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
                      • 11055 ☆ A M B ☆
                      • 3,112 Posts
                      Got your post on the other thread.
                      This is not the right solution, roughly?

                      <?php
                      $pagetitle = $modx->getOption('pagetitle', $scriptProperties, $_POST['pagetitle']);
                      $published = $modx->getOption('published', $scriptProperties, $_POST['published']);
                      $content = $modx->getOption('content', $scriptProperties, $_POST['content']);
                      
                      $response = $modx->runProcessor('resource/create',array(
                        'pagetitle' => $pagetitle,
                        'published' => $published ,
                        'content' => $content,
                        /* etc */
                      ));
                      if ($response->isError()) {
                        if ($response->hasFieldErrors()) {
                            $fieldErrors = $response->getAllErrors();
                            $errorMessage = implode("\n",$fieldErrors);
                        } else {
                            $errorMessage = 'An error occurred: '.$response->getMessage();
                        }
                        return $errorMessage;
                      }
                      return 'Success!';
                      
                        Rico
                        Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                        MODx is great, but knowing how to use it well makes it perfect!

                        www.virtudraft.com

                        Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

                        Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

                        Maintainter/contributor of Babel

                        Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.