We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3689
    • 264 Posts
    Thanks so much! This was 1 of the most important features I needed to get my site up and running smiley Thanks again!! grin grin
      • 3749
      • 24,544 Posts
      Good work! laugh

      Is this a great community, or what?
        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
        • 3689
        • 264 Posts
        Quote from: BobRay at Jan 24, 2010, 12:55 PM

        Good work! laugh

        Is this a great community, or what?

        the best! smiley
          • 33968
          • 863 Posts
          I was pulling my hair out with this one... tried the same code as above and whenever I tested it the document just disappeared instead of moving under the new parent >:(

          But I’ve realised that the parent needs to be published as a container otherwise it will not work. Sure enough, I changed the target parent to a container and all my test documents were there smiley

          Is there any way we could have the plugin check to see if the target parent is already a container, and if not, set it to be a container? I’m using the plugin in a slightly different context and the parents will often not be set as containers. Does that make sense?

          Cheers, Luke
            • 4172
            • 5,888 Posts
            perhaps something like that will do it:

            <?php//remove this line, only for sytnax-highlighting
            $rs=$modx->db->select('id',$modx->getFullTablename('site_tmplvars'),'name="status"');
            $row=$modx->db->getRow($rs);
            //$modx->logEvent('1','1',print_r($_POST['tv'.$row['id']],true));
            if (in_array($_POST['tv'.$row['id']], array ('4', '34', '27')))
            {
                $parent = $_POST['tv'.$row['id']];
            
                if ($parent !== $_POST['parent'])
                {
                    //make sure parent is container and published:
                    $modx->db->update( array ('isfolder'=>'1', 'published'=>'1'), $modx->getFullTablename('site_content'), 'id='.$parent);
                    //move resource to new container:
                    $modx->db->update( array ('parent'=>$parent), $modx->getFullTablename('site_content'), 'id='.$params['id']);
                }
            }
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 33968
              • 863 Posts
              Bruno thanks for your quick response.

              I’ve tried it but get the following error:
              MODx encountered the following error while attempting to parse the requested resource:
              « Execution of a query to the database failed - Unknown column 'folder' in 'field list' »
                    SQL: UPDATE `mod`.`modx_site_content` SET folder='1',published='1' WHERE id=11 


              Should ’folder’ be something else?
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                isfolder

                I don’t think it has to be published, it’s just that isfolder is used when building the Tree display.
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 33968
                  • 863 Posts
                  Great! Thanks both of you for your help, here’s the final working solution:
                  <?php//remove this line, only for sytnax-highlighting
                  $rs=$modx->db->select('id',$modx->getFullTablename('site_tmplvars'),'name="status"');
                  $row=$modx->db->getRow($rs);
                  //$modx->logEvent('1','1',print_r($_POST['tv'.$row['id']],true));
                  if (in_array($_POST['tv'.$row['id']], array ('4', '34', '27')))
                  {
                      $parent = $_POST['tv'.$row['id']];
                  
                      if ($parent !== $_POST['parent'])
                      {
                          //make sure parent is container and published:
                          $modx->db->update( array ('isfolder'=>'1', 'published'=>'1'), $modx->getFullTablename('site_content'), 'id='.$parent);
                          //move resource to new container:
                          $modx->db->update( array ('parent'=>$parent), $modx->getFullTablename('site_content'), 'id='.$params['id']);
                      }
                  }


                    • 8921
                    • 55 Posts
                    For the life of me, I cannot get this to work. I have spent *hours* trying. Is the above code just not compatible with Revo 2.2.4?

                    What happens: after creating this plugin, when I have "OnDocFormSave" checked, I can no longer save *any* resource on the site. I get the endless "Saving" progress bar. If I uncheck "OnDocFormSave", I can save resources again but of course can't use the plugin. Here's the weird part: even if I have the plugin disabled, it will still prevent resources from saving if I have "OnDocFormSave" checked. Nothing shows up in the error log either.

                    Any ideas? Thanks.
                      • 3749
                      • 24,544 Posts
                      Yes, that's a two-year-old message and the code is for MODX Evolution. I'm not sure what the Revolution code would look like for that.

                      You're more likely to get help if you start a new thread, since this one is marked as solved.


                      ------------------------------------------------------------------------------------------
                      PLEASE, PLEASE specify the version of MODX you are using.
                      MODX info for everyone: http://bobsguides.com/modx.html
                        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