@@ -34,258 +34,258 @@ |
||
| 34 | 34 | |
| 35 | 35 | class CustomPropertiesBackend implements BackendInterface { |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Ignored properties |
|
| 39 | - * |
|
| 40 | - * @var array |
|
| 41 | - */ |
|
| 42 | - private $ignoredProperties = array( |
|
| 43 | - '{DAV:}getcontentlength', |
|
| 44 | - '{DAV:}getcontenttype', |
|
| 45 | - '{DAV:}getetag', |
|
| 46 | - '{DAV:}quota-used-bytes', |
|
| 47 | - '{DAV:}quota-available-bytes', |
|
| 48 | - '{http://owncloud.org/ns}permissions', |
|
| 49 | - '{http://owncloud.org/ns}downloadURL', |
|
| 50 | - '{http://owncloud.org/ns}dDC', |
|
| 51 | - '{http://owncloud.org/ns}size', |
|
| 52 | - ); |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @var Tree |
|
| 56 | - */ |
|
| 57 | - private $tree; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @var IDBConnection |
|
| 61 | - */ |
|
| 62 | - private $connection; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @var string |
|
| 66 | - */ |
|
| 67 | - private $user; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Properties cache |
|
| 71 | - * |
|
| 72 | - * @var array |
|
| 73 | - */ |
|
| 74 | - private $cache = []; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @param Tree $tree node tree |
|
| 78 | - * @param IDBConnection $connection database connection |
|
| 79 | - * @param IUser $user owner of the tree and properties |
|
| 80 | - */ |
|
| 81 | - public function __construct( |
|
| 82 | - Tree $tree, |
|
| 83 | - IDBConnection $connection, |
|
| 84 | - IUser $user) { |
|
| 85 | - $this->tree = $tree; |
|
| 86 | - $this->connection = $connection; |
|
| 87 | - $this->user = $user->getUID(); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Fetches properties for a path. |
|
| 92 | - * |
|
| 93 | - * @param string $path |
|
| 94 | - * @param PropFind $propFind |
|
| 95 | - * @return void |
|
| 96 | - */ |
|
| 97 | - public function propFind($path, PropFind $propFind) { |
|
| 98 | - |
|
| 99 | - $requestedProps = $propFind->get404Properties(); |
|
| 100 | - |
|
| 101 | - // these might appear |
|
| 102 | - $requestedProps = array_diff( |
|
| 103 | - $requestedProps, |
|
| 104 | - $this->ignoredProperties |
|
| 105 | - ); |
|
| 106 | - |
|
| 107 | - // substr of calendars/ => path is inside the CalDAV component |
|
| 108 | - // two '/' => this a calendar (no calendar-home nor calendar object) |
|
| 109 | - if (substr($path, 0, 10) === 'calendars/' && substr_count($path, '/') === 2) { |
|
| 110 | - $allRequestedProps = $propFind->getRequestedProperties(); |
|
| 111 | - $customPropertiesForShares = [ |
|
| 112 | - '{DAV:}displayname', |
|
| 113 | - '{urn:ietf:params:xml:ns:caldav}calendar-description', |
|
| 114 | - '{urn:ietf:params:xml:ns:caldav}calendar-timezone', |
|
| 115 | - '{http://apple.com/ns/ical/}calendar-order', |
|
| 116 | - '{http://apple.com/ns/ical/}calendar-color', |
|
| 117 | - '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp', |
|
| 118 | - ]; |
|
| 119 | - |
|
| 120 | - foreach ($customPropertiesForShares as $customPropertyForShares) { |
|
| 121 | - if (in_array($customPropertyForShares, $allRequestedProps)) { |
|
| 122 | - $requestedProps[] = $customPropertyForShares; |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - if (empty($requestedProps)) { |
|
| 128 | - return; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - $props = $this->getProperties($path, $requestedProps); |
|
| 132 | - foreach ($props as $propName => $propValue) { |
|
| 133 | - $propFind->set($propName, $propValue); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Updates properties for a path |
|
| 139 | - * |
|
| 140 | - * @param string $path |
|
| 141 | - * @param PropPatch $propPatch |
|
| 142 | - * |
|
| 143 | - * @return void |
|
| 144 | - */ |
|
| 145 | - public function propPatch($path, PropPatch $propPatch) { |
|
| 146 | - $propPatch->handleRemaining(function($changedProps) use ($path) { |
|
| 147 | - return $this->updateProperties($path, $changedProps); |
|
| 148 | - }); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * This method is called after a node is deleted. |
|
| 153 | - * |
|
| 154 | - * @param string $path path of node for which to delete properties |
|
| 155 | - */ |
|
| 156 | - public function delete($path) { |
|
| 157 | - $statement = $this->connection->prepare( |
|
| 158 | - 'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?' |
|
| 159 | - ); |
|
| 160 | - $statement->execute(array($this->user, $path)); |
|
| 161 | - $statement->closeCursor(); |
|
| 162 | - |
|
| 163 | - unset($this->cache[$path]); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * This method is called after a successful MOVE |
|
| 168 | - * |
|
| 169 | - * @param string $source |
|
| 170 | - * @param string $destination |
|
| 171 | - * |
|
| 172 | - * @return void |
|
| 173 | - */ |
|
| 174 | - public function move($source, $destination) { |
|
| 175 | - $statement = $this->connection->prepare( |
|
| 176 | - 'UPDATE `*PREFIX*properties` SET `propertypath` = ?' . |
|
| 177 | - ' WHERE `userid` = ? AND `propertypath` = ?' |
|
| 178 | - ); |
|
| 179 | - $statement->execute(array($destination, $this->user, $source)); |
|
| 180 | - $statement->closeCursor(); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * Returns a list of properties for this nodes.; |
|
| 185 | - * @param string $path |
|
| 186 | - * @param array $requestedProperties requested properties or empty array for "all" |
|
| 187 | - * @return array |
|
| 188 | - * @note The properties list is a list of propertynames the client |
|
| 189 | - * requested, encoded as xmlnamespace#tagName, for example: |
|
| 190 | - * http://www.example.org/namespace#author If the array is empty, all |
|
| 191 | - * properties should be returned |
|
| 192 | - */ |
|
| 193 | - private function getProperties($path, array $requestedProperties) { |
|
| 194 | - if (isset($this->cache[$path])) { |
|
| 195 | - return $this->cache[$path]; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - // TODO: chunking if more than 1000 properties |
|
| 199 | - $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'; |
|
| 200 | - |
|
| 201 | - $whereValues = array($this->user, $path); |
|
| 202 | - $whereTypes = array(null, null); |
|
| 203 | - |
|
| 204 | - if (!empty($requestedProperties)) { |
|
| 205 | - // request only a subset |
|
| 206 | - $sql .= ' AND `propertyname` in (?)'; |
|
| 207 | - $whereValues[] = $requestedProperties; |
|
| 208 | - $whereTypes[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - $result = $this->connection->executeQuery( |
|
| 212 | - $sql, |
|
| 213 | - $whereValues, |
|
| 214 | - $whereTypes |
|
| 215 | - ); |
|
| 216 | - |
|
| 217 | - $props = []; |
|
| 218 | - while ($row = $result->fetch()) { |
|
| 219 | - $props[$row['propertyname']] = $row['propertyvalue']; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - $result->closeCursor(); |
|
| 223 | - |
|
| 224 | - $this->cache[$path] = $props; |
|
| 225 | - return $props; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Update properties |
|
| 230 | - * |
|
| 231 | - * @param string $path node for which to update properties |
|
| 232 | - * @param array $properties array of properties to update |
|
| 233 | - * |
|
| 234 | - * @return bool |
|
| 235 | - */ |
|
| 236 | - private function updateProperties($path, $properties) { |
|
| 237 | - |
|
| 238 | - $deleteStatement = 'DELETE FROM `*PREFIX*properties`' . |
|
| 239 | - ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
| 240 | - |
|
| 241 | - $insertStatement = 'INSERT INTO `*PREFIX*properties`' . |
|
| 242 | - ' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)'; |
|
| 243 | - |
|
| 244 | - $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' . |
|
| 245 | - ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
| 246 | - |
|
| 247 | - // TODO: use "insert or update" strategy ? |
|
| 248 | - $existing = $this->getProperties($path, array()); |
|
| 249 | - $this->connection->beginTransaction(); |
|
| 250 | - foreach ($properties as $propertyName => $propertyValue) { |
|
| 251 | - // If it was null, we need to delete the property |
|
| 252 | - if (is_null($propertyValue)) { |
|
| 253 | - if (array_key_exists($propertyName, $existing)) { |
|
| 254 | - $this->connection->executeUpdate($deleteStatement, |
|
| 255 | - array( |
|
| 256 | - $this->user, |
|
| 257 | - $path, |
|
| 258 | - $propertyName |
|
| 259 | - ) |
|
| 260 | - ); |
|
| 261 | - } |
|
| 262 | - } else { |
|
| 263 | - if (!array_key_exists($propertyName, $existing)) { |
|
| 264 | - $this->connection->executeUpdate($insertStatement, |
|
| 265 | - array( |
|
| 266 | - $this->user, |
|
| 267 | - $path, |
|
| 268 | - $propertyName, |
|
| 269 | - $propertyValue |
|
| 270 | - ) |
|
| 271 | - ); |
|
| 272 | - } else { |
|
| 273 | - $this->connection->executeUpdate($updateStatement, |
|
| 274 | - array( |
|
| 275 | - $propertyValue, |
|
| 276 | - $this->user, |
|
| 277 | - $path, |
|
| 278 | - $propertyName |
|
| 279 | - ) |
|
| 280 | - ); |
|
| 281 | - } |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - $this->connection->commit(); |
|
| 286 | - unset($this->cache[$path]); |
|
| 287 | - |
|
| 288 | - return true; |
|
| 289 | - } |
|
| 37 | + /** |
|
| 38 | + * Ignored properties |
|
| 39 | + * |
|
| 40 | + * @var array |
|
| 41 | + */ |
|
| 42 | + private $ignoredProperties = array( |
|
| 43 | + '{DAV:}getcontentlength', |
|
| 44 | + '{DAV:}getcontenttype', |
|
| 45 | + '{DAV:}getetag', |
|
| 46 | + '{DAV:}quota-used-bytes', |
|
| 47 | + '{DAV:}quota-available-bytes', |
|
| 48 | + '{http://owncloud.org/ns}permissions', |
|
| 49 | + '{http://owncloud.org/ns}downloadURL', |
|
| 50 | + '{http://owncloud.org/ns}dDC', |
|
| 51 | + '{http://owncloud.org/ns}size', |
|
| 52 | + ); |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @var Tree |
|
| 56 | + */ |
|
| 57 | + private $tree; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @var IDBConnection |
|
| 61 | + */ |
|
| 62 | + private $connection; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @var string |
|
| 66 | + */ |
|
| 67 | + private $user; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Properties cache |
|
| 71 | + * |
|
| 72 | + * @var array |
|
| 73 | + */ |
|
| 74 | + private $cache = []; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @param Tree $tree node tree |
|
| 78 | + * @param IDBConnection $connection database connection |
|
| 79 | + * @param IUser $user owner of the tree and properties |
|
| 80 | + */ |
|
| 81 | + public function __construct( |
|
| 82 | + Tree $tree, |
|
| 83 | + IDBConnection $connection, |
|
| 84 | + IUser $user) { |
|
| 85 | + $this->tree = $tree; |
|
| 86 | + $this->connection = $connection; |
|
| 87 | + $this->user = $user->getUID(); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Fetches properties for a path. |
|
| 92 | + * |
|
| 93 | + * @param string $path |
|
| 94 | + * @param PropFind $propFind |
|
| 95 | + * @return void |
|
| 96 | + */ |
|
| 97 | + public function propFind($path, PropFind $propFind) { |
|
| 98 | + |
|
| 99 | + $requestedProps = $propFind->get404Properties(); |
|
| 100 | + |
|
| 101 | + // these might appear |
|
| 102 | + $requestedProps = array_diff( |
|
| 103 | + $requestedProps, |
|
| 104 | + $this->ignoredProperties |
|
| 105 | + ); |
|
| 106 | + |
|
| 107 | + // substr of calendars/ => path is inside the CalDAV component |
|
| 108 | + // two '/' => this a calendar (no calendar-home nor calendar object) |
|
| 109 | + if (substr($path, 0, 10) === 'calendars/' && substr_count($path, '/') === 2) { |
|
| 110 | + $allRequestedProps = $propFind->getRequestedProperties(); |
|
| 111 | + $customPropertiesForShares = [ |
|
| 112 | + '{DAV:}displayname', |
|
| 113 | + '{urn:ietf:params:xml:ns:caldav}calendar-description', |
|
| 114 | + '{urn:ietf:params:xml:ns:caldav}calendar-timezone', |
|
| 115 | + '{http://apple.com/ns/ical/}calendar-order', |
|
| 116 | + '{http://apple.com/ns/ical/}calendar-color', |
|
| 117 | + '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp', |
|
| 118 | + ]; |
|
| 119 | + |
|
| 120 | + foreach ($customPropertiesForShares as $customPropertyForShares) { |
|
| 121 | + if (in_array($customPropertyForShares, $allRequestedProps)) { |
|
| 122 | + $requestedProps[] = $customPropertyForShares; |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + if (empty($requestedProps)) { |
|
| 128 | + return; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + $props = $this->getProperties($path, $requestedProps); |
|
| 132 | + foreach ($props as $propName => $propValue) { |
|
| 133 | + $propFind->set($propName, $propValue); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Updates properties for a path |
|
| 139 | + * |
|
| 140 | + * @param string $path |
|
| 141 | + * @param PropPatch $propPatch |
|
| 142 | + * |
|
| 143 | + * @return void |
|
| 144 | + */ |
|
| 145 | + public function propPatch($path, PropPatch $propPatch) { |
|
| 146 | + $propPatch->handleRemaining(function($changedProps) use ($path) { |
|
| 147 | + return $this->updateProperties($path, $changedProps); |
|
| 148 | + }); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * This method is called after a node is deleted. |
|
| 153 | + * |
|
| 154 | + * @param string $path path of node for which to delete properties |
|
| 155 | + */ |
|
| 156 | + public function delete($path) { |
|
| 157 | + $statement = $this->connection->prepare( |
|
| 158 | + 'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?' |
|
| 159 | + ); |
|
| 160 | + $statement->execute(array($this->user, $path)); |
|
| 161 | + $statement->closeCursor(); |
|
| 162 | + |
|
| 163 | + unset($this->cache[$path]); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * This method is called after a successful MOVE |
|
| 168 | + * |
|
| 169 | + * @param string $source |
|
| 170 | + * @param string $destination |
|
| 171 | + * |
|
| 172 | + * @return void |
|
| 173 | + */ |
|
| 174 | + public function move($source, $destination) { |
|
| 175 | + $statement = $this->connection->prepare( |
|
| 176 | + 'UPDATE `*PREFIX*properties` SET `propertypath` = ?' . |
|
| 177 | + ' WHERE `userid` = ? AND `propertypath` = ?' |
|
| 178 | + ); |
|
| 179 | + $statement->execute(array($destination, $this->user, $source)); |
|
| 180 | + $statement->closeCursor(); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * Returns a list of properties for this nodes.; |
|
| 185 | + * @param string $path |
|
| 186 | + * @param array $requestedProperties requested properties or empty array for "all" |
|
| 187 | + * @return array |
|
| 188 | + * @note The properties list is a list of propertynames the client |
|
| 189 | + * requested, encoded as xmlnamespace#tagName, for example: |
|
| 190 | + * http://www.example.org/namespace#author If the array is empty, all |
|
| 191 | + * properties should be returned |
|
| 192 | + */ |
|
| 193 | + private function getProperties($path, array $requestedProperties) { |
|
| 194 | + if (isset($this->cache[$path])) { |
|
| 195 | + return $this->cache[$path]; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + // TODO: chunking if more than 1000 properties |
|
| 199 | + $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'; |
|
| 200 | + |
|
| 201 | + $whereValues = array($this->user, $path); |
|
| 202 | + $whereTypes = array(null, null); |
|
| 203 | + |
|
| 204 | + if (!empty($requestedProperties)) { |
|
| 205 | + // request only a subset |
|
| 206 | + $sql .= ' AND `propertyname` in (?)'; |
|
| 207 | + $whereValues[] = $requestedProperties; |
|
| 208 | + $whereTypes[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + $result = $this->connection->executeQuery( |
|
| 212 | + $sql, |
|
| 213 | + $whereValues, |
|
| 214 | + $whereTypes |
|
| 215 | + ); |
|
| 216 | + |
|
| 217 | + $props = []; |
|
| 218 | + while ($row = $result->fetch()) { |
|
| 219 | + $props[$row['propertyname']] = $row['propertyvalue']; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + $result->closeCursor(); |
|
| 223 | + |
|
| 224 | + $this->cache[$path] = $props; |
|
| 225 | + return $props; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Update properties |
|
| 230 | + * |
|
| 231 | + * @param string $path node for which to update properties |
|
| 232 | + * @param array $properties array of properties to update |
|
| 233 | + * |
|
| 234 | + * @return bool |
|
| 235 | + */ |
|
| 236 | + private function updateProperties($path, $properties) { |
|
| 237 | + |
|
| 238 | + $deleteStatement = 'DELETE FROM `*PREFIX*properties`' . |
|
| 239 | + ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
| 240 | + |
|
| 241 | + $insertStatement = 'INSERT INTO `*PREFIX*properties`' . |
|
| 242 | + ' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)'; |
|
| 243 | + |
|
| 244 | + $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' . |
|
| 245 | + ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
| 246 | + |
|
| 247 | + // TODO: use "insert or update" strategy ? |
|
| 248 | + $existing = $this->getProperties($path, array()); |
|
| 249 | + $this->connection->beginTransaction(); |
|
| 250 | + foreach ($properties as $propertyName => $propertyValue) { |
|
| 251 | + // If it was null, we need to delete the property |
|
| 252 | + if (is_null($propertyValue)) { |
|
| 253 | + if (array_key_exists($propertyName, $existing)) { |
|
| 254 | + $this->connection->executeUpdate($deleteStatement, |
|
| 255 | + array( |
|
| 256 | + $this->user, |
|
| 257 | + $path, |
|
| 258 | + $propertyName |
|
| 259 | + ) |
|
| 260 | + ); |
|
| 261 | + } |
|
| 262 | + } else { |
|
| 263 | + if (!array_key_exists($propertyName, $existing)) { |
|
| 264 | + $this->connection->executeUpdate($insertStatement, |
|
| 265 | + array( |
|
| 266 | + $this->user, |
|
| 267 | + $path, |
|
| 268 | + $propertyName, |
|
| 269 | + $propertyValue |
|
| 270 | + ) |
|
| 271 | + ); |
|
| 272 | + } else { |
|
| 273 | + $this->connection->executeUpdate($updateStatement, |
|
| 274 | + array( |
|
| 275 | + $propertyValue, |
|
| 276 | + $this->user, |
|
| 277 | + $path, |
|
| 278 | + $propertyName |
|
| 279 | + ) |
|
| 280 | + ); |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + $this->connection->commit(); |
|
| 286 | + unset($this->cache[$path]); |
|
| 287 | + |
|
| 288 | + return true; |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | 291 | } |
@@ -27,230 +27,230 @@ |
||
| 27 | 27 | |
| 28 | 28 | class EventMerger implements IEventMerger { |
| 29 | 29 | |
| 30 | - /** @var IL10N */ |
|
| 31 | - protected $l10n; |
|
| 30 | + /** @var IL10N */ |
|
| 31 | + protected $l10n; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @param IL10N $l10n |
|
| 35 | - */ |
|
| 36 | - public function __construct(IL10N $l10n) { |
|
| 37 | - $this->l10n = $l10n; |
|
| 38 | - } |
|
| 33 | + /** |
|
| 34 | + * @param IL10N $l10n |
|
| 35 | + */ |
|
| 36 | + public function __construct(IL10N $l10n) { |
|
| 37 | + $this->l10n = $l10n; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Combines two events when possible to have grouping: |
|
| 42 | - * |
|
| 43 | - * Example1: Two events with subject '{user} created {file}' and |
|
| 44 | - * $mergeParameter file with different file and same user will be merged |
|
| 45 | - * to '{user} created {file1} and {file2}' and the childEvent on the return |
|
| 46 | - * will be set, if the events have been merged. |
|
| 47 | - * |
|
| 48 | - * Example2: Two events with subject '{user} created {file}' and |
|
| 49 | - * $mergeParameter file with same file and same user will be merged to |
|
| 50 | - * '{user} created {file1}' and the childEvent on the return will be set, if |
|
| 51 | - * the events have been merged. |
|
| 52 | - * |
|
| 53 | - * The following requirements have to be met, in order to be merged: |
|
| 54 | - * - Both events need to have the same `getApp()` |
|
| 55 | - * - Both events must not have a message `getMessage()` |
|
| 56 | - * - Both events need to have the same subject `getSubject()` |
|
| 57 | - * - Both events need to have the same object type `getObjectType()` |
|
| 58 | - * - The time difference between both events must not be bigger then 3 hours |
|
| 59 | - * - Only up to 5 events can be merged. |
|
| 60 | - * - All parameters apart from such starting with $mergeParameter must be |
|
| 61 | - * the same for both events. |
|
| 62 | - * |
|
| 63 | - * @param string $mergeParameter |
|
| 64 | - * @param IEvent $event |
|
| 65 | - * @param IEvent|null $previousEvent |
|
| 66 | - * @return IEvent |
|
| 67 | - */ |
|
| 68 | - public function mergeEvents($mergeParameter, IEvent $event, IEvent $previousEvent = null) { |
|
| 69 | - // No second event => can not combine |
|
| 70 | - if (!$previousEvent instanceof IEvent) { |
|
| 71 | - return $event; |
|
| 72 | - } |
|
| 40 | + /** |
|
| 41 | + * Combines two events when possible to have grouping: |
|
| 42 | + * |
|
| 43 | + * Example1: Two events with subject '{user} created {file}' and |
|
| 44 | + * $mergeParameter file with different file and same user will be merged |
|
| 45 | + * to '{user} created {file1} and {file2}' and the childEvent on the return |
|
| 46 | + * will be set, if the events have been merged. |
|
| 47 | + * |
|
| 48 | + * Example2: Two events with subject '{user} created {file}' and |
|
| 49 | + * $mergeParameter file with same file and same user will be merged to |
|
| 50 | + * '{user} created {file1}' and the childEvent on the return will be set, if |
|
| 51 | + * the events have been merged. |
|
| 52 | + * |
|
| 53 | + * The following requirements have to be met, in order to be merged: |
|
| 54 | + * - Both events need to have the same `getApp()` |
|
| 55 | + * - Both events must not have a message `getMessage()` |
|
| 56 | + * - Both events need to have the same subject `getSubject()` |
|
| 57 | + * - Both events need to have the same object type `getObjectType()` |
|
| 58 | + * - The time difference between both events must not be bigger then 3 hours |
|
| 59 | + * - Only up to 5 events can be merged. |
|
| 60 | + * - All parameters apart from such starting with $mergeParameter must be |
|
| 61 | + * the same for both events. |
|
| 62 | + * |
|
| 63 | + * @param string $mergeParameter |
|
| 64 | + * @param IEvent $event |
|
| 65 | + * @param IEvent|null $previousEvent |
|
| 66 | + * @return IEvent |
|
| 67 | + */ |
|
| 68 | + public function mergeEvents($mergeParameter, IEvent $event, IEvent $previousEvent = null) { |
|
| 69 | + // No second event => can not combine |
|
| 70 | + if (!$previousEvent instanceof IEvent) { |
|
| 71 | + return $event; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - // Different app => can not combine |
|
| 75 | - if ($event->getApp() !== $previousEvent->getApp()) { |
|
| 76 | - return $event; |
|
| 77 | - } |
|
| 74 | + // Different app => can not combine |
|
| 75 | + if ($event->getApp() !== $previousEvent->getApp()) { |
|
| 76 | + return $event; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - // Message is set => can not combine |
|
| 80 | - if ($event->getMessage() !== '' || $previousEvent->getMessage() !== '') { |
|
| 81 | - return $event; |
|
| 82 | - } |
|
| 79 | + // Message is set => can not combine |
|
| 80 | + if ($event->getMessage() !== '' || $previousEvent->getMessage() !== '') { |
|
| 81 | + return $event; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - // Different subject => can not combine |
|
| 85 | - if ($event->getSubject() !== $previousEvent->getSubject()) { |
|
| 86 | - return $event; |
|
| 87 | - } |
|
| 84 | + // Different subject => can not combine |
|
| 85 | + if ($event->getSubject() !== $previousEvent->getSubject()) { |
|
| 86 | + return $event; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - // Different object type => can not combine |
|
| 90 | - if ($event->getObjectType() !== $previousEvent->getObjectType()) { |
|
| 91 | - return $event; |
|
| 92 | - } |
|
| 89 | + // Different object type => can not combine |
|
| 90 | + if ($event->getObjectType() !== $previousEvent->getObjectType()) { |
|
| 91 | + return $event; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - // More than 3 hours difference => can not combine |
|
| 95 | - if (abs($event->getTimestamp() - $previousEvent->getTimestamp()) > 3 * 60 * 60) { |
|
| 96 | - return $event; |
|
| 97 | - } |
|
| 94 | + // More than 3 hours difference => can not combine |
|
| 95 | + if (abs($event->getTimestamp() - $previousEvent->getTimestamp()) > 3 * 60 * 60) { |
|
| 96 | + return $event; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - // Other parameters are not the same => can not combine |
|
| 100 | - try { |
|
| 101 | - list($combined, $parameters) = $this->combineParameters($mergeParameter, $event, $previousEvent); |
|
| 102 | - } catch (\UnexpectedValueException $e) { |
|
| 103 | - return $event; |
|
| 104 | - } |
|
| 99 | + // Other parameters are not the same => can not combine |
|
| 100 | + try { |
|
| 101 | + list($combined, $parameters) = $this->combineParameters($mergeParameter, $event, $previousEvent); |
|
| 102 | + } catch (\UnexpectedValueException $e) { |
|
| 103 | + return $event; |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - try { |
|
| 107 | - $newSubject = $this->getExtendedSubject($event->getRichSubject(), $mergeParameter, $combined); |
|
| 108 | - $parsedSubject = $this->generateParsedSubject($newSubject, $parameters); |
|
| 106 | + try { |
|
| 107 | + $newSubject = $this->getExtendedSubject($event->getRichSubject(), $mergeParameter, $combined); |
|
| 108 | + $parsedSubject = $this->generateParsedSubject($newSubject, $parameters); |
|
| 109 | 109 | |
| 110 | - $event->setRichSubject($newSubject, $parameters) |
|
| 111 | - ->setParsedSubject($parsedSubject) |
|
| 112 | - ->setChildEvent($previousEvent); |
|
| 113 | - } catch (\UnexpectedValueException $e) { |
|
| 114 | - return $event; |
|
| 115 | - } |
|
| 110 | + $event->setRichSubject($newSubject, $parameters) |
|
| 111 | + ->setParsedSubject($parsedSubject) |
|
| 112 | + ->setChildEvent($previousEvent); |
|
| 113 | + } catch (\UnexpectedValueException $e) { |
|
| 114 | + return $event; |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - return $event; |
|
| 118 | - } |
|
| 117 | + return $event; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * @param string $mergeParameter |
|
| 122 | - * @param IEvent $event |
|
| 123 | - * @param IEvent $previousEvent |
|
| 124 | - * @return array |
|
| 125 | - * @throws \UnexpectedValueException |
|
| 126 | - */ |
|
| 127 | - protected function combineParameters($mergeParameter, IEvent $event, IEvent $previousEvent) { |
|
| 128 | - $params1 = $event->getRichSubjectParameters(); |
|
| 129 | - $params2 = $previousEvent->getRichSubjectParameters(); |
|
| 130 | - $params = []; |
|
| 120 | + /** |
|
| 121 | + * @param string $mergeParameter |
|
| 122 | + * @param IEvent $event |
|
| 123 | + * @param IEvent $previousEvent |
|
| 124 | + * @return array |
|
| 125 | + * @throws \UnexpectedValueException |
|
| 126 | + */ |
|
| 127 | + protected function combineParameters($mergeParameter, IEvent $event, IEvent $previousEvent) { |
|
| 128 | + $params1 = $event->getRichSubjectParameters(); |
|
| 129 | + $params2 = $previousEvent->getRichSubjectParameters(); |
|
| 130 | + $params = []; |
|
| 131 | 131 | |
| 132 | - $combined = 0; |
|
| 132 | + $combined = 0; |
|
| 133 | 133 | |
| 134 | - // Check that all parameters from $event exist in $previousEvent |
|
| 135 | - foreach ($params1 as $key => $parameter) { |
|
| 136 | - if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
| 137 | - if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { |
|
| 138 | - $combined++; |
|
| 139 | - $params[$mergeParameter . $combined] = $parameter; |
|
| 140 | - } |
|
| 141 | - continue; |
|
| 142 | - } |
|
| 134 | + // Check that all parameters from $event exist in $previousEvent |
|
| 135 | + foreach ($params1 as $key => $parameter) { |
|
| 136 | + if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
| 137 | + if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { |
|
| 138 | + $combined++; |
|
| 139 | + $params[$mergeParameter . $combined] = $parameter; |
|
| 140 | + } |
|
| 141 | + continue; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - if (!isset($params2[$key]) || $params2[$key] !== $parameter) { |
|
| 145 | - // Parameter missing on $previousEvent or different => can not combine |
|
| 146 | - throw new \UnexpectedValueException(); |
|
| 147 | - } |
|
| 144 | + if (!isset($params2[$key]) || $params2[$key] !== $parameter) { |
|
| 145 | + // Parameter missing on $previousEvent or different => can not combine |
|
| 146 | + throw new \UnexpectedValueException(); |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - $params[$key] = $parameter; |
|
| 150 | - } |
|
| 149 | + $params[$key] = $parameter; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - // Check that all parameters from $previousEvent exist in $event |
|
| 153 | - foreach ($params2 as $key => $parameter) { |
|
| 154 | - if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
| 155 | - if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { |
|
| 156 | - $combined++; |
|
| 157 | - $params[$mergeParameter . $combined] = $parameter; |
|
| 158 | - } |
|
| 159 | - continue; |
|
| 160 | - } |
|
| 152 | + // Check that all parameters from $previousEvent exist in $event |
|
| 153 | + foreach ($params2 as $key => $parameter) { |
|
| 154 | + if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
| 155 | + if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { |
|
| 156 | + $combined++; |
|
| 157 | + $params[$mergeParameter . $combined] = $parameter; |
|
| 158 | + } |
|
| 159 | + continue; |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - if (!isset($params1[$key]) || $params1[$key] !== $parameter) { |
|
| 163 | - // Parameter missing on $event or different => can not combine |
|
| 164 | - throw new \UnexpectedValueException(); |
|
| 165 | - } |
|
| 162 | + if (!isset($params1[$key]) || $params1[$key] !== $parameter) { |
|
| 163 | + // Parameter missing on $event or different => can not combine |
|
| 164 | + throw new \UnexpectedValueException(); |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - $params[$key] = $parameter; |
|
| 168 | - } |
|
| 167 | + $params[$key] = $parameter; |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - return [$combined, $params]; |
|
| 171 | - } |
|
| 170 | + return [$combined, $params]; |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - /** |
|
| 174 | - * @param array[] $parameters |
|
| 175 | - * @param string $mergeParameter |
|
| 176 | - * @param array $parameter |
|
| 177 | - * @return bool |
|
| 178 | - */ |
|
| 179 | - protected function checkParameterAlreadyExits($parameters, $mergeParameter, $parameter) { |
|
| 180 | - foreach ($parameters as $key => $param) { |
|
| 181 | - if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
| 182 | - if ($param === $parameter) { |
|
| 183 | - return true; |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - } |
|
| 187 | - return false; |
|
| 188 | - } |
|
| 173 | + /** |
|
| 174 | + * @param array[] $parameters |
|
| 175 | + * @param string $mergeParameter |
|
| 176 | + * @param array $parameter |
|
| 177 | + * @return bool |
|
| 178 | + */ |
|
| 179 | + protected function checkParameterAlreadyExits($parameters, $mergeParameter, $parameter) { |
|
| 180 | + foreach ($parameters as $key => $param) { |
|
| 181 | + if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
| 182 | + if ($param === $parameter) { |
|
| 183 | + return true; |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | + return false; |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | - /** |
|
| 191 | - * @param string $subject |
|
| 192 | - * @param string $parameter |
|
| 193 | - * @param int $counter |
|
| 194 | - * @return mixed |
|
| 195 | - */ |
|
| 196 | - protected function getExtendedSubject($subject, $parameter, $counter) { |
|
| 197 | - switch ($counter) { |
|
| 198 | - case 1: |
|
| 199 | - $replacement = '{' . $parameter . '1}'; |
|
| 200 | - break; |
|
| 201 | - case 2: |
|
| 202 | - $replacement = $this->l10n->t( |
|
| 203 | - '%1$s and %2$s', |
|
| 204 | - ['{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
| 205 | - ); |
|
| 206 | - break; |
|
| 207 | - case 3: |
|
| 208 | - $replacement = $this->l10n->t( |
|
| 209 | - '%1$s, %2$s and %3$s', |
|
| 210 | - ['{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
| 211 | - ); |
|
| 212 | - break; |
|
| 213 | - case 4: |
|
| 214 | - $replacement = $this->l10n->t( |
|
| 215 | - '%1$s, %2$s, %3$s and %4$s', |
|
| 216 | - ['{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
| 217 | - ); |
|
| 218 | - break; |
|
| 219 | - case 5: |
|
| 220 | - $replacement = $this->l10n->t( |
|
| 221 | - '%1$s, %2$s, %3$s, %4$s and %5$s', |
|
| 222 | - ['{' . $parameter . '5}', '{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
| 223 | - ); |
|
| 224 | - break; |
|
| 225 | - default: |
|
| 226 | - throw new \UnexpectedValueException(); |
|
| 227 | - } |
|
| 190 | + /** |
|
| 191 | + * @param string $subject |
|
| 192 | + * @param string $parameter |
|
| 193 | + * @param int $counter |
|
| 194 | + * @return mixed |
|
| 195 | + */ |
|
| 196 | + protected function getExtendedSubject($subject, $parameter, $counter) { |
|
| 197 | + switch ($counter) { |
|
| 198 | + case 1: |
|
| 199 | + $replacement = '{' . $parameter . '1}'; |
|
| 200 | + break; |
|
| 201 | + case 2: |
|
| 202 | + $replacement = $this->l10n->t( |
|
| 203 | + '%1$s and %2$s', |
|
| 204 | + ['{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
| 205 | + ); |
|
| 206 | + break; |
|
| 207 | + case 3: |
|
| 208 | + $replacement = $this->l10n->t( |
|
| 209 | + '%1$s, %2$s and %3$s', |
|
| 210 | + ['{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
| 211 | + ); |
|
| 212 | + break; |
|
| 213 | + case 4: |
|
| 214 | + $replacement = $this->l10n->t( |
|
| 215 | + '%1$s, %2$s, %3$s and %4$s', |
|
| 216 | + ['{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
| 217 | + ); |
|
| 218 | + break; |
|
| 219 | + case 5: |
|
| 220 | + $replacement = $this->l10n->t( |
|
| 221 | + '%1$s, %2$s, %3$s, %4$s and %5$s', |
|
| 222 | + ['{' . $parameter . '5}', '{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
| 223 | + ); |
|
| 224 | + break; |
|
| 225 | + default: |
|
| 226 | + throw new \UnexpectedValueException(); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - return str_replace( |
|
| 230 | - '{' . $parameter . '}', |
|
| 231 | - $replacement, |
|
| 232 | - $subject |
|
| 233 | - ); |
|
| 234 | - } |
|
| 229 | + return str_replace( |
|
| 230 | + '{' . $parameter . '}', |
|
| 231 | + $replacement, |
|
| 232 | + $subject |
|
| 233 | + ); |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | - /** |
|
| 237 | - * @param string $subject |
|
| 238 | - * @param array[] $parameters |
|
| 239 | - * @return string |
|
| 240 | - */ |
|
| 241 | - protected function generateParsedSubject($subject, $parameters) { |
|
| 242 | - $placeholders = $replacements = []; |
|
| 243 | - foreach ($parameters as $placeholder => $parameter) { |
|
| 244 | - $placeholders[] = '{' . $placeholder . '}'; |
|
| 245 | - if ($parameter['type'] === 'file') { |
|
| 246 | - $replacements[] = trim($parameter['path'], '/'); |
|
| 247 | - } else if (isset($parameter['name'])) { |
|
| 248 | - $replacements[] = $parameter['name']; |
|
| 249 | - } else { |
|
| 250 | - $replacements[] = $parameter['id']; |
|
| 251 | - } |
|
| 252 | - } |
|
| 236 | + /** |
|
| 237 | + * @param string $subject |
|
| 238 | + * @param array[] $parameters |
|
| 239 | + * @return string |
|
| 240 | + */ |
|
| 241 | + protected function generateParsedSubject($subject, $parameters) { |
|
| 242 | + $placeholders = $replacements = []; |
|
| 243 | + foreach ($parameters as $placeholder => $parameter) { |
|
| 244 | + $placeholders[] = '{' . $placeholder . '}'; |
|
| 245 | + if ($parameter['type'] === 'file') { |
|
| 246 | + $replacements[] = trim($parameter['path'], '/'); |
|
| 247 | + } else if (isset($parameter['name'])) { |
|
| 248 | + $replacements[] = $parameter['name']; |
|
| 249 | + } else { |
|
| 250 | + $replacements[] = $parameter['id']; |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | 253 | |
| 254 | - return str_replace($placeholders, $replacements, $subject); |
|
| 255 | - } |
|
| 254 | + return str_replace($placeholders, $replacements, $subject); |
|
| 255 | + } |
|
| 256 | 256 | } |
@@ -27,72 +27,72 @@ |
||
| 27 | 27 | use Sabre\DAV\File; |
| 28 | 28 | |
| 29 | 29 | class AvatarNode extends File { |
| 30 | - private $ext; |
|
| 31 | - private $size; |
|
| 32 | - private $avatar; |
|
| 30 | + private $ext; |
|
| 31 | + private $size; |
|
| 32 | + private $avatar; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * AvatarNode constructor. |
|
| 36 | - * |
|
| 37 | - * @param integer $size |
|
| 38 | - * @param string $ext |
|
| 39 | - * @param IAvatar $avatar |
|
| 40 | - */ |
|
| 41 | - public function __construct($size, $ext, $avatar) { |
|
| 42 | - $this->size = $size; |
|
| 43 | - $this->ext = $ext; |
|
| 44 | - $this->avatar = $avatar; |
|
| 45 | - } |
|
| 34 | + /** |
|
| 35 | + * AvatarNode constructor. |
|
| 36 | + * |
|
| 37 | + * @param integer $size |
|
| 38 | + * @param string $ext |
|
| 39 | + * @param IAvatar $avatar |
|
| 40 | + */ |
|
| 41 | + public function __construct($size, $ext, $avatar) { |
|
| 42 | + $this->size = $size; |
|
| 43 | + $this->ext = $ext; |
|
| 44 | + $this->avatar = $avatar; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Returns the name of the node. |
|
| 49 | - * |
|
| 50 | - * This is used to generate the url. |
|
| 51 | - * |
|
| 52 | - * @return string |
|
| 53 | - */ |
|
| 54 | - public function getName() { |
|
| 55 | - return "$this->size.$this->ext"; |
|
| 56 | - } |
|
| 47 | + /** |
|
| 48 | + * Returns the name of the node. |
|
| 49 | + * |
|
| 50 | + * This is used to generate the url. |
|
| 51 | + * |
|
| 52 | + * @return string |
|
| 53 | + */ |
|
| 54 | + public function getName() { |
|
| 55 | + return "$this->size.$this->ext"; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - public function get() { |
|
| 59 | - $image = $this->avatar->get($this->size); |
|
| 60 | - $res = $image->resource(); |
|
| 58 | + public function get() { |
|
| 59 | + $image = $this->avatar->get($this->size); |
|
| 60 | + $res = $image->resource(); |
|
| 61 | 61 | |
| 62 | - ob_start(); |
|
| 63 | - if ($this->ext === 'png') { |
|
| 64 | - imagepng($res); |
|
| 65 | - } else { |
|
| 66 | - imagejpeg($res); |
|
| 67 | - } |
|
| 62 | + ob_start(); |
|
| 63 | + if ($this->ext === 'png') { |
|
| 64 | + imagepng($res); |
|
| 65 | + } else { |
|
| 66 | + imagejpeg($res); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - return ob_get_clean(); |
|
| 70 | - } |
|
| 69 | + return ob_get_clean(); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Returns the mime-type for a file |
|
| 74 | - * |
|
| 75 | - * If null is returned, we'll assume application/octet-stream |
|
| 76 | - * |
|
| 77 | - * @return string|null |
|
| 78 | - */ |
|
| 79 | - public function getContentType() { |
|
| 80 | - if ($this->ext === 'png') { |
|
| 81 | - return 'image/png'; |
|
| 82 | - } |
|
| 83 | - return 'image/jpeg'; |
|
| 84 | - } |
|
| 72 | + /** |
|
| 73 | + * Returns the mime-type for a file |
|
| 74 | + * |
|
| 75 | + * If null is returned, we'll assume application/octet-stream |
|
| 76 | + * |
|
| 77 | + * @return string|null |
|
| 78 | + */ |
|
| 79 | + public function getContentType() { |
|
| 80 | + if ($this->ext === 'png') { |
|
| 81 | + return 'image/png'; |
|
| 82 | + } |
|
| 83 | + return 'image/jpeg'; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - public function getETag() { |
|
| 87 | - return $this->avatar->getFile($this->size)->getEtag(); |
|
| 88 | - } |
|
| 86 | + public function getETag() { |
|
| 87 | + return $this->avatar->getFile($this->size)->getEtag(); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - public function getLastModified() { |
|
| 91 | - $timestamp = $this->avatar->getFile($this->size)->getMTime(); |
|
| 92 | - if (!empty($timestamp)) { |
|
| 93 | - return (int)$timestamp; |
|
| 94 | - } |
|
| 95 | - return $timestamp; |
|
| 90 | + public function getLastModified() { |
|
| 91 | + $timestamp = $this->avatar->getFile($this->size)->getMTime(); |
|
| 92 | + if (!empty($timestamp)) { |
|
| 93 | + return (int)$timestamp; |
|
| 94 | + } |
|
| 95 | + return $timestamp; |
|
| 96 | 96 | |
| 97 | - } |
|
| 97 | + } |
|
| 98 | 98 | } |
@@ -31,66 +31,66 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class CappedMemoryCache implements ICache, \ArrayAccess { |
| 33 | 33 | |
| 34 | - private $capacity; |
|
| 35 | - private $cache = []; |
|
| 36 | - |
|
| 37 | - public function __construct($capacity = 512) { |
|
| 38 | - $this->capacity = $capacity; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - public function hasKey($key) { |
|
| 42 | - return isset($this->cache[$key]); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - public function get($key) { |
|
| 46 | - return isset($this->cache[$key]) ? $this->cache[$key] : null; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - public function set($key, $value, $ttl = 0) { |
|
| 50 | - if (is_null($key)) { |
|
| 51 | - $this->cache[] = $value; |
|
| 52 | - } else { |
|
| 53 | - $this->cache[$key] = $value; |
|
| 54 | - } |
|
| 55 | - $this->garbageCollect(); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - public function remove($key) { |
|
| 59 | - unset($this->cache[$key]); |
|
| 60 | - return true; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - public function clear($prefix = '') { |
|
| 64 | - $this->cache = []; |
|
| 65 | - return true; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - public function offsetExists($offset) { |
|
| 69 | - return $this->hasKey($offset); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - public function &offsetGet($offset) { |
|
| 73 | - return $this->cache[$offset]; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - public function offsetSet($offset, $value) { |
|
| 77 | - $this->set($offset, $value); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - public function offsetUnset($offset) { |
|
| 81 | - $this->remove($offset); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - public function getData() { |
|
| 85 | - return $this->cache; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - |
|
| 89 | - private function garbageCollect() { |
|
| 90 | - while (count($this->cache) > $this->capacity) { |
|
| 91 | - reset($this->cache); |
|
| 92 | - $key = key($this->cache); |
|
| 93 | - $this->remove($key); |
|
| 94 | - } |
|
| 95 | - } |
|
| 34 | + private $capacity; |
|
| 35 | + private $cache = []; |
|
| 36 | + |
|
| 37 | + public function __construct($capacity = 512) { |
|
| 38 | + $this->capacity = $capacity; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + public function hasKey($key) { |
|
| 42 | + return isset($this->cache[$key]); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + public function get($key) { |
|
| 46 | + return isset($this->cache[$key]) ? $this->cache[$key] : null; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + public function set($key, $value, $ttl = 0) { |
|
| 50 | + if (is_null($key)) { |
|
| 51 | + $this->cache[] = $value; |
|
| 52 | + } else { |
|
| 53 | + $this->cache[$key] = $value; |
|
| 54 | + } |
|
| 55 | + $this->garbageCollect(); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + public function remove($key) { |
|
| 59 | + unset($this->cache[$key]); |
|
| 60 | + return true; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + public function clear($prefix = '') { |
|
| 64 | + $this->cache = []; |
|
| 65 | + return true; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + public function offsetExists($offset) { |
|
| 69 | + return $this->hasKey($offset); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + public function &offsetGet($offset) { |
|
| 73 | + return $this->cache[$offset]; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + public function offsetSet($offset, $value) { |
|
| 77 | + $this->set($offset, $value); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + public function offsetUnset($offset) { |
|
| 81 | + $this->remove($offset); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + public function getData() { |
|
| 85 | + return $this->cache; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + |
|
| 89 | + private function garbageCollect() { |
|
| 90 | + while (count($this->cache) > $this->capacity) { |
|
| 91 | + reset($this->cache); |
|
| 92 | + $key = key($this->cache); |
|
| 93 | + $this->remove($key); |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | 96 | } |
@@ -33,137 +33,137 @@ |
||
| 33 | 33 | |
| 34 | 34 | class FileSystemTags implements ICheck { |
| 35 | 35 | |
| 36 | - /** @var array */ |
|
| 37 | - protected $fileIds; |
|
| 38 | - |
|
| 39 | - /** @var array */ |
|
| 40 | - protected $fileSystemTags; |
|
| 41 | - |
|
| 42 | - /** @var IL10N */ |
|
| 43 | - protected $l; |
|
| 44 | - |
|
| 45 | - /** @var ISystemTagManager */ |
|
| 46 | - protected $systemTagManager; |
|
| 47 | - |
|
| 48 | - /** @var ISystemTagObjectMapper */ |
|
| 49 | - protected $systemTagObjectMapper; |
|
| 50 | - |
|
| 51 | - /** @var IStorage */ |
|
| 52 | - protected $storage; |
|
| 53 | - |
|
| 54 | - /** @var string */ |
|
| 55 | - protected $path; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param IL10N $l |
|
| 59 | - * @param ISystemTagManager $systemTagManager |
|
| 60 | - * @param ISystemTagObjectMapper $systemTagObjectMapper |
|
| 61 | - */ |
|
| 62 | - public function __construct(IL10N $l, ISystemTagManager $systemTagManager, ISystemTagObjectMapper $systemTagObjectMapper) { |
|
| 63 | - $this->l = $l; |
|
| 64 | - $this->systemTagManager = $systemTagManager; |
|
| 65 | - $this->systemTagObjectMapper = $systemTagObjectMapper; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @param IStorage $storage |
|
| 70 | - * @param string $path |
|
| 71 | - */ |
|
| 72 | - public function setFileInfo(IStorage $storage, $path) { |
|
| 73 | - $this->storage = $storage; |
|
| 74 | - $this->path = $path; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @param string $operator |
|
| 79 | - * @param string $value |
|
| 80 | - * @return bool |
|
| 81 | - */ |
|
| 82 | - public function executeCheck($operator, $value) { |
|
| 83 | - $systemTags = $this->getSystemTags(); |
|
| 84 | - return ($operator === 'is') === in_array($value, $systemTags); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @param string $operator |
|
| 89 | - * @param string $value |
|
| 90 | - * @throws \UnexpectedValueException |
|
| 91 | - */ |
|
| 92 | - public function validateCheck($operator, $value) { |
|
| 93 | - if (!in_array($operator, ['is', '!is'])) { |
|
| 94 | - throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - try { |
|
| 98 | - $this->systemTagManager->getTagsByIds($value); |
|
| 99 | - } catch (TagNotFoundException $e) { |
|
| 100 | - throw new \UnexpectedValueException($this->l->t('The given tag id is invalid'), 2); |
|
| 101 | - } catch (\InvalidArgumentException $e) { |
|
| 102 | - throw new \UnexpectedValueException($this->l->t('The given tag id is invalid'), 3); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Get the ids of the assigned system tags |
|
| 108 | - * @return string[] |
|
| 109 | - */ |
|
| 110 | - protected function getSystemTags() { |
|
| 111 | - $cache = $this->storage->getCache(); |
|
| 112 | - $fileIds = $this->getFileIds($cache, $this->path, !$this->storage->instanceOfStorage(IHomeStorage::class)); |
|
| 113 | - |
|
| 114 | - $systemTags = []; |
|
| 115 | - foreach ($fileIds as $i => $fileId) { |
|
| 116 | - if (isset($this->fileSystemTags[$fileId])) { |
|
| 117 | - $systemTags[] = $this->fileSystemTags[$fileId]; |
|
| 118 | - unset($fileIds[$i]); |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - if (!empty($fileIds)) { |
|
| 123 | - $mappedSystemTags = $this->systemTagObjectMapper->getTagIdsForObjects($fileIds, 'files'); |
|
| 124 | - foreach ($mappedSystemTags as $fileId => $fileSystemTags) { |
|
| 125 | - $this->fileSystemTags[$fileId] = $fileSystemTags; |
|
| 126 | - $systemTags[] = $fileSystemTags; |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - $systemTags = call_user_func_array('array_merge', $systemTags); |
|
| 131 | - $systemTags = array_unique($systemTags); |
|
| 132 | - return $systemTags; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Get the file ids of the given path and its parents |
|
| 137 | - * @param ICache $cache |
|
| 138 | - * @param string $path |
|
| 139 | - * @param bool $isExternalStorage |
|
| 140 | - * @return int[] |
|
| 141 | - */ |
|
| 142 | - protected function getFileIds(ICache $cache, $path, $isExternalStorage) { |
|
| 143 | - $cacheId = $cache->getNumericStorageId(); |
|
| 144 | - if (isset($this->fileIds[$cacheId][$path])) { |
|
| 145 | - return $this->fileIds[$cacheId][$path]; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - $parentIds = []; |
|
| 149 | - if ($path !== $this->dirname($path)) { |
|
| 150 | - $parentIds = $this->getFileIds($cache, $this->dirname($path), $isExternalStorage); |
|
| 151 | - } else if (!$isExternalStorage) { |
|
| 152 | - return []; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - $fileId = $cache->getId($path); |
|
| 156 | - if ($fileId !== -1) { |
|
| 157 | - $parentIds[] = $cache->getId($path); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - $this->fileIds[$cacheId][$path] = $parentIds; |
|
| 161 | - |
|
| 162 | - return $parentIds; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - protected function dirname($path) { |
|
| 166 | - $dir = dirname($path); |
|
| 167 | - return $dir === '.' ? '' : $dir; |
|
| 168 | - } |
|
| 36 | + /** @var array */ |
|
| 37 | + protected $fileIds; |
|
| 38 | + |
|
| 39 | + /** @var array */ |
|
| 40 | + protected $fileSystemTags; |
|
| 41 | + |
|
| 42 | + /** @var IL10N */ |
|
| 43 | + protected $l; |
|
| 44 | + |
|
| 45 | + /** @var ISystemTagManager */ |
|
| 46 | + protected $systemTagManager; |
|
| 47 | + |
|
| 48 | + /** @var ISystemTagObjectMapper */ |
|
| 49 | + protected $systemTagObjectMapper; |
|
| 50 | + |
|
| 51 | + /** @var IStorage */ |
|
| 52 | + protected $storage; |
|
| 53 | + |
|
| 54 | + /** @var string */ |
|
| 55 | + protected $path; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param IL10N $l |
|
| 59 | + * @param ISystemTagManager $systemTagManager |
|
| 60 | + * @param ISystemTagObjectMapper $systemTagObjectMapper |
|
| 61 | + */ |
|
| 62 | + public function __construct(IL10N $l, ISystemTagManager $systemTagManager, ISystemTagObjectMapper $systemTagObjectMapper) { |
|
| 63 | + $this->l = $l; |
|
| 64 | + $this->systemTagManager = $systemTagManager; |
|
| 65 | + $this->systemTagObjectMapper = $systemTagObjectMapper; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @param IStorage $storage |
|
| 70 | + * @param string $path |
|
| 71 | + */ |
|
| 72 | + public function setFileInfo(IStorage $storage, $path) { |
|
| 73 | + $this->storage = $storage; |
|
| 74 | + $this->path = $path; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @param string $operator |
|
| 79 | + * @param string $value |
|
| 80 | + * @return bool |
|
| 81 | + */ |
|
| 82 | + public function executeCheck($operator, $value) { |
|
| 83 | + $systemTags = $this->getSystemTags(); |
|
| 84 | + return ($operator === 'is') === in_array($value, $systemTags); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @param string $operator |
|
| 89 | + * @param string $value |
|
| 90 | + * @throws \UnexpectedValueException |
|
| 91 | + */ |
|
| 92 | + public function validateCheck($operator, $value) { |
|
| 93 | + if (!in_array($operator, ['is', '!is'])) { |
|
| 94 | + throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + try { |
|
| 98 | + $this->systemTagManager->getTagsByIds($value); |
|
| 99 | + } catch (TagNotFoundException $e) { |
|
| 100 | + throw new \UnexpectedValueException($this->l->t('The given tag id is invalid'), 2); |
|
| 101 | + } catch (\InvalidArgumentException $e) { |
|
| 102 | + throw new \UnexpectedValueException($this->l->t('The given tag id is invalid'), 3); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Get the ids of the assigned system tags |
|
| 108 | + * @return string[] |
|
| 109 | + */ |
|
| 110 | + protected function getSystemTags() { |
|
| 111 | + $cache = $this->storage->getCache(); |
|
| 112 | + $fileIds = $this->getFileIds($cache, $this->path, !$this->storage->instanceOfStorage(IHomeStorage::class)); |
|
| 113 | + |
|
| 114 | + $systemTags = []; |
|
| 115 | + foreach ($fileIds as $i => $fileId) { |
|
| 116 | + if (isset($this->fileSystemTags[$fileId])) { |
|
| 117 | + $systemTags[] = $this->fileSystemTags[$fileId]; |
|
| 118 | + unset($fileIds[$i]); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + if (!empty($fileIds)) { |
|
| 123 | + $mappedSystemTags = $this->systemTagObjectMapper->getTagIdsForObjects($fileIds, 'files'); |
|
| 124 | + foreach ($mappedSystemTags as $fileId => $fileSystemTags) { |
|
| 125 | + $this->fileSystemTags[$fileId] = $fileSystemTags; |
|
| 126 | + $systemTags[] = $fileSystemTags; |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + $systemTags = call_user_func_array('array_merge', $systemTags); |
|
| 131 | + $systemTags = array_unique($systemTags); |
|
| 132 | + return $systemTags; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Get the file ids of the given path and its parents |
|
| 137 | + * @param ICache $cache |
|
| 138 | + * @param string $path |
|
| 139 | + * @param bool $isExternalStorage |
|
| 140 | + * @return int[] |
|
| 141 | + */ |
|
| 142 | + protected function getFileIds(ICache $cache, $path, $isExternalStorage) { |
|
| 143 | + $cacheId = $cache->getNumericStorageId(); |
|
| 144 | + if (isset($this->fileIds[$cacheId][$path])) { |
|
| 145 | + return $this->fileIds[$cacheId][$path]; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + $parentIds = []; |
|
| 149 | + if ($path !== $this->dirname($path)) { |
|
| 150 | + $parentIds = $this->getFileIds($cache, $this->dirname($path), $isExternalStorage); |
|
| 151 | + } else if (!$isExternalStorage) { |
|
| 152 | + return []; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + $fileId = $cache->getId($path); |
|
| 156 | + if ($fileId !== -1) { |
|
| 157 | + $parentIds[] = $cache->getId($path); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + $this->fileIds[$cacheId][$path] = $parentIds; |
|
| 161 | + |
|
| 162 | + return $parentIds; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + protected function dirname($path) { |
|
| 166 | + $dir = dirname($path); |
|
| 167 | + return $dir === '.' ? '' : $dir; |
|
| 168 | + } |
|
| 169 | 169 | } |
@@ -37,308 +37,308 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | interface IShare { |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Set the internal id of the share |
|
| 42 | - * It is only allowed to set the internal id of a share once. |
|
| 43 | - * Attempts to override the internal id will result in an IllegalIDChangeException |
|
| 44 | - * |
|
| 45 | - * @param string $id |
|
| 46 | - * @return \OCP\Share\IShare |
|
| 47 | - * @throws IllegalIDChangeException |
|
| 48 | - * @throws \InvalidArgumentException |
|
| 49 | - * @since 9.1.0 |
|
| 50 | - */ |
|
| 51 | - public function setId($id); |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Get the internal id of the share. |
|
| 55 | - * |
|
| 56 | - * @return string |
|
| 57 | - * @since 9.0.0 |
|
| 58 | - */ |
|
| 59 | - public function getId(); |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Get the full share id. This is the <providerid>:<internalid>. |
|
| 63 | - * The full id is unique in the system. |
|
| 64 | - * |
|
| 65 | - * @return string |
|
| 66 | - * @since 9.0.0 |
|
| 67 | - * @throws \UnexpectedValueException If the fullId could not be constructed |
|
| 68 | - */ |
|
| 69 | - public function getFullId(); |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Set the provider id of the share |
|
| 73 | - * It is only allowed to set the provider id of a share once. |
|
| 74 | - * Attempts to override the provider id will result in an IllegalIDChangeException |
|
| 75 | - * |
|
| 76 | - * @param string $id |
|
| 77 | - * @return \OCP\Share\IShare |
|
| 78 | - * @throws IllegalIDChangeException |
|
| 79 | - * @throws \InvalidArgumentException |
|
| 80 | - * @since 9.1.0 |
|
| 81 | - */ |
|
| 82 | - public function setProviderId($id); |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Set the node of the file/folder that is shared |
|
| 86 | - * |
|
| 87 | - * @param Node $node |
|
| 88 | - * @return \OCP\Share\IShare The modified object |
|
| 89 | - * @since 9.0.0 |
|
| 90 | - */ |
|
| 91 | - public function setNode(Node $node); |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Get the node of the file/folder that is shared |
|
| 95 | - * |
|
| 96 | - * @return File|Folder |
|
| 97 | - * @since 9.0.0 |
|
| 98 | - * @throws NotFoundException |
|
| 99 | - */ |
|
| 100 | - public function getNode(); |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Set file id for lazy evaluation of the node |
|
| 104 | - * @param int $fileId |
|
| 105 | - * @return \OCP\Share\IShare The modified object |
|
| 106 | - * @since 9.0.0 |
|
| 107 | - */ |
|
| 108 | - public function setNodeId($fileId); |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Get the fileid of the node of this share |
|
| 112 | - * @return int |
|
| 113 | - * @since 9.0.0 |
|
| 114 | - * @throws NotFoundException |
|
| 115 | - */ |
|
| 116 | - public function getNodeId(); |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Set the type of node (file/folder) |
|
| 120 | - * |
|
| 121 | - * @param string $type |
|
| 122 | - * @return \OCP\Share\IShare The modified object |
|
| 123 | - * @since 9.0.0 |
|
| 124 | - */ |
|
| 125 | - public function setNodeType($type); |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Get the type of node (file/folder) |
|
| 129 | - * |
|
| 130 | - * @return string |
|
| 131 | - * @since 9.0.0 |
|
| 132 | - * @throws NotFoundException |
|
| 133 | - */ |
|
| 134 | - public function getNodeType(); |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Set the shareType |
|
| 138 | - * |
|
| 139 | - * @param int $shareType |
|
| 140 | - * @return \OCP\Share\IShare The modified object |
|
| 141 | - * @since 9.0.0 |
|
| 142 | - */ |
|
| 143 | - public function setShareType($shareType); |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Get the shareType |
|
| 147 | - * |
|
| 148 | - * @return int |
|
| 149 | - * @since 9.0.0 |
|
| 150 | - */ |
|
| 151 | - public function getShareType(); |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Set the receiver of this share. |
|
| 155 | - * |
|
| 156 | - * @param string $sharedWith |
|
| 157 | - * @return \OCP\Share\IShare The modified object |
|
| 158 | - * @since 9.0.0 |
|
| 159 | - */ |
|
| 160 | - public function setSharedWith($sharedWith); |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Get the receiver of this share. |
|
| 164 | - * |
|
| 165 | - * @return string |
|
| 166 | - * @since 9.0.0 |
|
| 167 | - */ |
|
| 168 | - public function getSharedWith(); |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Set the permissions. |
|
| 172 | - * See \OCP\Constants::PERMISSION_* |
|
| 173 | - * |
|
| 174 | - * @param int $permissions |
|
| 175 | - * @return \OCP\Share\IShare The modified object |
|
| 176 | - * @since 9.0.0 |
|
| 177 | - */ |
|
| 178 | - public function setPermissions($permissions); |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Get the share permissions |
|
| 182 | - * See \OCP\Constants::PERMISSION_* |
|
| 183 | - * |
|
| 184 | - * @return int |
|
| 185 | - * @since 9.0.0 |
|
| 186 | - */ |
|
| 187 | - public function getPermissions(); |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Set the expiration date |
|
| 191 | - * |
|
| 192 | - * @param null|\DateTime $expireDate |
|
| 193 | - * @return \OCP\Share\IShare The modified object |
|
| 194 | - * @since 9.0.0 |
|
| 195 | - */ |
|
| 196 | - public function setExpirationDate($expireDate); |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Get the expiration date |
|
| 200 | - * |
|
| 201 | - * @return \DateTime |
|
| 202 | - * @since 9.0.0 |
|
| 203 | - */ |
|
| 204 | - public function getExpirationDate(); |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Set the sharer of the path. |
|
| 208 | - * |
|
| 209 | - * @param string $sharedBy |
|
| 210 | - * @return \OCP\Share\IShare The modified object |
|
| 211 | - * @since 9.0.0 |
|
| 212 | - */ |
|
| 213 | - public function setSharedBy($sharedBy); |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Get share sharer |
|
| 217 | - * |
|
| 218 | - * @return string |
|
| 219 | - * @since 9.0.0 |
|
| 220 | - */ |
|
| 221 | - public function getSharedBy(); |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Set the original share owner (who owns the path that is shared) |
|
| 225 | - * |
|
| 226 | - * @param string $shareOwner |
|
| 227 | - * @return \OCP\Share\IShare The modified object |
|
| 228 | - * @since 9.0.0 |
|
| 229 | - */ |
|
| 230 | - public function setShareOwner($shareOwner); |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * Get the original share owner (who owns the path that is shared) |
|
| 234 | - * |
|
| 235 | - * @return string |
|
| 236 | - * @since 9.0.0 |
|
| 237 | - */ |
|
| 238 | - public function getShareOwner(); |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * Set the password for this share. |
|
| 242 | - * When the share is passed to the share manager to be created |
|
| 243 | - * or updated the password will be hashed. |
|
| 244 | - * |
|
| 245 | - * @param string $password |
|
| 246 | - * @return \OCP\Share\IShare The modified object |
|
| 247 | - * @since 9.0.0 |
|
| 248 | - */ |
|
| 249 | - public function setPassword($password); |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * Get the password of this share. |
|
| 253 | - * If this share is obtained via a shareprovider the password is |
|
| 254 | - * hashed. |
|
| 255 | - * |
|
| 256 | - * @return string |
|
| 257 | - * @since 9.0.0 |
|
| 258 | - */ |
|
| 259 | - public function getPassword(); |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Set the public link token. |
|
| 263 | - * |
|
| 264 | - * @param string $token |
|
| 265 | - * @return \OCP\Share\IShare The modified object |
|
| 266 | - * @since 9.0.0 |
|
| 267 | - */ |
|
| 268 | - public function setToken($token); |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * Get the public link token. |
|
| 272 | - * |
|
| 273 | - * @return string |
|
| 274 | - * @since 9.0.0 |
|
| 275 | - */ |
|
| 276 | - public function getToken(); |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * Set the target path of this share relative to the recipients user folder. |
|
| 280 | - * |
|
| 281 | - * @param string $target |
|
| 282 | - * @return \OCP\Share\IShare The modified object |
|
| 283 | - * @since 9.0.0 |
|
| 284 | - */ |
|
| 285 | - public function setTarget($target); |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * Get the target path of this share relative to the recipients user folder. |
|
| 289 | - * |
|
| 290 | - * @return string |
|
| 291 | - * @since 9.0.0 |
|
| 292 | - */ |
|
| 293 | - public function getTarget(); |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * Set the time this share was created |
|
| 297 | - * |
|
| 298 | - * @param \DateTime $shareTime |
|
| 299 | - * @return \OCP\Share\IShare The modified object |
|
| 300 | - * @since 9.0.0 |
|
| 301 | - */ |
|
| 302 | - public function setShareTime(\DateTime $shareTime); |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Get the timestamp this share was created |
|
| 306 | - * |
|
| 307 | - * @return \DateTime |
|
| 308 | - * @since 9.0.0 |
|
| 309 | - */ |
|
| 310 | - public function getShareTime(); |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * Set if the recipient is informed by mail about the share. |
|
| 314 | - * |
|
| 315 | - * @param bool $mailSend |
|
| 316 | - * @return \OCP\Share\IShare The modified object |
|
| 317 | - * @since 9.0.0 |
|
| 318 | - */ |
|
| 319 | - public function setMailSend($mailSend); |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Get if the recipient informed by mail about the share. |
|
| 323 | - * |
|
| 324 | - * @return bool |
|
| 325 | - * @since 9.0.0 |
|
| 326 | - */ |
|
| 327 | - public function getMailSend(); |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * Set the cache entry for the shared node |
|
| 331 | - * |
|
| 332 | - * @param ICacheEntry $entry |
|
| 333 | - * @since 11.0.0 |
|
| 334 | - */ |
|
| 335 | - public function setNodeCacheEntry(ICacheEntry $entry); |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * Get the cache entry for the shared node |
|
| 339 | - * |
|
| 340 | - * @return null|ICacheEntry |
|
| 341 | - * @since 11.0.0 |
|
| 342 | - */ |
|
| 343 | - public function getNodeCacheEntry(); |
|
| 40 | + /** |
|
| 41 | + * Set the internal id of the share |
|
| 42 | + * It is only allowed to set the internal id of a share once. |
|
| 43 | + * Attempts to override the internal id will result in an IllegalIDChangeException |
|
| 44 | + * |
|
| 45 | + * @param string $id |
|
| 46 | + * @return \OCP\Share\IShare |
|
| 47 | + * @throws IllegalIDChangeException |
|
| 48 | + * @throws \InvalidArgumentException |
|
| 49 | + * @since 9.1.0 |
|
| 50 | + */ |
|
| 51 | + public function setId($id); |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Get the internal id of the share. |
|
| 55 | + * |
|
| 56 | + * @return string |
|
| 57 | + * @since 9.0.0 |
|
| 58 | + */ |
|
| 59 | + public function getId(); |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Get the full share id. This is the <providerid>:<internalid>. |
|
| 63 | + * The full id is unique in the system. |
|
| 64 | + * |
|
| 65 | + * @return string |
|
| 66 | + * @since 9.0.0 |
|
| 67 | + * @throws \UnexpectedValueException If the fullId could not be constructed |
|
| 68 | + */ |
|
| 69 | + public function getFullId(); |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Set the provider id of the share |
|
| 73 | + * It is only allowed to set the provider id of a share once. |
|
| 74 | + * Attempts to override the provider id will result in an IllegalIDChangeException |
|
| 75 | + * |
|
| 76 | + * @param string $id |
|
| 77 | + * @return \OCP\Share\IShare |
|
| 78 | + * @throws IllegalIDChangeException |
|
| 79 | + * @throws \InvalidArgumentException |
|
| 80 | + * @since 9.1.0 |
|
| 81 | + */ |
|
| 82 | + public function setProviderId($id); |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Set the node of the file/folder that is shared |
|
| 86 | + * |
|
| 87 | + * @param Node $node |
|
| 88 | + * @return \OCP\Share\IShare The modified object |
|
| 89 | + * @since 9.0.0 |
|
| 90 | + */ |
|
| 91 | + public function setNode(Node $node); |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Get the node of the file/folder that is shared |
|
| 95 | + * |
|
| 96 | + * @return File|Folder |
|
| 97 | + * @since 9.0.0 |
|
| 98 | + * @throws NotFoundException |
|
| 99 | + */ |
|
| 100 | + public function getNode(); |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Set file id for lazy evaluation of the node |
|
| 104 | + * @param int $fileId |
|
| 105 | + * @return \OCP\Share\IShare The modified object |
|
| 106 | + * @since 9.0.0 |
|
| 107 | + */ |
|
| 108 | + public function setNodeId($fileId); |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Get the fileid of the node of this share |
|
| 112 | + * @return int |
|
| 113 | + * @since 9.0.0 |
|
| 114 | + * @throws NotFoundException |
|
| 115 | + */ |
|
| 116 | + public function getNodeId(); |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Set the type of node (file/folder) |
|
| 120 | + * |
|
| 121 | + * @param string $type |
|
| 122 | + * @return \OCP\Share\IShare The modified object |
|
| 123 | + * @since 9.0.0 |
|
| 124 | + */ |
|
| 125 | + public function setNodeType($type); |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Get the type of node (file/folder) |
|
| 129 | + * |
|
| 130 | + * @return string |
|
| 131 | + * @since 9.0.0 |
|
| 132 | + * @throws NotFoundException |
|
| 133 | + */ |
|
| 134 | + public function getNodeType(); |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Set the shareType |
|
| 138 | + * |
|
| 139 | + * @param int $shareType |
|
| 140 | + * @return \OCP\Share\IShare The modified object |
|
| 141 | + * @since 9.0.0 |
|
| 142 | + */ |
|
| 143 | + public function setShareType($shareType); |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Get the shareType |
|
| 147 | + * |
|
| 148 | + * @return int |
|
| 149 | + * @since 9.0.0 |
|
| 150 | + */ |
|
| 151 | + public function getShareType(); |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Set the receiver of this share. |
|
| 155 | + * |
|
| 156 | + * @param string $sharedWith |
|
| 157 | + * @return \OCP\Share\IShare The modified object |
|
| 158 | + * @since 9.0.0 |
|
| 159 | + */ |
|
| 160 | + public function setSharedWith($sharedWith); |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Get the receiver of this share. |
|
| 164 | + * |
|
| 165 | + * @return string |
|
| 166 | + * @since 9.0.0 |
|
| 167 | + */ |
|
| 168 | + public function getSharedWith(); |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Set the permissions. |
|
| 172 | + * See \OCP\Constants::PERMISSION_* |
|
| 173 | + * |
|
| 174 | + * @param int $permissions |
|
| 175 | + * @return \OCP\Share\IShare The modified object |
|
| 176 | + * @since 9.0.0 |
|
| 177 | + */ |
|
| 178 | + public function setPermissions($permissions); |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Get the share permissions |
|
| 182 | + * See \OCP\Constants::PERMISSION_* |
|
| 183 | + * |
|
| 184 | + * @return int |
|
| 185 | + * @since 9.0.0 |
|
| 186 | + */ |
|
| 187 | + public function getPermissions(); |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Set the expiration date |
|
| 191 | + * |
|
| 192 | + * @param null|\DateTime $expireDate |
|
| 193 | + * @return \OCP\Share\IShare The modified object |
|
| 194 | + * @since 9.0.0 |
|
| 195 | + */ |
|
| 196 | + public function setExpirationDate($expireDate); |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Get the expiration date |
|
| 200 | + * |
|
| 201 | + * @return \DateTime |
|
| 202 | + * @since 9.0.0 |
|
| 203 | + */ |
|
| 204 | + public function getExpirationDate(); |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Set the sharer of the path. |
|
| 208 | + * |
|
| 209 | + * @param string $sharedBy |
|
| 210 | + * @return \OCP\Share\IShare The modified object |
|
| 211 | + * @since 9.0.0 |
|
| 212 | + */ |
|
| 213 | + public function setSharedBy($sharedBy); |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Get share sharer |
|
| 217 | + * |
|
| 218 | + * @return string |
|
| 219 | + * @since 9.0.0 |
|
| 220 | + */ |
|
| 221 | + public function getSharedBy(); |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Set the original share owner (who owns the path that is shared) |
|
| 225 | + * |
|
| 226 | + * @param string $shareOwner |
|
| 227 | + * @return \OCP\Share\IShare The modified object |
|
| 228 | + * @since 9.0.0 |
|
| 229 | + */ |
|
| 230 | + public function setShareOwner($shareOwner); |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * Get the original share owner (who owns the path that is shared) |
|
| 234 | + * |
|
| 235 | + * @return string |
|
| 236 | + * @since 9.0.0 |
|
| 237 | + */ |
|
| 238 | + public function getShareOwner(); |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Set the password for this share. |
|
| 242 | + * When the share is passed to the share manager to be created |
|
| 243 | + * or updated the password will be hashed. |
|
| 244 | + * |
|
| 245 | + * @param string $password |
|
| 246 | + * @return \OCP\Share\IShare The modified object |
|
| 247 | + * @since 9.0.0 |
|
| 248 | + */ |
|
| 249 | + public function setPassword($password); |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * Get the password of this share. |
|
| 253 | + * If this share is obtained via a shareprovider the password is |
|
| 254 | + * hashed. |
|
| 255 | + * |
|
| 256 | + * @return string |
|
| 257 | + * @since 9.0.0 |
|
| 258 | + */ |
|
| 259 | + public function getPassword(); |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Set the public link token. |
|
| 263 | + * |
|
| 264 | + * @param string $token |
|
| 265 | + * @return \OCP\Share\IShare The modified object |
|
| 266 | + * @since 9.0.0 |
|
| 267 | + */ |
|
| 268 | + public function setToken($token); |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * Get the public link token. |
|
| 272 | + * |
|
| 273 | + * @return string |
|
| 274 | + * @since 9.0.0 |
|
| 275 | + */ |
|
| 276 | + public function getToken(); |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * Set the target path of this share relative to the recipients user folder. |
|
| 280 | + * |
|
| 281 | + * @param string $target |
|
| 282 | + * @return \OCP\Share\IShare The modified object |
|
| 283 | + * @since 9.0.0 |
|
| 284 | + */ |
|
| 285 | + public function setTarget($target); |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * Get the target path of this share relative to the recipients user folder. |
|
| 289 | + * |
|
| 290 | + * @return string |
|
| 291 | + * @since 9.0.0 |
|
| 292 | + */ |
|
| 293 | + public function getTarget(); |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * Set the time this share was created |
|
| 297 | + * |
|
| 298 | + * @param \DateTime $shareTime |
|
| 299 | + * @return \OCP\Share\IShare The modified object |
|
| 300 | + * @since 9.0.0 |
|
| 301 | + */ |
|
| 302 | + public function setShareTime(\DateTime $shareTime); |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Get the timestamp this share was created |
|
| 306 | + * |
|
| 307 | + * @return \DateTime |
|
| 308 | + * @since 9.0.0 |
|
| 309 | + */ |
|
| 310 | + public function getShareTime(); |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * Set if the recipient is informed by mail about the share. |
|
| 314 | + * |
|
| 315 | + * @param bool $mailSend |
|
| 316 | + * @return \OCP\Share\IShare The modified object |
|
| 317 | + * @since 9.0.0 |
|
| 318 | + */ |
|
| 319 | + public function setMailSend($mailSend); |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Get if the recipient informed by mail about the share. |
|
| 323 | + * |
|
| 324 | + * @return bool |
|
| 325 | + * @since 9.0.0 |
|
| 326 | + */ |
|
| 327 | + public function getMailSend(); |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * Set the cache entry for the shared node |
|
| 331 | + * |
|
| 332 | + * @param ICacheEntry $entry |
|
| 333 | + * @since 11.0.0 |
|
| 334 | + */ |
|
| 335 | + public function setNodeCacheEntry(ICacheEntry $entry); |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * Get the cache entry for the shared node |
|
| 339 | + * |
|
| 340 | + * @return null|ICacheEntry |
|
| 341 | + * @since 11.0.0 |
|
| 342 | + */ |
|
| 343 | + public function getNodeCacheEntry(); |
|
| 344 | 344 | } |
@@ -35,80 +35,80 @@ |
||
| 35 | 35 | |
| 36 | 36 | class ActionProviderStore { |
| 37 | 37 | |
| 38 | - /** @var IServerContainer */ |
|
| 39 | - private $serverContainer; |
|
| 40 | - |
|
| 41 | - /** @var AppManager */ |
|
| 42 | - private $appManager; |
|
| 43 | - |
|
| 44 | - /** @var ILogger */ |
|
| 45 | - private $logger; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @param IServerContainer $serverContainer |
|
| 49 | - * @param AppManager $appManager |
|
| 50 | - * @param ILogger $logger |
|
| 51 | - */ |
|
| 52 | - public function __construct(IServerContainer $serverContainer, AppManager $appManager, ILogger $logger) { |
|
| 53 | - $this->serverContainer = $serverContainer; |
|
| 54 | - $this->appManager = $appManager; |
|
| 55 | - $this->logger = $logger; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @param IUser $user |
|
| 60 | - * @return IProvider[] |
|
| 61 | - * @throws Exception |
|
| 62 | - */ |
|
| 63 | - public function getProviders(IUser $user) { |
|
| 64 | - $appClasses = $this->getAppProviderClasses($user); |
|
| 65 | - $providerClasses = $this->getServerProviderClasses(); |
|
| 66 | - $allClasses = array_merge($providerClasses, $appClasses); |
|
| 67 | - $providers = []; |
|
| 68 | - |
|
| 69 | - foreach ($allClasses as $class) { |
|
| 70 | - try { |
|
| 71 | - $providers[] = $this->serverContainer->query($class); |
|
| 72 | - } catch (QueryException $ex) { |
|
| 73 | - $this->logger->logException($ex, [ |
|
| 74 | - 'message' => "Could not load contacts menu action provider $class", |
|
| 75 | - 'app' => 'core', |
|
| 76 | - ]); |
|
| 77 | - throw new Exception("Could not load contacts menu action provider"); |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - return $providers; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @return string[] |
|
| 86 | - */ |
|
| 87 | - private function getServerProviderClasses() { |
|
| 88 | - return [ |
|
| 89 | - EMailProvider::class, |
|
| 90 | - ]; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @param IUser $user |
|
| 95 | - * @return string[] |
|
| 96 | - */ |
|
| 97 | - private function getAppProviderClasses(IUser $user) { |
|
| 98 | - return array_reduce($this->appManager->getEnabledAppsForUser($user), function($all, $appId) { |
|
| 99 | - $info = $this->appManager->getAppInfo($appId); |
|
| 100 | - |
|
| 101 | - if (!isset($info['contactsmenu']) || !isset($info['contactsmenu'])) { |
|
| 102 | - // Nothing to add |
|
| 103 | - return $all; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $providers = array_reduce($info['contactsmenu'], function($all, $provider) { |
|
| 107 | - return array_merge($all, [$provider]); |
|
| 108 | - }, []); |
|
| 109 | - |
|
| 110 | - return array_merge($all, $providers); |
|
| 111 | - }, []); |
|
| 112 | - } |
|
| 38 | + /** @var IServerContainer */ |
|
| 39 | + private $serverContainer; |
|
| 40 | + |
|
| 41 | + /** @var AppManager */ |
|
| 42 | + private $appManager; |
|
| 43 | + |
|
| 44 | + /** @var ILogger */ |
|
| 45 | + private $logger; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @param IServerContainer $serverContainer |
|
| 49 | + * @param AppManager $appManager |
|
| 50 | + * @param ILogger $logger |
|
| 51 | + */ |
|
| 52 | + public function __construct(IServerContainer $serverContainer, AppManager $appManager, ILogger $logger) { |
|
| 53 | + $this->serverContainer = $serverContainer; |
|
| 54 | + $this->appManager = $appManager; |
|
| 55 | + $this->logger = $logger; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @param IUser $user |
|
| 60 | + * @return IProvider[] |
|
| 61 | + * @throws Exception |
|
| 62 | + */ |
|
| 63 | + public function getProviders(IUser $user) { |
|
| 64 | + $appClasses = $this->getAppProviderClasses($user); |
|
| 65 | + $providerClasses = $this->getServerProviderClasses(); |
|
| 66 | + $allClasses = array_merge($providerClasses, $appClasses); |
|
| 67 | + $providers = []; |
|
| 68 | + |
|
| 69 | + foreach ($allClasses as $class) { |
|
| 70 | + try { |
|
| 71 | + $providers[] = $this->serverContainer->query($class); |
|
| 72 | + } catch (QueryException $ex) { |
|
| 73 | + $this->logger->logException($ex, [ |
|
| 74 | + 'message' => "Could not load contacts menu action provider $class", |
|
| 75 | + 'app' => 'core', |
|
| 76 | + ]); |
|
| 77 | + throw new Exception("Could not load contacts menu action provider"); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + return $providers; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @return string[] |
|
| 86 | + */ |
|
| 87 | + private function getServerProviderClasses() { |
|
| 88 | + return [ |
|
| 89 | + EMailProvider::class, |
|
| 90 | + ]; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @param IUser $user |
|
| 95 | + * @return string[] |
|
| 96 | + */ |
|
| 97 | + private function getAppProviderClasses(IUser $user) { |
|
| 98 | + return array_reduce($this->appManager->getEnabledAppsForUser($user), function($all, $appId) { |
|
| 99 | + $info = $this->appManager->getAppInfo($appId); |
|
| 100 | + |
|
| 101 | + if (!isset($info['contactsmenu']) || !isset($info['contactsmenu'])) { |
|
| 102 | + // Nothing to add |
|
| 103 | + return $all; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $providers = array_reduce($info['contactsmenu'], function($all, $provider) { |
|
| 107 | + return array_merge($all, [$provider]); |
|
| 108 | + }, []); |
|
| 109 | + |
|
| 110 | + return array_merge($all, $providers); |
|
| 111 | + }, []); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | 114 | } |
@@ -24,56 +24,56 @@ |
||
| 24 | 24 | use OCP\Lockdown\ILockdownManager; |
| 25 | 25 | |
| 26 | 26 | class LockdownManager implements ILockdownManager { |
| 27 | - /** @var ISession */ |
|
| 28 | - private $sessionCallback; |
|
| 27 | + /** @var ISession */ |
|
| 28 | + private $sessionCallback; |
|
| 29 | 29 | |
| 30 | - private $enabled = false; |
|
| 30 | + private $enabled = false; |
|
| 31 | 31 | |
| 32 | - /** @var array|null */ |
|
| 33 | - private $scope; |
|
| 32 | + /** @var array|null */ |
|
| 33 | + private $scope; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * LockdownManager constructor. |
|
| 37 | - * |
|
| 38 | - * @param callable $sessionCallback we need to inject the session lazily to avoid dependency loops |
|
| 39 | - */ |
|
| 40 | - public function __construct(callable $sessionCallback) { |
|
| 41 | - $this->sessionCallback = $sessionCallback; |
|
| 42 | - } |
|
| 35 | + /** |
|
| 36 | + * LockdownManager constructor. |
|
| 37 | + * |
|
| 38 | + * @param callable $sessionCallback we need to inject the session lazily to avoid dependency loops |
|
| 39 | + */ |
|
| 40 | + public function __construct(callable $sessionCallback) { |
|
| 41 | + $this->sessionCallback = $sessionCallback; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | - public function enable() { |
|
| 46 | - $this->enabled = true; |
|
| 47 | - } |
|
| 45 | + public function enable() { |
|
| 46 | + $this->enabled = true; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @return ISession |
|
| 51 | - */ |
|
| 52 | - private function getSession() { |
|
| 53 | - $callback = $this->sessionCallback; |
|
| 54 | - return $callback(); |
|
| 55 | - } |
|
| 49 | + /** |
|
| 50 | + * @return ISession |
|
| 51 | + */ |
|
| 52 | + private function getSession() { |
|
| 53 | + $callback = $this->sessionCallback; |
|
| 54 | + return $callback(); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - private function getScopeAsArray() { |
|
| 58 | - if (!$this->scope) { |
|
| 59 | - $session = $this->getSession(); |
|
| 60 | - $sessionScope = $session->get('token_scope'); |
|
| 61 | - if ($sessionScope) { |
|
| 62 | - $this->scope = $sessionScope; |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - return $this->scope; |
|
| 66 | - } |
|
| 57 | + private function getScopeAsArray() { |
|
| 58 | + if (!$this->scope) { |
|
| 59 | + $session = $this->getSession(); |
|
| 60 | + $sessionScope = $session->get('token_scope'); |
|
| 61 | + if ($sessionScope) { |
|
| 62 | + $this->scope = $sessionScope; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + return $this->scope; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - public function setToken(IToken $token) { |
|
| 69 | - $this->scope = $token->getScopeAsArray(); |
|
| 70 | - $session = $this->getSession(); |
|
| 71 | - $session->set('token_scope', $this->scope); |
|
| 72 | - $this->enable(); |
|
| 73 | - } |
|
| 68 | + public function setToken(IToken $token) { |
|
| 69 | + $this->scope = $token->getScopeAsArray(); |
|
| 70 | + $session = $this->getSession(); |
|
| 71 | + $session->set('token_scope', $this->scope); |
|
| 72 | + $this->enable(); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - public function canAccessFilesystem() { |
|
| 76 | - $scope = $this->getScopeAsArray(); |
|
| 77 | - return !$scope || $scope['filesystem']; |
|
| 78 | - } |
|
| 75 | + public function canAccessFilesystem() { |
|
| 76 | + $scope = $this->getScopeAsArray(); |
|
| 77 | + return !$scope || $scope['filesystem']; |
|
| 78 | + } |
|
| 79 | 79 | } |
@@ -23,36 +23,36 @@ |
||
| 23 | 23 | |
| 24 | 24 | /** @var $this \OCP\Route\IRouter */ |
| 25 | 25 | $this->create('user_ldap_ajax_clearMappings', 'ajax/clearMappings.php') |
| 26 | - ->actionInclude('user_ldap/ajax/clearMappings.php'); |
|
| 26 | + ->actionInclude('user_ldap/ajax/clearMappings.php'); |
|
| 27 | 27 | $this->create('user_ldap_ajax_deleteConfiguration', 'ajax/deleteConfiguration.php') |
| 28 | - ->actionInclude('user_ldap/ajax/deleteConfiguration.php'); |
|
| 28 | + ->actionInclude('user_ldap/ajax/deleteConfiguration.php'); |
|
| 29 | 29 | $this->create('user_ldap_ajax_getConfiguration', 'ajax/getConfiguration.php') |
| 30 | - ->actionInclude('user_ldap/ajax/getConfiguration.php'); |
|
| 30 | + ->actionInclude('user_ldap/ajax/getConfiguration.php'); |
|
| 31 | 31 | $this->create('user_ldap_ajax_getNewServerConfigPrefix', 'ajax/getNewServerConfigPrefix.php') |
| 32 | - ->actionInclude('user_ldap/ajax/getNewServerConfigPrefix.php'); |
|
| 32 | + ->actionInclude('user_ldap/ajax/getNewServerConfigPrefix.php'); |
|
| 33 | 33 | $this->create('user_ldap_ajax_setConfiguration', 'ajax/setConfiguration.php') |
| 34 | - ->actionInclude('user_ldap/ajax/setConfiguration.php'); |
|
| 34 | + ->actionInclude('user_ldap/ajax/setConfiguration.php'); |
|
| 35 | 35 | $this->create('user_ldap_ajax_testConfiguration', 'ajax/testConfiguration.php') |
| 36 | - ->actionInclude('user_ldap/ajax/testConfiguration.php'); |
|
| 36 | + ->actionInclude('user_ldap/ajax/testConfiguration.php'); |
|
| 37 | 37 | $this->create('user_ldap_ajax_wizard', 'ajax/wizard.php') |
| 38 | - ->actionInclude('user_ldap/ajax/wizard.php'); |
|
| 38 | + ->actionInclude('user_ldap/ajax/wizard.php'); |
|
| 39 | 39 | |
| 40 | 40 | $application = new \OCP\AppFramework\App('user_ldap'); |
| 41 | 41 | $application->registerRoutes($this, [ |
| 42 | - 'ocs' => [ |
|
| 43 | - ['name' => 'ConfigAPI#create', 'url' => '/api/v1/config', 'verb' => 'POST'], |
|
| 44 | - ['name' => 'ConfigAPI#show', 'url' => '/api/v1/config/{configID}', 'verb' => 'GET'], |
|
| 45 | - ['name' => 'ConfigAPI#modify', 'url' => '/api/v1/config/{configID}', 'verb' => 'PUT'], |
|
| 46 | - ['name' => 'ConfigAPI#delete', 'url' => '/api/v1/config/{configID}', 'verb' => 'DELETE'], |
|
| 47 | - ] |
|
| 42 | + 'ocs' => [ |
|
| 43 | + ['name' => 'ConfigAPI#create', 'url' => '/api/v1/config', 'verb' => 'POST'], |
|
| 44 | + ['name' => 'ConfigAPI#show', 'url' => '/api/v1/config/{configID}', 'verb' => 'GET'], |
|
| 45 | + ['name' => 'ConfigAPI#modify', 'url' => '/api/v1/config/{configID}', 'verb' => 'PUT'], |
|
| 46 | + ['name' => 'ConfigAPI#delete', 'url' => '/api/v1/config/{configID}', 'verb' => 'DELETE'], |
|
| 47 | + ] |
|
| 48 | 48 | ]); |
| 49 | 49 | |
| 50 | 50 | $application = new OCA\User_LDAP\AppInfo\Application(); |
| 51 | 51 | $application->registerRoutes($this, [ |
| 52 | - 'routes' => [ |
|
| 53 | - ['name' => 'renewPassword#tryRenewPassword', 'url' => '/renewpassword', 'verb' => 'POST'], |
|
| 54 | - ['name' => 'renewPassword#showRenewPasswordForm', 'url' => '/renewpassword/{user}', 'verb' => 'GET'], |
|
| 55 | - ['name' => 'renewPassword#cancel', 'url' => '/renewpassword/cancel', 'verb' => 'GET'], |
|
| 56 | - ['name' => 'renewPassword#showLoginFormInvalidPassword', 'url' => '/renewpassword/invalidlogin/{user}', 'verb' => 'GET'], |
|
| 57 | - ] |
|
| 52 | + 'routes' => [ |
|
| 53 | + ['name' => 'renewPassword#tryRenewPassword', 'url' => '/renewpassword', 'verb' => 'POST'], |
|
| 54 | + ['name' => 'renewPassword#showRenewPasswordForm', 'url' => '/renewpassword/{user}', 'verb' => 'GET'], |
|
| 55 | + ['name' => 'renewPassword#cancel', 'url' => '/renewpassword/cancel', 'verb' => 'GET'], |
|
| 56 | + ['name' => 'renewPassword#showLoginFormInvalidPassword', 'url' => '/renewpassword/invalidlogin/{user}', 'verb' => 'GET'], |
|
| 57 | + ] |
|
| 58 | 58 | ]); |