@@ -31,36 +31,36 @@ |
||
31 | 31 | |
32 | 32 | class SyncSystemAddressBook extends Command { |
33 | 33 | |
34 | - /** @var SyncService */ |
|
35 | - private $syncService; |
|
34 | + /** @var SyncService */ |
|
35 | + private $syncService; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param SyncService $syncService |
|
39 | - */ |
|
40 | - function __construct(SyncService $syncService) { |
|
41 | - parent::__construct(); |
|
42 | - $this->syncService = $syncService; |
|
43 | - } |
|
37 | + /** |
|
38 | + * @param SyncService $syncService |
|
39 | + */ |
|
40 | + function __construct(SyncService $syncService) { |
|
41 | + parent::__construct(); |
|
42 | + $this->syncService = $syncService; |
|
43 | + } |
|
44 | 44 | |
45 | - protected function configure() { |
|
46 | - $this |
|
47 | - ->setName('dav:sync-system-addressbook') |
|
48 | - ->setDescription('Synchronizes users to the system addressbook'); |
|
49 | - } |
|
45 | + protected function configure() { |
|
46 | + $this |
|
47 | + ->setName('dav:sync-system-addressbook') |
|
48 | + ->setDescription('Synchronizes users to the system addressbook'); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param InputInterface $input |
|
53 | - * @param OutputInterface $output |
|
54 | - */ |
|
55 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
56 | - $output->writeln('Syncing users ...'); |
|
57 | - $progress = new ProgressBar($output); |
|
58 | - $progress->start(); |
|
59 | - $this->syncService->syncInstance(function() use ($progress) { |
|
60 | - $progress->advance(); |
|
61 | - }); |
|
51 | + /** |
|
52 | + * @param InputInterface $input |
|
53 | + * @param OutputInterface $output |
|
54 | + */ |
|
55 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
56 | + $output->writeln('Syncing users ...'); |
|
57 | + $progress = new ProgressBar($output); |
|
58 | + $progress->start(); |
|
59 | + $this->syncService->syncInstance(function() use ($progress) { |
|
60 | + $progress->advance(); |
|
61 | + }); |
|
62 | 62 | |
63 | - $progress->finish(); |
|
64 | - $output->writeln(''); |
|
65 | - } |
|
63 | + $progress->finish(); |
|
64 | + $output->writeln(''); |
|
65 | + } |
|
66 | 66 | } |
@@ -36,43 +36,43 @@ |
||
36 | 36 | |
37 | 37 | class CreateAddressBook extends Command { |
38 | 38 | |
39 | - /** @var IUserManager */ |
|
40 | - private $userManager; |
|
39 | + /** @var IUserManager */ |
|
40 | + private $userManager; |
|
41 | 41 | |
42 | - /** @var CardDavBackend */ |
|
43 | - private $cardDavBackend; |
|
42 | + /** @var CardDavBackend */ |
|
43 | + private $cardDavBackend; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param IUserManager $userManager |
|
47 | - * @param CardDavBackend $cardDavBackend |
|
48 | - */ |
|
49 | - function __construct(IUserManager $userManager, |
|
50 | - CardDavBackend $cardDavBackend |
|
51 | - ) { |
|
52 | - parent::__construct(); |
|
53 | - $this->userManager = $userManager; |
|
54 | - $this->cardDavBackend = $cardDavBackend; |
|
55 | - } |
|
45 | + /** |
|
46 | + * @param IUserManager $userManager |
|
47 | + * @param CardDavBackend $cardDavBackend |
|
48 | + */ |
|
49 | + function __construct(IUserManager $userManager, |
|
50 | + CardDavBackend $cardDavBackend |
|
51 | + ) { |
|
52 | + parent::__construct(); |
|
53 | + $this->userManager = $userManager; |
|
54 | + $this->cardDavBackend = $cardDavBackend; |
|
55 | + } |
|
56 | 56 | |
57 | - protected function configure() { |
|
58 | - $this |
|
59 | - ->setName('dav:create-addressbook') |
|
60 | - ->setDescription('Create a dav addressbook') |
|
61 | - ->addArgument('user', |
|
62 | - InputArgument::REQUIRED, |
|
63 | - 'User for whom the addressbook will be created') |
|
64 | - ->addArgument('name', |
|
65 | - InputArgument::REQUIRED, |
|
66 | - 'Name of the addressbook'); |
|
67 | - } |
|
57 | + protected function configure() { |
|
58 | + $this |
|
59 | + ->setName('dav:create-addressbook') |
|
60 | + ->setDescription('Create a dav addressbook') |
|
61 | + ->addArgument('user', |
|
62 | + InputArgument::REQUIRED, |
|
63 | + 'User for whom the addressbook will be created') |
|
64 | + ->addArgument('name', |
|
65 | + InputArgument::REQUIRED, |
|
66 | + 'Name of the addressbook'); |
|
67 | + } |
|
68 | 68 | |
69 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
70 | - $user = $input->getArgument('user'); |
|
71 | - if (!$this->userManager->userExists($user)) { |
|
72 | - throw new \InvalidArgumentException("User <$user> in unknown."); |
|
73 | - } |
|
69 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
70 | + $user = $input->getArgument('user'); |
|
71 | + if (!$this->userManager->userExists($user)) { |
|
72 | + throw new \InvalidArgumentException("User <$user> in unknown."); |
|
73 | + } |
|
74 | 74 | |
75 | - $name = $input->getArgument('name'); |
|
76 | - $this->cardDavBackend->createAddressBook("principals/users/$user", $name, []); |
|
77 | - } |
|
75 | + $name = $input->getArgument('name'); |
|
76 | + $this->cardDavBackend->createAddressBook("principals/users/$user", $name, []); |
|
77 | + } |
|
78 | 78 | } |
@@ -32,238 +32,238 @@ |
||
32 | 32 | |
33 | 33 | class CustomPropertiesBackend implements BackendInterface { |
34 | 34 | |
35 | - /** |
|
36 | - * Ignored properties |
|
37 | - * |
|
38 | - * @var array |
|
39 | - */ |
|
40 | - private $ignoredProperties = array( |
|
41 | - '{DAV:}getcontentlength', |
|
42 | - '{DAV:}getcontenttype', |
|
43 | - '{DAV:}getetag', |
|
44 | - '{DAV:}quota-used-bytes', |
|
45 | - '{DAV:}quota-available-bytes', |
|
46 | - '{http://owncloud.org/ns}permissions', |
|
47 | - '{http://owncloud.org/ns}downloadURL', |
|
48 | - '{http://owncloud.org/ns}dDC', |
|
49 | - '{http://owncloud.org/ns}size', |
|
50 | - ); |
|
51 | - |
|
52 | - /** |
|
53 | - * @var Tree |
|
54 | - */ |
|
55 | - private $tree; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var IDBConnection |
|
59 | - */ |
|
60 | - private $connection; |
|
61 | - |
|
62 | - /** |
|
63 | - * @var string |
|
64 | - */ |
|
65 | - private $user; |
|
66 | - |
|
67 | - /** |
|
68 | - * Properties cache |
|
69 | - * |
|
70 | - * @var array |
|
71 | - */ |
|
72 | - private $cache = []; |
|
73 | - |
|
74 | - /** |
|
75 | - * @param Tree $tree node tree |
|
76 | - * @param IDBConnection $connection database connection |
|
77 | - * @param IUser $user owner of the tree and properties |
|
78 | - */ |
|
79 | - public function __construct( |
|
80 | - Tree $tree, |
|
81 | - IDBConnection $connection, |
|
82 | - IUser $user) { |
|
83 | - $this->tree = $tree; |
|
84 | - $this->connection = $connection; |
|
85 | - $this->user = $user->getUID(); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Fetches properties for a path. |
|
90 | - * |
|
91 | - * @param string $path |
|
92 | - * @param PropFind $propFind |
|
93 | - * @return void |
|
94 | - */ |
|
95 | - public function propFind($path, PropFind $propFind) { |
|
96 | - |
|
97 | - $requestedProps = $propFind->get404Properties(); |
|
98 | - |
|
99 | - // these might appear |
|
100 | - $requestedProps = array_diff( |
|
101 | - $requestedProps, |
|
102 | - $this->ignoredProperties |
|
103 | - ); |
|
104 | - |
|
105 | - if (empty($requestedProps)) { |
|
106 | - return; |
|
107 | - } |
|
108 | - |
|
109 | - $props = $this->getProperties($path, $requestedProps); |
|
110 | - foreach ($props as $propName => $propValue) { |
|
111 | - $propFind->set($propName, $propValue); |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Updates properties for a path |
|
117 | - * |
|
118 | - * @param string $path |
|
119 | - * @param PropPatch $propPatch |
|
120 | - * |
|
121 | - * @return void |
|
122 | - */ |
|
123 | - public function propPatch($path, PropPatch $propPatch) { |
|
124 | - $propPatch->handleRemaining(function($changedProps) use ($path) { |
|
125 | - return $this->updateProperties($path, $changedProps); |
|
126 | - }); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * This method is called after a node is deleted. |
|
131 | - * |
|
132 | - * @param string $path path of node for which to delete properties |
|
133 | - */ |
|
134 | - public function delete($path) { |
|
135 | - $statement = $this->connection->prepare( |
|
136 | - 'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?' |
|
137 | - ); |
|
138 | - $statement->execute(array($this->user, $path)); |
|
139 | - $statement->closeCursor(); |
|
140 | - |
|
141 | - unset($this->cache[$path]); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * This method is called after a successful MOVE |
|
146 | - * |
|
147 | - * @param string $source |
|
148 | - * @param string $destination |
|
149 | - * |
|
150 | - * @return void |
|
151 | - */ |
|
152 | - public function move($source, $destination) { |
|
153 | - $statement = $this->connection->prepare( |
|
154 | - 'UPDATE `*PREFIX*properties` SET `propertypath` = ?' . |
|
155 | - ' WHERE `userid` = ? AND `propertypath` = ?' |
|
156 | - ); |
|
157 | - $statement->execute(array($destination, $this->user, $source)); |
|
158 | - $statement->closeCursor(); |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * Returns a list of properties for this nodes.; |
|
163 | - * @param string $path |
|
164 | - * @param array $requestedProperties requested properties or empty array for "all" |
|
165 | - * @return array |
|
166 | - * @note The properties list is a list of propertynames the client |
|
167 | - * requested, encoded as xmlnamespace#tagName, for example: |
|
168 | - * http://www.example.org/namespace#author If the array is empty, all |
|
169 | - * properties should be returned |
|
170 | - */ |
|
171 | - private function getProperties($path, array $requestedProperties) { |
|
172 | - if (isset($this->cache[$path])) { |
|
173 | - return $this->cache[$path]; |
|
174 | - } |
|
175 | - |
|
176 | - // TODO: chunking if more than 1000 properties |
|
177 | - $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'; |
|
178 | - |
|
179 | - $whereValues = array($this->user, $path); |
|
180 | - $whereTypes = array(null, null); |
|
181 | - |
|
182 | - if (!empty($requestedProperties)) { |
|
183 | - // request only a subset |
|
184 | - $sql .= ' AND `propertyname` in (?)'; |
|
185 | - $whereValues[] = $requestedProperties; |
|
186 | - $whereTypes[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY; |
|
187 | - } |
|
188 | - |
|
189 | - $result = $this->connection->executeQuery( |
|
190 | - $sql, |
|
191 | - $whereValues, |
|
192 | - $whereTypes |
|
193 | - ); |
|
194 | - |
|
195 | - $props = []; |
|
196 | - while ($row = $result->fetch()) { |
|
197 | - $props[$row['propertyname']] = $row['propertyvalue']; |
|
198 | - } |
|
199 | - |
|
200 | - $result->closeCursor(); |
|
201 | - |
|
202 | - $this->cache[$path] = $props; |
|
203 | - return $props; |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Update properties |
|
208 | - * |
|
209 | - * @param string $path node for which to update properties |
|
210 | - * @param array $properties array of properties to update |
|
211 | - * |
|
212 | - * @return bool |
|
213 | - */ |
|
214 | - private function updateProperties($path, $properties) { |
|
215 | - |
|
216 | - $deleteStatement = 'DELETE FROM `*PREFIX*properties`' . |
|
217 | - ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
218 | - |
|
219 | - $insertStatement = 'INSERT INTO `*PREFIX*properties`' . |
|
220 | - ' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)'; |
|
221 | - |
|
222 | - $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' . |
|
223 | - ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
224 | - |
|
225 | - // TODO: use "insert or update" strategy ? |
|
226 | - $existing = $this->getProperties($path, array()); |
|
227 | - $this->connection->beginTransaction(); |
|
228 | - foreach ($properties as $propertyName => $propertyValue) { |
|
229 | - // If it was null, we need to delete the property |
|
230 | - if (is_null($propertyValue)) { |
|
231 | - if (array_key_exists($propertyName, $existing)) { |
|
232 | - $this->connection->executeUpdate($deleteStatement, |
|
233 | - array( |
|
234 | - $this->user, |
|
235 | - $path, |
|
236 | - $propertyName |
|
237 | - ) |
|
238 | - ); |
|
239 | - } |
|
240 | - } else { |
|
241 | - if (!array_key_exists($propertyName, $existing)) { |
|
242 | - $this->connection->executeUpdate($insertStatement, |
|
243 | - array( |
|
244 | - $this->user, |
|
245 | - $path, |
|
246 | - $propertyName, |
|
247 | - $propertyValue |
|
248 | - ) |
|
249 | - ); |
|
250 | - } else { |
|
251 | - $this->connection->executeUpdate($updateStatement, |
|
252 | - array( |
|
253 | - $propertyValue, |
|
254 | - $this->user, |
|
255 | - $path, |
|
256 | - $propertyName |
|
257 | - ) |
|
258 | - ); |
|
259 | - } |
|
260 | - } |
|
261 | - } |
|
262 | - |
|
263 | - $this->connection->commit(); |
|
264 | - unset($this->cache[$path]); |
|
265 | - |
|
266 | - return true; |
|
267 | - } |
|
35 | + /** |
|
36 | + * Ignored properties |
|
37 | + * |
|
38 | + * @var array |
|
39 | + */ |
|
40 | + private $ignoredProperties = array( |
|
41 | + '{DAV:}getcontentlength', |
|
42 | + '{DAV:}getcontenttype', |
|
43 | + '{DAV:}getetag', |
|
44 | + '{DAV:}quota-used-bytes', |
|
45 | + '{DAV:}quota-available-bytes', |
|
46 | + '{http://owncloud.org/ns}permissions', |
|
47 | + '{http://owncloud.org/ns}downloadURL', |
|
48 | + '{http://owncloud.org/ns}dDC', |
|
49 | + '{http://owncloud.org/ns}size', |
|
50 | + ); |
|
51 | + |
|
52 | + /** |
|
53 | + * @var Tree |
|
54 | + */ |
|
55 | + private $tree; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var IDBConnection |
|
59 | + */ |
|
60 | + private $connection; |
|
61 | + |
|
62 | + /** |
|
63 | + * @var string |
|
64 | + */ |
|
65 | + private $user; |
|
66 | + |
|
67 | + /** |
|
68 | + * Properties cache |
|
69 | + * |
|
70 | + * @var array |
|
71 | + */ |
|
72 | + private $cache = []; |
|
73 | + |
|
74 | + /** |
|
75 | + * @param Tree $tree node tree |
|
76 | + * @param IDBConnection $connection database connection |
|
77 | + * @param IUser $user owner of the tree and properties |
|
78 | + */ |
|
79 | + public function __construct( |
|
80 | + Tree $tree, |
|
81 | + IDBConnection $connection, |
|
82 | + IUser $user) { |
|
83 | + $this->tree = $tree; |
|
84 | + $this->connection = $connection; |
|
85 | + $this->user = $user->getUID(); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Fetches properties for a path. |
|
90 | + * |
|
91 | + * @param string $path |
|
92 | + * @param PropFind $propFind |
|
93 | + * @return void |
|
94 | + */ |
|
95 | + public function propFind($path, PropFind $propFind) { |
|
96 | + |
|
97 | + $requestedProps = $propFind->get404Properties(); |
|
98 | + |
|
99 | + // these might appear |
|
100 | + $requestedProps = array_diff( |
|
101 | + $requestedProps, |
|
102 | + $this->ignoredProperties |
|
103 | + ); |
|
104 | + |
|
105 | + if (empty($requestedProps)) { |
|
106 | + return; |
|
107 | + } |
|
108 | + |
|
109 | + $props = $this->getProperties($path, $requestedProps); |
|
110 | + foreach ($props as $propName => $propValue) { |
|
111 | + $propFind->set($propName, $propValue); |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Updates properties for a path |
|
117 | + * |
|
118 | + * @param string $path |
|
119 | + * @param PropPatch $propPatch |
|
120 | + * |
|
121 | + * @return void |
|
122 | + */ |
|
123 | + public function propPatch($path, PropPatch $propPatch) { |
|
124 | + $propPatch->handleRemaining(function($changedProps) use ($path) { |
|
125 | + return $this->updateProperties($path, $changedProps); |
|
126 | + }); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * This method is called after a node is deleted. |
|
131 | + * |
|
132 | + * @param string $path path of node for which to delete properties |
|
133 | + */ |
|
134 | + public function delete($path) { |
|
135 | + $statement = $this->connection->prepare( |
|
136 | + 'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?' |
|
137 | + ); |
|
138 | + $statement->execute(array($this->user, $path)); |
|
139 | + $statement->closeCursor(); |
|
140 | + |
|
141 | + unset($this->cache[$path]); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * This method is called after a successful MOVE |
|
146 | + * |
|
147 | + * @param string $source |
|
148 | + * @param string $destination |
|
149 | + * |
|
150 | + * @return void |
|
151 | + */ |
|
152 | + public function move($source, $destination) { |
|
153 | + $statement = $this->connection->prepare( |
|
154 | + 'UPDATE `*PREFIX*properties` SET `propertypath` = ?' . |
|
155 | + ' WHERE `userid` = ? AND `propertypath` = ?' |
|
156 | + ); |
|
157 | + $statement->execute(array($destination, $this->user, $source)); |
|
158 | + $statement->closeCursor(); |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * Returns a list of properties for this nodes.; |
|
163 | + * @param string $path |
|
164 | + * @param array $requestedProperties requested properties or empty array for "all" |
|
165 | + * @return array |
|
166 | + * @note The properties list is a list of propertynames the client |
|
167 | + * requested, encoded as xmlnamespace#tagName, for example: |
|
168 | + * http://www.example.org/namespace#author If the array is empty, all |
|
169 | + * properties should be returned |
|
170 | + */ |
|
171 | + private function getProperties($path, array $requestedProperties) { |
|
172 | + if (isset($this->cache[$path])) { |
|
173 | + return $this->cache[$path]; |
|
174 | + } |
|
175 | + |
|
176 | + // TODO: chunking if more than 1000 properties |
|
177 | + $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'; |
|
178 | + |
|
179 | + $whereValues = array($this->user, $path); |
|
180 | + $whereTypes = array(null, null); |
|
181 | + |
|
182 | + if (!empty($requestedProperties)) { |
|
183 | + // request only a subset |
|
184 | + $sql .= ' AND `propertyname` in (?)'; |
|
185 | + $whereValues[] = $requestedProperties; |
|
186 | + $whereTypes[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY; |
|
187 | + } |
|
188 | + |
|
189 | + $result = $this->connection->executeQuery( |
|
190 | + $sql, |
|
191 | + $whereValues, |
|
192 | + $whereTypes |
|
193 | + ); |
|
194 | + |
|
195 | + $props = []; |
|
196 | + while ($row = $result->fetch()) { |
|
197 | + $props[$row['propertyname']] = $row['propertyvalue']; |
|
198 | + } |
|
199 | + |
|
200 | + $result->closeCursor(); |
|
201 | + |
|
202 | + $this->cache[$path] = $props; |
|
203 | + return $props; |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Update properties |
|
208 | + * |
|
209 | + * @param string $path node for which to update properties |
|
210 | + * @param array $properties array of properties to update |
|
211 | + * |
|
212 | + * @return bool |
|
213 | + */ |
|
214 | + private function updateProperties($path, $properties) { |
|
215 | + |
|
216 | + $deleteStatement = 'DELETE FROM `*PREFIX*properties`' . |
|
217 | + ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
218 | + |
|
219 | + $insertStatement = 'INSERT INTO `*PREFIX*properties`' . |
|
220 | + ' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)'; |
|
221 | + |
|
222 | + $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' . |
|
223 | + ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
224 | + |
|
225 | + // TODO: use "insert or update" strategy ? |
|
226 | + $existing = $this->getProperties($path, array()); |
|
227 | + $this->connection->beginTransaction(); |
|
228 | + foreach ($properties as $propertyName => $propertyValue) { |
|
229 | + // If it was null, we need to delete the property |
|
230 | + if (is_null($propertyValue)) { |
|
231 | + if (array_key_exists($propertyName, $existing)) { |
|
232 | + $this->connection->executeUpdate($deleteStatement, |
|
233 | + array( |
|
234 | + $this->user, |
|
235 | + $path, |
|
236 | + $propertyName |
|
237 | + ) |
|
238 | + ); |
|
239 | + } |
|
240 | + } else { |
|
241 | + if (!array_key_exists($propertyName, $existing)) { |
|
242 | + $this->connection->executeUpdate($insertStatement, |
|
243 | + array( |
|
244 | + $this->user, |
|
245 | + $path, |
|
246 | + $propertyName, |
|
247 | + $propertyValue |
|
248 | + ) |
|
249 | + ); |
|
250 | + } else { |
|
251 | + $this->connection->executeUpdate($updateStatement, |
|
252 | + array( |
|
253 | + $propertyValue, |
|
254 | + $this->user, |
|
255 | + $path, |
|
256 | + $propertyName |
|
257 | + ) |
|
258 | + ); |
|
259 | + } |
|
260 | + } |
|
261 | + } |
|
262 | + |
|
263 | + $this->connection->commit(); |
|
264 | + unset($this->cache[$path]); |
|
265 | + |
|
266 | + return true; |
|
267 | + } |
|
268 | 268 | |
269 | 269 | } |
@@ -32,33 +32,33 @@ |
||
32 | 32 | * Verify that the public link share is valid |
33 | 33 | */ |
34 | 34 | class PublicLinkCheckPlugin extends ServerPlugin { |
35 | - /** |
|
36 | - * @var FileInfo |
|
37 | - */ |
|
38 | - private $fileInfo; |
|
35 | + /** |
|
36 | + * @var FileInfo |
|
37 | + */ |
|
38 | + private $fileInfo; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param FileInfo $fileInfo |
|
42 | - */ |
|
43 | - public function setFileInfo($fileInfo) { |
|
44 | - $this->fileInfo = $fileInfo; |
|
45 | - } |
|
40 | + /** |
|
41 | + * @param FileInfo $fileInfo |
|
42 | + */ |
|
43 | + public function setFileInfo($fileInfo) { |
|
44 | + $this->fileInfo = $fileInfo; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * This initializes the plugin. |
|
49 | - * |
|
50 | - * @param \Sabre\DAV\Server $server Sabre server |
|
51 | - * |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - public function initialize(\Sabre\DAV\Server $server) { |
|
55 | - $server->on('beforeMethod', [$this, 'beforeMethod']); |
|
56 | - } |
|
47 | + /** |
|
48 | + * This initializes the plugin. |
|
49 | + * |
|
50 | + * @param \Sabre\DAV\Server $server Sabre server |
|
51 | + * |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + public function initialize(\Sabre\DAV\Server $server) { |
|
55 | + $server->on('beforeMethod', [$this, 'beforeMethod']); |
|
56 | + } |
|
57 | 57 | |
58 | - public function beforeMethod(RequestInterface $request, ResponseInterface $response){ |
|
59 | - // verify that the owner didn't have his share permissions revoked |
|
60 | - if ($this->fileInfo && !$this->fileInfo->isShareable()) { |
|
61 | - throw new NotFound(); |
|
62 | - } |
|
63 | - } |
|
58 | + public function beforeMethod(RequestInterface $request, ResponseInterface $response){ |
|
59 | + // verify that the owner didn't have his share permissions revoked |
|
60 | + if ($this->fileInfo && !$this->fileInfo->isShareable()) { |
|
61 | + throw new NotFound(); |
|
62 | + } |
|
63 | + } |
|
64 | 64 | } |
@@ -28,54 +28,54 @@ |
||
28 | 28 | |
29 | 29 | class UploadFolder implements ICollection { |
30 | 30 | |
31 | - private $node; |
|
31 | + private $node; |
|
32 | 32 | |
33 | - function __construct(Directory $node) { |
|
34 | - $this->node = $node; |
|
35 | - } |
|
33 | + function __construct(Directory $node) { |
|
34 | + $this->node = $node; |
|
35 | + } |
|
36 | 36 | |
37 | - function createFile($name, $data = null) { |
|
38 | - // TODO: verify name - should be a simple number |
|
39 | - $this->node->createFile($name, $data); |
|
40 | - } |
|
37 | + function createFile($name, $data = null) { |
|
38 | + // TODO: verify name - should be a simple number |
|
39 | + $this->node->createFile($name, $data); |
|
40 | + } |
|
41 | 41 | |
42 | - function createDirectory($name) { |
|
43 | - throw new Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
44 | - } |
|
42 | + function createDirectory($name) { |
|
43 | + throw new Forbidden('Permission denied to create file (filename ' . $name . ')'); |
|
44 | + } |
|
45 | 45 | |
46 | - function getChild($name) { |
|
47 | - if ($name === '.file') { |
|
48 | - return new FutureFile($this->node, '.file'); |
|
49 | - } |
|
50 | - return $this->node->getChild($name); |
|
51 | - } |
|
46 | + function getChild($name) { |
|
47 | + if ($name === '.file') { |
|
48 | + return new FutureFile($this->node, '.file'); |
|
49 | + } |
|
50 | + return $this->node->getChild($name); |
|
51 | + } |
|
52 | 52 | |
53 | - function getChildren() { |
|
54 | - $children = $this->node->getChildren(); |
|
55 | - $children[] = new FutureFile($this->node, '.file'); |
|
56 | - return $children; |
|
57 | - } |
|
53 | + function getChildren() { |
|
54 | + $children = $this->node->getChildren(); |
|
55 | + $children[] = new FutureFile($this->node, '.file'); |
|
56 | + return $children; |
|
57 | + } |
|
58 | 58 | |
59 | - function childExists($name) { |
|
60 | - if ($name === '.file') { |
|
61 | - return true; |
|
62 | - } |
|
63 | - return $this->node->childExists($name); |
|
64 | - } |
|
59 | + function childExists($name) { |
|
60 | + if ($name === '.file') { |
|
61 | + return true; |
|
62 | + } |
|
63 | + return $this->node->childExists($name); |
|
64 | + } |
|
65 | 65 | |
66 | - function delete() { |
|
67 | - $this->node->delete(); |
|
68 | - } |
|
66 | + function delete() { |
|
67 | + $this->node->delete(); |
|
68 | + } |
|
69 | 69 | |
70 | - function getName() { |
|
71 | - return $this->node->getName(); |
|
72 | - } |
|
70 | + function getName() { |
|
71 | + return $this->node->getName(); |
|
72 | + } |
|
73 | 73 | |
74 | - function setName($name) { |
|
75 | - throw new Forbidden('Permission denied to rename this folder'); |
|
76 | - } |
|
74 | + function setName($name) { |
|
75 | + throw new Forbidden('Permission denied to rename this folder'); |
|
76 | + } |
|
77 | 77 | |
78 | - function getLastModified() { |
|
79 | - return $this->node->getLastModified(); |
|
80 | - } |
|
78 | + function getLastModified() { |
|
79 | + return $this->node->getLastModified(); |
|
80 | + } |
|
81 | 81 | } |
@@ -26,18 +26,18 @@ |
||
26 | 26 | |
27 | 27 | class RootCollection extends AbstractPrincipalCollection { |
28 | 28 | |
29 | - /** |
|
30 | - * @inheritdoc |
|
31 | - */ |
|
32 | - function getChildForPrincipal(array $principalInfo) { |
|
33 | - return new UploadHome($principalInfo); |
|
34 | - } |
|
29 | + /** |
|
30 | + * @inheritdoc |
|
31 | + */ |
|
32 | + function getChildForPrincipal(array $principalInfo) { |
|
33 | + return new UploadHome($principalInfo); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @inheritdoc |
|
38 | - */ |
|
39 | - function getName() { |
|
40 | - return 'uploads'; |
|
41 | - } |
|
36 | + /** |
|
37 | + * @inheritdoc |
|
38 | + */ |
|
39 | + function getName() { |
|
40 | + return 'uploads'; |
|
41 | + } |
|
42 | 42 | |
43 | 43 | } |
@@ -37,87 +37,87 @@ |
||
37 | 37 | */ |
38 | 38 | class FutureFile implements \Sabre\DAV\IFile { |
39 | 39 | |
40 | - /** @var Directory */ |
|
41 | - private $root; |
|
42 | - /** @var string */ |
|
43 | - private $name; |
|
40 | + /** @var Directory */ |
|
41 | + private $root; |
|
42 | + /** @var string */ |
|
43 | + private $name; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param Directory $root |
|
47 | - * @param string $name |
|
48 | - */ |
|
49 | - function __construct(Directory $root, $name) { |
|
50 | - $this->root = $root; |
|
51 | - $this->name = $name; |
|
52 | - } |
|
45 | + /** |
|
46 | + * @param Directory $root |
|
47 | + * @param string $name |
|
48 | + */ |
|
49 | + function __construct(Directory $root, $name) { |
|
50 | + $this->root = $root; |
|
51 | + $this->name = $name; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @inheritdoc |
|
56 | - */ |
|
57 | - function put($data) { |
|
58 | - throw new Forbidden('Permission denied to put into this file'); |
|
59 | - } |
|
54 | + /** |
|
55 | + * @inheritdoc |
|
56 | + */ |
|
57 | + function put($data) { |
|
58 | + throw new Forbidden('Permission denied to put into this file'); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @inheritdoc |
|
63 | - */ |
|
64 | - function get() { |
|
65 | - $nodes = $this->root->getChildren(); |
|
66 | - return AssemblyStream::wrap($nodes); |
|
67 | - } |
|
61 | + /** |
|
62 | + * @inheritdoc |
|
63 | + */ |
|
64 | + function get() { |
|
65 | + $nodes = $this->root->getChildren(); |
|
66 | + return AssemblyStream::wrap($nodes); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @inheritdoc |
|
71 | - */ |
|
72 | - function getContentType() { |
|
73 | - return 'application/octet-stream'; |
|
74 | - } |
|
69 | + /** |
|
70 | + * @inheritdoc |
|
71 | + */ |
|
72 | + function getContentType() { |
|
73 | + return 'application/octet-stream'; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @inheritdoc |
|
78 | - */ |
|
79 | - function getETag() { |
|
80 | - return $this->root->getETag(); |
|
81 | - } |
|
76 | + /** |
|
77 | + * @inheritdoc |
|
78 | + */ |
|
79 | + function getETag() { |
|
80 | + return $this->root->getETag(); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @inheritdoc |
|
85 | - */ |
|
86 | - function getSize() { |
|
87 | - $children = $this->root->getChildren(); |
|
88 | - $sizes = array_map(function($node) { |
|
89 | - /** @var IFile $node */ |
|
90 | - return $node->getSize(); |
|
91 | - }, $children); |
|
83 | + /** |
|
84 | + * @inheritdoc |
|
85 | + */ |
|
86 | + function getSize() { |
|
87 | + $children = $this->root->getChildren(); |
|
88 | + $sizes = array_map(function($node) { |
|
89 | + /** @var IFile $node */ |
|
90 | + return $node->getSize(); |
|
91 | + }, $children); |
|
92 | 92 | |
93 | - return array_sum($sizes); |
|
94 | - } |
|
93 | + return array_sum($sizes); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * @inheritdoc |
|
98 | - */ |
|
99 | - function delete() { |
|
100 | - $this->root->delete(); |
|
101 | - } |
|
96 | + /** |
|
97 | + * @inheritdoc |
|
98 | + */ |
|
99 | + function delete() { |
|
100 | + $this->root->delete(); |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * @inheritdoc |
|
105 | - */ |
|
106 | - function getName() { |
|
107 | - return $this->name; |
|
108 | - } |
|
103 | + /** |
|
104 | + * @inheritdoc |
|
105 | + */ |
|
106 | + function getName() { |
|
107 | + return $this->name; |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * @inheritdoc |
|
112 | - */ |
|
113 | - function setName($name) { |
|
114 | - throw new Forbidden('Permission denied to rename this file'); |
|
115 | - } |
|
110 | + /** |
|
111 | + * @inheritdoc |
|
112 | + */ |
|
113 | + function setName($name) { |
|
114 | + throw new Forbidden('Permission denied to rename this file'); |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * @inheritdoc |
|
119 | - */ |
|
120 | - function getLastModified() { |
|
121 | - return $this->root->getLastModified(); |
|
122 | - } |
|
117 | + /** |
|
118 | + * @inheritdoc |
|
119 | + */ |
|
120 | + function getLastModified() { |
|
121 | + return $this->root->getLastModified(); |
|
122 | + } |
|
123 | 123 | } |
@@ -42,88 +42,88 @@ |
||
42 | 42 | */ |
43 | 43 | class IMipPlugin extends SabreIMipPlugin { |
44 | 44 | |
45 | - /** @var IMailer */ |
|
46 | - private $mailer; |
|
47 | - |
|
48 | - /** @var ILogger */ |
|
49 | - private $logger; |
|
50 | - |
|
51 | - /** |
|
52 | - * Creates the email handler. |
|
53 | - * |
|
54 | - * @param IMailer $mailer |
|
55 | - */ |
|
56 | - function __construct(IMailer $mailer, ILogger $logger) { |
|
57 | - parent::__construct(''); |
|
58 | - $this->mailer = $mailer; |
|
59 | - $this->logger = $logger; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Event handler for the 'schedule' event. |
|
64 | - * |
|
65 | - * @param ITip\Message $iTipMessage |
|
66 | - * @return void |
|
67 | - */ |
|
68 | - function schedule(ITip\Message $iTipMessage) { |
|
69 | - |
|
70 | - // Not sending any emails if the system considers the update |
|
71 | - // insignificant. |
|
72 | - if (!$iTipMessage->significantChange) { |
|
73 | - if (!$iTipMessage->scheduleStatus) { |
|
74 | - $iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email'; |
|
75 | - } |
|
76 | - return; |
|
77 | - } |
|
78 | - |
|
79 | - $summary = $iTipMessage->message->VEVENT->SUMMARY; |
|
80 | - |
|
81 | - if (parse_url($iTipMessage->sender, PHP_URL_SCHEME) !== 'mailto') { |
|
82 | - return; |
|
83 | - } |
|
84 | - |
|
85 | - if (parse_url($iTipMessage->recipient, PHP_URL_SCHEME) !== 'mailto') { |
|
86 | - return; |
|
87 | - } |
|
88 | - |
|
89 | - $sender = substr($iTipMessage->sender, 7); |
|
90 | - $recipient = substr($iTipMessage->recipient, 7); |
|
91 | - |
|
92 | - $senderName = ($iTipMessage->senderName) ? $iTipMessage->senderName : null; |
|
93 | - $recipientName = ($iTipMessage->recipientName) ? $iTipMessage->recipientName : null; |
|
94 | - |
|
95 | - $subject = 'SabreDAV iTIP message'; |
|
96 | - switch (strtoupper($iTipMessage->method)) { |
|
97 | - case 'REPLY' : |
|
98 | - $subject = 'Re: ' . $summary; |
|
99 | - break; |
|
100 | - case 'REQUEST' : |
|
101 | - $subject = $summary; |
|
102 | - break; |
|
103 | - case 'CANCEL' : |
|
104 | - $subject = 'Cancelled: ' . $summary; |
|
105 | - break; |
|
106 | - } |
|
107 | - |
|
108 | - $contentType = 'text/calendar; charset=UTF-8; method=' . $iTipMessage->method; |
|
109 | - |
|
110 | - $message = $this->mailer->createMessage(); |
|
111 | - |
|
112 | - $message->setReplyTo([$sender => $senderName]) |
|
113 | - ->setTo([$recipient => $recipientName]) |
|
114 | - ->setSubject($subject) |
|
115 | - ->setBody($iTipMessage->message->serialize(), $contentType); |
|
116 | - try { |
|
117 | - $failed = $this->mailer->send($message); |
|
118 | - if ($failed) { |
|
119 | - $this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => implode(', ', $failed)]); |
|
120 | - $iTipMessage->scheduleStatus = '5.0; EMail delivery failed'; |
|
121 | - } |
|
122 | - $iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip'; |
|
123 | - } catch(\Exception $ex) { |
|
124 | - $this->logger->logException($ex, ['app' => 'dav']); |
|
125 | - $iTipMessage->scheduleStatus = '5.0; EMail delivery failed'; |
|
126 | - } |
|
127 | - } |
|
45 | + /** @var IMailer */ |
|
46 | + private $mailer; |
|
47 | + |
|
48 | + /** @var ILogger */ |
|
49 | + private $logger; |
|
50 | + |
|
51 | + /** |
|
52 | + * Creates the email handler. |
|
53 | + * |
|
54 | + * @param IMailer $mailer |
|
55 | + */ |
|
56 | + function __construct(IMailer $mailer, ILogger $logger) { |
|
57 | + parent::__construct(''); |
|
58 | + $this->mailer = $mailer; |
|
59 | + $this->logger = $logger; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Event handler for the 'schedule' event. |
|
64 | + * |
|
65 | + * @param ITip\Message $iTipMessage |
|
66 | + * @return void |
|
67 | + */ |
|
68 | + function schedule(ITip\Message $iTipMessage) { |
|
69 | + |
|
70 | + // Not sending any emails if the system considers the update |
|
71 | + // insignificant. |
|
72 | + if (!$iTipMessage->significantChange) { |
|
73 | + if (!$iTipMessage->scheduleStatus) { |
|
74 | + $iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email'; |
|
75 | + } |
|
76 | + return; |
|
77 | + } |
|
78 | + |
|
79 | + $summary = $iTipMessage->message->VEVENT->SUMMARY; |
|
80 | + |
|
81 | + if (parse_url($iTipMessage->sender, PHP_URL_SCHEME) !== 'mailto') { |
|
82 | + return; |
|
83 | + } |
|
84 | + |
|
85 | + if (parse_url($iTipMessage->recipient, PHP_URL_SCHEME) !== 'mailto') { |
|
86 | + return; |
|
87 | + } |
|
88 | + |
|
89 | + $sender = substr($iTipMessage->sender, 7); |
|
90 | + $recipient = substr($iTipMessage->recipient, 7); |
|
91 | + |
|
92 | + $senderName = ($iTipMessage->senderName) ? $iTipMessage->senderName : null; |
|
93 | + $recipientName = ($iTipMessage->recipientName) ? $iTipMessage->recipientName : null; |
|
94 | + |
|
95 | + $subject = 'SabreDAV iTIP message'; |
|
96 | + switch (strtoupper($iTipMessage->method)) { |
|
97 | + case 'REPLY' : |
|
98 | + $subject = 'Re: ' . $summary; |
|
99 | + break; |
|
100 | + case 'REQUEST' : |
|
101 | + $subject = $summary; |
|
102 | + break; |
|
103 | + case 'CANCEL' : |
|
104 | + $subject = 'Cancelled: ' . $summary; |
|
105 | + break; |
|
106 | + } |
|
107 | + |
|
108 | + $contentType = 'text/calendar; charset=UTF-8; method=' . $iTipMessage->method; |
|
109 | + |
|
110 | + $message = $this->mailer->createMessage(); |
|
111 | + |
|
112 | + $message->setReplyTo([$sender => $senderName]) |
|
113 | + ->setTo([$recipient => $recipientName]) |
|
114 | + ->setSubject($subject) |
|
115 | + ->setBody($iTipMessage->message->serialize(), $contentType); |
|
116 | + try { |
|
117 | + $failed = $this->mailer->send($message); |
|
118 | + if ($failed) { |
|
119 | + $this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => implode(', ', $failed)]); |
|
120 | + $iTipMessage->scheduleStatus = '5.0; EMail delivery failed'; |
|
121 | + } |
|
122 | + $iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip'; |
|
123 | + } catch(\Exception $ex) { |
|
124 | + $this->logger->logException($ex, ['app' => 'dav']); |
|
125 | + $iTipMessage->scheduleStatus = '5.0; EMail delivery failed'; |
|
126 | + } |
|
127 | + } |
|
128 | 128 | |
129 | 129 | } |
@@ -24,7 +24,7 @@ |
||
24 | 24 | |
25 | 25 | class CalendarRoot extends \Sabre\CalDAV\CalendarRoot { |
26 | 26 | |
27 | - function getChildForPrincipal(array $principal) { |
|
28 | - return new CalendarHome($this->caldavBackend, $principal); |
|
29 | - } |
|
27 | + function getChildForPrincipal(array $principal) { |
|
28 | + return new CalendarHome($this->caldavBackend, $principal); |
|
29 | + } |
|
30 | 30 | } |
31 | 31 | \ No newline at end of file |