Miscellaneous data layer fixes and tweaks
This commit is contained in:
parent
53e40bb0f4
commit
aa512f0f8d
4 changed files with 47 additions and 60 deletions
|
@ -258,7 +258,7 @@ Zotero.Collection.prototype._initSave = Zotero.Promise.coroutine(function* (env)
|
||||||
|
|
||||||
// Verify parent
|
// Verify parent
|
||||||
if (this._parentKey) {
|
if (this._parentKey) {
|
||||||
let newParent = this.ObjectsClass.getByLibraryAndKey(
|
let newParent = yield this.ObjectsClass.getByLibraryAndKeyAsync(
|
||||||
this.libraryID, this._parentKey
|
this.libraryID, this._parentKey
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -285,6 +285,7 @@ Zotero.Collection.prototype._initSave = Zotero.Promise.coroutine(function* (env)
|
||||||
|
|
||||||
Zotero.Collection.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
|
Zotero.Collection.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
|
||||||
var isNew = env.isNew;
|
var isNew = env.isNew;
|
||||||
|
var options = env.options;
|
||||||
|
|
||||||
var collectionID = env.id = this._id = this.id ? this.id : yield Zotero.ID.get('collections');
|
var collectionID = env.id = this._id = this.id ? this.id : yield Zotero.ID.get('collections');
|
||||||
var libraryID = env.libraryID = this.libraryID || Zotero.Libraries.userLibraryID;
|
var libraryID = env.libraryID = this.libraryID || Zotero.Libraries.userLibraryID;
|
||||||
|
@ -311,10 +312,14 @@ Zotero.Collection.prototype._saveData = Zotero.Promise.coroutine(function* (env)
|
||||||
this.version ? this.version : 0,
|
this.version ? this.version : 0,
|
||||||
this.synced ? 1 : 0
|
this.synced ? 1 : 0
|
||||||
];
|
];
|
||||||
if (isNew) {
|
if (isNew || !options.skipClientDateModified) {
|
||||||
var placeholders = columns.map(function () '?').join();
|
columns.push('clientDateModified');
|
||||||
|
sqlValues.push(Zotero.DB.transactionDateTime);
|
||||||
|
}
|
||||||
|
|
||||||
var sql = "REPLACE INTO collections (" + columns.join(', ') + ") "
|
if (isNew) {
|
||||||
|
let placeholders = columns.map(function () '?').join();
|
||||||
|
let sql = "INSERT INTO collections (" + columns.join(', ') + ") "
|
||||||
+ "VALUES (" + placeholders + ")";
|
+ "VALUES (" + placeholders + ")";
|
||||||
var insertID = yield Zotero.DB.queryAsync(sql, sqlValues);
|
var insertID = yield Zotero.DB.queryAsync(sql, sqlValues);
|
||||||
if (!collectionID) {
|
if (!collectionID) {
|
||||||
|
|
|
@ -169,7 +169,7 @@ Zotero.Creators = new function() {
|
||||||
firstName: '',
|
firstName: '',
|
||||||
lastName: ''
|
lastName: ''
|
||||||
};
|
};
|
||||||
for (i=0; i<this.fields.length; i++) {
|
for (let i=0; i<this.fields.length; i++) {
|
||||||
let field = this.fields[i];
|
let field = this.fields[i];
|
||||||
let val = data[field];
|
let val = data[field];
|
||||||
switch (field) {
|
switch (field) {
|
||||||
|
|
|
@ -36,7 +36,7 @@ Zotero.Item = function(itemTypeOrID) {
|
||||||
|
|
||||||
this._disabled = false;
|
this._disabled = false;
|
||||||
|
|
||||||
// loadPrimaryData (additional properties in dataObjet.js)
|
// loadPrimaryData (additional properties in dataObject.js)
|
||||||
this._itemTypeID = null;
|
this._itemTypeID = null;
|
||||||
this._firstCreator = null;
|
this._firstCreator = null;
|
||||||
this._sortCreator = null;
|
this._sortCreator = null;
|
||||||
|
@ -290,7 +290,7 @@ Zotero.Item.prototype.getField = function(field, unformatted, includeBaseMapped)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Boolean} asNames
|
* @param {Boolean} asNames
|
||||||
* @return {Integer{}|String[]}
|
* @return {Integer[]|String[]}
|
||||||
*/
|
*/
|
||||||
Zotero.Item.prototype.getUsedFields = function(asNames) {
|
Zotero.Item.prototype.getUsedFields = function(asNames) {
|
||||||
this._requireData('itemData');
|
this._requireData('itemData');
|
||||||
|
@ -711,7 +711,7 @@ Zotero.Item.prototype.setField = function(field, value, loadIn) {
|
||||||
this._requireData('primaryData');
|
this._requireData('primaryData');
|
||||||
|
|
||||||
if (loadIn) {
|
if (loadIn) {
|
||||||
throw('Cannot set primary field ' + field + ' in loadIn mode in Zotero.Item.setField()');
|
throw new Error('Cannot set primary field ' + field + ' in loadIn mode in Zotero.Item.setField()');
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (field) {
|
switch (field) {
|
||||||
|
@ -736,7 +736,7 @@ Zotero.Item.prototype.setField = function(field, value, loadIn) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw ('Primary field ' + field + ' cannot be changed in Zotero.Item.setField()');
|
throw new Error('Primary field ' + field + ' cannot be changed in Zotero.Item.setField()');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1534,7 +1534,7 @@ Zotero.Item.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isAttachment() || this._changed.attachmentData) {
|
if (this._changed.attachmentData) {
|
||||||
let sql = "REPLACE INTO itemAttachments (itemID, parentItemID, linkMode, "
|
let sql = "REPLACE INTO itemAttachments (itemID, parentItemID, linkMode, "
|
||||||
+ "contentType, charsetID, path, syncState) VALUES (?,?,?,?,?,?,?)";
|
+ "contentType, charsetID, path, syncState) VALUES (?,?,?,?,?,?,?)";
|
||||||
let linkMode = this.attachmentLinkMode;
|
let linkMode = this.attachmentLinkMode;
|
||||||
|
@ -3803,7 +3803,9 @@ Zotero.Item.prototype.multiDiff = Zotero.Promise.coroutine(function* (otherItems
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an unsaved copy of the item
|
* Returns an unsaved copy of the item without an itemID or key
|
||||||
|
*
|
||||||
|
* This is used to duplicate items and copy them between libraries.
|
||||||
*
|
*
|
||||||
* @param {Number} [libraryID] - libraryID of the new item, or the same as original if omitted
|
* @param {Number} [libraryID] - libraryID of the new item, or the same as original if omitted
|
||||||
* @param {Boolean} [skipTags=false] - Skip tags
|
* @param {Boolean} [skipTags=false] - Skip tags
|
||||||
|
@ -3997,7 +3999,7 @@ Zotero.Item.prototype.fromJSON = Zotero.Promise.coroutine(function* (json) {
|
||||||
var setFields = {};
|
var setFields = {};
|
||||||
|
|
||||||
// Primary data
|
// Primary data
|
||||||
for (var field in json) {
|
for (let field in json) {
|
||||||
let val = json[field];
|
let val = json[field];
|
||||||
|
|
||||||
switch (field) {
|
switch (field) {
|
||||||
|
|
|
@ -120,48 +120,11 @@ Zotero.Search.prototype._set = function (field, value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Load a saved search from the DB
|
|
||||||
*/
|
|
||||||
Zotero.Search.prototype.loadPrimaryData = Zotero.Promise.coroutine(function* (reload) {
|
|
||||||
if (this._loaded.primaryData && !reload) return;
|
|
||||||
|
|
||||||
var id = this._id;
|
|
||||||
var key = this._key;
|
|
||||||
var libraryID = this._libraryID;
|
|
||||||
var desc = id ? id : libraryID + "/" + key;
|
|
||||||
|
|
||||||
if (!id && !key) {
|
|
||||||
throw new Error('ID or key not set');
|
|
||||||
}
|
|
||||||
|
|
||||||
var sql = Zotero.Searches.getPrimaryDataSQL()
|
|
||||||
if (id) {
|
|
||||||
sql += " AND savedSearchID=?";
|
|
||||||
var params = id;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sql += " AND key=? AND libraryID=?";
|
|
||||||
var params = [key, libraryID];
|
|
||||||
}
|
|
||||||
var data = yield Zotero.DB.rowQueryAsync(sql, params);
|
|
||||||
|
|
||||||
this._loaded.primaryData = true;
|
|
||||||
this._clearChanged('primaryData');
|
|
||||||
|
|
||||||
if (!data) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.loadFromRow(data);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
Zotero.Search.prototype.loadFromRow = function (row) {
|
Zotero.Search.prototype.loadFromRow = function (row) {
|
||||||
this._id = row.savedSearchID;
|
this._id = row.savedSearchID;
|
||||||
this._libraryID = row.libraryID;
|
this._libraryID = row.libraryID;
|
||||||
this._key = row.key;
|
this._key = row.key;
|
||||||
this._name = row.savedSearchName;
|
this._name = row.name;
|
||||||
this._version = row.version;
|
this._version = row.version;
|
||||||
this._synced = !!row.synced;
|
this._synced = !!row.synced;
|
||||||
|
|
||||||
|
@ -171,15 +134,18 @@ Zotero.Search.prototype.loadFromRow = function (row) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Zotero.Search.prototype._initSave = Zotero.Promise.coroutine(function* (env) {
|
Zotero.Search.prototype._initSave = Zotero.Promise.coroutine(function* (env) {
|
||||||
|
if (!this.libraryID) {
|
||||||
|
throw new Error('libraryID must be set before saving search');
|
||||||
|
}
|
||||||
if (!this.name) {
|
if (!this.name) {
|
||||||
throw new Error('Name not provided for saved search');
|
throw new Error('Name not provided for saved search');
|
||||||
}
|
}
|
||||||
|
|
||||||
return Zotero.Search._super.prototype._initSave.apply(this, arguments);
|
return Zotero.Search._super.prototype._initSave.apply(this, arguments);
|
||||||
});
|
});
|
||||||
|
|
||||||
Zotero.Search.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
|
Zotero.Search.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
|
||||||
var isNew = env.isNew;
|
var isNew = env.isNew;
|
||||||
|
var options = env.options;
|
||||||
|
|
||||||
var searchID = env.id = this._id = this.id ? this.id : yield Zotero.ID.get('savedSearches');
|
var searchID = env.id = this._id = this.id ? this.id : yield Zotero.ID.get('savedSearches');
|
||||||
var libraryID = env.libraryID = this.libraryID || Zotero.Libraries.userLibraryID;
|
var libraryID = env.libraryID = this.libraryID || Zotero.Libraries.userLibraryID;
|
||||||
|
@ -189,7 +155,6 @@ Zotero.Search.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
|
||||||
var columns = [
|
var columns = [
|
||||||
'savedSearchID',
|
'savedSearchID',
|
||||||
'savedSearchName',
|
'savedSearchName',
|
||||||
'clientDateModified',
|
|
||||||
'libraryID',
|
'libraryID',
|
||||||
'key',
|
'key',
|
||||||
'version',
|
'version',
|
||||||
|
@ -204,12 +169,27 @@ Zotero.Search.prototype._saveData = Zotero.Promise.coroutine(function* (env) {
|
||||||
this.version ? this.version : 0,
|
this.version ? this.version : 0,
|
||||||
this.synced ? 1 : 0
|
this.synced ? 1 : 0
|
||||||
];
|
];
|
||||||
|
if (isNew || !options.skipClientDateModified) {
|
||||||
|
columns.push('clientDateModified');
|
||||||
|
sqlValues.push(Zotero.DB.transactionDateTime);
|
||||||
|
}
|
||||||
|
|
||||||
var sql = "REPLACE INTO savedSearches (" + columns.join(', ') + ") "
|
if (isNew) {
|
||||||
+ "VALUES (" + placeholders + ")";
|
let placeholders = columns.map(function () '?').join();
|
||||||
var insertID = yield Zotero.DB.queryAsync(sql, sqlValues);
|
let sql = "INSERT INTO savedSearches (" + columns.join(', ') + ") "
|
||||||
if (!searchID) {
|
+ "VALUES (" + placeholders + ")";
|
||||||
searchID = env.id = insertID;
|
var insertID = yield Zotero.DB.queryAsync(sql, sqlValues);
|
||||||
|
if (!searchID) {
|
||||||
|
searchID = env.id = insertID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
columns.shift();
|
||||||
|
sqlValues.push(sqlValues.shift());
|
||||||
|
let sql = 'UPDATE savedSearches SET '
|
||||||
|
+ columns.map(function (x) x + '=?').join(', ')
|
||||||
|
+ ' WHERE savedSearchID=?';
|
||||||
|
yield Zotero.DB.queryAsync(sql, sqlValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isNew) {
|
if (!isNew) {
|
||||||
|
@ -1674,18 +1654,19 @@ Zotero.Searches = function() {
|
||||||
this.constructor = null;
|
this.constructor = null;
|
||||||
|
|
||||||
this._ZDO_object = 'search';
|
this._ZDO_object = 'search';
|
||||||
this._ZDO_id = 'savedSearch';
|
this._ZDO_id = 'savedSearchID';
|
||||||
this._ZDO_table = 'savedSearches';
|
this._ZDO_table = 'savedSearches';
|
||||||
|
|
||||||
this._primaryDataSQLParts = {
|
this._primaryDataSQLParts = {
|
||||||
savedSearchID: "O.savedSearchID",
|
savedSearchID: "O.savedSearchID",
|
||||||
name: "O.savedSearchName",
|
name: "O.savedSearchName AS name",
|
||||||
libraryID: "O.libraryID",
|
libraryID: "O.libraryID",
|
||||||
key: "O.key",
|
key: "O.key",
|
||||||
version: "O.version",
|
version: "O.version",
|
||||||
synced: "O.synced"
|
synced: "O.synced"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._primaryDataSQLFrom = "FROM savedSearches O";
|
||||||
|
|
||||||
this.init = Zotero.Promise.coroutine(function* () {
|
this.init = Zotero.Promise.coroutine(function* () {
|
||||||
yield Zotero.DataObjects.prototype.init.apply(this);
|
yield Zotero.DataObjects.prototype.init.apply(this);
|
||||||
|
@ -1715,7 +1696,6 @@ Zotero.Searches = function() {
|
||||||
var searches = [];
|
var searches = [];
|
||||||
for (var i=0; i<rows.length; i++) {
|
for (var i=0; i<rows.length; i++) {
|
||||||
let search = new Zotero.Search;
|
let search = new Zotero.Search;
|
||||||
search.libraryID = libraryID;
|
|
||||||
search.id = rows[i].id;
|
search.id = rows[i].id;
|
||||||
yield search.loadPrimaryData();
|
yield search.loadPrimaryData();
|
||||||
searches.push(search);
|
searches.push(search);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue