<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[15075] CalendarServer/trunk/calendarserver/tools</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/15075">15075</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2015-08-28 08:52:40 -0700 (Fri, 28 Aug 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Cope with missing organizer events.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcalendarservertoolscalverifypy">CalendarServer/trunk/calendarserver/tools/calverify.py</a></li>
<li><a href="#CalendarServertrunkcalendarservertoolstesttest_calverifypy">CalendarServer/trunk/calendarserver/tools/test/test_calverify.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkcalendarservertoolscalverifypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/calverify.py (15074 => 15075)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tools/calverify.py        2015-08-27 20:29:31 UTC (rev 15074)
+++ CalendarServer/trunk/calendarserver/tools/calverify.py        2015-08-28 15:52:40 UTC (rev 15075)
</span><span class="lines">@@ -2760,7 +2760,7 @@
</span><span class="cx">             if fail:
</span><span class="cx">                 details.append(Details(resid, uid,))
</span><span class="cx">                 if self.fix:
</span><del>-                    yield self.fixCalendarData(cal, rname)
</del><ins>+                    yield self.fixCalendarData(cal, rname, resid)
</ins><span class="cx">                     fixed += 1
</span><span class="cx"> 
</span><span class="cx">             if self.options[&quot;verbose&quot;] and not self.options[&quot;summary&quot;]:
</span><span class="lines">@@ -2809,15 +2809,22 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def fixCalendarData(self, cal, rname):
</del><ins>+    def fixCalendarData(self, cal, rname, location_resid):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Fix problems in calendar data using store APIs.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><ins>+        result = True
+        message = &quot;&quot;
+
</ins><span class="cx">         # Extract organizer (strip off urn:x-uid:) and UID
</span><span class="cx">         organizer = cal.getOrganizer()[10:]
</span><span class="cx">         uid = cal.resourceUID()
</span><span class="cx">         _ignore_calendar, resid, _ignore_created, _ignore_modified = yield self.getCalendarForOwnerByUID(organizer, uid)
</span><ins>+        if resid is None:
+            # No organizer copy exists - it is safe to delete the location resource
+            yield self.removeEvent(location_resid)
+            returnValue((result, message,))
</ins><span class="cx"> 
</span><span class="cx">         # Get the organizer's calendar object and data
</span><span class="cx">         homeID, calendarID = yield self.getAllResourceInfoForResourceID(resid)
</span><span class="lines">@@ -2840,8 +2847,6 @@
</span><span class="cx">                 comp.addProperty(Property(&quot;LOCATION&quot;, rname))
</span><span class="cx"> 
</span><span class="cx">         # Write out fix, commit and get a new transaction
</span><del>-        result = True
-        message = &quot;&quot;
</del><span class="cx">         try:
</span><span class="cx">             yield calendarObj.setComponent(component)
</span><span class="cx">         except Exception, e:
</span></span></pre></div>
<a id="CalendarServertrunkcalendarservertoolstesttest_calverifypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/test/test_calverify.py (15074 => 15075)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tools/test/test_calverify.py        2015-08-27 20:29:31 UTC (rev 15074)
+++ CalendarServer/trunk/calendarserver/tools/test/test_calverify.py        2015-08-28 15:52:40 UTC (rev 15075)
</span><span class="lines">@@ -2856,10 +2856,77 @@
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> &quot;&quot;&quot;.replace(&quot;\n&quot;, &quot;\r\n&quot;) % subs
</span><span class="cx"> 
</span><ins>+    # Room as organizer event
+    ROOM_ORGANIZER_ICS = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100303T181216Z
+UID:ROOM_ORGANIZER_ICS
+TRANSP:OPAQUE
+SUMMARY:ROOM_ORGANIZER_ICS
+DTSTART:%(year)s%(month)02d08T120000Z
+DURATION:PT1H
+DTSTAMP:20100303T181220Z
+SEQUENCE:2
+ORGANIZER:urn:x-uid:%(uuidl1)s
+ATTENDEE:urn:x-uid:%(uuidl1)s
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.replace(&quot;\n&quot;, &quot;\r\n&quot;) % subs
+
+    # Room event without organizer
+    ROOM_NO_ORGANIZER_ICS = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100303T181216Z
+UID:ROOM_NO_ORGANIZER_ICS
+TRANSP:OPAQUE
+SUMMARY:ROOM_NO_ORGANIZER_ICS
+DTSTART:%(year)s%(month)02d08T120000Z
+DURATION:PT1H
+DTSTAMP:20100303T181220Z
+SEQUENCE:2
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.replace(&quot;\n&quot;, &quot;\r\n&quot;) % subs
+
+    # Invalid event with no organizer copt
+    ROOM_MISSING_ORGANIZER_ICS = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100303T181216Z
+UID:ROOM_MISSING_ORGANIZER_ICS
+TRANSP:OPAQUE
+SUMMARY:ROOM_MISSING_ORGANIZER_ICS
+DTSTART:%(year)s%(month)02d08T120000Z
+DURATION:PT1H
+DTSTAMP:20100303T181220Z
+SEQUENCE:2
+ORGANIZER:urn:x-uid:%(uuid1)s
+ATTENDEE:urn:x-uid:%(uuid1)s
+ATTENDEE:urn:x-uid:%(uuid2)s
+ATTENDEE:urn:x-uid:%(uuidl1)s
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.replace(&quot;\n&quot;, &quot;\r\n&quot;) % subs
+
</ins><span class="cx">     allEvents = {
</span><span class="cx">         &quot;invite1.ics&quot;      : (VALID_ICS, CalVerifyMismatchTestsBase.metadata,),
</span><span class="cx">         &quot;invite2.ics&quot;      : (INVALID_ICS, CalVerifyMismatchTestsBase.metadata,),
</span><span class="cx">     }
</span><ins>+    allEvents_Room = {
+        &quot;invite1.ics&quot;      : (VALID_ICS, CalVerifyMismatchTestsBase.metadata,),
+        &quot;invite2.ics&quot;      : (INVALID_ICS, CalVerifyMismatchTestsBase.metadata,),
+        &quot;invite3.ics&quot;      : (ROOM_ORGANIZER_ICS, CalVerifyMismatchTestsBase.metadata,),
+        &quot;invite4.ics&quot;      : (ROOM_NO_ORGANIZER_ICS, CalVerifyMismatchTestsBase.metadata,),
+        &quot;invite5.ics&quot;      : (ROOM_MISSING_ORGANIZER_ICS, CalVerifyMismatchTestsBase.metadata,),
+    }
</ins><span class="cx"> 
</span><span class="cx">     requirements = {
</span><span class="cx">         CalVerifyMismatchTestsBase.uuid1 : {
</span><span class="lines">@@ -2875,7 +2942,7 @@
</span><span class="cx">             &quot;inbox&quot; : {},
</span><span class="cx">         },
</span><span class="cx">         CalVerifyMismatchTestsBase.uuidl1 : {
</span><del>-            &quot;calendar&quot; : allEvents,
</del><ins>+            &quot;calendar&quot; : allEvents_Room,
</ins><span class="cx">             &quot;inbox&quot; : {},
</span><span class="cx">         },
</span><span class="cx">     }
</span><span class="lines">@@ -2918,9 +2985,9 @@
</span><span class="cx">         self.assertEqual(calverify.results[&quot;Number of events to process&quot;], len(self.requirements[CalVerifyMismatchTestsBase.uuidl1][&quot;calendar&quot;]))
</span><span class="cx">         self.assertEqual(
</span><span class="cx">             sorted([i.uid for i in calverify.results[&quot;Bad Events&quot;]]),
</span><del>-            [&quot;INVALID_ICS&quot;, ]
</del><ins>+            [&quot;INVALID_ICS&quot;, &quot;ROOM_MISSING_ORGANIZER_ICS&quot;, &quot;ROOM_ORGANIZER_ICS&quot;, ]
</ins><span class="cx">         )
</span><del>-        self.assertEqual(calverify.results[&quot;Number of bad events&quot;], 1)
</del><ins>+        self.assertEqual(calverify.results[&quot;Number of bad events&quot;], 3)
</ins><span class="cx">         self.assertTrue(&quot;Fix bad events&quot; not in calverify.results)
</span><span class="cx"> 
</span><span class="cx">         sync_token_newl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name=&quot;calendar&quot;)).syncToken())
</span><span class="lines">@@ -2972,10 +3039,10 @@
</span><span class="cx">         self.assertEqual(calverify.results[&quot;Number of events to process&quot;], len(self.requirements[CalVerifyMismatchTestsBase.uuidl1][&quot;calendar&quot;]))
</span><span class="cx">         self.assertEqual(
</span><span class="cx">             sorted([i.uid for i in calverify.results[&quot;Bad Events&quot;]]),
</span><del>-            [&quot;INVALID_ICS&quot;, ]
</del><ins>+            [&quot;INVALID_ICS&quot;, &quot;ROOM_MISSING_ORGANIZER_ICS&quot;, &quot;ROOM_ORGANIZER_ICS&quot;, ]
</ins><span class="cx">         )
</span><del>-        self.assertEqual(calverify.results[&quot;Number of bad events&quot;], 1)
-        self.assertEqual(calverify.results[&quot;Fix bad events&quot;], 1)
</del><ins>+        self.assertEqual(calverify.results[&quot;Number of bad events&quot;], 3)
+        self.assertEqual(calverify.results[&quot;Fix bad events&quot;], 3)
</ins><span class="cx"> 
</span><span class="cx">         sync_token_newl1 = (yield (yield self.calendarUnderTest(home=self.uuidl1, name=&quot;calendar&quot;)).syncToken())
</span><span class="cx">         self.assertNotEqual(sync_token_oldl1, sync_token_newl1)
</span><span class="lines">@@ -2990,7 +3057,7 @@
</span><span class="cx">         calverify = MissingLocationService(self._sqlCalendarStore, options, output, reactor, config)
</span><span class="cx">         yield calverify.doAction()
</span><span class="cx"> 
</span><del>-        self.assertEqual(calverify.results[&quot;Number of events to process&quot;], len(self.requirements[CalVerifyMismatchTestsBase.uuidl1][&quot;calendar&quot;]))
</del><ins>+        self.assertEqual(calverify.results[&quot;Number of events to process&quot;], len(self.requirements[CalVerifyMismatchTestsBase.uuidl1][&quot;calendar&quot;]) - 1)
</ins><span class="cx">         self.assertEqual(len(calverify.results[&quot;Bad Events&quot;]), 0)
</span><span class="cx">         self.assertTrue(&quot;Fix bad events&quot; not in calverify.results)
</span><span class="cx"> 
</span><span class="lines">@@ -2999,4 +3066,16 @@
</span><span class="cx">             calobj = yield self.calendarObjectUnderTest(home=uid, calendar_name=&quot;calendar&quot;, name=&quot;invite2.ics&quot;)
</span><span class="cx">             caldata = yield calobj.componentForUser()
</span><span class="cx">             self.assertTrue(&quot;LOCATION:&quot; in str(caldata))
</span><ins>+
+        calobj = yield self.calendarObjectUnderTest(home=uid, calendar_name=&quot;calendar&quot;, name=&quot;invite3.ics&quot;)
+        caldata = yield calobj.componentForUser()
+        self.assertTrue(&quot;LOCATION:&quot; in str(caldata))
+
+        calobj = yield self.calendarObjectUnderTest(home=uid, calendar_name=&quot;calendar&quot;, name=&quot;invite4.ics&quot;)
+        caldata = yield calobj.componentForUser()
+        self.assertTrue(&quot;LOCATION:&quot; not in str(caldata))
+
+        calobj = yield self.calendarObjectUnderTest(home=uid, calendar_name=&quot;calendar&quot;, name=&quot;invite5.ics&quot;)
+        self.assertTrue(calobj is None)
+
</ins><span class="cx">         yield self.commit()
</span></span></pre>
</div>
</div>

</body>
</html>