@@ -47,58 +47,58 @@ |
||
47 | 47 | */ |
48 | 48 | interface IContainer { |
49 | 49 | |
50 | - /** |
|
51 | - * If a parameter is not registered in the container try to instantiate it |
|
52 | - * by using reflection to find out how to build the class |
|
53 | - * @param string $name the class name to resolve |
|
54 | - * @return \stdClass |
|
55 | - * @since 8.2.0 |
|
56 | - * @throws QueryException if the class could not be found or instantiated |
|
57 | - */ |
|
58 | - public function resolve($name); |
|
50 | + /** |
|
51 | + * If a parameter is not registered in the container try to instantiate it |
|
52 | + * by using reflection to find out how to build the class |
|
53 | + * @param string $name the class name to resolve |
|
54 | + * @return \stdClass |
|
55 | + * @since 8.2.0 |
|
56 | + * @throws QueryException if the class could not be found or instantiated |
|
57 | + */ |
|
58 | + public function resolve($name); |
|
59 | 59 | |
60 | - /** |
|
61 | - * Look up a service for a given name in the container. |
|
62 | - * |
|
63 | - * @param string $name |
|
64 | - * @return mixed |
|
65 | - * @throws QueryException if the query could not be resolved |
|
66 | - * @since 6.0.0 |
|
67 | - */ |
|
68 | - public function query($name); |
|
60 | + /** |
|
61 | + * Look up a service for a given name in the container. |
|
62 | + * |
|
63 | + * @param string $name |
|
64 | + * @return mixed |
|
65 | + * @throws QueryException if the query could not be resolved |
|
66 | + * @since 6.0.0 |
|
67 | + */ |
|
68 | + public function query($name); |
|
69 | 69 | |
70 | - /** |
|
71 | - * A value is stored in the container with it's corresponding name |
|
72 | - * |
|
73 | - * @param string $name |
|
74 | - * @param mixed $value |
|
75 | - * @return void |
|
76 | - * @since 6.0.0 |
|
77 | - */ |
|
78 | - public function registerParameter($name, $value); |
|
70 | + /** |
|
71 | + * A value is stored in the container with it's corresponding name |
|
72 | + * |
|
73 | + * @param string $name |
|
74 | + * @param mixed $value |
|
75 | + * @return void |
|
76 | + * @since 6.0.0 |
|
77 | + */ |
|
78 | + public function registerParameter($name, $value); |
|
79 | 79 | |
80 | - /** |
|
81 | - * A service is registered in the container where a closure is passed in which will actually |
|
82 | - * create the service on demand. |
|
83 | - * In case the parameter $shared is set to true (the default usage) the once created service will remain in |
|
84 | - * memory and be reused on subsequent calls. |
|
85 | - * In case the parameter is false the service will be recreated on every call. |
|
86 | - * |
|
87 | - * @param string $name |
|
88 | - * @param \Closure $closure |
|
89 | - * @param bool $shared |
|
90 | - * @return void |
|
91 | - * @since 6.0.0 |
|
92 | - */ |
|
93 | - public function registerService($name, Closure $closure, $shared = true); |
|
80 | + /** |
|
81 | + * A service is registered in the container where a closure is passed in which will actually |
|
82 | + * create the service on demand. |
|
83 | + * In case the parameter $shared is set to true (the default usage) the once created service will remain in |
|
84 | + * memory and be reused on subsequent calls. |
|
85 | + * In case the parameter is false the service will be recreated on every call. |
|
86 | + * |
|
87 | + * @param string $name |
|
88 | + * @param \Closure $closure |
|
89 | + * @param bool $shared |
|
90 | + * @return void |
|
91 | + * @since 6.0.0 |
|
92 | + */ |
|
93 | + public function registerService($name, Closure $closure, $shared = true); |
|
94 | 94 | |
95 | - /** |
|
96 | - * Shortcut for returning a service from a service under a different key, |
|
97 | - * e.g. to tell the container to return a class when queried for an |
|
98 | - * interface |
|
99 | - * @param string $alias the alias that should be registered |
|
100 | - * @param string $target the target that should be resolved instead |
|
101 | - * @since 8.2.0 |
|
102 | - */ |
|
103 | - public function registerAlias($alias, $target); |
|
95 | + /** |
|
96 | + * Shortcut for returning a service from a service under a different key, |
|
97 | + * e.g. to tell the container to return a class when queried for an |
|
98 | + * interface |
|
99 | + * @param string $alias the alias that should be registered |
|
100 | + * @param string $target the target that should be resolved instead |
|
101 | + * @since 8.2.0 |
|
102 | + */ |
|
103 | + public function registerAlias($alias, $target); |
|
104 | 104 | } |
@@ -23,86 +23,86 @@ |
||
23 | 23 | namespace OC; |
24 | 24 | |
25 | 25 | class RedisFactory { |
26 | - /** @var \Redis */ |
|
27 | - private $instance; |
|
26 | + /** @var \Redis */ |
|
27 | + private $instance; |
|
28 | 28 | |
29 | - /** @var SystemConfig */ |
|
30 | - private $config; |
|
29 | + /** @var SystemConfig */ |
|
30 | + private $config; |
|
31 | 31 | |
32 | - /** |
|
33 | - * RedisFactory constructor. |
|
34 | - * |
|
35 | - * @param SystemConfig $config |
|
36 | - */ |
|
37 | - public function __construct(SystemConfig $config) { |
|
38 | - $this->config = $config; |
|
39 | - } |
|
32 | + /** |
|
33 | + * RedisFactory constructor. |
|
34 | + * |
|
35 | + * @param SystemConfig $config |
|
36 | + */ |
|
37 | + public function __construct(SystemConfig $config) { |
|
38 | + $this->config = $config; |
|
39 | + } |
|
40 | 40 | |
41 | - private function create() { |
|
42 | - if ($config = $this->config->getValue('redis.cluster', [])) { |
|
43 | - if (!class_exists('RedisCluster')) { |
|
44 | - throw new \Exception('Redis Cluster support is not available'); |
|
45 | - } |
|
46 | - // cluster config |
|
47 | - if (isset($config['timeout'])) { |
|
48 | - $timeout = $config['timeout']; |
|
49 | - } else { |
|
50 | - $timeout = null; |
|
51 | - } |
|
52 | - if (isset($config['read_timeout'])) { |
|
53 | - $readTimeout = $config['read_timeout']; |
|
54 | - } else { |
|
55 | - $readTimeout = null; |
|
56 | - } |
|
57 | - $this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout); |
|
41 | + private function create() { |
|
42 | + if ($config = $this->config->getValue('redis.cluster', [])) { |
|
43 | + if (!class_exists('RedisCluster')) { |
|
44 | + throw new \Exception('Redis Cluster support is not available'); |
|
45 | + } |
|
46 | + // cluster config |
|
47 | + if (isset($config['timeout'])) { |
|
48 | + $timeout = $config['timeout']; |
|
49 | + } else { |
|
50 | + $timeout = null; |
|
51 | + } |
|
52 | + if (isset($config['read_timeout'])) { |
|
53 | + $readTimeout = $config['read_timeout']; |
|
54 | + } else { |
|
55 | + $readTimeout = null; |
|
56 | + } |
|
57 | + $this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout); |
|
58 | 58 | |
59 | - if (isset($config['failover_mode'])) { |
|
60 | - $this->instance->setOption(\RedisCluster::OPT_SLAVE_FAILOVER, $config['failover_mode']); |
|
61 | - } |
|
62 | - } else { |
|
59 | + if (isset($config['failover_mode'])) { |
|
60 | + $this->instance->setOption(\RedisCluster::OPT_SLAVE_FAILOVER, $config['failover_mode']); |
|
61 | + } |
|
62 | + } else { |
|
63 | 63 | |
64 | - $this->instance = new \Redis(); |
|
65 | - $config = $this->config->getValue('redis', []); |
|
66 | - if (isset($config['host'])) { |
|
67 | - $host = $config['host']; |
|
68 | - } else { |
|
69 | - $host = '127.0.0.1'; |
|
70 | - } |
|
71 | - if (isset($config['port'])) { |
|
72 | - $port = $config['port']; |
|
73 | - } else { |
|
74 | - $port = 6379; |
|
75 | - } |
|
76 | - if (isset($config['timeout'])) { |
|
77 | - $timeout = $config['timeout']; |
|
78 | - } else { |
|
79 | - $timeout = 0.0; // unlimited |
|
80 | - } |
|
64 | + $this->instance = new \Redis(); |
|
65 | + $config = $this->config->getValue('redis', []); |
|
66 | + if (isset($config['host'])) { |
|
67 | + $host = $config['host']; |
|
68 | + } else { |
|
69 | + $host = '127.0.0.1'; |
|
70 | + } |
|
71 | + if (isset($config['port'])) { |
|
72 | + $port = $config['port']; |
|
73 | + } else { |
|
74 | + $port = 6379; |
|
75 | + } |
|
76 | + if (isset($config['timeout'])) { |
|
77 | + $timeout = $config['timeout']; |
|
78 | + } else { |
|
79 | + $timeout = 0.0; // unlimited |
|
80 | + } |
|
81 | 81 | |
82 | - $this->instance->connect($host, $port, $timeout); |
|
83 | - if (isset($config['password']) && $config['password'] !== '') { |
|
84 | - $this->instance->auth($config['password']); |
|
85 | - } |
|
82 | + $this->instance->connect($host, $port, $timeout); |
|
83 | + if (isset($config['password']) && $config['password'] !== '') { |
|
84 | + $this->instance->auth($config['password']); |
|
85 | + } |
|
86 | 86 | |
87 | - if (isset($config['dbindex'])) { |
|
88 | - $this->instance->select($config['dbindex']); |
|
89 | - } |
|
90 | - } |
|
91 | - } |
|
87 | + if (isset($config['dbindex'])) { |
|
88 | + $this->instance->select($config['dbindex']); |
|
89 | + } |
|
90 | + } |
|
91 | + } |
|
92 | 92 | |
93 | - public function getInstance() { |
|
94 | - if (!$this->isAvailable()) { |
|
95 | - throw new \Exception('Redis support is not available'); |
|
96 | - } |
|
97 | - if (!$this->instance instanceof \Redis) { |
|
98 | - $this->create(); |
|
99 | - } |
|
93 | + public function getInstance() { |
|
94 | + if (!$this->isAvailable()) { |
|
95 | + throw new \Exception('Redis support is not available'); |
|
96 | + } |
|
97 | + if (!$this->instance instanceof \Redis) { |
|
98 | + $this->create(); |
|
99 | + } |
|
100 | 100 | |
101 | - return $this->instance; |
|
102 | - } |
|
101 | + return $this->instance; |
|
102 | + } |
|
103 | 103 | |
104 | - public function isAvailable() { |
|
105 | - return extension_loaded('redis') |
|
106 | - && version_compare(phpversion('redis'), '2.2.5', '>='); |
|
107 | - } |
|
104 | + public function isAvailable() { |
|
105 | + return extension_loaded('redis') |
|
106 | + && version_compare(phpversion('redis'), '2.2.5', '>='); |
|
107 | + } |
|
108 | 108 | } |
@@ -7,23 +7,23 @@ |
||
7 | 7 | |
8 | 8 | class RootCollection extends AbstractPrincipalCollection { |
9 | 9 | |
10 | - /** |
|
11 | - * This method returns a node for a principal. |
|
12 | - * |
|
13 | - * The passed array contains principal information, and is guaranteed to |
|
14 | - * at least contain a uri item. Other properties may or may not be |
|
15 | - * supplied by the authentication backend. |
|
16 | - * |
|
17 | - * @param array $principalInfo |
|
18 | - * @return AvatarHome |
|
19 | - */ |
|
20 | - public function getChildForPrincipal(array $principalInfo) { |
|
21 | - $avatarManager = \OC::$server->getAvatarManager(); |
|
22 | - return new AvatarHome($principalInfo, $avatarManager); |
|
23 | - } |
|
10 | + /** |
|
11 | + * This method returns a node for a principal. |
|
12 | + * |
|
13 | + * The passed array contains principal information, and is guaranteed to |
|
14 | + * at least contain a uri item. Other properties may or may not be |
|
15 | + * supplied by the authentication backend. |
|
16 | + * |
|
17 | + * @param array $principalInfo |
|
18 | + * @return AvatarHome |
|
19 | + */ |
|
20 | + public function getChildForPrincipal(array $principalInfo) { |
|
21 | + $avatarManager = \OC::$server->getAvatarManager(); |
|
22 | + return new AvatarHome($principalInfo, $avatarManager); |
|
23 | + } |
|
24 | 24 | |
25 | - public function getName() { |
|
26 | - return 'avatars'; |
|
27 | - } |
|
25 | + public function getName() { |
|
26 | + return 'avatars'; |
|
27 | + } |
|
28 | 28 | |
29 | 29 | } |
@@ -33,87 +33,87 @@ |
||
33 | 33 | |
34 | 34 | class CalDAVRemoveEmptyValue implements IRepairStep { |
35 | 35 | |
36 | - /** @var IDBConnection */ |
|
37 | - private $db; |
|
38 | - |
|
39 | - /** @var CalDavBackend */ |
|
40 | - private $calDavBackend; |
|
41 | - |
|
42 | - /** @var ILogger */ |
|
43 | - private $logger; |
|
44 | - |
|
45 | - /** |
|
46 | - * @param IDBConnection $db |
|
47 | - * @param CalDavBackend $calDavBackend |
|
48 | - * @param ILogger $logger |
|
49 | - */ |
|
50 | - public function __construct(IDBConnection $db, CalDavBackend $calDavBackend, ILogger $logger) { |
|
51 | - $this->db = $db; |
|
52 | - $this->calDavBackend = $calDavBackend; |
|
53 | - $this->logger = $logger; |
|
54 | - } |
|
55 | - |
|
56 | - public function getName() { |
|
57 | - return 'Fix broken values of calendar objects'; |
|
58 | - } |
|
59 | - |
|
60 | - public function run(IOutput $output) { |
|
61 | - $pattern = ';VALUE=:'; |
|
62 | - $count = $warnings = 0; |
|
63 | - |
|
64 | - $objects = $this->getInvalidObjects($pattern); |
|
65 | - |
|
66 | - $output->startProgress(count($objects)); |
|
67 | - foreach ($objects as $row) { |
|
68 | - $calObject = $this->calDavBackend->getCalendarObject((int)$row['calendarid'], $row['uri']); |
|
69 | - $data = preg_replace('/' . $pattern . '/', ':', $calObject['calendardata']); |
|
70 | - |
|
71 | - if ($data !== $calObject['calendardata']) { |
|
72 | - $output->advance(); |
|
73 | - |
|
74 | - try { |
|
75 | - $this->calDavBackend->getDenormalizedData($data); |
|
76 | - } catch (InvalidDataException $e) { |
|
77 | - $this->logger->info('Calendar object for calendar {cal} with uri {uri} still invalid', [ |
|
78 | - 'app' => 'dav', |
|
79 | - 'cal' => (int)$row['calendarid'], |
|
80 | - 'uri' => $row['uri'], |
|
81 | - ]); |
|
82 | - $warnings++; |
|
83 | - continue; |
|
84 | - } |
|
85 | - |
|
86 | - $this->calDavBackend->updateCalendarObject((int)$row['calendarid'], $row['uri'], $data); |
|
87 | - $count++; |
|
88 | - } |
|
89 | - } |
|
90 | - $output->finishProgress(); |
|
91 | - |
|
92 | - if ($warnings > 0) { |
|
93 | - $output->warning(sprintf('%d events could not be updated, see log file for more information', $warnings)); |
|
94 | - } |
|
95 | - if ($count > 0) { |
|
96 | - $output->info(sprintf('Updated %d events', $count)); |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - protected function getInvalidObjects($pattern) { |
|
101 | - $query = $this->db->getQueryBuilder(); |
|
102 | - $query->select(['calendarid', 'uri']) |
|
103 | - ->from('calendarobjects') |
|
104 | - ->where($query->expr()->like( |
|
105 | - 'calendardata', |
|
106 | - $query->createNamedParameter( |
|
107 | - '%' . $this->db->escapeLikeParameter($pattern) . '%', |
|
108 | - IQueryBuilder::PARAM_STR |
|
109 | - ), |
|
110 | - IQueryBuilder::PARAM_STR |
|
111 | - )); |
|
112 | - |
|
113 | - $result = $query->execute(); |
|
114 | - $rows = $result->fetchAll(); |
|
115 | - $result->closeCursor(); |
|
116 | - |
|
117 | - return $rows; |
|
118 | - } |
|
36 | + /** @var IDBConnection */ |
|
37 | + private $db; |
|
38 | + |
|
39 | + /** @var CalDavBackend */ |
|
40 | + private $calDavBackend; |
|
41 | + |
|
42 | + /** @var ILogger */ |
|
43 | + private $logger; |
|
44 | + |
|
45 | + /** |
|
46 | + * @param IDBConnection $db |
|
47 | + * @param CalDavBackend $calDavBackend |
|
48 | + * @param ILogger $logger |
|
49 | + */ |
|
50 | + public function __construct(IDBConnection $db, CalDavBackend $calDavBackend, ILogger $logger) { |
|
51 | + $this->db = $db; |
|
52 | + $this->calDavBackend = $calDavBackend; |
|
53 | + $this->logger = $logger; |
|
54 | + } |
|
55 | + |
|
56 | + public function getName() { |
|
57 | + return 'Fix broken values of calendar objects'; |
|
58 | + } |
|
59 | + |
|
60 | + public function run(IOutput $output) { |
|
61 | + $pattern = ';VALUE=:'; |
|
62 | + $count = $warnings = 0; |
|
63 | + |
|
64 | + $objects = $this->getInvalidObjects($pattern); |
|
65 | + |
|
66 | + $output->startProgress(count($objects)); |
|
67 | + foreach ($objects as $row) { |
|
68 | + $calObject = $this->calDavBackend->getCalendarObject((int)$row['calendarid'], $row['uri']); |
|
69 | + $data = preg_replace('/' . $pattern . '/', ':', $calObject['calendardata']); |
|
70 | + |
|
71 | + if ($data !== $calObject['calendardata']) { |
|
72 | + $output->advance(); |
|
73 | + |
|
74 | + try { |
|
75 | + $this->calDavBackend->getDenormalizedData($data); |
|
76 | + } catch (InvalidDataException $e) { |
|
77 | + $this->logger->info('Calendar object for calendar {cal} with uri {uri} still invalid', [ |
|
78 | + 'app' => 'dav', |
|
79 | + 'cal' => (int)$row['calendarid'], |
|
80 | + 'uri' => $row['uri'], |
|
81 | + ]); |
|
82 | + $warnings++; |
|
83 | + continue; |
|
84 | + } |
|
85 | + |
|
86 | + $this->calDavBackend->updateCalendarObject((int)$row['calendarid'], $row['uri'], $data); |
|
87 | + $count++; |
|
88 | + } |
|
89 | + } |
|
90 | + $output->finishProgress(); |
|
91 | + |
|
92 | + if ($warnings > 0) { |
|
93 | + $output->warning(sprintf('%d events could not be updated, see log file for more information', $warnings)); |
|
94 | + } |
|
95 | + if ($count > 0) { |
|
96 | + $output->info(sprintf('Updated %d events', $count)); |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + protected function getInvalidObjects($pattern) { |
|
101 | + $query = $this->db->getQueryBuilder(); |
|
102 | + $query->select(['calendarid', 'uri']) |
|
103 | + ->from('calendarobjects') |
|
104 | + ->where($query->expr()->like( |
|
105 | + 'calendardata', |
|
106 | + $query->createNamedParameter( |
|
107 | + '%' . $this->db->escapeLikeParameter($pattern) . '%', |
|
108 | + IQueryBuilder::PARAM_STR |
|
109 | + ), |
|
110 | + IQueryBuilder::PARAM_STR |
|
111 | + )); |
|
112 | + |
|
113 | + $result = $query->execute(); |
|
114 | + $rows = $result->fetchAll(); |
|
115 | + $result->closeCursor(); |
|
116 | + |
|
117 | + return $rows; |
|
118 | + } |
|
119 | 119 | } |
@@ -27,21 +27,21 @@ |
||
27 | 27 | |
28 | 28 | class CompFilter implements XmlDeserializable { |
29 | 29 | |
30 | - /** |
|
31 | - * @param Reader $reader |
|
32 | - * @throws BadRequest |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - static function xmlDeserialize(Reader $reader) { |
|
36 | - $att = $reader->parseAttributes(); |
|
37 | - $componentName = $att['name']; |
|
30 | + /** |
|
31 | + * @param Reader $reader |
|
32 | + * @throws BadRequest |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + static function xmlDeserialize(Reader $reader) { |
|
36 | + $att = $reader->parseAttributes(); |
|
37 | + $componentName = $att['name']; |
|
38 | 38 | |
39 | - $reader->parseInnerTree(); |
|
39 | + $reader->parseInnerTree(); |
|
40 | 40 | |
41 | - if (!is_string($componentName)) { |
|
42 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}comp-filter requires a valid name attribute'); |
|
43 | - } |
|
41 | + if (!is_string($componentName)) { |
|
42 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}comp-filter requires a valid name attribute'); |
|
43 | + } |
|
44 | 44 | |
45 | - return $componentName; |
|
46 | - } |
|
45 | + return $componentName; |
|
46 | + } |
|
47 | 47 | } |
@@ -27,17 +27,17 @@ |
||
27 | 27 | |
28 | 28 | class SearchTermFilter implements XmlDeserializable { |
29 | 29 | |
30 | - /** |
|
31 | - * @param Reader $reader |
|
32 | - * @throws BadRequest |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - static function xmlDeserialize(Reader $reader) { |
|
36 | - $value = $reader->parseInnerTree(); |
|
37 | - if (!is_string($value)) { |
|
38 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}search-term has illegal value'); |
|
39 | - } |
|
30 | + /** |
|
31 | + * @param Reader $reader |
|
32 | + * @throws BadRequest |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + static function xmlDeserialize(Reader $reader) { |
|
36 | + $value = $reader->parseInnerTree(); |
|
37 | + if (!is_string($value)) { |
|
38 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}search-term has illegal value'); |
|
39 | + } |
|
40 | 40 | |
41 | - return $value; |
|
42 | - } |
|
41 | + return $value; |
|
42 | + } |
|
43 | 43 | } |
44 | 44 | \ No newline at end of file |
@@ -27,21 +27,21 @@ |
||
27 | 27 | |
28 | 28 | class PropFilter implements XmlDeserializable { |
29 | 29 | |
30 | - /** |
|
31 | - * @param Reader $reader |
|
32 | - * @throws BadRequest |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - static function xmlDeserialize(Reader $reader) { |
|
36 | - $att = $reader->parseAttributes(); |
|
37 | - $componentName = $att['name']; |
|
30 | + /** |
|
31 | + * @param Reader $reader |
|
32 | + * @throws BadRequest |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + static function xmlDeserialize(Reader $reader) { |
|
36 | + $att = $reader->parseAttributes(); |
|
37 | + $componentName = $att['name']; |
|
38 | 38 | |
39 | - $reader->parseInnerTree(); |
|
39 | + $reader->parseInnerTree(); |
|
40 | 40 | |
41 | - if (!is_string($componentName)) { |
|
42 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}prop-filter requires a valid name attribute'); |
|
43 | - } |
|
41 | + if (!is_string($componentName)) { |
|
42 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}prop-filter requires a valid name attribute'); |
|
43 | + } |
|
44 | 44 | |
45 | - return $componentName; |
|
46 | - } |
|
45 | + return $componentName; |
|
46 | + } |
|
47 | 47 | } |
@@ -27,29 +27,29 @@ |
||
27 | 27 | |
28 | 28 | class ParamFilter implements XmlDeserializable { |
29 | 29 | |
30 | - /** |
|
31 | - * @param Reader $reader |
|
32 | - * @throws BadRequest |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - static function xmlDeserialize(Reader $reader) { |
|
36 | - $att = $reader->parseAttributes(); |
|
37 | - $property = $att['property']; |
|
38 | - $parameter = $att['name']; |
|
30 | + /** |
|
31 | + * @param Reader $reader |
|
32 | + * @throws BadRequest |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + static function xmlDeserialize(Reader $reader) { |
|
36 | + $att = $reader->parseAttributes(); |
|
37 | + $property = $att['property']; |
|
38 | + $parameter = $att['name']; |
|
39 | 39 | |
40 | - $reader->parseInnerTree(); |
|
40 | + $reader->parseInnerTree(); |
|
41 | 41 | |
42 | - if (!is_string($property)) { |
|
43 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}param-filter requires a valid property attribute'); |
|
42 | + if (!is_string($property)) { |
|
43 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}param-filter requires a valid property attribute'); |
|
44 | 44 | |
45 | - } |
|
46 | - if (!is_string($parameter)) { |
|
47 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}param-filter requires a valid parameter attribute'); |
|
48 | - } |
|
45 | + } |
|
46 | + if (!is_string($parameter)) { |
|
47 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}param-filter requires a valid parameter attribute'); |
|
48 | + } |
|
49 | 49 | |
50 | - return [ |
|
51 | - 'property' => $property, |
|
52 | - 'parameter' => $parameter, |
|
53 | - ]; |
|
54 | - } |
|
50 | + return [ |
|
51 | + 'property' => $property, |
|
52 | + 'parameter' => $parameter, |
|
53 | + ]; |
|
54 | + } |
|
55 | 55 | } |
@@ -27,230 +27,230 @@ |
||
27 | 27 | |
28 | 28 | class EventMerger implements IEventMerger { |
29 | 29 | |
30 | - /** @var IL10N */ |
|
31 | - protected $l10n; |
|
30 | + /** @var IL10N */ |
|
31 | + protected $l10n; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @param IL10N $l10n |
|
35 | - */ |
|
36 | - public function __construct(IL10N $l10n) { |
|
37 | - $this->l10n = $l10n; |
|
38 | - } |
|
33 | + /** |
|
34 | + * @param IL10N $l10n |
|
35 | + */ |
|
36 | + public function __construct(IL10N $l10n) { |
|
37 | + $this->l10n = $l10n; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Combines two events when possible to have grouping: |
|
42 | - * |
|
43 | - * Example1: Two events with subject '{user} created {file}' and |
|
44 | - * $mergeParameter file with different file and same user will be merged |
|
45 | - * to '{user} created {file1} and {file2}' and the childEvent on the return |
|
46 | - * will be set, if the events have been merged. |
|
47 | - * |
|
48 | - * Example2: Two events with subject '{user} created {file}' and |
|
49 | - * $mergeParameter file with same file and same user will be merged to |
|
50 | - * '{user} created {file1}' and the childEvent on the return will be set, if |
|
51 | - * the events have been merged. |
|
52 | - * |
|
53 | - * The following requirements have to be met, in order to be merged: |
|
54 | - * - Both events need to have the same `getApp()` |
|
55 | - * - Both events must not have a message `getMessage()` |
|
56 | - * - Both events need to have the same subject `getSubject()` |
|
57 | - * - Both events need to have the same object type `getObjectType()` |
|
58 | - * - The time difference between both events must not be bigger then 3 hours |
|
59 | - * - Only up to 5 events can be merged. |
|
60 | - * - All parameters apart from such starting with $mergeParameter must be |
|
61 | - * the same for both events. |
|
62 | - * |
|
63 | - * @param string $mergeParameter |
|
64 | - * @param IEvent $event |
|
65 | - * @param IEvent|null $previousEvent |
|
66 | - * @return IEvent |
|
67 | - */ |
|
68 | - public function mergeEvents($mergeParameter, IEvent $event, IEvent $previousEvent = null) { |
|
69 | - // No second event => can not combine |
|
70 | - if (!$previousEvent instanceof IEvent) { |
|
71 | - return $event; |
|
72 | - } |
|
40 | + /** |
|
41 | + * Combines two events when possible to have grouping: |
|
42 | + * |
|
43 | + * Example1: Two events with subject '{user} created {file}' and |
|
44 | + * $mergeParameter file with different file and same user will be merged |
|
45 | + * to '{user} created {file1} and {file2}' and the childEvent on the return |
|
46 | + * will be set, if the events have been merged. |
|
47 | + * |
|
48 | + * Example2: Two events with subject '{user} created {file}' and |
|
49 | + * $mergeParameter file with same file and same user will be merged to |
|
50 | + * '{user} created {file1}' and the childEvent on the return will be set, if |
|
51 | + * the events have been merged. |
|
52 | + * |
|
53 | + * The following requirements have to be met, in order to be merged: |
|
54 | + * - Both events need to have the same `getApp()` |
|
55 | + * - Both events must not have a message `getMessage()` |
|
56 | + * - Both events need to have the same subject `getSubject()` |
|
57 | + * - Both events need to have the same object type `getObjectType()` |
|
58 | + * - The time difference between both events must not be bigger then 3 hours |
|
59 | + * - Only up to 5 events can be merged. |
|
60 | + * - All parameters apart from such starting with $mergeParameter must be |
|
61 | + * the same for both events. |
|
62 | + * |
|
63 | + * @param string $mergeParameter |
|
64 | + * @param IEvent $event |
|
65 | + * @param IEvent|null $previousEvent |
|
66 | + * @return IEvent |
|
67 | + */ |
|
68 | + public function mergeEvents($mergeParameter, IEvent $event, IEvent $previousEvent = null) { |
|
69 | + // No second event => can not combine |
|
70 | + if (!$previousEvent instanceof IEvent) { |
|
71 | + return $event; |
|
72 | + } |
|
73 | 73 | |
74 | - // Different app => can not combine |
|
75 | - if ($event->getApp() !== $previousEvent->getApp()) { |
|
76 | - return $event; |
|
77 | - } |
|
74 | + // Different app => can not combine |
|
75 | + if ($event->getApp() !== $previousEvent->getApp()) { |
|
76 | + return $event; |
|
77 | + } |
|
78 | 78 | |
79 | - // Message is set => can not combine |
|
80 | - if ($event->getMessage() !== '' || $previousEvent->getMessage() !== '') { |
|
81 | - return $event; |
|
82 | - } |
|
79 | + // Message is set => can not combine |
|
80 | + if ($event->getMessage() !== '' || $previousEvent->getMessage() !== '') { |
|
81 | + return $event; |
|
82 | + } |
|
83 | 83 | |
84 | - // Different subject => can not combine |
|
85 | - if ($event->getSubject() !== $previousEvent->getSubject()) { |
|
86 | - return $event; |
|
87 | - } |
|
84 | + // Different subject => can not combine |
|
85 | + if ($event->getSubject() !== $previousEvent->getSubject()) { |
|
86 | + return $event; |
|
87 | + } |
|
88 | 88 | |
89 | - // Different object type => can not combine |
|
90 | - if ($event->getObjectType() !== $previousEvent->getObjectType()) { |
|
91 | - return $event; |
|
92 | - } |
|
89 | + // Different object type => can not combine |
|
90 | + if ($event->getObjectType() !== $previousEvent->getObjectType()) { |
|
91 | + return $event; |
|
92 | + } |
|
93 | 93 | |
94 | - // More than 3 hours difference => can not combine |
|
95 | - if (abs($event->getTimestamp() - $previousEvent->getTimestamp()) > 3 * 60 * 60) { |
|
96 | - return $event; |
|
97 | - } |
|
94 | + // More than 3 hours difference => can not combine |
|
95 | + if (abs($event->getTimestamp() - $previousEvent->getTimestamp()) > 3 * 60 * 60) { |
|
96 | + return $event; |
|
97 | + } |
|
98 | 98 | |
99 | - // Other parameters are not the same => can not combine |
|
100 | - try { |
|
101 | - list($combined, $parameters) = $this->combineParameters($mergeParameter, $event, $previousEvent); |
|
102 | - } catch (\UnexpectedValueException $e) { |
|
103 | - return $event; |
|
104 | - } |
|
99 | + // Other parameters are not the same => can not combine |
|
100 | + try { |
|
101 | + list($combined, $parameters) = $this->combineParameters($mergeParameter, $event, $previousEvent); |
|
102 | + } catch (\UnexpectedValueException $e) { |
|
103 | + return $event; |
|
104 | + } |
|
105 | 105 | |
106 | - try { |
|
107 | - $newSubject = $this->getExtendedSubject($event->getRichSubject(), $mergeParameter, $combined); |
|
108 | - $parsedSubject = $this->generateParsedSubject($newSubject, $parameters); |
|
106 | + try { |
|
107 | + $newSubject = $this->getExtendedSubject($event->getRichSubject(), $mergeParameter, $combined); |
|
108 | + $parsedSubject = $this->generateParsedSubject($newSubject, $parameters); |
|
109 | 109 | |
110 | - $event->setRichSubject($newSubject, $parameters) |
|
111 | - ->setParsedSubject($parsedSubject) |
|
112 | - ->setChildEvent($previousEvent); |
|
113 | - } catch (\UnexpectedValueException $e) { |
|
114 | - return $event; |
|
115 | - } |
|
110 | + $event->setRichSubject($newSubject, $parameters) |
|
111 | + ->setParsedSubject($parsedSubject) |
|
112 | + ->setChildEvent($previousEvent); |
|
113 | + } catch (\UnexpectedValueException $e) { |
|
114 | + return $event; |
|
115 | + } |
|
116 | 116 | |
117 | - return $event; |
|
118 | - } |
|
117 | + return $event; |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * @param string $mergeParameter |
|
122 | - * @param IEvent $event |
|
123 | - * @param IEvent $previousEvent |
|
124 | - * @return array |
|
125 | - * @throws \UnexpectedValueException |
|
126 | - */ |
|
127 | - protected function combineParameters($mergeParameter, IEvent $event, IEvent $previousEvent) { |
|
128 | - $params1 = $event->getRichSubjectParameters(); |
|
129 | - $params2 = $previousEvent->getRichSubjectParameters(); |
|
130 | - $params = []; |
|
120 | + /** |
|
121 | + * @param string $mergeParameter |
|
122 | + * @param IEvent $event |
|
123 | + * @param IEvent $previousEvent |
|
124 | + * @return array |
|
125 | + * @throws \UnexpectedValueException |
|
126 | + */ |
|
127 | + protected function combineParameters($mergeParameter, IEvent $event, IEvent $previousEvent) { |
|
128 | + $params1 = $event->getRichSubjectParameters(); |
|
129 | + $params2 = $previousEvent->getRichSubjectParameters(); |
|
130 | + $params = []; |
|
131 | 131 | |
132 | - $combined = 0; |
|
132 | + $combined = 0; |
|
133 | 133 | |
134 | - // Check that all parameters from $event exist in $previousEvent |
|
135 | - foreach ($params1 as $key => $parameter) { |
|
136 | - if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
137 | - if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { |
|
138 | - $combined++; |
|
139 | - $params[$mergeParameter . $combined] = $parameter; |
|
140 | - } |
|
141 | - continue; |
|
142 | - } |
|
134 | + // Check that all parameters from $event exist in $previousEvent |
|
135 | + foreach ($params1 as $key => $parameter) { |
|
136 | + if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
137 | + if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { |
|
138 | + $combined++; |
|
139 | + $params[$mergeParameter . $combined] = $parameter; |
|
140 | + } |
|
141 | + continue; |
|
142 | + } |
|
143 | 143 | |
144 | - if (!isset($params2[$key]) || $params2[$key] !== $parameter) { |
|
145 | - // Parameter missing on $previousEvent or different => can not combine |
|
146 | - throw new \UnexpectedValueException(); |
|
147 | - } |
|
144 | + if (!isset($params2[$key]) || $params2[$key] !== $parameter) { |
|
145 | + // Parameter missing on $previousEvent or different => can not combine |
|
146 | + throw new \UnexpectedValueException(); |
|
147 | + } |
|
148 | 148 | |
149 | - $params[$key] = $parameter; |
|
150 | - } |
|
149 | + $params[$key] = $parameter; |
|
150 | + } |
|
151 | 151 | |
152 | - // Check that all parameters from $previousEvent exist in $event |
|
153 | - foreach ($params2 as $key => $parameter) { |
|
154 | - if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
155 | - if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { |
|
156 | - $combined++; |
|
157 | - $params[$mergeParameter . $combined] = $parameter; |
|
158 | - } |
|
159 | - continue; |
|
160 | - } |
|
152 | + // Check that all parameters from $previousEvent exist in $event |
|
153 | + foreach ($params2 as $key => $parameter) { |
|
154 | + if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
155 | + if (!$this->checkParameterAlreadyExits($params, $mergeParameter, $parameter)) { |
|
156 | + $combined++; |
|
157 | + $params[$mergeParameter . $combined] = $parameter; |
|
158 | + } |
|
159 | + continue; |
|
160 | + } |
|
161 | 161 | |
162 | - if (!isset($params1[$key]) || $params1[$key] !== $parameter) { |
|
163 | - // Parameter missing on $event or different => can not combine |
|
164 | - throw new \UnexpectedValueException(); |
|
165 | - } |
|
162 | + if (!isset($params1[$key]) || $params1[$key] !== $parameter) { |
|
163 | + // Parameter missing on $event or different => can not combine |
|
164 | + throw new \UnexpectedValueException(); |
|
165 | + } |
|
166 | 166 | |
167 | - $params[$key] = $parameter; |
|
168 | - } |
|
167 | + $params[$key] = $parameter; |
|
168 | + } |
|
169 | 169 | |
170 | - return [$combined, $params]; |
|
171 | - } |
|
170 | + return [$combined, $params]; |
|
171 | + } |
|
172 | 172 | |
173 | - /** |
|
174 | - * @param array[] $parameters |
|
175 | - * @param string $mergeParameter |
|
176 | - * @param array $parameter |
|
177 | - * @return bool |
|
178 | - */ |
|
179 | - protected function checkParameterAlreadyExits($parameters, $mergeParameter, $parameter) { |
|
180 | - foreach ($parameters as $key => $param) { |
|
181 | - if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
182 | - if ($param === $parameter) { |
|
183 | - return true; |
|
184 | - } |
|
185 | - } |
|
186 | - } |
|
187 | - return false; |
|
188 | - } |
|
173 | + /** |
|
174 | + * @param array[] $parameters |
|
175 | + * @param string $mergeParameter |
|
176 | + * @param array $parameter |
|
177 | + * @return bool |
|
178 | + */ |
|
179 | + protected function checkParameterAlreadyExits($parameters, $mergeParameter, $parameter) { |
|
180 | + foreach ($parameters as $key => $param) { |
|
181 | + if (preg_match('/^' . $mergeParameter . '(\d+)?$/', $key)) { |
|
182 | + if ($param === $parameter) { |
|
183 | + return true; |
|
184 | + } |
|
185 | + } |
|
186 | + } |
|
187 | + return false; |
|
188 | + } |
|
189 | 189 | |
190 | - /** |
|
191 | - * @param string $subject |
|
192 | - * @param string $parameter |
|
193 | - * @param int $counter |
|
194 | - * @return mixed |
|
195 | - */ |
|
196 | - protected function getExtendedSubject($subject, $parameter, $counter) { |
|
197 | - switch ($counter) { |
|
198 | - case 1: |
|
199 | - $replacement = '{' . $parameter . '1}'; |
|
200 | - break; |
|
201 | - case 2: |
|
202 | - $replacement = $this->l10n->t( |
|
203 | - '%1$s and %2$s', |
|
204 | - ['{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
205 | - ); |
|
206 | - break; |
|
207 | - case 3: |
|
208 | - $replacement = $this->l10n->t( |
|
209 | - '%1$s, %2$s and %3$s', |
|
210 | - ['{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
211 | - ); |
|
212 | - break; |
|
213 | - case 4: |
|
214 | - $replacement = $this->l10n->t( |
|
215 | - '%1$s, %2$s, %3$s and %4$s', |
|
216 | - ['{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
217 | - ); |
|
218 | - break; |
|
219 | - case 5: |
|
220 | - $replacement = $this->l10n->t( |
|
221 | - '%1$s, %2$s, %3$s, %4$s and %5$s', |
|
222 | - ['{' . $parameter . '5}', '{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
223 | - ); |
|
224 | - break; |
|
225 | - default: |
|
226 | - throw new \UnexpectedValueException(); |
|
227 | - } |
|
190 | + /** |
|
191 | + * @param string $subject |
|
192 | + * @param string $parameter |
|
193 | + * @param int $counter |
|
194 | + * @return mixed |
|
195 | + */ |
|
196 | + protected function getExtendedSubject($subject, $parameter, $counter) { |
|
197 | + switch ($counter) { |
|
198 | + case 1: |
|
199 | + $replacement = '{' . $parameter . '1}'; |
|
200 | + break; |
|
201 | + case 2: |
|
202 | + $replacement = $this->l10n->t( |
|
203 | + '%1$s and %2$s', |
|
204 | + ['{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
205 | + ); |
|
206 | + break; |
|
207 | + case 3: |
|
208 | + $replacement = $this->l10n->t( |
|
209 | + '%1$s, %2$s and %3$s', |
|
210 | + ['{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
211 | + ); |
|
212 | + break; |
|
213 | + case 4: |
|
214 | + $replacement = $this->l10n->t( |
|
215 | + '%1$s, %2$s, %3$s and %4$s', |
|
216 | + ['{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
217 | + ); |
|
218 | + break; |
|
219 | + case 5: |
|
220 | + $replacement = $this->l10n->t( |
|
221 | + '%1$s, %2$s, %3$s, %4$s and %5$s', |
|
222 | + ['{' . $parameter . '5}', '{' . $parameter . '4}', '{' . $parameter . '3}', '{' . $parameter . '2}', '{' . $parameter . '1}'] |
|
223 | + ); |
|
224 | + break; |
|
225 | + default: |
|
226 | + throw new \UnexpectedValueException(); |
|
227 | + } |
|
228 | 228 | |
229 | - return str_replace( |
|
230 | - '{' . $parameter . '}', |
|
231 | - $replacement, |
|
232 | - $subject |
|
233 | - ); |
|
234 | - } |
|
229 | + return str_replace( |
|
230 | + '{' . $parameter . '}', |
|
231 | + $replacement, |
|
232 | + $subject |
|
233 | + ); |
|
234 | + } |
|
235 | 235 | |
236 | - /** |
|
237 | - * @param string $subject |
|
238 | - * @param array[] $parameters |
|
239 | - * @return string |
|
240 | - */ |
|
241 | - protected function generateParsedSubject($subject, $parameters) { |
|
242 | - $placeholders = $replacements = []; |
|
243 | - foreach ($parameters as $placeholder => $parameter) { |
|
244 | - $placeholders[] = '{' . $placeholder . '}'; |
|
245 | - if ($parameter['type'] === 'file') { |
|
246 | - $replacements[] = trim($parameter['path'], '/'); |
|
247 | - } else if (isset($parameter['name'])) { |
|
248 | - $replacements[] = $parameter['name']; |
|
249 | - } else { |
|
250 | - $replacements[] = $parameter['id']; |
|
251 | - } |
|
252 | - } |
|
236 | + /** |
|
237 | + * @param string $subject |
|
238 | + * @param array[] $parameters |
|
239 | + * @return string |
|
240 | + */ |
|
241 | + protected function generateParsedSubject($subject, $parameters) { |
|
242 | + $placeholders = $replacements = []; |
|
243 | + foreach ($parameters as $placeholder => $parameter) { |
|
244 | + $placeholders[] = '{' . $placeholder . '}'; |
|
245 | + if ($parameter['type'] === 'file') { |
|
246 | + $replacements[] = trim($parameter['path'], '/'); |
|
247 | + } else if (isset($parameter['name'])) { |
|
248 | + $replacements[] = $parameter['name']; |
|
249 | + } else { |
|
250 | + $replacements[] = $parameter['id']; |
|
251 | + } |
|
252 | + } |
|
253 | 253 | |
254 | - return str_replace($placeholders, $replacements, $subject); |
|
255 | - } |
|
254 | + return str_replace($placeholders, $replacements, $subject); |
|
255 | + } |
|
256 | 256 | } |