Commit b852a826 authored by Julien Muchembled's avatar Julien Muchembled

Fix document ingestion so that no workflow method is called when the...

Fix document ingestion so that no workflow method is called when the transition doesn't exist for the current state.
This is mainly done by removing 'edit' transition on processing_workflow, to prevent duplicate processing of ingestion.
Reuse edit_workflow for all portal types with processing_status_workflow and update computation of revision (Document.getRevision).


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27896 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ebcbc202
...@@ -5,19 +5,19 @@ ...@@ -5,19 +5,19 @@
</chain> </chain>
<chain> <chain>
<type>Drawing</type> <type>Drawing</type>
<workflow>local_permission_interaction_workflow, processing_status_workflow, document_interaction_workflow, document_publication_workflow</workflow> <workflow>local_permission_interaction_workflow, edit_workflow, processing_status_workflow, document_interaction_workflow, document_publication_workflow</workflow>
</chain> </chain>
<chain> <chain>
<type>File</type> <type>File</type>
<workflow>-edit_workflow, document_publication_workflow, document_interaction_workflow, local_permission_interaction_workflow, processing_status_workflow</workflow> <workflow>document_publication_workflow, document_interaction_workflow, local_permission_interaction_workflow, processing_status_workflow</workflow>
</chain> </chain>
<chain> <chain>
<type>Image</type> <type>Image</type>
<workflow>-edit_workflow, document_interaction_workflow, document_publication_workflow, processing_status_workflow, local_permission_interaction_workflow</workflow> <workflow>document_interaction_workflow, document_publication_workflow, processing_status_workflow, local_permission_interaction_workflow</workflow>
</chain> </chain>
<chain> <chain>
<type>PDF</type> <type>PDF</type>
<workflow>local_permission_interaction_workflow, processing_status_workflow, document_interaction_workflow, document_publication_workflow</workflow> <workflow>local_permission_interaction_workflow, edit_workflow, processing_status_workflow, document_interaction_workflow, document_publication_workflow</workflow>
</chain> </chain>
<chain> <chain>
<type>Person</type> <type>Person</type>
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
</chain> </chain>
<chain> <chain>
<type>Presentation</type> <type>Presentation</type>
<workflow>document_publication_workflow, local_permission_interaction_workflow, processing_status_workflow, document_interaction_workflow</workflow> <workflow>document_publication_workflow, local_permission_interaction_workflow, processing_status_workflow, document_interaction_workflow, edit_workflow</workflow>
</chain> </chain>
<chain> <chain>
<type>RSS Feed</type> <type>RSS Feed</type>
...@@ -33,11 +33,11 @@ ...@@ -33,11 +33,11 @@
</chain> </chain>
<chain> <chain>
<type>Spreadsheet</type> <type>Spreadsheet</type>
<workflow>document_interaction_workflow, processing_status_workflow, document_publication_workflow, local_permission_interaction_workflow</workflow> <workflow>edit_workflow, document_interaction_workflow, processing_status_workflow, document_publication_workflow, local_permission_interaction_workflow</workflow>
</chain> </chain>
<chain> <chain>
<type>Text</type> <type>Text</type>
<workflow>processing_status_workflow, local_permission_interaction_workflow, document_publication_workflow, document_interaction_workflow</workflow> <workflow>processing_status_workflow, local_permission_interaction_workflow, document_publication_workflow, edit_workflow, document_interaction_workflow</workflow>
</chain> </chain>
<chain> <chain>
<type>URL Crawler</type> <type>URL Crawler</type>
......
...@@ -53,15 +53,16 @@ ...@@ -53,15 +53,16 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>object = state_change[\'object\']\n <value> <string>document = state_change[\'object\']\n
object.uploadFile()\n document.uploadFile()\n
\n \n
# do not activate conversion if the object is in portal_contributions\n # do not activate conversion if the object is in portal_contributions\n
# because it will be gone from there in a second\n # because it will be gone from there in a second\n
# and activate would fail\n # and activate would fail\n
if object.getParentValue().getPortalType() != \'Contribution Tool\':\n if document.getParentValue().getPortalType() != \'Contribution Tool\' \\\n
object.processFile()\n and document.isSupportBaseDataConversion():\n
object.activate().Document_tryToConvertToBaseFormat()\n document.processFile()\n
document.activate().Document_tryToConvertToBaseFormat()\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
...@@ -100,7 +101,7 @@ if object.getParentValue().getPortalType() != \'Contribution Tool\':\n ...@@ -100,7 +101,7 @@ if object.getParentValue().getPortalType() != \'Contribution Tool\':\n
<tuple> <tuple>
<string>state_change</string> <string>state_change</string>
<string>_getitem_</string> <string>_getitem_</string>
<string>object</string> <string>document</string>
<string>_getattr_</string> <string>_getattr_</string>
</tuple> </tuple>
</value> </value>
......
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
<string>cancel_action</string> <string>cancel_action</string>
<string>delete</string> <string>delete</string>
<string>delete_action</string> <string>delete_action</string>
<string>edit</string>
<string>embed</string> <string>embed</string>
<string>publish</string> <string>publish</string>
<string>publish_action</string> <string>publish_action</string>
......
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
<key> <string>transitions</string> </key> <key> <string>transitions</string> </key>
<value> <value>
<tuple> <tuple>
<string>edit</string>
<string>extract</string> <string>extract</string>
</tuple> </tuple>
</value> </value>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="TransitionDefinition" module="Products.DCWorkflow.Transitions"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>actbox_category</string> </key>
<value> <string>workflow</string> </value>
</item>
<item>
<key> <string>actbox_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>actbox_url</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>after_script_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>The edit workflow method is trigerred each time a document is modified. It is necessary so that the embed automatic script can be invoked (XXX - double check this)</string> </value>
</item>
<item>
<key> <string>guard</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>edit</string> </value>
</item>
<item>
<key> <string>new_state_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>script_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Edit</string> </value>
</item>
<item>
<key> <string>trigger_type</string> </key>
<value> <int>2</int> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
<key> <string>transitions</string> </key> <key> <string>transitions</string> </key>
<value> <value>
<tuple> <tuple>
<string>edit</string>
<string>update_file_metadata</string> <string>update_file_metadata</string>
<string>upload_file</string> <string>upload_file</string>
</tuple> </tuple>
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
<tuple> <tuple>
<string>convert_action</string> <string>convert_action</string>
<string>convert_file</string> <string>convert_file</string>
<string>edit</string>
<string>process_file</string> <string>process_file</string>
<string>upload_file</string> <string>upload_file</string>
</tuple> </tuple>
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
<value> <value>
<tuple> <tuple>
<string>detect_uploaded_file</string> <string>detect_uploaded_file</string>
<string>edit</string>
<string>upload_file</string> <string>upload_file</string>
</tuple> </tuple>
</value> </value>
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
<tuple> <tuple>
<string>convert_action</string> <string>convert_action</string>
<string>detect_converted_file</string> <string>detect_converted_file</string>
<string>edit</string>
<string>process_file</string> <string>process_file</string>
<string>upload_file</string> <string>upload_file</string>
</tuple> </tuple>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="TransitionDefinition" module="Products.DCWorkflow.Transitions"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>actbox_category</string> </key>
<value> <string>workflow</string> </value>
</item>
<item>
<key> <string>actbox_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>actbox_url</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>after_script_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>action called when editing a document</string> </value>
</item>
<item>
<key> <string>guard</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>edit</string> </value>
</item>
<item>
<key> <string>new_state_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>script_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Edit</string> </value>
</item>
<item>
<key> <string>trigger_type</string> </key>
<value> <int>2</int> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
2009-07-03 jm
* Remove 'edit' transition on processing_status_workflow and reuse edit_workflow.
2009-05-15 yusei 2009-05-15 yusei
* Add my_editor_field to Base_viewDMSFieldLibrary. * Add my_editor_field to Base_viewDMSFieldLibrary.
......
988 989
\ No newline at end of file \ No newline at end of file
...@@ -3,25 +3,26 @@ Document Ingestion Message | document_ingestion_workflow ...@@ -3,25 +3,26 @@ Document Ingestion Message | document_ingestion_workflow
Document Ingestion Message | edit_workflow Document Ingestion Message | edit_workflow
Drawing | document_interaction_workflow Drawing | document_interaction_workflow
Drawing | document_publication_workflow Drawing | document_publication_workflow
Drawing | edit_workflow
Drawing | local_permission_interaction_workflow Drawing | local_permission_interaction_workflow
Drawing | processing_status_workflow Drawing | processing_status_workflow
File | -edit_workflow
File | document_interaction_workflow File | document_interaction_workflow
File | document_publication_workflow File | document_publication_workflow
File | local_permission_interaction_workflow File | local_permission_interaction_workflow
File | processing_status_workflow File | processing_status_workflow
Image | -edit_workflow
Image | document_interaction_workflow Image | document_interaction_workflow
Image | document_publication_workflow Image | document_publication_workflow
Image | local_permission_interaction_workflow Image | local_permission_interaction_workflow
Image | processing_status_workflow Image | processing_status_workflow
PDF | document_interaction_workflow PDF | document_interaction_workflow
PDF | document_publication_workflow PDF | document_publication_workflow
PDF | edit_workflow
PDF | local_permission_interaction_workflow PDF | local_permission_interaction_workflow
PDF | processing_status_workflow PDF | processing_status_workflow
Person | local_permission_interaction_workflow Person | local_permission_interaction_workflow
Presentation | document_interaction_workflow Presentation | document_interaction_workflow
Presentation | document_publication_workflow Presentation | document_publication_workflow
Presentation | edit_workflow
Presentation | local_permission_interaction_workflow Presentation | local_permission_interaction_workflow
Presentation | processing_status_workflow Presentation | processing_status_workflow
RSS Feed | document_publication_workflow RSS Feed | document_publication_workflow
...@@ -29,10 +30,12 @@ RSS Feed | edit_workflow ...@@ -29,10 +30,12 @@ RSS Feed | edit_workflow
RSS Feed | local_permission_interaction_workflow RSS Feed | local_permission_interaction_workflow
Spreadsheet | document_interaction_workflow Spreadsheet | document_interaction_workflow
Spreadsheet | document_publication_workflow Spreadsheet | document_publication_workflow
Spreadsheet | edit_workflow
Spreadsheet | local_permission_interaction_workflow Spreadsheet | local_permission_interaction_workflow
Spreadsheet | processing_status_workflow Spreadsheet | processing_status_workflow
Text | document_interaction_workflow Text | document_interaction_workflow
Text | document_publication_workflow Text | document_publication_workflow
Text | edit_workflow
Text | local_permission_interaction_workflow Text | local_permission_interaction_workflow
Text | processing_status_workflow Text | processing_status_workflow
URL Crawler | document_publication_workflow URL Crawler | document_publication_workflow
......
...@@ -980,26 +980,14 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, ConversionCacheMixin, Sna ...@@ -980,26 +980,14 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, ConversionCacheMixin, Sna
of the current object. The return value is a string of the current object. The return value is a string
in order to be consistent with the property sheet in order to be consistent with the property sheet
definition. definition.
"""
NOTE: for now, workflow choice is hardcoded. This is revision = len(self.getWorkflowInfo('history', 'edit_workflow'))
an optimisation hack. If a document does neither use # XXX Also look at processing_status_workflow for compatibility.
edit_workflow or processing_status_workflow, the for history_item in self.getWorkflowInfo('history',
first workflow in the chain has prioriot. Better 'processing_status_workflow'):
implementation would require to be able to define if history_item.get('action') == 'edit':
which workflow in a chain is the default one for revision += 1
revision tracking (and for modification date). return str(revision)
"""
portal_workflow = getToolByName(self, 'portal_workflow')
wf_list = list(portal_workflow.getWorkflowsFor(self))
wf = portal_workflow.getWorkflowById('edit_workflow')
if wf is not None: wf_list = [wf] + wf_list
wf = portal_workflow.getWorkflowById('processing_status_workflow')
if wf is not None: wf_list = [wf] + wf_list
for wf in wf_list:
history = wf.getInfoFor(self, 'history', None)
if history:
return str(len(filter(lambda x:x.get('action', None) in ('edit', 'upload'), history)))
return ''
security.declareProtected(Permissions.AccessContentsInformation, 'getRevisionList') security.declareProtected(Permissions.AccessContentsInformation, 'getRevisionList')
def getRevisionList(self): def getRevisionList(self):
...@@ -1007,10 +995,7 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, ConversionCacheMixin, Sna ...@@ -1007,10 +995,7 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, ConversionCacheMixin, Sna
Returns the list of revision numbers of the current document Returns the list of revision numbers of the current document
by by analysing the change log of the current object. by by analysing the change log of the current object.
""" """
revision = self.getRevision() return map(str, range(1, 1 + int(self.getRevision())))
if revision == '':
return []
return [str(r) for r in range(0, int(self.getRevision()))]
security.declareProtected(Permissions.ModifyPortalContent, 'mergeRevision') security.declareProtected(Permissions.ModifyPortalContent, 'mergeRevision')
def mergeRevision(self): def mergeRevision(self):
......
...@@ -364,14 +364,9 @@ class ContributionTool(BaseTool): ...@@ -364,14 +364,9 @@ class ContributionTool(BaseTool):
# If we need to discoverMetadata synchronously, it must # If we need to discoverMetadata synchronously, it must
# be for user interface and should thus be handled by # be for user interface and should thus be handled by
# ZODB scripts # ZODB scripts
document.activate(after_path_and_method_id=(document.getPath(),
# XXX converting state is for only document which is necessary to ('convertToBaseFormat', 'Document_tryToConvertToBaseFormat'))) \
# convert base format. .discoverMetadata(file_name=name, user_login=user_login)
portal_workflow = self.getPortalObject().portal_workflow
if 'processing_status_workflow' in portal_workflow.getChainFor(document):
document.processFile() # move to converting state.
document.activate().Document_convertToBaseFormatAndDiscoverMetadata(
file_name=name, user_login=user_login)
else: else:
if existing_document.isExternalDocument(): if existing_document.isExternalDocument():
document = existing_document document = existing_document
......
...@@ -206,14 +206,14 @@ class TestDocument(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -206,14 +206,14 @@ class TestDocument(ERP5TypeTestCase, ZopeTestCase.Functional):
if not run: return if not run: return
printAndLog('\nTest Revision System') printAndLog('\nTest Revision System')
# create a test document # create a test document
# revision should be 0 # revision should be 1
# upload file (can be the same) into it # upload file (can be the same) into it
# revision should now be 1
# edit the document with any value or no values
# revision should now be 2 # revision should now be 2
# edit the document with any value or no values
# revision should now be 3
# contribute the same file through portal_contributions # contribute the same file through portal_contributions
# the same document should now have revision 3 (because it should have done mergeRevision) # the same document should now have revision 4 (because it should have done mergeRevision)
# getRevisionList should return (0, 1, 2, 3) # getRevisionList should return (1, 2, 3, 4)
filename = 'TEST-en-002.doc' filename = 'TEST-en-002.doc'
file = makeFileUpload(filename) file = makeFileUpload(filename)
document = self.portal.portal_contributions.newContent(file=file) document = self.portal.portal_contributions.newContent(file=file)
...@@ -223,20 +223,20 @@ class TestDocument(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -223,20 +223,20 @@ class TestDocument(ERP5TypeTestCase, ZopeTestCase.Functional):
document_url = document.getRelativeUrl() document_url = document.getRelativeUrl()
def getTestDocument(): def getTestDocument():
return self.portal.restrictedTraverse(document_url) return self.portal.restrictedTraverse(document_url)
self.failUnless(getTestDocument().getRevision() == '0') self.failUnless(getTestDocument().getRevision(), '1')
getTestDocument().edit(file=file) getTestDocument().edit(file=file)
transaction.commit() transaction.commit()
self.tic() self.tic()
self.failUnless(getTestDocument().getRevision() == '1') self.failUnless(getTestDocument().getRevision(), '2')
getTestDocument().edit(title='Hey Joe') getTestDocument().edit(title='Hey Joe')
transaction.commit() transaction.commit()
self.tic() self.tic()
self.failUnless(getTestDocument().getRevision() == '2') self.failUnless(getTestDocument().getRevision(), '3')
another_document = self.portal.portal_contributions.newContent(file=file) another_document = self.portal.portal_contributions.newContent(file=file)
transaction.commit() transaction.commit()
self.tic() self.tic()
self.failUnless(getTestDocument().getRevision() == '3') self.failUnless(getTestDocument().getRevision(), '4')
self.failUnless(getTestDocument().getRevisionList() == ['0', '1', '2'] ) self.failUnless(getTestDocument().getRevisionList(), ['1', '2', '3', '4'])
def test_03_Versioning(self,quiet=QUIET,run=RUN_ALL_TEST): def test_03_Versioning(self,quiet=QUIET,run=RUN_ALL_TEST):
""" """
......
...@@ -304,7 +304,6 @@ class TestIngestion(ERP5TypeTestCase): ...@@ -304,7 +304,6 @@ class TestIngestion(ERP5TypeTestCase):
printAndLog('Ingesting file: ' + filename) printAndLog('Ingesting file: ' + filename)
f = makeFileUpload(filename) f = makeFileUpload(filename)
context.edit(file=f) context.edit(file=f)
context.convertToBaseFormat()
context.reindexObject() context.reindexObject()
transaction.commit() transaction.commit()
self.tic() self.tic()
...@@ -328,7 +327,6 @@ class TestIngestion(ERP5TypeTestCase): ...@@ -328,7 +327,6 @@ class TestIngestion(ERP5TypeTestCase):
filename = 'TEST-en-002.' + format filename = 'TEST-en-002.' + format
f = makeFileUpload(filename) f = makeFileUpload(filename)
context.edit(file=f) context.edit(file=f)
context.convertToBaseFormat()
context.reindexObject() context.reindexObject()
transaction.commit() transaction.commit()
self.tic() self.tic()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment