2006-06-07 01:02:59 +00:00
|
|
|
Scholar.Schema = new function(){
|
2006-06-07 15:27:21 +00:00
|
|
|
var _dbVersions = [];
|
|
|
|
var _schemaVersions = [];
|
2006-06-15 21:06:24 +00:00
|
|
|
var _repositoryTimer;
|
2006-06-07 01:02:59 +00:00
|
|
|
|
|
|
|
this.updateSchema = updateSchema;
|
2006-06-15 06:13:02 +00:00
|
|
|
this.updateScrapersRemote = updateScrapersRemote;
|
2006-06-15 21:06:24 +00:00
|
|
|
this.stopRepositoryTimer = stopRepositoryTimer;
|
2006-06-07 01:02:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Checks if the DB schema exists and is up-to-date, updating if necessary
|
|
|
|
*/
|
|
|
|
function updateSchema(){
|
|
|
|
var dbVersion = _getDBVersion();
|
|
|
|
var schemaVersion = _getSchemaSQLVersion();
|
|
|
|
|
2006-06-07 15:27:21 +00:00
|
|
|
if (dbVersion == schemaVersion){
|
|
|
|
if (SCHOLAR_CONFIG['DB_REBUILD']){
|
|
|
|
if (confirm('Erase all data and recreate database from schema?')){
|
|
|
|
_initializeSchema();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-15 06:13:02 +00:00
|
|
|
_updateScrapersLocal();
|
2006-06-07 15:27:21 +00:00
|
|
|
return;
|
2006-06-07 01:02:59 +00:00
|
|
|
}
|
2006-06-07 15:27:21 +00:00
|
|
|
// If DB version is less than schema file, create or update
|
2006-06-07 01:02:59 +00:00
|
|
|
else if (dbVersion < schemaVersion){
|
|
|
|
if (!dbVersion){
|
|
|
|
Scholar.debug('Database does not exist -- creating\n');
|
2006-06-07 15:27:21 +00:00
|
|
|
_initializeSchema();
|
|
|
|
return;
|
2006-06-07 01:02:59 +00:00
|
|
|
}
|
|
|
|
|
2006-06-07 15:27:21 +00:00
|
|
|
_migrateSchema(dbVersion);
|
2006-06-15 06:13:02 +00:00
|
|
|
_updateScrapersLocal();
|
2006-06-07 15:27:21 +00:00
|
|
|
return;
|
2006-06-07 01:02:59 +00:00
|
|
|
}
|
2006-06-07 15:27:21 +00:00
|
|
|
else {
|
|
|
|
throw("Scholar DB version is newer than schema version");
|
2006-06-07 01:02:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-15 06:13:02 +00:00
|
|
|
/**
|
|
|
|
* Send XMLHTTP request for updated scrapers to the central repository
|
|
|
|
*
|
|
|
|
* _force_ forces a repository query regardless of how long it's been
|
|
|
|
* since the last check
|
|
|
|
**/
|
|
|
|
function updateScrapersRemote(force){
|
2006-06-25 07:34:03 +00:00
|
|
|
if (!force){
|
|
|
|
// Check user preference for automatic updates
|
|
|
|
if (!Scholar.Prefs.get('automaticScraperUpdates')){
|
|
|
|
Scholar.debug('Automatic scraper updating disabled -- not checking repository', 4);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Determine the earliest local time that we'd query the repository again
|
|
|
|
var nextCheck = new Date();
|
|
|
|
nextCheck.setTime((parseInt(_getDBVersion('lastcheck'))
|
|
|
|
+ SCHOLAR_CONFIG['REPOSITORY_CHECK_INTERVAL']) * 1000); // JS uses ms
|
|
|
|
var now = new Date();
|
|
|
|
|
|
|
|
// If enough time hasn't passed, don't update
|
|
|
|
if (now < nextCheck){
|
|
|
|
Scholar.debug('Not enough time since last update -- not checking repository', 4);
|
|
|
|
// Set the repository timer to the remaining time
|
|
|
|
_setRepositoryTimer(Math.round((nextCheck.getTime() - now.getTime()) / 1000));
|
|
|
|
return false;
|
|
|
|
}
|
2006-06-15 06:13:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the last timestamp we got from the server
|
|
|
|
var lastUpdated = _getDBVersion('repository');
|
|
|
|
|
|
|
|
var url = SCHOLAR_CONFIG['REPOSITORY_URL'] + '/updated?'
|
|
|
|
+ (lastUpdated ? 'last=' + lastUpdated + '&' : '')
|
|
|
|
+ 'version=' + Scholar.version;
|
|
|
|
|
|
|
|
Scholar.debug('Checking repository for updates (' + url + ')');
|
2006-06-27 23:24:02 +00:00
|
|
|
var get = Scholar.Utilities.HTTP.doGet(url, _updateScrapersRemoteCallback);
|
2006-06-15 21:06:24 +00:00
|
|
|
|
|
|
|
// TODO: instead, add an observer to start and stop timer on online state change
|
|
|
|
if (!get){
|
|
|
|
Scholar.debug('Browser is offline -- skipping check');
|
2006-06-25 20:14:11 +00:00
|
|
|
_setRepositoryTimer(SCHOLAR_CONFIG['REPOSITORY_RETRY_INTERVAL']);
|
2006-06-15 21:06:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function stopRepositoryTimer(){
|
|
|
|
if (_repositoryTimer){
|
|
|
|
Scholar.debug('Stopping repository check timer');
|
|
|
|
_repositoryTimer.cancel();
|
|
|
|
}
|
2006-06-15 06:13:02 +00:00
|
|
|
}
|
|
|
|
|
2006-06-15 21:06:24 +00:00
|
|
|
|
2006-06-15 06:13:02 +00:00
|
|
|
|
2006-06-07 01:02:59 +00:00
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Private methods
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Retrieve the DB schema version
|
|
|
|
*/
|
2006-06-07 15:27:21 +00:00
|
|
|
function _getDBVersion(schema){
|
|
|
|
// Default to schema.sql
|
|
|
|
if (!schema){
|
|
|
|
schema = 'schema';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_dbVersions[schema]){
|
|
|
|
return _dbVersions[schema];
|
2006-06-07 01:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Scholar.DB.tableExists('version')){
|
2006-06-07 15:27:21 +00:00
|
|
|
try {
|
|
|
|
var dbVersion = Scholar.DB.valueQuery("SELECT version FROM "
|
2006-06-08 00:16:35 +00:00
|
|
|
+ "version WHERE schema='" + schema + "'");
|
2006-06-07 15:27:21 +00:00
|
|
|
}
|
|
|
|
// DEBUG: this is temporary to handle version table schema change
|
|
|
|
catch(e){
|
|
|
|
if (e=='no such column: schema'){
|
|
|
|
Scholar.debug(e, 1);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If some other problem, bail
|
|
|
|
throw(e);
|
|
|
|
}
|
|
|
|
_dbVersions[schema] = dbVersion;
|
2006-06-07 01:02:59 +00:00
|
|
|
return dbVersion;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2006-06-07 15:27:21 +00:00
|
|
|
* Retrieve the version from the top line of the schema SQL file
|
2006-06-07 01:02:59 +00:00
|
|
|
*/
|
2006-06-07 15:27:21 +00:00
|
|
|
function _getSchemaSQLVersion(schema){
|
|
|
|
// Default to schema.sql
|
|
|
|
if (!schema){
|
|
|
|
schema = 'schema';
|
|
|
|
}
|
|
|
|
|
|
|
|
var schemaFile = schema + '.sql';
|
|
|
|
|
|
|
|
if (_schemaVersions[schema]){
|
|
|
|
return _schemaVersions[schema];
|
2006-06-07 01:02:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var file = Components.classes["@mozilla.org/extensions/manager;1"]
|
|
|
|
.getService(Components.interfaces.nsIExtensionManager)
|
|
|
|
.getInstallLocation(SCHOLAR_CONFIG['GUID'])
|
|
|
|
.getItemLocation(SCHOLAR_CONFIG['GUID']);
|
2006-06-07 15:27:21 +00:00
|
|
|
file.append(schemaFile);
|
2006-06-07 01:02:59 +00:00
|
|
|
|
|
|
|
// Open an input stream from file
|
|
|
|
var istream = Components.classes["@mozilla.org/network/file-input-stream;1"]
|
|
|
|
.createInstance(Components.interfaces.nsIFileInputStream);
|
|
|
|
istream.init(file, 0x01, 0444, 0);
|
|
|
|
istream.QueryInterface(Components.interfaces.nsILineInputStream);
|
|
|
|
|
|
|
|
var line = {};
|
|
|
|
|
|
|
|
// Fetch the schema version from the first line of the file
|
|
|
|
istream.readLine(line);
|
|
|
|
var schemaVersion = line.value.match(/-- ([0-9]+)/)[1];
|
|
|
|
istream.close();
|
|
|
|
|
2006-06-07 15:27:21 +00:00
|
|
|
_schemaVersions[schema] = schemaVersion;
|
2006-06-07 01:02:59 +00:00
|
|
|
return schemaVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load in SQL schema
|
|
|
|
*
|
|
|
|
* Returns an _array_ of SQL statements for feeding into query()
|
|
|
|
*/
|
2006-06-07 15:27:21 +00:00
|
|
|
function _getSchemaSQL(schema){
|
|
|
|
// Default to schema.sql
|
|
|
|
if (!schema){
|
|
|
|
schema = 'schema';
|
|
|
|
}
|
|
|
|
|
|
|
|
var schemaFile = schema + '.sql';
|
|
|
|
|
2006-06-07 01:02:59 +00:00
|
|
|
// We pull the schema from an external file so we only have to process
|
|
|
|
// it when necessary
|
|
|
|
var file = Components.classes["@mozilla.org/extensions/manager;1"]
|
|
|
|
.getService(Components.interfaces.nsIExtensionManager)
|
|
|
|
.getInstallLocation(SCHOLAR_CONFIG['GUID'])
|
|
|
|
.getItemLocation(SCHOLAR_CONFIG['GUID']);
|
2006-06-07 15:27:21 +00:00
|
|
|
file.append(schemaFile);
|
2006-06-07 01:02:59 +00:00
|
|
|
|
|
|
|
// Open an input stream from file
|
|
|
|
var istream = Components.classes["@mozilla.org/network/file-input-stream;1"]
|
|
|
|
.createInstance(Components.interfaces.nsIFileInputStream);
|
|
|
|
istream.init(file, 0x01, 0444, 0);
|
|
|
|
istream.QueryInterface(Components.interfaces.nsILineInputStream);
|
|
|
|
|
|
|
|
var line = {}, sql = '', hasmore;
|
|
|
|
|
|
|
|
// Skip the first line, which contains the schema version
|
|
|
|
istream.readLine(line);
|
|
|
|
//var schemaVersion = line.value.match(/-- ([0-9]+)/)[1];
|
|
|
|
|
|
|
|
do {
|
|
|
|
hasmore = istream.readLine(line);
|
|
|
|
sql += line.value + "\n";
|
|
|
|
} while(hasmore);
|
|
|
|
|
|
|
|
istream.close();
|
|
|
|
|
|
|
|
return sql;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create new DB schema
|
|
|
|
*/
|
|
|
|
function _initializeSchema(){
|
|
|
|
try {
|
2006-06-07 14:35:04 +00:00
|
|
|
Scholar.DB.beginTransaction();
|
2006-06-07 15:27:21 +00:00
|
|
|
Scholar.DB.query(_getSchemaSQL());
|
2006-06-15 06:13:02 +00:00
|
|
|
_updateDBVersion('schema', _getSchemaSQLVersion());
|
2006-06-07 15:27:21 +00:00
|
|
|
Scholar.DB.query(_getSchemaSQL('scrapers'));
|
2006-06-15 06:13:02 +00:00
|
|
|
_updateDBVersion('scrapers', _getSchemaSQLVersion('scrapers'));
|
2006-06-07 14:35:04 +00:00
|
|
|
Scholar.DB.commitTransaction();
|
2006-06-07 01:02:59 +00:00
|
|
|
}
|
|
|
|
catch(e){
|
Addresses #17, add filesystem/ability to store files
Not finished, but enough to give David something to work with
No BLOBs -- just linking/importing of files and loaded documents
New Scholar.Item methods:
incrementFileCount() (used internally)
decrementFileCount() (used internally)
isFile()
numFiles()
getFile() -- returns nsILocalFile or false if associated file doesn't exist (note: always returns false for items with LINK_MODE_LINKED_URL, since they have no files -- use getFileURL() instead)
getFileURL() -- returns URL string
getFileLinkMode() -- compare to Scholar.Files.LINK_MODE_* constants: LINKED_FILE, IMPORTED_FILE, LINKED_URL, IMPORTED_URL
getFileMimeType() -- mime type of file (e.g. text/plain)
getFileCharset() -- charsetID of file
getFiles() -- array of file itemIDs this file is a source for
New Scholar.Files methods:
importFromFile(nsIFile file [, int sourceItemID])
linkFromFile(nsIFile file [, int sourceItemID])
importFromDocument(nsIDOMDocument document [, int sourceItemID])
linkFromDocument(nsIDOMDocument document [, int sourceItemID])
New class Scholar.FileTypes -- partially implemented, not yet used
New class Scholar.CharacterSets -- same as other *Types classes:
getID(idOrName)
getName(idOrName)
getTypes() (aliased to getAll(), which I'll probably change the others to as well)
Charsets table with all official character sets (copied from Mozilla source)
Renamed Item.setNoteSource() to setSource() and Item.getNoteSource() to getSource() and adjusted to handle both notes and files
2006-07-27 09:16:02 +00:00
|
|
|
Scholar.debug(e, 1);
|
|
|
|
alert('Error initializing Scholar database'); // TODO: localize
|
2006-06-07 14:35:04 +00:00
|
|
|
Scholar.DB.rollbackTransaction();
|
2006-06-07 01:02:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-07 15:27:21 +00:00
|
|
|
/*
|
|
|
|
* Update a DB schema version tag in an existing database
|
|
|
|
*/
|
|
|
|
function _updateDBVersion(schema, version){
|
2006-06-15 16:28:11 +00:00
|
|
|
_dbVersions[schema] = version;
|
2006-06-15 06:13:02 +00:00
|
|
|
var sql = "REPLACE INTO version (schema,version) VALUES (?,?)";
|
|
|
|
return Scholar.DB.query(sql, [{'string':schema},{'int':version}]);
|
2006-06-07 15:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the scrapers in the DB to the latest bundled versions
|
|
|
|
*/
|
2006-06-15 06:13:02 +00:00
|
|
|
function _updateScrapersLocal(){
|
2006-06-07 15:27:21 +00:00
|
|
|
var dbVersion = _getDBVersion('scrapers');
|
|
|
|
var schemaVersion = _getSchemaSQLVersion('scrapers');
|
|
|
|
|
|
|
|
if (dbVersion == schemaVersion){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (dbVersion < schemaVersion){
|
|
|
|
Scholar.DB.beginTransaction();
|
|
|
|
Scholar.DB.query(_getSchemaSQL('scrapers'));
|
|
|
|
_updateDBVersion('scrapers', schemaVersion);
|
|
|
|
Scholar.DB.commitTransaction();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw("Scraper set in DB is newer than schema version");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-15 06:13:02 +00:00
|
|
|
/**
|
|
|
|
* Process the response from the repository
|
|
|
|
**/
|
|
|
|
function _updateScrapersRemoteCallback(xmlhttp){
|
2006-06-25 20:14:11 +00:00
|
|
|
if (!xmlhttp.responseXML){
|
|
|
|
if (!xmlhttp.noNetwork){
|
|
|
|
Scholar.debug('Invalid response from repository', 2);
|
|
|
|
}
|
|
|
|
_setRepositoryTimer(SCHOLAR_CONFIG['REPOSITORY_RETRY_INTERVAL']);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-06-15 06:13:02 +00:00
|
|
|
var currentTime = xmlhttp.responseXML.
|
|
|
|
getElementsByTagName('currentTime')[0].firstChild.nodeValue;
|
2006-06-29 07:58:50 +00:00
|
|
|
var updates = xmlhttp.responseXML.getElementsByTagName('translator');
|
2006-06-15 06:13:02 +00:00
|
|
|
|
|
|
|
Scholar.DB.beginTransaction();
|
|
|
|
|
|
|
|
// Store the timestamp provided by the server
|
|
|
|
_updateDBVersion('repository', currentTime);
|
|
|
|
|
|
|
|
// And the local timestamp of the update time
|
|
|
|
var d = new Date();
|
2006-06-15 21:06:24 +00:00
|
|
|
_updateDBVersion('lastcheck', Math.round(d.getTime()/1000)); // JS uses ms
|
2006-06-15 06:13:02 +00:00
|
|
|
|
|
|
|
if (!updates.length){
|
|
|
|
Scholar.debug('All scrapers are up-to-date');
|
|
|
|
Scholar.DB.commitTransaction();
|
2006-06-15 21:06:24 +00:00
|
|
|
_setRepositoryTimer(SCHOLAR_CONFIG['REPOSITORY_CHECK_INTERVAL']);
|
2006-06-15 06:13:02 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i=0, len=updates.length; i<len; i++){
|
|
|
|
try {
|
|
|
|
_scraperXMLToDBQuery(updates[i]);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
Scholar.debug(e, 1);
|
|
|
|
Scholar.DB.rollbackTransaction();
|
|
|
|
var breakout = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!breakout){
|
|
|
|
Scholar.DB.commitTransaction();
|
2006-06-15 21:06:24 +00:00
|
|
|
_setRepositoryTimer(SCHOLAR_CONFIG['REPOSITORY_CHECK_INTERVAL']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the interval between repository queries
|
|
|
|
*
|
|
|
|
* We add an additional two seconds to avoid race conditions
|
|
|
|
**/
|
|
|
|
function _setRepositoryTimer(interval){
|
|
|
|
if (!interval){
|
|
|
|
interval = SCHOLAR_CONFIG['REPOSITORY_CHECK_INTERVAL'];
|
|
|
|
}
|
|
|
|
|
|
|
|
var fudge = 2; // two seconds
|
|
|
|
var displayInterval = interval + fudge;
|
|
|
|
var interval = (interval + fudge) * 1000; // convert to ms
|
|
|
|
|
|
|
|
if (!_repositoryTimer || _repositoryTimer.delay!=interval){
|
|
|
|
Scholar.debug('Setting repository check interval to ' + displayInterval + ' seconds');
|
|
|
|
_repositoryTimer = Components.classes["@mozilla.org/timer;1"].
|
|
|
|
createInstance(Components.interfaces.nsITimer);
|
|
|
|
_repositoryTimer.initWithCallback({
|
|
|
|
// implements nsITimerCallback
|
|
|
|
notify: function(timer){
|
|
|
|
Scholar.Schema.updateScrapersRemote();
|
|
|
|
}
|
|
|
|
}, interval, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK);
|
2006-06-15 06:13:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Traverse an XML scraper node from the repository and
|
|
|
|
* update the local scrapers table with the scraper data
|
|
|
|
**/
|
|
|
|
function _scraperXMLToDBQuery(xmlnode){
|
|
|
|
var sqlValues = [
|
|
|
|
{'string':xmlnode.getAttribute('id')},
|
2006-06-29 07:58:50 +00:00
|
|
|
{'string':xmlnode.getAttribute('lastUpdated')},
|
|
|
|
{'string':xmlnode.getAttribute('type')},
|
2006-06-15 06:13:02 +00:00
|
|
|
{'string':xmlnode.getElementsByTagName('label')[0].firstChild.nodeValue},
|
|
|
|
{'string':xmlnode.getElementsByTagName('creator')[0].firstChild.nodeValue},
|
2006-06-29 07:58:50 +00:00
|
|
|
// target
|
|
|
|
(xmlnode.getElementsByTagName('target').item(0) &&
|
|
|
|
xmlnode.getElementsByTagName('target')[0].firstChild)
|
|
|
|
? {'string':xmlnode.getElementsByTagName('target')[0].firstChild.nodeValue}
|
2006-06-15 06:13:02 +00:00
|
|
|
: {'null':true},
|
2006-06-29 07:58:50 +00:00
|
|
|
// detectCode can not exist or be empty
|
|
|
|
(xmlnode.getElementsByTagName('detectCode').item(0) &&
|
|
|
|
xmlnode.getElementsByTagName('detectCode')[0].firstChild)
|
|
|
|
? {'string':xmlnode.getElementsByTagName('detectCode')[0].firstChild.nodeValue}
|
|
|
|
: {'null':true},
|
|
|
|
{'string':xmlnode.getElementsByTagName('code')[0].firstChild.nodeValue}
|
2006-06-15 06:13:02 +00:00
|
|
|
]
|
|
|
|
|
2006-06-29 07:58:50 +00:00
|
|
|
var sql = "REPLACE INTO translators VALUES (?,?,?,?,?,?,?,?)";
|
2006-06-15 06:13:02 +00:00
|
|
|
return Scholar.DB.query(sql, sqlValues);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-07 01:02:59 +00:00
|
|
|
/*
|
|
|
|
* Migrate schema from an older version, preserving data
|
|
|
|
*/
|
|
|
|
function _migrateSchema(fromVersion){
|
|
|
|
//
|
|
|
|
// Change this value to match the schema version
|
|
|
|
//
|
2006-07-31 04:31:44 +00:00
|
|
|
var toVersion = 31;
|
2006-06-07 01:02:59 +00:00
|
|
|
|
|
|
|
if (toVersion != _getSchemaSQLVersion()){
|
|
|
|
throw('Schema version does not match version in _migrateSchema()');
|
|
|
|
}
|
|
|
|
|
|
|
|
Scholar.debug('Updating DB from version ' + fromVersion + ' to ' + toVersion + '\n');
|
|
|
|
|
|
|
|
Scholar.DB.beginTransaction();
|
|
|
|
|
|
|
|
// Step through version changes until we reach the current version
|
|
|
|
//
|
|
|
|
// Each block performs the changes necessary to move from the
|
|
|
|
// previous revision to that one.
|
2006-06-29 07:58:50 +00:00
|
|
|
for (var i=fromVersion + 1; i<=toVersion; i++){
|
Addresses #17, add filesystem/ability to store files
Not finished, but enough to give David something to work with
No BLOBs -- just linking/importing of files and loaded documents
New Scholar.Item methods:
incrementFileCount() (used internally)
decrementFileCount() (used internally)
isFile()
numFiles()
getFile() -- returns nsILocalFile or false if associated file doesn't exist (note: always returns false for items with LINK_MODE_LINKED_URL, since they have no files -- use getFileURL() instead)
getFileURL() -- returns URL string
getFileLinkMode() -- compare to Scholar.Files.LINK_MODE_* constants: LINKED_FILE, IMPORTED_FILE, LINKED_URL, IMPORTED_URL
getFileMimeType() -- mime type of file (e.g. text/plain)
getFileCharset() -- charsetID of file
getFiles() -- array of file itemIDs this file is a source for
New Scholar.Files methods:
importFromFile(nsIFile file [, int sourceItemID])
linkFromFile(nsIFile file [, int sourceItemID])
importFromDocument(nsIDOMDocument document [, int sourceItemID])
linkFromDocument(nsIDOMDocument document [, int sourceItemID])
New class Scholar.FileTypes -- partially implemented, not yet used
New class Scholar.CharacterSets -- same as other *Types classes:
getID(idOrName)
getName(idOrName)
getTypes() (aliased to getAll(), which I'll probably change the others to as well)
Charsets table with all official character sets (copied from Mozilla source)
Renamed Item.setNoteSource() to setSource() and Item.getNoteSource() to getSource() and adjusted to handle both notes and files
2006-07-27 09:16:02 +00:00
|
|
|
if (i==30){
|
|
|
|
// Remove old SQLite DB
|
|
|
|
var file = Scholar.getProfileDirectory();
|
|
|
|
file.append('scholar.sqlite');
|
|
|
|
if (file.exists()){
|
|
|
|
file.remove(null);
|
|
|
|
}
|
2006-07-31 04:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i==31){
|
2006-06-08 00:16:35 +00:00
|
|
|
_initializeSchema();
|
2006-06-07 01:02:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-07 15:27:21 +00:00
|
|
|
_updateDBVersion('schema', i-1);
|
2006-06-07 01:02:59 +00:00
|
|
|
Scholar.DB.commitTransaction();
|
|
|
|
}
|
|
|
|
}
|