We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4310
    • 2,310 Posts
    I had to do something similar and ended up using this function :
    function emptyCache() {
    	global $modx;
    	include_once $modx->config['base_path']."manager/processors/cache_sync.class.processor.php";
    	$sync = new synccache();
    	$sync->setCachepath("assets/cache/");
    	$sync->setReport(false);
    	$sync->emptyCache();
    }

    And called it after inserting the page date in to the DB.
      • 36533
      • 65 Posts
      I had tried something similar and couldn't get it to work. Does this look correct?

      if($mode=="new"){ 
          $wuid = $username;
          $table_name = $modx->getFullTableName( 'site_content' );
          $fields = array(
                              'type'  =>  'document',
                  'contentType'   => 'text/html',
                  'pagetitle' => $wuid,
                  'alias'     => $wuid,
                  'published' => '1', //is the page published?
                  'parent'    => '16', //what is the parent of this new page?
                  'isfolder'  => '0', // lets make this a folder
                  'template'  => '15', //type template id here
                  'cacheable' => '0',
                  'createdby' => $wuid,
                  'createdon' => time(),
                  'editedon'  => time(),
                  'publishedon'   => time(),
                  'hidemenu'  => '1'
                  );
      
          $modx->db->insert( $fields, $table_name); // put the fields in the db (id wil be created incremental.)
       
          //Create  placeholder and put the id in a session to use for mail or whatever.
          $_SESSION['eigenpaginaid'] =  $modx->db->getInsertId();
          $modx->setPlaceholder('eigenpaginaid', $modx->db->getInsertId());
      
          return;
      }
      function emptyCache() {
          global $modx;
          include_once $modx->config['base_path']."manager/processors/cache_sync.class.processor.php";
          $sync = new synccache();
          $sync->setCachepath("assets/cache/");
          $sync->setReport(false);
          $sync->emptyCache();
          
          return;
      }
      
        • 36533
        • 65 Posts
        bunk, that doesn't seem to work for me.

        A suggestion to store the id in a session and then redirecting to a page sounded like the solution in a few other threads... I found this in NewsPublisher, but am not sure how to apply it to my original plugin code. Unfortunately, I'm a bit new to PHP here.. so I'm probably fumbling around a bit.

        Any help on how to apply this to my plugin?

        public function forward($postId) {
                    if (empty($postId)) {
                        $postId = $this->existing? $this->existing : $this->resource->get('id');
                    }
                    /* clear cache on new resource */
                    if (! $this->existing) {
                       $cacheManager = $this->modx->getCacheManager();
                       $cacheManager->clearCache(array (
                            "{$this->resource->context_key}/",
                        ),
                        array(
                            'objects' => array('modResource', 'modContext', 'modTemplateVarResource'),
                            'publishing' => true
                            )
                        );
                    }
        
                    $_SESSION['np_resource_id'] = $this->resource->get('id');
                    $goToUrl = $this->modx->makeUrl($postId);
        
                    /* redirect to post id */
        
                    /* ToDo: The next two lines can probably be removed once makeUrl() and sendRedirect() are updated */
                    $controller = $this->modx->getOption('request_controller',null,'index.php');
                    $goToUrl = $controller . '?id=' . $postId;
        
                    $this->modx->sendRedirect($goToUrl);
                }


        - to this -

        if($mode=="new"){ 
            $wuid = $username;
            $table_name = $modx->getFullTableName( 'site_content' );
            $fields = array(
                                'type'  =>  'document',
                    'contentType'   => 'text/html',
                    'pagetitle' => $wuid,
                    'alias'     => $wuid,
                    'published' => '1', //is the page published?
                    'parent'    => '16', //what is the parent of this new page?
                    'isfolder'  => '0', // lets make this a folder
                    'template'  => '15', //type template id here
                    'cacheable' => '0',
                    'createdby' => $wuid,
                    'createdon' => time(),
                    'editedon'  => time(),
                    'publishedon'   => time(),
                    'hidemenu'  => '1'
                    );
         
            $modx->db->insert( $fields, $table_name); // put the fields in the db (id wil be created incremental.)
          
            //Create  placeholder and put the id in a session to use for mail or whatever.
            $_SESSION['eigenpaginaid'] =  $modx->db->getInsertId();
            $modx->setPlaceholder('eigenpaginaid', $modx->db->getInsertId());
         
            return;
        }
          • 3749
          • 24,544 Posts
          Actually, what NewsPublisher does (and what worked for me in Revolution) is this:

          $modx->sendRedirect('index.php?id='. $forwardId);


            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
            • 4310
            • 2,310 Posts
            I can't see that you ever ran the function i.e. line 26
            if($mode=="new"){ 
                $wuid = $username;
                $table_name = $modx->getFullTableName( 'site_content' );
                $fields = array(
                                    'type'  =>  'document',
                        'contentType'   => 'text/html',
                        'pagetitle' => $wuid,
                        'alias'     => $wuid,
                        'published' => '1', //is the page published?
                        'parent'    => '16', //what is the parent of this new page?
                        'isfolder'  => '0', // lets make this a folder
                        'template'  => '15', //type template id here
                        'cacheable' => '0',
                        'createdby' => $wuid,
                        'createdon' => time(),
                        'editedon'  => time(),
                        'publishedon'   => time(),
                        'hidemenu'  => '1'
                        );
             
                $modx->db->insert( $fields, $table_name); // put the fields in the db (id wil be created incremental.)
              
                //Create  placeholder and put the id in a session to use for mail or whatever.
                $_SESSION['eigenpaginaid'] =  $modx->db->getInsertId();
                $modx->setPlaceholder('eigenpaginaid', $modx->db->getInsertId());
             emptyCache();
                return;
            }
            function emptyCache() {
                global $modx;
                include_once $modx->config['base_path']."manager/processors/cache_sync.class.processor.php";
                $sync = new synccache();
                $sync->setCachepath("assets/cache/");
                $sync->setReport(false);
                $sync->emptyCache();
                 
                return;
            }
              • 3749
              • 24,544 Posts
              This is what NewsPublisher does (more or less) when creating a new page:
                    // $fields holds the resource fields as in your code + this one:
                    $fields['syncsite'] = true;
              
                    $response = $modx->runProcessor('resource/create', $fields);
              
                    if ($response->isError()) {
                          if ($response->hasFieldErrors()) {
                              $fieldErrors = $response->getAllErrors();
                              $errorMessage = implode("\n", $fieldErrors);
                          } else {
                              $errorMessage = 'An error occurred: ' . $response->getMessage();
                          }
                          $this->setError($errorMessage);
                          return '';
              
                      } else {
                          $object = $response->getObject();
                          $postId = $object['id'];
                      }
              
              $controller =$modx->getOption('request_controller',null,'index.php');
              $goToUrl = $controller . '?id=' . $postId;
              $modx->sendRedirect($goToUrl);
              [ed. note: BobRay last edited this post 15 years 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
                • 3749
                • 24,544 Posts
                Oops. I was wrong. NewsPublisher now does this:

                https://forums.modx.com/thread/70991/auto-generated-pages-on-websignup-not-working-with-case-sensitive?page=2#dis-post-396807


                The code in the previous post worked, but without FURLs. [ed. note: BobRay last edited this post 15 years 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
                  • 20413
                  • 2,877 Posts
                    @hawproductions | http://mrhaw.com/

                    Infograph: MODX Advanced Install in 7 steps:
                    http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                    Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                    http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower