MOBILE-2354 workshop: Migrate tables from the old app
parent
973f1cdc72
commit
7a86e1beeb
|
@ -25,14 +25,14 @@ import { CoreTimeUtilsProvider } from '@providers/utils/time';
|
||||||
export class AddonModWorkshopOfflineProvider {
|
export class AddonModWorkshopOfflineProvider {
|
||||||
|
|
||||||
// Variables for database.
|
// Variables for database.
|
||||||
protected SUBMISSIONS_TABLE = 'addon_mod_workshop_submissions';
|
static SUBMISSIONS_TABLE = 'addon_mod_workshop_submissions';
|
||||||
protected ASSESSMENTS_TABLE = 'addon_mod_workshop_assessments';
|
static ASSESSMENTS_TABLE = 'addon_mod_workshop_assessments';
|
||||||
protected EVALUATE_SUBMISSIONS_TABLE = 'addon_mod_workshop_evaluate_submissions';
|
static EVALUATE_SUBMISSIONS_TABLE = 'addon_mod_workshop_evaluate_submissions';
|
||||||
protected EVALUATE_ASSESSMENTS_TABLE = 'addon_mod_workshop_evaluate_assessments';
|
static EVALUATE_ASSESSMENTS_TABLE = 'addon_mod_workshop_evaluate_assessments';
|
||||||
|
|
||||||
protected tablesSchema = [
|
protected tablesSchema = [
|
||||||
{
|
{
|
||||||
name: this.SUBMISSIONS_TABLE,
|
name: AddonModWorkshopOfflineProvider.SUBMISSIONS_TABLE,
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
name: 'workshopid',
|
name: 'workshopid',
|
||||||
|
@ -70,7 +70,7 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
primaryKeys: ['workshopid', 'submissionid', 'action']
|
primaryKeys: ['workshopid', 'submissionid', 'action']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: this.ASSESSMENTS_TABLE,
|
name: AddonModWorkshopOfflineProvider.ASSESSMENTS_TABLE,
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
name: 'workshopid',
|
name: 'workshopid',
|
||||||
|
@ -96,7 +96,7 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
primaryKeys: ['workshopid', 'assessmentid']
|
primaryKeys: ['workshopid', 'assessmentid']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: this.EVALUATE_SUBMISSIONS_TABLE,
|
name: AddonModWorkshopOfflineProvider.EVALUATE_SUBMISSIONS_TABLE,
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
name: 'workshopid',
|
name: 'workshopid',
|
||||||
|
@ -130,7 +130,7 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
primaryKeys: ['workshopid', 'submissionid']
|
primaryKeys: ['workshopid', 'submissionid']
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: this.EVALUATE_ASSESSMENTS_TABLE,
|
name: AddonModWorkshopOfflineProvider.EVALUATE_ASSESSMENTS_TABLE,
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
name: 'workshopid',
|
name: 'workshopid',
|
||||||
|
@ -240,7 +240,7 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
action: action
|
action: action
|
||||||
};
|
};
|
||||||
|
|
||||||
return site.getDb().deleteRecords(this.SUBMISSIONS_TABLE, conditions);
|
return site.getDb().deleteRecords(AddonModWorkshopOfflineProvider.SUBMISSIONS_TABLE, conditions);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
submissionid: submissionId,
|
submissionid: submissionId,
|
||||||
};
|
};
|
||||||
|
|
||||||
return site.getDb().deleteRecords(this.SUBMISSIONS_TABLE, conditions);
|
return site.getDb().deleteRecords(AddonModWorkshopOfflineProvider.SUBMISSIONS_TABLE, conditions);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,7 +271,7 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
*/
|
*/
|
||||||
getAllSubmissions(siteId?: string): Promise<any[]> {
|
getAllSubmissions(siteId?: string): Promise<any[]> {
|
||||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||||
return site.getDb().getRecords(this.SUBMISSIONS_TABLE).then((records) => {
|
return site.getDb().getRecords(AddonModWorkshopOfflineProvider.SUBMISSIONS_TABLE).then((records) => {
|
||||||
records.forEach(this.parseSubmissionRecord.bind(this));
|
records.forEach(this.parseSubmissionRecord.bind(this));
|
||||||
|
|
||||||
return records;
|
return records;
|
||||||
|
@ -292,7 +292,7 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
workshopid: workshopId
|
workshopid: workshopId
|
||||||
};
|
};
|
||||||
|
|
||||||
return site.getDb().getRecords(this.SUBMISSIONS_TABLE, conditions).then((records) => {
|
return site.getDb().getRecords(AddonModWorkshopOfflineProvider.SUBMISSIONS_TABLE, conditions).then((records) => {
|
||||||
records.forEach(this.parseSubmissionRecord.bind(this));
|
records.forEach(this.parseSubmissionRecord.bind(this));
|
||||||
|
|
||||||
return records;
|
return records;
|
||||||
|
@ -315,7 +315,7 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
submissionid: submissionId
|
submissionid: submissionId
|
||||||
};
|
};
|
||||||
|
|
||||||
return site.getDb().getRecords(this.SUBMISSIONS_TABLE, conditions).then((records) => {
|
return site.getDb().getRecords(AddonModWorkshopOfflineProvider.SUBMISSIONS_TABLE, conditions).then((records) => {
|
||||||
records.forEach(this.parseSubmissionRecord.bind(this));
|
records.forEach(this.parseSubmissionRecord.bind(this));
|
||||||
|
|
||||||
return records;
|
return records;
|
||||||
|
@ -340,7 +340,7 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
action: action
|
action: action
|
||||||
};
|
};
|
||||||
|
|
||||||
return site.getDb().getRecord(this.SUBMISSIONS_TABLE, conditions).then((record) => {
|
return site.getDb().getRecord(AddonModWorkshopOfflineProvider.SUBMISSIONS_TABLE, conditions).then((record) => {
|
||||||
this.parseSubmissionRecord(record);
|
this.parseSubmissionRecord(record);
|
||||||
|
|
||||||
return record;
|
return record;
|
||||||
|
@ -377,7 +377,7 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
timemodified: timemodified
|
timemodified: timemodified
|
||||||
};
|
};
|
||||||
|
|
||||||
return site.getDb().insertRecord(this.SUBMISSIONS_TABLE, assessment);
|
return site.getDb().insertRecord(AddonModWorkshopOfflineProvider.SUBMISSIONS_TABLE, assessment);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -405,7 +405,7 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
assessmentid: assessmentId
|
assessmentid: assessmentId
|
||||||
};
|
};
|
||||||
|
|
||||||
return site.getDb().deleteRecords(this.ASSESSMENTS_TABLE, conditions);
|
return site.getDb().deleteRecords(AddonModWorkshopOfflineProvider.ASSESSMENTS_TABLE, conditions);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,7 +417,7 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
*/
|
*/
|
||||||
getAllAssessments(siteId?: string): Promise<any[]> {
|
getAllAssessments(siteId?: string): Promise<any[]> {
|
||||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||||
return site.getDb().getRecords(this.ASSESSMENTS_TABLE).then((records) => {
|
return site.getDb().getRecords(AddonModWorkshopOfflineProvider.ASSESSMENTS_TABLE).then((records) => {
|
||||||
records.forEach(this.parseAssessmentRecord.bind(this));
|
records.forEach(this.parseAssessmentRecord.bind(this));
|
||||||
|
|
||||||
return records;
|
return records;
|
||||||
|
@ -438,7 +438,7 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
workshopid: workshopId
|
workshopid: workshopId
|
||||||
};
|
};
|
||||||
|
|
||||||
return site.getDb().getRecords(this.ASSESSMENTS_TABLE, conditions).then((records) => {
|
return site.getDb().getRecords(AddonModWorkshopOfflineProvider.ASSESSMENTS_TABLE, conditions).then((records) => {
|
||||||
records.forEach(this.parseAssessmentRecord.bind(this));
|
records.forEach(this.parseAssessmentRecord.bind(this));
|
||||||
|
|
||||||
return records;
|
return records;
|
||||||
|
@ -461,7 +461,7 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
assessmentid: assessmentId
|
assessmentid: assessmentId
|
||||||
};
|
};
|
||||||
|
|
||||||
return site.getDb().getRecord(this.ASSESSMENTS_TABLE, conditions).then((record) => {
|
return site.getDb().getRecord(AddonModWorkshopOfflineProvider.ASSESSMENTS_TABLE, conditions).then((record) => {
|
||||||
this.parseAssessmentRecord(record);
|
this.parseAssessmentRecord(record);
|
||||||
|
|
||||||
return record;
|
return record;
|
||||||
|
@ -489,7 +489,7 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
timemodified: this.timeUtils.timestamp()
|
timemodified: this.timeUtils.timestamp()
|
||||||
};
|
};
|
||||||
|
|
||||||
return site.getDb().insertRecord(this.ASSESSMENTS_TABLE, assessment);
|
return site.getDb().insertRecord(AddonModWorkshopOfflineProvider.ASSESSMENTS_TABLE, assessment);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,7 +517,7 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||||
return site.getDb().deleteRecords(this.EVALUATE_SUBMISSIONS_TABLE, conditions);
|
return site.getDb().deleteRecords(AddonModWorkshopOfflineProvider.EVALUATE_SUBMISSIONS_TABLE, conditions);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -529,7 +529,7 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
*/
|
*/
|
||||||
getAllEvaluateSubmissions(siteId?: string): Promise<any[]> {
|
getAllEvaluateSubmissions(siteId?: string): Promise<any[]> {
|
||||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||||
return site.getDb().getRecords(this.EVALUATE_SUBMISSIONS_TABLE).then((records) => {
|
return site.getDb().getRecords(AddonModWorkshopOfflineProvider.EVALUATE_SUBMISSIONS_TABLE).then((records) => {
|
||||||
records.forEach(this.parseEvaluateSubmissionRecord.bind(this));
|
records.forEach(this.parseEvaluateSubmissionRecord.bind(this));
|
||||||
|
|
||||||
return records;
|
return records;
|
||||||
|
@ -550,7 +550,8 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
workshopid: workshopId
|
workshopid: workshopId
|
||||||
};
|
};
|
||||||
|
|
||||||
return site.getDb().getRecords(this.EVALUATE_SUBMISSIONS_TABLE, conditions).then((records) => {
|
return site.getDb().getRecords(AddonModWorkshopOfflineProvider.EVALUATE_SUBMISSIONS_TABLE, conditions)
|
||||||
|
.then((records) => {
|
||||||
records.forEach(this.parseEvaluateSubmissionRecord.bind(this));
|
records.forEach(this.parseEvaluateSubmissionRecord.bind(this));
|
||||||
|
|
||||||
return records;
|
return records;
|
||||||
|
@ -573,7 +574,7 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
submissionid: submissionId
|
submissionid: submissionId
|
||||||
};
|
};
|
||||||
|
|
||||||
return site.getDb().getRecord(this.EVALUATE_SUBMISSIONS_TABLE, conditions).then((record) => {
|
return site.getDb().getRecord(AddonModWorkshopOfflineProvider.EVALUATE_SUBMISSIONS_TABLE, conditions).then((record) => {
|
||||||
this.parseEvaluateSubmissionRecord(record);
|
this.parseEvaluateSubmissionRecord(record);
|
||||||
|
|
||||||
return record;
|
return record;
|
||||||
|
@ -606,7 +607,7 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
gradeover: JSON.stringify(gradeOver)
|
gradeover: JSON.stringify(gradeOver)
|
||||||
};
|
};
|
||||||
|
|
||||||
return site.getDb().insertRecord(this.EVALUATE_SUBMISSIONS_TABLE, submission);
|
return site.getDb().insertRecord(AddonModWorkshopOfflineProvider.EVALUATE_SUBMISSIONS_TABLE, submission);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -635,7 +636,7 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
assessmentid: assessmentId
|
assessmentid: assessmentId
|
||||||
};
|
};
|
||||||
|
|
||||||
return site.getDb().deleteRecords(this.EVALUATE_ASSESSMENTS_TABLE, conditions);
|
return site.getDb().deleteRecords(AddonModWorkshopOfflineProvider.EVALUATE_ASSESSMENTS_TABLE, conditions);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -647,7 +648,7 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
*/
|
*/
|
||||||
getAllEvaluateAssessments(siteId?: string): Promise<any[]> {
|
getAllEvaluateAssessments(siteId?: string): Promise<any[]> {
|
||||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||||
return site.getDb().getRecords(this.EVALUATE_ASSESSMENTS_TABLE).then((records) => {
|
return site.getDb().getRecords(AddonModWorkshopOfflineProvider.EVALUATE_ASSESSMENTS_TABLE).then((records) => {
|
||||||
records.forEach(this.parseEvaluateAssessmentRecord.bind(this));
|
records.forEach(this.parseEvaluateAssessmentRecord.bind(this));
|
||||||
|
|
||||||
return records;
|
return records;
|
||||||
|
@ -668,7 +669,8 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
workshopid: workshopId
|
workshopid: workshopId
|
||||||
};
|
};
|
||||||
|
|
||||||
return site.getDb().getRecords(this.EVALUATE_ASSESSMENTS_TABLE, conditions).then((records) => {
|
return site.getDb().getRecords(AddonModWorkshopOfflineProvider.EVALUATE_ASSESSMENTS_TABLE, conditions)
|
||||||
|
.then((records) => {
|
||||||
records.forEach(this.parseEvaluateAssessmentRecord.bind(this));
|
records.forEach(this.parseEvaluateAssessmentRecord.bind(this));
|
||||||
|
|
||||||
return records;
|
return records;
|
||||||
|
@ -691,7 +693,7 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
assessmentid: assessmentId
|
assessmentid: assessmentId
|
||||||
};
|
};
|
||||||
|
|
||||||
return site.getDb().getRecord(this.EVALUATE_ASSESSMENTS_TABLE, conditions).then((record) => {
|
return site.getDb().getRecord(AddonModWorkshopOfflineProvider.EVALUATE_ASSESSMENTS_TABLE, conditions).then((record) => {
|
||||||
this.parseEvaluateAssessmentRecord(record);
|
this.parseEvaluateAssessmentRecord(record);
|
||||||
|
|
||||||
return record;
|
return record;
|
||||||
|
@ -724,7 +726,7 @@ export class AddonModWorkshopOfflineProvider {
|
||||||
gradinggradeover: JSON.stringify(gradingGradeOver)
|
gradinggradeover: JSON.stringify(gradingGradeOver)
|
||||||
};
|
};
|
||||||
|
|
||||||
return site.getDb().insertRecord(this.EVALUATE_ASSESSMENTS_TABLE, assessment);
|
return site.getDb().insertRecord(AddonModWorkshopOfflineProvider.EVALUATE_ASSESSMENTS_TABLE, assessment);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ import { AddonModWorkshopHelperProvider } from './providers/helper';
|
||||||
import { AddonWorkshopAssessmentStrategyDelegate } from './providers/assessment-strategy-delegate';
|
import { AddonWorkshopAssessmentStrategyDelegate } from './providers/assessment-strategy-delegate';
|
||||||
import { AddonModWorkshopPrefetchHandler } from './providers/prefetch-handler';
|
import { AddonModWorkshopPrefetchHandler } from './providers/prefetch-handler';
|
||||||
import { AddonModWorkshopSyncCronHandler } from './providers/sync-cron-handler';
|
import { AddonModWorkshopSyncCronHandler } from './providers/sync-cron-handler';
|
||||||
|
import { CoreUpdateManagerProvider } from '@providers/update-manager';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
|
@ -52,10 +53,60 @@ export class AddonModWorkshopModule {
|
||||||
constructor(moduleDelegate: CoreCourseModuleDelegate, moduleHandler: AddonModWorkshopModuleHandler,
|
constructor(moduleDelegate: CoreCourseModuleDelegate, moduleHandler: AddonModWorkshopModuleHandler,
|
||||||
contentLinksDelegate: CoreContentLinksDelegate, linkHandler: AddonModWorkshopLinkHandler,
|
contentLinksDelegate: CoreContentLinksDelegate, linkHandler: AddonModWorkshopLinkHandler,
|
||||||
prefetchDelegate: CoreCourseModulePrefetchDelegate, prefetchHandler: AddonModWorkshopPrefetchHandler,
|
prefetchDelegate: CoreCourseModulePrefetchDelegate, prefetchHandler: AddonModWorkshopPrefetchHandler,
|
||||||
cronDelegate: CoreCronDelegate, syncHandler: AddonModWorkshopSyncCronHandler) {
|
cronDelegate: CoreCronDelegate, syncHandler: AddonModWorkshopSyncCronHandler,
|
||||||
|
updateManager: CoreUpdateManagerProvider) {
|
||||||
|
|
||||||
moduleDelegate.registerHandler(moduleHandler);
|
moduleDelegate.registerHandler(moduleHandler);
|
||||||
contentLinksDelegate.registerHandler(linkHandler);
|
contentLinksDelegate.registerHandler(linkHandler);
|
||||||
prefetchDelegate.registerHandler(prefetchHandler);
|
prefetchDelegate.registerHandler(prefetchHandler);
|
||||||
cronDelegate.register(syncHandler);
|
cronDelegate.register(syncHandler);
|
||||||
|
|
||||||
|
// Allow migrating the tables from the old app to the new schema.
|
||||||
|
updateManager.registerSiteTablesMigration([
|
||||||
|
{
|
||||||
|
name: 'mma_mod_workshop_offline_submissions',
|
||||||
|
newName: AddonModWorkshopOfflineProvider.SUBMISSIONS_TABLE,
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: 'attachmentsid',
|
||||||
|
type: 'object'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'mma_mod_workshop_offline_assessments',
|
||||||
|
newName: AddonModWorkshopOfflineProvider.ASSESSMENTS_TABLE,
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: 'inputdata',
|
||||||
|
type: 'object'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'mma_mod_workshop_offline_evaluate_submissions',
|
||||||
|
newName: AddonModWorkshopOfflineProvider.EVALUATE_SUBMISSIONS_TABLE,
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: 'gradeover',
|
||||||
|
type: 'object'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'published',
|
||||||
|
type: 'boolean'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'mma_mod_workshop_offline_evaluate_assessments',
|
||||||
|
newName: AddonModWorkshopOfflineProvider.EVALUATE_ASSESSMENTS_TABLE,
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: 'gradinggradeover',
|
||||||
|
type: 'object'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue