25 const Cc = Components.classes;
26 const Ci = Components.interfaces;
27 const Cr = Components.results;
28 const Cu = Components.utils;
30 Cu.import(
"resource://gre/modules/XPCOMUtils.jsm");
31 Cu.import(
"resource://app/jsmodules/sbLocalDatabaseMigrationUtils.jsm");
32 Cu.import(
"resource://app/jsmodules/SBJobUtils.jsm");
33 Cu.import(
"resource://app/jsmodules/sbProperties.jsm");
34 Cu.import(
"resource://app/jsmodules/GeneratorThread.jsm");
35 Cu.import(
"resource://app/jsmodules/sbLibraryUtils.jsm");
41 dump(
"----++++----++++sbLibraryMigration " +
44 "\n----++++----++++\n");
49 SBLocalDatabaseMigrationUtils.BaseMigrationHandler.call(
this);
54 this._contentMigrations = {
60 SBProperties.trackName,
61 SBProperties.artistName,
62 SBProperties.albumName,
75 SBProperties.trackName,
76 SBProperties.artistName,
77 SBProperties.albumName,
101 __proto__: SBLocalDatabaseMigrationUtils.BaseMigrationHandler.prototype,
104 classID: Components.ID(
"{4eba22e9-d657-4599-a181-b8340852e7a2}"),
105 contractID: SBLocalDatabaseMigrationUtils.baseHandlerContractID +
111 migrate:
function sbLibraryMigration_migrate(aLibrary) {
115 var sip =
Cc[
"@mozilla.org/supports-interface-pointer;1"]
116 .createInstance(
Ci.nsISupportsInterfacePointer);
124 this._thread.maxPctCPU = 95;
125 this._thread.period = 50;
126 this._thread.start();
129 SBJobUtils.showProgressDialog(sip.data,
null, 0);
132 processItems:
function sbLibraryMigration_processItems() {
134 this._databaseGUID = this.
_library.databaseGuid;
135 this._databaseLocation = this.
_library.databaseLocation;
138 this._titleText =
"Library Migration Helper";
139 this._statusText =
"Preparing to migrate 1.9 database to 1.10 database...";
140 yield this.checkIfShouldUpdateAndYield();
143 var query = this.createMigrationQuery(this.
_library);
144 query.addQuery(
"alter table media_items add column metadata_hash_identity");
145 query.addQuery(
"alter table library_media_item add column metadata_hash_identity");
146 query.addQuery(
"create index idx_media_items_metadata_hash_identity" +
147 "on media_items (metadata_hash_identity)");
149 query.addQuery(
"REINDEX");
150 query.addQuery(
"ANALYZE");
151 query.addQuery(
"COMMIT");
153 query.setAsyncQuery(
true);
159 for (var contentType in this._contentMigrations) {
160 yield this.hashExistingMediaItems(contentType);
164 dump(
"Exception occured: " + e);
169 hashExistingMediaItems:
function sbLibraryMigration_hashExistingMediaItems
174 var propNames = this._contentMigrations[contentType].props;
175 var propMap = this.getPropertyIDs(propNames);
177 var idService =
Cc[
"@songbirdnest.com/Songbird/IdentityService;1"]
178 .getService(
Ci.sbIIdentityService);
187 let selectSQL =
"SELECT media_items.guid, media_items.content_mime_type";
188 let fromSQL =
"FROM media_items"
190 let whereSQL =
"WHERE content_mime_type = '" + contentType +
"'" +
191 " AND media_items.is_list = '0'";
193 for (var
i = 0;
i < propNames.length;
i++) {
195 yield this.checkIfShouldUpdateAndYield();
197 var propID = propMap[propNames[
i]];
198 var resourcePropAlias =
'rp' +
i;
199 selectSQL +=
", " + resourcePropAlias +
".obj";
200 joinSQL +=
" LEFT OUTER JOIN resource_properties as " + resourcePropAlias +
201 " ON media_items.media_item_id = " +
202 resourcePropAlias +
".media_item_id" +
203 " AND " + resourcePropAlias +
".property_id = " + propID;
219 let sql = selectSQL +
" " +
223 var selectPropertiesQuery = this.createMigrationQuery(this.
_library);
224 selectPropertiesQuery.addQuery(sql);
228 selectPropertiesQuery.execute(retval);
235 var updateQuery = this.createMigrationQuery(this.
_library);
236 updateQuery.addQuery(
"BEGIN");
238 var preparedUpdateStatement = updateQuery.prepareQuery
239 (
"UPDATE media_items SET metadata_hash_identity = ? WHERE guid = ?");
243 var propertyResultSet = selectPropertiesQuery.getResultObject();
244 var colCount = propertyResultSet.getColumnCount();
245 var rowCount = propertyResultSet.getRowCount();
250 this._total = rowCount;
251 this._statusText =
"Migrating " + contentType +
" files in 1.9 database to 1.10 database...";
253 var idService =
Cc[
"@songbirdnest.com/Songbird/IdentityService;1"]
254 .getService(
Ci.sbIIdentityService);
255 for(let currentRow = 0; currentRow < rowCount; currentRow++) {
257 yield this.checkIfShouldUpdateAndYield();
259 var guid = propertyResultSet.getRowCell(currentRow, 0);
261 var hasHashableMetadata =
false;
262 var propsToHash = [];
265 for (let currentCol = 1; currentCol < colCount; currentCol++) {
266 let propVal = propertyResultSet.getRowCell(currentRow, currentCol);
269 propsToHash.push(propVal);
270 hasHashableMetadata =
true;
273 propsToHash.push(
"");
279 if (hasHashableMetadata) {
280 var stringToHash = propsToHash.join(this.separator);
281 var identity = idService.hashString(stringToHash);
282 updateQuery.addPreparedStatement(preparedUpdateStatement);
283 updateQuery.bindStringParameter(0, identity);
284 updateQuery.bindStringParameter(1, guid);
291 updateQuery.addQuery(
"commit");
292 updateQuery.execute(retval);
298 this._contentMigrations[contentType].completed =
true;
299 for (var contentType in this._contentMigrations) {
300 if (!this._contentMigrations[contentType].
completed) {
305 this._status =
Ci.sbIJobProgress.STATUS_SUCCEEDED;
306 this.notifyJobProgressListeners();
311 getPropertyIDs:
function sbLibraryMigration_getPropertyIDs(propertyNames) {
313 var sql =
"SELECT property_name, property_id FROM properties WHERE " +
315 sql += propertyNames.join(
"' OR property_name = '");
324 var query = this.createMigrationQuery(this.
_library);
328 query.execute(retval);
330 var resultSet = query.getResultObject();
336 var propertyIDs = [];
337 var rowCount = resultSet.getRowCount();
338 for(let currentRow = 0; currentRow < rowCount; ++currentRow) {
339 propName = resultSet.getRowCell(currentRow, 0);
340 propId = resultSet.getRowCell(currentRow, 1);
349 checkIfShouldUpdateAndYield:
function
350 sbLibraryMigration_checkIfShouldUpdateAndYield() {
355 this.notifyJobProgressListeners();
366 return this._progress;
377 return XPCOMUtils.generateModule([
function GeneratorThread(aEntryPoint)
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
function completed(cancel)
sbDeviceFirmwareAutoCheckForUpdate prototype classID
_getSelectedPageStyle s i
sbAutoDownloader prototype _library