diff --git a/www/core/components/settings/controllers/space-usage.js b/www/core/components/settings/controllers/space-usage.js index 91ebc074b86..fecd58f4a35 100644 --- a/www/core/components/settings/controllers/space-usage.js +++ b/www/core/components/settings/controllers/space-usage.js @@ -23,7 +23,7 @@ angular.module('mm.core.settings') * @todo When "mock site" is implemented we should have functions to calculate the site usage and delete its files. */ .controller('mmSettingsSpaceUsageCtrl', function($log, $scope, $mmSitesManager, $mmFS, $q, $mmUtil, $translate, - $mmCourse, $mmText) { + $mmCourse, $mmText, $mmFilepool) { $log = $log.getInstance('mmSettingsSpaceUsageCtrl'); // Convenience function to calculate each site's usage, and the total usage. @@ -107,6 +107,7 @@ angular.module('mm.core.settings') }).then(function(site) { return site.deleteFolder().then(function() { $mmCourse.clearAllModulesStatus(siteid); + $mmFilepool.clearFilepool(siteid); updateSiteUsage(siteData, 0); }).catch(function(error) { if (error && error.code === FileError.NOT_FOUND_ERR) { diff --git a/www/core/lib/filepool.js b/www/core/lib/filepool.js index e0b182e8dbc..873cf84f798 100644 --- a/www/core/lib/filepool.js +++ b/www/core/lib/filepool.js @@ -414,6 +414,21 @@ angular.module('mm.core') self._processQueue(); }; + /** + * Clears the filepool. Use it only when all the files from a site are deleted. + * + * @module mm.core + * @ngdoc method + * @name $mmFilepool#clearFilepool + * @param {String} siteId ID of the site to clear. + * @return {Promise} Promise resolved when the filepool is cleared. + */ + self.clearFilepool = function(siteId) { + return getSiteDb(siteId).then(function(db) { + return db.removeAll(mmFilepoolStore); + }); + }; + /** * Returns whether a component has files in the pool. *