diff --git a/src/addon/calendar/providers/calendar.ts b/src/addon/calendar/providers/calendar.ts index fda684ad5..ab5b3e301 100644 --- a/src/addon/calendar/providers/calendar.ts +++ b/src/addon/calendar/providers/calendar.ts @@ -14,7 +14,7 @@ import { Injectable } from '@angular/core'; import { CoreLoggerProvider } from '@providers/logger'; -import { CoreSitesProvider } from '@providers/sites'; +import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; import { CoreSite } from '@classes/site'; import { CoreCoursesProvider } from '@core/courses/providers/courses'; import { CoreTimeUtilsProvider } from '@providers/utils/time'; @@ -23,7 +23,6 @@ import { CoreConstants } from '@core/constants'; import { CoreLocalNotificationsProvider } from '@providers/local-notifications'; import { CoreConfigProvider } from '@providers/config'; import { ILocalNotification } from '@ionic-native/local-notifications'; -import { SQLiteDBTableSchema } from '@classes/sqlitedb'; /** * Service to handle calendar events. @@ -39,95 +38,99 @@ export class AddonCalendarProvider { // Variables for database. static EVENTS_TABLE = 'addon_calendar_events'; - protected tablesSchema: SQLiteDBTableSchema[] = [ - { - name: AddonCalendarProvider.EVENTS_TABLE, - columns: [ - { - name: 'id', - type: 'INTEGER', - primaryKey: true - }, - { - name: 'notificationtime', - type: 'INTEGER' - }, - { - name: 'name', - type: 'TEXT', - notNull: true - }, - { - name: 'description', - type: 'TEXT' - }, - { - name: 'format', - type: 'INTEGER' - }, - { - name: 'eventtype', - type: 'TEXT' - }, - { - name: 'courseid', - type: 'INTEGER' - }, - { - name: 'timestart', - type: 'INTEGER' - }, - { - name: 'timeduration', - type: 'INTEGER' - }, - { - name: 'categoryid', - type: 'INTEGER' - }, - { - name: 'groupid', - type: 'INTEGER' - }, - { - name: 'userid', - type: 'INTEGER' - }, - { - name: 'instance', - type: 'INTEGER' - }, - { - name: 'modulename', - type: 'TEXT' - }, - { - name: 'timemodified', - type: 'INTEGER' - }, - { - name: 'repeatid', - type: 'INTEGER' - }, - { - name: 'visible', - type: 'INTEGER' - }, - { - name: 'uuid', - type: 'TEXT' - }, - { - name: 'sequence', - type: 'INTEGER' - }, - { - name: 'subscriptionid', - type: 'INTEGER' - } - ] - } - ]; + protected siteSchema: CoreSiteSchema = { + name: 'AddonCalendarProvider', + version: 1, + tables: [ + { + name: AddonCalendarProvider.EVENTS_TABLE, + columns: [ + { + name: 'id', + type: 'INTEGER', + primaryKey: true + }, + { + name: 'notificationtime', + type: 'INTEGER' + }, + { + name: 'name', + type: 'TEXT', + notNull: true + }, + { + name: 'description', + type: 'TEXT' + }, + { + name: 'format', + type: 'INTEGER' + }, + { + name: 'eventtype', + type: 'TEXT' + }, + { + name: 'courseid', + type: 'INTEGER' + }, + { + name: 'timestart', + type: 'INTEGER' + }, + { + name: 'timeduration', + type: 'INTEGER' + }, + { + name: 'categoryid', + type: 'INTEGER' + }, + { + name: 'groupid', + type: 'INTEGER' + }, + { + name: 'userid', + type: 'INTEGER' + }, + { + name: 'instance', + type: 'INTEGER' + }, + { + name: 'modulename', + type: 'TEXT' + }, + { + name: 'timemodified', + type: 'INTEGER' + }, + { + name: 'repeatid', + type: 'INTEGER' + }, + { + name: 'visible', + type: 'INTEGER' + }, + { + name: 'uuid', + type: 'TEXT' + }, + { + name: 'sequence', + type: 'INTEGER' + }, + { + name: 'subscriptionid', + type: 'INTEGER' + } + ] + } + ] + }; protected logger; @@ -135,7 +138,7 @@ export class AddonCalendarProvider { private coursesProvider: CoreCoursesProvider, private timeUtils: CoreTimeUtilsProvider, private localNotificationsProvider: CoreLocalNotificationsProvider, private configProvider: CoreConfigProvider) { this.logger = logger.getInstance('AddonCalendarProvider'); - this.sitesProvider.createTablesFromSchema(this.tablesSchema); + this.sitesProvider.registerSiteSchema(this.siteSchema); } /** diff --git a/src/addon/messages/providers/messages-offline.ts b/src/addon/messages/providers/messages-offline.ts index bca52ffd7..38737c50e 100644 --- a/src/addon/messages/providers/messages-offline.ts +++ b/src/addon/messages/providers/messages-offline.ts @@ -14,10 +14,9 @@ import { Injectable } from '@angular/core'; import { CoreLoggerProvider } from '@providers/logger'; -import { CoreSitesProvider } from '@providers/sites'; +import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; import { CoreAppProvider } from '@providers/app'; import { CoreTextUtilsProvider } from '@providers/utils/text'; -import { SQLiteDBTableSchema } from '@classes/sqlitedb'; /** * Service to handle Offline messages. @@ -30,65 +29,69 @@ export class AddonMessagesOfflineProvider { // Variables for database. static MESSAGES_TABLE = 'addon_messages_offline_messages'; // When group messaging isn't available or a new conversation starts. static CONVERSATION_MESSAGES_TABLE = 'addon_messages_offline_conversation_messages'; // Conversation messages. - protected tablesSchema: SQLiteDBTableSchema[] = [ - { - name: AddonMessagesOfflineProvider.MESSAGES_TABLE, - columns: [ - { - name: 'touserid', - type: 'INTEGER' - }, - { - name: 'useridfrom', - type: 'INTEGER' - }, - { - name: 'smallmessage', - type: 'TEXT' - }, - { - name: 'timecreated', - type: 'INTEGER' - }, - { - name: 'deviceoffline', // If message was stored because device was offline. - type: 'INTEGER' - } - ], - primaryKeys: ['touserid', 'smallmessage', 'timecreated'] - }, - { - name: AddonMessagesOfflineProvider.CONVERSATION_MESSAGES_TABLE, - columns: [ - { - name: 'conversationid', - type: 'INTEGER' - }, - { - name: 'text', - type: 'TEXT' - }, - { - name: 'timecreated', - type: 'INTEGER' - }, - { - name: 'deviceoffline', // If message was stored because device was offline. - type: 'INTEGER' - }, - { - name: 'conversation', // Data about the conversation. - type: 'TEXT' - } - ], - primaryKeys: ['conversationid', 'text', 'timecreated'] - } - ]; + protected siteSchema: CoreSiteSchema = { + name: 'AddonMessagesOfflineProvider', + version: 1, + tables: [ + { + name: AddonMessagesOfflineProvider.MESSAGES_TABLE, + columns: [ + { + name: 'touserid', + type: 'INTEGER' + }, + { + name: 'useridfrom', + type: 'INTEGER' + }, + { + name: 'smallmessage', + type: 'TEXT' + }, + { + name: 'timecreated', + type: 'INTEGER' + }, + { + name: 'deviceoffline', // If message was stored because device was offline. + type: 'INTEGER' + } + ], + primaryKeys: ['touserid', 'smallmessage', 'timecreated'] + }, + { + name: AddonMessagesOfflineProvider.CONVERSATION_MESSAGES_TABLE, + columns: [ + { + name: 'conversationid', + type: 'INTEGER' + }, + { + name: 'text', + type: 'TEXT' + }, + { + name: 'timecreated', + type: 'INTEGER' + }, + { + name: 'deviceoffline', // If message was stored because device was offline. + type: 'INTEGER' + }, + { + name: 'conversation', // Data about the conversation. + type: 'TEXT' + } + ], + primaryKeys: ['conversationid', 'text', 'timecreated'] + } + ] + }; constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private appProvider: CoreAppProvider, private textUtils: CoreTextUtilsProvider) { this.logger = logger.getInstance('AddonMessagesOfflineProvider'); - this.sitesProvider.createTablesFromSchema(this.tablesSchema); + this.sitesProvider.registerSiteSchema(this.siteSchema); } /** diff --git a/src/addon/mod/assign/providers/assign-offline.ts b/src/addon/mod/assign/providers/assign-offline.ts index 39b32baf6..87d630837 100644 --- a/src/addon/mod/assign/providers/assign-offline.ts +++ b/src/addon/mod/assign/providers/assign-offline.ts @@ -15,10 +15,9 @@ import { Injectable } from '@angular/core'; import { CoreFileProvider } from '@providers/file'; import { CoreLoggerProvider } from '@providers/logger'; -import { CoreSitesProvider } from '@providers/sites'; +import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; import { CoreTextUtilsProvider } from '@providers/utils/text'; import { CoreTimeUtilsProvider } from '@providers/utils/time'; -import { SQLiteDBTableSchema } from '@classes/sqlitedb'; /** * Service to handle offline assign. @@ -31,105 +30,109 @@ export class AddonModAssignOfflineProvider { // Variables for database. static SUBMISSIONS_TABLE = 'addon_mod_assign_submissions'; static SUBMISSIONS_GRADES_TABLE = 'addon_mod_assign_submissions_grading'; - protected tablesSchema: SQLiteDBTableSchema[] = [ - { - name: AddonModAssignOfflineProvider.SUBMISSIONS_TABLE, - columns: [ - { - name: 'assignid', - type: 'INTEGER' - }, - { - name: 'courseid', - type: 'INTEGER' - }, - { - name: 'userid', - type: 'INTEGER' - }, - { - name: 'plugindata', - type: 'TEXT' - }, - { - name: 'onlinetimemodified', - type: 'INTEGER' - }, - { - name: 'timecreated', - type: 'INTEGER' - }, - { - name: 'timemodified', - type: 'INTEGER' - }, - { - name: 'submitted', - type: 'INTEGER' - }, - { - name: 'submissionstatement', - type: 'INTEGER' - } - ], - primaryKeys: ['assignid', 'userid'] - }, - { - name: AddonModAssignOfflineProvider.SUBMISSIONS_GRADES_TABLE, - columns: [ - { - name: 'assignid', - type: 'INTEGER' - }, - { - name: 'courseid', - type: 'INTEGER' - }, - { - name: 'userid', - type: 'INTEGER' - }, - { - name: 'grade', - type: 'REAL' - }, - { - name: 'attemptnumber', - type: 'INTEGER' - }, - { - name: 'addattempt', - type: 'INTEGER' - }, - { - name: 'workflowstate', - type: 'TEXT' - }, - { - name: 'applytoall', - type: 'INTEGER' - }, - { - name: 'outcomes', - type: 'TEXT' - }, - { - name: 'plugindata', - type: 'TEXT' - }, - { - name: 'timemodified', - type: 'INTEGER' - } - ], - primaryKeys: ['assignid', 'userid'] - } - ]; + protected siteSchema: CoreSiteSchema = { + name: 'AddonModAssignOfflineProvider', + version: 1, + tables: [ + { + name: AddonModAssignOfflineProvider.SUBMISSIONS_TABLE, + columns: [ + { + name: 'assignid', + type: 'INTEGER' + }, + { + name: 'courseid', + type: 'INTEGER' + }, + { + name: 'userid', + type: 'INTEGER' + }, + { + name: 'plugindata', + type: 'TEXT' + }, + { + name: 'onlinetimemodified', + type: 'INTEGER' + }, + { + name: 'timecreated', + type: 'INTEGER' + }, + { + name: 'timemodified', + type: 'INTEGER' + }, + { + name: 'submitted', + type: 'INTEGER' + }, + { + name: 'submissionstatement', + type: 'INTEGER' + } + ], + primaryKeys: ['assignid', 'userid'] + }, + { + name: AddonModAssignOfflineProvider.SUBMISSIONS_GRADES_TABLE, + columns: [ + { + name: 'assignid', + type: 'INTEGER' + }, + { + name: 'courseid', + type: 'INTEGER' + }, + { + name: 'userid', + type: 'INTEGER' + }, + { + name: 'grade', + type: 'REAL' + }, + { + name: 'attemptnumber', + type: 'INTEGER' + }, + { + name: 'addattempt', + type: 'INTEGER' + }, + { + name: 'workflowstate', + type: 'TEXT' + }, + { + name: 'applytoall', + type: 'INTEGER' + }, + { + name: 'outcomes', + type: 'TEXT' + }, + { + name: 'plugindata', + type: 'TEXT' + }, + { + name: 'timemodified', + type: 'INTEGER' + } + ], + primaryKeys: ['assignid', 'userid'] + } + ] + }; constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private textUtils: CoreTextUtilsProvider, private fileProvider: CoreFileProvider, private timeUtils: CoreTimeUtilsProvider) { this.logger = logger.getInstance('AddonModAssignOfflineProvider'); - this.sitesProvider.createTablesFromSchema(this.tablesSchema); + this.sitesProvider.registerSiteSchema(this.siteSchema); } /** diff --git a/src/addon/mod/choice/providers/offline.ts b/src/addon/mod/choice/providers/offline.ts index dc8afd2fd..b4193f380 100644 --- a/src/addon/mod/choice/providers/offline.ts +++ b/src/addon/mod/choice/providers/offline.ts @@ -13,8 +13,7 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { CoreSitesProvider } from '@providers/sites'; -import { SQLiteDBTableSchema } from '@classes/sqlitedb'; +import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; /** * Service to handle offline choices. @@ -24,45 +23,50 @@ export class AddonModChoiceOfflineProvider { // Variables for database. static CHOICE_TABLE = 'addon_mod_choice_responses'; - protected tablesSchema: SQLiteDBTableSchema[] = [ - { - name: AddonModChoiceOfflineProvider.CHOICE_TABLE, - columns: [ - { - name: 'choiceid', - type: 'INTEGER' - }, - { - name: 'name', - type: 'TEXT' - }, - { - name: 'courseid', - type: 'INTEGER' - }, - { - name: 'userid', - type: 'INTEGER' - }, - { - name: 'responses', - type: 'TEXT' - }, - { - name: 'deleting', - type: 'INTEGER' - }, - { - name: 'timecreated', - type: 'INTEGER' - } - ], - primaryKeys: ['choiceid', 'userid'] - } - ]; + + protected siteSchema: CoreSiteSchema = { + name: 'AddonModChoiceOfflineProvider', + version: 1, + tables: [ + { + name: AddonModChoiceOfflineProvider.CHOICE_TABLE, + columns: [ + { + name: 'choiceid', + type: 'INTEGER' + }, + { + name: 'name', + type: 'TEXT' + }, + { + name: 'courseid', + type: 'INTEGER' + }, + { + name: 'userid', + type: 'INTEGER' + }, + { + name: 'responses', + type: 'TEXT' + }, + { + name: 'deleting', + type: 'INTEGER' + }, + { + name: 'timecreated', + type: 'INTEGER' + } + ], + primaryKeys: ['choiceid', 'userid'] + } + ] + }; constructor(private sitesProvider: CoreSitesProvider) { - this.sitesProvider.createTablesFromSchema(this.tablesSchema); + this.sitesProvider.registerSiteSchema(this.siteSchema); } /** diff --git a/src/addon/mod/feedback/providers/offline.ts b/src/addon/mod/feedback/providers/offline.ts index 80ea785f4..b9fd588ef 100644 --- a/src/addon/mod/feedback/providers/offline.ts +++ b/src/addon/mod/feedback/providers/offline.ts @@ -14,10 +14,9 @@ import { Injectable } from '@angular/core'; import { CoreLoggerProvider } from '@providers/logger'; -import { CoreSitesProvider } from '@providers/sites'; +import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; import { CoreTextUtilsProvider } from '@providers/utils/text'; import { CoreTimeUtilsProvider } from '@providers/utils/time'; -import { SQLiteDBTableSchema } from '@classes/sqlitedb'; /** * Service to handle Offline feedback. @@ -29,39 +28,43 @@ export class AddonModFeedbackOfflineProvider { // Variables for database. static FEEDBACK_TABLE = 'addon_mod_feedback_answers'; - protected tablesSchema: SQLiteDBTableSchema[] = [ - { - name: AddonModFeedbackOfflineProvider.FEEDBACK_TABLE, - columns: [ - { - name: 'feedbackid', - type: 'INTEGER' - }, - { - name: 'page', - type: 'INTEGER' - }, - { - name: 'courseid', - type: 'INTEGER' - }, - { - name: 'responses', - type: 'TEXT' - }, - { - name: 'timemodified', - type: 'INTEGER' - } - ], - primaryKeys: ['feedbackid', 'page'] - } - ]; + protected siteSchema: CoreSiteSchema = { + name: 'AddonModFeedbackOfflineProvider', + version: 1, + tables: [ + { + name: AddonModFeedbackOfflineProvider.FEEDBACK_TABLE, + columns: [ + { + name: 'feedbackid', + type: 'INTEGER' + }, + { + name: 'page', + type: 'INTEGER' + }, + { + name: 'courseid', + type: 'INTEGER' + }, + { + name: 'responses', + type: 'TEXT' + }, + { + name: 'timemodified', + type: 'INTEGER' + } + ], + primaryKeys: ['feedbackid', 'page'] + } + ] + }; constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private textUtils: CoreTextUtilsProvider, private timeUtils: CoreTimeUtilsProvider) { this.logger = logger.getInstance('AddonModFeedbackOfflineProvider'); - this.sitesProvider.createTablesFromSchema(this.tablesSchema); + this.sitesProvider.registerSiteSchema(this.siteSchema); } /** diff --git a/src/addon/mod/forum/providers/offline.ts b/src/addon/mod/forum/providers/offline.ts index 4140897d4..a5223f786 100644 --- a/src/addon/mod/forum/providers/offline.ts +++ b/src/addon/mod/forum/providers/offline.ts @@ -14,9 +14,8 @@ import { Injectable } from '@angular/core'; import { CoreFileProvider } from '@providers/file'; -import { CoreSitesProvider } from '@providers/sites'; +import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; import { CoreTextUtilsProvider } from '@providers/utils/text'; -import { SQLiteDBTableSchema } from '@classes/sqlitedb'; /** * Service to handle offline forum. @@ -28,101 +27,105 @@ export class AddonModForumOfflineProvider { static DISCUSSIONS_TABLE = 'addon_mod_forum_discussions'; static REPLIES_TABLE = 'addon_mod_forum_replies'; - protected tablesSchema: SQLiteDBTableSchema[] = [ - { - name: AddonModForumOfflineProvider.DISCUSSIONS_TABLE, - columns: [ - { - name: 'forumid', - type: 'INTEGER', - }, - { - name: 'name', - type: 'TEXT', - }, - { - name: 'courseid', - type: 'INTEGER', - }, - { - name: 'subject', - type: 'TEXT', - }, - { - name: 'message', - type: 'TEXT', - }, - { - name: 'options', - type: 'TEXT', - }, - { - name: 'groupid', - type: 'INTEGER', - }, - { - name: 'userid', - type: 'INTEGER', - }, - { - name: 'timecreated', - type: 'INTEGER', - } - ], - primaryKeys: ['forumid', 'userid', 'timecreated'] - }, - { - name: AddonModForumOfflineProvider.REPLIES_TABLE, - columns: [ - { - name: 'postid', - type: 'INTEGER', - }, - { - name: 'discussionid', - type: 'INTEGER', - }, - { - name: 'forumid', - type: 'INTEGER', - }, - { - name: 'name', - type: 'TEXT', - }, - { - name: 'courseid', - type: 'INTEGER', - }, - { - name: 'subject', - type: 'TEXT', - }, - { - name: 'message', - type: 'TEXT', - }, - { - name: 'options', - type: 'TEXT', - }, - { - name: 'userid', - type: 'INTEGER', - }, - { - name: 'timecreated', - type: 'INTEGER', - } - ], - primaryKeys: ['postid', 'userid'] - } - ]; + protected siteSchema: CoreSiteSchema = { + name: 'AddonModForumOfflineProvider', + version: 1, + tables: [ + { + name: AddonModForumOfflineProvider.DISCUSSIONS_TABLE, + columns: [ + { + name: 'forumid', + type: 'INTEGER', + }, + { + name: 'name', + type: 'TEXT', + }, + { + name: 'courseid', + type: 'INTEGER', + }, + { + name: 'subject', + type: 'TEXT', + }, + { + name: 'message', + type: 'TEXT', + }, + { + name: 'options', + type: 'TEXT', + }, + { + name: 'groupid', + type: 'INTEGER', + }, + { + name: 'userid', + type: 'INTEGER', + }, + { + name: 'timecreated', + type: 'INTEGER', + } + ], + primaryKeys: ['forumid', 'userid', 'timecreated'] + }, + { + name: AddonModForumOfflineProvider.REPLIES_TABLE, + columns: [ + { + name: 'postid', + type: 'INTEGER', + }, + { + name: 'discussionid', + type: 'INTEGER', + }, + { + name: 'forumid', + type: 'INTEGER', + }, + { + name: 'name', + type: 'TEXT', + }, + { + name: 'courseid', + type: 'INTEGER', + }, + { + name: 'subject', + type: 'TEXT', + }, + { + name: 'message', + type: 'TEXT', + }, + { + name: 'options', + type: 'TEXT', + }, + { + name: 'userid', + type: 'INTEGER', + }, + { + name: 'timecreated', + type: 'INTEGER', + } + ], + primaryKeys: ['postid', 'userid'] + } + ] + }; constructor(private fileProvider: CoreFileProvider, private sitesProvider: CoreSitesProvider, private textUtils: CoreTextUtilsProvider) { - this.sitesProvider.createTablesFromSchema(this.tablesSchema); + this.sitesProvider.registerSiteSchema(this.siteSchema); } /** diff --git a/src/addon/mod/glossary/providers/offline.ts b/src/addon/mod/glossary/providers/offline.ts index 20b0ef53d..ffe5aef84 100644 --- a/src/addon/mod/glossary/providers/offline.ts +++ b/src/addon/mod/glossary/providers/offline.ts @@ -14,10 +14,9 @@ import { Injectable } from '@angular/core'; import { CoreFileProvider } from '@providers/file'; -import { CoreSitesProvider } from '@providers/sites'; +import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreTextUtilsProvider } from '@providers/utils/text'; -import { SQLiteDBTableSchema } from '@classes/sqlitedb'; /** * Service to handle offline glossary. @@ -28,56 +27,60 @@ export class AddonModGlossaryOfflineProvider { // Variables for database. static ENTRIES_TABLE = 'addon_mod_glossary_entrues'; - protected tablesSchema: SQLiteDBTableSchema[] = [ - { - name: AddonModGlossaryOfflineProvider.ENTRIES_TABLE, - columns: [ - { - name: 'glossaryid', - type: 'INTEGER', - }, - { - name: 'courseid', - type: 'INTEGER', - }, - { - name: 'concept', - type: 'TEXT', - }, - { - name: 'definition', - type: 'TEXT', - }, - { - name: 'definitionformat', - type: 'TEXT', - }, - { - name: 'userid', - type: 'INTEGER', - }, - { - name: 'timecreated', - type: 'INTEGER', - }, - { - name: 'options', - type: 'TEXT', - }, - { - name: 'attachments', - type: 'TEXT', - }, - ], - primaryKeys: ['glossaryid', 'concept', 'timecreated'] - } - ]; + protected siteSchema: CoreSiteSchema = { + name: 'AddonModGlossaryOfflineProvider', + version: 1, + tables: [ + { + name: AddonModGlossaryOfflineProvider.ENTRIES_TABLE, + columns: [ + { + name: 'glossaryid', + type: 'INTEGER', + }, + { + name: 'courseid', + type: 'INTEGER', + }, + { + name: 'concept', + type: 'TEXT', + }, + { + name: 'definition', + type: 'TEXT', + }, + { + name: 'definitionformat', + type: 'TEXT', + }, + { + name: 'userid', + type: 'INTEGER', + }, + { + name: 'timecreated', + type: 'INTEGER', + }, + { + name: 'options', + type: 'TEXT', + }, + { + name: 'attachments', + type: 'TEXT', + }, + ], + primaryKeys: ['glossaryid', 'concept', 'timecreated'] + } + ] + }; constructor(private fileProvider: CoreFileProvider, private sitesProvider: CoreSitesProvider, private textUtils: CoreTextUtilsProvider, private utils: CoreUtilsProvider) { - this.sitesProvider.createTablesFromSchema(this.tablesSchema); + this.sitesProvider.registerSiteSchema(this.siteSchema); } /** diff --git a/src/addon/mod/lesson/providers/lesson-offline.ts b/src/addon/mod/lesson/providers/lesson-offline.ts index 32dcdc74c..1d7882461 100644 --- a/src/addon/mod/lesson/providers/lesson-offline.ts +++ b/src/addon/mod/lesson/providers/lesson-offline.ts @@ -14,11 +14,10 @@ import { Injectable } from '@angular/core'; import { CoreLoggerProvider } from '@providers/logger'; -import { CoreSitesProvider } from '@providers/sites'; +import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; import { CoreTextUtilsProvider } from '@providers/utils/text'; import { CoreTimeUtilsProvider } from '@providers/utils/time'; import { CoreUtilsProvider } from '@providers/utils/utils'; -import { SQLiteDBTableSchema } from '@classes/sqlitedb'; import { AddonModLessonProvider } from './lesson'; /** @@ -32,103 +31,108 @@ export class AddonModLessonOfflineProvider { // Variables for database. We use lowercase in the names to match the WS responses. static RETAKES_TABLE = 'addon_mod_lesson_retakes'; static PAGE_ATTEMPTS_TABLE = 'addon_mod_lesson_page_attempts'; - protected tablesSchema: SQLiteDBTableSchema[] = [ - { - name: AddonModLessonOfflineProvider.RETAKES_TABLE, - columns: [ - { - name: 'lessonid', - type: 'INTEGER', - primaryKey: true // Only 1 offline retake per lesson. - }, - { - name: 'retake', // Retake number. - type: 'INTEGER', - notNull: true - }, - { - name: 'courseid', - type: 'INTEGER' - }, - { - name: 'finished', - type: 'INTEGER' - }, - { - name: 'outoftime', - type: 'INTEGER' - }, - { - name: 'timemodified', - type: 'INTEGER' - }, - { - name: 'lastquestionpage', - type: 'INTEGER' - }, - ] - }, - { - name: AddonModLessonOfflineProvider.PAGE_ATTEMPTS_TABLE, - columns: [ - { - name: 'lessonid', - type: 'INTEGER', - notNull: true - }, - { - name: 'retake', // Retake number. - type: 'INTEGER', - notNull: true - }, - { - name: 'pageid', - type: 'INTEGER', - notNull: true - }, - { - name: 'timemodified', - type: 'INTEGER', - notNull: true - }, - { - name: 'courseid', - type: 'INTEGER' - }, - { - name: 'data', - type: 'TEXT' - }, - { - name: 'type', - type: 'INTEGER' - }, - { - name: 'newpageid', - type: 'INTEGER' - }, - { - name: 'correct', - type: 'INTEGER' - }, - { - name: 'answerid', - type: 'INTEGER' - }, - { - name: 'useranswer', - type: 'TEXT' - }, - ], - primaryKeys: ['lessonid', 'retake', 'pageid', 'timemodified'] // A user can attempt several times per page and retake. - } - ]; + protected siteSchema: CoreSiteSchema = { + name: 'AddonModLessonOfflineProvider', + version: 1, + tables: [ + { + name: AddonModLessonOfflineProvider.RETAKES_TABLE, + columns: [ + { + name: 'lessonid', + type: 'INTEGER', + primaryKey: true // Only 1 offline retake per lesson. + }, + { + name: 'retake', // Retake number. + type: 'INTEGER', + notNull: true + }, + { + name: 'courseid', + type: 'INTEGER' + }, + { + name: 'finished', + type: 'INTEGER' + }, + { + name: 'outoftime', + type: 'INTEGER' + }, + { + name: 'timemodified', + type: 'INTEGER' + }, + { + name: 'lastquestionpage', + type: 'INTEGER' + }, + ] + }, + { + name: AddonModLessonOfflineProvider.PAGE_ATTEMPTS_TABLE, + columns: [ + { + name: 'lessonid', + type: 'INTEGER', + notNull: true + }, + { + name: 'retake', // Retake number. + type: 'INTEGER', + notNull: true + }, + { + name: 'pageid', + type: 'INTEGER', + notNull: true + }, + { + name: 'timemodified', + type: 'INTEGER', + notNull: true + }, + { + name: 'courseid', + type: 'INTEGER' + }, + { + name: 'data', + type: 'TEXT' + }, + { + name: 'type', + type: 'INTEGER' + }, + { + name: 'newpageid', + type: 'INTEGER' + }, + { + name: 'correct', + type: 'INTEGER' + }, + { + name: 'answerid', + type: 'INTEGER' + }, + { + name: 'useranswer', + type: 'TEXT' + }, + ], + // A user can attempt several times per page and retake. + primaryKeys: ['lessonid', 'retake', 'pageid', 'timemodified'] + } + ] + }; constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private timeUtils: CoreTimeUtilsProvider, private textUtils: CoreTextUtilsProvider, private utils: CoreUtilsProvider) { this.logger = logger.getInstance('AddonModLessonOfflineProvider'); - this.sitesProvider.createTablesFromSchema(this.tablesSchema); + this.sitesProvider.registerSiteSchema(this.siteSchema); } /** diff --git a/src/addon/mod/lesson/providers/lesson-sync.ts b/src/addon/mod/lesson/providers/lesson-sync.ts index 1e250f951..1dfafc0d4 100644 --- a/src/addon/mod/lesson/providers/lesson-sync.ts +++ b/src/addon/mod/lesson/providers/lesson-sync.ts @@ -17,7 +17,7 @@ import { TranslateService } from '@ngx-translate/core'; import { CoreAppProvider } from '@providers/app'; import { CoreEventsProvider } from '@providers/events'; import { CoreLoggerProvider } from '@providers/logger'; -import { CoreSitesProvider } from '@providers/sites'; +import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; import { CoreSyncProvider } from '@providers/sync'; import { CoreTextUtilsProvider } from '@providers/utils/text'; import { CoreTimeUtilsProvider } from '@providers/utils/time'; @@ -25,7 +25,6 @@ import { CoreUrlUtilsProvider } from '@providers/utils/url'; import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreCourseProvider } from '@core/course/providers/course'; import { CoreSyncBaseProvider } from '@classes/base-sync'; -import { SQLiteDBTableSchema } from '@classes/sqlitedb'; import { AddonModLessonProvider } from './lesson'; import { AddonModLessonOfflineProvider } from './lesson-offline'; import { AddonModLessonPrefetchHandler } from './prefetch-handler'; @@ -59,25 +58,31 @@ export class AddonModLessonSyncProvider extends CoreSyncBaseProvider { // Variables for database. static RETAKES_FINISHED_TABLE = 'addon_mod_lesson_retakes_finished_sync'; - protected tablesSchema: SQLiteDBTableSchema = { - name: AddonModLessonSyncProvider.RETAKES_FINISHED_TABLE, - columns: [ + protected siteSchema: CoreSiteSchema = { + name: 'AddonModLessonSyncProvider', + version: 1, + tables: [ { - name: 'lessonid', - type: 'INTEGER', - primaryKey: true - }, - { - name: 'retake', - type: 'INTEGER' - }, - { - name: 'pageid', - type: 'INTEGER' - }, - { - name: 'timefinished', - type: 'INTEGER' + name: AddonModLessonSyncProvider.RETAKES_FINISHED_TABLE, + columns: [ + { + name: 'lessonid', + type: 'INTEGER', + primaryKey: true + }, + { + name: 'retake', + type: 'INTEGER' + }, + { + name: 'pageid', + type: 'INTEGER' + }, + { + name: 'timefinished', + type: 'INTEGER' + } + ] } ] }; @@ -94,7 +99,7 @@ export class AddonModLessonSyncProvider extends CoreSyncBaseProvider { this.componentTranslate = courseProvider.translateModuleName('lesson'); - this.sitesProvider.createTableFromSchema(this.tablesSchema); + this.sitesProvider.registerSiteSchema(this.siteSchema); } /** diff --git a/src/addon/mod/lesson/providers/lesson.ts b/src/addon/mod/lesson/providers/lesson.ts index e2343fbcb..3204147b5 100644 --- a/src/addon/mod/lesson/providers/lesson.ts +++ b/src/addon/mod/lesson/providers/lesson.ts @@ -15,13 +15,12 @@ import { Injectable } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; import { CoreLoggerProvider } from '@providers/logger'; -import { CoreSitesProvider } from '@providers/sites'; +import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; import { CoreTextUtilsProvider } from '@providers/utils/text'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreGradesProvider } from '@core/grades/providers/grades'; import { CoreSiteWSPreSets } from '@classes/site'; -import { SQLiteDBTableSchema } from '@classes/sqlitedb'; import { AddonModLessonOfflineProvider } from './lesson-offline'; /** @@ -156,21 +155,27 @@ export class AddonModLessonProvider { // Variables for database. static PASSWORD_TABLE = 'addon_mod_lesson_password'; - protected tablesSchema: SQLiteDBTableSchema = { - name: AddonModLessonProvider.PASSWORD_TABLE, - columns: [ + protected siteSchema: CoreSiteSchema = { + name: 'AddonModLessonProvider', + version: 1, + tables: [ { - name: 'lessonid', - type: 'INTEGER', - primaryKey: true - }, - { - name: 'password', - type: 'TEXT' - }, - { - name: 'timemodified', - type: 'INTEGER' + name: AddonModLessonProvider.PASSWORD_TABLE, + columns: [ + { + name: 'lessonid', + type: 'INTEGER', + primaryKey: true + }, + { + name: 'password', + type: 'TEXT' + }, + { + name: 'timemodified', + type: 'INTEGER' + } + ] } ] }; @@ -183,7 +188,7 @@ export class AddonModLessonProvider { private lessonOfflineProvider: AddonModLessonOfflineProvider) { this.logger = logger.getInstance('AddonModLessonProvider'); - this.sitesProvider.createTableFromSchema(this.tablesSchema); + this.sitesProvider.registerSiteSchema(this.siteSchema); } /** diff --git a/src/addon/mod/quiz/accessrules/password/providers/handler.ts b/src/addon/mod/quiz/accessrules/password/providers/handler.ts index 52b482eea..be42e7591 100644 --- a/src/addon/mod/quiz/accessrules/password/providers/handler.ts +++ b/src/addon/mod/quiz/accessrules/password/providers/handler.ts @@ -14,10 +14,9 @@ // limitations under the License. import { Injectable, Injector } from '@angular/core'; -import { CoreSitesProvider } from '@providers/sites'; +import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; import { AddonModQuizAccessRuleHandler } from '../../../providers/access-rules-delegate'; import { AddonModQuizAccessPasswordComponent } from '../component/password'; -import { SQLiteDBTableSchema } from '@classes/sqlitedb'; /** * Handler to support password access rule. @@ -26,21 +25,27 @@ import { SQLiteDBTableSchema } from '@classes/sqlitedb'; export class AddonModQuizAccessPasswordHandler implements AddonModQuizAccessRuleHandler { // Variables for database. static PASSWORD_TABLE = 'addon_mod_quiz_access_password'; - protected tableSchema: SQLiteDBTableSchema = { - name: AddonModQuizAccessPasswordHandler.PASSWORD_TABLE, - columns: [ + protected siteSchema: CoreSiteSchema = { + name: 'AddonModQuizAccessPasswordHandler', + version: 1, + tables: [ { - name: 'id', - type: 'INTEGER', - primaryKey: true - }, - { - name: 'password', - type: 'TEXT' - }, - { - name: 'timemodified', - type: 'INTEGER' + name: AddonModQuizAccessPasswordHandler.PASSWORD_TABLE, + columns: [ + { + name: 'id', + type: 'INTEGER', + primaryKey: true + }, + { + name: 'password', + type: 'TEXT' + }, + { + name: 'timemodified', + type: 'INTEGER' + } + ] } ] }; @@ -49,7 +54,7 @@ export class AddonModQuizAccessPasswordHandler implements AddonModQuizAccessRule ruleName = 'quizaccess_password'; constructor(private sitesProvider: CoreSitesProvider) { - this.sitesProvider.createTableFromSchema(this.tableSchema); + this.sitesProvider.registerSiteSchema(this.siteSchema); } /** diff --git a/src/addon/mod/quiz/providers/quiz-offline.ts b/src/addon/mod/quiz/providers/quiz-offline.ts index 5d21446d1..b7fe048d2 100644 --- a/src/addon/mod/quiz/providers/quiz-offline.ts +++ b/src/addon/mod/quiz/providers/quiz-offline.ts @@ -15,13 +15,13 @@ import { Injectable } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; import { CoreLoggerProvider } from '@providers/logger'; -import { CoreSitesProvider } from '@providers/sites'; +import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; import { CoreTimeUtilsProvider } from '@providers/utils/time'; import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreQuestionProvider } from '@core/question/providers/question'; import { CoreQuestionBehaviourDelegate } from '@core/question/providers/behaviour-delegate'; import { AddonModQuizProvider } from './quiz'; -import { SQLiteDB, SQLiteDBTableSchema } from '@classes/sqlitedb'; +import { SQLiteDB } from '@classes/sqlitedb'; /** * Service to handle offline quiz. @@ -33,57 +33,61 @@ export class AddonModQuizOfflineProvider { // Variables for database. static ATTEMPTS_TABLE = 'addon_mod_quiz_attempts'; - protected tablesSchema: SQLiteDBTableSchema[] = [ - { - name: AddonModQuizOfflineProvider.ATTEMPTS_TABLE, - columns: [ - { - name: 'id', // Attempt ID. - type: 'INTEGER', - primaryKey: true - }, - { - name: 'attempt', // Attempt number. - type: 'INTEGER' - }, - { - name: 'courseid', - type: 'INTEGER' - }, - { - name: 'userid', - type: 'INTEGER' - }, - { - name: 'quizid', - type: 'INTEGER' - }, - { - name: 'currentpage', - type: 'INTEGER' - }, - { - name: 'timecreated', - type: 'INTEGER' - }, - { - name: 'timemodified', - type: 'INTEGER' - }, - { - name: 'finished', - type: 'INTEGER' - } - ] - } - ]; + protected siteSchema: CoreSiteSchema = { + name: 'AddonModQuizOfflineProvider', + version: 1, + tables: [ + { + name: AddonModQuizOfflineProvider.ATTEMPTS_TABLE, + columns: [ + { + name: 'id', // Attempt ID. + type: 'INTEGER', + primaryKey: true + }, + { + name: 'attempt', // Attempt number. + type: 'INTEGER' + }, + { + name: 'courseid', + type: 'INTEGER' + }, + { + name: 'userid', + type: 'INTEGER' + }, + { + name: 'quizid', + type: 'INTEGER' + }, + { + name: 'currentpage', + type: 'INTEGER' + }, + { + name: 'timecreated', + type: 'INTEGER' + }, + { + name: 'timemodified', + type: 'INTEGER' + }, + { + name: 'finished', + type: 'INTEGER' + } + ] + } + ] + }; constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private timeUtils: CoreTimeUtilsProvider, private questionProvider: CoreQuestionProvider, private translate: TranslateService, private utils: CoreUtilsProvider, private behaviourDelegate: CoreQuestionBehaviourDelegate) { this.logger = logger.getInstance('AddonModQuizOfflineProvider'); - this.sitesProvider.createTablesFromSchema(this.tablesSchema); + this.sitesProvider.registerSiteSchema(this.siteSchema); } /** diff --git a/src/addon/mod/scorm/providers/scorm-offline.ts b/src/addon/mod/scorm/providers/scorm-offline.ts index 9bfdd2c79..74af07260 100644 --- a/src/addon/mod/scorm/providers/scorm-offline.ts +++ b/src/addon/mod/scorm/providers/scorm-offline.ts @@ -14,14 +14,14 @@ import { Injectable } from '@angular/core'; import { CoreLoggerProvider } from '@providers/logger'; -import { CoreSitesProvider } from '@providers/sites'; +import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; import { CoreSyncProvider } from '@providers/sync'; import { CoreTextUtilsProvider } from '@providers/utils/text'; import { CoreTimeUtilsProvider } from '@providers/utils/time'; import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreUserProvider } from '@core/user/providers/user'; import { AddonModScormProvider } from './scorm'; -import { SQLiteDB, SQLiteDBTableSchema } from '@classes/sqlitedb'; +import { SQLiteDB } from '@classes/sqlitedb'; /** * Service to handle offline SCORM. @@ -34,95 +34,99 @@ export class AddonModScormOfflineProvider { // Variables for database. static ATTEMPTS_TABLE = 'addon_mod_scorm_offline_attempts'; static TRACKS_TABLE = 'addon_mod_scorm_offline_scos_tracks'; - protected tablesSchema: SQLiteDBTableSchema[] = [ - { - name: AddonModScormOfflineProvider.ATTEMPTS_TABLE, - columns: [ - { - name: 'scormid', - type: 'INTEGER', - notNull: true - }, - { - name: 'attempt', // Attempt number. - type: 'INTEGER', - notNull: true - }, - { - name: 'userid', - type: 'INTEGER', - notNull: true - }, - { - name: 'courseid', - type: 'INTEGER' - }, - { - name: 'timecreated', - type: 'INTEGER' - }, - { - name: 'timemodified', - type: 'INTEGER' - }, - { - name: 'snapshot', - type: 'TEXT' - }, - ], - primaryKeys: ['scormid', 'userid', 'attempt'] - }, - { - name: AddonModScormOfflineProvider.TRACKS_TABLE, - columns: [ - { - name: 'scormid', - type: 'INTEGER', - notNull: true - }, - { - name: 'attempt', // Attempt number. - type: 'INTEGER', - notNull: true - }, - { - name: 'userid', - type: 'INTEGER', - notNull: true - }, - { - name: 'scoid', - type: 'INTEGER', - notNull: true - }, - { - name: 'element', - type: 'TEXT', - notNull: true - }, - { - name: 'value', - type: 'TEXT' - }, - { - name: 'timemodified', - type: 'INTEGER' - }, - { - name: 'synced', - type: 'INTEGER' - }, - ], - primaryKeys: ['scormid', 'userid', 'attempt', 'scoid', 'element'] - } - ]; + protected siteSchema: CoreSiteSchema = { + name: 'AddonModScormOfflineProvider', + version: 1, + tables: [ + { + name: AddonModScormOfflineProvider.ATTEMPTS_TABLE, + columns: [ + { + name: 'scormid', + type: 'INTEGER', + notNull: true + }, + { + name: 'attempt', // Attempt number. + type: 'INTEGER', + notNull: true + }, + { + name: 'userid', + type: 'INTEGER', + notNull: true + }, + { + name: 'courseid', + type: 'INTEGER' + }, + { + name: 'timecreated', + type: 'INTEGER' + }, + { + name: 'timemodified', + type: 'INTEGER' + }, + { + name: 'snapshot', + type: 'TEXT' + }, + ], + primaryKeys: ['scormid', 'userid', 'attempt'] + }, + { + name: AddonModScormOfflineProvider.TRACKS_TABLE, + columns: [ + { + name: 'scormid', + type: 'INTEGER', + notNull: true + }, + { + name: 'attempt', // Attempt number. + type: 'INTEGER', + notNull: true + }, + { + name: 'userid', + type: 'INTEGER', + notNull: true + }, + { + name: 'scoid', + type: 'INTEGER', + notNull: true + }, + { + name: 'element', + type: 'TEXT', + notNull: true + }, + { + name: 'value', + type: 'TEXT' + }, + { + name: 'timemodified', + type: 'INTEGER' + }, + { + name: 'synced', + type: 'INTEGER' + }, + ], + primaryKeys: ['scormid', 'userid', 'attempt', 'scoid', 'element'] + } + ] + }; constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private timeUtils: CoreTimeUtilsProvider, private syncProvider: CoreSyncProvider, private utils: CoreUtilsProvider, private textUtils: CoreTextUtilsProvider, private userProvider: CoreUserProvider) { this.logger = logger.getInstance('AddonModScormOfflineProvider'); - this.sitesProvider.createTablesFromSchema(this.tablesSchema); + this.sitesProvider.registerSiteSchema(this.siteSchema); } /** diff --git a/src/addon/mod/survey/providers/offline.ts b/src/addon/mod/survey/providers/offline.ts index 61d04a315..5e3185315 100644 --- a/src/addon/mod/survey/providers/offline.ts +++ b/src/addon/mod/survey/providers/offline.ts @@ -14,9 +14,8 @@ import { Injectable } from '@angular/core'; import { CoreLoggerProvider } from '@providers/logger'; -import { CoreSitesProvider } from '@providers/sites'; +import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; import { CoreTextUtilsProvider } from '@providers/utils/text'; -import { SQLiteDBTableSchema } from '@classes/sqlitedb'; /** * Service to handle Offline survey. @@ -28,42 +27,46 @@ export class AddonModSurveyOfflineProvider { // Variables for database. static SURVEY_TABLE = 'addon_mod_survey_answers'; - protected tablesSchema: SQLiteDBTableSchema[] = [ - { - name: AddonModSurveyOfflineProvider.SURVEY_TABLE, - columns: [ - { - name: 'surveyid', - type: 'INTEGER' - }, - { - name: 'name', - type: 'TEXT' - }, - { - name: 'courseid', - type: 'INTEGER' - }, - { - name: 'userid', - type: 'INTEGER' - }, - { - name: 'answers', - type: 'TEXT' - }, - { - name: 'timecreated', - type: 'INTEGER' - } - ], - primaryKeys: ['surveyid', 'userid'] - } - ]; + protected siteSchema: CoreSiteSchema = { + name: 'AddonModSurveyOfflineProvider', + version: 1, + tables: [ + { + name: AddonModSurveyOfflineProvider.SURVEY_TABLE, + columns: [ + { + name: 'surveyid', + type: 'INTEGER' + }, + { + name: 'name', + type: 'TEXT' + }, + { + name: 'courseid', + type: 'INTEGER' + }, + { + name: 'userid', + type: 'INTEGER' + }, + { + name: 'answers', + type: 'TEXT' + }, + { + name: 'timecreated', + type: 'INTEGER' + } + ], + primaryKeys: ['surveyid', 'userid'] + } + ] + }; constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private textUtils: CoreTextUtilsProvider) { this.logger = logger.getInstance('AddonModSurveyOfflineProvider'); - this.sitesProvider.createTablesFromSchema(this.tablesSchema); + this.sitesProvider.registerSiteSchema(this.siteSchema); } /** diff --git a/src/addon/mod/wiki/providers/wiki-offline.ts b/src/addon/mod/wiki/providers/wiki-offline.ts index d9407e2dc..003fa3b7a 100644 --- a/src/addon/mod/wiki/providers/wiki-offline.ts +++ b/src/addon/mod/wiki/providers/wiki-offline.ts @@ -14,8 +14,7 @@ import { Injectable } from '@angular/core'; import { CoreLoggerProvider } from '@providers/logger'; -import { CoreSitesProvider } from '@providers/sites'; -import { SQLiteDBTableSchema } from '@classes/sqlitedb'; +import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; /** * Service to handle offline wiki. @@ -27,62 +26,66 @@ export class AddonModWikiOfflineProvider { // Variables for database. static NEW_PAGES_TABLE = 'addon_mod_wiki_new_pages_store'; - protected tablesSchema: SQLiteDBTableSchema[] = [ - { - name: AddonModWikiOfflineProvider.NEW_PAGES_TABLE, - columns: [ + protected siteSchema: CoreSiteSchema = { + name: 'AddonModWikiOfflineProvider', + version: 1, + tables: [ { - name: 'wikiid', - type: 'INTEGER' - }, - { - name: 'subwikiid', - type: 'INTEGER' - }, - { - name: 'userid', - type: 'INTEGER' - }, - { - name: 'groupid', - type: 'INTEGER' - }, - { - name: 'title', - type: 'TEXT' - }, - { - name: 'cachedcontent', - type: 'TEXT' - }, - { - name: 'contentformat', - type: 'TEXT' - }, - { - name: 'courseid', - type: 'INTEGER' - }, - { - name: 'timecreated', - type: 'INTEGER' - }, - { - name: 'timemodified', - type: 'INTEGER' - }, - { - name: 'caneditpage', - type: 'INTEGER' - } - ], - primaryKeys: ['wikiid', 'subwikiid', 'userid', 'groupid', 'title'] - } - ]; + name: AddonModWikiOfflineProvider.NEW_PAGES_TABLE, + columns: [ + { + name: 'wikiid', + type: 'INTEGER' + }, + { + name: 'subwikiid', + type: 'INTEGER' + }, + { + name: 'userid', + type: 'INTEGER' + }, + { + name: 'groupid', + type: 'INTEGER' + }, + { + name: 'title', + type: 'TEXT' + }, + { + name: 'cachedcontent', + type: 'TEXT' + }, + { + name: 'contentformat', + type: 'TEXT' + }, + { + name: 'courseid', + type: 'INTEGER' + }, + { + name: 'timecreated', + type: 'INTEGER' + }, + { + name: 'timemodified', + type: 'INTEGER' + }, + { + name: 'caneditpage', + type: 'INTEGER' + } + ], + primaryKeys: ['wikiid', 'subwikiid', 'userid', 'groupid', 'title'] + } + ] + }; constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider) { this.logger = logger.getInstance('AddonModWikiOfflineProvider'); - this.sitesProvider.createTablesFromSchema(this.tablesSchema); + this.sitesProvider.registerSiteSchema(this.siteSchema); } /** diff --git a/src/addon/mod/workshop/providers/offline.ts b/src/addon/mod/workshop/providers/offline.ts index c5c8c78d8..dcd7f1adc 100644 --- a/src/addon/mod/workshop/providers/offline.ts +++ b/src/addon/mod/workshop/providers/offline.ts @@ -14,10 +14,9 @@ import { Injectable } from '@angular/core'; import { CoreFileProvider } from '@providers/file'; -import { CoreSitesProvider } from '@providers/sites'; +import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; import { CoreTextUtilsProvider } from '@providers/utils/text'; import { CoreTimeUtilsProvider } from '@providers/utils/time'; -import { SQLiteDBTableSchema } from '@classes/sqlitedb'; /** * Service to handle offline workshop. @@ -31,146 +30,150 @@ export class AddonModWorkshopOfflineProvider { static EVALUATE_SUBMISSIONS_TABLE = 'addon_mod_workshop_evaluate_submissions'; static EVALUATE_ASSESSMENTS_TABLE = 'addon_mod_workshop_evaluate_assessments'; - protected tablesSchema: SQLiteDBTableSchema[] = [ - { - name: AddonModWorkshopOfflineProvider.SUBMISSIONS_TABLE, - columns: [ - { - name: 'workshopid', - type: 'INTEGER', - }, - { - name: 'submissionid', - type: 'INTEGER', - }, - { - name: 'action', - type: 'TEXT', - }, - { - name: 'courseid', - type: 'INTEGER', - }, - { - name: 'title', - type: 'TEXT', - }, - { - name: 'content', - type: 'TEXT', - }, - { - name: 'attachmentsid', - type: 'TEXT', - }, - { - name: 'timemodified', - type: 'INTEGER', - } - ], - primaryKeys: ['workshopid', 'submissionid', 'action'] - }, - { - name: AddonModWorkshopOfflineProvider.ASSESSMENTS_TABLE, - columns: [ - { - name: 'workshopid', - type: 'INTEGER', - }, - { - name: 'assessmentid', - type: 'INTEGER', - }, - { - name: 'courseid', - type: 'INTEGER', - }, - { - name: 'inputdata', - type: 'TEXT', - }, - { - name: 'timemodified', - type: 'INTEGER', - }, - ], - primaryKeys: ['workshopid', 'assessmentid'] - }, - { - name: AddonModWorkshopOfflineProvider.EVALUATE_SUBMISSIONS_TABLE, - columns: [ - { - name: 'workshopid', - type: 'INTEGER', - }, - { - name: 'submissionid', - type: 'INTEGER', - }, - { - name: 'courseid', - type: 'INTEGER', - }, - { - name: 'timemodified', - type: 'INTEGER', - }, - { - name: 'feedbacktext', - type: 'TEXT', - }, - { - name: 'published', - type: 'INTEGER', - }, - { - name: 'gradeover', - type: 'TEXT', - }, - ], - primaryKeys: ['workshopid', 'submissionid'] - }, - { - name: AddonModWorkshopOfflineProvider.EVALUATE_ASSESSMENTS_TABLE, - columns: [ - { - name: 'workshopid', - type: 'INTEGER', - }, - { - name: 'assessmentid', - type: 'INTEGER', - }, - { - name: 'courseid', - type: 'INTEGER', - }, - { - name: 'timemodified', - type: 'INTEGER', - }, - { - name: 'feedbacktext', - type: 'TEXT', - }, - { - name: 'weight', - type: 'INTEGER', - }, - { - name: 'gradinggradeover', - type: 'TEXT', - }, - ], - primaryKeys: ['workshopid', 'assessmentid'] - } - ]; + protected siteSchema: CoreSiteSchema = { + name: 'AddonModWorkshopOfflineProvider', + version: 1, + tables: [ + { + name: AddonModWorkshopOfflineProvider.SUBMISSIONS_TABLE, + columns: [ + { + name: 'workshopid', + type: 'INTEGER', + }, + { + name: 'submissionid', + type: 'INTEGER', + }, + { + name: 'action', + type: 'TEXT', + }, + { + name: 'courseid', + type: 'INTEGER', + }, + { + name: 'title', + type: 'TEXT', + }, + { + name: 'content', + type: 'TEXT', + }, + { + name: 'attachmentsid', + type: 'TEXT', + }, + { + name: 'timemodified', + type: 'INTEGER', + } + ], + primaryKeys: ['workshopid', 'submissionid', 'action'] + }, + { + name: AddonModWorkshopOfflineProvider.ASSESSMENTS_TABLE, + columns: [ + { + name: 'workshopid', + type: 'INTEGER', + }, + { + name: 'assessmentid', + type: 'INTEGER', + }, + { + name: 'courseid', + type: 'INTEGER', + }, + { + name: 'inputdata', + type: 'TEXT', + }, + { + name: 'timemodified', + type: 'INTEGER', + }, + ], + primaryKeys: ['workshopid', 'assessmentid'] + }, + { + name: AddonModWorkshopOfflineProvider.EVALUATE_SUBMISSIONS_TABLE, + columns: [ + { + name: 'workshopid', + type: 'INTEGER', + }, + { + name: 'submissionid', + type: 'INTEGER', + }, + { + name: 'courseid', + type: 'INTEGER', + }, + { + name: 'timemodified', + type: 'INTEGER', + }, + { + name: 'feedbacktext', + type: 'TEXT', + }, + { + name: 'published', + type: 'INTEGER', + }, + { + name: 'gradeover', + type: 'TEXT', + }, + ], + primaryKeys: ['workshopid', 'submissionid'] + }, + { + name: AddonModWorkshopOfflineProvider.EVALUATE_ASSESSMENTS_TABLE, + columns: [ + { + name: 'workshopid', + type: 'INTEGER', + }, + { + name: 'assessmentid', + type: 'INTEGER', + }, + { + name: 'courseid', + type: 'INTEGER', + }, + { + name: 'timemodified', + type: 'INTEGER', + }, + { + name: 'feedbacktext', + type: 'TEXT', + }, + { + name: 'weight', + type: 'INTEGER', + }, + { + name: 'gradinggradeover', + type: 'TEXT', + }, + ], + primaryKeys: ['workshopid', 'assessmentid'] + } + ] + }; constructor(private fileProvider: CoreFileProvider, private sitesProvider: CoreSitesProvider, private textUtils: CoreTextUtilsProvider, private timeUtils: CoreTimeUtilsProvider) { - this.sitesProvider.createTablesFromSchema(this.tablesSchema); + this.sitesProvider.registerSiteSchema(this.siteSchema); } /** diff --git a/src/addon/notes/providers/notes-offline.ts b/src/addon/notes/providers/notes-offline.ts index 1572c6559..486fa0111 100644 --- a/src/addon/notes/providers/notes-offline.ts +++ b/src/addon/notes/providers/notes-offline.ts @@ -14,9 +14,8 @@ import { Injectable } from '@angular/core'; import { CoreLoggerProvider } from '@providers/logger'; -import { CoreSitesProvider } from '@providers/sites'; +import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; import { CoreTimeUtilsProvider } from '@providers/utils/time'; -import { SQLiteDBTableSchema } from '@classes/sqlitedb'; /** * Service to handle offline notes. @@ -27,46 +26,50 @@ export class AddonNotesOfflineProvider { // Variables for database. static NOTES_TABLE = 'addon_notes_offline_notes'; - protected tablesSchema: SQLiteDBTableSchema[] = [ - { - name: AddonNotesOfflineProvider.NOTES_TABLE, - columns: [ - { - name: 'userid', - type: 'INTEGER' - }, - { - name: 'courseid', - type: 'INTEGER' - }, - { - name: 'publishstate', - type: 'TEXT', - }, - { - name: 'content', - type: 'TEXT' - }, - { - name: 'format', - type: 'INTEGER' - }, - { - name: 'created', - type: 'INTEGER' - }, - { - name: 'lastmodified', - type: 'INTEGER' - } - ], - primaryKeys: ['userid', 'content', 'created'] - } - ]; + protected siteSchema: CoreSiteSchema = { + name: 'AddonNotesOfflineProvider', + version: 1, + tables: [ + { + name: AddonNotesOfflineProvider.NOTES_TABLE, + columns: [ + { + name: 'userid', + type: 'INTEGER' + }, + { + name: 'courseid', + type: 'INTEGER' + }, + { + name: 'publishstate', + type: 'TEXT', + }, + { + name: 'content', + type: 'TEXT' + }, + { + name: 'format', + type: 'INTEGER' + }, + { + name: 'created', + type: 'INTEGER' + }, + { + name: 'lastmodified', + type: 'INTEGER' + } + ], + primaryKeys: ['userid', 'content', 'created'] + } + ] + }; constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private timeUtils: CoreTimeUtilsProvider) { this.logger = logger.getInstance('AddonNotesOfflineProvider'); - this.sitesProvider.createTablesFromSchema(this.tablesSchema); + this.sitesProvider.registerSiteSchema(this.siteSchema); } /** diff --git a/src/classes/site.ts b/src/classes/site.ts index 3c84bcd8a..36fd3d598 100644 --- a/src/classes/site.ts +++ b/src/classes/site.ts @@ -15,7 +15,7 @@ import { Injector } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; import { HttpClient } from '@angular/common/http'; -import { SQLiteDB, SQLiteDBTableSchema } from './sqlitedb'; +import { SQLiteDB } from './sqlitedb'; import { CoreAppProvider } from '@providers/app'; import { CoreDbProvider } from '@providers/db'; import { CoreEventsProvider } from '@providers/events'; @@ -166,47 +166,8 @@ export class CoreSite { protected wsProvider: CoreWSProvider; // Variables for the database. - protected WS_CACHE_TABLE = 'wscache'; - protected CONFIG_TABLE = 'core_site_config'; - protected tableSchemas: SQLiteDBTableSchema[] = [ - { - name: this.WS_CACHE_TABLE, - columns: [ - { - name: 'id', - type: 'TEXT', - primaryKey: true - }, - { - name: 'data', - type: 'TEXT' - }, - { - name: 'key', - type: 'TEXT' - }, - { - name: 'expirationTime', - type: 'INTEGER' - } - ] - }, - { - name: this.CONFIG_TABLE, - columns: [ - { - name: 'name', - type: 'TEXT', - unique: true, - notNull: true - }, - { - name: 'value' - } - ] - } - - ]; + static WS_CACHE_TABLE = 'wscache'; + static CONFIG_TABLE = 'core_site_config'; // Versions of Moodle releases. protected MOODLE_RELEASES = { @@ -267,7 +228,6 @@ export class CoreSite { */ initDB(): void { this.db = this.dbProvider.getDB('Site-' + this.id); - this.db.createTablesFromSchema(this.tableSchemas); } /** @@ -784,10 +744,10 @@ export class CoreSite { let promise; if (preSets.getCacheUsingCacheKey || (emergency && preSets.getEmergencyCacheUsingCacheKey)) { - promise = this.db.getRecords(this.WS_CACHE_TABLE, { key: preSets.cacheKey }).then((entries) => { + promise = this.db.getRecords(CoreSite.WS_CACHE_TABLE, { key: preSets.cacheKey }).then((entries) => { if (!entries.length) { // Cache key not found, get by params sent. - return this.db.getRecord(this.WS_CACHE_TABLE, { id: id }); + return this.db.getRecord(CoreSite.WS_CACHE_TABLE, { id: id }); } else if (entries.length > 1) { // More than one entry found. Search the one with same ID as this call. for (let i = 0, len = entries.length; i < len; i++) { @@ -801,13 +761,13 @@ export class CoreSite { return entries[0]; }); } else { - promise = this.db.getRecord(this.WS_CACHE_TABLE, { id: id }).catch(() => { + promise = this.db.getRecord(CoreSite.WS_CACHE_TABLE, { id: id }).catch(() => { // Entry not found, try to get it using the old ID. const oldId = this.getCacheOldId(method, originalData || {}); - return this.db.getRecord(this.WS_CACHE_TABLE, { id: oldId }).then((entry) => { + return this.db.getRecord(CoreSite.WS_CACHE_TABLE, { id: oldId }).then((entry) => { // Update the entry ID to use the new one. - this.db.updateRecords(this.WS_CACHE_TABLE, {id: id}, {id: oldId}); + this.db.updateRecords(CoreSite.WS_CACHE_TABLE, {id: id}, {id: oldId}); return entry; }); @@ -877,7 +837,7 @@ export class CoreSite { entry.key = preSets.cacheKey; } - return this.db.insertRecord(this.WS_CACHE_TABLE, entry); + return this.db.insertRecord(CoreSite.WS_CACHE_TABLE, entry); }); } @@ -898,10 +858,10 @@ export class CoreSite { const id = this.getCacheId(method, data); if (allCacheKey) { - return this.db.deleteRecords(this.WS_CACHE_TABLE, { key: preSets.cacheKey }); + return this.db.deleteRecords(CoreSite.WS_CACHE_TABLE, { key: preSets.cacheKey }); } - return this.db.deleteRecords(this.WS_CACHE_TABLE, { id: id }); + return this.db.deleteRecords(CoreSite.WS_CACHE_TABLE, { id: id }); } /* @@ -935,7 +895,7 @@ export class CoreSite { this.logger.debug('Invalidate all the cache for site: ' + this.id); - return this.db.updateRecords(this.WS_CACHE_TABLE, { expirationTime: 0 }); + return this.db.updateRecords(CoreSite.WS_CACHE_TABLE, { expirationTime: 0 }); } /** @@ -954,7 +914,7 @@ export class CoreSite { this.logger.debug('Invalidate cache for key: ' + key); - return this.db.updateRecords(this.WS_CACHE_TABLE, { expirationTime: 0 }, { key: key }); + return this.db.updateRecords(CoreSite.WS_CACHE_TABLE, { expirationTime: 0 }, { key: key }); } /** @@ -997,7 +957,7 @@ export class CoreSite { this.logger.debug('Invalidate cache for key starting with: ' + key); - const sql = 'UPDATE ' + this.WS_CACHE_TABLE + ' SET expirationTime=0 WHERE key LIKE ?'; + const sql = 'UPDATE ' + CoreSite.WS_CACHE_TABLE + ' SET expirationTime=0 WHERE key LIKE ?'; return this.db.execute(sql, [key + '%']); } @@ -1590,7 +1550,7 @@ export class CoreSite { * @return {Promise} Promise resolved when done. */ deleteSiteConfig(name: string): Promise { - return this.db.deleteRecords(this.CONFIG_TABLE, { name: name }); + return this.db.deleteRecords(CoreSite.CONFIG_TABLE, { name: name }); } /** @@ -1601,7 +1561,7 @@ export class CoreSite { * @return {Promise} Resolves upon success along with the config data. Reject on failure. */ getLocalSiteConfig(name: string, defaultValue?: any): Promise { - return this.db.getRecord(this.CONFIG_TABLE, { name: name }).then((entry) => { + return this.db.getRecord(CoreSite.CONFIG_TABLE, { name: name }).then((entry) => { return entry.value; }).catch((error) => { if (typeof defaultValue != 'undefined') { @@ -1620,6 +1580,6 @@ export class CoreSite { * @return {Promise} Promise resolved when done. */ setLocalSiteConfig(name: string, value: number | string): Promise { - return this.db.insertRecord(this.CONFIG_TABLE, { name: name, value: value }); + return this.db.insertRecord(CoreSite.CONFIG_TABLE, { name: name, value: value }); } } diff --git a/src/core/course/providers/course-offline.ts b/src/core/course/providers/course-offline.ts index af28b5cbf..4de3ac671 100644 --- a/src/core/course/providers/course-offline.ts +++ b/src/core/course/providers/course-offline.ts @@ -13,8 +13,7 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { CoreSitesProvider } from '@providers/sites'; -import { SQLiteDBTableSchema } from '@classes/sqlitedb'; +import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; /** * Service to handle offline data for courses. @@ -24,37 +23,41 @@ export class CoreCourseOfflineProvider { // Variables for database. static MANUAL_COMPLETION_TABLE = 'course_manual_completion'; - protected tablesSchema: SQLiteDBTableSchema[] = [ - { - name: CoreCourseOfflineProvider.MANUAL_COMPLETION_TABLE, - columns: [ - { - name: 'cmid', - type: 'INTEGER', - primaryKey: true - }, - { - name: 'completed', - type: 'INTEGER' - }, - { - name: 'courseid', - type: 'INTEGER' - }, - { - name: 'coursename', - type: 'TEXT' - }, - { - name: 'timecompleted', - type: 'INTEGER' - } - ] - } - ]; + protected siteSchema: CoreSiteSchema = { + name: 'CoreCourseOfflineProvider', + version: 1, + tables: [ + { + name: CoreCourseOfflineProvider.MANUAL_COMPLETION_TABLE, + columns: [ + { + name: 'cmid', + type: 'INTEGER', + primaryKey: true + }, + { + name: 'completed', + type: 'INTEGER' + }, + { + name: 'courseid', + type: 'INTEGER' + }, + { + name: 'coursename', + type: 'TEXT' + }, + { + name: 'timecompleted', + type: 'INTEGER' + } + ] + } + ] + }; constructor(private sitesProvider: CoreSitesProvider) { - this.sitesProvider.createTablesFromSchema(this.tablesSchema); + this.sitesProvider.registerSiteSchema(this.siteSchema); } /** diff --git a/src/core/course/providers/course.ts b/src/core/course/providers/course.ts index 59b7dfe15..f35b76067 100644 --- a/src/core/course/providers/course.ts +++ b/src/core/course/providers/course.ts @@ -17,13 +17,12 @@ import { TranslateService } from '@ngx-translate/core'; import { CoreAppProvider } from '@providers/app'; import { CoreEventsProvider } from '@providers/events'; import { CoreLoggerProvider } from '@providers/logger'; -import { CoreSitesProvider } from '@providers/sites'; +import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; import { CoreTimeUtilsProvider } from '@providers/utils/time'; import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreSiteWSPreSets, CoreSite } from '@classes/site'; import { CoreConstants } from '../../constants'; import { CoreCourseOfflineProvider } from './course-offline'; -import { SQLiteDBTableSchema } from '@classes/sqlitedb'; /** * Service that provides some features regarding a course. @@ -48,34 +47,40 @@ export class CoreCourseProvider { // Variables for database. protected COURSE_STATUS_TABLE = 'course_status'; - protected courseStatusTableSchema: SQLiteDBTableSchema = { - name: this.COURSE_STATUS_TABLE, - columns: [ + protected siteSchema: CoreSiteSchema = { + name: 'CoreCourseProvider', + version: 1, + tables: [ { - name: 'id', - type: 'INTEGER', - primaryKey: true - }, - { - name: 'status', - type: 'TEXT', - notNull: true - }, - { - name: 'previous', - type: 'TEXT' - }, - { - name: 'updated', - type: 'INTEGER' - }, - { - name: 'downloadTime', - type: 'INTEGER' - }, - { - name: 'previousDownloadTime', - type: 'INTEGER' + name: this.COURSE_STATUS_TABLE, + columns: [ + { + name: 'id', + type: 'INTEGER', + primaryKey: true + }, + { + name: 'status', + type: 'TEXT', + notNull: true + }, + { + name: 'previous', + type: 'TEXT' + }, + { + name: 'updated', + type: 'INTEGER' + }, + { + name: 'downloadTime', + type: 'INTEGER' + }, + { + name: 'previousDownloadTime', + type: 'INTEGER' + } + ] } ] }; @@ -92,7 +97,7 @@ export class CoreCourseProvider { private courseOffline: CoreCourseOfflineProvider, private appProvider: CoreAppProvider) { this.logger = logger.getInstance('CoreCourseProvider'); - this.sitesProvider.createTableFromSchema(this.courseStatusTableSchema); + this.sitesProvider.registerSiteSchema(this.siteSchema); } /** diff --git a/src/core/course/providers/module-prefetch-delegate.ts b/src/core/course/providers/module-prefetch-delegate.ts index 61e228345..c381ac64e 100644 --- a/src/core/course/providers/module-prefetch-delegate.ts +++ b/src/core/course/providers/module-prefetch-delegate.ts @@ -17,7 +17,7 @@ import { CoreEventsProvider } from '@providers/events'; import { CoreFileProvider } from '@providers/file'; import { CoreFilepoolProvider } from '@providers/filepool'; import { CoreLoggerProvider } from '@providers/logger'; -import { CoreSitesProvider } from '@providers/sites'; +import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; import { CoreTimeUtilsProvider } from '@providers/utils/time'; import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreCourseProvider } from './course'; @@ -27,7 +27,6 @@ import { CoreConstants } from '../../constants'; import { Md5 } from 'ts-md5/dist/md5'; import { Subject, BehaviorSubject, Subscription } from 'rxjs'; import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate'; -import { SQLiteDBTableSchema } from '@classes/sqlitedb'; /** * Progress of downloading a list of modules. @@ -203,18 +202,24 @@ export interface CoreCourseModulePrefetchHandler extends CoreDelegateHandler { export class CoreCourseModulePrefetchDelegate extends CoreDelegate { // Variables for database. protected CHECK_UPDATES_TIMES_TABLE = 'check_updates_times'; - protected checkUpdatesTableSchema: SQLiteDBTableSchema = { - name: this.CHECK_UPDATES_TIMES_TABLE, - columns: [ + protected siteSchema: CoreSiteSchema = { + name: 'CoreCourseModulePrefetchDelegate', + version: 1, + tables: [ { - name: 'courseId', - type: 'INTEGER', - primaryKey: true - }, - { - name: 'time', - type: 'INTEGER', - notNull: true + name: this.CHECK_UPDATES_TIMES_TABLE, + columns: [ + { + name: 'courseId', + type: 'INTEGER', + primaryKey: true + }, + { + name: 'time', + type: 'INTEGER', + notNull: true + } + ] } ] }; @@ -243,7 +248,7 @@ export class CoreCourseModulePrefetchDelegate extends CoreDelegate { protected eventsProvider: CoreEventsProvider) { super('CoreCourseModulePrefetchDelegate', loggerProvider, sitesProvider, eventsProvider); - this.sitesProvider.createTableFromSchema(this.checkUpdatesTableSchema); + this.sitesProvider.registerSiteSchema(this.siteSchema); eventsProvider.on(CoreEventsProvider.LOGOUT, this.clearStatusCache.bind(this)); eventsProvider.on(CoreEventsProvider.PACKAGE_STATUS_CHANGED, (data) => { diff --git a/src/core/emulator/providers/helper.ts b/src/core/emulator/providers/helper.ts index e3eb05776..fc10a32a2 100644 --- a/src/core/emulator/providers/helper.ts +++ b/src/core/emulator/providers/helper.ts @@ -20,13 +20,12 @@ import { LocalNotifications, ILocalNotification } from '@ionic-native/local-noti import { CoreAppProvider } from '@providers/app'; import { CoreInitDelegate, CoreInitHandler } from '@providers/init'; import { CoreLoggerProvider } from '@providers/logger'; -import { CoreSitesProvider } from '@providers/sites'; +import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; import { CoreLocalNotificationsProvider } from '@providers/local-notifications'; import { CoreTimeUtilsProvider } from '@providers/utils/time'; import { FileTransferErrorMock } from './file-transfer'; import { CoreEmulatorCaptureHelperProvider } from './capture-helper'; import { CoreConstants } from '../../constants'; -import { SQLiteDBTableSchema } from '@classes/sqlitedb'; /** * Helper service for the emulator feature. It also acts as an init handler. @@ -41,33 +40,37 @@ export class CoreEmulatorHelperProvider implements CoreInitHandler { // Variables for database. protected LAST_RECEIVED_NOTIFICATION_TABLE = 'core_emulator_last_received_notification'; - protected tablesSchema: SQLiteDBTableSchema[] = [ - { - name: this.LAST_RECEIVED_NOTIFICATION_TABLE, - columns: [ - { - name: 'component', - type: 'TEXT' - }, - { - name: 'id', - type: 'INTEGER', - }, - { - name: 'timecreated', - type: 'INTEGER', - }, - ], - primaryKeys: ['component'] - } - ]; + protected siteSchema: CoreSiteSchema = { + name: 'CoreEmulatorHelperProvider', + version: 1, + tables: [ + { + name: this.LAST_RECEIVED_NOTIFICATION_TABLE, + columns: [ + { + name: 'component', + type: 'TEXT' + }, + { + name: 'id', + type: 'INTEGER', + }, + { + name: 'timecreated', + type: 'INTEGER', + }, + ], + primaryKeys: ['component'] + } + ] + }; constructor(private file: File, private fileProvider: CoreFileProvider, private utils: CoreUtilsProvider, logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private localNotif: LocalNotifications, private captureHelper: CoreEmulatorCaptureHelperProvider, private timeUtils: CoreTimeUtilsProvider, private appProvider: CoreAppProvider, private localNotifProvider: CoreLocalNotificationsProvider) { this.logger = logger.getInstance('CoreEmulatorHelper'); - sitesProvider.createTablesFromSchema(this.tablesSchema); + sitesProvider.registerSiteSchema(this.siteSchema); } /** diff --git a/src/core/question/providers/question.ts b/src/core/question/providers/question.ts index 4c1e56e0e..92d8bc55c 100644 --- a/src/core/question/providers/question.ts +++ b/src/core/question/providers/question.ts @@ -14,10 +14,9 @@ import { Injectable } from '@angular/core'; import { CoreLoggerProvider } from '@providers/logger'; -import { CoreSitesProvider } from '@providers/sites'; +import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; import { CoreTimeUtilsProvider } from '@providers/utils/time'; import { CoreUtilsProvider } from '@providers/utils/utils'; -import { SQLiteDBTableSchema } from '@classes/sqlitedb'; /** * An object to represent a question state. @@ -64,86 +63,90 @@ export class CoreQuestionProvider { // Variables for database. protected QUESTION_TABLE = 'questions'; protected QUESTION_ANSWERS_TABLE = 'question_answers'; - protected tablesSchema: SQLiteDBTableSchema[] = [ - { - name: this.QUESTION_TABLE, - columns: [ - { - name: 'component', - type: 'TEXT', - notNull: true - }, - { - name: 'attemptid', - type: 'INTEGER', - notNull: true - }, - { - name: 'slot', - type: 'INTEGER', - notNull: true - }, - { - name: 'componentid', - type: 'INTEGER' - }, - { - name: 'userid', - type: 'INTEGER' - }, - { - name: 'number', - type: 'INTEGER' - }, - { - name: 'state', - type: 'TEXT' - } - ], - primaryKeys: ['component', 'attemptid', 'slot'] - }, - { - name: this.QUESTION_ANSWERS_TABLE, - columns: [ - { - name: 'component', - type: 'TEXT', - notNull: true - }, - { - name: 'attemptid', - type: 'INTEGER', - notNull: true - }, - { - name: 'name', - type: 'TEXT', - notNull: true - }, - { - name: 'componentid', - type: 'INTEGER' - }, - { - name: 'userid', - type: 'INTEGER' - }, - { - name: 'questionslot', - type: 'INTEGER' - }, - { - name: 'value', - type: 'TEXT' - }, - { - name: 'timemodified', - type: 'INTEGER' - } - ], - primaryKeys: ['component', 'attemptid', 'name'] - } - ]; + protected siteSchema: CoreSiteSchema = { + name: 'CoreQuestionProvider', + version: 1, + tables: [ + { + name: this.QUESTION_TABLE, + columns: [ + { + name: 'component', + type: 'TEXT', + notNull: true + }, + { + name: 'attemptid', + type: 'INTEGER', + notNull: true + }, + { + name: 'slot', + type: 'INTEGER', + notNull: true + }, + { + name: 'componentid', + type: 'INTEGER' + }, + { + name: 'userid', + type: 'INTEGER' + }, + { + name: 'number', + type: 'INTEGER' + }, + { + name: 'state', + type: 'TEXT' + } + ], + primaryKeys: ['component', 'attemptid', 'slot'] + }, + { + name: this.QUESTION_ANSWERS_TABLE, + columns: [ + { + name: 'component', + type: 'TEXT', + notNull: true + }, + { + name: 'attemptid', + type: 'INTEGER', + notNull: true + }, + { + name: 'name', + type: 'TEXT', + notNull: true + }, + { + name: 'componentid', + type: 'INTEGER' + }, + { + name: 'userid', + type: 'INTEGER' + }, + { + name: 'questionslot', + type: 'INTEGER' + }, + { + name: 'value', + type: 'TEXT' + }, + { + name: 'timemodified', + type: 'INTEGER' + } + ], + primaryKeys: ['component', 'attemptid', 'name'] + } + ] + }; protected QUESTION_PREFIX_REGEX = /q\d+:(\d+)_/; protected STATES: {[name: string]: CoreQuestionState} = { @@ -245,7 +248,7 @@ export class CoreQuestionProvider { constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private timeUtils: CoreTimeUtilsProvider, private utils: CoreUtilsProvider) { this.logger = logger.getInstance('CoreQuestionProvider'); - this.sitesProvider.createTablesFromSchema(this.tablesSchema); + this.sitesProvider.registerSiteSchema(this.siteSchema); } /** diff --git a/src/core/user/providers/user.ts b/src/core/user/providers/user.ts index 96c1fa0f5..928fb7bff 100644 --- a/src/core/user/providers/user.ts +++ b/src/core/user/providers/user.ts @@ -16,9 +16,8 @@ import { Injectable } from '@angular/core'; import { CoreFilepoolProvider } from '@providers/filepool'; import { CoreLoggerProvider } from '@providers/logger'; import { CoreSite } from '@classes/site'; -import { CoreSitesProvider } from '@providers/sites'; +import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; import { CoreUtilsProvider } from '@providers/utils/utils'; -import { SQLiteDBTableSchema } from '@classes/sqlitedb'; /** * Service to provide user functionalities. @@ -32,33 +31,37 @@ export class CoreUserProvider { // Variables for database. protected USERS_TABLE = 'users'; - protected tablesSchema: SQLiteDBTableSchema[] = [ - { - name: this.USERS_TABLE, - columns: [ - { - name: 'id', - type: 'INTEGER', - primaryKey: true - }, - { - name: 'fullname', - type: 'TEXT' - }, - { - name: 'profileimageurl', - type: 'TEXT' - } - ] - } - ]; + protected siteSchema: CoreSiteSchema = { + name: 'CoreUserProvider', + version: 1, + tables: [ + { + name: this.USERS_TABLE, + columns: [ + { + name: 'id', + type: 'INTEGER', + primaryKey: true + }, + { + name: 'fullname', + type: 'TEXT' + }, + { + name: 'profileimageurl', + type: 'TEXT' + } + ] + } + ] + }; protected logger; constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private utils: CoreUtilsProvider, private filepoolProvider: CoreFilepoolProvider) { this.logger = logger.getInstance('CoreUserProvider'); - this.sitesProvider.createTablesFromSchema(this.tablesSchema); + this.sitesProvider.registerSiteSchema(this.siteSchema); } /** diff --git a/src/providers/filepool.ts b/src/providers/filepool.ts index 08fbb85a6..d148c7f72 100644 --- a/src/providers/filepool.ts +++ b/src/providers/filepool.ts @@ -20,7 +20,7 @@ import { CoreFileProvider } from './file'; import { CoreInitDelegate } from './init'; import { CoreLoggerProvider } from './logger'; import { CorePluginFileDelegate } from './plugin-file-delegate'; -import { CoreSitesProvider } from './sites'; +import { CoreSitesProvider, CoreSiteSchema } from './sites'; import { CoreWSProvider } from './ws'; import { CoreDomUtilsProvider } from './utils/dom'; import { CoreMimetypeUtilsProvider } from './utils/mimetype'; @@ -306,115 +306,119 @@ export class CoreFilepoolProvider { primaryKeys: ['siteId', 'fileId'] } ]; - protected sitesTablesSchema: SQLiteDBTableSchema[] = [ - { - name: this.FILES_TABLE, - columns: [ - { - name: 'fileId', - type: 'TEXT', - primaryKey: true - }, - { - name: 'url', - type: 'TEXT', - notNull: true - }, - { - name: 'revision', - type: 'INTEGER' - }, - { - name: 'timemodified', - type: 'INTEGER' - }, - { - name: 'stale', - type: 'INTEGER' - }, - { - name: 'downloadTime', - type: 'INTEGER' - }, - { - name: 'isexternalfile', - type: 'INTEGER' - }, - { - name: 'repositorytype', - type: 'TEXT' - }, - { - name: 'path', - type: 'TEXT' - }, - { - name: 'extension', - type: 'TEXT' - } - ] - }, - { - name: this.LINKS_TABLE, - columns: [ - { - name: 'fileId', - type: 'TEXT' - }, - { - name: 'component', - type: 'TEXT' - }, - { - name: 'componentId', - type: 'TEXT' - } - ], - primaryKeys: ['fileId', 'component', 'componentId'] - }, - { - name: this.PACKAGES_TABLE, - columns: [ - { - name: 'id', - type: 'TEXT', - primaryKey: true - }, - { - name: 'component', - type: 'TEXT' - }, - { - name: 'componentId', - type: 'TEXT' - }, - { - name: 'status', - type: 'TEXT' - }, - { - name: 'previous', - type: 'TEXT' - }, - { - name: 'updated', - type: 'INTEGER' - }, - { - name: 'downloadTime', - type: 'INTEGER' - }, - { - name: 'previousDownloadTime', - type: 'INTEGER' - }, - { - name: 'extra', - type: 'TEXT' - } - ] - }, - ]; + protected siteSchma: CoreSiteSchema = { + name: 'CoreFilepoolProvider', + version: 1, + tables: [ + { + name: this.FILES_TABLE, + columns: [ + { + name: 'fileId', + type: 'TEXT', + primaryKey: true + }, + { + name: 'url', + type: 'TEXT', + notNull: true + }, + { + name: 'revision', + type: 'INTEGER' + }, + { + name: 'timemodified', + type: 'INTEGER' + }, + { + name: 'stale', + type: 'INTEGER' + }, + { + name: 'downloadTime', + type: 'INTEGER' + }, + { + name: 'isexternalfile', + type: 'INTEGER' + }, + { + name: 'repositorytype', + type: 'TEXT' + }, + { + name: 'path', + type: 'TEXT' + }, + { + name: 'extension', + type: 'TEXT' + } + ] + }, + { + name: this.LINKS_TABLE, + columns: [ + { + name: 'fileId', + type: 'TEXT' + }, + { + name: 'component', + type: 'TEXT' + }, + { + name: 'componentId', + type: 'TEXT' + } + ], + primaryKeys: ['fileId', 'component', 'componentId'] + }, + { + name: this.PACKAGES_TABLE, + columns: [ + { + name: 'id', + type: 'TEXT', + primaryKey: true + }, + { + name: 'component', + type: 'TEXT' + }, + { + name: 'componentId', + type: 'TEXT' + }, + { + name: 'status', + type: 'TEXT' + }, + { + name: 'previous', + type: 'TEXT' + }, + { + name: 'updated', + type: 'INTEGER' + }, + { + name: 'downloadTime', + type: 'INTEGER' + }, + { + name: 'previousDownloadTime', + type: 'INTEGER' + }, + { + name: 'extra', + type: 'TEXT' + } + ] + } + ] + }; protected logger; protected appDB: SQLiteDB; @@ -443,7 +447,7 @@ export class CoreFilepoolProvider { this.appDB = this.appProvider.getDB(); this.appDB.createTablesFromSchema(this.appTablesSchema); - this.sitesProvider.createTablesFromSchema(this.sitesTablesSchema); + this.sitesProvider.registerSiteSchema(this.siteSchma); initDelegate.ready().then(() => { // Waiting for the app to be ready to start processing the queue. diff --git a/src/providers/sites.ts b/src/providers/sites.ts index cd156af0c..7398ffcbe 100644 --- a/src/providers/sites.ts +++ b/src/providers/sites.ts @@ -265,6 +265,50 @@ export class CoreSitesProvider { } ]; + // Site schema for this provider. + protected siteSchema: CoreSiteSchema = { + name: 'CoreSitesProvider', + version: 1, + tables: [ + { + name: CoreSite.WS_CACHE_TABLE, + columns: [ + { + name: 'id', + type: 'TEXT', + primaryKey: true + }, + { + name: 'data', + type: 'TEXT' + }, + { + name: 'key', + type: 'TEXT' + }, + { + name: 'expirationTime', + type: 'INTEGER' + } + ] + }, + { + name: CoreSite.CONFIG_TABLE, + columns: [ + { + name: 'name', + type: 'TEXT', + unique: true, + notNull: true + }, + { + name: 'value' + } + ] + } + ] + }; + constructor(logger: CoreLoggerProvider, private http: HttpClient, private sitesFactory: CoreSitesFactoryProvider, private appProvider: CoreAppProvider, private translate: TranslateService, private urlUtils: CoreUrlUtilsProvider, private eventsProvider: CoreEventsProvider, private textUtils: CoreTextUtilsProvider, @@ -273,6 +317,7 @@ export class CoreSitesProvider { this.appDB = appProvider.getDB(); this.appDB.createTablesFromSchema(this.appTablesSchema); + this.registerSiteSchema(this.siteSchema); } /** diff --git a/src/providers/sync.ts b/src/providers/sync.ts index e1329d8e0..a248c2ad1 100644 --- a/src/providers/sync.ts +++ b/src/providers/sync.ts @@ -14,8 +14,7 @@ import { Injectable } from '@angular/core'; import { CoreEventsProvider } from './events'; -import { CoreSitesProvider } from './sites'; -import { SQLiteDBTableSchema } from '@classes/sqlitedb'; +import { CoreSitesProvider, CoreSiteSchema } from './sites'; /* * Service that provides some features regarding synchronization. @@ -25,36 +24,42 @@ export class CoreSyncProvider { // Variables for the database. protected SYNC_TABLE = 'sync'; - protected tableSchema: SQLiteDBTableSchema = { - name: this.SYNC_TABLE, - columns: [ + protected siteSchema: CoreSiteSchema = { + name: 'CoreSyncProvider', + version: 1, + tables: [ { - name: 'component', - type: 'TEXT', - notNull: true - }, - { - name: 'id', - type: 'TEXT', - notNull: true - }, - { - name: 'time', - type: 'INTEGER' - }, - { - name: 'warnings', - type: 'TEXT' + name: this.SYNC_TABLE, + columns: [ + { + name: 'component', + type: 'TEXT', + notNull: true + }, + { + name: 'id', + type: 'TEXT', + notNull: true + }, + { + name: 'time', + type: 'INTEGER' + }, + { + name: 'warnings', + type: 'TEXT' + } + ], + primaryKeys: ['component', 'id'] } - ], - primaryKeys: ['component', 'id'] + ] }; // Store blocked sync objects. protected blockedItems: { [siteId: string]: { [blockId: string]: { [operation: string]: boolean } } } = {}; constructor(eventsProvider: CoreEventsProvider, private sitesProvider: CoreSitesProvider) { - this.sitesProvider.createTableFromSchema(this.tableSchema); + this.sitesProvider.registerSiteSchema(this.siteSchema); // Unblock all blocks on logout. eventsProvider.on(CoreEventsProvider.LOGOUT, (data) => {