Forums / Setup & design / Old content and published date

Old content and published date

Author Message

Bruce Morrison

Monday 07 April 2003 12:29:54 am

We are developing a number of sites using ezpublish where we are taking an existing web site and it's content and converting it to an ezpublish solution. The problem is that there is many content types that have a published date that is required to be displayed and in most cases this needs to be set in the past.

To accomidate this we have created a content class with a published attribute. The trouble is that we can't order a list of content by an attribute. This can only be done using the meta data associated with a given node.

One of the metadata attributes is 'published' I am thinking of creating some workflow to set the metadata "published' attribute to the node published attribute.

Does anyone else have this issue and have come up with a solution?

Am I on the right track with a workflow solution?

Thanks
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Sergiy Pushchin

Monday 07 April 2003 3:00:15 am

Yes I think the workflow solution is ok for it, but you should assume that you need to connect that workflow to after publish trigger. Another problem here is that we have not tested a lot post operation triggers, but it should work fine.

Conrad Decker

Monday 17 January 2011 8:21:11 am

I'm currently attempting to accomplish the same thing where we're importing content from an older site and for display purposes, the publish dates need to be set to a date in the past. Is this possible?

It doesn't seem to be so using the createAndPublishObject methods, but I'm hoping there's an easy way to do this with the API nowadays?

Any and all help is extremely appreciated.

Thanks!

Peter Keung

Monday 17 January 2011 9:10:55 am

Our import logic (from data_import extension; sqliimport extension might have similar logic too) usually creates the object, then runs these as necessary:

// Set the created date if the source handler has implemented logic for it
        $createdDate = $this->source_handler->getCreatedDate();
        if( $createdDate !== false )
        {
            $this->current_eZ_object->setAttribute( 'published', $createdDate );
  }
        
        // Set the modified date if the source handler has implemented logic for it
        $modifiedDate = $this->source_handler->getModifiedDate();
        if( $modifiedDate !== false )
        {
            $this->current_eZ_object->setAttribute( 'modified', $modifiedDate );
        }

Then, we store the object and publish the node.

http://www.mugo.ca
Mugo Web, eZ Partner in Vancouver, Canada

Conrad Decker

Monday 24 January 2011 3:30:12 pm

Thanks for the info Peter.

I ended up having to dig a little further to figure this one out, but found some similar code in the cronjobs/rssimport.php file. For anyone that's interested, here's what I ended up with. Would be curious if anyone sees anything wrong with this, or if there's a better way to accomplish it.

So, after my initial createAndPublishObject call, I proceeded with this:

$contentObject = eZContentFunctions::createAndPublishObject( $params );<span> </span>

$db = eZDB::instance();            
$db->begin();                        

$object  = eZContentObject::fetch( $contentObject->attribute('id') );            
$version = $object->attribute('current');
           
$object->setAttribute( 'published', strtotime($date) );            
$version->setAttribute( 'created', strtotime($date) );

$object->setAttribute( 'modified', strtotime($date) );            
$version->setAttribute( 'modified', strtotime($date) );
          
$version->store();            
$object->store();                       

$db->commit();

Hopefully this will save someone some time down the road...