svn commit: r1035196 - /ofbiz/trunk/applications/party/script/org/ofbiz/party/communication/CommunicationEventServices.xml

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1035196 - /ofbiz/trunk/applications/party/script/org/ofbiz/party/communication/CommunicationEventServices.xml

hansbak-2
Author: hansbak
Date: Mon Nov 15 09:21:50 2010
New Revision: 1035196

URL: http://svn.apache.org/viewvc?rev=1035196&view=rev
Log:
deleting many commevents (spam) with attachments in the same transaction can result in errors. this will fix it

Modified:
    ofbiz/trunk/applications/party/script/org/ofbiz/party/communication/CommunicationEventServices.xml

Modified: ofbiz/trunk/applications/party/script/org/ofbiz/party/communication/CommunicationEventServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/party/script/org/ofbiz/party/communication/CommunicationEventServices.xml?rev=1035196&r1=1035195&r2=1035196&view=diff
==============================================================================
--- ofbiz/trunk/applications/party/script/org/ofbiz/party/communication/CommunicationEventServices.xml (original)
+++ ofbiz/trunk/applications/party/script/org/ofbiz/party/communication/CommunicationEventServices.xml Mon Nov 15 09:21:50 2010
@@ -340,6 +340,9 @@ under the License.
 
     <simple-method method-name="deleteCommunicationEvent" short-description="Delete a CommunicationEvent">
         <entity-one entity-name="CommunicationEvent" value-field="event"/>
+        <if-empty field="event"><!-- the service can be called multiple times because event can have several recipients-->
+            <return/><!-- ignore if already deleted -->
+        </if-empty>
         <!-- remove related links to content -->
         <get-related value-field="event" relation-name="CommEventContentAssoc" list="contentAssocs"/>
         <if-not-empty field="contentAssocs">
@@ -352,19 +355,26 @@ under the License.
                         <iterate entry="content" list="contents">
                             <remove-related value-field="content" relation-name="ContentRole"/>
                             <remove-value value-field="content"/>
-                            <get-related-one value-field="content" relation-name="DataResource" to-value-field="dataResource"/>
-                            <if-not-empty field="dataResource">
-                                <get-related-one value-field="dataResource" relation-name="ImageDataResource" to-value-field="imageDataResource"/>
-                                <if-not-empty field="imageDataResource">
-                                    <remove-value value-field="imageDataResource"/>
-                                </if-not-empty>
-                                <get-related-one value-field="dataResource" relation-name="ElectronicText" to-value-field="electronicText"/>
-                                <if-not-empty field="electronicText">
-                                    <remove-value value-field="electronicText"/>
+                            <!-- check first if the content is used on any other communication event if yes, only delete link-->
+                            <entity-and entity-name="CommEventContentAssoc" list="commEvents">
+                                <field-map field-name="contentId" from-field="content.contentId"/>
+                            </entity-and>
+                            <set field="commEventsSize" value="${groovy: return(commEvents.size())}" type="Integer"/>
+                            <if-compare field="commEventsSize" operator="equals" value="1">
+                                <get-related-one value-field="content" relation-name="DataResource" to-value-field="dataResource"/>
+                                <if-not-empty field="dataResource">
+                                    <get-related-one value-field="dataResource" relation-name="ImageDataResource" to-value-field="imageDataResource"/>
+                                    <if-not-empty field="imageDataResource">
+                                        <remove-value value-field="imageDataResource"/>
+                                    </if-not-empty>
+                                    <get-related-one value-field="dataResource" relation-name="ElectronicText" to-value-field="electronicText"/>
+                                    <if-not-empty field="electronicText">
+                                        <remove-value value-field="electronicText"/>
+                                    </if-not-empty>
+                                    <remove-related value-field="dataResource" relation-name="DataResourceRole"/>
+                                    <remove-value value-field="dataResource"/>
                                 </if-not-empty>
-                                <remove-related value-field="dataResource" relation-name="DataResourceRole"/>
-                                <remove-value value-field="dataResource"/>
-                            </if-not-empty>
+                            </if-compare>
                         </iterate>
                     </if-not-empty>
                 </if-compare>