[Pkg-owncloud-commits] [php-sabre-vobject] 29/106: Some refactoring.

David Prévot taffit at moszumanska.debian.org
Fri Aug 22 15:10:58 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository php-sabre-vobject.

commit bbe9b0e4b9fe4e08998ee1b852ec34ed4cff497c
Author: Evert Pot <evert at rooftopsolutions.nl>
Date:   Wed Jul 23 14:22:13 2014 -0400

    Some refactoring.
---
 lib/Sabre/VObject/ITip/Broker.php | 162 ++++++++++++++++++++------------------
 1 file changed, 86 insertions(+), 76 deletions(-)

diff --git a/lib/Sabre/VObject/ITip/Broker.php b/lib/Sabre/VObject/ITip/Broker.php
index ba7ea8b..077a1f3 100644
--- a/lib/Sabre/VObject/ITip/Broker.php
+++ b/lib/Sabre/VObject/ITip/Broker.php
@@ -98,80 +98,8 @@ class Broker {
             case 'CANCEL' :
                 return $this->processMessageCancel($itipMessage, $existingObject);
 
-            /**
-             * The message is a reply. This is for example an attendee telling
-             * an organizer he accepted the invite, or declined it.
-             */
             case 'REPLY' :
-                // A reply can only be processed based on an existing object.
-                // If the object is not available, the reply is ignored.
-                if (!$existingObject) {
-                    return false;
-                }
-                $instances = array();
-                foreach($itipMessage->message->VEVENT as $vevent) {
-                    $recurId = isset($vevent->{'RECURRENCE-ID'})?$vevent->{'RECURRENCE-ID'}->getValue():'master';
-                    $attendee = $vevent->ATTENDEE;
-                    $instances[$recurId] = $attendee['PARTSTAT']->getValue();
-                }
-                $masterObject = null;
-                foreach($existingObject->VEVENT as $vevent) {
-                    $recurId = isset($vevent->{'RECURRENCE-ID'})?$vevent->{'RECURRENCE-ID'}->getValue():'master';
-                    if ($recurId==='master') {
-                        $masterObject = $vevent;
-                    }
-                    if (isset($instances[$recurId])) {
-                        $attendeeFound = false;
-                        foreach($vevent->ATTENDEE as $attendee) {
-                            if ($attendee->getValue() === $message->sender) {
-                                $attendeeFound = true;
-                                $attendee['PARTSTAT'] = $instances[$recurId];
-                                break;
-                            }
-                        }
-                        if (!$attendeeFound) {
-                            // Adding a new attendee
-                            $attendee = $vevent->add('ATTENDEE', $message->sender, array(
-                                'CN' => $message->senderName,
-                                'PARTSTAT' => $instances[$recurId]
-                            ));
-                        }
-                        unset($instances[$recurId]);
-                    }
-                }
-                // If we got replies to instances that did not exist in the
-                // original list, it means that new exceptions must be created.
-                foreach($instances as $recurId=>$partstat) {
-                    if(!$masterObject) {
-                        // No master object, we can't add new instances.
-                        return false;
-                    }
-                    $newObject = clone $masterObject;
-                    unset(
-                        $newObject->RRULE,
-                        $newObject->EXDATE,
-                        $newObject->RDATE
-                    );
-                    $newObject->{'RECURRENCE-ID'} = $recurId;
-                    $attendeeFound = false;
-                    foreach($vevent->ATTENDEE as $attendee) {
-                        if ($attendee->getValue() === $message->sender) {
-                            $attendeeFound = true;
-                            $attendee['PARTSTAT'] = $partstat;
-                            break;
-                        }
-                    }
-                    if (!$attendeeFound) {
-                        // Adding a new attendee
-                        $attendee = $vevent->add('ATTENDEE', $message->sender, array(
-                            'CN' => $message->senderName,
-                            'PARTSTAT' => $partstat
-                        ));
-                    }
-                    $existingObject->add($newObject);
-
-                }
-                break;
+                return $this->processMessageReply($itipMessage, $existingObject);
 
             default :
                 // Unsupported iTip message
@@ -263,7 +191,7 @@ class Broker {
      * @param VCalendar $existingObject
      * @return VCalendar|bool
      */
-    protected function processMessageRequest(Message $itipMessage, VCalendar $existingObject) {
+    protected function processMessageRequest(Message $itipMessage, VCalendar $existingObject = null) {
 
         if (!$existingObject) {
             // This is a new invite, and we're just going to copy over
@@ -298,7 +226,7 @@ class Broker {
      * @param VCalendar $existingObject
      * @return VCalendar|bool
      */
-    protected function processMessageCancel(Message $itipMessage, VCalendar $existingObject) {
+    protected function processMessageCancel(Message $itipMessage, VCalendar $existingObject = null) {
 
         if (!$existingObject) {
             // The event didn't exist in the first place, so we're just
@@ -309,8 +237,90 @@ class Broker {
                 $vevent->SEQUENCE = $itipMessage->sequence;
             }
         }
-        break;
+        return $existingObject;
+
+    }
+
+    /**
+     * Processes incoming REPLY messages.
+     *
+     * The message is a reply. This is for example an attendee telling
+     * an organizer he accepted the invite, or declined it.
+     *
+     * @param Message $itipMessage
+     * @param VCalendar $existingObject
+     * @return VCalendar|bool
+     */
+    protected function processMessageReply(Message $itipMessage, VCalendar $existingObject = null) {
+
+        // A reply can only be processed based on an existing object.
+        // If the object is not available, the reply is ignored.
+        if (!$existingObject) {
+            return false;
+        }
+        $instances = array();
+        foreach($itipMessage->message->VEVENT as $vevent) {
+            $recurId = isset($vevent->{'RECURRENCE-ID'})?$vevent->{'RECURRENCE-ID'}->getValue():'master';
+            $attendee = $vevent->ATTENDEE;
+            $instances[$recurId] = $attendee['PARTSTAT']->getValue();
+        }
+        $masterObject = null;
+        foreach($existingObject->VEVENT as $vevent) {
+            $recurId = isset($vevent->{'RECURRENCE-ID'})?$vevent->{'RECURRENCE-ID'}->getValue():'master';
+            if ($recurId==='master') {
+                $masterObject = $vevent;
+            }
+            if (isset($instances[$recurId])) {
+                $attendeeFound = false;
+                foreach($vevent->ATTENDEE as $attendee) {
+                    if ($attendee->getValue() === $message->sender) {
+                        $attendeeFound = true;
+                        $attendee['PARTSTAT'] = $instances[$recurId];
+                        break;
+                    }
+                }
+                if (!$attendeeFound) {
+                    // Adding a new attendee
+                    $attendee = $vevent->add('ATTENDEE', $message->sender, array(
+                        'CN' => $message->senderName,
+                        'PARTSTAT' => $instances[$recurId]
+                    ));
+                }
+                unset($instances[$recurId]);
+            }
+        }
+        // If we got replies to instances that did not exist in the
+        // original list, it means that new exceptions must be created.
+        foreach($instances as $recurId=>$partstat) {
+            if(!$masterObject) {
+                // No master object, we can't add new instances.
+                return false;
+            }
+            $newObject = clone $masterObject;
+            unset(
+                $newObject->RRULE,
+                $newObject->EXDATE,
+                $newObject->RDATE
+            );
+            $newObject->{'RECURRENCE-ID'} = $recurId;
+            $attendeeFound = false;
+            foreach($vevent->ATTENDEE as $attendee) {
+                if ($attendee->getValue() === $message->sender) {
+                    $attendeeFound = true;
+                    $attendee['PARTSTAT'] = $partstat;
+                    break;
+                }
+            }
+            if (!$attendeeFound) {
+                // Adding a new attendee
+                $attendee = $vevent->add('ATTENDEE', $message->sender, array(
+                    'CN' => $message->senderName,
+                    'PARTSTAT' => $partstat
+                ));
+            }
+            $existingObject->add($newObject);
 
+        }
         return $existingObject;
 
     }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabre-vobject.git



More information about the Pkg-owncloud-commits mailing list