@@ -580,12 +580,14 @@ angular.module('mm.core')
580580 * @param {Boolean } prefetch True if should prefetch the contents (queue), false if they should be downloaded right now.
581581 * @param {String } component The component to link the file to.
582582 * @param {Number } [componentId] An ID to use in conjunction with the component.
583+ * @param {Number } [revision] Package's revision. If not defined, it will be calculated using the list of files.
584+ * @param {Number } [timemod] Package's timemodified. If not defined, it will be calculated using the list of files.
583585 * @param {String } [dirPath] Name of the directory where to store the files (inside filepool dir). If not defined, store
584586 * the files directly inside the filepool folder.
585587 * @return {Promise } Promise resolved when all files are downloaded.
586588 * @protected
587589 */
588- self . _downloadOrPrefetchPackage = function ( siteId , fileList , prefetch , component , componentId , dirPath ) {
590+ self . _downloadOrPrefetchPackage = function ( siteId , fileList , prefetch , component , componentId , revision , timemod , dirPath ) {
589591
590592 var packageId = self . getPackageId ( component , componentId ) ;
591593
@@ -596,9 +598,10 @@ angular.module('mm.core')
596598 packagesPromises [ siteId ] = { } ;
597599 }
598600
599- var revision = self . getRevisionFromFileList ( fileList ) ,
600- timemod = self . getTimemodifiedFromFileList ( fileList ) ,
601- dwnPromise ,
601+ revision = revision || self . getRevisionFromFileList ( fileList ) ;
602+ timemod = timemod || self . getTimemodifiedFromFileList ( fileList ) ;
603+
604+ var dwnPromise ,
602605 deleted = false ;
603606
604607 // Set package as downloading.
@@ -651,16 +654,18 @@ angular.module('mm.core')
651654 * @module mm.core
652655 * @ngdoc method
653656 * @name $mmFilepool#downloadPackage
654- * @param {String } siteId The site ID.
655- * @param {Object[] } fileList List of files to download.
656- * @param {String } component The component to link the file to.
657- * @param {Number } componentId An ID to identify the download. Must be unique.
658- * @param {String } [dirPath] Name of the directory where to store the files (inside filepool dir). If not defined, store
659- * the files directly inside the filepool folder.
660- * @return {Promise } Promise resolved when all files are downloaded.
657+ * @param {String } siteId The site ID.
658+ * @param {Object[] } fileList List of files to download.
659+ * @param {String } component The component to link the file to.
660+ * @param {Number } componentId An ID to identify the download. Must be unique.
661+ * @param {Number } [revision] Package's revision. If not defined, it will be calculated using the list of files.
662+ * @param {Number } [timemodified] Package's timemodified. If not defined, it will be calculated using the list of files.
663+ * @param {String } [dirPath] Name of the directory where to store the files (inside filepool dir). If not defined, store
664+ * the files directly inside the filepool folder.
665+ * @return {Promise } Promise resolved when all files are downloaded.
661666 */
662- self . downloadPackage = function ( siteId , fileList , component , componentId , dirPath ) {
663- return self . _downloadOrPrefetchPackage ( siteId , fileList , false , component , componentId , dirPath ) ;
667+ self . downloadPackage = function ( siteId , fileList , component , componentId , revision , timemodified , dirPath ) {
668+ return self . _downloadOrPrefetchPackage ( siteId , fileList , false , component , componentId , revision , timemodified , dirPath ) ;
664669 } ;
665670
666671 /**
@@ -1340,18 +1345,18 @@ angular.module('mm.core')
13401345 * @return {Number } Package revision.
13411346 */
13421347 self . getRevisionFromFileList = function ( files ) {
1343- if ( files && files . length ) {
1344- for ( var i = 0 ; i < files . length ; i ++ ) {
1345- var file = files [ i ] ;
1346- if ( file . fileurl ) {
1347- var revision = self . getRevisionFromUrl ( file . fileurl ) ;
1348- if ( typeof revision !== 'undefined' ) {
1349- return revision ;
1350- }
1348+ var revision = 0 ;
1349+
1350+ angular . forEach ( files , function ( file ) {
1351+ if ( file . fileurl ) {
1352+ var r = self . getRevisionFromUrl ( file . fileurl ) ;
1353+ if ( r > revision ) {
1354+ revision = r ;
13511355 }
13521356 }
1353- }
1354- return 0 ;
1357+ } ) ;
1358+
1359+ return revision ;
13551360 } ;
13561361
13571362 /**
@@ -1403,15 +1408,15 @@ angular.module('mm.core')
14031408 * @return {Number } Package time modified.
14041409 */
14051410 self . getTimemodifiedFromFileList = function ( files ) {
1406- if ( files && files . length ) {
1407- for ( var i = 0 ; i < files . length ; i ++ ) {
1408- var file = files [ i ] ;
1409- if ( file . timemodified ) {
1410- return file . timemodified ;
1411- }
1411+ var timemod = 0 ;
1412+
1413+ angular . forEach ( files , function ( file ) {
1414+ if ( file . timemodified > timemod ) {
1415+ timemod = file . timemodified ;
14121416 }
1413- }
1414- return 0 ;
1417+ } ) ;
1418+
1419+ return timemod ;
14151420 } ;
14161421
14171422 /**
@@ -1627,16 +1632,18 @@ angular.module('mm.core')
16271632 * @module mm.core
16281633 * @ngdoc method
16291634 * @name $mmFilepool#prefetchPackage
1630- * @param {String } siteId The site ID.
1631- * @param {Object[] } fileList List of files to download.
1632- * @param {String } component The component to link the file to.
1633- * @param {Number } componentId An ID to identify the download. Must be unique.
1634- * @param {String } [dirPath] Name of the directory where to store the files (inside filepool dir). If not defined, store
1635- * the files directly inside the filepool folder.
1636- * @return {Promise } Promise resolved when all files are downloaded.
1635+ * @param {String } siteId The site ID.
1636+ * @param {Object[] } fileList List of files to download.
1637+ * @param {String } component The component to link the file to.
1638+ * @param {Number } componentId An ID to identify the download. Must be unique.
1639+ * @param {Number } [revision] Package's revision. If not defined, it will be calculated using the list of files.
1640+ * @param {Number } [timemodified] Package's timemodified. If not defined, it will be calculated using the list of files.
1641+ * @param {String } [dirPath] Name of the directory where to store the files (inside filepool dir). If not defined, store
1642+ * the files directly inside the filepool folder.
1643+ * @return {Promise } Promise resolved when all files are downloaded.
16371644 */
1638- self . prefetchPackage = function ( siteId , fileList , component , componentId , dirPath ) {
1639- return self . _downloadOrPrefetchPackage ( siteId , fileList , true , component , componentId , dirPath ) ;
1645+ self . prefetchPackage = function ( siteId , fileList , component , componentId , revision , timemodified , dirPath ) {
1646+ return self . _downloadOrPrefetchPackage ( siteId , fileList , true , component , componentId , revision , timemodified , dirPath ) ;
16401647 } ;
16411648
16421649 /**
0 commit comments