[CalendarServer-changes] [14805] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Tue May 19 16:53:53 PDT 2015


Revision: 14805
          http://trac.calendarserver.org//changeset/14805
Author:   sagen at apple.com
Date:     2015-05-19 16:53:53 -0700 (Tue, 19 May 2015)
Log Message:
-----------
Allow recovery of all trashed events or collections

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/resource.py
    CalendarServer/trunk/txdav/common/datastore/sql.py

Modified: CalendarServer/trunk/twistedcaldav/resource.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/resource.py	2015-05-19 21:16:06 UTC (rev 14804)
+++ CalendarServer/trunk/twistedcaldav/resource.py	2015-05-19 23:53:53 UTC (rev 14805)
@@ -2758,7 +2758,21 @@
 
         elif action == "recovertrash":
             mode = request.args.get("mode", ("event",))[0]
-            recoveryID = int(request.args.get("id", ("0",))[0])
+            recoveryID = request.args.get("id", (None,))[0]
+            if recoveryID is None:
+                returnValue(
+                    self._ok("error", "Invalid id")
+                )
+            if recoveryID == "all":
+                recoveryID = None
+            else:
+                try:
+                    recoveryID = int(recoveryID)
+                except ValueError:
+                    returnValue(
+                        self._ok("error", "Invalid id")
+                    )
+
             yield self._newStoreHome.recoverTrash(mode, recoveryID)
             returnValue(
                 self._ok("ok", "Recover Trash")

Modified: CalendarServer/trunk/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql.py	2015-05-19 21:16:06 UTC (rev 14804)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py	2015-05-19 23:53:53 UTC (rev 14805)
@@ -3127,16 +3127,31 @@
         if trash is not None:
 
             if mode == "event":
-                child = yield trash.objectResourceWithID(recoveryID)
-                if child is not None:
-                    yield child.fromTrash()
-
+                if recoveryID:
+                    child = yield trash.objectResourceWithID(recoveryID)
+                    if child is not None:
+                        yield child.fromTrash()
+                else:
+                    # Recover all trashed events
+                    untrashedCollections = yield self.children(onlyInTrash=False)
+                    for collection in untrashedCollections:
+                        children = yield trash.trashForCollection(
+                            collection._resourceID
+                        )
+                        for child in children:
+                            yield child.fromTrash()
             else:
-                collection = yield self.childWithID(recoveryID, onlyInTrash=True)
-                if collection is not None:
-                    yield collection.fromTrash(
-                        restoreChildren=True, delta=datetime.timedelta(minutes=5)
-                    )
+                if recoveryID:
+                    collection = yield self.childWithID(recoveryID, onlyInTrash=True)
+                    if collection is not None:
+                        yield collection.fromTrash(
+                            restoreChildren=True, delta=datetime.timedelta(minutes=5)
+                        )
+                else:
+                    # Recover all trashed collections (and their events)
+                    trashedCollections = yield self.children(onlyInTrash=True)
+                    for collection in trashedCollections:
+                        yield collection.fromTrash(restoreChildren=True)
 
 
 class CommonHomeChild(FancyEqMixin, Memoizable, _SharedSyncLogic, HomeChildBase, SharingMixIn):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150519/bf2391f0/attachment.html>


More information about the calendarserver-changes mailing list