MOBILE-2404 update: Migrate site DB addon tables

main
Dani Palou 2018-05-31 12:57:40 +02:00
parent 91035595b2
commit dcd1ab0415
35 changed files with 653 additions and 190 deletions

View File

@ -20,6 +20,7 @@ import { CoreMainMenuDelegate } from '@core/mainmenu/providers/delegate';
import { CoreInitDelegate } from '@providers/init';
import { CoreLocalNotificationsProvider } from '@providers/local-notifications';
import { CoreLoginHelperProvider } from '@core/login/providers/helper';
import { CoreUpdateManagerProvider } from '@providers/update-manager';
@NgModule({
declarations: [
@ -35,7 +36,7 @@ import { CoreLoginHelperProvider } from '@core/login/providers/helper';
export class AddonCalendarModule {
constructor(mainMenuDelegate: CoreMainMenuDelegate, calendarHandler: AddonCalendarMainMenuHandler,
initDelegate: CoreInitDelegate, calendarProvider: AddonCalendarProvider, loginHelper: CoreLoginHelperProvider,
localNotificationsProvider: CoreLocalNotificationsProvider) {
localNotificationsProvider: CoreLocalNotificationsProvider, updateManager: CoreUpdateManagerProvider) {
mainMenuDelegate.registerHandler(calendarHandler);
initDelegate.ready().then(() => {
@ -56,5 +57,15 @@ export class AddonCalendarModule {
});
}
});
// Allow migrating the table from the old app to the new schema.
// In the old app some calculated properties were stored when it shouldn't. Filter only the fields we want.
updateManager.registerSiteTableMigration({
name: 'calendar_events',
newName: AddonCalendarProvider.EVENTS_TABLE,
filterFields: ['id', 'name', 'description', 'format', 'eventtype', 'courseid', 'timestart', 'timeduration',
'categoryid', 'groupid', 'userid', 'instance', 'modulename', 'timemodified', 'repeatid', 'visible', 'uuid',
'sequence', 'subscriptionid', 'notificationtime']
});
}
}

View File

@ -36,10 +36,10 @@ export class AddonCalendarProvider {
protected DEFAULT_NOTIFICATION_TIME = 60;
// Variables for database.
protected EVENTS_TABLE = 'calendar_events';
static EVENTS_TABLE = 'addon_calendar_events';
protected tablesSchema = [
{
name: this.EVENTS_TABLE,
name: AddonCalendarProvider.EVENTS_TABLE,
columns: [
{
name: 'id',
@ -59,6 +59,10 @@ export class AddonCalendarProvider {
name: 'description',
type: 'TEXT'
},
{
name: 'format',
type: 'INTEGER'
},
{
name: 'eventtype',
type: 'TEXT'
@ -83,6 +87,10 @@ export class AddonCalendarProvider {
name: 'groupid',
type: 'INTEGER'
},
{
name: 'userid',
type: 'INTEGER'
},
{
name: 'instance',
type: 'INTEGER'
@ -98,6 +106,22 @@ export class AddonCalendarProvider {
{
name: 'repeatid',
type: 'INTEGER'
},
{
name: 'visible',
type: 'INTEGER'
},
{
name: 'uuid',
type: 'TEXT'
},
{
name: 'sequence',
type: 'INTEGER'
},
{
name: 'subscriptionid',
type: 'INTEGER'
}
]
}
@ -181,7 +205,7 @@ export class AddonCalendarProvider {
*/
getEventFromLocalDb(id: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecord(this.EVENTS_TABLE, { id: id });
return site.getDb().getRecord(AddonCalendarProvider.EVENTS_TABLE, { id: id });
});
}
@ -286,7 +310,7 @@ export class AddonCalendarProvider {
* @return {string} Prefix Cache key.
*/
protected getEventsListPrefixCacheKey(): string {
return this.ROOT_CACHE_KEY + 'eventslist:';
return this.ROOT_CACHE_KEY + 'events:';
}
/**
@ -501,20 +525,26 @@ export class AddonCalendarProvider {
id: event.id,
name: event.name,
description: event.description,
format: event.format,
eventtype: event.eventtype,
courseid: event.courseid,
timestart: event.timestart,
timeduration: event.timeduration,
categoryid: event.categoryid,
groupid: event.groupid,
userid: event.userid,
instance: event.instance,
modulename: event.modulename,
timemodified: event.timemodified,
repeatid: event.repeatid,
visible: event.visible,
uuid: event.uuid,
sequence: event.sequence,
subscriptionid: event.subscriptionid,
notificationtime: e.notificationtime || -1
};
return db.insertRecord(this.EVENTS_TABLE, eventRecord);
return db.insertRecord(AddonCalendarProvider.EVENTS_TABLE, eventRecord);
}));
});
@ -539,7 +569,7 @@ export class AddonCalendarProvider {
event.notificationtime = time;
return site.getDb().insertRecord(this.EVENTS_TABLE, event).then(() => {
return site.getDb().insertRecord(AddonCalendarProvider.EVENTS_TABLE, event).then(() => {
return this.scheduleEventNotification(event, time);
});
});

View File

@ -36,6 +36,7 @@ import { CoreSettingsDelegate } from '@core/settings/providers/delegate';
import { AddonMessagesSettingsHandler } from './providers/settings-handler';
import { AddonPushNotificationsDelegate } from '@addon/pushnotifications/providers/delegate';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreUpdateManagerProvider } from '@providers/update-manager';
@NgModule({
declarations: [
@ -63,7 +64,7 @@ export class AddonMessagesModule {
userDelegate: CoreUserDelegate, cronDelegate: CoreCronDelegate, syncHandler: AddonMessagesSyncCronHandler,
network: Network, messagesSync: AddonMessagesSyncProvider, appProvider: CoreAppProvider,
localNotifications: CoreLocalNotificationsProvider, messagesProvider: AddonMessagesProvider,
sitesProvider: CoreSitesProvider, linkHelper: CoreContentLinksHelperProvider,
sitesProvider: CoreSitesProvider, linkHelper: CoreContentLinksHelperProvider, updateManager: CoreUpdateManagerProvider,
settingsHandler: AddonMessagesSettingsHandler, settingsDelegate: CoreSettingsDelegate,
pushNotificationsDelegate: AddonPushNotificationsDelegate, utils: CoreUtilsProvider,
addContactHandler: AddonMessagesAddContactUserHandler, blockContactHandler: AddonMessagesBlockContactUserHandler) {
@ -111,5 +112,17 @@ export class AddonMessagesModule {
return true;
}
});
// Allow migrating the table from the old app to the new schema.
updateManager.registerSiteTableMigration({
name: 'mma_messages_offline_messages',
newName: AddonMessagesOfflineProvider.MESSAGES_TABLE,
fields: [
{
name: 'textformat',
delete: true
}
]
});
}
}

View File

@ -26,10 +26,10 @@ export class AddonMessagesOfflineProvider {
protected logger;
// Variables for database.
protected MESSAGES_TABLE = 'addon_messages_offline_messages';
static MESSAGES_TABLE = 'addon_messages_offline_messages';
protected tablesSchema = [
{
name: this.MESSAGES_TABLE,
name: AddonMessagesOfflineProvider.MESSAGES_TABLE,
columns: [
{
name: 'touserid',
@ -72,7 +72,7 @@ export class AddonMessagesOfflineProvider {
*/
deleteMessage(toUserId: number, message: string, timeCreated: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().deleteRecords(this.MESSAGES_TABLE, {
return site.getDb().deleteRecords(AddonMessagesOfflineProvider.MESSAGES_TABLE, {
touserid: toUserId,
smallmessage: message,
timecreated: timeCreated
@ -88,7 +88,7 @@ export class AddonMessagesOfflineProvider {
*/
getAllDeviceOfflineMessages(siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecords(this.MESSAGES_TABLE, {deviceoffline: 1});
return site.getDb().getRecords(AddonMessagesOfflineProvider.MESSAGES_TABLE, {deviceoffline: 1});
});
}
@ -101,7 +101,7 @@ export class AddonMessagesOfflineProvider {
*/
getMessages(toUserId: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecords(this.MESSAGES_TABLE, {touserid: toUserId});
return site.getDb().getRecords(AddonMessagesOfflineProvider.MESSAGES_TABLE, {touserid: toUserId});
});
}
@ -113,7 +113,7 @@ export class AddonMessagesOfflineProvider {
*/
getAllMessages(siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getAllRecords(this.MESSAGES_TABLE);
return site.getDb().getAllRecords(AddonMessagesOfflineProvider.MESSAGES_TABLE);
});
}
@ -148,7 +148,7 @@ export class AddonMessagesOfflineProvider {
deviceoffline: this.appProvider.isOnline() ? 0 : 1
};
return site.getDb().insertRecord(this.MESSAGES_TABLE, entry).then(() => {
return site.getDb().insertRecord(AddonMessagesOfflineProvider.MESSAGES_TABLE, entry).then(() => {
return entry;
});
});
@ -169,7 +169,7 @@ export class AddonMessagesOfflineProvider {
data = { deviceoffline: value ? 1 : 0 };
messages.forEach((message) => {
promises.push(db.insertRecord(this.MESSAGES_TABLE, data));
promises.push(db.insertRecord(AddonMessagesOfflineProvider.MESSAGES_TABLE, data));
});
return Promise.all(promises);

View File

@ -29,6 +29,7 @@ import { AddonModAssignPrefetchHandler } from './providers/prefetch-handler';
import { AddonModAssignSyncCronHandler } from './providers/sync-cron-handler';
import { AddonModAssignSubmissionModule } from './submission/submission.module';
import { AddonModAssignFeedbackModule } from './feedback/feedback.module';
import { CoreUpdateManagerProvider } from '@providers/update-manager';
@NgModule({
declarations: [
@ -54,9 +55,61 @@ import { AddonModAssignFeedbackModule } from './feedback/feedback.module';
export class AddonModAssignModule {
constructor(moduleDelegate: CoreCourseModuleDelegate, moduleHandler: AddonModAssignModuleHandler,
prefetchDelegate: CoreCourseModulePrefetchDelegate, prefetchHandler: AddonModAssignPrefetchHandler,
cronDelegate: CoreCronDelegate, syncHandler: AddonModAssignSyncCronHandler) {
cronDelegate: CoreCronDelegate, syncHandler: AddonModAssignSyncCronHandler, updateManager: CoreUpdateManagerProvider) {
moduleDelegate.registerHandler(moduleHandler);
prefetchDelegate.registerHandler(prefetchHandler);
cronDelegate.register(syncHandler);
// Allow migrating the tables from the old app to the new schema.
updateManager.registerSiteTablesMigration([
{
name: 'mma_mod_assign_submissions',
newName: AddonModAssignOfflineProvider.SUBMISSIONS_TABLE,
fields: [
{
name: 'assignmentid',
newName: 'assignid'
},
{
name: 'submitted',
type: 'boolean'
},
{
name: 'submissionstatement',
type: 'boolean'
},
{
name: 'plugindata',
type: 'object'
}
]
},
{
name: 'mma_mod_assign_submissions_grading',
newName: AddonModAssignOfflineProvider.SUBMISSIONS_GRADES_TABLE,
fields: [
{
name: 'assignmentid',
newName: 'assignid'
},
{
name: 'addattempt',
type: 'boolean'
},
{
name: 'applytoall',
type: 'boolean'
},
{
name: 'outcomes',
type: 'object'
},
{
name: 'plugindata',
type: 'object'
}
]
}
]);
}
}

View File

@ -28,11 +28,11 @@ export class AddonModAssignOfflineProvider {
protected logger;
// Variables for database.
protected SUBMISSIONS_TABLE = 'addon_mod_assign_submissions';
protected SUBMISSIONS_GRADES_TABLE = 'addon_mod_assign_submissions_grading';
static SUBMISSIONS_TABLE = 'addon_mod_assign_submissions';
static SUBMISSIONS_GRADES_TABLE = 'addon_mod_assign_submissions_grading';
protected tablesSchema = [
{
name: this.SUBMISSIONS_TABLE,
name: AddonModAssignOfflineProvider.SUBMISSIONS_TABLE,
columns: [
{
name: 'assignid',
@ -74,7 +74,7 @@ export class AddonModAssignOfflineProvider {
primaryKeys: ['assignid', 'userid']
},
{
name: this.SUBMISSIONS_GRADES_TABLE,
name: AddonModAssignOfflineProvider.SUBMISSIONS_GRADES_TABLE,
columns: [
{
name: 'assignid',
@ -143,7 +143,8 @@ export class AddonModAssignOfflineProvider {
return this.sitesProvider.getSite(siteId).then((site) => {
userId = userId || site.getUserId();
return site.getDb().deleteRecords(this.SUBMISSIONS_TABLE, {assignid: assignId, userid: userId});
return site.getDb().deleteRecords(AddonModAssignOfflineProvider.SUBMISSIONS_TABLE,
{assignid: assignId, userid: userId});
});
}
@ -159,7 +160,8 @@ export class AddonModAssignOfflineProvider {
return this.sitesProvider.getSite(siteId).then((site) => {
userId = userId || site.getUserId();
return site.getDb().deleteRecords(this.SUBMISSIONS_GRADES_TABLE, {assignid: assignId, userid: userId});
return site.getDb().deleteRecords(AddonModAssignOfflineProvider.SUBMISSIONS_GRADES_TABLE,
{assignid: assignId, userid: userId});
});
}
@ -201,7 +203,7 @@ export class AddonModAssignOfflineProvider {
*/
protected getAllSubmissions(siteId?: string): Promise<any[]> {
return this.sitesProvider.getSiteDb(siteId).then((db) => {
return db.getAllRecords(this.SUBMISSIONS_TABLE);
return db.getAllRecords(AddonModAssignOfflineProvider.SUBMISSIONS_TABLE);
}).then((submissions) => {
// Parse the plugin data.
@ -221,7 +223,7 @@ export class AddonModAssignOfflineProvider {
*/
protected getAllSubmissionsGrade(siteId?: string): Promise<any[]> {
return this.sitesProvider.getSiteDb(siteId).then((db) => {
return db.getAllRecords(this.SUBMISSIONS_GRADES_TABLE);
return db.getAllRecords(AddonModAssignOfflineProvider.SUBMISSIONS_GRADES_TABLE);
}).then((submissions) => {
// Parse the plugin data and outcomes.
@ -243,7 +245,7 @@ export class AddonModAssignOfflineProvider {
*/
getAssignSubmissions(assignId: number, siteId?: string): Promise<any[]> {
return this.sitesProvider.getSiteDb(siteId).then((db) => {
return db.getRecords(this.SUBMISSIONS_TABLE, {assignid: assignId});
return db.getRecords(AddonModAssignOfflineProvider.SUBMISSIONS_TABLE, {assignid: assignId});
}).then((submissions) => {
// Parse the plugin data.
@ -264,7 +266,7 @@ export class AddonModAssignOfflineProvider {
*/
getAssignSubmissionsGrade(assignId: number, siteId?: string): Promise<any[]> {
return this.sitesProvider.getSiteDb(siteId).then((db) => {
return db.getRecords(this.SUBMISSIONS_GRADES_TABLE, {assignid: assignId});
return db.getRecords(AddonModAssignOfflineProvider.SUBMISSIONS_GRADES_TABLE, {assignid: assignId});
}).then((submissions) => {
// Parse the plugin data and outcomes.
@ -289,7 +291,7 @@ export class AddonModAssignOfflineProvider {
return this.sitesProvider.getSite(siteId).then((site) => {
userId = userId || site.getUserId();
return site.getDb().getRecord(this.SUBMISSIONS_TABLE, {assignid: assignId, userid: userId});
return site.getDb().getRecord(AddonModAssignOfflineProvider.SUBMISSIONS_TABLE, {assignid: assignId, userid: userId});
}).then((submission) => {
// Parse the plugin data.
@ -331,7 +333,8 @@ export class AddonModAssignOfflineProvider {
return this.sitesProvider.getSite(siteId).then((site) => {
userId = userId || site.getUserId();
return site.getDb().getRecord(this.SUBMISSIONS_GRADES_TABLE, {assignid: assignId, userid: userId});
return site.getDb().getRecord(AddonModAssignOfflineProvider.SUBMISSIONS_GRADES_TABLE,
{assignid: assignId, userid: userId});
}).then((submission) => {
// Parse the plugin data and outcomes.
@ -423,7 +426,7 @@ export class AddonModAssignOfflineProvider {
submission.submissionstatement = acceptStatement ? 1 : 0;
submission.plugindata = submission.plugindata ? JSON.stringify(submission.plugindata) : '{}';
return site.getDb().insertRecord(this.SUBMISSIONS_TABLE, submission);
return site.getDb().insertRecord(AddonModAssignOfflineProvider.SUBMISSIONS_TABLE, submission);
});
});
}
@ -458,7 +461,7 @@ export class AddonModAssignOfflineProvider {
onlinetimemodified: timemodified
};
return site.getDb().insertRecord(this.SUBMISSIONS_TABLE, entry);
return site.getDb().insertRecord(AddonModAssignOfflineProvider.SUBMISSIONS_TABLE, entry);
});
}
@ -497,7 +500,7 @@ export class AddonModAssignOfflineProvider {
timemodified: now
};
return site.getDb().insertRecord(this.SUBMISSIONS_GRADES_TABLE, entry);
return site.getDb().insertRecord(AddonModAssignOfflineProvider.SUBMISSIONS_GRADES_TABLE, entry);
});
}
}

View File

@ -25,6 +25,7 @@ import { AddonModChoicePrefetchHandler } from './providers/prefetch-handler';
import { AddonModChoiceSyncProvider } from './providers/sync';
import { AddonModChoiceSyncCronHandler } from './providers/sync-cron-handler';
import { AddonModChoiceOfflineProvider } from './providers/offline';
import { CoreUpdateManagerProvider } from '@providers/update-manager';
@NgModule({
declarations: [
@ -46,10 +47,26 @@ export class AddonModChoiceModule {
constructor(moduleDelegate: CoreCourseModuleDelegate, moduleHandler: AddonModChoiceModuleHandler,
prefetchDelegate: CoreCourseModulePrefetchDelegate, prefetchHandler: AddonModChoicePrefetchHandler,
contentLinksDelegate: CoreContentLinksDelegate, linkHandler: AddonModChoiceLinkHandler,
cronDelegate: CoreCronDelegate, syncHandler: AddonModChoiceSyncCronHandler) {
cronDelegate: CoreCronDelegate, syncHandler: AddonModChoiceSyncCronHandler, updateManager: CoreUpdateManagerProvider) {
moduleDelegate.registerHandler(moduleHandler);
prefetchDelegate.registerHandler(prefetchHandler);
contentLinksDelegate.registerHandler(linkHandler);
cronDelegate.register(syncHandler);
// Allow migrating the tables from the old app to the new schema.
updateManager.registerSiteTableMigration({
name: 'mma_mod_choice_offline_responses',
newName: AddonModChoiceOfflineProvider.CHOICE_TABLE,
fields: [
{
name: 'responses',
type: 'object'
},
{
name: 'deleting',
type: 'boolean'
}
]
});
}
}

View File

@ -22,10 +22,10 @@ import { CoreSitesProvider } from '@providers/sites';
export class AddonModChoiceOfflineProvider {
// Variables for database.
protected CHOICE_TABLE = 'addon_mod_choice_responses';
static CHOICE_TABLE = 'addon_mod_choice_responses';
protected tablesSchema = [
{
name: this.CHOICE_TABLE,
name: AddonModChoiceOfflineProvider.CHOICE_TABLE,
columns: [
{
name: 'choiceid',
@ -76,7 +76,7 @@ export class AddonModChoiceOfflineProvider {
return this.sitesProvider.getSite(siteId).then((site) => {
userId = userId || site.getUserId();
return site.getDb().deleteRecords(this.CHOICE_TABLE, {choiceid: choiceId, userid: userId});
return site.getDb().deleteRecords(AddonModChoiceOfflineProvider.CHOICE_TABLE, {choiceid: choiceId, userid: userId});
});
}
@ -88,7 +88,7 @@ export class AddonModChoiceOfflineProvider {
*/
getResponses(siteId?: string): Promise<any[]> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecords(this.CHOICE_TABLE).then((records) => {
return site.getDb().getRecords(AddonModChoiceOfflineProvider.CHOICE_TABLE).then((records) => {
records.forEach((record) => {
record.responses = JSON.parse(record.responses);
});
@ -127,7 +127,8 @@ export class AddonModChoiceOfflineProvider {
return this.sitesProvider.getSite(siteId).then((site) => {
userId = userId || site.getUserId();
return site.getDb().getRecord(this.CHOICE_TABLE, {choiceid: choiceId, userid: userId}).then((record) => {
return site.getDb().getRecord(AddonModChoiceOfflineProvider.CHOICE_TABLE, {choiceid: choiceId, userid: userId})
.then((record) => {
record.responses = JSON.parse(record.responses);
return record;
@ -160,7 +161,7 @@ export class AddonModChoiceOfflineProvider {
timecreated: new Date().getTime()
};
return site.getDb().insertRecord(this.CHOICE_TABLE, entry);
return site.getDb().insertRecord(AddonModChoiceOfflineProvider.CHOICE_TABLE, entry);
});
}
}

View File

@ -33,6 +33,7 @@ import { AddonModDataOfflineProvider } from './providers/offline';
import { AddonModDataFieldsDelegate } from './providers/fields-delegate';
import { AddonModDataDefaultFieldHandler } from './providers/default-field-handler';
import { AddonModDataFieldModule } from './fields/field.module';
import { CoreUpdateManagerProvider } from '@providers/update-manager';
@NgModule({
declarations: [
@ -62,7 +63,7 @@ export class AddonModDataModule {
constructor(moduleDelegate: CoreCourseModuleDelegate, moduleHandler: AddonModDataModuleHandler,
prefetchDelegate: CoreCourseModulePrefetchDelegate, prefetchHandler: AddonModDataPrefetchHandler,
contentLinksDelegate: CoreContentLinksDelegate, linkHandler: AddonModDataLinkHandler,
cronDelegate: CoreCronDelegate, syncHandler: AddonModDataSyncCronHandler,
cronDelegate: CoreCronDelegate, syncHandler: AddonModDataSyncCronHandler, updateManager: CoreUpdateManagerProvider,
approveLinkHandler: AddonModDataApproveLinkHandler, deleteLinkHandler: AddonModDataDeleteLinkHandler,
showLinkHandler: AddonModDataShowLinkHandler, editLinkHandler: AddonModDataEditLinkHandler) {
moduleDelegate.registerHandler(moduleHandler);
@ -73,5 +74,21 @@ export class AddonModDataModule {
contentLinksDelegate.registerHandler(showLinkHandler);
contentLinksDelegate.registerHandler(editLinkHandler);
cronDelegate.register(syncHandler);
// Allow migrating the tables from the old app to the new schema.
updateManager.registerSiteTableMigration({
name: 'mma_mod_data_entry',
newName: AddonModDataOfflineProvider.DATA_ENTRY_TABLE,
fields: [
{
name: 'fields',
type: 'object'
},
{
name: 'dataAndEntry',
delete: true
}
]
});
}
}

View File

@ -27,10 +27,10 @@ export class AddonModDataOfflineProvider {
protected logger;
// Variables for database.
protected DATA_ENTRY_TABLE = 'addon_mod_data_entry';
static DATA_ENTRY_TABLE = 'addon_mod_data_entry';
protected tablesSchema = [
{
name: this.DATA_ENTRY_TABLE,
name: AddonModDataOfflineProvider.DATA_ENTRY_TABLE,
columns: [
{
name: 'dataid',
@ -102,7 +102,8 @@ export class AddonModDataOfflineProvider {
*/
deleteEntry(dataId: number, entryId: number, action: string, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().deleteRecords(this.DATA_ENTRY_TABLE, {dataid: dataId, entryid: entryId, action: action});
return site.getDb().deleteRecords(AddonModDataOfflineProvider.DATA_ENTRY_TABLE, {dataid: dataId, entryid: entryId,
action: action});
});
}
@ -114,7 +115,9 @@ export class AddonModDataOfflineProvider {
*/
getAllEntries(siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getAllRecords(this.DATA_ENTRY_TABLE);
return site.getDb().getAllRecords(AddonModDataOfflineProvider.DATA_ENTRY_TABLE);
}).then((entries) => {
return entries.map(this.parseRecord.bind(this));
});
}
@ -127,7 +130,9 @@ export class AddonModDataOfflineProvider {
*/
getDatabaseEntries(dataId: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecords(this.DATA_ENTRY_TABLE, {dataid: dataId});
return site.getDb().getRecords(AddonModDataOfflineProvider.DATA_ENTRY_TABLE, {dataid: dataId});
}).then((entries) => {
return entries.map(this.parseRecord.bind(this));
});
}
@ -142,7 +147,10 @@ export class AddonModDataOfflineProvider {
*/
getEntry(dataId: number, entryId: number, action: string, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecord(this.DATA_ENTRY_TABLE, {dataid: dataId, entryid: entryId, action: action});
return site.getDb().getRecord(AddonModDataOfflineProvider.DATA_ENTRY_TABLE, {dataid: dataId, entryid: entryId,
action: action});
}).then((entry) => {
return this.parseRecord(entry);
});
}
@ -156,7 +164,9 @@ export class AddonModDataOfflineProvider {
*/
getEntryActions(dataId: number, entryId: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecords(this.DATA_ENTRY_TABLE, {dataid: dataId, entryid: entryId});
return site.getDb().getRecords(AddonModDataOfflineProvider.DATA_ENTRY_TABLE, {dataid: dataId, entryid: entryId});
}).then((entries) => {
return entries.map(this.parseRecord.bind(this));
});
}
@ -208,6 +218,18 @@ export class AddonModDataOfflineProvider {
});
}
/**
* Parse "fields" of an offline record.
*
* @param {any} record Record object
* @return {any} Record object with columns parsed.
*/
protected parseRecord(record: any): any {
record.fields = this.textUtils.parseJSON(record.fields);
return record;
}
/**
* Save an entry data to be sent later.
*
@ -233,11 +255,11 @@ export class AddonModDataOfflineProvider {
groupid: groupId,
action: action,
entryid: entryId,
fields: fields,
fields: JSON.stringify(fields || []),
timemodified: timemodified
};
return site.getDb().insertRecord(this.DATA_ENTRY_TABLE, entry);
return site.getDb().insertRecord(AddonModDataOfflineProvider.DATA_ENTRY_TABLE, entry);
});
}

View File

@ -31,6 +31,7 @@ import { AddonModFeedbackPrefetchHandler } from './providers/prefetch-handler';
import { AddonModFeedbackSyncProvider } from './providers/sync';
import { AddonModFeedbackSyncCronHandler } from './providers/sync-cron-handler';
import { AddonModFeedbackOfflineProvider } from './providers/offline';
import { CoreUpdateManagerProvider } from '@providers/update-manager';
@NgModule({
declarations: [
@ -59,7 +60,7 @@ export class AddonModFeedbackModule {
prefetchDelegate: CoreCourseModulePrefetchDelegate, prefetchHandler: AddonModFeedbackPrefetchHandler,
contentLinksDelegate: CoreContentLinksDelegate, linkHandler: AddonModFeedbackLinkHandler,
cronDelegate: CoreCronDelegate, syncHandler: AddonModFeedbackSyncCronHandler,
analysisLinkHandler: AddonModFeedbackAnalysisLinkHandler,
analysisLinkHandler: AddonModFeedbackAnalysisLinkHandler, updateManager: CoreUpdateManagerProvider,
showEntriesLinkHandler: AddonModFeedbackShowEntriesLinkHandler,
showNonRespondentsLinkHandler: AddonModFeedbackShowNonRespondentsLinkHandler,
completeLinkHandler: AddonModFeedbackCompleteLinkHandler,
@ -73,5 +74,17 @@ export class AddonModFeedbackModule {
contentLinksDelegate.registerHandler(completeLinkHandler);
contentLinksDelegate.registerHandler(printLinkHandler);
cronDelegate.register(syncHandler);
// Allow migrating the tables from the old app to the new schema.
updateManager.registerSiteTableMigration({
name: 'mma_mod_feedback_responses',
newName: AddonModFeedbackOfflineProvider.FEEDBACK_TABLE,
fields: [
{
name: 'responses',
type: 'object'
}
]
});
}
}

View File

@ -27,10 +27,10 @@ export class AddonModFeedbackOfflineProvider {
protected logger;
// Variables for database.
protected FEEDBACK_TABLE = 'addon_mod_feedback_answers';
static FEEDBACK_TABLE = 'addon_mod_feedback_answers';
protected tablesSchema = [
{
name: this.FEEDBACK_TABLE,
name: AddonModFeedbackOfflineProvider.FEEDBACK_TABLE,
columns: [
{
name: 'feedbackid',
@ -73,7 +73,7 @@ export class AddonModFeedbackOfflineProvider {
*/
deleteFeedbackPageResponses(feedbackId: number, page: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().deleteRecords(this.FEEDBACK_TABLE, {feedbackid: feedbackId, page: page});
return site.getDb().deleteRecords(AddonModFeedbackOfflineProvider.FEEDBACK_TABLE, {feedbackid: feedbackId, page: page});
});
}
@ -85,7 +85,7 @@ export class AddonModFeedbackOfflineProvider {
*/
getAllFeedbackResponses(siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getAllRecords(this.FEEDBACK_TABLE).then((entries) => {
return site.getDb().getAllRecords(AddonModFeedbackOfflineProvider.FEEDBACK_TABLE).then((entries) => {
return entries.map((entry) => {
entry.responses = this.textUtils.parseJSON(entry.responses);
});
@ -102,10 +102,10 @@ export class AddonModFeedbackOfflineProvider {
*/
getFeedbackResponses(feedbackId: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecords(this.FEEDBACK_TABLE, {feedbackid: feedbackId}).then((entries) => {
return entries.map((entry) => {
entry.responses = this.textUtils.parseJSON(entry.responses);
});
return site.getDb().getRecords(AddonModFeedbackOfflineProvider.FEEDBACK_TABLE, {feedbackid: feedbackId});
}).then((entries) => {
return entries.map((entry) => {
entry.responses = this.textUtils.parseJSON(entry.responses);
});
});
}
@ -120,11 +120,11 @@ export class AddonModFeedbackOfflineProvider {
*/
getFeedbackPageResponses(feedbackId: number, page: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecord(this.FEEDBACK_TABLE, {feedbackid: feedbackId, page: page}).then((entry) => {
entry.responses = this.textUtils.parseJSON(entry.responses);
return site.getDb().getRecord(AddonModFeedbackOfflineProvider.FEEDBACK_TABLE, {feedbackid: feedbackId, page: page});
}).then((entry) => {
entry.responses = this.textUtils.parseJSON(entry.responses);
return entry;
});
return entry;
});
}
@ -161,7 +161,7 @@ export class AddonModFeedbackOfflineProvider {
timemodified: this.timeUtils.timestamp()
};
return site.getDb().insertRecord(this.FEEDBACK_TABLE, entry);
return site.getDb().insertRecord(AddonModFeedbackOfflineProvider.FEEDBACK_TABLE, entry);
});
}
}

View File

@ -27,6 +27,7 @@ import { AddonModForumSyncCronHandler } from './providers/sync-cron-handler';
import { AddonModForumIndexLinkHandler } from './providers/index-link-handler';
import { AddonModForumDiscussionLinkHandler } from './providers/discussion-link-handler';
import { AddonModForumComponentsModule } from './components/components.module';
import { CoreUpdateManagerProvider } from '@providers/update-manager';
@NgModule({
declarations: [
@ -50,11 +51,49 @@ export class AddonModForumModule {
constructor(moduleDelegate: CoreCourseModuleDelegate, moduleHandler: AddonModForumModuleHandler,
prefetchDelegate: CoreCourseModulePrefetchDelegate, prefetchHandler: AddonModForumPrefetchHandler,
cronDelegate: CoreCronDelegate, syncHandler: AddonModForumSyncCronHandler, linksDelegate: CoreContentLinksDelegate,
indexHandler: AddonModForumIndexLinkHandler, discussionHandler: AddonModForumDiscussionLinkHandler) {
indexHandler: AddonModForumIndexLinkHandler, discussionHandler: AddonModForumDiscussionLinkHandler,
updateManager: CoreUpdateManagerProvider) {
moduleDelegate.registerHandler(moduleHandler);
prefetchDelegate.registerHandler(prefetchHandler);
cronDelegate.register(syncHandler);
linksDelegate.registerHandler(indexHandler);
linksDelegate.registerHandler(discussionHandler);
// Allow migrating the tables from the old app to the new schema.
updateManager.registerSiteTablesMigration([
{
name: 'mma_mod_forum_offline_discussions',
newName: AddonModForumOfflineProvider.DISCUSSIONS_TABLE,
fields: [
{
name: 'forumAndUser',
delete: true
},
{
name: 'options',
type: 'object'
}
]
},
{
name: 'mma_mod_forum_offline_replies',
newName: AddonModForumOfflineProvider.REPLIES_TABLE,
fields: [
{
name: 'forumAndUser',
delete: true
},
{
name: 'discussionAndUser',
delete: true
},
{
name: 'options',
type: 'object'
}
]
}
]);
}
}

View File

@ -24,12 +24,12 @@ import { CoreTextUtilsProvider } from '@providers/utils/text';
export class AddonModForumOfflineProvider {
// Variables for database.
protected DISCUSSIONS_TABLE = 'addon_mod_forum_discussions';
protected REPLIES_TABLE = 'addon_mod_forum_replies';
static DISCUSSIONS_TABLE = 'addon_mod_forum_discussions';
static REPLIES_TABLE = 'addon_mod_forum_replies';
protected tablesSchema = [
{
name: this.DISCUSSIONS_TABLE,
name: AddonModForumOfflineProvider.DISCUSSIONS_TABLE,
columns: [
{
name: 'forumid',
@ -71,7 +71,7 @@ export class AddonModForumOfflineProvider {
primaryKeys: ['forumid', 'userid', 'timecreated']
},
{
name: this.REPLIES_TABLE,
name: AddonModForumOfflineProvider.REPLIES_TABLE,
columns: [
{
name: 'postid',
@ -141,7 +141,7 @@ export class AddonModForumOfflineProvider {
timecreated: timeCreated,
};
return site.getDb().deleteRecords(this.DISCUSSIONS_TABLE, conditions);
return site.getDb().deleteRecords(AddonModForumOfflineProvider.DISCUSSIONS_TABLE, conditions);
});
}
@ -162,7 +162,7 @@ export class AddonModForumOfflineProvider {
timecreated: timeCreated,
};
return site.getDb().getRecord(this.DISCUSSIONS_TABLE, conditions).then((record) => {
return site.getDb().getRecord(AddonModForumOfflineProvider.DISCUSSIONS_TABLE, conditions).then((record) => {
record.options = this.textUtils.parseJSON(record.options);
return record;
@ -178,7 +178,7 @@ export class AddonModForumOfflineProvider {
*/
getAllNewDiscussions(siteId?: string): Promise<any[]> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecords(this.DISCUSSIONS_TABLE).then(this.parseRecordOptions.bind(this));
return site.getDb().getRecords(AddonModForumOfflineProvider.DISCUSSIONS_TABLE).then(this.parseRecordOptions.bind(this));
});
}
@ -214,7 +214,8 @@ export class AddonModForumOfflineProvider {
userid: userId || site.getUserId(),
};
return site.getDb().getRecords(this.DISCUSSIONS_TABLE, conditions).then(this.parseRecordOptions.bind(this));
return site.getDb().getRecords(AddonModForumOfflineProvider.DISCUSSIONS_TABLE, conditions)
.then(this.parseRecordOptions.bind(this));
});
}
@ -248,7 +249,7 @@ export class AddonModForumOfflineProvider {
timecreated: timeCreated || new Date().getTime()
};
return site.getDb().insertRecord(this.DISCUSSIONS_TABLE, data);
return site.getDb().insertRecord(AddonModForumOfflineProvider.DISCUSSIONS_TABLE, data);
});
}
@ -267,7 +268,7 @@ export class AddonModForumOfflineProvider {
userid: userId || site.getUserId(),
};
return site.getDb().deleteRecords(this.REPLIES_TABLE, conditions);
return site.getDb().deleteRecords(AddonModForumOfflineProvider.REPLIES_TABLE, conditions);
});
}
@ -279,7 +280,7 @@ export class AddonModForumOfflineProvider {
*/
getAllReplies(siteId?: string): Promise<any[]> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecords(this.REPLIES_TABLE).then(this.parseRecordOptions.bind(this));
return site.getDb().getRecords(AddonModForumOfflineProvider.REPLIES_TABLE).then(this.parseRecordOptions.bind(this));
});
}
@ -315,7 +316,8 @@ export class AddonModForumOfflineProvider {
userid: userId || site.getUserId(),
};
return site.getDb().getRecords(this.REPLIES_TABLE, conditions).then(this.parseRecordOptions.bind(this));
return site.getDb().getRecords(AddonModForumOfflineProvider.REPLIES_TABLE, conditions)
.then(this.parseRecordOptions.bind(this));
});
}
@ -351,7 +353,8 @@ export class AddonModForumOfflineProvider {
userid: userId || site.getUserId(),
};
return site.getDb().getRecords(this.REPLIES_TABLE, conditions).then(this.parseRecordOptions.bind(this));
return site.getDb().getRecords(AddonModForumOfflineProvider.REPLIES_TABLE, conditions)
.then(this.parseRecordOptions.bind(this));
});
}
@ -386,7 +389,7 @@ export class AddonModForumOfflineProvider {
timecreated: new Date().getTime()
};
return site.getDb().insertRecord(this.REPLIES_TABLE, data);
return site.getDb().insertRecord(AddonModForumOfflineProvider.REPLIES_TABLE, data);
});
}

View File

@ -27,6 +27,7 @@ import { AddonModGlossarySyncCronHandler } from './providers/sync-cron-handler';
import { AddonModGlossaryIndexLinkHandler } from './providers/index-link-handler';
import { AddonModGlossaryEntryLinkHandler } from './providers/entry-link-handler';
import { AddonModGlossaryComponentsModule } from './components/components.module';
import { CoreUpdateManagerProvider } from '@providers/update-manager';
@NgModule({
declarations: [
@ -50,11 +51,37 @@ export class AddonModGlossaryModule {
constructor(moduleDelegate: CoreCourseModuleDelegate, moduleHandler: AddonModGlossaryModuleHandler,
prefetchDelegate: CoreCourseModulePrefetchDelegate, prefetchHandler: AddonModGlossaryPrefetchHandler,
cronDelegate: CoreCronDelegate, syncHandler: AddonModGlossarySyncCronHandler, linksDelegate: CoreContentLinksDelegate,
indexHandler: AddonModGlossaryIndexLinkHandler, discussionHandler: AddonModGlossaryEntryLinkHandler) {
indexHandler: AddonModGlossaryIndexLinkHandler, discussionHandler: AddonModGlossaryEntryLinkHandler,
updateManager: CoreUpdateManagerProvider) {
moduleDelegate.registerHandler(moduleHandler);
prefetchDelegate.registerHandler(prefetchHandler);
cronDelegate.register(syncHandler);
linksDelegate.registerHandler(indexHandler);
linksDelegate.registerHandler(discussionHandler);
// Allow migrating the tables from the old app to the new schema.
updateManager.registerSiteTableMigration({
name: 'mma_mod_glossary_add_entry',
newName: AddonModGlossaryOfflineProvider.ENTRIES_TABLE,
fields: [
{
name: 'glossaryAndConcept',
delete: true
},
{
name: 'glossaryAndUser',
delete: true
},
{
name: 'options',
type: 'object'
},
{
name: 'attachments',
type: 'object'
}
]
});
}
}

View File

@ -25,11 +25,11 @@ import { CoreTextUtilsProvider } from '@providers/utils/text';
export class AddonModGlossaryOfflineProvider {
// Variables for database.
protected ENTRIES_TABLE = 'addon_mod_glossary_entrues';
static ENTRIES_TABLE = 'addon_mod_glossary_entrues';
protected tablesSchema = [
{
name: this.ENTRIES_TABLE,
name: AddonModGlossaryOfflineProvider.ENTRIES_TABLE,
columns: [
{
name: 'glossaryid',
@ -96,7 +96,7 @@ export class AddonModGlossaryOfflineProvider {
timecreated: timeCreated,
};
return site.getDb().deleteRecords(this.ENTRIES_TABLE, conditions);
return site.getDb().deleteRecords(AddonModGlossaryOfflineProvider.ENTRIES_TABLE, conditions);
});
}
@ -108,7 +108,7 @@ export class AddonModGlossaryOfflineProvider {
*/
getAllNewEntries(siteId?: string): Promise<any[]> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecords(this.ENTRIES_TABLE).then((records: any[]) => {
return site.getDb().getRecords(AddonModGlossaryOfflineProvider.ENTRIES_TABLE).then((records: any[]) => {
return records.map(this.parseRecord.bind(this));
});
});
@ -131,7 +131,8 @@ export class AddonModGlossaryOfflineProvider {
timecreated: timeCreated,
};
return site.getDb().getRecord(this.ENTRIES_TABLE, conditions).then(this.parseRecord.bind(this));
return site.getDb().getRecord(AddonModGlossaryOfflineProvider.ENTRIES_TABLE, conditions)
.then(this.parseRecord.bind(this));
});
}
@ -150,7 +151,7 @@ export class AddonModGlossaryOfflineProvider {
userId: userId || site.getUserId(),
};
return site.getDb().getRecords(this.ENTRIES_TABLE, conditions).then((records: any[]) => {
return site.getDb().getRecords(AddonModGlossaryOfflineProvider.ENTRIES_TABLE, conditions).then((records: any[]) => {
return records.map(this.parseRecord.bind(this));
});
});
@ -172,7 +173,7 @@ export class AddonModGlossaryOfflineProvider {
concept: concept,
};
return site.getDb().getRecords(this.ENTRIES_TABLE, conditions).then((entries) => {
return site.getDb().getRecords(AddonModGlossaryOfflineProvider.ENTRIES_TABLE, conditions).then((entries) => {
if (!entries.length) {
return false;
}
@ -229,7 +230,7 @@ export class AddonModGlossaryOfflineProvider {
}
return discardPromise.then(() => {
return site.getDb().insertRecord(this.ENTRIES_TABLE, entry).then(() => false);
return site.getDb().insertRecord(AddonModGlossaryOfflineProvider.ENTRIES_TABLE, entry).then(() => false);
});
});
}

View File

@ -364,7 +364,7 @@ export class AddonModLessonIndexComponent extends CoreCourseModuleMainActivityCo
this.navCtrl.push('AddonModLessonPlayerPage', {
courseId: this.courseId,
lessonId: this.lesson.id,
pageId: this.retakeToReview.pageId,
pageId: this.retakeToReview.pageid,
password: this.password,
review: true,
retake: this.retakeToReview.retake

View File

@ -28,6 +28,7 @@ import { AddonModLessonSyncCronHandler } from './providers/sync-cron-handler';
import { AddonModLessonIndexLinkHandler } from './providers/index-link-handler';
import { AddonModLessonGradeLinkHandler } from './providers/grade-link-handler';
import { AddonModLessonReportLinkHandler } from './providers/report-link-handler';
import { CoreUpdateManagerProvider } from '@providers/update-manager';
@NgModule({
declarations: [
@ -53,7 +54,7 @@ export class AddonModLessonModule {
prefetchDelegate: CoreCourseModulePrefetchDelegate, prefetchHandler: AddonModLessonPrefetchHandler,
cronDelegate: CoreCronDelegate, syncHandler: AddonModLessonSyncCronHandler, linksDelegate: CoreContentLinksDelegate,
indexHandler: AddonModLessonIndexLinkHandler, gradeHandler: AddonModLessonGradeLinkHandler,
reportHandler: AddonModLessonReportLinkHandler) {
reportHandler: AddonModLessonReportLinkHandler, updateManager: CoreUpdateManagerProvider) {
moduleDelegate.registerHandler(moduleHandler);
prefetchDelegate.registerHandler(prefetchHandler);
@ -61,5 +62,71 @@ export class AddonModLessonModule {
linksDelegate.registerHandler(indexHandler);
linksDelegate.registerHandler(gradeHandler);
linksDelegate.registerHandler(reportHandler);
// Allow migrating the tables from the old app to the new schema.
updateManager.registerSiteTablesMigration([
{
name: 'mma_mod_lesson_password',
newName: AddonModLessonProvider.PASSWORD_TABLE,
fields: [
{
name: 'id',
newName: 'lessonid'
}
]
},
{
name: 'mma_mod_lesson_retakes',
newName: AddonModLessonOfflineProvider.RETAKES_TABLE,
fields: [
{
name: 'finished',
type: 'boolean'
},
{
name: 'outoftime',
type: 'boolean'
}
]
},
{
name: 'mma_mod_lesson_page_attempts',
newName: AddonModLessonOfflineProvider.PAGE_ATTEMPTS_TABLE,
fields: [
{
name: 'lessonAndPage',
delete: true
},
{
name: 'lessonAndRetake',
delete: true
},
{
name: 'lessonAndRetakeAndType',
delete: true
},
{
name: 'lessonAndRetakeAndPage',
delete: true
},
{
name: 'data',
type: 'object'
},
{
name: 'correct',
type: 'boolean'
},
{
name: 'userAnswer',
type: 'object'
}
]
},
{
name: 'mma_mod_lesson_retakes_finished_sync',
newName: AddonModLessonSyncProvider.RETAKES_FINISHED_TABLE
}
]);
}
}

View File

@ -29,11 +29,11 @@ export class AddonModLessonOfflineProvider {
protected logger;
// Variables for database. We use lowercase in the names to match the WS responses.
protected RETAKES_TABLE = 'addon_mod_lesson_retakes';
protected PAGE_ATTEMPTS_TABLE = 'addon_mod_lesson_page_attempts';
static RETAKES_TABLE = 'addon_mod_lesson_retakes';
static PAGE_ATTEMPTS_TABLE = 'addon_mod_lesson_page_attempts';
protected tablesSchema = [
{
name: this.RETAKES_TABLE,
name: AddonModLessonOfflineProvider.RETAKES_TABLE,
columns: [
{
name: 'lessonid',
@ -68,7 +68,7 @@ export class AddonModLessonOfflineProvider {
]
},
{
name: this.PAGE_ATTEMPTS_TABLE,
name: AddonModLessonOfflineProvider.PAGE_ATTEMPTS_TABLE,
columns: [
{
name: 'lessonid',
@ -142,7 +142,7 @@ export class AddonModLessonOfflineProvider {
*/
deleteAttempt(lessonId: number, retake: number, pageId: number, timemodified: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().deleteRecords(this.PAGE_ATTEMPTS_TABLE, {
return site.getDb().deleteRecords(AddonModLessonOfflineProvider.PAGE_ATTEMPTS_TABLE, {
lessonid: lessonId,
retake: retake,
pageid: pageId,
@ -160,7 +160,7 @@ export class AddonModLessonOfflineProvider {
*/
deleteRetake(lessonId: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().deleteRecords(this.RETAKES_TABLE, {lessonid: lessonId});
return site.getDb().deleteRecords(AddonModLessonOfflineProvider.RETAKES_TABLE, {lessonid: lessonId});
});
}
@ -175,7 +175,8 @@ export class AddonModLessonOfflineProvider {
*/
deleteRetakeAttemptsForPage(lessonId: number, retake: number, pageId: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().deleteRecords(this.PAGE_ATTEMPTS_TABLE, {lessonid: lessonId, retake: retake, pageid: pageId});
return site.getDb().deleteRecords(AddonModLessonOfflineProvider.PAGE_ATTEMPTS_TABLE, {lessonid: lessonId,
retake: retake, pageid: pageId});
});
}
@ -200,7 +201,7 @@ export class AddonModLessonOfflineProvider {
entry.outoftime = outOfTime ? 1 : 0;
entry.timemodified = this.timeUtils.timestamp();
return site.getDb().insertRecord(this.RETAKES_TABLE, entry);
return site.getDb().insertRecord(AddonModLessonOfflineProvider.RETAKES_TABLE, entry);
});
});
}
@ -213,7 +214,7 @@ export class AddonModLessonOfflineProvider {
*/
getAllAttempts(siteId?: string): Promise<any> {
return this.sitesProvider.getSiteDb(siteId).then((db) => {
return db.getAllRecords(this.PAGE_ATTEMPTS_TABLE);
return db.getAllRecords(AddonModLessonOfflineProvider.PAGE_ATTEMPTS_TABLE);
}).then((attempts) => {
return this.parsePageAttempts(attempts);
});
@ -256,7 +257,7 @@ export class AddonModLessonOfflineProvider {
*/
getAllRetakes(siteId?: string): Promise<any> {
return this.sitesProvider.getSiteDb(siteId).then((db) => {
return db.getAllRecords(this.RETAKES_TABLE);
return db.getAllRecords(AddonModLessonOfflineProvider.RETAKES_TABLE);
});
}
@ -297,7 +298,7 @@ export class AddonModLessonOfflineProvider {
*/
getLessonAttempts(lessonId: number, siteId?: string): Promise<any[]> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecords(this.PAGE_ATTEMPTS_TABLE, {lessonid: lessonId});
return site.getDb().getRecords(AddonModLessonOfflineProvider.PAGE_ATTEMPTS_TABLE, {lessonid: lessonId});
}).then((attempts) => {
return this.parsePageAttempts(attempts);
});
@ -361,7 +362,7 @@ export class AddonModLessonOfflineProvider {
*/
getRetake(lessonId: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecord(this.RETAKES_TABLE, {lessonid: lessonId});
return site.getDb().getRecord(AddonModLessonOfflineProvider.RETAKES_TABLE, {lessonid: lessonId});
});
}
@ -375,7 +376,7 @@ export class AddonModLessonOfflineProvider {
*/
getRetakeAttempts(lessonId: number, retake: number, siteId?: string): Promise<any[]> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecords(this.PAGE_ATTEMPTS_TABLE, {lessonid: lessonId, retake: retake});
return site.getDb().getRecords(AddonModLessonOfflineProvider.PAGE_ATTEMPTS_TABLE, {lessonid: lessonId, retake: retake});
}).then((attempts) => {
return this.parsePageAttempts(attempts);
});
@ -392,7 +393,8 @@ export class AddonModLessonOfflineProvider {
*/
getRetakeAttemptsForPage(lessonId: number, retake: number, pageId: number, siteId?: string): Promise<any[]> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecords(this.PAGE_ATTEMPTS_TABLE, {lessonid: lessonId, retake: retake, pageid: pageId});
return site.getDb().getRecords(AddonModLessonOfflineProvider.PAGE_ATTEMPTS_TABLE, {lessonid: lessonId, retake: retake,
pageid: pageId});
}).then((attempts) => {
return this.parsePageAttempts(attempts);
});
@ -409,7 +411,8 @@ export class AddonModLessonOfflineProvider {
*/
getRetakeAttemptsForType(lessonId: number, retake: number, type: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecords(this.PAGE_ATTEMPTS_TABLE, {lessonid: lessonId, retake: retake, type: type});
return site.getDb().getRecords(AddonModLessonOfflineProvider.PAGE_ATTEMPTS_TABLE, {lessonid: lessonId, retake: retake,
type: type});
}).then((attempts) => {
return this.parsePageAttempts(attempts);
});
@ -563,7 +566,7 @@ export class AddonModLessonOfflineProvider {
useranswer: userAnswer ? JSON.stringify(userAnswer) : null,
};
return site.getDb().insertRecord(this.PAGE_ATTEMPTS_TABLE, entry);
return site.getDb().insertRecord(AddonModLessonOfflineProvider.PAGE_ATTEMPTS_TABLE, entry);
}).then(() => {
if (page.type == AddonModLessonProvider.TYPE_QUESTION) {
// It's a question page, set it as last question page attempted.
@ -591,7 +594,7 @@ export class AddonModLessonOfflineProvider {
entry.lastquestionpage = lastPage;
entry.timemodified = this.timeUtils.timestamp();
return site.getDb().insertRecord(this.RETAKES_TABLE, entry);
return site.getDb().insertRecord(AddonModLessonOfflineProvider.RETAKES_TABLE, entry);
});
});
}

View File

@ -58,12 +58,12 @@ export class AddonModLessonSyncProvider extends CoreSyncBaseProvider {
protected componentTranslate: string;
// Variables for database.
protected RETAKES_FINISHED_TABLE = 'addon_mod_lesson_retakes_finished_sync';
static RETAKES_FINISHED_TABLE = 'addon_mod_lesson_retakes_finished_sync';
protected tablesSchema = {
name: this.RETAKES_FINISHED_TABLE,
name: AddonModLessonSyncProvider.RETAKES_FINISHED_TABLE,
columns: [
{
name: 'lessonId',
name: 'lessonid',
type: 'INTEGER',
primaryKey: true
},
@ -72,7 +72,7 @@ export class AddonModLessonSyncProvider extends CoreSyncBaseProvider {
type: 'INTEGER'
},
{
name: 'pageId',
name: 'pageid',
type: 'INTEGER'
},
{
@ -105,7 +105,7 @@ export class AddonModLessonSyncProvider extends CoreSyncBaseProvider {
*/
deleteRetakeFinishedInSync(lessonId: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().deleteRecords(this.RETAKES_FINISHED_TABLE, {lessonId});
return site.getDb().deleteRecords(AddonModLessonSyncProvider.RETAKES_FINISHED_TABLE, {lessonid: lessonId});
}).catch(() => {
// Ignore errors, maybe there is none.
});
@ -120,7 +120,7 @@ export class AddonModLessonSyncProvider extends CoreSyncBaseProvider {
*/
getRetakeFinishedInSync(lessonId: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecord(this.RETAKES_FINISHED_TABLE, {lessonId});
return site.getDb().getRecord(AddonModLessonSyncProvider.RETAKES_FINISHED_TABLE, {lessonid: lessonId});
}).catch(() => {
// Ignore errors, return undefined.
});
@ -164,10 +164,10 @@ export class AddonModLessonSyncProvider extends CoreSyncBaseProvider {
*/
setRetakeFinishedInSync(lessonId: number, retake: number, pageId: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().insertRecord(this.RETAKES_FINISHED_TABLE, {
lessonId: lessonId,
return site.getDb().insertRecord(AddonModLessonSyncProvider.RETAKES_FINISHED_TABLE, {
lessonid: lessonId,
retake: Number(retake),
pageId: Number(pageId),
pageid: Number(pageId),
timefinished: this.timeUtils.timestamp()
});
});

View File

@ -148,12 +148,12 @@ export class AddonModLessonProvider {
static LESSON_PAGE_ENDOFCLUSTER = 31;
// Variables for database.
protected PASSWORD_TABLE = 'addon_mod_lesson_password';
static PASSWORD_TABLE = 'addon_mod_lesson_password';
protected tablesSchema = {
name: this.PASSWORD_TABLE,
name: AddonModLessonProvider.PASSWORD_TABLE,
columns: [
{
name: 'lessonId',
name: 'lessonid',
type: 'INTEGER',
primaryKey: true
},
@ -2072,7 +2072,7 @@ export class AddonModLessonProvider {
*/
getStoredPassword(lessonId: number, siteId?: string): Promise<string> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecord(this.PASSWORD_TABLE, {lessonId}).then((entry) => {
return site.getDb().getRecord(AddonModLessonProvider.PASSWORD_TABLE, {lessonid: lessonId}).then((entry) => {
return entry.password;
});
});
@ -3169,7 +3169,7 @@ export class AddonModLessonProvider {
*/
removeStoredPassword(lessonId: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().deleteRecords(this.PASSWORD_TABLE, {lessonId});
return site.getDb().deleteRecords(AddonModLessonProvider.PASSWORD_TABLE, {lessonid: lessonId});
});
}
@ -3184,12 +3184,12 @@ export class AddonModLessonProvider {
storePassword(lessonId: number, password: string, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
const entry = {
lessonId: lessonId,
lessonid: lessonId,
password: password,
timemodified: Date.now()
};
return site.getDb().insertRecord(this.PASSWORD_TABLE, entry);
return site.getDb().insertRecord(AddonModLessonProvider.PASSWORD_TABLE, entry);
});
}

View File

@ -20,6 +20,7 @@ import { CoreComponentsModule } from '@components/components.module';
import { AddonModQuizAccessPasswordHandler } from './providers/handler';
import { AddonModQuizAccessPasswordComponent } from './component/password';
import { AddonModQuizAccessRuleDelegate } from '../../providers/access-rules-delegate';
import { CoreUpdateManagerProvider } from '@providers/update-manager';
@NgModule({
declarations: [
@ -42,7 +43,14 @@ import { AddonModQuizAccessRuleDelegate } from '../../providers/access-rules-del
]
})
export class AddonModQuizAccessPasswordModule {
constructor(accessRuleDelegate: AddonModQuizAccessRuleDelegate, handler: AddonModQuizAccessPasswordHandler) {
constructor(accessRuleDelegate: AddonModQuizAccessRuleDelegate, handler: AddonModQuizAccessPasswordHandler,
updateManager: CoreUpdateManagerProvider) {
accessRuleDelegate.registerHandler(handler);
// Allow migrating the tables from the old app to the new schema.
updateManager.registerSiteTableMigration({
name: 'mod_quiz_access_password',
newName: AddonModQuizAccessPasswordHandler.PASSWORD_TABLE
});
}
}

View File

@ -23,13 +23,10 @@ import { AddonModQuizAccessPasswordComponent } from '../component/password';
*/
@Injectable()
export class AddonModQuizAccessPasswordHandler implements AddonModQuizAccessRuleHandler {
name = 'AddonModQuizAccessPassword';
ruleName = 'quizaccess_password';
// Variables for database.
protected PASSWORD_TABLE = 'mod_quiz_access_password';
static PASSWORD_TABLE = 'addon_mod_quiz_access_password';
protected tableSchema = {
name: this.PASSWORD_TABLE,
name: AddonModQuizAccessPasswordHandler.PASSWORD_TABLE,
columns: [
{
name: 'id',
@ -47,6 +44,9 @@ export class AddonModQuizAccessPasswordHandler implements AddonModQuizAccessRule
]
};
name = 'AddonModQuizAccessPassword';
ruleName = 'quizaccess_password';
constructor(private sitesProvider: CoreSitesProvider) {
this.sitesProvider.createTableFromSchema(this.tableSchema);
}
@ -82,7 +82,7 @@ export class AddonModQuizAccessPasswordHandler implements AddonModQuizAccessRule
protected getPasswordEntry(quizId: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecord(this.PASSWORD_TABLE, {id: quizId});
return site.getDb().getRecord(AddonModQuizAccessPasswordHandler.PASSWORD_TABLE, {id: quizId});
});
}
@ -174,7 +174,7 @@ export class AddonModQuizAccessPasswordHandler implements AddonModQuizAccessRule
protected removePassword(quizId: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().deleteRecords(this.PASSWORD_TABLE, {id: quizId});
return site.getDb().deleteRecords(AddonModQuizAccessPasswordHandler.PASSWORD_TABLE, {id: quizId});
});
}
@ -195,7 +195,7 @@ export class AddonModQuizAccessPasswordHandler implements AddonModQuizAccessRule
timemodified: Date.now()
};
return site.getDb().insertRecord(this.PASSWORD_TABLE, entry);
return site.getDb().insertRecord(AddonModQuizAccessPasswordHandler.PASSWORD_TABLE, entry);
});
}
}

View File

@ -32,10 +32,10 @@ export class AddonModQuizOfflineProvider {
protected logger;
// Variables for database.
protected ATTEMPTS_TABLE = 'addon_mod_quiz_attempts';
static ATTEMPTS_TABLE = 'addon_mod_quiz_attempts';
protected tablesSchema = [
{
name: this.ATTEMPTS_TABLE,
name: AddonModQuizOfflineProvider.ATTEMPTS_TABLE,
columns: [
{
name: 'id', // Attempt ID.
@ -141,7 +141,7 @@ export class AddonModQuizOfflineProvider {
*/
getAllAttempts(siteId?: string): Promise<any[]> {
return this.sitesProvider.getSiteDb(siteId).then((db) => {
return db.getAllRecords(this.ATTEMPTS_TABLE);
return db.getAllRecords(AddonModQuizOfflineProvider.ATTEMPTS_TABLE);
});
}
@ -165,7 +165,7 @@ export class AddonModQuizOfflineProvider {
*/
getAttemptById(attemptId: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSiteDb(siteId).then((db) => {
return db.getRecord(this.ATTEMPTS_TABLE, {id: attemptId});
return db.getRecord(AddonModQuizOfflineProvider.ATTEMPTS_TABLE, {id: attemptId});
});
}
@ -181,7 +181,7 @@ export class AddonModQuizOfflineProvider {
return this.sitesProvider.getSite(siteId).then((site) => {
userId = userId || site.getUserId();
return site.getDb().getRecords(this.ATTEMPTS_TABLE, {quizid: quizId, userid: userId});
return site.getDb().getRecords(AddonModQuizOfflineProvider.ATTEMPTS_TABLE, {quizid: quizId, userid: userId});
});
}
@ -251,7 +251,7 @@ export class AddonModQuizOfflineProvider {
entry.timemodified = now;
entry.finished = finish ? 1 : 0;
return db.insertRecord(this.ATTEMPTS_TABLE, entry);
return db.insertRecord(AddonModQuizOfflineProvider.ATTEMPTS_TABLE, entry);
}).then(() => {
// Attempt has been saved, now we need to save the answers.
return this.saveAnswers(quiz, attempt, questions, data, now, siteId);
@ -276,7 +276,7 @@ export class AddonModQuizOfflineProvider {
// Remove the attempt.
promises.push(this.sitesProvider.getSiteDb(siteId).then((db) => {
return db.deleteRecords(this.ATTEMPTS_TABLE, {id: attemptId});
return db.deleteRecords(AddonModQuizOfflineProvider.ATTEMPTS_TABLE, {id: attemptId});
}));
return Promise.all(promises);
@ -379,7 +379,7 @@ export class AddonModQuizOfflineProvider {
*/
setAttemptCurrentPage(attemptId: number, page: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSiteDb(siteId).then((db) => {
return db.updateRecords(this.ATTEMPTS_TABLE, {currentpage: page}, {id: attemptId});
return db.updateRecords(AddonModQuizOfflineProvider.ATTEMPTS_TABLE, {currentpage: page}, {id: attemptId});
});
}
}

View File

@ -29,6 +29,7 @@ import { AddonModQuizIndexLinkHandler } from './providers/index-link-handler';
import { AddonModQuizGradeLinkHandler } from './providers/grade-link-handler';
import { AddonModQuizReviewLinkHandler } from './providers/review-link-handler';
import { AddonModQuizComponentsModule } from './components/components.module';
import { CoreUpdateManagerProvider } from '@providers/update-manager';
// Access rules.
import { AddonModQuizAccessDelayBetweenAttemptsModule } from './accessrules/delaybetweenattempts/delaybetweenattempts.module';
@ -75,7 +76,7 @@ export class AddonModQuizModule {
prefetchDelegate: CoreCourseModulePrefetchDelegate, prefetchHandler: AddonModQuizPrefetchHandler,
cronDelegate: CoreCronDelegate, syncHandler: AddonModQuizSyncCronHandler, linksDelegate: CoreContentLinksDelegate,
indexHandler: AddonModQuizIndexLinkHandler, gradeHandler: AddonModQuizGradeLinkHandler,
reviewHandler: AddonModQuizReviewLinkHandler) {
reviewHandler: AddonModQuizReviewLinkHandler, updateManager: CoreUpdateManagerProvider) {
moduleDelegate.registerHandler(moduleHandler);
prefetchDelegate.registerHandler(prefetchHandler);
@ -83,5 +84,21 @@ export class AddonModQuizModule {
linksDelegate.registerHandler(indexHandler);
linksDelegate.registerHandler(gradeHandler);
linksDelegate.registerHandler(reviewHandler);
// Allow migrating the tables from the old app to the new schema.
updateManager.registerSiteTableMigration({
name: 'mod_quiz_attempts',
newName: AddonModQuizOfflineProvider.ATTEMPTS_TABLE,
fields: [
{
name: 'quizAndUser',
delete: true
},
{
name: 'finished',
type: 'boolean'
}
]
});
}
}

View File

@ -32,11 +32,11 @@ export class AddonModScormOfflineProvider {
protected logger;
// Variables for database.
protected ATTEMPTS_TABLE = 'addon_mod_scorm_offline_attempts';
protected TRACKS_TABLE = 'addon_mod_scorm_offline_scos_tracks';
static ATTEMPTS_TABLE = 'addon_mod_scorm_offline_attempts';
static TRACKS_TABLE = 'addon_mod_scorm_offline_scos_tracks';
protected tablesSchema = [
{
name: this.ATTEMPTS_TABLE,
name: AddonModScormOfflineProvider.ATTEMPTS_TABLE,
columns: [
{
name: 'scormid',
@ -73,7 +73,7 @@ export class AddonModScormOfflineProvider {
primaryKeys: ['scormid', 'userid', 'attempt']
},
{
name: this.TRACKS_TABLE,
name: AddonModScormOfflineProvider.TRACKS_TABLE,
columns: [
{
name: 'scormid',
@ -156,7 +156,7 @@ export class AddonModScormOfflineProvider {
// Block the SCORM so it can't be synced.
this.syncProvider.blockOperation(AddonModScormProvider.COMPONENT, scormId, 'changeAttemptNumber', site.id);
return db.updateRecords(this.ATTEMPTS_TABLE, newData, currentAttemptConditions).then(() => {
return db.updateRecords(AddonModScormOfflineProvider.ATTEMPTS_TABLE, newData, currentAttemptConditions).then(() => {
// Now update the attempt number of all the tracks and mark them as not synced.
newData = {
@ -164,9 +164,11 @@ export class AddonModScormOfflineProvider {
synced: 0
};
return db.updateRecords(this.TRACKS_TABLE, newData, currentAttemptConditions).catch((error) => {
return db.updateRecords(AddonModScormOfflineProvider.TRACKS_TABLE, newData, currentAttemptConditions)
.catch((error) => {
// Failed to update the tracks, restore the old attempt number.
return db.updateRecords(this.ATTEMPTS_TABLE, { attempt: attempt }, newAttemptConditions).then(() => {
return db.updateRecords(AddonModScormOfflineProvider.ATTEMPTS_TABLE, { attempt: attempt },
newAttemptConditions).then(() => {
return Promise.reject(error);
});
});
@ -216,7 +218,7 @@ export class AddonModScormOfflineProvider {
entry.snapshot = JSON.stringify(this.removeDefaultData(snapshot));
}
return db.insertRecord(this.ATTEMPTS_TABLE, entry).then(() => {
return db.insertRecord(AddonModScormOfflineProvider.ATTEMPTS_TABLE, entry).then(() => {
// Store all the data in userData.
const promises = [];
@ -258,10 +260,12 @@ export class AddonModScormOfflineProvider {
db = site.getDb();
// Delete the attempt.
promises.push(db.deleteRecords(this.ATTEMPTS_TABLE, {scormid: scormId, userid: userId, attempt: attempt}));
promises.push(db.deleteRecords(AddonModScormOfflineProvider.ATTEMPTS_TABLE, {scormid: scormId, userid: userId,
attempt: attempt}));
// Delete all the tracks.
promises.push(db.deleteRecords(this.TRACKS_TABLE, {scormid: scormId, userid: userId, attempt: attempt}));
promises.push(db.deleteRecords(AddonModScormOfflineProvider.TRACKS_TABLE, {scormid: scormId, userid: userId,
attempt: attempt}));
return Promise.all(promises);
});
@ -331,7 +335,7 @@ export class AddonModScormOfflineProvider {
*/
getAllAttempts(siteId?: string): Promise<any[]> {
return this.sitesProvider.getSiteDb(siteId).then((db) => {
return db.getAllRecords(this.ATTEMPTS_TABLE);
return db.getAllRecords(AddonModScormOfflineProvider.ATTEMPTS_TABLE);
}).then((attempts) => {
attempts.forEach((attempt) => {
attempt.snapshot = this.textUtils.parseJSON(attempt.snapshot);
@ -354,7 +358,8 @@ export class AddonModScormOfflineProvider {
return this.sitesProvider.getSite(siteId).then((site) => {
userId = userId || site.getUserId();
return site.getDb().getRecord(this.ATTEMPTS_TABLE, {scormid: scormId, userid: userId, attempt: attempt});
return site.getDb().getRecord(AddonModScormOfflineProvider.ATTEMPTS_TABLE, {scormid: scormId, userid: userId,
attempt: attempt});
}).then((entry) => {
entry.snapshot = this.textUtils.parseJSON(entry.snapshot);
@ -391,7 +396,7 @@ export class AddonModScormOfflineProvider {
return this.sitesProvider.getSite(siteId).then((site) => {
userId = userId || site.getUserId();
return site.getDb().getRecords(this.ATTEMPTS_TABLE, {scormid: scormId, userid: userId});
return site.getDb().getRecords(AddonModScormOfflineProvider.ATTEMPTS_TABLE, {scormid: scormId, userid: userId});
}).then((attempts) => {
attempts.forEach((attempt) => {
attempt.snapshot = this.textUtils.parseJSON(attempt.snapshot);
@ -467,7 +472,7 @@ export class AddonModScormOfflineProvider {
conditions.synced = 1;
}
return site.getDb().getRecords(this.TRACKS_TABLE, conditions);
return site.getDb().getRecords(AddonModScormOfflineProvider.TRACKS_TABLE, conditions);
}).then((tracks) => {
tracks.forEach((track) => {
track.value = this.textUtils.parseJSON(track.value);
@ -704,11 +709,11 @@ export class AddonModScormOfflineProvider {
if (synchronous) {
// The insert operation is always asynchronous, always return true.
db.insertRecord(this.TRACKS_TABLE, entry);
db.insertRecord(AddonModScormOfflineProvider.TRACKS_TABLE, entry);
return true;
} else {
return db.insertRecord(this.TRACKS_TABLE, entry);
return db.insertRecord(AddonModScormOfflineProvider.TRACKS_TABLE, entry);
}
}
@ -790,7 +795,7 @@ export class AddonModScormOfflineProvider {
this.logger.debug('Mark SCO ' + scoId + ' as synced for attempt ' + attempt + ' in SCORM ' + scormId);
return site.getDb().updateRecords(this.TRACKS_TABLE, {synced: 1}, {
return site.getDb().updateRecords(AddonModScormOfflineProvider.TRACKS_TABLE, {synced: 1}, {
scormid: scormId,
userid: userId,
attempt: attempt,
@ -916,7 +921,8 @@ export class AddonModScormOfflineProvider {
snapshot: JSON.stringify(this.removeDefaultData(userData))
};
return site.getDb().updateRecords(this.ATTEMPTS_TABLE, newData, { scormid: scormId, userid: userId, attempt: attempt });
return site.getDb().updateRecords(AddonModScormOfflineProvider.ATTEMPTS_TABLE, newData, { scormid: scormId,
userid: userId, attempt: attempt });
});
}
}

View File

@ -27,6 +27,7 @@ import { AddonModScormIndexLinkHandler } from './providers/index-link-handler';
import { AddonModScormGradeLinkHandler } from './providers/grade-link-handler';
import { AddonModScormSyncProvider } from './providers/scorm-sync';
import { AddonModScormComponentsModule } from './components/components.module';
import { CoreUpdateManagerProvider } from '@providers/update-manager';
@NgModule({
declarations: [
@ -50,12 +51,49 @@ export class AddonModScormModule {
constructor(moduleDelegate: CoreCourseModuleDelegate, moduleHandler: AddonModScormModuleHandler,
prefetchDelegate: CoreCourseModulePrefetchDelegate, prefetchHandler: AddonModScormPrefetchHandler,
cronDelegate: CoreCronDelegate, syncHandler: AddonModScormSyncCronHandler, linksDelegate: CoreContentLinksDelegate,
indexHandler: AddonModScormIndexLinkHandler, gradeHandler: AddonModScormGradeLinkHandler) {
indexHandler: AddonModScormIndexLinkHandler, gradeHandler: AddonModScormGradeLinkHandler,
updateManager: CoreUpdateManagerProvider) {
moduleDelegate.registerHandler(moduleHandler);
prefetchDelegate.registerHandler(prefetchHandler);
cronDelegate.register(syncHandler);
linksDelegate.registerHandler(indexHandler);
linksDelegate.registerHandler(gradeHandler);
// Allow migrating the tables from the old app to the new schema.
updateManager.registerSiteTablesMigration([
{
name: 'mod_scorm_offline_attempts',
newName: AddonModScormOfflineProvider.ATTEMPTS_TABLE,
fields: [
{
name: 'snapshot',
type: 'object'
},
{
name: 'scormAndUser',
delete: true
}
]
},
{
name: 'mod_scorm_offline_scos_tracks',
newName: AddonModScormOfflineProvider.TRACKS_TABLE,
fields: [
{
name: 'value',
type: 'object'
},
{
name: 'scormUserAttempt',
delete: true
},
{
name: 'scormUserAttemptSynced',
delete: true
}
]
}
]);
}
}

View File

@ -26,10 +26,10 @@ export class AddonModSurveyOfflineProvider {
protected logger;
// Variables for database.
protected SURVEY_TABLE = 'addon_mod_survey_answers';
static SURVEY_TABLE = 'addon_mod_survey_answers';
protected tablesSchema = [
{
name: this.SURVEY_TABLE,
name: AddonModSurveyOfflineProvider.SURVEY_TABLE,
columns: [
{
name: 'surveyid',
@ -77,7 +77,7 @@ export class AddonModSurveyOfflineProvider {
return this.sitesProvider.getSite(siteId).then((site) => {
userId = userId || site.getUserId();
return site.getDb().deleteRecords(this.SURVEY_TABLE, {surveyid: surveyId, userid: userId});
return site.getDb().deleteRecords(AddonModSurveyOfflineProvider.SURVEY_TABLE, {surveyid: surveyId, userid: userId});
});
}
@ -89,7 +89,7 @@ export class AddonModSurveyOfflineProvider {
*/
getAllData(siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getAllRecords(this.SURVEY_TABLE).then((entries) => {
return site.getDb().getAllRecords(AddonModSurveyOfflineProvider.SURVEY_TABLE).then((entries) => {
return entries.map((entry) => {
entry.answers = this.textUtils.parseJSON(entry.answers);
});
@ -125,11 +125,11 @@ export class AddonModSurveyOfflineProvider {
return this.sitesProvider.getSite(siteId).then((site) => {
userId = userId || site.getUserId();
return site.getDb().getRecord(this.SURVEY_TABLE, {surveyid: surveyId, userid: userId}).then((entry) => {
entry.answers = this.textUtils.parseJSON(entry.answers);
return site.getDb().getRecord(AddonModSurveyOfflineProvider.SURVEY_TABLE, {surveyid: surveyId, userid: userId});
}).then((entry) => {
entry.answers = this.textUtils.parseJSON(entry.answers);
return entry;
});
return entry;
});
}
@ -171,7 +171,7 @@ export class AddonModSurveyOfflineProvider {
timecreated: new Date().getTime()
};
return site.getDb().insertRecord(this.SURVEY_TABLE, entry);
return site.getDb().insertRecord(AddonModSurveyOfflineProvider.SURVEY_TABLE, entry);
});
}
}

View File

@ -26,6 +26,7 @@ import { AddonModSurveyPrefetchHandler } from './providers/prefetch-handler';
import { AddonModSurveySyncProvider } from './providers/sync';
import { AddonModSurveySyncCronHandler } from './providers/sync-cron-handler';
import { AddonModSurveyOfflineProvider } from './providers/offline';
import { CoreUpdateManagerProvider } from '@providers/update-manager';
@NgModule({
declarations: [
@ -48,10 +49,23 @@ export class AddonModSurveyModule {
constructor(moduleDelegate: CoreCourseModuleDelegate, moduleHandler: AddonModSurveyModuleHandler,
prefetchDelegate: CoreCourseModulePrefetchDelegate, prefetchHandler: AddonModSurveyPrefetchHandler,
contentLinksDelegate: CoreContentLinksDelegate, linkHandler: AddonModSurveyLinkHandler,
cronDelegate: CoreCronDelegate, syncHandler: AddonModSurveySyncCronHandler) {
cronDelegate: CoreCronDelegate, syncHandler: AddonModSurveySyncCronHandler, updateManager: CoreUpdateManagerProvider) {
moduleDelegate.registerHandler(moduleHandler);
prefetchDelegate.registerHandler(prefetchHandler);
contentLinksDelegate.registerHandler(linkHandler);
cronDelegate.register(syncHandler);
// Allow migrating the tables from the old app to the new schema.
updateManager.registerSiteTableMigration({
name: 'mma_mod_survey_answers',
newName: AddonModSurveyOfflineProvider.SURVEY_TABLE,
fields: [
{
name: 'answers',
type: 'object'
}
]
});
}
}

View File

@ -25,10 +25,10 @@ export class AddonModWikiOfflineProvider {
protected logger;
// Variables for database.
protected NEW_PAGES_TABLE = 'addon_mod_wiki_new_pages_store';
static NEW_PAGES_TABLE = 'addon_mod_wiki_new_pages_store';
protected tablesSchema = [
{
name: this.NEW_PAGES_TABLE,
name: AddonModWikiOfflineProvider.NEW_PAGES_TABLE,
columns: [
{
name: 'wikiid',
@ -117,7 +117,7 @@ export class AddonModWikiOfflineProvider {
userId = this.convertToPositiveNumber(userId);
groupId = this.convertToPositiveNumber(groupId);
return site.getDb().deleteRecords(this.NEW_PAGES_TABLE, {
return site.getDb().deleteRecords(AddonModWikiOfflineProvider.NEW_PAGES_TABLE, {
subwikiid: subwikiId,
wikiid: wikiId,
userid: userId,
@ -135,7 +135,7 @@ export class AddonModWikiOfflineProvider {
*/
getAllNewPages(siteId?: string): Promise<any[]> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getAllRecords(this.NEW_PAGES_TABLE);
return site.getDb().getAllRecords(AddonModWikiOfflineProvider.NEW_PAGES_TABLE);
});
}
@ -160,7 +160,7 @@ export class AddonModWikiOfflineProvider {
userId = this.convertToPositiveNumber(userId);
groupId = this.convertToPositiveNumber(groupId);
return site.getDb().getRecord(this.NEW_PAGES_TABLE, {
return site.getDb().getRecord(AddonModWikiOfflineProvider.NEW_PAGES_TABLE, {
subwikiid: subwikiId,
wikiid: wikiId,
userid: userId,
@ -188,7 +188,7 @@ export class AddonModWikiOfflineProvider {
userId = this.convertToPositiveNumber(userId);
groupId = this.convertToPositiveNumber(groupId);
return site.getDb().getRecords(this.NEW_PAGES_TABLE, {
return site.getDb().getRecords(AddonModWikiOfflineProvider.NEW_PAGES_TABLE, {
subwikiid: subwikiId,
wikiid: wikiId,
userid: userId,
@ -247,10 +247,10 @@ export class AddonModWikiOfflineProvider {
contentformat: 'html',
timecreated: now,
timemodified: now,
caneditpage: true
caneditpage: 1
};
return site.getDb().insertRecord(this.NEW_PAGES_TABLE, entry);
return site.getDb().insertRecord(AddonModWikiOfflineProvider.NEW_PAGES_TABLE, entry);
});
}

View File

@ -28,6 +28,7 @@ import { AddonModWikiIndexLinkHandler } from './providers/index-link-handler';
import { AddonModWikiPageOrMapLinkHandler } from './providers/page-or-map-link-handler';
import { AddonModWikiCreateLinkHandler } from './providers/create-link-handler';
import { AddonModWikiEditLinkHandler } from './providers/edit-link-handler';
import { CoreUpdateManagerProvider } from '@providers/update-manager';
@NgModule({
declarations: [
@ -53,7 +54,8 @@ export class AddonModWikiModule {
prefetchDelegate: CoreCourseModulePrefetchDelegate, prefetchHandler: AddonModWikiPrefetchHandler,
cronDelegate: CoreCronDelegate, syncHandler: AddonModWikiSyncCronHandler, linksDelegate: CoreContentLinksDelegate,
indexHandler: AddonModWikiIndexLinkHandler, pageOrMapHandler: AddonModWikiPageOrMapLinkHandler,
createHandler: AddonModWikiCreateLinkHandler, editHandler: AddonModWikiEditLinkHandler) {
createHandler: AddonModWikiCreateLinkHandler, editHandler: AddonModWikiEditLinkHandler,
updateManager: CoreUpdateManagerProvider) {
moduleDelegate.registerHandler(moduleHandler);
prefetchDelegate.registerHandler(prefetchHandler);
@ -62,5 +64,21 @@ export class AddonModWikiModule {
linksDelegate.registerHandler(pageOrMapHandler);
linksDelegate.registerHandler(createHandler);
linksDelegate.registerHandler(editHandler);
// Allow migrating the tables from the old app to the new schema.
updateManager.registerSiteTableMigration({
name: 'mma_mod_wiki_new_pages_store',
newName: AddonModWikiOfflineProvider.NEW_PAGES_TABLE,
fields: [
{
name: 'subwikiWikiUserGroup',
delete: true
},
{
name: 'caneditpage',
type: 'boolean'
}
]
});
}
}

View File

@ -23,6 +23,7 @@ import { AddonNotesComponentsModule } from './components/components.module';
import { CoreCourseOptionsDelegate } from '@core/course/providers/options-delegate';
import { CoreCronDelegate } from '@providers/cron';
import { CoreUserDelegate } from '@core/user/providers/user-delegate';
import { CoreUpdateManagerProvider } from '@providers/update-manager';
@NgModule({
declarations: [
@ -42,10 +43,17 @@ import { CoreUserDelegate } from '@core/user/providers/user-delegate';
export class AddonNotesModule {
constructor(courseOptionsDelegate: CoreCourseOptionsDelegate, courseOptionHandler: AddonNotesCourseOptionHandler,
userDelegate: CoreUserDelegate, userHandler: AddonNotesUserHandler,
cronDelegate: CoreCronDelegate, syncHandler: AddonNotesSyncCronHandler) {
cronDelegate: CoreCronDelegate, syncHandler: AddonNotesSyncCronHandler, updateManager: CoreUpdateManagerProvider) {
// Register handlers.
courseOptionsDelegate.registerHandler(courseOptionHandler);
userDelegate.registerHandler(userHandler);
cronDelegate.register(syncHandler);
// Allow migrating the tables from the old app to the new schema.
updateManager.registerSiteTableMigration({
name: 'mma_notes_offline_notes',
newName: AddonNotesOfflineProvider.NOTES_TABLE
});
}
}

View File

@ -25,10 +25,10 @@ export class AddonNotesOfflineProvider {
protected logger;
// Variables for database.
protected NOTES_TABLE = 'addon_notes_offline_notes';
static NOTES_TABLE = 'addon_notes_offline_notes';
protected tablesSchema = [
{
name: this.NOTES_TABLE,
name: AddonNotesOfflineProvider.NOTES_TABLE,
columns: [
{
name: 'userid',
@ -79,7 +79,7 @@ export class AddonNotesOfflineProvider {
*/
deleteNote(userId: number, content: string, timecreated: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().deleteRecords(this.NOTES_TABLE, {
return site.getDb().deleteRecords(AddonNotesOfflineProvider.NOTES_TABLE, {
userid: userId,
content: content,
created: timecreated
@ -95,7 +95,7 @@ export class AddonNotesOfflineProvider {
*/
getAllNotes(siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecords(this.NOTES_TABLE);
return site.getDb().getRecords(AddonNotesOfflineProvider.NOTES_TABLE);
});
}
@ -110,7 +110,7 @@ export class AddonNotesOfflineProvider {
*/
getNote(userId: number, content: string, timecreated: number, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecord(this.NOTES_TABLE, {
return site.getDb().getRecord(AddonNotesOfflineProvider.NOTES_TABLE, {
userid: userId,
content: content,
created: timecreated
@ -127,7 +127,7 @@ export class AddonNotesOfflineProvider {
*/
getNotesForCourse(courseId: number, siteId?: string): Promise<any[]> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecords(this.NOTES_TABLE, {courseid: courseId});
return site.getDb().getRecords(AddonNotesOfflineProvider.NOTES_TABLE, {courseid: courseId});
});
}
@ -140,7 +140,7 @@ export class AddonNotesOfflineProvider {
*/
getNotesForUser(userId: number, siteId?: string): Promise<any[]> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecords(this.NOTES_TABLE, {userid: userId});
return site.getDb().getRecords(AddonNotesOfflineProvider.NOTES_TABLE, {userid: userId});
});
}
@ -153,7 +153,7 @@ export class AddonNotesOfflineProvider {
*/
getNotesWithPublishState(state: string, siteId?: string): Promise<any> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.getDb().getRecords(this.NOTES_TABLE, {publishstate: state});
return site.getDb().getRecords(AddonNotesOfflineProvider.NOTES_TABLE, {publishstate: state});
});
}
@ -219,7 +219,7 @@ export class AddonNotesOfflineProvider {
lastmodified: now
};
return site.getDb().insertRecord(this.NOTES_TABLE, data).then(() => {
return site.getDb().insertRecord(AddonNotesOfflineProvider.NOTES_TABLE, data).then(() => {
return data;
});
});

View File

@ -132,7 +132,10 @@ export class SQLiteDBMock extends SQLiteDB {
tx.executeSql(query, params, (tx, results) => {
resolve(results);
}, reject);
}, (tx, error) => {
console.error(query, params, error);
reject(error);
});
}));
});

View File

@ -371,7 +371,18 @@ export class CoreUpdateManagerProvider implements CoreInitHandler {
}
/**
* Register a table to be migrated to the new schema.
* Register several app tables to be migrated to the new schema.
*
* @param {CoreUpdateManagerMigrateTable[]} tables The tables to migrate.
*/
registerAppTablesMigration(tables: CoreUpdateManagerMigrateTable[]): void {
tables.forEach((table) => {
this.registerAppTableMigration(table);
});
}
/**
* Register an app table to be migrated to the new schema.
*
* @param {CoreUpdateManagerMigrateTable} table The table to migrate.
*/
@ -379,6 +390,26 @@ export class CoreUpdateManagerProvider implements CoreInitHandler {
this.appDBTables.push(table);
}
/**
* Register several site tables to be migrated to the new schema.
*
* @param {CoreUpdateManagerMigrateTable[]} tables The tables to migrate.
*/
registerSiteTablesMigration(tables: CoreUpdateManagerMigrateTable[]): void {
tables.forEach((table) => {
this.registerSiteTableMigration(table);
});
}
/**
* Register a site table to be migrated to the new schema.
*
* @param {CoreUpdateManagerMigrateTable} table The table to migrate.
*/
registerSiteTableMigration(table: CoreUpdateManagerMigrateTable): void {
this.siteDBTables.push(table);
}
/**
* Migrate all DBs and tables from the old format to SQLite.
*