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)
This commit is contained in:
Dan Stillman 2006-08-11 05:15:56 +00:00
parent 957b220cd3
commit 9c7f33e21a
3 changed files with 30 additions and 51 deletions

View file

@ -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'];
sql = "INSERT INTO itemCreators VALUES (?,?,?,?)";
// 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);
}
sqlValues = [
{'int':itemID},
{'int':creatorID},
{'int':creator['creatorTypeID']},
{'int':orderIndex}
];
// 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']]);
}
Scholar.DB.query(sql, sqlValues);
Scholar.History.add('itemCreators',
'itemID-creatorID-creatorTypeID',
[this.getID(), creatorID, creator['creatorTypeID']]);
}
// Delete obsolete creators

View file

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

View file

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