@@ -33,17 +33,17 @@ discard block |
||
| 33 | 33 | use OCA\DAV\Connector\Sabre\Principal; |
| 34 | 34 | |
| 35 | 35 | $authBackend = new Auth( |
| 36 | - \OC::$server->getSession(), |
|
| 37 | - \OC::$server->getUserSession(), |
|
| 38 | - \OC::$server->getRequest(), |
|
| 39 | - \OC::$server->getTwoFactorAuthManager(), |
|
| 40 | - \OC::$server->getBruteForceThrottler(), |
|
| 41 | - 'principals/' |
|
| 36 | + \OC::$server->getSession(), |
|
| 37 | + \OC::$server->getUserSession(), |
|
| 38 | + \OC::$server->getRequest(), |
|
| 39 | + \OC::$server->getTwoFactorAuthManager(), |
|
| 40 | + \OC::$server->getBruteForceThrottler(), |
|
| 41 | + 'principals/' |
|
| 42 | 42 | ); |
| 43 | 43 | $principalBackend = new Principal( |
| 44 | - \OC::$server->getUserManager(), |
|
| 45 | - \OC::$server->getGroupManager(), |
|
| 46 | - 'principals/' |
|
| 44 | + \OC::$server->getUserManager(), |
|
| 45 | + \OC::$server->getGroupManager(), |
|
| 46 | + 'principals/' |
|
| 47 | 47 | ); |
| 48 | 48 | $db = \OC::$server->getDatabaseConnection(); |
| 49 | 49 | $userManager = \OC::$server->getUserManager(); |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | $addressBookRoot->disableListing = !$debugging; // Disable listing |
| 63 | 63 | |
| 64 | 64 | $nodes = array( |
| 65 | - $principalCollection, |
|
| 66 | - $addressBookRoot, |
|
| 65 | + $principalCollection, |
|
| 66 | + $addressBookRoot, |
|
| 67 | 67 | ); |
| 68 | 68 | |
| 69 | 69 | // Fire up server |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | |
| 80 | 80 | $server->addPlugin(new LegacyDAVACL()); |
| 81 | 81 | if ($debugging) { |
| 82 | - $server->addPlugin(new Sabre\DAV\Browser\Plugin()); |
|
| 82 | + $server->addPlugin(new Sabre\DAV\Browser\Plugin()); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | $server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | $server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
| 88 | 88 | |
| 89 | 89 | if ($sendInvitations) { |
| 90 | - $server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); |
|
| 90 | + $server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); |
|
| 91 | 91 | } |
| 92 | 92 | $server->addPlugin(new ExceptionLoggerPlugin('caldav', \OC::$server->getLogger())); |
| 93 | 93 | |
@@ -60,218 +60,218 @@ |
||
| 60 | 60 | |
| 61 | 61 | class Server { |
| 62 | 62 | |
| 63 | - /** @var IRequest */ |
|
| 64 | - private $request; |
|
| 63 | + /** @var IRequest */ |
|
| 64 | + private $request; |
|
| 65 | 65 | |
| 66 | - /** @var string */ |
|
| 67 | - private $baseUri; |
|
| 66 | + /** @var string */ |
|
| 67 | + private $baseUri; |
|
| 68 | 68 | |
| 69 | - /** @var Connector\Sabre\Server */ |
|
| 70 | - private $server; |
|
| 69 | + /** @var Connector\Sabre\Server */ |
|
| 70 | + private $server; |
|
| 71 | 71 | |
| 72 | - public function __construct(IRequest $request, $baseUri) { |
|
| 73 | - $this->request = $request; |
|
| 74 | - $this->baseUri = $baseUri; |
|
| 75 | - $logger = \OC::$server->getLogger(); |
|
| 76 | - $mailer = \OC::$server->getMailer(); |
|
| 77 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 78 | - $timezone = new TimeFactory(); |
|
| 79 | - $sendInvitations = \OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes'; |
|
| 80 | - $l10nFactory = \OC::$server->getL10NFactory(); |
|
| 72 | + public function __construct(IRequest $request, $baseUri) { |
|
| 73 | + $this->request = $request; |
|
| 74 | + $this->baseUri = $baseUri; |
|
| 75 | + $logger = \OC::$server->getLogger(); |
|
| 76 | + $mailer = \OC::$server->getMailer(); |
|
| 77 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 78 | + $timezone = new TimeFactory(); |
|
| 79 | + $sendInvitations = \OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes'; |
|
| 80 | + $l10nFactory = \OC::$server->getL10NFactory(); |
|
| 81 | 81 | |
| 82 | - $root = new RootCollection(); |
|
| 83 | - $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); |
|
| 82 | + $root = new RootCollection(); |
|
| 83 | + $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); |
|
| 84 | 84 | |
| 85 | - // Add maintenance plugin |
|
| 86 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig())); |
|
| 85 | + // Add maintenance plugin |
|
| 86 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig())); |
|
| 87 | 87 | |
| 88 | - // Backends |
|
| 89 | - $authBackend = new Auth( |
|
| 90 | - \OC::$server->getSession(), |
|
| 91 | - \OC::$server->getUserSession(), |
|
| 92 | - \OC::$server->getRequest(), |
|
| 93 | - \OC::$server->getTwoFactorAuthManager(), |
|
| 94 | - \OC::$server->getBruteForceThrottler() |
|
| 95 | - ); |
|
| 88 | + // Backends |
|
| 89 | + $authBackend = new Auth( |
|
| 90 | + \OC::$server->getSession(), |
|
| 91 | + \OC::$server->getUserSession(), |
|
| 92 | + \OC::$server->getRequest(), |
|
| 93 | + \OC::$server->getTwoFactorAuthManager(), |
|
| 94 | + \OC::$server->getBruteForceThrottler() |
|
| 95 | + ); |
|
| 96 | 96 | |
| 97 | - // Set URL explicitly due to reverse-proxy situations |
|
| 98 | - $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
| 99 | - $this->server->setBaseUri($this->baseUri); |
|
| 97 | + // Set URL explicitly due to reverse-proxy situations |
|
| 98 | + $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
| 99 | + $this->server->setBaseUri($this->baseUri); |
|
| 100 | 100 | |
| 101 | - $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
| 102 | - $authPlugin = new Plugin(); |
|
| 103 | - $authPlugin->addBackend(new PublicAuth()); |
|
| 104 | - $this->server->addPlugin($authPlugin); |
|
| 101 | + $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
| 102 | + $authPlugin = new Plugin(); |
|
| 103 | + $authPlugin->addBackend(new PublicAuth()); |
|
| 104 | + $this->server->addPlugin($authPlugin); |
|
| 105 | 105 | |
| 106 | - // allow setup of additional auth backends |
|
| 107 | - $event = new SabrePluginEvent($this->server); |
|
| 108 | - $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
| 106 | + // allow setup of additional auth backends |
|
| 107 | + $event = new SabrePluginEvent($this->server); |
|
| 108 | + $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
| 109 | 109 | |
| 110 | - $bearerAuthBackend = new BearerAuth( |
|
| 111 | - \OC::$server->getUserSession(), |
|
| 112 | - \OC::$server->getSession(), |
|
| 113 | - \OC::$server->getRequest() |
|
| 114 | - ); |
|
| 115 | - $authPlugin->addBackend($bearerAuthBackend); |
|
| 116 | - // because we are throwing exceptions this plugin has to be the last one |
|
| 117 | - $authPlugin->addBackend($authBackend); |
|
| 110 | + $bearerAuthBackend = new BearerAuth( |
|
| 111 | + \OC::$server->getUserSession(), |
|
| 112 | + \OC::$server->getSession(), |
|
| 113 | + \OC::$server->getRequest() |
|
| 114 | + ); |
|
| 115 | + $authPlugin->addBackend($bearerAuthBackend); |
|
| 116 | + // because we are throwing exceptions this plugin has to be the last one |
|
| 117 | + $authPlugin->addBackend($authBackend); |
|
| 118 | 118 | |
| 119 | - // debugging |
|
| 120 | - if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 121 | - $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
| 122 | - } else { |
|
| 123 | - $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
| 124 | - } |
|
| 119 | + // debugging |
|
| 120 | + if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 121 | + $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
| 122 | + } else { |
|
| 123 | + $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
| 127 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
| 128 | - $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
| 126 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
| 127 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
| 128 | + $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
| 129 | 129 | |
| 130 | - // acl |
|
| 131 | - $acl = new DavAclPlugin(); |
|
| 132 | - $acl->principalCollectionSet = [ |
|
| 133 | - 'principals/users', 'principals/groups' |
|
| 134 | - ]; |
|
| 135 | - $acl->defaultUsernamePath = 'principals/users'; |
|
| 136 | - $this->server->addPlugin($acl); |
|
| 130 | + // acl |
|
| 131 | + $acl = new DavAclPlugin(); |
|
| 132 | + $acl->principalCollectionSet = [ |
|
| 133 | + 'principals/users', 'principals/groups' |
|
| 134 | + ]; |
|
| 135 | + $acl->defaultUsernamePath = 'principals/users'; |
|
| 136 | + $this->server->addPlugin($acl); |
|
| 137 | 137 | |
| 138 | - // calendar plugins |
|
| 139 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
| 140 | - $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); |
|
| 141 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
|
| 142 | - if ($sendInvitations) { |
|
| 143 | - $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); |
|
| 144 | - } |
|
| 145 | - $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
| 146 | - $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
| 147 | - $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
| 148 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
| 149 | - \OC::$server->getConfig(), |
|
| 150 | - \OC::$server->getURLGenerator() |
|
| 151 | - )); |
|
| 138 | + // calendar plugins |
|
| 139 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
| 140 | + $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); |
|
| 141 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
|
| 142 | + if ($sendInvitations) { |
|
| 143 | + $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); |
|
| 144 | + } |
|
| 145 | + $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
| 146 | + $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
| 147 | + $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
| 148 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
| 149 | + \OC::$server->getConfig(), |
|
| 150 | + \OC::$server->getURLGenerator() |
|
| 151 | + )); |
|
| 152 | 152 | |
| 153 | - // addressbook plugins |
|
| 154 | - $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
| 155 | - $this->server->addPlugin(new VCFExportPlugin()); |
|
| 156 | - $this->server->addPlugin(new ImageExportPlugin(new PhotoCache(\OC::$server->getAppDataDir('dav-photocache')))); |
|
| 153 | + // addressbook plugins |
|
| 154 | + $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
| 155 | + $this->server->addPlugin(new VCFExportPlugin()); |
|
| 156 | + $this->server->addPlugin(new ImageExportPlugin(new PhotoCache(\OC::$server->getAppDataDir('dav-photocache')))); |
|
| 157 | 157 | |
| 158 | - // system tags plugins |
|
| 159 | - $this->server->addPlugin(new SystemTagPlugin( |
|
| 160 | - \OC::$server->getSystemTagManager(), |
|
| 161 | - \OC::$server->getGroupManager(), |
|
| 162 | - \OC::$server->getUserSession() |
|
| 163 | - )); |
|
| 158 | + // system tags plugins |
|
| 159 | + $this->server->addPlugin(new SystemTagPlugin( |
|
| 160 | + \OC::$server->getSystemTagManager(), |
|
| 161 | + \OC::$server->getGroupManager(), |
|
| 162 | + \OC::$server->getUserSession() |
|
| 163 | + )); |
|
| 164 | 164 | |
| 165 | - // comments plugin |
|
| 166 | - $this->server->addPlugin(new CommentsPlugin( |
|
| 167 | - \OC::$server->getCommentsManager(), |
|
| 168 | - \OC::$server->getUserSession() |
|
| 169 | - )); |
|
| 165 | + // comments plugin |
|
| 166 | + $this->server->addPlugin(new CommentsPlugin( |
|
| 167 | + \OC::$server->getCommentsManager(), |
|
| 168 | + \OC::$server->getUserSession() |
|
| 169 | + )); |
|
| 170 | 170 | |
| 171 | - $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
| 171 | + $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
| 172 | 172 | |
| 173 | - // allow setup of additional plugins |
|
| 174 | - $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event); |
|
| 173 | + // allow setup of additional plugins |
|
| 174 | + $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event); |
|
| 175 | 175 | |
| 176 | - // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 177 | - // we do not provide locking we emulate it using a fake locking plugin. |
|
| 178 | - if($request->isUserAgent([ |
|
| 179 | - '/WebDAVFS/', |
|
| 180 | - '/Microsoft Office OneNote 2013/', |
|
| 181 | - '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
| 182 | - ])) { |
|
| 183 | - $this->server->addPlugin(new FakeLockerPlugin()); |
|
| 184 | - } |
|
| 176 | + // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 177 | + // we do not provide locking we emulate it using a fake locking plugin. |
|
| 178 | + if($request->isUserAgent([ |
|
| 179 | + '/WebDAVFS/', |
|
| 180 | + '/Microsoft Office OneNote 2013/', |
|
| 181 | + '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
| 182 | + ])) { |
|
| 183 | + $this->server->addPlugin(new FakeLockerPlugin()); |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
| 187 | - $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 188 | - } |
|
| 186 | + if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
| 187 | + $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | - // wait with registering these until auth is handled and the filesystem is setup |
|
| 191 | - $this->server->on('beforeMethod', function () use ($root) { |
|
| 192 | - // custom properties plugin must be the last one |
|
| 193 | - $userSession = \OC::$server->getUserSession(); |
|
| 194 | - $user = $userSession->getUser(); |
|
| 195 | - if ($user !== null) { |
|
| 196 | - $view = \OC\Files\Filesystem::getView(); |
|
| 197 | - $this->server->addPlugin( |
|
| 198 | - new FilesPlugin( |
|
| 199 | - $this->server->tree, |
|
| 200 | - \OC::$server->getConfig(), |
|
| 201 | - $this->request, |
|
| 202 | - \OC::$server->getPreviewManager(), |
|
| 203 | - false, |
|
| 204 | - !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
| 205 | - ) |
|
| 206 | - ); |
|
| 190 | + // wait with registering these until auth is handled and the filesystem is setup |
|
| 191 | + $this->server->on('beforeMethod', function () use ($root) { |
|
| 192 | + // custom properties plugin must be the last one |
|
| 193 | + $userSession = \OC::$server->getUserSession(); |
|
| 194 | + $user = $userSession->getUser(); |
|
| 195 | + if ($user !== null) { |
|
| 196 | + $view = \OC\Files\Filesystem::getView(); |
|
| 197 | + $this->server->addPlugin( |
|
| 198 | + new FilesPlugin( |
|
| 199 | + $this->server->tree, |
|
| 200 | + \OC::$server->getConfig(), |
|
| 201 | + $this->request, |
|
| 202 | + \OC::$server->getPreviewManager(), |
|
| 203 | + false, |
|
| 204 | + !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
| 205 | + ) |
|
| 206 | + ); |
|
| 207 | 207 | |
| 208 | - $this->server->addPlugin( |
|
| 209 | - new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 210 | - new CustomPropertiesBackend( |
|
| 211 | - $this->server->tree, |
|
| 212 | - \OC::$server->getDatabaseConnection(), |
|
| 213 | - \OC::$server->getUserSession()->getUser() |
|
| 214 | - ) |
|
| 215 | - ) |
|
| 216 | - ); |
|
| 217 | - if ($view !== null) { |
|
| 218 | - $this->server->addPlugin( |
|
| 219 | - new QuotaPlugin($view, false)); |
|
| 220 | - } |
|
| 221 | - $this->server->addPlugin( |
|
| 222 | - new TagsPlugin( |
|
| 223 | - $this->server->tree, \OC::$server->getTagManager() |
|
| 224 | - ) |
|
| 225 | - ); |
|
| 226 | - // TODO: switch to LazyUserFolder |
|
| 227 | - $userFolder = \OC::$server->getUserFolder(); |
|
| 228 | - $this->server->addPlugin(new SharesPlugin( |
|
| 229 | - $this->server->tree, |
|
| 230 | - $userSession, |
|
| 231 | - $userFolder, |
|
| 232 | - \OC::$server->getShareManager() |
|
| 233 | - )); |
|
| 234 | - $this->server->addPlugin(new CommentPropertiesPlugin( |
|
| 235 | - \OC::$server->getCommentsManager(), |
|
| 236 | - $userSession |
|
| 237 | - )); |
|
| 238 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
| 239 | - if ($view !== null) { |
|
| 240 | - $this->server->addPlugin(new FilesReportPlugin( |
|
| 241 | - $this->server->tree, |
|
| 242 | - $view, |
|
| 243 | - \OC::$server->getSystemTagManager(), |
|
| 244 | - \OC::$server->getSystemTagObjectMapper(), |
|
| 245 | - \OC::$server->getTagManager(), |
|
| 246 | - $userSession, |
|
| 247 | - \OC::$server->getGroupManager(), |
|
| 248 | - $userFolder |
|
| 249 | - )); |
|
| 250 | - $this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend( |
|
| 251 | - $this->server->tree, |
|
| 252 | - $user, |
|
| 253 | - \OC::$server->getRootFolder(), |
|
| 254 | - \OC::$server->getShareManager(), |
|
| 255 | - $view |
|
| 256 | - ))); |
|
| 257 | - } |
|
| 258 | - } |
|
| 208 | + $this->server->addPlugin( |
|
| 209 | + new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 210 | + new CustomPropertiesBackend( |
|
| 211 | + $this->server->tree, |
|
| 212 | + \OC::$server->getDatabaseConnection(), |
|
| 213 | + \OC::$server->getUserSession()->getUser() |
|
| 214 | + ) |
|
| 215 | + ) |
|
| 216 | + ); |
|
| 217 | + if ($view !== null) { |
|
| 218 | + $this->server->addPlugin( |
|
| 219 | + new QuotaPlugin($view, false)); |
|
| 220 | + } |
|
| 221 | + $this->server->addPlugin( |
|
| 222 | + new TagsPlugin( |
|
| 223 | + $this->server->tree, \OC::$server->getTagManager() |
|
| 224 | + ) |
|
| 225 | + ); |
|
| 226 | + // TODO: switch to LazyUserFolder |
|
| 227 | + $userFolder = \OC::$server->getUserFolder(); |
|
| 228 | + $this->server->addPlugin(new SharesPlugin( |
|
| 229 | + $this->server->tree, |
|
| 230 | + $userSession, |
|
| 231 | + $userFolder, |
|
| 232 | + \OC::$server->getShareManager() |
|
| 233 | + )); |
|
| 234 | + $this->server->addPlugin(new CommentPropertiesPlugin( |
|
| 235 | + \OC::$server->getCommentsManager(), |
|
| 236 | + $userSession |
|
| 237 | + )); |
|
| 238 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
| 239 | + if ($view !== null) { |
|
| 240 | + $this->server->addPlugin(new FilesReportPlugin( |
|
| 241 | + $this->server->tree, |
|
| 242 | + $view, |
|
| 243 | + \OC::$server->getSystemTagManager(), |
|
| 244 | + \OC::$server->getSystemTagObjectMapper(), |
|
| 245 | + \OC::$server->getTagManager(), |
|
| 246 | + $userSession, |
|
| 247 | + \OC::$server->getGroupManager(), |
|
| 248 | + $userFolder |
|
| 249 | + )); |
|
| 250 | + $this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend( |
|
| 251 | + $this->server->tree, |
|
| 252 | + $user, |
|
| 253 | + \OC::$server->getRootFolder(), |
|
| 254 | + \OC::$server->getShareManager(), |
|
| 255 | + $view |
|
| 256 | + ))); |
|
| 257 | + } |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - // register plugins from apps |
|
| 261 | - $pluginManager = new PluginManager( |
|
| 262 | - \OC::$server, |
|
| 263 | - \OC::$server->getAppManager() |
|
| 264 | - ); |
|
| 265 | - foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
| 266 | - $this->server->addPlugin($appPlugin); |
|
| 267 | - } |
|
| 268 | - foreach ($pluginManager->getAppCollections() as $appCollection) { |
|
| 269 | - $root->addChild($appCollection); |
|
| 270 | - } |
|
| 271 | - }); |
|
| 272 | - } |
|
| 260 | + // register plugins from apps |
|
| 261 | + $pluginManager = new PluginManager( |
|
| 262 | + \OC::$server, |
|
| 263 | + \OC::$server->getAppManager() |
|
| 264 | + ); |
|
| 265 | + foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
| 266 | + $this->server->addPlugin($appPlugin); |
|
| 267 | + } |
|
| 268 | + foreach ($pluginManager->getAppCollections() as $appCollection) { |
|
| 269 | + $root->addChild($appCollection); |
|
| 270 | + } |
|
| 271 | + }); |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - public function exec() { |
|
| 275 | - $this->server->exec(); |
|
| 276 | - } |
|
| 274 | + public function exec() { |
|
| 275 | + $this->server->exec(); |
|
| 276 | + } |
|
| 277 | 277 | } |
@@ -52,261 +52,261 @@ |
||
| 52 | 52 | */ |
| 53 | 53 | class IMipPlugin extends SabreIMipPlugin { |
| 54 | 54 | |
| 55 | - /** @var string */ |
|
| 56 | - private $userId; |
|
| 57 | - |
|
| 58 | - /** @var IConfig */ |
|
| 59 | - private $config; |
|
| 60 | - |
|
| 61 | - /** @var IMailer */ |
|
| 62 | - private $mailer; |
|
| 63 | - |
|
| 64 | - /** @var ILogger */ |
|
| 65 | - private $logger; |
|
| 66 | - |
|
| 67 | - /** @var ITimeFactory */ |
|
| 68 | - private $timeFactory; |
|
| 69 | - |
|
| 70 | - /** @var L10NFactory */ |
|
| 71 | - private $l10nFactory; |
|
| 72 | - |
|
| 73 | - const MAX_DATE = '2038-01-01'; |
|
| 74 | - |
|
| 75 | - const METHOD_REQUEST = 'request'; |
|
| 76 | - const METHOD_REPLY = 'reply'; |
|
| 77 | - const METHOD_CANCEL = 'cancel'; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @param IConfig $config |
|
| 81 | - * @param IMailer $mailer |
|
| 82 | - * @param ILogger $logger |
|
| 83 | - * @param ITimeFactory $timeFactory |
|
| 84 | - * @param L10NFactory $l10nFactory |
|
| 85 | - * @param string $userId |
|
| 86 | - */ |
|
| 87 | - public function __construct(IConfig $config, IMailer $mailer, ILogger $logger, ITimeFactory $timeFactory, L10NFactory $l10nFactory, $userId) { |
|
| 88 | - parent::__construct(''); |
|
| 89 | - $this->userId = $userId; |
|
| 90 | - $this->config = $config; |
|
| 91 | - $this->mailer = $mailer; |
|
| 92 | - $this->logger = $logger; |
|
| 93 | - $this->timeFactory = $timeFactory; |
|
| 94 | - $this->l10nFactory = $l10nFactory; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Event handler for the 'schedule' event. |
|
| 99 | - * |
|
| 100 | - * @param Message $iTipMessage |
|
| 101 | - * @return void |
|
| 102 | - */ |
|
| 103 | - public function schedule(Message $iTipMessage) { |
|
| 104 | - |
|
| 105 | - // Not sending any emails if the system considers the update |
|
| 106 | - // insignificant. |
|
| 107 | - if (!$iTipMessage->significantChange) { |
|
| 108 | - if (!$iTipMessage->scheduleStatus) { |
|
| 109 | - $iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email'; |
|
| 110 | - } |
|
| 111 | - return; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - $summary = $iTipMessage->message->VEVENT->SUMMARY; |
|
| 115 | - |
|
| 116 | - if (parse_url($iTipMessage->sender, PHP_URL_SCHEME) !== 'mailto') { |
|
| 117 | - return; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - if (parse_url($iTipMessage->recipient, PHP_URL_SCHEME) !== 'mailto') { |
|
| 121 | - return; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - // don't send out mails for events that already took place |
|
| 125 | - if ($this->isEventInThePast($iTipMessage->message)) { |
|
| 126 | - return; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - // Strip off mailto: |
|
| 130 | - $sender = substr($iTipMessage->sender, 7); |
|
| 131 | - $recipient = substr($iTipMessage->recipient, 7); |
|
| 132 | - |
|
| 133 | - $senderName = $iTipMessage->senderName ?: null; |
|
| 134 | - $recipientName = $iTipMessage->recipientName ?: null; |
|
| 135 | - |
|
| 136 | - /** @var VEvent $vevent */ |
|
| 137 | - $vevent = $iTipMessage->message->VEVENT; |
|
| 138 | - |
|
| 139 | - $attendee = $this->getCurrentAttendee($iTipMessage); |
|
| 140 | - $defaultLang = $this->config->getUserValue($this->userId, 'core', 'lang', $this->l10nFactory->findLanguage()); |
|
| 141 | - $lang = $this->getAttendeeLangOrDefault($defaultLang, $attendee); |
|
| 142 | - $l10n = $this->l10nFactory->get('dav', $lang); |
|
| 143 | - |
|
| 144 | - $meetingAttendeeName = $recipientName ?: $recipient; |
|
| 145 | - $meetingInviteeName = $senderName ?: $sender; |
|
| 146 | - |
|
| 147 | - $meetingTitle = $vevent->SUMMARY; |
|
| 148 | - $meetingDescription = $vevent->DESCRIPTION; |
|
| 149 | - |
|
| 150 | - $meetingStart = $l10n->l('datetime', $vevent->DTSTART->getDateTime()->getTimestamp()); |
|
| 151 | - $meetingEnd = $l10n->l('datetime', $vevent->DTEND->getDateTime()->getTimestamp()); |
|
| 152 | - |
|
| 153 | - $meetingUrl = $vevent->URL; |
|
| 154 | - |
|
| 155 | - $defaultVal = '--'; |
|
| 156 | - |
|
| 157 | - $method = self::METHOD_REQUEST; |
|
| 158 | - switch (strtolower($iTipMessage->method)) { |
|
| 159 | - case self::METHOD_REPLY: |
|
| 160 | - $method = self::METHOD_REPLY; |
|
| 161 | - break; |
|
| 162 | - case self::METHOD_CANCEL: |
|
| 163 | - $method = self::METHOD_CANCEL; |
|
| 164 | - break; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - $data = array( |
|
| 168 | - 'attendee_name' => (string)$meetingAttendeeName ?: $defaultVal, |
|
| 169 | - 'invitee_name' => (string)$meetingInviteeName ?: $defaultVal, |
|
| 170 | - 'meeting_title' => (string)$meetingTitle ?: $defaultVal, |
|
| 171 | - 'meeting_description' => (string)$meetingDescription ?: $defaultVal, |
|
| 172 | - 'meeting_start' => (string)$meetingStart, |
|
| 173 | - 'meeting_end' => (string)$meetingEnd, |
|
| 174 | - 'meeting_url' => (string)$meetingUrl ?: $defaultVal, |
|
| 175 | - ); |
|
| 176 | - |
|
| 177 | - $message = $this->mailer->createMessage() |
|
| 178 | - ->setReplyTo([$sender => $senderName]) |
|
| 179 | - ->setTo([$recipient => $recipientName]) |
|
| 180 | - ; |
|
| 181 | - |
|
| 182 | - $template = $this->mailer->createEMailTemplate('dav.calendarInvite.' . $method, $data); |
|
| 183 | - $template->addHeader(); |
|
| 184 | - |
|
| 185 | - if ($method === self::METHOD_CANCEL) { |
|
| 186 | - $template->setSubject('Cancelled: ' . $summary); |
|
| 187 | - $template->addHeading($l10n->t('Event canceled'), $l10n->t('Hello %s,', [$data['attendee_name']])); |
|
| 188 | - $template->addBodyText($l10n->t('The meeting with %s was canceled.', [$data['invitee_name']])); |
|
| 189 | - } else if ($method === self::METHOD_REPLY) { |
|
| 190 | - $template->setSubject('Re: ' . $summary); |
|
| 191 | - $template->addHeading($l10n->t('Event updated'), $l10n->t('Hello %s,', [$data['attendee_name']])); |
|
| 192 | - $template->addBodyText($l10n->t('The meeting with %s was updated.', [$data['invitee_name']])); |
|
| 193 | - } else { |
|
| 194 | - $template->setSubject($summary); |
|
| 195 | - $template->addHeading($l10n->t('Event invitation'), $l10n->t('Hello %s,', [$data['attendee_name']])); |
|
| 196 | - $template->addBodyText($l10n->t('%s has invited you to a meeting.', [$data['invitee_name']])); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - $template->addBodyText($l10n->t('Title: %s', [$data['meeting_title']])); |
|
| 200 | - $template->addBodyText($l10n->t('Description: %s', [$data['meeting_description']])); |
|
| 201 | - $template->addBodyText($l10n->t('Start: %s', [$data['meeting_start']])); |
|
| 202 | - $template->addBodyText($l10n->t('End: %s', [$data['meeting_end']])); |
|
| 203 | - if ($data['meeting_url']) { |
|
| 204 | - $template->addBodyText($l10n->t('URL: %s', [$data['meeting_url']])); |
|
| 205 | - } |
|
| 206 | - $template->addFooter(); |
|
| 207 | - |
|
| 208 | - $message->useTemplate($template); |
|
| 209 | - |
|
| 210 | - $attachment = $this->mailer->createAttachment( |
|
| 211 | - $iTipMessage->message->serialize(), |
|
| 212 | - 'event.ics',// TODO(leon): Make file name unique, e.g. add event id |
|
| 213 | - 'text/calendar; method=' . $iTipMessage->method |
|
| 214 | - ); |
|
| 215 | - $message->attach($attachment); |
|
| 216 | - |
|
| 217 | - try { |
|
| 218 | - $failed = $this->mailer->send($message); |
|
| 219 | - $iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip'; |
|
| 220 | - if ($failed) { |
|
| 221 | - $this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => implode(', ', $failed)]); |
|
| 222 | - $iTipMessage->scheduleStatus = '5.0; EMail delivery failed'; |
|
| 223 | - } |
|
| 224 | - } catch(\Exception $ex) { |
|
| 225 | - $this->logger->logException($ex, ['app' => 'dav']); |
|
| 226 | - $iTipMessage->scheduleStatus = '5.0; EMail delivery failed'; |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * check if event took place in the past already |
|
| 232 | - * @param VCalendar $vObject |
|
| 233 | - * @return bool |
|
| 234 | - */ |
|
| 235 | - private function isEventInThePast(VCalendar $vObject) { |
|
| 236 | - /** @var VEvent $component */ |
|
| 237 | - $component = $vObject->VEVENT; |
|
| 238 | - |
|
| 239 | - $firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp(); |
|
| 240 | - // Finding the last occurrence is a bit harder |
|
| 241 | - if (!isset($component->RRULE)) { |
|
| 242 | - if (isset($component->DTEND)) { |
|
| 243 | - $lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp(); |
|
| 244 | - } elseif (isset($component->DURATION)) { |
|
| 245 | - /** @var \DateTime $endDate */ |
|
| 246 | - $endDate = clone $component->DTSTART->getDateTime(); |
|
| 247 | - // $component->DTEND->getDateTime() returns DateTimeImmutable |
|
| 248 | - $endDate = $endDate->add(DateTimeParser::parse($component->DURATION->getValue())); |
|
| 249 | - $lastOccurrence = $endDate->getTimestamp(); |
|
| 250 | - } elseif (!$component->DTSTART->hasTime()) { |
|
| 251 | - /** @var \DateTime $endDate */ |
|
| 252 | - $endDate = clone $component->DTSTART->getDateTime(); |
|
| 253 | - // $component->DTSTART->getDateTime() returns DateTimeImmutable |
|
| 254 | - $endDate = $endDate->modify('+1 day'); |
|
| 255 | - $lastOccurrence = $endDate->getTimestamp(); |
|
| 256 | - } else { |
|
| 257 | - $lastOccurrence = $firstOccurrence; |
|
| 258 | - } |
|
| 259 | - } else { |
|
| 260 | - $it = new EventIterator($vObject, (string)$component->UID); |
|
| 261 | - $maxDate = new \DateTime(self::MAX_DATE); |
|
| 262 | - if ($it->isInfinite()) { |
|
| 263 | - $lastOccurrence = $maxDate->getTimestamp(); |
|
| 264 | - } else { |
|
| 265 | - $end = $it->getDtEnd(); |
|
| 266 | - while($it->valid() && $end < $maxDate) { |
|
| 267 | - $end = $it->getDtEnd(); |
|
| 268 | - $it->next(); |
|
| 269 | - |
|
| 270 | - } |
|
| 271 | - $lastOccurrence = $end->getTimestamp(); |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - $currentTime = $this->timeFactory->getTime(); |
|
| 276 | - return $lastOccurrence < $currentTime; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * @param Message $iTipMessage |
|
| 282 | - * @return null|Property |
|
| 283 | - */ |
|
| 284 | - private function getCurrentAttendee(Message $iTipMessage) { |
|
| 285 | - /** @var VEvent $vevent */ |
|
| 286 | - $vevent = $iTipMessage->message->VEVENT; |
|
| 287 | - $attendees = $vevent->select('ATTENDEE'); |
|
| 288 | - foreach ($attendees as $attendee) { |
|
| 289 | - /** @var Property $attendee */ |
|
| 290 | - if (strcasecmp($attendee->getValue(), $iTipMessage->recipient) === 0) { |
|
| 291 | - return $attendee; |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - return null; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * @param string $default |
|
| 299 | - * @param Property|null $attendee |
|
| 300 | - * @return string |
|
| 301 | - */ |
|
| 302 | - private function getAttendeeLangOrDefault($default, Property $attendee = null) { |
|
| 303 | - if ($attendee !== null) { |
|
| 304 | - $lang = $attendee->offsetGet('LANGUAGE'); |
|
| 305 | - if ($lang instanceof Parameter) { |
|
| 306 | - return $lang->getValue(); |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - return $default; |
|
| 310 | - } |
|
| 55 | + /** @var string */ |
|
| 56 | + private $userId; |
|
| 57 | + |
|
| 58 | + /** @var IConfig */ |
|
| 59 | + private $config; |
|
| 60 | + |
|
| 61 | + /** @var IMailer */ |
|
| 62 | + private $mailer; |
|
| 63 | + |
|
| 64 | + /** @var ILogger */ |
|
| 65 | + private $logger; |
|
| 66 | + |
|
| 67 | + /** @var ITimeFactory */ |
|
| 68 | + private $timeFactory; |
|
| 69 | + |
|
| 70 | + /** @var L10NFactory */ |
|
| 71 | + private $l10nFactory; |
|
| 72 | + |
|
| 73 | + const MAX_DATE = '2038-01-01'; |
|
| 74 | + |
|
| 75 | + const METHOD_REQUEST = 'request'; |
|
| 76 | + const METHOD_REPLY = 'reply'; |
|
| 77 | + const METHOD_CANCEL = 'cancel'; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param IConfig $config |
|
| 81 | + * @param IMailer $mailer |
|
| 82 | + * @param ILogger $logger |
|
| 83 | + * @param ITimeFactory $timeFactory |
|
| 84 | + * @param L10NFactory $l10nFactory |
|
| 85 | + * @param string $userId |
|
| 86 | + */ |
|
| 87 | + public function __construct(IConfig $config, IMailer $mailer, ILogger $logger, ITimeFactory $timeFactory, L10NFactory $l10nFactory, $userId) { |
|
| 88 | + parent::__construct(''); |
|
| 89 | + $this->userId = $userId; |
|
| 90 | + $this->config = $config; |
|
| 91 | + $this->mailer = $mailer; |
|
| 92 | + $this->logger = $logger; |
|
| 93 | + $this->timeFactory = $timeFactory; |
|
| 94 | + $this->l10nFactory = $l10nFactory; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Event handler for the 'schedule' event. |
|
| 99 | + * |
|
| 100 | + * @param Message $iTipMessage |
|
| 101 | + * @return void |
|
| 102 | + */ |
|
| 103 | + public function schedule(Message $iTipMessage) { |
|
| 104 | + |
|
| 105 | + // Not sending any emails if the system considers the update |
|
| 106 | + // insignificant. |
|
| 107 | + if (!$iTipMessage->significantChange) { |
|
| 108 | + if (!$iTipMessage->scheduleStatus) { |
|
| 109 | + $iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email'; |
|
| 110 | + } |
|
| 111 | + return; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + $summary = $iTipMessage->message->VEVENT->SUMMARY; |
|
| 115 | + |
|
| 116 | + if (parse_url($iTipMessage->sender, PHP_URL_SCHEME) !== 'mailto') { |
|
| 117 | + return; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + if (parse_url($iTipMessage->recipient, PHP_URL_SCHEME) !== 'mailto') { |
|
| 121 | + return; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + // don't send out mails for events that already took place |
|
| 125 | + if ($this->isEventInThePast($iTipMessage->message)) { |
|
| 126 | + return; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + // Strip off mailto: |
|
| 130 | + $sender = substr($iTipMessage->sender, 7); |
|
| 131 | + $recipient = substr($iTipMessage->recipient, 7); |
|
| 132 | + |
|
| 133 | + $senderName = $iTipMessage->senderName ?: null; |
|
| 134 | + $recipientName = $iTipMessage->recipientName ?: null; |
|
| 135 | + |
|
| 136 | + /** @var VEvent $vevent */ |
|
| 137 | + $vevent = $iTipMessage->message->VEVENT; |
|
| 138 | + |
|
| 139 | + $attendee = $this->getCurrentAttendee($iTipMessage); |
|
| 140 | + $defaultLang = $this->config->getUserValue($this->userId, 'core', 'lang', $this->l10nFactory->findLanguage()); |
|
| 141 | + $lang = $this->getAttendeeLangOrDefault($defaultLang, $attendee); |
|
| 142 | + $l10n = $this->l10nFactory->get('dav', $lang); |
|
| 143 | + |
|
| 144 | + $meetingAttendeeName = $recipientName ?: $recipient; |
|
| 145 | + $meetingInviteeName = $senderName ?: $sender; |
|
| 146 | + |
|
| 147 | + $meetingTitle = $vevent->SUMMARY; |
|
| 148 | + $meetingDescription = $vevent->DESCRIPTION; |
|
| 149 | + |
|
| 150 | + $meetingStart = $l10n->l('datetime', $vevent->DTSTART->getDateTime()->getTimestamp()); |
|
| 151 | + $meetingEnd = $l10n->l('datetime', $vevent->DTEND->getDateTime()->getTimestamp()); |
|
| 152 | + |
|
| 153 | + $meetingUrl = $vevent->URL; |
|
| 154 | + |
|
| 155 | + $defaultVal = '--'; |
|
| 156 | + |
|
| 157 | + $method = self::METHOD_REQUEST; |
|
| 158 | + switch (strtolower($iTipMessage->method)) { |
|
| 159 | + case self::METHOD_REPLY: |
|
| 160 | + $method = self::METHOD_REPLY; |
|
| 161 | + break; |
|
| 162 | + case self::METHOD_CANCEL: |
|
| 163 | + $method = self::METHOD_CANCEL; |
|
| 164 | + break; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + $data = array( |
|
| 168 | + 'attendee_name' => (string)$meetingAttendeeName ?: $defaultVal, |
|
| 169 | + 'invitee_name' => (string)$meetingInviteeName ?: $defaultVal, |
|
| 170 | + 'meeting_title' => (string)$meetingTitle ?: $defaultVal, |
|
| 171 | + 'meeting_description' => (string)$meetingDescription ?: $defaultVal, |
|
| 172 | + 'meeting_start' => (string)$meetingStart, |
|
| 173 | + 'meeting_end' => (string)$meetingEnd, |
|
| 174 | + 'meeting_url' => (string)$meetingUrl ?: $defaultVal, |
|
| 175 | + ); |
|
| 176 | + |
|
| 177 | + $message = $this->mailer->createMessage() |
|
| 178 | + ->setReplyTo([$sender => $senderName]) |
|
| 179 | + ->setTo([$recipient => $recipientName]) |
|
| 180 | + ; |
|
| 181 | + |
|
| 182 | + $template = $this->mailer->createEMailTemplate('dav.calendarInvite.' . $method, $data); |
|
| 183 | + $template->addHeader(); |
|
| 184 | + |
|
| 185 | + if ($method === self::METHOD_CANCEL) { |
|
| 186 | + $template->setSubject('Cancelled: ' . $summary); |
|
| 187 | + $template->addHeading($l10n->t('Event canceled'), $l10n->t('Hello %s,', [$data['attendee_name']])); |
|
| 188 | + $template->addBodyText($l10n->t('The meeting with %s was canceled.', [$data['invitee_name']])); |
|
| 189 | + } else if ($method === self::METHOD_REPLY) { |
|
| 190 | + $template->setSubject('Re: ' . $summary); |
|
| 191 | + $template->addHeading($l10n->t('Event updated'), $l10n->t('Hello %s,', [$data['attendee_name']])); |
|
| 192 | + $template->addBodyText($l10n->t('The meeting with %s was updated.', [$data['invitee_name']])); |
|
| 193 | + } else { |
|
| 194 | + $template->setSubject($summary); |
|
| 195 | + $template->addHeading($l10n->t('Event invitation'), $l10n->t('Hello %s,', [$data['attendee_name']])); |
|
| 196 | + $template->addBodyText($l10n->t('%s has invited you to a meeting.', [$data['invitee_name']])); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + $template->addBodyText($l10n->t('Title: %s', [$data['meeting_title']])); |
|
| 200 | + $template->addBodyText($l10n->t('Description: %s', [$data['meeting_description']])); |
|
| 201 | + $template->addBodyText($l10n->t('Start: %s', [$data['meeting_start']])); |
|
| 202 | + $template->addBodyText($l10n->t('End: %s', [$data['meeting_end']])); |
|
| 203 | + if ($data['meeting_url']) { |
|
| 204 | + $template->addBodyText($l10n->t('URL: %s', [$data['meeting_url']])); |
|
| 205 | + } |
|
| 206 | + $template->addFooter(); |
|
| 207 | + |
|
| 208 | + $message->useTemplate($template); |
|
| 209 | + |
|
| 210 | + $attachment = $this->mailer->createAttachment( |
|
| 211 | + $iTipMessage->message->serialize(), |
|
| 212 | + 'event.ics',// TODO(leon): Make file name unique, e.g. add event id |
|
| 213 | + 'text/calendar; method=' . $iTipMessage->method |
|
| 214 | + ); |
|
| 215 | + $message->attach($attachment); |
|
| 216 | + |
|
| 217 | + try { |
|
| 218 | + $failed = $this->mailer->send($message); |
|
| 219 | + $iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip'; |
|
| 220 | + if ($failed) { |
|
| 221 | + $this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => implode(', ', $failed)]); |
|
| 222 | + $iTipMessage->scheduleStatus = '5.0; EMail delivery failed'; |
|
| 223 | + } |
|
| 224 | + } catch(\Exception $ex) { |
|
| 225 | + $this->logger->logException($ex, ['app' => 'dav']); |
|
| 226 | + $iTipMessage->scheduleStatus = '5.0; EMail delivery failed'; |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * check if event took place in the past already |
|
| 232 | + * @param VCalendar $vObject |
|
| 233 | + * @return bool |
|
| 234 | + */ |
|
| 235 | + private function isEventInThePast(VCalendar $vObject) { |
|
| 236 | + /** @var VEvent $component */ |
|
| 237 | + $component = $vObject->VEVENT; |
|
| 238 | + |
|
| 239 | + $firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp(); |
|
| 240 | + // Finding the last occurrence is a bit harder |
|
| 241 | + if (!isset($component->RRULE)) { |
|
| 242 | + if (isset($component->DTEND)) { |
|
| 243 | + $lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp(); |
|
| 244 | + } elseif (isset($component->DURATION)) { |
|
| 245 | + /** @var \DateTime $endDate */ |
|
| 246 | + $endDate = clone $component->DTSTART->getDateTime(); |
|
| 247 | + // $component->DTEND->getDateTime() returns DateTimeImmutable |
|
| 248 | + $endDate = $endDate->add(DateTimeParser::parse($component->DURATION->getValue())); |
|
| 249 | + $lastOccurrence = $endDate->getTimestamp(); |
|
| 250 | + } elseif (!$component->DTSTART->hasTime()) { |
|
| 251 | + /** @var \DateTime $endDate */ |
|
| 252 | + $endDate = clone $component->DTSTART->getDateTime(); |
|
| 253 | + // $component->DTSTART->getDateTime() returns DateTimeImmutable |
|
| 254 | + $endDate = $endDate->modify('+1 day'); |
|
| 255 | + $lastOccurrence = $endDate->getTimestamp(); |
|
| 256 | + } else { |
|
| 257 | + $lastOccurrence = $firstOccurrence; |
|
| 258 | + } |
|
| 259 | + } else { |
|
| 260 | + $it = new EventIterator($vObject, (string)$component->UID); |
|
| 261 | + $maxDate = new \DateTime(self::MAX_DATE); |
|
| 262 | + if ($it->isInfinite()) { |
|
| 263 | + $lastOccurrence = $maxDate->getTimestamp(); |
|
| 264 | + } else { |
|
| 265 | + $end = $it->getDtEnd(); |
|
| 266 | + while($it->valid() && $end < $maxDate) { |
|
| 267 | + $end = $it->getDtEnd(); |
|
| 268 | + $it->next(); |
|
| 269 | + |
|
| 270 | + } |
|
| 271 | + $lastOccurrence = $end->getTimestamp(); |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + $currentTime = $this->timeFactory->getTime(); |
|
| 276 | + return $lastOccurrence < $currentTime; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * @param Message $iTipMessage |
|
| 282 | + * @return null|Property |
|
| 283 | + */ |
|
| 284 | + private function getCurrentAttendee(Message $iTipMessage) { |
|
| 285 | + /** @var VEvent $vevent */ |
|
| 286 | + $vevent = $iTipMessage->message->VEVENT; |
|
| 287 | + $attendees = $vevent->select('ATTENDEE'); |
|
| 288 | + foreach ($attendees as $attendee) { |
|
| 289 | + /** @var Property $attendee */ |
|
| 290 | + if (strcasecmp($attendee->getValue(), $iTipMessage->recipient) === 0) { |
|
| 291 | + return $attendee; |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + return null; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * @param string $default |
|
| 299 | + * @param Property|null $attendee |
|
| 300 | + * @return string |
|
| 301 | + */ |
|
| 302 | + private function getAttendeeLangOrDefault($default, Property $attendee = null) { |
|
| 303 | + if ($attendee !== null) { |
|
| 304 | + $lang = $attendee->offsetGet('LANGUAGE'); |
|
| 305 | + if ($lang instanceof Parameter) { |
|
| 306 | + return $lang->getValue(); |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + return $default; |
|
| 310 | + } |
|
| 311 | 311 | |
| 312 | 312 | } |
@@ -165,13 +165,13 @@ discard block |
||
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | $data = array( |
| 168 | - 'attendee_name' => (string)$meetingAttendeeName ?: $defaultVal, |
|
| 169 | - 'invitee_name' => (string)$meetingInviteeName ?: $defaultVal, |
|
| 170 | - 'meeting_title' => (string)$meetingTitle ?: $defaultVal, |
|
| 171 | - 'meeting_description' => (string)$meetingDescription ?: $defaultVal, |
|
| 172 | - 'meeting_start' => (string)$meetingStart, |
|
| 173 | - 'meeting_end' => (string)$meetingEnd, |
|
| 174 | - 'meeting_url' => (string)$meetingUrl ?: $defaultVal, |
|
| 168 | + 'attendee_name' => (string) $meetingAttendeeName ?: $defaultVal, |
|
| 169 | + 'invitee_name' => (string) $meetingInviteeName ?: $defaultVal, |
|
| 170 | + 'meeting_title' => (string) $meetingTitle ?: $defaultVal, |
|
| 171 | + 'meeting_description' => (string) $meetingDescription ?: $defaultVal, |
|
| 172 | + 'meeting_start' => (string) $meetingStart, |
|
| 173 | + 'meeting_end' => (string) $meetingEnd, |
|
| 174 | + 'meeting_url' => (string) $meetingUrl ?: $defaultVal, |
|
| 175 | 175 | ); |
| 176 | 176 | |
| 177 | 177 | $message = $this->mailer->createMessage() |
@@ -179,15 +179,15 @@ discard block |
||
| 179 | 179 | ->setTo([$recipient => $recipientName]) |
| 180 | 180 | ; |
| 181 | 181 | |
| 182 | - $template = $this->mailer->createEMailTemplate('dav.calendarInvite.' . $method, $data); |
|
| 182 | + $template = $this->mailer->createEMailTemplate('dav.calendarInvite.'.$method, $data); |
|
| 183 | 183 | $template->addHeader(); |
| 184 | 184 | |
| 185 | 185 | if ($method === self::METHOD_CANCEL) { |
| 186 | - $template->setSubject('Cancelled: ' . $summary); |
|
| 186 | + $template->setSubject('Cancelled: '.$summary); |
|
| 187 | 187 | $template->addHeading($l10n->t('Event canceled'), $l10n->t('Hello %s,', [$data['attendee_name']])); |
| 188 | 188 | $template->addBodyText($l10n->t('The meeting with %s was canceled.', [$data['invitee_name']])); |
| 189 | 189 | } else if ($method === self::METHOD_REPLY) { |
| 190 | - $template->setSubject('Re: ' . $summary); |
|
| 190 | + $template->setSubject('Re: '.$summary); |
|
| 191 | 191 | $template->addHeading($l10n->t('Event updated'), $l10n->t('Hello %s,', [$data['attendee_name']])); |
| 192 | 192 | $template->addBodyText($l10n->t('The meeting with %s was updated.', [$data['invitee_name']])); |
| 193 | 193 | } else { |
@@ -209,8 +209,8 @@ discard block |
||
| 209 | 209 | |
| 210 | 210 | $attachment = $this->mailer->createAttachment( |
| 211 | 211 | $iTipMessage->message->serialize(), |
| 212 | - 'event.ics',// TODO(leon): Make file name unique, e.g. add event id |
|
| 213 | - 'text/calendar; method=' . $iTipMessage->method |
|
| 212 | + 'event.ics', // TODO(leon): Make file name unique, e.g. add event id |
|
| 213 | + 'text/calendar; method='.$iTipMessage->method |
|
| 214 | 214 | ); |
| 215 | 215 | $message->attach($attachment); |
| 216 | 216 | |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | $this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' => implode(', ', $failed)]); |
| 222 | 222 | $iTipMessage->scheduleStatus = '5.0; EMail delivery failed'; |
| 223 | 223 | } |
| 224 | - } catch(\Exception $ex) { |
|
| 224 | + } catch (\Exception $ex) { |
|
| 225 | 225 | $this->logger->logException($ex, ['app' => 'dav']); |
| 226 | 226 | $iTipMessage->scheduleStatus = '5.0; EMail delivery failed'; |
| 227 | 227 | } |
@@ -257,13 +257,13 @@ discard block |
||
| 257 | 257 | $lastOccurrence = $firstOccurrence; |
| 258 | 258 | } |
| 259 | 259 | } else { |
| 260 | - $it = new EventIterator($vObject, (string)$component->UID); |
|
| 260 | + $it = new EventIterator($vObject, (string) $component->UID); |
|
| 261 | 261 | $maxDate = new \DateTime(self::MAX_DATE); |
| 262 | 262 | if ($it->isInfinite()) { |
| 263 | 263 | $lastOccurrence = $maxDate->getTimestamp(); |
| 264 | 264 | } else { |
| 265 | 265 | $end = $it->getDtEnd(); |
| 266 | - while($it->valid() && $end < $maxDate) { |
|
| 266 | + while ($it->valid() && $end < $maxDate) { |
|
| 267 | 267 | $end = $it->getDtEnd(); |
| 268 | 268 | $it->next(); |
| 269 | 269 | |