Forums / Developer / How to fetch drafts ?

How to fetch drafts ?

Author Message

Samuel Torton

Monday 11 October 2010 8:56:08 am

Hello,

I would like to fetch all contents with "draft" status, and especially all drafts in a specific parent node.

I feel a bit embarrassed, because I've read the following note, regarding the "fetch (section, object_list ...":

"Note that fetching all draft objects that belong to a certain section is not supported"

Thus, what would be a nice workaround ?

Thanks a lot for your answers.

Samuel Torton

Heath

Monday 11 October 2010 3:27:48 pm

Hello Again Samuel,

It sure sounds like fetching all draft objects is not provided by the built-in fetch functions.

Perhaps you could create your own custom fetch function which does provide this feature?

Cheers,

Heath

Brookins Consulting | http://brookinsconsulting.com/
Certified | http://auth.ez.no/certification/verify/380350
Solutions | http://projects.ez.no/users/community/brookins_consulting
eZpedia community documentation project | http://ezpedia.org

kracker (the)

Monday 11 October 2010 3:44:09 pm

Hello,

I think in a case like this I would learn from the content/draft module view and template code.

I would create your own custom fetch function to be similar in design to the draft_version_list.

http://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Modules/content/Fetch-functions/draft_version_list

The following snippet is from, kernel/content/ezcontentfunctioncollection.php

static public function fetchDraftVersionList( $offset, $limit )    {        $userID = eZUser::currentUserID();        $draftVersionList =  eZPersistentObject::fetchObjectList( eZContentObjectVersion::definition(),                                                                   null, array(  'creator_id' => $userID,                                                                                 'status' => eZContentObjectVersion::STATUS_DRAFT ),                                                                   array( 'modified' => true,                                                                          'initial_language_id' => true ),                                                                   array( 'length' => $limit, 'offset' => $offset ),                                                                   true );        return array( 'result' => $draftVersionList );    }
static public function fetchDraftVersionList( $offset, $limit )    {        $userID = eZUser::currentUserID();        $draftVersionList =  eZPersistentObject::fetchObjectList( eZContentObjectVersion::definition(),                                                                   null, array(  'creator_id' => $userID,                                                                                 'status' => eZContentObjectVersion::STATUS_DRAFT ),                                                                   array( 'modified' => true,                                                                          'initial_language_id' => true ),                                                                   array( 'length' => $limit, 'offset' => $offset ),                                                                   true );        return array( 'result' => $draftVersionList );    }

I would first fetch all users and then per user iterate over their draft list as desired. Bingo problem solved.

This is also a good article about how to create custom fetch functions.

http://share.ez.no/learn/ez-publish/understanding-and-developing-fetch-functions

Cheers,

//kracker

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

Samuel Torton

Monday 11 October 2010 4:16:34 pm

Hello Heath,

Yes, today I could create my own functions based on the code you mentioned, and I was successful ! ;-)

(solution: function fetchDraftVersionList_in_a_node(): I've removed the user_id parameter, and added parent_node_id in order to fetch into a specific node)

Thus I went further into my project.

Now, I'm facing another problem ! ;-)

Ezpublish doesn't allow users to edit other users drafts.

Thus I thought it could be possible to copy one draft to a second draft, but... the second draft is loosing the original parent id because this new draft is not linked to any contentobject_id ! :-(

My objective is to allow people editing the same draft, without sending it for publication, for instance:

. user1 creates a new object, he starts editing it, and he saves it as a draft without sending for publication (= draft v1);

. user2 edits and modifies this draft... and saves it again as a draft (= draft v2);

... and so on ... (= draft v7)

. and then, user3 edits and modifies this "draft v7"... and send it for publishing;

I would really want ezpublish to allow a user to edit another user's draft.

I keep investigating and search for a solution... if you have hints, I'm interested.

Thank you.

Samuel Torton

Heath

Monday 11 October 2010 5:06:30 pm

Samuel,

The default content module is limited in this regard.

I strongly suggest you look further into ezapprove2 which provides for editing of other peoples drafts before actual publish.

Otherwise you may find yourself having to build your own custom module view to provide the features you need.

There is no simple solution if you can't change your requirements to fit ezapprove2.

Cheers,

Heath

Brookins Consulting | http://brookinsconsulting.com/
Certified | http://auth.ez.no/certification/verify/380350
Solutions | http://projects.ez.no/users/community/brookins_consulting
eZpedia community documentation project | http://ezpedia.org

Samuel Torton

Tuesday 12 October 2010 1:50:25 am

Heath,

Yes, I have to say I'm limited with the default content module.

Before going any further with a custom solution, I'll try to get back to eZApprove2.

But eZApprove2 doesn't seem to work with eZp4: I can create a new workflow with a new "event/ezapprove2", but I cannnot configure it...

I will post again on the eZApprove2 forum.

Thank you for your help.

Samuel Torton

Heath

Tuesday 12 October 2010 2:04:59 am

Samuel,

I am using the very same eZApprove2 to power another eZ Publish 4.x site.

So your installation may need help but the extension software is fairly solid.

Best to post to the project forum though.

Cheers,

Heath

Brookins Consulting | http://brookinsconsulting.com/
Certified | http://auth.ez.no/certification/verify/380350
Solutions | http://projects.ez.no/users/community/brookins_consulting
eZpedia community documentation project | http://ezpedia.org

Samuel Torton

Tuesday 12 October 2010 6:01:44 am

Hi Heath,
I found the solution!
There is a bug in the "affected section" template.
The solution is here:
http://projects.ez.no/ezapprove2/forum/general/problem_saving_affected_sections
Then I started testing this extension, and seems to meet my requirements, thank you !
Now, I'm facing another issue.
If I select "Users select approvers themselves" parameter in my event/approve2.
When an editor modifies a content, as soon as he sends article for publication, there is an interface asking him to select users.... and when clicks on "select users", there is a kernel_error: not authorized to access this page.
What rule/policy do I have to activate to give them access ?
Thank you.

Samuel Torton