ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\DAV\Sync\Plugin Class Reference

This plugin all WebDAV-sync capabilities to the Server. More...

+ Inheritance diagram for Sabre\DAV\Sync\Plugin:
+ Collaboration diagram for Sabre\DAV\Sync\Plugin:

Public Member Functions

 getPluginName ()
 Returns a plugin name. More...
 
 initialize (DAV\Server $server)
 Initializes the plugin. More...
 
 getSupportedReportSet ($uri)
 Returns a list of reports this plugin supports. More...
 
 syncCollection ($uri, SyncCollectionReport $report)
 This method handles the {DAV:}sync-collection HTTP REPORT. More...
 
 propFind (DAV\PropFind $propFind, DAV\INode $node)
 This method is triggered whenever properties are requested for a node. More...
 
 validateTokens (RequestInterface $request, &$conditions)
 The validateTokens event is triggered before every request. More...
 
 getPluginInfo ()
 Returns a bunch of meta-data about the plugin. More...
 
- Public Member Functions inherited from Sabre\DAV\ServerPlugin
 initialize (Server $server)
 This initializes the plugin. More...
 
 getFeatures ()
 This method should return a list of server-features. More...
 
 getHTTPMethods ($path)
 Use this method to tell the server this plugin defines additional HTTP methods. More...
 
 getPluginName ()
 Returns a plugin name. More...
 
 getSupportedReportSet ($uri)
 Returns a list of reports this plugin supports. More...
 
 getPluginInfo ()
 Returns a bunch of meta-data about the plugin. More...
 

Data Fields

const SYNCTOKEN_PREFIX = 'http://sabre.io/ns/sync/'
 

Protected Member Functions

 sendSyncCollectionResponse ($syncToken, $collectionUrl, array $added, array $modified, array $deleted, array $properties)
 Sends the response to a sync-collection request. More...
 

Protected Attributes

 $server
 

Detailed Description

This plugin all WebDAV-sync capabilities to the Server.

WebDAV-sync is defined by rfc6578

The sync capabilities only work with collections that implement Sabre.

Author
Evert Pot (http://evertpot.com/) http://sabre.io/license/ Modified BSD License

Definition at line 21 of file Plugin.php.

Member Function Documentation

◆ getPluginInfo()

Sabre\DAV\Sync\Plugin::getPluginInfo ( )

Returns a bunch of meta-data about the plugin.

Providing this information is optional, and is mainly displayed by the Browser plugin.

The description key in the returned array may contain html and will not be sanitized.

Returns
array

Definition at line 267 of file Plugin.php.

References Sabre\DAV\Sync\Plugin\getPluginName().

267  {
268 
269  return [
270  'name' => $this->getPluginName(),
271  'description' => 'Adds support for WebDAV Collection Sync (rfc6578)',
272  'link' => 'http://sabre.io/dav/sync/',
273  ];
274 
275  }
getPluginName()
Returns a plugin name.
Definition: Plugin.php:40
+ Here is the call graph for this function:

◆ getPluginName()

Sabre\DAV\Sync\Plugin::getPluginName ( )

Returns a plugin name.

Using this name other plugins will be able to access other plugins using ::getPlugin

Returns
string

Definition at line 40 of file Plugin.php.

Referenced by Sabre\DAV\Sync\Plugin\getPluginInfo().

40  {
41 
42  return 'sync';
43 
44  }
+ Here is the caller graph for this function:

◆ getSupportedReportSet()

Sabre\DAV\Sync\Plugin::getSupportedReportSet (   $uri)

Returns a list of reports this plugin supports.

This will be used in the {DAV:}supported-report-set property. Note that you still need to subscribe to the 'report' event to actually implement them

Parameters
string$uri
Returns
array

Definition at line 86 of file Plugin.php.

References Sabre\DAV\Sync\ISyncCollection\getSyncToken().

86  {
87 
88  $node = $this->server->tree->getNodeForPath($uri);
89  if ($node instanceof ISyncCollection && $node->getSyncToken()) {
90  return [
91  '{DAV:}sync-collection',
92  ];
93  }
94 
95  return [];
96 
97  }
+ Here is the call graph for this function:

◆ initialize()

Sabre\DAV\Sync\Plugin::initialize ( DAV\Server  $server)

Initializes the plugin.

This is when the plugin registers it's hooks.

Parameters
DAV\Server$server
Returns
void

Definition at line 54 of file Plugin.php.

References Sabre\DAV\Sync\Plugin\$server.

54  {
55 
56  $this->server = $server;
57  $server->xml->elementMap['{DAV:}sync-collection'] = 'Sabre\\DAV\\Xml\\Request\\SyncCollectionReport';
58 
59  $self = $this;
60 
61  $server->on('report', function($reportName, $dom, $uri) use ($self) {
62 
63  if ($reportName === '{DAV:}sync-collection') {
64  $this->server->transactionType = 'report-sync-collection';
65  $self->syncCollection($uri, $dom);
66  return false;
67  }
68 
69  });
70 
71  $server->on('propFind', [$this, 'propFind']);
72  $server->on('validateTokens', [$this, 'validateTokens']);
73 
74  }

◆ propFind()

Sabre\DAV\Sync\Plugin::propFind ( DAV\PropFind  $propFind,
DAV\INode  $node 
)

This method is triggered whenever properties are requested for a node.

We intercept this to see if we must return a {DAV:}sync-token.

Parameters
DAV\PropFind$propFind
DAV\INode$node
Returns
void

Definition at line 208 of file Plugin.php.

References PHPMailer\PHPMailer\$token.

208  {
209 
210  $propFind->handle('{DAV:}sync-token', function() use ($node) {
211  if (!$node instanceof ISyncCollection || !$token = $node->getSyncToken()) {
212  return;
213  }
214  return self::SYNCTOKEN_PREFIX . $token;
215  });
216 
217  }

◆ sendSyncCollectionResponse()

Sabre\DAV\Sync\Plugin::sendSyncCollectionResponse (   $syncToken,
  $collectionUrl,
array  $added,
array  $modified,
array  $deleted,
array  $properties 
)
protected

Sends the response to a sync-collection request.

Parameters
string$syncToken
string$collectionUrl
array$added
array$modified
array$deleted
array$properties
Returns
void

Definition at line 160 of file Plugin.php.

Referenced by Sabre\DAV\Sync\Plugin\syncCollection().

160  {
161 
162 
163  $fullPaths = [];
164 
165  // Pre-fetching children, if this is possible.
166  foreach (array_merge($added, $modified) as $item) {
167  $fullPath = $collectionUrl . '/' . $item;
168  $fullPaths[] = $fullPath;
169  }
170 
171  $responses = [];
172  foreach ($this->server->getPropertiesForMultiplePaths($fullPaths, $properties) as $fullPath => $props) {
173 
174  // The 'Property_Response' class is responsible for generating a
175  // single {DAV:}response xml element.
176  $responses[] = new DAV\Xml\Element\Response($fullPath, $props);
177 
178  }
179 
180 
181 
182  // Deleted items also show up as 'responses'. They have no properties,
183  // and a single {DAV:}status element set as 'HTTP/1.1 404 Not Found'.
184  foreach ($deleted as $item) {
185 
186  $fullPath = $collectionUrl . '/' . $item;
187  $responses[] = new DAV\Xml\Element\Response($fullPath, [], 404);
188 
189  }
190  $multiStatus = new DAV\Xml\Response\MultiStatus($responses, self::SYNCTOKEN_PREFIX . $syncToken);
191 
192  $this->server->httpResponse->setStatus(207);
193  $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
194  $this->server->httpResponse->setBody(
195  $this->server->xml->write('{DAV:}multistatus', $multiStatus, $this->server->getBaseUri())
196  );
197 
198  }
+ Here is the caller graph for this function:

◆ syncCollection()

Sabre\DAV\Sync\Plugin::syncCollection (   $uri,
SyncCollectionReport  $report 
)

This method handles the {DAV:}sync-collection HTTP REPORT.

Parameters
string$uri
SyncCollectionReport$report
Returns
void

Definition at line 107 of file Plugin.php.

References PHPMailer\PHPMailer\$token, and Sabre\DAV\Sync\Plugin\sendSyncCollectionResponse().

107  {
108 
109  // Getting the data
110  $node = $this->server->tree->getNodeForPath($uri);
111  if (!$node instanceof ISyncCollection) {
112  throw new DAV\Exception\ReportNotSupported('The {DAV:}sync-collection REPORT is not supported on this url.');
113  }
114  $token = $node->getSyncToken();
115  if (!$token) {
116  throw new DAV\Exception\ReportNotSupported('No sync information is available at this node');
117  }
118 
119  $syncToken = $report->syncToken;
120  if (!is_null($syncToken)) {
121  // Sync-token must start with our prefix
122  if (substr($syncToken, 0, strlen(self::SYNCTOKEN_PREFIX)) !== self::SYNCTOKEN_PREFIX) {
123  throw new DAV\Exception\InvalidSyncToken('Invalid or unknown sync token');
124  }
125 
126  $syncToken = substr($syncToken, strlen(self::SYNCTOKEN_PREFIX));
127 
128  }
129  $changeInfo = $node->getChanges($syncToken, $report->syncLevel, $report->limit);
130 
131  if (is_null($changeInfo)) {
132 
133  throw new DAV\Exception\InvalidSyncToken('Invalid or unknown sync token');
134 
135  }
136 
137  // Encoding the response
139  $changeInfo['syncToken'],
140  $uri,
141  $changeInfo['added'],
142  $changeInfo['modified'],
143  $changeInfo['deleted'],
144  $report->properties
145  );
146 
147  }
sendSyncCollectionResponse($syncToken, $collectionUrl, array $added, array $modified, array $deleted, array $properties)
Sends the response to a sync-collection request.
Definition: Plugin.php:160
+ Here is the call graph for this function:

◆ validateTokens()

Sabre\DAV\Sync\Plugin::validateTokens ( RequestInterface  $request,
$conditions 
)

The validateTokens event is triggered before every request.

It's a moment where this plugin can check all the supplied lock tokens in the If: header, and check if they are valid.

Parameters
RequestInterface$request
array$conditions
Returns
void

Definition at line 229 of file Plugin.php.

References $ii, PHPMailer\PHPMailer\$token, and Sabre\DAV\Sync\ISyncCollection\getSyncToken().

229  {
230 
231  foreach ($conditions as $kk => $condition) {
232 
233  foreach ($condition['tokens'] as $ii => $token) {
234 
235  // Sync-tokens must always start with our designated prefix.
236  if (substr($token['token'], 0, strlen(self::SYNCTOKEN_PREFIX)) !== self::SYNCTOKEN_PREFIX) {
237  continue;
238  }
239 
240  // Checking if the token is a match.
241  $node = $this->server->tree->getNodeForPath($condition['uri']);
242 
243  if (
244  $node instanceof ISyncCollection &&
245  $node->getSyncToken() == substr($token['token'], strlen(self::SYNCTOKEN_PREFIX))
246  ) {
247  $conditions[$kk]['tokens'][$ii]['validToken'] = true;
248  }
249 
250  }
251 
252  }
253 
254  }
+ Here is the call graph for this function:

Field Documentation

◆ $server

Sabre\DAV\Sync\Plugin::$server
protected

Definition at line 28 of file Plugin.php.

Referenced by Sabre\DAV\Sync\Plugin\initialize().

◆ SYNCTOKEN_PREFIX

const Sabre\DAV\Sync\Plugin::SYNCTOKEN_PREFIX = 'http://sabre.io/ns/sync/'

Definition at line 30 of file Plugin.php.


The documentation for this class was generated from the following file: