initial implementation of activity manager

This commit is contained in:
Thomas Müller 2013-09-29 20:31:12 +02:00
parent 2e1e283592
commit 48b5c1d5f9
4 changed files with 73 additions and 0 deletions

48
lib/activitymanager.php Executable file
View File

@ -0,0 +1,48 @@
<?php
/**
* Copyright (c) 2013 Thomas Müller thomas.mueller@tmit.eu
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*
*/
namespace OC;
use OCP\Activity\IConsumer;
class ActivityManager implements \OCP\Activity\IManager {
private $consumers = array();
/**
* @param $app
* @param $subject
* @param $message
* @param $file
* @param $link
* @return mixed
*/
function publishActivity($app, $subject, $message, $file, $link) {
foreach($this->consumers as $consumer) {
$c = $consumer();
if ($c instanceof IConsumer) {
$c->receive($app, $subject, $message, $file, $link);
}
}
}
/**
* In order to improve lazy loading a closure can be registered which will be called in case
* activity consumers are actually requested
*
* $callable has to return an instance of OCA\Activity\IConsumer
*
* @param string $key
* @param \Closure $callable
*/
function registerConsumer(\Closure $callable) {
array_push($this->consumers, $callable);
}
}

View File

@ -25,6 +25,14 @@ namespace OCP\Activity;
interface IManager {
/**
* @param $app
* @param $subject
* @param $message
* @param $file
* @param $link
* @return mixed
*/
function publishActivity($app, $subject, $message, $file, $link);
/**

View File

@ -1400,6 +1400,11 @@ class Share {
'id' => $parent,
'token' => $token
));
// hook up activity manager
$subject = 'Something has been shared';
\OC::$server->getActivityManager()->publishActivity('files_sharing', $subject, '', '', '');
if ($parentFolder === true) {
// Return parent folders to preserve file target paths for potential children
return $parentFolders;

View File

@ -114,6 +114,9 @@ class Server extends SimpleContainer implements IServerContainer {
$this->registerService('UserCache', function($c) {
return new UserCache();
});
$this->registerService('ActivityManager', function($c) {
return new ActivityManager();
});
}
/**
@ -252,4 +255,13 @@ class Server extends SimpleContainer implements IServerContainer {
function getDatabaseConnection() {
return \OC_DB::getConnection();
}
/**
* Returns the activity manager
*
* @return \OCP\Activity\IManager
*/
function getActivityManager() {
return $this->query('ActivityManager');
}
}