diff --git a/chrome/content/zotero/xpcom/data/library.js b/chrome/content/zotero/xpcom/data/library.js index 70e69b943..0f16b3b18 100644 --- a/chrome/content/zotero/xpcom/data/library.js +++ b/chrome/content/zotero/xpcom/data/library.js @@ -48,6 +48,7 @@ Zotero.Library = function(params = {}) { 'libraryVersion', 'storageVersion', 'lastSync', + 'archived' ] ); @@ -68,7 +69,7 @@ Zotero.Library = function(params = {}) { // DB columns Zotero.defineProperty(Zotero.Library, '_dbColumns', { value: Object.freeze([ - 'type', 'editable', 'filesEditable', 'version', 'storageVersion', 'lastSync' + 'type', 'editable', 'filesEditable', 'version', 'storageVersion', 'lastSync', 'archived' ]) }); @@ -195,7 +196,7 @@ Zotero.defineProperty(Zotero.Library.prototype, 'hasTrash', { // Create other accessors (function() { - let accessors = ['editable', 'filesEditable', 'storageVersion']; + let accessors = ['editable', 'filesEditable', 'storageVersion', 'archived']; for (let i=0; i<accessors.length; i++) { let prop = Zotero.Library._colToProp(accessors[i]); Zotero.defineProperty(Zotero.Library.prototype, accessors[i], { @@ -300,6 +301,16 @@ Zotero.Library.prototype._set = function(prop, val) { val = new Date(Math.floor(val.getTime()/1000) * 1000); } break; + + case '_libraryArchived': + if (['user', 'publications', 'feeds'].indexOf(this._libraryType) != -1) { + throw new Error('Cannot change ' + prop + ' for ' + this._libraryType + ' library'); + } + if (val && this._libraryEditable) { + throw new Error('Cannot set editable library as archived'); + } + val = !!val; + break; } if (this[prop] == val) return; // Unchanged @@ -326,6 +337,7 @@ Zotero.Library.prototype._loadDataFromRow = function(row) { this._libraryVersion = row._libraryVersion; this._libraryStorageVersion = row._libraryStorageVersion; this._libraryLastSync = row._libraryLastSync !== 0 ? new Date(row._libraryLastSync * 1000) : false; + this._libraryArchived = !!row._libraryArchived; this._hasCollections = !!row.hasCollections; this._hasSearches = !!row.hasSearches; diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js index 19750c5f0..a5047a3cf 100644 --- a/chrome/content/zotero/xpcom/schema.js +++ b/chrome/content/zotero/xpcom/schema.js @@ -2367,6 +2367,10 @@ Zotero.Schema = new function(){ yield Zotero.DB.queryAsync("INSERT INTO feeds SELECT libraryID, name, url, lastUpdate, lastCheck, lastCheckError, 30, cleanupAfter, refreshInterval FROM feedsOld"); yield Zotero.DB.queryAsync("DROP TABLE feedsOld"); } + + else if (i == 91) { + yield Zotero.DB.queryAsync("ALTER TABLE libraries ADD COLUMN archived INT NOT NULL DEFAULT 0"); + } } yield _updateDBVersion('userdata', toVersion); diff --git a/resource/schema/userdata.sql b/resource/schema/userdata.sql index 7e171224c..dd113d29d 100644 --- a/resource/schema/userdata.sql +++ b/resource/schema/userdata.sql @@ -1,4 +1,4 @@ --- 90 +-- 91 -- Copyright (c) 2009 Center for History and New Media -- George Mason University, Fairfax, Virginia, USA @@ -255,7 +255,8 @@ CREATE TABLE libraries ( filesEditable INT NOT NULL, version INT NOT NULL DEFAULT 0, storageVersion INT NOT NULL DEFAULT 0, - lastSync INT NOT NULL DEFAULT 0 + lastSync INT NOT NULL DEFAULT 0, + archived INT NOT NULL DEFAULT 0 ); CREATE TABLE users ( diff --git a/test/content/support.js b/test/content/support.js index d1d936cbf..3d51059e1 100644 --- a/test/content/support.js +++ b/test/content/support.js @@ -311,6 +311,7 @@ var createGroup = Zotero.Promise.coroutine(function* (props = {}) { if (props.libraryVersion) { group.libraryVersion = props.libraryVersion; } + group.archived = props.archived === undefined ? false : props.archived; yield group.saveTx(); return group; }); diff --git a/test/tests/libraryTest.js b/test/tests/libraryTest.js index b648cee0c..3b54c824b 100644 --- a/test/tests/libraryTest.js +++ b/test/tests/libraryTest.js @@ -127,6 +127,37 @@ describe("Zotero.Library", function() { }); }); + describe("#archived", function() { + it("should return archived status", function() { + let library = Zotero.Libraries.get(Zotero.Libraries.userLibraryID); + assert.isFalse(library.archived, 'user library is not archived'); + }); + + it("should allow setting archived status", function* () { + let library = yield createGroup({ editable: false, archived: true }); + assert.isTrue(library.archived); + assert.equal((yield Zotero.DB.valueQueryAsync("SELECT archived FROM libraries WHERE libraryID=?", library.libraryID)), 1) + + library.archived = false; + yield library.saveTx(); + assert.isFalse(library.archived); + assert.equal((yield Zotero.DB.valueQueryAsync("SELECT archived FROM libraries WHERE libraryID=?", library.libraryID)), 0) + }); + + it("should not be settable for user and publications libraries", function* () { + let library = Zotero.Libraries.get(Zotero.Libraries.userLibraryID); + assert.throws(() => library.archived = true, /^Cannot change _libraryArchived for user library$/, "does not allow setting user library as archived"); + + library = Zotero.Libraries.get(Zotero.Libraries.publicationsLibraryID); + assert.throws(() => library.archived = true, /^Cannot change _libraryArchived for publications library$/, "does not allow setting publications library as archived"); + }); + + it("should only be settable on read-only library", function* () { + let library = yield createGroup(); + assert.throws(() => library.archived = true, /^Cannot set editable library as archived$/); + }); + }); + describe("#save()", function() { it("should require mandatory parameters to be set", function* () { let library = new Zotero.Library({ editable: true, filesEditable: true });