MOBILE-3833 completion: Remove course name from completion objects

main
Pau Ferrer Ocaña 2021-12-16 13:30:33 +01:00
parent 49a1d1d806
commit 5794b66cd9
6 changed files with 30 additions and 18 deletions

View File

@ -256,7 +256,10 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy {
if (sync) {
// Try to synchronize the course data.
// For now we don't allow manual syncing, so ignore errors.
const result = await CoreUtils.ignoreErrors(CoreCourseSync.syncCourse(this.course.id));
const result = await CoreUtils.ignoreErrors(CoreCourseSync.syncCourse(
this.course.id,
this.course.displayname || this.course.fullname,
));
if (result?.warnings?.length) {
CoreDomUtils.showErrorModal(result.warnings[0]);
}

View File

@ -164,7 +164,7 @@ export class CoreCourseHelperProvider {
* @param sections List of sections to treat modules.
* @param courseId Course ID of the modules.
* @param completionStatus List of completion status.
* @param courseName Course name. Recommended if completionStatus is supplied.
* @param courseName Not used since 4.0
* @param forCoursePage Whether the data will be used to render the course page.
* @return Whether the sections have content.
*/
@ -210,7 +210,6 @@ export class CoreCourseHelperProvider {
valueused: activityStatus.valueused,
tracking: activityStatus.tracking,
courseId,
courseName,
cmid: module.id,
};
}

View File

@ -81,7 +81,7 @@ export class CoreCourseOfflineProvider {
* @param cmId The module ID to store the completion.
* @param completed Whether the module is completed or not.
* @param courseId Course ID the module belongs to.
* @param courseName Course name. Recommended, it is used to display a better warning message.
* @param courseName Not used since 4.0.
* @param siteId Site ID. If not defined, current site.
* @return Promise resolved when completion is successfully stored.
*/
@ -99,7 +99,6 @@ export class CoreCourseOfflineProvider {
cmid: cmId,
completed: completed ? 1 : 0,
courseid: courseId,
coursename: courseName || '',
timecompleted: Date.now(),
};
await site.getDb().insertRecord(MANUAL_COMPLETION_TABLE, entry);

View File

@ -1041,7 +1041,7 @@ export class CoreCourseProvider {
* @param cmId The module ID.
* @param completed Whether the module is completed or not.
* @param courseId Course ID the module belongs to.
* @param courseName Course name. Recommended, it is used to display a better warning message.
* @param courseName Not used since 4.0.
* @param siteId Site ID. If not defined, current site.
* @return Promise resolved when completion is successfully sent or stored.
*/
@ -1057,7 +1057,7 @@ export class CoreCourseProvider {
// Convenience function to store a completion to be synchronized later.
const storeOffline = (): Promise<CoreStatusWithWarningsWSResponse> =>
CoreCourseOffline.markCompletedManually(cmId, completed, courseId, courseName, siteId);
CoreCourseOffline.markCompletedManually(cmId, completed, courseId, undefined, siteId);
// The offline function requires a courseId and it could be missing because it's a calculated field.
if (!CoreApp.isOnline()) {

View File

@ -81,7 +81,7 @@ export const OFFLINE_SITE_SCHEMA: CoreSiteSchema = {
type: 'INTEGER',
},
{
name: 'coursename',
name: 'coursename', // Not used since 4.0 it can be safely removed.
type: 'TEXT',
},
{
@ -106,6 +106,5 @@ export type CoreCourseManualCompletionDBRecord = {
cmid: number;
completed: number;
courseid: number;
coursename: string;
timecompleted: number;
};

View File

@ -28,6 +28,7 @@ import { CoreCourseManualCompletionDBRecord } from './database/course';
import { CoreNetworkError } from '@classes/errors/network-error';
import { makeSingleton, Translate } from '@singletons';
import { CoreEvents } from '@singletons/events';
import { CoreCourses } from '@features/courses/services/courses';
/**
* Service to sync course offline data. This only syncs the offline data of the course itself, not the offline data of
@ -77,10 +78,18 @@ export class CoreCourseSyncProvider extends CoreSyncBaseProvider<CoreCourseSyncR
protected async syncCoursesCompletion(siteId: string, force: boolean): Promise<void> {
const completions = await CoreCourseOffline.getAllManualCompletions(siteId);
const courseNames: Record<number, string | undefined> = {};
// Sync all courses.
await Promise.all(completions.map(async (completion) => {
const result = await (force ? this.syncCourse(completion.courseid, siteId) :
this.syncCourseIfNeeded(completion.courseid, siteId));
if (courseNames[completion.courseid] === undefined) {
const course = await CoreUtils.ignoreErrors(CoreCourses.getUserCourse(completion.courseid, true, siteId));
courseNames[completion.courseid] = course?.displayname || course?.fullname;
}
const result = await (force ? this.syncCourse(completion.courseid, courseNames[completion.courseid], siteId) :
this.syncCourseIfNeeded(completion.courseid, courseNames[completion.courseid], siteId));
if (!result || !result.updated) {
return;
@ -98,23 +107,25 @@ export class CoreCourseSyncProvider extends CoreSyncBaseProvider<CoreCourseSyncR
* Sync a course if it's needed.
*
* @param courseId Course ID to be synced.
* @param courseName Course Name to be synced.
* @param siteId Site ID. If not defined, current site.
* @return Promise resolved when the course is synced or it doesn't need to be synced.
*/
syncCourseIfNeeded(courseId: number, siteId?: string): Promise<CoreCourseSyncResult> {
syncCourseIfNeeded(courseId: number, courseName?: string, siteId?: string): Promise<CoreCourseSyncResult> {
// Usually we call isSyncNeeded to check if a certain time has passed.
// However, since we barely send data for now just sync the course.
return this.syncCourse(courseId, siteId);
return this.syncCourse(courseId, courseName, siteId);
}
/**
* Synchronize a course.
*
* @param courseId Course ID to be synced.
* @param courseName Course Name to be synced.
* @param siteId Site ID. If not defined, current site.
* @return Promise resolved if sync is successful, rejected otherwise.
*/
async syncCourse(courseId: number, siteId?: string): Promise<CoreCourseSyncResult> {
async syncCourse(courseId: number, courseName?: string, siteId?: string): Promise<CoreCourseSyncResult> {
siteId = siteId || CoreSites.getCurrentSiteId();
const currentSyncPromise = this.getOngoingSync(courseId, siteId);
@ -125,17 +136,18 @@ export class CoreCourseSyncProvider extends CoreSyncBaseProvider<CoreCourseSyncR
this.logger.debug(`Try to sync course '${courseId}'`);
return this.addOngoingSync(courseId, this.syncCourseCompletion(courseId, siteId), siteId);
return this.addOngoingSync(courseId, this.syncCourseCompletion(courseId, courseName, siteId), siteId);
}
/**
* Sync course offline completion.
*
* @param courseId Course ID to be synced.
* @param courseName Course Name to be synced.
* @param siteId Site ID. If not defined, current site.
* @return Promise resolved if sync is successful, rejected otherwise.
*/
protected async syncCourseCompletion(courseId: number, siteId?: string): Promise<CoreCourseSyncResult> {
protected async syncCourseCompletion(courseId: number, courseName?: string, siteId?: string): Promise<CoreCourseSyncResult> {
const result: CoreCourseSyncResult = {
warnings: [],
updated: false,
@ -182,7 +194,7 @@ export class CoreCourseSyncProvider extends CoreSyncBaseProvider<CoreCourseSyncR
// Completion deleted, add a warning if the completion status doesn't match.
if (onlineComp.state != entry.completed) {
result.warnings.push(Translate.instant('core.course.warningofflinemanualcompletiondeleted', {
name: entry.coursename || courseId,
name: courseName || courseId,
error: Translate.instant('core.course.warningmanualcompletionmodified'),
}));
}
@ -209,7 +221,7 @@ export class CoreCourseSyncProvider extends CoreSyncBaseProvider<CoreCourseSyncR
// Completion deleted, add a warning.
result.warnings.push(Translate.instant('core.course.warningofflinemanualcompletiondeleted', {
name: entry.coursename || courseId,
name: courseName || courseId,
error: CoreTextUtils.getErrorMessageFromError(error),
}));
}