27 Components.utils.import(
"resource://gre/modules/XPCOMUtils.jsm");
28 Components.utils.import(
"resource://app/jsmodules/ArrayConverter.jsm");
29 Components.utils.import(
"resource://app/jsmodules/sbLocalDatabaseMigrationUtils.jsm");
30 Components.utils.import(
"resource://app/jsmodules/SBJobUtils.jsm");
31 Components.utils.import(
"resource://app/jsmodules/sbProperties.jsm");
33 const Cc = Components.classes;
34 const Ci = Components.interfaces;
35 const Cr = Components.results;
41 dump(
"----++++----++++sbLibraryMigration " +
44 "\n----++++----++++\n");
49 SBLocalDatabaseMigrationUtils.BaseMigrationHandler.call(
this);
58 __proto__: SBLocalDatabaseMigrationUtils.BaseMigrationHandler.prototype,
61 classID: Components.ID(
"{925d55b1-9fed-451b-857b-3cdb08150d8c}"),
62 contractID: SBLocalDatabaseMigrationUtils.baseHandlerContractID +
71 migrate:
function sbLibraryMigration_migrate(aLibrary) {
72 if (!(
"@songbirdnest.com/Songbird/MetadataHandler/WMA;1" in
Cc)) {
74 var query = this.createMigrationQuery(aLibrary);
75 query.addQuery(
"commit");
76 query.setAsyncQuery(
false);
77 if (query.execute() != 0) {
78 throw(
"Query failed: " + query.getLastError());
83 this.startNotificationTimer();
84 this._databaseGUID = aLibrary.databaseGuid;
85 this._databaseLocation = aLibrary.databaseLocation;
88 var query = Cc[
"@songbirdnest.com/Songbird/DatabaseQuery;1"]
89 .createInstance(
Ci.sbIDatabaseQuery);
90 query.databaseLocation = aLibrary.databaseLocation;
91 query.setDatabaseGUID(aLibrary.databaseGuid);
94 INSERT OR IGNORE INTO properties
95 (property_name) VALUES (
"{SBProperties.isDRMProtected}");</>);
97 SELECT property_id FROM properties
98 WHERE property_name =
"{SBProperties.isDRMProtected}";
100 query.setAsyncQuery(
false);
101 if (query.execute() != 0) {
102 throw "Failed to create property";
104 var propertyId = query.getResultObject().getRowCell(0, 0);
107 query = Cc[
"@songbirdnest.com/Songbird/DatabaseQuery;1"]
108 .createInstance(
Ci.sbIDatabaseQuery);
109 query.databaseLocation = aLibrary.databaseLocation;
110 query.setDatabaseGUID(aLibrary.databaseGuid);
113 INSERT OR REPLACE INTO resource_properties(
114 media_item_id, property_id, obj, obj_searchable, obj_sortable)
115 SELECT media_item_id,
"{propertyId}",
"1",
"1",
"1"
117 WHERE content_url LIKE
"%.m4p";
119 query.setAsyncQuery(
false);
120 if (query.execute() != 0) {
121 throw "Media item fetch failed";
125 query = Cc[
"@songbirdnest.com/Songbird/DatabaseQuery;1"]
126 .createInstance(
Ci.sbIDatabaseQuery);
127 query.databaseLocation = aLibrary.databaseLocation;
128 query.setDatabaseGUID(aLibrary.databaseGuid);
130 query.addQuery(<>SELECT guid, content_url FROM media_items
131 WHERE content_url LIKE
"file://%.wma"
133 query.setAsyncQuery(
false);
134 if (query.execute() != 0) {
135 throw "Media item fetch failed";
137 var result = query.getResultObject();
139 function addChunk(guids) {
141 INSERT OR REPLACE INTO resource_properties(
142 media_item_id, property_id, obj, obj_searchable, obj_sortable)
143 SELECT media_item_id,
"{propertyId}",
"1",
"1",
"1"
145 WHERE guid in (
"{guids.join('",
"')}");
150 var
handler = Cc[
"@songbirdnest.com/Songbird/MetadataHandler/WMA;1"]
151 .createInstance(
Ci.sbIMetadataHandlerWMA);
152 var
ioService = Cc[
"@mozilla.org/network/io-service;1"]
153 .getService(
Ci.nsIIOService);
154 this._total = result.getRowCount();
155 const CHUNK_SIZE = 1000;
158 query = this.createMigrationQuery(aLibrary);
159 for (this._progress = 0; this._progress < this._total; ++this._progress) {
160 let spec = result.getRowCell(this._progress, 1);
162 let
uri = ioService.newURI();
163 if (!(uri instanceof
Ci.nsIFileURL)) {
165 this._errors.push(spec);
169 if (!file.exists()) {
172 if (handler.isDRMProtected(file.path)) {
173 guids.push(result.getRowCell(
this._progress, 0));
177 this._errors.push(spec);
179 if (guids.length >= CHUNK_SIZE) {
180 query.addQuery(addChunk(guids));
185 if (guids.length > 0) {
186 query.addQuery(addChunk(guids));
188 query.addQuery(
"commit");
189 query.setAsyncQuery(
false);
190 if (query.execute() != 0) {
191 throw(
"Query failed: " + query.getLastError());
195 LOG(
"Exception occured: " + e);
199 this.stopNotificationTimer();
204 get status()
Ci.sbIJobProgress.STATUS_RUNNING,
206 get progress() this._progress,
207 get total() this._total,
208 get errorCount() this._errors.length,
209 getErrorMessages:
function sbLibMig20to21_getErrorMessages()
210 ArrayConverter.StringEnumerator(this._errors),
213 get canCancel()
false,
214 cancel:
function sbLibMig20to21_cancel() {
throw Cr.NS_ERROR_NOT_IMPLEMENTED }
221 return XPCOMUtils.generateModule([
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
function sbLibraryMigration()
function NSGetModule(compMgr, fileSpec)
sbDeviceFirmwareAutoCheckForUpdate prototype classID