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:
parent
957b220cd3
commit
9c7f33e21a
|
@ -228,7 +228,7 @@ Scholar.Item.prototype.setCreator = function(orderIndex, firstName, lastName, cr
|
||||||
this._loadCreators();
|
this._loadCreators();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!firstName){
|
if (isInstitution || !firstName){
|
||||||
firstName = '';
|
firstName = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,11 +287,23 @@ Scholar.Item.prototype.removeCreator = function(orderIndex){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Currently unused
|
||||||
Scholar.Item.prototype.creatorExists = function(firstName, lastName, creatorTypeID, isInstitution, skipIndex){
|
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++){
|
for (var j=0, len=this.numCreators(); j<len; j++){
|
||||||
if (typeof skipIndex!='undefined' && skipIndex==j){
|
if (typeof skipIndex!='undefined' && skipIndex==j){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var creator2 = this.getCreator(j);
|
var creator2 = this.getCreator(j);
|
||||||
|
|
||||||
if (firstName==creator2['firstName'] &&
|
if (firstName==creator2['firstName'] &&
|
||||||
|
@ -441,16 +453,6 @@ Scholar.Item.prototype.save = function(){
|
||||||
// Creators
|
// Creators
|
||||||
//
|
//
|
||||||
if (this._changedCreators.length){
|
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){
|
for (orderIndex in this._changedCreators.items){
|
||||||
Scholar.debug('Creator ' + orderIndex + ' has changed', 4);
|
Scholar.debug('Creator ' + orderIndex + ' has changed', 4);
|
||||||
|
|
||||||
|
@ -493,43 +495,20 @@ Scholar.Item.prototype.save = function(){
|
||||||
+ ' AND creatorID=' + creatorID
|
+ ' AND creatorID=' + creatorID
|
||||||
+ ' AND creatorTypeID=' + creator['creatorTypeID'];
|
+ ' AND creatorTypeID=' + creator['creatorTypeID'];
|
||||||
|
|
||||||
// If this creator and creatorType exists elsewhere, move it
|
sql = "INSERT INTO itemCreators VALUES (?,?,?,?)";
|
||||||
if (Scholar.DB.valueQuery(sql2)){
|
|
||||||
Scholar.History.modify('itemCreators',
|
|
||||||
'itemID-creatorID-creatorTypeID',
|
|
||||||
[this.getID(), creatorID, creator['creatorTypeID']]);
|
|
||||||
|
|
||||||
sql = 'UPDATE itemCreators SET orderIndex=? '
|
sqlValues = [
|
||||||
+ "WHERE itemID=? AND creatorID=? AND "
|
{'int':itemID},
|
||||||
+ "creatorTypeID=?";
|
{'int':creatorID},
|
||||||
|
{'int':creator['creatorTypeID']},
|
||||||
|
{'int':orderIndex}
|
||||||
|
];
|
||||||
|
|
||||||
sqlValues = [
|
Scholar.DB.query(sql, sqlValues);
|
||||||
{'int':orderIndex},
|
|
||||||
{'int':this.getID()},
|
|
||||||
{'int':creatorID},
|
|
||||||
{'int':creator['creatorTypeID']}
|
|
||||||
];
|
|
||||||
|
|
||||||
Scholar.DB.query(sql, sqlValues);
|
Scholar.History.add('itemCreators',
|
||||||
}
|
'itemID-creatorID-creatorTypeID',
|
||||||
|
[this.getID(), creatorID, creator['creatorTypeID']]);
|
||||||
// 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']]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete obsolete creators
|
// Delete obsolete creators
|
||||||
|
|
|
@ -391,7 +391,7 @@ Scholar.Schema = new function(){
|
||||||
//
|
//
|
||||||
// Change this value to match the schema version
|
// Change this value to match the schema version
|
||||||
//
|
//
|
||||||
var toVersion = 37;
|
var toVersion = 38;
|
||||||
|
|
||||||
if (toVersion != _getSchemaSQLVersion()){
|
if (toVersion != _getSchemaSQLVersion()){
|
||||||
throw('Schema version does not match version in _migrateSchema()');
|
throw('Schema version does not match version in _migrateSchema()');
|
||||||
|
@ -415,7 +415,7 @@ Scholar.Schema = new function(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i==37){
|
if (i==38){
|
||||||
_initializeSchema();
|
_initializeSchema();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
-- 37
|
-- 38
|
||||||
|
|
||||||
DROP TABLE IF EXISTS version;
|
DROP TABLE IF EXISTS version;
|
||||||
CREATE TABLE version (
|
CREATE TABLE version (
|
||||||
|
@ -180,7 +180,7 @@
|
||||||
creatorID INT,
|
creatorID INT,
|
||||||
creatorTypeID INT DEFAULT 1,
|
creatorTypeID INT DEFAULT 1,
|
||||||
orderIndex INT DEFAULT 0,
|
orderIndex INT DEFAULT 0,
|
||||||
PRIMARY KEY (itemID, creatorID, creatorTypeID),
|
PRIMARY KEY (itemID, creatorID, creatorTypeID, orderIndex),
|
||||||
FOREIGN KEY (itemID) REFERENCES items(itemID),
|
FOREIGN KEY (itemID) REFERENCES items(itemID),
|
||||||
FOREIGN KEY (creatorID) REFERENCES creators(creatorID)
|
FOREIGN KEY (creatorID) REFERENCES creators(creatorID)
|
||||||
FOREIGN KEY (creatorTypeID) REFERENCES creatorTypes(creatorTypeID)
|
FOREIGN KEY (creatorTypeID) REFERENCES creatorTypes(creatorTypeID)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user