how to edit date/time when published/editing a article ?

Author Message

Alexandre Cunha

Monday 21 August 2006 11:05:31 am

Hi

There is any suggestion how to allow the user edit the publish/modified date/time of a article?
Something like we have now when creating a article: we can edit the author name.

Why need this:

The person who is responsable to manage the content of a site, needs move the content from a old site (non ezp) to a new site (with ezp).
This site have news and articles. Moving to the new site, the news and articles need have the same date and time as published on older site.
This can me done by the editor (dont need any export / import solution)

thank for your sugestions.

ac

http://AlexandreCunha.com

Marcin Drozd

Tuesday 22 August 2006 1:14:27 am

Hi
Maybe add a new attribute (datetime) to article class, and change tpl

http://ez-publish.pl

Xavier Dutoit

Tuesday 22 August 2006 5:20:40 am

Hi,

I wrote an extension do to it a while ago.

Unfortunately, this extension does a lot of other stuff, that aren't made to be public (mostly debug/dev tools).

Could you contact me privately to discuss the easiest way to collaborate on that ? (xavier at sydesy dot com )

X+

http://www.sydesy.com

Alexandre Cunha

Thursday 24 August 2006 8:47:52 am

<quote>
Hi
Maybe add a new attribute (datetime) to article class, and change tpl
</quote>

Well, this is one of the possible solutions.

Im considering 3 solutions:

1 - Change the class. This is the most dificult because need change templates and "break" the original relation with date/time stored in databse

2 - Dont change the class, but find a way to change the template (admin template) to alow edit a propriety (date/time) of the content not stored in the class. I like this solution but I dont know if this can be done with a extension or changing the code of ezpubish. If need change the code of ezp, I dont like this.

3 - A "external" option (new option ? can use a extension ?) that allow user browse the content and edit the date/time of any object. I prefer this, but really dont know how to do this.

Any help is apreciated.

Thank you

http://AlexandreCunha.com

Claudia Kosny

Thursday 24 August 2006 12:59:36 pm

Hi Alexandre

My first idea is to give this class an attribute where your editors can insert the original published time. Then write a script that goes through all objects, fetches the value of this attribute set the published attribute of the content object to this value. Run this script as a cronjob once your editors are done or how often you want.
An better idea would be to do this on the publish workflow but unfortunately I have no idea of workflows yet...
Possible problems:
- I am not sure whether it is this published attribute that is used for sorting. The different versions that each content object consists of also hold their created and modified date so you might have to change these attributes. I frankly also have no clue whether EZ will cope with setting the published date manually to the past, but I right now I don't think there will be problems with this.
- If you run the script very often it might cause a lot of stress on the server unless you are very specific which nodes to fetch and update. So make sure you fetch only the nodes whose published date still needs to be updated if possible.

A rough outline of such a script is below. As usual with me I have not tested it so there might be lots of typos and maybe some major flaws, so don't try it on your live database... It still should give you a general idea on what to do.

$offset = 0;
$limit = 50;

//this is the identifier of the class attribute that contains your date
$originalDateAttribute='original_publishdate';

$rootNode = eZContentObjectTreeNode::fetch(2);
while(true)
{
  //try to to limit the number of fetches nodes as far as you can, 
  //e.g. by specifying certain classes and attributes  values
  //e.g if you run this script every hour you just need the nodes that 
  //were created in this last hour (plus a few minutes for processing time)
  $nodeArray =& $rootNode->subTree( array('ClassFilterType' => 'include',
                                          'ClassFilterArray' => array('articles'),
                                          'Offset' => $offset,
                                          'Limit' => $limit));
   //break if there are no more nodes                                       
   if (!$nodeArray || count( $nodeArray ) == 0)
   {
     break;
   }

   $offset += $limit;

   //now go through each fetched node,create a new version of the content 
   //and set the published date of this version
   foreach (array_keys( $nodeArray ) as $key )
   {
     $node    =& $nodeArray[$key];
     
     //fetch the content of your date attribute
     $dataMap       =& $node->attribute('data_map');
     $dateAttribute =& $dataMap[$originalDateAttribute];

     if (is_null($dateAttribute) || !$dateAttribute->hasContent())
     {
       continue;
     }
     
     $originalDateObj = $dateAttribute->content();
     $originalDate    = $originalDateObj->attribute('timestamp');
     
     //if there is a date, set the published attrib of the contentobject accordingly and store it.
     if ($originalDate)
     {
       $contentObject =& $node->ContentObject;       
       $contentObject->setAttribute('published', $originalDate);       
       $contentObject->store();
     }
   }
}

If you don't want to have an additional date attribute in your class (which you will not need once everything is done after all), you can also create an extension that displays a form where each node has a input field forthe new date assigned to it. Then just post the form to a script which does roughly the same as above, you just have to fetch the nodes whose data was posted and update the published attribute with the posted value.

Greetings from Luxembourg

Claudia

Kristof Coomans

Thursday 24 August 2006 11:03:31 pm

One little thing to add after the object is stored:

// Clean up content cache
include_once( 'kernel/classes/ezcontentcachemanager.php' );
eZContentCacheManager::clearContentCache( $contentObject->attribute( 'id' ) );

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

H-Works Agency

Monday 20 November 2006 3:09:49 pm

Its a little of topic but here is how to manually change an object publish/modified datetime in ezp > 3.8.x

In table ezcontentobject search in name field for you object ("%name%")

You will have a row of you matching object.

You have two fields : modified and published.

Edit those fields with your new time.

Clear content cache then order will be changed

EZP is Great

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.