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
|