From 4ea5e2d426e40ebec69c0012b82bc13d83ba87ad Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 6 Aug 2014 17:38:04 -0400 Subject: [PATCH] Update code to use 0 instead of NULL for libraryID --- chrome/content/zotero/bindings/tagsbox.xml | 2 +- .../content/zotero/bindings/tagselector.xml | 3 - .../content/zotero/bindings/zoterosearch.xml | 2 - chrome/content/zotero/lookup.js | 2 +- chrome/content/zotero/recognizePDF.js | 2 +- .../zotero/xpcom/collectionTreeView.js | 55 +++++++---------- .../content/zotero/xpcom/data/collection.js | 25 ++++---- chrome/content/zotero/xpcom/data/creator.js | 31 +++++----- chrome/content/zotero/xpcom/data/creators.js | 17 ++---- .../zotero/xpcom/data/dataObjectUtilities.js | 51 ++++++++++++++++ .../content/zotero/xpcom/data/dataObjects.js | 39 ++---------- chrome/content/zotero/xpcom/data/item.js | 30 ++++----- chrome/content/zotero/xpcom/data/items.js | 29 ++------- chrome/content/zotero/xpcom/data/relation.js | 4 ++ chrome/content/zotero/xpcom/data/tag.js | 31 +++++----- chrome/content/zotero/xpcom/data/tags.js | 61 +++++-------------- chrome/content/zotero/xpcom/data_access.js | 13 +--- chrome/content/zotero/xpcom/duplicates.js | 2 +- chrome/content/zotero/xpcom/integration.js | 9 ++- chrome/content/zotero/xpcom/itemTreeView.js | 13 +--- chrome/content/zotero/xpcom/search.js | 37 +++++------ chrome/content/zotero/xpcom/storage.js | 37 ++++------- .../zotero/xpcom/translation/translate.js | 2 +- chrome/content/zotero/xpcom/uri.js | 1 - chrome/content/zotero/zoteroPane.js | 16 +++-- components/zotero-autocomplete.js | 9 +-- components/zotero-protocol-handler.js | 2 +- components/zotero-service.js | 1 + 28 files changed, 213 insertions(+), 313 deletions(-) create mode 100644 chrome/content/zotero/xpcom/data/dataObjectUtilities.js diff --git a/chrome/content/zotero/bindings/tagsbox.xml b/chrome/content/zotero/bindings/tagsbox.xml index d55c5781a8..8011488058 100644 --- a/chrome/content/zotero/bindings/tagsbox.xml +++ b/chrome/content/zotero/bindings/tagsbox.xml @@ -207,7 +207,7 @@ this.id('addButton').hidden = !this.editable; var self = this; - return Zotero.Tags.getColors(self.item.libraryIDInt) + return Zotero.Tags.getColors(self.item.libraryID) .then(function (colors) { self._tagColors = colors; diff --git a/chrome/content/zotero/bindings/tagselector.xml b/chrome/content/zotero/bindings/tagselector.xml index faca83397b..e795c67479 100644 --- a/chrome/content/zotero/bindings/tagselector.xml +++ b/chrome/content/zotero/bindings/tagselector.xml @@ -77,9 +77,6 @@ . + + ***** END LICENSE BLOCK ***** +*/ + + +Zotero.DataObjectUtilities = { + "checkLibraryID": function (libraryID) { + if (libraryID === null) { + Zotero.debug("Deprecated: libraryID cannot be NULL\n\n" + Components.stack, 2); + } + else { + var intValue = parseInt(libraryID); + if (libraryID != intValue) { + throw new Error("libraryID must be an integer"); + } + } + return intValue; + }, + + "getObjectTypePlural": function getObjectTypePlural(objectType) { + return objectType == 'search' ? 'searches' : objectType + 's'; + }, + + + "getClassForObjectType": function getClassForObjectType(objectType) { + var objectTypePlural = this.getObjectTypePlural(objectType); + var className = objectTypePlural[0].toUpperCase() + objectTypePlural.substr(1); + return Zotero[className] + } +}; diff --git a/chrome/content/zotero/xpcom/data/dataObjects.js b/chrome/content/zotero/xpcom/data/dataObjects.js index 27ca1691f8..20d1831e14 100644 --- a/chrome/content/zotero/xpcom/data/dataObjects.js +++ b/chrome/content/zotero/xpcom/data/dataObjects.js @@ -55,7 +55,6 @@ Zotero.DataObjects = function (object, objectPlural, id, table) { this.makeLibraryKeyHash = function (libraryID, key) { - var libraryID = libraryID ? libraryID : 0; return libraryID + '_' + key; } @@ -70,57 +69,29 @@ Zotero.DataObjects = function (object, objectPlural, id, table) { if (!key) { return false; } - libraryID = parseInt(libraryID); return { - libraryID: libraryID ? libraryID : null, + libraryID: parseInt(libraryID), key: key }; } - /** - * Retrieves an object of the current by its key - * - * @param {String} key - * @return {Zotero.DataObject} Zotero data object, or FALSE if not found - */ - this.getByKey = function (key) { - if (arguments.length > 1) { - throw ("getByKey() takes only one argument"); - } - - Components.utils.reportError("Zotero." + this._ZDO_Objects - + ".getByKey() is deprecated -- use getByLibraryAndKey()"); - - return this.getByLibraryAndKey(null, key); - } - - /** * Retrieves an object by its libraryID and key * - * @param {Integer|NULL} libraryID + * @param {Integer} libraryID * @param {String} key * @return {Zotero.DataObject} Zotero data object, or FALSE if not found */ this.getByLibraryAndKey = function (libraryID, key) { var sql = "SELECT ROWID FROM " + this._ZDO_table + " WHERE "; - var params = []; if (this._ZDO_idOnly) { sql += "ROWID=?"; - params.push(key); + var params = [key] } else { - sql += "libraryID"; - if (libraryID && libraryID !== '0') { - sql += "=? "; - params.push(libraryID); - } - else { - sql += " IS NULL "; - } - sql += "AND key=?"; - params.push(key); + sql += "libraryID=? AND key=?"; + var params = [libraryID, key]; } var id = Zotero.DB.valueQuery(sql, params); if (!id) { diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 32b3312545..720f2f9cf3 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -112,8 +112,6 @@ Zotero.Item.prototype.__defineGetter__('itemID', function () { }); Zotero.Item.prototype.__defineSetter__('id', function (val) { this.setField('id', val); }); Zotero.Item.prototype.__defineGetter__('libraryID', function () { return this.getField('libraryID'); }); -// Temporary until everything expects an integer -Zotero.Item.prototype.__defineGetter__('libraryIDInt', function () { var libraryID = this.getField('libraryID'); return libraryID ? parseInt(libraryID) : 0; }); Zotero.Item.prototype.__defineSetter__('libraryID', function (val) { this.setField('libraryID', val); }); Zotero.Item.prototype.__defineGetter__('key', function () { return this.getField('key'); }); Zotero.Item.prototype.__defineSetter__('key', function (val) { this.setField('key', val) }); @@ -132,7 +130,7 @@ Zotero.Item.prototype.__defineSetter__('relatedItems', function (arr) { this._se Zotero.Item.prototype.__defineGetter__('relatedItemsReverse', function () { var ids = this._getRelatedItemsReverse(); return ids; }); Zotero.Item.prototype.__defineGetter__('relatedItemsBidirectional', function () { var ids = this._getRelatedItemsBidirectional(); return ids; }); -Zotero.Item.prototype.__defineGetter__('libraryKey', function () this.libraryIDInt + "/" + this.key); +Zotero.Item.prototype.__defineGetter__('libraryKey', function () this.libraryID + "/" + this.key); Zotero.Item.prototype.getID = function() { Zotero.debug('Item.getID() is deprecated -- use Item.id'); @@ -344,15 +342,8 @@ Zotero.Item.prototype.loadPrimaryData = function(allowFail) { var params = id; } else { - sql += "key=? "; - var params = [key]; - if (libraryID) { - sql += "AND libraryID=? "; - params.push(libraryID); - } - else { - sql += "AND libraryID IS NULL "; - } + sql += "key=? AND libraryID=? "; + var params = [key, libraryID]; } sql += (where.length ? ' AND ' + where.join(' AND ') : ''); var row = Zotero.DB.rowQuery(sql, params); @@ -398,7 +389,7 @@ Zotero.Item.prototype.loadFromRow = function(row, reload) { break; case 'libraryID': - this['_' + col] = row[col] ? row[col] : null; + this['_' + col] = row[col]; break; case 'numNotes': @@ -707,6 +698,10 @@ Zotero.Item.prototype.setField = function(field, value, loadIn) { case 'id': case 'libraryID': case 'key': + if (field == 'libraryID') { + value = Zotero.DataObjectUtilities.checkLibraryID(value); + } + if (value == this['_' + field]) { return; } @@ -714,7 +709,6 @@ Zotero.Item.prototype.setField = function(field, value, loadIn) { if (this._primaryDataLoaded) { throw ("Cannot set " + field + " after object is already loaded in Zotero.Item.setField()"); } - //this._checkValue(field, val); this['_' + field] = value; return; } @@ -1323,7 +1317,7 @@ Zotero.Item.prototype.save = function(options) { this.dateAdded ? this.dateAdded : Zotero.DB.transactionDateTime, this.dateModified ? this.dateModified : Zotero.DB.transactionDateTime, Zotero.DB.transactionDateTime, - this.libraryID ? this.libraryID : null, + this.libraryID ? this.libraryID : 0, key ); @@ -2181,7 +2175,7 @@ Zotero.Item.prototype.save = function(options) { } } // Refresh trash - Zotero.Notifier.trigger('refresh', 'trash', this.libraryID ? this.libraryID : 0); + Zotero.Notifier.trigger('refresh', 'trash', this.libraryID); if (this._deleted) { Zotero.Notifier.trigger('trash', 'item', this.id); } @@ -3784,7 +3778,7 @@ Zotero.Item.prototype.addTag = function(name, type) { var tagID = Zotero.Tags.getID(name, type, this.libraryID); if (!tagID) { var tag = new Zotero.Tag; - tag.libraryID = this.libraryID ? this.libraryID : null; + tag.libraryID = this.libraryID; tag.name = name; tag.type = type; var tagID = tag.save(); @@ -4025,7 +4019,7 @@ Zotero.Item.prototype.addLinkedItem = function (item) { // If one of the items is a personal library, store relation with that. // Otherwise, use current item's library (which in calling code is the // new, copied item). - var libraryID = (!this.libraryID || !item.libraryID) ? null : this.libraryID; + var libraryID = (!this.libraryID || !item.libraryID) ? 0 : this.libraryID; Zotero.Relations.add(libraryID, url1, predicate, url2); } diff --git a/chrome/content/zotero/xpcom/data/items.js b/chrome/content/zotero/xpcom/data/items.js index abc500e8a4..4a37d9a376 100644 --- a/chrome/content/zotero/xpcom/data/items.js +++ b/chrome/content/zotero/xpcom/data/items.js @@ -132,31 +132,20 @@ Zotero.Items = new function() { /** * Return items marked as deleted * - * @param {Number|NULL} libraryID + * @param {Integer} libraryID * @param {Boolean} asIDs Return itemIDs instead of * Zotero.Item objects * @return {Zotero.Item[]|Integer[]} */ this.getDeleted = function (libraryID, asIDs, days) { - // Throw warning for pre-3.0b3 arguments - if (typeof libraryID == 'boolean') { - throw new Error("libraryID must be a number or null"); - } - var sql = "SELECT itemID FROM items JOIN deletedItems USING (itemID) " - + "WHERE libraryID" + (libraryID ? "=?" : " IS NULL"); + + "WHERE libraryID=?"; if (days) { sql += " AND dateDeleted<=DATE('NOW', '-" + parseInt(days) + " DAYS')"; } - if (libraryID) { - var ids = Zotero.DB.columnQuery(sql, [libraryID]); - } - else { - var ids = Zotero.DB.columnQuery(sql); - } - + var ids = Zotero.DB.columnQuery(sql, [libraryID]); if (!ids) { return []; } @@ -185,14 +174,8 @@ Zotero.Items = new function() { if (!includeDeleted) { sql += " AND A.itemID NOT IN (SELECT itemID FROM deletedItems)"; } - if (libraryID) { - sql += " AND libraryID=?"; - var ids = Zotero.DB.columnQuery(sql, libraryID); - } - else { - sql += " AND libraryID IS NULL"; - var ids = Zotero.DB.columnQuery(sql); - } + sql += " AND libraryID=?"; + var ids = Zotero.DB.columnQuery(sql, libraryID); return this.get(ids); } @@ -505,7 +488,7 @@ Zotero.Items = new function() { deletedIDs = deletedIDs.slice(0, limit - 1) } this.erase(deletedIDs); - Zotero.Notifier.trigger('refresh', 'trash', libraryID ? libraryID : 0); + Zotero.Notifier.trigger('refresh', 'trash', libraryID); } Zotero.DB.commitTransaction(); diff --git a/chrome/content/zotero/xpcom/data/relation.js b/chrome/content/zotero/xpcom/data/relation.js index 32a3eee373..87ca522bdc 100644 --- a/chrome/content/zotero/xpcom/data/relation.js +++ b/chrome/content/zotero/xpcom/data/relation.js @@ -73,6 +73,10 @@ Zotero.Relation.prototype._set = function (field, val) { if (this._loaded) { throw ("Cannot set " + field + " after object is already loaded in Zotero.Relation._set()"); } + + if (field == 'libraryID') { + val = parseInt(val); + } this['_' + field] = val; return; } diff --git a/chrome/content/zotero/xpcom/data/tag.js b/chrome/content/zotero/xpcom/data/tag.js index f7a1a0914d..e1276656ac 100644 --- a/chrome/content/zotero/xpcom/data/tag.js +++ b/chrome/content/zotero/xpcom/data/tag.js @@ -86,6 +86,10 @@ Zotero.Tag.prototype._set = function (field, val) { case 'id': case 'libraryID': case 'key': + if (field == 'libraryID') { + val = Zotero.DataObjectUtilities.checkLibraryID(val); + } + if (val == this['_' + field]) { return; } @@ -93,7 +97,9 @@ Zotero.Tag.prototype._set = function (field, val) { if (this._loaded) { throw ("Cannot set " + field + " after object is already loaded in Zotero.Tag._set()"); } + //this._checkValue(field, val); + this['_' + field] = val; return; @@ -158,15 +164,8 @@ Zotero.Tag.prototype.load = function() { var params = id; } else { - sql += "key=?"; - var params = [key]; - if (libraryID) { - sql += " AND libraryID=?"; - params.push(libraryID); - } - else { - sql += " AND libraryID IS NULL"; - } + sql += "key=? AND libraryID=?"; + var params = [key, libraryID]; } var row = Zotero.DB.rowQuery(sql, params); @@ -192,7 +191,7 @@ Zotero.Tag.prototype.loadFromRow = function (row) { continue; case 'libraryID': - this['_' + col] = row[col] ? row[col] : null; + this['_' + col] = row[col]; continue; } this['_' + col] = (!row[col] && row[col] !== 0) ? '' : row[col]; @@ -321,7 +320,7 @@ Zotero.Tag.prototype.save = function (full) { 'libraryID', 'key' ]; - var placeholders = ['?', '?', '?', '?', '?', '?', '?', '?']; + var placeholders = columns.map(function () '?').join(); var sqlValues = [ tagID ? { int: tagID } : null, { string: this.name }, @@ -332,14 +331,14 @@ Zotero.Tag.prototype.save = function (full) { this._changed.dateModified ? this.dateModified : Zotero.DB.transactionDateTime, Zotero.DB.transactionDateTime, - this.libraryID ? this.libraryID : null, + this.libraryID ? this.libraryID : 0, key ]; try { if (isNew) { - var sql = "INSERT INTO tags (" + columns.join(', ') + ") VALUES (" - + placeholders.join(', ') + ")"; + var sql = "INSERT INTO tags (" + columns.join(', ') + ") " + + "VALUES (" + placeholders + ")"; var insertID = Zotero.DB.query(sql, sqlValues); if (!tagID) { tagID = insertID; @@ -381,8 +380,8 @@ Zotero.Tag.prototype.save = function (full) { // Save again if (isNew) { - var sql = "INSERT INTO tags (" + columns.join(', ') + ") VALUES (" - + placeholders.join(', ') + ")"; + var sql = "INSERT INTO tags (" + columns.join(', ') + ") " + + "VALUES (" + placeholders + ")"; var insertID = Zotero.DB.query(sql, sqlValues); if (!tagID) { tagID = insertID; diff --git a/chrome/content/zotero/xpcom/data/tags.js b/chrome/content/zotero/xpcom/data/tags.js index a8b8949cc8..9cd55d23aa 100644 --- a/chrome/content/zotero/xpcom/data/tags.js +++ b/chrome/content/zotero/xpcom/data/tags.js @@ -98,16 +98,8 @@ Zotero.Tags = new function() { // FIXME: COLLATE NOCASE doesn't work for Unicode characters, so this // won't find Äbc if "äbc" is entered and will allow a duplicate tag // to be created - var sql = "SELECT tagID FROM tags WHERE name=? AND type=? AND libraryID"; - var params = [name, type]; - if (libraryID) { - sql += "=?"; - params.push(libraryID); - } - else { - sql += " IS NULL"; - } - var tagID = Zotero.DB.valueQuery(sql, params); + var sql = "SELECT tagID FROM tags WHERE name=? AND type=? AND libraryID=?"; + var tagID = Zotero.DB.valueQuery(sql, [name, type, libraryID]); if (tagID) { if (!_tags[libraryID]) { _tags[libraryID] = {}; @@ -127,16 +119,8 @@ Zotero.Tags = new function() { */ function getIDs(name, libraryID) { name = Zotero.Utilities.trim(name); - var sql = "SELECT tagID FROM tags WHERE name=? AND libraryID"; - var params = [name]; - if (libraryID) { - sql += "=?"; - params.push(libraryID); - } - else { - sql += " IS NULL"; - } - return Zotero.DB.columnQuery(sql, params); + var sql = "SELECT tagID FROM tags WHERE name=? AND libraryID=?"; + return Zotero.DB.columnQuery(sql, [name, libraryID]); } @@ -145,16 +129,8 @@ Zotero.Tags = new function() { */ function getTypes(name, libraryID) { name = Zotero.Utilities.trim(name); - var sql = "SELECT type FROM tags WHERE name=? AND libraryID"; - var params = [name]; - if (libraryID) { - sql += "=?"; - params.push(libraryID); - } - else { - sql += " IS NULL"; - } - return Zotero.DB.columnQuery(sql, params); + var sql = "SELECT type FROM tags WHERE name=? AND libraryID=?"; + return Zotero.DB.columnQuery(sql, [name, libraryID]); } @@ -164,15 +140,8 @@ Zotero.Tags = new function() { * _types_ is an optional array of tag types to fetch */ function getAll(types, libraryID) { - var sql = "SELECT tagID, name FROM tags WHERE libraryID"; - var params = []; - if (libraryID) { - sql += "=?"; - params.push(libraryID); - } - else { - sql += " IS NULL"; - } + var sql = "SELECT tagID, name FROM tags WHERE libraryID=?"; + var params = [libraryID]; if (types) { sql += " AND type IN (" + types.join() + ")"; } @@ -314,7 +283,7 @@ Zotero.Tags = new function() { // We need to know if the old tag has a color assigned so that // we can assign it to the new name - return self.getColor(libraryID ? parseInt(libraryID) : 0, oldName); + return self.getColor(libraryID, oldName); }) .then(function (oldColorData) { Zotero.DB.beginTransaction(); @@ -400,14 +369,12 @@ Zotero.Tags = new function() { Zotero.DB.commitTransaction(); if (oldColorData) { - var libraryIDInt = libraryID ? parseInt(libraryID) : 0 - // Remove color from old tag - return self.setColor(libraryIDInt, oldName) + return self.setColor(libraryID, oldName) // Add color to new tag .then(function () { return self.setColor( - libraryIDInt, + libraryID, newName, oldColorData.color, oldColorData.position @@ -493,7 +460,7 @@ Zotero.Tags = new function() { * @return {Promise} */ this.setColor = function (libraryID, name, color, position) { - if (libraryID === null) { + if (!Number.isInteger(libraryID)) { throw new Error("libraryID must be an integer"); } @@ -828,7 +795,7 @@ Zotero.Tags = new function() { var tag = this.get(id); if (tag) { deleted.push({ - libraryID: tag.libraryID ? parseInt(tag.libraryID) : 0, + libraryID: tag.libraryID, name: tag.name }); tag.erase(); @@ -950,7 +917,7 @@ Zotero.Tags = new function() { for each(var id in ids) { var tag = this._objectCache[id]; delete this._objectCache[id]; - var libraryID = tag.libraryID ? tag.libraryID : 0; + var libraryID = tag.libraryID; if (tag && _tags[libraryID] && _tags[libraryID][tag.type]) { delete _tags[libraryID][tag.type]['_' + tag.name]; } diff --git a/chrome/content/zotero/xpcom/data_access.js b/chrome/content/zotero/xpcom/data_access.js index b01e12d236..5165e308b5 100644 --- a/chrome/content/zotero/xpcom/data_access.js +++ b/chrome/content/zotero/xpcom/data_access.js @@ -41,17 +41,8 @@ Zotero.getCollections = function(parent, recursive, libraryID) { } var sql = "SELECT collectionID AS id, collectionName AS name FROM collections C " - + "WHERE parentCollectionID " + (parent ? '=' + parent : 'IS NULL'); - if (libraryID) { - sql += " AND libraryID=?"; - var children = Zotero.DB.query(sql, libraryID); - } - else { - if (!parent) { - sql += " AND libraryID IS NULL"; - } - var children = Zotero.DB.query(sql); - } + + "WHERE libraryID=? AND parentCollectionID " + (parent ? '=' + parent : 'IS NULL'); + var children = Zotero.DB.query(sql, [libraryID ? libraryID : 0]); if (!children) { Zotero.debug('No child collections of collection ' + parent, 5); diff --git a/chrome/content/zotero/xpcom/duplicates.js b/chrome/content/zotero/xpcom/duplicates.js index e3350cac50..c26b4c0701 100644 --- a/chrome/content/zotero/xpcom/duplicates.js +++ b/chrome/content/zotero/xpcom/duplicates.js @@ -29,7 +29,7 @@ Zotero.Duplicates = function (libraryID) { } if (!libraryID) { - libraryID = null; + libraryID = 0; } this._libraryID = libraryID; diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index 3d92761a98..11900cf16b 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -2309,7 +2309,8 @@ Zotero.Integration.Session.prototype.lookupItems = function(citation, index) { } } else { if(citationItem.key) { - zoteroItem = Zotero.Items.getByKey(citationItem.key); + // DEBUG: why no library id? + zoteroItem = Zotero.Items.getByLibraryAndKey(0, citationItem.key); } else if(citationItem.itemID) { zoteroItem = Zotero.Items.get(citationItem.itemID); } else if(citationItem.id) { @@ -2705,7 +2706,8 @@ Zotero.Integration.Session.prototype.loadBibliographyData = function(json) { } else { for(var itemID in documentData.uncited) { // if not yet in item set, add to item set - var zoteroItem = Zotero.Items.getByKey(itemID); + // DEBUG: why no libraryID? + var zoteroItem = Zotero.Items.getByLibraryAndKey(0, itemID); if(!zoteroItem) zoteroItem = Zotero.Items.get(itemID); if(zoteroItem) this.uncitedItems[zoteroItem.id] = true; } @@ -2733,7 +2735,8 @@ Zotero.Integration.Session.prototype.loadBibliographyData = function(json) { } else { // old style hash for(var itemID in documentData.custom) { - var zoteroItem = Zotero.Items.getByKey(itemID); + // DEBUG: why no libraryID? + var zoteroItem = Zotero.Items.getByLibraryAndKey(0, itemID); if(!zoteroItem) zoteroItem = Zotero.Items.get(itemID); if(!zoteroItem) continue; diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js index 6b0c8de16c..b37c6c4f7b 100644 --- a/chrome/content/zotero/xpcom/itemTreeView.js +++ b/chrome/content/zotero/xpcom/itemTreeView.js @@ -195,7 +195,6 @@ Zotero.ItemTreeView.prototype._setTreeGenerator = function(treebox) Q.fcall(function () { if (coloredTagsRE.test(key)) { let libraryID = self._itemGroup.ref.libraryID; - libraryID = libraryID ? parseInt(libraryID) : 0; let position = parseInt(key) - 1; return Zotero.Tags.getColorByPosition(libraryID, position) .then(function (colorData) { @@ -1038,8 +1037,7 @@ Zotero.ItemTreeView.prototype.getImageSrc = function(row, col) var colorData = []; for (let i=0, len=tags.length; i=?"; var params = [ - libraryID == 0 ? null : libraryID, + libraryID, Zotero.Attachments.LINK_MODE_IMPORTED_FILE, Zotero.Attachments.LINK_MODE_IMPORTED_URL, Zotero.Sync.Storage.SYNC_STATE_IN_SYNC, diff --git a/chrome/content/zotero/xpcom/translation/translate.js b/chrome/content/zotero/xpcom/translation/translate.js index d895ef404f..2e55a6644c 100644 --- a/chrome/content/zotero/xpcom/translation/translate.js +++ b/chrome/content/zotero/xpcom/translation/translate.js @@ -1074,7 +1074,7 @@ Zotero.Translate.Base.prototype = { * translators, but new code should use {@link Zotero.Translate.Base#setHandler} to register a * "done" handler to determine when execution of web/search translators is complete. * - * @param {NULL|Integer|FALSE} [libraryID=null] Library in which to save items, + * @param {Integer|FALSE} [libraryID=0] Library in which to save items, * or NULL for default library; * if FALSE, don't save items * @param {Boolean} [saveAttachments=true] Exclude attachments (e.g., snapshots) on import diff --git a/chrome/content/zotero/xpcom/uri.js b/chrome/content/zotero/xpcom/uri.js index 38511214a8..b13fe8ff50 100644 --- a/chrome/content/zotero/xpcom/uri.js +++ b/chrome/content/zotero/xpcom/uri.js @@ -83,7 +83,6 @@ Zotero.URI = new function () { * Get path portion of library URI (e.g., users/6 or groups/1) */ this.getLibraryPath = function (libraryID) { - libraryID = libraryID ? parseInt(libraryID) : 0; var libraryType = Zotero.Libraries.getType(libraryID); switch (libraryType) { diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index 652fffcdbe..c212f1ae07 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -761,7 +761,7 @@ var ZoteroPane = new function() var libraryID = itemGroup.ref.libraryID; } else { - var libraryID = null; + var libraryID = 0; var itemGroup = null; } @@ -885,12 +885,12 @@ var ZoteroPane = new function() switch (mode) { case 'duplicates': var prefKey = 'duplicateLibraries'; - var lastViewedFolderID = 'D' + (libraryID ? libraryID : 0); + var lastViewedFolderID = 'D' + libraryID; break; case 'unfiled': var prefKey = 'unfiledLibraries'; - var lastViewedFolderID = 'U' + (libraryID ? libraryID : 0); + var lastViewedFolderID = 'U' + libraryID; break; default: @@ -2491,8 +2491,7 @@ var ZoteroPane = new function() // on a library sync error icon if (itemGroup.isLibrary(true)) { if (col.value.id == 'zotero-collections-sync-status-column') { - var libraryID = itemGroup.isLibrary() ? 0 : itemGroup.ref.libraryID; - var errors = Zotero.Sync.Runner.getErrors(libraryID); + var errors = Zotero.Sync.Runner.getErrors(itemGroup.ref.libraryID); if (errors) { event.stopPropagation(); return; @@ -2569,8 +2568,7 @@ var ZoteroPane = new function() // sync error icon if (itemGroup.isLibrary(true)) { if (col.value.id == 'zotero-collections-sync-status-column') { - var libraryID = itemGroup.isLibrary() ? 0 : itemGroup.ref.libraryID; - var errors = Zotero.Sync.Runner.getErrors(libraryID); + var errors = Zotero.Sync.Runner.getErrors(itemGroup.ref.libraryID); if (!errors) { return; } @@ -3195,7 +3193,7 @@ var ZoteroPane = new function() var libraryID = itemGroup.ref.libraryID; } else { - var libraryID = null; + var libraryID = 0; var itemGroup = null; } // @@ -3317,7 +3315,7 @@ var ZoteroPane = new function() var libraryID = itemGroup.ref.libraryID; } else { - var libraryID = null; + var libraryID = 0; var itemGroup = null; } // diff --git a/components/zotero-autocomplete.js b/components/zotero-autocomplete.js index 331cdb1442..884366eb64 100644 --- a/components/zotero-autocomplete.js +++ b/components/zotero-autocomplete.js @@ -156,13 +156,8 @@ ZoteroAutoComplete.prototype.startSearch = function(searchString, searchParams, fromSQL += ")"; } if (typeof searchParams.libraryID != 'undefined') { - if (searchParams.libraryID) { - fromSQL += " AND libraryID=?"; - sqlParams.push(searchParams.libraryID); - } - else { - fromSQL += " AND libraryID IS NULL"; - } + fromSQL += " AND libraryID=?"; + sqlParams.push(searchParams.libraryID); } sql += fromSQL; diff --git a/components/zotero-protocol-handler.js b/components/zotero-protocol-handler.js index 95bf637123..ec370b13d1 100644 --- a/components/zotero-protocol-handler.js +++ b/components/zotero-protocol-handler.js @@ -696,7 +696,7 @@ function ChromeExtensionHandler() { default: type = 'library'; var s = new Zotero.Search(); - s.addCondition('libraryID', 'is', id ? id : null); + s.addCondition('libraryID', 'is', id ? id : 0); s.addCondition('noChildren', 'true'); var ids = s.search(); var results = Zotero.Items.get(ids); diff --git a/components/zotero-service.js b/components/zotero-service.js index 4e5c1c381e..3f6f635b6d 100644 --- a/components/zotero-service.js +++ b/components/zotero-service.js @@ -61,6 +61,7 @@ const xpcomFilesLocal = [ 'cookieSandbox', 'data_access', 'data/dataObjects', + 'data/dataObjectUtilities', 'data/cachedTypes', 'data/item', 'data/items',