Bug 862749 - B2G MMS: UpgradeSchema should also set defualt type to sms when the type is undefined. r=vyang, a=leo+
authorChia-hung Tai <ctai@mozilla.com>
Wed, 17 Apr 2013 22:18:23 +0800
changeset 119134 6c1d375a2e57416845664960a0284641d0e42e9e
parent 119133 09470bb4b4a74ddd26604f87da9d84311ebae973
child 119135 baafe342359045b520152704e4b26049e21cead9
push id691
push uservyang@mozilla.com
push dateFri, 19 Apr 2013 12:09:08 +0000
reviewersvyang, leo
bugs862749
milestone18.0
Bug 862749 - B2G MMS: UpgradeSchema should also set defualt type to sms when the type is undefined. r=vyang, a=leo+
dom/mobilemessage/src/ril/MobileMessageDatabaseService.js
--- a/dom/mobilemessage/src/ril/MobileMessageDatabaseService.js
+++ b/dom/mobilemessage/src/ril/MobileMessageDatabaseService.js
@@ -16,17 +16,17 @@ const RIL_MOBILEMESSAGEDATABASESERVICE_C
   Components.ID("{29785f90-6b5b-11e2-9201-3b280170b2ec}");
 const RIL_GETMESSAGESCURSOR_CID =
   Components.ID("{484d1ad8-840e-4782-9dc4-9ebc4d914937}");
 const RIL_GETTHREADSCURSOR_CID =
   Components.ID("{95ee7c3e-d6f2-4ec4-ade5-0c453c036d35}");
 
 const DEBUG = false;
 const DB_NAME = "sms";
-const DB_VERSION = 9;
+const DB_VERSION = 10;
 const MESSAGE_STORE_NAME = "sms";
 const THREAD_STORE_NAME = "thread";
 const PARTICIPANT_STORE_NAME = "participant";
 const MOST_RECENT_STORE_NAME = "most-recent";
 
 const DELIVERY_SENDING = "sending";
 const DELIVERY_SENT = "sent";
 const DELIVERY_RECEIVED = "received";
@@ -199,16 +199,20 @@ MobileMessageDatabaseService.prototype =
           case 7:
             if (DEBUG) debug("Upgrade to version 8. Add participant/thread stores.");
             self.upgradeSchema7(db, event.target.transaction);
             break;
           case 8:
             if (DEBUG) debug("Upgrade to version 9. Add transactionId index for incoming MMS.");
             self.upgradeSchema8(event.target.transaction);
             break;
+          case 9:
+            if (DEBUG) debug("Upgrade to version 10. Upgrade type if it's not existing.");
+            self.upgradeSchema9(event.target.transaction);
+            break;
           default:
             event.target.transaction.abort();
             callback("Old database version: " + event.oldVersion, null);
             break;
         }
         currentVersion++;
       }
     };
@@ -591,16 +595,35 @@ MobileMessageDatabaseService.prototype =
         messageRecord.transactionIdIndex =
           messageRecord.headers["x-mms-transaction-id"];
         cursor.update(messageRecord);
       }
       cursor.continue();
     };
   },
 
+  upgradeSchema9: function upgradeSchema9(transaction) {
+    let messageStore = transaction.objectStore(MESSAGE_STORE_NAME);
+
+    // Update type attributes.
+    messageStore.openCursor().onsuccess = function(event) {
+      let cursor = event.target.result;
+      if (!cursor) {
+        return;
+      }
+
+      let messageRecord = cursor.value;
+      if (messageRecord.type == undefined) {
+        messageRecord.type = "sms";
+        cursor.update(messageRecord);
+      }
+      cursor.continue();
+    };
+  },
+
   createDomMessageFromRecord: function createDomMessageFromRecord(aMessageRecord) {
     if (DEBUG) {
       debug("createDomMessageFromRecord: " + JSON.stringify(aMessageRecord));
     }
     if (aMessageRecord.type == "sms") {
       return gMobileMessageService.createSmsMessage(aMessageRecord.id,
                                                     aMessageRecord.threadId,
                                                     aMessageRecord.delivery,