Bug 1182264 - Possible dataloss after editing calendar properties;r+a=philipp
authorMakeMyDay <makemyday@gmx-topmail.de>
Wed, 15 Jul 2015 23:10:20 +0200
changeset 22835 89a926b8c66f0894652a64bac298f8534b23edbd
parent 22834 a38bd6d34748136d70e8614edf04a25ebe4748a3
child 22836 a74ee7be23a748cbca9488ca43a0fc2a948cd487
push id1443
push usermbanner@mozilla.com
push dateMon, 10 Aug 2015 18:31:17 +0000
treeherdercomm-beta@8fe07d686c22 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1182264
Bug 1182264 - Possible dataloss after editing calendar properties;r+a=philipp
calendar/base/src/calCalendarManager.js
calendar/resources/content/calendarCreation.js
--- a/calendar/base/src/calCalendarManager.js
+++ b/calendar/base/src/calCalendarManager.js
@@ -830,30 +830,37 @@ calMgrCalendarObserver.prototype = {
         }
     },
 
     changeCalendarCache: function(aCalendar, aName, aValue, aOldValue) {
         const cICM = Components.interfaces.calICalendarManager;
         aOldValue = aOldValue || false;
         aValue = aValue || false;
 
+        // hack for bug 1182264 to deal with calendars, which have set cache.enabled, but in fact do
+        // not support caching (like storage calendars) - this also prevents enabling cache again
+        if (!aCalendar.getProperty('cache.supported')) {
+            aCalendar.setProperty("cache.enabled", false);
+            return;
+        }
+
         if (aOldValue != aValue) {
             // Try to find the current sort order
             let sortOrderPref = Preferences.get("calendar.list.sortOrder", "").split(" ");
             let initialSortOrderPos = null;
             for (let i = 0; i < sortOrderPref.length; ++i) {
                 if (sortOrderPref[i] == aCalendar.id) {
                     initialSortOrderPos = i;
                 }
             }
             // Enabling or disabling cache on a calendar re-creates
             // it so the registerCalendar call can wrap/unwrap the
             // calCachedCalendar facade saving the user the need to
             // restart Thunderbird and making sure a new Id is used.
-            this.calMgr.removeCalendar(aCalendar, cICM.REMOVE_UNSUBSCRIBE);
+            this.calMgr.removeCalendar(aCalendar, cICM.REMOVE_NO_DELETE);
             var newCal = this.calMgr.createCalendar(aCalendar.type,aCalendar.uri);
             newCal.name = aCalendar.name;
 
             // TODO: if properties get added this list will need to be adjusted,
             // ideally we should add a "getProperties" method to calICalendar.idl
             // to retrieve all non-transient properties for a calendar.
             let propsToCopy = [ "color",
                                 "disabled",
--- a/calendar/resources/content/calendarCreation.js
+++ b/calendar/resources/content/calendarCreation.js
@@ -169,17 +169,18 @@ function prepareCreateCalendar() {
  */
 function doCreateCalendar() {
     let cal_name = document.getElementById("calendar-name").value;
     let cal_color = document.getElementById("calendar-color").value;
 
     gCalendar.name = cal_name;
     gCalendar.setProperty('color', cal_color);
     if (!gCalendar.getProperty("cache.always")) {
-        gCalendar.setProperty("cache.enabled", document.getElementById("cache").checked);
+        gCalendar.setProperty("cache.enabled", gCalendar.getProperty("cache.supported") !== false ?
+                                               document.getElementById("cache").checked : false);
     }
 
     if (!document.getElementById("fire-alarms").checked) {
         gCalendar.setProperty('suppressAlarms', true);
     }
 
     cal.getCalendarManager().registerCalendar(gCalendar);
     return true;