@@ -80,7 +80,7 @@ |
||
80 | 80 | * the next element. |
81 | 81 | * |
82 | 82 | * @param Reader $reader |
83 | - * @return mixed |
|
83 | + * @return null|TagList |
|
84 | 84 | */ |
85 | 85 | static function xmlDeserialize(Reader $reader) { |
86 | 86 | $tags = []; |
@@ -34,92 +34,92 @@ |
||
34 | 34 | * This property contains multiple "tag" elements, each containing a tag name. |
35 | 35 | */ |
36 | 36 | class TagList implements Element { |
37 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
37 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
38 | 38 | |
39 | - /** |
|
40 | - * tags |
|
41 | - * |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - private $tags; |
|
39 | + /** |
|
40 | + * tags |
|
41 | + * |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + private $tags; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param array $tags |
|
48 | - */ |
|
49 | - public function __construct(array $tags) { |
|
50 | - $this->tags = $tags; |
|
51 | - } |
|
46 | + /** |
|
47 | + * @param array $tags |
|
48 | + */ |
|
49 | + public function __construct(array $tags) { |
|
50 | + $this->tags = $tags; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Returns the tags |
|
55 | - * |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function getTags() { |
|
53 | + /** |
|
54 | + * Returns the tags |
|
55 | + * |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function getTags() { |
|
59 | 59 | |
60 | - return $this->tags; |
|
60 | + return $this->tags; |
|
61 | 61 | |
62 | - } |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * The deserialize method is called during xml parsing. |
|
66 | - * |
|
67 | - * This method is called statictly, this is because in theory this method |
|
68 | - * may be used as a type of constructor, or factory method. |
|
69 | - * |
|
70 | - * Often you want to return an instance of the current class, but you are |
|
71 | - * free to return other data as well. |
|
72 | - * |
|
73 | - * You are responsible for advancing the reader to the next element. Not |
|
74 | - * doing anything will result in a never-ending loop. |
|
75 | - * |
|
76 | - * If you just want to skip parsing for this element altogether, you can |
|
77 | - * just call $reader->next(); |
|
78 | - * |
|
79 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
80 | - * the next element. |
|
81 | - * |
|
82 | - * @param Reader $reader |
|
83 | - * @return mixed |
|
84 | - */ |
|
85 | - static function xmlDeserialize(Reader $reader) { |
|
86 | - $tags = []; |
|
64 | + /** |
|
65 | + * The deserialize method is called during xml parsing. |
|
66 | + * |
|
67 | + * This method is called statictly, this is because in theory this method |
|
68 | + * may be used as a type of constructor, or factory method. |
|
69 | + * |
|
70 | + * Often you want to return an instance of the current class, but you are |
|
71 | + * free to return other data as well. |
|
72 | + * |
|
73 | + * You are responsible for advancing the reader to the next element. Not |
|
74 | + * doing anything will result in a never-ending loop. |
|
75 | + * |
|
76 | + * If you just want to skip parsing for this element altogether, you can |
|
77 | + * just call $reader->next(); |
|
78 | + * |
|
79 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
80 | + * the next element. |
|
81 | + * |
|
82 | + * @param Reader $reader |
|
83 | + * @return mixed |
|
84 | + */ |
|
85 | + static function xmlDeserialize(Reader $reader) { |
|
86 | + $tags = []; |
|
87 | 87 | |
88 | - $tree = $reader->parseInnerTree(); |
|
89 | - if ($tree === null) { |
|
90 | - return null; |
|
91 | - } |
|
92 | - foreach ($tree as $elem) { |
|
93 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
94 | - $tags[] = $elem['value']; |
|
95 | - } |
|
96 | - } |
|
97 | - return new self($tags); |
|
98 | - } |
|
88 | + $tree = $reader->parseInnerTree(); |
|
89 | + if ($tree === null) { |
|
90 | + return null; |
|
91 | + } |
|
92 | + foreach ($tree as $elem) { |
|
93 | + if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
94 | + $tags[] = $elem['value']; |
|
95 | + } |
|
96 | + } |
|
97 | + return new self($tags); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * The xmlSerialize metod is called during xml writing. |
|
102 | - * |
|
103 | - * Use the $writer argument to write its own xml serialization. |
|
104 | - * |
|
105 | - * An important note: do _not_ create a parent element. Any element |
|
106 | - * implementing XmlSerializble should only ever write what's considered |
|
107 | - * its 'inner xml'. |
|
108 | - * |
|
109 | - * The parent of the current element is responsible for writing a |
|
110 | - * containing element. |
|
111 | - * |
|
112 | - * This allows serializers to be re-used for different element names. |
|
113 | - * |
|
114 | - * If you are opening new elements, you must also close them again. |
|
115 | - * |
|
116 | - * @param Writer $writer |
|
117 | - * @return void |
|
118 | - */ |
|
119 | - function xmlSerialize(Writer $writer) { |
|
100 | + /** |
|
101 | + * The xmlSerialize metod is called during xml writing. |
|
102 | + * |
|
103 | + * Use the $writer argument to write its own xml serialization. |
|
104 | + * |
|
105 | + * An important note: do _not_ create a parent element. Any element |
|
106 | + * implementing XmlSerializble should only ever write what's considered |
|
107 | + * its 'inner xml'. |
|
108 | + * |
|
109 | + * The parent of the current element is responsible for writing a |
|
110 | + * containing element. |
|
111 | + * |
|
112 | + * This allows serializers to be re-used for different element names. |
|
113 | + * |
|
114 | + * If you are opening new elements, you must also close them again. |
|
115 | + * |
|
116 | + * @param Writer $writer |
|
117 | + * @return void |
|
118 | + */ |
|
119 | + function xmlSerialize(Writer $writer) { |
|
120 | 120 | |
121 | - foreach ($this->tags as $tag) { |
|
122 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
123 | - } |
|
124 | - } |
|
121 | + foreach ($this->tags as $tag) { |
|
122 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
123 | + } |
|
124 | + } |
|
125 | 125 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | return null; |
91 | 91 | } |
92 | 92 | foreach ($tree as $elem) { |
93 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
93 | + if ($elem['name'] === '{'.self::NS_OWNCLOUD.'}tag') { |
|
94 | 94 | $tags[] = $elem['value']; |
95 | 95 | } |
96 | 96 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | function xmlSerialize(Writer $writer) { |
120 | 120 | |
121 | 121 | foreach ($this->tags as $tag) { |
122 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
122 | + $writer->writeElement('{'.self::NS_OWNCLOUD.'}tag', $tag); |
|
123 | 123 | } |
124 | 124 | } |
125 | 125 | } |
@@ -30,7 +30,6 @@ |
||
30 | 30 | |
31 | 31 | namespace OC\Share; |
32 | 32 | |
33 | -use DateTime; |
|
34 | 33 | use OCP\IL10N; |
35 | 34 | use OCP\IURLGenerator; |
36 | 35 | use OCP\IUser; |
@@ -46,113 +46,113 @@ |
||
46 | 46 | */ |
47 | 47 | class MailNotifications { |
48 | 48 | |
49 | - /** @var IUser sender userId */ |
|
50 | - private $user; |
|
51 | - /** @var string sender email address */ |
|
52 | - private $replyTo; |
|
53 | - /** @var string */ |
|
54 | - private $senderDisplayName; |
|
55 | - /** @var IL10N */ |
|
56 | - private $l; |
|
57 | - /** @var IMailer */ |
|
58 | - private $mailer; |
|
59 | - /** @var Defaults */ |
|
60 | - private $defaults; |
|
61 | - /** @var ILogger */ |
|
62 | - private $logger; |
|
63 | - /** @var IURLGenerator */ |
|
64 | - private $urlGenerator; |
|
49 | + /** @var IUser sender userId */ |
|
50 | + private $user; |
|
51 | + /** @var string sender email address */ |
|
52 | + private $replyTo; |
|
53 | + /** @var string */ |
|
54 | + private $senderDisplayName; |
|
55 | + /** @var IL10N */ |
|
56 | + private $l; |
|
57 | + /** @var IMailer */ |
|
58 | + private $mailer; |
|
59 | + /** @var Defaults */ |
|
60 | + private $defaults; |
|
61 | + /** @var ILogger */ |
|
62 | + private $logger; |
|
63 | + /** @var IURLGenerator */ |
|
64 | + private $urlGenerator; |
|
65 | 65 | |
66 | - /** |
|
67 | - * @param IUser $user |
|
68 | - * @param IL10N $l10n |
|
69 | - * @param IMailer $mailer |
|
70 | - * @param ILogger $logger |
|
71 | - * @param Defaults $defaults |
|
72 | - * @param IURLGenerator $urlGenerator |
|
73 | - */ |
|
74 | - public function __construct(IUser $user, |
|
75 | - IL10N $l10n, |
|
76 | - IMailer $mailer, |
|
77 | - ILogger $logger, |
|
78 | - Defaults $defaults, |
|
79 | - IURLGenerator $urlGenerator) { |
|
80 | - $this->l = $l10n; |
|
81 | - $this->user = $user; |
|
82 | - $this->mailer = $mailer; |
|
83 | - $this->logger = $logger; |
|
84 | - $this->defaults = $defaults; |
|
85 | - $this->urlGenerator = $urlGenerator; |
|
66 | + /** |
|
67 | + * @param IUser $user |
|
68 | + * @param IL10N $l10n |
|
69 | + * @param IMailer $mailer |
|
70 | + * @param ILogger $logger |
|
71 | + * @param Defaults $defaults |
|
72 | + * @param IURLGenerator $urlGenerator |
|
73 | + */ |
|
74 | + public function __construct(IUser $user, |
|
75 | + IL10N $l10n, |
|
76 | + IMailer $mailer, |
|
77 | + ILogger $logger, |
|
78 | + Defaults $defaults, |
|
79 | + IURLGenerator $urlGenerator) { |
|
80 | + $this->l = $l10n; |
|
81 | + $this->user = $user; |
|
82 | + $this->mailer = $mailer; |
|
83 | + $this->logger = $logger; |
|
84 | + $this->defaults = $defaults; |
|
85 | + $this->urlGenerator = $urlGenerator; |
|
86 | 86 | |
87 | - $this->replyTo = $this->user->getEMailAddress(); |
|
88 | - $this->senderDisplayName = $this->user->getDisplayName(); |
|
89 | - } |
|
87 | + $this->replyTo = $this->user->getEMailAddress(); |
|
88 | + $this->senderDisplayName = $this->user->getDisplayName(); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * inform recipient about public link share |
|
93 | - * |
|
94 | - * @param string $recipient recipient email address |
|
95 | - * @param string $filename the shared file |
|
96 | - * @param string $link the public link |
|
97 | - * @param int $expiration expiration date (timestamp) |
|
98 | - * @return string[] $result of failed recipients |
|
99 | - */ |
|
100 | - public function sendLinkShareMail($recipient, $filename, $link, $expiration) { |
|
101 | - $subject = (string)$this->l->t('%s shared »%s« with you', [$this->senderDisplayName, $filename]); |
|
102 | - list($htmlBody, $textBody) = $this->createMailBody($filename, $link, $expiration); |
|
91 | + /** |
|
92 | + * inform recipient about public link share |
|
93 | + * |
|
94 | + * @param string $recipient recipient email address |
|
95 | + * @param string $filename the shared file |
|
96 | + * @param string $link the public link |
|
97 | + * @param int $expiration expiration date (timestamp) |
|
98 | + * @return string[] $result of failed recipients |
|
99 | + */ |
|
100 | + public function sendLinkShareMail($recipient, $filename, $link, $expiration) { |
|
101 | + $subject = (string)$this->l->t('%s shared »%s« with you', [$this->senderDisplayName, $filename]); |
|
102 | + list($htmlBody, $textBody) = $this->createMailBody($filename, $link, $expiration); |
|
103 | 103 | |
104 | - $recipient = str_replace([', ', '; ', ',', ';', ' '], ',', $recipient); |
|
105 | - $recipients = explode(',', $recipient); |
|
106 | - try { |
|
107 | - $message = $this->mailer->createMessage(); |
|
108 | - $message->setSubject($subject); |
|
109 | - $message->setTo($recipients); |
|
110 | - $message->setHtmlBody($htmlBody); |
|
111 | - $message->setPlainBody($textBody); |
|
112 | - $message->setFrom([ |
|
113 | - Util::getDefaultEmailAddress('sharing-noreply') => |
|
114 | - (string)$this->l->t('%s via %s', [ |
|
115 | - $this->senderDisplayName, |
|
116 | - $this->defaults->getName() |
|
117 | - ]), |
|
118 | - ]); |
|
119 | - if(!is_null($this->replyTo)) { |
|
120 | - $message->setReplyTo([$this->replyTo]); |
|
121 | - } |
|
104 | + $recipient = str_replace([', ', '; ', ',', ';', ' '], ',', $recipient); |
|
105 | + $recipients = explode(',', $recipient); |
|
106 | + try { |
|
107 | + $message = $this->mailer->createMessage(); |
|
108 | + $message->setSubject($subject); |
|
109 | + $message->setTo($recipients); |
|
110 | + $message->setHtmlBody($htmlBody); |
|
111 | + $message->setPlainBody($textBody); |
|
112 | + $message->setFrom([ |
|
113 | + Util::getDefaultEmailAddress('sharing-noreply') => |
|
114 | + (string)$this->l->t('%s via %s', [ |
|
115 | + $this->senderDisplayName, |
|
116 | + $this->defaults->getName() |
|
117 | + ]), |
|
118 | + ]); |
|
119 | + if(!is_null($this->replyTo)) { |
|
120 | + $message->setReplyTo([$this->replyTo]); |
|
121 | + } |
|
122 | 122 | |
123 | - return $this->mailer->send($message); |
|
124 | - } catch (\Exception $e) { |
|
125 | - $this->logger->error("Can't send mail with public link to $recipient: ".$e->getMessage(), ['app' => 'sharing']); |
|
126 | - return [$recipient]; |
|
127 | - } |
|
128 | - } |
|
123 | + return $this->mailer->send($message); |
|
124 | + } catch (\Exception $e) { |
|
125 | + $this->logger->error("Can't send mail with public link to $recipient: ".$e->getMessage(), ['app' => 'sharing']); |
|
126 | + return [$recipient]; |
|
127 | + } |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * create mail body for plain text and html mail |
|
132 | - * |
|
133 | - * @param string $filename the shared file |
|
134 | - * @param string $link link to the shared file |
|
135 | - * @param int $expiration expiration date (timestamp) |
|
136 | - * @param string $prefix prefix of mail template files |
|
137 | - * @return array an array of the html mail body and the plain text mail body |
|
138 | - */ |
|
139 | - private function createMailBody($filename, $link, $expiration, $prefix = '') { |
|
140 | - $formattedDate = $expiration ? $this->l->l('date', $expiration) : null; |
|
130 | + /** |
|
131 | + * create mail body for plain text and html mail |
|
132 | + * |
|
133 | + * @param string $filename the shared file |
|
134 | + * @param string $link link to the shared file |
|
135 | + * @param int $expiration expiration date (timestamp) |
|
136 | + * @param string $prefix prefix of mail template files |
|
137 | + * @return array an array of the html mail body and the plain text mail body |
|
138 | + */ |
|
139 | + private function createMailBody($filename, $link, $expiration, $prefix = '') { |
|
140 | + $formattedDate = $expiration ? $this->l->l('date', $expiration) : null; |
|
141 | 141 | |
142 | - $html = new \OC_Template('core', $prefix . 'mail', ''); |
|
143 | - $html->assign ('link', $link); |
|
144 | - $html->assign ('user_displayname', $this->senderDisplayName); |
|
145 | - $html->assign ('filename', $filename); |
|
146 | - $html->assign('expiration', $formattedDate); |
|
147 | - $htmlMail = $html->fetchPage(); |
|
142 | + $html = new \OC_Template('core', $prefix . 'mail', ''); |
|
143 | + $html->assign ('link', $link); |
|
144 | + $html->assign ('user_displayname', $this->senderDisplayName); |
|
145 | + $html->assign ('filename', $filename); |
|
146 | + $html->assign('expiration', $formattedDate); |
|
147 | + $htmlMail = $html->fetchPage(); |
|
148 | 148 | |
149 | - $plainText = new \OC_Template('core', $prefix . 'altmail', ''); |
|
150 | - $plainText->assign ('link', $link); |
|
151 | - $plainText->assign ('user_displayname', $this->senderDisplayName); |
|
152 | - $plainText->assign ('filename', $filename); |
|
153 | - $plainText->assign('expiration', $formattedDate); |
|
154 | - $plainTextMail = $plainText->fetchPage(); |
|
149 | + $plainText = new \OC_Template('core', $prefix . 'altmail', ''); |
|
150 | + $plainText->assign ('link', $link); |
|
151 | + $plainText->assign ('user_displayname', $this->senderDisplayName); |
|
152 | + $plainText->assign ('filename', $filename); |
|
153 | + $plainText->assign('expiration', $formattedDate); |
|
154 | + $plainTextMail = $plainText->fetchPage(); |
|
155 | 155 | |
156 | - return [$htmlMail, $plainTextMail]; |
|
157 | - } |
|
156 | + return [$htmlMail, $plainTextMail]; |
|
157 | + } |
|
158 | 158 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * @return string[] $result of failed recipients |
99 | 99 | */ |
100 | 100 | public function sendLinkShareMail($recipient, $filename, $link, $expiration) { |
101 | - $subject = (string)$this->l->t('%s shared »%s« with you', [$this->senderDisplayName, $filename]); |
|
101 | + $subject = (string) $this->l->t('%s shared »%s« with you', [$this->senderDisplayName, $filename]); |
|
102 | 102 | list($htmlBody, $textBody) = $this->createMailBody($filename, $link, $expiration); |
103 | 103 | |
104 | 104 | $recipient = str_replace([', ', '; ', ',', ';', ' '], ',', $recipient); |
@@ -111,12 +111,12 @@ discard block |
||
111 | 111 | $message->setPlainBody($textBody); |
112 | 112 | $message->setFrom([ |
113 | 113 | Util::getDefaultEmailAddress('sharing-noreply') => |
114 | - (string)$this->l->t('%s via %s', [ |
|
114 | + (string) $this->l->t('%s via %s', [ |
|
115 | 115 | $this->senderDisplayName, |
116 | 116 | $this->defaults->getName() |
117 | 117 | ]), |
118 | 118 | ]); |
119 | - if(!is_null($this->replyTo)) { |
|
119 | + if (!is_null($this->replyTo)) { |
|
120 | 120 | $message->setReplyTo([$this->replyTo]); |
121 | 121 | } |
122 | 122 | |
@@ -139,17 +139,17 @@ discard block |
||
139 | 139 | private function createMailBody($filename, $link, $expiration, $prefix = '') { |
140 | 140 | $formattedDate = $expiration ? $this->l->l('date', $expiration) : null; |
141 | 141 | |
142 | - $html = new \OC_Template('core', $prefix . 'mail', ''); |
|
143 | - $html->assign ('link', $link); |
|
144 | - $html->assign ('user_displayname', $this->senderDisplayName); |
|
145 | - $html->assign ('filename', $filename); |
|
146 | - $html->assign('expiration', $formattedDate); |
|
142 | + $html = new \OC_Template('core', $prefix.'mail', ''); |
|
143 | + $html->assign('link', $link); |
|
144 | + $html->assign('user_displayname', $this->senderDisplayName); |
|
145 | + $html->assign('filename', $filename); |
|
146 | + $html->assign('expiration', $formattedDate); |
|
147 | 147 | $htmlMail = $html->fetchPage(); |
148 | 148 | |
149 | - $plainText = new \OC_Template('core', $prefix . 'altmail', ''); |
|
150 | - $plainText->assign ('link', $link); |
|
151 | - $plainText->assign ('user_displayname', $this->senderDisplayName); |
|
152 | - $plainText->assign ('filename', $filename); |
|
149 | + $plainText = new \OC_Template('core', $prefix.'altmail', ''); |
|
150 | + $plainText->assign('link', $link); |
|
151 | + $plainText->assign('user_displayname', $this->senderDisplayName); |
|
152 | + $plainText->assign('filename', $filename); |
|
153 | 153 | $plainText->assign('expiration', $formattedDate); |
154 | 154 | $plainTextMail = $plainText->fetchPage(); |
155 | 155 |
@@ -51,7 +51,6 @@ |
||
51 | 51 | use OC\App\InfoParser; |
52 | 52 | use OC\App\Platform; |
53 | 53 | use OC\Installer; |
54 | -use OC\OCSClient; |
|
55 | 54 | use OC\Repair; |
56 | 55 | use OCP\App\ManagerEvent; |
57 | 56 |
@@ -1063,7 +1063,7 @@ discard block |
||
1063 | 1063 | * @param string $app |
1064 | 1064 | * @param \OCP\IConfig $config |
1065 | 1065 | * @param \OCP\IL10N $l |
1066 | - * @return bool |
|
1066 | + * @return string |
|
1067 | 1067 | * |
1068 | 1068 | * @throws Exception if app is not compatible with this version of ownCloud |
1069 | 1069 | * @throws Exception if no app-name was specified |
@@ -1243,6 +1243,11 @@ discard block |
||
1243 | 1243 | } |
1244 | 1244 | } |
1245 | 1245 | |
1246 | + /** |
|
1247 | + * @param string $lang |
|
1248 | + * |
|
1249 | + * @return string |
|
1250 | + */ |
|
1246 | 1251 | protected static function findBestL10NOption($options, $lang) { |
1247 | 1252 | $fallback = $similarLangFallback = $englishFallback = false; |
1248 | 1253 |
@@ -61,1275 +61,1275 @@ |
||
61 | 61 | * upgrading and removing apps. |
62 | 62 | */ |
63 | 63 | class OC_App { |
64 | - static private $appVersion = []; |
|
65 | - static private $adminForms = array(); |
|
66 | - static private $personalForms = array(); |
|
67 | - static private $appInfo = array(); |
|
68 | - static private $appTypes = array(); |
|
69 | - static private $loadedApps = array(); |
|
70 | - static private $altLogin = array(); |
|
71 | - static private $alreadyRegistered = []; |
|
72 | - const officialApp = 200; |
|
73 | - |
|
74 | - /** |
|
75 | - * clean the appId |
|
76 | - * |
|
77 | - * @param string|boolean $app AppId that needs to be cleaned |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - public static function cleanAppId($app) { |
|
81 | - return str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Check if an app is loaded |
|
86 | - * |
|
87 | - * @param string $app |
|
88 | - * @return bool |
|
89 | - */ |
|
90 | - public static function isAppLoaded($app) { |
|
91 | - return in_array($app, self::$loadedApps, true); |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * loads all apps |
|
96 | - * |
|
97 | - * @param string[] | string | null $types |
|
98 | - * @return bool |
|
99 | - * |
|
100 | - * This function walks through the ownCloud directory and loads all apps |
|
101 | - * it can find. A directory contains an app if the file /appinfo/info.xml |
|
102 | - * exists. |
|
103 | - * |
|
104 | - * if $types is set, only apps of those types will be loaded |
|
105 | - */ |
|
106 | - public static function loadApps($types = null) { |
|
107 | - if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
108 | - return false; |
|
109 | - } |
|
110 | - // Load the enabled apps here |
|
111 | - $apps = self::getEnabledApps(); |
|
112 | - |
|
113 | - // Add each apps' folder as allowed class path |
|
114 | - foreach($apps as $app) { |
|
115 | - $path = self::getAppPath($app); |
|
116 | - if($path !== false) { |
|
117 | - self::registerAutoloading($app, $path); |
|
118 | - } |
|
119 | - } |
|
120 | - |
|
121 | - // prevent app.php from printing output |
|
122 | - ob_start(); |
|
123 | - foreach ($apps as $app) { |
|
124 | - if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) { |
|
125 | - self::loadApp($app); |
|
126 | - } |
|
127 | - } |
|
128 | - ob_end_clean(); |
|
129 | - |
|
130 | - return true; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * load a single app |
|
135 | - * |
|
136 | - * @param string $app |
|
137 | - * @param bool $checkUpgrade whether an upgrade check should be done |
|
138 | - * @throws \OC\NeedsUpdateException |
|
139 | - */ |
|
140 | - public static function loadApp($app, $checkUpgrade = true) { |
|
141 | - self::$loadedApps[] = $app; |
|
142 | - $appPath = self::getAppPath($app); |
|
143 | - if($appPath === false) { |
|
144 | - return; |
|
145 | - } |
|
146 | - |
|
147 | - // in case someone calls loadApp() directly |
|
148 | - self::registerAutoloading($app, $appPath); |
|
149 | - |
|
150 | - if (is_file($appPath . '/appinfo/app.php')) { |
|
151 | - \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
152 | - if ($checkUpgrade and self::shouldUpgrade($app)) { |
|
153 | - throw new \OC\NeedsUpdateException(); |
|
154 | - } |
|
155 | - self::requireAppFile($app); |
|
156 | - if (self::isType($app, array('authentication'))) { |
|
157 | - // since authentication apps affect the "is app enabled for group" check, |
|
158 | - // the enabled apps cache needs to be cleared to make sure that the |
|
159 | - // next time getEnableApps() is called it will also include apps that were |
|
160 | - // enabled for groups |
|
161 | - self::$enabledAppsCache = array(); |
|
162 | - } |
|
163 | - \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
164 | - } |
|
165 | - |
|
166 | - $info = self::getAppInfo($app); |
|
167 | - if (!empty($info['activity']['filters'])) { |
|
168 | - foreach ($info['activity']['filters'] as $filter) { |
|
169 | - \OC::$server->getActivityManager()->registerFilter($filter); |
|
170 | - } |
|
171 | - } |
|
172 | - if (!empty($info['activity']['settings'])) { |
|
173 | - foreach ($info['activity']['settings'] as $setting) { |
|
174 | - \OC::$server->getActivityManager()->registerSetting($setting); |
|
175 | - } |
|
176 | - } |
|
177 | - if (!empty($info['activity']['providers'])) { |
|
178 | - foreach ($info['activity']['providers'] as $provider) { |
|
179 | - \OC::$server->getActivityManager()->registerProvider($provider); |
|
180 | - } |
|
181 | - } |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * @internal |
|
186 | - * @param string $app |
|
187 | - * @param string $path |
|
188 | - */ |
|
189 | - public static function registerAutoloading($app, $path) { |
|
190 | - $key = $app . '-' . $path; |
|
191 | - if(isset(self::$alreadyRegistered[$key])) { |
|
192 | - return; |
|
193 | - } |
|
194 | - self::$alreadyRegistered[$key] = true; |
|
195 | - // Register on PSR-4 composer autoloader |
|
196 | - $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
|
197 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
198 | - if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
|
199 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
200 | - } |
|
201 | - |
|
202 | - // Register on legacy autoloader |
|
203 | - \OC::$loader->addValidRoot($path); |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Load app.php from the given app |
|
208 | - * |
|
209 | - * @param string $app app name |
|
210 | - */ |
|
211 | - private static function requireAppFile($app) { |
|
212 | - try { |
|
213 | - // encapsulated here to avoid variable scope conflicts |
|
214 | - require_once $app . '/appinfo/app.php'; |
|
215 | - } catch (Error $ex) { |
|
216 | - \OC::$server->getLogger()->logException($ex); |
|
217 | - $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
|
218 | - if (!in_array($app, $blacklist)) { |
|
219 | - self::disable($app); |
|
220 | - } |
|
221 | - } |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * check if an app is of a specific type |
|
226 | - * |
|
227 | - * @param string $app |
|
228 | - * @param string|array $types |
|
229 | - * @return bool |
|
230 | - */ |
|
231 | - public static function isType($app, $types) { |
|
232 | - if (is_string($types)) { |
|
233 | - $types = array($types); |
|
234 | - } |
|
235 | - $appTypes = self::getAppTypes($app); |
|
236 | - foreach ($types as $type) { |
|
237 | - if (array_search($type, $appTypes) !== false) { |
|
238 | - return true; |
|
239 | - } |
|
240 | - } |
|
241 | - return false; |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * get the types of an app |
|
246 | - * |
|
247 | - * @param string $app |
|
248 | - * @return array |
|
249 | - */ |
|
250 | - private static function getAppTypes($app) { |
|
251 | - //load the cache |
|
252 | - if (count(self::$appTypes) == 0) { |
|
253 | - self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types'); |
|
254 | - } |
|
255 | - |
|
256 | - if (isset(self::$appTypes[$app])) { |
|
257 | - return explode(',', self::$appTypes[$app]); |
|
258 | - } else { |
|
259 | - return array(); |
|
260 | - } |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * read app types from info.xml and cache them in the database |
|
265 | - */ |
|
266 | - public static function setAppTypes($app) { |
|
267 | - $appData = self::getAppInfo($app); |
|
268 | - if(!is_array($appData)) { |
|
269 | - return; |
|
270 | - } |
|
271 | - |
|
272 | - if (isset($appData['types'])) { |
|
273 | - $appTypes = implode(',', $appData['types']); |
|
274 | - } else { |
|
275 | - $appTypes = ''; |
|
276 | - $appData['types'] = []; |
|
277 | - } |
|
278 | - |
|
279 | - \OC::$server->getAppConfig()->setValue($app, 'types', $appTypes); |
|
280 | - |
|
281 | - if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) { |
|
282 | - $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'yes'); |
|
283 | - if ($enabled !== 'yes' && $enabled !== 'no') { |
|
284 | - \OC::$server->getAppConfig()->setValue($app, 'enabled', 'yes'); |
|
285 | - } |
|
286 | - } |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * check if app is shipped |
|
291 | - * |
|
292 | - * @param string $appId the id of the app to check |
|
293 | - * @return bool |
|
294 | - * |
|
295 | - * Check if an app that is installed is a shipped app or installed from the appstore. |
|
296 | - */ |
|
297 | - public static function isShipped($appId) { |
|
298 | - return \OC::$server->getAppManager()->isShipped($appId); |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * get all enabled apps |
|
303 | - */ |
|
304 | - protected static $enabledAppsCache = array(); |
|
305 | - |
|
306 | - /** |
|
307 | - * Returns apps enabled for the current user. |
|
308 | - * |
|
309 | - * @param bool $forceRefresh whether to refresh the cache |
|
310 | - * @param bool $all whether to return apps for all users, not only the |
|
311 | - * currently logged in one |
|
312 | - * @return string[] |
|
313 | - */ |
|
314 | - public static function getEnabledApps($forceRefresh = false, $all = false) { |
|
315 | - if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
316 | - return array(); |
|
317 | - } |
|
318 | - // in incognito mode or when logged out, $user will be false, |
|
319 | - // which is also the case during an upgrade |
|
320 | - $appManager = \OC::$server->getAppManager(); |
|
321 | - if ($all) { |
|
322 | - $user = null; |
|
323 | - } else { |
|
324 | - $user = \OC::$server->getUserSession()->getUser(); |
|
325 | - } |
|
326 | - |
|
327 | - if (is_null($user)) { |
|
328 | - $apps = $appManager->getInstalledApps(); |
|
329 | - } else { |
|
330 | - $apps = $appManager->getEnabledAppsForUser($user); |
|
331 | - } |
|
332 | - $apps = array_filter($apps, function ($app) { |
|
333 | - return $app !== 'files';//we add this manually |
|
334 | - }); |
|
335 | - sort($apps); |
|
336 | - array_unshift($apps, 'files'); |
|
337 | - return $apps; |
|
338 | - } |
|
339 | - |
|
340 | - /** |
|
341 | - * checks whether or not an app is enabled |
|
342 | - * |
|
343 | - * @param string $app app |
|
344 | - * @return bool |
|
345 | - * |
|
346 | - * This function checks whether or not an app is enabled. |
|
347 | - */ |
|
348 | - public static function isEnabled($app) { |
|
349 | - return \OC::$server->getAppManager()->isEnabledForUser($app); |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * enables an app |
|
354 | - * |
|
355 | - * @param string $appId |
|
356 | - * @param array $groups (optional) when set, only these groups will have access to the app |
|
357 | - * @throws \Exception |
|
358 | - * @return void |
|
359 | - * |
|
360 | - * This function set an app as enabled in appconfig. |
|
361 | - */ |
|
362 | - public function enable($appId, |
|
363 | - $groups = null) { |
|
364 | - self::$enabledAppsCache = []; // flush |
|
365 | - $l = \OC::$server->getL10N('core'); |
|
366 | - $config = \OC::$server->getConfig(); |
|
367 | - |
|
368 | - // Check if app is already downloaded |
|
369 | - $installer = new Installer( |
|
370 | - \OC::$server->getAppFetcher(), |
|
371 | - \OC::$server->getHTTPClientService(), |
|
372 | - \OC::$server->getTempManager(), |
|
373 | - \OC::$server->getLogger() |
|
374 | - ); |
|
375 | - $isDownloaded = $installer->isDownloaded($appId); |
|
376 | - |
|
377 | - if(!$isDownloaded) { |
|
378 | - $installer->downloadApp($appId); |
|
379 | - } |
|
380 | - |
|
381 | - if (!Installer::isInstalled($appId)) { |
|
382 | - $appId = self::installApp( |
|
383 | - $appId, |
|
384 | - $config, |
|
385 | - $l |
|
386 | - ); |
|
387 | - $appPath = self::getAppPath($appId); |
|
388 | - self::registerAutoloading($appId, $appPath); |
|
389 | - $installer->installApp($appId); |
|
390 | - } else { |
|
391 | - // check for required dependencies |
|
392 | - $info = self::getAppInfo($appId); |
|
393 | - self::checkAppDependencies($config, $l, $info); |
|
394 | - $appPath = self::getAppPath($appId); |
|
395 | - self::registerAutoloading($appId, $appPath); |
|
396 | - $installer->installApp($appId); |
|
397 | - } |
|
398 | - |
|
399 | - $appManager = \OC::$server->getAppManager(); |
|
400 | - if (!is_null($groups)) { |
|
401 | - $groupManager = \OC::$server->getGroupManager(); |
|
402 | - $groupsList = []; |
|
403 | - foreach ($groups as $group) { |
|
404 | - $groupItem = $groupManager->get($group); |
|
405 | - if ($groupItem instanceof \OCP\IGroup) { |
|
406 | - $groupsList[] = $groupManager->get($group); |
|
407 | - } |
|
408 | - } |
|
409 | - $appManager->enableAppForGroups($appId, $groupsList); |
|
410 | - } else { |
|
411 | - $appManager->enableApp($appId); |
|
412 | - } |
|
413 | - |
|
414 | - $info = self::getAppInfo($appId); |
|
415 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
416 | - $appPath = self::getAppPath($appId); |
|
417 | - self::registerAutoloading($appId, $appPath); |
|
418 | - \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
419 | - } |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * @param string $app |
|
424 | - * @return bool |
|
425 | - */ |
|
426 | - public static function removeApp($app) { |
|
427 | - if (self::isShipped($app)) { |
|
428 | - return false; |
|
429 | - } |
|
430 | - |
|
431 | - $installer = new Installer( |
|
432 | - \OC::$server->getAppFetcher(), |
|
433 | - \OC::$server->getHTTPClientService(), |
|
434 | - \OC::$server->getTempManager(), |
|
435 | - \OC::$server->getLogger() |
|
436 | - ); |
|
437 | - return $installer->removeApp($app); |
|
438 | - } |
|
439 | - |
|
440 | - /** |
|
441 | - * This function set an app as disabled in appconfig. |
|
442 | - * |
|
443 | - * @param string $app app |
|
444 | - * @throws Exception |
|
445 | - */ |
|
446 | - public static function disable($app) { |
|
447 | - // flush |
|
448 | - self::$enabledAppsCache = array(); |
|
449 | - |
|
450 | - // run uninstall steps |
|
451 | - $appData = OC_App::getAppInfo($app); |
|
452 | - if (!is_null($appData)) { |
|
453 | - OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']); |
|
454 | - } |
|
455 | - |
|
456 | - // emit disable hook - needed anymore ? |
|
457 | - \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app)); |
|
458 | - |
|
459 | - // finally disable it |
|
460 | - $appManager = \OC::$server->getAppManager(); |
|
461 | - $appManager->disableApp($app); |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * Returns the Settings Navigation |
|
466 | - * |
|
467 | - * @return string[] |
|
468 | - * |
|
469 | - * This function returns an array containing all settings pages added. The |
|
470 | - * entries are sorted by the key 'order' ascending. |
|
471 | - */ |
|
472 | - public static function getSettingsNavigation() { |
|
473 | - $l = \OC::$server->getL10N('lib'); |
|
474 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
475 | - |
|
476 | - $settings = array(); |
|
477 | - // by default, settings only contain the help menu |
|
478 | - if (\OC::$server->getSystemConfig()->getValue('knowledgebaseenabled', true)) { |
|
479 | - $settings = array( |
|
480 | - array( |
|
481 | - "id" => "help", |
|
482 | - "order" => 4, |
|
483 | - "href" => $urlGenerator->linkToRoute('settings_help'), |
|
484 | - "name" => $l->t("Help"), |
|
485 | - "icon" => $urlGenerator->imagePath("settings", "help.svg") |
|
486 | - ) |
|
487 | - ); |
|
488 | - } |
|
489 | - |
|
490 | - // if the user is logged-in |
|
491 | - if (OC_User::isLoggedIn()) { |
|
492 | - // personal menu |
|
493 | - $settings[] = array( |
|
494 | - "id" => "personal", |
|
495 | - "order" => 1, |
|
496 | - "href" => $urlGenerator->linkToRoute('settings_personal'), |
|
497 | - "name" => $l->t("Personal"), |
|
498 | - "icon" => $urlGenerator->imagePath("settings", "personal.svg") |
|
499 | - ); |
|
500 | - |
|
501 | - //SubAdmins are also allowed to access user management |
|
502 | - $userObject = \OC::$server->getUserSession()->getUser(); |
|
503 | - $isSubAdmin = false; |
|
504 | - if($userObject !== null) { |
|
505 | - $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
|
506 | - } |
|
507 | - if ($isSubAdmin) { |
|
508 | - // admin users menu |
|
509 | - $settings[] = array( |
|
510 | - "id" => "core_users", |
|
511 | - "order" => 3, |
|
512 | - "href" => $urlGenerator->linkToRoute('settings_users'), |
|
513 | - "name" => $l->t("Users"), |
|
514 | - "icon" => $urlGenerator->imagePath("settings", "users.svg") |
|
515 | - ); |
|
516 | - } |
|
517 | - |
|
518 | - // if the user is an admin |
|
519 | - if (OC_User::isAdminUser(OC_User::getUser())) { |
|
520 | - // admin settings |
|
521 | - $settings[] = array( |
|
522 | - "id" => "admin", |
|
523 | - "order" => 2, |
|
524 | - "href" => $urlGenerator->linkToRoute('settings.AdminSettings.index'), |
|
525 | - "name" => $l->t("Admin"), |
|
526 | - "icon" => $urlGenerator->imagePath("settings", "admin.svg") |
|
527 | - ); |
|
528 | - } |
|
529 | - } |
|
530 | - |
|
531 | - $navigation = self::proceedNavigation($settings); |
|
532 | - return $navigation; |
|
533 | - } |
|
534 | - |
|
535 | - // This is private as well. It simply works, so don't ask for more details |
|
536 | - private static function proceedNavigation($list) { |
|
537 | - $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); |
|
538 | - foreach ($list as &$navEntry) { |
|
539 | - if ($navEntry['id'] == $activeApp) { |
|
540 | - $navEntry['active'] = true; |
|
541 | - } else { |
|
542 | - $navEntry['active'] = false; |
|
543 | - } |
|
544 | - } |
|
545 | - unset($navEntry); |
|
546 | - |
|
547 | - usort($list, function($a, $b) { |
|
548 | - if (isset($a['order']) && isset($b['order'])) { |
|
549 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
550 | - } else if (isset($a['order']) || isset($b['order'])) { |
|
551 | - return isset($a['order']) ? -1 : 1; |
|
552 | - } else { |
|
553 | - return ($a['name'] < $b['name']) ? -1 : 1; |
|
554 | - } |
|
555 | - }); |
|
556 | - |
|
557 | - return $list; |
|
558 | - } |
|
559 | - |
|
560 | - /** |
|
561 | - * Get the path where to install apps |
|
562 | - * |
|
563 | - * @return string|false |
|
564 | - */ |
|
565 | - public static function getInstallPath() { |
|
566 | - if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) { |
|
567 | - return false; |
|
568 | - } |
|
569 | - |
|
570 | - foreach (OC::$APPSROOTS as $dir) { |
|
571 | - if (isset($dir['writable']) && $dir['writable'] === true) { |
|
572 | - return $dir['path']; |
|
573 | - } |
|
574 | - } |
|
575 | - |
|
576 | - \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR); |
|
577 | - return null; |
|
578 | - } |
|
579 | - |
|
580 | - |
|
581 | - /** |
|
582 | - * search for an app in all app-directories |
|
583 | - * |
|
584 | - * @param string $appId |
|
585 | - * @return false|string |
|
586 | - */ |
|
587 | - public static function findAppInDirectories($appId) { |
|
588 | - $sanitizedAppId = self::cleanAppId($appId); |
|
589 | - if($sanitizedAppId !== $appId) { |
|
590 | - return false; |
|
591 | - } |
|
592 | - static $app_dir = array(); |
|
593 | - |
|
594 | - if (isset($app_dir[$appId])) { |
|
595 | - return $app_dir[$appId]; |
|
596 | - } |
|
597 | - |
|
598 | - $possibleApps = array(); |
|
599 | - foreach (OC::$APPSROOTS as $dir) { |
|
600 | - if (file_exists($dir['path'] . '/' . $appId)) { |
|
601 | - $possibleApps[] = $dir; |
|
602 | - } |
|
603 | - } |
|
604 | - |
|
605 | - if (empty($possibleApps)) { |
|
606 | - return false; |
|
607 | - } elseif (count($possibleApps) === 1) { |
|
608 | - $dir = array_shift($possibleApps); |
|
609 | - $app_dir[$appId] = $dir; |
|
610 | - return $dir; |
|
611 | - } else { |
|
612 | - $versionToLoad = array(); |
|
613 | - foreach ($possibleApps as $possibleApp) { |
|
614 | - $version = self::getAppVersionByPath($possibleApp['path']); |
|
615 | - if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
|
616 | - $versionToLoad = array( |
|
617 | - 'dir' => $possibleApp, |
|
618 | - 'version' => $version, |
|
619 | - ); |
|
620 | - } |
|
621 | - } |
|
622 | - $app_dir[$appId] = $versionToLoad['dir']; |
|
623 | - return $versionToLoad['dir']; |
|
624 | - //TODO - write test |
|
625 | - } |
|
626 | - } |
|
627 | - |
|
628 | - /** |
|
629 | - * Get the directory for the given app. |
|
630 | - * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
631 | - * |
|
632 | - * @param string $appId |
|
633 | - * @return string|false |
|
634 | - */ |
|
635 | - public static function getAppPath($appId) { |
|
636 | - if ($appId === null || trim($appId) === '') { |
|
637 | - return false; |
|
638 | - } |
|
639 | - |
|
640 | - if (($dir = self::findAppInDirectories($appId)) != false) { |
|
641 | - return $dir['path'] . '/' . $appId; |
|
642 | - } |
|
643 | - return false; |
|
644 | - } |
|
645 | - |
|
646 | - /** |
|
647 | - * Get the path for the given app on the access |
|
648 | - * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
649 | - * |
|
650 | - * @param string $appId |
|
651 | - * @return string|false |
|
652 | - */ |
|
653 | - public static function getAppWebPath($appId) { |
|
654 | - if (($dir = self::findAppInDirectories($appId)) != false) { |
|
655 | - return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
656 | - } |
|
657 | - return false; |
|
658 | - } |
|
659 | - |
|
660 | - /** |
|
661 | - * get the last version of the app from appinfo/info.xml |
|
662 | - * |
|
663 | - * @param string $appId |
|
664 | - * @param bool $useCache |
|
665 | - * @return string |
|
666 | - */ |
|
667 | - public static function getAppVersion($appId, $useCache = true) { |
|
668 | - if($useCache && isset(self::$appVersion[$appId])) { |
|
669 | - return self::$appVersion[$appId]; |
|
670 | - } |
|
671 | - |
|
672 | - $file = self::getAppPath($appId); |
|
673 | - self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0'; |
|
674 | - return self::$appVersion[$appId]; |
|
675 | - } |
|
676 | - |
|
677 | - /** |
|
678 | - * get app's version based on it's path |
|
679 | - * |
|
680 | - * @param string $path |
|
681 | - * @return string |
|
682 | - */ |
|
683 | - public static function getAppVersionByPath($path) { |
|
684 | - $infoFile = $path . '/appinfo/info.xml'; |
|
685 | - $appData = self::getAppInfo($infoFile, true); |
|
686 | - return isset($appData['version']) ? $appData['version'] : ''; |
|
687 | - } |
|
688 | - |
|
689 | - |
|
690 | - /** |
|
691 | - * Read all app metadata from the info.xml file |
|
692 | - * |
|
693 | - * @param string $appId id of the app or the path of the info.xml file |
|
694 | - * @param bool $path |
|
695 | - * @param string $lang |
|
696 | - * @return array|null |
|
697 | - * @note all data is read from info.xml, not just pre-defined fields |
|
698 | - */ |
|
699 | - public static function getAppInfo($appId, $path = false, $lang = null) { |
|
700 | - if ($path) { |
|
701 | - $file = $appId; |
|
702 | - } else { |
|
703 | - if ($lang === null && isset(self::$appInfo[$appId])) { |
|
704 | - return self::$appInfo[$appId]; |
|
705 | - } |
|
706 | - $appPath = self::getAppPath($appId); |
|
707 | - if($appPath === false) { |
|
708 | - return null; |
|
709 | - } |
|
710 | - $file = $appPath . '/appinfo/info.xml'; |
|
711 | - } |
|
712 | - |
|
713 | - $parser = new InfoParser(\OC::$server->getMemCacheFactory()->create('core.appinfo')); |
|
714 | - $data = $parser->parse($file); |
|
715 | - |
|
716 | - if (is_array($data)) { |
|
717 | - $data = OC_App::parseAppInfo($data, $lang); |
|
718 | - } |
|
719 | - if(isset($data['ocsid'])) { |
|
720 | - $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
|
721 | - if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
722 | - $data['ocsid'] = $storedId; |
|
723 | - } |
|
724 | - } |
|
725 | - |
|
726 | - if ($lang === null) { |
|
727 | - self::$appInfo[$appId] = $data; |
|
728 | - } |
|
729 | - |
|
730 | - return $data; |
|
731 | - } |
|
732 | - |
|
733 | - /** |
|
734 | - * Returns the navigation |
|
735 | - * |
|
736 | - * @return array |
|
737 | - * |
|
738 | - * This function returns an array containing all entries added. The |
|
739 | - * entries are sorted by the key 'order' ascending. Additional to the keys |
|
740 | - * given for each app the following keys exist: |
|
741 | - * - active: boolean, signals if the user is on this navigation entry |
|
742 | - */ |
|
743 | - public static function getNavigation() { |
|
744 | - $entries = OC::$server->getNavigationManager()->getAll(); |
|
745 | - $navigation = self::proceedNavigation($entries); |
|
746 | - return $navigation; |
|
747 | - } |
|
748 | - |
|
749 | - /** |
|
750 | - * get the id of loaded app |
|
751 | - * |
|
752 | - * @return string |
|
753 | - */ |
|
754 | - public static function getCurrentApp() { |
|
755 | - $request = \OC::$server->getRequest(); |
|
756 | - $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); |
|
757 | - $topFolder = substr($script, 0, strpos($script, '/')); |
|
758 | - if (empty($topFolder)) { |
|
759 | - $path_info = $request->getPathInfo(); |
|
760 | - if ($path_info) { |
|
761 | - $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); |
|
762 | - } |
|
763 | - } |
|
764 | - if ($topFolder == 'apps') { |
|
765 | - $length = strlen($topFolder); |
|
766 | - return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1); |
|
767 | - } else { |
|
768 | - return $topFolder; |
|
769 | - } |
|
770 | - } |
|
771 | - |
|
772 | - /** |
|
773 | - * @param string $type |
|
774 | - * @return array |
|
775 | - */ |
|
776 | - public static function getForms($type) { |
|
777 | - $forms = array(); |
|
778 | - switch ($type) { |
|
779 | - case 'admin': |
|
780 | - $source = self::$adminForms; |
|
781 | - break; |
|
782 | - case 'personal': |
|
783 | - $source = self::$personalForms; |
|
784 | - break; |
|
785 | - default: |
|
786 | - return array(); |
|
787 | - } |
|
788 | - foreach ($source as $form) { |
|
789 | - $forms[] = include $form; |
|
790 | - } |
|
791 | - return $forms; |
|
792 | - } |
|
793 | - |
|
794 | - /** |
|
795 | - * register an admin form to be shown |
|
796 | - * |
|
797 | - * @param string $app |
|
798 | - * @param string $page |
|
799 | - */ |
|
800 | - public static function registerAdmin($app, $page) { |
|
801 | - self::$adminForms[] = $app . '/' . $page . '.php'; |
|
802 | - } |
|
803 | - |
|
804 | - /** |
|
805 | - * register a personal form to be shown |
|
806 | - * @param string $app |
|
807 | - * @param string $page |
|
808 | - */ |
|
809 | - public static function registerPersonal($app, $page) { |
|
810 | - self::$personalForms[] = $app . '/' . $page . '.php'; |
|
811 | - } |
|
812 | - |
|
813 | - /** |
|
814 | - * @param array $entry |
|
815 | - */ |
|
816 | - public static function registerLogIn(array $entry) { |
|
817 | - self::$altLogin[] = $entry; |
|
818 | - } |
|
819 | - |
|
820 | - /** |
|
821 | - * @return array |
|
822 | - */ |
|
823 | - public static function getAlternativeLogIns() { |
|
824 | - return self::$altLogin; |
|
825 | - } |
|
826 | - |
|
827 | - /** |
|
828 | - * get a list of all apps in the apps folder |
|
829 | - * |
|
830 | - * @return array an array of app names (string IDs) |
|
831 | - * @todo: change the name of this method to getInstalledApps, which is more accurate |
|
832 | - */ |
|
833 | - public static function getAllApps() { |
|
834 | - |
|
835 | - $apps = array(); |
|
836 | - |
|
837 | - foreach (OC::$APPSROOTS as $apps_dir) { |
|
838 | - if (!is_readable($apps_dir['path'])) { |
|
839 | - \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
840 | - continue; |
|
841 | - } |
|
842 | - $dh = opendir($apps_dir['path']); |
|
843 | - |
|
844 | - if (is_resource($dh)) { |
|
845 | - while (($file = readdir($dh)) !== false) { |
|
846 | - |
|
847 | - if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
848 | - |
|
849 | - $apps[] = $file; |
|
850 | - } |
|
851 | - } |
|
852 | - } |
|
853 | - } |
|
854 | - |
|
855 | - return $apps; |
|
856 | - } |
|
857 | - |
|
858 | - /** |
|
859 | - * List all apps, this is used in apps.php |
|
860 | - * |
|
861 | - * @return array |
|
862 | - */ |
|
863 | - public function listAllApps() { |
|
864 | - $installedApps = OC_App::getAllApps(); |
|
865 | - |
|
866 | - //we don't want to show configuration for these |
|
867 | - $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
|
868 | - $appList = array(); |
|
869 | - $langCode = \OC::$server->getL10N('core')->getLanguageCode(); |
|
870 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
871 | - |
|
872 | - foreach ($installedApps as $app) { |
|
873 | - if (array_search($app, $blacklist) === false) { |
|
874 | - |
|
875 | - $info = OC_App::getAppInfo($app, false, $langCode); |
|
876 | - if (!is_array($info)) { |
|
877 | - \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
878 | - continue; |
|
879 | - } |
|
880 | - |
|
881 | - if (!isset($info['name'])) { |
|
882 | - \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
883 | - continue; |
|
884 | - } |
|
885 | - |
|
886 | - $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no'); |
|
887 | - $info['groups'] = null; |
|
888 | - if ($enabled === 'yes') { |
|
889 | - $active = true; |
|
890 | - } else if ($enabled === 'no') { |
|
891 | - $active = false; |
|
892 | - } else { |
|
893 | - $active = true; |
|
894 | - $info['groups'] = $enabled; |
|
895 | - } |
|
896 | - |
|
897 | - $info['active'] = $active; |
|
898 | - |
|
899 | - if (self::isShipped($app)) { |
|
900 | - $info['internal'] = true; |
|
901 | - $info['level'] = self::officialApp; |
|
902 | - $info['removable'] = false; |
|
903 | - } else { |
|
904 | - $info['internal'] = false; |
|
905 | - $info['removable'] = true; |
|
906 | - } |
|
907 | - |
|
908 | - $appPath = self::getAppPath($app); |
|
909 | - if($appPath !== false) { |
|
910 | - $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
911 | - if (file_exists($appIcon)) { |
|
912 | - $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app . '.svg'); |
|
913 | - $info['previewAsIcon'] = true; |
|
914 | - } else { |
|
915 | - $appIcon = $appPath . '/img/app.svg'; |
|
916 | - if (file_exists($appIcon)) { |
|
917 | - $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, 'app.svg'); |
|
918 | - $info['previewAsIcon'] = true; |
|
919 | - } |
|
920 | - } |
|
921 | - } |
|
922 | - // fix documentation |
|
923 | - if (isset($info['documentation']) && is_array($info['documentation'])) { |
|
924 | - foreach ($info['documentation'] as $key => $url) { |
|
925 | - // If it is not an absolute URL we assume it is a key |
|
926 | - // i.e. admin-ldap will get converted to go.php?to=admin-ldap |
|
927 | - if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) { |
|
928 | - $url = $urlGenerator->linkToDocs($url); |
|
929 | - } |
|
930 | - |
|
931 | - $info['documentation'][$key] = $url; |
|
932 | - } |
|
933 | - } |
|
934 | - |
|
935 | - $info['version'] = OC_App::getAppVersion($app); |
|
936 | - $appList[] = $info; |
|
937 | - } |
|
938 | - } |
|
939 | - |
|
940 | - return $appList; |
|
941 | - } |
|
942 | - |
|
943 | - /** |
|
944 | - * Returns the internal app ID or false |
|
945 | - * @param string $ocsID |
|
946 | - * @return string|false |
|
947 | - */ |
|
948 | - public static function getInternalAppIdByOcs($ocsID) { |
|
949 | - if(is_numeric($ocsID)) { |
|
950 | - $idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid'); |
|
951 | - if(array_search($ocsID, $idArray)) { |
|
952 | - return array_search($ocsID, $idArray); |
|
953 | - } |
|
954 | - } |
|
955 | - return false; |
|
956 | - } |
|
957 | - |
|
958 | - public static function shouldUpgrade($app) { |
|
959 | - $versions = self::getAppVersions(); |
|
960 | - $currentVersion = OC_App::getAppVersion($app); |
|
961 | - if ($currentVersion && isset($versions[$app])) { |
|
962 | - $installedVersion = $versions[$app]; |
|
963 | - if (!version_compare($currentVersion, $installedVersion, '=')) { |
|
964 | - return true; |
|
965 | - } |
|
966 | - } |
|
967 | - return false; |
|
968 | - } |
|
969 | - |
|
970 | - /** |
|
971 | - * Adjust the number of version parts of $version1 to match |
|
972 | - * the number of version parts of $version2. |
|
973 | - * |
|
974 | - * @param string $version1 version to adjust |
|
975 | - * @param string $version2 version to take the number of parts from |
|
976 | - * @return string shortened $version1 |
|
977 | - */ |
|
978 | - private static function adjustVersionParts($version1, $version2) { |
|
979 | - $version1 = explode('.', $version1); |
|
980 | - $version2 = explode('.', $version2); |
|
981 | - // reduce $version1 to match the number of parts in $version2 |
|
982 | - while (count($version1) > count($version2)) { |
|
983 | - array_pop($version1); |
|
984 | - } |
|
985 | - // if $version1 does not have enough parts, add some |
|
986 | - while (count($version1) < count($version2)) { |
|
987 | - $version1[] = '0'; |
|
988 | - } |
|
989 | - return implode('.', $version1); |
|
990 | - } |
|
991 | - |
|
992 | - /** |
|
993 | - * Check whether the current ownCloud version matches the given |
|
994 | - * application's version requirements. |
|
995 | - * |
|
996 | - * The comparison is made based on the number of parts that the |
|
997 | - * app info version has. For example for ownCloud 6.0.3 if the |
|
998 | - * app info version is expecting version 6.0, the comparison is |
|
999 | - * made on the first two parts of the ownCloud version. |
|
1000 | - * This means that it's possible to specify "requiremin" => 6 |
|
1001 | - * and "requiremax" => 6 and it will still match ownCloud 6.0.3. |
|
1002 | - * |
|
1003 | - * @param string $ocVersion ownCloud version to check against |
|
1004 | - * @param array $appInfo app info (from xml) |
|
1005 | - * |
|
1006 | - * @return boolean true if compatible, otherwise false |
|
1007 | - */ |
|
1008 | - public static function isAppCompatible($ocVersion, $appInfo) { |
|
1009 | - $requireMin = ''; |
|
1010 | - $requireMax = ''; |
|
1011 | - if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
1012 | - $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version']; |
|
1013 | - } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
1014 | - $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version']; |
|
1015 | - } else if (isset($appInfo['requiremin'])) { |
|
1016 | - $requireMin = $appInfo['requiremin']; |
|
1017 | - } else if (isset($appInfo['require'])) { |
|
1018 | - $requireMin = $appInfo['require']; |
|
1019 | - } |
|
1020 | - |
|
1021 | - if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
1022 | - $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version']; |
|
1023 | - } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
1024 | - $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version']; |
|
1025 | - } else if (isset($appInfo['requiremax'])) { |
|
1026 | - $requireMax = $appInfo['requiremax']; |
|
1027 | - } |
|
1028 | - |
|
1029 | - if (is_array($ocVersion)) { |
|
1030 | - $ocVersion = implode('.', $ocVersion); |
|
1031 | - } |
|
1032 | - |
|
1033 | - if (!empty($requireMin) |
|
1034 | - && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<') |
|
1035 | - ) { |
|
1036 | - |
|
1037 | - return false; |
|
1038 | - } |
|
1039 | - |
|
1040 | - if (!empty($requireMax) |
|
1041 | - && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') |
|
1042 | - ) { |
|
1043 | - return false; |
|
1044 | - } |
|
1045 | - |
|
1046 | - return true; |
|
1047 | - } |
|
1048 | - |
|
1049 | - /** |
|
1050 | - * get the installed version of all apps |
|
1051 | - */ |
|
1052 | - public static function getAppVersions() { |
|
1053 | - static $versions; |
|
1054 | - |
|
1055 | - if(!$versions) { |
|
1056 | - $appConfig = \OC::$server->getAppConfig(); |
|
1057 | - $versions = $appConfig->getValues(false, 'installed_version'); |
|
1058 | - } |
|
1059 | - return $versions; |
|
1060 | - } |
|
1061 | - |
|
1062 | - /** |
|
1063 | - * @param string $app |
|
1064 | - * @param \OCP\IConfig $config |
|
1065 | - * @param \OCP\IL10N $l |
|
1066 | - * @return bool |
|
1067 | - * |
|
1068 | - * @throws Exception if app is not compatible with this version of ownCloud |
|
1069 | - * @throws Exception if no app-name was specified |
|
1070 | - */ |
|
1071 | - public function installApp($app, |
|
1072 | - \OCP\IConfig $config, |
|
1073 | - \OCP\IL10N $l) { |
|
1074 | - if ($app !== false) { |
|
1075 | - // check if the app is compatible with this version of ownCloud |
|
1076 | - $info = self::getAppInfo($app); |
|
1077 | - if(!is_array($info)) { |
|
1078 | - throw new \Exception( |
|
1079 | - $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
1080 | - [$info['name']] |
|
1081 | - ) |
|
1082 | - ); |
|
1083 | - } |
|
1084 | - |
|
1085 | - $version = \OCP\Util::getVersion(); |
|
1086 | - if (!self::isAppCompatible($version, $info)) { |
|
1087 | - throw new \Exception( |
|
1088 | - $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
1089 | - array($info['name']) |
|
1090 | - ) |
|
1091 | - ); |
|
1092 | - } |
|
1093 | - |
|
1094 | - // check for required dependencies |
|
1095 | - self::checkAppDependencies($config, $l, $info); |
|
1096 | - |
|
1097 | - $config->setAppValue($app, 'enabled', 'yes'); |
|
1098 | - if (isset($appData['id'])) { |
|
1099 | - $config->setAppValue($app, 'ocsid', $appData['id']); |
|
1100 | - } |
|
1101 | - |
|
1102 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
1103 | - $appPath = self::getAppPath($app); |
|
1104 | - self::registerAutoloading($app, $appPath); |
|
1105 | - \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
1106 | - } |
|
1107 | - |
|
1108 | - \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
|
1109 | - } else { |
|
1110 | - if(empty($appName) ) { |
|
1111 | - throw new \Exception($l->t("No app name specified")); |
|
1112 | - } else { |
|
1113 | - throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
|
1114 | - } |
|
1115 | - } |
|
1116 | - |
|
1117 | - return $app; |
|
1118 | - } |
|
1119 | - |
|
1120 | - /** |
|
1121 | - * update the database for the app and call the update script |
|
1122 | - * |
|
1123 | - * @param string $appId |
|
1124 | - * @return bool |
|
1125 | - */ |
|
1126 | - public static function updateApp($appId) { |
|
1127 | - $appPath = self::getAppPath($appId); |
|
1128 | - if($appPath === false) { |
|
1129 | - return false; |
|
1130 | - } |
|
1131 | - $appData = self::getAppInfo($appId); |
|
1132 | - self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
|
1133 | - if (file_exists($appPath . '/appinfo/database.xml')) { |
|
1134 | - OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
1135 | - } |
|
1136 | - self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
|
1137 | - self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
|
1138 | - unset(self::$appVersion[$appId]); |
|
1139 | - // run upgrade code |
|
1140 | - if (file_exists($appPath . '/appinfo/update.php')) { |
|
1141 | - self::loadApp($appId, false); |
|
1142 | - include $appPath . '/appinfo/update.php'; |
|
1143 | - } |
|
1144 | - self::setupBackgroundJobs($appData['background-jobs']); |
|
1145 | - if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
1146 | - $appPath = self::getAppPath($appId); |
|
1147 | - self::registerAutoloading($appId, $appPath); |
|
1148 | - \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
|
1149 | - } |
|
1150 | - |
|
1151 | - //set remote/public handlers |
|
1152 | - if (array_key_exists('ocsid', $appData)) { |
|
1153 | - \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
|
1154 | - } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
1155 | - \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
|
1156 | - } |
|
1157 | - foreach ($appData['remote'] as $name => $path) { |
|
1158 | - \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
1159 | - } |
|
1160 | - foreach ($appData['public'] as $name => $path) { |
|
1161 | - \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
1162 | - } |
|
1163 | - |
|
1164 | - self::setAppTypes($appId); |
|
1165 | - |
|
1166 | - $version = \OC_App::getAppVersion($appId); |
|
1167 | - \OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version); |
|
1168 | - |
|
1169 | - \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( |
|
1170 | - ManagerEvent::EVENT_APP_UPDATE, $appId |
|
1171 | - )); |
|
1172 | - |
|
1173 | - return true; |
|
1174 | - } |
|
1175 | - |
|
1176 | - /** |
|
1177 | - * @param string $appId |
|
1178 | - * @param string[] $steps |
|
1179 | - * @throws \OC\NeedsUpdateException |
|
1180 | - */ |
|
1181 | - public static function executeRepairSteps($appId, array $steps) { |
|
1182 | - if (empty($steps)) { |
|
1183 | - return; |
|
1184 | - } |
|
1185 | - // load the app |
|
1186 | - self::loadApp($appId, false); |
|
1187 | - |
|
1188 | - $dispatcher = OC::$server->getEventDispatcher(); |
|
1189 | - |
|
1190 | - // load the steps |
|
1191 | - $r = new Repair([], $dispatcher); |
|
1192 | - foreach ($steps as $step) { |
|
1193 | - try { |
|
1194 | - $r->addStep($step); |
|
1195 | - } catch (Exception $ex) { |
|
1196 | - $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); |
|
1197 | - \OC::$server->getLogger()->logException($ex); |
|
1198 | - } |
|
1199 | - } |
|
1200 | - // run the steps |
|
1201 | - $r->run(); |
|
1202 | - } |
|
1203 | - |
|
1204 | - public static function setupBackgroundJobs(array $jobs) { |
|
1205 | - $queue = \OC::$server->getJobList(); |
|
1206 | - foreach ($jobs as $job) { |
|
1207 | - $queue->add($job); |
|
1208 | - } |
|
1209 | - } |
|
1210 | - |
|
1211 | - /** |
|
1212 | - * @param string $appId |
|
1213 | - * @param string[] $steps |
|
1214 | - */ |
|
1215 | - private static function setupLiveMigrations($appId, array $steps) { |
|
1216 | - $queue = \OC::$server->getJobList(); |
|
1217 | - foreach ($steps as $step) { |
|
1218 | - $queue->add('OC\Migration\BackgroundRepair', [ |
|
1219 | - 'app' => $appId, |
|
1220 | - 'step' => $step]); |
|
1221 | - } |
|
1222 | - } |
|
1223 | - |
|
1224 | - /** |
|
1225 | - * @param string $appId |
|
1226 | - * @return \OC\Files\View|false |
|
1227 | - */ |
|
1228 | - public static function getStorage($appId) { |
|
1229 | - if (OC_App::isEnabled($appId)) { //sanity check |
|
1230 | - if (OC_User::isLoggedIn()) { |
|
1231 | - $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
1232 | - if (!$view->file_exists($appId)) { |
|
1233 | - $view->mkdir($appId); |
|
1234 | - } |
|
1235 | - return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
1236 | - } else { |
|
1237 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
1238 | - return false; |
|
1239 | - } |
|
1240 | - } else { |
|
1241 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
1242 | - return false; |
|
1243 | - } |
|
1244 | - } |
|
1245 | - |
|
1246 | - protected static function findBestL10NOption($options, $lang) { |
|
1247 | - $fallback = $similarLangFallback = $englishFallback = false; |
|
1248 | - |
|
1249 | - $lang = strtolower($lang); |
|
1250 | - $similarLang = $lang; |
|
1251 | - if (strpos($similarLang, '_')) { |
|
1252 | - // For "de_DE" we want to find "de" and the other way around |
|
1253 | - $similarLang = substr($lang, 0, strpos($lang, '_')); |
|
1254 | - } |
|
1255 | - |
|
1256 | - foreach ($options as $option) { |
|
1257 | - if (is_array($option)) { |
|
1258 | - if ($fallback === false) { |
|
1259 | - $fallback = $option['@value']; |
|
1260 | - } |
|
1261 | - |
|
1262 | - if (!isset($option['@attributes']['lang'])) { |
|
1263 | - continue; |
|
1264 | - } |
|
1265 | - |
|
1266 | - $attributeLang = strtolower($option['@attributes']['lang']); |
|
1267 | - if ($attributeLang === $lang) { |
|
1268 | - return $option['@value']; |
|
1269 | - } |
|
1270 | - |
|
1271 | - if ($attributeLang === $similarLang) { |
|
1272 | - $similarLangFallback = $option['@value']; |
|
1273 | - } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
1274 | - if ($similarLangFallback === false) { |
|
1275 | - $similarLangFallback = $option['@value']; |
|
1276 | - } |
|
1277 | - } |
|
1278 | - } else { |
|
1279 | - $englishFallback = $option; |
|
1280 | - } |
|
1281 | - } |
|
1282 | - |
|
1283 | - if ($similarLangFallback !== false) { |
|
1284 | - return $similarLangFallback; |
|
1285 | - } else if ($englishFallback !== false) { |
|
1286 | - return $englishFallback; |
|
1287 | - } |
|
1288 | - return (string) $fallback; |
|
1289 | - } |
|
1290 | - |
|
1291 | - /** |
|
1292 | - * parses the app data array and enhanced the 'description' value |
|
1293 | - * |
|
1294 | - * @param array $data the app data |
|
1295 | - * @param string $lang |
|
1296 | - * @return array improved app data |
|
1297 | - */ |
|
1298 | - public static function parseAppInfo(array $data, $lang = null) { |
|
1299 | - |
|
1300 | - if ($lang && isset($data['name']) && is_array($data['name'])) { |
|
1301 | - $data['name'] = self::findBestL10NOption($data['name'], $lang); |
|
1302 | - } |
|
1303 | - if ($lang && isset($data['summary']) && is_array($data['summary'])) { |
|
1304 | - $data['summary'] = self::findBestL10NOption($data['summary'], $lang); |
|
1305 | - } |
|
1306 | - if ($lang && isset($data['description']) && is_array($data['description'])) { |
|
1307 | - $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
|
1308 | - } else if (isset($data['description']) && is_string($data['description'])) { |
|
1309 | - $data['description'] = trim($data['description']); |
|
1310 | - } else { |
|
1311 | - $data['description'] = ''; |
|
1312 | - } |
|
1313 | - |
|
1314 | - return $data; |
|
1315 | - } |
|
1316 | - |
|
1317 | - /** |
|
1318 | - * @param \OCP\IConfig $config |
|
1319 | - * @param \OCP\IL10N $l |
|
1320 | - * @param array $info |
|
1321 | - * @throws \Exception |
|
1322 | - */ |
|
1323 | - protected static function checkAppDependencies($config, $l, $info) { |
|
1324 | - $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); |
|
1325 | - $missing = $dependencyAnalyzer->analyze($info); |
|
1326 | - if (!empty($missing)) { |
|
1327 | - $missingMsg = join(PHP_EOL, $missing); |
|
1328 | - throw new \Exception( |
|
1329 | - $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', |
|
1330 | - [$info['name'], $missingMsg] |
|
1331 | - ) |
|
1332 | - ); |
|
1333 | - } |
|
1334 | - } |
|
64 | + static private $appVersion = []; |
|
65 | + static private $adminForms = array(); |
|
66 | + static private $personalForms = array(); |
|
67 | + static private $appInfo = array(); |
|
68 | + static private $appTypes = array(); |
|
69 | + static private $loadedApps = array(); |
|
70 | + static private $altLogin = array(); |
|
71 | + static private $alreadyRegistered = []; |
|
72 | + const officialApp = 200; |
|
73 | + |
|
74 | + /** |
|
75 | + * clean the appId |
|
76 | + * |
|
77 | + * @param string|boolean $app AppId that needs to be cleaned |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + public static function cleanAppId($app) { |
|
81 | + return str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Check if an app is loaded |
|
86 | + * |
|
87 | + * @param string $app |
|
88 | + * @return bool |
|
89 | + */ |
|
90 | + public static function isAppLoaded($app) { |
|
91 | + return in_array($app, self::$loadedApps, true); |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * loads all apps |
|
96 | + * |
|
97 | + * @param string[] | string | null $types |
|
98 | + * @return bool |
|
99 | + * |
|
100 | + * This function walks through the ownCloud directory and loads all apps |
|
101 | + * it can find. A directory contains an app if the file /appinfo/info.xml |
|
102 | + * exists. |
|
103 | + * |
|
104 | + * if $types is set, only apps of those types will be loaded |
|
105 | + */ |
|
106 | + public static function loadApps($types = null) { |
|
107 | + if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
108 | + return false; |
|
109 | + } |
|
110 | + // Load the enabled apps here |
|
111 | + $apps = self::getEnabledApps(); |
|
112 | + |
|
113 | + // Add each apps' folder as allowed class path |
|
114 | + foreach($apps as $app) { |
|
115 | + $path = self::getAppPath($app); |
|
116 | + if($path !== false) { |
|
117 | + self::registerAutoloading($app, $path); |
|
118 | + } |
|
119 | + } |
|
120 | + |
|
121 | + // prevent app.php from printing output |
|
122 | + ob_start(); |
|
123 | + foreach ($apps as $app) { |
|
124 | + if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) { |
|
125 | + self::loadApp($app); |
|
126 | + } |
|
127 | + } |
|
128 | + ob_end_clean(); |
|
129 | + |
|
130 | + return true; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * load a single app |
|
135 | + * |
|
136 | + * @param string $app |
|
137 | + * @param bool $checkUpgrade whether an upgrade check should be done |
|
138 | + * @throws \OC\NeedsUpdateException |
|
139 | + */ |
|
140 | + public static function loadApp($app, $checkUpgrade = true) { |
|
141 | + self::$loadedApps[] = $app; |
|
142 | + $appPath = self::getAppPath($app); |
|
143 | + if($appPath === false) { |
|
144 | + return; |
|
145 | + } |
|
146 | + |
|
147 | + // in case someone calls loadApp() directly |
|
148 | + self::registerAutoloading($app, $appPath); |
|
149 | + |
|
150 | + if (is_file($appPath . '/appinfo/app.php')) { |
|
151 | + \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
152 | + if ($checkUpgrade and self::shouldUpgrade($app)) { |
|
153 | + throw new \OC\NeedsUpdateException(); |
|
154 | + } |
|
155 | + self::requireAppFile($app); |
|
156 | + if (self::isType($app, array('authentication'))) { |
|
157 | + // since authentication apps affect the "is app enabled for group" check, |
|
158 | + // the enabled apps cache needs to be cleared to make sure that the |
|
159 | + // next time getEnableApps() is called it will also include apps that were |
|
160 | + // enabled for groups |
|
161 | + self::$enabledAppsCache = array(); |
|
162 | + } |
|
163 | + \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
164 | + } |
|
165 | + |
|
166 | + $info = self::getAppInfo($app); |
|
167 | + if (!empty($info['activity']['filters'])) { |
|
168 | + foreach ($info['activity']['filters'] as $filter) { |
|
169 | + \OC::$server->getActivityManager()->registerFilter($filter); |
|
170 | + } |
|
171 | + } |
|
172 | + if (!empty($info['activity']['settings'])) { |
|
173 | + foreach ($info['activity']['settings'] as $setting) { |
|
174 | + \OC::$server->getActivityManager()->registerSetting($setting); |
|
175 | + } |
|
176 | + } |
|
177 | + if (!empty($info['activity']['providers'])) { |
|
178 | + foreach ($info['activity']['providers'] as $provider) { |
|
179 | + \OC::$server->getActivityManager()->registerProvider($provider); |
|
180 | + } |
|
181 | + } |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * @internal |
|
186 | + * @param string $app |
|
187 | + * @param string $path |
|
188 | + */ |
|
189 | + public static function registerAutoloading($app, $path) { |
|
190 | + $key = $app . '-' . $path; |
|
191 | + if(isset(self::$alreadyRegistered[$key])) { |
|
192 | + return; |
|
193 | + } |
|
194 | + self::$alreadyRegistered[$key] = true; |
|
195 | + // Register on PSR-4 composer autoloader |
|
196 | + $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
|
197 | + \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
198 | + if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
|
199 | + \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
200 | + } |
|
201 | + |
|
202 | + // Register on legacy autoloader |
|
203 | + \OC::$loader->addValidRoot($path); |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Load app.php from the given app |
|
208 | + * |
|
209 | + * @param string $app app name |
|
210 | + */ |
|
211 | + private static function requireAppFile($app) { |
|
212 | + try { |
|
213 | + // encapsulated here to avoid variable scope conflicts |
|
214 | + require_once $app . '/appinfo/app.php'; |
|
215 | + } catch (Error $ex) { |
|
216 | + \OC::$server->getLogger()->logException($ex); |
|
217 | + $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
|
218 | + if (!in_array($app, $blacklist)) { |
|
219 | + self::disable($app); |
|
220 | + } |
|
221 | + } |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * check if an app is of a specific type |
|
226 | + * |
|
227 | + * @param string $app |
|
228 | + * @param string|array $types |
|
229 | + * @return bool |
|
230 | + */ |
|
231 | + public static function isType($app, $types) { |
|
232 | + if (is_string($types)) { |
|
233 | + $types = array($types); |
|
234 | + } |
|
235 | + $appTypes = self::getAppTypes($app); |
|
236 | + foreach ($types as $type) { |
|
237 | + if (array_search($type, $appTypes) !== false) { |
|
238 | + return true; |
|
239 | + } |
|
240 | + } |
|
241 | + return false; |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * get the types of an app |
|
246 | + * |
|
247 | + * @param string $app |
|
248 | + * @return array |
|
249 | + */ |
|
250 | + private static function getAppTypes($app) { |
|
251 | + //load the cache |
|
252 | + if (count(self::$appTypes) == 0) { |
|
253 | + self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types'); |
|
254 | + } |
|
255 | + |
|
256 | + if (isset(self::$appTypes[$app])) { |
|
257 | + return explode(',', self::$appTypes[$app]); |
|
258 | + } else { |
|
259 | + return array(); |
|
260 | + } |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * read app types from info.xml and cache them in the database |
|
265 | + */ |
|
266 | + public static function setAppTypes($app) { |
|
267 | + $appData = self::getAppInfo($app); |
|
268 | + if(!is_array($appData)) { |
|
269 | + return; |
|
270 | + } |
|
271 | + |
|
272 | + if (isset($appData['types'])) { |
|
273 | + $appTypes = implode(',', $appData['types']); |
|
274 | + } else { |
|
275 | + $appTypes = ''; |
|
276 | + $appData['types'] = []; |
|
277 | + } |
|
278 | + |
|
279 | + \OC::$server->getAppConfig()->setValue($app, 'types', $appTypes); |
|
280 | + |
|
281 | + if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) { |
|
282 | + $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'yes'); |
|
283 | + if ($enabled !== 'yes' && $enabled !== 'no') { |
|
284 | + \OC::$server->getAppConfig()->setValue($app, 'enabled', 'yes'); |
|
285 | + } |
|
286 | + } |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * check if app is shipped |
|
291 | + * |
|
292 | + * @param string $appId the id of the app to check |
|
293 | + * @return bool |
|
294 | + * |
|
295 | + * Check if an app that is installed is a shipped app or installed from the appstore. |
|
296 | + */ |
|
297 | + public static function isShipped($appId) { |
|
298 | + return \OC::$server->getAppManager()->isShipped($appId); |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * get all enabled apps |
|
303 | + */ |
|
304 | + protected static $enabledAppsCache = array(); |
|
305 | + |
|
306 | + /** |
|
307 | + * Returns apps enabled for the current user. |
|
308 | + * |
|
309 | + * @param bool $forceRefresh whether to refresh the cache |
|
310 | + * @param bool $all whether to return apps for all users, not only the |
|
311 | + * currently logged in one |
|
312 | + * @return string[] |
|
313 | + */ |
|
314 | + public static function getEnabledApps($forceRefresh = false, $all = false) { |
|
315 | + if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
316 | + return array(); |
|
317 | + } |
|
318 | + // in incognito mode or when logged out, $user will be false, |
|
319 | + // which is also the case during an upgrade |
|
320 | + $appManager = \OC::$server->getAppManager(); |
|
321 | + if ($all) { |
|
322 | + $user = null; |
|
323 | + } else { |
|
324 | + $user = \OC::$server->getUserSession()->getUser(); |
|
325 | + } |
|
326 | + |
|
327 | + if (is_null($user)) { |
|
328 | + $apps = $appManager->getInstalledApps(); |
|
329 | + } else { |
|
330 | + $apps = $appManager->getEnabledAppsForUser($user); |
|
331 | + } |
|
332 | + $apps = array_filter($apps, function ($app) { |
|
333 | + return $app !== 'files';//we add this manually |
|
334 | + }); |
|
335 | + sort($apps); |
|
336 | + array_unshift($apps, 'files'); |
|
337 | + return $apps; |
|
338 | + } |
|
339 | + |
|
340 | + /** |
|
341 | + * checks whether or not an app is enabled |
|
342 | + * |
|
343 | + * @param string $app app |
|
344 | + * @return bool |
|
345 | + * |
|
346 | + * This function checks whether or not an app is enabled. |
|
347 | + */ |
|
348 | + public static function isEnabled($app) { |
|
349 | + return \OC::$server->getAppManager()->isEnabledForUser($app); |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * enables an app |
|
354 | + * |
|
355 | + * @param string $appId |
|
356 | + * @param array $groups (optional) when set, only these groups will have access to the app |
|
357 | + * @throws \Exception |
|
358 | + * @return void |
|
359 | + * |
|
360 | + * This function set an app as enabled in appconfig. |
|
361 | + */ |
|
362 | + public function enable($appId, |
|
363 | + $groups = null) { |
|
364 | + self::$enabledAppsCache = []; // flush |
|
365 | + $l = \OC::$server->getL10N('core'); |
|
366 | + $config = \OC::$server->getConfig(); |
|
367 | + |
|
368 | + // Check if app is already downloaded |
|
369 | + $installer = new Installer( |
|
370 | + \OC::$server->getAppFetcher(), |
|
371 | + \OC::$server->getHTTPClientService(), |
|
372 | + \OC::$server->getTempManager(), |
|
373 | + \OC::$server->getLogger() |
|
374 | + ); |
|
375 | + $isDownloaded = $installer->isDownloaded($appId); |
|
376 | + |
|
377 | + if(!$isDownloaded) { |
|
378 | + $installer->downloadApp($appId); |
|
379 | + } |
|
380 | + |
|
381 | + if (!Installer::isInstalled($appId)) { |
|
382 | + $appId = self::installApp( |
|
383 | + $appId, |
|
384 | + $config, |
|
385 | + $l |
|
386 | + ); |
|
387 | + $appPath = self::getAppPath($appId); |
|
388 | + self::registerAutoloading($appId, $appPath); |
|
389 | + $installer->installApp($appId); |
|
390 | + } else { |
|
391 | + // check for required dependencies |
|
392 | + $info = self::getAppInfo($appId); |
|
393 | + self::checkAppDependencies($config, $l, $info); |
|
394 | + $appPath = self::getAppPath($appId); |
|
395 | + self::registerAutoloading($appId, $appPath); |
|
396 | + $installer->installApp($appId); |
|
397 | + } |
|
398 | + |
|
399 | + $appManager = \OC::$server->getAppManager(); |
|
400 | + if (!is_null($groups)) { |
|
401 | + $groupManager = \OC::$server->getGroupManager(); |
|
402 | + $groupsList = []; |
|
403 | + foreach ($groups as $group) { |
|
404 | + $groupItem = $groupManager->get($group); |
|
405 | + if ($groupItem instanceof \OCP\IGroup) { |
|
406 | + $groupsList[] = $groupManager->get($group); |
|
407 | + } |
|
408 | + } |
|
409 | + $appManager->enableAppForGroups($appId, $groupsList); |
|
410 | + } else { |
|
411 | + $appManager->enableApp($appId); |
|
412 | + } |
|
413 | + |
|
414 | + $info = self::getAppInfo($appId); |
|
415 | + if(isset($info['settings']) && is_array($info['settings'])) { |
|
416 | + $appPath = self::getAppPath($appId); |
|
417 | + self::registerAutoloading($appId, $appPath); |
|
418 | + \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
419 | + } |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * @param string $app |
|
424 | + * @return bool |
|
425 | + */ |
|
426 | + public static function removeApp($app) { |
|
427 | + if (self::isShipped($app)) { |
|
428 | + return false; |
|
429 | + } |
|
430 | + |
|
431 | + $installer = new Installer( |
|
432 | + \OC::$server->getAppFetcher(), |
|
433 | + \OC::$server->getHTTPClientService(), |
|
434 | + \OC::$server->getTempManager(), |
|
435 | + \OC::$server->getLogger() |
|
436 | + ); |
|
437 | + return $installer->removeApp($app); |
|
438 | + } |
|
439 | + |
|
440 | + /** |
|
441 | + * This function set an app as disabled in appconfig. |
|
442 | + * |
|
443 | + * @param string $app app |
|
444 | + * @throws Exception |
|
445 | + */ |
|
446 | + public static function disable($app) { |
|
447 | + // flush |
|
448 | + self::$enabledAppsCache = array(); |
|
449 | + |
|
450 | + // run uninstall steps |
|
451 | + $appData = OC_App::getAppInfo($app); |
|
452 | + if (!is_null($appData)) { |
|
453 | + OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']); |
|
454 | + } |
|
455 | + |
|
456 | + // emit disable hook - needed anymore ? |
|
457 | + \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app)); |
|
458 | + |
|
459 | + // finally disable it |
|
460 | + $appManager = \OC::$server->getAppManager(); |
|
461 | + $appManager->disableApp($app); |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | + * Returns the Settings Navigation |
|
466 | + * |
|
467 | + * @return string[] |
|
468 | + * |
|
469 | + * This function returns an array containing all settings pages added. The |
|
470 | + * entries are sorted by the key 'order' ascending. |
|
471 | + */ |
|
472 | + public static function getSettingsNavigation() { |
|
473 | + $l = \OC::$server->getL10N('lib'); |
|
474 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
475 | + |
|
476 | + $settings = array(); |
|
477 | + // by default, settings only contain the help menu |
|
478 | + if (\OC::$server->getSystemConfig()->getValue('knowledgebaseenabled', true)) { |
|
479 | + $settings = array( |
|
480 | + array( |
|
481 | + "id" => "help", |
|
482 | + "order" => 4, |
|
483 | + "href" => $urlGenerator->linkToRoute('settings_help'), |
|
484 | + "name" => $l->t("Help"), |
|
485 | + "icon" => $urlGenerator->imagePath("settings", "help.svg") |
|
486 | + ) |
|
487 | + ); |
|
488 | + } |
|
489 | + |
|
490 | + // if the user is logged-in |
|
491 | + if (OC_User::isLoggedIn()) { |
|
492 | + // personal menu |
|
493 | + $settings[] = array( |
|
494 | + "id" => "personal", |
|
495 | + "order" => 1, |
|
496 | + "href" => $urlGenerator->linkToRoute('settings_personal'), |
|
497 | + "name" => $l->t("Personal"), |
|
498 | + "icon" => $urlGenerator->imagePath("settings", "personal.svg") |
|
499 | + ); |
|
500 | + |
|
501 | + //SubAdmins are also allowed to access user management |
|
502 | + $userObject = \OC::$server->getUserSession()->getUser(); |
|
503 | + $isSubAdmin = false; |
|
504 | + if($userObject !== null) { |
|
505 | + $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
|
506 | + } |
|
507 | + if ($isSubAdmin) { |
|
508 | + // admin users menu |
|
509 | + $settings[] = array( |
|
510 | + "id" => "core_users", |
|
511 | + "order" => 3, |
|
512 | + "href" => $urlGenerator->linkToRoute('settings_users'), |
|
513 | + "name" => $l->t("Users"), |
|
514 | + "icon" => $urlGenerator->imagePath("settings", "users.svg") |
|
515 | + ); |
|
516 | + } |
|
517 | + |
|
518 | + // if the user is an admin |
|
519 | + if (OC_User::isAdminUser(OC_User::getUser())) { |
|
520 | + // admin settings |
|
521 | + $settings[] = array( |
|
522 | + "id" => "admin", |
|
523 | + "order" => 2, |
|
524 | + "href" => $urlGenerator->linkToRoute('settings.AdminSettings.index'), |
|
525 | + "name" => $l->t("Admin"), |
|
526 | + "icon" => $urlGenerator->imagePath("settings", "admin.svg") |
|
527 | + ); |
|
528 | + } |
|
529 | + } |
|
530 | + |
|
531 | + $navigation = self::proceedNavigation($settings); |
|
532 | + return $navigation; |
|
533 | + } |
|
534 | + |
|
535 | + // This is private as well. It simply works, so don't ask for more details |
|
536 | + private static function proceedNavigation($list) { |
|
537 | + $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); |
|
538 | + foreach ($list as &$navEntry) { |
|
539 | + if ($navEntry['id'] == $activeApp) { |
|
540 | + $navEntry['active'] = true; |
|
541 | + } else { |
|
542 | + $navEntry['active'] = false; |
|
543 | + } |
|
544 | + } |
|
545 | + unset($navEntry); |
|
546 | + |
|
547 | + usort($list, function($a, $b) { |
|
548 | + if (isset($a['order']) && isset($b['order'])) { |
|
549 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
550 | + } else if (isset($a['order']) || isset($b['order'])) { |
|
551 | + return isset($a['order']) ? -1 : 1; |
|
552 | + } else { |
|
553 | + return ($a['name'] < $b['name']) ? -1 : 1; |
|
554 | + } |
|
555 | + }); |
|
556 | + |
|
557 | + return $list; |
|
558 | + } |
|
559 | + |
|
560 | + /** |
|
561 | + * Get the path where to install apps |
|
562 | + * |
|
563 | + * @return string|false |
|
564 | + */ |
|
565 | + public static function getInstallPath() { |
|
566 | + if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) { |
|
567 | + return false; |
|
568 | + } |
|
569 | + |
|
570 | + foreach (OC::$APPSROOTS as $dir) { |
|
571 | + if (isset($dir['writable']) && $dir['writable'] === true) { |
|
572 | + return $dir['path']; |
|
573 | + } |
|
574 | + } |
|
575 | + |
|
576 | + \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR); |
|
577 | + return null; |
|
578 | + } |
|
579 | + |
|
580 | + |
|
581 | + /** |
|
582 | + * search for an app in all app-directories |
|
583 | + * |
|
584 | + * @param string $appId |
|
585 | + * @return false|string |
|
586 | + */ |
|
587 | + public static function findAppInDirectories($appId) { |
|
588 | + $sanitizedAppId = self::cleanAppId($appId); |
|
589 | + if($sanitizedAppId !== $appId) { |
|
590 | + return false; |
|
591 | + } |
|
592 | + static $app_dir = array(); |
|
593 | + |
|
594 | + if (isset($app_dir[$appId])) { |
|
595 | + return $app_dir[$appId]; |
|
596 | + } |
|
597 | + |
|
598 | + $possibleApps = array(); |
|
599 | + foreach (OC::$APPSROOTS as $dir) { |
|
600 | + if (file_exists($dir['path'] . '/' . $appId)) { |
|
601 | + $possibleApps[] = $dir; |
|
602 | + } |
|
603 | + } |
|
604 | + |
|
605 | + if (empty($possibleApps)) { |
|
606 | + return false; |
|
607 | + } elseif (count($possibleApps) === 1) { |
|
608 | + $dir = array_shift($possibleApps); |
|
609 | + $app_dir[$appId] = $dir; |
|
610 | + return $dir; |
|
611 | + } else { |
|
612 | + $versionToLoad = array(); |
|
613 | + foreach ($possibleApps as $possibleApp) { |
|
614 | + $version = self::getAppVersionByPath($possibleApp['path']); |
|
615 | + if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
|
616 | + $versionToLoad = array( |
|
617 | + 'dir' => $possibleApp, |
|
618 | + 'version' => $version, |
|
619 | + ); |
|
620 | + } |
|
621 | + } |
|
622 | + $app_dir[$appId] = $versionToLoad['dir']; |
|
623 | + return $versionToLoad['dir']; |
|
624 | + //TODO - write test |
|
625 | + } |
|
626 | + } |
|
627 | + |
|
628 | + /** |
|
629 | + * Get the directory for the given app. |
|
630 | + * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
631 | + * |
|
632 | + * @param string $appId |
|
633 | + * @return string|false |
|
634 | + */ |
|
635 | + public static function getAppPath($appId) { |
|
636 | + if ($appId === null || trim($appId) === '') { |
|
637 | + return false; |
|
638 | + } |
|
639 | + |
|
640 | + if (($dir = self::findAppInDirectories($appId)) != false) { |
|
641 | + return $dir['path'] . '/' . $appId; |
|
642 | + } |
|
643 | + return false; |
|
644 | + } |
|
645 | + |
|
646 | + /** |
|
647 | + * Get the path for the given app on the access |
|
648 | + * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
649 | + * |
|
650 | + * @param string $appId |
|
651 | + * @return string|false |
|
652 | + */ |
|
653 | + public static function getAppWebPath($appId) { |
|
654 | + if (($dir = self::findAppInDirectories($appId)) != false) { |
|
655 | + return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
656 | + } |
|
657 | + return false; |
|
658 | + } |
|
659 | + |
|
660 | + /** |
|
661 | + * get the last version of the app from appinfo/info.xml |
|
662 | + * |
|
663 | + * @param string $appId |
|
664 | + * @param bool $useCache |
|
665 | + * @return string |
|
666 | + */ |
|
667 | + public static function getAppVersion($appId, $useCache = true) { |
|
668 | + if($useCache && isset(self::$appVersion[$appId])) { |
|
669 | + return self::$appVersion[$appId]; |
|
670 | + } |
|
671 | + |
|
672 | + $file = self::getAppPath($appId); |
|
673 | + self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0'; |
|
674 | + return self::$appVersion[$appId]; |
|
675 | + } |
|
676 | + |
|
677 | + /** |
|
678 | + * get app's version based on it's path |
|
679 | + * |
|
680 | + * @param string $path |
|
681 | + * @return string |
|
682 | + */ |
|
683 | + public static function getAppVersionByPath($path) { |
|
684 | + $infoFile = $path . '/appinfo/info.xml'; |
|
685 | + $appData = self::getAppInfo($infoFile, true); |
|
686 | + return isset($appData['version']) ? $appData['version'] : ''; |
|
687 | + } |
|
688 | + |
|
689 | + |
|
690 | + /** |
|
691 | + * Read all app metadata from the info.xml file |
|
692 | + * |
|
693 | + * @param string $appId id of the app or the path of the info.xml file |
|
694 | + * @param bool $path |
|
695 | + * @param string $lang |
|
696 | + * @return array|null |
|
697 | + * @note all data is read from info.xml, not just pre-defined fields |
|
698 | + */ |
|
699 | + public static function getAppInfo($appId, $path = false, $lang = null) { |
|
700 | + if ($path) { |
|
701 | + $file = $appId; |
|
702 | + } else { |
|
703 | + if ($lang === null && isset(self::$appInfo[$appId])) { |
|
704 | + return self::$appInfo[$appId]; |
|
705 | + } |
|
706 | + $appPath = self::getAppPath($appId); |
|
707 | + if($appPath === false) { |
|
708 | + return null; |
|
709 | + } |
|
710 | + $file = $appPath . '/appinfo/info.xml'; |
|
711 | + } |
|
712 | + |
|
713 | + $parser = new InfoParser(\OC::$server->getMemCacheFactory()->create('core.appinfo')); |
|
714 | + $data = $parser->parse($file); |
|
715 | + |
|
716 | + if (is_array($data)) { |
|
717 | + $data = OC_App::parseAppInfo($data, $lang); |
|
718 | + } |
|
719 | + if(isset($data['ocsid'])) { |
|
720 | + $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
|
721 | + if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
722 | + $data['ocsid'] = $storedId; |
|
723 | + } |
|
724 | + } |
|
725 | + |
|
726 | + if ($lang === null) { |
|
727 | + self::$appInfo[$appId] = $data; |
|
728 | + } |
|
729 | + |
|
730 | + return $data; |
|
731 | + } |
|
732 | + |
|
733 | + /** |
|
734 | + * Returns the navigation |
|
735 | + * |
|
736 | + * @return array |
|
737 | + * |
|
738 | + * This function returns an array containing all entries added. The |
|
739 | + * entries are sorted by the key 'order' ascending. Additional to the keys |
|
740 | + * given for each app the following keys exist: |
|
741 | + * - active: boolean, signals if the user is on this navigation entry |
|
742 | + */ |
|
743 | + public static function getNavigation() { |
|
744 | + $entries = OC::$server->getNavigationManager()->getAll(); |
|
745 | + $navigation = self::proceedNavigation($entries); |
|
746 | + return $navigation; |
|
747 | + } |
|
748 | + |
|
749 | + /** |
|
750 | + * get the id of loaded app |
|
751 | + * |
|
752 | + * @return string |
|
753 | + */ |
|
754 | + public static function getCurrentApp() { |
|
755 | + $request = \OC::$server->getRequest(); |
|
756 | + $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); |
|
757 | + $topFolder = substr($script, 0, strpos($script, '/')); |
|
758 | + if (empty($topFolder)) { |
|
759 | + $path_info = $request->getPathInfo(); |
|
760 | + if ($path_info) { |
|
761 | + $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); |
|
762 | + } |
|
763 | + } |
|
764 | + if ($topFolder == 'apps') { |
|
765 | + $length = strlen($topFolder); |
|
766 | + return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1); |
|
767 | + } else { |
|
768 | + return $topFolder; |
|
769 | + } |
|
770 | + } |
|
771 | + |
|
772 | + /** |
|
773 | + * @param string $type |
|
774 | + * @return array |
|
775 | + */ |
|
776 | + public static function getForms($type) { |
|
777 | + $forms = array(); |
|
778 | + switch ($type) { |
|
779 | + case 'admin': |
|
780 | + $source = self::$adminForms; |
|
781 | + break; |
|
782 | + case 'personal': |
|
783 | + $source = self::$personalForms; |
|
784 | + break; |
|
785 | + default: |
|
786 | + return array(); |
|
787 | + } |
|
788 | + foreach ($source as $form) { |
|
789 | + $forms[] = include $form; |
|
790 | + } |
|
791 | + return $forms; |
|
792 | + } |
|
793 | + |
|
794 | + /** |
|
795 | + * register an admin form to be shown |
|
796 | + * |
|
797 | + * @param string $app |
|
798 | + * @param string $page |
|
799 | + */ |
|
800 | + public static function registerAdmin($app, $page) { |
|
801 | + self::$adminForms[] = $app . '/' . $page . '.php'; |
|
802 | + } |
|
803 | + |
|
804 | + /** |
|
805 | + * register a personal form to be shown |
|
806 | + * @param string $app |
|
807 | + * @param string $page |
|
808 | + */ |
|
809 | + public static function registerPersonal($app, $page) { |
|
810 | + self::$personalForms[] = $app . '/' . $page . '.php'; |
|
811 | + } |
|
812 | + |
|
813 | + /** |
|
814 | + * @param array $entry |
|
815 | + */ |
|
816 | + public static function registerLogIn(array $entry) { |
|
817 | + self::$altLogin[] = $entry; |
|
818 | + } |
|
819 | + |
|
820 | + /** |
|
821 | + * @return array |
|
822 | + */ |
|
823 | + public static function getAlternativeLogIns() { |
|
824 | + return self::$altLogin; |
|
825 | + } |
|
826 | + |
|
827 | + /** |
|
828 | + * get a list of all apps in the apps folder |
|
829 | + * |
|
830 | + * @return array an array of app names (string IDs) |
|
831 | + * @todo: change the name of this method to getInstalledApps, which is more accurate |
|
832 | + */ |
|
833 | + public static function getAllApps() { |
|
834 | + |
|
835 | + $apps = array(); |
|
836 | + |
|
837 | + foreach (OC::$APPSROOTS as $apps_dir) { |
|
838 | + if (!is_readable($apps_dir['path'])) { |
|
839 | + \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
840 | + continue; |
|
841 | + } |
|
842 | + $dh = opendir($apps_dir['path']); |
|
843 | + |
|
844 | + if (is_resource($dh)) { |
|
845 | + while (($file = readdir($dh)) !== false) { |
|
846 | + |
|
847 | + if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
848 | + |
|
849 | + $apps[] = $file; |
|
850 | + } |
|
851 | + } |
|
852 | + } |
|
853 | + } |
|
854 | + |
|
855 | + return $apps; |
|
856 | + } |
|
857 | + |
|
858 | + /** |
|
859 | + * List all apps, this is used in apps.php |
|
860 | + * |
|
861 | + * @return array |
|
862 | + */ |
|
863 | + public function listAllApps() { |
|
864 | + $installedApps = OC_App::getAllApps(); |
|
865 | + |
|
866 | + //we don't want to show configuration for these |
|
867 | + $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
|
868 | + $appList = array(); |
|
869 | + $langCode = \OC::$server->getL10N('core')->getLanguageCode(); |
|
870 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
871 | + |
|
872 | + foreach ($installedApps as $app) { |
|
873 | + if (array_search($app, $blacklist) === false) { |
|
874 | + |
|
875 | + $info = OC_App::getAppInfo($app, false, $langCode); |
|
876 | + if (!is_array($info)) { |
|
877 | + \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
878 | + continue; |
|
879 | + } |
|
880 | + |
|
881 | + if (!isset($info['name'])) { |
|
882 | + \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
883 | + continue; |
|
884 | + } |
|
885 | + |
|
886 | + $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no'); |
|
887 | + $info['groups'] = null; |
|
888 | + if ($enabled === 'yes') { |
|
889 | + $active = true; |
|
890 | + } else if ($enabled === 'no') { |
|
891 | + $active = false; |
|
892 | + } else { |
|
893 | + $active = true; |
|
894 | + $info['groups'] = $enabled; |
|
895 | + } |
|
896 | + |
|
897 | + $info['active'] = $active; |
|
898 | + |
|
899 | + if (self::isShipped($app)) { |
|
900 | + $info['internal'] = true; |
|
901 | + $info['level'] = self::officialApp; |
|
902 | + $info['removable'] = false; |
|
903 | + } else { |
|
904 | + $info['internal'] = false; |
|
905 | + $info['removable'] = true; |
|
906 | + } |
|
907 | + |
|
908 | + $appPath = self::getAppPath($app); |
|
909 | + if($appPath !== false) { |
|
910 | + $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
911 | + if (file_exists($appIcon)) { |
|
912 | + $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app . '.svg'); |
|
913 | + $info['previewAsIcon'] = true; |
|
914 | + } else { |
|
915 | + $appIcon = $appPath . '/img/app.svg'; |
|
916 | + if (file_exists($appIcon)) { |
|
917 | + $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, 'app.svg'); |
|
918 | + $info['previewAsIcon'] = true; |
|
919 | + } |
|
920 | + } |
|
921 | + } |
|
922 | + // fix documentation |
|
923 | + if (isset($info['documentation']) && is_array($info['documentation'])) { |
|
924 | + foreach ($info['documentation'] as $key => $url) { |
|
925 | + // If it is not an absolute URL we assume it is a key |
|
926 | + // i.e. admin-ldap will get converted to go.php?to=admin-ldap |
|
927 | + if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) { |
|
928 | + $url = $urlGenerator->linkToDocs($url); |
|
929 | + } |
|
930 | + |
|
931 | + $info['documentation'][$key] = $url; |
|
932 | + } |
|
933 | + } |
|
934 | + |
|
935 | + $info['version'] = OC_App::getAppVersion($app); |
|
936 | + $appList[] = $info; |
|
937 | + } |
|
938 | + } |
|
939 | + |
|
940 | + return $appList; |
|
941 | + } |
|
942 | + |
|
943 | + /** |
|
944 | + * Returns the internal app ID or false |
|
945 | + * @param string $ocsID |
|
946 | + * @return string|false |
|
947 | + */ |
|
948 | + public static function getInternalAppIdByOcs($ocsID) { |
|
949 | + if(is_numeric($ocsID)) { |
|
950 | + $idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid'); |
|
951 | + if(array_search($ocsID, $idArray)) { |
|
952 | + return array_search($ocsID, $idArray); |
|
953 | + } |
|
954 | + } |
|
955 | + return false; |
|
956 | + } |
|
957 | + |
|
958 | + public static function shouldUpgrade($app) { |
|
959 | + $versions = self::getAppVersions(); |
|
960 | + $currentVersion = OC_App::getAppVersion($app); |
|
961 | + if ($currentVersion && isset($versions[$app])) { |
|
962 | + $installedVersion = $versions[$app]; |
|
963 | + if (!version_compare($currentVersion, $installedVersion, '=')) { |
|
964 | + return true; |
|
965 | + } |
|
966 | + } |
|
967 | + return false; |
|
968 | + } |
|
969 | + |
|
970 | + /** |
|
971 | + * Adjust the number of version parts of $version1 to match |
|
972 | + * the number of version parts of $version2. |
|
973 | + * |
|
974 | + * @param string $version1 version to adjust |
|
975 | + * @param string $version2 version to take the number of parts from |
|
976 | + * @return string shortened $version1 |
|
977 | + */ |
|
978 | + private static function adjustVersionParts($version1, $version2) { |
|
979 | + $version1 = explode('.', $version1); |
|
980 | + $version2 = explode('.', $version2); |
|
981 | + // reduce $version1 to match the number of parts in $version2 |
|
982 | + while (count($version1) > count($version2)) { |
|
983 | + array_pop($version1); |
|
984 | + } |
|
985 | + // if $version1 does not have enough parts, add some |
|
986 | + while (count($version1) < count($version2)) { |
|
987 | + $version1[] = '0'; |
|
988 | + } |
|
989 | + return implode('.', $version1); |
|
990 | + } |
|
991 | + |
|
992 | + /** |
|
993 | + * Check whether the current ownCloud version matches the given |
|
994 | + * application's version requirements. |
|
995 | + * |
|
996 | + * The comparison is made based on the number of parts that the |
|
997 | + * app info version has. For example for ownCloud 6.0.3 if the |
|
998 | + * app info version is expecting version 6.0, the comparison is |
|
999 | + * made on the first two parts of the ownCloud version. |
|
1000 | + * This means that it's possible to specify "requiremin" => 6 |
|
1001 | + * and "requiremax" => 6 and it will still match ownCloud 6.0.3. |
|
1002 | + * |
|
1003 | + * @param string $ocVersion ownCloud version to check against |
|
1004 | + * @param array $appInfo app info (from xml) |
|
1005 | + * |
|
1006 | + * @return boolean true if compatible, otherwise false |
|
1007 | + */ |
|
1008 | + public static function isAppCompatible($ocVersion, $appInfo) { |
|
1009 | + $requireMin = ''; |
|
1010 | + $requireMax = ''; |
|
1011 | + if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
1012 | + $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version']; |
|
1013 | + } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
1014 | + $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version']; |
|
1015 | + } else if (isset($appInfo['requiremin'])) { |
|
1016 | + $requireMin = $appInfo['requiremin']; |
|
1017 | + } else if (isset($appInfo['require'])) { |
|
1018 | + $requireMin = $appInfo['require']; |
|
1019 | + } |
|
1020 | + |
|
1021 | + if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
1022 | + $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version']; |
|
1023 | + } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
1024 | + $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version']; |
|
1025 | + } else if (isset($appInfo['requiremax'])) { |
|
1026 | + $requireMax = $appInfo['requiremax']; |
|
1027 | + } |
|
1028 | + |
|
1029 | + if (is_array($ocVersion)) { |
|
1030 | + $ocVersion = implode('.', $ocVersion); |
|
1031 | + } |
|
1032 | + |
|
1033 | + if (!empty($requireMin) |
|
1034 | + && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<') |
|
1035 | + ) { |
|
1036 | + |
|
1037 | + return false; |
|
1038 | + } |
|
1039 | + |
|
1040 | + if (!empty($requireMax) |
|
1041 | + && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') |
|
1042 | + ) { |
|
1043 | + return false; |
|
1044 | + } |
|
1045 | + |
|
1046 | + return true; |
|
1047 | + } |
|
1048 | + |
|
1049 | + /** |
|
1050 | + * get the installed version of all apps |
|
1051 | + */ |
|
1052 | + public static function getAppVersions() { |
|
1053 | + static $versions; |
|
1054 | + |
|
1055 | + if(!$versions) { |
|
1056 | + $appConfig = \OC::$server->getAppConfig(); |
|
1057 | + $versions = $appConfig->getValues(false, 'installed_version'); |
|
1058 | + } |
|
1059 | + return $versions; |
|
1060 | + } |
|
1061 | + |
|
1062 | + /** |
|
1063 | + * @param string $app |
|
1064 | + * @param \OCP\IConfig $config |
|
1065 | + * @param \OCP\IL10N $l |
|
1066 | + * @return bool |
|
1067 | + * |
|
1068 | + * @throws Exception if app is not compatible with this version of ownCloud |
|
1069 | + * @throws Exception if no app-name was specified |
|
1070 | + */ |
|
1071 | + public function installApp($app, |
|
1072 | + \OCP\IConfig $config, |
|
1073 | + \OCP\IL10N $l) { |
|
1074 | + if ($app !== false) { |
|
1075 | + // check if the app is compatible with this version of ownCloud |
|
1076 | + $info = self::getAppInfo($app); |
|
1077 | + if(!is_array($info)) { |
|
1078 | + throw new \Exception( |
|
1079 | + $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
1080 | + [$info['name']] |
|
1081 | + ) |
|
1082 | + ); |
|
1083 | + } |
|
1084 | + |
|
1085 | + $version = \OCP\Util::getVersion(); |
|
1086 | + if (!self::isAppCompatible($version, $info)) { |
|
1087 | + throw new \Exception( |
|
1088 | + $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
1089 | + array($info['name']) |
|
1090 | + ) |
|
1091 | + ); |
|
1092 | + } |
|
1093 | + |
|
1094 | + // check for required dependencies |
|
1095 | + self::checkAppDependencies($config, $l, $info); |
|
1096 | + |
|
1097 | + $config->setAppValue($app, 'enabled', 'yes'); |
|
1098 | + if (isset($appData['id'])) { |
|
1099 | + $config->setAppValue($app, 'ocsid', $appData['id']); |
|
1100 | + } |
|
1101 | + |
|
1102 | + if(isset($info['settings']) && is_array($info['settings'])) { |
|
1103 | + $appPath = self::getAppPath($app); |
|
1104 | + self::registerAutoloading($app, $appPath); |
|
1105 | + \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
1106 | + } |
|
1107 | + |
|
1108 | + \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
|
1109 | + } else { |
|
1110 | + if(empty($appName) ) { |
|
1111 | + throw new \Exception($l->t("No app name specified")); |
|
1112 | + } else { |
|
1113 | + throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
|
1114 | + } |
|
1115 | + } |
|
1116 | + |
|
1117 | + return $app; |
|
1118 | + } |
|
1119 | + |
|
1120 | + /** |
|
1121 | + * update the database for the app and call the update script |
|
1122 | + * |
|
1123 | + * @param string $appId |
|
1124 | + * @return bool |
|
1125 | + */ |
|
1126 | + public static function updateApp($appId) { |
|
1127 | + $appPath = self::getAppPath($appId); |
|
1128 | + if($appPath === false) { |
|
1129 | + return false; |
|
1130 | + } |
|
1131 | + $appData = self::getAppInfo($appId); |
|
1132 | + self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
|
1133 | + if (file_exists($appPath . '/appinfo/database.xml')) { |
|
1134 | + OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
1135 | + } |
|
1136 | + self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
|
1137 | + self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
|
1138 | + unset(self::$appVersion[$appId]); |
|
1139 | + // run upgrade code |
|
1140 | + if (file_exists($appPath . '/appinfo/update.php')) { |
|
1141 | + self::loadApp($appId, false); |
|
1142 | + include $appPath . '/appinfo/update.php'; |
|
1143 | + } |
|
1144 | + self::setupBackgroundJobs($appData['background-jobs']); |
|
1145 | + if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
1146 | + $appPath = self::getAppPath($appId); |
|
1147 | + self::registerAutoloading($appId, $appPath); |
|
1148 | + \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
|
1149 | + } |
|
1150 | + |
|
1151 | + //set remote/public handlers |
|
1152 | + if (array_key_exists('ocsid', $appData)) { |
|
1153 | + \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
|
1154 | + } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
1155 | + \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
|
1156 | + } |
|
1157 | + foreach ($appData['remote'] as $name => $path) { |
|
1158 | + \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
1159 | + } |
|
1160 | + foreach ($appData['public'] as $name => $path) { |
|
1161 | + \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
1162 | + } |
|
1163 | + |
|
1164 | + self::setAppTypes($appId); |
|
1165 | + |
|
1166 | + $version = \OC_App::getAppVersion($appId); |
|
1167 | + \OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version); |
|
1168 | + |
|
1169 | + \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( |
|
1170 | + ManagerEvent::EVENT_APP_UPDATE, $appId |
|
1171 | + )); |
|
1172 | + |
|
1173 | + return true; |
|
1174 | + } |
|
1175 | + |
|
1176 | + /** |
|
1177 | + * @param string $appId |
|
1178 | + * @param string[] $steps |
|
1179 | + * @throws \OC\NeedsUpdateException |
|
1180 | + */ |
|
1181 | + public static function executeRepairSteps($appId, array $steps) { |
|
1182 | + if (empty($steps)) { |
|
1183 | + return; |
|
1184 | + } |
|
1185 | + // load the app |
|
1186 | + self::loadApp($appId, false); |
|
1187 | + |
|
1188 | + $dispatcher = OC::$server->getEventDispatcher(); |
|
1189 | + |
|
1190 | + // load the steps |
|
1191 | + $r = new Repair([], $dispatcher); |
|
1192 | + foreach ($steps as $step) { |
|
1193 | + try { |
|
1194 | + $r->addStep($step); |
|
1195 | + } catch (Exception $ex) { |
|
1196 | + $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); |
|
1197 | + \OC::$server->getLogger()->logException($ex); |
|
1198 | + } |
|
1199 | + } |
|
1200 | + // run the steps |
|
1201 | + $r->run(); |
|
1202 | + } |
|
1203 | + |
|
1204 | + public static function setupBackgroundJobs(array $jobs) { |
|
1205 | + $queue = \OC::$server->getJobList(); |
|
1206 | + foreach ($jobs as $job) { |
|
1207 | + $queue->add($job); |
|
1208 | + } |
|
1209 | + } |
|
1210 | + |
|
1211 | + /** |
|
1212 | + * @param string $appId |
|
1213 | + * @param string[] $steps |
|
1214 | + */ |
|
1215 | + private static function setupLiveMigrations($appId, array $steps) { |
|
1216 | + $queue = \OC::$server->getJobList(); |
|
1217 | + foreach ($steps as $step) { |
|
1218 | + $queue->add('OC\Migration\BackgroundRepair', [ |
|
1219 | + 'app' => $appId, |
|
1220 | + 'step' => $step]); |
|
1221 | + } |
|
1222 | + } |
|
1223 | + |
|
1224 | + /** |
|
1225 | + * @param string $appId |
|
1226 | + * @return \OC\Files\View|false |
|
1227 | + */ |
|
1228 | + public static function getStorage($appId) { |
|
1229 | + if (OC_App::isEnabled($appId)) { //sanity check |
|
1230 | + if (OC_User::isLoggedIn()) { |
|
1231 | + $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
1232 | + if (!$view->file_exists($appId)) { |
|
1233 | + $view->mkdir($appId); |
|
1234 | + } |
|
1235 | + return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
1236 | + } else { |
|
1237 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
1238 | + return false; |
|
1239 | + } |
|
1240 | + } else { |
|
1241 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
1242 | + return false; |
|
1243 | + } |
|
1244 | + } |
|
1245 | + |
|
1246 | + protected static function findBestL10NOption($options, $lang) { |
|
1247 | + $fallback = $similarLangFallback = $englishFallback = false; |
|
1248 | + |
|
1249 | + $lang = strtolower($lang); |
|
1250 | + $similarLang = $lang; |
|
1251 | + if (strpos($similarLang, '_')) { |
|
1252 | + // For "de_DE" we want to find "de" and the other way around |
|
1253 | + $similarLang = substr($lang, 0, strpos($lang, '_')); |
|
1254 | + } |
|
1255 | + |
|
1256 | + foreach ($options as $option) { |
|
1257 | + if (is_array($option)) { |
|
1258 | + if ($fallback === false) { |
|
1259 | + $fallback = $option['@value']; |
|
1260 | + } |
|
1261 | + |
|
1262 | + if (!isset($option['@attributes']['lang'])) { |
|
1263 | + continue; |
|
1264 | + } |
|
1265 | + |
|
1266 | + $attributeLang = strtolower($option['@attributes']['lang']); |
|
1267 | + if ($attributeLang === $lang) { |
|
1268 | + return $option['@value']; |
|
1269 | + } |
|
1270 | + |
|
1271 | + if ($attributeLang === $similarLang) { |
|
1272 | + $similarLangFallback = $option['@value']; |
|
1273 | + } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
1274 | + if ($similarLangFallback === false) { |
|
1275 | + $similarLangFallback = $option['@value']; |
|
1276 | + } |
|
1277 | + } |
|
1278 | + } else { |
|
1279 | + $englishFallback = $option; |
|
1280 | + } |
|
1281 | + } |
|
1282 | + |
|
1283 | + if ($similarLangFallback !== false) { |
|
1284 | + return $similarLangFallback; |
|
1285 | + } else if ($englishFallback !== false) { |
|
1286 | + return $englishFallback; |
|
1287 | + } |
|
1288 | + return (string) $fallback; |
|
1289 | + } |
|
1290 | + |
|
1291 | + /** |
|
1292 | + * parses the app data array and enhanced the 'description' value |
|
1293 | + * |
|
1294 | + * @param array $data the app data |
|
1295 | + * @param string $lang |
|
1296 | + * @return array improved app data |
|
1297 | + */ |
|
1298 | + public static function parseAppInfo(array $data, $lang = null) { |
|
1299 | + |
|
1300 | + if ($lang && isset($data['name']) && is_array($data['name'])) { |
|
1301 | + $data['name'] = self::findBestL10NOption($data['name'], $lang); |
|
1302 | + } |
|
1303 | + if ($lang && isset($data['summary']) && is_array($data['summary'])) { |
|
1304 | + $data['summary'] = self::findBestL10NOption($data['summary'], $lang); |
|
1305 | + } |
|
1306 | + if ($lang && isset($data['description']) && is_array($data['description'])) { |
|
1307 | + $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
|
1308 | + } else if (isset($data['description']) && is_string($data['description'])) { |
|
1309 | + $data['description'] = trim($data['description']); |
|
1310 | + } else { |
|
1311 | + $data['description'] = ''; |
|
1312 | + } |
|
1313 | + |
|
1314 | + return $data; |
|
1315 | + } |
|
1316 | + |
|
1317 | + /** |
|
1318 | + * @param \OCP\IConfig $config |
|
1319 | + * @param \OCP\IL10N $l |
|
1320 | + * @param array $info |
|
1321 | + * @throws \Exception |
|
1322 | + */ |
|
1323 | + protected static function checkAppDependencies($config, $l, $info) { |
|
1324 | + $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); |
|
1325 | + $missing = $dependencyAnalyzer->analyze($info); |
|
1326 | + if (!empty($missing)) { |
|
1327 | + $missingMsg = join(PHP_EOL, $missing); |
|
1328 | + throw new \Exception( |
|
1329 | + $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', |
|
1330 | + [$info['name'], $missingMsg] |
|
1331 | + ) |
|
1332 | + ); |
|
1333 | + } |
|
1334 | + } |
|
1335 | 1335 | } |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | $apps = self::getEnabledApps(); |
112 | 112 | |
113 | 113 | // Add each apps' folder as allowed class path |
114 | - foreach($apps as $app) { |
|
114 | + foreach ($apps as $app) { |
|
115 | 115 | $path = self::getAppPath($app); |
116 | - if($path !== false) { |
|
116 | + if ($path !== false) { |
|
117 | 117 | self::registerAutoloading($app, $path); |
118 | 118 | } |
119 | 119 | } |
@@ -140,15 +140,15 @@ discard block |
||
140 | 140 | public static function loadApp($app, $checkUpgrade = true) { |
141 | 141 | self::$loadedApps[] = $app; |
142 | 142 | $appPath = self::getAppPath($app); |
143 | - if($appPath === false) { |
|
143 | + if ($appPath === false) { |
|
144 | 144 | return; |
145 | 145 | } |
146 | 146 | |
147 | 147 | // in case someone calls loadApp() directly |
148 | 148 | self::registerAutoloading($app, $appPath); |
149 | 149 | |
150 | - if (is_file($appPath . '/appinfo/app.php')) { |
|
151 | - \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
150 | + if (is_file($appPath.'/appinfo/app.php')) { |
|
151 | + \OC::$server->getEventLogger()->start('load_app_'.$app, 'Load app: '.$app); |
|
152 | 152 | if ($checkUpgrade and self::shouldUpgrade($app)) { |
153 | 153 | throw new \OC\NeedsUpdateException(); |
154 | 154 | } |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | // enabled for groups |
161 | 161 | self::$enabledAppsCache = array(); |
162 | 162 | } |
163 | - \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
163 | + \OC::$server->getEventLogger()->end('load_app_'.$app); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | $info = self::getAppInfo($app); |
@@ -187,16 +187,16 @@ discard block |
||
187 | 187 | * @param string $path |
188 | 188 | */ |
189 | 189 | public static function registerAutoloading($app, $path) { |
190 | - $key = $app . '-' . $path; |
|
191 | - if(isset(self::$alreadyRegistered[$key])) { |
|
190 | + $key = $app.'-'.$path; |
|
191 | + if (isset(self::$alreadyRegistered[$key])) { |
|
192 | 192 | return; |
193 | 193 | } |
194 | 194 | self::$alreadyRegistered[$key] = true; |
195 | 195 | // Register on PSR-4 composer autoloader |
196 | 196 | $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
197 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
197 | + \OC::$composerAutoloader->addPsr4($appNamespace.'\\', $path.'/lib/', true); |
|
198 | 198 | if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
199 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
199 | + \OC::$composerAutoloader->addPsr4($appNamespace.'\\Tests\\', $path.'/tests/', true); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | // Register on legacy autoloader |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | private static function requireAppFile($app) { |
212 | 212 | try { |
213 | 213 | // encapsulated here to avoid variable scope conflicts |
214 | - require_once $app . '/appinfo/app.php'; |
|
214 | + require_once $app.'/appinfo/app.php'; |
|
215 | 215 | } catch (Error $ex) { |
216 | 216 | \OC::$server->getLogger()->logException($ex); |
217 | 217 | $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | */ |
266 | 266 | public static function setAppTypes($app) { |
267 | 267 | $appData = self::getAppInfo($app); |
268 | - if(!is_array($appData)) { |
|
268 | + if (!is_array($appData)) { |
|
269 | 269 | return; |
270 | 270 | } |
271 | 271 | |
@@ -329,8 +329,8 @@ discard block |
||
329 | 329 | } else { |
330 | 330 | $apps = $appManager->getEnabledAppsForUser($user); |
331 | 331 | } |
332 | - $apps = array_filter($apps, function ($app) { |
|
333 | - return $app !== 'files';//we add this manually |
|
332 | + $apps = array_filter($apps, function($app) { |
|
333 | + return $app !== 'files'; //we add this manually |
|
334 | 334 | }); |
335 | 335 | sort($apps); |
336 | 336 | array_unshift($apps, 'files'); |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | ); |
375 | 375 | $isDownloaded = $installer->isDownloaded($appId); |
376 | 376 | |
377 | - if(!$isDownloaded) { |
|
377 | + if (!$isDownloaded) { |
|
378 | 378 | $installer->downloadApp($appId); |
379 | 379 | } |
380 | 380 | |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | } |
413 | 413 | |
414 | 414 | $info = self::getAppInfo($appId); |
415 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
415 | + if (isset($info['settings']) && is_array($info['settings'])) { |
|
416 | 416 | $appPath = self::getAppPath($appId); |
417 | 417 | self::registerAutoloading($appId, $appPath); |
418 | 418 | \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
@@ -501,7 +501,7 @@ discard block |
||
501 | 501 | //SubAdmins are also allowed to access user management |
502 | 502 | $userObject = \OC::$server->getUserSession()->getUser(); |
503 | 503 | $isSubAdmin = false; |
504 | - if($userObject !== null) { |
|
504 | + if ($userObject !== null) { |
|
505 | 505 | $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject); |
506 | 506 | } |
507 | 507 | if ($isSubAdmin) { |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | */ |
587 | 587 | public static function findAppInDirectories($appId) { |
588 | 588 | $sanitizedAppId = self::cleanAppId($appId); |
589 | - if($sanitizedAppId !== $appId) { |
|
589 | + if ($sanitizedAppId !== $appId) { |
|
590 | 590 | return false; |
591 | 591 | } |
592 | 592 | static $app_dir = array(); |
@@ -597,7 +597,7 @@ discard block |
||
597 | 597 | |
598 | 598 | $possibleApps = array(); |
599 | 599 | foreach (OC::$APPSROOTS as $dir) { |
600 | - if (file_exists($dir['path'] . '/' . $appId)) { |
|
600 | + if (file_exists($dir['path'].'/'.$appId)) { |
|
601 | 601 | $possibleApps[] = $dir; |
602 | 602 | } |
603 | 603 | } |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | } |
639 | 639 | |
640 | 640 | if (($dir = self::findAppInDirectories($appId)) != false) { |
641 | - return $dir['path'] . '/' . $appId; |
|
641 | + return $dir['path'].'/'.$appId; |
|
642 | 642 | } |
643 | 643 | return false; |
644 | 644 | } |
@@ -652,7 +652,7 @@ discard block |
||
652 | 652 | */ |
653 | 653 | public static function getAppWebPath($appId) { |
654 | 654 | if (($dir = self::findAppInDirectories($appId)) != false) { |
655 | - return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
655 | + return OC::$WEBROOT.$dir['url'].'/'.$appId; |
|
656 | 656 | } |
657 | 657 | return false; |
658 | 658 | } |
@@ -665,7 +665,7 @@ discard block |
||
665 | 665 | * @return string |
666 | 666 | */ |
667 | 667 | public static function getAppVersion($appId, $useCache = true) { |
668 | - if($useCache && isset(self::$appVersion[$appId])) { |
|
668 | + if ($useCache && isset(self::$appVersion[$appId])) { |
|
669 | 669 | return self::$appVersion[$appId]; |
670 | 670 | } |
671 | 671 | |
@@ -681,7 +681,7 @@ discard block |
||
681 | 681 | * @return string |
682 | 682 | */ |
683 | 683 | public static function getAppVersionByPath($path) { |
684 | - $infoFile = $path . '/appinfo/info.xml'; |
|
684 | + $infoFile = $path.'/appinfo/info.xml'; |
|
685 | 685 | $appData = self::getAppInfo($infoFile, true); |
686 | 686 | return isset($appData['version']) ? $appData['version'] : ''; |
687 | 687 | } |
@@ -704,10 +704,10 @@ discard block |
||
704 | 704 | return self::$appInfo[$appId]; |
705 | 705 | } |
706 | 706 | $appPath = self::getAppPath($appId); |
707 | - if($appPath === false) { |
|
707 | + if ($appPath === false) { |
|
708 | 708 | return null; |
709 | 709 | } |
710 | - $file = $appPath . '/appinfo/info.xml'; |
|
710 | + $file = $appPath.'/appinfo/info.xml'; |
|
711 | 711 | } |
712 | 712 | |
713 | 713 | $parser = new InfoParser(\OC::$server->getMemCacheFactory()->create('core.appinfo')); |
@@ -716,9 +716,9 @@ discard block |
||
716 | 716 | if (is_array($data)) { |
717 | 717 | $data = OC_App::parseAppInfo($data, $lang); |
718 | 718 | } |
719 | - if(isset($data['ocsid'])) { |
|
719 | + if (isset($data['ocsid'])) { |
|
720 | 720 | $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
721 | - if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
721 | + if ($storedId !== '' && $storedId !== $data['ocsid']) { |
|
722 | 722 | $data['ocsid'] = $storedId; |
723 | 723 | } |
724 | 724 | } |
@@ -798,7 +798,7 @@ discard block |
||
798 | 798 | * @param string $page |
799 | 799 | */ |
800 | 800 | public static function registerAdmin($app, $page) { |
801 | - self::$adminForms[] = $app . '/' . $page . '.php'; |
|
801 | + self::$adminForms[] = $app.'/'.$page.'.php'; |
|
802 | 802 | } |
803 | 803 | |
804 | 804 | /** |
@@ -807,7 +807,7 @@ discard block |
||
807 | 807 | * @param string $page |
808 | 808 | */ |
809 | 809 | public static function registerPersonal($app, $page) { |
810 | - self::$personalForms[] = $app . '/' . $page . '.php'; |
|
810 | + self::$personalForms[] = $app.'/'.$page.'.php'; |
|
811 | 811 | } |
812 | 812 | |
813 | 813 | /** |
@@ -836,7 +836,7 @@ discard block |
||
836 | 836 | |
837 | 837 | foreach (OC::$APPSROOTS as $apps_dir) { |
838 | 838 | if (!is_readable($apps_dir['path'])) { |
839 | - \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
839 | + \OCP\Util::writeLog('core', 'unable to read app folder : '.$apps_dir['path'], \OCP\Util::WARN); |
|
840 | 840 | continue; |
841 | 841 | } |
842 | 842 | $dh = opendir($apps_dir['path']); |
@@ -844,7 +844,7 @@ discard block |
||
844 | 844 | if (is_resource($dh)) { |
845 | 845 | while (($file = readdir($dh)) !== false) { |
846 | 846 | |
847 | - if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
847 | + if ($file[0] != '.' and is_dir($apps_dir['path'].'/'.$file) and is_file($apps_dir['path'].'/'.$file.'/appinfo/info.xml')) { |
|
848 | 848 | |
849 | 849 | $apps[] = $file; |
850 | 850 | } |
@@ -874,12 +874,12 @@ discard block |
||
874 | 874 | |
875 | 875 | $info = OC_App::getAppInfo($app, false, $langCode); |
876 | 876 | if (!is_array($info)) { |
877 | - \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
877 | + \OCP\Util::writeLog('core', 'Could not read app info file for app "'.$app.'"', \OCP\Util::ERROR); |
|
878 | 878 | continue; |
879 | 879 | } |
880 | 880 | |
881 | 881 | if (!isset($info['name'])) { |
882 | - \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
882 | + \OCP\Util::writeLog('core', 'App id "'.$app.'" has no name in appinfo', \OCP\Util::ERROR); |
|
883 | 883 | continue; |
884 | 884 | } |
885 | 885 | |
@@ -906,13 +906,13 @@ discard block |
||
906 | 906 | } |
907 | 907 | |
908 | 908 | $appPath = self::getAppPath($app); |
909 | - if($appPath !== false) { |
|
910 | - $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
909 | + if ($appPath !== false) { |
|
910 | + $appIcon = $appPath.'/img/'.$app.'.svg'; |
|
911 | 911 | if (file_exists($appIcon)) { |
912 | - $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app . '.svg'); |
|
912 | + $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app.'.svg'); |
|
913 | 913 | $info['previewAsIcon'] = true; |
914 | 914 | } else { |
915 | - $appIcon = $appPath . '/img/app.svg'; |
|
915 | + $appIcon = $appPath.'/img/app.svg'; |
|
916 | 916 | if (file_exists($appIcon)) { |
917 | 917 | $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, 'app.svg'); |
918 | 918 | $info['previewAsIcon'] = true; |
@@ -946,9 +946,9 @@ discard block |
||
946 | 946 | * @return string|false |
947 | 947 | */ |
948 | 948 | public static function getInternalAppIdByOcs($ocsID) { |
949 | - if(is_numeric($ocsID)) { |
|
949 | + if (is_numeric($ocsID)) { |
|
950 | 950 | $idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid'); |
951 | - if(array_search($ocsID, $idArray)) { |
|
951 | + if (array_search($ocsID, $idArray)) { |
|
952 | 952 | return array_search($ocsID, $idArray); |
953 | 953 | } |
954 | 954 | } |
@@ -1052,7 +1052,7 @@ discard block |
||
1052 | 1052 | public static function getAppVersions() { |
1053 | 1053 | static $versions; |
1054 | 1054 | |
1055 | - if(!$versions) { |
|
1055 | + if (!$versions) { |
|
1056 | 1056 | $appConfig = \OC::$server->getAppConfig(); |
1057 | 1057 | $versions = $appConfig->getValues(false, 'installed_version'); |
1058 | 1058 | } |
@@ -1074,7 +1074,7 @@ discard block |
||
1074 | 1074 | if ($app !== false) { |
1075 | 1075 | // check if the app is compatible with this version of ownCloud |
1076 | 1076 | $info = self::getAppInfo($app); |
1077 | - if(!is_array($info)) { |
|
1077 | + if (!is_array($info)) { |
|
1078 | 1078 | throw new \Exception( |
1079 | 1079 | $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
1080 | 1080 | [$info['name']] |
@@ -1099,7 +1099,7 @@ discard block |
||
1099 | 1099 | $config->setAppValue($app, 'ocsid', $appData['id']); |
1100 | 1100 | } |
1101 | 1101 | |
1102 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
1102 | + if (isset($info['settings']) && is_array($info['settings'])) { |
|
1103 | 1103 | $appPath = self::getAppPath($app); |
1104 | 1104 | self::registerAutoloading($app, $appPath); |
1105 | 1105 | \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
@@ -1107,7 +1107,7 @@ discard block |
||
1107 | 1107 | |
1108 | 1108 | \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
1109 | 1109 | } else { |
1110 | - if(empty($appName) ) { |
|
1110 | + if (empty($appName)) { |
|
1111 | 1111 | throw new \Exception($l->t("No app name specified")); |
1112 | 1112 | } else { |
1113 | 1113 | throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
@@ -1125,24 +1125,24 @@ discard block |
||
1125 | 1125 | */ |
1126 | 1126 | public static function updateApp($appId) { |
1127 | 1127 | $appPath = self::getAppPath($appId); |
1128 | - if($appPath === false) { |
|
1128 | + if ($appPath === false) { |
|
1129 | 1129 | return false; |
1130 | 1130 | } |
1131 | 1131 | $appData = self::getAppInfo($appId); |
1132 | 1132 | self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
1133 | - if (file_exists($appPath . '/appinfo/database.xml')) { |
|
1134 | - OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
1133 | + if (file_exists($appPath.'/appinfo/database.xml')) { |
|
1134 | + OC_DB::updateDbFromStructure($appPath.'/appinfo/database.xml'); |
|
1135 | 1135 | } |
1136 | 1136 | self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
1137 | 1137 | self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
1138 | 1138 | unset(self::$appVersion[$appId]); |
1139 | 1139 | // run upgrade code |
1140 | - if (file_exists($appPath . '/appinfo/update.php')) { |
|
1140 | + if (file_exists($appPath.'/appinfo/update.php')) { |
|
1141 | 1141 | self::loadApp($appId, false); |
1142 | - include $appPath . '/appinfo/update.php'; |
|
1142 | + include $appPath.'/appinfo/update.php'; |
|
1143 | 1143 | } |
1144 | 1144 | self::setupBackgroundJobs($appData['background-jobs']); |
1145 | - if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
1145 | + if (isset($appData['settings']) && is_array($appData['settings'])) { |
|
1146 | 1146 | $appPath = self::getAppPath($appId); |
1147 | 1147 | self::registerAutoloading($appId, $appPath); |
1148 | 1148 | \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
@@ -1151,14 +1151,14 @@ discard block |
||
1151 | 1151 | //set remote/public handlers |
1152 | 1152 | if (array_key_exists('ocsid', $appData)) { |
1153 | 1153 | \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
1154 | - } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
1154 | + } elseif (\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
1155 | 1155 | \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
1156 | 1156 | } |
1157 | 1157 | foreach ($appData['remote'] as $name => $path) { |
1158 | - \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
1158 | + \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $appId.'/'.$path); |
|
1159 | 1159 | } |
1160 | 1160 | foreach ($appData['public'] as $name => $path) { |
1161 | - \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
1161 | + \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $appId.'/'.$path); |
|
1162 | 1162 | } |
1163 | 1163 | |
1164 | 1164 | self::setAppTypes($appId); |
@@ -1228,17 +1228,17 @@ discard block |
||
1228 | 1228 | public static function getStorage($appId) { |
1229 | 1229 | if (OC_App::isEnabled($appId)) { //sanity check |
1230 | 1230 | if (OC_User::isLoggedIn()) { |
1231 | - $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
1231 | + $view = new \OC\Files\View('/'.OC_User::getUser()); |
|
1232 | 1232 | if (!$view->file_exists($appId)) { |
1233 | 1233 | $view->mkdir($appId); |
1234 | 1234 | } |
1235 | - return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
1235 | + return new \OC\Files\View('/'.OC_User::getUser().'/'.$appId); |
|
1236 | 1236 | } else { |
1237 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
1237 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.', user not logged in', \OCP\Util::ERROR); |
|
1238 | 1238 | return false; |
1239 | 1239 | } |
1240 | 1240 | } else { |
1241 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
1241 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.' not enabled', \OCP\Util::ERROR); |
|
1242 | 1242 | return false; |
1243 | 1243 | } |
1244 | 1244 | } |
@@ -1270,9 +1270,9 @@ discard block |
||
1270 | 1270 | |
1271 | 1271 | if ($attributeLang === $similarLang) { |
1272 | 1272 | $similarLangFallback = $option['@value']; |
1273 | - } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
1273 | + } else if (strpos($attributeLang, $similarLang.'_') === 0) { |
|
1274 | 1274 | if ($similarLangFallback === false) { |
1275 | - $similarLangFallback = $option['@value']; |
|
1275 | + $similarLangFallback = $option['@value']; |
|
1276 | 1276 | } |
1277 | 1277 | } |
1278 | 1278 | } else { |
@@ -1307,7 +1307,7 @@ discard block |
||
1307 | 1307 | $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
1308 | 1308 | } else if (isset($data['description']) && is_string($data['description'])) { |
1309 | 1309 | $data['description'] = trim($data['description']); |
1310 | - } else { |
|
1310 | + } else { |
|
1311 | 1311 | $data['description'] = ''; |
1312 | 1312 | } |
1313 | 1313 |
@@ -318,6 +318,11 @@ |
||
318 | 318 | */ |
319 | 319 | // FIXME This method is only public, until OC_L10N does not need it anymore, |
320 | 320 | // FIXME This is also the reason, why it is not in the public interface |
321 | + |
|
322 | + /** |
|
323 | + * @param string $app |
|
324 | + * @param string $lang |
|
325 | + */ |
|
321 | 326 | public function getL10nFilesForApp($app, $lang) { |
322 | 327 | $languageFiles = []; |
323 | 328 |
@@ -40,391 +40,391 @@ |
||
40 | 40 | */ |
41 | 41 | class Factory implements IFactory { |
42 | 42 | |
43 | - /** @var string */ |
|
44 | - protected $requestLanguage = ''; |
|
45 | - |
|
46 | - /** |
|
47 | - * cached instances |
|
48 | - * @var array Structure: Lang => App => \OCP\IL10N |
|
49 | - */ |
|
50 | - protected $instances = []; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var array Structure: App => string[] |
|
54 | - */ |
|
55 | - protected $availableLanguages = []; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var array Structure: string => callable |
|
59 | - */ |
|
60 | - protected $pluralFunctions = []; |
|
61 | - |
|
62 | - /** @var IConfig */ |
|
63 | - protected $config; |
|
64 | - |
|
65 | - /** @var IRequest */ |
|
66 | - protected $request; |
|
67 | - |
|
68 | - /** @var IUserSession */ |
|
69 | - protected $userSession; |
|
70 | - |
|
71 | - /** @var string */ |
|
72 | - protected $serverRoot; |
|
73 | - |
|
74 | - /** |
|
75 | - * @param IConfig $config |
|
76 | - * @param IRequest $request |
|
77 | - * @param IUserSession $userSession |
|
78 | - * @param string $serverRoot |
|
79 | - */ |
|
80 | - public function __construct(IConfig $config, |
|
81 | - IRequest $request, |
|
82 | - IUserSession $userSession, |
|
83 | - $serverRoot) { |
|
84 | - $this->config = $config; |
|
85 | - $this->request = $request; |
|
86 | - $this->userSession = $userSession; |
|
87 | - $this->serverRoot = $serverRoot; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Get a language instance |
|
92 | - * |
|
93 | - * @param string $app |
|
94 | - * @param string|null $lang |
|
95 | - * @return \OCP\IL10N |
|
96 | - */ |
|
97 | - public function get($app, $lang = null) { |
|
98 | - $app = \OC_App::cleanAppId($app); |
|
99 | - if ($lang !== null) { |
|
100 | - $lang = str_replace(array('\0', '/', '\\', '..'), '', (string) $lang); |
|
101 | - } |
|
102 | - if ($lang === null || !$this->languageExists($app, $lang)) { |
|
103 | - $lang = $this->findLanguage($app); |
|
104 | - } |
|
105 | - |
|
106 | - if (!isset($this->instances[$lang][$app])) { |
|
107 | - $this->instances[$lang][$app] = new L10N( |
|
108 | - $this, $app, $lang, |
|
109 | - $this->getL10nFilesForApp($app, $lang) |
|
110 | - ); |
|
111 | - } |
|
112 | - |
|
113 | - return $this->instances[$lang][$app]; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Find the best language |
|
118 | - * |
|
119 | - * @param string|null $app App id or null for core |
|
120 | - * @return string language If nothing works it returns 'en' |
|
121 | - */ |
|
122 | - public function findLanguage($app = null) { |
|
123 | - if ($this->requestLanguage !== '' && $this->languageExists($app, $this->requestLanguage)) { |
|
124 | - return $this->requestLanguage; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * At this point ownCloud might not yet be installed and thus the lookup |
|
129 | - * in the preferences table might fail. For this reason we need to check |
|
130 | - * whether the instance has already been installed |
|
131 | - * |
|
132 | - * @link https://github.com/owncloud/core/issues/21955 |
|
133 | - */ |
|
134 | - if($this->config->getSystemValue('installed', false)) { |
|
135 | - $userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() : null; |
|
136 | - if(!is_null($userId)) { |
|
137 | - $userLang = $this->config->getUserValue($userId, 'core', 'lang', null); |
|
138 | - } else { |
|
139 | - $userLang = null; |
|
140 | - } |
|
141 | - } else { |
|
142 | - $userId = null; |
|
143 | - $userLang = null; |
|
144 | - } |
|
145 | - |
|
146 | - if ($userLang) { |
|
147 | - $this->requestLanguage = $userLang; |
|
148 | - if ($this->languageExists($app, $userLang)) { |
|
149 | - return $userLang; |
|
150 | - } |
|
151 | - } |
|
152 | - |
|
153 | - try { |
|
154 | - // Try to get the language from the Request |
|
155 | - $lang = $this->getLanguageFromRequest($app); |
|
156 | - if ($userId !== null && $app === null && !$userLang) { |
|
157 | - $this->config->setUserValue($userId, 'core', 'lang', $lang); |
|
158 | - } |
|
159 | - return $lang; |
|
160 | - } catch (LanguageNotFoundException $e) { |
|
161 | - // Finding language from request failed fall back to default language |
|
162 | - $defaultLanguage = $this->config->getSystemValue('default_language', false); |
|
163 | - if ($defaultLanguage !== false && $this->languageExists($app, $defaultLanguage)) { |
|
164 | - return $defaultLanguage; |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - // We could not find any language so fall back to english |
|
169 | - return 'en'; |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Find all available languages for an app |
|
174 | - * |
|
175 | - * @param string|null $app App id or null for core |
|
176 | - * @return array an array of available languages |
|
177 | - */ |
|
178 | - public function findAvailableLanguages($app = null) { |
|
179 | - $key = $app; |
|
180 | - if ($key === null) { |
|
181 | - $key = 'null'; |
|
182 | - } |
|
183 | - |
|
184 | - // also works with null as key |
|
185 | - if (!empty($this->availableLanguages[$key])) { |
|
186 | - return $this->availableLanguages[$key]; |
|
187 | - } |
|
188 | - |
|
189 | - $available = ['en']; //english is always available |
|
190 | - $dir = $this->findL10nDir($app); |
|
191 | - if (is_dir($dir)) { |
|
192 | - $files = scandir($dir); |
|
193 | - if ($files !== false) { |
|
194 | - foreach ($files as $file) { |
|
195 | - if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') { |
|
196 | - $available[] = substr($file, 0, -5); |
|
197 | - } |
|
198 | - } |
|
199 | - } |
|
200 | - } |
|
201 | - |
|
202 | - // merge with translations from theme |
|
203 | - $theme = $this->config->getSystemValue('theme'); |
|
204 | - if (!empty($theme)) { |
|
205 | - $themeDir = $this->serverRoot . '/themes/' . $theme . substr($dir, strlen($this->serverRoot)); |
|
206 | - |
|
207 | - if (is_dir($themeDir)) { |
|
208 | - $files = scandir($themeDir); |
|
209 | - if ($files !== false) { |
|
210 | - foreach ($files as $file) { |
|
211 | - if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') { |
|
212 | - $available[] = substr($file, 0, -5); |
|
213 | - } |
|
214 | - } |
|
215 | - } |
|
216 | - } |
|
217 | - } |
|
218 | - |
|
219 | - $this->availableLanguages[$key] = $available; |
|
220 | - return $available; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * @param string|null $app App id or null for core |
|
225 | - * @param string $lang |
|
226 | - * @return bool |
|
227 | - */ |
|
228 | - public function languageExists($app, $lang) { |
|
229 | - if ($lang === 'en') {//english is always available |
|
230 | - return true; |
|
231 | - } |
|
232 | - |
|
233 | - $languages = $this->findAvailableLanguages($app); |
|
234 | - return array_search($lang, $languages) !== false; |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * @param string|null $app |
|
239 | - * @return string |
|
240 | - * @throws LanguageNotFoundException |
|
241 | - */ |
|
242 | - private function getLanguageFromRequest($app) { |
|
243 | - $header = $this->request->getHeader('ACCEPT_LANGUAGE'); |
|
244 | - if ($header) { |
|
245 | - $available = $this->findAvailableLanguages($app); |
|
246 | - |
|
247 | - // E.g. make sure that 'de' is before 'de_DE'. |
|
248 | - sort($available); |
|
249 | - |
|
250 | - $preferences = preg_split('/,\s*/', strtolower($header)); |
|
251 | - foreach ($preferences as $preference) { |
|
252 | - list($preferred_language) = explode(';', $preference); |
|
253 | - $preferred_language = str_replace('-', '_', $preferred_language); |
|
254 | - |
|
255 | - foreach ($available as $available_language) { |
|
256 | - if ($preferred_language === strtolower($available_language)) { |
|
257 | - return $available_language; |
|
258 | - } |
|
259 | - } |
|
260 | - |
|
261 | - // Fallback from de_De to de |
|
262 | - foreach ($available as $available_language) { |
|
263 | - if (substr($preferred_language, 0, 2) === $available_language) { |
|
264 | - return $available_language; |
|
265 | - } |
|
266 | - } |
|
267 | - } |
|
268 | - } |
|
269 | - |
|
270 | - throw new LanguageNotFoundException(); |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * @param string|null $app App id or null for core |
|
275 | - * @return string |
|
276 | - */ |
|
277 | - public function setLanguageFromRequest($app = null) { |
|
278 | - |
|
279 | - try { |
|
280 | - $requestLanguage = $this->getLanguageFromRequest($app); |
|
281 | - } catch (LanguageNotFoundException $e) { |
|
282 | - $requestLanguage = 'en'; |
|
283 | - } |
|
284 | - |
|
285 | - if ($app === null && !$this->requestLanguage) { |
|
286 | - $this->requestLanguage = $requestLanguage; |
|
287 | - } |
|
288 | - return $requestLanguage; |
|
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * Checks if $sub is a subdirectory of $parent |
|
293 | - * |
|
294 | - * @param string $sub |
|
295 | - * @param string $parent |
|
296 | - * @return bool |
|
297 | - */ |
|
298 | - private function isSubDirectory($sub, $parent) { |
|
299 | - // Check whether $sub contains no ".." |
|
300 | - if(strpos($sub, '..') !== false) { |
|
301 | - return false; |
|
302 | - } |
|
303 | - |
|
304 | - // Check whether $sub is a subdirectory of $parent |
|
305 | - if (strpos($sub, $parent) === 0) { |
|
306 | - return true; |
|
307 | - } |
|
308 | - |
|
309 | - return false; |
|
310 | - } |
|
311 | - |
|
312 | - /** |
|
313 | - * Get a list of language files that should be loaded |
|
314 | - * |
|
315 | - * @param string $app |
|
316 | - * @param string $lang |
|
317 | - * @return string[] |
|
318 | - */ |
|
319 | - // FIXME This method is only public, until OC_L10N does not need it anymore, |
|
320 | - // FIXME This is also the reason, why it is not in the public interface |
|
321 | - public function getL10nFilesForApp($app, $lang) { |
|
322 | - $languageFiles = []; |
|
323 | - |
|
324 | - $i18nDir = $this->findL10nDir($app); |
|
325 | - $transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json'; |
|
326 | - |
|
327 | - if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/l10n/') |
|
328 | - || $this->isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/') |
|
329 | - || $this->isSubDirectory($transFile, $this->serverRoot . '/settings/l10n/') |
|
330 | - || $this->isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/') |
|
331 | - ) |
|
332 | - && file_exists($transFile)) { |
|
333 | - // load the translations file |
|
334 | - $languageFiles[] = $transFile; |
|
335 | - } |
|
336 | - |
|
337 | - // merge with translations from theme |
|
338 | - $theme = $this->config->getSystemValue('theme'); |
|
339 | - if (!empty($theme)) { |
|
340 | - $transFile = $this->serverRoot . '/themes/' . $theme . substr($transFile, strlen($this->serverRoot)); |
|
341 | - if (file_exists($transFile)) { |
|
342 | - $languageFiles[] = $transFile; |
|
343 | - } |
|
344 | - } |
|
345 | - |
|
346 | - return $languageFiles; |
|
347 | - } |
|
348 | - |
|
349 | - /** |
|
350 | - * find the l10n directory |
|
351 | - * |
|
352 | - * @param string $app App id or empty string for core |
|
353 | - * @return string directory |
|
354 | - */ |
|
355 | - protected function findL10nDir($app = null) { |
|
356 | - if (in_array($app, ['core', 'lib', 'settings'])) { |
|
357 | - if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) { |
|
358 | - return $this->serverRoot . '/' . $app . '/l10n/'; |
|
359 | - } |
|
360 | - } else if ($app && \OC_App::getAppPath($app) !== false) { |
|
361 | - // Check if the app is in the app folder |
|
362 | - return \OC_App::getAppPath($app) . '/l10n/'; |
|
363 | - } |
|
364 | - return $this->serverRoot . '/core/l10n/'; |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * Creates a function from the plural string |
|
370 | - * |
|
371 | - * Parts of the code is copied from Habari: |
|
372 | - * https://github.com/habari/system/blob/master/classes/locale.php |
|
373 | - * @param string $string |
|
374 | - * @return string |
|
375 | - */ |
|
376 | - public function createPluralFunction($string) { |
|
377 | - if (isset($this->pluralFunctions[$string])) { |
|
378 | - return $this->pluralFunctions[$string]; |
|
379 | - } |
|
380 | - |
|
381 | - if (preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) { |
|
382 | - // sanitize |
|
383 | - $nplurals = preg_replace( '/[^0-9]/', '', $matches[1] ); |
|
384 | - $plural = preg_replace( '#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2] ); |
|
385 | - |
|
386 | - $body = str_replace( |
|
387 | - array( 'plural', 'n', '$n$plurals', ), |
|
388 | - array( '$plural', '$n', '$nplurals', ), |
|
389 | - 'nplurals='. $nplurals . '; plural=' . $plural |
|
390 | - ); |
|
391 | - |
|
392 | - // add parents |
|
393 | - // important since PHP's ternary evaluates from left to right |
|
394 | - $body .= ';'; |
|
395 | - $res = ''; |
|
396 | - $p = 0; |
|
397 | - for($i = 0; $i < strlen($body); $i++) { |
|
398 | - $ch = $body[$i]; |
|
399 | - switch ( $ch ) { |
|
400 | - case '?': |
|
401 | - $res .= ' ? ('; |
|
402 | - $p++; |
|
403 | - break; |
|
404 | - case ':': |
|
405 | - $res .= ') : ('; |
|
406 | - break; |
|
407 | - case ';': |
|
408 | - $res .= str_repeat( ')', $p ) . ';'; |
|
409 | - $p = 0; |
|
410 | - break; |
|
411 | - default: |
|
412 | - $res .= $ch; |
|
413 | - } |
|
414 | - } |
|
415 | - |
|
416 | - $body = $res . 'return ($plural>=$nplurals?$nplurals-1:$plural);'; |
|
417 | - $function = create_function('$n', $body); |
|
418 | - $this->pluralFunctions[$string] = $function; |
|
419 | - return $function; |
|
420 | - } else { |
|
421 | - // default: one plural form for all cases but n==1 (english) |
|
422 | - $function = create_function( |
|
423 | - '$n', |
|
424 | - '$nplurals=2;$plural=($n==1?0:1);return ($plural>=$nplurals?$nplurals-1:$plural);' |
|
425 | - ); |
|
426 | - $this->pluralFunctions[$string] = $function; |
|
427 | - return $function; |
|
428 | - } |
|
429 | - } |
|
43 | + /** @var string */ |
|
44 | + protected $requestLanguage = ''; |
|
45 | + |
|
46 | + /** |
|
47 | + * cached instances |
|
48 | + * @var array Structure: Lang => App => \OCP\IL10N |
|
49 | + */ |
|
50 | + protected $instances = []; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var array Structure: App => string[] |
|
54 | + */ |
|
55 | + protected $availableLanguages = []; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var array Structure: string => callable |
|
59 | + */ |
|
60 | + protected $pluralFunctions = []; |
|
61 | + |
|
62 | + /** @var IConfig */ |
|
63 | + protected $config; |
|
64 | + |
|
65 | + /** @var IRequest */ |
|
66 | + protected $request; |
|
67 | + |
|
68 | + /** @var IUserSession */ |
|
69 | + protected $userSession; |
|
70 | + |
|
71 | + /** @var string */ |
|
72 | + protected $serverRoot; |
|
73 | + |
|
74 | + /** |
|
75 | + * @param IConfig $config |
|
76 | + * @param IRequest $request |
|
77 | + * @param IUserSession $userSession |
|
78 | + * @param string $serverRoot |
|
79 | + */ |
|
80 | + public function __construct(IConfig $config, |
|
81 | + IRequest $request, |
|
82 | + IUserSession $userSession, |
|
83 | + $serverRoot) { |
|
84 | + $this->config = $config; |
|
85 | + $this->request = $request; |
|
86 | + $this->userSession = $userSession; |
|
87 | + $this->serverRoot = $serverRoot; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Get a language instance |
|
92 | + * |
|
93 | + * @param string $app |
|
94 | + * @param string|null $lang |
|
95 | + * @return \OCP\IL10N |
|
96 | + */ |
|
97 | + public function get($app, $lang = null) { |
|
98 | + $app = \OC_App::cleanAppId($app); |
|
99 | + if ($lang !== null) { |
|
100 | + $lang = str_replace(array('\0', '/', '\\', '..'), '', (string) $lang); |
|
101 | + } |
|
102 | + if ($lang === null || !$this->languageExists($app, $lang)) { |
|
103 | + $lang = $this->findLanguage($app); |
|
104 | + } |
|
105 | + |
|
106 | + if (!isset($this->instances[$lang][$app])) { |
|
107 | + $this->instances[$lang][$app] = new L10N( |
|
108 | + $this, $app, $lang, |
|
109 | + $this->getL10nFilesForApp($app, $lang) |
|
110 | + ); |
|
111 | + } |
|
112 | + |
|
113 | + return $this->instances[$lang][$app]; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Find the best language |
|
118 | + * |
|
119 | + * @param string|null $app App id or null for core |
|
120 | + * @return string language If nothing works it returns 'en' |
|
121 | + */ |
|
122 | + public function findLanguage($app = null) { |
|
123 | + if ($this->requestLanguage !== '' && $this->languageExists($app, $this->requestLanguage)) { |
|
124 | + return $this->requestLanguage; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * At this point ownCloud might not yet be installed and thus the lookup |
|
129 | + * in the preferences table might fail. For this reason we need to check |
|
130 | + * whether the instance has already been installed |
|
131 | + * |
|
132 | + * @link https://github.com/owncloud/core/issues/21955 |
|
133 | + */ |
|
134 | + if($this->config->getSystemValue('installed', false)) { |
|
135 | + $userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() : null; |
|
136 | + if(!is_null($userId)) { |
|
137 | + $userLang = $this->config->getUserValue($userId, 'core', 'lang', null); |
|
138 | + } else { |
|
139 | + $userLang = null; |
|
140 | + } |
|
141 | + } else { |
|
142 | + $userId = null; |
|
143 | + $userLang = null; |
|
144 | + } |
|
145 | + |
|
146 | + if ($userLang) { |
|
147 | + $this->requestLanguage = $userLang; |
|
148 | + if ($this->languageExists($app, $userLang)) { |
|
149 | + return $userLang; |
|
150 | + } |
|
151 | + } |
|
152 | + |
|
153 | + try { |
|
154 | + // Try to get the language from the Request |
|
155 | + $lang = $this->getLanguageFromRequest($app); |
|
156 | + if ($userId !== null && $app === null && !$userLang) { |
|
157 | + $this->config->setUserValue($userId, 'core', 'lang', $lang); |
|
158 | + } |
|
159 | + return $lang; |
|
160 | + } catch (LanguageNotFoundException $e) { |
|
161 | + // Finding language from request failed fall back to default language |
|
162 | + $defaultLanguage = $this->config->getSystemValue('default_language', false); |
|
163 | + if ($defaultLanguage !== false && $this->languageExists($app, $defaultLanguage)) { |
|
164 | + return $defaultLanguage; |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + // We could not find any language so fall back to english |
|
169 | + return 'en'; |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Find all available languages for an app |
|
174 | + * |
|
175 | + * @param string|null $app App id or null for core |
|
176 | + * @return array an array of available languages |
|
177 | + */ |
|
178 | + public function findAvailableLanguages($app = null) { |
|
179 | + $key = $app; |
|
180 | + if ($key === null) { |
|
181 | + $key = 'null'; |
|
182 | + } |
|
183 | + |
|
184 | + // also works with null as key |
|
185 | + if (!empty($this->availableLanguages[$key])) { |
|
186 | + return $this->availableLanguages[$key]; |
|
187 | + } |
|
188 | + |
|
189 | + $available = ['en']; //english is always available |
|
190 | + $dir = $this->findL10nDir($app); |
|
191 | + if (is_dir($dir)) { |
|
192 | + $files = scandir($dir); |
|
193 | + if ($files !== false) { |
|
194 | + foreach ($files as $file) { |
|
195 | + if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') { |
|
196 | + $available[] = substr($file, 0, -5); |
|
197 | + } |
|
198 | + } |
|
199 | + } |
|
200 | + } |
|
201 | + |
|
202 | + // merge with translations from theme |
|
203 | + $theme = $this->config->getSystemValue('theme'); |
|
204 | + if (!empty($theme)) { |
|
205 | + $themeDir = $this->serverRoot . '/themes/' . $theme . substr($dir, strlen($this->serverRoot)); |
|
206 | + |
|
207 | + if (is_dir($themeDir)) { |
|
208 | + $files = scandir($themeDir); |
|
209 | + if ($files !== false) { |
|
210 | + foreach ($files as $file) { |
|
211 | + if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') { |
|
212 | + $available[] = substr($file, 0, -5); |
|
213 | + } |
|
214 | + } |
|
215 | + } |
|
216 | + } |
|
217 | + } |
|
218 | + |
|
219 | + $this->availableLanguages[$key] = $available; |
|
220 | + return $available; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * @param string|null $app App id or null for core |
|
225 | + * @param string $lang |
|
226 | + * @return bool |
|
227 | + */ |
|
228 | + public function languageExists($app, $lang) { |
|
229 | + if ($lang === 'en') {//english is always available |
|
230 | + return true; |
|
231 | + } |
|
232 | + |
|
233 | + $languages = $this->findAvailableLanguages($app); |
|
234 | + return array_search($lang, $languages) !== false; |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * @param string|null $app |
|
239 | + * @return string |
|
240 | + * @throws LanguageNotFoundException |
|
241 | + */ |
|
242 | + private function getLanguageFromRequest($app) { |
|
243 | + $header = $this->request->getHeader('ACCEPT_LANGUAGE'); |
|
244 | + if ($header) { |
|
245 | + $available = $this->findAvailableLanguages($app); |
|
246 | + |
|
247 | + // E.g. make sure that 'de' is before 'de_DE'. |
|
248 | + sort($available); |
|
249 | + |
|
250 | + $preferences = preg_split('/,\s*/', strtolower($header)); |
|
251 | + foreach ($preferences as $preference) { |
|
252 | + list($preferred_language) = explode(';', $preference); |
|
253 | + $preferred_language = str_replace('-', '_', $preferred_language); |
|
254 | + |
|
255 | + foreach ($available as $available_language) { |
|
256 | + if ($preferred_language === strtolower($available_language)) { |
|
257 | + return $available_language; |
|
258 | + } |
|
259 | + } |
|
260 | + |
|
261 | + // Fallback from de_De to de |
|
262 | + foreach ($available as $available_language) { |
|
263 | + if (substr($preferred_language, 0, 2) === $available_language) { |
|
264 | + return $available_language; |
|
265 | + } |
|
266 | + } |
|
267 | + } |
|
268 | + } |
|
269 | + |
|
270 | + throw new LanguageNotFoundException(); |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * @param string|null $app App id or null for core |
|
275 | + * @return string |
|
276 | + */ |
|
277 | + public function setLanguageFromRequest($app = null) { |
|
278 | + |
|
279 | + try { |
|
280 | + $requestLanguage = $this->getLanguageFromRequest($app); |
|
281 | + } catch (LanguageNotFoundException $e) { |
|
282 | + $requestLanguage = 'en'; |
|
283 | + } |
|
284 | + |
|
285 | + if ($app === null && !$this->requestLanguage) { |
|
286 | + $this->requestLanguage = $requestLanguage; |
|
287 | + } |
|
288 | + return $requestLanguage; |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * Checks if $sub is a subdirectory of $parent |
|
293 | + * |
|
294 | + * @param string $sub |
|
295 | + * @param string $parent |
|
296 | + * @return bool |
|
297 | + */ |
|
298 | + private function isSubDirectory($sub, $parent) { |
|
299 | + // Check whether $sub contains no ".." |
|
300 | + if(strpos($sub, '..') !== false) { |
|
301 | + return false; |
|
302 | + } |
|
303 | + |
|
304 | + // Check whether $sub is a subdirectory of $parent |
|
305 | + if (strpos($sub, $parent) === 0) { |
|
306 | + return true; |
|
307 | + } |
|
308 | + |
|
309 | + return false; |
|
310 | + } |
|
311 | + |
|
312 | + /** |
|
313 | + * Get a list of language files that should be loaded |
|
314 | + * |
|
315 | + * @param string $app |
|
316 | + * @param string $lang |
|
317 | + * @return string[] |
|
318 | + */ |
|
319 | + // FIXME This method is only public, until OC_L10N does not need it anymore, |
|
320 | + // FIXME This is also the reason, why it is not in the public interface |
|
321 | + public function getL10nFilesForApp($app, $lang) { |
|
322 | + $languageFiles = []; |
|
323 | + |
|
324 | + $i18nDir = $this->findL10nDir($app); |
|
325 | + $transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json'; |
|
326 | + |
|
327 | + if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/l10n/') |
|
328 | + || $this->isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/') |
|
329 | + || $this->isSubDirectory($transFile, $this->serverRoot . '/settings/l10n/') |
|
330 | + || $this->isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/') |
|
331 | + ) |
|
332 | + && file_exists($transFile)) { |
|
333 | + // load the translations file |
|
334 | + $languageFiles[] = $transFile; |
|
335 | + } |
|
336 | + |
|
337 | + // merge with translations from theme |
|
338 | + $theme = $this->config->getSystemValue('theme'); |
|
339 | + if (!empty($theme)) { |
|
340 | + $transFile = $this->serverRoot . '/themes/' . $theme . substr($transFile, strlen($this->serverRoot)); |
|
341 | + if (file_exists($transFile)) { |
|
342 | + $languageFiles[] = $transFile; |
|
343 | + } |
|
344 | + } |
|
345 | + |
|
346 | + return $languageFiles; |
|
347 | + } |
|
348 | + |
|
349 | + /** |
|
350 | + * find the l10n directory |
|
351 | + * |
|
352 | + * @param string $app App id or empty string for core |
|
353 | + * @return string directory |
|
354 | + */ |
|
355 | + protected function findL10nDir($app = null) { |
|
356 | + if (in_array($app, ['core', 'lib', 'settings'])) { |
|
357 | + if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) { |
|
358 | + return $this->serverRoot . '/' . $app . '/l10n/'; |
|
359 | + } |
|
360 | + } else if ($app && \OC_App::getAppPath($app) !== false) { |
|
361 | + // Check if the app is in the app folder |
|
362 | + return \OC_App::getAppPath($app) . '/l10n/'; |
|
363 | + } |
|
364 | + return $this->serverRoot . '/core/l10n/'; |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * Creates a function from the plural string |
|
370 | + * |
|
371 | + * Parts of the code is copied from Habari: |
|
372 | + * https://github.com/habari/system/blob/master/classes/locale.php |
|
373 | + * @param string $string |
|
374 | + * @return string |
|
375 | + */ |
|
376 | + public function createPluralFunction($string) { |
|
377 | + if (isset($this->pluralFunctions[$string])) { |
|
378 | + return $this->pluralFunctions[$string]; |
|
379 | + } |
|
380 | + |
|
381 | + if (preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) { |
|
382 | + // sanitize |
|
383 | + $nplurals = preg_replace( '/[^0-9]/', '', $matches[1] ); |
|
384 | + $plural = preg_replace( '#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2] ); |
|
385 | + |
|
386 | + $body = str_replace( |
|
387 | + array( 'plural', 'n', '$n$plurals', ), |
|
388 | + array( '$plural', '$n', '$nplurals', ), |
|
389 | + 'nplurals='. $nplurals . '; plural=' . $plural |
|
390 | + ); |
|
391 | + |
|
392 | + // add parents |
|
393 | + // important since PHP's ternary evaluates from left to right |
|
394 | + $body .= ';'; |
|
395 | + $res = ''; |
|
396 | + $p = 0; |
|
397 | + for($i = 0; $i < strlen($body); $i++) { |
|
398 | + $ch = $body[$i]; |
|
399 | + switch ( $ch ) { |
|
400 | + case '?': |
|
401 | + $res .= ' ? ('; |
|
402 | + $p++; |
|
403 | + break; |
|
404 | + case ':': |
|
405 | + $res .= ') : ('; |
|
406 | + break; |
|
407 | + case ';': |
|
408 | + $res .= str_repeat( ')', $p ) . ';'; |
|
409 | + $p = 0; |
|
410 | + break; |
|
411 | + default: |
|
412 | + $res .= $ch; |
|
413 | + } |
|
414 | + } |
|
415 | + |
|
416 | + $body = $res . 'return ($plural>=$nplurals?$nplurals-1:$plural);'; |
|
417 | + $function = create_function('$n', $body); |
|
418 | + $this->pluralFunctions[$string] = $function; |
|
419 | + return $function; |
|
420 | + } else { |
|
421 | + // default: one plural form for all cases but n==1 (english) |
|
422 | + $function = create_function( |
|
423 | + '$n', |
|
424 | + '$nplurals=2;$plural=($n==1?0:1);return ($plural>=$nplurals?$nplurals-1:$plural);' |
|
425 | + ); |
|
426 | + $this->pluralFunctions[$string] = $function; |
|
427 | + return $function; |
|
428 | + } |
|
429 | + } |
|
430 | 430 | } |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @link https://github.com/owncloud/core/issues/21955 |
133 | 133 | */ |
134 | - if($this->config->getSystemValue('installed', false)) { |
|
135 | - $userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() : null; |
|
136 | - if(!is_null($userId)) { |
|
134 | + if ($this->config->getSystemValue('installed', false)) { |
|
135 | + $userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() : null; |
|
136 | + if (!is_null($userId)) { |
|
137 | 137 | $userLang = $this->config->getUserValue($userId, 'core', 'lang', null); |
138 | 138 | } else { |
139 | 139 | $userLang = null; |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | // merge with translations from theme |
203 | 203 | $theme = $this->config->getSystemValue('theme'); |
204 | 204 | if (!empty($theme)) { |
205 | - $themeDir = $this->serverRoot . '/themes/' . $theme . substr($dir, strlen($this->serverRoot)); |
|
205 | + $themeDir = $this->serverRoot.'/themes/'.$theme.substr($dir, strlen($this->serverRoot)); |
|
206 | 206 | |
207 | 207 | if (is_dir($themeDir)) { |
208 | 208 | $files = scandir($themeDir); |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | */ |
298 | 298 | private function isSubDirectory($sub, $parent) { |
299 | 299 | // Check whether $sub contains no ".." |
300 | - if(strpos($sub, '..') !== false) { |
|
300 | + if (strpos($sub, '..') !== false) { |
|
301 | 301 | return false; |
302 | 302 | } |
303 | 303 | |
@@ -322,12 +322,12 @@ discard block |
||
322 | 322 | $languageFiles = []; |
323 | 323 | |
324 | 324 | $i18nDir = $this->findL10nDir($app); |
325 | - $transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json'; |
|
325 | + $transFile = strip_tags($i18nDir).strip_tags($lang).'.json'; |
|
326 | 326 | |
327 | - if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/l10n/') |
|
328 | - || $this->isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/') |
|
329 | - || $this->isSubDirectory($transFile, $this->serverRoot . '/settings/l10n/') |
|
330 | - || $this->isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/') |
|
327 | + if (($this->isSubDirectory($transFile, $this->serverRoot.'/core/l10n/') |
|
328 | + || $this->isSubDirectory($transFile, $this->serverRoot.'/lib/l10n/') |
|
329 | + || $this->isSubDirectory($transFile, $this->serverRoot.'/settings/l10n/') |
|
330 | + || $this->isSubDirectory($transFile, \OC_App::getAppPath($app).'/l10n/') |
|
331 | 331 | ) |
332 | 332 | && file_exists($transFile)) { |
333 | 333 | // load the translations file |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | // merge with translations from theme |
338 | 338 | $theme = $this->config->getSystemValue('theme'); |
339 | 339 | if (!empty($theme)) { |
340 | - $transFile = $this->serverRoot . '/themes/' . $theme . substr($transFile, strlen($this->serverRoot)); |
|
340 | + $transFile = $this->serverRoot.'/themes/'.$theme.substr($transFile, strlen($this->serverRoot)); |
|
341 | 341 | if (file_exists($transFile)) { |
342 | 342 | $languageFiles[] = $transFile; |
343 | 343 | } |
@@ -354,14 +354,14 @@ discard block |
||
354 | 354 | */ |
355 | 355 | protected function findL10nDir($app = null) { |
356 | 356 | if (in_array($app, ['core', 'lib', 'settings'])) { |
357 | - if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) { |
|
358 | - return $this->serverRoot . '/' . $app . '/l10n/'; |
|
357 | + if (file_exists($this->serverRoot.'/'.$app.'/l10n/')) { |
|
358 | + return $this->serverRoot.'/'.$app.'/l10n/'; |
|
359 | 359 | } |
360 | 360 | } else if ($app && \OC_App::getAppPath($app) !== false) { |
361 | 361 | // Check if the app is in the app folder |
362 | - return \OC_App::getAppPath($app) . '/l10n/'; |
|
362 | + return \OC_App::getAppPath($app).'/l10n/'; |
|
363 | 363 | } |
364 | - return $this->serverRoot . '/core/l10n/'; |
|
364 | + return $this->serverRoot.'/core/l10n/'; |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | |
@@ -378,15 +378,15 @@ discard block |
||
378 | 378 | return $this->pluralFunctions[$string]; |
379 | 379 | } |
380 | 380 | |
381 | - if (preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) { |
|
381 | + if (preg_match('/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) { |
|
382 | 382 | // sanitize |
383 | - $nplurals = preg_replace( '/[^0-9]/', '', $matches[1] ); |
|
384 | - $plural = preg_replace( '#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2] ); |
|
383 | + $nplurals = preg_replace('/[^0-9]/', '', $matches[1]); |
|
384 | + $plural = preg_replace('#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2]); |
|
385 | 385 | |
386 | 386 | $body = str_replace( |
387 | - array( 'plural', 'n', '$n$plurals', ), |
|
388 | - array( '$plural', '$n', '$nplurals', ), |
|
389 | - 'nplurals='. $nplurals . '; plural=' . $plural |
|
387 | + array('plural', 'n', '$n$plurals',), |
|
388 | + array('$plural', '$n', '$nplurals',), |
|
389 | + 'nplurals='.$nplurals.'; plural='.$plural |
|
390 | 390 | ); |
391 | 391 | |
392 | 392 | // add parents |
@@ -394,9 +394,9 @@ discard block |
||
394 | 394 | $body .= ';'; |
395 | 395 | $res = ''; |
396 | 396 | $p = 0; |
397 | - for($i = 0; $i < strlen($body); $i++) { |
|
397 | + for ($i = 0; $i < strlen($body); $i++) { |
|
398 | 398 | $ch = $body[$i]; |
399 | - switch ( $ch ) { |
|
399 | + switch ($ch) { |
|
400 | 400 | case '?': |
401 | 401 | $res .= ' ? ('; |
402 | 402 | $p++; |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | $res .= ') : ('; |
406 | 406 | break; |
407 | 407 | case ';': |
408 | - $res .= str_repeat( ')', $p ) . ';'; |
|
408 | + $res .= str_repeat(')', $p).';'; |
|
409 | 409 | $p = 0; |
410 | 410 | break; |
411 | 411 | default: |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | } |
414 | 414 | } |
415 | 415 | |
416 | - $body = $res . 'return ($plural>=$nplurals?$nplurals-1:$plural);'; |
|
416 | + $body = $res.'return ($plural>=$nplurals?$nplurals-1:$plural);'; |
|
417 | 417 | $function = create_function('$n', $body); |
418 | 418 | $this->pluralFunctions[$string] = $function; |
419 | 419 | return $function; |
@@ -45,7 +45,6 @@ |
||
45 | 45 | use OC\App\CodeChecker\CodeChecker; |
46 | 46 | use OC\App\CodeChecker\EmptyCheck; |
47 | 47 | use OC\App\CodeChecker\PrivateCheck; |
48 | -use OC\Archive\Archive; |
|
49 | 48 | use OC\Archive\TAR; |
50 | 49 | use OC_App; |
51 | 50 | use OC_DB; |
@@ -60,493 +60,493 @@ |
||
60 | 60 | * This class provides the functionality needed to install, update and remove apps |
61 | 61 | */ |
62 | 62 | class Installer { |
63 | - /** @var AppFetcher */ |
|
64 | - private $appFetcher; |
|
65 | - /** @var IClientService */ |
|
66 | - private $clientService; |
|
67 | - /** @var ITempManager */ |
|
68 | - private $tempManager; |
|
69 | - /** @var ILogger */ |
|
70 | - private $logger; |
|
71 | - |
|
72 | - /** |
|
73 | - * @param AppFetcher $appFetcher |
|
74 | - * @param IClientService $clientService |
|
75 | - * @param ITempManager $tempManager |
|
76 | - * @param ILogger $logger |
|
77 | - */ |
|
78 | - public function __construct(AppFetcher $appFetcher, |
|
79 | - IClientService $clientService, |
|
80 | - ITempManager $tempManager, |
|
81 | - ILogger $logger) { |
|
82 | - $this->appFetcher = $appFetcher; |
|
83 | - $this->clientService = $clientService; |
|
84 | - $this->tempManager = $tempManager; |
|
85 | - $this->logger = $logger; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Installs an app that is located in one of the app folders already |
|
90 | - * |
|
91 | - * @param string $appId App to install |
|
92 | - * @throws \Exception |
|
93 | - * @return integer |
|
94 | - */ |
|
95 | - public function installApp($appId) { |
|
96 | - $app = \OC_App::findAppInDirectories($appId); |
|
97 | - if($app === false) { |
|
98 | - throw new \Exception('App not found in any app directory'); |
|
99 | - } |
|
100 | - |
|
101 | - $basedir = $app['path'].'/'.$appId; |
|
102 | - $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true); |
|
103 | - |
|
104 | - //install the database |
|
105 | - if(is_file($basedir.'/appinfo/database.xml')) { |
|
106 | - if (\OC::$server->getAppConfig()->getValue($info['id'], 'installed_version') === null) { |
|
107 | - OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
|
108 | - } else { |
|
109 | - OC_DB::updateDbFromStructure($basedir.'/appinfo/database.xml'); |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
114 | - |
|
115 | - //run appinfo/install.php |
|
116 | - if((!isset($data['noinstall']) or $data['noinstall']==false)) { |
|
117 | - self::includeAppScript($basedir . '/appinfo/install.php'); |
|
118 | - } |
|
119 | - |
|
120 | - $appData = OC_App::getAppInfo($appId); |
|
121 | - OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']); |
|
122 | - |
|
123 | - //set the installed version |
|
124 | - \OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'], false)); |
|
125 | - \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
|
126 | - |
|
127 | - //set remote/public handlers |
|
128 | - foreach($info['remote'] as $name=>$path) { |
|
129 | - \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
|
130 | - } |
|
131 | - foreach($info['public'] as $name=>$path) { |
|
132 | - \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
|
133 | - } |
|
134 | - |
|
135 | - OC_App::setAppTypes($info['id']); |
|
136 | - |
|
137 | - return $info['id']; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * @brief checks whether or not an app is installed |
|
142 | - * @param string $app app |
|
143 | - * @returns bool |
|
144 | - * |
|
145 | - * Checks whether or not an app is installed, i.e. registered in apps table. |
|
146 | - */ |
|
147 | - public static function isInstalled( $app ) { |
|
148 | - return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null); |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Updates the specified app from the appstore |
|
153 | - * |
|
154 | - * @param string $appId |
|
155 | - * @return bool |
|
156 | - */ |
|
157 | - public function updateAppstoreApp($appId) { |
|
158 | - if(self::isUpdateAvailable($appId, $this->appFetcher)) { |
|
159 | - try { |
|
160 | - $this->downloadApp($appId); |
|
161 | - } catch (\Exception $e) { |
|
162 | - $this->logger->error($e->getMessage(), ['app' => 'core']); |
|
163 | - return false; |
|
164 | - } |
|
165 | - return OC_App::updateApp($appId); |
|
166 | - } |
|
167 | - |
|
168 | - return false; |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Downloads an app and puts it into the app directory |
|
173 | - * |
|
174 | - * @param string $appId |
|
175 | - * |
|
176 | - * @throws \Exception If the installation was not successful |
|
177 | - */ |
|
178 | - public function downloadApp($appId) { |
|
179 | - $appId = strtolower($appId); |
|
180 | - |
|
181 | - $apps = $this->appFetcher->get(); |
|
182 | - foreach($apps as $app) { |
|
183 | - if($app['id'] === $appId) { |
|
184 | - // Load the certificate |
|
185 | - $certificate = new X509(); |
|
186 | - $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
187 | - $loadedCertificate = $certificate->loadX509($app['certificate']); |
|
188 | - |
|
189 | - // Verify if the certificate has been revoked |
|
190 | - $crl = new X509(); |
|
191 | - $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
192 | - $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
193 | - if($crl->validateSignature() !== true) { |
|
194 | - throw new \Exception('Could not validate CRL signature'); |
|
195 | - } |
|
196 | - $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
|
197 | - $revoked = $crl->getRevoked($csn); |
|
198 | - if ($revoked !== false) { |
|
199 | - throw new \Exception( |
|
200 | - sprintf( |
|
201 | - 'Certificate "%s" has been revoked', |
|
202 | - $csn |
|
203 | - ) |
|
204 | - ); |
|
205 | - } |
|
206 | - |
|
207 | - // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
|
208 | - if($certificate->validateSignature() !== true) { |
|
209 | - throw new \Exception( |
|
210 | - sprintf( |
|
211 | - 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
|
212 | - $appId |
|
213 | - ) |
|
214 | - ); |
|
215 | - } |
|
216 | - |
|
217 | - // Verify if the certificate is issued for the requested app id |
|
218 | - $certInfo = openssl_x509_parse($app['certificate']); |
|
219 | - if(!isset($certInfo['subject']['CN'])) { |
|
220 | - throw new \Exception( |
|
221 | - sprintf( |
|
222 | - 'App with id %s has a cert with no CN', |
|
223 | - $appId |
|
224 | - ) |
|
225 | - ); |
|
226 | - } |
|
227 | - if($certInfo['subject']['CN'] !== $appId) { |
|
228 | - throw new \Exception( |
|
229 | - sprintf( |
|
230 | - 'App with id %s has a cert issued to %s', |
|
231 | - $appId, |
|
232 | - $certInfo['subject']['CN'] |
|
233 | - ) |
|
234 | - ); |
|
235 | - } |
|
236 | - |
|
237 | - // Download the release |
|
238 | - $tempFile = $this->tempManager->getTemporaryFile('.tar.gz'); |
|
239 | - $client = $this->clientService->newClient(); |
|
240 | - $client->get($app['releases'][0]['download'], ['save_to' => $tempFile]); |
|
241 | - |
|
242 | - // Check if the signature actually matches the downloaded content |
|
243 | - $certificate = openssl_get_publickey($app['certificate']); |
|
244 | - $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
245 | - openssl_free_key($certificate); |
|
246 | - |
|
247 | - if($verified === true) { |
|
248 | - // Seems to match, let's proceed |
|
249 | - $extractDir = $this->tempManager->getTemporaryFolder(); |
|
250 | - $archive = new TAR($tempFile); |
|
251 | - |
|
252 | - if($archive) { |
|
253 | - $archive->extract($extractDir); |
|
254 | - $allFiles = scandir($extractDir); |
|
255 | - $folders = array_diff($allFiles, ['.', '..']); |
|
256 | - $folders = array_values($folders); |
|
257 | - |
|
258 | - if(count($folders) > 1) { |
|
259 | - throw new \Exception( |
|
260 | - sprintf( |
|
261 | - 'Extracted app %s has more than 1 folder', |
|
262 | - $appId |
|
263 | - ) |
|
264 | - ); |
|
265 | - } |
|
266 | - |
|
267 | - // Check if appinfo/info.xml has the same app ID as well |
|
268 | - $loadEntities = libxml_disable_entity_loader(false); |
|
269 | - $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
270 | - libxml_disable_entity_loader($loadEntities); |
|
271 | - if((string)$xml->id !== $appId) { |
|
272 | - throw new \Exception( |
|
273 | - sprintf( |
|
274 | - 'App for id %s has a wrong app ID in info.xml: %s', |
|
275 | - $appId, |
|
276 | - (string)$xml->id |
|
277 | - ) |
|
278 | - ); |
|
279 | - } |
|
280 | - |
|
281 | - // Check if the version is lower than before |
|
282 | - $currentVersion = OC_App::getAppVersion($appId); |
|
283 | - $newVersion = (string)$xml->version; |
|
284 | - if(version_compare($currentVersion, $newVersion) === 1) { |
|
285 | - throw new \Exception( |
|
286 | - sprintf( |
|
287 | - 'App for id %s has version %s and tried to update to lower version %s', |
|
288 | - $appId, |
|
289 | - $currentVersion, |
|
290 | - $newVersion |
|
291 | - ) |
|
292 | - ); |
|
293 | - } |
|
294 | - |
|
295 | - $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
296 | - // Remove old app with the ID if existent |
|
297 | - OC_Helper::rmdirr($baseDir); |
|
298 | - // Move to app folder |
|
299 | - if(@mkdir($baseDir)) { |
|
300 | - $extractDir .= '/' . $folders[0]; |
|
301 | - OC_Helper::copyr($extractDir, $baseDir); |
|
302 | - } |
|
303 | - OC_Helper::copyr($extractDir, $baseDir); |
|
304 | - OC_Helper::rmdirr($extractDir); |
|
305 | - return; |
|
306 | - } else { |
|
307 | - throw new \Exception( |
|
308 | - sprintf( |
|
309 | - 'Could not extract app with ID %s to %s', |
|
310 | - $appId, |
|
311 | - $extractDir |
|
312 | - ) |
|
313 | - ); |
|
314 | - } |
|
315 | - } else { |
|
316 | - // Signature does not match |
|
317 | - throw new \Exception( |
|
318 | - sprintf( |
|
319 | - 'App with id %s has invalid signature', |
|
320 | - $appId |
|
321 | - ) |
|
322 | - ); |
|
323 | - } |
|
324 | - } |
|
325 | - } |
|
326 | - |
|
327 | - throw new \Exception( |
|
328 | - sprintf( |
|
329 | - 'Could not download app %s', |
|
330 | - $appId |
|
331 | - ) |
|
332 | - ); |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * Check if an update for the app is available |
|
337 | - * |
|
338 | - * @param string $appId |
|
339 | - * @param AppFetcher $appFetcher |
|
340 | - * @return string|false false or the version number of the update |
|
341 | - */ |
|
342 | - public static function isUpdateAvailable($appId, |
|
343 | - AppFetcher $appFetcher) { |
|
344 | - static $isInstanceReadyForUpdates = null; |
|
345 | - |
|
346 | - if ($isInstanceReadyForUpdates === null) { |
|
347 | - $installPath = OC_App::getInstallPath(); |
|
348 | - if ($installPath === false || $installPath === null) { |
|
349 | - $isInstanceReadyForUpdates = false; |
|
350 | - } else { |
|
351 | - $isInstanceReadyForUpdates = true; |
|
352 | - } |
|
353 | - } |
|
354 | - |
|
355 | - if ($isInstanceReadyForUpdates === false) { |
|
356 | - return false; |
|
357 | - } |
|
358 | - |
|
359 | - $apps = $appFetcher->get(); |
|
360 | - foreach($apps as $app) { |
|
361 | - if($app['id'] === $appId) { |
|
362 | - $currentVersion = OC_App::getAppVersion($appId); |
|
363 | - $newestVersion = $app['releases'][0]['version']; |
|
364 | - if (version_compare($newestVersion, $currentVersion, '>')) { |
|
365 | - return $newestVersion; |
|
366 | - } else { |
|
367 | - return false; |
|
368 | - } |
|
369 | - } |
|
370 | - } |
|
371 | - |
|
372 | - return false; |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * Check if app is already downloaded |
|
377 | - * @param string $name name of the application to remove |
|
378 | - * @return boolean |
|
379 | - * |
|
380 | - * The function will check if the app is already downloaded in the apps repository |
|
381 | - */ |
|
382 | - public function isDownloaded($name) { |
|
383 | - foreach(\OC::$APPSROOTS as $dir) { |
|
384 | - $dirToTest = $dir['path']; |
|
385 | - $dirToTest .= '/'; |
|
386 | - $dirToTest .= $name; |
|
387 | - $dirToTest .= '/'; |
|
388 | - |
|
389 | - if (is_dir($dirToTest)) { |
|
390 | - return true; |
|
391 | - } |
|
392 | - } |
|
393 | - |
|
394 | - return false; |
|
395 | - } |
|
396 | - |
|
397 | - /** |
|
398 | - * Removes an app |
|
399 | - * @param string $appId ID of the application to remove |
|
400 | - * @return boolean |
|
401 | - * |
|
402 | - * |
|
403 | - * This function works as follows |
|
404 | - * -# call uninstall repair steps |
|
405 | - * -# removing the files |
|
406 | - * |
|
407 | - * The function will not delete preferences, tables and the configuration, |
|
408 | - * this has to be done by the function oc_app_uninstall(). |
|
409 | - */ |
|
410 | - public function removeApp($appId) { |
|
411 | - if($this->isDownloaded( $appId )) { |
|
412 | - $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
413 | - OC_Helper::rmdirr($appDir); |
|
414 | - return true; |
|
415 | - }else{ |
|
416 | - \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
|
417 | - |
|
418 | - return false; |
|
419 | - } |
|
420 | - |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * Installs shipped apps |
|
425 | - * |
|
426 | - * This function installs all apps found in the 'apps' directory that should be enabled by default; |
|
427 | - * @param bool $softErrors When updating we ignore errors and simply log them, better to have a |
|
428 | - * working ownCloud at the end instead of an aborted update. |
|
429 | - * @return array Array of error messages (appid => Exception) |
|
430 | - */ |
|
431 | - public static function installShippedApps($softErrors = false) { |
|
432 | - $errors = []; |
|
433 | - foreach(\OC::$APPSROOTS as $app_dir) { |
|
434 | - if($dir = opendir( $app_dir['path'] )) { |
|
435 | - while( false !== ( $filename = readdir( $dir ))) { |
|
436 | - if( substr( $filename, 0, 1 ) != '.' and is_dir($app_dir['path']."/$filename") ) { |
|
437 | - if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
438 | - if(!Installer::isInstalled($filename)) { |
|
439 | - $info=OC_App::getAppInfo($filename); |
|
440 | - $enabled = isset($info['default_enable']); |
|
441 | - if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps())) |
|
442 | - && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') { |
|
443 | - if ($softErrors) { |
|
444 | - try { |
|
445 | - Installer::installShippedApp($filename); |
|
446 | - } catch (HintException $e) { |
|
447 | - if ($e->getPrevious() instanceof TableExistsException) { |
|
448 | - $errors[$filename] = $e; |
|
449 | - continue; |
|
450 | - } |
|
451 | - throw $e; |
|
452 | - } |
|
453 | - } else { |
|
454 | - Installer::installShippedApp($filename); |
|
455 | - } |
|
456 | - \OC::$server->getConfig()->setAppValue($filename, 'enabled', 'yes'); |
|
457 | - } |
|
458 | - } |
|
459 | - } |
|
460 | - } |
|
461 | - } |
|
462 | - closedir( $dir ); |
|
463 | - } |
|
464 | - } |
|
465 | - |
|
466 | - return $errors; |
|
467 | - } |
|
468 | - |
|
469 | - /** |
|
470 | - * install an app already placed in the app folder |
|
471 | - * @param string $app id of the app to install |
|
472 | - * @return integer |
|
473 | - */ |
|
474 | - public static function installShippedApp($app) { |
|
475 | - //install the database |
|
476 | - $appPath = OC_App::getAppPath($app); |
|
477 | - if(is_file("$appPath/appinfo/database.xml")) { |
|
478 | - try { |
|
479 | - OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
|
480 | - } catch (TableExistsException $e) { |
|
481 | - throw new HintException( |
|
482 | - 'Failed to enable app ' . $app, |
|
483 | - 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer">support channels</a>.', |
|
484 | - 0, $e |
|
485 | - ); |
|
486 | - } |
|
487 | - } |
|
488 | - |
|
489 | - //run appinfo/install.php |
|
490 | - \OC_App::registerAutoloading($app, $appPath); |
|
491 | - self::includeAppScript("$appPath/appinfo/install.php"); |
|
492 | - |
|
493 | - $info = OC_App::getAppInfo($app); |
|
494 | - if (is_null($info)) { |
|
495 | - return false; |
|
496 | - } |
|
497 | - \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
498 | - |
|
499 | - OC_App::executeRepairSteps($app, $info['repair-steps']['install']); |
|
500 | - |
|
501 | - $config = \OC::$server->getConfig(); |
|
502 | - |
|
503 | - $config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app)); |
|
504 | - if (array_key_exists('ocsid', $info)) { |
|
505 | - $config->setAppValue($app, 'ocsid', $info['ocsid']); |
|
506 | - } |
|
507 | - |
|
508 | - //set remote/public handlers |
|
509 | - foreach($info['remote'] as $name=>$path) { |
|
510 | - $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
|
511 | - } |
|
512 | - foreach($info['public'] as $name=>$path) { |
|
513 | - $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
|
514 | - } |
|
515 | - |
|
516 | - OC_App::setAppTypes($info['id']); |
|
517 | - |
|
518 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
519 | - // requires that autoloading was registered for the app, |
|
520 | - // as happens before running the install.php some lines above |
|
521 | - \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
522 | - } |
|
523 | - |
|
524 | - return $info['id']; |
|
525 | - } |
|
526 | - |
|
527 | - /** |
|
528 | - * check the code of an app with some static code checks |
|
529 | - * @param string $folder the folder of the app to check |
|
530 | - * @return boolean true for app is o.k. and false for app is not o.k. |
|
531 | - */ |
|
532 | - public static function checkCode($folder) { |
|
533 | - // is the code checker enabled? |
|
534 | - if(!\OC::$server->getConfig()->getSystemValue('appcodechecker', false)) { |
|
535 | - return true; |
|
536 | - } |
|
537 | - |
|
538 | - $codeChecker = new CodeChecker(new PrivateCheck(new EmptyCheck())); |
|
539 | - $errors = $codeChecker->analyseFolder(basename($folder), $folder); |
|
540 | - |
|
541 | - return empty($errors); |
|
542 | - } |
|
543 | - |
|
544 | - /** |
|
545 | - * @param string $script |
|
546 | - */ |
|
547 | - private static function includeAppScript($script) { |
|
548 | - if ( file_exists($script) ){ |
|
549 | - include $script; |
|
550 | - } |
|
551 | - } |
|
63 | + /** @var AppFetcher */ |
|
64 | + private $appFetcher; |
|
65 | + /** @var IClientService */ |
|
66 | + private $clientService; |
|
67 | + /** @var ITempManager */ |
|
68 | + private $tempManager; |
|
69 | + /** @var ILogger */ |
|
70 | + private $logger; |
|
71 | + |
|
72 | + /** |
|
73 | + * @param AppFetcher $appFetcher |
|
74 | + * @param IClientService $clientService |
|
75 | + * @param ITempManager $tempManager |
|
76 | + * @param ILogger $logger |
|
77 | + */ |
|
78 | + public function __construct(AppFetcher $appFetcher, |
|
79 | + IClientService $clientService, |
|
80 | + ITempManager $tempManager, |
|
81 | + ILogger $logger) { |
|
82 | + $this->appFetcher = $appFetcher; |
|
83 | + $this->clientService = $clientService; |
|
84 | + $this->tempManager = $tempManager; |
|
85 | + $this->logger = $logger; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Installs an app that is located in one of the app folders already |
|
90 | + * |
|
91 | + * @param string $appId App to install |
|
92 | + * @throws \Exception |
|
93 | + * @return integer |
|
94 | + */ |
|
95 | + public function installApp($appId) { |
|
96 | + $app = \OC_App::findAppInDirectories($appId); |
|
97 | + if($app === false) { |
|
98 | + throw new \Exception('App not found in any app directory'); |
|
99 | + } |
|
100 | + |
|
101 | + $basedir = $app['path'].'/'.$appId; |
|
102 | + $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true); |
|
103 | + |
|
104 | + //install the database |
|
105 | + if(is_file($basedir.'/appinfo/database.xml')) { |
|
106 | + if (\OC::$server->getAppConfig()->getValue($info['id'], 'installed_version') === null) { |
|
107 | + OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
|
108 | + } else { |
|
109 | + OC_DB::updateDbFromStructure($basedir.'/appinfo/database.xml'); |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
114 | + |
|
115 | + //run appinfo/install.php |
|
116 | + if((!isset($data['noinstall']) or $data['noinstall']==false)) { |
|
117 | + self::includeAppScript($basedir . '/appinfo/install.php'); |
|
118 | + } |
|
119 | + |
|
120 | + $appData = OC_App::getAppInfo($appId); |
|
121 | + OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']); |
|
122 | + |
|
123 | + //set the installed version |
|
124 | + \OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'], false)); |
|
125 | + \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
|
126 | + |
|
127 | + //set remote/public handlers |
|
128 | + foreach($info['remote'] as $name=>$path) { |
|
129 | + \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
|
130 | + } |
|
131 | + foreach($info['public'] as $name=>$path) { |
|
132 | + \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
|
133 | + } |
|
134 | + |
|
135 | + OC_App::setAppTypes($info['id']); |
|
136 | + |
|
137 | + return $info['id']; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * @brief checks whether or not an app is installed |
|
142 | + * @param string $app app |
|
143 | + * @returns bool |
|
144 | + * |
|
145 | + * Checks whether or not an app is installed, i.e. registered in apps table. |
|
146 | + */ |
|
147 | + public static function isInstalled( $app ) { |
|
148 | + return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null); |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Updates the specified app from the appstore |
|
153 | + * |
|
154 | + * @param string $appId |
|
155 | + * @return bool |
|
156 | + */ |
|
157 | + public function updateAppstoreApp($appId) { |
|
158 | + if(self::isUpdateAvailable($appId, $this->appFetcher)) { |
|
159 | + try { |
|
160 | + $this->downloadApp($appId); |
|
161 | + } catch (\Exception $e) { |
|
162 | + $this->logger->error($e->getMessage(), ['app' => 'core']); |
|
163 | + return false; |
|
164 | + } |
|
165 | + return OC_App::updateApp($appId); |
|
166 | + } |
|
167 | + |
|
168 | + return false; |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Downloads an app and puts it into the app directory |
|
173 | + * |
|
174 | + * @param string $appId |
|
175 | + * |
|
176 | + * @throws \Exception If the installation was not successful |
|
177 | + */ |
|
178 | + public function downloadApp($appId) { |
|
179 | + $appId = strtolower($appId); |
|
180 | + |
|
181 | + $apps = $this->appFetcher->get(); |
|
182 | + foreach($apps as $app) { |
|
183 | + if($app['id'] === $appId) { |
|
184 | + // Load the certificate |
|
185 | + $certificate = new X509(); |
|
186 | + $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
187 | + $loadedCertificate = $certificate->loadX509($app['certificate']); |
|
188 | + |
|
189 | + // Verify if the certificate has been revoked |
|
190 | + $crl = new X509(); |
|
191 | + $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
192 | + $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
193 | + if($crl->validateSignature() !== true) { |
|
194 | + throw new \Exception('Could not validate CRL signature'); |
|
195 | + } |
|
196 | + $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
|
197 | + $revoked = $crl->getRevoked($csn); |
|
198 | + if ($revoked !== false) { |
|
199 | + throw new \Exception( |
|
200 | + sprintf( |
|
201 | + 'Certificate "%s" has been revoked', |
|
202 | + $csn |
|
203 | + ) |
|
204 | + ); |
|
205 | + } |
|
206 | + |
|
207 | + // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
|
208 | + if($certificate->validateSignature() !== true) { |
|
209 | + throw new \Exception( |
|
210 | + sprintf( |
|
211 | + 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
|
212 | + $appId |
|
213 | + ) |
|
214 | + ); |
|
215 | + } |
|
216 | + |
|
217 | + // Verify if the certificate is issued for the requested app id |
|
218 | + $certInfo = openssl_x509_parse($app['certificate']); |
|
219 | + if(!isset($certInfo['subject']['CN'])) { |
|
220 | + throw new \Exception( |
|
221 | + sprintf( |
|
222 | + 'App with id %s has a cert with no CN', |
|
223 | + $appId |
|
224 | + ) |
|
225 | + ); |
|
226 | + } |
|
227 | + if($certInfo['subject']['CN'] !== $appId) { |
|
228 | + throw new \Exception( |
|
229 | + sprintf( |
|
230 | + 'App with id %s has a cert issued to %s', |
|
231 | + $appId, |
|
232 | + $certInfo['subject']['CN'] |
|
233 | + ) |
|
234 | + ); |
|
235 | + } |
|
236 | + |
|
237 | + // Download the release |
|
238 | + $tempFile = $this->tempManager->getTemporaryFile('.tar.gz'); |
|
239 | + $client = $this->clientService->newClient(); |
|
240 | + $client->get($app['releases'][0]['download'], ['save_to' => $tempFile]); |
|
241 | + |
|
242 | + // Check if the signature actually matches the downloaded content |
|
243 | + $certificate = openssl_get_publickey($app['certificate']); |
|
244 | + $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
245 | + openssl_free_key($certificate); |
|
246 | + |
|
247 | + if($verified === true) { |
|
248 | + // Seems to match, let's proceed |
|
249 | + $extractDir = $this->tempManager->getTemporaryFolder(); |
|
250 | + $archive = new TAR($tempFile); |
|
251 | + |
|
252 | + if($archive) { |
|
253 | + $archive->extract($extractDir); |
|
254 | + $allFiles = scandir($extractDir); |
|
255 | + $folders = array_diff($allFiles, ['.', '..']); |
|
256 | + $folders = array_values($folders); |
|
257 | + |
|
258 | + if(count($folders) > 1) { |
|
259 | + throw new \Exception( |
|
260 | + sprintf( |
|
261 | + 'Extracted app %s has more than 1 folder', |
|
262 | + $appId |
|
263 | + ) |
|
264 | + ); |
|
265 | + } |
|
266 | + |
|
267 | + // Check if appinfo/info.xml has the same app ID as well |
|
268 | + $loadEntities = libxml_disable_entity_loader(false); |
|
269 | + $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
270 | + libxml_disable_entity_loader($loadEntities); |
|
271 | + if((string)$xml->id !== $appId) { |
|
272 | + throw new \Exception( |
|
273 | + sprintf( |
|
274 | + 'App for id %s has a wrong app ID in info.xml: %s', |
|
275 | + $appId, |
|
276 | + (string)$xml->id |
|
277 | + ) |
|
278 | + ); |
|
279 | + } |
|
280 | + |
|
281 | + // Check if the version is lower than before |
|
282 | + $currentVersion = OC_App::getAppVersion($appId); |
|
283 | + $newVersion = (string)$xml->version; |
|
284 | + if(version_compare($currentVersion, $newVersion) === 1) { |
|
285 | + throw new \Exception( |
|
286 | + sprintf( |
|
287 | + 'App for id %s has version %s and tried to update to lower version %s', |
|
288 | + $appId, |
|
289 | + $currentVersion, |
|
290 | + $newVersion |
|
291 | + ) |
|
292 | + ); |
|
293 | + } |
|
294 | + |
|
295 | + $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
296 | + // Remove old app with the ID if existent |
|
297 | + OC_Helper::rmdirr($baseDir); |
|
298 | + // Move to app folder |
|
299 | + if(@mkdir($baseDir)) { |
|
300 | + $extractDir .= '/' . $folders[0]; |
|
301 | + OC_Helper::copyr($extractDir, $baseDir); |
|
302 | + } |
|
303 | + OC_Helper::copyr($extractDir, $baseDir); |
|
304 | + OC_Helper::rmdirr($extractDir); |
|
305 | + return; |
|
306 | + } else { |
|
307 | + throw new \Exception( |
|
308 | + sprintf( |
|
309 | + 'Could not extract app with ID %s to %s', |
|
310 | + $appId, |
|
311 | + $extractDir |
|
312 | + ) |
|
313 | + ); |
|
314 | + } |
|
315 | + } else { |
|
316 | + // Signature does not match |
|
317 | + throw new \Exception( |
|
318 | + sprintf( |
|
319 | + 'App with id %s has invalid signature', |
|
320 | + $appId |
|
321 | + ) |
|
322 | + ); |
|
323 | + } |
|
324 | + } |
|
325 | + } |
|
326 | + |
|
327 | + throw new \Exception( |
|
328 | + sprintf( |
|
329 | + 'Could not download app %s', |
|
330 | + $appId |
|
331 | + ) |
|
332 | + ); |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * Check if an update for the app is available |
|
337 | + * |
|
338 | + * @param string $appId |
|
339 | + * @param AppFetcher $appFetcher |
|
340 | + * @return string|false false or the version number of the update |
|
341 | + */ |
|
342 | + public static function isUpdateAvailable($appId, |
|
343 | + AppFetcher $appFetcher) { |
|
344 | + static $isInstanceReadyForUpdates = null; |
|
345 | + |
|
346 | + if ($isInstanceReadyForUpdates === null) { |
|
347 | + $installPath = OC_App::getInstallPath(); |
|
348 | + if ($installPath === false || $installPath === null) { |
|
349 | + $isInstanceReadyForUpdates = false; |
|
350 | + } else { |
|
351 | + $isInstanceReadyForUpdates = true; |
|
352 | + } |
|
353 | + } |
|
354 | + |
|
355 | + if ($isInstanceReadyForUpdates === false) { |
|
356 | + return false; |
|
357 | + } |
|
358 | + |
|
359 | + $apps = $appFetcher->get(); |
|
360 | + foreach($apps as $app) { |
|
361 | + if($app['id'] === $appId) { |
|
362 | + $currentVersion = OC_App::getAppVersion($appId); |
|
363 | + $newestVersion = $app['releases'][0]['version']; |
|
364 | + if (version_compare($newestVersion, $currentVersion, '>')) { |
|
365 | + return $newestVersion; |
|
366 | + } else { |
|
367 | + return false; |
|
368 | + } |
|
369 | + } |
|
370 | + } |
|
371 | + |
|
372 | + return false; |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * Check if app is already downloaded |
|
377 | + * @param string $name name of the application to remove |
|
378 | + * @return boolean |
|
379 | + * |
|
380 | + * The function will check if the app is already downloaded in the apps repository |
|
381 | + */ |
|
382 | + public function isDownloaded($name) { |
|
383 | + foreach(\OC::$APPSROOTS as $dir) { |
|
384 | + $dirToTest = $dir['path']; |
|
385 | + $dirToTest .= '/'; |
|
386 | + $dirToTest .= $name; |
|
387 | + $dirToTest .= '/'; |
|
388 | + |
|
389 | + if (is_dir($dirToTest)) { |
|
390 | + return true; |
|
391 | + } |
|
392 | + } |
|
393 | + |
|
394 | + return false; |
|
395 | + } |
|
396 | + |
|
397 | + /** |
|
398 | + * Removes an app |
|
399 | + * @param string $appId ID of the application to remove |
|
400 | + * @return boolean |
|
401 | + * |
|
402 | + * |
|
403 | + * This function works as follows |
|
404 | + * -# call uninstall repair steps |
|
405 | + * -# removing the files |
|
406 | + * |
|
407 | + * The function will not delete preferences, tables and the configuration, |
|
408 | + * this has to be done by the function oc_app_uninstall(). |
|
409 | + */ |
|
410 | + public function removeApp($appId) { |
|
411 | + if($this->isDownloaded( $appId )) { |
|
412 | + $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
413 | + OC_Helper::rmdirr($appDir); |
|
414 | + return true; |
|
415 | + }else{ |
|
416 | + \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
|
417 | + |
|
418 | + return false; |
|
419 | + } |
|
420 | + |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * Installs shipped apps |
|
425 | + * |
|
426 | + * This function installs all apps found in the 'apps' directory that should be enabled by default; |
|
427 | + * @param bool $softErrors When updating we ignore errors and simply log them, better to have a |
|
428 | + * working ownCloud at the end instead of an aborted update. |
|
429 | + * @return array Array of error messages (appid => Exception) |
|
430 | + */ |
|
431 | + public static function installShippedApps($softErrors = false) { |
|
432 | + $errors = []; |
|
433 | + foreach(\OC::$APPSROOTS as $app_dir) { |
|
434 | + if($dir = opendir( $app_dir['path'] )) { |
|
435 | + while( false !== ( $filename = readdir( $dir ))) { |
|
436 | + if( substr( $filename, 0, 1 ) != '.' and is_dir($app_dir['path']."/$filename") ) { |
|
437 | + if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
438 | + if(!Installer::isInstalled($filename)) { |
|
439 | + $info=OC_App::getAppInfo($filename); |
|
440 | + $enabled = isset($info['default_enable']); |
|
441 | + if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps())) |
|
442 | + && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') { |
|
443 | + if ($softErrors) { |
|
444 | + try { |
|
445 | + Installer::installShippedApp($filename); |
|
446 | + } catch (HintException $e) { |
|
447 | + if ($e->getPrevious() instanceof TableExistsException) { |
|
448 | + $errors[$filename] = $e; |
|
449 | + continue; |
|
450 | + } |
|
451 | + throw $e; |
|
452 | + } |
|
453 | + } else { |
|
454 | + Installer::installShippedApp($filename); |
|
455 | + } |
|
456 | + \OC::$server->getConfig()->setAppValue($filename, 'enabled', 'yes'); |
|
457 | + } |
|
458 | + } |
|
459 | + } |
|
460 | + } |
|
461 | + } |
|
462 | + closedir( $dir ); |
|
463 | + } |
|
464 | + } |
|
465 | + |
|
466 | + return $errors; |
|
467 | + } |
|
468 | + |
|
469 | + /** |
|
470 | + * install an app already placed in the app folder |
|
471 | + * @param string $app id of the app to install |
|
472 | + * @return integer |
|
473 | + */ |
|
474 | + public static function installShippedApp($app) { |
|
475 | + //install the database |
|
476 | + $appPath = OC_App::getAppPath($app); |
|
477 | + if(is_file("$appPath/appinfo/database.xml")) { |
|
478 | + try { |
|
479 | + OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
|
480 | + } catch (TableExistsException $e) { |
|
481 | + throw new HintException( |
|
482 | + 'Failed to enable app ' . $app, |
|
483 | + 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer">support channels</a>.', |
|
484 | + 0, $e |
|
485 | + ); |
|
486 | + } |
|
487 | + } |
|
488 | + |
|
489 | + //run appinfo/install.php |
|
490 | + \OC_App::registerAutoloading($app, $appPath); |
|
491 | + self::includeAppScript("$appPath/appinfo/install.php"); |
|
492 | + |
|
493 | + $info = OC_App::getAppInfo($app); |
|
494 | + if (is_null($info)) { |
|
495 | + return false; |
|
496 | + } |
|
497 | + \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
498 | + |
|
499 | + OC_App::executeRepairSteps($app, $info['repair-steps']['install']); |
|
500 | + |
|
501 | + $config = \OC::$server->getConfig(); |
|
502 | + |
|
503 | + $config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app)); |
|
504 | + if (array_key_exists('ocsid', $info)) { |
|
505 | + $config->setAppValue($app, 'ocsid', $info['ocsid']); |
|
506 | + } |
|
507 | + |
|
508 | + //set remote/public handlers |
|
509 | + foreach($info['remote'] as $name=>$path) { |
|
510 | + $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
|
511 | + } |
|
512 | + foreach($info['public'] as $name=>$path) { |
|
513 | + $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
|
514 | + } |
|
515 | + |
|
516 | + OC_App::setAppTypes($info['id']); |
|
517 | + |
|
518 | + if(isset($info['settings']) && is_array($info['settings'])) { |
|
519 | + // requires that autoloading was registered for the app, |
|
520 | + // as happens before running the install.php some lines above |
|
521 | + \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
522 | + } |
|
523 | + |
|
524 | + return $info['id']; |
|
525 | + } |
|
526 | + |
|
527 | + /** |
|
528 | + * check the code of an app with some static code checks |
|
529 | + * @param string $folder the folder of the app to check |
|
530 | + * @return boolean true for app is o.k. and false for app is not o.k. |
|
531 | + */ |
|
532 | + public static function checkCode($folder) { |
|
533 | + // is the code checker enabled? |
|
534 | + if(!\OC::$server->getConfig()->getSystemValue('appcodechecker', false)) { |
|
535 | + return true; |
|
536 | + } |
|
537 | + |
|
538 | + $codeChecker = new CodeChecker(new PrivateCheck(new EmptyCheck())); |
|
539 | + $errors = $codeChecker->analyseFolder(basename($folder), $folder); |
|
540 | + |
|
541 | + return empty($errors); |
|
542 | + } |
|
543 | + |
|
544 | + /** |
|
545 | + * @param string $script |
|
546 | + */ |
|
547 | + private static function includeAppScript($script) { |
|
548 | + if ( file_exists($script) ){ |
|
549 | + include $script; |
|
550 | + } |
|
551 | + } |
|
552 | 552 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function installApp($appId) { |
96 | 96 | $app = \OC_App::findAppInDirectories($appId); |
97 | - if($app === false) { |
|
97 | + if ($app === false) { |
|
98 | 98 | throw new \Exception('App not found in any app directory'); |
99 | 99 | } |
100 | 100 | |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true); |
103 | 103 | |
104 | 104 | //install the database |
105 | - if(is_file($basedir.'/appinfo/database.xml')) { |
|
105 | + if (is_file($basedir.'/appinfo/database.xml')) { |
|
106 | 106 | if (\OC::$server->getAppConfig()->getValue($info['id'], 'installed_version') === null) { |
107 | 107 | OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
108 | 108 | } else { |
@@ -113,8 +113,8 @@ discard block |
||
113 | 113 | \OC_App::setupBackgroundJobs($info['background-jobs']); |
114 | 114 | |
115 | 115 | //run appinfo/install.php |
116 | - if((!isset($data['noinstall']) or $data['noinstall']==false)) { |
|
117 | - self::includeAppScript($basedir . '/appinfo/install.php'); |
|
116 | + if ((!isset($data['noinstall']) or $data['noinstall'] == false)) { |
|
117 | + self::includeAppScript($basedir.'/appinfo/install.php'); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | $appData = OC_App::getAppInfo($appId); |
@@ -125,10 +125,10 @@ discard block |
||
125 | 125 | \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
126 | 126 | |
127 | 127 | //set remote/public handlers |
128 | - foreach($info['remote'] as $name=>$path) { |
|
128 | + foreach ($info['remote'] as $name=>$path) { |
|
129 | 129 | \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
130 | 130 | } |
131 | - foreach($info['public'] as $name=>$path) { |
|
131 | + foreach ($info['public'] as $name=>$path) { |
|
132 | 132 | \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
133 | 133 | } |
134 | 134 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * |
145 | 145 | * Checks whether or not an app is installed, i.e. registered in apps table. |
146 | 146 | */ |
147 | - public static function isInstalled( $app ) { |
|
147 | + public static function isInstalled($app) { |
|
148 | 148 | return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null); |
149 | 149 | } |
150 | 150 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * @return bool |
156 | 156 | */ |
157 | 157 | public function updateAppstoreApp($appId) { |
158 | - if(self::isUpdateAvailable($appId, $this->appFetcher)) { |
|
158 | + if (self::isUpdateAvailable($appId, $this->appFetcher)) { |
|
159 | 159 | try { |
160 | 160 | $this->downloadApp($appId); |
161 | 161 | } catch (\Exception $e) { |
@@ -179,18 +179,18 @@ discard block |
||
179 | 179 | $appId = strtolower($appId); |
180 | 180 | |
181 | 181 | $apps = $this->appFetcher->get(); |
182 | - foreach($apps as $app) { |
|
183 | - if($app['id'] === $appId) { |
|
182 | + foreach ($apps as $app) { |
|
183 | + if ($app['id'] === $appId) { |
|
184 | 184 | // Load the certificate |
185 | 185 | $certificate = new X509(); |
186 | - $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
186 | + $certificate->loadCA(file_get_contents(__DIR__.'/../../resources/codesigning/root.crt')); |
|
187 | 187 | $loadedCertificate = $certificate->loadX509($app['certificate']); |
188 | 188 | |
189 | 189 | // Verify if the certificate has been revoked |
190 | 190 | $crl = new X509(); |
191 | - $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
192 | - $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
193 | - if($crl->validateSignature() !== true) { |
|
191 | + $crl->loadCA(file_get_contents(__DIR__.'/../../resources/codesigning/root.crt')); |
|
192 | + $crl->loadCRL(file_get_contents(__DIR__.'/../../resources/codesigning/root.crl')); |
|
193 | + if ($crl->validateSignature() !== true) { |
|
194 | 194 | throw new \Exception('Could not validate CRL signature'); |
195 | 195 | } |
196 | 196 | $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | } |
206 | 206 | |
207 | 207 | // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
208 | - if($certificate->validateSignature() !== true) { |
|
208 | + if ($certificate->validateSignature() !== true) { |
|
209 | 209 | throw new \Exception( |
210 | 210 | sprintf( |
211 | 211 | 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | |
217 | 217 | // Verify if the certificate is issued for the requested app id |
218 | 218 | $certInfo = openssl_x509_parse($app['certificate']); |
219 | - if(!isset($certInfo['subject']['CN'])) { |
|
219 | + if (!isset($certInfo['subject']['CN'])) { |
|
220 | 220 | throw new \Exception( |
221 | 221 | sprintf( |
222 | 222 | 'App with id %s has a cert with no CN', |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | ) |
225 | 225 | ); |
226 | 226 | } |
227 | - if($certInfo['subject']['CN'] !== $appId) { |
|
227 | + if ($certInfo['subject']['CN'] !== $appId) { |
|
228 | 228 | throw new \Exception( |
229 | 229 | sprintf( |
230 | 230 | 'App with id %s has a cert issued to %s', |
@@ -241,21 +241,21 @@ discard block |
||
241 | 241 | |
242 | 242 | // Check if the signature actually matches the downloaded content |
243 | 243 | $certificate = openssl_get_publickey($app['certificate']); |
244 | - $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
244 | + $verified = (bool) openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
245 | 245 | openssl_free_key($certificate); |
246 | 246 | |
247 | - if($verified === true) { |
|
247 | + if ($verified === true) { |
|
248 | 248 | // Seems to match, let's proceed |
249 | 249 | $extractDir = $this->tempManager->getTemporaryFolder(); |
250 | 250 | $archive = new TAR($tempFile); |
251 | 251 | |
252 | - if($archive) { |
|
252 | + if ($archive) { |
|
253 | 253 | $archive->extract($extractDir); |
254 | 254 | $allFiles = scandir($extractDir); |
255 | 255 | $folders = array_diff($allFiles, ['.', '..']); |
256 | 256 | $folders = array_values($folders); |
257 | 257 | |
258 | - if(count($folders) > 1) { |
|
258 | + if (count($folders) > 1) { |
|
259 | 259 | throw new \Exception( |
260 | 260 | sprintf( |
261 | 261 | 'Extracted app %s has more than 1 folder', |
@@ -266,22 +266,22 @@ discard block |
||
266 | 266 | |
267 | 267 | // Check if appinfo/info.xml has the same app ID as well |
268 | 268 | $loadEntities = libxml_disable_entity_loader(false); |
269 | - $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
269 | + $xml = simplexml_load_file($extractDir.'/'.$folders[0].'/appinfo/info.xml'); |
|
270 | 270 | libxml_disable_entity_loader($loadEntities); |
271 | - if((string)$xml->id !== $appId) { |
|
271 | + if ((string) $xml->id !== $appId) { |
|
272 | 272 | throw new \Exception( |
273 | 273 | sprintf( |
274 | 274 | 'App for id %s has a wrong app ID in info.xml: %s', |
275 | 275 | $appId, |
276 | - (string)$xml->id |
|
276 | + (string) $xml->id |
|
277 | 277 | ) |
278 | 278 | ); |
279 | 279 | } |
280 | 280 | |
281 | 281 | // Check if the version is lower than before |
282 | 282 | $currentVersion = OC_App::getAppVersion($appId); |
283 | - $newVersion = (string)$xml->version; |
|
284 | - if(version_compare($currentVersion, $newVersion) === 1) { |
|
283 | + $newVersion = (string) $xml->version; |
|
284 | + if (version_compare($currentVersion, $newVersion) === 1) { |
|
285 | 285 | throw new \Exception( |
286 | 286 | sprintf( |
287 | 287 | 'App for id %s has version %s and tried to update to lower version %s', |
@@ -292,12 +292,12 @@ discard block |
||
292 | 292 | ); |
293 | 293 | } |
294 | 294 | |
295 | - $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
295 | + $baseDir = OC_App::getInstallPath().'/'.$appId; |
|
296 | 296 | // Remove old app with the ID if existent |
297 | 297 | OC_Helper::rmdirr($baseDir); |
298 | 298 | // Move to app folder |
299 | - if(@mkdir($baseDir)) { |
|
300 | - $extractDir .= '/' . $folders[0]; |
|
299 | + if (@mkdir($baseDir)) { |
|
300 | + $extractDir .= '/'.$folders[0]; |
|
301 | 301 | OC_Helper::copyr($extractDir, $baseDir); |
302 | 302 | } |
303 | 303 | OC_Helper::copyr($extractDir, $baseDir); |
@@ -357,8 +357,8 @@ discard block |
||
357 | 357 | } |
358 | 358 | |
359 | 359 | $apps = $appFetcher->get(); |
360 | - foreach($apps as $app) { |
|
361 | - if($app['id'] === $appId) { |
|
360 | + foreach ($apps as $app) { |
|
361 | + if ($app['id'] === $appId) { |
|
362 | 362 | $currentVersion = OC_App::getAppVersion($appId); |
363 | 363 | $newestVersion = $app['releases'][0]['version']; |
364 | 364 | if (version_compare($newestVersion, $currentVersion, '>')) { |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | * The function will check if the app is already downloaded in the apps repository |
381 | 381 | */ |
382 | 382 | public function isDownloaded($name) { |
383 | - foreach(\OC::$APPSROOTS as $dir) { |
|
383 | + foreach (\OC::$APPSROOTS as $dir) { |
|
384 | 384 | $dirToTest = $dir['path']; |
385 | 385 | $dirToTest .= '/'; |
386 | 386 | $dirToTest .= $name; |
@@ -408,11 +408,11 @@ discard block |
||
408 | 408 | * this has to be done by the function oc_app_uninstall(). |
409 | 409 | */ |
410 | 410 | public function removeApp($appId) { |
411 | - if($this->isDownloaded( $appId )) { |
|
412 | - $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
411 | + if ($this->isDownloaded($appId)) { |
|
412 | + $appDir = OC_App::getInstallPath().'/'.$appId; |
|
413 | 413 | OC_Helper::rmdirr($appDir); |
414 | 414 | return true; |
415 | - }else{ |
|
415 | + } else { |
|
416 | 416 | \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
417 | 417 | |
418 | 418 | return false; |
@@ -430,13 +430,13 @@ discard block |
||
430 | 430 | */ |
431 | 431 | public static function installShippedApps($softErrors = false) { |
432 | 432 | $errors = []; |
433 | - foreach(\OC::$APPSROOTS as $app_dir) { |
|
434 | - if($dir = opendir( $app_dir['path'] )) { |
|
435 | - while( false !== ( $filename = readdir( $dir ))) { |
|
436 | - if( substr( $filename, 0, 1 ) != '.' and is_dir($app_dir['path']."/$filename") ) { |
|
437 | - if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
438 | - if(!Installer::isInstalled($filename)) { |
|
439 | - $info=OC_App::getAppInfo($filename); |
|
433 | + foreach (\OC::$APPSROOTS as $app_dir) { |
|
434 | + if ($dir = opendir($app_dir['path'])) { |
|
435 | + while (false !== ($filename = readdir($dir))) { |
|
436 | + if (substr($filename, 0, 1) != '.' and is_dir($app_dir['path']."/$filename")) { |
|
437 | + if (file_exists($app_dir['path']."/$filename/appinfo/info.xml")) { |
|
438 | + if (!Installer::isInstalled($filename)) { |
|
439 | + $info = OC_App::getAppInfo($filename); |
|
440 | 440 | $enabled = isset($info['default_enable']); |
441 | 441 | if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps())) |
442 | 442 | && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') { |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | } |
460 | 460 | } |
461 | 461 | } |
462 | - closedir( $dir ); |
|
462 | + closedir($dir); |
|
463 | 463 | } |
464 | 464 | } |
465 | 465 | |
@@ -474,12 +474,12 @@ discard block |
||
474 | 474 | public static function installShippedApp($app) { |
475 | 475 | //install the database |
476 | 476 | $appPath = OC_App::getAppPath($app); |
477 | - if(is_file("$appPath/appinfo/database.xml")) { |
|
477 | + if (is_file("$appPath/appinfo/database.xml")) { |
|
478 | 478 | try { |
479 | 479 | OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
480 | 480 | } catch (TableExistsException $e) { |
481 | 481 | throw new HintException( |
482 | - 'Failed to enable app ' . $app, |
|
482 | + 'Failed to enable app '.$app, |
|
483 | 483 | 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer">support channels</a>.', |
484 | 484 | 0, $e |
485 | 485 | ); |
@@ -506,16 +506,16 @@ discard block |
||
506 | 506 | } |
507 | 507 | |
508 | 508 | //set remote/public handlers |
509 | - foreach($info['remote'] as $name=>$path) { |
|
509 | + foreach ($info['remote'] as $name=>$path) { |
|
510 | 510 | $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
511 | 511 | } |
512 | - foreach($info['public'] as $name=>$path) { |
|
512 | + foreach ($info['public'] as $name=>$path) { |
|
513 | 513 | $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
514 | 514 | } |
515 | 515 | |
516 | 516 | OC_App::setAppTypes($info['id']); |
517 | 517 | |
518 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
518 | + if (isset($info['settings']) && is_array($info['settings'])) { |
|
519 | 519 | // requires that autoloading was registered for the app, |
520 | 520 | // as happens before running the install.php some lines above |
521 | 521 | \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | */ |
532 | 532 | public static function checkCode($folder) { |
533 | 533 | // is the code checker enabled? |
534 | - if(!\OC::$server->getConfig()->getSystemValue('appcodechecker', false)) { |
|
534 | + if (!\OC::$server->getConfig()->getSystemValue('appcodechecker', false)) { |
|
535 | 535 | return true; |
536 | 536 | } |
537 | 537 | |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | * @param string $script |
546 | 546 | */ |
547 | 547 | private static function includeAppScript($script) { |
548 | - if ( file_exists($script) ){ |
|
548 | + if (file_exists($script)) { |
|
549 | 549 | include $script; |
550 | 550 | } |
551 | 551 | } |
@@ -412,7 +412,7 @@ |
||
412 | 412 | $appDir = OC_App::getInstallPath() . '/' . $appId; |
413 | 413 | OC_Helper::rmdirr($appDir); |
414 | 414 | return true; |
415 | - }else{ |
|
415 | + } else{ |
|
416 | 416 | \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
417 | 417 | |
418 | 418 | return false; |
@@ -131,7 +131,7 @@ |
||
131 | 131 | /** |
132 | 132 | * Create the federated share provider |
133 | 133 | * |
134 | - * @return FederatedShareProvider |
|
134 | + * @return null|ShareByMailProvider |
|
135 | 135 | */ |
136 | 136 | protected function getShareByMailProvider() { |
137 | 137 | if ($this->shareByMailProvider === null) { |
@@ -40,178 +40,178 @@ |
||
40 | 40 | */ |
41 | 41 | class ProviderFactory implements IProviderFactory { |
42 | 42 | |
43 | - /** @var IServerContainer */ |
|
44 | - private $serverContainer; |
|
45 | - /** @var DefaultShareProvider */ |
|
46 | - private $defaultProvider = null; |
|
47 | - /** @var FederatedShareProvider */ |
|
48 | - private $federatedProvider = null; |
|
49 | - /** @var ShareByMailProvider */ |
|
50 | - private $shareByMailProvider; |
|
51 | - |
|
52 | - /** |
|
53 | - * IProviderFactory constructor. |
|
54 | - * @param IServerContainer $serverContainer |
|
55 | - */ |
|
56 | - public function __construct(IServerContainer $serverContainer) { |
|
57 | - $this->serverContainer = $serverContainer; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Create the default share provider. |
|
62 | - * |
|
63 | - * @return DefaultShareProvider |
|
64 | - */ |
|
65 | - protected function defaultShareProvider() { |
|
66 | - if ($this->defaultProvider === null) { |
|
67 | - $this->defaultProvider = new DefaultShareProvider( |
|
68 | - $this->serverContainer->getDatabaseConnection(), |
|
69 | - $this->serverContainer->getUserManager(), |
|
70 | - $this->serverContainer->getGroupManager(), |
|
71 | - $this->serverContainer->getLazyRootFolder() |
|
72 | - ); |
|
73 | - } |
|
74 | - |
|
75 | - return $this->defaultProvider; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Create the federated share provider |
|
80 | - * |
|
81 | - * @return FederatedShareProvider |
|
82 | - */ |
|
83 | - protected function federatedShareProvider() { |
|
84 | - if ($this->federatedProvider === null) { |
|
85 | - /* |
|
43 | + /** @var IServerContainer */ |
|
44 | + private $serverContainer; |
|
45 | + /** @var DefaultShareProvider */ |
|
46 | + private $defaultProvider = null; |
|
47 | + /** @var FederatedShareProvider */ |
|
48 | + private $federatedProvider = null; |
|
49 | + /** @var ShareByMailProvider */ |
|
50 | + private $shareByMailProvider; |
|
51 | + |
|
52 | + /** |
|
53 | + * IProviderFactory constructor. |
|
54 | + * @param IServerContainer $serverContainer |
|
55 | + */ |
|
56 | + public function __construct(IServerContainer $serverContainer) { |
|
57 | + $this->serverContainer = $serverContainer; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Create the default share provider. |
|
62 | + * |
|
63 | + * @return DefaultShareProvider |
|
64 | + */ |
|
65 | + protected function defaultShareProvider() { |
|
66 | + if ($this->defaultProvider === null) { |
|
67 | + $this->defaultProvider = new DefaultShareProvider( |
|
68 | + $this->serverContainer->getDatabaseConnection(), |
|
69 | + $this->serverContainer->getUserManager(), |
|
70 | + $this->serverContainer->getGroupManager(), |
|
71 | + $this->serverContainer->getLazyRootFolder() |
|
72 | + ); |
|
73 | + } |
|
74 | + |
|
75 | + return $this->defaultProvider; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Create the federated share provider |
|
80 | + * |
|
81 | + * @return FederatedShareProvider |
|
82 | + */ |
|
83 | + protected function federatedShareProvider() { |
|
84 | + if ($this->federatedProvider === null) { |
|
85 | + /* |
|
86 | 86 | * Check if the app is enabled |
87 | 87 | */ |
88 | - $appManager = $this->serverContainer->getAppManager(); |
|
89 | - if (!$appManager->isEnabledForUser('federatedfilesharing')) { |
|
90 | - return null; |
|
91 | - } |
|
88 | + $appManager = $this->serverContainer->getAppManager(); |
|
89 | + if (!$appManager->isEnabledForUser('federatedfilesharing')) { |
|
90 | + return null; |
|
91 | + } |
|
92 | 92 | |
93 | - /* |
|
93 | + /* |
|
94 | 94 | * TODO: add factory to federated sharing app |
95 | 95 | */ |
96 | - $l = $this->serverContainer->getL10N('federatedfilessharing'); |
|
97 | - $addressHandler = new AddressHandler( |
|
98 | - $this->serverContainer->getURLGenerator(), |
|
99 | - $l, |
|
100 | - $this->serverContainer->getCloudIdManager() |
|
101 | - ); |
|
102 | - $discoveryManager = new DiscoveryManager( |
|
103 | - $this->serverContainer->getMemCacheFactory(), |
|
104 | - $this->serverContainer->getHTTPClientService() |
|
105 | - ); |
|
106 | - $notifications = new Notifications( |
|
107 | - $addressHandler, |
|
108 | - $this->serverContainer->getHTTPClientService(), |
|
109 | - $discoveryManager, |
|
110 | - $this->serverContainer->getJobList() |
|
111 | - ); |
|
112 | - $tokenHandler = new TokenHandler( |
|
113 | - $this->serverContainer->getSecureRandom() |
|
114 | - ); |
|
115 | - |
|
116 | - $this->federatedProvider = new FederatedShareProvider( |
|
117 | - $this->serverContainer->getDatabaseConnection(), |
|
118 | - $addressHandler, |
|
119 | - $notifications, |
|
120 | - $tokenHandler, |
|
121 | - $l, |
|
122 | - $this->serverContainer->getLogger(), |
|
123 | - $this->serverContainer->getLazyRootFolder(), |
|
124 | - $this->serverContainer->getConfig(), |
|
125 | - $this->serverContainer->getUserManager(), |
|
126 | - $this->serverContainer->getCloudIdManager() |
|
127 | - ); |
|
128 | - } |
|
129 | - |
|
130 | - return $this->federatedProvider; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Create the federated share provider |
|
135 | - * |
|
136 | - * @return FederatedShareProvider |
|
137 | - */ |
|
138 | - protected function getShareByMailProvider() { |
|
139 | - if ($this->shareByMailProvider === null) { |
|
140 | - /* |
|
96 | + $l = $this->serverContainer->getL10N('federatedfilessharing'); |
|
97 | + $addressHandler = new AddressHandler( |
|
98 | + $this->serverContainer->getURLGenerator(), |
|
99 | + $l, |
|
100 | + $this->serverContainer->getCloudIdManager() |
|
101 | + ); |
|
102 | + $discoveryManager = new DiscoveryManager( |
|
103 | + $this->serverContainer->getMemCacheFactory(), |
|
104 | + $this->serverContainer->getHTTPClientService() |
|
105 | + ); |
|
106 | + $notifications = new Notifications( |
|
107 | + $addressHandler, |
|
108 | + $this->serverContainer->getHTTPClientService(), |
|
109 | + $discoveryManager, |
|
110 | + $this->serverContainer->getJobList() |
|
111 | + ); |
|
112 | + $tokenHandler = new TokenHandler( |
|
113 | + $this->serverContainer->getSecureRandom() |
|
114 | + ); |
|
115 | + |
|
116 | + $this->federatedProvider = new FederatedShareProvider( |
|
117 | + $this->serverContainer->getDatabaseConnection(), |
|
118 | + $addressHandler, |
|
119 | + $notifications, |
|
120 | + $tokenHandler, |
|
121 | + $l, |
|
122 | + $this->serverContainer->getLogger(), |
|
123 | + $this->serverContainer->getLazyRootFolder(), |
|
124 | + $this->serverContainer->getConfig(), |
|
125 | + $this->serverContainer->getUserManager(), |
|
126 | + $this->serverContainer->getCloudIdManager() |
|
127 | + ); |
|
128 | + } |
|
129 | + |
|
130 | + return $this->federatedProvider; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Create the federated share provider |
|
135 | + * |
|
136 | + * @return FederatedShareProvider |
|
137 | + */ |
|
138 | + protected function getShareByMailProvider() { |
|
139 | + if ($this->shareByMailProvider === null) { |
|
140 | + /* |
|
141 | 141 | * Check if the app is enabled |
142 | 142 | */ |
143 | - $appManager = $this->serverContainer->getAppManager(); |
|
144 | - if (!$appManager->isEnabledForUser('sharebymail')) { |
|
145 | - return null; |
|
146 | - } |
|
147 | - |
|
148 | - $l = $this->serverContainer->getL10N('sharebymail'); |
|
149 | - |
|
150 | - $this->shareByMailProvider = new ShareByMailProvider( |
|
151 | - $this->serverContainer->getDatabaseConnection(), |
|
152 | - $this->serverContainer->getSecureRandom(), |
|
153 | - $this->serverContainer->getUserManager(), |
|
154 | - $this->serverContainer->getLazyRootFolder(), |
|
155 | - $l, |
|
156 | - $this->serverContainer->getLogger(), |
|
157 | - $this->serverContainer->getMailer(), |
|
158 | - $this->serverContainer->getURLGenerator(), |
|
159 | - $this->serverContainer->getActivityManager() |
|
160 | - ); |
|
161 | - } |
|
162 | - |
|
163 | - return $this->shareByMailProvider; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * @inheritdoc |
|
169 | - */ |
|
170 | - public function getProvider($id) { |
|
171 | - $provider = null; |
|
172 | - if ($id === 'ocinternal') { |
|
173 | - $provider = $this->defaultShareProvider(); |
|
174 | - } else if ($id === 'ocFederatedSharing') { |
|
175 | - $provider = $this->federatedShareProvider(); |
|
176 | - } else if ($id = 'ocMailShare') { |
|
177 | - $provider = $this->getShareByMailProvider(); |
|
178 | - } |
|
179 | - |
|
180 | - if ($provider === null) { |
|
181 | - throw new ProviderException('No provider with id .' . $id . ' found.'); |
|
182 | - } |
|
183 | - |
|
184 | - return $provider; |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * @inheritdoc |
|
189 | - */ |
|
190 | - public function getProviderForType($shareType) { |
|
191 | - $provider = null; |
|
192 | - |
|
193 | - if ($shareType === \OCP\Share::SHARE_TYPE_USER || |
|
194 | - $shareType === \OCP\Share::SHARE_TYPE_GROUP || |
|
195 | - $shareType === \OCP\Share::SHARE_TYPE_LINK) { |
|
196 | - $provider = $this->defaultShareProvider(); |
|
197 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
198 | - $provider = $this->federatedShareProvider(); |
|
199 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
200 | - $provider = $this->getShareByMailProvider(); |
|
201 | - } |
|
202 | - |
|
203 | - if ($provider === null) { |
|
204 | - throw new ProviderException('No share provider for share type ' . $shareType); |
|
205 | - } |
|
206 | - |
|
207 | - return $provider; |
|
208 | - } |
|
209 | - |
|
210 | - public function getAllProviders() { |
|
211 | - $shareByMail = $this->getShareByMailProvider(); |
|
212 | - if ($shareByMail !== null) { |
|
213 | - return [$this->defaultShareProvider(), $this->federatedShareProvider(), $shareByMail]; |
|
214 | - } |
|
215 | - return [$this->defaultShareProvider(), $this->federatedShareProvider()]; |
|
216 | - } |
|
143 | + $appManager = $this->serverContainer->getAppManager(); |
|
144 | + if (!$appManager->isEnabledForUser('sharebymail')) { |
|
145 | + return null; |
|
146 | + } |
|
147 | + |
|
148 | + $l = $this->serverContainer->getL10N('sharebymail'); |
|
149 | + |
|
150 | + $this->shareByMailProvider = new ShareByMailProvider( |
|
151 | + $this->serverContainer->getDatabaseConnection(), |
|
152 | + $this->serverContainer->getSecureRandom(), |
|
153 | + $this->serverContainer->getUserManager(), |
|
154 | + $this->serverContainer->getLazyRootFolder(), |
|
155 | + $l, |
|
156 | + $this->serverContainer->getLogger(), |
|
157 | + $this->serverContainer->getMailer(), |
|
158 | + $this->serverContainer->getURLGenerator(), |
|
159 | + $this->serverContainer->getActivityManager() |
|
160 | + ); |
|
161 | + } |
|
162 | + |
|
163 | + return $this->shareByMailProvider; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * @inheritdoc |
|
169 | + */ |
|
170 | + public function getProvider($id) { |
|
171 | + $provider = null; |
|
172 | + if ($id === 'ocinternal') { |
|
173 | + $provider = $this->defaultShareProvider(); |
|
174 | + } else if ($id === 'ocFederatedSharing') { |
|
175 | + $provider = $this->federatedShareProvider(); |
|
176 | + } else if ($id = 'ocMailShare') { |
|
177 | + $provider = $this->getShareByMailProvider(); |
|
178 | + } |
|
179 | + |
|
180 | + if ($provider === null) { |
|
181 | + throw new ProviderException('No provider with id .' . $id . ' found.'); |
|
182 | + } |
|
183 | + |
|
184 | + return $provider; |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * @inheritdoc |
|
189 | + */ |
|
190 | + public function getProviderForType($shareType) { |
|
191 | + $provider = null; |
|
192 | + |
|
193 | + if ($shareType === \OCP\Share::SHARE_TYPE_USER || |
|
194 | + $shareType === \OCP\Share::SHARE_TYPE_GROUP || |
|
195 | + $shareType === \OCP\Share::SHARE_TYPE_LINK) { |
|
196 | + $provider = $this->defaultShareProvider(); |
|
197 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
198 | + $provider = $this->federatedShareProvider(); |
|
199 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
200 | + $provider = $this->getShareByMailProvider(); |
|
201 | + } |
|
202 | + |
|
203 | + if ($provider === null) { |
|
204 | + throw new ProviderException('No share provider for share type ' . $shareType); |
|
205 | + } |
|
206 | + |
|
207 | + return $provider; |
|
208 | + } |
|
209 | + |
|
210 | + public function getAllProviders() { |
|
211 | + $shareByMail = $this->getShareByMailProvider(); |
|
212 | + if ($shareByMail !== null) { |
|
213 | + return [$this->defaultShareProvider(), $this->federatedShareProvider(), $shareByMail]; |
|
214 | + } |
|
215 | + return [$this->defaultShareProvider(), $this->federatedShareProvider()]; |
|
216 | + } |
|
217 | 217 | } |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | } |
179 | 179 | |
180 | 180 | if ($provider === null) { |
181 | - throw new ProviderException('No provider with id .' . $id . ' found.'); |
|
181 | + throw new ProviderException('No provider with id .'.$id.' found.'); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | return $provider; |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | public function getProviderForType($shareType) { |
191 | 191 | $provider = null; |
192 | 192 | |
193 | - if ($shareType === \OCP\Share::SHARE_TYPE_USER || |
|
193 | + if ($shareType === \OCP\Share::SHARE_TYPE_USER || |
|
194 | 194 | $shareType === \OCP\Share::SHARE_TYPE_GROUP || |
195 | 195 | $shareType === \OCP\Share::SHARE_TYPE_LINK) { |
196 | 196 | $provider = $this->defaultShareProvider(); |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | } |
202 | 202 | |
203 | 203 | if ($provider === null) { |
204 | - throw new ProviderException('No share provider for share type ' . $shareType); |
|
204 | + throw new ProviderException('No share provider for share type '.$shareType); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | return $provider; |
@@ -28,7 +28,6 @@ |
||
28 | 28 | use OCP\IUserManager; |
29 | 29 | use OCP\Util; |
30 | 30 | use Symfony\Component\EventDispatcher\EventDispatcher; |
31 | -use Symfony\Component\EventDispatcher\GenericEvent; |
|
32 | 31 | |
33 | 32 | class HookManager { |
34 | 33 |
@@ -32,115 +32,115 @@ |
||
32 | 32 | |
33 | 33 | class HookManager { |
34 | 34 | |
35 | - /** @var IUserManager */ |
|
36 | - private $userManager; |
|
37 | - |
|
38 | - /** @var SyncService */ |
|
39 | - private $syncService; |
|
40 | - |
|
41 | - /** @var IUser[] */ |
|
42 | - private $usersToDelete; |
|
43 | - |
|
44 | - /** @var CalDavBackend */ |
|
45 | - private $calDav; |
|
46 | - |
|
47 | - /** @var CardDavBackend */ |
|
48 | - private $cardDav; |
|
49 | - |
|
50 | - /** @var array */ |
|
51 | - private $calendarsToDelete; |
|
52 | - |
|
53 | - /** @var array */ |
|
54 | - private $addressBooksToDelete; |
|
55 | - |
|
56 | - /** @var EventDispatcher */ |
|
57 | - private $eventDispatcher; |
|
58 | - |
|
59 | - public function __construct(IUserManager $userManager, |
|
60 | - SyncService $syncService, |
|
61 | - CalDavBackend $calDav, |
|
62 | - CardDavBackend $cardDav, |
|
63 | - EventDispatcher $eventDispatcher) { |
|
64 | - $this->userManager = $userManager; |
|
65 | - $this->syncService = $syncService; |
|
66 | - $this->calDav = $calDav; |
|
67 | - $this->cardDav = $cardDav; |
|
68 | - $this->eventDispatcher = $eventDispatcher; |
|
69 | - } |
|
70 | - |
|
71 | - public function setup() { |
|
72 | - Util::connectHook('OC_User', |
|
73 | - 'post_createUser', |
|
74 | - $this, |
|
75 | - 'postCreateUser'); |
|
76 | - Util::connectHook('OC_User', |
|
77 | - 'pre_deleteUser', |
|
78 | - $this, |
|
79 | - 'preDeleteUser'); |
|
80 | - Util::connectHook('OC_User', |
|
81 | - 'post_deleteUser', |
|
82 | - $this, |
|
83 | - 'postDeleteUser'); |
|
84 | - Util::connectHook('OC_User', |
|
85 | - 'changeUser', |
|
86 | - $this, |
|
87 | - 'changeUser'); |
|
88 | - } |
|
89 | - |
|
90 | - public function postCreateUser($params) { |
|
91 | - $user = $this->userManager->get($params['uid']); |
|
92 | - $this->syncService->updateUser($user); |
|
93 | - } |
|
94 | - |
|
95 | - public function preDeleteUser($params) { |
|
96 | - $uid = $params['uid']; |
|
97 | - $this->usersToDelete[$uid] = $this->userManager->get($uid); |
|
98 | - $this->calendarsToDelete = $this->calDav->getUsersOwnCalendars('principals/users/' . $uid); |
|
99 | - $this->addressBooksToDelete = $this->cardDav->getUsersOwnAddressBooks('principals/users/' . $uid); |
|
100 | - } |
|
101 | - |
|
102 | - public function postDeleteUser($params) { |
|
103 | - $uid = $params['uid']; |
|
104 | - if (isset($this->usersToDelete[$uid])){ |
|
105 | - $this->syncService->deleteUser($this->usersToDelete[$uid]); |
|
106 | - } |
|
107 | - |
|
108 | - foreach ($this->calendarsToDelete as $calendar) { |
|
109 | - $this->calDav->deleteCalendar($calendar['id']); |
|
110 | - } |
|
111 | - $this->calDav->deleteAllSharesByUser('principals/users/' . $uid); |
|
112 | - |
|
113 | - foreach ($this->addressBooksToDelete as $addressBook) { |
|
114 | - $this->cardDav->deleteAddressBook($addressBook['id']); |
|
115 | - } |
|
116 | - } |
|
117 | - |
|
118 | - public function changeUser($params) { |
|
119 | - $user = $params['user']; |
|
120 | - $this->syncService->updateUser($user); |
|
121 | - } |
|
122 | - |
|
123 | - public function firstLogin(IUser $user = null) { |
|
124 | - if (!is_null($user)) { |
|
125 | - $principal = 'principals/users/' . $user->getUID(); |
|
126 | - if ($this->calDav->getCalendarsForUserCount($principal) === 0) { |
|
127 | - try { |
|
128 | - $this->calDav->createCalendar($principal, CalDavBackend::PERSONAL_CALENDAR_URI, [ |
|
129 | - '{DAV:}displayname' => CalDavBackend::PERSONAL_CALENDAR_NAME, |
|
130 | - ]); |
|
131 | - } catch (\Exception $ex) { |
|
132 | - \OC::$server->getLogger()->logException($ex); |
|
133 | - } |
|
134 | - } |
|
135 | - if ($this->cardDav->getAddressBooksForUserCount($principal) === 0) { |
|
136 | - try { |
|
137 | - $this->cardDav->createAddressBook($principal, CardDavBackend::PERSONAL_ADDRESSBOOK_URI, [ |
|
138 | - '{DAV:}displayname' => CardDavBackend::PERSONAL_ADDRESSBOOK_NAME, |
|
139 | - ]); |
|
140 | - } catch (\Exception $ex) { |
|
141 | - \OC::$server->getLogger()->logException($ex); |
|
142 | - } |
|
143 | - } |
|
144 | - } |
|
145 | - } |
|
35 | + /** @var IUserManager */ |
|
36 | + private $userManager; |
|
37 | + |
|
38 | + /** @var SyncService */ |
|
39 | + private $syncService; |
|
40 | + |
|
41 | + /** @var IUser[] */ |
|
42 | + private $usersToDelete; |
|
43 | + |
|
44 | + /** @var CalDavBackend */ |
|
45 | + private $calDav; |
|
46 | + |
|
47 | + /** @var CardDavBackend */ |
|
48 | + private $cardDav; |
|
49 | + |
|
50 | + /** @var array */ |
|
51 | + private $calendarsToDelete; |
|
52 | + |
|
53 | + /** @var array */ |
|
54 | + private $addressBooksToDelete; |
|
55 | + |
|
56 | + /** @var EventDispatcher */ |
|
57 | + private $eventDispatcher; |
|
58 | + |
|
59 | + public function __construct(IUserManager $userManager, |
|
60 | + SyncService $syncService, |
|
61 | + CalDavBackend $calDav, |
|
62 | + CardDavBackend $cardDav, |
|
63 | + EventDispatcher $eventDispatcher) { |
|
64 | + $this->userManager = $userManager; |
|
65 | + $this->syncService = $syncService; |
|
66 | + $this->calDav = $calDav; |
|
67 | + $this->cardDav = $cardDav; |
|
68 | + $this->eventDispatcher = $eventDispatcher; |
|
69 | + } |
|
70 | + |
|
71 | + public function setup() { |
|
72 | + Util::connectHook('OC_User', |
|
73 | + 'post_createUser', |
|
74 | + $this, |
|
75 | + 'postCreateUser'); |
|
76 | + Util::connectHook('OC_User', |
|
77 | + 'pre_deleteUser', |
|
78 | + $this, |
|
79 | + 'preDeleteUser'); |
|
80 | + Util::connectHook('OC_User', |
|
81 | + 'post_deleteUser', |
|
82 | + $this, |
|
83 | + 'postDeleteUser'); |
|
84 | + Util::connectHook('OC_User', |
|
85 | + 'changeUser', |
|
86 | + $this, |
|
87 | + 'changeUser'); |
|
88 | + } |
|
89 | + |
|
90 | + public function postCreateUser($params) { |
|
91 | + $user = $this->userManager->get($params['uid']); |
|
92 | + $this->syncService->updateUser($user); |
|
93 | + } |
|
94 | + |
|
95 | + public function preDeleteUser($params) { |
|
96 | + $uid = $params['uid']; |
|
97 | + $this->usersToDelete[$uid] = $this->userManager->get($uid); |
|
98 | + $this->calendarsToDelete = $this->calDav->getUsersOwnCalendars('principals/users/' . $uid); |
|
99 | + $this->addressBooksToDelete = $this->cardDav->getUsersOwnAddressBooks('principals/users/' . $uid); |
|
100 | + } |
|
101 | + |
|
102 | + public function postDeleteUser($params) { |
|
103 | + $uid = $params['uid']; |
|
104 | + if (isset($this->usersToDelete[$uid])){ |
|
105 | + $this->syncService->deleteUser($this->usersToDelete[$uid]); |
|
106 | + } |
|
107 | + |
|
108 | + foreach ($this->calendarsToDelete as $calendar) { |
|
109 | + $this->calDav->deleteCalendar($calendar['id']); |
|
110 | + } |
|
111 | + $this->calDav->deleteAllSharesByUser('principals/users/' . $uid); |
|
112 | + |
|
113 | + foreach ($this->addressBooksToDelete as $addressBook) { |
|
114 | + $this->cardDav->deleteAddressBook($addressBook['id']); |
|
115 | + } |
|
116 | + } |
|
117 | + |
|
118 | + public function changeUser($params) { |
|
119 | + $user = $params['user']; |
|
120 | + $this->syncService->updateUser($user); |
|
121 | + } |
|
122 | + |
|
123 | + public function firstLogin(IUser $user = null) { |
|
124 | + if (!is_null($user)) { |
|
125 | + $principal = 'principals/users/' . $user->getUID(); |
|
126 | + if ($this->calDav->getCalendarsForUserCount($principal) === 0) { |
|
127 | + try { |
|
128 | + $this->calDav->createCalendar($principal, CalDavBackend::PERSONAL_CALENDAR_URI, [ |
|
129 | + '{DAV:}displayname' => CalDavBackend::PERSONAL_CALENDAR_NAME, |
|
130 | + ]); |
|
131 | + } catch (\Exception $ex) { |
|
132 | + \OC::$server->getLogger()->logException($ex); |
|
133 | + } |
|
134 | + } |
|
135 | + if ($this->cardDav->getAddressBooksForUserCount($principal) === 0) { |
|
136 | + try { |
|
137 | + $this->cardDav->createAddressBook($principal, CardDavBackend::PERSONAL_ADDRESSBOOK_URI, [ |
|
138 | + '{DAV:}displayname' => CardDavBackend::PERSONAL_ADDRESSBOOK_NAME, |
|
139 | + ]); |
|
140 | + } catch (\Exception $ex) { |
|
141 | + \OC::$server->getLogger()->logException($ex); |
|
142 | + } |
|
143 | + } |
|
144 | + } |
|
145 | + } |
|
146 | 146 | } |
@@ -95,20 +95,20 @@ discard block |
||
95 | 95 | public function preDeleteUser($params) { |
96 | 96 | $uid = $params['uid']; |
97 | 97 | $this->usersToDelete[$uid] = $this->userManager->get($uid); |
98 | - $this->calendarsToDelete = $this->calDav->getUsersOwnCalendars('principals/users/' . $uid); |
|
99 | - $this->addressBooksToDelete = $this->cardDav->getUsersOwnAddressBooks('principals/users/' . $uid); |
|
98 | + $this->calendarsToDelete = $this->calDav->getUsersOwnCalendars('principals/users/'.$uid); |
|
99 | + $this->addressBooksToDelete = $this->cardDav->getUsersOwnAddressBooks('principals/users/'.$uid); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | public function postDeleteUser($params) { |
103 | 103 | $uid = $params['uid']; |
104 | - if (isset($this->usersToDelete[$uid])){ |
|
104 | + if (isset($this->usersToDelete[$uid])) { |
|
105 | 105 | $this->syncService->deleteUser($this->usersToDelete[$uid]); |
106 | 106 | } |
107 | 107 | |
108 | 108 | foreach ($this->calendarsToDelete as $calendar) { |
109 | 109 | $this->calDav->deleteCalendar($calendar['id']); |
110 | 110 | } |
111 | - $this->calDav->deleteAllSharesByUser('principals/users/' . $uid); |
|
111 | + $this->calDav->deleteAllSharesByUser('principals/users/'.$uid); |
|
112 | 112 | |
113 | 113 | foreach ($this->addressBooksToDelete as $addressBook) { |
114 | 114 | $this->cardDav->deleteAddressBook($addressBook['id']); |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | |
123 | 123 | public function firstLogin(IUser $user = null) { |
124 | 124 | if (!is_null($user)) { |
125 | - $principal = 'principals/users/' . $user->getUID(); |
|
125 | + $principal = 'principals/users/'.$user->getUID(); |
|
126 | 126 | if ($this->calDav->getCalendarsForUserCount($principal) === 0) { |
127 | 127 | try { |
128 | 128 | $this->calDav->createCalendar($principal, CalDavBackend::PERSONAL_CALENDAR_URI, [ |
@@ -110,6 +110,9 @@ |
||
110 | 110 | return parent::moveFromCache($sourceCache, $sourcePath, $targetPath); |
111 | 111 | } |
112 | 112 | |
113 | + /** |
|
114 | + * @param ICacheEntry $entry |
|
115 | + */ |
|
113 | 116 | protected function formatCacheEntry($entry) { |
114 | 117 | $path = isset($entry['path']) ? $entry['path'] : ''; |
115 | 118 | $entry = parent::formatCacheEntry($entry); |
@@ -29,7 +29,6 @@ |
||
29 | 29 | |
30 | 30 | use OC\Files\Cache\Wrapper\CacheJail; |
31 | 31 | use OCP\Files\Cache\ICacheEntry; |
32 | -use OCP\Files\Storage\IStorage; |
|
33 | 32 | |
34 | 33 | /** |
35 | 34 | * Metadata cache for shared files |
@@ -37,103 +37,103 @@ |
||
37 | 37 | * don't use this class directly if you need to get metadata, use \OC\Files\Filesystem::getFileInfo instead |
38 | 38 | */ |
39 | 39 | class Cache extends CacheJail { |
40 | - /** |
|
41 | - * @var \OCA\Files_Sharing\SharedStorage |
|
42 | - */ |
|
43 | - private $storage; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var ICacheEntry |
|
47 | - */ |
|
48 | - private $sourceRootInfo; |
|
49 | - |
|
50 | - private $rootUnchanged = true; |
|
51 | - |
|
52 | - private $ownerDisplayName; |
|
53 | - |
|
54 | - /** |
|
55 | - * @param \OCA\Files_Sharing\SharedStorage $storage |
|
56 | - * @param ICacheEntry $sourceRootInfo |
|
57 | - */ |
|
58 | - public function __construct($storage, ICacheEntry $sourceRootInfo) { |
|
59 | - $this->storage = $storage; |
|
60 | - $this->sourceRootInfo = $sourceRootInfo; |
|
61 | - parent::__construct( |
|
62 | - null, |
|
63 | - $this->sourceRootInfo->getPath() |
|
64 | - ); |
|
65 | - } |
|
66 | - |
|
67 | - public function getCache() { |
|
68 | - if (is_null($this->cache)) { |
|
69 | - $this->cache = $this->storage->getSourceStorage()->getCache(); |
|
70 | - } |
|
71 | - return $this->cache; |
|
72 | - } |
|
73 | - |
|
74 | - public function getNumericStorageId() { |
|
75 | - if (isset($this->numericId)) { |
|
76 | - return $this->numericId; |
|
77 | - } else { |
|
78 | - return false; |
|
79 | - } |
|
80 | - } |
|
81 | - |
|
82 | - public function get($file) { |
|
83 | - if ($this->rootUnchanged && ($file === '' || $file === $this->sourceRootInfo->getId())) { |
|
84 | - return $this->formatCacheEntry(clone $this->sourceRootInfo); |
|
85 | - } |
|
86 | - return parent::get($file); |
|
87 | - } |
|
88 | - |
|
89 | - public function update($id, array $data) { |
|
90 | - $this->rootUnchanged = false; |
|
91 | - parent::update($id, $data); |
|
92 | - } |
|
93 | - |
|
94 | - public function insert($file, array $data) { |
|
95 | - $this->rootUnchanged = false; |
|
96 | - return parent::insert($file, $data); |
|
97 | - } |
|
98 | - |
|
99 | - public function remove($file) { |
|
100 | - $this->rootUnchanged = false; |
|
101 | - parent::remove($file); |
|
102 | - } |
|
103 | - |
|
104 | - public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) { |
|
105 | - $this->rootUnchanged = false; |
|
106 | - return parent::moveFromCache($sourceCache, $sourcePath, $targetPath); |
|
107 | - } |
|
108 | - |
|
109 | - protected function formatCacheEntry($entry) { |
|
110 | - $path = isset($entry['path']) ? $entry['path'] : ''; |
|
111 | - $entry = parent::formatCacheEntry($entry); |
|
112 | - $sharePermissions = $this->storage->getPermissions($path); |
|
113 | - if (isset($entry['permissions'])) { |
|
114 | - $entry['permissions'] &= $sharePermissions; |
|
115 | - } else { |
|
116 | - $entry['permissions'] = $sharePermissions; |
|
117 | - } |
|
118 | - $entry['uid_owner'] = $this->storage->getOwner($path); |
|
119 | - $entry['displayname_owner'] = $this->getOwnerDisplayName(); |
|
120 | - if ($path === '') { |
|
121 | - $entry['is_share_mount_point'] = true; |
|
122 | - } |
|
123 | - return $entry; |
|
124 | - } |
|
125 | - |
|
126 | - private function getOwnerDisplayName() { |
|
127 | - if (!$this->ownerDisplayName) { |
|
128 | - $this->ownerDisplayName = \OC_User::getDisplayName($this->storage->getOwner('')); |
|
129 | - } |
|
130 | - return $this->ownerDisplayName; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * remove all entries for files that are stored on the storage from the cache |
|
135 | - */ |
|
136 | - public function clear() { |
|
137 | - // Not a valid action for Shared Cache |
|
138 | - } |
|
40 | + /** |
|
41 | + * @var \OCA\Files_Sharing\SharedStorage |
|
42 | + */ |
|
43 | + private $storage; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var ICacheEntry |
|
47 | + */ |
|
48 | + private $sourceRootInfo; |
|
49 | + |
|
50 | + private $rootUnchanged = true; |
|
51 | + |
|
52 | + private $ownerDisplayName; |
|
53 | + |
|
54 | + /** |
|
55 | + * @param \OCA\Files_Sharing\SharedStorage $storage |
|
56 | + * @param ICacheEntry $sourceRootInfo |
|
57 | + */ |
|
58 | + public function __construct($storage, ICacheEntry $sourceRootInfo) { |
|
59 | + $this->storage = $storage; |
|
60 | + $this->sourceRootInfo = $sourceRootInfo; |
|
61 | + parent::__construct( |
|
62 | + null, |
|
63 | + $this->sourceRootInfo->getPath() |
|
64 | + ); |
|
65 | + } |
|
66 | + |
|
67 | + public function getCache() { |
|
68 | + if (is_null($this->cache)) { |
|
69 | + $this->cache = $this->storage->getSourceStorage()->getCache(); |
|
70 | + } |
|
71 | + return $this->cache; |
|
72 | + } |
|
73 | + |
|
74 | + public function getNumericStorageId() { |
|
75 | + if (isset($this->numericId)) { |
|
76 | + return $this->numericId; |
|
77 | + } else { |
|
78 | + return false; |
|
79 | + } |
|
80 | + } |
|
81 | + |
|
82 | + public function get($file) { |
|
83 | + if ($this->rootUnchanged && ($file === '' || $file === $this->sourceRootInfo->getId())) { |
|
84 | + return $this->formatCacheEntry(clone $this->sourceRootInfo); |
|
85 | + } |
|
86 | + return parent::get($file); |
|
87 | + } |
|
88 | + |
|
89 | + public function update($id, array $data) { |
|
90 | + $this->rootUnchanged = false; |
|
91 | + parent::update($id, $data); |
|
92 | + } |
|
93 | + |
|
94 | + public function insert($file, array $data) { |
|
95 | + $this->rootUnchanged = false; |
|
96 | + return parent::insert($file, $data); |
|
97 | + } |
|
98 | + |
|
99 | + public function remove($file) { |
|
100 | + $this->rootUnchanged = false; |
|
101 | + parent::remove($file); |
|
102 | + } |
|
103 | + |
|
104 | + public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) { |
|
105 | + $this->rootUnchanged = false; |
|
106 | + return parent::moveFromCache($sourceCache, $sourcePath, $targetPath); |
|
107 | + } |
|
108 | + |
|
109 | + protected function formatCacheEntry($entry) { |
|
110 | + $path = isset($entry['path']) ? $entry['path'] : ''; |
|
111 | + $entry = parent::formatCacheEntry($entry); |
|
112 | + $sharePermissions = $this->storage->getPermissions($path); |
|
113 | + if (isset($entry['permissions'])) { |
|
114 | + $entry['permissions'] &= $sharePermissions; |
|
115 | + } else { |
|
116 | + $entry['permissions'] = $sharePermissions; |
|
117 | + } |
|
118 | + $entry['uid_owner'] = $this->storage->getOwner($path); |
|
119 | + $entry['displayname_owner'] = $this->getOwnerDisplayName(); |
|
120 | + if ($path === '') { |
|
121 | + $entry['is_share_mount_point'] = true; |
|
122 | + } |
|
123 | + return $entry; |
|
124 | + } |
|
125 | + |
|
126 | + private function getOwnerDisplayName() { |
|
127 | + if (!$this->ownerDisplayName) { |
|
128 | + $this->ownerDisplayName = \OC_User::getDisplayName($this->storage->getOwner('')); |
|
129 | + } |
|
130 | + return $this->ownerDisplayName; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * remove all entries for files that are stored on the storage from the cache |
|
135 | + */ |
|
136 | + public function clear() { |
|
137 | + // Not a valid action for Shared Cache |
|
138 | + } |
|
139 | 139 | } |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * |
159 | 159 | * By default this excludes the automatically generated birthday calendar |
160 | 160 | * |
161 | - * @param $principalUri |
|
161 | + * @param string $principalUri |
|
162 | 162 | * @param bool $excludeBirthday |
163 | 163 | * @return int |
164 | 164 | */ |
@@ -304,6 +304,9 @@ discard block |
||
304 | 304 | return array_values($calendars); |
305 | 305 | } |
306 | 306 | |
307 | + /** |
|
308 | + * @param string $principalUri |
|
309 | + */ |
|
307 | 310 | public function getUsersOwnCalendars($principalUri) { |
308 | 311 | $principalUri = $this->convertPrincipal($principalUri, true); |
309 | 312 | $fields = array_values($this->propertyMap); |
@@ -878,7 +881,7 @@ discard block |
||
878 | 881 | * calendar-data. If the result of a subsequent GET to this object is not |
879 | 882 | * the exact same as this request body, you should omit the ETag. |
880 | 883 | * |
881 | - * @param mixed $calendarId |
|
884 | + * @param integer $calendarId |
|
882 | 885 | * @param string $objectUri |
883 | 886 | * @param string $calendarData |
884 | 887 | * @return string |
@@ -1370,7 +1373,7 @@ discard block |
||
1370 | 1373 | * @param string $principalUri |
1371 | 1374 | * @param string $uri |
1372 | 1375 | * @param array $properties |
1373 | - * @return mixed |
|
1376 | + * @return integer |
|
1374 | 1377 | */ |
1375 | 1378 | function createSubscription($principalUri, $uri, array $properties) { |
1376 | 1379 | |
@@ -1783,6 +1786,9 @@ discard block |
||
1783 | 1786 | return $this->sharingBackend->applyShareAcl($resourceId, $acl); |
1784 | 1787 | } |
1785 | 1788 | |
1789 | + /** |
|
1790 | + * @param boolean $toV2 |
|
1791 | + */ |
|
1786 | 1792 | private function convertPrincipal($principalUri, $toV2) { |
1787 | 1793 | if ($this->principalBackend->getPrincipalPrefix() === 'principals') { |
1788 | 1794 | list(, $name) = URLUtil::splitPath($principalUri); |
@@ -59,1744 +59,1744 @@ |
||
59 | 59 | */ |
60 | 60 | class CalDavBackend extends AbstractBackend implements SyncSupport, SubscriptionSupport, SchedulingSupport { |
61 | 61 | |
62 | - const PERSONAL_CALENDAR_URI = 'personal'; |
|
63 | - const PERSONAL_CALENDAR_NAME = 'Personal'; |
|
64 | - |
|
65 | - /** |
|
66 | - * We need to specify a max date, because we need to stop *somewhere* |
|
67 | - * |
|
68 | - * On 32 bit system the maximum for a signed integer is 2147483647, so |
|
69 | - * MAX_DATE cannot be higher than date('Y-m-d', 2147483647) which results |
|
70 | - * in 2038-01-19 to avoid problems when the date is converted |
|
71 | - * to a unix timestamp. |
|
72 | - */ |
|
73 | - const MAX_DATE = '2038-01-01'; |
|
74 | - |
|
75 | - const ACCESS_PUBLIC = 4; |
|
76 | - const CLASSIFICATION_PUBLIC = 0; |
|
77 | - const CLASSIFICATION_PRIVATE = 1; |
|
78 | - const CLASSIFICATION_CONFIDENTIAL = 2; |
|
79 | - |
|
80 | - /** |
|
81 | - * List of CalDAV properties, and how they map to database field names |
|
82 | - * Add your own properties by simply adding on to this array. |
|
83 | - * |
|
84 | - * Note that only string-based properties are supported here. |
|
85 | - * |
|
86 | - * @var array |
|
87 | - */ |
|
88 | - public $propertyMap = [ |
|
89 | - '{DAV:}displayname' => 'displayname', |
|
90 | - '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'description', |
|
91 | - '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => 'timezone', |
|
92 | - '{http://apple.com/ns/ical/}calendar-order' => 'calendarorder', |
|
93 | - '{http://apple.com/ns/ical/}calendar-color' => 'calendarcolor', |
|
94 | - ]; |
|
95 | - |
|
96 | - /** |
|
97 | - * List of subscription properties, and how they map to database field names. |
|
98 | - * |
|
99 | - * @var array |
|
100 | - */ |
|
101 | - public $subscriptionPropertyMap = [ |
|
102 | - '{DAV:}displayname' => 'displayname', |
|
103 | - '{http://apple.com/ns/ical/}refreshrate' => 'refreshrate', |
|
104 | - '{http://apple.com/ns/ical/}calendar-order' => 'calendarorder', |
|
105 | - '{http://apple.com/ns/ical/}calendar-color' => 'calendarcolor', |
|
106 | - '{http://calendarserver.org/ns/}subscribed-strip-todos' => 'striptodos', |
|
107 | - '{http://calendarserver.org/ns/}subscribed-strip-alarms' => 'stripalarms', |
|
108 | - '{http://calendarserver.org/ns/}subscribed-strip-attachments' => 'stripattachments', |
|
109 | - ]; |
|
110 | - |
|
111 | - /** |
|
112 | - * @var string[] Map of uid => display name |
|
113 | - */ |
|
114 | - protected $userDisplayNames; |
|
115 | - |
|
116 | - /** @var IDBConnection */ |
|
117 | - private $db; |
|
118 | - |
|
119 | - /** @var Backend */ |
|
120 | - private $sharingBackend; |
|
121 | - |
|
122 | - /** @var Principal */ |
|
123 | - private $principalBackend; |
|
124 | - |
|
125 | - /** @var IUserManager */ |
|
126 | - private $userManager; |
|
127 | - |
|
128 | - /** @var ISecureRandom */ |
|
129 | - private $random; |
|
130 | - |
|
131 | - /** @var EventDispatcherInterface */ |
|
132 | - private $dispatcher; |
|
133 | - |
|
134 | - /** @var bool */ |
|
135 | - private $legacyEndpoint; |
|
136 | - |
|
137 | - /** |
|
138 | - * CalDavBackend constructor. |
|
139 | - * |
|
140 | - * @param IDBConnection $db |
|
141 | - * @param Principal $principalBackend |
|
142 | - * @param IUserManager $userManager |
|
143 | - * @param ISecureRandom $random |
|
144 | - * @param EventDispatcherInterface $dispatcher |
|
145 | - * @param bool $legacyEndpoint |
|
146 | - */ |
|
147 | - public function __construct(IDBConnection $db, |
|
148 | - Principal $principalBackend, |
|
149 | - IUserManager $userManager, |
|
150 | - ISecureRandom $random, |
|
151 | - EventDispatcherInterface $dispatcher, |
|
152 | - $legacyEndpoint = false) { |
|
153 | - $this->db = $db; |
|
154 | - $this->principalBackend = $principalBackend; |
|
155 | - $this->userManager = $userManager; |
|
156 | - $this->sharingBackend = new Backend($this->db, $principalBackend, 'calendar'); |
|
157 | - $this->random = $random; |
|
158 | - $this->dispatcher = $dispatcher; |
|
159 | - $this->legacyEndpoint = $legacyEndpoint; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Return the number of calendars for a principal |
|
164 | - * |
|
165 | - * By default this excludes the automatically generated birthday calendar |
|
166 | - * |
|
167 | - * @param $principalUri |
|
168 | - * @param bool $excludeBirthday |
|
169 | - * @return int |
|
170 | - */ |
|
171 | - public function getCalendarsForUserCount($principalUri, $excludeBirthday = true) { |
|
172 | - $principalUri = $this->convertPrincipal($principalUri, true); |
|
173 | - $query = $this->db->getQueryBuilder(); |
|
174 | - $query->select($query->createFunction('COUNT(*)')) |
|
175 | - ->from('calendars') |
|
176 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))); |
|
177 | - |
|
178 | - if ($excludeBirthday) { |
|
179 | - $query->andWhere($query->expr()->neq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))); |
|
180 | - } |
|
181 | - |
|
182 | - return (int)$query->execute()->fetchColumn(); |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Returns a list of calendars for a principal. |
|
187 | - * |
|
188 | - * Every project is an array with the following keys: |
|
189 | - * * id, a unique id that will be used by other functions to modify the |
|
190 | - * calendar. This can be the same as the uri or a database key. |
|
191 | - * * uri, which the basename of the uri with which the calendar is |
|
192 | - * accessed. |
|
193 | - * * principaluri. The owner of the calendar. Almost always the same as |
|
194 | - * principalUri passed to this method. |
|
195 | - * |
|
196 | - * Furthermore it can contain webdav properties in clark notation. A very |
|
197 | - * common one is '{DAV:}displayname'. |
|
198 | - * |
|
199 | - * Many clients also require: |
|
200 | - * {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set |
|
201 | - * For this property, you can just return an instance of |
|
202 | - * Sabre\CalDAV\Property\SupportedCalendarComponentSet. |
|
203 | - * |
|
204 | - * If you return {http://sabredav.org/ns}read-only and set the value to 1, |
|
205 | - * ACL will automatically be put in read-only mode. |
|
206 | - * |
|
207 | - * @param string $principalUri |
|
208 | - * @return array |
|
209 | - */ |
|
210 | - function getCalendarsForUser($principalUri) { |
|
211 | - $principalUriOriginal = $principalUri; |
|
212 | - $principalUri = $this->convertPrincipal($principalUri, true); |
|
213 | - $fields = array_values($this->propertyMap); |
|
214 | - $fields[] = 'id'; |
|
215 | - $fields[] = 'uri'; |
|
216 | - $fields[] = 'synctoken'; |
|
217 | - $fields[] = 'components'; |
|
218 | - $fields[] = 'principaluri'; |
|
219 | - $fields[] = 'transparent'; |
|
220 | - |
|
221 | - // Making fields a comma-delimited list |
|
222 | - $query = $this->db->getQueryBuilder(); |
|
223 | - $query->select($fields)->from('calendars') |
|
224 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
225 | - ->orderBy('calendarorder', 'ASC'); |
|
226 | - $stmt = $query->execute(); |
|
227 | - |
|
228 | - $calendars = []; |
|
229 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
230 | - |
|
231 | - $components = []; |
|
232 | - if ($row['components']) { |
|
233 | - $components = explode(',',$row['components']); |
|
234 | - } |
|
235 | - |
|
236 | - $calendar = [ |
|
237 | - 'id' => $row['id'], |
|
238 | - 'uri' => $row['uri'], |
|
239 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
240 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
241 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
242 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
243 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
244 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
245 | - ]; |
|
246 | - |
|
247 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
248 | - $calendar[$xmlName] = $row[$dbName]; |
|
249 | - } |
|
250 | - |
|
251 | - if (!isset($calendars[$calendar['id']])) { |
|
252 | - $calendars[$calendar['id']] = $calendar; |
|
253 | - } |
|
254 | - } |
|
255 | - |
|
256 | - $stmt->closeCursor(); |
|
257 | - |
|
258 | - // query for shared calendars |
|
259 | - $principals = $this->principalBackend->getGroupMembership($principalUriOriginal, true); |
|
260 | - $principals[]= $principalUri; |
|
261 | - |
|
262 | - $fields = array_values($this->propertyMap); |
|
263 | - $fields[] = 'a.id'; |
|
264 | - $fields[] = 'a.uri'; |
|
265 | - $fields[] = 'a.synctoken'; |
|
266 | - $fields[] = 'a.components'; |
|
267 | - $fields[] = 'a.principaluri'; |
|
268 | - $fields[] = 'a.transparent'; |
|
269 | - $fields[] = 's.access'; |
|
270 | - $query = $this->db->getQueryBuilder(); |
|
271 | - $result = $query->select($fields) |
|
272 | - ->from('dav_shares', 's') |
|
273 | - ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
274 | - ->where($query->expr()->in('s.principaluri', $query->createParameter('principaluri'))) |
|
275 | - ->andWhere($query->expr()->eq('s.type', $query->createParameter('type'))) |
|
276 | - ->setParameter('type', 'calendar') |
|
277 | - ->setParameter('principaluri', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) |
|
278 | - ->execute(); |
|
279 | - |
|
280 | - while($row = $result->fetch()) { |
|
281 | - list(, $name) = URLUtil::splitPath($row['principaluri']); |
|
282 | - $uri = $row['uri'] . '_shared_by_' . $name; |
|
283 | - $row['displayname'] = $row['displayname'] . ' (' . $this->getUserDisplayName($name) . ')'; |
|
284 | - $components = []; |
|
285 | - if ($row['components']) { |
|
286 | - $components = explode(',',$row['components']); |
|
287 | - } |
|
288 | - $calendar = [ |
|
289 | - 'id' => $row['id'], |
|
290 | - 'uri' => $uri, |
|
291 | - 'principaluri' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
292 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
293 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
294 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
295 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
296 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
297 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
298 | - ]; |
|
299 | - |
|
300 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
301 | - $calendar[$xmlName] = $row[$dbName]; |
|
302 | - } |
|
303 | - |
|
304 | - if (!isset($calendars[$calendar['id']])) { |
|
305 | - $calendars[$calendar['id']] = $calendar; |
|
306 | - } |
|
307 | - } |
|
308 | - $result->closeCursor(); |
|
309 | - |
|
310 | - return array_values($calendars); |
|
311 | - } |
|
312 | - |
|
313 | - public function getUsersOwnCalendars($principalUri) { |
|
314 | - $principalUri = $this->convertPrincipal($principalUri, true); |
|
315 | - $fields = array_values($this->propertyMap); |
|
316 | - $fields[] = 'id'; |
|
317 | - $fields[] = 'uri'; |
|
318 | - $fields[] = 'synctoken'; |
|
319 | - $fields[] = 'components'; |
|
320 | - $fields[] = 'principaluri'; |
|
321 | - $fields[] = 'transparent'; |
|
322 | - // Making fields a comma-delimited list |
|
323 | - $query = $this->db->getQueryBuilder(); |
|
324 | - $query->select($fields)->from('calendars') |
|
325 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
326 | - ->orderBy('calendarorder', 'ASC'); |
|
327 | - $stmt = $query->execute(); |
|
328 | - $calendars = []; |
|
329 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
330 | - $components = []; |
|
331 | - if ($row['components']) { |
|
332 | - $components = explode(',',$row['components']); |
|
333 | - } |
|
334 | - $calendar = [ |
|
335 | - 'id' => $row['id'], |
|
336 | - 'uri' => $row['uri'], |
|
337 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
338 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
339 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
340 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
341 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
342 | - ]; |
|
343 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
344 | - $calendar[$xmlName] = $row[$dbName]; |
|
345 | - } |
|
346 | - if (!isset($calendars[$calendar['id']])) { |
|
347 | - $calendars[$calendar['id']] = $calendar; |
|
348 | - } |
|
349 | - } |
|
350 | - $stmt->closeCursor(); |
|
351 | - return array_values($calendars); |
|
352 | - } |
|
353 | - |
|
354 | - |
|
355 | - private function getUserDisplayName($uid) { |
|
356 | - if (!isset($this->userDisplayNames[$uid])) { |
|
357 | - $user = $this->userManager->get($uid); |
|
358 | - |
|
359 | - if ($user instanceof IUser) { |
|
360 | - $this->userDisplayNames[$uid] = $user->getDisplayName(); |
|
361 | - } else { |
|
362 | - $this->userDisplayNames[$uid] = $uid; |
|
363 | - } |
|
364 | - } |
|
365 | - |
|
366 | - return $this->userDisplayNames[$uid]; |
|
367 | - } |
|
62 | + const PERSONAL_CALENDAR_URI = 'personal'; |
|
63 | + const PERSONAL_CALENDAR_NAME = 'Personal'; |
|
64 | + |
|
65 | + /** |
|
66 | + * We need to specify a max date, because we need to stop *somewhere* |
|
67 | + * |
|
68 | + * On 32 bit system the maximum for a signed integer is 2147483647, so |
|
69 | + * MAX_DATE cannot be higher than date('Y-m-d', 2147483647) which results |
|
70 | + * in 2038-01-19 to avoid problems when the date is converted |
|
71 | + * to a unix timestamp. |
|
72 | + */ |
|
73 | + const MAX_DATE = '2038-01-01'; |
|
74 | + |
|
75 | + const ACCESS_PUBLIC = 4; |
|
76 | + const CLASSIFICATION_PUBLIC = 0; |
|
77 | + const CLASSIFICATION_PRIVATE = 1; |
|
78 | + const CLASSIFICATION_CONFIDENTIAL = 2; |
|
79 | + |
|
80 | + /** |
|
81 | + * List of CalDAV properties, and how they map to database field names |
|
82 | + * Add your own properties by simply adding on to this array. |
|
83 | + * |
|
84 | + * Note that only string-based properties are supported here. |
|
85 | + * |
|
86 | + * @var array |
|
87 | + */ |
|
88 | + public $propertyMap = [ |
|
89 | + '{DAV:}displayname' => 'displayname', |
|
90 | + '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'description', |
|
91 | + '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => 'timezone', |
|
92 | + '{http://apple.com/ns/ical/}calendar-order' => 'calendarorder', |
|
93 | + '{http://apple.com/ns/ical/}calendar-color' => 'calendarcolor', |
|
94 | + ]; |
|
95 | + |
|
96 | + /** |
|
97 | + * List of subscription properties, and how they map to database field names. |
|
98 | + * |
|
99 | + * @var array |
|
100 | + */ |
|
101 | + public $subscriptionPropertyMap = [ |
|
102 | + '{DAV:}displayname' => 'displayname', |
|
103 | + '{http://apple.com/ns/ical/}refreshrate' => 'refreshrate', |
|
104 | + '{http://apple.com/ns/ical/}calendar-order' => 'calendarorder', |
|
105 | + '{http://apple.com/ns/ical/}calendar-color' => 'calendarcolor', |
|
106 | + '{http://calendarserver.org/ns/}subscribed-strip-todos' => 'striptodos', |
|
107 | + '{http://calendarserver.org/ns/}subscribed-strip-alarms' => 'stripalarms', |
|
108 | + '{http://calendarserver.org/ns/}subscribed-strip-attachments' => 'stripattachments', |
|
109 | + ]; |
|
110 | + |
|
111 | + /** |
|
112 | + * @var string[] Map of uid => display name |
|
113 | + */ |
|
114 | + protected $userDisplayNames; |
|
115 | + |
|
116 | + /** @var IDBConnection */ |
|
117 | + private $db; |
|
118 | + |
|
119 | + /** @var Backend */ |
|
120 | + private $sharingBackend; |
|
121 | + |
|
122 | + /** @var Principal */ |
|
123 | + private $principalBackend; |
|
124 | + |
|
125 | + /** @var IUserManager */ |
|
126 | + private $userManager; |
|
127 | + |
|
128 | + /** @var ISecureRandom */ |
|
129 | + private $random; |
|
130 | + |
|
131 | + /** @var EventDispatcherInterface */ |
|
132 | + private $dispatcher; |
|
133 | + |
|
134 | + /** @var bool */ |
|
135 | + private $legacyEndpoint; |
|
136 | + |
|
137 | + /** |
|
138 | + * CalDavBackend constructor. |
|
139 | + * |
|
140 | + * @param IDBConnection $db |
|
141 | + * @param Principal $principalBackend |
|
142 | + * @param IUserManager $userManager |
|
143 | + * @param ISecureRandom $random |
|
144 | + * @param EventDispatcherInterface $dispatcher |
|
145 | + * @param bool $legacyEndpoint |
|
146 | + */ |
|
147 | + public function __construct(IDBConnection $db, |
|
148 | + Principal $principalBackend, |
|
149 | + IUserManager $userManager, |
|
150 | + ISecureRandom $random, |
|
151 | + EventDispatcherInterface $dispatcher, |
|
152 | + $legacyEndpoint = false) { |
|
153 | + $this->db = $db; |
|
154 | + $this->principalBackend = $principalBackend; |
|
155 | + $this->userManager = $userManager; |
|
156 | + $this->sharingBackend = new Backend($this->db, $principalBackend, 'calendar'); |
|
157 | + $this->random = $random; |
|
158 | + $this->dispatcher = $dispatcher; |
|
159 | + $this->legacyEndpoint = $legacyEndpoint; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Return the number of calendars for a principal |
|
164 | + * |
|
165 | + * By default this excludes the automatically generated birthday calendar |
|
166 | + * |
|
167 | + * @param $principalUri |
|
168 | + * @param bool $excludeBirthday |
|
169 | + * @return int |
|
170 | + */ |
|
171 | + public function getCalendarsForUserCount($principalUri, $excludeBirthday = true) { |
|
172 | + $principalUri = $this->convertPrincipal($principalUri, true); |
|
173 | + $query = $this->db->getQueryBuilder(); |
|
174 | + $query->select($query->createFunction('COUNT(*)')) |
|
175 | + ->from('calendars') |
|
176 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))); |
|
177 | + |
|
178 | + if ($excludeBirthday) { |
|
179 | + $query->andWhere($query->expr()->neq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))); |
|
180 | + } |
|
181 | + |
|
182 | + return (int)$query->execute()->fetchColumn(); |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Returns a list of calendars for a principal. |
|
187 | + * |
|
188 | + * Every project is an array with the following keys: |
|
189 | + * * id, a unique id that will be used by other functions to modify the |
|
190 | + * calendar. This can be the same as the uri or a database key. |
|
191 | + * * uri, which the basename of the uri with which the calendar is |
|
192 | + * accessed. |
|
193 | + * * principaluri. The owner of the calendar. Almost always the same as |
|
194 | + * principalUri passed to this method. |
|
195 | + * |
|
196 | + * Furthermore it can contain webdav properties in clark notation. A very |
|
197 | + * common one is '{DAV:}displayname'. |
|
198 | + * |
|
199 | + * Many clients also require: |
|
200 | + * {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set |
|
201 | + * For this property, you can just return an instance of |
|
202 | + * Sabre\CalDAV\Property\SupportedCalendarComponentSet. |
|
203 | + * |
|
204 | + * If you return {http://sabredav.org/ns}read-only and set the value to 1, |
|
205 | + * ACL will automatically be put in read-only mode. |
|
206 | + * |
|
207 | + * @param string $principalUri |
|
208 | + * @return array |
|
209 | + */ |
|
210 | + function getCalendarsForUser($principalUri) { |
|
211 | + $principalUriOriginal = $principalUri; |
|
212 | + $principalUri = $this->convertPrincipal($principalUri, true); |
|
213 | + $fields = array_values($this->propertyMap); |
|
214 | + $fields[] = 'id'; |
|
215 | + $fields[] = 'uri'; |
|
216 | + $fields[] = 'synctoken'; |
|
217 | + $fields[] = 'components'; |
|
218 | + $fields[] = 'principaluri'; |
|
219 | + $fields[] = 'transparent'; |
|
220 | + |
|
221 | + // Making fields a comma-delimited list |
|
222 | + $query = $this->db->getQueryBuilder(); |
|
223 | + $query->select($fields)->from('calendars') |
|
224 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
225 | + ->orderBy('calendarorder', 'ASC'); |
|
226 | + $stmt = $query->execute(); |
|
227 | + |
|
228 | + $calendars = []; |
|
229 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
230 | + |
|
231 | + $components = []; |
|
232 | + if ($row['components']) { |
|
233 | + $components = explode(',',$row['components']); |
|
234 | + } |
|
235 | + |
|
236 | + $calendar = [ |
|
237 | + 'id' => $row['id'], |
|
238 | + 'uri' => $row['uri'], |
|
239 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
240 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
241 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
242 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
243 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
244 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
245 | + ]; |
|
246 | + |
|
247 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
248 | + $calendar[$xmlName] = $row[$dbName]; |
|
249 | + } |
|
250 | + |
|
251 | + if (!isset($calendars[$calendar['id']])) { |
|
252 | + $calendars[$calendar['id']] = $calendar; |
|
253 | + } |
|
254 | + } |
|
255 | + |
|
256 | + $stmt->closeCursor(); |
|
257 | + |
|
258 | + // query for shared calendars |
|
259 | + $principals = $this->principalBackend->getGroupMembership($principalUriOriginal, true); |
|
260 | + $principals[]= $principalUri; |
|
261 | + |
|
262 | + $fields = array_values($this->propertyMap); |
|
263 | + $fields[] = 'a.id'; |
|
264 | + $fields[] = 'a.uri'; |
|
265 | + $fields[] = 'a.synctoken'; |
|
266 | + $fields[] = 'a.components'; |
|
267 | + $fields[] = 'a.principaluri'; |
|
268 | + $fields[] = 'a.transparent'; |
|
269 | + $fields[] = 's.access'; |
|
270 | + $query = $this->db->getQueryBuilder(); |
|
271 | + $result = $query->select($fields) |
|
272 | + ->from('dav_shares', 's') |
|
273 | + ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
274 | + ->where($query->expr()->in('s.principaluri', $query->createParameter('principaluri'))) |
|
275 | + ->andWhere($query->expr()->eq('s.type', $query->createParameter('type'))) |
|
276 | + ->setParameter('type', 'calendar') |
|
277 | + ->setParameter('principaluri', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) |
|
278 | + ->execute(); |
|
279 | + |
|
280 | + while($row = $result->fetch()) { |
|
281 | + list(, $name) = URLUtil::splitPath($row['principaluri']); |
|
282 | + $uri = $row['uri'] . '_shared_by_' . $name; |
|
283 | + $row['displayname'] = $row['displayname'] . ' (' . $this->getUserDisplayName($name) . ')'; |
|
284 | + $components = []; |
|
285 | + if ($row['components']) { |
|
286 | + $components = explode(',',$row['components']); |
|
287 | + } |
|
288 | + $calendar = [ |
|
289 | + 'id' => $row['id'], |
|
290 | + 'uri' => $uri, |
|
291 | + 'principaluri' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
292 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
293 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
294 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
295 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
296 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
297 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
298 | + ]; |
|
299 | + |
|
300 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
301 | + $calendar[$xmlName] = $row[$dbName]; |
|
302 | + } |
|
303 | + |
|
304 | + if (!isset($calendars[$calendar['id']])) { |
|
305 | + $calendars[$calendar['id']] = $calendar; |
|
306 | + } |
|
307 | + } |
|
308 | + $result->closeCursor(); |
|
309 | + |
|
310 | + return array_values($calendars); |
|
311 | + } |
|
312 | + |
|
313 | + public function getUsersOwnCalendars($principalUri) { |
|
314 | + $principalUri = $this->convertPrincipal($principalUri, true); |
|
315 | + $fields = array_values($this->propertyMap); |
|
316 | + $fields[] = 'id'; |
|
317 | + $fields[] = 'uri'; |
|
318 | + $fields[] = 'synctoken'; |
|
319 | + $fields[] = 'components'; |
|
320 | + $fields[] = 'principaluri'; |
|
321 | + $fields[] = 'transparent'; |
|
322 | + // Making fields a comma-delimited list |
|
323 | + $query = $this->db->getQueryBuilder(); |
|
324 | + $query->select($fields)->from('calendars') |
|
325 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
326 | + ->orderBy('calendarorder', 'ASC'); |
|
327 | + $stmt = $query->execute(); |
|
328 | + $calendars = []; |
|
329 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
330 | + $components = []; |
|
331 | + if ($row['components']) { |
|
332 | + $components = explode(',',$row['components']); |
|
333 | + } |
|
334 | + $calendar = [ |
|
335 | + 'id' => $row['id'], |
|
336 | + 'uri' => $row['uri'], |
|
337 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
338 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
339 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
340 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
341 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
342 | + ]; |
|
343 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
344 | + $calendar[$xmlName] = $row[$dbName]; |
|
345 | + } |
|
346 | + if (!isset($calendars[$calendar['id']])) { |
|
347 | + $calendars[$calendar['id']] = $calendar; |
|
348 | + } |
|
349 | + } |
|
350 | + $stmt->closeCursor(); |
|
351 | + return array_values($calendars); |
|
352 | + } |
|
353 | + |
|
354 | + |
|
355 | + private function getUserDisplayName($uid) { |
|
356 | + if (!isset($this->userDisplayNames[$uid])) { |
|
357 | + $user = $this->userManager->get($uid); |
|
358 | + |
|
359 | + if ($user instanceof IUser) { |
|
360 | + $this->userDisplayNames[$uid] = $user->getDisplayName(); |
|
361 | + } else { |
|
362 | + $this->userDisplayNames[$uid] = $uid; |
|
363 | + } |
|
364 | + } |
|
365 | + |
|
366 | + return $this->userDisplayNames[$uid]; |
|
367 | + } |
|
368 | 368 | |
369 | - /** |
|
370 | - * @return array |
|
371 | - */ |
|
372 | - public function getPublicCalendars() { |
|
373 | - $fields = array_values($this->propertyMap); |
|
374 | - $fields[] = 'a.id'; |
|
375 | - $fields[] = 'a.uri'; |
|
376 | - $fields[] = 'a.synctoken'; |
|
377 | - $fields[] = 'a.components'; |
|
378 | - $fields[] = 'a.principaluri'; |
|
379 | - $fields[] = 'a.transparent'; |
|
380 | - $fields[] = 's.access'; |
|
381 | - $fields[] = 's.publicuri'; |
|
382 | - $calendars = []; |
|
383 | - $query = $this->db->getQueryBuilder(); |
|
384 | - $result = $query->select($fields) |
|
385 | - ->from('dav_shares', 's') |
|
386 | - ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
387 | - ->where($query->expr()->in('s.access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
388 | - ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
|
389 | - ->execute(); |
|
390 | - |
|
391 | - while($row = $result->fetch()) { |
|
392 | - list(, $name) = URLUtil::splitPath($row['principaluri']); |
|
393 | - $row['displayname'] = $row['displayname'] . "($name)"; |
|
394 | - $components = []; |
|
395 | - if ($row['components']) { |
|
396 | - $components = explode(',',$row['components']); |
|
397 | - } |
|
398 | - $calendar = [ |
|
399 | - 'id' => $row['id'], |
|
400 | - 'uri' => $row['publicuri'], |
|
401 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
402 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
403 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
404 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
405 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
406 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], $this->legacyEndpoint), |
|
407 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
408 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
409 | - ]; |
|
410 | - |
|
411 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
412 | - $calendar[$xmlName] = $row[$dbName]; |
|
413 | - } |
|
414 | - |
|
415 | - if (!isset($calendars[$calendar['id']])) { |
|
416 | - $calendars[$calendar['id']] = $calendar; |
|
417 | - } |
|
418 | - } |
|
419 | - $result->closeCursor(); |
|
420 | - |
|
421 | - return array_values($calendars); |
|
422 | - } |
|
423 | - |
|
424 | - /** |
|
425 | - * @param string $uri |
|
426 | - * @return array |
|
427 | - * @throws NotFound |
|
428 | - */ |
|
429 | - public function getPublicCalendar($uri) { |
|
430 | - $fields = array_values($this->propertyMap); |
|
431 | - $fields[] = 'a.id'; |
|
432 | - $fields[] = 'a.uri'; |
|
433 | - $fields[] = 'a.synctoken'; |
|
434 | - $fields[] = 'a.components'; |
|
435 | - $fields[] = 'a.principaluri'; |
|
436 | - $fields[] = 'a.transparent'; |
|
437 | - $fields[] = 's.access'; |
|
438 | - $fields[] = 's.publicuri'; |
|
439 | - $query = $this->db->getQueryBuilder(); |
|
440 | - $result = $query->select($fields) |
|
441 | - ->from('dav_shares', 's') |
|
442 | - ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
443 | - ->where($query->expr()->in('s.access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
444 | - ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
|
445 | - ->andWhere($query->expr()->eq('s.publicuri', $query->createNamedParameter($uri))) |
|
446 | - ->execute(); |
|
447 | - |
|
448 | - $row = $result->fetch(\PDO::FETCH_ASSOC); |
|
449 | - |
|
450 | - $result->closeCursor(); |
|
451 | - |
|
452 | - if ($row === false) { |
|
453 | - throw new NotFound('Node with name \'' . $uri . '\' could not be found'); |
|
454 | - } |
|
455 | - |
|
456 | - list(, $name) = URLUtil::splitPath($row['principaluri']); |
|
457 | - $row['displayname'] = $row['displayname'] . ' ' . "($name)"; |
|
458 | - $components = []; |
|
459 | - if ($row['components']) { |
|
460 | - $components = explode(',',$row['components']); |
|
461 | - } |
|
462 | - $calendar = [ |
|
463 | - 'id' => $row['id'], |
|
464 | - 'uri' => $row['publicuri'], |
|
465 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
466 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
467 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
468 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
469 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
470 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
471 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
472 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
473 | - ]; |
|
474 | - |
|
475 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
476 | - $calendar[$xmlName] = $row[$dbName]; |
|
477 | - } |
|
478 | - |
|
479 | - return $calendar; |
|
480 | - |
|
481 | - } |
|
482 | - |
|
483 | - /** |
|
484 | - * @param string $principal |
|
485 | - * @param string $uri |
|
486 | - * @return array|null |
|
487 | - */ |
|
488 | - public function getCalendarByUri($principal, $uri) { |
|
489 | - $fields = array_values($this->propertyMap); |
|
490 | - $fields[] = 'id'; |
|
491 | - $fields[] = 'uri'; |
|
492 | - $fields[] = 'synctoken'; |
|
493 | - $fields[] = 'components'; |
|
494 | - $fields[] = 'principaluri'; |
|
495 | - $fields[] = 'transparent'; |
|
496 | - |
|
497 | - // Making fields a comma-delimited list |
|
498 | - $query = $this->db->getQueryBuilder(); |
|
499 | - $query->select($fields)->from('calendars') |
|
500 | - ->where($query->expr()->eq('uri', $query->createNamedParameter($uri))) |
|
501 | - ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($principal))) |
|
502 | - ->setMaxResults(1); |
|
503 | - $stmt = $query->execute(); |
|
504 | - |
|
505 | - $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
506 | - $stmt->closeCursor(); |
|
507 | - if ($row === false) { |
|
508 | - return null; |
|
509 | - } |
|
510 | - |
|
511 | - $components = []; |
|
512 | - if ($row['components']) { |
|
513 | - $components = explode(',',$row['components']); |
|
514 | - } |
|
515 | - |
|
516 | - $calendar = [ |
|
517 | - 'id' => $row['id'], |
|
518 | - 'uri' => $row['uri'], |
|
519 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
520 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
521 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
522 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
523 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
524 | - ]; |
|
525 | - |
|
526 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
527 | - $calendar[$xmlName] = $row[$dbName]; |
|
528 | - } |
|
529 | - |
|
530 | - return $calendar; |
|
531 | - } |
|
532 | - |
|
533 | - public function getCalendarById($calendarId) { |
|
534 | - $fields = array_values($this->propertyMap); |
|
535 | - $fields[] = 'id'; |
|
536 | - $fields[] = 'uri'; |
|
537 | - $fields[] = 'synctoken'; |
|
538 | - $fields[] = 'components'; |
|
539 | - $fields[] = 'principaluri'; |
|
540 | - $fields[] = 'transparent'; |
|
541 | - |
|
542 | - // Making fields a comma-delimited list |
|
543 | - $query = $this->db->getQueryBuilder(); |
|
544 | - $query->select($fields)->from('calendars') |
|
545 | - ->where($query->expr()->eq('id', $query->createNamedParameter($calendarId))) |
|
546 | - ->setMaxResults(1); |
|
547 | - $stmt = $query->execute(); |
|
548 | - |
|
549 | - $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
550 | - $stmt->closeCursor(); |
|
551 | - if ($row === false) { |
|
552 | - return null; |
|
553 | - } |
|
554 | - |
|
555 | - $components = []; |
|
556 | - if ($row['components']) { |
|
557 | - $components = explode(',',$row['components']); |
|
558 | - } |
|
559 | - |
|
560 | - $calendar = [ |
|
561 | - 'id' => $row['id'], |
|
562 | - 'uri' => $row['uri'], |
|
563 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
564 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
565 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
566 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
567 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
568 | - ]; |
|
569 | - |
|
570 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
571 | - $calendar[$xmlName] = $row[$dbName]; |
|
572 | - } |
|
573 | - |
|
574 | - return $calendar; |
|
575 | - } |
|
576 | - |
|
577 | - /** |
|
578 | - * Creates a new calendar for a principal. |
|
579 | - * |
|
580 | - * If the creation was a success, an id must be returned that can be used to reference |
|
581 | - * this calendar in other methods, such as updateCalendar. |
|
582 | - * |
|
583 | - * @param string $principalUri |
|
584 | - * @param string $calendarUri |
|
585 | - * @param array $properties |
|
586 | - * @return int |
|
587 | - */ |
|
588 | - function createCalendar($principalUri, $calendarUri, array $properties) { |
|
589 | - $values = [ |
|
590 | - 'principaluri' => $this->convertPrincipal($principalUri, true), |
|
591 | - 'uri' => $calendarUri, |
|
592 | - 'synctoken' => 1, |
|
593 | - 'transparent' => 0, |
|
594 | - 'components' => 'VEVENT,VTODO', |
|
595 | - 'displayname' => $calendarUri |
|
596 | - ]; |
|
597 | - |
|
598 | - // Default value |
|
599 | - $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'; |
|
600 | - if (isset($properties[$sccs])) { |
|
601 | - if (!($properties[$sccs] instanceof SupportedCalendarComponentSet)) { |
|
602 | - throw new DAV\Exception('The ' . $sccs . ' property must be of type: \Sabre\CalDAV\Property\SupportedCalendarComponentSet'); |
|
603 | - } |
|
604 | - $values['components'] = implode(',',$properties[$sccs]->getValue()); |
|
605 | - } |
|
606 | - $transp = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
607 | - if (isset($properties[$transp])) { |
|
608 | - $values['transparent'] = $properties[$transp]->getValue()==='transparent'; |
|
609 | - } |
|
610 | - |
|
611 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
612 | - if (isset($properties[$xmlName])) { |
|
613 | - $values[$dbName] = $properties[$xmlName]; |
|
614 | - } |
|
615 | - } |
|
616 | - |
|
617 | - $query = $this->db->getQueryBuilder(); |
|
618 | - $query->insert('calendars'); |
|
619 | - foreach($values as $column => $value) { |
|
620 | - $query->setValue($column, $query->createNamedParameter($value)); |
|
621 | - } |
|
622 | - $query->execute(); |
|
623 | - $calendarId = $query->getLastInsertId(); |
|
624 | - |
|
625 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', new GenericEvent( |
|
626 | - '\OCA\DAV\CalDAV\CalDavBackend::createCalendar', |
|
627 | - [ |
|
628 | - 'calendarId' => $calendarId, |
|
629 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
630 | - ])); |
|
631 | - |
|
632 | - return $calendarId; |
|
633 | - } |
|
634 | - |
|
635 | - /** |
|
636 | - * Updates properties for a calendar. |
|
637 | - * |
|
638 | - * The list of mutations is stored in a Sabre\DAV\PropPatch object. |
|
639 | - * To do the actual updates, you must tell this object which properties |
|
640 | - * you're going to process with the handle() method. |
|
641 | - * |
|
642 | - * Calling the handle method is like telling the PropPatch object "I |
|
643 | - * promise I can handle updating this property". |
|
644 | - * |
|
645 | - * Read the PropPatch documentation for more info and examples. |
|
646 | - * |
|
647 | - * @param PropPatch $propPatch |
|
648 | - * @return void |
|
649 | - */ |
|
650 | - function updateCalendar($calendarId, PropPatch $propPatch) { |
|
651 | - $supportedProperties = array_keys($this->propertyMap); |
|
652 | - $supportedProperties[] = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
653 | - |
|
654 | - $propPatch->handle($supportedProperties, function($mutations) use ($calendarId) { |
|
655 | - $newValues = []; |
|
656 | - foreach ($mutations as $propertyName => $propertyValue) { |
|
657 | - |
|
658 | - switch ($propertyName) { |
|
659 | - case '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' : |
|
660 | - $fieldName = 'transparent'; |
|
661 | - $newValues[$fieldName] = $propertyValue->getValue() === 'transparent'; |
|
662 | - break; |
|
663 | - default : |
|
664 | - $fieldName = $this->propertyMap[$propertyName]; |
|
665 | - $newValues[$fieldName] = $propertyValue; |
|
666 | - break; |
|
667 | - } |
|
668 | - |
|
669 | - } |
|
670 | - $query = $this->db->getQueryBuilder(); |
|
671 | - $query->update('calendars'); |
|
672 | - foreach ($newValues as $fieldName => $value) { |
|
673 | - $query->set($fieldName, $query->createNamedParameter($value)); |
|
674 | - } |
|
675 | - $query->where($query->expr()->eq('id', $query->createNamedParameter($calendarId))); |
|
676 | - $query->execute(); |
|
677 | - |
|
678 | - $this->addChange($calendarId, "", 2); |
|
679 | - |
|
680 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', new GenericEvent( |
|
681 | - '\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', |
|
682 | - [ |
|
683 | - 'calendarId' => $calendarId, |
|
684 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
685 | - 'shares' => $this->getShares($calendarId), |
|
686 | - 'propertyMutations' => $mutations, |
|
687 | - ])); |
|
688 | - |
|
689 | - return true; |
|
690 | - }); |
|
691 | - } |
|
692 | - |
|
693 | - /** |
|
694 | - * Delete a calendar and all it's objects |
|
695 | - * |
|
696 | - * @param mixed $calendarId |
|
697 | - * @return void |
|
698 | - */ |
|
699 | - function deleteCalendar($calendarId) { |
|
700 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', new GenericEvent( |
|
701 | - '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', |
|
702 | - [ |
|
703 | - 'calendarId' => $calendarId, |
|
704 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
705 | - 'shares' => $this->getShares($calendarId), |
|
706 | - ])); |
|
707 | - |
|
708 | - $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ?'); |
|
709 | - $stmt->execute([$calendarId]); |
|
710 | - |
|
711 | - $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
712 | - $stmt->execute([$calendarId]); |
|
713 | - |
|
714 | - $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarchanges` WHERE `calendarid` = ?'); |
|
715 | - $stmt->execute([$calendarId]); |
|
716 | - |
|
717 | - $this->sharingBackend->deleteAllShares($calendarId); |
|
718 | - } |
|
719 | - |
|
720 | - /** |
|
721 | - * Delete all of an user's shares |
|
722 | - * |
|
723 | - * @param string $principaluri |
|
724 | - * @return void |
|
725 | - */ |
|
726 | - function deleteAllSharesByUser($principaluri) { |
|
727 | - $this->sharingBackend->deleteAllSharesByUser($principaluri); |
|
728 | - } |
|
729 | - |
|
730 | - /** |
|
731 | - * Returns all calendar objects within a calendar. |
|
732 | - * |
|
733 | - * Every item contains an array with the following keys: |
|
734 | - * * calendardata - The iCalendar-compatible calendar data |
|
735 | - * * uri - a unique key which will be used to construct the uri. This can |
|
736 | - * be any arbitrary string, but making sure it ends with '.ics' is a |
|
737 | - * good idea. This is only the basename, or filename, not the full |
|
738 | - * path. |
|
739 | - * * lastmodified - a timestamp of the last modification time |
|
740 | - * * etag - An arbitrary string, surrounded by double-quotes. (e.g.: |
|
741 | - * '"abcdef"') |
|
742 | - * * size - The size of the calendar objects, in bytes. |
|
743 | - * * component - optional, a string containing the type of object, such |
|
744 | - * as 'vevent' or 'vtodo'. If specified, this will be used to populate |
|
745 | - * the Content-Type header. |
|
746 | - * |
|
747 | - * Note that the etag is optional, but it's highly encouraged to return for |
|
748 | - * speed reasons. |
|
749 | - * |
|
750 | - * The calendardata is also optional. If it's not returned |
|
751 | - * 'getCalendarObject' will be called later, which *is* expected to return |
|
752 | - * calendardata. |
|
753 | - * |
|
754 | - * If neither etag or size are specified, the calendardata will be |
|
755 | - * used/fetched to determine these numbers. If both are specified the |
|
756 | - * amount of times this is needed is reduced by a great degree. |
|
757 | - * |
|
758 | - * @param mixed $calendarId |
|
759 | - * @return array |
|
760 | - */ |
|
761 | - function getCalendarObjects($calendarId) { |
|
762 | - $query = $this->db->getQueryBuilder(); |
|
763 | - $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'componenttype', 'classification']) |
|
764 | - ->from('calendarobjects') |
|
765 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
766 | - $stmt = $query->execute(); |
|
767 | - |
|
768 | - $result = []; |
|
769 | - foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
770 | - $result[] = [ |
|
771 | - 'id' => $row['id'], |
|
772 | - 'uri' => $row['uri'], |
|
773 | - 'lastmodified' => $row['lastmodified'], |
|
774 | - 'etag' => '"' . $row['etag'] . '"', |
|
775 | - 'calendarid' => $row['calendarid'], |
|
776 | - 'size' => (int)$row['size'], |
|
777 | - 'component' => strtolower($row['componenttype']), |
|
778 | - 'classification'=> (int)$row['classification'] |
|
779 | - ]; |
|
780 | - } |
|
781 | - |
|
782 | - return $result; |
|
783 | - } |
|
784 | - |
|
785 | - /** |
|
786 | - * Returns information from a single calendar object, based on it's object |
|
787 | - * uri. |
|
788 | - * |
|
789 | - * The object uri is only the basename, or filename and not a full path. |
|
790 | - * |
|
791 | - * The returned array must have the same keys as getCalendarObjects. The |
|
792 | - * 'calendardata' object is required here though, while it's not required |
|
793 | - * for getCalendarObjects. |
|
794 | - * |
|
795 | - * This method must return null if the object did not exist. |
|
796 | - * |
|
797 | - * @param mixed $calendarId |
|
798 | - * @param string $objectUri |
|
799 | - * @return array|null |
|
800 | - */ |
|
801 | - function getCalendarObject($calendarId, $objectUri) { |
|
802 | - |
|
803 | - $query = $this->db->getQueryBuilder(); |
|
804 | - $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification']) |
|
805 | - ->from('calendarobjects') |
|
806 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
807 | - ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))); |
|
808 | - $stmt = $query->execute(); |
|
809 | - $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
810 | - |
|
811 | - if(!$row) return null; |
|
812 | - |
|
813 | - return [ |
|
814 | - 'id' => $row['id'], |
|
815 | - 'uri' => $row['uri'], |
|
816 | - 'lastmodified' => $row['lastmodified'], |
|
817 | - 'etag' => '"' . $row['etag'] . '"', |
|
818 | - 'calendarid' => $row['calendarid'], |
|
819 | - 'size' => (int)$row['size'], |
|
820 | - 'calendardata' => $this->readBlob($row['calendardata']), |
|
821 | - 'component' => strtolower($row['componenttype']), |
|
822 | - 'classification'=> (int)$row['classification'] |
|
823 | - ]; |
|
824 | - } |
|
825 | - |
|
826 | - /** |
|
827 | - * Returns a list of calendar objects. |
|
828 | - * |
|
829 | - * This method should work identical to getCalendarObject, but instead |
|
830 | - * return all the calendar objects in the list as an array. |
|
831 | - * |
|
832 | - * If the backend supports this, it may allow for some speed-ups. |
|
833 | - * |
|
834 | - * @param mixed $calendarId |
|
835 | - * @param string[] $uris |
|
836 | - * @return array |
|
837 | - */ |
|
838 | - function getMultipleCalendarObjects($calendarId, array $uris) { |
|
839 | - if (empty($uris)) { |
|
840 | - return []; |
|
841 | - } |
|
842 | - |
|
843 | - $chunks = array_chunk($uris, 100); |
|
844 | - $objects = []; |
|
845 | - |
|
846 | - $query = $this->db->getQueryBuilder(); |
|
847 | - $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification']) |
|
848 | - ->from('calendarobjects') |
|
849 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
850 | - ->andWhere($query->expr()->in('uri', $query->createParameter('uri'))); |
|
851 | - |
|
852 | - foreach ($chunks as $uris) { |
|
853 | - $query->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY); |
|
854 | - $result = $query->execute(); |
|
855 | - |
|
856 | - while ($row = $result->fetch()) { |
|
857 | - $objects[] = [ |
|
858 | - 'id' => $row['id'], |
|
859 | - 'uri' => $row['uri'], |
|
860 | - 'lastmodified' => $row['lastmodified'], |
|
861 | - 'etag' => '"' . $row['etag'] . '"', |
|
862 | - 'calendarid' => $row['calendarid'], |
|
863 | - 'size' => (int)$row['size'], |
|
864 | - 'calendardata' => $this->readBlob($row['calendardata']), |
|
865 | - 'component' => strtolower($row['componenttype']), |
|
866 | - 'classification' => (int)$row['classification'] |
|
867 | - ]; |
|
868 | - } |
|
869 | - $result->closeCursor(); |
|
870 | - } |
|
871 | - return $objects; |
|
872 | - } |
|
873 | - |
|
874 | - /** |
|
875 | - * Creates a new calendar object. |
|
876 | - * |
|
877 | - * The object uri is only the basename, or filename and not a full path. |
|
878 | - * |
|
879 | - * It is possible return an etag from this function, which will be used in |
|
880 | - * the response to this PUT request. Note that the ETag must be surrounded |
|
881 | - * by double-quotes. |
|
882 | - * |
|
883 | - * However, you should only really return this ETag if you don't mangle the |
|
884 | - * calendar-data. If the result of a subsequent GET to this object is not |
|
885 | - * the exact same as this request body, you should omit the ETag. |
|
886 | - * |
|
887 | - * @param mixed $calendarId |
|
888 | - * @param string $objectUri |
|
889 | - * @param string $calendarData |
|
890 | - * @return string |
|
891 | - */ |
|
892 | - function createCalendarObject($calendarId, $objectUri, $calendarData) { |
|
893 | - $extraData = $this->getDenormalizedData($calendarData); |
|
894 | - |
|
895 | - $query = $this->db->getQueryBuilder(); |
|
896 | - $query->insert('calendarobjects') |
|
897 | - ->values([ |
|
898 | - 'calendarid' => $query->createNamedParameter($calendarId), |
|
899 | - 'uri' => $query->createNamedParameter($objectUri), |
|
900 | - 'calendardata' => $query->createNamedParameter($calendarData, IQueryBuilder::PARAM_LOB), |
|
901 | - 'lastmodified' => $query->createNamedParameter(time()), |
|
902 | - 'etag' => $query->createNamedParameter($extraData['etag']), |
|
903 | - 'size' => $query->createNamedParameter($extraData['size']), |
|
904 | - 'componenttype' => $query->createNamedParameter($extraData['componentType']), |
|
905 | - 'firstoccurence' => $query->createNamedParameter($extraData['firstOccurence']), |
|
906 | - 'lastoccurence' => $query->createNamedParameter($extraData['lastOccurence']), |
|
907 | - 'classification' => $query->createNamedParameter($extraData['classification']), |
|
908 | - 'uid' => $query->createNamedParameter($extraData['uid']), |
|
909 | - ]) |
|
910 | - ->execute(); |
|
911 | - |
|
912 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', new GenericEvent( |
|
913 | - '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', |
|
914 | - [ |
|
915 | - 'calendarId' => $calendarId, |
|
916 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
917 | - 'shares' => $this->getShares($calendarId), |
|
918 | - 'objectData' => $this->getCalendarObject($calendarId, $objectUri), |
|
919 | - ] |
|
920 | - )); |
|
921 | - $this->addChange($calendarId, $objectUri, 1); |
|
922 | - |
|
923 | - return '"' . $extraData['etag'] . '"'; |
|
924 | - } |
|
925 | - |
|
926 | - /** |
|
927 | - * Updates an existing calendarobject, based on it's uri. |
|
928 | - * |
|
929 | - * The object uri is only the basename, or filename and not a full path. |
|
930 | - * |
|
931 | - * It is possible return an etag from this function, which will be used in |
|
932 | - * the response to this PUT request. Note that the ETag must be surrounded |
|
933 | - * by double-quotes. |
|
934 | - * |
|
935 | - * However, you should only really return this ETag if you don't mangle the |
|
936 | - * calendar-data. If the result of a subsequent GET to this object is not |
|
937 | - * the exact same as this request body, you should omit the ETag. |
|
938 | - * |
|
939 | - * @param mixed $calendarId |
|
940 | - * @param string $objectUri |
|
941 | - * @param string $calendarData |
|
942 | - * @return string |
|
943 | - */ |
|
944 | - function updateCalendarObject($calendarId, $objectUri, $calendarData) { |
|
945 | - $extraData = $this->getDenormalizedData($calendarData); |
|
946 | - |
|
947 | - $query = $this->db->getQueryBuilder(); |
|
948 | - $query->update('calendarobjects') |
|
949 | - ->set('calendardata', $query->createNamedParameter($calendarData, IQueryBuilder::PARAM_LOB)) |
|
950 | - ->set('lastmodified', $query->createNamedParameter(time())) |
|
951 | - ->set('etag', $query->createNamedParameter($extraData['etag'])) |
|
952 | - ->set('size', $query->createNamedParameter($extraData['size'])) |
|
953 | - ->set('componenttype', $query->createNamedParameter($extraData['componentType'])) |
|
954 | - ->set('firstoccurence', $query->createNamedParameter($extraData['firstOccurence'])) |
|
955 | - ->set('lastoccurence', $query->createNamedParameter($extraData['lastOccurence'])) |
|
956 | - ->set('classification', $query->createNamedParameter($extraData['classification'])) |
|
957 | - ->set('uid', $query->createNamedParameter($extraData['uid'])) |
|
958 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
959 | - ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
960 | - ->execute(); |
|
961 | - |
|
962 | - $data = $this->getCalendarObject($calendarId, $objectUri); |
|
963 | - if (is_array($data)) { |
|
964 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', new GenericEvent( |
|
965 | - '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', |
|
966 | - [ |
|
967 | - 'calendarId' => $calendarId, |
|
968 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
969 | - 'shares' => $this->getShares($calendarId), |
|
970 | - 'objectData' => $data, |
|
971 | - ] |
|
972 | - )); |
|
973 | - } |
|
974 | - $this->addChange($calendarId, $objectUri, 2); |
|
975 | - |
|
976 | - return '"' . $extraData['etag'] . '"'; |
|
977 | - } |
|
978 | - |
|
979 | - /** |
|
980 | - * @param int $calendarObjectId |
|
981 | - * @param int $classification |
|
982 | - */ |
|
983 | - public function setClassification($calendarObjectId, $classification) { |
|
984 | - if (!in_array($classification, [ |
|
985 | - self::CLASSIFICATION_PUBLIC, self::CLASSIFICATION_PRIVATE, self::CLASSIFICATION_CONFIDENTIAL |
|
986 | - ])) { |
|
987 | - throw new \InvalidArgumentException(); |
|
988 | - } |
|
989 | - $query = $this->db->getQueryBuilder(); |
|
990 | - $query->update('calendarobjects') |
|
991 | - ->set('classification', $query->createNamedParameter($classification)) |
|
992 | - ->where($query->expr()->eq('id', $query->createNamedParameter($calendarObjectId))) |
|
993 | - ->execute(); |
|
994 | - } |
|
995 | - |
|
996 | - /** |
|
997 | - * Deletes an existing calendar object. |
|
998 | - * |
|
999 | - * The object uri is only the basename, or filename and not a full path. |
|
1000 | - * |
|
1001 | - * @param mixed $calendarId |
|
1002 | - * @param string $objectUri |
|
1003 | - * @return void |
|
1004 | - */ |
|
1005 | - function deleteCalendarObject($calendarId, $objectUri) { |
|
1006 | - $data = $this->getCalendarObject($calendarId, $objectUri); |
|
1007 | - if (is_array($data)) { |
|
1008 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', new GenericEvent( |
|
1009 | - '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', |
|
1010 | - [ |
|
1011 | - 'calendarId' => $calendarId, |
|
1012 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
1013 | - 'shares' => $this->getShares($calendarId), |
|
1014 | - 'objectData' => $data, |
|
1015 | - ] |
|
1016 | - )); |
|
1017 | - } |
|
1018 | - |
|
1019 | - $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ? AND `uri` = ?'); |
|
1020 | - $stmt->execute([$calendarId, $objectUri]); |
|
1021 | - |
|
1022 | - $this->addChange($calendarId, $objectUri, 3); |
|
1023 | - } |
|
1024 | - |
|
1025 | - /** |
|
1026 | - * Performs a calendar-query on the contents of this calendar. |
|
1027 | - * |
|
1028 | - * The calendar-query is defined in RFC4791 : CalDAV. Using the |
|
1029 | - * calendar-query it is possible for a client to request a specific set of |
|
1030 | - * object, based on contents of iCalendar properties, date-ranges and |
|
1031 | - * iCalendar component types (VTODO, VEVENT). |
|
1032 | - * |
|
1033 | - * This method should just return a list of (relative) urls that match this |
|
1034 | - * query. |
|
1035 | - * |
|
1036 | - * The list of filters are specified as an array. The exact array is |
|
1037 | - * documented by Sabre\CalDAV\CalendarQueryParser. |
|
1038 | - * |
|
1039 | - * Note that it is extremely likely that getCalendarObject for every path |
|
1040 | - * returned from this method will be called almost immediately after. You |
|
1041 | - * may want to anticipate this to speed up these requests. |
|
1042 | - * |
|
1043 | - * This method provides a default implementation, which parses *all* the |
|
1044 | - * iCalendar objects in the specified calendar. |
|
1045 | - * |
|
1046 | - * This default may well be good enough for personal use, and calendars |
|
1047 | - * that aren't very large. But if you anticipate high usage, big calendars |
|
1048 | - * or high loads, you are strongly advised to optimize certain paths. |
|
1049 | - * |
|
1050 | - * The best way to do so is override this method and to optimize |
|
1051 | - * specifically for 'common filters'. |
|
1052 | - * |
|
1053 | - * Requests that are extremely common are: |
|
1054 | - * * requests for just VEVENTS |
|
1055 | - * * requests for just VTODO |
|
1056 | - * * requests with a time-range-filter on either VEVENT or VTODO. |
|
1057 | - * |
|
1058 | - * ..and combinations of these requests. It may not be worth it to try to |
|
1059 | - * handle every possible situation and just rely on the (relatively |
|
1060 | - * easy to use) CalendarQueryValidator to handle the rest. |
|
1061 | - * |
|
1062 | - * Note that especially time-range-filters may be difficult to parse. A |
|
1063 | - * time-range filter specified on a VEVENT must for instance also handle |
|
1064 | - * recurrence rules correctly. |
|
1065 | - * A good example of how to interprete all these filters can also simply |
|
1066 | - * be found in Sabre\CalDAV\CalendarQueryFilter. This class is as correct |
|
1067 | - * as possible, so it gives you a good idea on what type of stuff you need |
|
1068 | - * to think of. |
|
1069 | - * |
|
1070 | - * @param mixed $calendarId |
|
1071 | - * @param array $filters |
|
1072 | - * @return array |
|
1073 | - */ |
|
1074 | - function calendarQuery($calendarId, array $filters) { |
|
1075 | - $componentType = null; |
|
1076 | - $requirePostFilter = true; |
|
1077 | - $timeRange = null; |
|
1078 | - |
|
1079 | - // if no filters were specified, we don't need to filter after a query |
|
1080 | - if (!$filters['prop-filters'] && !$filters['comp-filters']) { |
|
1081 | - $requirePostFilter = false; |
|
1082 | - } |
|
1083 | - |
|
1084 | - // Figuring out if there's a component filter |
|
1085 | - if (count($filters['comp-filters']) > 0 && !$filters['comp-filters'][0]['is-not-defined']) { |
|
1086 | - $componentType = $filters['comp-filters'][0]['name']; |
|
1087 | - |
|
1088 | - // Checking if we need post-filters |
|
1089 | - if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['time-range'] && !$filters['comp-filters'][0]['prop-filters']) { |
|
1090 | - $requirePostFilter = false; |
|
1091 | - } |
|
1092 | - // There was a time-range filter |
|
1093 | - if ($componentType == 'VEVENT' && isset($filters['comp-filters'][0]['time-range'])) { |
|
1094 | - $timeRange = $filters['comp-filters'][0]['time-range']; |
|
1095 | - |
|
1096 | - // If start time OR the end time is not specified, we can do a |
|
1097 | - // 100% accurate mysql query. |
|
1098 | - if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['prop-filters'] && (!$timeRange['start'] || !$timeRange['end'])) { |
|
1099 | - $requirePostFilter = false; |
|
1100 | - } |
|
1101 | - } |
|
1102 | - |
|
1103 | - } |
|
1104 | - $columns = ['uri']; |
|
1105 | - if ($requirePostFilter) { |
|
1106 | - $columns = ['uri', 'calendardata']; |
|
1107 | - } |
|
1108 | - $query = $this->db->getQueryBuilder(); |
|
1109 | - $query->select($columns) |
|
1110 | - ->from('calendarobjects') |
|
1111 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
1112 | - |
|
1113 | - if ($componentType) { |
|
1114 | - $query->andWhere($query->expr()->eq('componenttype', $query->createNamedParameter($componentType))); |
|
1115 | - } |
|
1116 | - |
|
1117 | - if ($timeRange && $timeRange['start']) { |
|
1118 | - $query->andWhere($query->expr()->gt('lastoccurence', $query->createNamedParameter($timeRange['start']->getTimeStamp()))); |
|
1119 | - } |
|
1120 | - if ($timeRange && $timeRange['end']) { |
|
1121 | - $query->andWhere($query->expr()->lt('firstoccurence', $query->createNamedParameter($timeRange['end']->getTimeStamp()))); |
|
1122 | - } |
|
1123 | - |
|
1124 | - $stmt = $query->execute(); |
|
1125 | - |
|
1126 | - $result = []; |
|
1127 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1128 | - if ($requirePostFilter) { |
|
1129 | - if (!$this->validateFilterForObject($row, $filters)) { |
|
1130 | - continue; |
|
1131 | - } |
|
1132 | - } |
|
1133 | - $result[] = $row['uri']; |
|
1134 | - } |
|
1135 | - |
|
1136 | - return $result; |
|
1137 | - } |
|
1138 | - |
|
1139 | - /** |
|
1140 | - * Searches through all of a users calendars and calendar objects to find |
|
1141 | - * an object with a specific UID. |
|
1142 | - * |
|
1143 | - * This method should return the path to this object, relative to the |
|
1144 | - * calendar home, so this path usually only contains two parts: |
|
1145 | - * |
|
1146 | - * calendarpath/objectpath.ics |
|
1147 | - * |
|
1148 | - * If the uid is not found, return null. |
|
1149 | - * |
|
1150 | - * This method should only consider * objects that the principal owns, so |
|
1151 | - * any calendars owned by other principals that also appear in this |
|
1152 | - * collection should be ignored. |
|
1153 | - * |
|
1154 | - * @param string $principalUri |
|
1155 | - * @param string $uid |
|
1156 | - * @return string|null |
|
1157 | - */ |
|
1158 | - function getCalendarObjectByUID($principalUri, $uid) { |
|
1159 | - |
|
1160 | - $query = $this->db->getQueryBuilder(); |
|
1161 | - $query->selectAlias('c.uri', 'calendaruri')->selectAlias('co.uri', 'objecturi') |
|
1162 | - ->from('calendarobjects', 'co') |
|
1163 | - ->leftJoin('co', 'calendars', 'c', $query->expr()->eq('co.calendarid', 'c.id')) |
|
1164 | - ->where($query->expr()->eq('c.principaluri', $query->createNamedParameter($principalUri))) |
|
1165 | - ->andWhere($query->expr()->eq('co.uid', $query->createNamedParameter($uid))); |
|
1166 | - |
|
1167 | - $stmt = $query->execute(); |
|
1168 | - |
|
1169 | - if ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1170 | - return $row['calendaruri'] . '/' . $row['objecturi']; |
|
1171 | - } |
|
1172 | - |
|
1173 | - return null; |
|
1174 | - } |
|
1175 | - |
|
1176 | - /** |
|
1177 | - * The getChanges method returns all the changes that have happened, since |
|
1178 | - * the specified syncToken in the specified calendar. |
|
1179 | - * |
|
1180 | - * This function should return an array, such as the following: |
|
1181 | - * |
|
1182 | - * [ |
|
1183 | - * 'syncToken' => 'The current synctoken', |
|
1184 | - * 'added' => [ |
|
1185 | - * 'new.txt', |
|
1186 | - * ], |
|
1187 | - * 'modified' => [ |
|
1188 | - * 'modified.txt', |
|
1189 | - * ], |
|
1190 | - * 'deleted' => [ |
|
1191 | - * 'foo.php.bak', |
|
1192 | - * 'old.txt' |
|
1193 | - * ] |
|
1194 | - * ); |
|
1195 | - * |
|
1196 | - * The returned syncToken property should reflect the *current* syncToken |
|
1197 | - * of the calendar, as reported in the {http://sabredav.org/ns}sync-token |
|
1198 | - * property This is * needed here too, to ensure the operation is atomic. |
|
1199 | - * |
|
1200 | - * If the $syncToken argument is specified as null, this is an initial |
|
1201 | - * sync, and all members should be reported. |
|
1202 | - * |
|
1203 | - * The modified property is an array of nodenames that have changed since |
|
1204 | - * the last token. |
|
1205 | - * |
|
1206 | - * The deleted property is an array with nodenames, that have been deleted |
|
1207 | - * from collection. |
|
1208 | - * |
|
1209 | - * The $syncLevel argument is basically the 'depth' of the report. If it's |
|
1210 | - * 1, you only have to report changes that happened only directly in |
|
1211 | - * immediate descendants. If it's 2, it should also include changes from |
|
1212 | - * the nodes below the child collections. (grandchildren) |
|
1213 | - * |
|
1214 | - * The $limit argument allows a client to specify how many results should |
|
1215 | - * be returned at most. If the limit is not specified, it should be treated |
|
1216 | - * as infinite. |
|
1217 | - * |
|
1218 | - * If the limit (infinite or not) is higher than you're willing to return, |
|
1219 | - * you should throw a Sabre\DAV\Exception\TooMuchMatches() exception. |
|
1220 | - * |
|
1221 | - * If the syncToken is expired (due to data cleanup) or unknown, you must |
|
1222 | - * return null. |
|
1223 | - * |
|
1224 | - * The limit is 'suggestive'. You are free to ignore it. |
|
1225 | - * |
|
1226 | - * @param string $calendarId |
|
1227 | - * @param string $syncToken |
|
1228 | - * @param int $syncLevel |
|
1229 | - * @param int $limit |
|
1230 | - * @return array |
|
1231 | - */ |
|
1232 | - function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null) { |
|
1233 | - // Current synctoken |
|
1234 | - $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
1235 | - $stmt->execute([ $calendarId ]); |
|
1236 | - $currentToken = $stmt->fetchColumn(0); |
|
1237 | - |
|
1238 | - if (is_null($currentToken)) { |
|
1239 | - return null; |
|
1240 | - } |
|
1241 | - |
|
1242 | - $result = [ |
|
1243 | - 'syncToken' => $currentToken, |
|
1244 | - 'added' => [], |
|
1245 | - 'modified' => [], |
|
1246 | - 'deleted' => [], |
|
1247 | - ]; |
|
1248 | - |
|
1249 | - if ($syncToken) { |
|
1250 | - |
|
1251 | - $query = "SELECT `uri`, `operation` FROM `*PREFIX*calendarchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `calendarid` = ? ORDER BY `synctoken`"; |
|
1252 | - if ($limit>0) { |
|
1253 | - $query.= " `LIMIT` " . (int)$limit; |
|
1254 | - } |
|
1255 | - |
|
1256 | - // Fetching all changes |
|
1257 | - $stmt = $this->db->prepare($query); |
|
1258 | - $stmt->execute([$syncToken, $currentToken, $calendarId]); |
|
1259 | - |
|
1260 | - $changes = []; |
|
1261 | - |
|
1262 | - // This loop ensures that any duplicates are overwritten, only the |
|
1263 | - // last change on a node is relevant. |
|
1264 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1265 | - |
|
1266 | - $changes[$row['uri']] = $row['operation']; |
|
1267 | - |
|
1268 | - } |
|
1269 | - |
|
1270 | - foreach($changes as $uri => $operation) { |
|
1271 | - |
|
1272 | - switch($operation) { |
|
1273 | - case 1 : |
|
1274 | - $result['added'][] = $uri; |
|
1275 | - break; |
|
1276 | - case 2 : |
|
1277 | - $result['modified'][] = $uri; |
|
1278 | - break; |
|
1279 | - case 3 : |
|
1280 | - $result['deleted'][] = $uri; |
|
1281 | - break; |
|
1282 | - } |
|
1283 | - |
|
1284 | - } |
|
1285 | - } else { |
|
1286 | - // No synctoken supplied, this is the initial sync. |
|
1287 | - $query = "SELECT `uri` FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ?"; |
|
1288 | - $stmt = $this->db->prepare($query); |
|
1289 | - $stmt->execute([$calendarId]); |
|
1290 | - |
|
1291 | - $result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN); |
|
1292 | - } |
|
1293 | - return $result; |
|
1294 | - |
|
1295 | - } |
|
1296 | - |
|
1297 | - /** |
|
1298 | - * Returns a list of subscriptions for a principal. |
|
1299 | - * |
|
1300 | - * Every subscription is an array with the following keys: |
|
1301 | - * * id, a unique id that will be used by other functions to modify the |
|
1302 | - * subscription. This can be the same as the uri or a database key. |
|
1303 | - * * uri. This is just the 'base uri' or 'filename' of the subscription. |
|
1304 | - * * principaluri. The owner of the subscription. Almost always the same as |
|
1305 | - * principalUri passed to this method. |
|
1306 | - * |
|
1307 | - * Furthermore, all the subscription info must be returned too: |
|
1308 | - * |
|
1309 | - * 1. {DAV:}displayname |
|
1310 | - * 2. {http://apple.com/ns/ical/}refreshrate |
|
1311 | - * 3. {http://calendarserver.org/ns/}subscribed-strip-todos (omit if todos |
|
1312 | - * should not be stripped). |
|
1313 | - * 4. {http://calendarserver.org/ns/}subscribed-strip-alarms (omit if alarms |
|
1314 | - * should not be stripped). |
|
1315 | - * 5. {http://calendarserver.org/ns/}subscribed-strip-attachments (omit if |
|
1316 | - * attachments should not be stripped). |
|
1317 | - * 6. {http://calendarserver.org/ns/}source (Must be a |
|
1318 | - * Sabre\DAV\Property\Href). |
|
1319 | - * 7. {http://apple.com/ns/ical/}calendar-color |
|
1320 | - * 8. {http://apple.com/ns/ical/}calendar-order |
|
1321 | - * 9. {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set |
|
1322 | - * (should just be an instance of |
|
1323 | - * Sabre\CalDAV\Property\SupportedCalendarComponentSet, with a bunch of |
|
1324 | - * default components). |
|
1325 | - * |
|
1326 | - * @param string $principalUri |
|
1327 | - * @return array |
|
1328 | - */ |
|
1329 | - function getSubscriptionsForUser($principalUri) { |
|
1330 | - $fields = array_values($this->subscriptionPropertyMap); |
|
1331 | - $fields[] = 'id'; |
|
1332 | - $fields[] = 'uri'; |
|
1333 | - $fields[] = 'source'; |
|
1334 | - $fields[] = 'principaluri'; |
|
1335 | - $fields[] = 'lastmodified'; |
|
1336 | - |
|
1337 | - $query = $this->db->getQueryBuilder(); |
|
1338 | - $query->select($fields) |
|
1339 | - ->from('calendarsubscriptions') |
|
1340 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1341 | - ->orderBy('calendarorder', 'asc'); |
|
1342 | - $stmt =$query->execute(); |
|
1343 | - |
|
1344 | - $subscriptions = []; |
|
1345 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1346 | - |
|
1347 | - $subscription = [ |
|
1348 | - 'id' => $row['id'], |
|
1349 | - 'uri' => $row['uri'], |
|
1350 | - 'principaluri' => $row['principaluri'], |
|
1351 | - 'source' => $row['source'], |
|
1352 | - 'lastmodified' => $row['lastmodified'], |
|
1353 | - |
|
1354 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']), |
|
1355 | - ]; |
|
1356 | - |
|
1357 | - foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1358 | - if (!is_null($row[$dbName])) { |
|
1359 | - $subscription[$xmlName] = $row[$dbName]; |
|
1360 | - } |
|
1361 | - } |
|
1362 | - |
|
1363 | - $subscriptions[] = $subscription; |
|
1364 | - |
|
1365 | - } |
|
1366 | - |
|
1367 | - return $subscriptions; |
|
1368 | - } |
|
1369 | - |
|
1370 | - /** |
|
1371 | - * Creates a new subscription for a principal. |
|
1372 | - * |
|
1373 | - * If the creation was a success, an id must be returned that can be used to reference |
|
1374 | - * this subscription in other methods, such as updateSubscription. |
|
1375 | - * |
|
1376 | - * @param string $principalUri |
|
1377 | - * @param string $uri |
|
1378 | - * @param array $properties |
|
1379 | - * @return mixed |
|
1380 | - */ |
|
1381 | - function createSubscription($principalUri, $uri, array $properties) { |
|
1382 | - |
|
1383 | - if (!isset($properties['{http://calendarserver.org/ns/}source'])) { |
|
1384 | - throw new Forbidden('The {http://calendarserver.org/ns/}source property is required when creating subscriptions'); |
|
1385 | - } |
|
1386 | - |
|
1387 | - $values = [ |
|
1388 | - 'principaluri' => $principalUri, |
|
1389 | - 'uri' => $uri, |
|
1390 | - 'source' => $properties['{http://calendarserver.org/ns/}source']->getHref(), |
|
1391 | - 'lastmodified' => time(), |
|
1392 | - ]; |
|
1393 | - |
|
1394 | - $propertiesBoolean = ['striptodos', 'stripalarms', 'stripattachments']; |
|
1395 | - |
|
1396 | - foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1397 | - if (array_key_exists($xmlName, $properties)) { |
|
1398 | - $values[$dbName] = $properties[$xmlName]; |
|
1399 | - if (in_array($dbName, $propertiesBoolean)) { |
|
1400 | - $values[$dbName] = true; |
|
1401 | - } |
|
1402 | - } |
|
1403 | - } |
|
1404 | - |
|
1405 | - $valuesToInsert = array(); |
|
1406 | - |
|
1407 | - $query = $this->db->getQueryBuilder(); |
|
1408 | - |
|
1409 | - foreach (array_keys($values) as $name) { |
|
1410 | - $valuesToInsert[$name] = $query->createNamedParameter($values[$name]); |
|
1411 | - } |
|
1412 | - |
|
1413 | - $query->insert('calendarsubscriptions') |
|
1414 | - ->values($valuesToInsert) |
|
1415 | - ->execute(); |
|
1416 | - |
|
1417 | - return $this->db->lastInsertId('*PREFIX*calendarsubscriptions'); |
|
1418 | - } |
|
1419 | - |
|
1420 | - /** |
|
1421 | - * Updates a subscription |
|
1422 | - * |
|
1423 | - * The list of mutations is stored in a Sabre\DAV\PropPatch object. |
|
1424 | - * To do the actual updates, you must tell this object which properties |
|
1425 | - * you're going to process with the handle() method. |
|
1426 | - * |
|
1427 | - * Calling the handle method is like telling the PropPatch object "I |
|
1428 | - * promise I can handle updating this property". |
|
1429 | - * |
|
1430 | - * Read the PropPatch documentation for more info and examples. |
|
1431 | - * |
|
1432 | - * @param mixed $subscriptionId |
|
1433 | - * @param PropPatch $propPatch |
|
1434 | - * @return void |
|
1435 | - */ |
|
1436 | - function updateSubscription($subscriptionId, PropPatch $propPatch) { |
|
1437 | - $supportedProperties = array_keys($this->subscriptionPropertyMap); |
|
1438 | - $supportedProperties[] = '{http://calendarserver.org/ns/}source'; |
|
1439 | - |
|
1440 | - $propPatch->handle($supportedProperties, function($mutations) use ($subscriptionId) { |
|
1441 | - |
|
1442 | - $newValues = []; |
|
1443 | - |
|
1444 | - foreach($mutations as $propertyName=>$propertyValue) { |
|
1445 | - if ($propertyName === '{http://calendarserver.org/ns/}source') { |
|
1446 | - $newValues['source'] = $propertyValue->getHref(); |
|
1447 | - } else { |
|
1448 | - $fieldName = $this->subscriptionPropertyMap[$propertyName]; |
|
1449 | - $newValues[$fieldName] = $propertyValue; |
|
1450 | - } |
|
1451 | - } |
|
1452 | - |
|
1453 | - $query = $this->db->getQueryBuilder(); |
|
1454 | - $query->update('calendarsubscriptions') |
|
1455 | - ->set('lastmodified', $query->createNamedParameter(time())); |
|
1456 | - foreach($newValues as $fieldName=>$value) { |
|
1457 | - $query->set($fieldName, $query->createNamedParameter($value)); |
|
1458 | - } |
|
1459 | - $query->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
|
1460 | - ->execute(); |
|
1461 | - |
|
1462 | - return true; |
|
1463 | - |
|
1464 | - }); |
|
1465 | - } |
|
1466 | - |
|
1467 | - /** |
|
1468 | - * Deletes a subscription. |
|
1469 | - * |
|
1470 | - * @param mixed $subscriptionId |
|
1471 | - * @return void |
|
1472 | - */ |
|
1473 | - function deleteSubscription($subscriptionId) { |
|
1474 | - $query = $this->db->getQueryBuilder(); |
|
1475 | - $query->delete('calendarsubscriptions') |
|
1476 | - ->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
|
1477 | - ->execute(); |
|
1478 | - } |
|
1479 | - |
|
1480 | - /** |
|
1481 | - * Returns a single scheduling object for the inbox collection. |
|
1482 | - * |
|
1483 | - * The returned array should contain the following elements: |
|
1484 | - * * uri - A unique basename for the object. This will be used to |
|
1485 | - * construct a full uri. |
|
1486 | - * * calendardata - The iCalendar object |
|
1487 | - * * lastmodified - The last modification date. Can be an int for a unix |
|
1488 | - * timestamp, or a PHP DateTime object. |
|
1489 | - * * etag - A unique token that must change if the object changed. |
|
1490 | - * * size - The size of the object, in bytes. |
|
1491 | - * |
|
1492 | - * @param string $principalUri |
|
1493 | - * @param string $objectUri |
|
1494 | - * @return array |
|
1495 | - */ |
|
1496 | - function getSchedulingObject($principalUri, $objectUri) { |
|
1497 | - $query = $this->db->getQueryBuilder(); |
|
1498 | - $stmt = $query->select(['uri', 'calendardata', 'lastmodified', 'etag', 'size']) |
|
1499 | - ->from('schedulingobjects') |
|
1500 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1501 | - ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
1502 | - ->execute(); |
|
1503 | - |
|
1504 | - $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
1505 | - |
|
1506 | - if(!$row) { |
|
1507 | - return null; |
|
1508 | - } |
|
1509 | - |
|
1510 | - return [ |
|
1511 | - 'uri' => $row['uri'], |
|
1512 | - 'calendardata' => $row['calendardata'], |
|
1513 | - 'lastmodified' => $row['lastmodified'], |
|
1514 | - 'etag' => '"' . $row['etag'] . '"', |
|
1515 | - 'size' => (int)$row['size'], |
|
1516 | - ]; |
|
1517 | - } |
|
1518 | - |
|
1519 | - /** |
|
1520 | - * Returns all scheduling objects for the inbox collection. |
|
1521 | - * |
|
1522 | - * These objects should be returned as an array. Every item in the array |
|
1523 | - * should follow the same structure as returned from getSchedulingObject. |
|
1524 | - * |
|
1525 | - * The main difference is that 'calendardata' is optional. |
|
1526 | - * |
|
1527 | - * @param string $principalUri |
|
1528 | - * @return array |
|
1529 | - */ |
|
1530 | - function getSchedulingObjects($principalUri) { |
|
1531 | - $query = $this->db->getQueryBuilder(); |
|
1532 | - $stmt = $query->select(['uri', 'calendardata', 'lastmodified', 'etag', 'size']) |
|
1533 | - ->from('schedulingobjects') |
|
1534 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1535 | - ->execute(); |
|
1536 | - |
|
1537 | - $result = []; |
|
1538 | - foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
1539 | - $result[] = [ |
|
1540 | - 'calendardata' => $row['calendardata'], |
|
1541 | - 'uri' => $row['uri'], |
|
1542 | - 'lastmodified' => $row['lastmodified'], |
|
1543 | - 'etag' => '"' . $row['etag'] . '"', |
|
1544 | - 'size' => (int)$row['size'], |
|
1545 | - ]; |
|
1546 | - } |
|
1547 | - |
|
1548 | - return $result; |
|
1549 | - } |
|
1550 | - |
|
1551 | - /** |
|
1552 | - * Deletes a scheduling object from the inbox collection. |
|
1553 | - * |
|
1554 | - * @param string $principalUri |
|
1555 | - * @param string $objectUri |
|
1556 | - * @return void |
|
1557 | - */ |
|
1558 | - function deleteSchedulingObject($principalUri, $objectUri) { |
|
1559 | - $query = $this->db->getQueryBuilder(); |
|
1560 | - $query->delete('schedulingobjects') |
|
1561 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1562 | - ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
1563 | - ->execute(); |
|
1564 | - } |
|
1565 | - |
|
1566 | - /** |
|
1567 | - * Creates a new scheduling object. This should land in a users' inbox. |
|
1568 | - * |
|
1569 | - * @param string $principalUri |
|
1570 | - * @param string $objectUri |
|
1571 | - * @param string $objectData |
|
1572 | - * @return void |
|
1573 | - */ |
|
1574 | - function createSchedulingObject($principalUri, $objectUri, $objectData) { |
|
1575 | - $query = $this->db->getQueryBuilder(); |
|
1576 | - $query->insert('schedulingobjects') |
|
1577 | - ->values([ |
|
1578 | - 'principaluri' => $query->createNamedParameter($principalUri), |
|
1579 | - 'calendardata' => $query->createNamedParameter($objectData), |
|
1580 | - 'uri' => $query->createNamedParameter($objectUri), |
|
1581 | - 'lastmodified' => $query->createNamedParameter(time()), |
|
1582 | - 'etag' => $query->createNamedParameter(md5($objectData)), |
|
1583 | - 'size' => $query->createNamedParameter(strlen($objectData)) |
|
1584 | - ]) |
|
1585 | - ->execute(); |
|
1586 | - } |
|
1587 | - |
|
1588 | - /** |
|
1589 | - * Adds a change record to the calendarchanges table. |
|
1590 | - * |
|
1591 | - * @param mixed $calendarId |
|
1592 | - * @param string $objectUri |
|
1593 | - * @param int $operation 1 = add, 2 = modify, 3 = delete. |
|
1594 | - * @return void |
|
1595 | - */ |
|
1596 | - protected function addChange($calendarId, $objectUri, $operation) { |
|
1597 | - |
|
1598 | - $stmt = $this->db->prepare('INSERT INTO `*PREFIX*calendarchanges` (`uri`, `synctoken`, `calendarid`, `operation`) SELECT ?, `synctoken`, ?, ? FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
1599 | - $stmt->execute([ |
|
1600 | - $objectUri, |
|
1601 | - $calendarId, |
|
1602 | - $operation, |
|
1603 | - $calendarId |
|
1604 | - ]); |
|
1605 | - $stmt = $this->db->prepare('UPDATE `*PREFIX*calendars` SET `synctoken` = `synctoken` + 1 WHERE `id` = ?'); |
|
1606 | - $stmt->execute([ |
|
1607 | - $calendarId |
|
1608 | - ]); |
|
1609 | - |
|
1610 | - } |
|
1611 | - |
|
1612 | - /** |
|
1613 | - * Parses some information from calendar objects, used for optimized |
|
1614 | - * calendar-queries. |
|
1615 | - * |
|
1616 | - * Returns an array with the following keys: |
|
1617 | - * * etag - An md5 checksum of the object without the quotes. |
|
1618 | - * * size - Size of the object in bytes |
|
1619 | - * * componentType - VEVENT, VTODO or VJOURNAL |
|
1620 | - * * firstOccurence |
|
1621 | - * * lastOccurence |
|
1622 | - * * uid - value of the UID property |
|
1623 | - * |
|
1624 | - * @param string $calendarData |
|
1625 | - * @return array |
|
1626 | - */ |
|
1627 | - public function getDenormalizedData($calendarData) { |
|
1628 | - |
|
1629 | - $vObject = Reader::read($calendarData); |
|
1630 | - $componentType = null; |
|
1631 | - $component = null; |
|
1632 | - $firstOccurrence = null; |
|
1633 | - $lastOccurrence = null; |
|
1634 | - $uid = null; |
|
1635 | - $classification = self::CLASSIFICATION_PUBLIC; |
|
1636 | - foreach($vObject->getComponents() as $component) { |
|
1637 | - if ($component->name!=='VTIMEZONE') { |
|
1638 | - $componentType = $component->name; |
|
1639 | - $uid = (string)$component->UID; |
|
1640 | - break; |
|
1641 | - } |
|
1642 | - } |
|
1643 | - if (!$componentType) { |
|
1644 | - throw new \Sabre\DAV\Exception\BadRequest('Calendar objects must have a VJOURNAL, VEVENT or VTODO component'); |
|
1645 | - } |
|
1646 | - if ($componentType === 'VEVENT' && $component->DTSTART) { |
|
1647 | - $firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp(); |
|
1648 | - // Finding the last occurrence is a bit harder |
|
1649 | - if (!isset($component->RRULE)) { |
|
1650 | - if (isset($component->DTEND)) { |
|
1651 | - $lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp(); |
|
1652 | - } elseif (isset($component->DURATION)) { |
|
1653 | - $endDate = clone $component->DTSTART->getDateTime(); |
|
1654 | - $endDate->add(DateTimeParser::parse($component->DURATION->getValue())); |
|
1655 | - $lastOccurrence = $endDate->getTimeStamp(); |
|
1656 | - } elseif (!$component->DTSTART->hasTime()) { |
|
1657 | - $endDate = clone $component->DTSTART->getDateTime(); |
|
1658 | - $endDate->modify('+1 day'); |
|
1659 | - $lastOccurrence = $endDate->getTimeStamp(); |
|
1660 | - } else { |
|
1661 | - $lastOccurrence = $firstOccurrence; |
|
1662 | - } |
|
1663 | - } else { |
|
1664 | - $it = new EventIterator($vObject, (string)$component->UID); |
|
1665 | - $maxDate = new \DateTime(self::MAX_DATE); |
|
1666 | - if ($it->isInfinite()) { |
|
1667 | - $lastOccurrence = $maxDate->getTimestamp(); |
|
1668 | - } else { |
|
1669 | - $end = $it->getDtEnd(); |
|
1670 | - while($it->valid() && $end < $maxDate) { |
|
1671 | - $end = $it->getDtEnd(); |
|
1672 | - $it->next(); |
|
1673 | - |
|
1674 | - } |
|
1675 | - $lastOccurrence = $end->getTimestamp(); |
|
1676 | - } |
|
1677 | - |
|
1678 | - } |
|
1679 | - } |
|
1680 | - |
|
1681 | - if ($component->CLASS) { |
|
1682 | - $classification = CalDavBackend::CLASSIFICATION_PRIVATE; |
|
1683 | - switch ($component->CLASS->getValue()) { |
|
1684 | - case 'PUBLIC': |
|
1685 | - $classification = CalDavBackend::CLASSIFICATION_PUBLIC; |
|
1686 | - break; |
|
1687 | - case 'CONFIDENTIAL': |
|
1688 | - $classification = CalDavBackend::CLASSIFICATION_CONFIDENTIAL; |
|
1689 | - break; |
|
1690 | - } |
|
1691 | - } |
|
1692 | - return [ |
|
1693 | - 'etag' => md5($calendarData), |
|
1694 | - 'size' => strlen($calendarData), |
|
1695 | - 'componentType' => $componentType, |
|
1696 | - 'firstOccurence' => is_null($firstOccurrence) ? null : max(0, $firstOccurrence), |
|
1697 | - 'lastOccurence' => $lastOccurrence, |
|
1698 | - 'uid' => $uid, |
|
1699 | - 'classification' => $classification |
|
1700 | - ]; |
|
1701 | - |
|
1702 | - } |
|
1703 | - |
|
1704 | - private function readBlob($cardData) { |
|
1705 | - if (is_resource($cardData)) { |
|
1706 | - return stream_get_contents($cardData); |
|
1707 | - } |
|
1708 | - |
|
1709 | - return $cardData; |
|
1710 | - } |
|
1711 | - |
|
1712 | - /** |
|
1713 | - * @param IShareable $shareable |
|
1714 | - * @param array $add |
|
1715 | - * @param array $remove |
|
1716 | - */ |
|
1717 | - public function updateShares($shareable, $add, $remove) { |
|
1718 | - $calendarId = $shareable->getResourceId(); |
|
1719 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateShares', new GenericEvent( |
|
1720 | - '\OCA\DAV\CalDAV\CalDavBackend::updateShares', |
|
1721 | - [ |
|
1722 | - 'calendarId' => $calendarId, |
|
1723 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
1724 | - 'shares' => $this->getShares($calendarId), |
|
1725 | - 'add' => $add, |
|
1726 | - 'remove' => $remove, |
|
1727 | - ])); |
|
1728 | - $this->sharingBackend->updateShares($shareable, $add, $remove); |
|
1729 | - } |
|
1730 | - |
|
1731 | - /** |
|
1732 | - * @param int $resourceId |
|
1733 | - * @return array |
|
1734 | - */ |
|
1735 | - public function getShares($resourceId) { |
|
1736 | - return $this->sharingBackend->getShares($resourceId); |
|
1737 | - } |
|
1738 | - |
|
1739 | - /** |
|
1740 | - * @param boolean $value |
|
1741 | - * @param \OCA\DAV\CalDAV\Calendar $calendar |
|
1742 | - * @return string|null |
|
1743 | - */ |
|
1744 | - public function setPublishStatus($value, $calendar) { |
|
1745 | - $query = $this->db->getQueryBuilder(); |
|
1746 | - if ($value) { |
|
1747 | - $publicUri = $this->random->generate(16, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS); |
|
1748 | - $query->insert('dav_shares') |
|
1749 | - ->values([ |
|
1750 | - 'principaluri' => $query->createNamedParameter($calendar->getPrincipalURI()), |
|
1751 | - 'type' => $query->createNamedParameter('calendar'), |
|
1752 | - 'access' => $query->createNamedParameter(self::ACCESS_PUBLIC), |
|
1753 | - 'resourceid' => $query->createNamedParameter($calendar->getResourceId()), |
|
1754 | - 'publicuri' => $query->createNamedParameter($publicUri) |
|
1755 | - ]); |
|
1756 | - $query->execute(); |
|
1757 | - return $publicUri; |
|
1758 | - } |
|
1759 | - $query->delete('dav_shares') |
|
1760 | - ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) |
|
1761 | - ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))); |
|
1762 | - $query->execute(); |
|
1763 | - return null; |
|
1764 | - } |
|
1765 | - |
|
1766 | - /** |
|
1767 | - * @param \OCA\DAV\CalDAV\Calendar $calendar |
|
1768 | - * @return mixed |
|
1769 | - */ |
|
1770 | - public function getPublishStatus($calendar) { |
|
1771 | - $query = $this->db->getQueryBuilder(); |
|
1772 | - $result = $query->select('publicuri') |
|
1773 | - ->from('dav_shares') |
|
1774 | - ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) |
|
1775 | - ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
1776 | - ->execute(); |
|
1777 | - |
|
1778 | - $row = $result->fetch(); |
|
1779 | - $result->closeCursor(); |
|
1780 | - return $row ? reset($row) : false; |
|
1781 | - } |
|
1782 | - |
|
1783 | - /** |
|
1784 | - * @param int $resourceId |
|
1785 | - * @param array $acl |
|
1786 | - * @return array |
|
1787 | - */ |
|
1788 | - public function applyShareAcl($resourceId, $acl) { |
|
1789 | - return $this->sharingBackend->applyShareAcl($resourceId, $acl); |
|
1790 | - } |
|
1791 | - |
|
1792 | - private function convertPrincipal($principalUri, $toV2) { |
|
1793 | - if ($this->principalBackend->getPrincipalPrefix() === 'principals') { |
|
1794 | - list(, $name) = URLUtil::splitPath($principalUri); |
|
1795 | - if ($toV2 === true) { |
|
1796 | - return "principals/users/$name"; |
|
1797 | - } |
|
1798 | - return "principals/$name"; |
|
1799 | - } |
|
1800 | - return $principalUri; |
|
1801 | - } |
|
369 | + /** |
|
370 | + * @return array |
|
371 | + */ |
|
372 | + public function getPublicCalendars() { |
|
373 | + $fields = array_values($this->propertyMap); |
|
374 | + $fields[] = 'a.id'; |
|
375 | + $fields[] = 'a.uri'; |
|
376 | + $fields[] = 'a.synctoken'; |
|
377 | + $fields[] = 'a.components'; |
|
378 | + $fields[] = 'a.principaluri'; |
|
379 | + $fields[] = 'a.transparent'; |
|
380 | + $fields[] = 's.access'; |
|
381 | + $fields[] = 's.publicuri'; |
|
382 | + $calendars = []; |
|
383 | + $query = $this->db->getQueryBuilder(); |
|
384 | + $result = $query->select($fields) |
|
385 | + ->from('dav_shares', 's') |
|
386 | + ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
387 | + ->where($query->expr()->in('s.access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
388 | + ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
|
389 | + ->execute(); |
|
390 | + |
|
391 | + while($row = $result->fetch()) { |
|
392 | + list(, $name) = URLUtil::splitPath($row['principaluri']); |
|
393 | + $row['displayname'] = $row['displayname'] . "($name)"; |
|
394 | + $components = []; |
|
395 | + if ($row['components']) { |
|
396 | + $components = explode(',',$row['components']); |
|
397 | + } |
|
398 | + $calendar = [ |
|
399 | + 'id' => $row['id'], |
|
400 | + 'uri' => $row['publicuri'], |
|
401 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
402 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
403 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
404 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
405 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
406 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], $this->legacyEndpoint), |
|
407 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
408 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
409 | + ]; |
|
410 | + |
|
411 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
412 | + $calendar[$xmlName] = $row[$dbName]; |
|
413 | + } |
|
414 | + |
|
415 | + if (!isset($calendars[$calendar['id']])) { |
|
416 | + $calendars[$calendar['id']] = $calendar; |
|
417 | + } |
|
418 | + } |
|
419 | + $result->closeCursor(); |
|
420 | + |
|
421 | + return array_values($calendars); |
|
422 | + } |
|
423 | + |
|
424 | + /** |
|
425 | + * @param string $uri |
|
426 | + * @return array |
|
427 | + * @throws NotFound |
|
428 | + */ |
|
429 | + public function getPublicCalendar($uri) { |
|
430 | + $fields = array_values($this->propertyMap); |
|
431 | + $fields[] = 'a.id'; |
|
432 | + $fields[] = 'a.uri'; |
|
433 | + $fields[] = 'a.synctoken'; |
|
434 | + $fields[] = 'a.components'; |
|
435 | + $fields[] = 'a.principaluri'; |
|
436 | + $fields[] = 'a.transparent'; |
|
437 | + $fields[] = 's.access'; |
|
438 | + $fields[] = 's.publicuri'; |
|
439 | + $query = $this->db->getQueryBuilder(); |
|
440 | + $result = $query->select($fields) |
|
441 | + ->from('dav_shares', 's') |
|
442 | + ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
443 | + ->where($query->expr()->in('s.access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
444 | + ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
|
445 | + ->andWhere($query->expr()->eq('s.publicuri', $query->createNamedParameter($uri))) |
|
446 | + ->execute(); |
|
447 | + |
|
448 | + $row = $result->fetch(\PDO::FETCH_ASSOC); |
|
449 | + |
|
450 | + $result->closeCursor(); |
|
451 | + |
|
452 | + if ($row === false) { |
|
453 | + throw new NotFound('Node with name \'' . $uri . '\' could not be found'); |
|
454 | + } |
|
455 | + |
|
456 | + list(, $name) = URLUtil::splitPath($row['principaluri']); |
|
457 | + $row['displayname'] = $row['displayname'] . ' ' . "($name)"; |
|
458 | + $components = []; |
|
459 | + if ($row['components']) { |
|
460 | + $components = explode(',',$row['components']); |
|
461 | + } |
|
462 | + $calendar = [ |
|
463 | + 'id' => $row['id'], |
|
464 | + 'uri' => $row['publicuri'], |
|
465 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
466 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
467 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
468 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
469 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
470 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
471 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
472 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
473 | + ]; |
|
474 | + |
|
475 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
476 | + $calendar[$xmlName] = $row[$dbName]; |
|
477 | + } |
|
478 | + |
|
479 | + return $calendar; |
|
480 | + |
|
481 | + } |
|
482 | + |
|
483 | + /** |
|
484 | + * @param string $principal |
|
485 | + * @param string $uri |
|
486 | + * @return array|null |
|
487 | + */ |
|
488 | + public function getCalendarByUri($principal, $uri) { |
|
489 | + $fields = array_values($this->propertyMap); |
|
490 | + $fields[] = 'id'; |
|
491 | + $fields[] = 'uri'; |
|
492 | + $fields[] = 'synctoken'; |
|
493 | + $fields[] = 'components'; |
|
494 | + $fields[] = 'principaluri'; |
|
495 | + $fields[] = 'transparent'; |
|
496 | + |
|
497 | + // Making fields a comma-delimited list |
|
498 | + $query = $this->db->getQueryBuilder(); |
|
499 | + $query->select($fields)->from('calendars') |
|
500 | + ->where($query->expr()->eq('uri', $query->createNamedParameter($uri))) |
|
501 | + ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($principal))) |
|
502 | + ->setMaxResults(1); |
|
503 | + $stmt = $query->execute(); |
|
504 | + |
|
505 | + $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
506 | + $stmt->closeCursor(); |
|
507 | + if ($row === false) { |
|
508 | + return null; |
|
509 | + } |
|
510 | + |
|
511 | + $components = []; |
|
512 | + if ($row['components']) { |
|
513 | + $components = explode(',',$row['components']); |
|
514 | + } |
|
515 | + |
|
516 | + $calendar = [ |
|
517 | + 'id' => $row['id'], |
|
518 | + 'uri' => $row['uri'], |
|
519 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
520 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
521 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
522 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
523 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
524 | + ]; |
|
525 | + |
|
526 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
527 | + $calendar[$xmlName] = $row[$dbName]; |
|
528 | + } |
|
529 | + |
|
530 | + return $calendar; |
|
531 | + } |
|
532 | + |
|
533 | + public function getCalendarById($calendarId) { |
|
534 | + $fields = array_values($this->propertyMap); |
|
535 | + $fields[] = 'id'; |
|
536 | + $fields[] = 'uri'; |
|
537 | + $fields[] = 'synctoken'; |
|
538 | + $fields[] = 'components'; |
|
539 | + $fields[] = 'principaluri'; |
|
540 | + $fields[] = 'transparent'; |
|
541 | + |
|
542 | + // Making fields a comma-delimited list |
|
543 | + $query = $this->db->getQueryBuilder(); |
|
544 | + $query->select($fields)->from('calendars') |
|
545 | + ->where($query->expr()->eq('id', $query->createNamedParameter($calendarId))) |
|
546 | + ->setMaxResults(1); |
|
547 | + $stmt = $query->execute(); |
|
548 | + |
|
549 | + $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
550 | + $stmt->closeCursor(); |
|
551 | + if ($row === false) { |
|
552 | + return null; |
|
553 | + } |
|
554 | + |
|
555 | + $components = []; |
|
556 | + if ($row['components']) { |
|
557 | + $components = explode(',',$row['components']); |
|
558 | + } |
|
559 | + |
|
560 | + $calendar = [ |
|
561 | + 'id' => $row['id'], |
|
562 | + 'uri' => $row['uri'], |
|
563 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
564 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
565 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
566 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
567 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
568 | + ]; |
|
569 | + |
|
570 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
571 | + $calendar[$xmlName] = $row[$dbName]; |
|
572 | + } |
|
573 | + |
|
574 | + return $calendar; |
|
575 | + } |
|
576 | + |
|
577 | + /** |
|
578 | + * Creates a new calendar for a principal. |
|
579 | + * |
|
580 | + * If the creation was a success, an id must be returned that can be used to reference |
|
581 | + * this calendar in other methods, such as updateCalendar. |
|
582 | + * |
|
583 | + * @param string $principalUri |
|
584 | + * @param string $calendarUri |
|
585 | + * @param array $properties |
|
586 | + * @return int |
|
587 | + */ |
|
588 | + function createCalendar($principalUri, $calendarUri, array $properties) { |
|
589 | + $values = [ |
|
590 | + 'principaluri' => $this->convertPrincipal($principalUri, true), |
|
591 | + 'uri' => $calendarUri, |
|
592 | + 'synctoken' => 1, |
|
593 | + 'transparent' => 0, |
|
594 | + 'components' => 'VEVENT,VTODO', |
|
595 | + 'displayname' => $calendarUri |
|
596 | + ]; |
|
597 | + |
|
598 | + // Default value |
|
599 | + $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'; |
|
600 | + if (isset($properties[$sccs])) { |
|
601 | + if (!($properties[$sccs] instanceof SupportedCalendarComponentSet)) { |
|
602 | + throw new DAV\Exception('The ' . $sccs . ' property must be of type: \Sabre\CalDAV\Property\SupportedCalendarComponentSet'); |
|
603 | + } |
|
604 | + $values['components'] = implode(',',$properties[$sccs]->getValue()); |
|
605 | + } |
|
606 | + $transp = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
607 | + if (isset($properties[$transp])) { |
|
608 | + $values['transparent'] = $properties[$transp]->getValue()==='transparent'; |
|
609 | + } |
|
610 | + |
|
611 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
612 | + if (isset($properties[$xmlName])) { |
|
613 | + $values[$dbName] = $properties[$xmlName]; |
|
614 | + } |
|
615 | + } |
|
616 | + |
|
617 | + $query = $this->db->getQueryBuilder(); |
|
618 | + $query->insert('calendars'); |
|
619 | + foreach($values as $column => $value) { |
|
620 | + $query->setValue($column, $query->createNamedParameter($value)); |
|
621 | + } |
|
622 | + $query->execute(); |
|
623 | + $calendarId = $query->getLastInsertId(); |
|
624 | + |
|
625 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', new GenericEvent( |
|
626 | + '\OCA\DAV\CalDAV\CalDavBackend::createCalendar', |
|
627 | + [ |
|
628 | + 'calendarId' => $calendarId, |
|
629 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
630 | + ])); |
|
631 | + |
|
632 | + return $calendarId; |
|
633 | + } |
|
634 | + |
|
635 | + /** |
|
636 | + * Updates properties for a calendar. |
|
637 | + * |
|
638 | + * The list of mutations is stored in a Sabre\DAV\PropPatch object. |
|
639 | + * To do the actual updates, you must tell this object which properties |
|
640 | + * you're going to process with the handle() method. |
|
641 | + * |
|
642 | + * Calling the handle method is like telling the PropPatch object "I |
|
643 | + * promise I can handle updating this property". |
|
644 | + * |
|
645 | + * Read the PropPatch documentation for more info and examples. |
|
646 | + * |
|
647 | + * @param PropPatch $propPatch |
|
648 | + * @return void |
|
649 | + */ |
|
650 | + function updateCalendar($calendarId, PropPatch $propPatch) { |
|
651 | + $supportedProperties = array_keys($this->propertyMap); |
|
652 | + $supportedProperties[] = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
653 | + |
|
654 | + $propPatch->handle($supportedProperties, function($mutations) use ($calendarId) { |
|
655 | + $newValues = []; |
|
656 | + foreach ($mutations as $propertyName => $propertyValue) { |
|
657 | + |
|
658 | + switch ($propertyName) { |
|
659 | + case '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' : |
|
660 | + $fieldName = 'transparent'; |
|
661 | + $newValues[$fieldName] = $propertyValue->getValue() === 'transparent'; |
|
662 | + break; |
|
663 | + default : |
|
664 | + $fieldName = $this->propertyMap[$propertyName]; |
|
665 | + $newValues[$fieldName] = $propertyValue; |
|
666 | + break; |
|
667 | + } |
|
668 | + |
|
669 | + } |
|
670 | + $query = $this->db->getQueryBuilder(); |
|
671 | + $query->update('calendars'); |
|
672 | + foreach ($newValues as $fieldName => $value) { |
|
673 | + $query->set($fieldName, $query->createNamedParameter($value)); |
|
674 | + } |
|
675 | + $query->where($query->expr()->eq('id', $query->createNamedParameter($calendarId))); |
|
676 | + $query->execute(); |
|
677 | + |
|
678 | + $this->addChange($calendarId, "", 2); |
|
679 | + |
|
680 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', new GenericEvent( |
|
681 | + '\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', |
|
682 | + [ |
|
683 | + 'calendarId' => $calendarId, |
|
684 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
685 | + 'shares' => $this->getShares($calendarId), |
|
686 | + 'propertyMutations' => $mutations, |
|
687 | + ])); |
|
688 | + |
|
689 | + return true; |
|
690 | + }); |
|
691 | + } |
|
692 | + |
|
693 | + /** |
|
694 | + * Delete a calendar and all it's objects |
|
695 | + * |
|
696 | + * @param mixed $calendarId |
|
697 | + * @return void |
|
698 | + */ |
|
699 | + function deleteCalendar($calendarId) { |
|
700 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', new GenericEvent( |
|
701 | + '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', |
|
702 | + [ |
|
703 | + 'calendarId' => $calendarId, |
|
704 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
705 | + 'shares' => $this->getShares($calendarId), |
|
706 | + ])); |
|
707 | + |
|
708 | + $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ?'); |
|
709 | + $stmt->execute([$calendarId]); |
|
710 | + |
|
711 | + $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
712 | + $stmt->execute([$calendarId]); |
|
713 | + |
|
714 | + $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarchanges` WHERE `calendarid` = ?'); |
|
715 | + $stmt->execute([$calendarId]); |
|
716 | + |
|
717 | + $this->sharingBackend->deleteAllShares($calendarId); |
|
718 | + } |
|
719 | + |
|
720 | + /** |
|
721 | + * Delete all of an user's shares |
|
722 | + * |
|
723 | + * @param string $principaluri |
|
724 | + * @return void |
|
725 | + */ |
|
726 | + function deleteAllSharesByUser($principaluri) { |
|
727 | + $this->sharingBackend->deleteAllSharesByUser($principaluri); |
|
728 | + } |
|
729 | + |
|
730 | + /** |
|
731 | + * Returns all calendar objects within a calendar. |
|
732 | + * |
|
733 | + * Every item contains an array with the following keys: |
|
734 | + * * calendardata - The iCalendar-compatible calendar data |
|
735 | + * * uri - a unique key which will be used to construct the uri. This can |
|
736 | + * be any arbitrary string, but making sure it ends with '.ics' is a |
|
737 | + * good idea. This is only the basename, or filename, not the full |
|
738 | + * path. |
|
739 | + * * lastmodified - a timestamp of the last modification time |
|
740 | + * * etag - An arbitrary string, surrounded by double-quotes. (e.g.: |
|
741 | + * '"abcdef"') |
|
742 | + * * size - The size of the calendar objects, in bytes. |
|
743 | + * * component - optional, a string containing the type of object, such |
|
744 | + * as 'vevent' or 'vtodo'. If specified, this will be used to populate |
|
745 | + * the Content-Type header. |
|
746 | + * |
|
747 | + * Note that the etag is optional, but it's highly encouraged to return for |
|
748 | + * speed reasons. |
|
749 | + * |
|
750 | + * The calendardata is also optional. If it's not returned |
|
751 | + * 'getCalendarObject' will be called later, which *is* expected to return |
|
752 | + * calendardata. |
|
753 | + * |
|
754 | + * If neither etag or size are specified, the calendardata will be |
|
755 | + * used/fetched to determine these numbers. If both are specified the |
|
756 | + * amount of times this is needed is reduced by a great degree. |
|
757 | + * |
|
758 | + * @param mixed $calendarId |
|
759 | + * @return array |
|
760 | + */ |
|
761 | + function getCalendarObjects($calendarId) { |
|
762 | + $query = $this->db->getQueryBuilder(); |
|
763 | + $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'componenttype', 'classification']) |
|
764 | + ->from('calendarobjects') |
|
765 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
766 | + $stmt = $query->execute(); |
|
767 | + |
|
768 | + $result = []; |
|
769 | + foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
770 | + $result[] = [ |
|
771 | + 'id' => $row['id'], |
|
772 | + 'uri' => $row['uri'], |
|
773 | + 'lastmodified' => $row['lastmodified'], |
|
774 | + 'etag' => '"' . $row['etag'] . '"', |
|
775 | + 'calendarid' => $row['calendarid'], |
|
776 | + 'size' => (int)$row['size'], |
|
777 | + 'component' => strtolower($row['componenttype']), |
|
778 | + 'classification'=> (int)$row['classification'] |
|
779 | + ]; |
|
780 | + } |
|
781 | + |
|
782 | + return $result; |
|
783 | + } |
|
784 | + |
|
785 | + /** |
|
786 | + * Returns information from a single calendar object, based on it's object |
|
787 | + * uri. |
|
788 | + * |
|
789 | + * The object uri is only the basename, or filename and not a full path. |
|
790 | + * |
|
791 | + * The returned array must have the same keys as getCalendarObjects. The |
|
792 | + * 'calendardata' object is required here though, while it's not required |
|
793 | + * for getCalendarObjects. |
|
794 | + * |
|
795 | + * This method must return null if the object did not exist. |
|
796 | + * |
|
797 | + * @param mixed $calendarId |
|
798 | + * @param string $objectUri |
|
799 | + * @return array|null |
|
800 | + */ |
|
801 | + function getCalendarObject($calendarId, $objectUri) { |
|
802 | + |
|
803 | + $query = $this->db->getQueryBuilder(); |
|
804 | + $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification']) |
|
805 | + ->from('calendarobjects') |
|
806 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
807 | + ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))); |
|
808 | + $stmt = $query->execute(); |
|
809 | + $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
810 | + |
|
811 | + if(!$row) return null; |
|
812 | + |
|
813 | + return [ |
|
814 | + 'id' => $row['id'], |
|
815 | + 'uri' => $row['uri'], |
|
816 | + 'lastmodified' => $row['lastmodified'], |
|
817 | + 'etag' => '"' . $row['etag'] . '"', |
|
818 | + 'calendarid' => $row['calendarid'], |
|
819 | + 'size' => (int)$row['size'], |
|
820 | + 'calendardata' => $this->readBlob($row['calendardata']), |
|
821 | + 'component' => strtolower($row['componenttype']), |
|
822 | + 'classification'=> (int)$row['classification'] |
|
823 | + ]; |
|
824 | + } |
|
825 | + |
|
826 | + /** |
|
827 | + * Returns a list of calendar objects. |
|
828 | + * |
|
829 | + * This method should work identical to getCalendarObject, but instead |
|
830 | + * return all the calendar objects in the list as an array. |
|
831 | + * |
|
832 | + * If the backend supports this, it may allow for some speed-ups. |
|
833 | + * |
|
834 | + * @param mixed $calendarId |
|
835 | + * @param string[] $uris |
|
836 | + * @return array |
|
837 | + */ |
|
838 | + function getMultipleCalendarObjects($calendarId, array $uris) { |
|
839 | + if (empty($uris)) { |
|
840 | + return []; |
|
841 | + } |
|
842 | + |
|
843 | + $chunks = array_chunk($uris, 100); |
|
844 | + $objects = []; |
|
845 | + |
|
846 | + $query = $this->db->getQueryBuilder(); |
|
847 | + $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification']) |
|
848 | + ->from('calendarobjects') |
|
849 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
850 | + ->andWhere($query->expr()->in('uri', $query->createParameter('uri'))); |
|
851 | + |
|
852 | + foreach ($chunks as $uris) { |
|
853 | + $query->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY); |
|
854 | + $result = $query->execute(); |
|
855 | + |
|
856 | + while ($row = $result->fetch()) { |
|
857 | + $objects[] = [ |
|
858 | + 'id' => $row['id'], |
|
859 | + 'uri' => $row['uri'], |
|
860 | + 'lastmodified' => $row['lastmodified'], |
|
861 | + 'etag' => '"' . $row['etag'] . '"', |
|
862 | + 'calendarid' => $row['calendarid'], |
|
863 | + 'size' => (int)$row['size'], |
|
864 | + 'calendardata' => $this->readBlob($row['calendardata']), |
|
865 | + 'component' => strtolower($row['componenttype']), |
|
866 | + 'classification' => (int)$row['classification'] |
|
867 | + ]; |
|
868 | + } |
|
869 | + $result->closeCursor(); |
|
870 | + } |
|
871 | + return $objects; |
|
872 | + } |
|
873 | + |
|
874 | + /** |
|
875 | + * Creates a new calendar object. |
|
876 | + * |
|
877 | + * The object uri is only the basename, or filename and not a full path. |
|
878 | + * |
|
879 | + * It is possible return an etag from this function, which will be used in |
|
880 | + * the response to this PUT request. Note that the ETag must be surrounded |
|
881 | + * by double-quotes. |
|
882 | + * |
|
883 | + * However, you should only really return this ETag if you don't mangle the |
|
884 | + * calendar-data. If the result of a subsequent GET to this object is not |
|
885 | + * the exact same as this request body, you should omit the ETag. |
|
886 | + * |
|
887 | + * @param mixed $calendarId |
|
888 | + * @param string $objectUri |
|
889 | + * @param string $calendarData |
|
890 | + * @return string |
|
891 | + */ |
|
892 | + function createCalendarObject($calendarId, $objectUri, $calendarData) { |
|
893 | + $extraData = $this->getDenormalizedData($calendarData); |
|
894 | + |
|
895 | + $query = $this->db->getQueryBuilder(); |
|
896 | + $query->insert('calendarobjects') |
|
897 | + ->values([ |
|
898 | + 'calendarid' => $query->createNamedParameter($calendarId), |
|
899 | + 'uri' => $query->createNamedParameter($objectUri), |
|
900 | + 'calendardata' => $query->createNamedParameter($calendarData, IQueryBuilder::PARAM_LOB), |
|
901 | + 'lastmodified' => $query->createNamedParameter(time()), |
|
902 | + 'etag' => $query->createNamedParameter($extraData['etag']), |
|
903 | + 'size' => $query->createNamedParameter($extraData['size']), |
|
904 | + 'componenttype' => $query->createNamedParameter($extraData['componentType']), |
|
905 | + 'firstoccurence' => $query->createNamedParameter($extraData['firstOccurence']), |
|
906 | + 'lastoccurence' => $query->createNamedParameter($extraData['lastOccurence']), |
|
907 | + 'classification' => $query->createNamedParameter($extraData['classification']), |
|
908 | + 'uid' => $query->createNamedParameter($extraData['uid']), |
|
909 | + ]) |
|
910 | + ->execute(); |
|
911 | + |
|
912 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', new GenericEvent( |
|
913 | + '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', |
|
914 | + [ |
|
915 | + 'calendarId' => $calendarId, |
|
916 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
917 | + 'shares' => $this->getShares($calendarId), |
|
918 | + 'objectData' => $this->getCalendarObject($calendarId, $objectUri), |
|
919 | + ] |
|
920 | + )); |
|
921 | + $this->addChange($calendarId, $objectUri, 1); |
|
922 | + |
|
923 | + return '"' . $extraData['etag'] . '"'; |
|
924 | + } |
|
925 | + |
|
926 | + /** |
|
927 | + * Updates an existing calendarobject, based on it's uri. |
|
928 | + * |
|
929 | + * The object uri is only the basename, or filename and not a full path. |
|
930 | + * |
|
931 | + * It is possible return an etag from this function, which will be used in |
|
932 | + * the response to this PUT request. Note that the ETag must be surrounded |
|
933 | + * by double-quotes. |
|
934 | + * |
|
935 | + * However, you should only really return this ETag if you don't mangle the |
|
936 | + * calendar-data. If the result of a subsequent GET to this object is not |
|
937 | + * the exact same as this request body, you should omit the ETag. |
|
938 | + * |
|
939 | + * @param mixed $calendarId |
|
940 | + * @param string $objectUri |
|
941 | + * @param string $calendarData |
|
942 | + * @return string |
|
943 | + */ |
|
944 | + function updateCalendarObject($calendarId, $objectUri, $calendarData) { |
|
945 | + $extraData = $this->getDenormalizedData($calendarData); |
|
946 | + |
|
947 | + $query = $this->db->getQueryBuilder(); |
|
948 | + $query->update('calendarobjects') |
|
949 | + ->set('calendardata', $query->createNamedParameter($calendarData, IQueryBuilder::PARAM_LOB)) |
|
950 | + ->set('lastmodified', $query->createNamedParameter(time())) |
|
951 | + ->set('etag', $query->createNamedParameter($extraData['etag'])) |
|
952 | + ->set('size', $query->createNamedParameter($extraData['size'])) |
|
953 | + ->set('componenttype', $query->createNamedParameter($extraData['componentType'])) |
|
954 | + ->set('firstoccurence', $query->createNamedParameter($extraData['firstOccurence'])) |
|
955 | + ->set('lastoccurence', $query->createNamedParameter($extraData['lastOccurence'])) |
|
956 | + ->set('classification', $query->createNamedParameter($extraData['classification'])) |
|
957 | + ->set('uid', $query->createNamedParameter($extraData['uid'])) |
|
958 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
959 | + ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
960 | + ->execute(); |
|
961 | + |
|
962 | + $data = $this->getCalendarObject($calendarId, $objectUri); |
|
963 | + if (is_array($data)) { |
|
964 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', new GenericEvent( |
|
965 | + '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', |
|
966 | + [ |
|
967 | + 'calendarId' => $calendarId, |
|
968 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
969 | + 'shares' => $this->getShares($calendarId), |
|
970 | + 'objectData' => $data, |
|
971 | + ] |
|
972 | + )); |
|
973 | + } |
|
974 | + $this->addChange($calendarId, $objectUri, 2); |
|
975 | + |
|
976 | + return '"' . $extraData['etag'] . '"'; |
|
977 | + } |
|
978 | + |
|
979 | + /** |
|
980 | + * @param int $calendarObjectId |
|
981 | + * @param int $classification |
|
982 | + */ |
|
983 | + public function setClassification($calendarObjectId, $classification) { |
|
984 | + if (!in_array($classification, [ |
|
985 | + self::CLASSIFICATION_PUBLIC, self::CLASSIFICATION_PRIVATE, self::CLASSIFICATION_CONFIDENTIAL |
|
986 | + ])) { |
|
987 | + throw new \InvalidArgumentException(); |
|
988 | + } |
|
989 | + $query = $this->db->getQueryBuilder(); |
|
990 | + $query->update('calendarobjects') |
|
991 | + ->set('classification', $query->createNamedParameter($classification)) |
|
992 | + ->where($query->expr()->eq('id', $query->createNamedParameter($calendarObjectId))) |
|
993 | + ->execute(); |
|
994 | + } |
|
995 | + |
|
996 | + /** |
|
997 | + * Deletes an existing calendar object. |
|
998 | + * |
|
999 | + * The object uri is only the basename, or filename and not a full path. |
|
1000 | + * |
|
1001 | + * @param mixed $calendarId |
|
1002 | + * @param string $objectUri |
|
1003 | + * @return void |
|
1004 | + */ |
|
1005 | + function deleteCalendarObject($calendarId, $objectUri) { |
|
1006 | + $data = $this->getCalendarObject($calendarId, $objectUri); |
|
1007 | + if (is_array($data)) { |
|
1008 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', new GenericEvent( |
|
1009 | + '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', |
|
1010 | + [ |
|
1011 | + 'calendarId' => $calendarId, |
|
1012 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
1013 | + 'shares' => $this->getShares($calendarId), |
|
1014 | + 'objectData' => $data, |
|
1015 | + ] |
|
1016 | + )); |
|
1017 | + } |
|
1018 | + |
|
1019 | + $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ? AND `uri` = ?'); |
|
1020 | + $stmt->execute([$calendarId, $objectUri]); |
|
1021 | + |
|
1022 | + $this->addChange($calendarId, $objectUri, 3); |
|
1023 | + } |
|
1024 | + |
|
1025 | + /** |
|
1026 | + * Performs a calendar-query on the contents of this calendar. |
|
1027 | + * |
|
1028 | + * The calendar-query is defined in RFC4791 : CalDAV. Using the |
|
1029 | + * calendar-query it is possible for a client to request a specific set of |
|
1030 | + * object, based on contents of iCalendar properties, date-ranges and |
|
1031 | + * iCalendar component types (VTODO, VEVENT). |
|
1032 | + * |
|
1033 | + * This method should just return a list of (relative) urls that match this |
|
1034 | + * query. |
|
1035 | + * |
|
1036 | + * The list of filters are specified as an array. The exact array is |
|
1037 | + * documented by Sabre\CalDAV\CalendarQueryParser. |
|
1038 | + * |
|
1039 | + * Note that it is extremely likely that getCalendarObject for every path |
|
1040 | + * returned from this method will be called almost immediately after. You |
|
1041 | + * may want to anticipate this to speed up these requests. |
|
1042 | + * |
|
1043 | + * This method provides a default implementation, which parses *all* the |
|
1044 | + * iCalendar objects in the specified calendar. |
|
1045 | + * |
|
1046 | + * This default may well be good enough for personal use, and calendars |
|
1047 | + * that aren't very large. But if you anticipate high usage, big calendars |
|
1048 | + * or high loads, you are strongly advised to optimize certain paths. |
|
1049 | + * |
|
1050 | + * The best way to do so is override this method and to optimize |
|
1051 | + * specifically for 'common filters'. |
|
1052 | + * |
|
1053 | + * Requests that are extremely common are: |
|
1054 | + * * requests for just VEVENTS |
|
1055 | + * * requests for just VTODO |
|
1056 | + * * requests with a time-range-filter on either VEVENT or VTODO. |
|
1057 | + * |
|
1058 | + * ..and combinations of these requests. It may not be worth it to try to |
|
1059 | + * handle every possible situation and just rely on the (relatively |
|
1060 | + * easy to use) CalendarQueryValidator to handle the rest. |
|
1061 | + * |
|
1062 | + * Note that especially time-range-filters may be difficult to parse. A |
|
1063 | + * time-range filter specified on a VEVENT must for instance also handle |
|
1064 | + * recurrence rules correctly. |
|
1065 | + * A good example of how to interprete all these filters can also simply |
|
1066 | + * be found in Sabre\CalDAV\CalendarQueryFilter. This class is as correct |
|
1067 | + * as possible, so it gives you a good idea on what type of stuff you need |
|
1068 | + * to think of. |
|
1069 | + * |
|
1070 | + * @param mixed $calendarId |
|
1071 | + * @param array $filters |
|
1072 | + * @return array |
|
1073 | + */ |
|
1074 | + function calendarQuery($calendarId, array $filters) { |
|
1075 | + $componentType = null; |
|
1076 | + $requirePostFilter = true; |
|
1077 | + $timeRange = null; |
|
1078 | + |
|
1079 | + // if no filters were specified, we don't need to filter after a query |
|
1080 | + if (!$filters['prop-filters'] && !$filters['comp-filters']) { |
|
1081 | + $requirePostFilter = false; |
|
1082 | + } |
|
1083 | + |
|
1084 | + // Figuring out if there's a component filter |
|
1085 | + if (count($filters['comp-filters']) > 0 && !$filters['comp-filters'][0]['is-not-defined']) { |
|
1086 | + $componentType = $filters['comp-filters'][0]['name']; |
|
1087 | + |
|
1088 | + // Checking if we need post-filters |
|
1089 | + if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['time-range'] && !$filters['comp-filters'][0]['prop-filters']) { |
|
1090 | + $requirePostFilter = false; |
|
1091 | + } |
|
1092 | + // There was a time-range filter |
|
1093 | + if ($componentType == 'VEVENT' && isset($filters['comp-filters'][0]['time-range'])) { |
|
1094 | + $timeRange = $filters['comp-filters'][0]['time-range']; |
|
1095 | + |
|
1096 | + // If start time OR the end time is not specified, we can do a |
|
1097 | + // 100% accurate mysql query. |
|
1098 | + if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['prop-filters'] && (!$timeRange['start'] || !$timeRange['end'])) { |
|
1099 | + $requirePostFilter = false; |
|
1100 | + } |
|
1101 | + } |
|
1102 | + |
|
1103 | + } |
|
1104 | + $columns = ['uri']; |
|
1105 | + if ($requirePostFilter) { |
|
1106 | + $columns = ['uri', 'calendardata']; |
|
1107 | + } |
|
1108 | + $query = $this->db->getQueryBuilder(); |
|
1109 | + $query->select($columns) |
|
1110 | + ->from('calendarobjects') |
|
1111 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
1112 | + |
|
1113 | + if ($componentType) { |
|
1114 | + $query->andWhere($query->expr()->eq('componenttype', $query->createNamedParameter($componentType))); |
|
1115 | + } |
|
1116 | + |
|
1117 | + if ($timeRange && $timeRange['start']) { |
|
1118 | + $query->andWhere($query->expr()->gt('lastoccurence', $query->createNamedParameter($timeRange['start']->getTimeStamp()))); |
|
1119 | + } |
|
1120 | + if ($timeRange && $timeRange['end']) { |
|
1121 | + $query->andWhere($query->expr()->lt('firstoccurence', $query->createNamedParameter($timeRange['end']->getTimeStamp()))); |
|
1122 | + } |
|
1123 | + |
|
1124 | + $stmt = $query->execute(); |
|
1125 | + |
|
1126 | + $result = []; |
|
1127 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1128 | + if ($requirePostFilter) { |
|
1129 | + if (!$this->validateFilterForObject($row, $filters)) { |
|
1130 | + continue; |
|
1131 | + } |
|
1132 | + } |
|
1133 | + $result[] = $row['uri']; |
|
1134 | + } |
|
1135 | + |
|
1136 | + return $result; |
|
1137 | + } |
|
1138 | + |
|
1139 | + /** |
|
1140 | + * Searches through all of a users calendars and calendar objects to find |
|
1141 | + * an object with a specific UID. |
|
1142 | + * |
|
1143 | + * This method should return the path to this object, relative to the |
|
1144 | + * calendar home, so this path usually only contains two parts: |
|
1145 | + * |
|
1146 | + * calendarpath/objectpath.ics |
|
1147 | + * |
|
1148 | + * If the uid is not found, return null. |
|
1149 | + * |
|
1150 | + * This method should only consider * objects that the principal owns, so |
|
1151 | + * any calendars owned by other principals that also appear in this |
|
1152 | + * collection should be ignored. |
|
1153 | + * |
|
1154 | + * @param string $principalUri |
|
1155 | + * @param string $uid |
|
1156 | + * @return string|null |
|
1157 | + */ |
|
1158 | + function getCalendarObjectByUID($principalUri, $uid) { |
|
1159 | + |
|
1160 | + $query = $this->db->getQueryBuilder(); |
|
1161 | + $query->selectAlias('c.uri', 'calendaruri')->selectAlias('co.uri', 'objecturi') |
|
1162 | + ->from('calendarobjects', 'co') |
|
1163 | + ->leftJoin('co', 'calendars', 'c', $query->expr()->eq('co.calendarid', 'c.id')) |
|
1164 | + ->where($query->expr()->eq('c.principaluri', $query->createNamedParameter($principalUri))) |
|
1165 | + ->andWhere($query->expr()->eq('co.uid', $query->createNamedParameter($uid))); |
|
1166 | + |
|
1167 | + $stmt = $query->execute(); |
|
1168 | + |
|
1169 | + if ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1170 | + return $row['calendaruri'] . '/' . $row['objecturi']; |
|
1171 | + } |
|
1172 | + |
|
1173 | + return null; |
|
1174 | + } |
|
1175 | + |
|
1176 | + /** |
|
1177 | + * The getChanges method returns all the changes that have happened, since |
|
1178 | + * the specified syncToken in the specified calendar. |
|
1179 | + * |
|
1180 | + * This function should return an array, such as the following: |
|
1181 | + * |
|
1182 | + * [ |
|
1183 | + * 'syncToken' => 'The current synctoken', |
|
1184 | + * 'added' => [ |
|
1185 | + * 'new.txt', |
|
1186 | + * ], |
|
1187 | + * 'modified' => [ |
|
1188 | + * 'modified.txt', |
|
1189 | + * ], |
|
1190 | + * 'deleted' => [ |
|
1191 | + * 'foo.php.bak', |
|
1192 | + * 'old.txt' |
|
1193 | + * ] |
|
1194 | + * ); |
|
1195 | + * |
|
1196 | + * The returned syncToken property should reflect the *current* syncToken |
|
1197 | + * of the calendar, as reported in the {http://sabredav.org/ns}sync-token |
|
1198 | + * property This is * needed here too, to ensure the operation is atomic. |
|
1199 | + * |
|
1200 | + * If the $syncToken argument is specified as null, this is an initial |
|
1201 | + * sync, and all members should be reported. |
|
1202 | + * |
|
1203 | + * The modified property is an array of nodenames that have changed since |
|
1204 | + * the last token. |
|
1205 | + * |
|
1206 | + * The deleted property is an array with nodenames, that have been deleted |
|
1207 | + * from collection. |
|
1208 | + * |
|
1209 | + * The $syncLevel argument is basically the 'depth' of the report. If it's |
|
1210 | + * 1, you only have to report changes that happened only directly in |
|
1211 | + * immediate descendants. If it's 2, it should also include changes from |
|
1212 | + * the nodes below the child collections. (grandchildren) |
|
1213 | + * |
|
1214 | + * The $limit argument allows a client to specify how many results should |
|
1215 | + * be returned at most. If the limit is not specified, it should be treated |
|
1216 | + * as infinite. |
|
1217 | + * |
|
1218 | + * If the limit (infinite or not) is higher than you're willing to return, |
|
1219 | + * you should throw a Sabre\DAV\Exception\TooMuchMatches() exception. |
|
1220 | + * |
|
1221 | + * If the syncToken is expired (due to data cleanup) or unknown, you must |
|
1222 | + * return null. |
|
1223 | + * |
|
1224 | + * The limit is 'suggestive'. You are free to ignore it. |
|
1225 | + * |
|
1226 | + * @param string $calendarId |
|
1227 | + * @param string $syncToken |
|
1228 | + * @param int $syncLevel |
|
1229 | + * @param int $limit |
|
1230 | + * @return array |
|
1231 | + */ |
|
1232 | + function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null) { |
|
1233 | + // Current synctoken |
|
1234 | + $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
1235 | + $stmt->execute([ $calendarId ]); |
|
1236 | + $currentToken = $stmt->fetchColumn(0); |
|
1237 | + |
|
1238 | + if (is_null($currentToken)) { |
|
1239 | + return null; |
|
1240 | + } |
|
1241 | + |
|
1242 | + $result = [ |
|
1243 | + 'syncToken' => $currentToken, |
|
1244 | + 'added' => [], |
|
1245 | + 'modified' => [], |
|
1246 | + 'deleted' => [], |
|
1247 | + ]; |
|
1248 | + |
|
1249 | + if ($syncToken) { |
|
1250 | + |
|
1251 | + $query = "SELECT `uri`, `operation` FROM `*PREFIX*calendarchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `calendarid` = ? ORDER BY `synctoken`"; |
|
1252 | + if ($limit>0) { |
|
1253 | + $query.= " `LIMIT` " . (int)$limit; |
|
1254 | + } |
|
1255 | + |
|
1256 | + // Fetching all changes |
|
1257 | + $stmt = $this->db->prepare($query); |
|
1258 | + $stmt->execute([$syncToken, $currentToken, $calendarId]); |
|
1259 | + |
|
1260 | + $changes = []; |
|
1261 | + |
|
1262 | + // This loop ensures that any duplicates are overwritten, only the |
|
1263 | + // last change on a node is relevant. |
|
1264 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1265 | + |
|
1266 | + $changes[$row['uri']] = $row['operation']; |
|
1267 | + |
|
1268 | + } |
|
1269 | + |
|
1270 | + foreach($changes as $uri => $operation) { |
|
1271 | + |
|
1272 | + switch($operation) { |
|
1273 | + case 1 : |
|
1274 | + $result['added'][] = $uri; |
|
1275 | + break; |
|
1276 | + case 2 : |
|
1277 | + $result['modified'][] = $uri; |
|
1278 | + break; |
|
1279 | + case 3 : |
|
1280 | + $result['deleted'][] = $uri; |
|
1281 | + break; |
|
1282 | + } |
|
1283 | + |
|
1284 | + } |
|
1285 | + } else { |
|
1286 | + // No synctoken supplied, this is the initial sync. |
|
1287 | + $query = "SELECT `uri` FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ?"; |
|
1288 | + $stmt = $this->db->prepare($query); |
|
1289 | + $stmt->execute([$calendarId]); |
|
1290 | + |
|
1291 | + $result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN); |
|
1292 | + } |
|
1293 | + return $result; |
|
1294 | + |
|
1295 | + } |
|
1296 | + |
|
1297 | + /** |
|
1298 | + * Returns a list of subscriptions for a principal. |
|
1299 | + * |
|
1300 | + * Every subscription is an array with the following keys: |
|
1301 | + * * id, a unique id that will be used by other functions to modify the |
|
1302 | + * subscription. This can be the same as the uri or a database key. |
|
1303 | + * * uri. This is just the 'base uri' or 'filename' of the subscription. |
|
1304 | + * * principaluri. The owner of the subscription. Almost always the same as |
|
1305 | + * principalUri passed to this method. |
|
1306 | + * |
|
1307 | + * Furthermore, all the subscription info must be returned too: |
|
1308 | + * |
|
1309 | + * 1. {DAV:}displayname |
|
1310 | + * 2. {http://apple.com/ns/ical/}refreshrate |
|
1311 | + * 3. {http://calendarserver.org/ns/}subscribed-strip-todos (omit if todos |
|
1312 | + * should not be stripped). |
|
1313 | + * 4. {http://calendarserver.org/ns/}subscribed-strip-alarms (omit if alarms |
|
1314 | + * should not be stripped). |
|
1315 | + * 5. {http://calendarserver.org/ns/}subscribed-strip-attachments (omit if |
|
1316 | + * attachments should not be stripped). |
|
1317 | + * 6. {http://calendarserver.org/ns/}source (Must be a |
|
1318 | + * Sabre\DAV\Property\Href). |
|
1319 | + * 7. {http://apple.com/ns/ical/}calendar-color |
|
1320 | + * 8. {http://apple.com/ns/ical/}calendar-order |
|
1321 | + * 9. {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set |
|
1322 | + * (should just be an instance of |
|
1323 | + * Sabre\CalDAV\Property\SupportedCalendarComponentSet, with a bunch of |
|
1324 | + * default components). |
|
1325 | + * |
|
1326 | + * @param string $principalUri |
|
1327 | + * @return array |
|
1328 | + */ |
|
1329 | + function getSubscriptionsForUser($principalUri) { |
|
1330 | + $fields = array_values($this->subscriptionPropertyMap); |
|
1331 | + $fields[] = 'id'; |
|
1332 | + $fields[] = 'uri'; |
|
1333 | + $fields[] = 'source'; |
|
1334 | + $fields[] = 'principaluri'; |
|
1335 | + $fields[] = 'lastmodified'; |
|
1336 | + |
|
1337 | + $query = $this->db->getQueryBuilder(); |
|
1338 | + $query->select($fields) |
|
1339 | + ->from('calendarsubscriptions') |
|
1340 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1341 | + ->orderBy('calendarorder', 'asc'); |
|
1342 | + $stmt =$query->execute(); |
|
1343 | + |
|
1344 | + $subscriptions = []; |
|
1345 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1346 | + |
|
1347 | + $subscription = [ |
|
1348 | + 'id' => $row['id'], |
|
1349 | + 'uri' => $row['uri'], |
|
1350 | + 'principaluri' => $row['principaluri'], |
|
1351 | + 'source' => $row['source'], |
|
1352 | + 'lastmodified' => $row['lastmodified'], |
|
1353 | + |
|
1354 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']), |
|
1355 | + ]; |
|
1356 | + |
|
1357 | + foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1358 | + if (!is_null($row[$dbName])) { |
|
1359 | + $subscription[$xmlName] = $row[$dbName]; |
|
1360 | + } |
|
1361 | + } |
|
1362 | + |
|
1363 | + $subscriptions[] = $subscription; |
|
1364 | + |
|
1365 | + } |
|
1366 | + |
|
1367 | + return $subscriptions; |
|
1368 | + } |
|
1369 | + |
|
1370 | + /** |
|
1371 | + * Creates a new subscription for a principal. |
|
1372 | + * |
|
1373 | + * If the creation was a success, an id must be returned that can be used to reference |
|
1374 | + * this subscription in other methods, such as updateSubscription. |
|
1375 | + * |
|
1376 | + * @param string $principalUri |
|
1377 | + * @param string $uri |
|
1378 | + * @param array $properties |
|
1379 | + * @return mixed |
|
1380 | + */ |
|
1381 | + function createSubscription($principalUri, $uri, array $properties) { |
|
1382 | + |
|
1383 | + if (!isset($properties['{http://calendarserver.org/ns/}source'])) { |
|
1384 | + throw new Forbidden('The {http://calendarserver.org/ns/}source property is required when creating subscriptions'); |
|
1385 | + } |
|
1386 | + |
|
1387 | + $values = [ |
|
1388 | + 'principaluri' => $principalUri, |
|
1389 | + 'uri' => $uri, |
|
1390 | + 'source' => $properties['{http://calendarserver.org/ns/}source']->getHref(), |
|
1391 | + 'lastmodified' => time(), |
|
1392 | + ]; |
|
1393 | + |
|
1394 | + $propertiesBoolean = ['striptodos', 'stripalarms', 'stripattachments']; |
|
1395 | + |
|
1396 | + foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1397 | + if (array_key_exists($xmlName, $properties)) { |
|
1398 | + $values[$dbName] = $properties[$xmlName]; |
|
1399 | + if (in_array($dbName, $propertiesBoolean)) { |
|
1400 | + $values[$dbName] = true; |
|
1401 | + } |
|
1402 | + } |
|
1403 | + } |
|
1404 | + |
|
1405 | + $valuesToInsert = array(); |
|
1406 | + |
|
1407 | + $query = $this->db->getQueryBuilder(); |
|
1408 | + |
|
1409 | + foreach (array_keys($values) as $name) { |
|
1410 | + $valuesToInsert[$name] = $query->createNamedParameter($values[$name]); |
|
1411 | + } |
|
1412 | + |
|
1413 | + $query->insert('calendarsubscriptions') |
|
1414 | + ->values($valuesToInsert) |
|
1415 | + ->execute(); |
|
1416 | + |
|
1417 | + return $this->db->lastInsertId('*PREFIX*calendarsubscriptions'); |
|
1418 | + } |
|
1419 | + |
|
1420 | + /** |
|
1421 | + * Updates a subscription |
|
1422 | + * |
|
1423 | + * The list of mutations is stored in a Sabre\DAV\PropPatch object. |
|
1424 | + * To do the actual updates, you must tell this object which properties |
|
1425 | + * you're going to process with the handle() method. |
|
1426 | + * |
|
1427 | + * Calling the handle method is like telling the PropPatch object "I |
|
1428 | + * promise I can handle updating this property". |
|
1429 | + * |
|
1430 | + * Read the PropPatch documentation for more info and examples. |
|
1431 | + * |
|
1432 | + * @param mixed $subscriptionId |
|
1433 | + * @param PropPatch $propPatch |
|
1434 | + * @return void |
|
1435 | + */ |
|
1436 | + function updateSubscription($subscriptionId, PropPatch $propPatch) { |
|
1437 | + $supportedProperties = array_keys($this->subscriptionPropertyMap); |
|
1438 | + $supportedProperties[] = '{http://calendarserver.org/ns/}source'; |
|
1439 | + |
|
1440 | + $propPatch->handle($supportedProperties, function($mutations) use ($subscriptionId) { |
|
1441 | + |
|
1442 | + $newValues = []; |
|
1443 | + |
|
1444 | + foreach($mutations as $propertyName=>$propertyValue) { |
|
1445 | + if ($propertyName === '{http://calendarserver.org/ns/}source') { |
|
1446 | + $newValues['source'] = $propertyValue->getHref(); |
|
1447 | + } else { |
|
1448 | + $fieldName = $this->subscriptionPropertyMap[$propertyName]; |
|
1449 | + $newValues[$fieldName] = $propertyValue; |
|
1450 | + } |
|
1451 | + } |
|
1452 | + |
|
1453 | + $query = $this->db->getQueryBuilder(); |
|
1454 | + $query->update('calendarsubscriptions') |
|
1455 | + ->set('lastmodified', $query->createNamedParameter(time())); |
|
1456 | + foreach($newValues as $fieldName=>$value) { |
|
1457 | + $query->set($fieldName, $query->createNamedParameter($value)); |
|
1458 | + } |
|
1459 | + $query->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
|
1460 | + ->execute(); |
|
1461 | + |
|
1462 | + return true; |
|
1463 | + |
|
1464 | + }); |
|
1465 | + } |
|
1466 | + |
|
1467 | + /** |
|
1468 | + * Deletes a subscription. |
|
1469 | + * |
|
1470 | + * @param mixed $subscriptionId |
|
1471 | + * @return void |
|
1472 | + */ |
|
1473 | + function deleteSubscription($subscriptionId) { |
|
1474 | + $query = $this->db->getQueryBuilder(); |
|
1475 | + $query->delete('calendarsubscriptions') |
|
1476 | + ->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
|
1477 | + ->execute(); |
|
1478 | + } |
|
1479 | + |
|
1480 | + /** |
|
1481 | + * Returns a single scheduling object for the inbox collection. |
|
1482 | + * |
|
1483 | + * The returned array should contain the following elements: |
|
1484 | + * * uri - A unique basename for the object. This will be used to |
|
1485 | + * construct a full uri. |
|
1486 | + * * calendardata - The iCalendar object |
|
1487 | + * * lastmodified - The last modification date. Can be an int for a unix |
|
1488 | + * timestamp, or a PHP DateTime object. |
|
1489 | + * * etag - A unique token that must change if the object changed. |
|
1490 | + * * size - The size of the object, in bytes. |
|
1491 | + * |
|
1492 | + * @param string $principalUri |
|
1493 | + * @param string $objectUri |
|
1494 | + * @return array |
|
1495 | + */ |
|
1496 | + function getSchedulingObject($principalUri, $objectUri) { |
|
1497 | + $query = $this->db->getQueryBuilder(); |
|
1498 | + $stmt = $query->select(['uri', 'calendardata', 'lastmodified', 'etag', 'size']) |
|
1499 | + ->from('schedulingobjects') |
|
1500 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1501 | + ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
1502 | + ->execute(); |
|
1503 | + |
|
1504 | + $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
1505 | + |
|
1506 | + if(!$row) { |
|
1507 | + return null; |
|
1508 | + } |
|
1509 | + |
|
1510 | + return [ |
|
1511 | + 'uri' => $row['uri'], |
|
1512 | + 'calendardata' => $row['calendardata'], |
|
1513 | + 'lastmodified' => $row['lastmodified'], |
|
1514 | + 'etag' => '"' . $row['etag'] . '"', |
|
1515 | + 'size' => (int)$row['size'], |
|
1516 | + ]; |
|
1517 | + } |
|
1518 | + |
|
1519 | + /** |
|
1520 | + * Returns all scheduling objects for the inbox collection. |
|
1521 | + * |
|
1522 | + * These objects should be returned as an array. Every item in the array |
|
1523 | + * should follow the same structure as returned from getSchedulingObject. |
|
1524 | + * |
|
1525 | + * The main difference is that 'calendardata' is optional. |
|
1526 | + * |
|
1527 | + * @param string $principalUri |
|
1528 | + * @return array |
|
1529 | + */ |
|
1530 | + function getSchedulingObjects($principalUri) { |
|
1531 | + $query = $this->db->getQueryBuilder(); |
|
1532 | + $stmt = $query->select(['uri', 'calendardata', 'lastmodified', 'etag', 'size']) |
|
1533 | + ->from('schedulingobjects') |
|
1534 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1535 | + ->execute(); |
|
1536 | + |
|
1537 | + $result = []; |
|
1538 | + foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
1539 | + $result[] = [ |
|
1540 | + 'calendardata' => $row['calendardata'], |
|
1541 | + 'uri' => $row['uri'], |
|
1542 | + 'lastmodified' => $row['lastmodified'], |
|
1543 | + 'etag' => '"' . $row['etag'] . '"', |
|
1544 | + 'size' => (int)$row['size'], |
|
1545 | + ]; |
|
1546 | + } |
|
1547 | + |
|
1548 | + return $result; |
|
1549 | + } |
|
1550 | + |
|
1551 | + /** |
|
1552 | + * Deletes a scheduling object from the inbox collection. |
|
1553 | + * |
|
1554 | + * @param string $principalUri |
|
1555 | + * @param string $objectUri |
|
1556 | + * @return void |
|
1557 | + */ |
|
1558 | + function deleteSchedulingObject($principalUri, $objectUri) { |
|
1559 | + $query = $this->db->getQueryBuilder(); |
|
1560 | + $query->delete('schedulingobjects') |
|
1561 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1562 | + ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
1563 | + ->execute(); |
|
1564 | + } |
|
1565 | + |
|
1566 | + /** |
|
1567 | + * Creates a new scheduling object. This should land in a users' inbox. |
|
1568 | + * |
|
1569 | + * @param string $principalUri |
|
1570 | + * @param string $objectUri |
|
1571 | + * @param string $objectData |
|
1572 | + * @return void |
|
1573 | + */ |
|
1574 | + function createSchedulingObject($principalUri, $objectUri, $objectData) { |
|
1575 | + $query = $this->db->getQueryBuilder(); |
|
1576 | + $query->insert('schedulingobjects') |
|
1577 | + ->values([ |
|
1578 | + 'principaluri' => $query->createNamedParameter($principalUri), |
|
1579 | + 'calendardata' => $query->createNamedParameter($objectData), |
|
1580 | + 'uri' => $query->createNamedParameter($objectUri), |
|
1581 | + 'lastmodified' => $query->createNamedParameter(time()), |
|
1582 | + 'etag' => $query->createNamedParameter(md5($objectData)), |
|
1583 | + 'size' => $query->createNamedParameter(strlen($objectData)) |
|
1584 | + ]) |
|
1585 | + ->execute(); |
|
1586 | + } |
|
1587 | + |
|
1588 | + /** |
|
1589 | + * Adds a change record to the calendarchanges table. |
|
1590 | + * |
|
1591 | + * @param mixed $calendarId |
|
1592 | + * @param string $objectUri |
|
1593 | + * @param int $operation 1 = add, 2 = modify, 3 = delete. |
|
1594 | + * @return void |
|
1595 | + */ |
|
1596 | + protected function addChange($calendarId, $objectUri, $operation) { |
|
1597 | + |
|
1598 | + $stmt = $this->db->prepare('INSERT INTO `*PREFIX*calendarchanges` (`uri`, `synctoken`, `calendarid`, `operation`) SELECT ?, `synctoken`, ?, ? FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
1599 | + $stmt->execute([ |
|
1600 | + $objectUri, |
|
1601 | + $calendarId, |
|
1602 | + $operation, |
|
1603 | + $calendarId |
|
1604 | + ]); |
|
1605 | + $stmt = $this->db->prepare('UPDATE `*PREFIX*calendars` SET `synctoken` = `synctoken` + 1 WHERE `id` = ?'); |
|
1606 | + $stmt->execute([ |
|
1607 | + $calendarId |
|
1608 | + ]); |
|
1609 | + |
|
1610 | + } |
|
1611 | + |
|
1612 | + /** |
|
1613 | + * Parses some information from calendar objects, used for optimized |
|
1614 | + * calendar-queries. |
|
1615 | + * |
|
1616 | + * Returns an array with the following keys: |
|
1617 | + * * etag - An md5 checksum of the object without the quotes. |
|
1618 | + * * size - Size of the object in bytes |
|
1619 | + * * componentType - VEVENT, VTODO or VJOURNAL |
|
1620 | + * * firstOccurence |
|
1621 | + * * lastOccurence |
|
1622 | + * * uid - value of the UID property |
|
1623 | + * |
|
1624 | + * @param string $calendarData |
|
1625 | + * @return array |
|
1626 | + */ |
|
1627 | + public function getDenormalizedData($calendarData) { |
|
1628 | + |
|
1629 | + $vObject = Reader::read($calendarData); |
|
1630 | + $componentType = null; |
|
1631 | + $component = null; |
|
1632 | + $firstOccurrence = null; |
|
1633 | + $lastOccurrence = null; |
|
1634 | + $uid = null; |
|
1635 | + $classification = self::CLASSIFICATION_PUBLIC; |
|
1636 | + foreach($vObject->getComponents() as $component) { |
|
1637 | + if ($component->name!=='VTIMEZONE') { |
|
1638 | + $componentType = $component->name; |
|
1639 | + $uid = (string)$component->UID; |
|
1640 | + break; |
|
1641 | + } |
|
1642 | + } |
|
1643 | + if (!$componentType) { |
|
1644 | + throw new \Sabre\DAV\Exception\BadRequest('Calendar objects must have a VJOURNAL, VEVENT or VTODO component'); |
|
1645 | + } |
|
1646 | + if ($componentType === 'VEVENT' && $component->DTSTART) { |
|
1647 | + $firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp(); |
|
1648 | + // Finding the last occurrence is a bit harder |
|
1649 | + if (!isset($component->RRULE)) { |
|
1650 | + if (isset($component->DTEND)) { |
|
1651 | + $lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp(); |
|
1652 | + } elseif (isset($component->DURATION)) { |
|
1653 | + $endDate = clone $component->DTSTART->getDateTime(); |
|
1654 | + $endDate->add(DateTimeParser::parse($component->DURATION->getValue())); |
|
1655 | + $lastOccurrence = $endDate->getTimeStamp(); |
|
1656 | + } elseif (!$component->DTSTART->hasTime()) { |
|
1657 | + $endDate = clone $component->DTSTART->getDateTime(); |
|
1658 | + $endDate->modify('+1 day'); |
|
1659 | + $lastOccurrence = $endDate->getTimeStamp(); |
|
1660 | + } else { |
|
1661 | + $lastOccurrence = $firstOccurrence; |
|
1662 | + } |
|
1663 | + } else { |
|
1664 | + $it = new EventIterator($vObject, (string)$component->UID); |
|
1665 | + $maxDate = new \DateTime(self::MAX_DATE); |
|
1666 | + if ($it->isInfinite()) { |
|
1667 | + $lastOccurrence = $maxDate->getTimestamp(); |
|
1668 | + } else { |
|
1669 | + $end = $it->getDtEnd(); |
|
1670 | + while($it->valid() && $end < $maxDate) { |
|
1671 | + $end = $it->getDtEnd(); |
|
1672 | + $it->next(); |
|
1673 | + |
|
1674 | + } |
|
1675 | + $lastOccurrence = $end->getTimestamp(); |
|
1676 | + } |
|
1677 | + |
|
1678 | + } |
|
1679 | + } |
|
1680 | + |
|
1681 | + if ($component->CLASS) { |
|
1682 | + $classification = CalDavBackend::CLASSIFICATION_PRIVATE; |
|
1683 | + switch ($component->CLASS->getValue()) { |
|
1684 | + case 'PUBLIC': |
|
1685 | + $classification = CalDavBackend::CLASSIFICATION_PUBLIC; |
|
1686 | + break; |
|
1687 | + case 'CONFIDENTIAL': |
|
1688 | + $classification = CalDavBackend::CLASSIFICATION_CONFIDENTIAL; |
|
1689 | + break; |
|
1690 | + } |
|
1691 | + } |
|
1692 | + return [ |
|
1693 | + 'etag' => md5($calendarData), |
|
1694 | + 'size' => strlen($calendarData), |
|
1695 | + 'componentType' => $componentType, |
|
1696 | + 'firstOccurence' => is_null($firstOccurrence) ? null : max(0, $firstOccurrence), |
|
1697 | + 'lastOccurence' => $lastOccurrence, |
|
1698 | + 'uid' => $uid, |
|
1699 | + 'classification' => $classification |
|
1700 | + ]; |
|
1701 | + |
|
1702 | + } |
|
1703 | + |
|
1704 | + private function readBlob($cardData) { |
|
1705 | + if (is_resource($cardData)) { |
|
1706 | + return stream_get_contents($cardData); |
|
1707 | + } |
|
1708 | + |
|
1709 | + return $cardData; |
|
1710 | + } |
|
1711 | + |
|
1712 | + /** |
|
1713 | + * @param IShareable $shareable |
|
1714 | + * @param array $add |
|
1715 | + * @param array $remove |
|
1716 | + */ |
|
1717 | + public function updateShares($shareable, $add, $remove) { |
|
1718 | + $calendarId = $shareable->getResourceId(); |
|
1719 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateShares', new GenericEvent( |
|
1720 | + '\OCA\DAV\CalDAV\CalDavBackend::updateShares', |
|
1721 | + [ |
|
1722 | + 'calendarId' => $calendarId, |
|
1723 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
1724 | + 'shares' => $this->getShares($calendarId), |
|
1725 | + 'add' => $add, |
|
1726 | + 'remove' => $remove, |
|
1727 | + ])); |
|
1728 | + $this->sharingBackend->updateShares($shareable, $add, $remove); |
|
1729 | + } |
|
1730 | + |
|
1731 | + /** |
|
1732 | + * @param int $resourceId |
|
1733 | + * @return array |
|
1734 | + */ |
|
1735 | + public function getShares($resourceId) { |
|
1736 | + return $this->sharingBackend->getShares($resourceId); |
|
1737 | + } |
|
1738 | + |
|
1739 | + /** |
|
1740 | + * @param boolean $value |
|
1741 | + * @param \OCA\DAV\CalDAV\Calendar $calendar |
|
1742 | + * @return string|null |
|
1743 | + */ |
|
1744 | + public function setPublishStatus($value, $calendar) { |
|
1745 | + $query = $this->db->getQueryBuilder(); |
|
1746 | + if ($value) { |
|
1747 | + $publicUri = $this->random->generate(16, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS); |
|
1748 | + $query->insert('dav_shares') |
|
1749 | + ->values([ |
|
1750 | + 'principaluri' => $query->createNamedParameter($calendar->getPrincipalURI()), |
|
1751 | + 'type' => $query->createNamedParameter('calendar'), |
|
1752 | + 'access' => $query->createNamedParameter(self::ACCESS_PUBLIC), |
|
1753 | + 'resourceid' => $query->createNamedParameter($calendar->getResourceId()), |
|
1754 | + 'publicuri' => $query->createNamedParameter($publicUri) |
|
1755 | + ]); |
|
1756 | + $query->execute(); |
|
1757 | + return $publicUri; |
|
1758 | + } |
|
1759 | + $query->delete('dav_shares') |
|
1760 | + ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) |
|
1761 | + ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))); |
|
1762 | + $query->execute(); |
|
1763 | + return null; |
|
1764 | + } |
|
1765 | + |
|
1766 | + /** |
|
1767 | + * @param \OCA\DAV\CalDAV\Calendar $calendar |
|
1768 | + * @return mixed |
|
1769 | + */ |
|
1770 | + public function getPublishStatus($calendar) { |
|
1771 | + $query = $this->db->getQueryBuilder(); |
|
1772 | + $result = $query->select('publicuri') |
|
1773 | + ->from('dav_shares') |
|
1774 | + ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) |
|
1775 | + ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
1776 | + ->execute(); |
|
1777 | + |
|
1778 | + $row = $result->fetch(); |
|
1779 | + $result->closeCursor(); |
|
1780 | + return $row ? reset($row) : false; |
|
1781 | + } |
|
1782 | + |
|
1783 | + /** |
|
1784 | + * @param int $resourceId |
|
1785 | + * @param array $acl |
|
1786 | + * @return array |
|
1787 | + */ |
|
1788 | + public function applyShareAcl($resourceId, $acl) { |
|
1789 | + return $this->sharingBackend->applyShareAcl($resourceId, $acl); |
|
1790 | + } |
|
1791 | + |
|
1792 | + private function convertPrincipal($principalUri, $toV2) { |
|
1793 | + if ($this->principalBackend->getPrincipalPrefix() === 'principals') { |
|
1794 | + list(, $name) = URLUtil::splitPath($principalUri); |
|
1795 | + if ($toV2 === true) { |
|
1796 | + return "principals/users/$name"; |
|
1797 | + } |
|
1798 | + return "principals/$name"; |
|
1799 | + } |
|
1800 | + return $principalUri; |
|
1801 | + } |
|
1802 | 1802 | } |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | $query->andWhere($query->expr()->neq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))); |
180 | 180 | } |
181 | 181 | |
182 | - return (int)$query->execute()->fetchColumn(); |
|
182 | + return (int) $query->execute()->fetchColumn(); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -226,25 +226,25 @@ discard block |
||
226 | 226 | $stmt = $query->execute(); |
227 | 227 | |
228 | 228 | $calendars = []; |
229 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
229 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
230 | 230 | |
231 | 231 | $components = []; |
232 | 232 | if ($row['components']) { |
233 | - $components = explode(',',$row['components']); |
|
233 | + $components = explode(',', $row['components']); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | $calendar = [ |
237 | 237 | 'id' => $row['id'], |
238 | 238 | 'uri' => $row['uri'], |
239 | 239 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
240 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
241 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
242 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
243 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
244 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
240 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
241 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
242 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
243 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
244 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
245 | 245 | ]; |
246 | 246 | |
247 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
247 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
248 | 248 | $calendar[$xmlName] = $row[$dbName]; |
249 | 249 | } |
250 | 250 | |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | |
258 | 258 | // query for shared calendars |
259 | 259 | $principals = $this->principalBackend->getGroupMembership($principalUriOriginal, true); |
260 | - $principals[]= $principalUri; |
|
260 | + $principals[] = $principalUri; |
|
261 | 261 | |
262 | 262 | $fields = array_values($this->propertyMap); |
263 | 263 | $fields[] = 'a.id'; |
@@ -277,27 +277,27 @@ discard block |
||
277 | 277 | ->setParameter('principaluri', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) |
278 | 278 | ->execute(); |
279 | 279 | |
280 | - while($row = $result->fetch()) { |
|
280 | + while ($row = $result->fetch()) { |
|
281 | 281 | list(, $name) = URLUtil::splitPath($row['principaluri']); |
282 | - $uri = $row['uri'] . '_shared_by_' . $name; |
|
283 | - $row['displayname'] = $row['displayname'] . ' (' . $this->getUserDisplayName($name) . ')'; |
|
282 | + $uri = $row['uri'].'_shared_by_'.$name; |
|
283 | + $row['displayname'] = $row['displayname'].' ('.$this->getUserDisplayName($name).')'; |
|
284 | 284 | $components = []; |
285 | 285 | if ($row['components']) { |
286 | - $components = explode(',',$row['components']); |
|
286 | + $components = explode(',', $row['components']); |
|
287 | 287 | } |
288 | 288 | $calendar = [ |
289 | 289 | 'id' => $row['id'], |
290 | 290 | 'uri' => $uri, |
291 | 291 | 'principaluri' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
292 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
293 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
294 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
295 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
296 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
297 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
292 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
293 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
294 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
295 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
296 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
297 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}read-only' => (int) $row['access'] === Backend::ACCESS_READ, |
|
298 | 298 | ]; |
299 | 299 | |
300 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
300 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
301 | 301 | $calendar[$xmlName] = $row[$dbName]; |
302 | 302 | } |
303 | 303 | |
@@ -326,21 +326,21 @@ discard block |
||
326 | 326 | ->orderBy('calendarorder', 'ASC'); |
327 | 327 | $stmt = $query->execute(); |
328 | 328 | $calendars = []; |
329 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
329 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
330 | 330 | $components = []; |
331 | 331 | if ($row['components']) { |
332 | - $components = explode(',',$row['components']); |
|
332 | + $components = explode(',', $row['components']); |
|
333 | 333 | } |
334 | 334 | $calendar = [ |
335 | 335 | 'id' => $row['id'], |
336 | 336 | 'uri' => $row['uri'], |
337 | 337 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
338 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
339 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
340 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
341 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
338 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
339 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
340 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
341 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
342 | 342 | ]; |
343 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
343 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
344 | 344 | $calendar[$xmlName] = $row[$dbName]; |
345 | 345 | } |
346 | 346 | if (!isset($calendars[$calendar['id']])) { |
@@ -388,27 +388,27 @@ discard block |
||
388 | 388 | ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
389 | 389 | ->execute(); |
390 | 390 | |
391 | - while($row = $result->fetch()) { |
|
391 | + while ($row = $result->fetch()) { |
|
392 | 392 | list(, $name) = URLUtil::splitPath($row['principaluri']); |
393 | - $row['displayname'] = $row['displayname'] . "($name)"; |
|
393 | + $row['displayname'] = $row['displayname']."($name)"; |
|
394 | 394 | $components = []; |
395 | 395 | if ($row['components']) { |
396 | - $components = explode(',',$row['components']); |
|
396 | + $components = explode(',', $row['components']); |
|
397 | 397 | } |
398 | 398 | $calendar = [ |
399 | 399 | 'id' => $row['id'], |
400 | 400 | 'uri' => $row['publicuri'], |
401 | 401 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
402 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
403 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
404 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
405 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
406 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], $this->legacyEndpoint), |
|
407 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
408 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
402 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
403 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
404 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
405 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
406 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal' => $this->convertPrincipal($row['principaluri'], $this->legacyEndpoint), |
|
407 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}read-only' => (int) $row['access'] === Backend::ACCESS_READ, |
|
408 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}public' => (int) $row['access'] === self::ACCESS_PUBLIC, |
|
409 | 409 | ]; |
410 | 410 | |
411 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
411 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
412 | 412 | $calendar[$xmlName] = $row[$dbName]; |
413 | 413 | } |
414 | 414 | |
@@ -450,29 +450,29 @@ discard block |
||
450 | 450 | $result->closeCursor(); |
451 | 451 | |
452 | 452 | if ($row === false) { |
453 | - throw new NotFound('Node with name \'' . $uri . '\' could not be found'); |
|
453 | + throw new NotFound('Node with name \''.$uri.'\' could not be found'); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | list(, $name) = URLUtil::splitPath($row['principaluri']); |
457 | - $row['displayname'] = $row['displayname'] . ' ' . "($name)"; |
|
457 | + $row['displayname'] = $row['displayname'].' '."($name)"; |
|
458 | 458 | $components = []; |
459 | 459 | if ($row['components']) { |
460 | - $components = explode(',',$row['components']); |
|
460 | + $components = explode(',', $row['components']); |
|
461 | 461 | } |
462 | 462 | $calendar = [ |
463 | 463 | 'id' => $row['id'], |
464 | 464 | 'uri' => $row['publicuri'], |
465 | 465 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
466 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
467 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
468 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
469 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
470 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
471 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
472 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
466 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
467 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
468 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
469 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
470 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
471 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}read-only' => (int) $row['access'] === Backend::ACCESS_READ, |
|
472 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}public' => (int) $row['access'] === self::ACCESS_PUBLIC, |
|
473 | 473 | ]; |
474 | 474 | |
475 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
475 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
476 | 476 | $calendar[$xmlName] = $row[$dbName]; |
477 | 477 | } |
478 | 478 | |
@@ -510,20 +510,20 @@ discard block |
||
510 | 510 | |
511 | 511 | $components = []; |
512 | 512 | if ($row['components']) { |
513 | - $components = explode(',',$row['components']); |
|
513 | + $components = explode(',', $row['components']); |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | $calendar = [ |
517 | 517 | 'id' => $row['id'], |
518 | 518 | 'uri' => $row['uri'], |
519 | 519 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
520 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
521 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
522 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
523 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
520 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
521 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
522 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
523 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
524 | 524 | ]; |
525 | 525 | |
526 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
526 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
527 | 527 | $calendar[$xmlName] = $row[$dbName]; |
528 | 528 | } |
529 | 529 | |
@@ -554,20 +554,20 @@ discard block |
||
554 | 554 | |
555 | 555 | $components = []; |
556 | 556 | if ($row['components']) { |
557 | - $components = explode(',',$row['components']); |
|
557 | + $components = explode(',', $row['components']); |
|
558 | 558 | } |
559 | 559 | |
560 | 560 | $calendar = [ |
561 | 561 | 'id' => $row['id'], |
562 | 562 | 'uri' => $row['uri'], |
563 | 563 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
564 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
565 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
566 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
567 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
564 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
565 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
566 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
567 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
568 | 568 | ]; |
569 | 569 | |
570 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
570 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
571 | 571 | $calendar[$xmlName] = $row[$dbName]; |
572 | 572 | } |
573 | 573 | |
@@ -599,16 +599,16 @@ discard block |
||
599 | 599 | $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'; |
600 | 600 | if (isset($properties[$sccs])) { |
601 | 601 | if (!($properties[$sccs] instanceof SupportedCalendarComponentSet)) { |
602 | - throw new DAV\Exception('The ' . $sccs . ' property must be of type: \Sabre\CalDAV\Property\SupportedCalendarComponentSet'); |
|
602 | + throw new DAV\Exception('The '.$sccs.' property must be of type: \Sabre\CalDAV\Property\SupportedCalendarComponentSet'); |
|
603 | 603 | } |
604 | - $values['components'] = implode(',',$properties[$sccs]->getValue()); |
|
604 | + $values['components'] = implode(',', $properties[$sccs]->getValue()); |
|
605 | 605 | } |
606 | - $transp = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
606 | + $transp = '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp'; |
|
607 | 607 | if (isset($properties[$transp])) { |
608 | - $values['transparent'] = $properties[$transp]->getValue()==='transparent'; |
|
608 | + $values['transparent'] = $properties[$transp]->getValue() === 'transparent'; |
|
609 | 609 | } |
610 | 610 | |
611 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
611 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
612 | 612 | if (isset($properties[$xmlName])) { |
613 | 613 | $values[$dbName] = $properties[$xmlName]; |
614 | 614 | } |
@@ -616,7 +616,7 @@ discard block |
||
616 | 616 | |
617 | 617 | $query = $this->db->getQueryBuilder(); |
618 | 618 | $query->insert('calendars'); |
619 | - foreach($values as $column => $value) { |
|
619 | + foreach ($values as $column => $value) { |
|
620 | 620 | $query->setValue($column, $query->createNamedParameter($value)); |
621 | 621 | } |
622 | 622 | $query->execute(); |
@@ -649,14 +649,14 @@ discard block |
||
649 | 649 | */ |
650 | 650 | function updateCalendar($calendarId, PropPatch $propPatch) { |
651 | 651 | $supportedProperties = array_keys($this->propertyMap); |
652 | - $supportedProperties[] = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
652 | + $supportedProperties[] = '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp'; |
|
653 | 653 | |
654 | 654 | $propPatch->handle($supportedProperties, function($mutations) use ($calendarId) { |
655 | 655 | $newValues = []; |
656 | 656 | foreach ($mutations as $propertyName => $propertyValue) { |
657 | 657 | |
658 | 658 | switch ($propertyName) { |
659 | - case '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' : |
|
659 | + case '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' : |
|
660 | 660 | $fieldName = 'transparent'; |
661 | 661 | $newValues[$fieldName] = $propertyValue->getValue() === 'transparent'; |
662 | 662 | break; |
@@ -766,16 +766,16 @@ discard block |
||
766 | 766 | $stmt = $query->execute(); |
767 | 767 | |
768 | 768 | $result = []; |
769 | - foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
769 | + foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
770 | 770 | $result[] = [ |
771 | 771 | 'id' => $row['id'], |
772 | 772 | 'uri' => $row['uri'], |
773 | 773 | 'lastmodified' => $row['lastmodified'], |
774 | - 'etag' => '"' . $row['etag'] . '"', |
|
774 | + 'etag' => '"'.$row['etag'].'"', |
|
775 | 775 | 'calendarid' => $row['calendarid'], |
776 | - 'size' => (int)$row['size'], |
|
776 | + 'size' => (int) $row['size'], |
|
777 | 777 | 'component' => strtolower($row['componenttype']), |
778 | - 'classification'=> (int)$row['classification'] |
|
778 | + 'classification'=> (int) $row['classification'] |
|
779 | 779 | ]; |
780 | 780 | } |
781 | 781 | |
@@ -808,18 +808,18 @@ discard block |
||
808 | 808 | $stmt = $query->execute(); |
809 | 809 | $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
810 | 810 | |
811 | - if(!$row) return null; |
|
811 | + if (!$row) return null; |
|
812 | 812 | |
813 | 813 | return [ |
814 | 814 | 'id' => $row['id'], |
815 | 815 | 'uri' => $row['uri'], |
816 | 816 | 'lastmodified' => $row['lastmodified'], |
817 | - 'etag' => '"' . $row['etag'] . '"', |
|
817 | + 'etag' => '"'.$row['etag'].'"', |
|
818 | 818 | 'calendarid' => $row['calendarid'], |
819 | - 'size' => (int)$row['size'], |
|
819 | + 'size' => (int) $row['size'], |
|
820 | 820 | 'calendardata' => $this->readBlob($row['calendardata']), |
821 | 821 | 'component' => strtolower($row['componenttype']), |
822 | - 'classification'=> (int)$row['classification'] |
|
822 | + 'classification'=> (int) $row['classification'] |
|
823 | 823 | ]; |
824 | 824 | } |
825 | 825 | |
@@ -858,12 +858,12 @@ discard block |
||
858 | 858 | 'id' => $row['id'], |
859 | 859 | 'uri' => $row['uri'], |
860 | 860 | 'lastmodified' => $row['lastmodified'], |
861 | - 'etag' => '"' . $row['etag'] . '"', |
|
861 | + 'etag' => '"'.$row['etag'].'"', |
|
862 | 862 | 'calendarid' => $row['calendarid'], |
863 | - 'size' => (int)$row['size'], |
|
863 | + 'size' => (int) $row['size'], |
|
864 | 864 | 'calendardata' => $this->readBlob($row['calendardata']), |
865 | 865 | 'component' => strtolower($row['componenttype']), |
866 | - 'classification' => (int)$row['classification'] |
|
866 | + 'classification' => (int) $row['classification'] |
|
867 | 867 | ]; |
868 | 868 | } |
869 | 869 | $result->closeCursor(); |
@@ -920,7 +920,7 @@ discard block |
||
920 | 920 | )); |
921 | 921 | $this->addChange($calendarId, $objectUri, 1); |
922 | 922 | |
923 | - return '"' . $extraData['etag'] . '"'; |
|
923 | + return '"'.$extraData['etag'].'"'; |
|
924 | 924 | } |
925 | 925 | |
926 | 926 | /** |
@@ -973,7 +973,7 @@ discard block |
||
973 | 973 | } |
974 | 974 | $this->addChange($calendarId, $objectUri, 2); |
975 | 975 | |
976 | - return '"' . $extraData['etag'] . '"'; |
|
976 | + return '"'.$extraData['etag'].'"'; |
|
977 | 977 | } |
978 | 978 | |
979 | 979 | /** |
@@ -1124,7 +1124,7 @@ discard block |
||
1124 | 1124 | $stmt = $query->execute(); |
1125 | 1125 | |
1126 | 1126 | $result = []; |
1127 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1127 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1128 | 1128 | if ($requirePostFilter) { |
1129 | 1129 | if (!$this->validateFilterForObject($row, $filters)) { |
1130 | 1130 | continue; |
@@ -1167,7 +1167,7 @@ discard block |
||
1167 | 1167 | $stmt = $query->execute(); |
1168 | 1168 | |
1169 | 1169 | if ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
1170 | - return $row['calendaruri'] . '/' . $row['objecturi']; |
|
1170 | + return $row['calendaruri'].'/'.$row['objecturi']; |
|
1171 | 1171 | } |
1172 | 1172 | |
1173 | 1173 | return null; |
@@ -1232,7 +1232,7 @@ discard block |
||
1232 | 1232 | function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null) { |
1233 | 1233 | // Current synctoken |
1234 | 1234 | $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*calendars` WHERE `id` = ?'); |
1235 | - $stmt->execute([ $calendarId ]); |
|
1235 | + $stmt->execute([$calendarId]); |
|
1236 | 1236 | $currentToken = $stmt->fetchColumn(0); |
1237 | 1237 | |
1238 | 1238 | if (is_null($currentToken)) { |
@@ -1249,8 +1249,8 @@ discard block |
||
1249 | 1249 | if ($syncToken) { |
1250 | 1250 | |
1251 | 1251 | $query = "SELECT `uri`, `operation` FROM `*PREFIX*calendarchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `calendarid` = ? ORDER BY `synctoken`"; |
1252 | - if ($limit>0) { |
|
1253 | - $query.= " `LIMIT` " . (int)$limit; |
|
1252 | + if ($limit > 0) { |
|
1253 | + $query .= " `LIMIT` ".(int) $limit; |
|
1254 | 1254 | } |
1255 | 1255 | |
1256 | 1256 | // Fetching all changes |
@@ -1261,15 +1261,15 @@ discard block |
||
1261 | 1261 | |
1262 | 1262 | // This loop ensures that any duplicates are overwritten, only the |
1263 | 1263 | // last change on a node is relevant. |
1264 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1264 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1265 | 1265 | |
1266 | 1266 | $changes[$row['uri']] = $row['operation']; |
1267 | 1267 | |
1268 | 1268 | } |
1269 | 1269 | |
1270 | - foreach($changes as $uri => $operation) { |
|
1270 | + foreach ($changes as $uri => $operation) { |
|
1271 | 1271 | |
1272 | - switch($operation) { |
|
1272 | + switch ($operation) { |
|
1273 | 1273 | case 1 : |
1274 | 1274 | $result['added'][] = $uri; |
1275 | 1275 | break; |
@@ -1339,10 +1339,10 @@ discard block |
||
1339 | 1339 | ->from('calendarsubscriptions') |
1340 | 1340 | ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
1341 | 1341 | ->orderBy('calendarorder', 'asc'); |
1342 | - $stmt =$query->execute(); |
|
1342 | + $stmt = $query->execute(); |
|
1343 | 1343 | |
1344 | 1344 | $subscriptions = []; |
1345 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1345 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1346 | 1346 | |
1347 | 1347 | $subscription = [ |
1348 | 1348 | 'id' => $row['id'], |
@@ -1351,10 +1351,10 @@ discard block |
||
1351 | 1351 | 'source' => $row['source'], |
1352 | 1352 | 'lastmodified' => $row['lastmodified'], |
1353 | 1353 | |
1354 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']), |
|
1354 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']), |
|
1355 | 1355 | ]; |
1356 | 1356 | |
1357 | - foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1357 | + foreach ($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1358 | 1358 | if (!is_null($row[$dbName])) { |
1359 | 1359 | $subscription[$xmlName] = $row[$dbName]; |
1360 | 1360 | } |
@@ -1393,7 +1393,7 @@ discard block |
||
1393 | 1393 | |
1394 | 1394 | $propertiesBoolean = ['striptodos', 'stripalarms', 'stripattachments']; |
1395 | 1395 | |
1396 | - foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1396 | + foreach ($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1397 | 1397 | if (array_key_exists($xmlName, $properties)) { |
1398 | 1398 | $values[$dbName] = $properties[$xmlName]; |
1399 | 1399 | if (in_array($dbName, $propertiesBoolean)) { |
@@ -1441,7 +1441,7 @@ discard block |
||
1441 | 1441 | |
1442 | 1442 | $newValues = []; |
1443 | 1443 | |
1444 | - foreach($mutations as $propertyName=>$propertyValue) { |
|
1444 | + foreach ($mutations as $propertyName=>$propertyValue) { |
|
1445 | 1445 | if ($propertyName === '{http://calendarserver.org/ns/}source') { |
1446 | 1446 | $newValues['source'] = $propertyValue->getHref(); |
1447 | 1447 | } else { |
@@ -1453,7 +1453,7 @@ discard block |
||
1453 | 1453 | $query = $this->db->getQueryBuilder(); |
1454 | 1454 | $query->update('calendarsubscriptions') |
1455 | 1455 | ->set('lastmodified', $query->createNamedParameter(time())); |
1456 | - foreach($newValues as $fieldName=>$value) { |
|
1456 | + foreach ($newValues as $fieldName=>$value) { |
|
1457 | 1457 | $query->set($fieldName, $query->createNamedParameter($value)); |
1458 | 1458 | } |
1459 | 1459 | $query->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
@@ -1503,7 +1503,7 @@ discard block |
||
1503 | 1503 | |
1504 | 1504 | $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
1505 | 1505 | |
1506 | - if(!$row) { |
|
1506 | + if (!$row) { |
|
1507 | 1507 | return null; |
1508 | 1508 | } |
1509 | 1509 | |
@@ -1511,8 +1511,8 @@ discard block |
||
1511 | 1511 | 'uri' => $row['uri'], |
1512 | 1512 | 'calendardata' => $row['calendardata'], |
1513 | 1513 | 'lastmodified' => $row['lastmodified'], |
1514 | - 'etag' => '"' . $row['etag'] . '"', |
|
1515 | - 'size' => (int)$row['size'], |
|
1514 | + 'etag' => '"'.$row['etag'].'"', |
|
1515 | + 'size' => (int) $row['size'], |
|
1516 | 1516 | ]; |
1517 | 1517 | } |
1518 | 1518 | |
@@ -1535,13 +1535,13 @@ discard block |
||
1535 | 1535 | ->execute(); |
1536 | 1536 | |
1537 | 1537 | $result = []; |
1538 | - foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
1538 | + foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
1539 | 1539 | $result[] = [ |
1540 | 1540 | 'calendardata' => $row['calendardata'], |
1541 | 1541 | 'uri' => $row['uri'], |
1542 | 1542 | 'lastmodified' => $row['lastmodified'], |
1543 | - 'etag' => '"' . $row['etag'] . '"', |
|
1544 | - 'size' => (int)$row['size'], |
|
1543 | + 'etag' => '"'.$row['etag'].'"', |
|
1544 | + 'size' => (int) $row['size'], |
|
1545 | 1545 | ]; |
1546 | 1546 | } |
1547 | 1547 | |
@@ -1633,10 +1633,10 @@ discard block |
||
1633 | 1633 | $lastOccurrence = null; |
1634 | 1634 | $uid = null; |
1635 | 1635 | $classification = self::CLASSIFICATION_PUBLIC; |
1636 | - foreach($vObject->getComponents() as $component) { |
|
1637 | - if ($component->name!=='VTIMEZONE') { |
|
1636 | + foreach ($vObject->getComponents() as $component) { |
|
1637 | + if ($component->name !== 'VTIMEZONE') { |
|
1638 | 1638 | $componentType = $component->name; |
1639 | - $uid = (string)$component->UID; |
|
1639 | + $uid = (string) $component->UID; |
|
1640 | 1640 | break; |
1641 | 1641 | } |
1642 | 1642 | } |
@@ -1661,13 +1661,13 @@ discard block |
||
1661 | 1661 | $lastOccurrence = $firstOccurrence; |
1662 | 1662 | } |
1663 | 1663 | } else { |
1664 | - $it = new EventIterator($vObject, (string)$component->UID); |
|
1664 | + $it = new EventIterator($vObject, (string) $component->UID); |
|
1665 | 1665 | $maxDate = new \DateTime(self::MAX_DATE); |
1666 | 1666 | if ($it->isInfinite()) { |
1667 | 1667 | $lastOccurrence = $maxDate->getTimestamp(); |
1668 | 1668 | } else { |
1669 | 1669 | $end = $it->getDtEnd(); |
1670 | - while($it->valid() && $end < $maxDate) { |
|
1670 | + while ($it->valid() && $end < $maxDate) { |
|
1671 | 1671 | $end = $it->getDtEnd(); |
1672 | 1672 | $it->next(); |
1673 | 1673 |
@@ -808,7 +808,9 @@ |
||
808 | 808 | $stmt = $query->execute(); |
809 | 809 | $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
810 | 810 | |
811 | - if(!$row) return null; |
|
811 | + if(!$row) { |
|
812 | + return null; |
|
813 | + } |
|
812 | 814 | |
813 | 815 | return [ |
814 | 816 | 'id' => $row['id'], |