Closes #340, Change isInstitution to fieldMode everywhere

Including in the DB, which it turns out isn't really all that bad (thanks, among other things, to SQLite's ability to DROP tables within transactions without autocommitting (which MySQL can't do))
This commit is contained in:
Dan Stillman 2006-10-05 00:59:26 +00:00
parent 74dbdec49b
commit cd26267afe
7 changed files with 50 additions and 50 deletions

View file

@ -247,7 +247,7 @@ var ZoteroItemPane = new function()
for(var i = 0, len=_itemBeingEdited.numCreators(); i<len; i++) for(var i = 0, len=_itemBeingEdited.numCreators(); i<len; i++)
{ {
var creator = _itemBeingEdited.getCreator(i); var creator = _itemBeingEdited.getCreator(i);
addCreatorRow(creator['firstName'], creator['lastName'], creator['creatorTypeID'], creator['isInstitution']); addCreatorRow(creator['firstName'], creator['lastName'], creator['creatorTypeID'], creator['fieldMode']);
} }
} }
else else
@ -1108,7 +1108,7 @@ var ZoteroItemPane = new function()
var firstName = creator['firstName']; var firstName = creator['firstName'];
var lastName = creator['lastName']; var lastName = creator['lastName'];
var typeID = creator['creatorTypeID']; var typeID = creator['creatorTypeID'];
var singleField = creator['isInstitution']; var singleField = creator['singleField'];
} }
// Don't save empty creators // Don't save empty creators

View file

@ -255,12 +255,12 @@ Zotero.Item.prototype.getCreators = function(){
/* /*
* Set or update the creator at the specified position * Set or update the creator at the specified position
*/ */
Zotero.Item.prototype.setCreator = function(orderIndex, firstName, lastName, creatorTypeID, isInstitution){ Zotero.Item.prototype.setCreator = function(orderIndex, firstName, lastName, creatorTypeID, fieldMode){
if (this.getID() && !this._creatorsLoaded){ if (this.getID() && !this._creatorsLoaded){
this._loadCreators(); this._loadCreators();
} }
if (isInstitution || !firstName){ if (fieldMode==1 || !firstName){
firstName = ''; firstName = '';
} }
@ -268,14 +268,12 @@ Zotero.Item.prototype.setCreator = function(orderIndex, firstName, lastName, cre
lastName = ''; lastName = '';
} }
isInstitution = !!isInstitution;
// If creator at this position hasn't changed, cancel // If creator at this position hasn't changed, cancel
if (this._creators.has(orderIndex) && if (this._creators.has(orderIndex) &&
this._creators.get(orderIndex)['firstName']==firstName && this._creators.get(orderIndex)['firstName']==firstName &&
this._creators.get(orderIndex)['lastName']==lastName && this._creators.get(orderIndex)['lastName']==lastName &&
this._creators.get(orderIndex)['creatorTypeID']==creatorTypeID && this._creators.get(orderIndex)['creatorTypeID']==creatorTypeID &&
this._creators.get(orderIndex)['isInstitution']==isInstitution){ this._creators.get(orderIndex)['fieldMode']==fieldMode){
return false; return false;
} }
@ -287,7 +285,7 @@ Zotero.Item.prototype.setCreator = function(orderIndex, firstName, lastName, cre
creator['firstName'] = firstName; creator['firstName'] = firstName;
creator['lastName'] = lastName; creator['lastName'] = lastName;
creator['creatorTypeID'] = creatorTypeID; creator['creatorTypeID'] = creatorTypeID;
creator['isInstitution'] = isInstitution; creator['fieldMode'] = fieldMode;
this._creators.set(orderIndex, creator); this._creators.set(orderIndex, creator);
this._changedCreators.set(orderIndex); this._changedCreators.set(orderIndex);
@ -320,8 +318,8 @@ Zotero.Item.prototype.removeCreator = function(orderIndex){
// Currently unused // Currently unused
Zotero.Item.prototype.creatorExists = function(firstName, lastName, creatorTypeID, isInstitution, skipIndex){ Zotero.Item.prototype.creatorExists = function(firstName, lastName, creatorTypeID, fieldMode, skipIndex){
if (isInstitution || !firstName){ if (fieldMode==1 || !firstName){
firstName = ''; firstName = '';
} }
@ -329,8 +327,6 @@ Zotero.Item.prototype.creatorExists = function(firstName, lastName, creatorTypeI
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;
@ -341,7 +337,7 @@ Zotero.Item.prototype.creatorExists = function(firstName, lastName, creatorTypeI
if (firstName==creator2['firstName'] && if (firstName==creator2['firstName'] &&
lastName==creator2['lastName'] && lastName==creator2['lastName'] &&
creatorTypeID==creator2['creatorTypeID'] && creatorTypeID==creator2['creatorTypeID'] &&
isInstitution==creator2['isInstitution']){ fieldMode==creator2['fieldMode']){
return true; return true;
} }
} }
@ -513,7 +509,7 @@ Zotero.Item.prototype.save = function(){
var creatorID = Zotero.Creators.getID( var creatorID = Zotero.Creators.getID(
creator['firstName'], creator['firstName'],
creator['lastName'], creator['lastName'],
creator['isInstitution'] creator['fieldMode']
); );
// If not, add it // If not, add it
@ -521,17 +517,11 @@ Zotero.Item.prototype.save = function(){
creatorID = Zotero.Creators.add( creatorID = Zotero.Creators.add(
creator['firstName'], creator['firstName'],
creator['lastName'], creator['lastName'],
creator['isInstitution'] creator['fieldMode']
); );
Zotero.History.add('creators', 'creatorID', creatorID); Zotero.History.add('creators', 'creatorID', creatorID);
} }
sql2 = 'SELECT COUNT(*) FROM itemCreators'
+ ' WHERE itemID=' + this.getID()
+ ' AND creatorID=' + creatorID
+ ' AND creatorTypeID=' + creator['creatorTypeID'];
sql = "INSERT INTO itemCreators VALUES (?,?,?,?)"; sql = "INSERT INTO itemCreators VALUES (?,?,?,?)";
sqlValues = [ sqlValues = [
@ -786,7 +776,7 @@ Zotero.Item.prototype.save = function(){
var creatorID = Zotero.Creators.getID( var creatorID = Zotero.Creators.getID(
creator['firstName'], creator['firstName'],
creator['lastName'], creator['lastName'],
creator['isInstitution'] creator['fieldMode']
); );
// If not, add it // If not, add it
@ -794,7 +784,7 @@ Zotero.Item.prototype.save = function(){
creatorID = Zotero.Creators.add( creatorID = Zotero.Creators.add(
creator['firstName'], creator['firstName'],
creator['lastName'], creator['lastName'],
creator['isInstitution'] creator['fieldMode']
); );
Zotero.History.add('creators', 'creatorID', creatorID); Zotero.History.add('creators', 'creatorID', creatorID);
} }
@ -1622,7 +1612,7 @@ Zotero.Item.prototype.toArray = function(){
arr['creators'][i] = []; arr['creators'][i] = [];
arr['creators'][i]['firstName'] = creators[i]['firstName']; arr['creators'][i]['firstName'] = creators[i]['firstName'];
arr['creators'][i]['lastName'] = creators[i]['lastName']; arr['creators'][i]['lastName'] = creators[i]['lastName'];
arr['creators'][i]['isInstitution'] = creators[i]['isInstitution']; arr['creators'][i]['fieldMode'] = creators[i]['fieldMode'];
// Convert creatorTypeIDs to text // Convert creatorTypeIDs to text
arr['creators'][i]['creatorType'] = arr['creators'][i]['creatorType'] =
Zotero.CreatorTypes.getName(creators[i]['creatorTypeID']); Zotero.CreatorTypes.getName(creators[i]['creatorTypeID']);
@ -1706,7 +1696,7 @@ Zotero.Item.prototype._loadCreators = function(){
var creator = new Array(); var creator = new Array();
creator['firstName'] = creators[i]['firstName']; creator['firstName'] = creators[i]['firstName'];
creator['lastName'] = creators[i]['lastName']; creator['lastName'] = creators[i]['lastName'];
creator['isInstitution'] = creators[i]['isInstitution']; creator['fieldMode'] = creators[i]['fieldMode'];
creator['creatorTypeID'] = creators[i]['creatorTypeID']; creator['creatorTypeID'] = creators[i]['creatorTypeID'];
// Save creator data into Hash, indexed by orderIndex // Save creator data into Hash, indexed by orderIndex
this._creators.set(creators[i]['orderIndex'], creator); this._creators.set(creators[i]['orderIndex'], creator);
@ -2557,7 +2547,7 @@ Zotero.Collections = new function(){
* Same structure as Zotero.Tags -- make changes in both places if possible * Same structure as Zotero.Tags -- make changes in both places if possible
*/ */
Zotero.Creators = new function(){ Zotero.Creators = new function(){
var _creators = new Array; // indexed by first%%%last%%%isInstitution hash var _creators = new Array; // indexed by first%%%last%%%fieldMode hash
var _creatorsByID = new Array; // indexed by creatorID var _creatorsByID = new Array; // indexed by creatorID
this.get = get; this.get = get;
@ -2590,7 +2580,7 @@ Zotero.Creators = new function(){
/* /*
* Returns the creatorID matching given name and type * Returns the creatorID matching given name and type
*/ */
function getID(firstName, lastName, isInstitution){ function getID(firstName, lastName, fieldMode){
if (!firstName){ if (!firstName){
firstName = ''; firstName = '';
} }
@ -2598,23 +2588,24 @@ Zotero.Creators = new function(){
lastName = ''; lastName = '';
} }
if (isInstitution){ // Only two modes for now
if (fieldMode){
firstName = ''; firstName = '';
isInstitution = 1; fieldMode = 1;
} }
else { else {
isInstitution = 0; fieldMode = 0;
} }
var hash = firstName + '%%%' + lastName + '%%%' + isInstitution; var hash = firstName + '%%%' + lastName + '%%%' + fieldMode;
if (_creators[hash]){ if (_creators[hash]){
return _creators[hash]; return _creators[hash];
} }
var sql = 'SELECT creatorID FROM creators ' var sql = 'SELECT creatorID FROM creators '
+ 'WHERE firstName=? AND lastName=? AND isInstitution=?'; + 'WHERE firstName=? AND lastName=? AND fieldMode=?';
var params = [{string: firstName}, {string: lastName}, isInstitution]; var params = [{string: firstName}, {string: lastName}, fieldMode];
var creatorID = Zotero.DB.valueQuery(sql, params); var creatorID = Zotero.DB.valueQuery(sql, params);
if (creatorID){ if (creatorID){
@ -2630,7 +2621,7 @@ Zotero.Creators = new function(){
* *
* Returns new creatorID * Returns new creatorID
*/ */
function add(firstName, lastName, isInstitution){ function add(firstName, lastName, fieldMode){
Zotero.debug('Adding new creator', 4); Zotero.debug('Adding new creator', 4);
Zotero.DB.beginTransaction(); Zotero.DB.beginTransaction();
@ -2638,8 +2629,8 @@ Zotero.Creators = new function(){
var sql = 'INSERT INTO creators VALUES (?,?,?,?)'; var sql = 'INSERT INTO creators VALUES (?,?,?,?)';
var rnd = Zotero.getRandomID('creators', 'creatorID'); var rnd = Zotero.getRandomID('creators', 'creatorID');
var params = [ var params = [
rnd, isInstitution ? '' : {string: firstName}, {string: lastName}, rnd, fieldMode ? '' : {string: firstName}, {string: lastName},
isInstitution ? 1 : 0 fieldMode ? 1 : 0
]; ];
Zotero.DB.query(sql, params); Zotero.DB.query(sql, params);
@ -2683,7 +2674,7 @@ Zotero.Creators = new function(){
return false; return false;
} }
return creator['firstName'] + '%%%' + creator['lastName'] + '%%%' + return creator['firstName'] + '%%%' + creator['lastName'] + '%%%' +
creator['isInstitution']; creator['fieldMode'];
} }
} }

View file

@ -471,7 +471,7 @@ Zotero.OpenURL = new function() {
} else if(key == "rft.au") { } else if(key == "rft.au") {
item.creators.push(Zotero.Utilities.prototype.cleanAuthor(value, "author", true)); item.creators.push(Zotero.Utilities.prototype.cleanAuthor(value, "author", true));
} else if(key == "rft.aucorp") { } else if(key == "rft.aucorp") {
item.creators.push({lastName:value, isInstitution:true}); item.creators.push({lastName:value, fieldMode:true});
} else if(key == "rft.isbn" && !item.ISBN) { } else if(key == "rft.isbn" && !item.ISBN) {
item.ISBN = value; item.ISBN = value;
} else if(key == "rft.pub") { } else if(key == "rft.pub") {

View file

@ -525,6 +525,15 @@ Zotero.Schema = new function(){
Zotero.DB.query("UPDATE itemAttachments SET path=NULL WHERE linkMode=3"); Zotero.DB.query("UPDATE itemAttachments SET path=NULL WHERE linkMode=3");
try { Zotero.DB.query("DELETE FROM fulltextItems WHERE itemID IS NULL"); } catch(e){} try { Zotero.DB.query("DELETE FROM fulltextItems WHERE itemID IS NULL"); } catch(e){}
} }
if (i==6){
Zotero.DB.query("CREATE TABLE creatorsTemp (creatorID INT, firstName INT, lastName INT, fieldMode INT)");
Zotero.DB.query("INSERT INTO creatorsTemp SELECT * FROM creators");
Zotero.DB.query("DROP TABLE creators");
Zotero.DB.query("CREATE TABLE creators (\n creatorID INT,\n firstName INT,\n lastName INT,\n fieldMode INT,\n PRIMARY KEY (creatorID)\n);");
Zotero.DB.query("INSERT INTO creators SELECT * FROM creatorsTemp");
Zotero.DB.query("DROP TABLE creatorsTemp");
}
} }
_updateSchema('userdata'); _updateSchema('userdata');

View file

@ -150,9 +150,9 @@ ZoteroAutoComplete.prototype.startSearch = function(searchString, searchParam,
if (fieldMode==2) if (fieldMode==2)
{ {
var sql = "SELECT DISTINCT CASE isInstitution WHEN 1 THEN lastName " var sql = "SELECT DISTINCT CASE fieldMode WHEN 1 THEN lastName "
+ "WHEN 0 THEN firstName || ' ' || lastName END AS name " + "WHEN 0 THEN firstName || ' ' || lastName END AS name "
+ "FROM creators WHERE CASE isInstitution " + "FROM creators WHERE CASE fieldMode "
+ "WHEN 1 THEN lastName " + "WHEN 1 THEN lastName "
+ "WHEN 0 THEN firstName || ' ' || lastName END " + "WHEN 0 THEN firstName || ' ' || lastName END "
+ "LIKE ? ORDER BY name"; + "LIKE ? ORDER BY name";
@ -181,7 +181,7 @@ ZoteroAutoComplete.prototype.startSearch = function(searchString, searchParam,
} }
var fromSQL = " FROM creators WHERE " + searchParts[2] var fromSQL = " FROM creators WHERE " + searchParts[2]
+ " LIKE ?1 " + "AND isInstitution=?2"; + " LIKE ?1 " + "AND fieldMode=?2";
var sqlParams = [searchString + '%', parseInt(fieldMode)]; var sqlParams = [searchString + '%', parseInt(fieldMode)];
if (itemID){ if (itemID){
fromSQL += " AND creatorID NOT IN (SELECT creatorID FROM " fromSQL += " AND creatorID NOT IN (SELECT creatorID FROM "

View file

@ -1,4 +1,4 @@
-- 97 -- 98
DROP TABLE IF EXISTS translators; DROP TABLE IF EXISTS translators;
CREATE TABLE translators ( CREATE TABLE translators (
@ -229,7 +229,7 @@ REPLACE INTO "translators" VALUES ('838d8849-4ffb-9f44-3d0d-aa8a0a079afe', '2006
for(var j=1; j<authors.length; j+=2) { for(var j=1; j<authors.length; j+=2) {
if(authors[j-1].substring(0, 1) != ''('' && !yearRegexp.test(authors[j])) { if(authors[j-1].substring(0, 1) != ''('' && !yearRegexp.test(authors[j])) {
// ignore places where there are parentheses // ignore places where there are parentheses
newItem.creators.push({lastName:authors[j], creatorType:"author", isInstitution:true}); newItem.creators.push({lastName:authors[j], creatorType:"author", fieldMode:true});
} }
} }
} else { } else {
@ -1073,7 +1073,7 @@ REPLACE INTO "translators" VALUES ('add7c71c-21f3-ee14-d188-caf9da12728b', '2006
} else if(field == "added author") { } else if(field == "added author") {
newItem.creators.push(Zotero.Utilities.cleanAuthor(value, "contributor", true)); newItem.creators.push(Zotero.Utilities.cleanAuthor(value, "contributor", true));
} else if(field == "corporate author") { } else if(field == "corporate author") {
newItem.creators.push({lastName:author, isInstitution:true}); newItem.creators.push({lastName:author, fieldMode:true});
} else if(field == "subject term" || field == "corporate subject" || field == "geographic term") { } else if(field == "subject term" || field == "corporate subject" || field == "geographic term") {
var subjects = value.split("--"); var subjects = value.split("--");
newItem.tags = newItem.tags.concat(subjects); newItem.tags = newItem.tags.concat(subjects);
@ -3516,7 +3516,7 @@ function scrape(doc, url) {
author = words.join(" "); author = words.join(" ");
if(words[0] == "The") { if(words[0] == "The") {
newItem.creators.push({lastName:author, creatorType:"author", isInstitution:true}); newItem.creators.push({lastName:author, creatorType:"author", fieldMode:true});
} else { } else {
newItem.creators.push(Zotero.Utilities.cleanAuthor(author, "author")); newItem.creators.push(Zotero.Utilities.cleanAuthor(author, "author"));
} }
@ -3640,7 +3640,7 @@ function scrape(doc) {
author = words.join(" "); author = words.join(" ");
if(words[0] == "The") { if(words[0] == "The") {
newItem.creators.push({lastName:author, creatorType:"author", isInstitution:true}); newItem.creators.push({lastName:author, creatorType:"author", fieldMode:true});
} else { } else {
newItem.creators.push(Zotero.Utilities.cleanAuthor(author, "author")); newItem.creators.push(Zotero.Utilities.cleanAuthor(author, "author"));
} }
@ -6261,7 +6261,7 @@ function processTag(item, tag, value) {
item.creators.push(Zotero.Utilities.cleanAuthor(value, type)); item.creators.push(Zotero.Utilities.cleanAuthor(value, type));
} }
} else if(tag == "Q") { } else if(tag == "Q") {
item.creators.push({creatorType:"author", lastName:value, isInstitution:true}); item.creators.push({creatorType:"author", lastName:value, fieldMode:true});
} else if(tag == "H" || tag == "O") { } else if(tag == "H" || tag == "O") {
item.extra += "\n"+value; item.extra += "\n"+value;
} else if(tag == "Z") { } else if(tag == "Z") {
@ -6893,7 +6893,7 @@ function pullISBN(text) {
// corporate author extraction // corporate author extraction
function corpAuthor(author) { function corpAuthor(author) {
return {lastName:author, isInstitution:true}; return {lastName:author, fieldMode:true};
} }
// regular author extraction // regular author extraction

View file

@ -1,4 +1,4 @@
-- 5 -- 6
-- This file creates tables containing user-specific data -- any changes -- This file creates tables containing user-specific data -- any changes
-- to existing tables made here must be mirrored in transition steps in -- to existing tables made here must be mirrored in transition steps in
@ -131,7 +131,7 @@ CREATE TABLE IF NOT EXISTS creators (
creatorID INT, creatorID INT,
firstName TEXT, firstName TEXT,
lastName TEXT, lastName TEXT,
isInstitution INT, fieldMode INT,
PRIMARY KEY (creatorID) PRIMARY KEY (creatorID)
); );