25 Components.utils.import(
"resource://gre/modules/XPCOMUtils.jsm");
26 Components.utils.import(
"resource://app/jsmodules/SBJobUtils.jsm");
27 Components.utils.import(
"resource://app/jsmodules/sbLocalDatabaseMigrationUtils.jsm");
28 Components.utils.import(
"resource://app/jsmodules/sbProperties.jsm");
30 const Cc = Components.classes;
31 const Ci = Components.interfaces;
32 const Cr = Components.results;
38 dump(
"----++++----++++sbLibraryMigration " +
41 "\n----++++----++++\n");
46 SBLocalDatabaseMigrationUtils.BaseMigrationHandler.call(
this);
85 __proto__: SBLocalDatabaseMigrationUtils.BaseMigrationHandler.prototype,
88 classID: Components.ID(
"{d460596d-aa22-4bd4-ae83-e82fb5a70019}"),
89 contractID: SBLocalDatabaseMigrationUtils.baseHandlerContractID +
101 migrate:
function sbLibraryMigration_migrate(aLibrary) {
104 var sysInfo =
Cc[
"@mozilla.org/system-info;1"]
105 .getService(
Ci.nsIPropertyBag2);
106 var platform = sysInfo.getProperty(
"name");
109 this._databaseGUID = aLibrary.databaseGuid;
110 this._databaseLocation = aLibrary.databaseLocation;
113 if (platform ==
"Darwin") {
114 this._convertTopLevelURLPropertyValues(aLibrary,
"content_url");
115 this._convertNonTopLevelURLPropertyValues(aLibrary,
116 SBProperties.originURL);
117 this._convertNonTopLevelURLPropertyValues(aLibrary,
118 SBProperties.primaryImageURL);
122 var query = this.createMigrationQuery(aLibrary);
123 query.addQuery(
"commit");
124 query.setAsyncQuery(
false);
131 var
prefs =
Cc[
"@mozilla.org/preferences-service;1"]
132 .getService(
Ci.nsIPrefBranch);
133 prefs.setBoolPref(
"songbird.propertycache." +
134 this._databaseGUID +
".invalidSortData",
136 prefs.QueryInterface(
Ci.nsIPrefService).savePrefFile(
null);
139 LOG(
"Exception occured: " + e);
153 _convertTopLevelURLPropertyValues:
function
154 sbLibraryMigration__convertTopLevelURLPropertyValues(aLibrary,
157 var selectQueryStr = <>SELECT guid, {aPropertyName} FROM media_items
158 WHERE {aPropertyName} LIKE
"file:%"</>;
159 var updatePreparedQueryStr = <>UPDATE media_items
160 SET {aPropertyName} = ?
164 this._convertURLPropertyValues(aLibrary,
166 updatePreparedQueryStr);
178 _convertNonTopLevelURLPropertyValues:
function
179 sbLibraryMigration__convertNonTopLevelURLPropertyValues(aLibrary,
182 var propertyID = this._getPropertyID(aLibrary, aPropertyName);
185 var selectQueryStr = <>SELECT media_item_id, obj
186 FROM resource_properties
187 WHERE property_id =
"{propertyID}" AND
188 obj LIKE
"file:%"</>;
189 var updatePreparedQueryStr = <>UPDATE resource_properties
191 WHERE media_item_id = ? AND
192 property_id =
"{propertyID}"</>;
195 this._convertURLPropertyValues(aLibrary,
197 updatePreparedQueryStr);
216 _convertURLPropertyValues:
function
217 sbLibraryMigration__convertURLPropertyValues(aLibrary,
219 aUpdatePreparedQueryStr) {
221 var query =
Cc[
"@songbirdnest.com/Songbird/DatabaseQuery;1"]
222 .createInstance(
Ci.sbIDatabaseQuery);
223 query.databaseLocation = aLibrary.databaseLocation;
224 query.setDatabaseGUID(aLibrary.databaseGuid);
225 query.addQuery(aSelectQueryStr);
226 query.setAsyncQuery(
false);
227 if (query.execute() != 0)
228 throw "Media item fetch failed";
229 var result = query.getResultObject();
232 var preparedStatement;
235 this._total = result.getRowCount();
236 for (this._progress = 0; this._progress < this._total; ++this._progress) {
238 var
id = result.getRowCell(this._progress, 0);
239 var
url = result.getRowCell(this._progress, 1);
243 var convertedURL = this._convertURL(url);
244 if (!convertedURL || (convertedURL == url))
249 query =
Cc[
"@songbirdnest.com/Songbird/DatabaseQuery;1"]
250 .createInstance(
Ci.sbIDatabaseQuery);
251 query.databaseLocation = aLibrary.databaseLocation;
252 query.setDatabaseGUID(aLibrary.databaseGuid);
253 preparedStatement = query.prepareQuery(aUpdatePreparedQueryStr);
255 query.addPreparedStatement(preparedStatement);
256 query.bindStringParameter(0, convertedURL);
257 query.bindStringParameter(1,
id);
261 if (queryCount >= this.batchSize) {
262 query.setAsyncQuery(
false);
263 if (query.execute() != 0)
264 throw "Media item write failed";
271 if (query && (queryCount > 0)) {
272 query.setAsyncQuery(
false);
273 if (query.execute() != 0)
274 throw "Media item write failed";
288 _convertURL:
function sbLibraryMigration__convertURL(aURL) {
290 var
ioService =
Cc[
"@mozilla.org/network/io-service;1"]
291 .getService(
Ci.nsIIOService);
296 var fileURL = uri.QueryInterface(
Ci.nsIFileURL);
297 var convertedURL = ioService.newFileURI(fileURL.file).spec;
300 LOG(
"URL should have been a file URL: " + aURL +
": " + e);
318 _getPropertyID:
function sbLibraryMigration__getPropertyID(aLibrary,
321 var query =
Cc[
"@songbirdnest.com/Songbird/DatabaseQuery;1"]
322 .createInstance(
Ci.sbIDatabaseQuery);
323 query.databaseLocation = aLibrary.databaseLocation;
324 query.setDatabaseGUID(aLibrary.databaseGuid);
325 query.addQuery(<>SELECT property_id FROM properties
326 WHERE property_name =
"{aPropertyName}"</>);
327 query.setAsyncQuery(
false);
328 if (query.execute() != 0)
329 throw "Property ID query failed";
331 return query.getResultObject().getRowCell(0, 0);
336 get status()
Ci.sbIJobProgress.STATUS_RUNNING,
338 get progress() this._progress,
339 get total() this._total,
340 get errorCount() this._errors.length,
341 getErrorMessages:
function sbLibraryMigration_getErrorMessages()
342 ArrayConverter.StringEnumerator(this._errors),
345 get canCancel()
false,
346 cancel:
function sbLibraryMigration_cancel()
347 {
throw Cr.NS_ERROR_NOT_IMPLEMENTED }
354 return XPCOMUtils.generateModule([
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
function sbLibraryMigration()
sbDeviceFirmwareAutoCheckForUpdate prototype classID
function NSGetModule(compMgr, fileSpec)