www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 9c7f33e21a4480921f29e1b6436bc904adf0f924
parent 957b220cd3cc0d04d9ac5fdd44ed8e73b1725aaa
Author: Dan Stillman <dstillman@zotero.org>
Date:   Fri, 11 Aug 2006 05:15:56 +0000

Extended itemCreators primary key to include orderIndex and removed artificial restriction on adding the same creator/creatorType more than once for the same source -- who knows, maybe they just have the same name...

Properly ignore firstName for institutional creators in Item.setCreator() and Item.creatorExists() (which is now unused)


Diffstat:
Mchrome/chromeFiles/content/scholar/xpcom/data_access.js | 73++++++++++++++++++++++++++-----------------------------------------------
Mchrome/chromeFiles/content/scholar/xpcom/schema.js | 4++--
Mschema.sql | 4++--
3 files changed, 30 insertions(+), 51 deletions(-)

diff --git a/chrome/chromeFiles/content/scholar/xpcom/data_access.js b/chrome/chromeFiles/content/scholar/xpcom/data_access.js @@ -228,7 +228,7 @@ Scholar.Item.prototype.setCreator = function(orderIndex, firstName, lastName, cr this._loadCreators(); } - if (!firstName){ + if (isInstitution || !firstName){ firstName = ''; } @@ -287,11 +287,23 @@ Scholar.Item.prototype.removeCreator = function(orderIndex){ } +// Currently unused Scholar.Item.prototype.creatorExists = function(firstName, lastName, creatorTypeID, isInstitution, skipIndex){ + if (isInstitution || !firstName){ + firstName = ''; + } + + if (!lastName){ + lastName = ''; + } + + isInstitution = !!isInstitution; + for (var j=0, len=this.numCreators(); j<len; j++){ if (typeof skipIndex!='undefined' && skipIndex==j){ continue; } + var creator2 = this.getCreator(j); if (firstName==creator2['firstName'] && @@ -441,16 +453,6 @@ Scholar.Item.prototype.save = function(){ // Creators // if (this._changedCreators.length){ - for (var i=0, len=this.numCreators(); i<len; i++){ - var creator = this.getCreator(i); - if (this.creatorExists(creator['firstName'], - creator['lastName'], creator['creatorTypeID'], - creator['isInstitution'], i)){ - throw('Cannot add duplicate creator/creatorType ' - + 'to item ' + this.getID()); - } - } - for (orderIndex in this._changedCreators.items){ Scholar.debug('Creator ' + orderIndex + ' has changed', 4); @@ -492,44 +494,21 @@ Scholar.Item.prototype.save = function(){ + ' WHERE itemID=' + this.getID() + ' AND creatorID=' + creatorID + ' AND creatorTypeID=' + creator['creatorTypeID']; - - // If this creator and creatorType exists elsewhere, move it - if (Scholar.DB.valueQuery(sql2)){ - Scholar.History.modify('itemCreators', - 'itemID-creatorID-creatorTypeID', - [this.getID(), creatorID, creator['creatorTypeID']]); - - sql = 'UPDATE itemCreators SET orderIndex=? ' - + "WHERE itemID=? AND creatorID=? AND " - + "creatorTypeID=?"; - - sqlValues = [ - {'int':orderIndex}, - {'int':this.getID()}, - {'int':creatorID}, - {'int':creator['creatorTypeID']} - ]; - Scholar.DB.query(sql, sqlValues); - } + sql = "INSERT INTO itemCreators VALUES (?,?,?,?)"; - // Otherwise insert - else { - sql = "INSERT INTO itemCreators VALUES (?,?,?,?)"; - - sqlValues = [ - {'int':itemID}, - {'int':creatorID}, - {'int':creator['creatorTypeID']}, - {'int':orderIndex} - ]; - - Scholar.DB.query(sql, sqlValues); - - Scholar.History.add('itemCreators', - 'itemID-creatorID-creatorTypeID', - [this.getID(), creatorID, creator['creatorTypeID']]); - } + sqlValues = [ + {'int':itemID}, + {'int':creatorID}, + {'int':creator['creatorTypeID']}, + {'int':orderIndex} + ]; + + Scholar.DB.query(sql, sqlValues); + + Scholar.History.add('itemCreators', + 'itemID-creatorID-creatorTypeID', + [this.getID(), creatorID, creator['creatorTypeID']]); } // Delete obsolete creators diff --git a/chrome/chromeFiles/content/scholar/xpcom/schema.js b/chrome/chromeFiles/content/scholar/xpcom/schema.js @@ -391,7 +391,7 @@ Scholar.Schema = new function(){ // // Change this value to match the schema version // - var toVersion = 37; + var toVersion = 38; if (toVersion != _getSchemaSQLVersion()){ throw('Schema version does not match version in _migrateSchema()'); @@ -415,7 +415,7 @@ Scholar.Schema = new function(){ } } - if (i==37){ + if (i==38){ _initializeSchema(); } } diff --git a/schema.sql b/schema.sql @@ -1,4 +1,4 @@ --- 37 +-- 38 DROP TABLE IF EXISTS version; CREATE TABLE version ( @@ -180,7 +180,7 @@ creatorID INT, creatorTypeID INT DEFAULT 1, orderIndex INT DEFAULT 0, - PRIMARY KEY (itemID, creatorID, creatorTypeID), + PRIMARY KEY (itemID, creatorID, creatorTypeID, orderIndex), FOREIGN KEY (itemID) REFERENCES items(itemID), FOREIGN KEY (creatorID) REFERENCES creators(creatorID) FOREIGN KEY (creatorTypeID) REFERENCES creatorTypes(creatorTypeID)