@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | public function getChild($name) { |
60 | 60 | $elements = pathinfo($name); |
61 | 61 | $ext = isset($elements['extension']) ? $elements['extension'] : ''; |
62 | - $size = (int)(isset($elements['filename']) ? $elements['filename'] : '64'); |
|
62 | + $size = (int) (isset($elements['filename']) ? $elements['filename'] : '64'); |
|
63 | 63 | if (!in_array($ext, ['jpeg', 'png'], true)) { |
64 | 64 | throw new MethodNotAllowed('File format not allowed'); |
65 | 65 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | return [ |
79 | 79 | $this->getChild('96.jpeg') |
80 | 80 | ]; |
81 | - } catch(NotFound $exception) { |
|
81 | + } catch (NotFound $exception) { |
|
82 | 82 | return []; |
83 | 83 | } |
84 | 84 | } |
@@ -35,89 +35,89 @@ |
||
35 | 35 | |
36 | 36 | class AvatarHome implements ICollection { |
37 | 37 | |
38 | - /** @var array */ |
|
39 | - private $principalInfo; |
|
40 | - /** @var IAvatarManager */ |
|
41 | - private $avatarManager; |
|
42 | - |
|
43 | - /** |
|
44 | - * AvatarHome constructor. |
|
45 | - * |
|
46 | - * @param array $principalInfo |
|
47 | - * @param IAvatarManager $avatarManager |
|
48 | - */ |
|
49 | - public function __construct($principalInfo, IAvatarManager $avatarManager) { |
|
50 | - $this->principalInfo = $principalInfo; |
|
51 | - $this->avatarManager = $avatarManager; |
|
52 | - } |
|
53 | - |
|
54 | - public function createFile($name, $data = null) { |
|
55 | - throw new Forbidden('Permission denied to create a file'); |
|
56 | - } |
|
57 | - |
|
58 | - public function createDirectory($name) { |
|
59 | - throw new Forbidden('Permission denied to create a folder'); |
|
60 | - } |
|
61 | - |
|
62 | - public function getChild($name) { |
|
63 | - $elements = pathinfo($name); |
|
64 | - $ext = isset($elements['extension']) ? $elements['extension'] : ''; |
|
65 | - $size = (int)(isset($elements['filename']) ? $elements['filename'] : '64'); |
|
66 | - if (!in_array($ext, ['jpeg', 'png'], true)) { |
|
67 | - throw new MethodNotAllowed('File format not allowed'); |
|
68 | - } |
|
69 | - if ($size <= 0 || $size > 1024) { |
|
70 | - throw new MethodNotAllowed('Invalid image size'); |
|
71 | - } |
|
72 | - $avatar = $this->avatarManager->getAvatar($this->getName()); |
|
73 | - if (!$avatar->exists()) { |
|
74 | - throw new NotFound(); |
|
75 | - } |
|
76 | - return new AvatarNode($size, $ext, $avatar); |
|
77 | - } |
|
78 | - |
|
79 | - public function getChildren() { |
|
80 | - try { |
|
81 | - return [ |
|
82 | - $this->getChild('96.jpeg') |
|
83 | - ]; |
|
84 | - } catch(NotFound $exception) { |
|
85 | - return []; |
|
86 | - } |
|
87 | - } |
|
88 | - |
|
89 | - public function childExists($name) { |
|
90 | - try { |
|
91 | - $ret = $this->getChild($name); |
|
92 | - return $ret !== null; |
|
93 | - } catch (NotFound $ex) { |
|
94 | - return false; |
|
95 | - } catch (MethodNotAllowed $ex) { |
|
96 | - return false; |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - public function delete() { |
|
101 | - throw new Forbidden('Permission denied to delete this folder'); |
|
102 | - } |
|
103 | - |
|
104 | - public function getName() { |
|
105 | - list(,$name) = Uri\split($this->principalInfo['uri']); |
|
106 | - return $name; |
|
107 | - } |
|
108 | - |
|
109 | - public function setName($name) { |
|
110 | - throw new Forbidden('Permission denied to rename this folder'); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Returns the last modification time, as a unix timestamp |
|
115 | - * |
|
116 | - * @return int|null |
|
117 | - */ |
|
118 | - public function getLastModified() { |
|
119 | - return null; |
|
120 | - } |
|
38 | + /** @var array */ |
|
39 | + private $principalInfo; |
|
40 | + /** @var IAvatarManager */ |
|
41 | + private $avatarManager; |
|
42 | + |
|
43 | + /** |
|
44 | + * AvatarHome constructor. |
|
45 | + * |
|
46 | + * @param array $principalInfo |
|
47 | + * @param IAvatarManager $avatarManager |
|
48 | + */ |
|
49 | + public function __construct($principalInfo, IAvatarManager $avatarManager) { |
|
50 | + $this->principalInfo = $principalInfo; |
|
51 | + $this->avatarManager = $avatarManager; |
|
52 | + } |
|
53 | + |
|
54 | + public function createFile($name, $data = null) { |
|
55 | + throw new Forbidden('Permission denied to create a file'); |
|
56 | + } |
|
57 | + |
|
58 | + public function createDirectory($name) { |
|
59 | + throw new Forbidden('Permission denied to create a folder'); |
|
60 | + } |
|
61 | + |
|
62 | + public function getChild($name) { |
|
63 | + $elements = pathinfo($name); |
|
64 | + $ext = isset($elements['extension']) ? $elements['extension'] : ''; |
|
65 | + $size = (int)(isset($elements['filename']) ? $elements['filename'] : '64'); |
|
66 | + if (!in_array($ext, ['jpeg', 'png'], true)) { |
|
67 | + throw new MethodNotAllowed('File format not allowed'); |
|
68 | + } |
|
69 | + if ($size <= 0 || $size > 1024) { |
|
70 | + throw new MethodNotAllowed('Invalid image size'); |
|
71 | + } |
|
72 | + $avatar = $this->avatarManager->getAvatar($this->getName()); |
|
73 | + if (!$avatar->exists()) { |
|
74 | + throw new NotFound(); |
|
75 | + } |
|
76 | + return new AvatarNode($size, $ext, $avatar); |
|
77 | + } |
|
78 | + |
|
79 | + public function getChildren() { |
|
80 | + try { |
|
81 | + return [ |
|
82 | + $this->getChild('96.jpeg') |
|
83 | + ]; |
|
84 | + } catch(NotFound $exception) { |
|
85 | + return []; |
|
86 | + } |
|
87 | + } |
|
88 | + |
|
89 | + public function childExists($name) { |
|
90 | + try { |
|
91 | + $ret = $this->getChild($name); |
|
92 | + return $ret !== null; |
|
93 | + } catch (NotFound $ex) { |
|
94 | + return false; |
|
95 | + } catch (MethodNotAllowed $ex) { |
|
96 | + return false; |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + public function delete() { |
|
101 | + throw new Forbidden('Permission denied to delete this folder'); |
|
102 | + } |
|
103 | + |
|
104 | + public function getName() { |
|
105 | + list(,$name) = Uri\split($this->principalInfo['uri']); |
|
106 | + return $name; |
|
107 | + } |
|
108 | + |
|
109 | + public function setName($name) { |
|
110 | + throw new Forbidden('Permission denied to rename this folder'); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Returns the last modification time, as a unix timestamp |
|
115 | + * |
|
116 | + * @return int|null |
|
117 | + */ |
|
118 | + public function getLastModified() { |
|
119 | + return null; |
|
120 | + } |
|
121 | 121 | |
122 | 122 | |
123 | 123 | } |
@@ -89,7 +89,7 @@ |
||
89 | 89 | public function getLastModified() { |
90 | 90 | $timestamp = $this->avatar->getFile($this->size)->getMTime(); |
91 | 91 | if (!empty($timestamp)) { |
92 | - return (int)$timestamp; |
|
92 | + return (int) $timestamp; |
|
93 | 93 | } |
94 | 94 | return $timestamp; |
95 | 95 |
@@ -27,72 +27,72 @@ |
||
27 | 27 | use Sabre\DAV\File; |
28 | 28 | |
29 | 29 | class AvatarNode extends File { |
30 | - private $ext; |
|
31 | - private $size; |
|
32 | - private $avatar; |
|
30 | + private $ext; |
|
31 | + private $size; |
|
32 | + private $avatar; |
|
33 | 33 | |
34 | - /** |
|
35 | - * AvatarNode constructor. |
|
36 | - * |
|
37 | - * @param integer $size |
|
38 | - * @param string $ext |
|
39 | - * @param IAvatar $avatar |
|
40 | - */ |
|
41 | - public function __construct($size, $ext, $avatar) { |
|
42 | - $this->size = $size; |
|
43 | - $this->ext = $ext; |
|
44 | - $this->avatar = $avatar; |
|
45 | - } |
|
34 | + /** |
|
35 | + * AvatarNode constructor. |
|
36 | + * |
|
37 | + * @param integer $size |
|
38 | + * @param string $ext |
|
39 | + * @param IAvatar $avatar |
|
40 | + */ |
|
41 | + public function __construct($size, $ext, $avatar) { |
|
42 | + $this->size = $size; |
|
43 | + $this->ext = $ext; |
|
44 | + $this->avatar = $avatar; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Returns the name of the node. |
|
49 | - * |
|
50 | - * This is used to generate the url. |
|
51 | - * |
|
52 | - * @return string |
|
53 | - */ |
|
54 | - public function getName() { |
|
55 | - return "$this->size.$this->ext"; |
|
56 | - } |
|
47 | + /** |
|
48 | + * Returns the name of the node. |
|
49 | + * |
|
50 | + * This is used to generate the url. |
|
51 | + * |
|
52 | + * @return string |
|
53 | + */ |
|
54 | + public function getName() { |
|
55 | + return "$this->size.$this->ext"; |
|
56 | + } |
|
57 | 57 | |
58 | - public function get() { |
|
59 | - $image = $this->avatar->get($this->size); |
|
60 | - $res = $image->resource(); |
|
58 | + public function get() { |
|
59 | + $image = $this->avatar->get($this->size); |
|
60 | + $res = $image->resource(); |
|
61 | 61 | |
62 | - ob_start(); |
|
63 | - if ($this->ext === 'png') { |
|
64 | - imagepng($res); |
|
65 | - } else { |
|
66 | - imagejpeg($res); |
|
67 | - } |
|
62 | + ob_start(); |
|
63 | + if ($this->ext === 'png') { |
|
64 | + imagepng($res); |
|
65 | + } else { |
|
66 | + imagejpeg($res); |
|
67 | + } |
|
68 | 68 | |
69 | - return ob_get_clean(); |
|
70 | - } |
|
69 | + return ob_get_clean(); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Returns the mime-type for a file |
|
74 | - * |
|
75 | - * If null is returned, we'll assume application/octet-stream |
|
76 | - * |
|
77 | - * @return string|null |
|
78 | - */ |
|
79 | - public function getContentType() { |
|
80 | - if ($this->ext === 'png') { |
|
81 | - return 'image/png'; |
|
82 | - } |
|
83 | - return 'image/jpeg'; |
|
84 | - } |
|
72 | + /** |
|
73 | + * Returns the mime-type for a file |
|
74 | + * |
|
75 | + * If null is returned, we'll assume application/octet-stream |
|
76 | + * |
|
77 | + * @return string|null |
|
78 | + */ |
|
79 | + public function getContentType() { |
|
80 | + if ($this->ext === 'png') { |
|
81 | + return 'image/png'; |
|
82 | + } |
|
83 | + return 'image/jpeg'; |
|
84 | + } |
|
85 | 85 | |
86 | - public function getETag() { |
|
87 | - return $this->avatar->getFile($this->size)->getEtag(); |
|
88 | - } |
|
86 | + public function getETag() { |
|
87 | + return $this->avatar->getFile($this->size)->getEtag(); |
|
88 | + } |
|
89 | 89 | |
90 | - public function getLastModified() { |
|
91 | - $timestamp = $this->avatar->getFile($this->size)->getMTime(); |
|
92 | - if (!empty($timestamp)) { |
|
93 | - return (int)$timestamp; |
|
94 | - } |
|
95 | - return $timestamp; |
|
90 | + public function getLastModified() { |
|
91 | + $timestamp = $this->avatar->getFile($this->size)->getMTime(); |
|
92 | + if (!empty($timestamp)) { |
|
93 | + return (int)$timestamp; |
|
94 | + } |
|
95 | + return $timestamp; |
|
96 | 96 | |
97 | - } |
|
97 | + } |
|
98 | 98 | } |
@@ -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 | } |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | |
66 | 66 | $output->startProgress(count($objects)); |
67 | 67 | foreach ($objects as $row) { |
68 | - $calObject = $this->calDavBackend->getCalendarObject((int)$row['calendarid'], $row['uri']); |
|
69 | - $data = preg_replace('/' . $pattern . '/', ':', $calObject['calendardata']); |
|
68 | + $calObject = $this->calDavBackend->getCalendarObject((int) $row['calendarid'], $row['uri']); |
|
69 | + $data = preg_replace('/'.$pattern.'/', ':', $calObject['calendardata']); |
|
70 | 70 | |
71 | 71 | if ($data !== $calObject['calendardata']) { |
72 | 72 | $output->advance(); |
@@ -76,14 +76,14 @@ discard block |
||
76 | 76 | } catch (InvalidDataException $e) { |
77 | 77 | $this->logger->info('Calendar object for calendar {cal} with uri {uri} still invalid', [ |
78 | 78 | 'app' => 'dav', |
79 | - 'cal' => (int)$row['calendarid'], |
|
79 | + 'cal' => (int) $row['calendarid'], |
|
80 | 80 | 'uri' => $row['uri'], |
81 | 81 | ]); |
82 | 82 | $warnings++; |
83 | 83 | continue; |
84 | 84 | } |
85 | 85 | |
86 | - $this->calDavBackend->updateCalendarObject((int)$row['calendarid'], $row['uri'], $data); |
|
86 | + $this->calDavBackend->updateCalendarObject((int) $row['calendarid'], $row['uri'], $data); |
|
87 | 87 | $count++; |
88 | 88 | } |
89 | 89 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | ->where($query->expr()->like( |
105 | 105 | 'calendardata', |
106 | 106 | $query->createNamedParameter( |
107 | - '%' . $this->db->escapeLikeParameter($pattern) . '%', |
|
107 | + '%'.$this->db->escapeLikeParameter($pattern).'%', |
|
108 | 108 | IQueryBuilder::PARAM_STR |
109 | 109 | ), |
110 | 110 | IQueryBuilder::PARAM_STR |
@@ -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 | } |
@@ -39,7 +39,7 @@ |
||
39 | 39 | $reader->parseInnerTree(); |
40 | 40 | |
41 | 41 | if (!is_string($componentName)) { |
42 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}comp-filter requires a valid name attribute'); |
|
42 | + throw new BadRequest('The {'.SearchPlugin::NS_Nextcloud.'}comp-filter requires a valid name attribute'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | return $componentName; |
@@ -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 |
@@ -35,7 +35,7 @@ |
||
35 | 35 | static function xmlDeserialize(Reader $reader) { |
36 | 36 | $value = $reader->parseInnerTree(); |
37 | 37 | if (!is_string($value)) { |
38 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}search-term has illegal value'); |
|
38 | + throw new BadRequest('The {'.SearchPlugin::NS_Nextcloud.'}search-term has illegal value'); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | return $value; |
@@ -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 | } |
@@ -39,7 +39,7 @@ |
||
39 | 39 | $reader->parseInnerTree(); |
40 | 40 | |
41 | 41 | if (!is_string($componentName)) { |
42 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}prop-filter requires a valid name attribute'); |
|
42 | + throw new BadRequest('The {'.SearchPlugin::NS_Nextcloud.'}prop-filter requires a valid name attribute'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | return $componentName; |
@@ -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 | } |
@@ -40,11 +40,11 @@ |
||
40 | 40 | $reader->parseInnerTree(); |
41 | 41 | |
42 | 42 | if (!is_string($property)) { |
43 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}param-filter requires a valid property attribute'); |
|
43 | + throw new BadRequest('The {'.SearchPlugin::NS_Nextcloud.'}param-filter requires a valid property attribute'); |
|
44 | 44 | |
45 | 45 | } |
46 | 46 | if (!is_string($parameter)) { |
47 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}param-filter requires a valid parameter attribute'); |
|
47 | + throw new BadRequest('The {'.SearchPlugin::NS_Nextcloud.'}param-filter requires a valid parameter attribute'); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | return [ |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public function move($source, $destination) { |
153 | 153 | $statement = $this->connection->prepare( |
154 | - 'UPDATE `*PREFIX*properties` SET `propertypath` = ?' . |
|
154 | + 'UPDATE `*PREFIX*properties` SET `propertypath` = ?'. |
|
155 | 155 | ' WHERE `userid` = ? AND `propertypath` = ?' |
156 | 156 | ); |
157 | 157 | $statement->execute(array($destination, $this->user, $source)); |
@@ -213,13 +213,13 @@ discard block |
||
213 | 213 | */ |
214 | 214 | private function updateProperties($path, $properties) { |
215 | 215 | |
216 | - $deleteStatement = 'DELETE FROM `*PREFIX*properties`' . |
|
216 | + $deleteStatement = 'DELETE FROM `*PREFIX*properties`'. |
|
217 | 217 | ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
218 | 218 | |
219 | - $insertStatement = 'INSERT INTO `*PREFIX*properties`' . |
|
219 | + $insertStatement = 'INSERT INTO `*PREFIX*properties`'. |
|
220 | 220 | ' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)'; |
221 | 221 | |
222 | - $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' . |
|
222 | + $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?'. |
|
223 | 223 | ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
224 | 224 | |
225 | 225 | // TODO: use "insert or update" strategy ? |
@@ -34,259 +34,259 @@ |
||
34 | 34 | |
35 | 35 | class CustomPropertiesBackend implements BackendInterface { |
36 | 36 | |
37 | - /** |
|
38 | - * Ignored properties |
|
39 | - * |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - private $ignoredProperties = array( |
|
43 | - '{DAV:}getcontentlength', |
|
44 | - '{DAV:}getcontenttype', |
|
45 | - '{DAV:}getetag', |
|
46 | - '{DAV:}quota-used-bytes', |
|
47 | - '{DAV:}quota-available-bytes', |
|
48 | - '{http://owncloud.org/ns}permissions', |
|
49 | - '{http://owncloud.org/ns}downloadURL', |
|
50 | - '{http://owncloud.org/ns}dDC', |
|
51 | - '{http://owncloud.org/ns}size', |
|
52 | - '{http://nextcloud.org/ns}is-encrypted', |
|
53 | - ); |
|
54 | - |
|
55 | - /** |
|
56 | - * @var Tree |
|
57 | - */ |
|
58 | - private $tree; |
|
59 | - |
|
60 | - /** |
|
61 | - * @var IDBConnection |
|
62 | - */ |
|
63 | - private $connection; |
|
64 | - |
|
65 | - /** |
|
66 | - * @var string |
|
67 | - */ |
|
68 | - private $user; |
|
69 | - |
|
70 | - /** |
|
71 | - * Properties cache |
|
72 | - * |
|
73 | - * @var array |
|
74 | - */ |
|
75 | - private $cache = []; |
|
76 | - |
|
77 | - /** |
|
78 | - * @param Tree $tree node tree |
|
79 | - * @param IDBConnection $connection database connection |
|
80 | - * @param IUser $user owner of the tree and properties |
|
81 | - */ |
|
82 | - public function __construct( |
|
83 | - Tree $tree, |
|
84 | - IDBConnection $connection, |
|
85 | - IUser $user) { |
|
86 | - $this->tree = $tree; |
|
87 | - $this->connection = $connection; |
|
88 | - $this->user = $user->getUID(); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Fetches properties for a path. |
|
93 | - * |
|
94 | - * @param string $path |
|
95 | - * @param PropFind $propFind |
|
96 | - * @return void |
|
97 | - */ |
|
98 | - public function propFind($path, PropFind $propFind) { |
|
99 | - |
|
100 | - $requestedProps = $propFind->get404Properties(); |
|
101 | - |
|
102 | - // these might appear |
|
103 | - $requestedProps = array_diff( |
|
104 | - $requestedProps, |
|
105 | - $this->ignoredProperties |
|
106 | - ); |
|
107 | - |
|
108 | - // substr of calendars/ => path is inside the CalDAV component |
|
109 | - // two '/' => this a calendar (no calendar-home nor calendar object) |
|
110 | - if (substr($path, 0, 10) === 'calendars/' && substr_count($path, '/') === 2) { |
|
111 | - $allRequestedProps = $propFind->getRequestedProperties(); |
|
112 | - $customPropertiesForShares = [ |
|
113 | - '{DAV:}displayname', |
|
114 | - '{urn:ietf:params:xml:ns:caldav}calendar-description', |
|
115 | - '{urn:ietf:params:xml:ns:caldav}calendar-timezone', |
|
116 | - '{http://apple.com/ns/ical/}calendar-order', |
|
117 | - '{http://apple.com/ns/ical/}calendar-color', |
|
118 | - '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp', |
|
119 | - ]; |
|
120 | - |
|
121 | - foreach ($customPropertiesForShares as $customPropertyForShares) { |
|
122 | - if (in_array($customPropertyForShares, $allRequestedProps)) { |
|
123 | - $requestedProps[] = $customPropertyForShares; |
|
124 | - } |
|
125 | - } |
|
126 | - } |
|
127 | - |
|
128 | - if (empty($requestedProps)) { |
|
129 | - return; |
|
130 | - } |
|
131 | - |
|
132 | - $props = $this->getProperties($path, $requestedProps); |
|
133 | - foreach ($props as $propName => $propValue) { |
|
134 | - $propFind->set($propName, $propValue); |
|
135 | - } |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Updates properties for a path |
|
140 | - * |
|
141 | - * @param string $path |
|
142 | - * @param PropPatch $propPatch |
|
143 | - * |
|
144 | - * @return void |
|
145 | - */ |
|
146 | - public function propPatch($path, PropPatch $propPatch) { |
|
147 | - $propPatch->handleRemaining(function($changedProps) use ($path) { |
|
148 | - return $this->updateProperties($path, $changedProps); |
|
149 | - }); |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * This method is called after a node is deleted. |
|
154 | - * |
|
155 | - * @param string $path path of node for which to delete properties |
|
156 | - */ |
|
157 | - public function delete($path) { |
|
158 | - $statement = $this->connection->prepare( |
|
159 | - 'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?' |
|
160 | - ); |
|
161 | - $statement->execute(array($this->user, $path)); |
|
162 | - $statement->closeCursor(); |
|
163 | - |
|
164 | - unset($this->cache[$path]); |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * This method is called after a successful MOVE |
|
169 | - * |
|
170 | - * @param string $source |
|
171 | - * @param string $destination |
|
172 | - * |
|
173 | - * @return void |
|
174 | - */ |
|
175 | - public function move($source, $destination) { |
|
176 | - $statement = $this->connection->prepare( |
|
177 | - 'UPDATE `*PREFIX*properties` SET `propertypath` = ?' . |
|
178 | - ' WHERE `userid` = ? AND `propertypath` = ?' |
|
179 | - ); |
|
180 | - $statement->execute(array($destination, $this->user, $source)); |
|
181 | - $statement->closeCursor(); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Returns a list of properties for this nodes.; |
|
186 | - * @param string $path |
|
187 | - * @param array $requestedProperties requested properties or empty array for "all" |
|
188 | - * @return array |
|
189 | - * @note The properties list is a list of propertynames the client |
|
190 | - * requested, encoded as xmlnamespace#tagName, for example: |
|
191 | - * http://www.example.org/namespace#author If the array is empty, all |
|
192 | - * properties should be returned |
|
193 | - */ |
|
194 | - private function getProperties($path, array $requestedProperties) { |
|
195 | - if (isset($this->cache[$path])) { |
|
196 | - return $this->cache[$path]; |
|
197 | - } |
|
198 | - |
|
199 | - // TODO: chunking if more than 1000 properties |
|
200 | - $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'; |
|
201 | - |
|
202 | - $whereValues = array($this->user, $path); |
|
203 | - $whereTypes = array(null, null); |
|
204 | - |
|
205 | - if (!empty($requestedProperties)) { |
|
206 | - // request only a subset |
|
207 | - $sql .= ' AND `propertyname` in (?)'; |
|
208 | - $whereValues[] = $requestedProperties; |
|
209 | - $whereTypes[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY; |
|
210 | - } |
|
211 | - |
|
212 | - $result = $this->connection->executeQuery( |
|
213 | - $sql, |
|
214 | - $whereValues, |
|
215 | - $whereTypes |
|
216 | - ); |
|
217 | - |
|
218 | - $props = []; |
|
219 | - while ($row = $result->fetch()) { |
|
220 | - $props[$row['propertyname']] = $row['propertyvalue']; |
|
221 | - } |
|
222 | - |
|
223 | - $result->closeCursor(); |
|
224 | - |
|
225 | - $this->cache[$path] = $props; |
|
226 | - return $props; |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Update properties |
|
231 | - * |
|
232 | - * @param string $path node for which to update properties |
|
233 | - * @param array $properties array of properties to update |
|
234 | - * |
|
235 | - * @return bool |
|
236 | - */ |
|
237 | - private function updateProperties($path, $properties) { |
|
238 | - |
|
239 | - $deleteStatement = 'DELETE FROM `*PREFIX*properties`' . |
|
240 | - ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
241 | - |
|
242 | - $insertStatement = 'INSERT INTO `*PREFIX*properties`' . |
|
243 | - ' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)'; |
|
244 | - |
|
245 | - $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' . |
|
246 | - ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
247 | - |
|
248 | - // TODO: use "insert or update" strategy ? |
|
249 | - $existing = $this->getProperties($path, array()); |
|
250 | - $this->connection->beginTransaction(); |
|
251 | - foreach ($properties as $propertyName => $propertyValue) { |
|
252 | - // If it was null, we need to delete the property |
|
253 | - if (is_null($propertyValue)) { |
|
254 | - if (array_key_exists($propertyName, $existing)) { |
|
255 | - $this->connection->executeUpdate($deleteStatement, |
|
256 | - array( |
|
257 | - $this->user, |
|
258 | - $path, |
|
259 | - $propertyName |
|
260 | - ) |
|
261 | - ); |
|
262 | - } |
|
263 | - } else { |
|
264 | - if (!array_key_exists($propertyName, $existing)) { |
|
265 | - $this->connection->executeUpdate($insertStatement, |
|
266 | - array( |
|
267 | - $this->user, |
|
268 | - $path, |
|
269 | - $propertyName, |
|
270 | - $propertyValue |
|
271 | - ) |
|
272 | - ); |
|
273 | - } else { |
|
274 | - $this->connection->executeUpdate($updateStatement, |
|
275 | - array( |
|
276 | - $propertyValue, |
|
277 | - $this->user, |
|
278 | - $path, |
|
279 | - $propertyName |
|
280 | - ) |
|
281 | - ); |
|
282 | - } |
|
283 | - } |
|
284 | - } |
|
285 | - |
|
286 | - $this->connection->commit(); |
|
287 | - unset($this->cache[$path]); |
|
288 | - |
|
289 | - return true; |
|
290 | - } |
|
37 | + /** |
|
38 | + * Ignored properties |
|
39 | + * |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + private $ignoredProperties = array( |
|
43 | + '{DAV:}getcontentlength', |
|
44 | + '{DAV:}getcontenttype', |
|
45 | + '{DAV:}getetag', |
|
46 | + '{DAV:}quota-used-bytes', |
|
47 | + '{DAV:}quota-available-bytes', |
|
48 | + '{http://owncloud.org/ns}permissions', |
|
49 | + '{http://owncloud.org/ns}downloadURL', |
|
50 | + '{http://owncloud.org/ns}dDC', |
|
51 | + '{http://owncloud.org/ns}size', |
|
52 | + '{http://nextcloud.org/ns}is-encrypted', |
|
53 | + ); |
|
54 | + |
|
55 | + /** |
|
56 | + * @var Tree |
|
57 | + */ |
|
58 | + private $tree; |
|
59 | + |
|
60 | + /** |
|
61 | + * @var IDBConnection |
|
62 | + */ |
|
63 | + private $connection; |
|
64 | + |
|
65 | + /** |
|
66 | + * @var string |
|
67 | + */ |
|
68 | + private $user; |
|
69 | + |
|
70 | + /** |
|
71 | + * Properties cache |
|
72 | + * |
|
73 | + * @var array |
|
74 | + */ |
|
75 | + private $cache = []; |
|
76 | + |
|
77 | + /** |
|
78 | + * @param Tree $tree node tree |
|
79 | + * @param IDBConnection $connection database connection |
|
80 | + * @param IUser $user owner of the tree and properties |
|
81 | + */ |
|
82 | + public function __construct( |
|
83 | + Tree $tree, |
|
84 | + IDBConnection $connection, |
|
85 | + IUser $user) { |
|
86 | + $this->tree = $tree; |
|
87 | + $this->connection = $connection; |
|
88 | + $this->user = $user->getUID(); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Fetches properties for a path. |
|
93 | + * |
|
94 | + * @param string $path |
|
95 | + * @param PropFind $propFind |
|
96 | + * @return void |
|
97 | + */ |
|
98 | + public function propFind($path, PropFind $propFind) { |
|
99 | + |
|
100 | + $requestedProps = $propFind->get404Properties(); |
|
101 | + |
|
102 | + // these might appear |
|
103 | + $requestedProps = array_diff( |
|
104 | + $requestedProps, |
|
105 | + $this->ignoredProperties |
|
106 | + ); |
|
107 | + |
|
108 | + // substr of calendars/ => path is inside the CalDAV component |
|
109 | + // two '/' => this a calendar (no calendar-home nor calendar object) |
|
110 | + if (substr($path, 0, 10) === 'calendars/' && substr_count($path, '/') === 2) { |
|
111 | + $allRequestedProps = $propFind->getRequestedProperties(); |
|
112 | + $customPropertiesForShares = [ |
|
113 | + '{DAV:}displayname', |
|
114 | + '{urn:ietf:params:xml:ns:caldav}calendar-description', |
|
115 | + '{urn:ietf:params:xml:ns:caldav}calendar-timezone', |
|
116 | + '{http://apple.com/ns/ical/}calendar-order', |
|
117 | + '{http://apple.com/ns/ical/}calendar-color', |
|
118 | + '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp', |
|
119 | + ]; |
|
120 | + |
|
121 | + foreach ($customPropertiesForShares as $customPropertyForShares) { |
|
122 | + if (in_array($customPropertyForShares, $allRequestedProps)) { |
|
123 | + $requestedProps[] = $customPropertyForShares; |
|
124 | + } |
|
125 | + } |
|
126 | + } |
|
127 | + |
|
128 | + if (empty($requestedProps)) { |
|
129 | + return; |
|
130 | + } |
|
131 | + |
|
132 | + $props = $this->getProperties($path, $requestedProps); |
|
133 | + foreach ($props as $propName => $propValue) { |
|
134 | + $propFind->set($propName, $propValue); |
|
135 | + } |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Updates properties for a path |
|
140 | + * |
|
141 | + * @param string $path |
|
142 | + * @param PropPatch $propPatch |
|
143 | + * |
|
144 | + * @return void |
|
145 | + */ |
|
146 | + public function propPatch($path, PropPatch $propPatch) { |
|
147 | + $propPatch->handleRemaining(function($changedProps) use ($path) { |
|
148 | + return $this->updateProperties($path, $changedProps); |
|
149 | + }); |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * This method is called after a node is deleted. |
|
154 | + * |
|
155 | + * @param string $path path of node for which to delete properties |
|
156 | + */ |
|
157 | + public function delete($path) { |
|
158 | + $statement = $this->connection->prepare( |
|
159 | + 'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?' |
|
160 | + ); |
|
161 | + $statement->execute(array($this->user, $path)); |
|
162 | + $statement->closeCursor(); |
|
163 | + |
|
164 | + unset($this->cache[$path]); |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * This method is called after a successful MOVE |
|
169 | + * |
|
170 | + * @param string $source |
|
171 | + * @param string $destination |
|
172 | + * |
|
173 | + * @return void |
|
174 | + */ |
|
175 | + public function move($source, $destination) { |
|
176 | + $statement = $this->connection->prepare( |
|
177 | + 'UPDATE `*PREFIX*properties` SET `propertypath` = ?' . |
|
178 | + ' WHERE `userid` = ? AND `propertypath` = ?' |
|
179 | + ); |
|
180 | + $statement->execute(array($destination, $this->user, $source)); |
|
181 | + $statement->closeCursor(); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Returns a list of properties for this nodes.; |
|
186 | + * @param string $path |
|
187 | + * @param array $requestedProperties requested properties or empty array for "all" |
|
188 | + * @return array |
|
189 | + * @note The properties list is a list of propertynames the client |
|
190 | + * requested, encoded as xmlnamespace#tagName, for example: |
|
191 | + * http://www.example.org/namespace#author If the array is empty, all |
|
192 | + * properties should be returned |
|
193 | + */ |
|
194 | + private function getProperties($path, array $requestedProperties) { |
|
195 | + if (isset($this->cache[$path])) { |
|
196 | + return $this->cache[$path]; |
|
197 | + } |
|
198 | + |
|
199 | + // TODO: chunking if more than 1000 properties |
|
200 | + $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'; |
|
201 | + |
|
202 | + $whereValues = array($this->user, $path); |
|
203 | + $whereTypes = array(null, null); |
|
204 | + |
|
205 | + if (!empty($requestedProperties)) { |
|
206 | + // request only a subset |
|
207 | + $sql .= ' AND `propertyname` in (?)'; |
|
208 | + $whereValues[] = $requestedProperties; |
|
209 | + $whereTypes[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY; |
|
210 | + } |
|
211 | + |
|
212 | + $result = $this->connection->executeQuery( |
|
213 | + $sql, |
|
214 | + $whereValues, |
|
215 | + $whereTypes |
|
216 | + ); |
|
217 | + |
|
218 | + $props = []; |
|
219 | + while ($row = $result->fetch()) { |
|
220 | + $props[$row['propertyname']] = $row['propertyvalue']; |
|
221 | + } |
|
222 | + |
|
223 | + $result->closeCursor(); |
|
224 | + |
|
225 | + $this->cache[$path] = $props; |
|
226 | + return $props; |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Update properties |
|
231 | + * |
|
232 | + * @param string $path node for which to update properties |
|
233 | + * @param array $properties array of properties to update |
|
234 | + * |
|
235 | + * @return bool |
|
236 | + */ |
|
237 | + private function updateProperties($path, $properties) { |
|
238 | + |
|
239 | + $deleteStatement = 'DELETE FROM `*PREFIX*properties`' . |
|
240 | + ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
241 | + |
|
242 | + $insertStatement = 'INSERT INTO `*PREFIX*properties`' . |
|
243 | + ' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)'; |
|
244 | + |
|
245 | + $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' . |
|
246 | + ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
247 | + |
|
248 | + // TODO: use "insert or update" strategy ? |
|
249 | + $existing = $this->getProperties($path, array()); |
|
250 | + $this->connection->beginTransaction(); |
|
251 | + foreach ($properties as $propertyName => $propertyValue) { |
|
252 | + // If it was null, we need to delete the property |
|
253 | + if (is_null($propertyValue)) { |
|
254 | + if (array_key_exists($propertyName, $existing)) { |
|
255 | + $this->connection->executeUpdate($deleteStatement, |
|
256 | + array( |
|
257 | + $this->user, |
|
258 | + $path, |
|
259 | + $propertyName |
|
260 | + ) |
|
261 | + ); |
|
262 | + } |
|
263 | + } else { |
|
264 | + if (!array_key_exists($propertyName, $existing)) { |
|
265 | + $this->connection->executeUpdate($insertStatement, |
|
266 | + array( |
|
267 | + $this->user, |
|
268 | + $path, |
|
269 | + $propertyName, |
|
270 | + $propertyValue |
|
271 | + ) |
|
272 | + ); |
|
273 | + } else { |
|
274 | + $this->connection->executeUpdate($updateStatement, |
|
275 | + array( |
|
276 | + $propertyValue, |
|
277 | + $this->user, |
|
278 | + $path, |
|
279 | + $propertyName |
|
280 | + ) |
|
281 | + ); |
|
282 | + } |
|
283 | + } |
|
284 | + } |
|
285 | + |
|
286 | + $this->connection->commit(); |
|
287 | + unset($this->cache[$path]); |
|
288 | + |
|
289 | + return true; |
|
290 | + } |
|
291 | 291 | |
292 | 292 | } |