Update code to use 0 instead of NULL for libraryID

This commit is contained in:
Dan Stillman 2014-08-06 17:38:04 -04:00
parent 368e568fe1
commit 4ea5e2d426
28 changed files with 213 additions and 313 deletions

View file

@ -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;

View file

@ -77,9 +77,6 @@
<property name="libraryID" onget="return this._libraryID">
<setter>
<![CDATA[
// TEMP: libraryIDInt
val = val ? parseInt(val) : 0;
if (this._libraryID != val) {
this._dirty = true;
}

View file

@ -442,7 +442,6 @@
var rows = [];
var libraryID = this.parent.search.libraryID;
libraryID = libraryID ? libraryID : null;
var cols = Zotero.getCollections(false, true, libraryID);
for (var i in cols) {
// Indent subcollections
@ -461,7 +460,6 @@
case 'savedSearch':
var rows = [];
var libraryID = this.parent.search.libraryID;
libraryID = libraryID ? libraryID : null;
var searches = Zotero.Searches.getAll(libraryID);
for (var i in searches) {
if (searches[i].id != this.parent.search.id) {

View file

@ -94,7 +94,7 @@ const Zotero_Lookup = new function () {
return false;
}
var libraryID = null;
var libraryID = false;
var collection = false;
try {
libraryID = ZoteroPane_Local.getSelectedLibraryID();

View file

@ -64,7 +64,7 @@ var Zotero_RecognizePDF = new function() {
* Retrieves metadata for a PDF and saves it as an item
*
* @param {nsIFile} file The PDF file to retrieve metadata for
* @param {Integer|null} libraryID The library in which to save the PDF
* @param {Integer} libraryID The library in which to save the PDF
* @param {Function} stopCheckCallback Function that returns true if the
* process is to be interrupted
* @return {Promise} A promise resolved when PDF metadata has been retrieved

View file

@ -139,27 +139,27 @@ Zotero.CollectionTreeView.prototype.refresh = function()
if (this.hideSources.indexOf('duplicates') == -1) {
try {
this._duplicateLibraries = Zotero.Prefs.get('duplicateLibraries').split(',');
this._duplicateLibraries = Zotero.Prefs.get('duplicateLibraries').split(',').map(function (val) parseInt(val));
}
catch (e) {
// Add to personal library by default
Zotero.Prefs.set('duplicateLibraries', '0');
this._duplicateLibraries = ['0'];
this._duplicateLibraries = [0];
}
}
try {
this._unfiledLibraries = Zotero.Prefs.get('unfiledLibraries').split(',');
this._unfiledLibraries = Zotero.Prefs.get('unfiledLibraries').split(',').map(function (val) parseInt(val));
}
catch (e) {
// Add to personal library by default
Zotero.Prefs.set('unfiledLibraries', '0');
this._unfiledLibraries = ['0'];
this._unfiledLibraries = [0];
}
var self = this;
var library = {
libraryID: null
libraryID: 0
};
// itemgroup, level, beforeRow, startOpen
@ -436,7 +436,7 @@ Zotero.CollectionTreeView.prototype.getImageSrc = function(row, col)
break;
case 'trash':
if (this._trashNotEmpty[itemGroup.ref.libraryID ? itemGroup.ref.libraryID : 0]) {
if (this._trashNotEmpty[itemGroup.ref.libraryID]) {
collectionType += '-full';
}
break;
@ -490,7 +490,6 @@ Zotero.CollectionTreeView.prototype.isContainerEmpty = function(row)
}
if (itemGroup.isGroup()) {
var libraryID = itemGroup.ref.libraryID;
libraryID = (libraryID ? libraryID : 0) + '';
return !itemGroup.ref.hasCollections()
&& !itemGroup.ref.hasSearches()
@ -701,7 +700,7 @@ Zotero.CollectionTreeView.prototype.expandToCollection = function(collectionID)
///
////////////////////////////////////////////////////////////////////////////////
/**
* @param {Integer|null} libraryID Library to select, or null for local library
* @param {Integer} libraryID Library to select
*/
Zotero.CollectionTreeView.prototype.selectLibrary = function (libraryID) {
if (Zotero.suppressUIUpdates) {
@ -884,7 +883,6 @@ Zotero.CollectionTreeView.prototype._expandRow = function (row, forceOpen) {
var isCollection = itemGroup.isCollection();
var level = this.getLevel(row);
var libraryID = itemGroup.ref.libraryID;
var intLibraryID = libraryID ? libraryID : 0;
if (isGroup) {
var group = Zotero.Groups.getByLibraryID(libraryID);
@ -897,8 +895,8 @@ Zotero.CollectionTreeView.prototype._expandRow = function (row, forceOpen) {
if (isLibrary) {
var savedSearches = Zotero.Searches.getAll(libraryID);
var showDuplicates = (this.hideSources.indexOf('duplicates') == -1
&& this._duplicateLibraries.indexOf(intLibraryID) != -1);
var showUnfiled = this._unfiledLibraries.indexOf(intLibraryID) != -1;
&& this._duplicateLibraries.indexOf(libraryID) != -1);
var showUnfiled = this._unfiledLibraries.indexOf(libraryID) != -1;
var showTrash = this.hideSources.indexOf('trash') == -1;
}
else {
@ -959,7 +957,7 @@ Zotero.CollectionTreeView.prototype._expandRow = function (row, forceOpen) {
// Duplicate items
if (showDuplicates) {
var d = new Zotero.Duplicates(intLibraryID);
var d = new Zotero.Duplicates(libraryID);
this._showRow(new Zotero.ItemGroup('duplicates', d), level + 1, row + 1 + newRows);
newRows++;
}
@ -967,9 +965,7 @@ Zotero.CollectionTreeView.prototype._expandRow = function (row, forceOpen) {
// Unfiled items
if (showUnfiled) {
var s = new Zotero.Search;
if (isGroup) {
s.libraryID = libraryID;
}
s.libraryID = libraryID;
s.name = Zotero.getString('pane.collections.unfiled');
s.addCondition('libraryID', 'is', libraryID);
s.addCondition('unfiled', 'true');
@ -986,7 +982,7 @@ Zotero.CollectionTreeView.prototype._expandRow = function (row, forceOpen) {
this._showRow(new Zotero.ItemGroup('trash', ref), level + 1, row + 1 + newRows);
newRows++;
}
this._trashNotEmpty[intLibraryID] = !!deletedItems.length;
this._trashNotEmpty[libraryID] = !!deletedItems.length;
}
return newRows;
@ -1071,12 +1067,12 @@ Zotero.CollectionTreeView.prototype.rememberSelection = function(selection)
/**
* Returns libraryID, null for personal library, or false if not a library
* Returns libraryID or FALSE if not a library
*/
Zotero.CollectionTreeView.prototype.getSelectedLibraryID = function() {
var itemGroup = this._getItemAtRow(this.selection.currentIndex);
return itemGroup && itemGroup.ref && itemGroup.ref.libraryID !== undefined
&& (itemGroup.ref.libraryID ? itemGroup.ref.libraryID : null);
&& itemGroup.ref.libraryID;
}
@ -1550,7 +1546,7 @@ Zotero.CollectionTreeView.prototype.drop = function(row, orient, dataTransfer)
}
var targetLibraryID = itemGroup.isWithinGroup() ? itemGroup.ref.libraryID : null;
var targetLibraryID = itemGroup.ref.libraryID;
var targetCollectionID = itemGroup.isCollection() ? itemGroup.ref.id : false;
if (dataType == 'zotero/collection') {
@ -1741,12 +1737,7 @@ Zotero.CollectionTreeView.prototype.drop = function(row, orient, dataTransfer)
Zotero.DB.commitTransaction();
}
else if (dataType == 'text/x-moz-url' || dataType == 'application/x-moz-file') {
if (itemGroup.isWithinGroup()) {
var targetLibraryID = itemGroup.ref.libraryID;
}
else {
var targetLibraryID = null;
}
var targetLibraryID = itemGroup.ref.libraryID;
if (itemGroup.isCollection()) {
var parentCollectionID = itemGroup.ref.id;
@ -1915,13 +1906,13 @@ Zotero.ItemGroup.prototype.__defineGetter__('id', function () {
return 'S' + this.ref.id;
case 'duplicates':
return 'D' + (this.ref.libraryID ? this.ref.libraryID : 0);
return 'D' + this.ref.libraryID;
case 'unfiled':
return 'U' + (this.ref.libraryID ? this.ref.libraryID : 0);
return 'U' + this.ref.libraryID;
case 'trash':
return 'T' + (this.ref.libraryID ? this.ref.libraryID : 0);
return 'T' + this.ref.libraryID;
case 'header':
if (this.ref.id == 'group-libraries-header') {
@ -2156,12 +2147,8 @@ Zotero.ItemGroup.prototype.getSearchObject = function() {
}
else {
var s = new Zotero.Search();
if (this.isLibrary()) {
s.addCondition('libraryID', 'is', null);
s.addCondition('noChildren', 'true');
includeScopeChildren = true;
}
else if (this.isGroup()) {
// Library root
if (this.isLibrary(true)) {
s.addCondition('libraryID', 'is', this.ref.libraryID);
s.addCondition('noChildren', 'true');
includeScopeChildren = true;

View file

@ -101,6 +101,10 @@ Zotero.Collection.prototype._set = function (field, val) {
case 'id':
case 'libraryID':
case 'key':
if (field == 'libraryID') {
val = Zotero.DataObjectUtilities.checkLibraryID(val);
}
if (val == this['_' + field]) {
return;
}
@ -108,7 +112,9 @@ Zotero.Collection.prototype._set = function (field, val) {
if (this._loaded) {
throw ("Cannot set " + field + " after object is already loaded in Zotero.Collection._set()");
}
//this._checkValue(field, val);
this['_' + field] = val;
return;
@ -183,15 +189,8 @@ Zotero.Collection.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 data = Zotero.DB.rowQuery(sql, params);
@ -434,12 +433,12 @@ Zotero.Collection.prototype.save = function () {
this._changed.dateModified ?
this.dateModified : Zotero.DB.transactionDateTime,
Zotero.DB.transactionDateTime,
this.libraryID ? this.libraryID : null,
this.libraryID ? this.libraryID : 0,
key
];
var sql = "REPLACE INTO collections (" + columns.join(', ') + ") VALUES ("
+ placeholders.join(', ') + ")";
var sql = "REPLACE INTO collections (" + columns.join(', ') + ") "
+ "VALUES (" + placeholders + ")";
var insertID = Zotero.DB.query(sql, sqlValues);
if (!collectionID) {
collectionID = insertID;
@ -1192,7 +1191,7 @@ Zotero.Collection.prototype.addLinkedCollection = function (collection) {
// If both group libraries, store relation with source group.
// Otherwise, store with personal library.
var libraryID = (this.libraryID && collection.libraryID) ? this.libraryID : null;
var libraryID = (this.libraryID && collection.libraryID) ? this.libraryID : 0;
Zotero.Relations.add(libraryID, url1, predicate, url2);
}

View file

@ -89,6 +89,10 @@ Zotero.Creator.prototype._set = function (field, val) {
case 'id':
case 'libraryID':
case 'key':
if (field == 'libraryID') {
val = Zotero.DataObjectUtilities.checkLibraryID(val);
}
if (val == this['_' + field]) {
return;
}
@ -96,7 +100,9 @@ Zotero.Creator.prototype._set = function (field, val) {
if (this._loaded) {
throw ("Cannot set " + field + " after object is already loaded in Zotero.Creator._set()");
}
this._checkValue(field, val);
this['_' + field] = val;
return;
@ -241,7 +247,7 @@ Zotero.Creator.prototype.save = function () {
'libraryID',
'key'
];
var placeholders = ['?', '?', '?', '?', '?', '?', '?'];
var placeholders = columns.map(function () '?').join();
var sqlValues = [
creatorID ? { int: creatorID } : null,
{ int: creatorDataID },
@ -251,13 +257,13 @@ Zotero.Creator.prototype.save = function () {
this._changed.dateModified ?
this.dateModified : Zotero.DB.transactionDateTime,
Zotero.DB.transactionDateTime,
this.libraryID ? this.libraryID : null,
this.libraryID ? this.libraryID : 0,
key
];
if (isNew) {
var sql = "INSERT INTO creators (" + columns.join(', ') + ") VALUES ("
+ placeholders.join(', ') + ")";
var sql = "INSERT INTO creators (" + columns.join(', ') + ") "
+ "VALUES (" + placeholders + ")";
var insertID = Zotero.DB.query(sql, sqlValues);
if (!creatorID) {
creatorID = insertID;
@ -456,21 +462,14 @@ Zotero.Creator.prototype.load = function (allowFail) {
throw ("ID or key not set in Zotero.Creator.load()");
}
var sql = "SELECT C.*, CD.* FROM creators C NATURAL JOIN creatorData CD WHERE ";
var sql = "SELECT O.*, CD.* FROM creators O NATURAL JOIN creatorData CD WHERE ";
if (id) {
sql += "creatorID=?";
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);
@ -500,7 +499,7 @@ Zotero.Creator.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] : '';
@ -524,7 +523,7 @@ Zotero.Creator.prototype._checkValue = function (field, value) {
break;
case 'libraryID':
if (value && parseInt(value) != value) {
if (parseInt(value) != value) {
this._invalidValueError(field, value);
}
break;

View file

@ -122,26 +122,17 @@ Zotero.Creators = new function() {
function getCreatorsWithData(creatorDataID, libraryID) {
var sql = "SELECT creatorID FROM creators WHERE creatorDataID=?";
var params = [creatorDataID];
if (libraryID) {
if (libraryID !== undefined) {
sql += " AND libraryID=?";
params.push(libraryID);
return Zotero.DB.columnQuery(sql, [creatorDataID, libraryID])
}
else {
sql += " AND libraryID IS NULL";
}
return Zotero.DB.columnQuery(sql, params);
return Zotero.DB.columnQuery(sql, [creatorDataID]);
}
function countCreatorsWithData(creatorDataID, libraryID) {
var sql = "SELECT COUNT(*) FROM creators WHERE creatorDataID=?";
var params = [creatorDataID];
if (libraryID) {
sql += " AND libraryID=?";
params.push(libraryID);
}
return Zotero.DB.valueQuery(sql, params);
return Zotero.DB.valueQuery(sql, [creatorDataID]);
}

View file

@ -0,0 +1,51 @@
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2009 Center for History and New Media
George Mason University, Fairfax, Virginia, USA
http://zotero.org
This file is part of Zotero.
Zotero is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Zotero 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
***** 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]
}
};

View file

@ -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) {

View file

@ -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);
}

View file

@ -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();

View file

@ -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;
}

View file

@ -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;

View file

@ -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];
}

View file

@ -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);

View file

@ -29,7 +29,7 @@ Zotero.Duplicates = function (libraryID) {
}
if (!libraryID) {
libraryID = null;
libraryID = 0;
}
this._libraryID = libraryID;

View file

@ -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;

View file

@ -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<len; i++) {
let libraryIDInt = item.libraryIDInt; // TEMP
colorData.push(Zotero.Tags.getColor(libraryIDInt, tags[i].name));
colorData.push(Zotero.Tags.getColor(item.libraryID, tags[i].name));
}
var self = this;
Q.all(colorData)
@ -3014,7 +3012,7 @@ Zotero.ItemTreeView.prototype.drop = function(row, orient, dataTransfer) {
var dataType = dragData.dataType;
var data = dragData.data;
var itemGroup = this.itemGroup;
var targetLibraryID = itemGroup.isWithinGroup() ? itemGroup.ref.libraryID : null;
var targetLibraryID = itemGroup.ref.libraryID;
if (dataType == 'zotero/item') {
var ids = data;
@ -3102,12 +3100,7 @@ Zotero.ItemTreeView.prototype.drop = function(row, orient, dataTransfer) {
return;
}
if (itemGroup.isWithinGroup()) {
var targetLibraryID = itemGroup.ref.libraryID;
}
else {
var targetLibraryID = null;
}
var targetLibraryID = itemGroup.ref.libraryID;
var sourceItemID = false;
var parentCollectionID = false;

View file

@ -102,6 +102,10 @@ Zotero.Search.prototype._set = function (field, val) {
case 'id':
case 'libraryID':
case 'key':
if (field == 'libraryID') {
val = Zotero.DataObjectUtilities.checkLibraryID(val);
}
if (val == this['_' + field]) {
return;
}
@ -109,7 +113,9 @@ Zotero.Search.prototype._set = function (field, val) {
if (this._loaded) {
throw new Error("Cannot set " + field + " after object is already loaded");
}
//this._checkValue(field, val);
this['_' + field] = val;
return;
@ -176,15 +182,8 @@ Zotero.Search.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];
}
sql += " GROUP BY savedSearchID";
var data = Zotero.DB.rowQuery(sql, params);
@ -290,12 +289,12 @@ Zotero.Search.prototype.save = function(fixGaps) {
this._changed.dateModified ?
this.dateModified : Zotero.DB.transactionDateTime,
Zotero.DB.transactionDateTime,
this.libraryID ? this.libraryID : this.libraryID,
this.libraryID ? this.libraryID : 0,
key
];
var sql = "REPLACE INTO savedSearches (" + columns.join(', ') + ") VALUES ("
+ placeholders.join(', ') + ")";
var sql = "REPLACE INTO savedSearches (" + columns.join(', ') + ") "
+ "VALUES (" + placeholders + ")";
var insertID = Zotero.DB.query(sql, sqlValues);
if (!searchID) {
searchID = insertID;
@ -1720,21 +1719,13 @@ Zotero.Searches = new function(){
/**
* Returns an array of Zotero.Search objects, ordered by name
*
* @param {Integer|null} [libraryID=null]
* @param {Integer} [libraryID=0]
*/
this.getAll = function (libraryID) {
var sql = "SELECT savedSearchID AS id, savedSearchName AS name "
+ "FROM savedSearches WHERE libraryID";
if (libraryID) {
sql += "=?";
var params = [libraryID];
}
else {
sql += " IS NULL";
var params = null;
}
+ "FROM savedSearches WHERE libraryID=?";
sql += " ORDER BY name COLLATE NOCASE";
var rows = Zotero.DB.query(sql, params);
var rows = Zotero.DB.query(sql, [libraryID ? libraryID : 0]);
if (!rows) {
return [];
}

View file

@ -259,10 +259,7 @@ Zotero.Sync.Storage = new function () {
+ "WHERE libraryID=? AND syncState=?";
var downloadForced = !!Zotero.DB.valueQuery(
sql,
[
libraryID == 0 ? null : libraryID,
Zotero.Sync.Storage.SYNC_STATE_FORCE_DOWNLOAD
]
[libraryID, Zotero.Sync.Storage.SYNC_STATE_FORCE_DOWNLOAD]
);
// If we don't have any forced downloads, we can skip
@ -414,12 +411,11 @@ Zotero.Sync.Storage = new function () {
// Public methods
//
this.queueItem = function (item, highPriority) {
if (item.libraryID) {
var library = item.libraryID;
var library = item.libraryID;
if (libraryID) {
var mode = Zotero.Sync.Storage.ZFS;
}
else {
var library = 0;
var mode = Zotero.Sync.Storage.ZFS.includeUserFiles
? Zotero.Sync.Storage.ZFS : Zotero.Sync.Storage.WebDAV;
}
@ -451,7 +447,7 @@ Zotero.Sync.Storage = new function () {
var queue = Zotero.Sync.Storage.QueueManager.get(queue, library);
var request = new Zotero.Sync.Storage.Request(
(item.libraryID ? item.libraryID : 0) + '/' + item.key, callbacks
item.libraryID + '/' + item.key, callbacks
);
if (queue.type == 'upload') {
try {
@ -653,7 +649,7 @@ Zotero.Sync.Storage = new function () {
/**
* @param {NULL|Integer|'groups'} [libraryID]
* @param {Integer|'groups'} [libraryID]
*/
this.downloadAsNeeded = function (libraryID) {
// Personal library
@ -668,7 +664,7 @@ Zotero.Sync.Storage = new function () {
/**
* @param {NULL|Integer|'groups'} [libraryID]
* @param {Integer|'groups'} [libraryID]
*/
this.downloadOnSync = function (libraryID) {
// Personal library
@ -768,7 +764,7 @@ Zotero.Sync.Storage = new function () {
);
if (libraryID !== false) {
sql += " AND libraryID=?";
params.push(libraryID == 0 ? null : libraryID);
params.push(libraryID);
}
if (chunk.length) {
sql += " AND itemID IN (" + chunk.map(function () '?').join() + ")";
@ -1018,10 +1014,6 @@ Zotero.Sync.Storage = new function () {
.then(function () {
// TODO: start sync icon
var library = item.libraryID;
if (!library) {
library = 0;
}
var queue = Zotero.Sync.Storage.QueueManager.get(
'download', library
);
@ -1201,7 +1193,7 @@ Zotero.Sync.Storage = new function () {
this.getItemDownloadImageNumber = function (item) {
var numImages = 64;
var lk = (item.libraryID ? item.libraryID : 0) + "/" + item.key;
var lk = item.libraryID + "/" + item.key;
if (typeof _itemDownloadPercentages[lk] == 'undefined') {
return false;
@ -1267,10 +1259,10 @@ Zotero.Sync.Storage = new function () {
//var sql = "UPDATE itemAttachments SET syncState=?, storageModTime=NULL, storageHash=NULL";
var sql = "UPDATE itemAttachments SET syncState=?";
if (includeUserFiles && !includeGroupFiles) {
sql += " WHERE itemID IN (SELECT itemID FROM items WHERE libraryID IS NULL)";
sql += " WHERE itemID IN (SELECT itemID FROM items WHERE libraryID = 0)";
}
else if (!includeUserFiles && includeGroupFiles) {
sql += " WHERE itemID IN (SELECT itemID FROM items WHERE libraryID IS NOT NULL)";
sql += " WHERE itemID IN (SELECT itemID FROM items WHERE libraryID != 0)";
}
Zotero.DB.query(sql, [syncState]);
@ -1880,10 +1872,7 @@ Zotero.Sync.Storage = new function () {
function _getFilesToDownload(libraryID, forcedOnly) {
var sql = "SELECT itemID FROM itemAttachments JOIN items USING (itemID) "
+ "WHERE libraryID=? AND syncState IN (?";
var params = [
libraryID == 0 ? null : libraryID,
Zotero.Sync.Storage.SYNC_STATE_FORCE_DOWNLOAD
];
var params = [libraryID, Zotero.Sync.Storage.SYNC_STATE_FORCE_DOWNLOAD];
if (!forcedOnly) {
sql += ",?";
params.push(Zotero.Sync.Storage.SYNC_STATE_TO_DOWNLOAD);
@ -1916,7 +1905,7 @@ Zotero.Sync.Storage = new function () {
];
if (typeof libraryID != 'undefined') {
sql += " AND libraryID=?";
params.push(libraryID == 0 ? null : libraryID);
params.push(libraryID);
}
else {
throw new Error("libraryID not specified");
@ -1943,7 +1932,7 @@ Zotero.Sync.Storage = new function () {
+ "WHERE libraryID=? AND linkMode IN (?,?) AND syncState IN (?) AND "
+ "storageModTime>=?";
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,

View file

@ -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

View file

@ -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) {

View file

@ -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;
}
//

View file

@ -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;

View file

@ -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);

View file

@ -61,6 +61,7 @@ const xpcomFilesLocal = [
'cookieSandbox',
'data_access',
'data/dataObjects',
'data/dataObjectUtilities',
'data/cachedTypes',
'data/item',
'data/items',