aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/lib/Activity/Provider.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/lib/Activity/Provider.php')
-rw-r--r--apps/files/lib/Activity/Provider.php61
1 files changed, 42 insertions, 19 deletions
diff --git a/apps/files/lib/Activity/Provider.php b/apps/files/lib/Activity/Provider.php
index ae303034610..3efab382640 100644
--- a/apps/files/lib/Activity/Provider.php
+++ b/apps/files/lib/Activity/Provider.php
@@ -103,7 +103,7 @@ class Provider implements IProvider {
* @since 11.0.0
*/
public function parseShortVersion(IEvent $event, IEvent $previousEvent = null) {
- $parsedParameters = $this->getParameters($event->getSubject(), $event->getSubjectParameters());
+ $parsedParameters = $this->getParameters($event);
if ($event->getSubject() === 'created_by') {
$subject = $this->l->t('Created by {user}');
@@ -128,9 +128,7 @@ class Provider implements IProvider {
$this->setSubjects($event, $subject, $parsedParameters);
- $event = $this->eventMerger->mergeEvents('user', $event, $previousEvent);
-
- return $event;
+ return $this->eventMerger->mergeEvents('user', $event, $previousEvent);
}
/**
@@ -141,7 +139,7 @@ class Provider implements IProvider {
* @since 11.0.0
*/
public function parseLongVersion(IEvent $event, IEvent $previousEvent = null) {
- $parsedParameters = $this->getParameters($event->getSubject(), $event->getSubjectParameters());
+ $parsedParameters = $this->getParameters($event);
if ($event->getSubject() === 'created_self') {
$subject = $this->l->t('You created {file}');
@@ -211,44 +209,65 @@ class Provider implements IProvider {
->setRichSubject($subject, $parameters);
}
- protected function getParameters($subject, array $parameters) {
- switch ($subject) {
+ /**
+ * @param IEvent $event
+ * @return array
+ * @throws \InvalidArgumentException
+ */
+ protected function getParameters(IEvent $event) {
+ $parameters = $event->getSubjectParameters();
+ switch ($event->getSubject()) {
case 'created_self':
case 'created_public':
case 'changed_self':
case 'deleted_self':
case 'restored_self':
return [
- 'file' => $this->getRichFileParameter($parameters[0]),
+ 'file' => $this->getFile($parameters[0], $event),
];
case 'created_by':
case 'changed_by':
case 'deleted_by':
case 'restored_by':
return [
- 'file' => $this->getRichFileParameter($parameters[0]),
- 'user' => $this->getRichUserParameter($parameters[1]),
+ 'file' => $this->getFile($parameters[0], $event),
+ 'user' => $this->getUser($parameters[1]),
];
case 'renamed_self':
case 'moved_self':
return [
- 'newfile' => $this->getRichFileParameter($parameters[0]),
- 'oldfile' => $this->getRichFileParameter($parameters[1]),
+ 'newfile' => $this->getFile($parameters[0]),
+ 'oldfile' => $this->getFile($parameters[1]),
];
case 'renamed_by':
case 'moved_by':
return [
- 'newfile' => $this->getRichFileParameter($parameters[0]),
- 'user' => $this->getRichUserParameter($parameters[1]),
- 'oldfile' => $this->getRichFileParameter($parameters[2]),
+ 'newfile' => $this->getFile($parameters[0]),
+ 'user' => $this->getUser($parameters[1]),
+ 'oldfile' => $this->getFile($parameters[2]),
];
}
return [];
}
- protected function getRichFileParameter($parameter) {
- $path = reset($parameter);
- $id = key($parameter);
+ /**
+ * @param array|string $parameter
+ * @param IEvent|null $event
+ * @return array
+ * @throws \InvalidArgumentException
+ */
+ protected function getFile($parameter, IEvent $event = null) {
+ if (is_array($parameter)) {
+ $path = reset($parameter);
+ $id = (string) key($parameter);
+ } else if ($event !== null) {
+ // Legacy from before ownCloud 8.2
+ $path = $parameter;
+ $id = $event->getObjectId();
+ } else {
+ throw new \InvalidArgumentException('Could not generate file parameter');
+ }
+
return [
'type' => 'file',
'id' => $id,
@@ -258,7 +277,11 @@ class Provider implements IProvider {
];
}
- protected function getRichUserParameter($uid) {
+ /**
+ * @param string $uid
+ * @return array
+ */
+ protected function getUser($uid) {
if (!isset($this->displayNames[$uid])) {
$this->displayNames[$uid] = $this->getDisplayName($uid);
}