Completed
Pull Request — master (#4212)
by Individual IT
13:52
created
apps/dav/lib/CalDAV/CalendarHome.php 1 patch
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -33,82 +33,82 @@
 block discarded – undo
33 33
 
34 34
 class CalendarHome extends \Sabre\CalDAV\CalendarHome {
35 35
 
36
-	/** @var \OCP\IL10N */
37
-	private $l10n;
36
+    /** @var \OCP\IL10N */
37
+    private $l10n;
38 38
 
39
-	public function __construct(BackendInterface $caldavBackend, $principalInfo) {
40
-		parent::__construct($caldavBackend, $principalInfo);
41
-		$this->l10n = \OC::$server->getL10N('dav');
42
-	}
39
+    public function __construct(BackendInterface $caldavBackend, $principalInfo) {
40
+        parent::__construct($caldavBackend, $principalInfo);
41
+        $this->l10n = \OC::$server->getL10N('dav');
42
+    }
43 43
 
44
-	/**
45
-	 * @return BackendInterface
46
-	 */
47
-	public function getCalDAVBackend() {
48
-		return $this->caldavBackend;
49
-	}
44
+    /**
45
+     * @return BackendInterface
46
+     */
47
+    public function getCalDAVBackend() {
48
+        return $this->caldavBackend;
49
+    }
50 50
 
51
-	/**
52
-	 * @inheritdoc
53
-	 */
54
-	function getChildren() {
55
-		$calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']);
56
-		$objects = [];
57
-		foreach ($calendars as $calendar) {
58
-			$objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n);
59
-		}
51
+    /**
52
+     * @inheritdoc
53
+     */
54
+    function getChildren() {
55
+        $calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']);
56
+        $objects = [];
57
+        foreach ($calendars as $calendar) {
58
+            $objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n);
59
+        }
60 60
 
61
-		if ($this->caldavBackend instanceof SchedulingSupport) {
62
-			$objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']);
63
-			$objects[] = new Outbox($this->principalInfo['uri']);
64
-		}
61
+        if ($this->caldavBackend instanceof SchedulingSupport) {
62
+            $objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']);
63
+            $objects[] = new Outbox($this->principalInfo['uri']);
64
+        }
65 65
 
66
-		// We're adding a notifications node, if it's supported by the backend.
67
-		if ($this->caldavBackend instanceof NotificationSupport) {
68
-			$objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
69
-		}
66
+        // We're adding a notifications node, if it's supported by the backend.
67
+        if ($this->caldavBackend instanceof NotificationSupport) {
68
+            $objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
69
+        }
70 70
 
71
-		// If the backend supports subscriptions, we'll add those as well,
72
-		if ($this->caldavBackend instanceof SubscriptionSupport) {
73
-			foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
74
-				$objects[] = new Subscription($this->caldavBackend, $subscription);
75
-			}
76
-		}
71
+        // If the backend supports subscriptions, we'll add those as well,
72
+        if ($this->caldavBackend instanceof SubscriptionSupport) {
73
+            foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
74
+                $objects[] = new Subscription($this->caldavBackend, $subscription);
75
+            }
76
+        }
77 77
 
78
-		return $objects;
79
-	}
78
+        return $objects;
79
+    }
80 80
 
81
-	/**
82
-	 * @inheritdoc
83
-	 */
84
-	function getChild($name) {
85
-		// Special nodes
86
-		if ($name === 'inbox' && $this->caldavBackend instanceof SchedulingSupport) {
87
-			return new Inbox($this->caldavBackend, $this->principalInfo['uri']);
88
-		}
89
-		if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) {
90
-			return new Outbox($this->principalInfo['uri']);
91
-		}
92
-		if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) {
93
-			return new \Sabre\CalDAv\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
94
-		}
81
+    /**
82
+     * @inheritdoc
83
+     */
84
+    function getChild($name) {
85
+        // Special nodes
86
+        if ($name === 'inbox' && $this->caldavBackend instanceof SchedulingSupport) {
87
+            return new Inbox($this->caldavBackend, $this->principalInfo['uri']);
88
+        }
89
+        if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) {
90
+            return new Outbox($this->principalInfo['uri']);
91
+        }
92
+        if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) {
93
+            return new \Sabre\CalDAv\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
94
+        }
95 95
 
96
-		// Calendars
97
-		foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) {
98
-			if ($calendar['uri'] === $name) {
99
-				return new Calendar($this->caldavBackend, $calendar, $this->l10n);
100
-			}
101
-		}
96
+        // Calendars
97
+        foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) {
98
+            if ($calendar['uri'] === $name) {
99
+                return new Calendar($this->caldavBackend, $calendar, $this->l10n);
100
+            }
101
+        }
102 102
 
103
-		if ($this->caldavBackend instanceof SubscriptionSupport) {
104
-			foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
105
-				if ($subscription['uri'] === $name) {
106
-					return new Subscription($this->caldavBackend, $subscription);
107
-				}
108
-			}
103
+        if ($this->caldavBackend instanceof SubscriptionSupport) {
104
+            foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
105
+                if ($subscription['uri'] === $name) {
106
+                    return new Subscription($this->caldavBackend, $subscription);
107
+                }
108
+            }
109 109
 
110
-		}
110
+        }
111 111
 
112
-		throw new NotFound('Node with name \'' . $name . '\' could not be found');
113
-	}
112
+        throw new NotFound('Node with name \'' . $name . '\' could not be found');
113
+    }
114 114
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/PublicCalendarRoot.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -25,43 +25,43 @@
 block discarded – undo
25 25
 
26 26
 class PublicCalendarRoot extends Collection {
27 27
 
28
-	/** @var CalDavBackend */
29
-	protected $caldavBackend;
28
+    /** @var CalDavBackend */
29
+    protected $caldavBackend;
30 30
 
31
-	/** @var \OCP\IL10N */
32
-	protected $l10n;
31
+    /** @var \OCP\IL10N */
32
+    protected $l10n;
33 33
 
34
-	function __construct(CalDavBackend $caldavBackend) {
35
-		$this->caldavBackend = $caldavBackend;
36
-		$this->l10n = \OC::$server->getL10N('dav');
37
-	}
34
+    function __construct(CalDavBackend $caldavBackend) {
35
+        $this->caldavBackend = $caldavBackend;
36
+        $this->l10n = \OC::$server->getL10N('dav');
37
+    }
38 38
 
39
-	/**
40
-	 * @inheritdoc
41
-	 */
42
-	function getName() {
43
-		return 'public-calendars';
44
-	}
39
+    /**
40
+     * @inheritdoc
41
+     */
42
+    function getName() {
43
+        return 'public-calendars';
44
+    }
45 45
 
46
-	/**
47
-	 * @inheritdoc
48
-	 */
49
-	function getChild($name) {
50
-		$calendar = $this->caldavBackend->getPublicCalendar($name);
51
-		return new Calendar($this->caldavBackend, $calendar, $this->l10n);
52
-	}
46
+    /**
47
+     * @inheritdoc
48
+     */
49
+    function getChild($name) {
50
+        $calendar = $this->caldavBackend->getPublicCalendar($name);
51
+        return new Calendar($this->caldavBackend, $calendar, $this->l10n);
52
+    }
53 53
 
54
-	/**
55
-	 * @inheritdoc
56
-	 */
57
-	function getChildren() {
58
-		$calendars = $this->caldavBackend->getPublicCalendars();
59
-		$children = [];
60
-		foreach ($calendars as $calendar) {
61
-			// TODO: maybe implement a new class PublicCalendar ???
62
-			$children[] = new Calendar($this->caldavBackend, $calendar, $this->l10n);
63
-		}
54
+    /**
55
+     * @inheritdoc
56
+     */
57
+    function getChildren() {
58
+        $calendars = $this->caldavBackend->getPublicCalendars();
59
+        $children = [];
60
+        foreach ($calendars as $calendar) {
61
+            // TODO: maybe implement a new class PublicCalendar ???
62
+            $children[] = new Calendar($this->caldavBackend, $calendar, $this->l10n);
63
+        }
64 64
 
65
-		return $children;
66
-	}
65
+        return $children;
66
+    }
67 67
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/Plugin.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -25,17 +25,17 @@
 block discarded – undo
25 25
 
26 26
 class Plugin extends \Sabre\CalDAV\Plugin {
27 27
 
28
-	/**
29
-	 * @inheritdoc
30
-	 */
31
-	function getCalendarHomeForPrincipal($principalUrl) {
28
+    /**
29
+     * @inheritdoc
30
+     */
31
+    function getCalendarHomeForPrincipal($principalUrl) {
32 32
 
33
-		if (strrpos($principalUrl, 'principals/users', -strlen($principalUrl)) !== false) {
34
-			list(, $principalId) = URLUtil::splitPath($principalUrl);
35
-			return self::CALENDAR_ROOT .'/' . $principalId;
36
-		}
33
+        if (strrpos($principalUrl, 'principals/users', -strlen($principalUrl)) !== false) {
34
+            list(, $principalId) = URLUtil::splitPath($principalUrl);
35
+            return self::CALENDAR_ROOT .'/' . $principalId;
36
+        }
37 37
 
38
-		return;
39
-	}
38
+        return;
39
+    }
40 40
 
41 41
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/CalendarObject.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -32,68 +32,68 @@
 block discarded – undo
32 32
 
33 33
 class CalendarObject extends \Sabre\CalDAV\CalendarObject {
34 34
 
35
-	/**
36
-	 * @inheritdoc
37
-	 */
38
-	function get() {
39
-		$data = parent::get();
40
-		if ($this->isShared() && $this->objectData['classification'] === CalDavBackend::CLASSIFICATION_CONFIDENTIAL) {
41
-			return $this->createConfidentialObject($data);
42
-		}
43
-		return $data;
44
-	}
35
+    /**
36
+     * @inheritdoc
37
+     */
38
+    function get() {
39
+        $data = parent::get();
40
+        if ($this->isShared() && $this->objectData['classification'] === CalDavBackend::CLASSIFICATION_CONFIDENTIAL) {
41
+            return $this->createConfidentialObject($data);
42
+        }
43
+        return $data;
44
+    }
45 45
 
46
-	private function isShared() {
47
-		if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
48
-			return false;
49
-		}
46
+    private function isShared() {
47
+        if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
48
+            return false;
49
+        }
50 50
 
51
-		return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri'];
52
-	}
51
+        return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri'];
52
+    }
53 53
 
54
-	/**
55
-	 * @param string $calData
56
-	 * @return string
57
-	 */
58
-	private static function createConfidentialObject($calData) {
54
+    /**
55
+     * @param string $calData
56
+     * @return string
57
+     */
58
+    private static function createConfidentialObject($calData) {
59 59
 
60
-		$vObject = Reader::read($calData);
60
+        $vObject = Reader::read($calData);
61 61
 
62
-		/** @var Component $vElement */
63
-		$vElement = null;
64
-		if(isset($vObject->VEVENT)) {
65
-			$vElement = $vObject->VEVENT;
66
-		}
67
-		if(isset($vObject->VJOURNAL)) {
68
-			$vElement = $vObject->VJOURNAL;
69
-		}
70
-		if(isset($vObject->VTODO)) {
71
-			$vElement = $vObject->VTODO;
72
-		}
73
-		if(!is_null($vElement)) {
74
-			foreach ($vElement->children() as &$property) {
75
-				/** @var Property $property */
76
-				switch($property->name) {
77
-					case 'CREATED':
78
-					case 'DTSTART':
79
-					case 'RRULE':
80
-					case 'DURATION':
81
-					case 'DTEND':
82
-					case 'CLASS':
83
-					case 'UID':
84
-						break;
85
-					case 'SUMMARY':
86
-						$property->setValue('Busy');
87
-						break;
88
-					default:
89
-						$vElement->__unset($property->name);
90
-						unset($property);
91
-						break;
92
-				}
93
-			}
94
-		}
62
+        /** @var Component $vElement */
63
+        $vElement = null;
64
+        if(isset($vObject->VEVENT)) {
65
+            $vElement = $vObject->VEVENT;
66
+        }
67
+        if(isset($vObject->VJOURNAL)) {
68
+            $vElement = $vObject->VJOURNAL;
69
+        }
70
+        if(isset($vObject->VTODO)) {
71
+            $vElement = $vObject->VTODO;
72
+        }
73
+        if(!is_null($vElement)) {
74
+            foreach ($vElement->children() as &$property) {
75
+                /** @var Property $property */
76
+                switch($property->name) {
77
+                    case 'CREATED':
78
+                    case 'DTSTART':
79
+                    case 'RRULE':
80
+                    case 'DURATION':
81
+                    case 'DTEND':
82
+                    case 'CLASS':
83
+                    case 'UID':
84
+                        break;
85
+                    case 'SUMMARY':
86
+                        $property->setValue('Busy');
87
+                        break;
88
+                    default:
89
+                        $vElement->__unset($property->name);
90
+                        unset($property);
91
+                        break;
92
+                }
93
+            }
94
+        }
95 95
 		
96
-		return $vObject->serialize();
97
-	}
96
+        return $vObject->serialize();
97
+    }
98 98
 
99 99
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/BirthdayService.php 1 patch
Indentation   +232 added lines, -232 removed lines patch added patch discarded remove patch
@@ -39,256 +39,256 @@
 block discarded – undo
39 39
 
40 40
 class BirthdayService {
41 41
 
42
-	const BIRTHDAY_CALENDAR_URI = 'contact_birthdays';
42
+    const BIRTHDAY_CALENDAR_URI = 'contact_birthdays';
43 43
 
44
-	/** @var GroupPrincipalBackend */
45
-	private $principalBackend;
44
+    /** @var GroupPrincipalBackend */
45
+    private $principalBackend;
46 46
 
47
-	/** @var CalDavBackend  */
48
-	private $calDavBackEnd;
47
+    /** @var CalDavBackend  */
48
+    private $calDavBackEnd;
49 49
 
50
-	/** @var CardDavBackend  */
51
-	private $cardDavBackEnd;
50
+    /** @var CardDavBackend  */
51
+    private $cardDavBackEnd;
52 52
 
53
-	/**
54
-	 * BirthdayService constructor.
55
-	 *
56
-	 * @param CalDavBackend $calDavBackEnd
57
-	 * @param CardDavBackend $cardDavBackEnd
58
-	 * @param GroupPrincipalBackend $principalBackend
59
-	 */
60
-	public function __construct(CalDavBackend $calDavBackEnd, CardDavBackend $cardDavBackEnd, GroupPrincipalBackend $principalBackend) {
61
-		$this->calDavBackEnd = $calDavBackEnd;
62
-		$this->cardDavBackEnd = $cardDavBackEnd;
63
-		$this->principalBackend = $principalBackend;
64
-	}
53
+    /**
54
+     * BirthdayService constructor.
55
+     *
56
+     * @param CalDavBackend $calDavBackEnd
57
+     * @param CardDavBackend $cardDavBackEnd
58
+     * @param GroupPrincipalBackend $principalBackend
59
+     */
60
+    public function __construct(CalDavBackend $calDavBackEnd, CardDavBackend $cardDavBackEnd, GroupPrincipalBackend $principalBackend) {
61
+        $this->calDavBackEnd = $calDavBackEnd;
62
+        $this->cardDavBackEnd = $cardDavBackEnd;
63
+        $this->principalBackend = $principalBackend;
64
+    }
65 65
 
66
-	/**
67
-	 * @param int $addressBookId
68
-	 * @param string $cardUri
69
-	 * @param string $cardData
70
-	 */
71
-	public function onCardChanged($addressBookId, $cardUri, $cardData) {
72
-		$targetPrincipals = $this->getAllAffectedPrincipals($addressBookId);
66
+    /**
67
+     * @param int $addressBookId
68
+     * @param string $cardUri
69
+     * @param string $cardData
70
+     */
71
+    public function onCardChanged($addressBookId, $cardUri, $cardData) {
72
+        $targetPrincipals = $this->getAllAffectedPrincipals($addressBookId);
73 73
 		
74
-		$book = $this->cardDavBackEnd->getAddressBookById($addressBookId);
75
-		$targetPrincipals[] = $book['principaluri'];
76
-		$datesToSync = [
77
-			['postfix' => '', 'field' => 'BDAY', 'symbol' => '*'],
78
-			['postfix' => '-death', 'field' => 'DEATHDATE', 'symbol' => "†"],
79
-			['postfix' => '-anniversary', 'field' => 'ANNIVERSARY', 'symbol' => "⚭"],
80
-		];
81
-		foreach ($targetPrincipals as $principalUri) {
82
-			$calendar = $this->ensureCalendarExists($principalUri);
83
-			foreach ($datesToSync as $type) {
84
-				$this->updateCalendar($cardUri, $cardData, $book, $calendar['id'], $type);
85
-			}
86
-		}
87
-	}
74
+        $book = $this->cardDavBackEnd->getAddressBookById($addressBookId);
75
+        $targetPrincipals[] = $book['principaluri'];
76
+        $datesToSync = [
77
+            ['postfix' => '', 'field' => 'BDAY', 'symbol' => '*'],
78
+            ['postfix' => '-death', 'field' => 'DEATHDATE', 'symbol' => "†"],
79
+            ['postfix' => '-anniversary', 'field' => 'ANNIVERSARY', 'symbol' => "⚭"],
80
+        ];
81
+        foreach ($targetPrincipals as $principalUri) {
82
+            $calendar = $this->ensureCalendarExists($principalUri);
83
+            foreach ($datesToSync as $type) {
84
+                $this->updateCalendar($cardUri, $cardData, $book, $calendar['id'], $type);
85
+            }
86
+        }
87
+    }
88 88
 
89
-	/**
90
-	 * @param int $addressBookId
91
-	 * @param string $cardUri
92
-	 */
93
-	public function onCardDeleted($addressBookId, $cardUri) {
94
-		$targetPrincipals = $this->getAllAffectedPrincipals($addressBookId);
95
-		$book = $this->cardDavBackEnd->getAddressBookById($addressBookId);
96
-		$targetPrincipals[] = $book['principaluri'];
97
-		foreach ($targetPrincipals as $principalUri) {
98
-			$calendar = $this->ensureCalendarExists($principalUri);
99
-			foreach (['', '-death', '-anniversary'] as $tag) {
100
-				$objectUri = $book['uri'] . '-' . $cardUri . $tag .'.ics';
101
-				$this->calDavBackEnd->deleteCalendarObject($calendar['id'], $objectUri);
102
-			}
103
-		}
104
-	}
89
+    /**
90
+     * @param int $addressBookId
91
+     * @param string $cardUri
92
+     */
93
+    public function onCardDeleted($addressBookId, $cardUri) {
94
+        $targetPrincipals = $this->getAllAffectedPrincipals($addressBookId);
95
+        $book = $this->cardDavBackEnd->getAddressBookById($addressBookId);
96
+        $targetPrincipals[] = $book['principaluri'];
97
+        foreach ($targetPrincipals as $principalUri) {
98
+            $calendar = $this->ensureCalendarExists($principalUri);
99
+            foreach (['', '-death', '-anniversary'] as $tag) {
100
+                $objectUri = $book['uri'] . '-' . $cardUri . $tag .'.ics';
101
+                $this->calDavBackEnd->deleteCalendarObject($calendar['id'], $objectUri);
102
+            }
103
+        }
104
+    }
105 105
 
106
-	/**
107
-	 * @param string $principal
108
-	 * @return array|null
109
-	 * @throws \Sabre\DAV\Exception\BadRequest
110
-	 */
111
-	public function ensureCalendarExists($principal) {
112
-		$book = $this->calDavBackEnd->getCalendarByUri($principal, self::BIRTHDAY_CALENDAR_URI);
113
-		if (!is_null($book)) {
114
-			return $book;
115
-		}
116
-		$this->calDavBackEnd->createCalendar($principal, self::BIRTHDAY_CALENDAR_URI, [
117
-			'{DAV:}displayname' => 'Contact birthdays',
118
-			'{http://apple.com/ns/ical/}calendar-color' => '#FFFFCA',
119
-			'components'   => 'VEVENT',
120
-		]);
106
+    /**
107
+     * @param string $principal
108
+     * @return array|null
109
+     * @throws \Sabre\DAV\Exception\BadRequest
110
+     */
111
+    public function ensureCalendarExists($principal) {
112
+        $book = $this->calDavBackEnd->getCalendarByUri($principal, self::BIRTHDAY_CALENDAR_URI);
113
+        if (!is_null($book)) {
114
+            return $book;
115
+        }
116
+        $this->calDavBackEnd->createCalendar($principal, self::BIRTHDAY_CALENDAR_URI, [
117
+            '{DAV:}displayname' => 'Contact birthdays',
118
+            '{http://apple.com/ns/ical/}calendar-color' => '#FFFFCA',
119
+            'components'   => 'VEVENT',
120
+        ]);
121 121
 
122
-		return $this->calDavBackEnd->getCalendarByUri($principal, self::BIRTHDAY_CALENDAR_URI);
123
-	}
122
+        return $this->calDavBackEnd->getCalendarByUri($principal, self::BIRTHDAY_CALENDAR_URI);
123
+    }
124 124
 
125
-	/**
126
-	 * @param string $cardData
127
-	 * @param string $dateField
128
-	 * @param string $summarySymbol
129
-	 * @return null|VCalendar
130
-	 */
131
-	public function buildDateFromContact($cardData, $dateField, $summarySymbol) {
132
-		if (empty($cardData)) {
133
-			return null;
134
-		}
135
-		try {
136
-			$doc = Reader::read($cardData);
137
-			// We're always converting to vCard 4.0 so we can rely on the
138
-			// VCardConverter handling the X-APPLE-OMIT-YEAR property for us.
139
-			if (!$doc instanceof VCard) {
140
-				return null;
141
-			}
142
-			$doc = $doc->convert(Document::VCARD40);
143
-		} catch (Exception $e) {
144
-			return null;
145
-		}
125
+    /**
126
+     * @param string $cardData
127
+     * @param string $dateField
128
+     * @param string $summarySymbol
129
+     * @return null|VCalendar
130
+     */
131
+    public function buildDateFromContact($cardData, $dateField, $summarySymbol) {
132
+        if (empty($cardData)) {
133
+            return null;
134
+        }
135
+        try {
136
+            $doc = Reader::read($cardData);
137
+            // We're always converting to vCard 4.0 so we can rely on the
138
+            // VCardConverter handling the X-APPLE-OMIT-YEAR property for us.
139
+            if (!$doc instanceof VCard) {
140
+                return null;
141
+            }
142
+            $doc = $doc->convert(Document::VCARD40);
143
+        } catch (Exception $e) {
144
+            return null;
145
+        }
146 146
 
147
-		if (!isset($doc->{$dateField})) {
148
-			return null;
149
-		}
150
-		if (!isset($doc->FN)) {
151
-			return null;
152
-		}
153
-		$birthday = $doc->{$dateField};
154
-		if (!(string)$birthday) {
155
-			return null;
156
-		}
157
-		// Skip if the BDAY property is not of the right type.
158
-		if (!$birthday instanceof DateAndOrTime) {
159
-			return null;
160
-		}
147
+        if (!isset($doc->{$dateField})) {
148
+            return null;
149
+        }
150
+        if (!isset($doc->FN)) {
151
+            return null;
152
+        }
153
+        $birthday = $doc->{$dateField};
154
+        if (!(string)$birthday) {
155
+            return null;
156
+        }
157
+        // Skip if the BDAY property is not of the right type.
158
+        if (!$birthday instanceof DateAndOrTime) {
159
+            return null;
160
+        }
161 161
 
162
-		// Skip if we can't parse the BDAY value.
163
-		try {
164
-			$dateParts = DateTimeParser::parseVCardDateTime($birthday->getValue());
165
-		} catch (InvalidDataException $e) {
166
-			return null;
167
-		}
162
+        // Skip if we can't parse the BDAY value.
163
+        try {
164
+            $dateParts = DateTimeParser::parseVCardDateTime($birthday->getValue());
165
+        } catch (InvalidDataException $e) {
166
+            return null;
167
+        }
168 168
 
169
-		$unknownYear = false;
170
-		if (!$dateParts['year']) {
171
-			$birthday = '1900-' . $dateParts['month'] . '-' . $dateParts['date'];
169
+        $unknownYear = false;
170
+        if (!$dateParts['year']) {
171
+            $birthday = '1900-' . $dateParts['month'] . '-' . $dateParts['date'];
172 172
 
173
-			$unknownYear = true;
174
-		}
173
+            $unknownYear = true;
174
+        }
175 175
 
176
-		try {
177
-			$date = new \DateTime($birthday);
178
-		} catch (Exception $e) {
179
-			return null;
180
-		}
181
-		if ($unknownYear) {
182
-			$summary = $doc->FN->getValue() . ' ' . $summarySymbol;
183
-		} else {
184
-			$year = (int)$date->format('Y');
185
-			$summary = $doc->FN->getValue() . " ($summarySymbol$year)";
186
-		}
187
-		$vCal = new VCalendar();
188
-		$vCal->VERSION = '2.0';
189
-		$vEvent = $vCal->createComponent('VEVENT');
190
-		$vEvent->add('DTSTART');
191
-		$vEvent->DTSTART->setDateTime(
192
-			$date
193
-		);
194
-		$vEvent->DTSTART['VALUE'] = 'DATE';
195
-		$vEvent->add('DTEND');
196
-		$date->add(new \DateInterval('P1D'));
197
-		$vEvent->DTEND->setDateTime(
198
-			$date
199
-		);
200
-		$vEvent->DTEND['VALUE'] = 'DATE';
201
-		$vEvent->{'UID'} = $doc->UID;
202
-		$vEvent->{'RRULE'} = 'FREQ=YEARLY';
203
-		$vEvent->{'SUMMARY'} = $summary;
204
-		$vEvent->{'TRANSP'} = 'TRANSPARENT';
205
-		$alarm = $vCal->createComponent('VALARM');
206
-		$alarm->add($vCal->createProperty('TRIGGER', '-PT0M', ['VALUE' => 'DURATION']));
207
-		$alarm->add($vCal->createProperty('ACTION', 'DISPLAY'));
208
-		$alarm->add($vCal->createProperty('DESCRIPTION', $vEvent->{'SUMMARY'}));
209
-		$vEvent->add($alarm);
210
-		$vCal->add($vEvent);
211
-		return $vCal;
212
-	}
176
+        try {
177
+            $date = new \DateTime($birthday);
178
+        } catch (Exception $e) {
179
+            return null;
180
+        }
181
+        if ($unknownYear) {
182
+            $summary = $doc->FN->getValue() . ' ' . $summarySymbol;
183
+        } else {
184
+            $year = (int)$date->format('Y');
185
+            $summary = $doc->FN->getValue() . " ($summarySymbol$year)";
186
+        }
187
+        $vCal = new VCalendar();
188
+        $vCal->VERSION = '2.0';
189
+        $vEvent = $vCal->createComponent('VEVENT');
190
+        $vEvent->add('DTSTART');
191
+        $vEvent->DTSTART->setDateTime(
192
+            $date
193
+        );
194
+        $vEvent->DTSTART['VALUE'] = 'DATE';
195
+        $vEvent->add('DTEND');
196
+        $date->add(new \DateInterval('P1D'));
197
+        $vEvent->DTEND->setDateTime(
198
+            $date
199
+        );
200
+        $vEvent->DTEND['VALUE'] = 'DATE';
201
+        $vEvent->{'UID'} = $doc->UID;
202
+        $vEvent->{'RRULE'} = 'FREQ=YEARLY';
203
+        $vEvent->{'SUMMARY'} = $summary;
204
+        $vEvent->{'TRANSP'} = 'TRANSPARENT';
205
+        $alarm = $vCal->createComponent('VALARM');
206
+        $alarm->add($vCal->createProperty('TRIGGER', '-PT0M', ['VALUE' => 'DURATION']));
207
+        $alarm->add($vCal->createProperty('ACTION', 'DISPLAY'));
208
+        $alarm->add($vCal->createProperty('DESCRIPTION', $vEvent->{'SUMMARY'}));
209
+        $vEvent->add($alarm);
210
+        $vCal->add($vEvent);
211
+        return $vCal;
212
+    }
213 213
 
214
-	/**
215
-	 * @param string $user
216
-	 */
217
-	public function syncUser($user) {
218
-		$principal = 'principals/users/'.$user;
219
-		$this->ensureCalendarExists($principal);
220
-		$books = $this->cardDavBackEnd->getAddressBooksForUser($principal);
221
-		foreach($books as $book) {
222
-			$cards = $this->cardDavBackEnd->getCards($book['id']);
223
-			foreach($cards as $card) {
224
-				$this->onCardChanged($book['id'], $card['uri'], $card['carddata']);
225
-			}
226
-		}
227
-	}
214
+    /**
215
+     * @param string $user
216
+     */
217
+    public function syncUser($user) {
218
+        $principal = 'principals/users/'.$user;
219
+        $this->ensureCalendarExists($principal);
220
+        $books = $this->cardDavBackEnd->getAddressBooksForUser($principal);
221
+        foreach($books as $book) {
222
+            $cards = $this->cardDavBackEnd->getCards($book['id']);
223
+            foreach($cards as $card) {
224
+                $this->onCardChanged($book['id'], $card['uri'], $card['carddata']);
225
+            }
226
+        }
227
+    }
228 228
 
229
-	/**
230
-	 * @param string $existingCalendarData
231
-	 * @param VCalendar $newCalendarData
232
-	 * @return bool
233
-	 */
234
-	public function birthdayEvenChanged($existingCalendarData, $newCalendarData) {
235
-		try {
236
-			$existingBirthday = Reader::read($existingCalendarData);
237
-		} catch (Exception $ex) {
238
-			return true;
239
-		}
240
-		if ($newCalendarData->VEVENT->DTSTART->getValue() !== $existingBirthday->VEVENT->DTSTART->getValue() ||
241
-			$newCalendarData->VEVENT->SUMMARY->getValue() !== $existingBirthday->VEVENT->SUMMARY->getValue()
242
-		) {
243
-			return true;
244
-		}
245
-		return false;
246
-	}
229
+    /**
230
+     * @param string $existingCalendarData
231
+     * @param VCalendar $newCalendarData
232
+     * @return bool
233
+     */
234
+    public function birthdayEvenChanged($existingCalendarData, $newCalendarData) {
235
+        try {
236
+            $existingBirthday = Reader::read($existingCalendarData);
237
+        } catch (Exception $ex) {
238
+            return true;
239
+        }
240
+        if ($newCalendarData->VEVENT->DTSTART->getValue() !== $existingBirthday->VEVENT->DTSTART->getValue() ||
241
+            $newCalendarData->VEVENT->SUMMARY->getValue() !== $existingBirthday->VEVENT->SUMMARY->getValue()
242
+        ) {
243
+            return true;
244
+        }
245
+        return false;
246
+    }
247 247
 
248
-	/**
249
-	 * @param integer $addressBookId
250
-	 * @return mixed
251
-	 */
252
-	protected function getAllAffectedPrincipals($addressBookId) {
253
-		$targetPrincipals = [];
254
-		$shares = $this->cardDavBackEnd->getShares($addressBookId);
255
-		foreach ($shares as $share) {
256
-			if ($share['{http://owncloud.org/ns}group-share']) {
257
-				$users = $this->principalBackend->getGroupMemberSet($share['{http://owncloud.org/ns}principal']);
258
-				foreach ($users as $user) {
259
-					$targetPrincipals[] = $user['uri'];
260
-				}
261
-			} else {
262
-				$targetPrincipals[] = $share['{http://owncloud.org/ns}principal'];
263
-			}
264
-		}
265
-		return array_values(array_unique($targetPrincipals, SORT_STRING));
266
-	}
248
+    /**
249
+     * @param integer $addressBookId
250
+     * @return mixed
251
+     */
252
+    protected function getAllAffectedPrincipals($addressBookId) {
253
+        $targetPrincipals = [];
254
+        $shares = $this->cardDavBackEnd->getShares($addressBookId);
255
+        foreach ($shares as $share) {
256
+            if ($share['{http://owncloud.org/ns}group-share']) {
257
+                $users = $this->principalBackend->getGroupMemberSet($share['{http://owncloud.org/ns}principal']);
258
+                foreach ($users as $user) {
259
+                    $targetPrincipals[] = $user['uri'];
260
+                }
261
+            } else {
262
+                $targetPrincipals[] = $share['{http://owncloud.org/ns}principal'];
263
+            }
264
+        }
265
+        return array_values(array_unique($targetPrincipals, SORT_STRING));
266
+    }
267 267
 
268
-	/**
269
-	 * @param string $cardUri
270
-	 * @param string  $cardData
271
-	 * @param array $book
272
-	 * @param int $calendarId
273
-	 * @param string $type
274
-	 */
275
-	private function updateCalendar($cardUri, $cardData, $book, $calendarId, $type) {
276
-		$objectUri = $book['uri'] . '-' . $cardUri . $type['postfix'] . '.ics';
277
-		$calendarData = $this->buildDateFromContact($cardData, $type['field'], $type['symbol']);
278
-		$existing = $this->calDavBackEnd->getCalendarObject($calendarId, $objectUri);
279
-		if (is_null($calendarData)) {
280
-			if (!is_null($existing)) {
281
-				$this->calDavBackEnd->deleteCalendarObject($calendarId, $objectUri);
282
-			}
283
-		} else {
284
-			if (is_null($existing)) {
285
-				$this->calDavBackEnd->createCalendarObject($calendarId, $objectUri, $calendarData->serialize());
286
-			} else {
287
-				if ($this->birthdayEvenChanged($existing['calendardata'], $calendarData)) {
288
-					$this->calDavBackEnd->updateCalendarObject($calendarId, $objectUri, $calendarData->serialize());
289
-				}
290
-			}
291
-		}
292
-	}
268
+    /**
269
+     * @param string $cardUri
270
+     * @param string  $cardData
271
+     * @param array $book
272
+     * @param int $calendarId
273
+     * @param string $type
274
+     */
275
+    private function updateCalendar($cardUri, $cardData, $book, $calendarId, $type) {
276
+        $objectUri = $book['uri'] . '-' . $cardUri . $type['postfix'] . '.ics';
277
+        $calendarData = $this->buildDateFromContact($cardData, $type['field'], $type['symbol']);
278
+        $existing = $this->calDavBackEnd->getCalendarObject($calendarId, $objectUri);
279
+        if (is_null($calendarData)) {
280
+            if (!is_null($existing)) {
281
+                $this->calDavBackEnd->deleteCalendarObject($calendarId, $objectUri);
282
+            }
283
+        } else {
284
+            if (is_null($existing)) {
285
+                $this->calDavBackEnd->createCalendarObject($calendarId, $objectUri, $calendarData->serialize());
286
+            } else {
287
+                if ($this->birthdayEvenChanged($existing['calendardata'], $calendarData)) {
288
+                    $this->calDavBackEnd->updateCalendarObject($calendarId, $objectUri, $calendarData->serialize());
289
+                }
290
+            }
291
+        }
292
+    }
293 293
 
294 294
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/Schedule/Plugin.php 1 patch
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -34,68 +34,68 @@
 block discarded – undo
34 34
 
35 35
 class Plugin extends \Sabre\CalDAV\Schedule\Plugin {
36 36
 
37
-	/**
38
-	 * Initializes the plugin
39
-	 *
40
-	 * @param Server $server
41
-	 * @return void
42
-	 */
43
-	function initialize(Server $server) {
44
-		parent::initialize($server);
45
-		$server->on('propFind', [$this, 'propFindDefaultCalendarUrl'], 90);
46
-	}
37
+    /**
38
+     * Initializes the plugin
39
+     *
40
+     * @param Server $server
41
+     * @return void
42
+     */
43
+    function initialize(Server $server) {
44
+        parent::initialize($server);
45
+        $server->on('propFind', [$this, 'propFindDefaultCalendarUrl'], 90);
46
+    }
47 47
 
48
-	/**
49
-	 * Returns a list of addresses that are associated with a principal.
50
-	 *
51
-	 * @param string $principal
52
-	 * @return array
53
-	 */
54
-	protected function getAddressesForPrincipal($principal) {
55
-		$result = parent::getAddressesForPrincipal($principal);
48
+    /**
49
+     * Returns a list of addresses that are associated with a principal.
50
+     *
51
+     * @param string $principal
52
+     * @return array
53
+     */
54
+    protected function getAddressesForPrincipal($principal) {
55
+        $result = parent::getAddressesForPrincipal($principal);
56 56
 
57
-		if ($result === null) {
58
-			$result = [];
59
-		}
57
+        if ($result === null) {
58
+            $result = [];
59
+        }
60 60
 
61
-		return $result;
62
-	}
61
+        return $result;
62
+    }
63 63
 
64
-	/**
65
-	 * Always use the personal calendar as target for scheduled events
66
-	 *
67
-	 * @param PropFind $propFind
68
-	 * @param INode $node
69
-	 * @return void
70
-	 */
71
-	function propFindDefaultCalendarUrl(PropFind $propFind, INode $node) {
72
-		if ($node instanceof IPrincipal) {
73
-			$propFind->handle('{' . self::NS_CALDAV . '}schedule-default-calendar-URL', function() use ($node) {
74
-				/** @var \OCA\DAV\CalDAV\Plugin $caldavPlugin */
75
-				$caldavPlugin = $this->server->getPlugin('caldav');
76
-				$principalUrl = $node->getPrincipalUrl();
64
+    /**
65
+     * Always use the personal calendar as target for scheduled events
66
+     *
67
+     * @param PropFind $propFind
68
+     * @param INode $node
69
+     * @return void
70
+     */
71
+    function propFindDefaultCalendarUrl(PropFind $propFind, INode $node) {
72
+        if ($node instanceof IPrincipal) {
73
+            $propFind->handle('{' . self::NS_CALDAV . '}schedule-default-calendar-URL', function() use ($node) {
74
+                /** @var \OCA\DAV\CalDAV\Plugin $caldavPlugin */
75
+                $caldavPlugin = $this->server->getPlugin('caldav');
76
+                $principalUrl = $node->getPrincipalUrl();
77 77
 
78
-				$calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
78
+                $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
79 79
 
80
-				if (!$calendarHomePath) {
81
-					return null;
82
-				}
80
+                if (!$calendarHomePath) {
81
+                    return null;
82
+                }
83 83
 
84
-				/** @var CalendarHome $calendarHome */
85
-				$calendarHome = $this->server->tree->getNodeForPath($calendarHomePath);
86
-				if (!$calendarHome->childExists(CalDavBackend::PERSONAL_CALENDAR_URI)) {
87
-					$calendarHome->getCalDAVBackend()->createCalendar($principalUrl, CalDavBackend::PERSONAL_CALENDAR_URI, [
88
-						'{DAV:}displayname' => CalDavBackend::PERSONAL_CALENDAR_NAME,
89
-					]);
90
-				}
84
+                /** @var CalendarHome $calendarHome */
85
+                $calendarHome = $this->server->tree->getNodeForPath($calendarHomePath);
86
+                if (!$calendarHome->childExists(CalDavBackend::PERSONAL_CALENDAR_URI)) {
87
+                    $calendarHome->getCalDAVBackend()->createCalendar($principalUrl, CalDavBackend::PERSONAL_CALENDAR_URI, [
88
+                        '{DAV:}displayname' => CalDavBackend::PERSONAL_CALENDAR_NAME,
89
+                    ]);
90
+                }
91 91
 
92
-				$result = $this->server->getPropertiesForPath($calendarHomePath . '/' . CalDavBackend::PERSONAL_CALENDAR_URI, [], 1);
93
-				if (empty($result)) {
94
-					return null;
95
-				}
92
+                $result = $this->server->getPropertiesForPath($calendarHomePath . '/' . CalDavBackend::PERSONAL_CALENDAR_URI, [], 1);
93
+                if (empty($result)) {
94
+                    return null;
95
+                }
96 96
 
97
-				return new LocalHref($result[0]['href']);
98
-			});
99
-		}
100
-	}
97
+                return new LocalHref($result[0]['href']);
98
+            });
99
+        }
100
+    }
101 101
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/Schedule/IMipPlugin.php 1 patch
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -42,88 +42,88 @@
 block discarded – undo
42 42
  */
43 43
 class IMipPlugin extends SabreIMipPlugin {
44 44
 
45
-	/** @var IMailer */
46
-	private $mailer;
47
-
48
-	/** @var ILogger */
49
-	private $logger;
50
-
51
-	/**
52
-	 * Creates the email handler.
53
-	 *
54
-	 * @param IMailer $mailer
55
-	 */
56
-	function __construct(IMailer $mailer, ILogger $logger) {
57
-		parent::__construct('');
58
-		$this->mailer = $mailer;
59
-		$this->logger = $logger;
60
-	}
61
-
62
-	/**
63
-	 * Event handler for the 'schedule' event.
64
-	 *
65
-	 * @param ITip\Message $iTipMessage
66
-	 * @return void
67
-	 */
68
-	function schedule(ITip\Message $iTipMessage) {
69
-
70
-		// Not sending any emails if the system considers the update
71
-		// insignificant.
72
-		if (!$iTipMessage->significantChange) {
73
-			if (!$iTipMessage->scheduleStatus) {
74
-				$iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email';
75
-			}
76
-			return;
77
-		}
78
-
79
-		$summary = $iTipMessage->message->VEVENT->SUMMARY;
80
-
81
-		if (parse_url($iTipMessage->sender, PHP_URL_SCHEME) !== 'mailto') {
82
-			return;
83
-		}
84
-
85
-		if (parse_url($iTipMessage->recipient, PHP_URL_SCHEME) !== 'mailto') {
86
-			return;
87
-		}
88
-
89
-		$sender = substr($iTipMessage->sender, 7);
90
-		$recipient = substr($iTipMessage->recipient, 7);
91
-
92
-		$senderName = ($iTipMessage->senderName) ? $iTipMessage->senderName : null;
93
-		$recipientName = ($iTipMessage->recipientName) ? $iTipMessage->recipientName : null;
94
-
95
-		$subject = 'SabreDAV iTIP message';
96
-		switch (strtoupper($iTipMessage->method)) {
97
-			case 'REPLY' :
98
-				$subject = 'Re: ' . $summary;
99
-				break;
100
-			case 'REQUEST' :
101
-				$subject = $summary;
102
-				break;
103
-			case 'CANCEL' :
104
-				$subject = 'Cancelled: ' . $summary;
105
-				break;
106
-		}
107
-
108
-		$contentType = 'text/calendar; charset=UTF-8; method=' . $iTipMessage->method;
109
-
110
-		$message = $this->mailer->createMessage();
111
-
112
-		$message->setReplyTo([$sender => $senderName])
113
-			->setTo([$recipient => $recipientName])
114
-			->setSubject($subject)
115
-			->setBody($iTipMessage->message->serialize(), $contentType);
116
-		try {
117
-			$failed = $this->mailer->send($message);
118
-			if ($failed) {
119
-				$this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' =>  implode(', ', $failed)]);
120
-				$iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
121
-			}
122
-			$iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip';
123
-		} catch(\Exception $ex) {
124
-			$this->logger->logException($ex, ['app' => 'dav']);
125
-			$iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
126
-		}
127
-	}
45
+    /** @var IMailer */
46
+    private $mailer;
47
+
48
+    /** @var ILogger */
49
+    private $logger;
50
+
51
+    /**
52
+     * Creates the email handler.
53
+     *
54
+     * @param IMailer $mailer
55
+     */
56
+    function __construct(IMailer $mailer, ILogger $logger) {
57
+        parent::__construct('');
58
+        $this->mailer = $mailer;
59
+        $this->logger = $logger;
60
+    }
61
+
62
+    /**
63
+     * Event handler for the 'schedule' event.
64
+     *
65
+     * @param ITip\Message $iTipMessage
66
+     * @return void
67
+     */
68
+    function schedule(ITip\Message $iTipMessage) {
69
+
70
+        // Not sending any emails if the system considers the update
71
+        // insignificant.
72
+        if (!$iTipMessage->significantChange) {
73
+            if (!$iTipMessage->scheduleStatus) {
74
+                $iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email';
75
+            }
76
+            return;
77
+        }
78
+
79
+        $summary = $iTipMessage->message->VEVENT->SUMMARY;
80
+
81
+        if (parse_url($iTipMessage->sender, PHP_URL_SCHEME) !== 'mailto') {
82
+            return;
83
+        }
84
+
85
+        if (parse_url($iTipMessage->recipient, PHP_URL_SCHEME) !== 'mailto') {
86
+            return;
87
+        }
88
+
89
+        $sender = substr($iTipMessage->sender, 7);
90
+        $recipient = substr($iTipMessage->recipient, 7);
91
+
92
+        $senderName = ($iTipMessage->senderName) ? $iTipMessage->senderName : null;
93
+        $recipientName = ($iTipMessage->recipientName) ? $iTipMessage->recipientName : null;
94
+
95
+        $subject = 'SabreDAV iTIP message';
96
+        switch (strtoupper($iTipMessage->method)) {
97
+            case 'REPLY' :
98
+                $subject = 'Re: ' . $summary;
99
+                break;
100
+            case 'REQUEST' :
101
+                $subject = $summary;
102
+                break;
103
+            case 'CANCEL' :
104
+                $subject = 'Cancelled: ' . $summary;
105
+                break;
106
+        }
107
+
108
+        $contentType = 'text/calendar; charset=UTF-8; method=' . $iTipMessage->method;
109
+
110
+        $message = $this->mailer->createMessage();
111
+
112
+        $message->setReplyTo([$sender => $senderName])
113
+            ->setTo([$recipient => $recipientName])
114
+            ->setSubject($subject)
115
+            ->setBody($iTipMessage->message->serialize(), $contentType);
116
+        try {
117
+            $failed = $this->mailer->send($message);
118
+            if ($failed) {
119
+                $this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' =>  implode(', ', $failed)]);
120
+                $iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
121
+            }
122
+            $iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip';
123
+        } catch(\Exception $ex) {
124
+            $this->logger->logException($ex, ['app' => 'dav']);
125
+            $iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
126
+        }
127
+    }
128 128
 
129 129
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/Publishing/PublishPlugin.php 1 patch
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -34,194 +34,194 @@
 block discarded – undo
34 34
 use OCP\IConfig;
35 35
 
36 36
 class PublishPlugin extends ServerPlugin {
37
-	const NS_CALENDARSERVER = 'http://calendarserver.org/ns/';
38
-
39
-	/**
40
-	 * Reference to SabreDAV server object.
41
-	 *
42
-	 * @var \Sabre\DAV\Server
43
-	 */
44
-	protected $server;
45
-
46
-	/**
47
-	 * Config instance to get instance secret.
48
-	 *
49
-	 * @var IConfig
50
-	 */
51
-	protected $config;
52
-
53
-	/**
54
-	 * URL Generator for absolute URLs.
55
-	 *
56
-	 * @var IURLGenerator
57
-	 */
58
-	protected $urlGenerator;
59
-
60
-	/**
61
-	 * PublishPlugin constructor.
62
-	 *
63
-	 * @param IConfig $config
64
-	 * @param IURLGenerator $urlGenerator
65
-	 */
66
-	public function __construct(IConfig $config, IURLGenerator $urlGenerator) {
67
-		$this->config = $config;
68
-		$this->urlGenerator = $urlGenerator;
69
-	}
70
-
71
-	/**
72
-	 * This method should return a list of server-features.
73
-	 *
74
-	 * This is for example 'versioning' and is added to the DAV: header
75
-	 * in an OPTIONS response.
76
-	 *
77
-	 * @return string[]
78
-	 */
79
-	public function getFeatures() {
80
-		// May have to be changed to be detected
81
-		return ['oc-calendar-publishing', 'calendarserver-sharing'];
82
-	}
83
-
84
-	/**
85
-	 * Returns a plugin name.
86
-	 *
87
-	 * Using this name other plugins will be able to access other plugins
88
-	 * using Sabre\DAV\Server::getPlugin
89
-	 *
90
-	 * @return string
91
-	 */
92
-	public function getPluginName()	{
93
-		return 'oc-calendar-publishing';
94
-	}
95
-
96
-	/**
97
-	 * This initializes the plugin.
98
-	 *
99
-	 * This function is called by Sabre\DAV\Server, after
100
-	 * addPlugin is called.
101
-	 *
102
-	 * This method should set up the required event subscriptions.
103
-	 *
104
-	 * @param Server $server
105
-	 */
106
-	public function initialize(Server $server) {
107
-		$this->server = $server;
108
-
109
-		$this->server->on('method:POST', [$this, 'httpPost']);
110
-		$this->server->on('propFind',    [$this, 'propFind']);
111
-	}
112
-
113
-	public function propFind(PropFind $propFind, INode $node) {
114
-		if ($node instanceof Calendar) {
115
-			$propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) {
116
-				if ($node->getPublishStatus()) {
117
-					// We return the publish-url only if the calendar is published.
118
-					$token = $node->getPublishStatus();
119
-					$publishUrl = $this->urlGenerator->getAbsoluteURL($this->server->getBaseUri().'public-calendars/').$token;
120
-
121
-					return new Publisher($publishUrl, true);
122
-				}
123
-			});
124
-
125
-			$propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function() use ($node) {
126
-				return new AllowedSharingModes(!$node->isSubscription(), !$node->isSubscription());
127
-			});
128
-		}
129
-	}
130
-
131
-	/**
132
-	 * We intercept this to handle POST requests on calendars.
133
-	 *
134
-	 * @param RequestInterface $request
135
-	 * @param ResponseInterface $response
136
-	 *
137
-	 * @return void|bool
138
-	 */
139
-	public function httpPost(RequestInterface $request, ResponseInterface $response) {
140
-		$path = $request->getPath();
141
-
142
-		// Only handling xml
143
-		$contentType = $request->getHeader('Content-Type');
144
-		if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) {
145
-			return;
146
-		}
147
-
148
-		// Making sure the node exists
149
-		try {
150
-			$node = $this->server->tree->getNodeForPath($path);
151
-		} catch (NotFound $e) {
152
-			return;
153
-		}
154
-
155
-		$requestBody = $request->getBodyAsString();
156
-
157
-		// If this request handler could not deal with this POST request, it
158
-		// will return 'null' and other plugins get a chance to handle the
159
-		// request.
160
-		//
161
-		// However, we already requested the full body. This is a problem,
162
-		// because a body can only be read once. This is why we preemptively
163
-		// re-populated the request body with the existing data.
164
-		$request->setBody($requestBody);
165
-
166
-		$this->server->xml->parse($requestBody, $request->getUrl(), $documentType);
167
-
168
-		switch ($documentType) {
169
-
170
-			case '{'.self::NS_CALENDARSERVER.'}publish-calendar' :
171
-
172
-			// We can only deal with IShareableCalendar objects
173
-			if (!$node instanceof Calendar) {
174
-				return;
175
-			}
176
-			$this->server->transactionType = 'post-publish-calendar';
177
-
178
-			// Getting ACL info
179
-			$acl = $this->server->getPlugin('acl');
180
-
181
-			// If there's no ACL support, we allow everything
182
-			if ($acl) {
183
-				$acl->checkPrivileges($path, '{DAV:}write');
184
-			}
185
-
186
-			$node->setPublishStatus(true);
187
-
188
-			// iCloud sends back the 202, so we will too.
189
-			$response->setStatus(202);
190
-
191
-			// Adding this because sending a response body may cause issues,
192
-			// and I wanted some type of indicator the response was handled.
193
-			$response->setHeader('X-Sabre-Status', 'everything-went-well');
194
-
195
-			// Breaking the event chain
196
-			return false;
197
-
198
-			case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar' :
199
-
200
-			// We can only deal with IShareableCalendar objects
201
-			if (!$node instanceof Calendar) {
202
-				return;
203
-			}
204
-			$this->server->transactionType = 'post-unpublish-calendar';
205
-
206
-			// Getting ACL info
207
-			$acl = $this->server->getPlugin('acl');
208
-
209
-			// If there's no ACL support, we allow everything
210
-			if ($acl) {
211
-				$acl->checkPrivileges($path, '{DAV:}write');
212
-			}
213
-
214
-			$node->setPublishStatus(false);
215
-
216
-			$response->setStatus(200);
217
-
218
-			// Adding this because sending a response body may cause issues,
219
-			// and I wanted some type of indicator the response was handled.
220
-			$response->setHeader('X-Sabre-Status', 'everything-went-well');
221
-
222
-			// Breaking the event chain
223
-			return false;
37
+    const NS_CALENDARSERVER = 'http://calendarserver.org/ns/';
38
+
39
+    /**
40
+     * Reference to SabreDAV server object.
41
+     *
42
+     * @var \Sabre\DAV\Server
43
+     */
44
+    protected $server;
45
+
46
+    /**
47
+     * Config instance to get instance secret.
48
+     *
49
+     * @var IConfig
50
+     */
51
+    protected $config;
52
+
53
+    /**
54
+     * URL Generator for absolute URLs.
55
+     *
56
+     * @var IURLGenerator
57
+     */
58
+    protected $urlGenerator;
59
+
60
+    /**
61
+     * PublishPlugin constructor.
62
+     *
63
+     * @param IConfig $config
64
+     * @param IURLGenerator $urlGenerator
65
+     */
66
+    public function __construct(IConfig $config, IURLGenerator $urlGenerator) {
67
+        $this->config = $config;
68
+        $this->urlGenerator = $urlGenerator;
69
+    }
70
+
71
+    /**
72
+     * This method should return a list of server-features.
73
+     *
74
+     * This is for example 'versioning' and is added to the DAV: header
75
+     * in an OPTIONS response.
76
+     *
77
+     * @return string[]
78
+     */
79
+    public function getFeatures() {
80
+        // May have to be changed to be detected
81
+        return ['oc-calendar-publishing', 'calendarserver-sharing'];
82
+    }
83
+
84
+    /**
85
+     * Returns a plugin name.
86
+     *
87
+     * Using this name other plugins will be able to access other plugins
88
+     * using Sabre\DAV\Server::getPlugin
89
+     *
90
+     * @return string
91
+     */
92
+    public function getPluginName()	{
93
+        return 'oc-calendar-publishing';
94
+    }
95
+
96
+    /**
97
+     * This initializes the plugin.
98
+     *
99
+     * This function is called by Sabre\DAV\Server, after
100
+     * addPlugin is called.
101
+     *
102
+     * This method should set up the required event subscriptions.
103
+     *
104
+     * @param Server $server
105
+     */
106
+    public function initialize(Server $server) {
107
+        $this->server = $server;
108
+
109
+        $this->server->on('method:POST', [$this, 'httpPost']);
110
+        $this->server->on('propFind',    [$this, 'propFind']);
111
+    }
112
+
113
+    public function propFind(PropFind $propFind, INode $node) {
114
+        if ($node instanceof Calendar) {
115
+            $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) {
116
+                if ($node->getPublishStatus()) {
117
+                    // We return the publish-url only if the calendar is published.
118
+                    $token = $node->getPublishStatus();
119
+                    $publishUrl = $this->urlGenerator->getAbsoluteURL($this->server->getBaseUri().'public-calendars/').$token;
120
+
121
+                    return new Publisher($publishUrl, true);
122
+                }
123
+            });
124
+
125
+            $propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function() use ($node) {
126
+                return new AllowedSharingModes(!$node->isSubscription(), !$node->isSubscription());
127
+            });
128
+        }
129
+    }
130
+
131
+    /**
132
+     * We intercept this to handle POST requests on calendars.
133
+     *
134
+     * @param RequestInterface $request
135
+     * @param ResponseInterface $response
136
+     *
137
+     * @return void|bool
138
+     */
139
+    public function httpPost(RequestInterface $request, ResponseInterface $response) {
140
+        $path = $request->getPath();
141
+
142
+        // Only handling xml
143
+        $contentType = $request->getHeader('Content-Type');
144
+        if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) {
145
+            return;
146
+        }
147
+
148
+        // Making sure the node exists
149
+        try {
150
+            $node = $this->server->tree->getNodeForPath($path);
151
+        } catch (NotFound $e) {
152
+            return;
153
+        }
154
+
155
+        $requestBody = $request->getBodyAsString();
156
+
157
+        // If this request handler could not deal with this POST request, it
158
+        // will return 'null' and other plugins get a chance to handle the
159
+        // request.
160
+        //
161
+        // However, we already requested the full body. This is a problem,
162
+        // because a body can only be read once. This is why we preemptively
163
+        // re-populated the request body with the existing data.
164
+        $request->setBody($requestBody);
165
+
166
+        $this->server->xml->parse($requestBody, $request->getUrl(), $documentType);
167
+
168
+        switch ($documentType) {
169
+
170
+            case '{'.self::NS_CALENDARSERVER.'}publish-calendar' :
171
+
172
+            // We can only deal with IShareableCalendar objects
173
+            if (!$node instanceof Calendar) {
174
+                return;
175
+            }
176
+            $this->server->transactionType = 'post-publish-calendar';
177
+
178
+            // Getting ACL info
179
+            $acl = $this->server->getPlugin('acl');
180
+
181
+            // If there's no ACL support, we allow everything
182
+            if ($acl) {
183
+                $acl->checkPrivileges($path, '{DAV:}write');
184
+            }
185
+
186
+            $node->setPublishStatus(true);
187
+
188
+            // iCloud sends back the 202, so we will too.
189
+            $response->setStatus(202);
190
+
191
+            // Adding this because sending a response body may cause issues,
192
+            // and I wanted some type of indicator the response was handled.
193
+            $response->setHeader('X-Sabre-Status', 'everything-went-well');
194
+
195
+            // Breaking the event chain
196
+            return false;
197
+
198
+            case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar' :
199
+
200
+            // We can only deal with IShareableCalendar objects
201
+            if (!$node instanceof Calendar) {
202
+                return;
203
+            }
204
+            $this->server->transactionType = 'post-unpublish-calendar';
205
+
206
+            // Getting ACL info
207
+            $acl = $this->server->getPlugin('acl');
208
+
209
+            // If there's no ACL support, we allow everything
210
+            if ($acl) {
211
+                $acl->checkPrivileges($path, '{DAV:}write');
212
+            }
213
+
214
+            $node->setPublishStatus(false);
215
+
216
+            $response->setStatus(200);
217
+
218
+            // Adding this because sending a response body may cause issues,
219
+            // and I wanted some type of indicator the response was handled.
220
+            $response->setHeader('X-Sabre-Status', 'everything-went-well');
221
+
222
+            // Breaking the event chain
223
+            return false;
224 224
 
225
-		}
226
-	}
225
+        }
226
+    }
227 227
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/Publishing/Xml/Publisher.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -26,58 +26,58 @@
 block discarded – undo
26 26
 
27 27
 class Publisher implements XmlSerializable {
28 28
 
29
-	/**
30
-	 * @var string $publishUrl
31
-	 */
32
-	protected $publishUrl;
29
+    /**
30
+     * @var string $publishUrl
31
+     */
32
+    protected $publishUrl;
33 33
 
34
-	/**
35
-	 * @var boolean $isPublished
36
-	 */
37
-	protected $isPublished;
34
+    /**
35
+     * @var boolean $isPublished
36
+     */
37
+    protected $isPublished;
38 38
 
39
-	/**
40
-	 * @param string $publishUrl
41
-	 * @param boolean $isPublished
42
-	 */
43
-	function __construct($publishUrl, $isPublished) {
44
-		$this->publishUrl = $publishUrl;
45
-		$this->isPublished = $isPublished;
46
-	}
39
+    /**
40
+     * @param string $publishUrl
41
+     * @param boolean $isPublished
42
+     */
43
+    function __construct($publishUrl, $isPublished) {
44
+        $this->publishUrl = $publishUrl;
45
+        $this->isPublished = $isPublished;
46
+    }
47 47
 
48
-	/**
49
-	 * @return string
50
-	 */
51
-	function getValue() {
52
-		return $this->publishUrl;
53
-	}
48
+    /**
49
+     * @return string
50
+     */
51
+    function getValue() {
52
+        return $this->publishUrl;
53
+    }
54 54
 
55
-	/**
56
-	 * The xmlSerialize metod is called during xml writing.
57
-	 *
58
-	 * Use the $writer argument to write its own xml serialization.
59
-	 *
60
-	 * An important note: do _not_ create a parent element. Any element
61
-	 * implementing XmlSerializble should only ever write what's considered
62
-	 * its 'inner xml'.
63
-	 *
64
-	 * The parent of the current element is responsible for writing a
65
-	 * containing element.
66
-	 *
67
-	 * This allows serializers to be re-used for different element names.
68
-	 *
69
-	 * If you are opening new elements, you must also close them again.
70
-	 *
71
-	 * @param Writer $writer
72
-	 * @return void
73
-	 */
74
-	function xmlSerialize(Writer $writer) {
75
-		if (!$this->isPublished) {
76
-			// for pre-publish-url
77
-			$writer->write($this->publishUrl);
78
-		} else {
79
-			// for publish-url
80
-			$writer->writeElement('{DAV:}href', $this->publishUrl);
81
-		}
82
-	}
55
+    /**
56
+     * The xmlSerialize metod is called during xml writing.
57
+     *
58
+     * Use the $writer argument to write its own xml serialization.
59
+     *
60
+     * An important note: do _not_ create a parent element. Any element
61
+     * implementing XmlSerializble should only ever write what's considered
62
+     * its 'inner xml'.
63
+     *
64
+     * The parent of the current element is responsible for writing a
65
+     * containing element.
66
+     *
67
+     * This allows serializers to be re-used for different element names.
68
+     *
69
+     * If you are opening new elements, you must also close them again.
70
+     *
71
+     * @param Writer $writer
72
+     * @return void
73
+     */
74
+    function xmlSerialize(Writer $writer) {
75
+        if (!$this->isPublished) {
76
+            // for pre-publish-url
77
+            $writer->write($this->publishUrl);
78
+        } else {
79
+            // for publish-url
80
+            $writer->writeElement('{DAV:}href', $this->publishUrl);
81
+        }
82
+    }
83 83
 }
Please login to merge, or discard this patch.