@@ -85,14 +85,14 @@ discard block |
||
| 85 | 85 | $this->logger = $logger; |
| 86 | 86 | |
| 87 | 87 | $methods = get_class_methods($this->comment); |
| 88 | - $methods = array_filter($methods, function ($name) { |
|
| 88 | + $methods = array_filter($methods, function($name) { |
|
| 89 | 89 | return strpos($name, 'get') === 0; |
| 90 | 90 | }); |
| 91 | 91 | foreach ($methods as $getter) { |
| 92 | 92 | if ($getter === 'getMentions') { |
| 93 | - continue; // special treatment |
|
| 93 | + continue; // special treatment |
|
| 94 | 94 | } |
| 95 | - $name = '{'.self::NS_OWNCLOUD.'}' . lcfirst(substr($getter, 3)); |
|
| 95 | + $name = '{'.self::NS_OWNCLOUD.'}'.lcfirst(substr($getter, 3)); |
|
| 96 | 96 | $this->properties[$name] = $getter; |
| 97 | 97 | } |
| 98 | 98 | $this->userManager = $userManager; |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | $this->logger->logException($e, ['app' => 'dav/comments']); |
| 198 | 198 | if ($e instanceof MessageTooLongException) { |
| 199 | 199 | $msg = 'Message exceeds allowed character limit of '; |
| 200 | - throw new BadRequest($msg . IComment::MAX_MESSAGE_LENGTH, 0, $e); |
|
| 200 | + throw new BadRequest($msg.IComment::MAX_MESSAGE_LENGTH, 0, $e); |
|
| 201 | 201 | } |
| 202 | 202 | throw $e; |
| 203 | 203 | } |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | * @return array |
| 284 | 284 | */ |
| 285 | 285 | protected function composeMentionsPropertyValue() { |
| 286 | - return array_map(function ($mention) { |
|
| 286 | + return array_map(function($mention) { |
|
| 287 | 287 | try { |
| 288 | 288 | $displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']); |
| 289 | 289 | } catch (\OutOfBoundsException $e) { |
@@ -36,270 +36,270 @@ |
||
| 36 | 36 | use Sabre\DAV\PropPatch; |
| 37 | 37 | |
| 38 | 38 | class CommentNode implements \Sabre\DAV\INode, \Sabre\DAV\IProperties { |
| 39 | - public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 39 | + public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 40 | 40 | |
| 41 | - public const PROPERTY_NAME_UNREAD = '{http://owncloud.org/ns}isUnread'; |
|
| 42 | - public const PROPERTY_NAME_MESSAGE = '{http://owncloud.org/ns}message'; |
|
| 43 | - public const PROPERTY_NAME_ACTOR_DISPLAYNAME = '{http://owncloud.org/ns}actorDisplayName'; |
|
| 44 | - public const PROPERTY_NAME_MENTIONS = '{http://owncloud.org/ns}mentions'; |
|
| 45 | - public const PROPERTY_NAME_MENTION = '{http://owncloud.org/ns}mention'; |
|
| 46 | - public const PROPERTY_NAME_MENTION_TYPE = '{http://owncloud.org/ns}mentionType'; |
|
| 47 | - public const PROPERTY_NAME_MENTION_ID = '{http://owncloud.org/ns}mentionId'; |
|
| 48 | - public const PROPERTY_NAME_MENTION_DISPLAYNAME = '{http://owncloud.org/ns}mentionDisplayName'; |
|
| 41 | + public const PROPERTY_NAME_UNREAD = '{http://owncloud.org/ns}isUnread'; |
|
| 42 | + public const PROPERTY_NAME_MESSAGE = '{http://owncloud.org/ns}message'; |
|
| 43 | + public const PROPERTY_NAME_ACTOR_DISPLAYNAME = '{http://owncloud.org/ns}actorDisplayName'; |
|
| 44 | + public const PROPERTY_NAME_MENTIONS = '{http://owncloud.org/ns}mentions'; |
|
| 45 | + public const PROPERTY_NAME_MENTION = '{http://owncloud.org/ns}mention'; |
|
| 46 | + public const PROPERTY_NAME_MENTION_TYPE = '{http://owncloud.org/ns}mentionType'; |
|
| 47 | + public const PROPERTY_NAME_MENTION_ID = '{http://owncloud.org/ns}mentionId'; |
|
| 48 | + public const PROPERTY_NAME_MENTION_DISPLAYNAME = '{http://owncloud.org/ns}mentionDisplayName'; |
|
| 49 | 49 | |
| 50 | - /** @var IComment */ |
|
| 51 | - public $comment; |
|
| 50 | + /** @var IComment */ |
|
| 51 | + public $comment; |
|
| 52 | 52 | |
| 53 | - /** @var ICommentsManager */ |
|
| 54 | - protected $commentsManager; |
|
| 53 | + /** @var ICommentsManager */ |
|
| 54 | + protected $commentsManager; |
|
| 55 | 55 | |
| 56 | - /** @var ILogger */ |
|
| 57 | - protected $logger; |
|
| 56 | + /** @var ILogger */ |
|
| 57 | + protected $logger; |
|
| 58 | 58 | |
| 59 | - /** @var array list of properties with key being their name and value their setter */ |
|
| 60 | - protected $properties = []; |
|
| 59 | + /** @var array list of properties with key being their name and value their setter */ |
|
| 60 | + protected $properties = []; |
|
| 61 | 61 | |
| 62 | - /** @var IUserManager */ |
|
| 63 | - protected $userManager; |
|
| 62 | + /** @var IUserManager */ |
|
| 63 | + protected $userManager; |
|
| 64 | 64 | |
| 65 | - /** @var IUserSession */ |
|
| 66 | - protected $userSession; |
|
| 65 | + /** @var IUserSession */ |
|
| 66 | + protected $userSession; |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * CommentNode constructor. |
|
| 70 | - * |
|
| 71 | - * @param ICommentsManager $commentsManager |
|
| 72 | - * @param IComment $comment |
|
| 73 | - * @param IUserManager $userManager |
|
| 74 | - * @param IUserSession $userSession |
|
| 75 | - * @param ILogger $logger |
|
| 76 | - */ |
|
| 77 | - public function __construct( |
|
| 78 | - ICommentsManager $commentsManager, |
|
| 79 | - IComment $comment, |
|
| 80 | - IUserManager $userManager, |
|
| 81 | - IUserSession $userSession, |
|
| 82 | - ILogger $logger |
|
| 83 | - ) { |
|
| 84 | - $this->commentsManager = $commentsManager; |
|
| 85 | - $this->comment = $comment; |
|
| 86 | - $this->logger = $logger; |
|
| 68 | + /** |
|
| 69 | + * CommentNode constructor. |
|
| 70 | + * |
|
| 71 | + * @param ICommentsManager $commentsManager |
|
| 72 | + * @param IComment $comment |
|
| 73 | + * @param IUserManager $userManager |
|
| 74 | + * @param IUserSession $userSession |
|
| 75 | + * @param ILogger $logger |
|
| 76 | + */ |
|
| 77 | + public function __construct( |
|
| 78 | + ICommentsManager $commentsManager, |
|
| 79 | + IComment $comment, |
|
| 80 | + IUserManager $userManager, |
|
| 81 | + IUserSession $userSession, |
|
| 82 | + ILogger $logger |
|
| 83 | + ) { |
|
| 84 | + $this->commentsManager = $commentsManager; |
|
| 85 | + $this->comment = $comment; |
|
| 86 | + $this->logger = $logger; |
|
| 87 | 87 | |
| 88 | - $methods = get_class_methods($this->comment); |
|
| 89 | - $methods = array_filter($methods, function ($name) { |
|
| 90 | - return strpos($name, 'get') === 0; |
|
| 91 | - }); |
|
| 92 | - foreach ($methods as $getter) { |
|
| 93 | - if ($getter === 'getMentions') { |
|
| 94 | - continue; // special treatment |
|
| 95 | - } |
|
| 96 | - $name = '{'.self::NS_OWNCLOUD.'}' . lcfirst(substr($getter, 3)); |
|
| 97 | - $this->properties[$name] = $getter; |
|
| 98 | - } |
|
| 99 | - $this->userManager = $userManager; |
|
| 100 | - $this->userSession = $userSession; |
|
| 101 | - } |
|
| 88 | + $methods = get_class_methods($this->comment); |
|
| 89 | + $methods = array_filter($methods, function ($name) { |
|
| 90 | + return strpos($name, 'get') === 0; |
|
| 91 | + }); |
|
| 92 | + foreach ($methods as $getter) { |
|
| 93 | + if ($getter === 'getMentions') { |
|
| 94 | + continue; // special treatment |
|
| 95 | + } |
|
| 96 | + $name = '{'.self::NS_OWNCLOUD.'}' . lcfirst(substr($getter, 3)); |
|
| 97 | + $this->properties[$name] = $getter; |
|
| 98 | + } |
|
| 99 | + $this->userManager = $userManager; |
|
| 100 | + $this->userSession = $userSession; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * returns a list of all possible property names |
|
| 105 | - * |
|
| 106 | - * @return array |
|
| 107 | - */ |
|
| 108 | - public static function getPropertyNames() { |
|
| 109 | - return [ |
|
| 110 | - '{http://owncloud.org/ns}id', |
|
| 111 | - '{http://owncloud.org/ns}parentId', |
|
| 112 | - '{http://owncloud.org/ns}topmostParentId', |
|
| 113 | - '{http://owncloud.org/ns}childrenCount', |
|
| 114 | - '{http://owncloud.org/ns}verb', |
|
| 115 | - '{http://owncloud.org/ns}actorType', |
|
| 116 | - '{http://owncloud.org/ns}actorId', |
|
| 117 | - '{http://owncloud.org/ns}creationDateTime', |
|
| 118 | - '{http://owncloud.org/ns}latestChildDateTime', |
|
| 119 | - '{http://owncloud.org/ns}objectType', |
|
| 120 | - '{http://owncloud.org/ns}objectId', |
|
| 121 | - // re-used property names are defined as constants |
|
| 122 | - self::PROPERTY_NAME_MESSAGE, |
|
| 123 | - self::PROPERTY_NAME_ACTOR_DISPLAYNAME, |
|
| 124 | - self::PROPERTY_NAME_UNREAD, |
|
| 125 | - self::PROPERTY_NAME_MENTIONS, |
|
| 126 | - self::PROPERTY_NAME_MENTION, |
|
| 127 | - self::PROPERTY_NAME_MENTION_TYPE, |
|
| 128 | - self::PROPERTY_NAME_MENTION_ID, |
|
| 129 | - self::PROPERTY_NAME_MENTION_DISPLAYNAME, |
|
| 130 | - ]; |
|
| 131 | - } |
|
| 103 | + /** |
|
| 104 | + * returns a list of all possible property names |
|
| 105 | + * |
|
| 106 | + * @return array |
|
| 107 | + */ |
|
| 108 | + public static function getPropertyNames() { |
|
| 109 | + return [ |
|
| 110 | + '{http://owncloud.org/ns}id', |
|
| 111 | + '{http://owncloud.org/ns}parentId', |
|
| 112 | + '{http://owncloud.org/ns}topmostParentId', |
|
| 113 | + '{http://owncloud.org/ns}childrenCount', |
|
| 114 | + '{http://owncloud.org/ns}verb', |
|
| 115 | + '{http://owncloud.org/ns}actorType', |
|
| 116 | + '{http://owncloud.org/ns}actorId', |
|
| 117 | + '{http://owncloud.org/ns}creationDateTime', |
|
| 118 | + '{http://owncloud.org/ns}latestChildDateTime', |
|
| 119 | + '{http://owncloud.org/ns}objectType', |
|
| 120 | + '{http://owncloud.org/ns}objectId', |
|
| 121 | + // re-used property names are defined as constants |
|
| 122 | + self::PROPERTY_NAME_MESSAGE, |
|
| 123 | + self::PROPERTY_NAME_ACTOR_DISPLAYNAME, |
|
| 124 | + self::PROPERTY_NAME_UNREAD, |
|
| 125 | + self::PROPERTY_NAME_MENTIONS, |
|
| 126 | + self::PROPERTY_NAME_MENTION, |
|
| 127 | + self::PROPERTY_NAME_MENTION_TYPE, |
|
| 128 | + self::PROPERTY_NAME_MENTION_ID, |
|
| 129 | + self::PROPERTY_NAME_MENTION_DISPLAYNAME, |
|
| 130 | + ]; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - protected function checkWriteAccessOnComment() { |
|
| 134 | - $user = $this->userSession->getUser(); |
|
| 135 | - if ($this->comment->getActorType() !== 'users' |
|
| 136 | - || is_null($user) |
|
| 137 | - || $this->comment->getActorId() !== $user->getUID() |
|
| 138 | - ) { |
|
| 139 | - throw new Forbidden('Only authors are allowed to edit their comment.'); |
|
| 140 | - } |
|
| 141 | - } |
|
| 133 | + protected function checkWriteAccessOnComment() { |
|
| 134 | + $user = $this->userSession->getUser(); |
|
| 135 | + if ($this->comment->getActorType() !== 'users' |
|
| 136 | + || is_null($user) |
|
| 137 | + || $this->comment->getActorId() !== $user->getUID() |
|
| 138 | + ) { |
|
| 139 | + throw new Forbidden('Only authors are allowed to edit their comment.'); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - /** |
|
| 144 | - * Deleted the current node |
|
| 145 | - * |
|
| 146 | - * @return void |
|
| 147 | - */ |
|
| 148 | - public function delete() { |
|
| 149 | - $this->checkWriteAccessOnComment(); |
|
| 150 | - $this->commentsManager->delete($this->comment->getId()); |
|
| 151 | - } |
|
| 143 | + /** |
|
| 144 | + * Deleted the current node |
|
| 145 | + * |
|
| 146 | + * @return void |
|
| 147 | + */ |
|
| 148 | + public function delete() { |
|
| 149 | + $this->checkWriteAccessOnComment(); |
|
| 150 | + $this->commentsManager->delete($this->comment->getId()); |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - /** |
|
| 154 | - * Returns the name of the node. |
|
| 155 | - * |
|
| 156 | - * This is used to generate the url. |
|
| 157 | - * |
|
| 158 | - * @return string |
|
| 159 | - */ |
|
| 160 | - public function getName() { |
|
| 161 | - return $this->comment->getId(); |
|
| 162 | - } |
|
| 153 | + /** |
|
| 154 | + * Returns the name of the node. |
|
| 155 | + * |
|
| 156 | + * This is used to generate the url. |
|
| 157 | + * |
|
| 158 | + * @return string |
|
| 159 | + */ |
|
| 160 | + public function getName() { |
|
| 161 | + return $this->comment->getId(); |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - /** |
|
| 165 | - * Renames the node |
|
| 166 | - * |
|
| 167 | - * @param string $name The new name |
|
| 168 | - * @throws MethodNotAllowed |
|
| 169 | - */ |
|
| 170 | - public function setName($name) { |
|
| 171 | - throw new MethodNotAllowed(); |
|
| 172 | - } |
|
| 164 | + /** |
|
| 165 | + * Renames the node |
|
| 166 | + * |
|
| 167 | + * @param string $name The new name |
|
| 168 | + * @throws MethodNotAllowed |
|
| 169 | + */ |
|
| 170 | + public function setName($name) { |
|
| 171 | + throw new MethodNotAllowed(); |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | - /** |
|
| 175 | - * Returns the last modification time, as a unix timestamp |
|
| 176 | - * |
|
| 177 | - * @return int |
|
| 178 | - */ |
|
| 179 | - public function getLastModified() { |
|
| 180 | - return null; |
|
| 181 | - } |
|
| 174 | + /** |
|
| 175 | + * Returns the last modification time, as a unix timestamp |
|
| 176 | + * |
|
| 177 | + * @return int |
|
| 178 | + */ |
|
| 179 | + public function getLastModified() { |
|
| 180 | + return null; |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - /** |
|
| 184 | - * update the comment's message |
|
| 185 | - * |
|
| 186 | - * @param $propertyValue |
|
| 187 | - * @return bool |
|
| 188 | - * @throws BadRequest |
|
| 189 | - * @throws \Exception |
|
| 190 | - */ |
|
| 191 | - public function updateComment($propertyValue) { |
|
| 192 | - $this->checkWriteAccessOnComment(); |
|
| 193 | - try { |
|
| 194 | - $this->comment->setMessage($propertyValue); |
|
| 195 | - $this->commentsManager->save($this->comment); |
|
| 196 | - return true; |
|
| 197 | - } catch (\Exception $e) { |
|
| 198 | - $this->logger->logException($e, ['app' => 'dav/comments']); |
|
| 199 | - if ($e instanceof MessageTooLongException) { |
|
| 200 | - $msg = 'Message exceeds allowed character limit of '; |
|
| 201 | - throw new BadRequest($msg . IComment::MAX_MESSAGE_LENGTH, 0, $e); |
|
| 202 | - } |
|
| 203 | - throw $e; |
|
| 204 | - } |
|
| 205 | - } |
|
| 183 | + /** |
|
| 184 | + * update the comment's message |
|
| 185 | + * |
|
| 186 | + * @param $propertyValue |
|
| 187 | + * @return bool |
|
| 188 | + * @throws BadRequest |
|
| 189 | + * @throws \Exception |
|
| 190 | + */ |
|
| 191 | + public function updateComment($propertyValue) { |
|
| 192 | + $this->checkWriteAccessOnComment(); |
|
| 193 | + try { |
|
| 194 | + $this->comment->setMessage($propertyValue); |
|
| 195 | + $this->commentsManager->save($this->comment); |
|
| 196 | + return true; |
|
| 197 | + } catch (\Exception $e) { |
|
| 198 | + $this->logger->logException($e, ['app' => 'dav/comments']); |
|
| 199 | + if ($e instanceof MessageTooLongException) { |
|
| 200 | + $msg = 'Message exceeds allowed character limit of '; |
|
| 201 | + throw new BadRequest($msg . IComment::MAX_MESSAGE_LENGTH, 0, $e); |
|
| 202 | + } |
|
| 203 | + throw $e; |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - /** |
|
| 208 | - * Updates properties on this node. |
|
| 209 | - * |
|
| 210 | - * This method received a PropPatch object, which contains all the |
|
| 211 | - * information about the update. |
|
| 212 | - * |
|
| 213 | - * To update specific properties, call the 'handle' method on this object. |
|
| 214 | - * Read the PropPatch documentation for more information. |
|
| 215 | - * |
|
| 216 | - * @param PropPatch $propPatch |
|
| 217 | - * @return void |
|
| 218 | - */ |
|
| 219 | - public function propPatch(PropPatch $propPatch) { |
|
| 220 | - // other properties than 'message' are read only |
|
| 221 | - $propPatch->handle(self::PROPERTY_NAME_MESSAGE, [$this, 'updateComment']); |
|
| 222 | - } |
|
| 207 | + /** |
|
| 208 | + * Updates properties on this node. |
|
| 209 | + * |
|
| 210 | + * This method received a PropPatch object, which contains all the |
|
| 211 | + * information about the update. |
|
| 212 | + * |
|
| 213 | + * To update specific properties, call the 'handle' method on this object. |
|
| 214 | + * Read the PropPatch documentation for more information. |
|
| 215 | + * |
|
| 216 | + * @param PropPatch $propPatch |
|
| 217 | + * @return void |
|
| 218 | + */ |
|
| 219 | + public function propPatch(PropPatch $propPatch) { |
|
| 220 | + // other properties than 'message' are read only |
|
| 221 | + $propPatch->handle(self::PROPERTY_NAME_MESSAGE, [$this, 'updateComment']); |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - /** |
|
| 225 | - * Returns a list of properties for this nodes. |
|
| 226 | - * |
|
| 227 | - * The properties list is a list of propertynames the client requested, |
|
| 228 | - * encoded in clark-notation {xmlnamespace}tagname |
|
| 229 | - * |
|
| 230 | - * If the array is empty, it means 'all properties' were requested. |
|
| 231 | - * |
|
| 232 | - * Note that it's fine to liberally give properties back, instead of |
|
| 233 | - * conforming to the list of requested properties. |
|
| 234 | - * The Server class will filter out the extra. |
|
| 235 | - * |
|
| 236 | - * @param array $properties |
|
| 237 | - * @return array |
|
| 238 | - */ |
|
| 239 | - public function getProperties($properties) { |
|
| 240 | - $properties = array_keys($this->properties); |
|
| 224 | + /** |
|
| 225 | + * Returns a list of properties for this nodes. |
|
| 226 | + * |
|
| 227 | + * The properties list is a list of propertynames the client requested, |
|
| 228 | + * encoded in clark-notation {xmlnamespace}tagname |
|
| 229 | + * |
|
| 230 | + * If the array is empty, it means 'all properties' were requested. |
|
| 231 | + * |
|
| 232 | + * Note that it's fine to liberally give properties back, instead of |
|
| 233 | + * conforming to the list of requested properties. |
|
| 234 | + * The Server class will filter out the extra. |
|
| 235 | + * |
|
| 236 | + * @param array $properties |
|
| 237 | + * @return array |
|
| 238 | + */ |
|
| 239 | + public function getProperties($properties) { |
|
| 240 | + $properties = array_keys($this->properties); |
|
| 241 | 241 | |
| 242 | - $result = []; |
|
| 243 | - foreach ($properties as $property) { |
|
| 244 | - $getter = $this->properties[$property]; |
|
| 245 | - if (method_exists($this->comment, $getter)) { |
|
| 246 | - $result[$property] = $this->comment->$getter(); |
|
| 247 | - } |
|
| 248 | - } |
|
| 242 | + $result = []; |
|
| 243 | + foreach ($properties as $property) { |
|
| 244 | + $getter = $this->properties[$property]; |
|
| 245 | + if (method_exists($this->comment, $getter)) { |
|
| 246 | + $result[$property] = $this->comment->$getter(); |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - if ($this->comment->getActorType() === 'users') { |
|
| 251 | - $user = $this->userManager->get($this->comment->getActorId()); |
|
| 252 | - $displayName = is_null($user) ? null : $user->getDisplayName(); |
|
| 253 | - $result[self::PROPERTY_NAME_ACTOR_DISPLAYNAME] = $displayName; |
|
| 254 | - } |
|
| 250 | + if ($this->comment->getActorType() === 'users') { |
|
| 251 | + $user = $this->userManager->get($this->comment->getActorId()); |
|
| 252 | + $displayName = is_null($user) ? null : $user->getDisplayName(); |
|
| 253 | + $result[self::PROPERTY_NAME_ACTOR_DISPLAYNAME] = $displayName; |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - $result[self::PROPERTY_NAME_MENTIONS] = $this->composeMentionsPropertyValue(); |
|
| 256 | + $result[self::PROPERTY_NAME_MENTIONS] = $this->composeMentionsPropertyValue(); |
|
| 257 | 257 | |
| 258 | - $unread = null; |
|
| 259 | - $user = $this->userSession->getUser(); |
|
| 260 | - if (!is_null($user)) { |
|
| 261 | - $readUntil = $this->commentsManager->getReadMark( |
|
| 262 | - $this->comment->getObjectType(), |
|
| 263 | - $this->comment->getObjectId(), |
|
| 264 | - $user |
|
| 265 | - ); |
|
| 266 | - if (is_null($readUntil)) { |
|
| 267 | - $unread = 'true'; |
|
| 268 | - } else { |
|
| 269 | - $unread = $this->comment->getCreationDateTime() > $readUntil; |
|
| 270 | - // re-format for output |
|
| 271 | - $unread = $unread ? 'true' : 'false'; |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - $result[self::PROPERTY_NAME_UNREAD] = $unread; |
|
| 258 | + $unread = null; |
|
| 259 | + $user = $this->userSession->getUser(); |
|
| 260 | + if (!is_null($user)) { |
|
| 261 | + $readUntil = $this->commentsManager->getReadMark( |
|
| 262 | + $this->comment->getObjectType(), |
|
| 263 | + $this->comment->getObjectId(), |
|
| 264 | + $user |
|
| 265 | + ); |
|
| 266 | + if (is_null($readUntil)) { |
|
| 267 | + $unread = 'true'; |
|
| 268 | + } else { |
|
| 269 | + $unread = $this->comment->getCreationDateTime() > $readUntil; |
|
| 270 | + // re-format for output |
|
| 271 | + $unread = $unread ? 'true' : 'false'; |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + $result[self::PROPERTY_NAME_UNREAD] = $unread; |
|
| 275 | 275 | |
| 276 | - return $result; |
|
| 277 | - } |
|
| 276 | + return $result; |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - /** |
|
| 280 | - * transforms a mentions array as returned from IComment->getMentions to an |
|
| 281 | - * array with DAV-compatible structure that can be assigned to the |
|
| 282 | - * PROPERTY_NAME_MENTION property. |
|
| 283 | - * |
|
| 284 | - * @return array |
|
| 285 | - */ |
|
| 286 | - protected function composeMentionsPropertyValue() { |
|
| 287 | - return array_map(function ($mention) { |
|
| 288 | - try { |
|
| 289 | - $displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']); |
|
| 290 | - } catch (\OutOfBoundsException $e) { |
|
| 291 | - $this->logger->logException($e); |
|
| 292 | - // No displayname, upon client's discretion what to display. |
|
| 293 | - $displayName = ''; |
|
| 294 | - } |
|
| 279 | + /** |
|
| 280 | + * transforms a mentions array as returned from IComment->getMentions to an |
|
| 281 | + * array with DAV-compatible structure that can be assigned to the |
|
| 282 | + * PROPERTY_NAME_MENTION property. |
|
| 283 | + * |
|
| 284 | + * @return array |
|
| 285 | + */ |
|
| 286 | + protected function composeMentionsPropertyValue() { |
|
| 287 | + return array_map(function ($mention) { |
|
| 288 | + try { |
|
| 289 | + $displayName = $this->commentsManager->resolveDisplayName($mention['type'], $mention['id']); |
|
| 290 | + } catch (\OutOfBoundsException $e) { |
|
| 291 | + $this->logger->logException($e); |
|
| 292 | + // No displayname, upon client's discretion what to display. |
|
| 293 | + $displayName = ''; |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | - return [ |
|
| 297 | - self::PROPERTY_NAME_MENTION => [ |
|
| 298 | - self::PROPERTY_NAME_MENTION_TYPE => $mention['type'], |
|
| 299 | - self::PROPERTY_NAME_MENTION_ID => $mention['id'], |
|
| 300 | - self::PROPERTY_NAME_MENTION_DISPLAYNAME => $displayName, |
|
| 301 | - ] |
|
| 302 | - ]; |
|
| 303 | - }, $this->comment->getMentions()); |
|
| 304 | - } |
|
| 296 | + return [ |
|
| 297 | + self::PROPERTY_NAME_MENTION => [ |
|
| 298 | + self::PROPERTY_NAME_MENTION_TYPE => $mention['type'], |
|
| 299 | + self::PROPERTY_NAME_MENTION_ID => $mention['id'], |
|
| 300 | + self::PROPERTY_NAME_MENTION_DISPLAYNAME => $displayName, |
|
| 301 | + ] |
|
| 302 | + ]; |
|
| 303 | + }, $this->comment->getMentions()); |
|
| 304 | + } |
|
| 305 | 305 | } |
@@ -77,7 +77,7 @@ |
||
| 77 | 77 | $path = array_pop($path); |
| 78 | 78 | |
| 79 | 79 | $newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view); |
| 80 | - $url = $request->getBaseUrl() . $newName; |
|
| 80 | + $url = $request->getBaseUrl().$newName; |
|
| 81 | 81 | $request->setUrl($url); |
| 82 | 82 | } |
| 83 | 83 | } |
@@ -35,51 +35,51 @@ |
||
| 35 | 35 | */ |
| 36 | 36 | class FilesDropPlugin extends ServerPlugin { |
| 37 | 37 | |
| 38 | - /** @var View */ |
|
| 39 | - private $view; |
|
| 38 | + /** @var View */ |
|
| 39 | + private $view; |
|
| 40 | 40 | |
| 41 | - /** @var bool */ |
|
| 42 | - private $enabled = false; |
|
| 41 | + /** @var bool */ |
|
| 42 | + private $enabled = false; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @param View $view |
|
| 46 | - */ |
|
| 47 | - public function setView($view) { |
|
| 48 | - $this->view = $view; |
|
| 49 | - } |
|
| 44 | + /** |
|
| 45 | + * @param View $view |
|
| 46 | + */ |
|
| 47 | + public function setView($view) { |
|
| 48 | + $this->view = $view; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - public function enable() { |
|
| 52 | - $this->enabled = true; |
|
| 53 | - } |
|
| 51 | + public function enable() { |
|
| 52 | + $this->enabled = true; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * This initializes the plugin. |
|
| 58 | - * |
|
| 59 | - * @param \Sabre\DAV\Server $server Sabre server |
|
| 60 | - * |
|
| 61 | - * @return void |
|
| 62 | - * @throws MethodNotAllowed |
|
| 63 | - */ |
|
| 64 | - public function initialize(\Sabre\DAV\Server $server) { |
|
| 65 | - $server->on('beforeMethod:*', [$this, 'beforeMethod'], 999); |
|
| 66 | - $this->enabled = false; |
|
| 67 | - } |
|
| 56 | + /** |
|
| 57 | + * This initializes the plugin. |
|
| 58 | + * |
|
| 59 | + * @param \Sabre\DAV\Server $server Sabre server |
|
| 60 | + * |
|
| 61 | + * @return void |
|
| 62 | + * @throws MethodNotAllowed |
|
| 63 | + */ |
|
| 64 | + public function initialize(\Sabre\DAV\Server $server) { |
|
| 65 | + $server->on('beforeMethod:*', [$this, 'beforeMethod'], 999); |
|
| 66 | + $this->enabled = false; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - public function beforeMethod(RequestInterface $request, ResponseInterface $response) { |
|
| 70 | - if (!$this->enabled) { |
|
| 71 | - return; |
|
| 72 | - } |
|
| 69 | + public function beforeMethod(RequestInterface $request, ResponseInterface $response) { |
|
| 70 | + if (!$this->enabled) { |
|
| 71 | + return; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - if ($request->getMethod() !== 'PUT') { |
|
| 75 | - throw new MethodNotAllowed('Only PUT is allowed on files drop'); |
|
| 76 | - } |
|
| 74 | + if ($request->getMethod() !== 'PUT') { |
|
| 75 | + throw new MethodNotAllowed('Only PUT is allowed on files drop'); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - $path = explode('/', $request->getPath()); |
|
| 79 | - $path = array_pop($path); |
|
| 78 | + $path = explode('/', $request->getPath()); |
|
| 79 | + $path = array_pop($path); |
|
| 80 | 80 | |
| 81 | - $newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view); |
|
| 82 | - $url = $request->getBaseUrl() . $newName; |
|
| 83 | - $request->setUrl($url); |
|
| 84 | - } |
|
| 81 | + $newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view); |
|
| 82 | + $url = $request->getBaseUrl() . $newName; |
|
| 83 | + $request->setUrl($url); |
|
| 84 | + } |
|
| 85 | 85 | } |
@@ -54,7 +54,7 @@ |
||
| 54 | 54 | $output->writeln('Syncing users ...'); |
| 55 | 55 | $progress = new ProgressBar($output); |
| 56 | 56 | $progress->start(); |
| 57 | - $this->syncService->syncInstance(function () use ($progress) { |
|
| 57 | + $this->syncService->syncInstance(function() use ($progress) { |
|
| 58 | 58 | $progress->advance(); |
| 59 | 59 | }); |
| 60 | 60 | |
@@ -32,37 +32,37 @@ |
||
| 32 | 32 | |
| 33 | 33 | class SyncSystemAddressBook extends Command { |
| 34 | 34 | |
| 35 | - /** @var SyncService */ |
|
| 36 | - private $syncService; |
|
| 35 | + /** @var SyncService */ |
|
| 36 | + private $syncService; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @param SyncService $syncService |
|
| 40 | - */ |
|
| 41 | - public function __construct(SyncService $syncService) { |
|
| 42 | - parent::__construct(); |
|
| 43 | - $this->syncService = $syncService; |
|
| 44 | - } |
|
| 38 | + /** |
|
| 39 | + * @param SyncService $syncService |
|
| 40 | + */ |
|
| 41 | + public function __construct(SyncService $syncService) { |
|
| 42 | + parent::__construct(); |
|
| 43 | + $this->syncService = $syncService; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - protected function configure() { |
|
| 47 | - $this |
|
| 48 | - ->setName('dav:sync-system-addressbook') |
|
| 49 | - ->setDescription('Synchronizes users to the system addressbook'); |
|
| 50 | - } |
|
| 46 | + protected function configure() { |
|
| 47 | + $this |
|
| 48 | + ->setName('dav:sync-system-addressbook') |
|
| 49 | + ->setDescription('Synchronizes users to the system addressbook'); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @param InputInterface $input |
|
| 54 | - * @param OutputInterface $output |
|
| 55 | - */ |
|
| 56 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 57 | - $output->writeln('Syncing users ...'); |
|
| 58 | - $progress = new ProgressBar($output); |
|
| 59 | - $progress->start(); |
|
| 60 | - $this->syncService->syncInstance(function () use ($progress) { |
|
| 61 | - $progress->advance(); |
|
| 62 | - }); |
|
| 52 | + /** |
|
| 53 | + * @param InputInterface $input |
|
| 54 | + * @param OutputInterface $output |
|
| 55 | + */ |
|
| 56 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 57 | + $output->writeln('Syncing users ...'); |
|
| 58 | + $progress = new ProgressBar($output); |
|
| 59 | + $progress->start(); |
|
| 60 | + $this->syncService->syncInstance(function () use ($progress) { |
|
| 61 | + $progress->advance(); |
|
| 62 | + }); |
|
| 63 | 63 | |
| 64 | - $progress->finish(); |
|
| 65 | - $output->writeln(''); |
|
| 66 | - return 0; |
|
| 67 | - } |
|
| 64 | + $progress->finish(); |
|
| 65 | + $output->writeln(''); |
|
| 66 | + return 0; |
|
| 67 | + } |
|
| 68 | 68 | } |
@@ -58,7 +58,7 @@ |
||
| 58 | 58 | public function getChild($name) { |
| 59 | 59 | $elements = pathinfo($name); |
| 60 | 60 | $ext = isset($elements['extension']) ? $elements['extension'] : ''; |
| 61 | - $size = (int)(isset($elements['filename']) ? $elements['filename'] : '64'); |
|
| 61 | + $size = (int) (isset($elements['filename']) ? $elements['filename'] : '64'); |
|
| 62 | 62 | if (!in_array($ext, ['jpeg', 'png'], true)) { |
| 63 | 63 | throw new MethodNotAllowed('File format not allowed'); |
| 64 | 64 | } |
@@ -34,87 +34,87 @@ |
||
| 34 | 34 | |
| 35 | 35 | class AvatarHome implements ICollection { |
| 36 | 36 | |
| 37 | - /** @var array */ |
|
| 38 | - private $principalInfo; |
|
| 39 | - /** @var IAvatarManager */ |
|
| 40 | - private $avatarManager; |
|
| 37 | + /** @var array */ |
|
| 38 | + private $principalInfo; |
|
| 39 | + /** @var IAvatarManager */ |
|
| 40 | + private $avatarManager; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * AvatarHome constructor. |
|
| 44 | - * |
|
| 45 | - * @param array $principalInfo |
|
| 46 | - * @param IAvatarManager $avatarManager |
|
| 47 | - */ |
|
| 48 | - public function __construct($principalInfo, IAvatarManager $avatarManager) { |
|
| 49 | - $this->principalInfo = $principalInfo; |
|
| 50 | - $this->avatarManager = $avatarManager; |
|
| 51 | - } |
|
| 42 | + /** |
|
| 43 | + * AvatarHome constructor. |
|
| 44 | + * |
|
| 45 | + * @param array $principalInfo |
|
| 46 | + * @param IAvatarManager $avatarManager |
|
| 47 | + */ |
|
| 48 | + public function __construct($principalInfo, IAvatarManager $avatarManager) { |
|
| 49 | + $this->principalInfo = $principalInfo; |
|
| 50 | + $this->avatarManager = $avatarManager; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - public function createFile($name, $data = null) { |
|
| 54 | - throw new Forbidden('Permission denied to create a file'); |
|
| 55 | - } |
|
| 53 | + public function createFile($name, $data = null) { |
|
| 54 | + throw new Forbidden('Permission denied to create a file'); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - public function createDirectory($name) { |
|
| 58 | - throw new Forbidden('Permission denied to create a folder'); |
|
| 59 | - } |
|
| 57 | + public function createDirectory($name) { |
|
| 58 | + throw new Forbidden('Permission denied to create a folder'); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - public function getChild($name) { |
|
| 62 | - $elements = pathinfo($name); |
|
| 63 | - $ext = isset($elements['extension']) ? $elements['extension'] : ''; |
|
| 64 | - $size = (int)(isset($elements['filename']) ? $elements['filename'] : '64'); |
|
| 65 | - if (!in_array($ext, ['jpeg', 'png'], true)) { |
|
| 66 | - throw new MethodNotAllowed('File format not allowed'); |
|
| 67 | - } |
|
| 68 | - if ($size <= 0 || $size > 1024) { |
|
| 69 | - throw new MethodNotAllowed('Invalid image size'); |
|
| 70 | - } |
|
| 71 | - $avatar = $this->avatarManager->getAvatar($this->getName()); |
|
| 72 | - if (!$avatar->exists()) { |
|
| 73 | - throw new NotFound(); |
|
| 74 | - } |
|
| 75 | - return new AvatarNode($size, $ext, $avatar); |
|
| 76 | - } |
|
| 61 | + public function getChild($name) { |
|
| 62 | + $elements = pathinfo($name); |
|
| 63 | + $ext = isset($elements['extension']) ? $elements['extension'] : ''; |
|
| 64 | + $size = (int)(isset($elements['filename']) ? $elements['filename'] : '64'); |
|
| 65 | + if (!in_array($ext, ['jpeg', 'png'], true)) { |
|
| 66 | + throw new MethodNotAllowed('File format not allowed'); |
|
| 67 | + } |
|
| 68 | + if ($size <= 0 || $size > 1024) { |
|
| 69 | + throw new MethodNotAllowed('Invalid image size'); |
|
| 70 | + } |
|
| 71 | + $avatar = $this->avatarManager->getAvatar($this->getName()); |
|
| 72 | + if (!$avatar->exists()) { |
|
| 73 | + throw new NotFound(); |
|
| 74 | + } |
|
| 75 | + return new AvatarNode($size, $ext, $avatar); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - public function getChildren() { |
|
| 79 | - try { |
|
| 80 | - return [ |
|
| 81 | - $this->getChild('96.jpeg') |
|
| 82 | - ]; |
|
| 83 | - } catch (NotFound $exception) { |
|
| 84 | - return []; |
|
| 85 | - } |
|
| 86 | - } |
|
| 78 | + public function getChildren() { |
|
| 79 | + try { |
|
| 80 | + return [ |
|
| 81 | + $this->getChild('96.jpeg') |
|
| 82 | + ]; |
|
| 83 | + } catch (NotFound $exception) { |
|
| 84 | + return []; |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - public function childExists($name) { |
|
| 89 | - try { |
|
| 90 | - $ret = $this->getChild($name); |
|
| 91 | - return $ret !== null; |
|
| 92 | - } catch (NotFound $ex) { |
|
| 93 | - return false; |
|
| 94 | - } catch (MethodNotAllowed $ex) { |
|
| 95 | - return false; |
|
| 96 | - } |
|
| 97 | - } |
|
| 88 | + public function childExists($name) { |
|
| 89 | + try { |
|
| 90 | + $ret = $this->getChild($name); |
|
| 91 | + return $ret !== null; |
|
| 92 | + } catch (NotFound $ex) { |
|
| 93 | + return false; |
|
| 94 | + } catch (MethodNotAllowed $ex) { |
|
| 95 | + return false; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - public function delete() { |
|
| 100 | - throw new Forbidden('Permission denied to delete this folder'); |
|
| 101 | - } |
|
| 99 | + public function delete() { |
|
| 100 | + throw new Forbidden('Permission denied to delete this folder'); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - public function getName() { |
|
| 104 | - [,$name] = Uri\split($this->principalInfo['uri']); |
|
| 105 | - return $name; |
|
| 106 | - } |
|
| 103 | + public function getName() { |
|
| 104 | + [,$name] = Uri\split($this->principalInfo['uri']); |
|
| 105 | + return $name; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - public function setName($name) { |
|
| 109 | - throw new Forbidden('Permission denied to rename this folder'); |
|
| 110 | - } |
|
| 108 | + public function setName($name) { |
|
| 109 | + throw new Forbidden('Permission denied to rename this folder'); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Returns the last modification time, as a unix timestamp |
|
| 114 | - * |
|
| 115 | - * @return int|null |
|
| 116 | - */ |
|
| 117 | - public function getLastModified() { |
|
| 118 | - return null; |
|
| 119 | - } |
|
| 112 | + /** |
|
| 113 | + * Returns the last modification time, as a unix timestamp |
|
| 114 | + * |
|
| 115 | + * @return int|null |
|
| 116 | + */ |
|
| 117 | + public function getLastModified() { |
|
| 118 | + return null; |
|
| 119 | + } |
|
| 120 | 120 | } |
@@ -26,71 +26,71 @@ |
||
| 26 | 26 | use Sabre\DAV\File; |
| 27 | 27 | |
| 28 | 28 | class AvatarNode extends File { |
| 29 | - private $ext; |
|
| 30 | - private $size; |
|
| 31 | - private $avatar; |
|
| 29 | + private $ext; |
|
| 30 | + private $size; |
|
| 31 | + private $avatar; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * AvatarNode constructor. |
|
| 35 | - * |
|
| 36 | - * @param integer $size |
|
| 37 | - * @param string $ext |
|
| 38 | - * @param IAvatar $avatar |
|
| 39 | - */ |
|
| 40 | - public function __construct($size, $ext, $avatar) { |
|
| 41 | - $this->size = $size; |
|
| 42 | - $this->ext = $ext; |
|
| 43 | - $this->avatar = $avatar; |
|
| 44 | - } |
|
| 33 | + /** |
|
| 34 | + * AvatarNode constructor. |
|
| 35 | + * |
|
| 36 | + * @param integer $size |
|
| 37 | + * @param string $ext |
|
| 38 | + * @param IAvatar $avatar |
|
| 39 | + */ |
|
| 40 | + public function __construct($size, $ext, $avatar) { |
|
| 41 | + $this->size = $size; |
|
| 42 | + $this->ext = $ext; |
|
| 43 | + $this->avatar = $avatar; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Returns the name of the node. |
|
| 48 | - * |
|
| 49 | - * This is used to generate the url. |
|
| 50 | - * |
|
| 51 | - * @return string |
|
| 52 | - */ |
|
| 53 | - public function getName() { |
|
| 54 | - return "$this->size.$this->ext"; |
|
| 55 | - } |
|
| 46 | + /** |
|
| 47 | + * Returns the name of the node. |
|
| 48 | + * |
|
| 49 | + * This is used to generate the url. |
|
| 50 | + * |
|
| 51 | + * @return string |
|
| 52 | + */ |
|
| 53 | + public function getName() { |
|
| 54 | + return "$this->size.$this->ext"; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - public function get() { |
|
| 58 | - $image = $this->avatar->get($this->size); |
|
| 59 | - $res = $image->resource(); |
|
| 57 | + public function get() { |
|
| 58 | + $image = $this->avatar->get($this->size); |
|
| 59 | + $res = $image->resource(); |
|
| 60 | 60 | |
| 61 | - ob_start(); |
|
| 62 | - if ($this->ext === 'png') { |
|
| 63 | - imagepng($res); |
|
| 64 | - } else { |
|
| 65 | - imagejpeg($res); |
|
| 66 | - } |
|
| 61 | + ob_start(); |
|
| 62 | + if ($this->ext === 'png') { |
|
| 63 | + imagepng($res); |
|
| 64 | + } else { |
|
| 65 | + imagejpeg($res); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - return ob_get_clean(); |
|
| 69 | - } |
|
| 68 | + return ob_get_clean(); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Returns the mime-type for a file |
|
| 73 | - * |
|
| 74 | - * If null is returned, we'll assume application/octet-stream |
|
| 75 | - * |
|
| 76 | - * @return string|null |
|
| 77 | - */ |
|
| 78 | - public function getContentType() { |
|
| 79 | - if ($this->ext === 'png') { |
|
| 80 | - return 'image/png'; |
|
| 81 | - } |
|
| 82 | - return 'image/jpeg'; |
|
| 83 | - } |
|
| 71 | + /** |
|
| 72 | + * Returns the mime-type for a file |
|
| 73 | + * |
|
| 74 | + * If null is returned, we'll assume application/octet-stream |
|
| 75 | + * |
|
| 76 | + * @return string|null |
|
| 77 | + */ |
|
| 78 | + public function getContentType() { |
|
| 79 | + if ($this->ext === 'png') { |
|
| 80 | + return 'image/png'; |
|
| 81 | + } |
|
| 82 | + return 'image/jpeg'; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - public function getETag() { |
|
| 86 | - return $this->avatar->getFile($this->size)->getEtag(); |
|
| 87 | - } |
|
| 85 | + public function getETag() { |
|
| 86 | + return $this->avatar->getFile($this->size)->getEtag(); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - public function getLastModified() { |
|
| 90 | - $timestamp = $this->avatar->getFile($this->size)->getMTime(); |
|
| 91 | - if (!empty($timestamp)) { |
|
| 92 | - return (int)$timestamp; |
|
| 93 | - } |
|
| 94 | - return $timestamp; |
|
| 95 | - } |
|
| 89 | + public function getLastModified() { |
|
| 90 | + $timestamp = $this->avatar->getFile($this->size)->getMTime(); |
|
| 91 | + if (!empty($timestamp)) { |
|
| 92 | + return (int)$timestamp; |
|
| 93 | + } |
|
| 94 | + return $timestamp; |
|
| 95 | + } |
|
| 96 | 96 | } |
@@ -89,7 +89,7 @@ |
||
| 89 | 89 | public function getLastModified() { |
| 90 | 90 | $timestamp = $this->avatar->getFile($this->size)->getMTime(); |
| 91 | 91 | if (!empty($timestamp)) { |
| 92 | - return (int)$timestamp; |
|
| 92 | + return (int) $timestamp; |
|
| 93 | 93 | } |
| 94 | 94 | return $timestamp; |
| 95 | 95 | } |
@@ -39,7 +39,7 @@ |
||
| 39 | 39 | |
| 40 | 40 | public function xmlSerialize(Writer $writer) { |
| 41 | 41 | foreach ($this->groups as $group) { |
| 42 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}group', $group); |
|
| 42 | + $writer->writeElement('{'.self::NS_OWNCLOUD.'}group', $group); |
|
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | } |
@@ -27,21 +27,21 @@ |
||
| 27 | 27 | use Sabre\Xml\XmlSerializable; |
| 28 | 28 | |
| 29 | 29 | class Groups implements XmlSerializable { |
| 30 | - public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 30 | + public const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
| 31 | 31 | |
| 32 | - /** @var string[] of TYPE:CHECKSUM */ |
|
| 33 | - private $groups; |
|
| 32 | + /** @var string[] of TYPE:CHECKSUM */ |
|
| 33 | + private $groups; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @param string $groups |
|
| 37 | - */ |
|
| 38 | - public function __construct($groups) { |
|
| 39 | - $this->groups = $groups; |
|
| 40 | - } |
|
| 35 | + /** |
|
| 36 | + * @param string $groups |
|
| 37 | + */ |
|
| 38 | + public function __construct($groups) { |
|
| 39 | + $this->groups = $groups; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - public function xmlSerialize(Writer $writer) { |
|
| 43 | - foreach ($this->groups as $group) { |
|
| 44 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}group', $group); |
|
| 45 | - } |
|
| 46 | - } |
|
| 42 | + public function xmlSerialize(Writer $writer) { |
|
| 43 | + foreach ($this->groups as $group) { |
|
| 44 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}group', $group); |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { |
| 97 | 97 | // remote server revoked access to the address book, remove it |
| 98 | 98 | $this->backend->deleteAddressBook($addressBookId); |
| 99 | - $this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']); |
|
| 99 | + $this->logger->info('Authorization failed, remove address book: '.$url, ['app' => 'dav']); |
|
| 100 | 100 | throw $ex; |
| 101 | 101 | } |
| 102 | 102 | } |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | */ |
| 170 | 170 | protected function getClient($url, $userName, $sharedSecret) { |
| 171 | 171 | $settings = [ |
| 172 | - 'baseUri' => $url . '/', |
|
| 172 | + 'baseUri' => $url.'/', |
|
| 173 | 173 | 'userName' => $userName, |
| 174 | 174 | 'password' => $sharedSecret, |
| 175 | 175 | ]; |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | if (is_null($this->localSystemAddressBook)) { |
| 307 | 307 | $systemPrincipal = "principals/system/system"; |
| 308 | 308 | $this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [ |
| 309 | - '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance' |
|
| 309 | + '{'.Plugin::NS_CARDDAV.'}addressbook-description' => 'System addressbook which holds all users of this instance' |
|
| 310 | 310 | ]); |
| 311 | 311 | } |
| 312 | 312 | |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | |
| 316 | 316 | public function syncInstance(\Closure $progressCallback = null) { |
| 317 | 317 | $systemAddressBook = $this->getLocalSystemAddressBook(); |
| 318 | - $this->userManager->callForAllUsers(function ($user) use ($systemAddressBook, $progressCallback) { |
|
| 318 | + $this->userManager->callForAllUsers(function($user) use ($systemAddressBook, $progressCallback) { |
|
| 319 | 319 | $this->updateUser($user); |
| 320 | 320 | if (!is_null($progressCallback)) { |
| 321 | 321 | $progressCallback(); |
@@ -42,300 +42,300 @@ |
||
| 42 | 42 | |
| 43 | 43 | class SyncService { |
| 44 | 44 | |
| 45 | - /** @var CardDavBackend */ |
|
| 46 | - private $backend; |
|
| 47 | - |
|
| 48 | - /** @var IUserManager */ |
|
| 49 | - private $userManager; |
|
| 50 | - |
|
| 51 | - /** @var ILogger */ |
|
| 52 | - private $logger; |
|
| 53 | - |
|
| 54 | - /** @var array */ |
|
| 55 | - private $localSystemAddressBook; |
|
| 56 | - |
|
| 57 | - /** @var AccountManager */ |
|
| 58 | - private $accountManager; |
|
| 59 | - |
|
| 60 | - /** @var string */ |
|
| 61 | - protected $certPath; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * SyncService constructor. |
|
| 65 | - * |
|
| 66 | - * @param CardDavBackend $backend |
|
| 67 | - * @param IUserManager $userManager |
|
| 68 | - * @param ILogger $logger |
|
| 69 | - * @param AccountManager $accountManager |
|
| 70 | - */ |
|
| 71 | - public function __construct(CardDavBackend $backend, IUserManager $userManager, ILogger $logger, AccountManager $accountManager) { |
|
| 72 | - $this->backend = $backend; |
|
| 73 | - $this->userManager = $userManager; |
|
| 74 | - $this->logger = $logger; |
|
| 75 | - $this->accountManager = $accountManager; |
|
| 76 | - $this->certPath = ''; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @param string $url |
|
| 81 | - * @param string $userName |
|
| 82 | - * @param string $addressBookUrl |
|
| 83 | - * @param string $sharedSecret |
|
| 84 | - * @param string $syncToken |
|
| 85 | - * @param int $targetBookId |
|
| 86 | - * @param string $targetPrincipal |
|
| 87 | - * @param array $targetProperties |
|
| 88 | - * @return string |
|
| 89 | - * @throws \Exception |
|
| 90 | - */ |
|
| 91 | - public function syncRemoteAddressBook($url, $userName, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetProperties) { |
|
| 92 | - // 1. create addressbook |
|
| 93 | - $book = $this->ensureSystemAddressBookExists($targetPrincipal, $targetBookId, $targetProperties); |
|
| 94 | - $addressBookId = $book['id']; |
|
| 95 | - |
|
| 96 | - // 2. query changes |
|
| 97 | - try { |
|
| 98 | - $response = $this->requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken); |
|
| 99 | - } catch (ClientHttpException $ex) { |
|
| 100 | - if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { |
|
| 101 | - // remote server revoked access to the address book, remove it |
|
| 102 | - $this->backend->deleteAddressBook($addressBookId); |
|
| 103 | - $this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']); |
|
| 104 | - throw $ex; |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - // 3. apply changes |
|
| 109 | - // TODO: use multi-get for download |
|
| 110 | - foreach ($response['response'] as $resource => $status) { |
|
| 111 | - $cardUri = basename($resource); |
|
| 112 | - if (isset($status[200])) { |
|
| 113 | - $vCard = $this->download($url, $userName, $sharedSecret, $resource); |
|
| 114 | - $existingCard = $this->backend->getCard($addressBookId, $cardUri); |
|
| 115 | - if ($existingCard === false) { |
|
| 116 | - $this->backend->createCard($addressBookId, $cardUri, $vCard['body']); |
|
| 117 | - } else { |
|
| 118 | - $this->backend->updateCard($addressBookId, $cardUri, $vCard['body']); |
|
| 119 | - } |
|
| 120 | - } else { |
|
| 121 | - $this->backend->deleteCard($addressBookId, $cardUri); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return $response['token']; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @param string $principal |
|
| 130 | - * @param string $id |
|
| 131 | - * @param array $properties |
|
| 132 | - * @return array|null |
|
| 133 | - * @throws \Sabre\DAV\Exception\BadRequest |
|
| 134 | - */ |
|
| 135 | - public function ensureSystemAddressBookExists($principal, $id, $properties) { |
|
| 136 | - $book = $this->backend->getAddressBooksByUri($principal, $id); |
|
| 137 | - if (!is_null($book)) { |
|
| 138 | - return $book; |
|
| 139 | - } |
|
| 140 | - $this->backend->createAddressBook($principal, $id, $properties); |
|
| 141 | - |
|
| 142 | - return $this->backend->getAddressBooksByUri($principal, $id); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Check if there is a valid certPath we should use |
|
| 147 | - * |
|
| 148 | - * @return string |
|
| 149 | - */ |
|
| 150 | - protected function getCertPath() { |
|
| 151 | - |
|
| 152 | - // we already have a valid certPath |
|
| 153 | - if ($this->certPath !== '') { |
|
| 154 | - return $this->certPath; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - $certManager = \OC::$server->getCertificateManager(); |
|
| 158 | - $certPath = $certManager->getAbsoluteBundlePath(); |
|
| 159 | - if (file_exists($certPath)) { |
|
| 160 | - $this->certPath = $certPath; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - return $this->certPath; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @param string $url |
|
| 168 | - * @param string $userName |
|
| 169 | - * @param string $addressBookUrl |
|
| 170 | - * @param string $sharedSecret |
|
| 171 | - * @return Client |
|
| 172 | - */ |
|
| 173 | - protected function getClient($url, $userName, $sharedSecret) { |
|
| 174 | - $settings = [ |
|
| 175 | - 'baseUri' => $url . '/', |
|
| 176 | - 'userName' => $userName, |
|
| 177 | - 'password' => $sharedSecret, |
|
| 178 | - ]; |
|
| 179 | - $client = new Client($settings); |
|
| 180 | - $certPath = $this->getCertPath(); |
|
| 181 | - $client->setThrowExceptions(true); |
|
| 182 | - |
|
| 183 | - if ($certPath !== '' && strpos($url, 'http://') !== 0) { |
|
| 184 | - $client->addCurlSetting(CURLOPT_CAINFO, $this->certPath); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - return $client; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * @param string $url |
|
| 192 | - * @param string $userName |
|
| 193 | - * @param string $addressBookUrl |
|
| 194 | - * @param string $sharedSecret |
|
| 195 | - * @param string $syncToken |
|
| 196 | - * @return array |
|
| 197 | - */ |
|
| 198 | - protected function requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken) { |
|
| 199 | - $client = $this->getClient($url, $userName, $sharedSecret); |
|
| 200 | - |
|
| 201 | - $body = $this->buildSyncCollectionRequestBody($syncToken); |
|
| 202 | - |
|
| 203 | - $response = $client->request('REPORT', $addressBookUrl, $body, [ |
|
| 204 | - 'Content-Type' => 'application/xml' |
|
| 205 | - ]); |
|
| 206 | - |
|
| 207 | - return $this->parseMultiStatus($response['body']); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * @param string $url |
|
| 212 | - * @param string $userName |
|
| 213 | - * @param string $sharedSecret |
|
| 214 | - * @param string $resourcePath |
|
| 215 | - * @return array |
|
| 216 | - */ |
|
| 217 | - protected function download($url, $userName, $sharedSecret, $resourcePath) { |
|
| 218 | - $client = $this->getClient($url, $userName, $sharedSecret); |
|
| 219 | - return $client->request('GET', $resourcePath); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * @param string|null $syncToken |
|
| 224 | - * @return string |
|
| 225 | - */ |
|
| 226 | - private function buildSyncCollectionRequestBody($syncToken) { |
|
| 227 | - $dom = new \DOMDocument('1.0', 'UTF-8'); |
|
| 228 | - $dom->formatOutput = true; |
|
| 229 | - $root = $dom->createElementNS('DAV:', 'd:sync-collection'); |
|
| 230 | - $sync = $dom->createElement('d:sync-token', $syncToken); |
|
| 231 | - $prop = $dom->createElement('d:prop'); |
|
| 232 | - $cont = $dom->createElement('d:getcontenttype'); |
|
| 233 | - $etag = $dom->createElement('d:getetag'); |
|
| 234 | - |
|
| 235 | - $prop->appendChild($cont); |
|
| 236 | - $prop->appendChild($etag); |
|
| 237 | - $root->appendChild($sync); |
|
| 238 | - $root->appendChild($prop); |
|
| 239 | - $dom->appendChild($root); |
|
| 240 | - return $dom->saveXML(); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * @param string $body |
|
| 245 | - * @return array |
|
| 246 | - * @throws \Sabre\Xml\ParseException |
|
| 247 | - */ |
|
| 248 | - private function parseMultiStatus($body) { |
|
| 249 | - $xml = new Service(); |
|
| 250 | - |
|
| 251 | - /** @var MultiStatus $multiStatus */ |
|
| 252 | - $multiStatus = $xml->expect('{DAV:}multistatus', $body); |
|
| 253 | - |
|
| 254 | - $result = []; |
|
| 255 | - foreach ($multiStatus->getResponses() as $response) { |
|
| 256 | - $result[$response->getHref()] = $response->getResponseProperties(); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - return ['response' => $result, 'token' => $multiStatus->getSyncToken()]; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * @param IUser $user |
|
| 264 | - */ |
|
| 265 | - public function updateUser(IUser $user) { |
|
| 266 | - $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
| 267 | - $addressBookId = $systemAddressBook['id']; |
|
| 268 | - $converter = new Converter($this->accountManager); |
|
| 269 | - $name = $user->getBackendClassName(); |
|
| 270 | - $userId = $user->getUID(); |
|
| 271 | - |
|
| 272 | - $cardId = "$name:$userId.vcf"; |
|
| 273 | - $card = $this->backend->getCard($addressBookId, $cardId); |
|
| 274 | - if ($user->isEnabled()) { |
|
| 275 | - if ($card === false) { |
|
| 276 | - $vCard = $converter->createCardFromUser($user); |
|
| 277 | - if ($vCard !== null) { |
|
| 278 | - $this->backend->createCard($addressBookId, $cardId, $vCard->serialize()); |
|
| 279 | - } |
|
| 280 | - } else { |
|
| 281 | - $vCard = $converter->createCardFromUser($user); |
|
| 282 | - if (is_null($vCard)) { |
|
| 283 | - $this->backend->deleteCard($addressBookId, $cardId); |
|
| 284 | - } else { |
|
| 285 | - $this->backend->updateCard($addressBookId, $cardId, $vCard->serialize()); |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - } else { |
|
| 289 | - $this->backend->deleteCard($addressBookId, $cardId); |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * @param IUser|string $userOrCardId |
|
| 295 | - */ |
|
| 296 | - public function deleteUser($userOrCardId) { |
|
| 297 | - $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
| 298 | - if ($userOrCardId instanceof IUser) { |
|
| 299 | - $name = $userOrCardId->getBackendClassName(); |
|
| 300 | - $userId = $userOrCardId->getUID(); |
|
| 301 | - |
|
| 302 | - $userOrCardId = "$name:$userId.vcf"; |
|
| 303 | - } |
|
| 304 | - $this->backend->deleteCard($systemAddressBook['id'], $userOrCardId); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * @return array|null |
|
| 309 | - */ |
|
| 310 | - public function getLocalSystemAddressBook() { |
|
| 311 | - if (is_null($this->localSystemAddressBook)) { |
|
| 312 | - $systemPrincipal = "principals/system/system"; |
|
| 313 | - $this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [ |
|
| 314 | - '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance' |
|
| 315 | - ]); |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - return $this->localSystemAddressBook; |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - public function syncInstance(\Closure $progressCallback = null) { |
|
| 322 | - $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
| 323 | - $this->userManager->callForAllUsers(function ($user) use ($systemAddressBook, $progressCallback) { |
|
| 324 | - $this->updateUser($user); |
|
| 325 | - if (!is_null($progressCallback)) { |
|
| 326 | - $progressCallback(); |
|
| 327 | - } |
|
| 328 | - }); |
|
| 329 | - |
|
| 330 | - // remove no longer existing |
|
| 331 | - $allCards = $this->backend->getCards($systemAddressBook['id']); |
|
| 332 | - foreach ($allCards as $card) { |
|
| 333 | - $vCard = Reader::read($card['carddata']); |
|
| 334 | - $uid = $vCard->UID->getValue(); |
|
| 335 | - // load backend and see if user exists |
|
| 336 | - if (!$this->userManager->userExists($uid)) { |
|
| 337 | - $this->deleteUser($card['uri']); |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - } |
|
| 45 | + /** @var CardDavBackend */ |
|
| 46 | + private $backend; |
|
| 47 | + |
|
| 48 | + /** @var IUserManager */ |
|
| 49 | + private $userManager; |
|
| 50 | + |
|
| 51 | + /** @var ILogger */ |
|
| 52 | + private $logger; |
|
| 53 | + |
|
| 54 | + /** @var array */ |
|
| 55 | + private $localSystemAddressBook; |
|
| 56 | + |
|
| 57 | + /** @var AccountManager */ |
|
| 58 | + private $accountManager; |
|
| 59 | + |
|
| 60 | + /** @var string */ |
|
| 61 | + protected $certPath; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * SyncService constructor. |
|
| 65 | + * |
|
| 66 | + * @param CardDavBackend $backend |
|
| 67 | + * @param IUserManager $userManager |
|
| 68 | + * @param ILogger $logger |
|
| 69 | + * @param AccountManager $accountManager |
|
| 70 | + */ |
|
| 71 | + public function __construct(CardDavBackend $backend, IUserManager $userManager, ILogger $logger, AccountManager $accountManager) { |
|
| 72 | + $this->backend = $backend; |
|
| 73 | + $this->userManager = $userManager; |
|
| 74 | + $this->logger = $logger; |
|
| 75 | + $this->accountManager = $accountManager; |
|
| 76 | + $this->certPath = ''; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param string $url |
|
| 81 | + * @param string $userName |
|
| 82 | + * @param string $addressBookUrl |
|
| 83 | + * @param string $sharedSecret |
|
| 84 | + * @param string $syncToken |
|
| 85 | + * @param int $targetBookId |
|
| 86 | + * @param string $targetPrincipal |
|
| 87 | + * @param array $targetProperties |
|
| 88 | + * @return string |
|
| 89 | + * @throws \Exception |
|
| 90 | + */ |
|
| 91 | + public function syncRemoteAddressBook($url, $userName, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetProperties) { |
|
| 92 | + // 1. create addressbook |
|
| 93 | + $book = $this->ensureSystemAddressBookExists($targetPrincipal, $targetBookId, $targetProperties); |
|
| 94 | + $addressBookId = $book['id']; |
|
| 95 | + |
|
| 96 | + // 2. query changes |
|
| 97 | + try { |
|
| 98 | + $response = $this->requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken); |
|
| 99 | + } catch (ClientHttpException $ex) { |
|
| 100 | + if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) { |
|
| 101 | + // remote server revoked access to the address book, remove it |
|
| 102 | + $this->backend->deleteAddressBook($addressBookId); |
|
| 103 | + $this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']); |
|
| 104 | + throw $ex; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + // 3. apply changes |
|
| 109 | + // TODO: use multi-get for download |
|
| 110 | + foreach ($response['response'] as $resource => $status) { |
|
| 111 | + $cardUri = basename($resource); |
|
| 112 | + if (isset($status[200])) { |
|
| 113 | + $vCard = $this->download($url, $userName, $sharedSecret, $resource); |
|
| 114 | + $existingCard = $this->backend->getCard($addressBookId, $cardUri); |
|
| 115 | + if ($existingCard === false) { |
|
| 116 | + $this->backend->createCard($addressBookId, $cardUri, $vCard['body']); |
|
| 117 | + } else { |
|
| 118 | + $this->backend->updateCard($addressBookId, $cardUri, $vCard['body']); |
|
| 119 | + } |
|
| 120 | + } else { |
|
| 121 | + $this->backend->deleteCard($addressBookId, $cardUri); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + return $response['token']; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @param string $principal |
|
| 130 | + * @param string $id |
|
| 131 | + * @param array $properties |
|
| 132 | + * @return array|null |
|
| 133 | + * @throws \Sabre\DAV\Exception\BadRequest |
|
| 134 | + */ |
|
| 135 | + public function ensureSystemAddressBookExists($principal, $id, $properties) { |
|
| 136 | + $book = $this->backend->getAddressBooksByUri($principal, $id); |
|
| 137 | + if (!is_null($book)) { |
|
| 138 | + return $book; |
|
| 139 | + } |
|
| 140 | + $this->backend->createAddressBook($principal, $id, $properties); |
|
| 141 | + |
|
| 142 | + return $this->backend->getAddressBooksByUri($principal, $id); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Check if there is a valid certPath we should use |
|
| 147 | + * |
|
| 148 | + * @return string |
|
| 149 | + */ |
|
| 150 | + protected function getCertPath() { |
|
| 151 | + |
|
| 152 | + // we already have a valid certPath |
|
| 153 | + if ($this->certPath !== '') { |
|
| 154 | + return $this->certPath; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + $certManager = \OC::$server->getCertificateManager(); |
|
| 158 | + $certPath = $certManager->getAbsoluteBundlePath(); |
|
| 159 | + if (file_exists($certPath)) { |
|
| 160 | + $this->certPath = $certPath; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + return $this->certPath; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @param string $url |
|
| 168 | + * @param string $userName |
|
| 169 | + * @param string $addressBookUrl |
|
| 170 | + * @param string $sharedSecret |
|
| 171 | + * @return Client |
|
| 172 | + */ |
|
| 173 | + protected function getClient($url, $userName, $sharedSecret) { |
|
| 174 | + $settings = [ |
|
| 175 | + 'baseUri' => $url . '/', |
|
| 176 | + 'userName' => $userName, |
|
| 177 | + 'password' => $sharedSecret, |
|
| 178 | + ]; |
|
| 179 | + $client = new Client($settings); |
|
| 180 | + $certPath = $this->getCertPath(); |
|
| 181 | + $client->setThrowExceptions(true); |
|
| 182 | + |
|
| 183 | + if ($certPath !== '' && strpos($url, 'http://') !== 0) { |
|
| 184 | + $client->addCurlSetting(CURLOPT_CAINFO, $this->certPath); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + return $client; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * @param string $url |
|
| 192 | + * @param string $userName |
|
| 193 | + * @param string $addressBookUrl |
|
| 194 | + * @param string $sharedSecret |
|
| 195 | + * @param string $syncToken |
|
| 196 | + * @return array |
|
| 197 | + */ |
|
| 198 | + protected function requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken) { |
|
| 199 | + $client = $this->getClient($url, $userName, $sharedSecret); |
|
| 200 | + |
|
| 201 | + $body = $this->buildSyncCollectionRequestBody($syncToken); |
|
| 202 | + |
|
| 203 | + $response = $client->request('REPORT', $addressBookUrl, $body, [ |
|
| 204 | + 'Content-Type' => 'application/xml' |
|
| 205 | + ]); |
|
| 206 | + |
|
| 207 | + return $this->parseMultiStatus($response['body']); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * @param string $url |
|
| 212 | + * @param string $userName |
|
| 213 | + * @param string $sharedSecret |
|
| 214 | + * @param string $resourcePath |
|
| 215 | + * @return array |
|
| 216 | + */ |
|
| 217 | + protected function download($url, $userName, $sharedSecret, $resourcePath) { |
|
| 218 | + $client = $this->getClient($url, $userName, $sharedSecret); |
|
| 219 | + return $client->request('GET', $resourcePath); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * @param string|null $syncToken |
|
| 224 | + * @return string |
|
| 225 | + */ |
|
| 226 | + private function buildSyncCollectionRequestBody($syncToken) { |
|
| 227 | + $dom = new \DOMDocument('1.0', 'UTF-8'); |
|
| 228 | + $dom->formatOutput = true; |
|
| 229 | + $root = $dom->createElementNS('DAV:', 'd:sync-collection'); |
|
| 230 | + $sync = $dom->createElement('d:sync-token', $syncToken); |
|
| 231 | + $prop = $dom->createElement('d:prop'); |
|
| 232 | + $cont = $dom->createElement('d:getcontenttype'); |
|
| 233 | + $etag = $dom->createElement('d:getetag'); |
|
| 234 | + |
|
| 235 | + $prop->appendChild($cont); |
|
| 236 | + $prop->appendChild($etag); |
|
| 237 | + $root->appendChild($sync); |
|
| 238 | + $root->appendChild($prop); |
|
| 239 | + $dom->appendChild($root); |
|
| 240 | + return $dom->saveXML(); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * @param string $body |
|
| 245 | + * @return array |
|
| 246 | + * @throws \Sabre\Xml\ParseException |
|
| 247 | + */ |
|
| 248 | + private function parseMultiStatus($body) { |
|
| 249 | + $xml = new Service(); |
|
| 250 | + |
|
| 251 | + /** @var MultiStatus $multiStatus */ |
|
| 252 | + $multiStatus = $xml->expect('{DAV:}multistatus', $body); |
|
| 253 | + |
|
| 254 | + $result = []; |
|
| 255 | + foreach ($multiStatus->getResponses() as $response) { |
|
| 256 | + $result[$response->getHref()] = $response->getResponseProperties(); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + return ['response' => $result, 'token' => $multiStatus->getSyncToken()]; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * @param IUser $user |
|
| 264 | + */ |
|
| 265 | + public function updateUser(IUser $user) { |
|
| 266 | + $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
| 267 | + $addressBookId = $systemAddressBook['id']; |
|
| 268 | + $converter = new Converter($this->accountManager); |
|
| 269 | + $name = $user->getBackendClassName(); |
|
| 270 | + $userId = $user->getUID(); |
|
| 271 | + |
|
| 272 | + $cardId = "$name:$userId.vcf"; |
|
| 273 | + $card = $this->backend->getCard($addressBookId, $cardId); |
|
| 274 | + if ($user->isEnabled()) { |
|
| 275 | + if ($card === false) { |
|
| 276 | + $vCard = $converter->createCardFromUser($user); |
|
| 277 | + if ($vCard !== null) { |
|
| 278 | + $this->backend->createCard($addressBookId, $cardId, $vCard->serialize()); |
|
| 279 | + } |
|
| 280 | + } else { |
|
| 281 | + $vCard = $converter->createCardFromUser($user); |
|
| 282 | + if (is_null($vCard)) { |
|
| 283 | + $this->backend->deleteCard($addressBookId, $cardId); |
|
| 284 | + } else { |
|
| 285 | + $this->backend->updateCard($addressBookId, $cardId, $vCard->serialize()); |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + } else { |
|
| 289 | + $this->backend->deleteCard($addressBookId, $cardId); |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * @param IUser|string $userOrCardId |
|
| 295 | + */ |
|
| 296 | + public function deleteUser($userOrCardId) { |
|
| 297 | + $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
| 298 | + if ($userOrCardId instanceof IUser) { |
|
| 299 | + $name = $userOrCardId->getBackendClassName(); |
|
| 300 | + $userId = $userOrCardId->getUID(); |
|
| 301 | + |
|
| 302 | + $userOrCardId = "$name:$userId.vcf"; |
|
| 303 | + } |
|
| 304 | + $this->backend->deleteCard($systemAddressBook['id'], $userOrCardId); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * @return array|null |
|
| 309 | + */ |
|
| 310 | + public function getLocalSystemAddressBook() { |
|
| 311 | + if (is_null($this->localSystemAddressBook)) { |
|
| 312 | + $systemPrincipal = "principals/system/system"; |
|
| 313 | + $this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [ |
|
| 314 | + '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance' |
|
| 315 | + ]); |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + return $this->localSystemAddressBook; |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + public function syncInstance(\Closure $progressCallback = null) { |
|
| 322 | + $systemAddressBook = $this->getLocalSystemAddressBook(); |
|
| 323 | + $this->userManager->callForAllUsers(function ($user) use ($systemAddressBook, $progressCallback) { |
|
| 324 | + $this->updateUser($user); |
|
| 325 | + if (!is_null($progressCallback)) { |
|
| 326 | + $progressCallback(); |
|
| 327 | + } |
|
| 328 | + }); |
|
| 329 | + |
|
| 330 | + // remove no longer existing |
|
| 331 | + $allCards = $this->backend->getCards($systemAddressBook['id']); |
|
| 332 | + foreach ($allCards as $card) { |
|
| 333 | + $vCard = Reader::read($card['carddata']); |
|
| 334 | + $uid = $vCard->UID->getValue(); |
|
| 335 | + // load backend and see if user exists |
|
| 336 | + if (!$this->userManager->userExists($uid)) { |
|
| 337 | + $this->deleteUser($card['uri']); |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | 341 | } |
@@ -29,47 +29,47 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | interface IShareable extends INode { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Updates the list of shares. |
|
| 34 | - * |
|
| 35 | - * The first array is a list of people that are to be added to the |
|
| 36 | - * resource. |
|
| 37 | - * |
|
| 38 | - * Every element in the add array has the following properties: |
|
| 39 | - * * href - A url. Usually a mailto: address |
|
| 40 | - * * commonName - Usually a first and last name, or false |
|
| 41 | - * * summary - A description of the share, can also be false |
|
| 42 | - * * readOnly - A boolean value |
|
| 43 | - * |
|
| 44 | - * Every element in the remove array is just the address string. |
|
| 45 | - * |
|
| 46 | - * @param array $add |
|
| 47 | - * @param array $remove |
|
| 48 | - * @return void |
|
| 49 | - */ |
|
| 50 | - public function updateShares(array $add, array $remove); |
|
| 32 | + /** |
|
| 33 | + * Updates the list of shares. |
|
| 34 | + * |
|
| 35 | + * The first array is a list of people that are to be added to the |
|
| 36 | + * resource. |
|
| 37 | + * |
|
| 38 | + * Every element in the add array has the following properties: |
|
| 39 | + * * href - A url. Usually a mailto: address |
|
| 40 | + * * commonName - Usually a first and last name, or false |
|
| 41 | + * * summary - A description of the share, can also be false |
|
| 42 | + * * readOnly - A boolean value |
|
| 43 | + * |
|
| 44 | + * Every element in the remove array is just the address string. |
|
| 45 | + * |
|
| 46 | + * @param array $add |
|
| 47 | + * @param array $remove |
|
| 48 | + * @return void |
|
| 49 | + */ |
|
| 50 | + public function updateShares(array $add, array $remove); |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Returns the list of people whom this resource is shared with. |
|
| 54 | - * |
|
| 55 | - * Every element in this array should have the following properties: |
|
| 56 | - * * href - Often a mailto: address |
|
| 57 | - * * commonName - Optional, for example a first + last name |
|
| 58 | - * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
| 59 | - * * readOnly - boolean |
|
| 60 | - * * summary - Optional, a description for the share |
|
| 61 | - * |
|
| 62 | - * @return array |
|
| 63 | - */ |
|
| 64 | - public function getShares(); |
|
| 52 | + /** |
|
| 53 | + * Returns the list of people whom this resource is shared with. |
|
| 54 | + * |
|
| 55 | + * Every element in this array should have the following properties: |
|
| 56 | + * * href - Often a mailto: address |
|
| 57 | + * * commonName - Optional, for example a first + last name |
|
| 58 | + * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
| 59 | + * * readOnly - boolean |
|
| 60 | + * * summary - Optional, a description for the share |
|
| 61 | + * |
|
| 62 | + * @return array |
|
| 63 | + */ |
|
| 64 | + public function getShares(); |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @return int |
|
| 68 | - */ |
|
| 69 | - public function getResourceId(); |
|
| 66 | + /** |
|
| 67 | + * @return int |
|
| 68 | + */ |
|
| 69 | + public function getResourceId(); |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @return string |
|
| 73 | - */ |
|
| 74 | - public function getOwner(); |
|
| 71 | + /** |
|
| 72 | + * @return string |
|
| 73 | + */ |
|
| 74 | + public function getOwner(); |
|
| 75 | 75 | } |
@@ -41,120 +41,120 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | class Invite implements XmlSerializable { |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * The list of users a calendar has been shared to. |
|
| 46 | - * |
|
| 47 | - * @var array |
|
| 48 | - */ |
|
| 49 | - protected $users; |
|
| 44 | + /** |
|
| 45 | + * The list of users a calendar has been shared to. |
|
| 46 | + * |
|
| 47 | + * @var array |
|
| 48 | + */ |
|
| 49 | + protected $users; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * The organizer contains information about the person who shared the |
|
| 53 | - * object. |
|
| 54 | - * |
|
| 55 | - * @var array|null |
|
| 56 | - */ |
|
| 57 | - protected $organizer; |
|
| 51 | + /** |
|
| 52 | + * The organizer contains information about the person who shared the |
|
| 53 | + * object. |
|
| 54 | + * |
|
| 55 | + * @var array|null |
|
| 56 | + */ |
|
| 57 | + protected $organizer; |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Creates the property. |
|
| 61 | - * |
|
| 62 | - * Users is an array. Each element of the array has the following |
|
| 63 | - * properties: |
|
| 64 | - * |
|
| 65 | - * * href - Often a mailto: address |
|
| 66 | - * * commonName - Optional, for example a first and lastname for a user. |
|
| 67 | - * * status - One of the SharingPlugin::STATUS_* constants. |
|
| 68 | - * * readOnly - true or false |
|
| 69 | - * * summary - Optional, description of the share |
|
| 70 | - * |
|
| 71 | - * The organizer key is optional to specify. It's only useful when a |
|
| 72 | - * 'sharee' requests the sharing information. |
|
| 73 | - * |
|
| 74 | - * The organizer may have the following properties: |
|
| 75 | - * * href - Often a mailto: address. |
|
| 76 | - * * commonName - Optional human-readable name. |
|
| 77 | - * * firstName - Optional first name. |
|
| 78 | - * * lastName - Optional last name. |
|
| 79 | - * |
|
| 80 | - * If you wonder why these two structures are so different, I guess a |
|
| 81 | - * valid answer is that the current spec is still a draft. |
|
| 82 | - * |
|
| 83 | - * @param array $users |
|
| 84 | - */ |
|
| 85 | - public function __construct(array $users, array $organizer = null) { |
|
| 86 | - $this->users = $users; |
|
| 87 | - $this->organizer = $organizer; |
|
| 88 | - } |
|
| 59 | + /** |
|
| 60 | + * Creates the property. |
|
| 61 | + * |
|
| 62 | + * Users is an array. Each element of the array has the following |
|
| 63 | + * properties: |
|
| 64 | + * |
|
| 65 | + * * href - Often a mailto: address |
|
| 66 | + * * commonName - Optional, for example a first and lastname for a user. |
|
| 67 | + * * status - One of the SharingPlugin::STATUS_* constants. |
|
| 68 | + * * readOnly - true or false |
|
| 69 | + * * summary - Optional, description of the share |
|
| 70 | + * |
|
| 71 | + * The organizer key is optional to specify. It's only useful when a |
|
| 72 | + * 'sharee' requests the sharing information. |
|
| 73 | + * |
|
| 74 | + * The organizer may have the following properties: |
|
| 75 | + * * href - Often a mailto: address. |
|
| 76 | + * * commonName - Optional human-readable name. |
|
| 77 | + * * firstName - Optional first name. |
|
| 78 | + * * lastName - Optional last name. |
|
| 79 | + * |
|
| 80 | + * If you wonder why these two structures are so different, I guess a |
|
| 81 | + * valid answer is that the current spec is still a draft. |
|
| 82 | + * |
|
| 83 | + * @param array $users |
|
| 84 | + */ |
|
| 85 | + public function __construct(array $users, array $organizer = null) { |
|
| 86 | + $this->users = $users; |
|
| 87 | + $this->organizer = $organizer; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Returns the list of users, as it was passed to the constructor. |
|
| 92 | - * |
|
| 93 | - * @return array |
|
| 94 | - */ |
|
| 95 | - public function getValue() { |
|
| 96 | - return $this->users; |
|
| 97 | - } |
|
| 90 | + /** |
|
| 91 | + * Returns the list of users, as it was passed to the constructor. |
|
| 92 | + * |
|
| 93 | + * @return array |
|
| 94 | + */ |
|
| 95 | + public function getValue() { |
|
| 96 | + return $this->users; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * The xmlSerialize metod is called during xml writing. |
|
| 101 | - * |
|
| 102 | - * Use the $writer argument to write its own xml serialization. |
|
| 103 | - * |
|
| 104 | - * An important note: do _not_ create a parent element. Any element |
|
| 105 | - * implementing XmlSerializble should only ever write what's considered |
|
| 106 | - * its 'inner xml'. |
|
| 107 | - * |
|
| 108 | - * The parent of the current element is responsible for writing a |
|
| 109 | - * containing element. |
|
| 110 | - * |
|
| 111 | - * This allows serializers to be re-used for different element names. |
|
| 112 | - * |
|
| 113 | - * If you are opening new elements, you must also close them again. |
|
| 114 | - * |
|
| 115 | - * @param Writer $writer |
|
| 116 | - * @return void |
|
| 117 | - */ |
|
| 118 | - public function xmlSerialize(Writer $writer) { |
|
| 119 | - $cs = '{' . Plugin::NS_OWNCLOUD . '}'; |
|
| 99 | + /** |
|
| 100 | + * The xmlSerialize metod is called during xml writing. |
|
| 101 | + * |
|
| 102 | + * Use the $writer argument to write its own xml serialization. |
|
| 103 | + * |
|
| 104 | + * An important note: do _not_ create a parent element. Any element |
|
| 105 | + * implementing XmlSerializble should only ever write what's considered |
|
| 106 | + * its 'inner xml'. |
|
| 107 | + * |
|
| 108 | + * The parent of the current element is responsible for writing a |
|
| 109 | + * containing element. |
|
| 110 | + * |
|
| 111 | + * This allows serializers to be re-used for different element names. |
|
| 112 | + * |
|
| 113 | + * If you are opening new elements, you must also close them again. |
|
| 114 | + * |
|
| 115 | + * @param Writer $writer |
|
| 116 | + * @return void |
|
| 117 | + */ |
|
| 118 | + public function xmlSerialize(Writer $writer) { |
|
| 119 | + $cs = '{' . Plugin::NS_OWNCLOUD . '}'; |
|
| 120 | 120 | |
| 121 | - if (!is_null($this->organizer)) { |
|
| 122 | - $writer->startElement($cs . 'organizer'); |
|
| 123 | - $writer->writeElement('{DAV:}href', $this->organizer['href']); |
|
| 121 | + if (!is_null($this->organizer)) { |
|
| 122 | + $writer->startElement($cs . 'organizer'); |
|
| 123 | + $writer->writeElement('{DAV:}href', $this->organizer['href']); |
|
| 124 | 124 | |
| 125 | - if (isset($this->organizer['commonName']) && $this->organizer['commonName']) { |
|
| 126 | - $writer->writeElement($cs . 'common-name', $this->organizer['commonName']); |
|
| 127 | - } |
|
| 128 | - if (isset($this->organizer['firstName']) && $this->organizer['firstName']) { |
|
| 129 | - $writer->writeElement($cs . 'first-name', $this->organizer['firstName']); |
|
| 130 | - } |
|
| 131 | - if (isset($this->organizer['lastName']) && $this->organizer['lastName']) { |
|
| 132 | - $writer->writeElement($cs . 'last-name', $this->organizer['lastName']); |
|
| 133 | - } |
|
| 134 | - $writer->endElement(); // organizer |
|
| 135 | - } |
|
| 125 | + if (isset($this->organizer['commonName']) && $this->organizer['commonName']) { |
|
| 126 | + $writer->writeElement($cs . 'common-name', $this->organizer['commonName']); |
|
| 127 | + } |
|
| 128 | + if (isset($this->organizer['firstName']) && $this->organizer['firstName']) { |
|
| 129 | + $writer->writeElement($cs . 'first-name', $this->organizer['firstName']); |
|
| 130 | + } |
|
| 131 | + if (isset($this->organizer['lastName']) && $this->organizer['lastName']) { |
|
| 132 | + $writer->writeElement($cs . 'last-name', $this->organizer['lastName']); |
|
| 133 | + } |
|
| 134 | + $writer->endElement(); // organizer |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - foreach ($this->users as $user) { |
|
| 138 | - $writer->startElement($cs . 'user'); |
|
| 139 | - $writer->writeElement('{DAV:}href', $user['href']); |
|
| 140 | - if (isset($user['commonName']) && $user['commonName']) { |
|
| 141 | - $writer->writeElement($cs . 'common-name', $user['commonName']); |
|
| 142 | - } |
|
| 143 | - $writer->writeElement($cs . 'invite-accepted'); |
|
| 137 | + foreach ($this->users as $user) { |
|
| 138 | + $writer->startElement($cs . 'user'); |
|
| 139 | + $writer->writeElement('{DAV:}href', $user['href']); |
|
| 140 | + if (isset($user['commonName']) && $user['commonName']) { |
|
| 141 | + $writer->writeElement($cs . 'common-name', $user['commonName']); |
|
| 142 | + } |
|
| 143 | + $writer->writeElement($cs . 'invite-accepted'); |
|
| 144 | 144 | |
| 145 | - $writer->startElement($cs . 'access'); |
|
| 146 | - if ($user['readOnly']) { |
|
| 147 | - $writer->writeElement($cs . 'read'); |
|
| 148 | - } else { |
|
| 149 | - $writer->writeElement($cs . 'read-write'); |
|
| 150 | - } |
|
| 151 | - $writer->endElement(); // access |
|
| 145 | + $writer->startElement($cs . 'access'); |
|
| 146 | + if ($user['readOnly']) { |
|
| 147 | + $writer->writeElement($cs . 'read'); |
|
| 148 | + } else { |
|
| 149 | + $writer->writeElement($cs . 'read-write'); |
|
| 150 | + } |
|
| 151 | + $writer->endElement(); // access |
|
| 152 | 152 | |
| 153 | - if (isset($user['summary']) && $user['summary']) { |
|
| 154 | - $writer->writeElement($cs . 'summary', $user['summary']); |
|
| 155 | - } |
|
| 153 | + if (isset($user['summary']) && $user['summary']) { |
|
| 154 | + $writer->writeElement($cs . 'summary', $user['summary']); |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - $writer->endElement(); //user |
|
| 158 | - } |
|
| 159 | - } |
|
| 157 | + $writer->endElement(); //user |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | 160 | } |
@@ -116,42 +116,42 @@ |
||
| 116 | 116 | * @return void |
| 117 | 117 | */ |
| 118 | 118 | public function xmlSerialize(Writer $writer) { |
| 119 | - $cs = '{' . Plugin::NS_OWNCLOUD . '}'; |
|
| 119 | + $cs = '{'.Plugin::NS_OWNCLOUD.'}'; |
|
| 120 | 120 | |
| 121 | 121 | if (!is_null($this->organizer)) { |
| 122 | - $writer->startElement($cs . 'organizer'); |
|
| 122 | + $writer->startElement($cs.'organizer'); |
|
| 123 | 123 | $writer->writeElement('{DAV:}href', $this->organizer['href']); |
| 124 | 124 | |
| 125 | 125 | if (isset($this->organizer['commonName']) && $this->organizer['commonName']) { |
| 126 | - $writer->writeElement($cs . 'common-name', $this->organizer['commonName']); |
|
| 126 | + $writer->writeElement($cs.'common-name', $this->organizer['commonName']); |
|
| 127 | 127 | } |
| 128 | 128 | if (isset($this->organizer['firstName']) && $this->organizer['firstName']) { |
| 129 | - $writer->writeElement($cs . 'first-name', $this->organizer['firstName']); |
|
| 129 | + $writer->writeElement($cs.'first-name', $this->organizer['firstName']); |
|
| 130 | 130 | } |
| 131 | 131 | if (isset($this->organizer['lastName']) && $this->organizer['lastName']) { |
| 132 | - $writer->writeElement($cs . 'last-name', $this->organizer['lastName']); |
|
| 132 | + $writer->writeElement($cs.'last-name', $this->organizer['lastName']); |
|
| 133 | 133 | } |
| 134 | 134 | $writer->endElement(); // organizer |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | foreach ($this->users as $user) { |
| 138 | - $writer->startElement($cs . 'user'); |
|
| 138 | + $writer->startElement($cs.'user'); |
|
| 139 | 139 | $writer->writeElement('{DAV:}href', $user['href']); |
| 140 | 140 | if (isset($user['commonName']) && $user['commonName']) { |
| 141 | - $writer->writeElement($cs . 'common-name', $user['commonName']); |
|
| 141 | + $writer->writeElement($cs.'common-name', $user['commonName']); |
|
| 142 | 142 | } |
| 143 | - $writer->writeElement($cs . 'invite-accepted'); |
|
| 143 | + $writer->writeElement($cs.'invite-accepted'); |
|
| 144 | 144 | |
| 145 | - $writer->startElement($cs . 'access'); |
|
| 145 | + $writer->startElement($cs.'access'); |
|
| 146 | 146 | if ($user['readOnly']) { |
| 147 | - $writer->writeElement($cs . 'read'); |
|
| 147 | + $writer->writeElement($cs.'read'); |
|
| 148 | 148 | } else { |
| 149 | - $writer->writeElement($cs . 'read-write'); |
|
| 149 | + $writer->writeElement($cs.'read-write'); |
|
| 150 | 150 | } |
| 151 | 151 | $writer->endElement(); // access |
| 152 | 152 | |
| 153 | 153 | if (isset($user['summary']) && $user['summary']) { |
| 154 | - $writer->writeElement($cs . 'summary', $user['summary']); |
|
| 154 | + $writer->writeElement($cs.'summary', $user['summary']); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | $writer->endElement(); //user |