@@ -188,7 +188,7 @@ angular.module('mm.addons.mod_data')
188188 } ) ;
189189
190190 angular . forEach ( offlineEntries , function ( entryActions ) {
191- promises . push ( syncEntry ( data , entryActions , result . warnings , siteId ) ) ;
191+ promises . push ( syncEntry ( data , entryActions , result , siteId ) ) ;
192192 } ) ;
193193
194194 return $q . all ( promises ) ;
@@ -216,16 +216,17 @@ angular.module('mm.addons.mod_data')
216216 /**
217217 * Synchronize an entry.
218218 *
219- * @param {Object } data Database.
220- * @param {Object } entryActions Entry actions.
221- * @param {Object[] } warnings List of warnings .
222- * @param {String } [siteId] Site ID. If not defined, current site.
223- * @return {Promise } Promise resolved if success, rejected otherwise.
219+ * @param {Object } data Database.
220+ * @param {Object } entryActions Entry actions.
221+ * @param {Object } result Object with the result of the sync .
222+ * @param {String } [siteId] Site ID. If not defined, current site.
223+ * @return {Promise } Promise resolved if success, rejected otherwise.
224224 */
225- function syncEntry ( data , entryActions , warnings , siteId ) {
225+ function syncEntry ( data , entryActions , result , siteId ) {
226226 var discardError ,
227227 timePromise ,
228228 entryId = 0 ,
229+ offlineId ,
229230 deleted = false ,
230231 promises = [ ] ;
231232
@@ -237,20 +238,22 @@ angular.module('mm.addons.mod_data')
237238 entryId = entryActions [ 0 ] . entryid ;
238239
239240 if ( entryId > 0 ) {
240- timePromise = $mmaModData . getEntry ( data . id , entryActions [ 0 ] . entryid , siteId ) . then ( function ( entry ) {
241+ timePromise = $mmaModData . getEntry ( data . id , entryId , siteId ) . then ( function ( entry ) {
241242 return entry . entry . timemodified ;
242243 } ) . catch ( function ( ) {
243244 return - 1 ;
244245 } ) ;
245246 } else {
247+ offlineId = entryId ;
246248 timePromise = $q . when ( 0 ) ;
247249 }
248250
249251 return timePromise . then ( function ( timemodified ) {
250252 if ( timemodified < 0 || timemodified >= entryActions [ 0 ] . timemodified ) {
251253 // The entry was not found in Moodle or the entry has been modified, discard the action.
254+ result . updated = true ;
252255 discardError = $translate . instant ( 'mma.mod_data.warningsubmissionmodified' ) ;
253- return ;
256+ return $mmaModDataOffline . deleteAllEntryActions ( data . id , entryId , siteId ) ;
254257 }
255258
256259 angular . forEach ( entryActions , function ( action ) {
@@ -310,6 +313,7 @@ angular.module('mm.addons.mod_data')
310313 }
311314 } ) . then ( function ( ) {
312315 // Delete the offline data.
316+ result . updated = true ;
313317 return $mmaModDataOffline . deleteEntry ( action . dataid , action . entryid , action . action , siteId ) ;
314318 } ) ) ;
315319 } ) ;
@@ -323,17 +327,18 @@ angular.module('mm.addons.mod_data')
323327 error : discardError
324328 } ) ;
325329
326- if ( warnings . indexOf ( message ) == - 1 ) {
327- warnings . push ( message ) ;
330+ if ( result . warnings . indexOf ( message ) == - 1 ) {
331+ result . warnings . push ( message ) ;
328332 }
329333 }
330334
331335 // Sync done. Send event.
332336 $mmEvents . trigger ( mmaModDataEventAutomSynced , {
333337 siteid : siteId ,
334- dataid : action . dataid ,
335- entryid : action . entryid ,
336- warnings : warnings ,
338+ dataid : data . id ,
339+ entryid : entryId ,
340+ offlineentryid : offlineId ,
341+ warnings : result . warnings ,
337342 deleted : deleted
338343 } ) ;
339344 } ) ;
0 commit comments