@@ -28,45 +28,45 @@ |
||
28 | 28 | |
29 | 29 | class Credentials implements ICredentials { |
30 | 30 | |
31 | - /** @var string */ |
|
32 | - private $uid; |
|
31 | + /** @var string */ |
|
32 | + private $uid; |
|
33 | 33 | |
34 | - /** @var string */ |
|
35 | - private $loginName; |
|
34 | + /** @var string */ |
|
35 | + private $loginName; |
|
36 | 36 | |
37 | - /** @var string */ |
|
38 | - private $password; |
|
37 | + /** @var string */ |
|
38 | + private $password; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param string $uid |
|
42 | - * @param string $loginName |
|
43 | - * @param string $password |
|
44 | - */ |
|
45 | - public function __construct($uid, $loginName, $password) { |
|
46 | - $this->uid = $uid; |
|
47 | - $this->loginName = $loginName; |
|
48 | - $this->password = $password; |
|
49 | - } |
|
40 | + /** |
|
41 | + * @param string $uid |
|
42 | + * @param string $loginName |
|
43 | + * @param string $password |
|
44 | + */ |
|
45 | + public function __construct($uid, $loginName, $password) { |
|
46 | + $this->uid = $uid; |
|
47 | + $this->loginName = $loginName; |
|
48 | + $this->password = $password; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return string |
|
53 | - */ |
|
54 | - public function getUID() { |
|
55 | - return $this->uid; |
|
56 | - } |
|
51 | + /** |
|
52 | + * @return string |
|
53 | + */ |
|
54 | + public function getUID() { |
|
55 | + return $this->uid; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function getLoginName() { |
|
62 | - return $this->loginName; |
|
63 | - } |
|
58 | + /** |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function getLoginName() { |
|
62 | + return $this->loginName; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function getPassword() { |
|
69 | - return $this->password; |
|
70 | - } |
|
65 | + /** |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function getPassword() { |
|
69 | + return $this->password; |
|
70 | + } |
|
71 | 71 | |
72 | 72 | } |
@@ -37,84 +37,84 @@ |
||
37 | 37 | |
38 | 38 | class Store implements IStore { |
39 | 39 | |
40 | - /** @var ISession */ |
|
41 | - private $session; |
|
42 | - |
|
43 | - /** @var ILogger */ |
|
44 | - private $logger; |
|
45 | - |
|
46 | - /** @var IProvider|null */ |
|
47 | - private $tokenProvider; |
|
48 | - |
|
49 | - /** |
|
50 | - * @param ISession $session |
|
51 | - * @param ILogger $logger |
|
52 | - * @param IProvider $tokenProvider |
|
53 | - */ |
|
54 | - public function __construct(ISession $session, ILogger $logger, IProvider $tokenProvider = null) { |
|
55 | - $this->session = $session; |
|
56 | - $this->logger = $logger; |
|
57 | - $this->tokenProvider = $tokenProvider; |
|
58 | - |
|
59 | - Util::connectHook('OC_User', 'post_login', $this, 'authenticate'); |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Hook listener on post login |
|
64 | - * |
|
65 | - * @param array $params |
|
66 | - */ |
|
67 | - public function authenticate(array $params) { |
|
68 | - $this->session->set('login_credentials', json_encode($params)); |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Replace the session implementation |
|
73 | - * |
|
74 | - * @param ISession $session |
|
75 | - */ |
|
76 | - public function setSession(ISession $session) { |
|
77 | - $this->session = $session; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @since 12 |
|
82 | - * |
|
83 | - * @return ICredentials the login credentials of the current user |
|
84 | - * @throws CredentialsUnavailableException |
|
85 | - */ |
|
86 | - public function getLoginCredentials() { |
|
87 | - if (is_null($this->tokenProvider)) { |
|
88 | - throw new CredentialsUnavailableException(); |
|
89 | - } |
|
90 | - |
|
91 | - $trySession = false; |
|
92 | - try { |
|
93 | - $sessionId = $this->session->getId(); |
|
94 | - $token = $this->tokenProvider->getToken($sessionId); |
|
95 | - |
|
96 | - $uid = $token->getUID(); |
|
97 | - $user = $token->getLoginName(); |
|
98 | - $password = $this->tokenProvider->getPassword($token, $sessionId); |
|
99 | - |
|
100 | - return new Credentials($uid, $user, $password); |
|
101 | - } catch (SessionNotAvailableException $ex) { |
|
102 | - $this->logger->debug('could not get login credentials because session is unavailable', ['app' => 'core']); |
|
103 | - } catch (InvalidTokenException $ex) { |
|
104 | - $this->logger->debug('could not get login credentials because the token is invalid', ['app' => 'core']); |
|
105 | - $trySession = true; |
|
106 | - } catch (PasswordlessTokenException $ex) { |
|
107 | - $this->logger->debug('could not get login credentials because the token has no password', ['app' => 'core']); |
|
108 | - $trySession = true; |
|
109 | - } |
|
110 | - |
|
111 | - if ($trySession && $this->session->exists('login_credentials')) { |
|
112 | - $creds = json_decode($this->session->get('login_credentials')); |
|
113 | - return new Credentials($creds->uid, $creds->uid, $creds->password); |
|
114 | - } |
|
115 | - |
|
116 | - // If we reach this line, an exception was thrown. |
|
117 | - throw new CredentialsUnavailableException(); |
|
118 | - } |
|
40 | + /** @var ISession */ |
|
41 | + private $session; |
|
42 | + |
|
43 | + /** @var ILogger */ |
|
44 | + private $logger; |
|
45 | + |
|
46 | + /** @var IProvider|null */ |
|
47 | + private $tokenProvider; |
|
48 | + |
|
49 | + /** |
|
50 | + * @param ISession $session |
|
51 | + * @param ILogger $logger |
|
52 | + * @param IProvider $tokenProvider |
|
53 | + */ |
|
54 | + public function __construct(ISession $session, ILogger $logger, IProvider $tokenProvider = null) { |
|
55 | + $this->session = $session; |
|
56 | + $this->logger = $logger; |
|
57 | + $this->tokenProvider = $tokenProvider; |
|
58 | + |
|
59 | + Util::connectHook('OC_User', 'post_login', $this, 'authenticate'); |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Hook listener on post login |
|
64 | + * |
|
65 | + * @param array $params |
|
66 | + */ |
|
67 | + public function authenticate(array $params) { |
|
68 | + $this->session->set('login_credentials', json_encode($params)); |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Replace the session implementation |
|
73 | + * |
|
74 | + * @param ISession $session |
|
75 | + */ |
|
76 | + public function setSession(ISession $session) { |
|
77 | + $this->session = $session; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @since 12 |
|
82 | + * |
|
83 | + * @return ICredentials the login credentials of the current user |
|
84 | + * @throws CredentialsUnavailableException |
|
85 | + */ |
|
86 | + public function getLoginCredentials() { |
|
87 | + if (is_null($this->tokenProvider)) { |
|
88 | + throw new CredentialsUnavailableException(); |
|
89 | + } |
|
90 | + |
|
91 | + $trySession = false; |
|
92 | + try { |
|
93 | + $sessionId = $this->session->getId(); |
|
94 | + $token = $this->tokenProvider->getToken($sessionId); |
|
95 | + |
|
96 | + $uid = $token->getUID(); |
|
97 | + $user = $token->getLoginName(); |
|
98 | + $password = $this->tokenProvider->getPassword($token, $sessionId); |
|
99 | + |
|
100 | + return new Credentials($uid, $user, $password); |
|
101 | + } catch (SessionNotAvailableException $ex) { |
|
102 | + $this->logger->debug('could not get login credentials because session is unavailable', ['app' => 'core']); |
|
103 | + } catch (InvalidTokenException $ex) { |
|
104 | + $this->logger->debug('could not get login credentials because the token is invalid', ['app' => 'core']); |
|
105 | + $trySession = true; |
|
106 | + } catch (PasswordlessTokenException $ex) { |
|
107 | + $this->logger->debug('could not get login credentials because the token has no password', ['app' => 'core']); |
|
108 | + $trySession = true; |
|
109 | + } |
|
110 | + |
|
111 | + if ($trySession && $this->session->exists('login_credentials')) { |
|
112 | + $creds = json_decode($this->session->get('login_credentials')); |
|
113 | + return new Credentials($creds->uid, $creds->uid, $creds->password); |
|
114 | + } |
|
115 | + |
|
116 | + // If we reach this line, an exception was thrown. |
|
117 | + throw new CredentialsUnavailableException(); |
|
118 | + } |
|
119 | 119 | |
120 | 120 | } |
@@ -129,7 +129,7 @@ |
||
129 | 129 | $data = $result->fetchAll(); |
130 | 130 | $result->closeCursor(); |
131 | 131 | |
132 | - $entities = array_map(function ($row) { |
|
132 | + $entities = array_map(function($row) { |
|
133 | 133 | return DefaultToken::fromRow($row); |
134 | 134 | }, $data); |
135 | 135 |
@@ -36,136 +36,136 @@ |
||
36 | 36 | |
37 | 37 | class DefaultTokenMapper extends QBMapper { |
38 | 38 | |
39 | - public function __construct(IDBConnection $db) { |
|
40 | - parent::__construct($db, 'authtoken'); |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Invalidate (delete) a given token |
|
45 | - * |
|
46 | - * @param string $token |
|
47 | - */ |
|
48 | - public function invalidate(string $token) { |
|
49 | - /* @var $qb IQueryBuilder */ |
|
50 | - $qb = $this->db->getQueryBuilder(); |
|
51 | - $qb->delete('authtoken') |
|
52 | - ->where($qb->expr()->eq('token', $qb->createNamedParameter($token, IQueryBuilder::PARAM_STR))) |
|
53 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
54 | - ->execute(); |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param int $olderThan |
|
59 | - * @param int $remember |
|
60 | - */ |
|
61 | - public function invalidateOld(int $olderThan, int $remember = IToken::DO_NOT_REMEMBER) { |
|
62 | - /* @var $qb IQueryBuilder */ |
|
63 | - $qb = $this->db->getQueryBuilder(); |
|
64 | - $qb->delete('authtoken') |
|
65 | - ->where($qb->expr()->lt('last_activity', $qb->createNamedParameter($olderThan, IQueryBuilder::PARAM_INT))) |
|
66 | - ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter(IToken::TEMPORARY_TOKEN, IQueryBuilder::PARAM_INT))) |
|
67 | - ->andWhere($qb->expr()->eq('remember', $qb->createNamedParameter($remember, IQueryBuilder::PARAM_INT))) |
|
68 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
69 | - ->execute(); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Get the user UID for the given token |
|
74 | - * |
|
75 | - * @param string $token |
|
76 | - * @throws DoesNotExistException |
|
77 | - * @return DefaultToken |
|
78 | - */ |
|
79 | - public function getToken(string $token): DefaultToken { |
|
80 | - /* @var $qb IQueryBuilder */ |
|
81 | - $qb = $this->db->getQueryBuilder(); |
|
82 | - $result = $qb->select('id', 'uid', 'login_name', 'password', 'name', 'token', 'type', 'remember', 'last_activity', 'last_check', 'scope', 'expires', 'version') |
|
83 | - ->from('authtoken') |
|
84 | - ->where($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
85 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
86 | - ->execute(); |
|
87 | - |
|
88 | - $data = $result->fetch(); |
|
89 | - $result->closeCursor(); |
|
90 | - if ($data === false) { |
|
91 | - throw new DoesNotExistException('token does not exist'); |
|
92 | - } |
|
93 | - return DefaultToken::fromRow($data); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Get the token for $id |
|
98 | - * |
|
99 | - * @param int $id |
|
100 | - * @throws DoesNotExistException |
|
101 | - * @return DefaultToken |
|
102 | - */ |
|
103 | - public function getTokenById(int $id): DefaultToken { |
|
104 | - /* @var $qb IQueryBuilder */ |
|
105 | - $qb = $this->db->getQueryBuilder(); |
|
106 | - $result = $qb->select('id', 'uid', 'login_name', 'password', 'name', 'token', 'type', 'remember', 'last_activity', 'last_check', 'scope', 'expires', 'version') |
|
107 | - ->from('authtoken') |
|
108 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
109 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
110 | - ->execute(); |
|
111 | - |
|
112 | - $data = $result->fetch(); |
|
113 | - $result->closeCursor(); |
|
114 | - if ($data === false) { |
|
115 | - throw new DoesNotExistException('token does not exist'); |
|
116 | - } |
|
117 | - return DefaultToken::fromRow($data); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Get all tokens of a user |
|
122 | - * |
|
123 | - * The provider may limit the number of result rows in case of an abuse |
|
124 | - * where a high number of (session) tokens is generated |
|
125 | - * |
|
126 | - * @param string $uid |
|
127 | - * @return DefaultToken[] |
|
128 | - */ |
|
129 | - public function getTokenByUser(string $uid): array { |
|
130 | - /* @var $qb IQueryBuilder */ |
|
131 | - $qb = $this->db->getQueryBuilder(); |
|
132 | - $qb->select('id', 'uid', 'login_name', 'password', 'name', 'token', 'type', 'remember', 'last_activity', 'last_check', 'scope', 'expires', 'version') |
|
133 | - ->from('authtoken') |
|
134 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
135 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
136 | - ->setMaxResults(1000); |
|
137 | - $result = $qb->execute(); |
|
138 | - $data = $result->fetchAll(); |
|
139 | - $result->closeCursor(); |
|
140 | - |
|
141 | - $entities = array_map(function ($row) { |
|
142 | - return DefaultToken::fromRow($row); |
|
143 | - }, $data); |
|
144 | - |
|
145 | - return $entities; |
|
146 | - } |
|
147 | - |
|
148 | - public function deleteById(string $uid, int $id) { |
|
149 | - /* @var $qb IQueryBuilder */ |
|
150 | - $qb = $this->db->getQueryBuilder(); |
|
151 | - $qb->delete('authtoken') |
|
152 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
153 | - ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
154 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
155 | - $qb->execute(); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * delete all auth token which belong to a specific client if the client was deleted |
|
160 | - * |
|
161 | - * @param string $name |
|
162 | - */ |
|
163 | - public function deleteByName(string $name) { |
|
164 | - $qb = $this->db->getQueryBuilder(); |
|
165 | - $qb->delete('authtoken') |
|
166 | - ->where($qb->expr()->eq('name', $qb->createNamedParameter($name), IQueryBuilder::PARAM_STR)) |
|
167 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
168 | - $qb->execute(); |
|
169 | - } |
|
39 | + public function __construct(IDBConnection $db) { |
|
40 | + parent::__construct($db, 'authtoken'); |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Invalidate (delete) a given token |
|
45 | + * |
|
46 | + * @param string $token |
|
47 | + */ |
|
48 | + public function invalidate(string $token) { |
|
49 | + /* @var $qb IQueryBuilder */ |
|
50 | + $qb = $this->db->getQueryBuilder(); |
|
51 | + $qb->delete('authtoken') |
|
52 | + ->where($qb->expr()->eq('token', $qb->createNamedParameter($token, IQueryBuilder::PARAM_STR))) |
|
53 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
54 | + ->execute(); |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param int $olderThan |
|
59 | + * @param int $remember |
|
60 | + */ |
|
61 | + public function invalidateOld(int $olderThan, int $remember = IToken::DO_NOT_REMEMBER) { |
|
62 | + /* @var $qb IQueryBuilder */ |
|
63 | + $qb = $this->db->getQueryBuilder(); |
|
64 | + $qb->delete('authtoken') |
|
65 | + ->where($qb->expr()->lt('last_activity', $qb->createNamedParameter($olderThan, IQueryBuilder::PARAM_INT))) |
|
66 | + ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter(IToken::TEMPORARY_TOKEN, IQueryBuilder::PARAM_INT))) |
|
67 | + ->andWhere($qb->expr()->eq('remember', $qb->createNamedParameter($remember, IQueryBuilder::PARAM_INT))) |
|
68 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
69 | + ->execute(); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Get the user UID for the given token |
|
74 | + * |
|
75 | + * @param string $token |
|
76 | + * @throws DoesNotExistException |
|
77 | + * @return DefaultToken |
|
78 | + */ |
|
79 | + public function getToken(string $token): DefaultToken { |
|
80 | + /* @var $qb IQueryBuilder */ |
|
81 | + $qb = $this->db->getQueryBuilder(); |
|
82 | + $result = $qb->select('id', 'uid', 'login_name', 'password', 'name', 'token', 'type', 'remember', 'last_activity', 'last_check', 'scope', 'expires', 'version') |
|
83 | + ->from('authtoken') |
|
84 | + ->where($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
85 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
86 | + ->execute(); |
|
87 | + |
|
88 | + $data = $result->fetch(); |
|
89 | + $result->closeCursor(); |
|
90 | + if ($data === false) { |
|
91 | + throw new DoesNotExistException('token does not exist'); |
|
92 | + } |
|
93 | + return DefaultToken::fromRow($data); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Get the token for $id |
|
98 | + * |
|
99 | + * @param int $id |
|
100 | + * @throws DoesNotExistException |
|
101 | + * @return DefaultToken |
|
102 | + */ |
|
103 | + public function getTokenById(int $id): DefaultToken { |
|
104 | + /* @var $qb IQueryBuilder */ |
|
105 | + $qb = $this->db->getQueryBuilder(); |
|
106 | + $result = $qb->select('id', 'uid', 'login_name', 'password', 'name', 'token', 'type', 'remember', 'last_activity', 'last_check', 'scope', 'expires', 'version') |
|
107 | + ->from('authtoken') |
|
108 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
109 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
110 | + ->execute(); |
|
111 | + |
|
112 | + $data = $result->fetch(); |
|
113 | + $result->closeCursor(); |
|
114 | + if ($data === false) { |
|
115 | + throw new DoesNotExistException('token does not exist'); |
|
116 | + } |
|
117 | + return DefaultToken::fromRow($data); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Get all tokens of a user |
|
122 | + * |
|
123 | + * The provider may limit the number of result rows in case of an abuse |
|
124 | + * where a high number of (session) tokens is generated |
|
125 | + * |
|
126 | + * @param string $uid |
|
127 | + * @return DefaultToken[] |
|
128 | + */ |
|
129 | + public function getTokenByUser(string $uid): array { |
|
130 | + /* @var $qb IQueryBuilder */ |
|
131 | + $qb = $this->db->getQueryBuilder(); |
|
132 | + $qb->select('id', 'uid', 'login_name', 'password', 'name', 'token', 'type', 'remember', 'last_activity', 'last_check', 'scope', 'expires', 'version') |
|
133 | + ->from('authtoken') |
|
134 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
135 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
136 | + ->setMaxResults(1000); |
|
137 | + $result = $qb->execute(); |
|
138 | + $data = $result->fetchAll(); |
|
139 | + $result->closeCursor(); |
|
140 | + |
|
141 | + $entities = array_map(function ($row) { |
|
142 | + return DefaultToken::fromRow($row); |
|
143 | + }, $data); |
|
144 | + |
|
145 | + return $entities; |
|
146 | + } |
|
147 | + |
|
148 | + public function deleteById(string $uid, int $id) { |
|
149 | + /* @var $qb IQueryBuilder */ |
|
150 | + $qb = $this->db->getQueryBuilder(); |
|
151 | + $qb->delete('authtoken') |
|
152 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
153 | + ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
154 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
155 | + $qb->execute(); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * delete all auth token which belong to a specific client if the client was deleted |
|
160 | + * |
|
161 | + * @param string $name |
|
162 | + */ |
|
163 | + public function deleteByName(string $name) { |
|
164 | + $qb = $this->db->getQueryBuilder(); |
|
165 | + $qb->delete('authtoken') |
|
166 | + ->where($qb->expr()->eq('name', $qb->createNamedParameter($name), IQueryBuilder::PARAM_STR)) |
|
167 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(DefaultToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
168 | + $qb->execute(); |
|
169 | + } |
|
170 | 170 | |
171 | 171 | } |
@@ -103,6 +103,6 @@ |
||
103 | 103 | $time = new \DateTime('now', $timeZone); |
104 | 104 | $timestampInfo = $time->format($this->config->getSystemValue('logdateformat', \DateTime::ATOM)); |
105 | 105 | |
106 | - return $timestampInfo . ' ' . $this->formatter->format($message); |
|
106 | + return $timestampInfo.' '.$this->formatter->format($message); |
|
107 | 107 | } |
108 | 108 | } |
@@ -28,85 +28,85 @@ |
||
28 | 28 | use Symfony\Component\Console\Formatter\OutputFormatterStyleInterface; |
29 | 29 | |
30 | 30 | class TimestampFormatter implements OutputFormatterInterface { |
31 | - /** @var IConfig */ |
|
32 | - protected $config; |
|
31 | + /** @var IConfig */ |
|
32 | + protected $config; |
|
33 | 33 | |
34 | - /** @var OutputFormatterInterface */ |
|
35 | - protected $formatter; |
|
34 | + /** @var OutputFormatterInterface */ |
|
35 | + protected $formatter; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param IConfig $config |
|
39 | - * @param OutputFormatterInterface $formatter |
|
40 | - */ |
|
41 | - public function __construct(IConfig $config, OutputFormatterInterface $formatter) { |
|
42 | - $this->config = $config; |
|
43 | - $this->formatter = $formatter; |
|
44 | - } |
|
37 | + /** |
|
38 | + * @param IConfig $config |
|
39 | + * @param OutputFormatterInterface $formatter |
|
40 | + */ |
|
41 | + public function __construct(IConfig $config, OutputFormatterInterface $formatter) { |
|
42 | + $this->config = $config; |
|
43 | + $this->formatter = $formatter; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Sets the decorated flag. |
|
48 | - * |
|
49 | - * @param bool $decorated Whether to decorate the messages or not |
|
50 | - */ |
|
51 | - public function setDecorated($decorated) { |
|
52 | - $this->formatter->setDecorated($decorated); |
|
53 | - } |
|
46 | + /** |
|
47 | + * Sets the decorated flag. |
|
48 | + * |
|
49 | + * @param bool $decorated Whether to decorate the messages or not |
|
50 | + */ |
|
51 | + public function setDecorated($decorated) { |
|
52 | + $this->formatter->setDecorated($decorated); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Gets the decorated flag. |
|
57 | - * |
|
58 | - * @return bool true if the output will decorate messages, false otherwise |
|
59 | - */ |
|
60 | - public function isDecorated() { |
|
61 | - return $this->formatter->isDecorated(); |
|
62 | - } |
|
55 | + /** |
|
56 | + * Gets the decorated flag. |
|
57 | + * |
|
58 | + * @return bool true if the output will decorate messages, false otherwise |
|
59 | + */ |
|
60 | + public function isDecorated() { |
|
61 | + return $this->formatter->isDecorated(); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Sets a new style. |
|
66 | - * |
|
67 | - * @param string $name The style name |
|
68 | - * @param OutputFormatterStyleInterface $style The style instance |
|
69 | - */ |
|
70 | - public function setStyle($name, OutputFormatterStyleInterface $style) { |
|
71 | - $this->formatter->setStyle($name, $style); |
|
72 | - } |
|
64 | + /** |
|
65 | + * Sets a new style. |
|
66 | + * |
|
67 | + * @param string $name The style name |
|
68 | + * @param OutputFormatterStyleInterface $style The style instance |
|
69 | + */ |
|
70 | + public function setStyle($name, OutputFormatterStyleInterface $style) { |
|
71 | + $this->formatter->setStyle($name, $style); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Checks if output formatter has style with specified name. |
|
76 | - * |
|
77 | - * @param string $name |
|
78 | - * @return bool |
|
79 | - */ |
|
80 | - public function hasStyle($name) { |
|
81 | - return $this->formatter->hasStyle($name); |
|
82 | - } |
|
74 | + /** |
|
75 | + * Checks if output formatter has style with specified name. |
|
76 | + * |
|
77 | + * @param string $name |
|
78 | + * @return bool |
|
79 | + */ |
|
80 | + public function hasStyle($name) { |
|
81 | + return $this->formatter->hasStyle($name); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * Gets style options from style with specified name. |
|
86 | - * |
|
87 | - * @param string $name |
|
88 | - * @return OutputFormatterStyleInterface |
|
89 | - * @throws \InvalidArgumentException When style isn't defined |
|
90 | - */ |
|
91 | - public function getStyle($name) { |
|
92 | - return $this->formatter->getStyle($name); |
|
93 | - } |
|
84 | + /** |
|
85 | + * Gets style options from style with specified name. |
|
86 | + * |
|
87 | + * @param string $name |
|
88 | + * @return OutputFormatterStyleInterface |
|
89 | + * @throws \InvalidArgumentException When style isn't defined |
|
90 | + */ |
|
91 | + public function getStyle($name) { |
|
92 | + return $this->formatter->getStyle($name); |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Formats a message according to the given styles. |
|
97 | - * |
|
98 | - * @param string $message The message to style |
|
99 | - * @return string The styled message, prepended with a timestamp using the |
|
100 | - * log timezone and dateformat, e.g. "2015-06-23T17:24:37+02:00" |
|
101 | - */ |
|
102 | - public function format($message) { |
|
95 | + /** |
|
96 | + * Formats a message according to the given styles. |
|
97 | + * |
|
98 | + * @param string $message The message to style |
|
99 | + * @return string The styled message, prepended with a timestamp using the |
|
100 | + * log timezone and dateformat, e.g. "2015-06-23T17:24:37+02:00" |
|
101 | + */ |
|
102 | + public function format($message) { |
|
103 | 103 | |
104 | - $timeZone = $this->config->getSystemValue('logtimezone', 'UTC'); |
|
105 | - $timeZone = $timeZone !== null ? new \DateTimeZone($timeZone) : null; |
|
104 | + $timeZone = $this->config->getSystemValue('logtimezone', 'UTC'); |
|
105 | + $timeZone = $timeZone !== null ? new \DateTimeZone($timeZone) : null; |
|
106 | 106 | |
107 | - $time = new \DateTime('now', $timeZone); |
|
108 | - $timestampInfo = $time->format($this->config->getSystemValue('logdateformat', \DateTime::ATOM)); |
|
107 | + $time = new \DateTime('now', $timeZone); |
|
108 | + $timestampInfo = $time->format($this->config->getSystemValue('logdateformat', \DateTime::ATOM)); |
|
109 | 109 | |
110 | - return $timestampInfo . ' ' . $this->formatter->format($message); |
|
111 | - } |
|
110 | + return $timestampInfo . ' ' . $this->formatter->format($message); |
|
111 | + } |
|
112 | 112 | } |
@@ -26,83 +26,83 @@ |
||
26 | 26 | |
27 | 27 | class LegacyFilter implements IFilter { |
28 | 28 | |
29 | - /** @var IManager */ |
|
30 | - protected $manager; |
|
31 | - /** @var string */ |
|
32 | - protected $identifier; |
|
33 | - /** @var string */ |
|
34 | - protected $name; |
|
35 | - /** @var bool */ |
|
36 | - protected $isTopFilter; |
|
29 | + /** @var IManager */ |
|
30 | + protected $manager; |
|
31 | + /** @var string */ |
|
32 | + protected $identifier; |
|
33 | + /** @var string */ |
|
34 | + protected $name; |
|
35 | + /** @var bool */ |
|
36 | + protected $isTopFilter; |
|
37 | 37 | |
38 | - /** |
|
39 | - * LegacySetting constructor. |
|
40 | - * |
|
41 | - * @param IManager $manager |
|
42 | - * @param string $identifier |
|
43 | - * @param string $name |
|
44 | - * @param bool $isTopFilter |
|
45 | - */ |
|
46 | - public function __construct(IManager $manager, |
|
47 | - $identifier, |
|
48 | - $name, |
|
49 | - $isTopFilter) { |
|
50 | - $this->manager = $manager; |
|
51 | - $this->identifier = $identifier; |
|
52 | - $this->name = $name; |
|
53 | - $this->isTopFilter = $isTopFilter; |
|
54 | - } |
|
38 | + /** |
|
39 | + * LegacySetting constructor. |
|
40 | + * |
|
41 | + * @param IManager $manager |
|
42 | + * @param string $identifier |
|
43 | + * @param string $name |
|
44 | + * @param bool $isTopFilter |
|
45 | + */ |
|
46 | + public function __construct(IManager $manager, |
|
47 | + $identifier, |
|
48 | + $name, |
|
49 | + $isTopFilter) { |
|
50 | + $this->manager = $manager; |
|
51 | + $this->identifier = $identifier; |
|
52 | + $this->name = $name; |
|
53 | + $this->isTopFilter = $isTopFilter; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @return string Lowercase a-z and underscore only identifier |
|
58 | - * @since 11.0.0 |
|
59 | - */ |
|
60 | - public function getIdentifier() { |
|
61 | - return $this->identifier; |
|
62 | - } |
|
56 | + /** |
|
57 | + * @return string Lowercase a-z and underscore only identifier |
|
58 | + * @since 11.0.0 |
|
59 | + */ |
|
60 | + public function getIdentifier() { |
|
61 | + return $this->identifier; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return string A translated string |
|
66 | - * @since 11.0.0 |
|
67 | - */ |
|
68 | - public function getName() { |
|
69 | - return $this->name; |
|
70 | - } |
|
64 | + /** |
|
65 | + * @return string A translated string |
|
66 | + * @since 11.0.0 |
|
67 | + */ |
|
68 | + public function getName() { |
|
69 | + return $this->name; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return int whether the filter should be rather on the top or bottom of |
|
74 | - * the admin section. The filters are arranged in ascending order of the |
|
75 | - * priority values. It is required to return a value between 0 and 100. |
|
76 | - * @since 11.0.0 |
|
77 | - */ |
|
78 | - public function getPriority() { |
|
79 | - return $this->isTopFilter ? 40 : 50; |
|
80 | - } |
|
72 | + /** |
|
73 | + * @return int whether the filter should be rather on the top or bottom of |
|
74 | + * the admin section. The filters are arranged in ascending order of the |
|
75 | + * priority values. It is required to return a value between 0 and 100. |
|
76 | + * @since 11.0.0 |
|
77 | + */ |
|
78 | + public function getPriority() { |
|
79 | + return $this->isTopFilter ? 40 : 50; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return string Full URL to an icon, empty string when none is given |
|
84 | - * @since 11.0.0 |
|
85 | - */ |
|
86 | - public function getIcon() { |
|
87 | - // Old API was CSS class, so we can not use this... |
|
88 | - return ''; |
|
89 | - } |
|
82 | + /** |
|
83 | + * @return string Full URL to an icon, empty string when none is given |
|
84 | + * @since 11.0.0 |
|
85 | + */ |
|
86 | + public function getIcon() { |
|
87 | + // Old API was CSS class, so we can not use this... |
|
88 | + return ''; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @param string[] $types |
|
93 | - * @return string[] An array of allowed apps from which activities should be displayed |
|
94 | - * @since 11.0.0 |
|
95 | - */ |
|
96 | - public function filterTypes(array $types) { |
|
97 | - return $this->manager->filterNotificationTypes($types, $this->getIdentifier()); |
|
98 | - } |
|
91 | + /** |
|
92 | + * @param string[] $types |
|
93 | + * @return string[] An array of allowed apps from which activities should be displayed |
|
94 | + * @since 11.0.0 |
|
95 | + */ |
|
96 | + public function filterTypes(array $types) { |
|
97 | + return $this->manager->filterNotificationTypes($types, $this->getIdentifier()); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @return string[] An array of allowed apps from which activities should be displayed |
|
102 | - * @since 11.0.0 |
|
103 | - */ |
|
104 | - public function allowedApps() { |
|
105 | - return []; |
|
106 | - } |
|
100 | + /** |
|
101 | + * @return string[] An array of allowed apps from which activities should be displayed |
|
102 | + * @since 11.0.0 |
|
103 | + */ |
|
104 | + public function allowedApps() { |
|
105 | + return []; |
|
106 | + } |
|
107 | 107 | } |
108 | 108 |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | } |
113 | 113 | |
114 | 114 | $this->consumers = []; |
115 | - foreach($this->consumersClosures as $consumer) { |
|
115 | + foreach ($this->consumersClosures as $consumer) { |
|
116 | 116 | $c = $consumer(); |
117 | 117 | if ($c instanceof IConsumer) { |
118 | 118 | $this->consumers[] = $c; |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | } |
134 | 134 | |
135 | 135 | $this->extensions = []; |
136 | - foreach($this->extensionsClosures as $extension) { |
|
136 | + foreach ($this->extensionsClosures as $extension) { |
|
137 | 137 | $e = $extension(); |
138 | 138 | if ($e instanceof IExtension) { |
139 | 139 | $this->extensions[] = $e; |
@@ -669,7 +669,7 @@ discard block |
||
669 | 669 | return array(null, null); |
670 | 670 | } |
671 | 671 | |
672 | - return array(' and ((' . implode(') or (', $conditions) . '))', $parameters); |
|
672 | + return array(' and (('.implode(') or (', $conditions).'))', $parameters); |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | /** |
@@ -40,663 +40,663 @@ |
||
40 | 40 | use OCP\RichObjectStrings\IValidator; |
41 | 41 | |
42 | 42 | class Manager implements IManager { |
43 | - /** @var IRequest */ |
|
44 | - protected $request; |
|
45 | - |
|
46 | - /** @var IUserSession */ |
|
47 | - protected $session; |
|
48 | - |
|
49 | - /** @var IConfig */ |
|
50 | - protected $config; |
|
51 | - |
|
52 | - /** @var IValidator */ |
|
53 | - protected $validator; |
|
54 | - |
|
55 | - /** @var string */ |
|
56 | - protected $formattingObjectType; |
|
57 | - |
|
58 | - /** @var int */ |
|
59 | - protected $formattingObjectId; |
|
60 | - |
|
61 | - /** @var bool */ |
|
62 | - protected $requirePNG; |
|
63 | - |
|
64 | - /** @var string */ |
|
65 | - protected $currentUserId; |
|
66 | - |
|
67 | - /** |
|
68 | - * constructor of the controller |
|
69 | - * |
|
70 | - * @param IRequest $request |
|
71 | - * @param IUserSession $session |
|
72 | - * @param IConfig $config |
|
73 | - * @param IValidator $validator |
|
74 | - */ |
|
75 | - public function __construct(IRequest $request, |
|
76 | - IUserSession $session, |
|
77 | - IConfig $config, |
|
78 | - IValidator $validator) { |
|
79 | - $this->request = $request; |
|
80 | - $this->session = $session; |
|
81 | - $this->config = $config; |
|
82 | - $this->validator = $validator; |
|
83 | - } |
|
84 | - |
|
85 | - /** @var \Closure[] */ |
|
86 | - private $consumersClosures = array(); |
|
87 | - |
|
88 | - /** @var IConsumer[] */ |
|
89 | - private $consumers = array(); |
|
90 | - |
|
91 | - /** @var \Closure[] */ |
|
92 | - private $extensionsClosures = array(); |
|
93 | - |
|
94 | - /** @var IExtension[] */ |
|
95 | - private $extensions = array(); |
|
96 | - |
|
97 | - /** @var array list of filters "name" => "is valid" */ |
|
98 | - protected $validFilters = array( |
|
99 | - 'all' => true, |
|
100 | - 'by' => true, |
|
101 | - 'self' => true, |
|
102 | - ); |
|
103 | - |
|
104 | - /** @var array list of type icons "type" => "css class" */ |
|
105 | - protected $typeIcons = array(); |
|
106 | - |
|
107 | - /** @var array list of special parameters "app" => ["text" => ["parameter" => "type"]] */ |
|
108 | - protected $specialParameters = array(); |
|
109 | - |
|
110 | - /** |
|
111 | - * @return \OCP\Activity\IConsumer[] |
|
112 | - */ |
|
113 | - protected function getConsumers() { |
|
114 | - if (!empty($this->consumers)) { |
|
115 | - return $this->consumers; |
|
116 | - } |
|
117 | - |
|
118 | - $this->consumers = []; |
|
119 | - foreach($this->consumersClosures as $consumer) { |
|
120 | - $c = $consumer(); |
|
121 | - if ($c instanceof IConsumer) { |
|
122 | - $this->consumers[] = $c; |
|
123 | - } else { |
|
124 | - throw new \InvalidArgumentException('The given consumer does not implement the \OCP\Activity\IConsumer interface'); |
|
125 | - } |
|
126 | - } |
|
127 | - |
|
128 | - return $this->consumers; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * @return \OCP\Activity\IExtension[] |
|
133 | - */ |
|
134 | - protected function getExtensions() { |
|
135 | - if (!empty($this->extensions)) { |
|
136 | - return $this->extensions; |
|
137 | - } |
|
138 | - |
|
139 | - $this->extensions = []; |
|
140 | - foreach($this->extensionsClosures as $extension) { |
|
141 | - $e = $extension(); |
|
142 | - if ($e instanceof IExtension) { |
|
143 | - $this->extensions[] = $e; |
|
144 | - } else { |
|
145 | - throw new \InvalidArgumentException('The given extension does not implement the \OCP\Activity\IExtension interface'); |
|
146 | - } |
|
147 | - } |
|
148 | - |
|
149 | - return $this->extensions; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Generates a new IEvent object |
|
154 | - * |
|
155 | - * Make sure to call at least the following methods before sending it to the |
|
156 | - * app with via the publish() method: |
|
157 | - * - setApp() |
|
158 | - * - setType() |
|
159 | - * - setAffectedUser() |
|
160 | - * - setSubject() |
|
161 | - * |
|
162 | - * @return IEvent |
|
163 | - */ |
|
164 | - public function generateEvent() { |
|
165 | - return new Event($this->validator); |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Publish an event to the activity consumers |
|
170 | - * |
|
171 | - * Make sure to call at least the following methods before sending an Event: |
|
172 | - * - setApp() |
|
173 | - * - setType() |
|
174 | - * - setAffectedUser() |
|
175 | - * - setSubject() |
|
176 | - * |
|
177 | - * @param IEvent $event |
|
178 | - * @throws \BadMethodCallException if required values have not been set |
|
179 | - */ |
|
180 | - public function publish(IEvent $event) { |
|
181 | - if ($event->getAuthor() === '') { |
|
182 | - if ($this->session->getUser() instanceof IUser) { |
|
183 | - $event->setAuthor($this->session->getUser()->getUID()); |
|
184 | - } |
|
185 | - } |
|
186 | - |
|
187 | - if (!$event->getTimestamp()) { |
|
188 | - $event->setTimestamp(time()); |
|
189 | - } |
|
190 | - |
|
191 | - if (!$event->isValid()) { |
|
192 | - throw new \BadMethodCallException('The given event is invalid'); |
|
193 | - } |
|
194 | - |
|
195 | - foreach ($this->getConsumers() as $c) { |
|
196 | - $c->receive($event); |
|
197 | - } |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
202 | - * activity consumers are actually requested |
|
203 | - * |
|
204 | - * $callable has to return an instance of OCA\Activity\IConsumer |
|
205 | - * |
|
206 | - * @param \Closure $callable |
|
207 | - */ |
|
208 | - public function registerConsumer(\Closure $callable) { |
|
209 | - $this->consumersClosures[] = $callable; |
|
210 | - $this->consumers = []; |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
215 | - * activity consumers are actually requested |
|
216 | - * |
|
217 | - * $callable has to return an instance of OCA\Activity\IExtension |
|
218 | - * |
|
219 | - * @param \Closure $callable |
|
220 | - */ |
|
221 | - public function registerExtension(\Closure $callable) { |
|
222 | - $this->extensionsClosures[] = $callable; |
|
223 | - $this->extensions = []; |
|
224 | - } |
|
225 | - |
|
226 | - /** @var string[] */ |
|
227 | - protected $filterClasses = []; |
|
228 | - |
|
229 | - /** @var IFilter[] */ |
|
230 | - protected $filters = []; |
|
231 | - |
|
232 | - /** @var bool */ |
|
233 | - protected $loadedLegacyFilters = false; |
|
234 | - |
|
235 | - /** |
|
236 | - * @param string $filter Class must implement OCA\Activity\IFilter |
|
237 | - * @return void |
|
238 | - */ |
|
239 | - public function registerFilter($filter) { |
|
240 | - $this->filterClasses[$filter] = false; |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * @return IFilter[] |
|
245 | - * @throws \InvalidArgumentException |
|
246 | - */ |
|
247 | - public function getFilters() { |
|
248 | - if (!$this->loadedLegacyFilters) { |
|
249 | - $legacyFilters = $this->getNavigation(); |
|
250 | - |
|
251 | - foreach ($legacyFilters['top'] as $filter => $data) { |
|
252 | - $this->filters[$filter] = new LegacyFilter( |
|
253 | - $this, $filter, $data['name'], true |
|
254 | - ); |
|
255 | - } |
|
256 | - |
|
257 | - foreach ($legacyFilters['apps'] as $filter => $data) { |
|
258 | - $this->filters[$filter] = new LegacyFilter( |
|
259 | - $this, $filter, $data['name'], false |
|
260 | - ); |
|
261 | - } |
|
262 | - $this->loadedLegacyFilters = true; |
|
263 | - } |
|
264 | - |
|
265 | - foreach ($this->filterClasses as $class => $false) { |
|
266 | - /** @var IFilter $filter */ |
|
267 | - $filter = \OC::$server->query($class); |
|
268 | - |
|
269 | - if (!$filter instanceof IFilter) { |
|
270 | - throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
271 | - } |
|
272 | - |
|
273 | - $this->filters[$filter->getIdentifier()] = $filter; |
|
274 | - |
|
275 | - unset($this->filterClasses[$class]); |
|
276 | - } |
|
277 | - return $this->filters; |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * @param string $id |
|
282 | - * @return IFilter |
|
283 | - * @throws \InvalidArgumentException when the filter was not found |
|
284 | - * @since 11.0.0 |
|
285 | - */ |
|
286 | - public function getFilterById($id) { |
|
287 | - $filters = $this->getFilters(); |
|
288 | - |
|
289 | - if (isset($filters[$id])) { |
|
290 | - return $filters[$id]; |
|
291 | - } |
|
292 | - |
|
293 | - throw new \InvalidArgumentException('Requested filter does not exist'); |
|
294 | - } |
|
295 | - |
|
296 | - /** @var string[] */ |
|
297 | - protected $providerClasses = []; |
|
298 | - |
|
299 | - /** @var IProvider[] */ |
|
300 | - protected $providers = []; |
|
301 | - |
|
302 | - /** |
|
303 | - * @param string $provider Class must implement OCA\Activity\IProvider |
|
304 | - * @return void |
|
305 | - */ |
|
306 | - public function registerProvider($provider) { |
|
307 | - $this->providerClasses[$provider] = false; |
|
308 | - } |
|
309 | - |
|
310 | - /** |
|
311 | - * @return IProvider[] |
|
312 | - * @throws \InvalidArgumentException |
|
313 | - */ |
|
314 | - public function getProviders() { |
|
315 | - foreach ($this->providerClasses as $class => $false) { |
|
316 | - /** @var IProvider $provider */ |
|
317 | - $provider = \OC::$server->query($class); |
|
318 | - |
|
319 | - if (!$provider instanceof IProvider) { |
|
320 | - throw new \InvalidArgumentException('Invalid activity provider registered'); |
|
321 | - } |
|
322 | - |
|
323 | - $this->providers[] = $provider; |
|
324 | - |
|
325 | - unset($this->providerClasses[$class]); |
|
326 | - } |
|
327 | - return $this->providers; |
|
328 | - } |
|
329 | - |
|
330 | - /** @var string[] */ |
|
331 | - protected $settingsClasses = []; |
|
332 | - |
|
333 | - /** @var ISetting[] */ |
|
334 | - protected $settings = []; |
|
335 | - |
|
336 | - /** @var bool */ |
|
337 | - protected $loadedLegacyTypes = false; |
|
338 | - |
|
339 | - /** |
|
340 | - * @param string $setting Class must implement OCA\Activity\ISetting |
|
341 | - * @return void |
|
342 | - */ |
|
343 | - public function registerSetting($setting) { |
|
344 | - $this->settingsClasses[$setting] = false; |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * @return ISetting[] |
|
349 | - * @throws \InvalidArgumentException |
|
350 | - */ |
|
351 | - public function getSettings() { |
|
352 | - if (!$this->loadedLegacyTypes) { |
|
353 | - $l = \OC::$server->getL10N('core'); |
|
354 | - $legacyTypes = $this->getNotificationTypes($l->getLanguageCode()); |
|
355 | - $streamTypes = $this->getDefaultTypes(IExtension::METHOD_STREAM); |
|
356 | - $mailTypes = $this->getDefaultTypes(IExtension::METHOD_MAIL); |
|
357 | - foreach ($legacyTypes as $type => $data) { |
|
358 | - if (is_string($data)) { |
|
359 | - $desc = $data; |
|
360 | - $canChangeStream = true; |
|
361 | - $canChangeMail = true; |
|
362 | - } else { |
|
363 | - $desc = $data['desc']; |
|
364 | - $canChangeStream = in_array(IExtension::METHOD_STREAM, $data['methods']); |
|
365 | - $canChangeMail = in_array(IExtension::METHOD_MAIL, $data['methods']); |
|
366 | - } |
|
367 | - |
|
368 | - $this->settings[$type] = new LegacySetting( |
|
369 | - $type, $desc, |
|
370 | - $canChangeStream, in_array($type, $streamTypes), |
|
371 | - $canChangeMail, in_array($type, $mailTypes) |
|
372 | - ); |
|
373 | - } |
|
374 | - $this->loadedLegacyTypes = true; |
|
375 | - } |
|
376 | - |
|
377 | - foreach ($this->settingsClasses as $class => $false) { |
|
378 | - /** @var ISetting $setting */ |
|
379 | - $setting = \OC::$server->query($class); |
|
380 | - |
|
381 | - if (!$setting instanceof ISetting) { |
|
382 | - throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
383 | - } |
|
384 | - |
|
385 | - $this->settings[$setting->getIdentifier()] = $setting; |
|
386 | - |
|
387 | - unset($this->settingsClasses[$class]); |
|
388 | - } |
|
389 | - return $this->settings; |
|
390 | - } |
|
391 | - |
|
392 | - /** |
|
393 | - * @param string $id |
|
394 | - * @return ISetting |
|
395 | - * @throws \InvalidArgumentException when the setting was not found |
|
396 | - * @since 11.0.0 |
|
397 | - */ |
|
398 | - public function getSettingById($id) { |
|
399 | - $settings = $this->getSettings(); |
|
400 | - |
|
401 | - if (isset($settings[$id])) { |
|
402 | - return $settings[$id]; |
|
403 | - } |
|
404 | - |
|
405 | - throw new \InvalidArgumentException('Requested setting does not exist'); |
|
406 | - } |
|
407 | - |
|
408 | - /** |
|
409 | - * @param string $type |
|
410 | - * @return string |
|
411 | - */ |
|
412 | - public function getTypeIcon($type) { |
|
413 | - if (isset($this->typeIcons[$type])) { |
|
414 | - return $this->typeIcons[$type]; |
|
415 | - } |
|
416 | - |
|
417 | - foreach ($this->getExtensions() as $c) { |
|
418 | - $icon = $c->getTypeIcon($type); |
|
419 | - if (is_string($icon)) { |
|
420 | - $this->typeIcons[$type] = $icon; |
|
421 | - return $icon; |
|
422 | - } |
|
423 | - } |
|
424 | - |
|
425 | - $this->typeIcons[$type] = ''; |
|
426 | - return ''; |
|
427 | - } |
|
428 | - |
|
429 | - /** |
|
430 | - * @param string $type |
|
431 | - * @param string $id |
|
432 | - */ |
|
433 | - public function setFormattingObject($type, $id) { |
|
434 | - $this->formattingObjectType = $type; |
|
435 | - $this->formattingObjectId = (string) $id; |
|
436 | - } |
|
437 | - |
|
438 | - /** |
|
439 | - * @return bool |
|
440 | - */ |
|
441 | - public function isFormattingFilteredObject() { |
|
442 | - return $this->formattingObjectType !== null && $this->formattingObjectId !== null |
|
443 | - && $this->formattingObjectType === $this->request->getParam('object_type') |
|
444 | - && $this->formattingObjectId === $this->request->getParam('object_id'); |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * @param bool $status Set to true, when parsing events should not use SVG icons |
|
449 | - */ |
|
450 | - public function setRequirePNG($status) { |
|
451 | - $this->requirePNG = $status; |
|
452 | - } |
|
453 | - |
|
454 | - /** |
|
455 | - * @return bool |
|
456 | - */ |
|
457 | - public function getRequirePNG() { |
|
458 | - return $this->requirePNG; |
|
459 | - } |
|
460 | - |
|
461 | - /** |
|
462 | - * @param string $app |
|
463 | - * @param string $text |
|
464 | - * @param array $params |
|
465 | - * @param boolean $stripPath |
|
466 | - * @param boolean $highlightParams |
|
467 | - * @param string $languageCode |
|
468 | - * @return string|false |
|
469 | - */ |
|
470 | - public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) { |
|
471 | - foreach ($this->getExtensions() as $c) { |
|
472 | - $translation = $c->translate($app, $text, $params, $stripPath, $highlightParams, $languageCode); |
|
473 | - if (is_string($translation)) { |
|
474 | - return $translation; |
|
475 | - } |
|
476 | - } |
|
477 | - |
|
478 | - return false; |
|
479 | - } |
|
480 | - |
|
481 | - /** |
|
482 | - * @param string $app |
|
483 | - * @param string $text |
|
484 | - * @return array|false |
|
485 | - */ |
|
486 | - public function getSpecialParameterList($app, $text) { |
|
487 | - if (isset($this->specialParameters[$app][$text])) { |
|
488 | - return $this->specialParameters[$app][$text]; |
|
489 | - } |
|
490 | - |
|
491 | - if (!isset($this->specialParameters[$app])) { |
|
492 | - $this->specialParameters[$app] = array(); |
|
493 | - } |
|
494 | - |
|
495 | - foreach ($this->getExtensions() as $c) { |
|
496 | - $specialParameter = $c->getSpecialParameterList($app, $text); |
|
497 | - if (is_array($specialParameter)) { |
|
498 | - $this->specialParameters[$app][$text] = $specialParameter; |
|
499 | - return $specialParameter; |
|
500 | - } |
|
501 | - } |
|
502 | - |
|
503 | - $this->specialParameters[$app][$text] = false; |
|
504 | - return false; |
|
505 | - } |
|
506 | - |
|
507 | - /** |
|
508 | - * @param array $activity |
|
509 | - * @return integer|false |
|
510 | - */ |
|
511 | - public function getGroupParameter($activity) { |
|
512 | - foreach ($this->getExtensions() as $c) { |
|
513 | - $parameter = $c->getGroupParameter($activity); |
|
514 | - if ($parameter !== false) { |
|
515 | - return $parameter; |
|
516 | - } |
|
517 | - } |
|
518 | - |
|
519 | - return false; |
|
520 | - } |
|
521 | - |
|
522 | - /** |
|
523 | - * Set the user we need to use |
|
524 | - * |
|
525 | - * @param string|null $currentUserId |
|
526 | - * @throws \UnexpectedValueException If the user is invalid |
|
527 | - */ |
|
528 | - public function setCurrentUserId($currentUserId) { |
|
529 | - if (!is_string($currentUserId) && $currentUserId !== null) { |
|
530 | - throw new \UnexpectedValueException('The given current user is invalid'); |
|
531 | - } |
|
532 | - $this->currentUserId = $currentUserId; |
|
533 | - } |
|
534 | - |
|
535 | - /** |
|
536 | - * Get the user we need to use |
|
537 | - * |
|
538 | - * Either the user is logged in, or we try to get it from the token |
|
539 | - * |
|
540 | - * @return string |
|
541 | - * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
542 | - */ |
|
543 | - public function getCurrentUserId() { |
|
544 | - if ($this->currentUserId !== null) { |
|
545 | - return $this->currentUserId; |
|
546 | - } else if (!$this->session->isLoggedIn()) { |
|
547 | - return $this->getUserFromToken(); |
|
548 | - } else { |
|
549 | - return $this->session->getUser()->getUID(); |
|
550 | - } |
|
551 | - } |
|
552 | - |
|
553 | - /** |
|
554 | - * Get the user for the token |
|
555 | - * |
|
556 | - * @return string |
|
557 | - * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
558 | - */ |
|
559 | - protected function getUserFromToken() { |
|
560 | - $token = (string) $this->request->getParam('token', ''); |
|
561 | - if (strlen($token) !== 30) { |
|
562 | - throw new \UnexpectedValueException('The token is invalid'); |
|
563 | - } |
|
564 | - |
|
565 | - $users = $this->config->getUsersForUserValue('activity', 'rsstoken', $token); |
|
566 | - |
|
567 | - if (count($users) !== 1) { |
|
568 | - // No unique user found |
|
569 | - throw new \UnexpectedValueException('The token is invalid'); |
|
570 | - } |
|
571 | - |
|
572 | - // Token found login as that user |
|
573 | - return array_shift($users); |
|
574 | - } |
|
575 | - |
|
576 | - /** |
|
577 | - * @return array |
|
578 | - * @deprecated 11.0.0 - Use getFilters() instead |
|
579 | - */ |
|
580 | - public function getNavigation() { |
|
581 | - $entries = array( |
|
582 | - 'apps' => array(), |
|
583 | - 'top' => array(), |
|
584 | - ); |
|
585 | - foreach ($this->getExtensions() as $c) { |
|
586 | - $additionalEntries = $c->getNavigation(); |
|
587 | - if (is_array($additionalEntries)) { |
|
588 | - $entries['apps'] = array_merge($entries['apps'], $additionalEntries['apps']); |
|
589 | - $entries['top'] = array_merge($entries['top'], $additionalEntries['top']); |
|
590 | - } |
|
591 | - } |
|
592 | - |
|
593 | - return $entries; |
|
594 | - } |
|
595 | - |
|
596 | - /** |
|
597 | - * @param string $filterValue |
|
598 | - * @return boolean |
|
599 | - * @deprecated 11.0.0 - Use getFilterById() instead |
|
600 | - */ |
|
601 | - public function isFilterValid($filterValue) { |
|
602 | - if (isset($this->validFilters[$filterValue])) { |
|
603 | - return $this->validFilters[$filterValue]; |
|
604 | - } |
|
605 | - |
|
606 | - foreach ($this->getExtensions() as $c) { |
|
607 | - if ($c->isFilterValid($filterValue) === true) { |
|
608 | - $this->validFilters[$filterValue] = true; |
|
609 | - return true; |
|
610 | - } |
|
611 | - } |
|
612 | - |
|
613 | - $this->validFilters[$filterValue] = false; |
|
614 | - return false; |
|
615 | - } |
|
616 | - |
|
617 | - /** |
|
618 | - * @param array $types |
|
619 | - * @param string $filter |
|
620 | - * @return array |
|
621 | - * @deprecated 11.0.0 - Use getFilterById()->filterTypes() instead |
|
622 | - */ |
|
623 | - public function filterNotificationTypes($types, $filter) { |
|
624 | - if (!$this->isFilterValid($filter)) { |
|
625 | - return $types; |
|
626 | - } |
|
627 | - |
|
628 | - foreach ($this->getExtensions() as $c) { |
|
629 | - $result = $c->filterNotificationTypes($types, $filter); |
|
630 | - if (is_array($result)) { |
|
631 | - $types = $result; |
|
632 | - } |
|
633 | - } |
|
634 | - return $types; |
|
635 | - } |
|
636 | - |
|
637 | - /** |
|
638 | - * @param string $filter |
|
639 | - * @return array |
|
640 | - * @deprecated 11.0.0 - Use getFilterById() instead |
|
641 | - */ |
|
642 | - public function getQueryForFilter($filter) { |
|
643 | - if (!$this->isFilterValid($filter)) { |
|
644 | - return [null, null]; |
|
645 | - } |
|
646 | - |
|
647 | - $conditions = array(); |
|
648 | - $parameters = array(); |
|
649 | - |
|
650 | - foreach ($this->getExtensions() as $c) { |
|
651 | - $result = $c->getQueryForFilter($filter); |
|
652 | - if (is_array($result)) { |
|
653 | - list($condition, $parameter) = $result; |
|
654 | - if ($condition && is_array($parameter)) { |
|
655 | - $conditions[] = $condition; |
|
656 | - $parameters = array_merge($parameters, $parameter); |
|
657 | - } |
|
658 | - } |
|
659 | - } |
|
660 | - |
|
661 | - if (empty($conditions)) { |
|
662 | - return array(null, null); |
|
663 | - } |
|
664 | - |
|
665 | - return array(' and ((' . implode(') or (', $conditions) . '))', $parameters); |
|
666 | - } |
|
667 | - |
|
668 | - /** |
|
669 | - * Will return additional notification types as specified by other apps |
|
670 | - * |
|
671 | - * @param string $languageCode |
|
672 | - * @return array |
|
673 | - * @deprecated 11.0.0 - Use getSettings() instead |
|
674 | - */ |
|
675 | - public function getNotificationTypes($languageCode) { |
|
676 | - $notificationTypes = $sharingNotificationTypes = []; |
|
677 | - foreach ($this->getExtensions() as $c) { |
|
678 | - $result = $c->getNotificationTypes($languageCode); |
|
679 | - if (is_array($result)) { |
|
680 | - $notificationTypes = array_merge($notificationTypes, $result); |
|
681 | - } |
|
682 | - } |
|
683 | - |
|
684 | - return array_merge($sharingNotificationTypes, $notificationTypes); |
|
685 | - } |
|
686 | - |
|
687 | - /** |
|
688 | - * @param string $method |
|
689 | - * @return array |
|
690 | - * @deprecated 11.0.0 - Use getSettings()->isDefaulEnabled<method>() instead |
|
691 | - */ |
|
692 | - public function getDefaultTypes($method) { |
|
693 | - $defaultTypes = array(); |
|
694 | - foreach ($this->getExtensions() as $c) { |
|
695 | - $types = $c->getDefaultTypes($method); |
|
696 | - if (is_array($types)) { |
|
697 | - $defaultTypes = array_merge($types, $defaultTypes); |
|
698 | - } |
|
699 | - } |
|
700 | - return $defaultTypes; |
|
701 | - } |
|
43 | + /** @var IRequest */ |
|
44 | + protected $request; |
|
45 | + |
|
46 | + /** @var IUserSession */ |
|
47 | + protected $session; |
|
48 | + |
|
49 | + /** @var IConfig */ |
|
50 | + protected $config; |
|
51 | + |
|
52 | + /** @var IValidator */ |
|
53 | + protected $validator; |
|
54 | + |
|
55 | + /** @var string */ |
|
56 | + protected $formattingObjectType; |
|
57 | + |
|
58 | + /** @var int */ |
|
59 | + protected $formattingObjectId; |
|
60 | + |
|
61 | + /** @var bool */ |
|
62 | + protected $requirePNG; |
|
63 | + |
|
64 | + /** @var string */ |
|
65 | + protected $currentUserId; |
|
66 | + |
|
67 | + /** |
|
68 | + * constructor of the controller |
|
69 | + * |
|
70 | + * @param IRequest $request |
|
71 | + * @param IUserSession $session |
|
72 | + * @param IConfig $config |
|
73 | + * @param IValidator $validator |
|
74 | + */ |
|
75 | + public function __construct(IRequest $request, |
|
76 | + IUserSession $session, |
|
77 | + IConfig $config, |
|
78 | + IValidator $validator) { |
|
79 | + $this->request = $request; |
|
80 | + $this->session = $session; |
|
81 | + $this->config = $config; |
|
82 | + $this->validator = $validator; |
|
83 | + } |
|
84 | + |
|
85 | + /** @var \Closure[] */ |
|
86 | + private $consumersClosures = array(); |
|
87 | + |
|
88 | + /** @var IConsumer[] */ |
|
89 | + private $consumers = array(); |
|
90 | + |
|
91 | + /** @var \Closure[] */ |
|
92 | + private $extensionsClosures = array(); |
|
93 | + |
|
94 | + /** @var IExtension[] */ |
|
95 | + private $extensions = array(); |
|
96 | + |
|
97 | + /** @var array list of filters "name" => "is valid" */ |
|
98 | + protected $validFilters = array( |
|
99 | + 'all' => true, |
|
100 | + 'by' => true, |
|
101 | + 'self' => true, |
|
102 | + ); |
|
103 | + |
|
104 | + /** @var array list of type icons "type" => "css class" */ |
|
105 | + protected $typeIcons = array(); |
|
106 | + |
|
107 | + /** @var array list of special parameters "app" => ["text" => ["parameter" => "type"]] */ |
|
108 | + protected $specialParameters = array(); |
|
109 | + |
|
110 | + /** |
|
111 | + * @return \OCP\Activity\IConsumer[] |
|
112 | + */ |
|
113 | + protected function getConsumers() { |
|
114 | + if (!empty($this->consumers)) { |
|
115 | + return $this->consumers; |
|
116 | + } |
|
117 | + |
|
118 | + $this->consumers = []; |
|
119 | + foreach($this->consumersClosures as $consumer) { |
|
120 | + $c = $consumer(); |
|
121 | + if ($c instanceof IConsumer) { |
|
122 | + $this->consumers[] = $c; |
|
123 | + } else { |
|
124 | + throw new \InvalidArgumentException('The given consumer does not implement the \OCP\Activity\IConsumer interface'); |
|
125 | + } |
|
126 | + } |
|
127 | + |
|
128 | + return $this->consumers; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * @return \OCP\Activity\IExtension[] |
|
133 | + */ |
|
134 | + protected function getExtensions() { |
|
135 | + if (!empty($this->extensions)) { |
|
136 | + return $this->extensions; |
|
137 | + } |
|
138 | + |
|
139 | + $this->extensions = []; |
|
140 | + foreach($this->extensionsClosures as $extension) { |
|
141 | + $e = $extension(); |
|
142 | + if ($e instanceof IExtension) { |
|
143 | + $this->extensions[] = $e; |
|
144 | + } else { |
|
145 | + throw new \InvalidArgumentException('The given extension does not implement the \OCP\Activity\IExtension interface'); |
|
146 | + } |
|
147 | + } |
|
148 | + |
|
149 | + return $this->extensions; |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Generates a new IEvent object |
|
154 | + * |
|
155 | + * Make sure to call at least the following methods before sending it to the |
|
156 | + * app with via the publish() method: |
|
157 | + * - setApp() |
|
158 | + * - setType() |
|
159 | + * - setAffectedUser() |
|
160 | + * - setSubject() |
|
161 | + * |
|
162 | + * @return IEvent |
|
163 | + */ |
|
164 | + public function generateEvent() { |
|
165 | + return new Event($this->validator); |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Publish an event to the activity consumers |
|
170 | + * |
|
171 | + * Make sure to call at least the following methods before sending an Event: |
|
172 | + * - setApp() |
|
173 | + * - setType() |
|
174 | + * - setAffectedUser() |
|
175 | + * - setSubject() |
|
176 | + * |
|
177 | + * @param IEvent $event |
|
178 | + * @throws \BadMethodCallException if required values have not been set |
|
179 | + */ |
|
180 | + public function publish(IEvent $event) { |
|
181 | + if ($event->getAuthor() === '') { |
|
182 | + if ($this->session->getUser() instanceof IUser) { |
|
183 | + $event->setAuthor($this->session->getUser()->getUID()); |
|
184 | + } |
|
185 | + } |
|
186 | + |
|
187 | + if (!$event->getTimestamp()) { |
|
188 | + $event->setTimestamp(time()); |
|
189 | + } |
|
190 | + |
|
191 | + if (!$event->isValid()) { |
|
192 | + throw new \BadMethodCallException('The given event is invalid'); |
|
193 | + } |
|
194 | + |
|
195 | + foreach ($this->getConsumers() as $c) { |
|
196 | + $c->receive($event); |
|
197 | + } |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
202 | + * activity consumers are actually requested |
|
203 | + * |
|
204 | + * $callable has to return an instance of OCA\Activity\IConsumer |
|
205 | + * |
|
206 | + * @param \Closure $callable |
|
207 | + */ |
|
208 | + public function registerConsumer(\Closure $callable) { |
|
209 | + $this->consumersClosures[] = $callable; |
|
210 | + $this->consumers = []; |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
215 | + * activity consumers are actually requested |
|
216 | + * |
|
217 | + * $callable has to return an instance of OCA\Activity\IExtension |
|
218 | + * |
|
219 | + * @param \Closure $callable |
|
220 | + */ |
|
221 | + public function registerExtension(\Closure $callable) { |
|
222 | + $this->extensionsClosures[] = $callable; |
|
223 | + $this->extensions = []; |
|
224 | + } |
|
225 | + |
|
226 | + /** @var string[] */ |
|
227 | + protected $filterClasses = []; |
|
228 | + |
|
229 | + /** @var IFilter[] */ |
|
230 | + protected $filters = []; |
|
231 | + |
|
232 | + /** @var bool */ |
|
233 | + protected $loadedLegacyFilters = false; |
|
234 | + |
|
235 | + /** |
|
236 | + * @param string $filter Class must implement OCA\Activity\IFilter |
|
237 | + * @return void |
|
238 | + */ |
|
239 | + public function registerFilter($filter) { |
|
240 | + $this->filterClasses[$filter] = false; |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * @return IFilter[] |
|
245 | + * @throws \InvalidArgumentException |
|
246 | + */ |
|
247 | + public function getFilters() { |
|
248 | + if (!$this->loadedLegacyFilters) { |
|
249 | + $legacyFilters = $this->getNavigation(); |
|
250 | + |
|
251 | + foreach ($legacyFilters['top'] as $filter => $data) { |
|
252 | + $this->filters[$filter] = new LegacyFilter( |
|
253 | + $this, $filter, $data['name'], true |
|
254 | + ); |
|
255 | + } |
|
256 | + |
|
257 | + foreach ($legacyFilters['apps'] as $filter => $data) { |
|
258 | + $this->filters[$filter] = new LegacyFilter( |
|
259 | + $this, $filter, $data['name'], false |
|
260 | + ); |
|
261 | + } |
|
262 | + $this->loadedLegacyFilters = true; |
|
263 | + } |
|
264 | + |
|
265 | + foreach ($this->filterClasses as $class => $false) { |
|
266 | + /** @var IFilter $filter */ |
|
267 | + $filter = \OC::$server->query($class); |
|
268 | + |
|
269 | + if (!$filter instanceof IFilter) { |
|
270 | + throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
271 | + } |
|
272 | + |
|
273 | + $this->filters[$filter->getIdentifier()] = $filter; |
|
274 | + |
|
275 | + unset($this->filterClasses[$class]); |
|
276 | + } |
|
277 | + return $this->filters; |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * @param string $id |
|
282 | + * @return IFilter |
|
283 | + * @throws \InvalidArgumentException when the filter was not found |
|
284 | + * @since 11.0.0 |
|
285 | + */ |
|
286 | + public function getFilterById($id) { |
|
287 | + $filters = $this->getFilters(); |
|
288 | + |
|
289 | + if (isset($filters[$id])) { |
|
290 | + return $filters[$id]; |
|
291 | + } |
|
292 | + |
|
293 | + throw new \InvalidArgumentException('Requested filter does not exist'); |
|
294 | + } |
|
295 | + |
|
296 | + /** @var string[] */ |
|
297 | + protected $providerClasses = []; |
|
298 | + |
|
299 | + /** @var IProvider[] */ |
|
300 | + protected $providers = []; |
|
301 | + |
|
302 | + /** |
|
303 | + * @param string $provider Class must implement OCA\Activity\IProvider |
|
304 | + * @return void |
|
305 | + */ |
|
306 | + public function registerProvider($provider) { |
|
307 | + $this->providerClasses[$provider] = false; |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * @return IProvider[] |
|
312 | + * @throws \InvalidArgumentException |
|
313 | + */ |
|
314 | + public function getProviders() { |
|
315 | + foreach ($this->providerClasses as $class => $false) { |
|
316 | + /** @var IProvider $provider */ |
|
317 | + $provider = \OC::$server->query($class); |
|
318 | + |
|
319 | + if (!$provider instanceof IProvider) { |
|
320 | + throw new \InvalidArgumentException('Invalid activity provider registered'); |
|
321 | + } |
|
322 | + |
|
323 | + $this->providers[] = $provider; |
|
324 | + |
|
325 | + unset($this->providerClasses[$class]); |
|
326 | + } |
|
327 | + return $this->providers; |
|
328 | + } |
|
329 | + |
|
330 | + /** @var string[] */ |
|
331 | + protected $settingsClasses = []; |
|
332 | + |
|
333 | + /** @var ISetting[] */ |
|
334 | + protected $settings = []; |
|
335 | + |
|
336 | + /** @var bool */ |
|
337 | + protected $loadedLegacyTypes = false; |
|
338 | + |
|
339 | + /** |
|
340 | + * @param string $setting Class must implement OCA\Activity\ISetting |
|
341 | + * @return void |
|
342 | + */ |
|
343 | + public function registerSetting($setting) { |
|
344 | + $this->settingsClasses[$setting] = false; |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * @return ISetting[] |
|
349 | + * @throws \InvalidArgumentException |
|
350 | + */ |
|
351 | + public function getSettings() { |
|
352 | + if (!$this->loadedLegacyTypes) { |
|
353 | + $l = \OC::$server->getL10N('core'); |
|
354 | + $legacyTypes = $this->getNotificationTypes($l->getLanguageCode()); |
|
355 | + $streamTypes = $this->getDefaultTypes(IExtension::METHOD_STREAM); |
|
356 | + $mailTypes = $this->getDefaultTypes(IExtension::METHOD_MAIL); |
|
357 | + foreach ($legacyTypes as $type => $data) { |
|
358 | + if (is_string($data)) { |
|
359 | + $desc = $data; |
|
360 | + $canChangeStream = true; |
|
361 | + $canChangeMail = true; |
|
362 | + } else { |
|
363 | + $desc = $data['desc']; |
|
364 | + $canChangeStream = in_array(IExtension::METHOD_STREAM, $data['methods']); |
|
365 | + $canChangeMail = in_array(IExtension::METHOD_MAIL, $data['methods']); |
|
366 | + } |
|
367 | + |
|
368 | + $this->settings[$type] = new LegacySetting( |
|
369 | + $type, $desc, |
|
370 | + $canChangeStream, in_array($type, $streamTypes), |
|
371 | + $canChangeMail, in_array($type, $mailTypes) |
|
372 | + ); |
|
373 | + } |
|
374 | + $this->loadedLegacyTypes = true; |
|
375 | + } |
|
376 | + |
|
377 | + foreach ($this->settingsClasses as $class => $false) { |
|
378 | + /** @var ISetting $setting */ |
|
379 | + $setting = \OC::$server->query($class); |
|
380 | + |
|
381 | + if (!$setting instanceof ISetting) { |
|
382 | + throw new \InvalidArgumentException('Invalid activity filter registered'); |
|
383 | + } |
|
384 | + |
|
385 | + $this->settings[$setting->getIdentifier()] = $setting; |
|
386 | + |
|
387 | + unset($this->settingsClasses[$class]); |
|
388 | + } |
|
389 | + return $this->settings; |
|
390 | + } |
|
391 | + |
|
392 | + /** |
|
393 | + * @param string $id |
|
394 | + * @return ISetting |
|
395 | + * @throws \InvalidArgumentException when the setting was not found |
|
396 | + * @since 11.0.0 |
|
397 | + */ |
|
398 | + public function getSettingById($id) { |
|
399 | + $settings = $this->getSettings(); |
|
400 | + |
|
401 | + if (isset($settings[$id])) { |
|
402 | + return $settings[$id]; |
|
403 | + } |
|
404 | + |
|
405 | + throw new \InvalidArgumentException('Requested setting does not exist'); |
|
406 | + } |
|
407 | + |
|
408 | + /** |
|
409 | + * @param string $type |
|
410 | + * @return string |
|
411 | + */ |
|
412 | + public function getTypeIcon($type) { |
|
413 | + if (isset($this->typeIcons[$type])) { |
|
414 | + return $this->typeIcons[$type]; |
|
415 | + } |
|
416 | + |
|
417 | + foreach ($this->getExtensions() as $c) { |
|
418 | + $icon = $c->getTypeIcon($type); |
|
419 | + if (is_string($icon)) { |
|
420 | + $this->typeIcons[$type] = $icon; |
|
421 | + return $icon; |
|
422 | + } |
|
423 | + } |
|
424 | + |
|
425 | + $this->typeIcons[$type] = ''; |
|
426 | + return ''; |
|
427 | + } |
|
428 | + |
|
429 | + /** |
|
430 | + * @param string $type |
|
431 | + * @param string $id |
|
432 | + */ |
|
433 | + public function setFormattingObject($type, $id) { |
|
434 | + $this->formattingObjectType = $type; |
|
435 | + $this->formattingObjectId = (string) $id; |
|
436 | + } |
|
437 | + |
|
438 | + /** |
|
439 | + * @return bool |
|
440 | + */ |
|
441 | + public function isFormattingFilteredObject() { |
|
442 | + return $this->formattingObjectType !== null && $this->formattingObjectId !== null |
|
443 | + && $this->formattingObjectType === $this->request->getParam('object_type') |
|
444 | + && $this->formattingObjectId === $this->request->getParam('object_id'); |
|
445 | + } |
|
446 | + |
|
447 | + /** |
|
448 | + * @param bool $status Set to true, when parsing events should not use SVG icons |
|
449 | + */ |
|
450 | + public function setRequirePNG($status) { |
|
451 | + $this->requirePNG = $status; |
|
452 | + } |
|
453 | + |
|
454 | + /** |
|
455 | + * @return bool |
|
456 | + */ |
|
457 | + public function getRequirePNG() { |
|
458 | + return $this->requirePNG; |
|
459 | + } |
|
460 | + |
|
461 | + /** |
|
462 | + * @param string $app |
|
463 | + * @param string $text |
|
464 | + * @param array $params |
|
465 | + * @param boolean $stripPath |
|
466 | + * @param boolean $highlightParams |
|
467 | + * @param string $languageCode |
|
468 | + * @return string|false |
|
469 | + */ |
|
470 | + public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) { |
|
471 | + foreach ($this->getExtensions() as $c) { |
|
472 | + $translation = $c->translate($app, $text, $params, $stripPath, $highlightParams, $languageCode); |
|
473 | + if (is_string($translation)) { |
|
474 | + return $translation; |
|
475 | + } |
|
476 | + } |
|
477 | + |
|
478 | + return false; |
|
479 | + } |
|
480 | + |
|
481 | + /** |
|
482 | + * @param string $app |
|
483 | + * @param string $text |
|
484 | + * @return array|false |
|
485 | + */ |
|
486 | + public function getSpecialParameterList($app, $text) { |
|
487 | + if (isset($this->specialParameters[$app][$text])) { |
|
488 | + return $this->specialParameters[$app][$text]; |
|
489 | + } |
|
490 | + |
|
491 | + if (!isset($this->specialParameters[$app])) { |
|
492 | + $this->specialParameters[$app] = array(); |
|
493 | + } |
|
494 | + |
|
495 | + foreach ($this->getExtensions() as $c) { |
|
496 | + $specialParameter = $c->getSpecialParameterList($app, $text); |
|
497 | + if (is_array($specialParameter)) { |
|
498 | + $this->specialParameters[$app][$text] = $specialParameter; |
|
499 | + return $specialParameter; |
|
500 | + } |
|
501 | + } |
|
502 | + |
|
503 | + $this->specialParameters[$app][$text] = false; |
|
504 | + return false; |
|
505 | + } |
|
506 | + |
|
507 | + /** |
|
508 | + * @param array $activity |
|
509 | + * @return integer|false |
|
510 | + */ |
|
511 | + public function getGroupParameter($activity) { |
|
512 | + foreach ($this->getExtensions() as $c) { |
|
513 | + $parameter = $c->getGroupParameter($activity); |
|
514 | + if ($parameter !== false) { |
|
515 | + return $parameter; |
|
516 | + } |
|
517 | + } |
|
518 | + |
|
519 | + return false; |
|
520 | + } |
|
521 | + |
|
522 | + /** |
|
523 | + * Set the user we need to use |
|
524 | + * |
|
525 | + * @param string|null $currentUserId |
|
526 | + * @throws \UnexpectedValueException If the user is invalid |
|
527 | + */ |
|
528 | + public function setCurrentUserId($currentUserId) { |
|
529 | + if (!is_string($currentUserId) && $currentUserId !== null) { |
|
530 | + throw new \UnexpectedValueException('The given current user is invalid'); |
|
531 | + } |
|
532 | + $this->currentUserId = $currentUserId; |
|
533 | + } |
|
534 | + |
|
535 | + /** |
|
536 | + * Get the user we need to use |
|
537 | + * |
|
538 | + * Either the user is logged in, or we try to get it from the token |
|
539 | + * |
|
540 | + * @return string |
|
541 | + * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
542 | + */ |
|
543 | + public function getCurrentUserId() { |
|
544 | + if ($this->currentUserId !== null) { |
|
545 | + return $this->currentUserId; |
|
546 | + } else if (!$this->session->isLoggedIn()) { |
|
547 | + return $this->getUserFromToken(); |
|
548 | + } else { |
|
549 | + return $this->session->getUser()->getUID(); |
|
550 | + } |
|
551 | + } |
|
552 | + |
|
553 | + /** |
|
554 | + * Get the user for the token |
|
555 | + * |
|
556 | + * @return string |
|
557 | + * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique |
|
558 | + */ |
|
559 | + protected function getUserFromToken() { |
|
560 | + $token = (string) $this->request->getParam('token', ''); |
|
561 | + if (strlen($token) !== 30) { |
|
562 | + throw new \UnexpectedValueException('The token is invalid'); |
|
563 | + } |
|
564 | + |
|
565 | + $users = $this->config->getUsersForUserValue('activity', 'rsstoken', $token); |
|
566 | + |
|
567 | + if (count($users) !== 1) { |
|
568 | + // No unique user found |
|
569 | + throw new \UnexpectedValueException('The token is invalid'); |
|
570 | + } |
|
571 | + |
|
572 | + // Token found login as that user |
|
573 | + return array_shift($users); |
|
574 | + } |
|
575 | + |
|
576 | + /** |
|
577 | + * @return array |
|
578 | + * @deprecated 11.0.0 - Use getFilters() instead |
|
579 | + */ |
|
580 | + public function getNavigation() { |
|
581 | + $entries = array( |
|
582 | + 'apps' => array(), |
|
583 | + 'top' => array(), |
|
584 | + ); |
|
585 | + foreach ($this->getExtensions() as $c) { |
|
586 | + $additionalEntries = $c->getNavigation(); |
|
587 | + if (is_array($additionalEntries)) { |
|
588 | + $entries['apps'] = array_merge($entries['apps'], $additionalEntries['apps']); |
|
589 | + $entries['top'] = array_merge($entries['top'], $additionalEntries['top']); |
|
590 | + } |
|
591 | + } |
|
592 | + |
|
593 | + return $entries; |
|
594 | + } |
|
595 | + |
|
596 | + /** |
|
597 | + * @param string $filterValue |
|
598 | + * @return boolean |
|
599 | + * @deprecated 11.0.0 - Use getFilterById() instead |
|
600 | + */ |
|
601 | + public function isFilterValid($filterValue) { |
|
602 | + if (isset($this->validFilters[$filterValue])) { |
|
603 | + return $this->validFilters[$filterValue]; |
|
604 | + } |
|
605 | + |
|
606 | + foreach ($this->getExtensions() as $c) { |
|
607 | + if ($c->isFilterValid($filterValue) === true) { |
|
608 | + $this->validFilters[$filterValue] = true; |
|
609 | + return true; |
|
610 | + } |
|
611 | + } |
|
612 | + |
|
613 | + $this->validFilters[$filterValue] = false; |
|
614 | + return false; |
|
615 | + } |
|
616 | + |
|
617 | + /** |
|
618 | + * @param array $types |
|
619 | + * @param string $filter |
|
620 | + * @return array |
|
621 | + * @deprecated 11.0.0 - Use getFilterById()->filterTypes() instead |
|
622 | + */ |
|
623 | + public function filterNotificationTypes($types, $filter) { |
|
624 | + if (!$this->isFilterValid($filter)) { |
|
625 | + return $types; |
|
626 | + } |
|
627 | + |
|
628 | + foreach ($this->getExtensions() as $c) { |
|
629 | + $result = $c->filterNotificationTypes($types, $filter); |
|
630 | + if (is_array($result)) { |
|
631 | + $types = $result; |
|
632 | + } |
|
633 | + } |
|
634 | + return $types; |
|
635 | + } |
|
636 | + |
|
637 | + /** |
|
638 | + * @param string $filter |
|
639 | + * @return array |
|
640 | + * @deprecated 11.0.0 - Use getFilterById() instead |
|
641 | + */ |
|
642 | + public function getQueryForFilter($filter) { |
|
643 | + if (!$this->isFilterValid($filter)) { |
|
644 | + return [null, null]; |
|
645 | + } |
|
646 | + |
|
647 | + $conditions = array(); |
|
648 | + $parameters = array(); |
|
649 | + |
|
650 | + foreach ($this->getExtensions() as $c) { |
|
651 | + $result = $c->getQueryForFilter($filter); |
|
652 | + if (is_array($result)) { |
|
653 | + list($condition, $parameter) = $result; |
|
654 | + if ($condition && is_array($parameter)) { |
|
655 | + $conditions[] = $condition; |
|
656 | + $parameters = array_merge($parameters, $parameter); |
|
657 | + } |
|
658 | + } |
|
659 | + } |
|
660 | + |
|
661 | + if (empty($conditions)) { |
|
662 | + return array(null, null); |
|
663 | + } |
|
664 | + |
|
665 | + return array(' and ((' . implode(') or (', $conditions) . '))', $parameters); |
|
666 | + } |
|
667 | + |
|
668 | + /** |
|
669 | + * Will return additional notification types as specified by other apps |
|
670 | + * |
|
671 | + * @param string $languageCode |
|
672 | + * @return array |
|
673 | + * @deprecated 11.0.0 - Use getSettings() instead |
|
674 | + */ |
|
675 | + public function getNotificationTypes($languageCode) { |
|
676 | + $notificationTypes = $sharingNotificationTypes = []; |
|
677 | + foreach ($this->getExtensions() as $c) { |
|
678 | + $result = $c->getNotificationTypes($languageCode); |
|
679 | + if (is_array($result)) { |
|
680 | + $notificationTypes = array_merge($notificationTypes, $result); |
|
681 | + } |
|
682 | + } |
|
683 | + |
|
684 | + return array_merge($sharingNotificationTypes, $notificationTypes); |
|
685 | + } |
|
686 | + |
|
687 | + /** |
|
688 | + * @param string $method |
|
689 | + * @return array |
|
690 | + * @deprecated 11.0.0 - Use getSettings()->isDefaulEnabled<method>() instead |
|
691 | + */ |
|
692 | + public function getDefaultTypes($method) { |
|
693 | + $defaultTypes = array(); |
|
694 | + foreach ($this->getExtensions() as $c) { |
|
695 | + $types = $c->getDefaultTypes($method); |
|
696 | + if (is_array($types)) { |
|
697 | + $defaultTypes = array_merge($types, $defaultTypes); |
|
698 | + } |
|
699 | + } |
|
700 | + return $defaultTypes; |
|
701 | + } |
|
702 | 702 | } |
@@ -25,99 +25,99 @@ |
||
25 | 25 | |
26 | 26 | class LegacySetting implements ISetting { |
27 | 27 | |
28 | - /** @var string */ |
|
29 | - protected $identifier; |
|
30 | - /** @var string */ |
|
31 | - protected $name; |
|
32 | - /** @var bool */ |
|
33 | - protected $canChangeStream; |
|
34 | - /** @var bool */ |
|
35 | - protected $isDefaultEnabledStream; |
|
36 | - /** @var bool */ |
|
37 | - protected $canChangeMail; |
|
38 | - /** @var bool */ |
|
39 | - protected $isDefaultEnabledMail; |
|
28 | + /** @var string */ |
|
29 | + protected $identifier; |
|
30 | + /** @var string */ |
|
31 | + protected $name; |
|
32 | + /** @var bool */ |
|
33 | + protected $canChangeStream; |
|
34 | + /** @var bool */ |
|
35 | + protected $isDefaultEnabledStream; |
|
36 | + /** @var bool */ |
|
37 | + protected $canChangeMail; |
|
38 | + /** @var bool */ |
|
39 | + protected $isDefaultEnabledMail; |
|
40 | 40 | |
41 | - /** |
|
42 | - * LegacySetting constructor. |
|
43 | - * |
|
44 | - * @param string $identifier |
|
45 | - * @param string $name |
|
46 | - * @param bool $canChangeStream |
|
47 | - * @param bool $isDefaultEnabledStream |
|
48 | - * @param bool $canChangeMail |
|
49 | - * @param bool $isDefaultEnabledMail |
|
50 | - */ |
|
51 | - public function __construct($identifier, |
|
52 | - $name, |
|
53 | - $canChangeStream, |
|
54 | - $isDefaultEnabledStream, |
|
55 | - $canChangeMail, |
|
56 | - $isDefaultEnabledMail) { |
|
57 | - $this->identifier = $identifier; |
|
58 | - $this->name = $name; |
|
59 | - $this->canChangeStream = $canChangeStream; |
|
60 | - $this->isDefaultEnabledStream = $isDefaultEnabledStream; |
|
61 | - $this->canChangeMail = $canChangeMail; |
|
62 | - $this->isDefaultEnabledMail = $isDefaultEnabledMail; |
|
63 | - } |
|
41 | + /** |
|
42 | + * LegacySetting constructor. |
|
43 | + * |
|
44 | + * @param string $identifier |
|
45 | + * @param string $name |
|
46 | + * @param bool $canChangeStream |
|
47 | + * @param bool $isDefaultEnabledStream |
|
48 | + * @param bool $canChangeMail |
|
49 | + * @param bool $isDefaultEnabledMail |
|
50 | + */ |
|
51 | + public function __construct($identifier, |
|
52 | + $name, |
|
53 | + $canChangeStream, |
|
54 | + $isDefaultEnabledStream, |
|
55 | + $canChangeMail, |
|
56 | + $isDefaultEnabledMail) { |
|
57 | + $this->identifier = $identifier; |
|
58 | + $this->name = $name; |
|
59 | + $this->canChangeStream = $canChangeStream; |
|
60 | + $this->isDefaultEnabledStream = $isDefaultEnabledStream; |
|
61 | + $this->canChangeMail = $canChangeMail; |
|
62 | + $this->isDefaultEnabledMail = $isDefaultEnabledMail; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @return string Lowercase a-z and underscore only identifier |
|
67 | - * @since 11.0.0 |
|
68 | - */ |
|
69 | - public function getIdentifier() { |
|
70 | - return $this->identifier; |
|
71 | - } |
|
65 | + /** |
|
66 | + * @return string Lowercase a-z and underscore only identifier |
|
67 | + * @since 11.0.0 |
|
68 | + */ |
|
69 | + public function getIdentifier() { |
|
70 | + return $this->identifier; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * @return string A translated string |
|
75 | - * @since 11.0.0 |
|
76 | - */ |
|
77 | - public function getName() { |
|
78 | - return $this->name; |
|
79 | - } |
|
73 | + /** |
|
74 | + * @return string A translated string |
|
75 | + * @since 11.0.0 |
|
76 | + */ |
|
77 | + public function getName() { |
|
78 | + return $this->name; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @return int whether the filter should be rather on the top or bottom of |
|
83 | - * the admin section. The filters are arranged in ascending order of the |
|
84 | - * priority values. It is required to return a value between 0 and 100. |
|
85 | - * @since 11.0.0 |
|
86 | - */ |
|
87 | - public function getPriority() { |
|
88 | - return 70; |
|
89 | - } |
|
81 | + /** |
|
82 | + * @return int whether the filter should be rather on the top or bottom of |
|
83 | + * the admin section. The filters are arranged in ascending order of the |
|
84 | + * priority values. It is required to return a value between 0 and 100. |
|
85 | + * @since 11.0.0 |
|
86 | + */ |
|
87 | + public function getPriority() { |
|
88 | + return 70; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @return bool True when the option can be changed for the stream |
|
93 | - * @since 11.0.0 |
|
94 | - */ |
|
95 | - public function canChangeStream() { |
|
96 | - return $this->canChangeStream; |
|
97 | - } |
|
91 | + /** |
|
92 | + * @return bool True when the option can be changed for the stream |
|
93 | + * @since 11.0.0 |
|
94 | + */ |
|
95 | + public function canChangeStream() { |
|
96 | + return $this->canChangeStream; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * @return bool True when the option can be changed for the stream |
|
101 | - * @since 11.0.0 |
|
102 | - */ |
|
103 | - public function isDefaultEnabledStream() { |
|
104 | - return $this->isDefaultEnabledStream; |
|
105 | - } |
|
99 | + /** |
|
100 | + * @return bool True when the option can be changed for the stream |
|
101 | + * @since 11.0.0 |
|
102 | + */ |
|
103 | + public function isDefaultEnabledStream() { |
|
104 | + return $this->isDefaultEnabledStream; |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * @return bool True when the option can be changed for the mail |
|
109 | - * @since 11.0.0 |
|
110 | - */ |
|
111 | - public function canChangeMail() { |
|
112 | - return $this->canChangeMail; |
|
113 | - } |
|
107 | + /** |
|
108 | + * @return bool True when the option can be changed for the mail |
|
109 | + * @since 11.0.0 |
|
110 | + */ |
|
111 | + public function canChangeMail() { |
|
112 | + return $this->canChangeMail; |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * @return bool True when the option can be changed for the stream |
|
117 | - * @since 11.0.0 |
|
118 | - */ |
|
119 | - public function isDefaultEnabledMail() { |
|
120 | - return $this->isDefaultEnabledMail; |
|
121 | - } |
|
115 | + /** |
|
116 | + * @return bool True when the option can be changed for the stream |
|
117 | + * @since 11.0.0 |
|
118 | + */ |
|
119 | + public function isDefaultEnabledMail() { |
|
120 | + return $this->isDefaultEnabledMail; |
|
121 | + } |
|
122 | 122 | } |
123 | 123 |
@@ -34,93 +34,93 @@ |
||
34 | 34 | */ |
35 | 35 | class CredentialsManager implements ICredentialsManager { |
36 | 36 | |
37 | - const DB_TABLE = 'credentials'; |
|
37 | + const DB_TABLE = 'credentials'; |
|
38 | 38 | |
39 | - /** @var ICrypto */ |
|
40 | - protected $crypto; |
|
39 | + /** @var ICrypto */ |
|
40 | + protected $crypto; |
|
41 | 41 | |
42 | - /** @var IDBConnection */ |
|
43 | - protected $dbConnection; |
|
42 | + /** @var IDBConnection */ |
|
43 | + protected $dbConnection; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param ICrypto $crypto |
|
47 | - * @param IDBConnection $dbConnection |
|
48 | - */ |
|
49 | - public function __construct(ICrypto $crypto, IDBConnection $dbConnection) { |
|
50 | - $this->crypto = $crypto; |
|
51 | - $this->dbConnection = $dbConnection; |
|
52 | - } |
|
45 | + /** |
|
46 | + * @param ICrypto $crypto |
|
47 | + * @param IDBConnection $dbConnection |
|
48 | + */ |
|
49 | + public function __construct(ICrypto $crypto, IDBConnection $dbConnection) { |
|
50 | + $this->crypto = $crypto; |
|
51 | + $this->dbConnection = $dbConnection; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Store a set of credentials |
|
56 | - * |
|
57 | - * @param string|null $userId Null for system-wide credentials |
|
58 | - * @param string $identifier |
|
59 | - * @param mixed $credentials |
|
60 | - */ |
|
61 | - public function store($userId, $identifier, $credentials) { |
|
62 | - $value = $this->crypto->encrypt(json_encode($credentials)); |
|
54 | + /** |
|
55 | + * Store a set of credentials |
|
56 | + * |
|
57 | + * @param string|null $userId Null for system-wide credentials |
|
58 | + * @param string $identifier |
|
59 | + * @param mixed $credentials |
|
60 | + */ |
|
61 | + public function store($userId, $identifier, $credentials) { |
|
62 | + $value = $this->crypto->encrypt(json_encode($credentials)); |
|
63 | 63 | |
64 | - $this->dbConnection->setValues(self::DB_TABLE, [ |
|
65 | - 'user' => $userId, |
|
66 | - 'identifier' => $identifier, |
|
67 | - ], [ |
|
68 | - 'credentials' => $value, |
|
69 | - ]); |
|
70 | - } |
|
64 | + $this->dbConnection->setValues(self::DB_TABLE, [ |
|
65 | + 'user' => $userId, |
|
66 | + 'identifier' => $identifier, |
|
67 | + ], [ |
|
68 | + 'credentials' => $value, |
|
69 | + ]); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Retrieve a set of credentials |
|
74 | - * |
|
75 | - * @param string|null $userId Null for system-wide credentials |
|
76 | - * @param string $identifier |
|
77 | - * @return mixed |
|
78 | - */ |
|
79 | - public function retrieve($userId, $identifier) { |
|
80 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
81 | - $qb->select('credentials') |
|
82 | - ->from(self::DB_TABLE) |
|
83 | - ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
84 | - ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
|
85 | - ; |
|
86 | - $result = $qb->execute()->fetch(); |
|
72 | + /** |
|
73 | + * Retrieve a set of credentials |
|
74 | + * |
|
75 | + * @param string|null $userId Null for system-wide credentials |
|
76 | + * @param string $identifier |
|
77 | + * @return mixed |
|
78 | + */ |
|
79 | + public function retrieve($userId, $identifier) { |
|
80 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
81 | + $qb->select('credentials') |
|
82 | + ->from(self::DB_TABLE) |
|
83 | + ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
84 | + ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
|
85 | + ; |
|
86 | + $result = $qb->execute()->fetch(); |
|
87 | 87 | |
88 | - if (!$result) { |
|
89 | - return null; |
|
90 | - } |
|
91 | - $value = $result['credentials']; |
|
88 | + if (!$result) { |
|
89 | + return null; |
|
90 | + } |
|
91 | + $value = $result['credentials']; |
|
92 | 92 | |
93 | - return json_decode($this->crypto->decrypt($value), true); |
|
94 | - } |
|
93 | + return json_decode($this->crypto->decrypt($value), true); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Delete a set of credentials |
|
98 | - * |
|
99 | - * @param string|null $userId Null for system-wide credentials |
|
100 | - * @param string $identifier |
|
101 | - * @return int rows removed |
|
102 | - */ |
|
103 | - public function delete($userId, $identifier) { |
|
104 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
105 | - $qb->delete(self::DB_TABLE) |
|
106 | - ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
107 | - ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
|
108 | - ; |
|
109 | - return $qb->execute(); |
|
110 | - } |
|
96 | + /** |
|
97 | + * Delete a set of credentials |
|
98 | + * |
|
99 | + * @param string|null $userId Null for system-wide credentials |
|
100 | + * @param string $identifier |
|
101 | + * @return int rows removed |
|
102 | + */ |
|
103 | + public function delete($userId, $identifier) { |
|
104 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
105 | + $qb->delete(self::DB_TABLE) |
|
106 | + ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
107 | + ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier))) |
|
108 | + ; |
|
109 | + return $qb->execute(); |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Erase all credentials stored for a user |
|
114 | - * |
|
115 | - * @param string $userId |
|
116 | - * @return int rows removed |
|
117 | - */ |
|
118 | - public function erase($userId) { |
|
119 | - $qb = $this->dbConnection->getQueryBuilder(); |
|
120 | - $qb->delete(self::DB_TABLE) |
|
121 | - ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
122 | - ; |
|
123 | - return $qb->execute(); |
|
124 | - } |
|
112 | + /** |
|
113 | + * Erase all credentials stored for a user |
|
114 | + * |
|
115 | + * @param string $userId |
|
116 | + * @return int rows removed |
|
117 | + */ |
|
118 | + public function erase($userId) { |
|
119 | + $qb = $this->dbConnection->getQueryBuilder(); |
|
120 | + $qb->delete(self::DB_TABLE) |
|
121 | + ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId))) |
|
122 | + ; |
|
123 | + return $qb->execute(); |
|
124 | + } |
|
125 | 125 | |
126 | 126 | } |
@@ -27,104 +27,104 @@ |
||
27 | 27 | use OCP\ICertificate; |
28 | 28 | |
29 | 29 | class Certificate implements ICertificate { |
30 | - protected $name; |
|
31 | - |
|
32 | - protected $commonName; |
|
33 | - |
|
34 | - protected $organization; |
|
35 | - |
|
36 | - protected $serial; |
|
37 | - |
|
38 | - protected $issueDate; |
|
39 | - |
|
40 | - protected $expireDate; |
|
41 | - |
|
42 | - protected $issuerName; |
|
43 | - |
|
44 | - protected $issuerOrganization; |
|
45 | - |
|
46 | - /** |
|
47 | - * @param string $data base64 encoded certificate |
|
48 | - * @param string $name |
|
49 | - * @throws \Exception If the certificate could not get parsed |
|
50 | - */ |
|
51 | - public function __construct($data, $name) { |
|
52 | - $this->name = $name; |
|
53 | - $gmt = new \DateTimeZone('GMT'); |
|
54 | - |
|
55 | - // If string starts with "file://" ignore the certificate |
|
56 | - $query = 'file://'; |
|
57 | - if(strtolower(substr($data, 0, strlen($query))) === $query) { |
|
58 | - throw new \Exception('Certificate could not get parsed.'); |
|
59 | - } |
|
60 | - |
|
61 | - $info = openssl_x509_parse($data); |
|
62 | - if(!is_array($info)) { |
|
63 | - throw new \Exception('Certificate could not get parsed.'); |
|
64 | - } |
|
65 | - |
|
66 | - $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null; |
|
67 | - $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null; |
|
68 | - $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt); |
|
69 | - $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt); |
|
70 | - $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null; |
|
71 | - $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - public function getName() { |
|
78 | - return $this->name; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * @return string|null |
|
83 | - */ |
|
84 | - public function getCommonName() { |
|
85 | - return $this->commonName; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public function getOrganization() { |
|
92 | - return $this->organization; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * @return \DateTime |
|
97 | - */ |
|
98 | - public function getIssueDate() { |
|
99 | - return $this->issueDate; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @return \DateTime |
|
104 | - */ |
|
105 | - public function getExpireDate() { |
|
106 | - return $this->expireDate; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @return bool |
|
111 | - */ |
|
112 | - public function isExpired() { |
|
113 | - $now = new \DateTime(); |
|
114 | - return $this->issueDate > $now or $now > $this->expireDate; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @return string|null |
|
119 | - */ |
|
120 | - public function getIssuerName() { |
|
121 | - return $this->issuerName; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @return string|null |
|
126 | - */ |
|
127 | - public function getIssuerOrganization() { |
|
128 | - return $this->issuerOrganization; |
|
129 | - } |
|
30 | + protected $name; |
|
31 | + |
|
32 | + protected $commonName; |
|
33 | + |
|
34 | + protected $organization; |
|
35 | + |
|
36 | + protected $serial; |
|
37 | + |
|
38 | + protected $issueDate; |
|
39 | + |
|
40 | + protected $expireDate; |
|
41 | + |
|
42 | + protected $issuerName; |
|
43 | + |
|
44 | + protected $issuerOrganization; |
|
45 | + |
|
46 | + /** |
|
47 | + * @param string $data base64 encoded certificate |
|
48 | + * @param string $name |
|
49 | + * @throws \Exception If the certificate could not get parsed |
|
50 | + */ |
|
51 | + public function __construct($data, $name) { |
|
52 | + $this->name = $name; |
|
53 | + $gmt = new \DateTimeZone('GMT'); |
|
54 | + |
|
55 | + // If string starts with "file://" ignore the certificate |
|
56 | + $query = 'file://'; |
|
57 | + if(strtolower(substr($data, 0, strlen($query))) === $query) { |
|
58 | + throw new \Exception('Certificate could not get parsed.'); |
|
59 | + } |
|
60 | + |
|
61 | + $info = openssl_x509_parse($data); |
|
62 | + if(!is_array($info)) { |
|
63 | + throw new \Exception('Certificate could not get parsed.'); |
|
64 | + } |
|
65 | + |
|
66 | + $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null; |
|
67 | + $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null; |
|
68 | + $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt); |
|
69 | + $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt); |
|
70 | + $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null; |
|
71 | + $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + public function getName() { |
|
78 | + return $this->name; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * @return string|null |
|
83 | + */ |
|
84 | + public function getCommonName() { |
|
85 | + return $this->commonName; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public function getOrganization() { |
|
92 | + return $this->organization; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * @return \DateTime |
|
97 | + */ |
|
98 | + public function getIssueDate() { |
|
99 | + return $this->issueDate; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @return \DateTime |
|
104 | + */ |
|
105 | + public function getExpireDate() { |
|
106 | + return $this->expireDate; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @return bool |
|
111 | + */ |
|
112 | + public function isExpired() { |
|
113 | + $now = new \DateTime(); |
|
114 | + return $this->issueDate > $now or $now > $this->expireDate; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @return string|null |
|
119 | + */ |
|
120 | + public function getIssuerName() { |
|
121 | + return $this->issuerName; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @return string|null |
|
126 | + */ |
|
127 | + public function getIssuerOrganization() { |
|
128 | + return $this->issuerOrganization; |
|
129 | + } |
|
130 | 130 | } |
@@ -54,19 +54,19 @@ |
||
54 | 54 | |
55 | 55 | // If string starts with "file://" ignore the certificate |
56 | 56 | $query = 'file://'; |
57 | - if(strtolower(substr($data, 0, strlen($query))) === $query) { |
|
57 | + if (strtolower(substr($data, 0, strlen($query))) === $query) { |
|
58 | 58 | throw new \Exception('Certificate could not get parsed.'); |
59 | 59 | } |
60 | 60 | |
61 | 61 | $info = openssl_x509_parse($data); |
62 | - if(!is_array($info)) { |
|
62 | + if (!is_array($info)) { |
|
63 | 63 | throw new \Exception('Certificate could not get parsed.'); |
64 | 64 | } |
65 | 65 | |
66 | 66 | $this->commonName = isset($info['subject']['CN']) ? $info['subject']['CN'] : null; |
67 | 67 | $this->organization = isset($info['subject']['O']) ? $info['subject']['O'] : null; |
68 | - $this->issueDate = new \DateTime('@' . $info['validFrom_time_t'], $gmt); |
|
69 | - $this->expireDate = new \DateTime('@' . $info['validTo_time_t'], $gmt); |
|
68 | + $this->issueDate = new \DateTime('@'.$info['validFrom_time_t'], $gmt); |
|
69 | + $this->expireDate = new \DateTime('@'.$info['validTo_time_t'], $gmt); |
|
70 | 70 | $this->issuerName = isset($info['issuer']['CN']) ? $info['issuer']['CN'] : null; |
71 | 71 | $this->issuerOrganization = isset($info['issuer']['O']) ? $info['issuer']['O'] : null; |
72 | 72 | } |