@@ -20,348 +20,348 @@ |
||
| 20 | 20 | use OCP\SystemTag\TagNotFoundException; |
| 21 | 21 | |
| 22 | 22 | class SystemTagObjectMapper implements ISystemTagObjectMapper { |
| 23 | - public const RELATION_TABLE = 'systemtag_object_mapping'; |
|
| 24 | - |
|
| 25 | - public function __construct( |
|
| 26 | - protected IDBConnection $connection, |
|
| 27 | - protected ISystemTagManager $tagManager, |
|
| 28 | - protected IEventDispatcher $dispatcher, |
|
| 29 | - ) { |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * {@inheritdoc} |
|
| 34 | - */ |
|
| 35 | - public function getTagIdsForObjects($objIds, string $objectType): array { |
|
| 36 | - if (!\is_array($objIds)) { |
|
| 37 | - $objIds = [$objIds]; |
|
| 38 | - } elseif (empty($objIds)) { |
|
| 39 | - return []; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - $query = $this->connection->getQueryBuilder(); |
|
| 43 | - $query->select(['systemtagid', 'objectid']) |
|
| 44 | - ->from(self::RELATION_TABLE) |
|
| 45 | - ->where($query->expr()->in('objectid', $query->createParameter('objectids'))) |
|
| 46 | - ->andWhere($query->expr()->eq('objecttype', $query->createParameter('objecttype'))) |
|
| 47 | - ->setParameter('objecttype', $objectType) |
|
| 48 | - ->addOrderBy('objectid', 'ASC') |
|
| 49 | - ->addOrderBy('systemtagid', 'ASC'); |
|
| 50 | - $chunks = array_chunk($objIds, 900, false); |
|
| 51 | - $mapping = []; |
|
| 52 | - foreach ($objIds as $objId) { |
|
| 53 | - $mapping[$objId] = []; |
|
| 54 | - } |
|
| 55 | - foreach ($chunks as $chunk) { |
|
| 56 | - $query->setParameter('objectids', $chunk, IQueryBuilder::PARAM_STR_ARRAY); |
|
| 57 | - $result = $query->executeQuery(); |
|
| 58 | - while ($row = $result->fetch()) { |
|
| 59 | - $objectId = $row['objectid']; |
|
| 60 | - $mapping[$objectId][] = $row['systemtagid']; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - $result->closeCursor(); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - return $mapping; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * {@inheritdoc} |
|
| 71 | - */ |
|
| 72 | - public function getObjectIdsForTags($tagIds, string $objectType, int $limit = 0, string $offset = ''): array { |
|
| 73 | - if (!\is_array($tagIds)) { |
|
| 74 | - $tagIds = [$tagIds]; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - $this->assertTagsExist($tagIds); |
|
| 78 | - |
|
| 79 | - $query = $this->connection->getQueryBuilder(); |
|
| 80 | - $query->selectDistinct('objectid') |
|
| 81 | - ->from(self::RELATION_TABLE) |
|
| 82 | - ->where($query->expr()->in('systemtagid', $query->createNamedParameter($tagIds, IQueryBuilder::PARAM_INT_ARRAY))) |
|
| 83 | - ->andWhere($query->expr()->eq('objecttype', $query->createNamedParameter($objectType))); |
|
| 84 | - |
|
| 85 | - if ($limit) { |
|
| 86 | - if (\count($tagIds) !== 1) { |
|
| 87 | - throw new \InvalidArgumentException('Limit is only allowed with a single tag'); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - $query->setMaxResults($limit) |
|
| 91 | - ->orderBy('objectid', 'ASC'); |
|
| 92 | - |
|
| 93 | - if ($offset !== '') { |
|
| 94 | - $query->andWhere($query->expr()->gt('objectid', $query->createNamedParameter($offset))); |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - $objectIds = []; |
|
| 99 | - |
|
| 100 | - $result = $query->executeQuery(); |
|
| 101 | - while ($row = $result->fetch()) { |
|
| 102 | - $objectIds[] = $row['objectid']; |
|
| 103 | - } |
|
| 104 | - $result->closeCursor(); |
|
| 105 | - |
|
| 106 | - return $objectIds; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * {@inheritdoc} |
|
| 111 | - */ |
|
| 112 | - public function assignTags(string $objId, string $objectType, $tagIds): void { |
|
| 113 | - if (!\is_array($tagIds)) { |
|
| 114 | - $tagIds = [$tagIds]; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $this->assertTagsExist($tagIds); |
|
| 118 | - $this->connection->beginTransaction(); |
|
| 119 | - |
|
| 120 | - $query = $this->connection->getQueryBuilder(); |
|
| 121 | - $query->select('systemtagid') |
|
| 122 | - ->from(self::RELATION_TABLE) |
|
| 123 | - ->where($query->expr()->in('systemtagid', $query->createNamedParameter($tagIds, IQueryBuilder::PARAM_INT_ARRAY))) |
|
| 124 | - ->andWhere($query->expr()->eq('objecttype', $query->createNamedParameter($objectType))) |
|
| 125 | - ->andWhere($query->expr()->eq('objectid', $query->createNamedParameter($objId))); |
|
| 126 | - $result = $query->executeQuery(); |
|
| 127 | - $rows = $result->fetchAll(); |
|
| 128 | - $existingTags = []; |
|
| 129 | - foreach ($rows as $row) { |
|
| 130 | - $existingTags[] = $row['systemtagid']; |
|
| 131 | - } |
|
| 132 | - //filter only tags that do not exist in db |
|
| 133 | - $tagIds = array_diff($tagIds, $existingTags); |
|
| 134 | - if (empty($tagIds)) { |
|
| 135 | - // no tags to insert so return here |
|
| 136 | - $this->connection->commit(); |
|
| 137 | - return; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - $query = $this->connection->getQueryBuilder(); |
|
| 141 | - $query->insert(self::RELATION_TABLE) |
|
| 142 | - ->values([ |
|
| 143 | - 'objectid' => $query->createNamedParameter($objId), |
|
| 144 | - 'objecttype' => $query->createNamedParameter($objectType), |
|
| 145 | - 'systemtagid' => $query->createParameter('tagid'), |
|
| 146 | - ]); |
|
| 147 | - |
|
| 148 | - $tagsAssigned = []; |
|
| 149 | - foreach ($tagIds as $tagId) { |
|
| 150 | - try { |
|
| 151 | - $query->setParameter('tagid', $tagId); |
|
| 152 | - $query->execute(); |
|
| 153 | - $tagsAssigned[] = $tagId; |
|
| 154 | - } catch (UniqueConstraintViolationException $e) { |
|
| 155 | - // ignore existing relations |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - $this->updateEtagForTags($tagIds); |
|
| 160 | - |
|
| 161 | - $this->connection->commit(); |
|
| 162 | - if (empty($tagsAssigned)) { |
|
| 163 | - return; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - $this->dispatcher->dispatch(MapperEvent::EVENT_ASSIGN, new MapperEvent( |
|
| 167 | - MapperEvent::EVENT_ASSIGN, |
|
| 168 | - $objectType, |
|
| 169 | - $objId, |
|
| 170 | - $tagsAssigned |
|
| 171 | - )); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * {@inheritdoc} |
|
| 176 | - */ |
|
| 177 | - public function unassignTags(string $objId, string $objectType, $tagIds): void { |
|
| 178 | - if (!\is_array($tagIds)) { |
|
| 179 | - $tagIds = [$tagIds]; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - $this->assertTagsExist($tagIds); |
|
| 183 | - |
|
| 184 | - $query = $this->connection->getQueryBuilder(); |
|
| 185 | - $query->delete(self::RELATION_TABLE) |
|
| 186 | - ->where($query->expr()->eq('objectid', $query->createParameter('objectid'))) |
|
| 187 | - ->andWhere($query->expr()->eq('objecttype', $query->createParameter('objecttype'))) |
|
| 188 | - ->andWhere($query->expr()->in('systemtagid', $query->createParameter('tagids'))) |
|
| 189 | - ->setParameter('objectid', $objId) |
|
| 190 | - ->setParameter('objecttype', $objectType) |
|
| 191 | - ->setParameter('tagids', $tagIds, IQueryBuilder::PARAM_INT_ARRAY) |
|
| 192 | - ->executeStatement(); |
|
| 193 | - |
|
| 194 | - $this->updateEtagForTags($tagIds); |
|
| 195 | - |
|
| 196 | - $this->dispatcher->dispatch(MapperEvent::EVENT_UNASSIGN, new MapperEvent( |
|
| 197 | - MapperEvent::EVENT_UNASSIGN, |
|
| 198 | - $objectType, |
|
| 199 | - $objId, |
|
| 200 | - $tagIds |
|
| 201 | - )); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Update the etag for the given tags. |
|
| 206 | - * |
|
| 207 | - * @param string[] $tagIds |
|
| 208 | - */ |
|
| 209 | - private function updateEtagForTags(array $tagIds): void { |
|
| 210 | - // Update etag after assigning tags |
|
| 211 | - $md5 = md5(json_encode(time())); |
|
| 212 | - $query = $this->connection->getQueryBuilder(); |
|
| 213 | - $query->update('systemtag') |
|
| 214 | - ->set('etag', $query->createNamedParameter($md5)) |
|
| 215 | - ->where($query->expr()->in('id', $query->createNamedParameter($tagIds, IQueryBuilder::PARAM_INT_ARRAY))); |
|
| 216 | - $query->execute(); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * {@inheritdoc} |
|
| 221 | - */ |
|
| 222 | - public function haveTag($objIds, string $objectType, string $tagId, bool $all = true): bool { |
|
| 223 | - $this->assertTagsExist([$tagId]); |
|
| 224 | - |
|
| 225 | - if (!\is_array($objIds)) { |
|
| 226 | - $objIds = [$objIds]; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - $query = $this->connection->getQueryBuilder(); |
|
| 230 | - |
|
| 231 | - if (!$all) { |
|
| 232 | - // If we only need one entry, we make the query lighter, by not |
|
| 233 | - // counting the elements |
|
| 234 | - $query->select('*') |
|
| 235 | - ->setMaxResults(1); |
|
| 236 | - } else { |
|
| 237 | - $query->select($query->func()->count($query->expr()->literal(1))); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - $query->from(self::RELATION_TABLE) |
|
| 241 | - ->where($query->expr()->in('objectid', $query->createParameter('objectids'))) |
|
| 242 | - ->andWhere($query->expr()->eq('objecttype', $query->createParameter('objecttype'))) |
|
| 243 | - ->andWhere($query->expr()->eq('systemtagid', $query->createParameter('tagid'))) |
|
| 244 | - ->setParameter('objectids', $objIds, IQueryBuilder::PARAM_STR_ARRAY) |
|
| 245 | - ->setParameter('tagid', $tagId) |
|
| 246 | - ->setParameter('objecttype', $objectType); |
|
| 247 | - |
|
| 248 | - $result = $query->executeQuery(); |
|
| 249 | - $row = $result->fetch(\PDO::FETCH_NUM); |
|
| 250 | - $result->closeCursor(); |
|
| 251 | - |
|
| 252 | - if ($all) { |
|
| 253 | - return ((int)$row[0] === \count($objIds)); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - return (bool)$row; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * Asserts that all the given tag ids exist. |
|
| 261 | - * |
|
| 262 | - * @param string[] $tagIds tag ids to check |
|
| 263 | - * |
|
| 264 | - * @throws \OCP\SystemTag\TagNotFoundException if at least one tag did not exist |
|
| 265 | - */ |
|
| 266 | - private function assertTagsExist(array $tagIds): void { |
|
| 267 | - $tags = $this->tagManager->getTagsByIds($tagIds); |
|
| 268 | - if (\count($tags) !== \count($tagIds)) { |
|
| 269 | - // at least one tag missing, bail out |
|
| 270 | - $foundTagIds = array_map( |
|
| 271 | - function (ISystemTag $tag) { |
|
| 272 | - return $tag->getId(); |
|
| 273 | - }, |
|
| 274 | - $tags |
|
| 275 | - ); |
|
| 276 | - $missingTagIds = array_diff($tagIds, $foundTagIds); |
|
| 277 | - throw new TagNotFoundException( |
|
| 278 | - 'Tags not found', 0, null, $missingTagIds |
|
| 279 | - ); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * {@inheritdoc} |
|
| 285 | - */ |
|
| 286 | - public function setObjectIdsForTag(string $tagId, string $objectType, array $objectIds): void { |
|
| 287 | - $currentObjectIds = $this->getObjectIdsForTags($tagId, $objectType); |
|
| 288 | - $removedObjectIds = array_diff($currentObjectIds, $objectIds); |
|
| 289 | - $addedObjectIds = array_diff($objectIds, $currentObjectIds); |
|
| 290 | - |
|
| 291 | - $this->connection->beginTransaction(); |
|
| 292 | - $query = $this->connection->getQueryBuilder(); |
|
| 293 | - $query->delete(self::RELATION_TABLE) |
|
| 294 | - ->where($query->expr()->eq('systemtagid', $query->createNamedParameter($tagId, IQueryBuilder::PARAM_INT))) |
|
| 295 | - ->andWhere($query->expr()->eq('objecttype', $query->createNamedParameter($objectType))) |
|
| 296 | - ->executeStatement(); |
|
| 297 | - $this->connection->commit(); |
|
| 298 | - |
|
| 299 | - foreach ($removedObjectIds as $objectId) { |
|
| 300 | - $this->dispatcher->dispatch(MapperEvent::EVENT_UNASSIGN, new MapperEvent( |
|
| 301 | - MapperEvent::EVENT_UNASSIGN, |
|
| 302 | - $objectType, |
|
| 303 | - (string)$objectId, |
|
| 304 | - [(int)$tagId] |
|
| 305 | - )); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - if (empty($objectIds)) { |
|
| 309 | - return; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - $this->connection->beginTransaction(); |
|
| 313 | - $query = $this->connection->getQueryBuilder(); |
|
| 314 | - $query->insert(self::RELATION_TABLE) |
|
| 315 | - ->values([ |
|
| 316 | - 'systemtagid' => $query->createNamedParameter($tagId, IQueryBuilder::PARAM_INT), |
|
| 317 | - 'objecttype' => $query->createNamedParameter($objectType), |
|
| 318 | - 'objectid' => $query->createParameter('objectid'), |
|
| 319 | - ]); |
|
| 320 | - |
|
| 321 | - foreach (array_unique($objectIds) as $objectId) { |
|
| 322 | - $query->setParameter('objectid', (string)$objectId); |
|
| 323 | - $query->executeStatement(); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - $this->updateEtagForTags([$tagId]); |
|
| 327 | - $this->connection->commit(); |
|
| 328 | - |
|
| 329 | - // Dispatch assign events for new object ids |
|
| 330 | - foreach ($addedObjectIds as $objectId) { |
|
| 331 | - $this->dispatcher->dispatch(MapperEvent::EVENT_ASSIGN, new MapperEvent( |
|
| 332 | - MapperEvent::EVENT_ASSIGN, |
|
| 333 | - $objectType, |
|
| 334 | - (string)$objectId, |
|
| 335 | - [(int)$tagId] |
|
| 336 | - )); |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - // Dispatch unassign events for removed object ids |
|
| 340 | - foreach ($removedObjectIds as $objectId) { |
|
| 341 | - $this->dispatcher->dispatch(MapperEvent::EVENT_UNASSIGN, new MapperEvent( |
|
| 342 | - MapperEvent::EVENT_UNASSIGN, |
|
| 343 | - $objectType, |
|
| 344 | - (string)$objectId, |
|
| 345 | - [(int)$tagId] |
|
| 346 | - )); |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * {@inheritdoc} |
|
| 352 | - */ |
|
| 353 | - public function getAvailableObjectTypes(): array { |
|
| 354 | - $query = $this->connection->getQueryBuilder(); |
|
| 355 | - $query->selectDistinct('objecttype') |
|
| 356 | - ->from(self::RELATION_TABLE); |
|
| 357 | - |
|
| 358 | - $result = $query->executeQuery(); |
|
| 359 | - $objectTypes = []; |
|
| 360 | - while ($row = $result->fetch()) { |
|
| 361 | - $objectTypes[] = $row['objecttype']; |
|
| 362 | - } |
|
| 363 | - $result->closeCursor(); |
|
| 364 | - |
|
| 365 | - return $objectTypes; |
|
| 366 | - } |
|
| 23 | + public const RELATION_TABLE = 'systemtag_object_mapping'; |
|
| 24 | + |
|
| 25 | + public function __construct( |
|
| 26 | + protected IDBConnection $connection, |
|
| 27 | + protected ISystemTagManager $tagManager, |
|
| 28 | + protected IEventDispatcher $dispatcher, |
|
| 29 | + ) { |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * {@inheritdoc} |
|
| 34 | + */ |
|
| 35 | + public function getTagIdsForObjects($objIds, string $objectType): array { |
|
| 36 | + if (!\is_array($objIds)) { |
|
| 37 | + $objIds = [$objIds]; |
|
| 38 | + } elseif (empty($objIds)) { |
|
| 39 | + return []; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + $query = $this->connection->getQueryBuilder(); |
|
| 43 | + $query->select(['systemtagid', 'objectid']) |
|
| 44 | + ->from(self::RELATION_TABLE) |
|
| 45 | + ->where($query->expr()->in('objectid', $query->createParameter('objectids'))) |
|
| 46 | + ->andWhere($query->expr()->eq('objecttype', $query->createParameter('objecttype'))) |
|
| 47 | + ->setParameter('objecttype', $objectType) |
|
| 48 | + ->addOrderBy('objectid', 'ASC') |
|
| 49 | + ->addOrderBy('systemtagid', 'ASC'); |
|
| 50 | + $chunks = array_chunk($objIds, 900, false); |
|
| 51 | + $mapping = []; |
|
| 52 | + foreach ($objIds as $objId) { |
|
| 53 | + $mapping[$objId] = []; |
|
| 54 | + } |
|
| 55 | + foreach ($chunks as $chunk) { |
|
| 56 | + $query->setParameter('objectids', $chunk, IQueryBuilder::PARAM_STR_ARRAY); |
|
| 57 | + $result = $query->executeQuery(); |
|
| 58 | + while ($row = $result->fetch()) { |
|
| 59 | + $objectId = $row['objectid']; |
|
| 60 | + $mapping[$objectId][] = $row['systemtagid']; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + $result->closeCursor(); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + return $mapping; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * {@inheritdoc} |
|
| 71 | + */ |
|
| 72 | + public function getObjectIdsForTags($tagIds, string $objectType, int $limit = 0, string $offset = ''): array { |
|
| 73 | + if (!\is_array($tagIds)) { |
|
| 74 | + $tagIds = [$tagIds]; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + $this->assertTagsExist($tagIds); |
|
| 78 | + |
|
| 79 | + $query = $this->connection->getQueryBuilder(); |
|
| 80 | + $query->selectDistinct('objectid') |
|
| 81 | + ->from(self::RELATION_TABLE) |
|
| 82 | + ->where($query->expr()->in('systemtagid', $query->createNamedParameter($tagIds, IQueryBuilder::PARAM_INT_ARRAY))) |
|
| 83 | + ->andWhere($query->expr()->eq('objecttype', $query->createNamedParameter($objectType))); |
|
| 84 | + |
|
| 85 | + if ($limit) { |
|
| 86 | + if (\count($tagIds) !== 1) { |
|
| 87 | + throw new \InvalidArgumentException('Limit is only allowed with a single tag'); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + $query->setMaxResults($limit) |
|
| 91 | + ->orderBy('objectid', 'ASC'); |
|
| 92 | + |
|
| 93 | + if ($offset !== '') { |
|
| 94 | + $query->andWhere($query->expr()->gt('objectid', $query->createNamedParameter($offset))); |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + $objectIds = []; |
|
| 99 | + |
|
| 100 | + $result = $query->executeQuery(); |
|
| 101 | + while ($row = $result->fetch()) { |
|
| 102 | + $objectIds[] = $row['objectid']; |
|
| 103 | + } |
|
| 104 | + $result->closeCursor(); |
|
| 105 | + |
|
| 106 | + return $objectIds; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * {@inheritdoc} |
|
| 111 | + */ |
|
| 112 | + public function assignTags(string $objId, string $objectType, $tagIds): void { |
|
| 113 | + if (!\is_array($tagIds)) { |
|
| 114 | + $tagIds = [$tagIds]; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $this->assertTagsExist($tagIds); |
|
| 118 | + $this->connection->beginTransaction(); |
|
| 119 | + |
|
| 120 | + $query = $this->connection->getQueryBuilder(); |
|
| 121 | + $query->select('systemtagid') |
|
| 122 | + ->from(self::RELATION_TABLE) |
|
| 123 | + ->where($query->expr()->in('systemtagid', $query->createNamedParameter($tagIds, IQueryBuilder::PARAM_INT_ARRAY))) |
|
| 124 | + ->andWhere($query->expr()->eq('objecttype', $query->createNamedParameter($objectType))) |
|
| 125 | + ->andWhere($query->expr()->eq('objectid', $query->createNamedParameter($objId))); |
|
| 126 | + $result = $query->executeQuery(); |
|
| 127 | + $rows = $result->fetchAll(); |
|
| 128 | + $existingTags = []; |
|
| 129 | + foreach ($rows as $row) { |
|
| 130 | + $existingTags[] = $row['systemtagid']; |
|
| 131 | + } |
|
| 132 | + //filter only tags that do not exist in db |
|
| 133 | + $tagIds = array_diff($tagIds, $existingTags); |
|
| 134 | + if (empty($tagIds)) { |
|
| 135 | + // no tags to insert so return here |
|
| 136 | + $this->connection->commit(); |
|
| 137 | + return; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + $query = $this->connection->getQueryBuilder(); |
|
| 141 | + $query->insert(self::RELATION_TABLE) |
|
| 142 | + ->values([ |
|
| 143 | + 'objectid' => $query->createNamedParameter($objId), |
|
| 144 | + 'objecttype' => $query->createNamedParameter($objectType), |
|
| 145 | + 'systemtagid' => $query->createParameter('tagid'), |
|
| 146 | + ]); |
|
| 147 | + |
|
| 148 | + $tagsAssigned = []; |
|
| 149 | + foreach ($tagIds as $tagId) { |
|
| 150 | + try { |
|
| 151 | + $query->setParameter('tagid', $tagId); |
|
| 152 | + $query->execute(); |
|
| 153 | + $tagsAssigned[] = $tagId; |
|
| 154 | + } catch (UniqueConstraintViolationException $e) { |
|
| 155 | + // ignore existing relations |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + $this->updateEtagForTags($tagIds); |
|
| 160 | + |
|
| 161 | + $this->connection->commit(); |
|
| 162 | + if (empty($tagsAssigned)) { |
|
| 163 | + return; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + $this->dispatcher->dispatch(MapperEvent::EVENT_ASSIGN, new MapperEvent( |
|
| 167 | + MapperEvent::EVENT_ASSIGN, |
|
| 168 | + $objectType, |
|
| 169 | + $objId, |
|
| 170 | + $tagsAssigned |
|
| 171 | + )); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * {@inheritdoc} |
|
| 176 | + */ |
|
| 177 | + public function unassignTags(string $objId, string $objectType, $tagIds): void { |
|
| 178 | + if (!\is_array($tagIds)) { |
|
| 179 | + $tagIds = [$tagIds]; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + $this->assertTagsExist($tagIds); |
|
| 183 | + |
|
| 184 | + $query = $this->connection->getQueryBuilder(); |
|
| 185 | + $query->delete(self::RELATION_TABLE) |
|
| 186 | + ->where($query->expr()->eq('objectid', $query->createParameter('objectid'))) |
|
| 187 | + ->andWhere($query->expr()->eq('objecttype', $query->createParameter('objecttype'))) |
|
| 188 | + ->andWhere($query->expr()->in('systemtagid', $query->createParameter('tagids'))) |
|
| 189 | + ->setParameter('objectid', $objId) |
|
| 190 | + ->setParameter('objecttype', $objectType) |
|
| 191 | + ->setParameter('tagids', $tagIds, IQueryBuilder::PARAM_INT_ARRAY) |
|
| 192 | + ->executeStatement(); |
|
| 193 | + |
|
| 194 | + $this->updateEtagForTags($tagIds); |
|
| 195 | + |
|
| 196 | + $this->dispatcher->dispatch(MapperEvent::EVENT_UNASSIGN, new MapperEvent( |
|
| 197 | + MapperEvent::EVENT_UNASSIGN, |
|
| 198 | + $objectType, |
|
| 199 | + $objId, |
|
| 200 | + $tagIds |
|
| 201 | + )); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Update the etag for the given tags. |
|
| 206 | + * |
|
| 207 | + * @param string[] $tagIds |
|
| 208 | + */ |
|
| 209 | + private function updateEtagForTags(array $tagIds): void { |
|
| 210 | + // Update etag after assigning tags |
|
| 211 | + $md5 = md5(json_encode(time())); |
|
| 212 | + $query = $this->connection->getQueryBuilder(); |
|
| 213 | + $query->update('systemtag') |
|
| 214 | + ->set('etag', $query->createNamedParameter($md5)) |
|
| 215 | + ->where($query->expr()->in('id', $query->createNamedParameter($tagIds, IQueryBuilder::PARAM_INT_ARRAY))); |
|
| 216 | + $query->execute(); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * {@inheritdoc} |
|
| 221 | + */ |
|
| 222 | + public function haveTag($objIds, string $objectType, string $tagId, bool $all = true): bool { |
|
| 223 | + $this->assertTagsExist([$tagId]); |
|
| 224 | + |
|
| 225 | + if (!\is_array($objIds)) { |
|
| 226 | + $objIds = [$objIds]; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + $query = $this->connection->getQueryBuilder(); |
|
| 230 | + |
|
| 231 | + if (!$all) { |
|
| 232 | + // If we only need one entry, we make the query lighter, by not |
|
| 233 | + // counting the elements |
|
| 234 | + $query->select('*') |
|
| 235 | + ->setMaxResults(1); |
|
| 236 | + } else { |
|
| 237 | + $query->select($query->func()->count($query->expr()->literal(1))); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + $query->from(self::RELATION_TABLE) |
|
| 241 | + ->where($query->expr()->in('objectid', $query->createParameter('objectids'))) |
|
| 242 | + ->andWhere($query->expr()->eq('objecttype', $query->createParameter('objecttype'))) |
|
| 243 | + ->andWhere($query->expr()->eq('systemtagid', $query->createParameter('tagid'))) |
|
| 244 | + ->setParameter('objectids', $objIds, IQueryBuilder::PARAM_STR_ARRAY) |
|
| 245 | + ->setParameter('tagid', $tagId) |
|
| 246 | + ->setParameter('objecttype', $objectType); |
|
| 247 | + |
|
| 248 | + $result = $query->executeQuery(); |
|
| 249 | + $row = $result->fetch(\PDO::FETCH_NUM); |
|
| 250 | + $result->closeCursor(); |
|
| 251 | + |
|
| 252 | + if ($all) { |
|
| 253 | + return ((int)$row[0] === \count($objIds)); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + return (bool)$row; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * Asserts that all the given tag ids exist. |
|
| 261 | + * |
|
| 262 | + * @param string[] $tagIds tag ids to check |
|
| 263 | + * |
|
| 264 | + * @throws \OCP\SystemTag\TagNotFoundException if at least one tag did not exist |
|
| 265 | + */ |
|
| 266 | + private function assertTagsExist(array $tagIds): void { |
|
| 267 | + $tags = $this->tagManager->getTagsByIds($tagIds); |
|
| 268 | + if (\count($tags) !== \count($tagIds)) { |
|
| 269 | + // at least one tag missing, bail out |
|
| 270 | + $foundTagIds = array_map( |
|
| 271 | + function (ISystemTag $tag) { |
|
| 272 | + return $tag->getId(); |
|
| 273 | + }, |
|
| 274 | + $tags |
|
| 275 | + ); |
|
| 276 | + $missingTagIds = array_diff($tagIds, $foundTagIds); |
|
| 277 | + throw new TagNotFoundException( |
|
| 278 | + 'Tags not found', 0, null, $missingTagIds |
|
| 279 | + ); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * {@inheritdoc} |
|
| 285 | + */ |
|
| 286 | + public function setObjectIdsForTag(string $tagId, string $objectType, array $objectIds): void { |
|
| 287 | + $currentObjectIds = $this->getObjectIdsForTags($tagId, $objectType); |
|
| 288 | + $removedObjectIds = array_diff($currentObjectIds, $objectIds); |
|
| 289 | + $addedObjectIds = array_diff($objectIds, $currentObjectIds); |
|
| 290 | + |
|
| 291 | + $this->connection->beginTransaction(); |
|
| 292 | + $query = $this->connection->getQueryBuilder(); |
|
| 293 | + $query->delete(self::RELATION_TABLE) |
|
| 294 | + ->where($query->expr()->eq('systemtagid', $query->createNamedParameter($tagId, IQueryBuilder::PARAM_INT))) |
|
| 295 | + ->andWhere($query->expr()->eq('objecttype', $query->createNamedParameter($objectType))) |
|
| 296 | + ->executeStatement(); |
|
| 297 | + $this->connection->commit(); |
|
| 298 | + |
|
| 299 | + foreach ($removedObjectIds as $objectId) { |
|
| 300 | + $this->dispatcher->dispatch(MapperEvent::EVENT_UNASSIGN, new MapperEvent( |
|
| 301 | + MapperEvent::EVENT_UNASSIGN, |
|
| 302 | + $objectType, |
|
| 303 | + (string)$objectId, |
|
| 304 | + [(int)$tagId] |
|
| 305 | + )); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + if (empty($objectIds)) { |
|
| 309 | + return; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + $this->connection->beginTransaction(); |
|
| 313 | + $query = $this->connection->getQueryBuilder(); |
|
| 314 | + $query->insert(self::RELATION_TABLE) |
|
| 315 | + ->values([ |
|
| 316 | + 'systemtagid' => $query->createNamedParameter($tagId, IQueryBuilder::PARAM_INT), |
|
| 317 | + 'objecttype' => $query->createNamedParameter($objectType), |
|
| 318 | + 'objectid' => $query->createParameter('objectid'), |
|
| 319 | + ]); |
|
| 320 | + |
|
| 321 | + foreach (array_unique($objectIds) as $objectId) { |
|
| 322 | + $query->setParameter('objectid', (string)$objectId); |
|
| 323 | + $query->executeStatement(); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + $this->updateEtagForTags([$tagId]); |
|
| 327 | + $this->connection->commit(); |
|
| 328 | + |
|
| 329 | + // Dispatch assign events for new object ids |
|
| 330 | + foreach ($addedObjectIds as $objectId) { |
|
| 331 | + $this->dispatcher->dispatch(MapperEvent::EVENT_ASSIGN, new MapperEvent( |
|
| 332 | + MapperEvent::EVENT_ASSIGN, |
|
| 333 | + $objectType, |
|
| 334 | + (string)$objectId, |
|
| 335 | + [(int)$tagId] |
|
| 336 | + )); |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + // Dispatch unassign events for removed object ids |
|
| 340 | + foreach ($removedObjectIds as $objectId) { |
|
| 341 | + $this->dispatcher->dispatch(MapperEvent::EVENT_UNASSIGN, new MapperEvent( |
|
| 342 | + MapperEvent::EVENT_UNASSIGN, |
|
| 343 | + $objectType, |
|
| 344 | + (string)$objectId, |
|
| 345 | + [(int)$tagId] |
|
| 346 | + )); |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * {@inheritdoc} |
|
| 352 | + */ |
|
| 353 | + public function getAvailableObjectTypes(): array { |
|
| 354 | + $query = $this->connection->getQueryBuilder(); |
|
| 355 | + $query->selectDistinct('objecttype') |
|
| 356 | + ->from(self::RELATION_TABLE); |
|
| 357 | + |
|
| 358 | + $result = $query->executeQuery(); |
|
| 359 | + $objectTypes = []; |
|
| 360 | + while ($row = $result->fetch()) { |
|
| 361 | + $objectTypes[] = $row['objecttype']; |
|
| 362 | + } |
|
| 363 | + $result->closeCursor(); |
|
| 364 | + |
|
| 365 | + return $objectTypes; |
|
| 366 | + } |
|
| 367 | 367 | } |
@@ -250,10 +250,10 @@ discard block |
||
| 250 | 250 | $result->closeCursor(); |
| 251 | 251 | |
| 252 | 252 | if ($all) { |
| 253 | - return ((int)$row[0] === \count($objIds)); |
|
| 253 | + return ((int) $row[0] === \count($objIds)); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - return (bool)$row; |
|
| 256 | + return (bool) $row; |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | if (\count($tags) !== \count($tagIds)) { |
| 269 | 269 | // at least one tag missing, bail out |
| 270 | 270 | $foundTagIds = array_map( |
| 271 | - function (ISystemTag $tag) { |
|
| 271 | + function(ISystemTag $tag) { |
|
| 272 | 272 | return $tag->getId(); |
| 273 | 273 | }, |
| 274 | 274 | $tags |
@@ -300,8 +300,8 @@ discard block |
||
| 300 | 300 | $this->dispatcher->dispatch(MapperEvent::EVENT_UNASSIGN, new MapperEvent( |
| 301 | 301 | MapperEvent::EVENT_UNASSIGN, |
| 302 | 302 | $objectType, |
| 303 | - (string)$objectId, |
|
| 304 | - [(int)$tagId] |
|
| 303 | + (string) $objectId, |
|
| 304 | + [(int) $tagId] |
|
| 305 | 305 | )); |
| 306 | 306 | } |
| 307 | 307 | |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | ]); |
| 320 | 320 | |
| 321 | 321 | foreach (array_unique($objectIds) as $objectId) { |
| 322 | - $query->setParameter('objectid', (string)$objectId); |
|
| 322 | + $query->setParameter('objectid', (string) $objectId); |
|
| 323 | 323 | $query->executeStatement(); |
| 324 | 324 | } |
| 325 | 325 | |
@@ -331,8 +331,8 @@ discard block |
||
| 331 | 331 | $this->dispatcher->dispatch(MapperEvent::EVENT_ASSIGN, new MapperEvent( |
| 332 | 332 | MapperEvent::EVENT_ASSIGN, |
| 333 | 333 | $objectType, |
| 334 | - (string)$objectId, |
|
| 335 | - [(int)$tagId] |
|
| 334 | + (string) $objectId, |
|
| 335 | + [(int) $tagId] |
|
| 336 | 336 | )); |
| 337 | 337 | } |
| 338 | 338 | |
@@ -341,8 +341,8 @@ discard block |
||
| 341 | 341 | $this->dispatcher->dispatch(MapperEvent::EVENT_UNASSIGN, new MapperEvent( |
| 342 | 342 | MapperEvent::EVENT_UNASSIGN, |
| 343 | 343 | $objectType, |
| 344 | - (string)$objectId, |
|
| 345 | - [(int)$tagId] |
|
| 344 | + (string) $objectId, |
|
| 345 | + [(int) $tagId] |
|
| 346 | 346 | )); |
| 347 | 347 | } |
| 348 | 348 | } |
@@ -15,308 +15,308 @@ |
||
| 15 | 15 | use OCP\L10N\IFactory; |
| 16 | 16 | |
| 17 | 17 | class Provider implements IProvider { |
| 18 | - public const CREATE_TAG = 'create_tag'; |
|
| 19 | - public const UPDATE_TAG = 'update_tag'; |
|
| 20 | - public const DELETE_TAG = 'delete_tag'; |
|
| 18 | + public const CREATE_TAG = 'create_tag'; |
|
| 19 | + public const UPDATE_TAG = 'update_tag'; |
|
| 20 | + public const DELETE_TAG = 'delete_tag'; |
|
| 21 | 21 | |
| 22 | - public const ASSIGN_TAG = 'assign_tag'; |
|
| 23 | - public const UNASSIGN_TAG = 'unassign_tag'; |
|
| 22 | + public const ASSIGN_TAG = 'assign_tag'; |
|
| 23 | + public const UNASSIGN_TAG = 'unassign_tag'; |
|
| 24 | 24 | |
| 25 | - /** @var IL10N */ |
|
| 26 | - protected $l; |
|
| 25 | + /** @var IL10N */ |
|
| 26 | + protected $l; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @param IFactory $languageFactory |
|
| 30 | - * @param IURLGenerator $url |
|
| 31 | - * @param IManager $activityManager |
|
| 32 | - * @param IUserManager $userManager |
|
| 33 | - */ |
|
| 34 | - public function __construct( |
|
| 35 | - protected IFactory $languageFactory, |
|
| 36 | - protected IURLGenerator $url, |
|
| 37 | - protected IManager $activityManager, |
|
| 38 | - protected IUserManager $userManager, |
|
| 39 | - ) { |
|
| 40 | - } |
|
| 28 | + /** |
|
| 29 | + * @param IFactory $languageFactory |
|
| 30 | + * @param IURLGenerator $url |
|
| 31 | + * @param IManager $activityManager |
|
| 32 | + * @param IUserManager $userManager |
|
| 33 | + */ |
|
| 34 | + public function __construct( |
|
| 35 | + protected IFactory $languageFactory, |
|
| 36 | + protected IURLGenerator $url, |
|
| 37 | + protected IManager $activityManager, |
|
| 38 | + protected IUserManager $userManager, |
|
| 39 | + ) { |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @param string $language |
|
| 44 | - * @param IEvent $event |
|
| 45 | - * @param IEvent|null $previousEvent |
|
| 46 | - * @return IEvent |
|
| 47 | - * @throws UnknownActivityException |
|
| 48 | - * @since 11.0.0 |
|
| 49 | - */ |
|
| 50 | - public function parse($language, IEvent $event, ?IEvent $previousEvent = null) { |
|
| 51 | - if ($event->getApp() !== 'systemtags') { |
|
| 52 | - throw new UnknownActivityException(); |
|
| 53 | - } |
|
| 42 | + /** |
|
| 43 | + * @param string $language |
|
| 44 | + * @param IEvent $event |
|
| 45 | + * @param IEvent|null $previousEvent |
|
| 46 | + * @return IEvent |
|
| 47 | + * @throws UnknownActivityException |
|
| 48 | + * @since 11.0.0 |
|
| 49 | + */ |
|
| 50 | + public function parse($language, IEvent $event, ?IEvent $previousEvent = null) { |
|
| 51 | + if ($event->getApp() !== 'systemtags') { |
|
| 52 | + throw new UnknownActivityException(); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - $this->l = $this->languageFactory->get('systemtags', $language); |
|
| 55 | + $this->l = $this->languageFactory->get('systemtags', $language); |
|
| 56 | 56 | |
| 57 | - if ($this->activityManager->isFormattingFilteredObject()) { |
|
| 58 | - try { |
|
| 59 | - return $this->parseShortVersion($event); |
|
| 60 | - } catch (UnknownActivityException) { |
|
| 61 | - // Ignore and simply use the long version... |
|
| 62 | - } |
|
| 63 | - } |
|
| 57 | + if ($this->activityManager->isFormattingFilteredObject()) { |
|
| 58 | + try { |
|
| 59 | + return $this->parseShortVersion($event); |
|
| 60 | + } catch (UnknownActivityException) { |
|
| 61 | + // Ignore and simply use the long version... |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - return $this->parseLongVersion($event); |
|
| 66 | - } |
|
| 65 | + return $this->parseLongVersion($event); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @param IEvent $event |
|
| 70 | - * @return IEvent |
|
| 71 | - * @throws UnknownActivityException |
|
| 72 | - * @since 11.0.0 |
|
| 73 | - */ |
|
| 74 | - public function parseShortVersion(IEvent $event): IEvent { |
|
| 75 | - $parsedParameters = $this->getParameters($event); |
|
| 68 | + /** |
|
| 69 | + * @param IEvent $event |
|
| 70 | + * @return IEvent |
|
| 71 | + * @throws UnknownActivityException |
|
| 72 | + * @since 11.0.0 |
|
| 73 | + */ |
|
| 74 | + public function parseShortVersion(IEvent $event): IEvent { |
|
| 75 | + $parsedParameters = $this->getParameters($event); |
|
| 76 | 76 | |
| 77 | - if ($this->activityManager->getRequirePNG()) { |
|
| 78 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.png'))); |
|
| 79 | - } else { |
|
| 80 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.svg'))); |
|
| 81 | - } |
|
| 77 | + if ($this->activityManager->getRequirePNG()) { |
|
| 78 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.png'))); |
|
| 79 | + } else { |
|
| 80 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.svg'))); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - if ($event->getSubject() === self::ASSIGN_TAG) { |
|
| 84 | - if ($parsedParameters['actor']['id'] === '') { |
|
| 85 | - $event->setParsedSubject($this->l->t('System tag %1$s added by the system', [ |
|
| 86 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 87 | - ])) |
|
| 88 | - ->setRichSubject($this->l->t('Added system tag {systemtag}'), [ |
|
| 89 | - 'systemtag' => $parsedParameters['systemtag'], |
|
| 90 | - ]); |
|
| 91 | - } elseif ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 92 | - $event->setParsedSubject($this->l->t('Added system tag %1$s', [ |
|
| 93 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 94 | - ])) |
|
| 95 | - ->setRichSubject($this->l->t('Added system tag {systemtag}'), [ |
|
| 96 | - 'systemtag' => $parsedParameters['systemtag'], |
|
| 97 | - ]); |
|
| 98 | - } else { |
|
| 99 | - $event->setParsedSubject($this->l->t('%1$s added system tag %2$s', [ |
|
| 100 | - $parsedParameters['actor']['name'], |
|
| 101 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 102 | - ])) |
|
| 103 | - ->setRichSubject($this->l->t('{actor} added system tag {systemtag}'), [ |
|
| 104 | - 'actor' => $parsedParameters['actor'], |
|
| 105 | - 'systemtag' => $parsedParameters['systemtag'], |
|
| 106 | - ]); |
|
| 107 | - } |
|
| 108 | - } elseif ($event->getSubject() === self::UNASSIGN_TAG) { |
|
| 109 | - if ($parsedParameters['actor']['id'] === '') { |
|
| 110 | - $event->setParsedSubject($this->l->t('System tag %1$s removed by the system', [ |
|
| 111 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 112 | - ])) |
|
| 113 | - ->setRichSubject($this->l->t('Removed system tag {systemtag}'), [ |
|
| 114 | - 'systemtag' => $parsedParameters['systemtag'], |
|
| 115 | - ]); |
|
| 116 | - } elseif ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 117 | - $event->setParsedSubject($this->l->t('Removed system tag %1$s', [ |
|
| 118 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 119 | - ])) |
|
| 120 | - ->setRichSubject($this->l->t('Removed system tag {systemtag}'), [ |
|
| 121 | - 'systemtag' => $parsedParameters['systemtag'], |
|
| 122 | - ]); |
|
| 123 | - } else { |
|
| 124 | - $event->setParsedSubject($this->l->t('%1$s removed system tag %2$s', [ |
|
| 125 | - $parsedParameters['actor']['name'], |
|
| 126 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 127 | - ])) |
|
| 128 | - ->setRichSubject($this->l->t('{actor} removed system tag {systemtag}'), [ |
|
| 129 | - 'actor' => $parsedParameters['actor'], |
|
| 130 | - 'systemtag' => $parsedParameters['systemtag'], |
|
| 131 | - ]); |
|
| 132 | - } |
|
| 133 | - } else { |
|
| 134 | - throw new UnknownActivityException(); |
|
| 135 | - } |
|
| 83 | + if ($event->getSubject() === self::ASSIGN_TAG) { |
|
| 84 | + if ($parsedParameters['actor']['id'] === '') { |
|
| 85 | + $event->setParsedSubject($this->l->t('System tag %1$s added by the system', [ |
|
| 86 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 87 | + ])) |
|
| 88 | + ->setRichSubject($this->l->t('Added system tag {systemtag}'), [ |
|
| 89 | + 'systemtag' => $parsedParameters['systemtag'], |
|
| 90 | + ]); |
|
| 91 | + } elseif ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 92 | + $event->setParsedSubject($this->l->t('Added system tag %1$s', [ |
|
| 93 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 94 | + ])) |
|
| 95 | + ->setRichSubject($this->l->t('Added system tag {systemtag}'), [ |
|
| 96 | + 'systemtag' => $parsedParameters['systemtag'], |
|
| 97 | + ]); |
|
| 98 | + } else { |
|
| 99 | + $event->setParsedSubject($this->l->t('%1$s added system tag %2$s', [ |
|
| 100 | + $parsedParameters['actor']['name'], |
|
| 101 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 102 | + ])) |
|
| 103 | + ->setRichSubject($this->l->t('{actor} added system tag {systemtag}'), [ |
|
| 104 | + 'actor' => $parsedParameters['actor'], |
|
| 105 | + 'systemtag' => $parsedParameters['systemtag'], |
|
| 106 | + ]); |
|
| 107 | + } |
|
| 108 | + } elseif ($event->getSubject() === self::UNASSIGN_TAG) { |
|
| 109 | + if ($parsedParameters['actor']['id'] === '') { |
|
| 110 | + $event->setParsedSubject($this->l->t('System tag %1$s removed by the system', [ |
|
| 111 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 112 | + ])) |
|
| 113 | + ->setRichSubject($this->l->t('Removed system tag {systemtag}'), [ |
|
| 114 | + 'systemtag' => $parsedParameters['systemtag'], |
|
| 115 | + ]); |
|
| 116 | + } elseif ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 117 | + $event->setParsedSubject($this->l->t('Removed system tag %1$s', [ |
|
| 118 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 119 | + ])) |
|
| 120 | + ->setRichSubject($this->l->t('Removed system tag {systemtag}'), [ |
|
| 121 | + 'systemtag' => $parsedParameters['systemtag'], |
|
| 122 | + ]); |
|
| 123 | + } else { |
|
| 124 | + $event->setParsedSubject($this->l->t('%1$s removed system tag %2$s', [ |
|
| 125 | + $parsedParameters['actor']['name'], |
|
| 126 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 127 | + ])) |
|
| 128 | + ->setRichSubject($this->l->t('{actor} removed system tag {systemtag}'), [ |
|
| 129 | + 'actor' => $parsedParameters['actor'], |
|
| 130 | + 'systemtag' => $parsedParameters['systemtag'], |
|
| 131 | + ]); |
|
| 132 | + } |
|
| 133 | + } else { |
|
| 134 | + throw new UnknownActivityException(); |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - return $event; |
|
| 138 | - } |
|
| 137 | + return $event; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * @param IEvent $event |
|
| 142 | - * @return IEvent |
|
| 143 | - * @throws UnknownActivityException |
|
| 144 | - * @since 11.0.0 |
|
| 145 | - */ |
|
| 146 | - public function parseLongVersion(IEvent $event): IEvent { |
|
| 147 | - $parsedParameters = $this->getParameters($event); |
|
| 140 | + /** |
|
| 141 | + * @param IEvent $event |
|
| 142 | + * @return IEvent |
|
| 143 | + * @throws UnknownActivityException |
|
| 144 | + * @since 11.0.0 |
|
| 145 | + */ |
|
| 146 | + public function parseLongVersion(IEvent $event): IEvent { |
|
| 147 | + $parsedParameters = $this->getParameters($event); |
|
| 148 | 148 | |
| 149 | - if ($this->activityManager->getRequirePNG()) { |
|
| 150 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.png'))); |
|
| 151 | - } else { |
|
| 152 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.svg'))); |
|
| 153 | - } |
|
| 149 | + if ($this->activityManager->getRequirePNG()) { |
|
| 150 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.png'))); |
|
| 151 | + } else { |
|
| 152 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/tag.svg'))); |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - if ($event->getSubject() === self::CREATE_TAG) { |
|
| 156 | - if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 157 | - $event->setParsedSubject($this->l->t('You created system tag %1$s', [ |
|
| 158 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 159 | - ])) |
|
| 160 | - ->setRichSubject($this->l->t('You created system tag {systemtag}'), $parsedParameters); |
|
| 161 | - } else { |
|
| 162 | - $event->setParsedSubject($this->l->t('%1$s created system tag %2$s', [ |
|
| 163 | - $parsedParameters['actor']['name'], |
|
| 164 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 165 | - ])) |
|
| 166 | - ->setRichSubject($this->l->t('{actor} created system tag {systemtag}'), $parsedParameters); |
|
| 167 | - } |
|
| 168 | - } elseif ($event->getSubject() === self::DELETE_TAG) { |
|
| 169 | - if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 170 | - $event->setParsedSubject($this->l->t('You deleted system tag %1$s', [ |
|
| 171 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 172 | - ])) |
|
| 173 | - ->setRichSubject($this->l->t('You deleted system tag {systemtag}'), $parsedParameters); |
|
| 174 | - } else { |
|
| 175 | - $event->setParsedSubject($this->l->t('%1$s deleted system tag %2$s', [ |
|
| 176 | - $parsedParameters['actor']['name'], |
|
| 177 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 178 | - ])) |
|
| 179 | - ->setRichSubject($this->l->t('{actor} deleted system tag {systemtag}'), $parsedParameters); |
|
| 180 | - } |
|
| 181 | - } elseif ($event->getSubject() === self::UPDATE_TAG) { |
|
| 182 | - if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 183 | - $event->setParsedSubject($this->l->t('You updated system tag %2$s to %1$s', [ |
|
| 184 | - $this->generatePlainSystemTag($parsedParameters['newsystemtag']), |
|
| 185 | - $this->generatePlainSystemTag($parsedParameters['oldsystemtag']), |
|
| 186 | - ])) |
|
| 187 | - ->setRichSubject($this->l->t('You updated system tag {oldsystemtag} to {newsystemtag}'), $parsedParameters); |
|
| 188 | - } else { |
|
| 189 | - $event->setParsedSubject($this->l->t('%1$s updated system tag %3$s to %2$s', [ |
|
| 190 | - $parsedParameters['actor']['name'], |
|
| 191 | - $this->generatePlainSystemTag($parsedParameters['newsystemtag']), |
|
| 192 | - $this->generatePlainSystemTag($parsedParameters['oldsystemtag']), |
|
| 193 | - ])) |
|
| 194 | - ->setRichSubject($this->l->t('{actor} updated system tag {oldsystemtag} to {newsystemtag}'), $parsedParameters); |
|
| 195 | - } |
|
| 196 | - } elseif ($event->getSubject() === self::ASSIGN_TAG) { |
|
| 197 | - if ($parsedParameters['actor']['id'] === '') { |
|
| 198 | - unset($parsedParameters['actor']); |
|
| 199 | - $event->setParsedSubject($this->l->t('System tag %2$s was added to %1$s by the system', [ |
|
| 200 | - $parsedParameters['file']['path'], |
|
| 201 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 202 | - ])) |
|
| 203 | - ->setRichSubject($this->l->t('System tag {systemtag} was added to {file} by the system'), $parsedParameters); |
|
| 204 | - } elseif ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 205 | - $event->setParsedSubject($this->l->t('You added system tag %2$s to %1$s', [ |
|
| 206 | - $parsedParameters['file']['path'], |
|
| 207 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 208 | - ])) |
|
| 209 | - ->setRichSubject($this->l->t('You added system tag {systemtag} to {file}'), $parsedParameters); |
|
| 210 | - } else { |
|
| 211 | - $event->setParsedSubject($this->l->t('%1$s added system tag %3$s to %2$s', [ |
|
| 212 | - $parsedParameters['actor']['name'], |
|
| 213 | - $parsedParameters['file']['path'], |
|
| 214 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 215 | - ])) |
|
| 216 | - ->setRichSubject($this->l->t('{actor} added system tag {systemtag} to {file}'), $parsedParameters); |
|
| 217 | - } |
|
| 218 | - } elseif ($event->getSubject() === self::UNASSIGN_TAG) { |
|
| 219 | - if ($parsedParameters['actor']['id'] === '') { |
|
| 220 | - unset($parsedParameters['actor']); |
|
| 221 | - $event->setParsedSubject($this->l->t('System tag %2$s was removed from %1$s by the system', [ |
|
| 222 | - $parsedParameters['file']['path'], |
|
| 223 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 224 | - ])) |
|
| 225 | - ->setRichSubject($this->l->t('System tag {systemtag} was removed from {file} by the system'), $parsedParameters); |
|
| 226 | - } elseif ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 227 | - $event->setParsedSubject($this->l->t('You removed system tag %2$s from %1$s', [ |
|
| 228 | - $parsedParameters['file']['path'], |
|
| 229 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 230 | - ])) |
|
| 231 | - ->setRichSubject($this->l->t('You removed system tag {systemtag} from {file}'), $parsedParameters); |
|
| 232 | - } else { |
|
| 233 | - $event->setParsedSubject($this->l->t('%1$s removed system tag %3$s from %2$s', [ |
|
| 234 | - $parsedParameters['actor']['name'], |
|
| 235 | - $parsedParameters['file']['path'], |
|
| 236 | - $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 237 | - ])) |
|
| 238 | - ->setRichSubject($this->l->t('{actor} removed system tag {systemtag} from {file}'), $parsedParameters); |
|
| 239 | - } |
|
| 240 | - } else { |
|
| 241 | - throw new UnknownActivityException(); |
|
| 242 | - } |
|
| 155 | + if ($event->getSubject() === self::CREATE_TAG) { |
|
| 156 | + if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 157 | + $event->setParsedSubject($this->l->t('You created system tag %1$s', [ |
|
| 158 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 159 | + ])) |
|
| 160 | + ->setRichSubject($this->l->t('You created system tag {systemtag}'), $parsedParameters); |
|
| 161 | + } else { |
|
| 162 | + $event->setParsedSubject($this->l->t('%1$s created system tag %2$s', [ |
|
| 163 | + $parsedParameters['actor']['name'], |
|
| 164 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 165 | + ])) |
|
| 166 | + ->setRichSubject($this->l->t('{actor} created system tag {systemtag}'), $parsedParameters); |
|
| 167 | + } |
|
| 168 | + } elseif ($event->getSubject() === self::DELETE_TAG) { |
|
| 169 | + if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 170 | + $event->setParsedSubject($this->l->t('You deleted system tag %1$s', [ |
|
| 171 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 172 | + ])) |
|
| 173 | + ->setRichSubject($this->l->t('You deleted system tag {systemtag}'), $parsedParameters); |
|
| 174 | + } else { |
|
| 175 | + $event->setParsedSubject($this->l->t('%1$s deleted system tag %2$s', [ |
|
| 176 | + $parsedParameters['actor']['name'], |
|
| 177 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 178 | + ])) |
|
| 179 | + ->setRichSubject($this->l->t('{actor} deleted system tag {systemtag}'), $parsedParameters); |
|
| 180 | + } |
|
| 181 | + } elseif ($event->getSubject() === self::UPDATE_TAG) { |
|
| 182 | + if ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 183 | + $event->setParsedSubject($this->l->t('You updated system tag %2$s to %1$s', [ |
|
| 184 | + $this->generatePlainSystemTag($parsedParameters['newsystemtag']), |
|
| 185 | + $this->generatePlainSystemTag($parsedParameters['oldsystemtag']), |
|
| 186 | + ])) |
|
| 187 | + ->setRichSubject($this->l->t('You updated system tag {oldsystemtag} to {newsystemtag}'), $parsedParameters); |
|
| 188 | + } else { |
|
| 189 | + $event->setParsedSubject($this->l->t('%1$s updated system tag %3$s to %2$s', [ |
|
| 190 | + $parsedParameters['actor']['name'], |
|
| 191 | + $this->generatePlainSystemTag($parsedParameters['newsystemtag']), |
|
| 192 | + $this->generatePlainSystemTag($parsedParameters['oldsystemtag']), |
|
| 193 | + ])) |
|
| 194 | + ->setRichSubject($this->l->t('{actor} updated system tag {oldsystemtag} to {newsystemtag}'), $parsedParameters); |
|
| 195 | + } |
|
| 196 | + } elseif ($event->getSubject() === self::ASSIGN_TAG) { |
|
| 197 | + if ($parsedParameters['actor']['id'] === '') { |
|
| 198 | + unset($parsedParameters['actor']); |
|
| 199 | + $event->setParsedSubject($this->l->t('System tag %2$s was added to %1$s by the system', [ |
|
| 200 | + $parsedParameters['file']['path'], |
|
| 201 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 202 | + ])) |
|
| 203 | + ->setRichSubject($this->l->t('System tag {systemtag} was added to {file} by the system'), $parsedParameters); |
|
| 204 | + } elseif ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 205 | + $event->setParsedSubject($this->l->t('You added system tag %2$s to %1$s', [ |
|
| 206 | + $parsedParameters['file']['path'], |
|
| 207 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 208 | + ])) |
|
| 209 | + ->setRichSubject($this->l->t('You added system tag {systemtag} to {file}'), $parsedParameters); |
|
| 210 | + } else { |
|
| 211 | + $event->setParsedSubject($this->l->t('%1$s added system tag %3$s to %2$s', [ |
|
| 212 | + $parsedParameters['actor']['name'], |
|
| 213 | + $parsedParameters['file']['path'], |
|
| 214 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 215 | + ])) |
|
| 216 | + ->setRichSubject($this->l->t('{actor} added system tag {systemtag} to {file}'), $parsedParameters); |
|
| 217 | + } |
|
| 218 | + } elseif ($event->getSubject() === self::UNASSIGN_TAG) { |
|
| 219 | + if ($parsedParameters['actor']['id'] === '') { |
|
| 220 | + unset($parsedParameters['actor']); |
|
| 221 | + $event->setParsedSubject($this->l->t('System tag %2$s was removed from %1$s by the system', [ |
|
| 222 | + $parsedParameters['file']['path'], |
|
| 223 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 224 | + ])) |
|
| 225 | + ->setRichSubject($this->l->t('System tag {systemtag} was removed from {file} by the system'), $parsedParameters); |
|
| 226 | + } elseif ($parsedParameters['actor']['id'] === $this->activityManager->getCurrentUserId()) { |
|
| 227 | + $event->setParsedSubject($this->l->t('You removed system tag %2$s from %1$s', [ |
|
| 228 | + $parsedParameters['file']['path'], |
|
| 229 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 230 | + ])) |
|
| 231 | + ->setRichSubject($this->l->t('You removed system tag {systemtag} from {file}'), $parsedParameters); |
|
| 232 | + } else { |
|
| 233 | + $event->setParsedSubject($this->l->t('%1$s removed system tag %3$s from %2$s', [ |
|
| 234 | + $parsedParameters['actor']['name'], |
|
| 235 | + $parsedParameters['file']['path'], |
|
| 236 | + $this->generatePlainSystemTag($parsedParameters['systemtag']), |
|
| 237 | + ])) |
|
| 238 | + ->setRichSubject($this->l->t('{actor} removed system tag {systemtag} from {file}'), $parsedParameters); |
|
| 239 | + } |
|
| 240 | + } else { |
|
| 241 | + throw new UnknownActivityException(); |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - return $event; |
|
| 245 | - } |
|
| 244 | + return $event; |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - protected function getParameters(IEvent $event) { |
|
| 248 | - $subject = $event->getSubject(); |
|
| 249 | - $parameters = $event->getSubjectParameters(); |
|
| 247 | + protected function getParameters(IEvent $event) { |
|
| 248 | + $subject = $event->getSubject(); |
|
| 249 | + $parameters = $event->getSubjectParameters(); |
|
| 250 | 250 | |
| 251 | - switch ($subject) { |
|
| 252 | - case self::CREATE_TAG: |
|
| 253 | - case self::DELETE_TAG: |
|
| 254 | - return [ |
|
| 255 | - 'actor' => $this->getUserParameter((string)$parameters[0]), |
|
| 256 | - 'systemtag' => $this->getSystemTagParameter($parameters[1]), |
|
| 257 | - ]; |
|
| 258 | - case self::UPDATE_TAG: |
|
| 259 | - return [ |
|
| 260 | - 'actor' => $this->getUserParameter((string)$parameters[0]), |
|
| 261 | - 'newsystemtag' => $this->getSystemTagParameter($parameters[1]), |
|
| 262 | - 'oldsystemtag' => $this->getSystemTagParameter($parameters[2]), |
|
| 263 | - ]; |
|
| 264 | - case self::ASSIGN_TAG: |
|
| 265 | - case self::UNASSIGN_TAG: |
|
| 266 | - return [ |
|
| 267 | - 'actor' => $this->getUserParameter((string)$parameters[0]), |
|
| 268 | - 'file' => $this->getFileParameter($event->getObjectId(), $parameters[1]), |
|
| 269 | - 'systemtag' => $this->getSystemTagParameter($parameters[2]), |
|
| 270 | - ]; |
|
| 271 | - } |
|
| 272 | - return []; |
|
| 273 | - } |
|
| 251 | + switch ($subject) { |
|
| 252 | + case self::CREATE_TAG: |
|
| 253 | + case self::DELETE_TAG: |
|
| 254 | + return [ |
|
| 255 | + 'actor' => $this->getUserParameter((string)$parameters[0]), |
|
| 256 | + 'systemtag' => $this->getSystemTagParameter($parameters[1]), |
|
| 257 | + ]; |
|
| 258 | + case self::UPDATE_TAG: |
|
| 259 | + return [ |
|
| 260 | + 'actor' => $this->getUserParameter((string)$parameters[0]), |
|
| 261 | + 'newsystemtag' => $this->getSystemTagParameter($parameters[1]), |
|
| 262 | + 'oldsystemtag' => $this->getSystemTagParameter($parameters[2]), |
|
| 263 | + ]; |
|
| 264 | + case self::ASSIGN_TAG: |
|
| 265 | + case self::UNASSIGN_TAG: |
|
| 266 | + return [ |
|
| 267 | + 'actor' => $this->getUserParameter((string)$parameters[0]), |
|
| 268 | + 'file' => $this->getFileParameter($event->getObjectId(), $parameters[1]), |
|
| 269 | + 'systemtag' => $this->getSystemTagParameter($parameters[2]), |
|
| 270 | + ]; |
|
| 271 | + } |
|
| 272 | + return []; |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | - protected function getFileParameter($id, $path) { |
|
| 276 | - return [ |
|
| 277 | - 'type' => 'file', |
|
| 278 | - 'id' => (string)$id, |
|
| 279 | - 'name' => basename($path), |
|
| 280 | - 'path' => trim($path, '/'), |
|
| 281 | - ]; |
|
| 282 | - } |
|
| 275 | + protected function getFileParameter($id, $path) { |
|
| 276 | + return [ |
|
| 277 | + 'type' => 'file', |
|
| 278 | + 'id' => (string)$id, |
|
| 279 | + 'name' => basename($path), |
|
| 280 | + 'path' => trim($path, '/'), |
|
| 281 | + ]; |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - protected function getSystemTagParameter($parameter) { |
|
| 285 | - $tagData = json_decode($parameter, true); |
|
| 286 | - if ($tagData === null) { |
|
| 287 | - [$name, $status] = explode('|||', substr($parameter, 3, -3)); |
|
| 288 | - $tagData = [ |
|
| 289 | - 'id' => '0', // No way to recover the ID |
|
| 290 | - 'name' => $name, |
|
| 291 | - 'assignable' => $status === 'assignable', |
|
| 292 | - 'visible' => $status !== 'invisible', |
|
| 293 | - ]; |
|
| 294 | - } |
|
| 284 | + protected function getSystemTagParameter($parameter) { |
|
| 285 | + $tagData = json_decode($parameter, true); |
|
| 286 | + if ($tagData === null) { |
|
| 287 | + [$name, $status] = explode('|||', substr($parameter, 3, -3)); |
|
| 288 | + $tagData = [ |
|
| 289 | + 'id' => '0', // No way to recover the ID |
|
| 290 | + 'name' => $name, |
|
| 291 | + 'assignable' => $status === 'assignable', |
|
| 292 | + 'visible' => $status !== 'invisible', |
|
| 293 | + ]; |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | - return [ |
|
| 297 | - 'type' => 'systemtag', |
|
| 298 | - 'id' => (string)$tagData['id'], |
|
| 299 | - 'name' => $tagData['name'], |
|
| 300 | - 'assignable' => $tagData['assignable'] ? '1' : '0', |
|
| 301 | - 'visibility' => $tagData['visible'] ? '1' : '0', |
|
| 302 | - ]; |
|
| 303 | - } |
|
| 296 | + return [ |
|
| 297 | + 'type' => 'systemtag', |
|
| 298 | + 'id' => (string)$tagData['id'], |
|
| 299 | + 'name' => $tagData['name'], |
|
| 300 | + 'assignable' => $tagData['assignable'] ? '1' : '0', |
|
| 301 | + 'visibility' => $tagData['visible'] ? '1' : '0', |
|
| 302 | + ]; |
|
| 303 | + } |
|
| 304 | 304 | |
| 305 | - protected function getUserParameter(string $uid): array { |
|
| 306 | - return [ |
|
| 307 | - 'type' => 'user', |
|
| 308 | - 'id' => $uid, |
|
| 309 | - 'name' => $this->userManager->getDisplayName($uid) ?? $uid, |
|
| 310 | - ]; |
|
| 311 | - } |
|
| 305 | + protected function getUserParameter(string $uid): array { |
|
| 306 | + return [ |
|
| 307 | + 'type' => 'user', |
|
| 308 | + 'id' => $uid, |
|
| 309 | + 'name' => $this->userManager->getDisplayName($uid) ?? $uid, |
|
| 310 | + ]; |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - protected function generatePlainSystemTag(array $parameter) { |
|
| 314 | - if ($parameter['assignable'] === '1') { |
|
| 315 | - return $parameter['name']; |
|
| 316 | - } elseif ($parameter['visibility'] === '1') { |
|
| 317 | - return $this->l->t('%s (restricted)', $parameter['name']); |
|
| 318 | - } else { |
|
| 319 | - return $this->l->t('%s (invisible)', $parameter['name']); |
|
| 320 | - } |
|
| 321 | - } |
|
| 313 | + protected function generatePlainSystemTag(array $parameter) { |
|
| 314 | + if ($parameter['assignable'] === '1') { |
|
| 315 | + return $parameter['name']; |
|
| 316 | + } elseif ($parameter['visibility'] === '1') { |
|
| 317 | + return $this->l->t('%s (restricted)', $parameter['name']); |
|
| 318 | + } else { |
|
| 319 | + return $this->l->t('%s (invisible)', $parameter['name']); |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | 322 | } |
@@ -252,19 +252,19 @@ discard block |
||
| 252 | 252 | case self::CREATE_TAG: |
| 253 | 253 | case self::DELETE_TAG: |
| 254 | 254 | return [ |
| 255 | - 'actor' => $this->getUserParameter((string)$parameters[0]), |
|
| 255 | + 'actor' => $this->getUserParameter((string) $parameters[0]), |
|
| 256 | 256 | 'systemtag' => $this->getSystemTagParameter($parameters[1]), |
| 257 | 257 | ]; |
| 258 | 258 | case self::UPDATE_TAG: |
| 259 | 259 | return [ |
| 260 | - 'actor' => $this->getUserParameter((string)$parameters[0]), |
|
| 260 | + 'actor' => $this->getUserParameter((string) $parameters[0]), |
|
| 261 | 261 | 'newsystemtag' => $this->getSystemTagParameter($parameters[1]), |
| 262 | 262 | 'oldsystemtag' => $this->getSystemTagParameter($parameters[2]), |
| 263 | 263 | ]; |
| 264 | 264 | case self::ASSIGN_TAG: |
| 265 | 265 | case self::UNASSIGN_TAG: |
| 266 | 266 | return [ |
| 267 | - 'actor' => $this->getUserParameter((string)$parameters[0]), |
|
| 267 | + 'actor' => $this->getUserParameter((string) $parameters[0]), |
|
| 268 | 268 | 'file' => $this->getFileParameter($event->getObjectId(), $parameters[1]), |
| 269 | 269 | 'systemtag' => $this->getSystemTagParameter($parameters[2]), |
| 270 | 270 | ]; |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | protected function getFileParameter($id, $path) { |
| 276 | 276 | return [ |
| 277 | 277 | 'type' => 'file', |
| 278 | - 'id' => (string)$id, |
|
| 278 | + 'id' => (string) $id, |
|
| 279 | 279 | 'name' => basename($path), |
| 280 | 280 | 'path' => trim($path, '/'), |
| 281 | 281 | ]; |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | |
| 296 | 296 | return [ |
| 297 | 297 | 'type' => 'systemtag', |
| 298 | - 'id' => (string)$tagData['id'], |
|
| 298 | + 'id' => (string) $tagData['id'], |
|
| 299 | 299 | 'name' => $tagData['name'], |
| 300 | 300 | 'assignable' => $tagData['assignable'] ? '1' : '0', |
| 301 | 301 | 'visibility' => $tagData['visible'] ? '1' : '0', |