MOBILE-3320 course: Fix some prefetchs never ending

main
Dani Palou 2021-06-11 08:56:11 +02:00
parent a0a0385c95
commit c5d18dffdc
18 changed files with 61 additions and 97 deletions

View File

@ -211,13 +211,9 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref
} }
/** /**
* Prefetch a module. * @inheritdoc
*
* @param module Module.
* @param courseId Course ID the module belongs to.
* @return Promise resolved when done.
*/ */
prefetch(module: CoreCourseAnyModuleData, courseId?: number): Promise<void> { prefetch(module: CoreCourseAnyModuleData, courseId: number): Promise<void> {
return this.prefetchPackage(module, courseId, this.prefetchAssign.bind(this, module, courseId)); return this.prefetchPackage(module, courseId, this.prefetchAssign.bind(this, module, courseId));
} }
@ -226,12 +222,11 @@ export class AddonModAssignPrefetchHandlerService extends CoreCourseActivityPref
* *
* @param module Module. * @param module Module.
* @param courseId Course ID the module belongs to. * @param courseId Course ID the module belongs to.
* @param siteId Site ID.
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
protected async prefetchAssign(module: CoreCourseAnyModuleData, courseId?: number): Promise<void> { protected async prefetchAssign(module: CoreCourseAnyModuleData, courseId: number, siteId: string): Promise<void> {
const userId = CoreSites.getCurrentSiteUserId(); const userId = CoreSites.getCurrentSiteUserId();
courseId = courseId || module.course || CoreSites.getCurrentSiteHomeId();
const siteId = CoreSites.getCurrentSiteId();
const options: CoreSitesCommonWSOptions = { const options: CoreSitesCommonWSOptions = {
readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK, readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK,

View File

@ -17,7 +17,7 @@ import { CoreCourseActivityPrefetchHandlerBase } from '@features/course/classes/
import { CoreCourse, CoreCourseAnyModuleData, CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { CoreCourse, CoreCourseAnyModuleData, CoreCourseCommonModWSOptions } from '@features/course/services/course';
import { CoreUser } from '@features/user/services/user'; import { CoreUser } from '@features/user/services/user';
import { CoreGroups } from '@services/groups'; import { CoreGroups } from '@services/groups';
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSitesReadingStrategy } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { AddonModChat, AddonModChatProvider, AddonModChatSession } from '../chat'; import { AddonModChat, AddonModChatProvider, AddonModChatSession } from '../chat';
@ -64,7 +64,7 @@ export class AddonModChatPrefetchHandlerService extends CoreCourseActivityPrefet
/** /**
* @inheritdoc * @inheritdoc
*/ */
prefetch(module: CoreCourseAnyModuleData, courseId?: number): Promise<void> { prefetch(module: CoreCourseAnyModuleData, courseId: number): Promise<void> {
return this.prefetchPackage(module, courseId, this.prefetchChat.bind(this, module, courseId)); return this.prefetchPackage(module, courseId, this.prefetchChat.bind(this, module, courseId));
} }
@ -73,10 +73,10 @@ export class AddonModChatPrefetchHandlerService extends CoreCourseActivityPrefet
* *
* @param module The module object returned by WS. * @param module The module object returned by WS.
* @param courseId Course ID the module belongs to. * @param courseId Course ID the module belongs to.
* @param siteId Site ID.
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
protected async prefetchChat(module: CoreCourseAnyModuleData, courseId: number): Promise<void> { protected async prefetchChat(module: CoreCourseAnyModuleData, courseId: number, siteId: string): Promise<void> {
const siteId = CoreSites.getCurrentSiteId();
const options = { const options = {
readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK, readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK,
siteId, siteId,

View File

@ -17,7 +17,7 @@ import { CoreCourseActivityPrefetchHandlerBase } from '@features/course/classes/
import { CoreCourseAnyModuleData, CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { CoreCourseAnyModuleData, CoreCourseCommonModWSOptions } from '@features/course/services/course';
import { CoreUser } from '@features/user/services/user'; import { CoreUser } from '@features/user/services/user';
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSitesReadingStrategy } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
@ -38,7 +38,7 @@ export class AddonModChoicePrefetchHandlerService extends CoreCourseActivityPref
/** /**
* @inheritdoc * @inheritdoc
*/ */
prefetch(module: CoreCourseAnyModuleData, courseId?: number, single?: boolean): Promise<void> { prefetch(module: CoreCourseAnyModuleData, courseId: number, single?: boolean): Promise<void> {
return this.prefetchPackage(module, courseId, this.prefetchChoice.bind(this, module, courseId, !!single)); return this.prefetchPackage(module, courseId, this.prefetchChoice.bind(this, module, courseId, !!single));
} }
@ -55,10 +55,8 @@ export class AddonModChoicePrefetchHandlerService extends CoreCourseActivityPref
module: CoreCourseAnyModuleData, module: CoreCourseAnyModuleData,
courseId: number, courseId: number,
single: boolean, single: boolean,
siteId?: string, siteId: string,
): Promise<void> { ): Promise<void> {
siteId = siteId || CoreSites.getCurrentSiteId();
const commonOptions = { const commonOptions = {
readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK, readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK,
siteId, siteId,

View File

@ -212,7 +212,7 @@ export class AddonModDataPrefetchHandlerService extends CoreCourseActivityPrefet
/** /**
* @inheritdoc * @inheritdoc
*/ */
prefetch(module: CoreCourseAnyModuleData, courseId?: number): Promise<void> { prefetch(module: CoreCourseAnyModuleData, courseId: number): Promise<void> {
return this.prefetchPackage(module, courseId, this.prefetchDatabase.bind(this, module, courseId)); return this.prefetchPackage(module, courseId, this.prefetchDatabase.bind(this, module, courseId));
} }
@ -221,12 +221,10 @@ export class AddonModDataPrefetchHandlerService extends CoreCourseActivityPrefet
* *
* @param module Module. * @param module Module.
* @param courseId Course ID the module belongs to. * @param courseId Course ID the module belongs to.
* @param siteId Site ID.
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
protected async prefetchDatabase(module: CoreCourseAnyModuleData, courseId?: number): Promise<void> { protected async prefetchDatabase(module: CoreCourseAnyModuleData, courseId: number, siteId: string): Promise<void> {
const siteId = CoreSites.getCurrentSiteId();
courseId = courseId || module.course || CoreSites.getCurrentSiteHomeId();
const options = { const options = {
cmId: module.id, cmId: module.id,
readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK, readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK,

View File

@ -17,7 +17,7 @@ import { CoreCourseActivityPrefetchHandlerBase } from '@features/course/classes/
import { CoreCourseAnyModuleData, CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { CoreCourseAnyModuleData, CoreCourseCommonModWSOptions } from '@features/course/services/course';
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
import { CoreGroups } from '@services/groups'; import { CoreGroups } from '@services/groups';
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSitesReadingStrategy } from '@services/sites';
import { CoreTimeUtils } from '@services/utils/time'; import { CoreTimeUtils } from '@services/utils/time';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
@ -122,7 +122,7 @@ export class AddonModFeedbackPrefetchHandlerService extends CoreCourseActivityPr
/** /**
* @inheritdoc * @inheritdoc
*/ */
prefetch(module: CoreCourseAnyModuleData, courseId?: number): Promise<void> { prefetch(module: CoreCourseAnyModuleData, courseId: number): Promise<void> {
return this.prefetchPackage(module, courseId, this.prefetchFeedback.bind(this, module, courseId)); return this.prefetchPackage(module, courseId, this.prefetchFeedback.bind(this, module, courseId));
} }
@ -131,10 +131,10 @@ export class AddonModFeedbackPrefetchHandlerService extends CoreCourseActivityPr
* *
* @param module Module. * @param module Module.
* @param courseId Course ID the module belongs to. * @param courseId Course ID the module belongs to.
* @param siteId Site ID.
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
protected async prefetchFeedback(module: CoreCourseAnyModuleData, courseId: number): Promise<void> { protected async prefetchFeedback(module: CoreCourseAnyModuleData, courseId: number, siteId: string): Promise<void> {
const siteId = CoreSites.getCurrentSiteId();
const commonOptions = { const commonOptions = {
readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK, readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK,
siteId, siteId,

View File

@ -171,15 +171,9 @@ export class AddonModForumPrefetchHandlerService extends CoreCourseActivityPrefe
} }
/** /**
* Prefetch a module. * @inheritdoc
*
* @param module Module.
* @param courseId Course ID the module belongs to.
* @param single True if we're downloading a single module, false if we're downloading a whole section.
* @param dirPath Path of the directory where to store all the content files.
* @return Promise resolved when done.
*/ */
prefetch(module: CoreCourseAnyModuleData, courseId?: number, single?: boolean): Promise<void> { prefetch(module: CoreCourseAnyModuleData, courseId: number, single?: boolean): Promise<void> {
return this.prefetchPackage(module, courseId, this.prefetchForum.bind(this, module, courseId, single)); return this.prefetchPackage(module, courseId, this.prefetchForum.bind(this, module, courseId, single));
} }

View File

@ -97,7 +97,7 @@ export class AddonModGlossaryPrefetchHandlerService extends CoreCourseActivityPr
/** /**
* @inheritdoc * @inheritdoc
*/ */
prefetch(module: CoreCourseAnyModuleData, courseId?: number): Promise<void> { prefetch(module: CoreCourseAnyModuleData, courseId: number): Promise<void> {
return this.prefetchPackage(module, courseId, this.prefetchGlossary.bind(this, module, courseId)); return this.prefetchPackage(module, courseId, this.prefetchGlossary.bind(this, module, courseId));
} }
@ -110,8 +110,6 @@ export class AddonModGlossaryPrefetchHandlerService extends CoreCourseActivityPr
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
protected async prefetchGlossary(module: CoreCourseAnyModuleData, courseId: number, siteId: string): Promise<void> { protected async prefetchGlossary(module: CoreCourseAnyModuleData, courseId: number, siteId: string): Promise<void> {
siteId = siteId || CoreSites.getCurrentSiteId();
const options = { const options = {
cmId: module.id, cmId: module.id,
readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK, readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK,

View File

@ -76,7 +76,7 @@ export class AddonModH5PActivityPrefetchHandlerService extends CoreCourseActivit
/** /**
* @inheritdoc * @inheritdoc
*/ */
prefetch(module: CoreCourseAnyModuleData, courseId?: number): Promise<void> { prefetch(module: CoreCourseAnyModuleData, courseId: number): Promise<void> {
return this.prefetchPackage(module, courseId, this.prefetchActivity.bind(this, module, courseId)); return this.prefetchPackage(module, courseId, this.prefetchActivity.bind(this, module, courseId));
} }
@ -91,10 +91,8 @@ export class AddonModH5PActivityPrefetchHandlerService extends CoreCourseActivit
protected async prefetchActivity( protected async prefetchActivity(
module: CoreCourseAnyModuleData, module: CoreCourseAnyModuleData,
courseId: number, courseId: number,
siteId?: string, siteId: string,
): Promise<void> { ): Promise<void> {
siteId = siteId || CoreSites.getCurrentSiteId();
const h5pActivity = await AddonModH5PActivity.getH5PActivity(courseId, module.id, { const h5pActivity = await AddonModH5PActivity.getH5PActivity(courseId, module.id, {
readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK, readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK,
siteId, siteId,

View File

@ -231,17 +231,10 @@ export class AddonModLessonPrefetchHandlerService extends CoreCourseActivityPref
} }
/** /**
* Prefetch a module. * @inheritdoc
*
* @param module Module.
* @param courseId Course ID the module belongs to.
* @param single True if we're downloading a single module, false if we're downloading a whole section.
* @param dirPath Path of the directory where to store all the content files.
* @return Promise resolved when done.
*/ */
// eslint-disable-next-line @typescript-eslint/no-unused-vars prefetch(module: CoreCourseAnyModuleData, courseId: number, single?: boolean): Promise<void> {
prefetch(module: CoreCourseAnyModuleData, courseId?: number, single?: boolean, dirPath?: string): Promise<void> { return this.prefetchPackage(module, courseId, this.prefetchLesson.bind(this, module, courseId, !!single));
return this.prefetchPackage(module, courseId, this.prefetchLesson.bind(this, module, courseId, single));
} }
/** /**
@ -250,12 +243,15 @@ export class AddonModLessonPrefetchHandlerService extends CoreCourseActivityPref
* @param module Module. * @param module Module.
* @param courseId Course ID the module belongs to. * @param courseId Course ID the module belongs to.
* @param single True if we're downloading a single module, false if we're downloading a whole section. * @param single True if we're downloading a single module, false if we're downloading a whole section.
* @param siteId Site ID.
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
protected async prefetchLesson(module: CoreCourseAnyModuleData, courseId?: number, single?: boolean): Promise<void> { protected async prefetchLesson(
const siteId = CoreSites.getCurrentSiteId(); module: CoreCourseAnyModuleData,
courseId = courseId || module.course || CoreSites.getCurrentSiteHomeId(); courseId: number,
single: boolean,
siteId: string,
): Promise<void> {
const commonOptions = { const commonOptions = {
readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK, readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK,
siteId, siteId,

View File

@ -269,7 +269,7 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet
*/ */
async prefetch( async prefetch(
module: SyncedModule, module: SyncedModule,
courseId?: number, courseId: number,
single?: boolean, single?: boolean,
dirPath?: string, dirPath?: string,
canStart: boolean = true, canStart: boolean = true,
@ -282,9 +282,7 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet
return; return;
} }
const siteId = CoreSites.getCurrentSiteId(); return this.prefetchPackage(module, courseId, this.prefetchQuiz.bind(this, module, courseId, !!single, canStart));
return this.prefetchPackage(module, courseId, this.prefetchQuiz.bind(this, module, courseId, single, siteId, canStart));
} }
/** /**
@ -293,16 +291,16 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet
* @param module Module. * @param module Module.
* @param courseId Course ID the module belongs to. * @param courseId Course ID the module belongs to.
* @param single True if we're downloading a single module, false if we're downloading a whole section. * @param single True if we're downloading a single module, false if we're downloading a whole section.
* @param siteId Site ID.
* @param canStart If true, start a new attempt if needed. * @param canStart If true, start a new attempt if needed.
* @param siteId Site ID.
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
protected async prefetchQuiz( protected async prefetchQuiz(
module: CoreCourseAnyModuleData, module: CoreCourseAnyModuleData,
courseId: number, courseId: number,
single: boolean, single: boolean,
siteId: string,
canStart: boolean, canStart: boolean,
siteId: string,
): Promise<void> { ): Promise<void> {
const commonOptions = { const commonOptions = {
readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK, readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK,

View File

@ -47,12 +47,10 @@ export class AddonModScormPrefetchHandlerService extends CoreCourseActivityPrefe
dirPath?: string, dirPath?: string,
onProgress?: AddonModScormProgressCallback, onProgress?: AddonModScormProgressCallback,
): Promise<void> { ): Promise<void> {
const siteId = CoreSites.getCurrentSiteId();
return this.prefetchPackage( return this.prefetchPackage(
module, module,
courseId, courseId,
this.downloadOrPrefetchScorm.bind(this, module, courseId, true, siteId, false, onProgress), this.downloadOrPrefetchScorm.bind(this, module, courseId, true, false, onProgress),
); );
} }
@ -62,18 +60,18 @@ export class AddonModScormPrefetchHandlerService extends CoreCourseActivityPrefe
* @param module Module. * @param module Module.
* @param courseId Course ID the module belongs to. * @param courseId Course ID the module belongs to.
* @param single True if we're downloading a single module, false if we're downloading a whole section. * @param single True if we're downloading a single module, false if we're downloading a whole section.
* @param siteId Site ID.
* @param prefetch True to prefetch, false to download right away. * @param prefetch True to prefetch, false to download right away.
* @param onProgress Function to call on progress. * @param onProgress Function to call on progress.
* @param siteId Site ID.
* @return Promise resolved with the "extra" data to store: the hash of the file. * @return Promise resolved with the "extra" data to store: the hash of the file.
*/ */
protected async downloadOrPrefetchScorm( protected async downloadOrPrefetchScorm(
module: CoreCourseAnyModuleData, module: CoreCourseAnyModuleData,
courseId: number, courseId: number,
single: boolean, single: boolean,
siteId: string,
prefetch: boolean, prefetch: boolean,
onProgress?: AddonModScormProgressCallback, onProgress: AddonModScormProgressCallback | undefined,
siteId: string,
): Promise<string> { ): Promise<string> {
const scorm = await this.getScorm(module, courseId, siteId); const scorm = await this.getScorm(module, courseId, siteId);
@ -370,12 +368,10 @@ export class AddonModScormPrefetchHandlerService extends CoreCourseActivityPrefe
dirPath?: string, dirPath?: string,
onProgress?: AddonModScormProgressCallback, onProgress?: AddonModScormProgressCallback,
): Promise<void> { ): Promise<void> {
const siteId = CoreSites.getCurrentSiteId();
return this.prefetchPackage( return this.prefetchPackage(
module, module,
courseId, courseId,
this.downloadOrPrefetchScorm.bind(this, module, courseId, single, siteId, true, onProgress), this.downloadOrPrefetchScorm.bind(this, module, courseId, single, true, onProgress),
); );
} }

View File

@ -67,7 +67,7 @@ export class AddonModSurveyPrefetchHandlerService extends CoreCourseActivityPref
/** /**
* @inheritdoc * @inheritdoc
*/ */
prefetch(module: CoreCourseAnyModuleData, courseId?: number): Promise<void> { prefetch(module: CoreCourseAnyModuleData, courseId: number): Promise<void> {
return this.prefetchPackage(module, courseId, this.prefetchSurvey.bind(this, module, courseId)); return this.prefetchPackage(module, courseId, this.prefetchSurvey.bind(this, module, courseId));
} }

View File

@ -130,7 +130,7 @@ export class AddonModWikiPrefetchHandlerService extends CoreCourseActivityPrefet
/** /**
* @inheritdoc * @inheritdoc
*/ */
async prefetch(module: CoreCourseAnyModuleData, courseId?: number, single?: boolean): Promise<void> { async prefetch(module: CoreCourseAnyModuleData, courseId: number, single?: boolean): Promise<void> {
// Get the download time of the package before starting the download (otherwise we'd always get current time). // Get the download time of the package before starting the download (otherwise we'd always get current time).
const siteId = CoreSites.getCurrentSiteId(); const siteId = CoreSites.getCurrentSiteId();
@ -138,7 +138,12 @@ export class AddonModWikiPrefetchHandlerService extends CoreCourseActivityPrefet
const downloadTime = data?.downloadTime || 0; const downloadTime = data?.downloadTime || 0;
return this.prefetchPackage(module, courseId, this.prefetchWiki.bind(this, module, courseId, single, downloadTime, siteId)); return this.prefetchPackage(
module,
courseId,
this.prefetchWiki.bind(this, module, courseId, !!single, downloadTime),
siteId,
);
} }
/** /**

View File

@ -210,7 +210,7 @@ export class AddonModWorkshopPrefetchHandlerService extends CoreCourseActivityPr
/** /**
* @inheritdoc * @inheritdoc
*/ */
prefetch(module: CoreCourseAnyModuleData, courseId?: number): Promise<void> { prefetch(module: CoreCourseAnyModuleData, courseId: number): Promise<void> {
return this.prefetchPackage(module, courseId, this.prefetchWorkshop.bind(this, module, courseId)); return this.prefetchPackage(module, courseId, this.prefetchWorkshop.bind(this, module, courseId));
} }
@ -258,9 +258,6 @@ export class AddonModWorkshopPrefetchHandlerService extends CoreCourseActivityPr
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
protected async prefetchWorkshop(module: CoreCourseAnyModuleData, courseId: number, siteId: string): Promise<void> { protected async prefetchWorkshop(module: CoreCourseAnyModuleData, courseId: number, siteId: string): Promise<void> {
siteId = siteId || CoreSites.getCurrentSiteId();
const userIds: number[] = []; const userIds: number[] = [];
const commonOptions = { const commonOptions = {
readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK, readingStrategy: CoreSitesReadingStrategy.ONLY_NETWORK,

View File

@ -78,8 +78,8 @@ export class CoreCourseActivityPrefetchHandlerBase extends CoreCourseModulePrefe
*/ */
async prefetchPackage( async prefetchPackage(
module: CoreCourseAnyModuleData, module: CoreCourseAnyModuleData,
courseId: number | undefined, courseId: number,
downloadFunction: () => Promise<string>, downloadFunction: (siteId: string) => Promise<string>,
siteId?: string, siteId?: string,
): Promise<void> { ): Promise<void> {
siteId = siteId || CoreSites.getCurrentSiteId(); siteId = siteId || CoreSites.getCurrentSiteId();
@ -111,8 +111,8 @@ export class CoreCourseActivityPrefetchHandlerBase extends CoreCourseModulePrefe
protected async changeStatusAndPrefetch( protected async changeStatusAndPrefetch(
module: CoreCourseAnyModuleData, module: CoreCourseAnyModuleData,
courseId: number | undefined, courseId: number | undefined,
downloadFunction: () => Promise<string>, downloadFunction: (siteId: string) => Promise<string>,
siteId?: string, siteId: string,
): Promise<void> { ): Promise<void> {
try { try {
await this.setDownloading(module.id, siteId); await this.setDownloading(module.id, siteId);
@ -125,7 +125,7 @@ export class CoreCourseActivityPrefetchHandlerBase extends CoreCourseModulePrefe
]); ]);
// Call the download function. // Call the download function.
let extra = await downloadFunction(); let extra = await downloadFunction(siteId);
// Only accept string types. // Only accept string types.
if (typeof extra != 'string') { if (typeof extra != 'string') {

View File

@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { CoreError } from '@classes/errors/error';
import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreNetworkError } from '@classes/errors/network-error';
import { CoreFilterHelper } from '@features/filter/services/filter-helper'; import { CoreFilterHelper } from '@features/filter/services/filter-helper';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
@ -191,12 +190,7 @@ export class CoreCourseResourcePrefetchHandlerBase extends CoreCourseModulePrefe
* @param dirPath Path of the directory where to store all the content files. * @param dirPath Path of the directory where to store all the content files.
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
prefetch(module: CoreCourseWSModule, courseId?: number, single?: boolean, dirPath?: string): Promise<void> { prefetch(module: CoreCourseWSModule, courseId: number, single?: boolean, dirPath?: string): Promise<void> {
courseId = courseId || module.course;
if (!courseId) {
throw new CoreError('Course ID not supplied.');
}
return this.downloadOrPrefetch(module, courseId, true, dirPath); return this.downloadOrPrefetch(module, courseId, true, dirPath);
} }

View File

@ -182,7 +182,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
if (!CoreFilepool.getPackageDownloadPromise(siteId, handler.component, module.id)) { if (!CoreFilepool.getPackageDownloadPromise(siteId, handler.component, module.id)) {
// Not handled, the app was probably restarted or something weird happened. // Not handled, the app was probably restarted or something weird happened.
// Re-start download (files already on queue or already downloaded will be skipped). // Re-start download (files already on queue or already downloaded will be skipped).
handler.prefetch(module); handler.prefetch(module, module.course!);
} }
} else if (handler.determineStatus) { } else if (handler.determineStatus) {
// The handler implements a determineStatus function. Apply it. // The handler implements a determineStatus function. Apply it.
@ -1403,7 +1403,7 @@ export interface CoreCourseModulePrefetchHandler extends CoreDelegateHandler {
* @param dirPath Path of the directory where to store all the content files. * @param dirPath Path of the directory where to store all the content files.
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
prefetch(module: CoreCourseAnyModuleData, courseId?: number, single?: boolean, dirPath?: string): Promise<void>; prefetch(module: CoreCourseAnyModuleData, courseId: number, single?: boolean, dirPath?: string): Promise<void>;
/** /**
* Download the module. * Download the module.

View File

@ -222,14 +222,11 @@ export class CoreSitePluginsModulePrefetchHandler extends CoreCourseActivityPref
/** /**
* @inheritdoc * @inheritdoc
*/ */
prefetch(module: CoreCourseAnyModuleData, courseId?: number, single?: boolean, dirPath?: string): Promise<void> { prefetch(module: CoreCourseAnyModuleData, courseId: number, single?: boolean, dirPath?: string): Promise<void> {
const siteId = CoreSites.getCurrentSiteId();
return this.prefetchPackage( return this.prefetchPackage(
module, module,
courseId, courseId,
this.downloadPrefetchPlugin.bind(this, module, courseId, true, dirPath, siteId), this.downloadPrefetchPlugin.bind(this, module, courseId, true, dirPath),
siteId,
); );
} }