- Add translator/style deleting mechanism (without repo)

- Fix style saving from repo (updated styles were saved without .csl extension, so updates were ignored)
- Don't update from repository on every load of SVN build with missing symlinked style targets
- Remove deleted "Open Worldcat (Search)" and "Worldcat.org" translators
This commit is contained in:
Dan Stillman 2009-04-16 10:07:48 +00:00
parent 34cd1103a0
commit 5cd7b3840e
2 changed files with 115 additions and 12 deletions

View file

@ -146,10 +146,9 @@ Zotero.Schema = new function(){
} }
} }
var up4 = this.updateBundledFiles('translators'); var up4 = this.updateBundledFiles();
var up5 = this.updateBundledFiles('styles');
if (up2 || up3 || up4 || up5) { if (up2 || up3 || up4) {
// Run a manual scraper update if upgraded and pref set // Run a manual scraper update if upgraded and pref set
if (Zotero.Prefs.get('automaticScraperUpdates')){ if (Zotero.Prefs.get('automaticScraperUpdates')){
this.updateFromRepository(2); this.updateFromRepository(2);
@ -167,9 +166,18 @@ Zotero.Schema = new function(){
* Update styles and translators in data directory with versions from * Update styles and translators in data directory with versions from
* ZIP file (XPI) or directory (SVN) in extension directory * ZIP file (XPI) or directory (SVN) in extension directory
* *
* @param {String} mode 'translators' or 'styles' * @param {String} [mode] 'translators' or 'styles'
* @param {Boolean} [skipDeleteUpdated] Skip updating of the file deleting version --
* since deleting uses a single version table key,
* it should only be updated the last time through
*/ */
this.updateBundledFiles = function (mode) { this.updateBundledFiles = function (mode, skipDeleteUpdate) {
if (!mode) {
var up1 = this.updateBundledFiles('translators', true);
var up2 = this.updateBundledFiles('styles');
return up1 && up2;
}
switch (mode) { switch (mode) {
case "translators": case "translators":
var titleField = 'label'; var titleField = 'label';
@ -179,7 +187,7 @@ Zotero.Schema = new function(){
case "styles": case "styles":
var titleField = 'title'; var titleField = 'title';
var fileExt = ".csl"; var fileExt = ".csl";
var hiddenDir = Zotero.getTranslatorsDirectory(); var hiddenDir = Zotero.getStylesDirectory();
hiddenDir.append('hidden'); hiddenDir.append('hidden');
break; break;
@ -221,6 +229,82 @@ Zotero.Schema = new function(){
break; break;
} }
//
// Delete obsolete files
//
var sql = "SELECT version FROM version WHERE schema='delete'";
var lastVersion = Zotero.DB.valueQuery(sql);
var deleted = extDir.clone();
deleted.append('deleted.txt');
deleted = Zotero.File.getContents(deleted);
deleted = deleted.match(/^([^\s]+)/gm);
var version = deleted.shift();
if (!lastVersion || lastVersion < version) {
var toDelete = [];
var entries = destDir.directoryEntries;
while (entries.hasMoreElements()) {
var file = entries.getNext();
file.QueryInterface(Components.interfaces.nsIFile);
if (!file.exists() // symlink to non-existent file
|| file.isDirectory()) {
continue;
}
// Delete incorrectly named files saved via repo pre-1.5b3
switch (file.leafName) {
case 'ama':
case 'apa':
case 'apsa':
case 'asa':
case 'chicago-author-date':
case 'chicago-fullnote-bibliography':
case 'chicago-note':
case 'chicago-note-bibliography':
case 'harvard1':
case 'ieee':
case 'mhra':
case 'mhra_note_without_bibliography':
case 'mla':
case 'nature':
case 'nlm':
case 'vancouver':
toDelete.push(file);
continue;
}
if (forceReinstall || !file.leafName.match(fileNameRE)) {
continue;
}
var newObj = new Zotero[Mode](file);
if (deleted.indexOf(newObj[mode + "ID"]) == -1) {
continue;
}
toDelete.push(file);
}
for each(var file in toDelete) {
Zotero.debug("Deleting " + file.path);
try {
file.remove(false);
}
catch (e) {
Zotero.debug(e);
}
}
if (!skipDeleteUpdate) {
sql = "REPLACE INTO version (schema, version) VALUES ('delete', ?)";
Zotero.DB.query(sql, version);
}
}
//
// Update files
//
var sql = "SELECT version FROM version WHERE schema=?"; var sql = "SELECT version FROM version WHERE schema=?";
var lastModTime = Zotero.DB.valueQuery(sql, modes); var lastModTime = Zotero.DB.valueQuery(sql, modes);
@ -229,7 +313,7 @@ Zotero.Schema = new function(){
if (!forceReinstall && lastModTime && modTime <= lastModTime) { if (!forceReinstall && lastModTime && modTime <= lastModTime) {
Zotero.debug("Installed " + modes + " are up-to-date with " + modes + ".zip"); Zotero.debug("Installed " + modes + " are up-to-date with " + modes + ".zip");
return 0; return false;
} }
Zotero.debug("Updating installed " + modes + " from " + modes + ".zip"); Zotero.debug("Updating installed " + modes + " from " + modes + ".zip");
@ -295,11 +379,12 @@ Zotero.Schema = new function(){
if (!sourceDir.exists()) { if (!sourceDir.exists()) {
Components.utils.reportError("No " + modes + " ZIP file or directory " Components.utils.reportError("No " + modes + " ZIP file or directory "
+ " in Zotero.Schema.updateBundledFiles()"); + " in Zotero.Schema.updateBundledFiles()");
return -1; return false;
} }
var entries = sourceDir.directoryEntries; var entries = sourceDir.directoryEntries;
var modTime = 0; var modTime = 0;
var sourceFilesExist = false;
while (entries.hasMoreElements()) { while (entries.hasMoreElements()) {
var file = entries.getNext(); var file = entries.getNext();
file.QueryInterface(Components.interfaces.nsIFile); file.QueryInterface(Components.interfaces.nsIFile);
@ -309,15 +394,22 @@ Zotero.Schema = new function(){
|| file.isDirectory()) { || file.isDirectory()) {
continue; continue;
} }
sourceFilesExist = true;
var fileModTime = Math.round(file.lastModifiedTime / 1000); var fileModTime = Math.round(file.lastModifiedTime / 1000);
if (fileModTime > modTime) { if (fileModTime > modTime) {
modTime = fileModTime; modTime = fileModTime;
} }
} }
// Don't attempt installation for SVN build with missing styles
if (!sourceFilesExist) {
Zotero.debug("No source " + mode + " files exist -- skipping update");
return false;
}
if (!forceReinstall && lastModTime && modTime <= lastModTime) { if (!forceReinstall && lastModTime && modTime <= lastModTime) {
Zotero.debug("Installed " + modes + " are up-to-date with " + modes + " directory"); Zotero.debug("Installed " + modes + " are up-to-date with " + modes + " directory");
return 0; return false;
} }
Zotero.debug("Updating installed " + modes + " from " + modes + " directory"); Zotero.debug("Updating installed " + modes + " from " + modes + " directory");
@ -385,7 +477,7 @@ Zotero.Schema = new function(){
Zotero.DB.commitTransaction(); Zotero.DB.commitTransaction();
Zotero[Modes].init(); Zotero[Modes].init();
return 1; return true;
} }
@ -986,7 +1078,6 @@ Zotero.Schema = new function(){
} }
var str = xmlnode.getElementsByTagName('csl')[0].firstChild.nodeValue; var str = xmlnode.getElementsByTagName('csl')[0].firstChild.nodeValue;
var style = Zotero.Styles.get(uri); var style = Zotero.Styles.get(uri);
if (style) { if (style) {
if (style.file.exists()) { if (style.file.exists()) {
@ -1001,7 +1092,7 @@ Zotero.Schema = new function(){
throw ("Invalid style URI '" + uri + "' from repository"); throw ("Invalid style URI '" + uri + "' from repository");
} }
var destFile = Zotero.getStylesDirectory(); var destFile = Zotero.getStylesDirectory();
destFile.append(matches[1]); destFile.append(matches[1] + ".csl");
if (destFile.exists()) { if (destFile.exists()) {
throw ("Different style with filename '" + matches[1] throw ("Different style with filename '" + matches[1]
+ "' already exists in Zotero.Schema._styleXMLToFile()"); + "' already exists in Zotero.Schema._styleXMLToFile()");

12
deleted.txt Normal file
View file

@ -0,0 +1,12 @@
1 # Increment number when modifying file
96b9f483-c44d-5784-cdad-ce21b984 # Amazon
add7c71c-21f3-ee14-d188-caf9da12 # SIRSI 2003+
fcf41bed-0cbc-3704-85c7-8062a006 # PubMed
0faa6714-927a-4b07-911e-7101895daae0 # GBV
360da304-5a4c-44ea-b655-28dcb5ebfa25 # YouTube
3af43735-36d3-46ae-9ca8-506ff032b0d3 # HeinOnline
da440efe-646c-4a18-9958-abe1f7d55cde # NCSU Library (Endeca 2)
37445f52-64fa-4a2a-9532-35753520a0f0 # HeinOnline
e07e9b8c-0e98-4915-bb5a-32a08cb2f365 # Open WorldCat (Search)
490909d7-7d79-4c7a-a136-77df618d4db2 # Worldcat.org