Fix no such column: IA.authorName error from early 6.0 beta upgrade

Fixes #3013
This commit is contained in:
Dan Stillman 2023-03-04 21:58:43 -05:00
parent 8ac77bf9f0
commit 1f45c44b86
2 changed files with 61 additions and 45 deletions

View file

@ -500,55 +500,68 @@ Zotero.Items = function() {
+ "FROM items JOIN itemAnnotations IA USING (itemID) " + "FROM items JOIN itemAnnotations IA USING (itemID) "
+ "WHERE libraryID=?" + idSQL; + "WHERE libraryID=?" + idSQL;
var params = [libraryID]; var params = [libraryID];
await Zotero.DB.queryAsync(
sql,
params,
{
noCache: true,
onRow: function (row) {
let itemID = row.getResultByIndex(0);
let item = this._objectCache[itemID]; // TEMP: Fix faulty upgrade from early 6.0 beta
if (!item) { // https://github.com/zotero/zotero/issues/3013
throw new Error("Item " + itemID + " not found"); try {
} await Zotero.DB.queryAsync(
sql,
params,
{
noCache: true,
onRow: function (row) {
let itemID = row.getResultByIndex(0);
item._parentItemID = row.getResultByIndex(1); let item = this._objectCache[itemID];
var typeID = row.getResultByIndex(2); if (!item) {
var type; throw new Error("Item " + itemID + " not found");
switch (typeID) { }
case Zotero.Annotations.ANNOTATION_TYPE_HIGHLIGHT:
type = 'highlight';
break;
case Zotero.Annotations.ANNOTATION_TYPE_NOTE: item._parentItemID = row.getResultByIndex(1);
type = 'note'; var typeID = row.getResultByIndex(2);
break; var type;
switch (typeID) {
case Zotero.Annotations.ANNOTATION_TYPE_HIGHLIGHT:
type = 'highlight';
break;
case Zotero.Annotations.ANNOTATION_TYPE_IMAGE: case Zotero.Annotations.ANNOTATION_TYPE_NOTE:
type = 'image'; type = 'note';
break; break;
case Zotero.Annotations.ANNOTATION_TYPE_INK: case Zotero.Annotations.ANNOTATION_TYPE_IMAGE:
type = 'ink'; type = 'image';
break; break;
default: case Zotero.Annotations.ANNOTATION_TYPE_INK:
throw new Error(`Unknown annotation type id ${typeID}`); type = 'ink';
} break;
item._annotationType = type;
item._annotationAuthorName = row.getResultByIndex(3);
item._annotationText = row.getResultByIndex(4);
item._annotationComment = row.getResultByIndex(5);
item._annotationColor = row.getResultByIndex(6);
item._annotationSortIndex = row.getResultByIndex(7);
item._annotationIsExternal = !!row.getResultByIndex(8);
item._loaded.annotation = true; default:
item._clearChanged('annotation'); throw new Error(`Unknown annotation type id ${typeID}`);
}.bind(this) }
item._annotationType = type;
item._annotationAuthorName = row.getResultByIndex(3);
item._annotationText = row.getResultByIndex(4);
item._annotationComment = row.getResultByIndex(5);
item._annotationColor = row.getResultByIndex(6);
item._annotationSortIndex = row.getResultByIndex(7);
item._annotationIsExternal = !!row.getResultByIndex(8);
item._loaded.annotation = true;
item._clearChanged('annotation');
}.bind(this)
}
);
}
catch (e) {
if (e.message.includes('no such column: IA.authorName')
&& await Zotero.DB.valueQueryAsync("SELECT COUNT(*) FROM version WHERE schema='userdata' AND version=120")) {
await Zotero.DB.queryAsync("UPDATE version SET version=119 WHERE schema='userdata'");
Zotero.crash();
} }
); throw e;
}
}; };

View file

@ -3466,6 +3466,9 @@ Zotero.Schema = new function(){
} }
} }
// TEMP: When adding 121, check whether IA.authorName fix in items.js::_loadAnnotations()
// should be updated
// If breaking compatibility or doing anything dangerous, clear minorUpdateFrom // If breaking compatibility or doing anything dangerous, clear minorUpdateFrom
} }