We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40225
    • 4 Posts
    I updated to the latest version of modx revolutions (2.2.4-pl)
    But it seems that the pub_date be ignored... nothing happens.

    Does anybody else have this problem? How can i fix that?

    Regard...
      • 22303 MODX Staff
      • 10,725 Posts
      I just tested this with a 2.2.4-pl installation and had no problem accessing the resource once the time indicated by pub_date passed. Can you describe what is happening in more detail?
        • 9241
        • 42 Posts
        We currently have 2.2.0-pl2 installation which does the same.

        I programmatically creates resources and then sets the pub_date. The resource is part of 'n list which wayfinder loads. The resource then never gets added to the wayfinder/menu list even if it's beyond the pub_date.

        Only time it actually displays it, is if I go into the resources in the manager and resave the resource, then it auto published it. This defeats the purposes as I would suspect it is suppose to publish it without intervention, or is my assumption wrong?
          • 22303 MODX Staff
          • 10,725 Posts
          Quote from: EvoBunny at Jul 05, 2012, 08:30 AM
          I programmatically creates resources and then sets the pub_date. The resource is part of 'n list which wayfinder loads. The resource then never gets added to the wayfinder/menu list even if it's beyond the pub_date.
          My first guesses would be perhaps you are not programmatically creating the Resource correctly, or, your Wayfinder calls are caching results that are not getting updated when the auto_publishing activity occurs. Are you using multiple Contexts by chance?
            • 9241
            • 42 Posts
            Quote from: opengeek at Jul 05, 2012, 08:48 AM
            Quote from: EvoBunny at Jul 05, 2012, 08:30 AM
            I programmatically creates resources and then sets the pub_date. The resource is part of 'n list which wayfinder loads. The resource then never gets added to the wayfinder/menu list even if it's beyond the pub_date.
            My first guesses would be perhaps you are not programmatically creating the Resource correctly, or, your Wayfinder calls are caching results that are not getting updated when the auto_publishing activity occurs. Are you using multiple Contexts by chance?

            When calling wayfinder did put in the ! so that it doesn't load the cached version, i.e.
            [[!WayFinder?...]]


            We are only using one context which is the default 'web' context.

            My steps when creating the resources is as follow:

            $resource = $event->getOne('Resource');
            
            if (!is_object($resource)) {
            	$resource = $modx->newObject('modResource');
            	$resource->set('createdby', $modx->user->get('id'));
            	$resource->set('createdon', $currentDate->getTimestamp());
            	$resource->set('parent', 15);
            	$resource->set('template', 6);
            	$resource->set('published', 0);
            	$event->addOne($resource);
            } else {
            	$resource->set('editedby', $modx->user->get('id'));
            	$resource->set('editedon', $currentDate->getTimestamp());
            }
            
            $resource->set('pagetitle', $name);
            $resource->set('alias', $resource->cleanAlias($resource->get('pagetitle')));
            $date = new DateTime($publishDate);
            $resource->set('pub_date', $date->getTimestamp());
            


            The resource is an aggregate of the event object and the event object is saved later down the line. Should I be saving the resource object first? Or is that not necessary?
              • 22303 MODX Staff
              • 10,725 Posts
              First, you need to create a valid modResource derivative: modDocument, modWebLink, modSymLink, modStaticResource, etc. I imagine resaving these in the manager is correcting the class_key on the records.

              Second, you should never call Wayfinder uncached IMO. The auto_publishing mechanism will refresh the cache.
                • 9241
                • 42 Posts
                So I should create the resource with:
                $resource = $modx->newObject('modDocument');
                


                or should I just set the class_key:
                $resource->set('class_key', 'modDocument');
                


                Isn't it by default setting the class_key to modDocument?

                I'll make the Wayfinder uncached.
                  • 22303 MODX Staff
                  • 10,725 Posts
                  Use
                  $resource = $modx->newObject('modDocument');

                  You need to instantiate the proper class at the point you are creating new instances so that the proper code is executed in the proper derivative class on save(); these derivatives override the behavior of the base modResource class methods. When retrieving instances using
                  $modx->getObject('modResource')

                  xPDO automatically looks at the class_key field to instantiate the proper derivative class itself. This is not possible when creating a new instance via newObject() because the data does not yet exist.
                    • 9241
                    • 42 Posts
                    Ah ok, thanks! Will try it and give feedback if it worked or not. Hopefully it solves the problem.
                      • 9241
                      • 42 Posts
                      I've changed it from modResource to modDocument, removed the ! from the Wayfinder snippet calls in the templates to make them cached and it didn't work.

                      What I did find however is that when I saved (and consequently modx cleared the cache) the template, it did auto publish the resources/documents.

                      Is there possibly a cache issue which might be causing this?