From 110e9f73727c13e9d97413d47fa11e48fdebf16b Mon Sep 17 00:00:00 2001 From: David Kellner <52860029+kellnerd@users.noreply.github.com> Date: Wed, 17 Jul 2024 22:17:49 +0200 Subject: [PATCH 1/5] fix(imports): Preserve annotation on approval --- src/func/imports/approve-import.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/func/imports/approve-import.ts b/src/func/imports/approve-import.ts index 0a58f79e..fe9b4db6 100644 --- a/src/func/imports/approve-import.ts +++ b/src/func/imports/approve-import.ts @@ -38,7 +38,7 @@ export async function approveImport( {orm, transacting, importEntity, editorId}: approveEntityPropsType ): Promise> { const {source, importId, type: entityType, disambiguationId, aliasSet, - identifierSetId} = importEntity; + identifierSetId, annotationId} = importEntity; const {id: aliasSetId} = aliasSet; const {Entity, Revision} = orm; @@ -79,6 +79,7 @@ export async function approveImport( const bbid = newEntity.get('bbid'); const propsToSet = _.extend({ aliasSetId, + annotationId, bbid, disambiguationId, identifierSetId, From 1d129f95f4266fcaef64bccf3194e75d6618dabd Mon Sep 17 00:00:00 2001 From: David Kellner <52860029+kellnerd@users.noreply.github.com> Date: Wed, 17 Jul 2024 23:12:48 +0200 Subject: [PATCH 2/5] fix(imports): Set revision of an imported annotation on approval --- src/func/imports/approve-import.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/func/imports/approve-import.ts b/src/func/imports/approve-import.ts index fe9b4db6..f6be42e0 100644 --- a/src/func/imports/approve-import.ts +++ b/src/func/imports/approve-import.ts @@ -41,23 +41,27 @@ export async function approveImport( identifierSetId, annotationId} = importEntity; const {id: aliasSetId} = aliasSet; - const {Entity, Revision} = orm; + const {Annotation, Entity, Revision} = orm; // Increase user edit count const editorUpdatePromise = incrementEditorEditCountById(orm, editorId, transacting); // Create a new revision record - const revisionPromise = new Revision({ + const revision = await new Revision({ authorId: editorId }).save(null, {transacting}); + const revisionId = revision.get('id'); + + if (annotationId) { + // Set revision of our annotation which is NULL for imports + await new Annotation({id: annotationId}) + .save({lastRevisionId: revisionId}, {transacting}); + } const note = `Approved from automatically imported record of ${source}`; // Create a new note promise - const notePromise = revisionPromise - .then((revision) => createNote( - orm, note, editorId, revision, transacting - )); + const notePromise = createNote(orm, note, editorId, revision, transacting); // Get additional props const additionalProps = getAdditionalEntityProps(importEntity, entityType); @@ -70,9 +74,7 @@ export async function approveImport( , {} ); - const [revisionRecord] = await Promise.all([ - revisionPromise, notePromise, editorUpdatePromise - ]); + await Promise.all([notePromise, editorUpdatePromise]); const newEntity = await new Entity({type: entityType}) .save(null, {transacting}); @@ -83,7 +85,7 @@ export async function approveImport( bbid, disambiguationId, identifierSetId, - revisionId: revisionRecord && revisionRecord.get('id') + revisionId }, entitySets, additionalProps); const Model = getEntityModelByType(orm, entityType); From 5a41a9f594a2e7e783e5b5de02d7eb5cff1aaab1 Mon Sep 17 00:00:00 2001 From: David Kellner <52860029+kellnerd@users.noreply.github.com> Date: Mon, 22 Jul 2024 15:27:41 +0200 Subject: [PATCH 3/5] fix(imports): Correctly convert entity type name to snake case Approving an Edition Group import failed previously: > error: select "data_id" from "bookbrainz"."editiongroup_import_header" where "import_id" = $1 - relation "bookbrainz.editiongroup_import_header" does not exist --- src/func/imports/delete-import.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/func/imports/delete-import.ts b/src/func/imports/delete-import.ts index 41ca7418..89fec124 100644 --- a/src/func/imports/delete-import.ts +++ b/src/func/imports/delete-import.ts @@ -27,8 +27,7 @@ export async function deleteImport( // Get the type of the import const [typeObj] = await transacting.select('type') .from('bookbrainz.import').where('id', importId); - const {type} = typeObj; - const importType = type.toLowerCase(); + const {type: importType} = typeObj; // Get the dataId of the import const [dataIdObj] = From 4e11b7259b7097c2256cdc649fc20ac8896e068e Mon Sep 17 00:00:00 2001 From: David Kellner <52860029+kellnerd@users.noreply.github.com> Date: Wed, 24 Jul 2024 18:45:25 +0200 Subject: [PATCH 4/5] fix(imports): Restrict type of the items in a series to exclude 'Series' --- src/types/parser.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/types/parser.ts b/src/types/parser.ts index 83587c01..8d914f1c 100644 --- a/src/types/parser.ts +++ b/src/types/parser.ts @@ -44,6 +44,7 @@ export type ParsedAuthor = ParsedBaseEntity & { beginDate?: string; endDate?: string; ended: boolean; + // TODO: `type` is currently ignored, only `typeId` is actually used! type?: string; typeId?: number; genderId?: number; @@ -79,7 +80,7 @@ export type ParsedPublisher = ParsedBaseEntity & { export type ParsedSeries = ParsedBaseEntity & { /** Type of the items in the series. */ - entityType: EntityTypeString; + entityType: Exclude; orderingTypeId: number; }; From aaa2a92248cd8b737965a6707cf5e3a17a47ea97 Mon Sep 17 00:00:00 2001 From: David Kellner <52860029+kellnerd@users.noreply.github.com> Date: Wed, 24 Jul 2024 20:27:45 +0200 Subject: [PATCH 5/5] feat(imports): Add model for imported series --- src/index.ts | 2 ++ src/models/imports/seriesImport.ts | 34 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/models/imports/seriesImport.ts diff --git a/src/index.ts b/src/index.ts index a9a8330d..7da0158d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -85,6 +85,7 @@ import revision from './models/revision'; import series from './models/entities/series'; import seriesData from './models/data/seriesData'; import seriesHeader from './models/headers/seriesHeader'; +import seriesImport from './models/imports/seriesImport'; import seriesOrderingType from './models/seriesOrderingType'; import seriesRevision from './models/revisions/seriesRevision'; import titleType from './models/titleType'; @@ -180,6 +181,7 @@ export default function init(config: Knex.Config) { Series: series(bookshelf), SeriesData, SeriesHeader: seriesHeader(bookshelf), + SeriesImport: seriesImport(bookshelf), SeriesOrderingType: seriesOrderingType(bookshelf), SeriesRevision: seriesRevision(bookshelf), TitleType: titleType(bookshelf), diff --git a/src/models/imports/seriesImport.ts b/src/models/imports/seriesImport.ts new file mode 100644 index 00000000..3b76bdce --- /dev/null +++ b/src/models/imports/seriesImport.ts @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2024 David Kellner + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +import type Bookshelf from '@metabrainz/bookshelf'; + + +export default function series(bookshelf: Bookshelf) { + const SeriesData = bookshelf.model('SeriesData'); + + const SeriesImport = SeriesData.extend({ + defaultAlias() { + return this.belongsTo('Alias', 'default_alias_id'); + }, + idAttribute: 'import_id', + tableName: 'bookbrainz.series_import' + }); + + return bookshelf.model('SeriesImport', SeriesImport); +}