Automatic style updating for all installed styles
This commit is contained in:
parent
428ddbab36
commit
73dd60f2c1
|
@ -1343,6 +1343,10 @@ function updateTranslators() {
|
|||
var label = Zotero.getString('zotero.preferences.update.error');
|
||||
}
|
||||
button.setAttribute('label', label);
|
||||
|
||||
if (updated) {
|
||||
refreshStylesList();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -942,16 +942,6 @@ Zotero.Schema = new function(){
|
|||
* @param {Function} callback
|
||||
*/
|
||||
this.updateFromRepository = function (force, callback) {
|
||||
// Little hack to manually update CSLs from repo on upgrades
|
||||
if (!force && Zotero.Prefs.get('automaticScraperUpdates')) {
|
||||
var syncTargetVersion = 3; // increment this when releasing new version that requires it
|
||||
var syncVersion = this.getDBVersion('sync');
|
||||
if (syncVersion < syncTargetVersion) {
|
||||
force = true;
|
||||
var forceCSLUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!force){
|
||||
if (_remoteUpdateInProgress) {
|
||||
Zotero.debug("A remote update is already in progress -- not checking repository");
|
||||
|
@ -978,7 +968,7 @@ Zotero.Schema = new function(){
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (_localUpdateInProgress) {
|
||||
Zotero.debug('A local update is already in progress -- delaying repository check', 4);
|
||||
_setRepositoryTimer(600);
|
||||
|
@ -1016,14 +1006,27 @@ Zotero.Schema = new function(){
|
|||
else {
|
||||
url += '&m=1';
|
||||
}
|
||||
|
||||
// Force updating of all public CSLs
|
||||
if (forceCSLUpdate) {
|
||||
url += '&cslup=' + syncTargetVersion;
|
||||
}
|
||||
}
|
||||
|
||||
var get = Zotero.HTTP.doGet(url, function (xmlhttp) {
|
||||
// Send list of installed styles
|
||||
var styles = Zotero.Styles.getAll();
|
||||
var styleTimestamps = [];
|
||||
for (var id in styles) {
|
||||
var updated = Zotero.Date.sqlToDate(styles[id].updated);
|
||||
updated = updated ? updated.getTime() / 1000 : 0;
|
||||
var selfLink = styles[id].url;
|
||||
var data = {
|
||||
id: id,
|
||||
updated: updated
|
||||
};
|
||||
if (selfLink) {
|
||||
data.url = selfLink;
|
||||
}
|
||||
styleTimestamps.push(data);
|
||||
}
|
||||
var body = 'styles=' + encodeURIComponent(JSON.stringify(styleTimestamps));
|
||||
|
||||
var get = Zotero.HTTP.doPost(url, body, function (xmlhttp) {
|
||||
var updated = _updateFromRepositoryCallback(xmlhttp, !!force);
|
||||
if (callback) {
|
||||
callback(xmlhttp, updated)
|
||||
|
@ -1538,16 +1541,7 @@ Zotero.Schema = new function(){
|
|||
|
||||
Zotero.DB.beginTransaction();
|
||||
|
||||
try {
|
||||
var re = /cslup=([0-9]+)/;
|
||||
var matches = re.exec(xmlhttp.channel.URI.spec);
|
||||
if (matches) {
|
||||
_updateDBVersion('sync', matches[1]);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
Zotero.debug(e);
|
||||
}
|
||||
// TODO: clear DB version 'sync' from removed _updateDBVersion()
|
||||
|
||||
// Store the timestamp provided by the server
|
||||
_updateDBVersion('repository', currentTime);
|
||||
|
@ -1708,7 +1702,7 @@ Zotero.Schema = new function(){
|
|||
var uri = xmlnode.getAttribute('id');
|
||||
|
||||
// Delete local style if CSL code is empty
|
||||
if (!xmlnode.getElementsByTagName('csl')[0].firstChild) {
|
||||
if (!xmlnode.firstChild) {
|
||||
var style = Zotero.Styles.get(uri);
|
||||
if (style) {
|
||||
style.file.remove(null);
|
||||
|
@ -1716,7 +1710,25 @@ Zotero.Schema = new function(){
|
|||
return;
|
||||
}
|
||||
|
||||
var str = xmlnode.getElementsByTagName('csl')[0].firstChild.nodeValue;
|
||||
// Remove renamed styles
|
||||
if (uri == 'http://www.zotero.org/styles/american-medical-association') {
|
||||
var oldID = 'http://www.zotero.org/styles/ama';
|
||||
var style = Zotero.Styles.get(oldID);
|
||||
if (style && style.file.exists()) {
|
||||
Zotero.debug("Deleting renamed style '" + oldID + "'");
|
||||
style.file.remove(false);
|
||||
}
|
||||
}
|
||||
else if (uri == 'http://www.zotero.org/styles/national-library-of-medicine') {
|
||||
var oldID = 'http://www.zotero.org/styles/nlm';
|
||||
var style = Zotero.Styles.get(oldID);
|
||||
if (style && style.file.exists()) {
|
||||
Zotero.debug("Deleting renamed style '" + oldID + "'");
|
||||
style.file.remove(false);
|
||||
}
|
||||
}
|
||||
|
||||
var str = xmlnode.firstChild.nodeValue;
|
||||
var style = Zotero.Styles.get(uri);
|
||||
if (style) {
|
||||
if (style.file.exists()) {
|
||||
|
|
|
@ -122,7 +122,9 @@ Zotero.Styles = new function() {
|
|||
var mappings = {
|
||||
"http://www.zotero.org/styles/chicago-note": "http://www.zotero.org/styles/chicago-note-bibliography",
|
||||
"http://www.zotero.org/styles/mhra_note_without_bibliography": "http://www.zotero.org/styles/mhra",
|
||||
"http://www.zotero.org/styles/aaa": "http://www.zotero.org/styles/american-anthropological-association"
|
||||
"http://www.zotero.org/styles/aaa": "http://www.zotero.org/styles/american-anthropological-association",
|
||||
"http://www.zotero.org/styles/ama": "http://www.zotero.org/styles/american-medical-association",
|
||||
"http://www.zotero.org/styles/nlm": "http://www.zotero.org/styles/national-library-of-medicine"
|
||||
};
|
||||
if(mappings[id]) {
|
||||
Zotero.debug("Mapping " + id + " to " + mappings[id]);
|
||||
|
@ -382,6 +384,7 @@ Zotero.Styles = new function() {
|
|||
* @class Represents a style file and its metadata
|
||||
* @property {nsIFile} file The path to the style file
|
||||
* @property {String} styleID
|
||||
* @property {String} url The URL where the style can be found (rel="self")
|
||||
* @property {String} type "csl" for CSL styles
|
||||
* @property {String} title
|
||||
* @property {String} updated SQL-style date updated
|
||||
|
@ -413,6 +416,9 @@ Zotero.Style = function(arg) {
|
|||
|
||||
this.styleID = Zotero.Utilities.xpathText(doc, '/csl:style/csl:info[1]/csl:id[1]',
|
||||
Zotero.Styles.ns);
|
||||
this.url = Zotero.Utilities.xpathText(doc,
|
||||
'/csl:style/csl:info[1]/csl:link[@rel="self"][1]/@href',
|
||||
Zotero.Styles.ns);
|
||||
this.title = Zotero.Utilities.xpathText(doc, '/csl:style/csl:info[1]/csl:title[1]',
|
||||
Zotero.Styles.ns);
|
||||
this.updated = Zotero.Utilities.xpathText(doc, '/csl:style/csl:info[1]/csl:updated[1]',
|
||||
|
|
Loading…
Reference in New Issue
Block a user