From 391dfbdfcc518e6798ff50f4ad2bb25ac6d3480b Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Mon, 17 Apr 2023 14:54:09 +0200 Subject: [PATCH 1/2] MOBILE-4284 question: Drop unused DB columns WebSQL doesn't support dropping columns, that's why we're migrating to a new table with the _2 suffix instead. --- .../question/services/database/question.ts | 24 +++++++++---------- .../features/question/services/question.ts | 3 --- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/core/features/question/services/database/question.ts b/src/core/features/question/services/database/question.ts index f43a7991e..fc13bd4bb 100644 --- a/src/core/features/question/services/database/question.ts +++ b/src/core/features/question/services/database/question.ts @@ -12,16 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. +import { SQLiteDB } from '@classes/sqlitedb'; import { CoreSiteSchema } from '@services/sites'; /** * Database variables for CoreQuestion service. */ -export const QUESTION_TABLE_NAME = 'questions'; +export const QUESTION_TABLE_NAME = 'questions_2'; export const QUESTION_ANSWERS_TABLE_NAME = 'question_answers'; export const QUESTION_SITE_SCHEMA: CoreSiteSchema = { name: 'CoreQuestionProvider', - version: 1, + version: 2, tables: [ { name: QUESTION_TABLE_NAME, @@ -45,14 +46,6 @@ export const QUESTION_SITE_SCHEMA: CoreSiteSchema = { name: 'componentid', type: 'INTEGER', }, - { - name: 'userid', - type: 'INTEGER', - }, - { - name: 'number', - type: 'INTEGER', - }, { name: 'state', type: 'TEXT', @@ -102,6 +95,15 @@ export const QUESTION_SITE_SCHEMA: CoreSiteSchema = { primaryKeys: ['component', 'attemptid', 'name'], }, ], + async migrate(db: SQLiteDB, oldVersion: number): Promise { + if (oldVersion < 2) { + await db.migrateTable( + 'questions', + QUESTION_TABLE_NAME, + ({ component, componentid, attemptid, slot, state }) => ({ component, componentid, attemptid, slot, state }), + ); + } + }, }; /** @@ -112,8 +114,6 @@ export type CoreQuestionDBRecord = { attemptid: number; slot: number; componentid: number; - userid: number; - number?: number; // eslint-disable-line id-blacklist state: string; }; diff --git a/src/core/features/question/services/question.ts b/src/core/features/question/services/question.ts index de21a3373..fc3ed4d60 100644 --- a/src/core/features/question/services/question.ts +++ b/src/core/features/question/services/question.ts @@ -547,14 +547,11 @@ export class CoreQuestionProvider { state: string, siteId?: string, ): Promise { - const site = await CoreSites.getSite(siteId); const entry: CoreQuestionDBRecord = { component, componentid: componentId, attemptid: attemptId, - userid: userId, - number: question.number, // eslint-disable-line id-blacklist slot: question.slot, state: state, }; From e77b834ff2be15cd443e167a49f4263cd372bd05 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Mon, 17 Apr 2023 14:55:03 +0200 Subject: [PATCH 2/2] MOBILE-4284 quiz: Replace number w/ questionnumber --- .../navigation-modal/navigation-modal.html | 6 +++--- src/addons/mod/quiz/pages/player/player.html | 14 +++++++------- src/addons/mod/quiz/pages/review/review.html | 5 +++-- .../features/question/services/question-helper.ts | 2 +- src/core/features/question/services/question.ts | 12 +++++++++--- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/addons/mod/quiz/components/navigation-modal/navigation-modal.html b/src/addons/mod/quiz/components/navigation-modal/navigation-modal.html index 02c53969d..e1b07186d 100644 --- a/src/addons/mod/quiz/components/navigation-modal/navigation-modal.html +++ b/src/addons/mod/quiz/components/navigation-modal/navigation-modal.html @@ -18,11 +18,11 @@ (click)="loadPage(question.page, question.slot)" detail="false"> - {{ 'core.question.questionno' | translate:{$a: question.number} }} - {{ 'core.question.information' | translate }} + {{ 'core.question.questionno' | translate:{$a: question.questionnumber} }} + {{ 'core.question.information' | translate }} - + diff --git a/src/addons/mod/quiz/pages/player/player.html b/src/addons/mod/quiz/pages/player/player.html index 1512ee76d..25350c4c3 100644 --- a/src/addons/mod/quiz/pages/player/player.html +++ b/src/addons/mod/quiz/pages/player/player.html @@ -44,10 +44,10 @@ -

- {{ 'core.question.questionno' | translate:{$a: question.number} }} +

+ {{ 'core.question.questionno' | translate:{$a: question.questionnumber} }}

-

{{ 'core.question.information' | translate }}

+

{{ 'core.question.information' | translate }}

@@ -108,12 +108,12 @@ - + - {{ question.number }} + {{ question.questionnumber }} {{ question.status }} diff --git a/src/addons/mod/quiz/pages/review/review.html b/src/addons/mod/quiz/pages/review/review.html index 12e0feb23..ba362a23c 100644 --- a/src/addons/mod/quiz/pages/review/review.html +++ b/src/addons/mod/quiz/pages/review/review.html @@ -86,8 +86,9 @@ -

{{ 'core.question.questionno' | translate:{$a: question.number} }}

-

{{ 'core.question.information' | translate }}

+

{{ 'core.question.questionno' | translate:{$a: question.questionnumber} }} +

+

{{ 'core.question.information' | translate }}

diff --git a/src/core/features/question/services/question-helper.ts b/src/core/features/question/services/question-helper.ts index 0ee6c30e8..846f4d640 100644 --- a/src/core/features/question/services/question-helper.ts +++ b/src/core/features/question/services/question-helper.ts @@ -637,7 +637,7 @@ export class CoreQuestionHelperProvider { ): Promise { if (!component) { component = CoreQuestionProvider.COMPONENT; - componentId = question.number; + componentId = question.questionnumber; } const files = CoreQuestionDelegate.getAdditionalDownloadableFiles(question, usageId) || []; diff --git a/src/core/features/question/services/question.ts b/src/core/features/question/services/question.ts index fc3ed4d60..d64438748 100644 --- a/src/core/features/question/services/question.ts +++ b/src/core/features/question/services/question.ts @@ -314,7 +314,7 @@ export class CoreQuestionProvider { * @returns Question component ID. */ getQuestionComponentId(question: CoreQuestionQuestionParsed, componentId: string | number): string { - return componentId + '_' + question.number; + return componentId + '_' + question.questionnumber; } /** @@ -385,6 +385,10 @@ export class CoreQuestionProvider { const parsedQuestions: CoreQuestionQuestionParsed[] = questions; parsedQuestions.forEach((question) => { + if (typeof question.questionnumber === 'undefined' && typeof question.number === 'number') { + question.questionnumber = String(question.number); + } + if (!question.settings) { return; } @@ -591,14 +595,16 @@ export type CoreQuestionQuestionWSData = { lastactiontime?: number; // The timestamp of the most recent step in this question attempt. hasautosavedstep?: boolean; // Whether this question attempt has autosaved data. flagged: boolean; // Whether the question is flagged or not. - // eslint-disable-next-line id-blacklist - number?: number; // Question ordering number in the quiz. + questionnumber?: string; // @since 4.2. Question ordering number in the quiz. state?: string; // The state where the question is in. It won't be returned if the user cannot see it. status?: string; // Current formatted state of the question. blockedbyprevious?: boolean; // Whether the question is blocked by the previous question. mark?: string; // The mark awarded. It will be returned only if the user is allowed to see it. maxmark?: number; // The maximum mark possible for this question attempt. settings?: string; // Question settings (JSON encoded). + + /** @deprecated Since 4.2. Use questionnumber instead. */ + number?: number; // eslint-disable-line id-blacklist }; /** * Question data with parsed data.