Completed
Push — developer ( d751a3...e1a3df )
by Błażej
164:44 queued 111:37
created
libraries/SabreDAV/DAV/PartialUpdate/Plugin.php 1 patch
Indentation   +190 added lines, -190 removed lines patch added patch discarded remove patch
@@ -22,194 +22,194 @@
 block discarded – undo
22 22
  */
23 23
 class Plugin extends DAV\ServerPlugin {
24 24
 
25
-    const RANGE_APPEND = 1;
26
-    const RANGE_START = 2;
27
-    const RANGE_END = 3;
28
-
29
-    /**
30
-     * Reference to server
31
-     *
32
-     * @var Sabre\DAV\Server
33
-     */
34
-    protected $server;
35
-
36
-    /**
37
-     * Initializes the plugin
38
-     *
39
-     * This method is automatically called by the Server class after addPlugin.
40
-     *
41
-     * @param DAV\Server $server
42
-     * @return void
43
-     */
44
-    public function initialize(DAV\Server $server) {
45
-
46
-        $this->server = $server;
47
-        $server->on('method:PATCH', [$this, 'httpPatch']);
48
-
49
-    }
50
-
51
-    /**
52
-     * Returns a plugin name.
53
-     *
54
-     * Using this name other plugins will be able to access other plugins
55
-     * using DAV\Server::getPlugin
56
-     *
57
-     * @return string
58
-     */
59
-    public function getPluginName() {
60
-
61
-        return 'partialupdate';
62
-
63
-    }
64
-
65
-    /**
66
-     * Use this method to tell the server this plugin defines additional
67
-     * HTTP methods.
68
-     *
69
-     * This method is passed a uri. It should only return HTTP methods that are
70
-     * available for the specified uri.
71
-     *
72
-     * We claim to support PATCH method (partirl update) if and only if
73
-     *     - the node exist
74
-     *     - the node implements our partial update interface
75
-     *
76
-     * @param string $uri
77
-     * @return array
78
-     */
79
-    public function getHTTPMethods($uri) {
80
-
81
-        $tree = $this->server->tree;
82
-
83
-        if ($tree->nodeExists($uri)) {
84
-            $node = $tree->getNodeForPath($uri);
85
-            if ($node instanceof IPatchSupport) {
86
-                return ['PATCH'];
87
-            }
88
-        }
89
-        return [];
90
-
91
-    }
92
-
93
-    /**
94
-     * Returns a list of features for the HTTP OPTIONS Dav: header.
95
-     *
96
-     * @return array
97
-     */
98
-    public function getFeatures() {
99
-
100
-        return ['sabredav-partialupdate'];
101
-
102
-    }
103
-
104
-    /**
105
-     * Patch an uri
106
-     *
107
-     * The WebDAV patch request can be used to modify only a part of an
108
-     * existing resource. If the resource does not exist yet and the first
109
-     * offset is not 0, the request fails
110
-     *
111
-     * @param RequestInterface $request
112
-     * @param ResponseInterface $response
113
-     * @return void
114
-     */
115
-    public function httpPatch(RequestInterface $request, ResponseInterface $response) {
116
-
117
-        $path = $request->getPath();
118
-
119
-        // Get the node. Will throw a 404 if not found
120
-        $node = $this->server->tree->getNodeForPath($path);
121
-        if (!$node instanceof IPatchSupport) {
122
-            throw new DAV\Exception\MethodNotAllowed('The target resource does not support the PATCH method.');
123
-        }
124
-
125
-        $range = $this->getHTTPUpdateRange($request);
126
-
127
-        if (!$range) {
128
-            throw new DAV\Exception\BadRequest('No valid "X-Update-Range" found in the headers');
129
-        }
130
-
131
-        $contentType = strtolower(
132
-            $request->getHeader('Content-Type')
133
-        );
134
-
135
-        if ($contentType != 'application/x-sabredav-partialupdate') {
136
-            throw new DAV\Exception\UnsupportedMediaType('Unknown Content-Type header "' . $contentType . '"');
137
-        }
138
-
139
-        $len = $this->server->httpRequest->getHeader('Content-Length');
140
-        if (!$len) throw new DAV\Exception\LengthRequired('A Content-Length header is required');
141
-
142
-        switch ($range[0]) {
143
-            case self::RANGE_START :
144
-                // Calculate the end-range if it doesn't exist.
145
-                if (!$range[2]) {
146
-                    $range[2] = $range[1] + $len - 1;
147
-                } else {
148
-                    if ($range[2] < $range[1]) {
149
-                        throw new DAV\Exception\RequestedRangeNotSatisfiable('The end offset (' . $range[2] . ') is lower than the start offset (' . $range[1] . ')');
150
-                    }
151
-                    if ($range[2] - $range[1] + 1 != $len) {
152
-                        throw new DAV\Exception\RequestedRangeNotSatisfiable('Actual data length (' . $len . ') is not consistent with begin (' . $range[1] . ') and end (' . $range[2] . ') offsets');
153
-                    }
154
-                }
155
-                break;
156
-        }
157
-
158
-        if (!$this->server->emit('beforeWriteContent', [$path, $node, null]))
159
-            return;
160
-
161
-        $body = $this->server->httpRequest->getBody();
162
-
163
-
164
-        $etag = $node->patch($body, $range[0], isset($range[1]) ? $range[1] : null);
165
-
166
-        $this->server->emit('afterWriteContent', [$path, $node]);
167
-
168
-        $response->setHeader('Content-Length', '0');
169
-        if ($etag) $response->setHeader('ETag', $etag);
170
-        $response->setStatus(204);
171
-
172
-        // Breaks the event chain
173
-        return false;
174
-
175
-    }
176
-
177
-    /**
178
-     * Returns the HTTP custom range update header
179
-     *
180
-     * This method returns null if there is no well-formed HTTP range request
181
-     * header. It returns array(1) if it was an append request, array(2,
182
-     * $start, $end) if it's a start and end range, lastly it's array(3,
183
-     * $endoffset) if the offset was negative, and should be calculated from
184
-     * the end of the file.
185
-     *
186
-     * Examples:
187
-     *
188
-     * null - invalid
189
-     * [1] - append
190
-     * [2,10,15] - update bytes 10, 11, 12, 13, 14, 15
191
-     * [2,10,null] - update bytes 10 until the end of the patch body
192
-     * [3,-5] - update from 5 bytes from the end of the file.
193
-     *
194
-     * @param RequestInterface $request
195
-     * @return array|null
196
-     */
197
-    public function getHTTPUpdateRange(RequestInterface $request) {
198
-
199
-        $range = $request->getHeader('X-Update-Range');
200
-        if (is_null($range)) return null;
201
-
202
-        // Matching "Range: bytes=1234-5678: both numbers are optional
203
-
204
-        if (!preg_match('/^(append)|(?:bytes=([0-9]+)-([0-9]*))|(?:bytes=(-[0-9]+))$/i', $range, $matches)) return null;
205
-
206
-        if ($matches[1] === 'append') {
207
-            return [self::RANGE_APPEND];
208
-        } elseif (strlen($matches[2]) > 0) {
209
-            return [self::RANGE_START, $matches[2], $matches[3] ?: null];
210
-        } else {
211
-            return [self::RANGE_END, $matches[4]];
212
-        }
213
-
214
-    }
25
+	const RANGE_APPEND = 1;
26
+	const RANGE_START = 2;
27
+	const RANGE_END = 3;
28
+
29
+	/**
30
+	 * Reference to server
31
+	 *
32
+	 * @var Sabre\DAV\Server
33
+	 */
34
+	protected $server;
35
+
36
+	/**
37
+	 * Initializes the plugin
38
+	 *
39
+	 * This method is automatically called by the Server class after addPlugin.
40
+	 *
41
+	 * @param DAV\Server $server
42
+	 * @return void
43
+	 */
44
+	public function initialize(DAV\Server $server) {
45
+
46
+		$this->server = $server;
47
+		$server->on('method:PATCH', [$this, 'httpPatch']);
48
+
49
+	}
50
+
51
+	/**
52
+	 * Returns a plugin name.
53
+	 *
54
+	 * Using this name other plugins will be able to access other plugins
55
+	 * using DAV\Server::getPlugin
56
+	 *
57
+	 * @return string
58
+	 */
59
+	public function getPluginName() {
60
+
61
+		return 'partialupdate';
62
+
63
+	}
64
+
65
+	/**
66
+	 * Use this method to tell the server this plugin defines additional
67
+	 * HTTP methods.
68
+	 *
69
+	 * This method is passed a uri. It should only return HTTP methods that are
70
+	 * available for the specified uri.
71
+	 *
72
+	 * We claim to support PATCH method (partirl update) if and only if
73
+	 *     - the node exist
74
+	 *     - the node implements our partial update interface
75
+	 *
76
+	 * @param string $uri
77
+	 * @return array
78
+	 */
79
+	public function getHTTPMethods($uri) {
80
+
81
+		$tree = $this->server->tree;
82
+
83
+		if ($tree->nodeExists($uri)) {
84
+			$node = $tree->getNodeForPath($uri);
85
+			if ($node instanceof IPatchSupport) {
86
+				return ['PATCH'];
87
+			}
88
+		}
89
+		return [];
90
+
91
+	}
92
+
93
+	/**
94
+	 * Returns a list of features for the HTTP OPTIONS Dav: header.
95
+	 *
96
+	 * @return array
97
+	 */
98
+	public function getFeatures() {
99
+
100
+		return ['sabredav-partialupdate'];
101
+
102
+	}
103
+
104
+	/**
105
+	 * Patch an uri
106
+	 *
107
+	 * The WebDAV patch request can be used to modify only a part of an
108
+	 * existing resource. If the resource does not exist yet and the first
109
+	 * offset is not 0, the request fails
110
+	 *
111
+	 * @param RequestInterface $request
112
+	 * @param ResponseInterface $response
113
+	 * @return void
114
+	 */
115
+	public function httpPatch(RequestInterface $request, ResponseInterface $response) {
116
+
117
+		$path = $request->getPath();
118
+
119
+		// Get the node. Will throw a 404 if not found
120
+		$node = $this->server->tree->getNodeForPath($path);
121
+		if (!$node instanceof IPatchSupport) {
122
+			throw new DAV\Exception\MethodNotAllowed('The target resource does not support the PATCH method.');
123
+		}
124
+
125
+		$range = $this->getHTTPUpdateRange($request);
126
+
127
+		if (!$range) {
128
+			throw new DAV\Exception\BadRequest('No valid "X-Update-Range" found in the headers');
129
+		}
130
+
131
+		$contentType = strtolower(
132
+			$request->getHeader('Content-Type')
133
+		);
134
+
135
+		if ($contentType != 'application/x-sabredav-partialupdate') {
136
+			throw new DAV\Exception\UnsupportedMediaType('Unknown Content-Type header "' . $contentType . '"');
137
+		}
138
+
139
+		$len = $this->server->httpRequest->getHeader('Content-Length');
140
+		if (!$len) throw new DAV\Exception\LengthRequired('A Content-Length header is required');
141
+
142
+		switch ($range[0]) {
143
+			case self::RANGE_START :
144
+				// Calculate the end-range if it doesn't exist.
145
+				if (!$range[2]) {
146
+					$range[2] = $range[1] + $len - 1;
147
+				} else {
148
+					if ($range[2] < $range[1]) {
149
+						throw new DAV\Exception\RequestedRangeNotSatisfiable('The end offset (' . $range[2] . ') is lower than the start offset (' . $range[1] . ')');
150
+					}
151
+					if ($range[2] - $range[1] + 1 != $len) {
152
+						throw new DAV\Exception\RequestedRangeNotSatisfiable('Actual data length (' . $len . ') is not consistent with begin (' . $range[1] . ') and end (' . $range[2] . ') offsets');
153
+					}
154
+				}
155
+				break;
156
+		}
157
+
158
+		if (!$this->server->emit('beforeWriteContent', [$path, $node, null]))
159
+			return;
160
+
161
+		$body = $this->server->httpRequest->getBody();
162
+
163
+
164
+		$etag = $node->patch($body, $range[0], isset($range[1]) ? $range[1] : null);
165
+
166
+		$this->server->emit('afterWriteContent', [$path, $node]);
167
+
168
+		$response->setHeader('Content-Length', '0');
169
+		if ($etag) $response->setHeader('ETag', $etag);
170
+		$response->setStatus(204);
171
+
172
+		// Breaks the event chain
173
+		return false;
174
+
175
+	}
176
+
177
+	/**
178
+	 * Returns the HTTP custom range update header
179
+	 *
180
+	 * This method returns null if there is no well-formed HTTP range request
181
+	 * header. It returns array(1) if it was an append request, array(2,
182
+	 * $start, $end) if it's a start and end range, lastly it's array(3,
183
+	 * $endoffset) if the offset was negative, and should be calculated from
184
+	 * the end of the file.
185
+	 *
186
+	 * Examples:
187
+	 *
188
+	 * null - invalid
189
+	 * [1] - append
190
+	 * [2,10,15] - update bytes 10, 11, 12, 13, 14, 15
191
+	 * [2,10,null] - update bytes 10 until the end of the patch body
192
+	 * [3,-5] - update from 5 bytes from the end of the file.
193
+	 *
194
+	 * @param RequestInterface $request
195
+	 * @return array|null
196
+	 */
197
+	public function getHTTPUpdateRange(RequestInterface $request) {
198
+
199
+		$range = $request->getHeader('X-Update-Range');
200
+		if (is_null($range)) return null;
201
+
202
+		// Matching "Range: bytes=1234-5678: both numbers are optional
203
+
204
+		if (!preg_match('/^(append)|(?:bytes=([0-9]+)-([0-9]*))|(?:bytes=(-[0-9]+))$/i', $range, $matches)) return null;
205
+
206
+		if ($matches[1] === 'append') {
207
+			return [self::RANGE_APPEND];
208
+		} elseif (strlen($matches[2]) > 0) {
209
+			return [self::RANGE_START, $matches[2], $matches[3] ?: null];
210
+		} else {
211
+			return [self::RANGE_END, $matches[4]];
212
+		}
213
+
214
+	}
215 215
 }
Please login to merge, or discard this patch.
libraries/SabreDAV/DAV/PartialUpdate/IPatchSupport.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -15,33 +15,33 @@
 block discarded – undo
15 15
  */
16 16
 interface IPatchSupport extends DAV\IFile {
17 17
 
18
-    /**
19
-     * Updates the file based on a range specification.
20
-     *
21
-     * The first argument is the data, which is either a readable stream
22
-     * resource or a string.
23
-     *
24
-     * The second argument is the type of update we're doing.
25
-     * This is either:
26
-     * * 1. append
27
-     * * 2. update based on a start byte
28
-     * * 3. update based on an end byte
29
-     *;
30
-     * The third argument is the start or end byte.
31
-     *
32
-     * After a successful put operation, you may choose to return an ETag. The
33
-     * etag must always be surrounded by double-quotes. These quotes must
34
-     * appear in the actual string you're returning.
35
-     *
36
-     * Clients may use the ETag from a PUT request to later on make sure that
37
-     * when they update the file, the contents haven't changed in the mean
38
-     * time.
39
-     *
40
-     * @param resource|string $data
41
-     * @param int $rangeType
42
-     * @param int $offset
43
-     * @return string|null
44
-     */
45
-    public function patch($data, $rangeType, $offset = null);
18
+	/**
19
+	 * Updates the file based on a range specification.
20
+	 *
21
+	 * The first argument is the data, which is either a readable stream
22
+	 * resource or a string.
23
+	 *
24
+	 * The second argument is the type of update we're doing.
25
+	 * This is either:
26
+	 * * 1. append
27
+	 * * 2. update based on a start byte
28
+	 * * 3. update based on an end byte
29
+	 *;
30
+	 * The third argument is the start or end byte.
31
+	 *
32
+	 * After a successful put operation, you may choose to return an ETag. The
33
+	 * etag must always be surrounded by double-quotes. These quotes must
34
+	 * appear in the actual string you're returning.
35
+	 *
36
+	 * Clients may use the ETag from a PUT request to later on make sure that
37
+	 * when they update the file, the contents haven't changed in the mean
38
+	 * time.
39
+	 *
40
+	 * @param resource|string $data
41
+	 * @param int $rangeType
42
+	 * @param int $offset
43
+	 * @return string|null
44
+	 */
45
+	public function patch($data, $rangeType, $offset = null);
46 46
 
47 47
 }
Please login to merge, or discard this patch.
libraries/SabreDAV/DAV/IMoveTarget.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -19,26 +19,26 @@
 block discarded – undo
19 19
  */
20 20
 interface IMoveTarget extends ICollection {
21 21
 
22
-    /**
23
-     * Moves a node into this collection.
24
-     *
25
-     * It is up to the implementors to:
26
-     *   1. Create the new resource.
27
-     *   2. Remove the old resource.
28
-     *   3. Transfer any properties or other data.
29
-     *
30
-     * Generally you should make very sure that your collection can easily move
31
-     * the move.
32
-     *
33
-     * If you don't, just return false, which will trigger sabre/dav to handle
34
-     * the move itself. If you return true from this function, the assumption
35
-     * is that the move was successful.
36
-     *
37
-     * @param string $targetName New local file/collection name.
38
-     * @param string $sourcePath Full path to source node
39
-     * @param INode $sourceNode Source node itself
40
-     * @return bool
41
-     */
42
-    public function moveInto($targetName, $sourcePath, INode $sourceNode);
22
+	/**
23
+	 * Moves a node into this collection.
24
+	 *
25
+	 * It is up to the implementors to:
26
+	 *   1. Create the new resource.
27
+	 *   2. Remove the old resource.
28
+	 *   3. Transfer any properties or other data.
29
+	 *
30
+	 * Generally you should make very sure that your collection can easily move
31
+	 * the move.
32
+	 *
33
+	 * If you don't, just return false, which will trigger sabre/dav to handle
34
+	 * the move itself. If you return true from this function, the assumption
35
+	 * is that the move was successful.
36
+	 *
37
+	 * @param string $targetName New local file/collection name.
38
+	 * @param string $sourcePath Full path to source node
39
+	 * @param INode $sourceNode Source node itself
40
+	 * @return bool
41
+	 */
42
+	public function moveInto($targetName, $sourcePath, INode $sourceNode);
43 43
 
44 44
 }
Please login to merge, or discard this patch.
libraries/SabreDAV/DAV/IProperties.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -13,35 +13,35 @@
 block discarded – undo
13 13
  */
14 14
 interface IProperties extends INode {
15 15
 
16
-    /**
17
-     * Updates properties on this node.
18
-     *
19
-     * This method received a PropPatch object, which contains all the
20
-     * information about the update.
21
-     *
22
-     * To update specific properties, call the 'handle' method on this object.
23
-     * Read the PropPatch documentation for more information.
24
-     *
25
-     * @param PropPatch $propPatch
26
-     * @return void
27
-     */
28
-    public function propPatch(PropPatch $propPatch);
16
+	/**
17
+	 * Updates properties on this node.
18
+	 *
19
+	 * This method received a PropPatch object, which contains all the
20
+	 * information about the update.
21
+	 *
22
+	 * To update specific properties, call the 'handle' method on this object.
23
+	 * Read the PropPatch documentation for more information.
24
+	 *
25
+	 * @param PropPatch $propPatch
26
+	 * @return void
27
+	 */
28
+	public function propPatch(PropPatch $propPatch);
29 29
 
30
-    /**
31
-     * Returns a list of properties for this nodes.
32
-     *
33
-     * The properties list is a list of propertynames the client requested,
34
-     * encoded in clark-notation {xmlnamespace}tagname
35
-     *
36
-     * If the array is empty, it means 'all properties' were requested.
37
-     *
38
-     * Note that it's fine to liberally give properties back, instead of
39
-     * conforming to the list of requested properties.
40
-     * The Server class will filter out the extra.
41
-     *
42
-     * @param array $properties
43
-     * @return array
44
-     */
45
-    public function getProperties($properties);
30
+	/**
31
+	 * Returns a list of properties for this nodes.
32
+	 *
33
+	 * The properties list is a list of propertynames the client requested,
34
+	 * encoded in clark-notation {xmlnamespace}tagname
35
+	 *
36
+	 * If the array is empty, it means 'all properties' were requested.
37
+	 *
38
+	 * Note that it's fine to liberally give properties back, instead of
39
+	 * conforming to the list of requested properties.
40
+	 * The Server class will filter out the extra.
41
+	 *
42
+	 * @param array $properties
43
+	 * @return array
44
+	 */
45
+	public function getProperties($properties);
46 46
 
47 47
 }
Please login to merge, or discard this patch.
libraries/SabreDAV/DAV/PropertyStorage/Backend/BackendInterface.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -17,64 +17,64 @@
 block discarded – undo
17 17
  */
18 18
 interface BackendInterface {
19 19
 
20
-    /**
21
-     * Fetches properties for a path.
22
-     *
23
-     * This method received a PropFind object, which contains all the
24
-     * information about the properties that need to be fetched.
25
-     *
26
-     * Ususually you would just want to call 'get404Properties' on this object,
27
-     * as this will give you the _exact_ list of properties that need to be
28
-     * fetched, and haven't yet.
29
-     *
30
-     * However, you can also support the 'allprops' property here. In that
31
-     * case, you should check for $propFind->isAllProps().
32
-     *
33
-     * @param string $path
34
-     * @param PropFind $propFind
35
-     * @return void
36
-     */
37
-    public function propFind($path, PropFind $propFind);
20
+	/**
21
+	 * Fetches properties for a path.
22
+	 *
23
+	 * This method received a PropFind object, which contains all the
24
+	 * information about the properties that need to be fetched.
25
+	 *
26
+	 * Ususually you would just want to call 'get404Properties' on this object,
27
+	 * as this will give you the _exact_ list of properties that need to be
28
+	 * fetched, and haven't yet.
29
+	 *
30
+	 * However, you can also support the 'allprops' property here. In that
31
+	 * case, you should check for $propFind->isAllProps().
32
+	 *
33
+	 * @param string $path
34
+	 * @param PropFind $propFind
35
+	 * @return void
36
+	 */
37
+	public function propFind($path, PropFind $propFind);
38 38
 
39
-    /**
40
-     * Updates properties for a path
41
-     *
42
-     * This method received a PropPatch object, which contains all the
43
-     * information about the update.
44
-     *
45
-     * Usually you would want to call 'handleRemaining' on this object, to get;
46
-     * a list of all properties that need to be stored.
47
-     *
48
-     * @param string $path
49
-     * @param PropPatch $propPatch
50
-     * @return void
51
-     */
52
-    public function propPatch($path, PropPatch $propPatch);
39
+	/**
40
+	 * Updates properties for a path
41
+	 *
42
+	 * This method received a PropPatch object, which contains all the
43
+	 * information about the update.
44
+	 *
45
+	 * Usually you would want to call 'handleRemaining' on this object, to get;
46
+	 * a list of all properties that need to be stored.
47
+	 *
48
+	 * @param string $path
49
+	 * @param PropPatch $propPatch
50
+	 * @return void
51
+	 */
52
+	public function propPatch($path, PropPatch $propPatch);
53 53
 
54
-    /**
55
-     * This method is called after a node is deleted.
56
-     *
57
-     * This allows a backend to clean up all associated properties.
58
-     *
59
-     * The delete method will get called once for the deletion of an entire
60
-     * tree.
61
-     *
62
-     * @param string $path
63
-     * @return void
64
-     */
65
-    public function delete($path);
54
+	/**
55
+	 * This method is called after a node is deleted.
56
+	 *
57
+	 * This allows a backend to clean up all associated properties.
58
+	 *
59
+	 * The delete method will get called once for the deletion of an entire
60
+	 * tree.
61
+	 *
62
+	 * @param string $path
63
+	 * @return void
64
+	 */
65
+	public function delete($path);
66 66
 
67
-    /**
68
-     * This method is called after a successful MOVE
69
-     *
70
-     * This should be used to migrate all properties from one path to another.
71
-     * Note that entire collections may be moved, so ensure that all properties
72
-     * for children are also moved along.
73
-     *
74
-     * @param string $source
75
-     * @param string $destination
76
-     * @return void
77
-     */
78
-    public function move($source, $destination);
67
+	/**
68
+	 * This method is called after a successful MOVE
69
+	 *
70
+	 * This should be used to migrate all properties from one path to another.
71
+	 * Note that entire collections may be moved, so ensure that all properties
72
+	 * for children are also moved along.
73
+	 *
74
+	 * @param string $source
75
+	 * @param string $destination
76
+	 * @return void
77
+	 */
78
+	public function move($source, $destination);
79 79
 
80 80
 }
Please login to merge, or discard this patch.
libraries/SabreDAV/DAV/PropertyStorage/Backend/PDO.php 1 patch
Indentation   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -20,198 +20,198 @@
 block discarded – undo
20 20
  */
21 21
 class PDO implements BackendInterface {
22 22
 
23
-    /**
24
-     * Value is stored as string.
25
-     */
26
-    const VT_STRING = 1;
27
-
28
-    /**
29
-     * Value is stored as XML fragment.
30
-     */
31
-    const VT_XML = 2;
32
-
33
-    /**
34
-     * Value is stored as a property object.
35
-     */
36
-    const VT_OBJECT = 3;
37
-
38
-    /**
39
-     * PDO
40
-     *
41
-     * @var \PDO
42
-     */
43
-    protected $pdo;
44
-
45
-    /**
46
-     * PDO table name we'll be using
47
-     *
48
-     * @var string
49
-     */
50
-    public $tableName = 'propertystorage';
51
-
52
-    /**
53
-     * Creates the PDO property storage engine
54
-     *
55
-     * @param \PDO $pdo
56
-     */
57
-    public function __construct(\PDO $pdo) {
58
-
59
-        $this->pdo = $pdo;
60
-
61
-    }
62
-
63
-    /**
64
-     * Fetches properties for a path.
65
-     *
66
-     * This method received a PropFind object, which contains all the
67
-     * information about the properties that need to be fetched.
68
-     *
69
-     * Ususually you would just want to call 'get404Properties' on this object,
70
-     * as this will give you the _exact_ list of properties that need to be
71
-     * fetched, and haven't yet.
72
-     *
73
-     * However, you can also support the 'allprops' property here. In that
74
-     * case, you should check for $propFind->isAllProps().
75
-     *
76
-     * @param string $path
77
-     * @param PropFind $propFind
78
-     * @return void
79
-     */
80
-    public function propFind($path, PropFind $propFind) {
81
-
82
-        if (!$propFind->isAllProps() && count($propFind->get404Properties()) === 0) {
83
-            return;
84
-        }
85
-
86
-        $query = sprintf('SELECT name, value, valuetype FROM %s WHERE path = ?', $this->tableName);
87
-        $stmt = $this->pdo->prepare($query);
88
-        $stmt->execute([$path]);
89
-
90
-        while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
91
-            switch ($row['valuetype']) {
92
-                case null :
93
-                case self::VT_STRING :
94
-                    $propFind->set($row['name'], $row['value']);
95
-                    break;
96
-                case self::VT_XML :
97
-                    $propFind->set($row['name'], new Complex($row['value']));
98
-                    break;
99
-                case self::VT_OBJECT :
100
-                    $propFind->set($row['name'], unserialize($row['value']));
101
-                    break;
102
-            }
103
-        }
104
-
105
-    }
106
-
107
-    /**
108
-     * Updates properties for a path
109
-     *
110
-     * This method received a PropPatch object, which contains all the
111
-     * information about the update.
112
-     *
113
-     * Usually you would want to call 'handleRemaining' on this object, to get;
114
-     * a list of all properties that need to be stored.
115
-     *
116
-     * @param string $path
117
-     * @param PropPatch $propPatch
118
-     * @return void
119
-     */
120
-    public function propPatch($path, PropPatch $propPatch) {
121
-
122
-        $propPatch->handleRemaining(function($properties) use ($path) {
123
-
124
-            $updateStmt = $this->pdo->prepare("REPLACE INTO " . $this->tableName . " (path, name, valuetype, value) VALUES (?, ?, ?, ?)");
125
-            $deleteStmt = $this->pdo->prepare(sprintf("DELETE FROM %s WHERE path = ? && name = ?", $this->tableName));
126
-
127
-            foreach ($properties as $name => $value) {
128
-
129
-                if (!is_null($value)) {
130
-                    if (is_scalar($value)) {
131
-                        $valueType = self::VT_STRING;
132
-                    } elseif ($value instanceof Complex) {
133
-                        $valueType = self::VT_XML;
134
-                        $value = $value->getXml();
135
-                    } else {
136
-                        $valueType = self::VT_OBJECT;
137
-                        $value = serialize($value);
138
-                    }
139
-                    $updateStmt->execute([$path, $name, $valueType, $value]);
140
-                } else {
141
-                    $deleteStmt->execute([$path, $name]);
142
-                }
143
-
144
-            }
145
-
146
-            return true;
147
-
148
-        });
149
-
150
-    }
151
-
152
-    /**
153
-     * This method is called after a node is deleted.
154
-     *
155
-     * This allows a backend to clean up all associated properties.
156
-     *
157
-     * The delete method will get called once for the deletion of an entire
158
-     * tree.
159
-     *
160
-     * @param string $path
161
-     * @return void
162
-     */
163
-    public function delete($path) {
164
-
165
-        $stmt = $this->pdo->prepare(sprintf("DELETE FROM %s  WHERE path = ? || path LIKE ? ESCAPE '='", $this->tableName));
166
-        $childPath = strtr(
167
-            $path,
168
-            [
169
-                '=' => '==',
170
-                '%' => '=%',
171
-                '_' => '=_'
172
-            ]
173
-        ) . '/%';
174
-
175
-        $stmt->execute([$path, $childPath]);
176
-
177
-    }
178
-
179
-    /**
180
-     * This method is called after a successful MOVE
181
-     *
182
-     * This should be used to migrate all properties from one path to another.
183
-     * Note that entire collections may be moved, so ensure that all properties
184
-     * for children are also moved along.
185
-     *
186
-     * @param string $source
187
-     * @param string $destination
188
-     * @return void
189
-     */
190
-    public function move($source, $destination) {
191
-
192
-        // I don't know a way to write this all in a single sql query that's
193
-        // also compatible across db engines, so we're letting PHP do all the
194
-        // updates. Much slower, but it should still be pretty fast in most
195
-        // cases.
196
-        $select = $this->pdo->prepare(sprintf('SELECT id, path FROM %s WHERE path = ? || path LIKE ?', $this->tableName));
197
-        $select->execute([$source, $source . '/%']);
198
-
199
-        $update = $this->pdo->prepare(sprintf('UPDATE %s SET path = ? WHERE id = ?', $this->tableName));
200
-        while ($row = $select->fetch(\PDO::FETCH_ASSOC)) {
201
-
202
-            // Sanity check. SQL may select too many records, such as records
203
-            // with different cases.
204
-            if ($row['path'] !== $source && strpos($row['path'], $source . '/') !== 0) continue;
205
-
206
-            $trailingPart = substr($row['path'], strlen($source) + 1);
207
-            $newPath = $destination;
208
-            if ($trailingPart) {
209
-                $newPath .= '/' . $trailingPart;
210
-            }
211
-            $update->execute([$newPath, $row['id']]);
212
-
213
-        }
214
-
215
-    }
23
+	/**
24
+	 * Value is stored as string.
25
+	 */
26
+	const VT_STRING = 1;
27
+
28
+	/**
29
+	 * Value is stored as XML fragment.
30
+	 */
31
+	const VT_XML = 2;
32
+
33
+	/**
34
+	 * Value is stored as a property object.
35
+	 */
36
+	const VT_OBJECT = 3;
37
+
38
+	/**
39
+	 * PDO
40
+	 *
41
+	 * @var \PDO
42
+	 */
43
+	protected $pdo;
44
+
45
+	/**
46
+	 * PDO table name we'll be using
47
+	 *
48
+	 * @var string
49
+	 */
50
+	public $tableName = 'propertystorage';
51
+
52
+	/**
53
+	 * Creates the PDO property storage engine
54
+	 *
55
+	 * @param \PDO $pdo
56
+	 */
57
+	public function __construct(\PDO $pdo) {
58
+
59
+		$this->pdo = $pdo;
60
+
61
+	}
62
+
63
+	/**
64
+	 * Fetches properties for a path.
65
+	 *
66
+	 * This method received a PropFind object, which contains all the
67
+	 * information about the properties that need to be fetched.
68
+	 *
69
+	 * Ususually you would just want to call 'get404Properties' on this object,
70
+	 * as this will give you the _exact_ list of properties that need to be
71
+	 * fetched, and haven't yet.
72
+	 *
73
+	 * However, you can also support the 'allprops' property here. In that
74
+	 * case, you should check for $propFind->isAllProps().
75
+	 *
76
+	 * @param string $path
77
+	 * @param PropFind $propFind
78
+	 * @return void
79
+	 */
80
+	public function propFind($path, PropFind $propFind) {
81
+
82
+		if (!$propFind->isAllProps() && count($propFind->get404Properties()) === 0) {
83
+			return;
84
+		}
85
+
86
+		$query = sprintf('SELECT name, value, valuetype FROM %s WHERE path = ?', $this->tableName);
87
+		$stmt = $this->pdo->prepare($query);
88
+		$stmt->execute([$path]);
89
+
90
+		while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
91
+			switch ($row['valuetype']) {
92
+				case null :
93
+				case self::VT_STRING :
94
+					$propFind->set($row['name'], $row['value']);
95
+					break;
96
+				case self::VT_XML :
97
+					$propFind->set($row['name'], new Complex($row['value']));
98
+					break;
99
+				case self::VT_OBJECT :
100
+					$propFind->set($row['name'], unserialize($row['value']));
101
+					break;
102
+			}
103
+		}
104
+
105
+	}
106
+
107
+	/**
108
+	 * Updates properties for a path
109
+	 *
110
+	 * This method received a PropPatch object, which contains all the
111
+	 * information about the update.
112
+	 *
113
+	 * Usually you would want to call 'handleRemaining' on this object, to get;
114
+	 * a list of all properties that need to be stored.
115
+	 *
116
+	 * @param string $path
117
+	 * @param PropPatch $propPatch
118
+	 * @return void
119
+	 */
120
+	public function propPatch($path, PropPatch $propPatch) {
121
+
122
+		$propPatch->handleRemaining(function($properties) use ($path) {
123
+
124
+			$updateStmt = $this->pdo->prepare("REPLACE INTO " . $this->tableName . " (path, name, valuetype, value) VALUES (?, ?, ?, ?)");
125
+			$deleteStmt = $this->pdo->prepare(sprintf("DELETE FROM %s WHERE path = ? && name = ?", $this->tableName));
126
+
127
+			foreach ($properties as $name => $value) {
128
+
129
+				if (!is_null($value)) {
130
+					if (is_scalar($value)) {
131
+						$valueType = self::VT_STRING;
132
+					} elseif ($value instanceof Complex) {
133
+						$valueType = self::VT_XML;
134
+						$value = $value->getXml();
135
+					} else {
136
+						$valueType = self::VT_OBJECT;
137
+						$value = serialize($value);
138
+					}
139
+					$updateStmt->execute([$path, $name, $valueType, $value]);
140
+				} else {
141
+					$deleteStmt->execute([$path, $name]);
142
+				}
143
+
144
+			}
145
+
146
+			return true;
147
+
148
+		});
149
+
150
+	}
151
+
152
+	/**
153
+	 * This method is called after a node is deleted.
154
+	 *
155
+	 * This allows a backend to clean up all associated properties.
156
+	 *
157
+	 * The delete method will get called once for the deletion of an entire
158
+	 * tree.
159
+	 *
160
+	 * @param string $path
161
+	 * @return void
162
+	 */
163
+	public function delete($path) {
164
+
165
+		$stmt = $this->pdo->prepare(sprintf("DELETE FROM %s  WHERE path = ? || path LIKE ? ESCAPE '='", $this->tableName));
166
+		$childPath = strtr(
167
+			$path,
168
+			[
169
+				'=' => '==',
170
+				'%' => '=%',
171
+				'_' => '=_'
172
+			]
173
+		) . '/%';
174
+
175
+		$stmt->execute([$path, $childPath]);
176
+
177
+	}
178
+
179
+	/**
180
+	 * This method is called after a successful MOVE
181
+	 *
182
+	 * This should be used to migrate all properties from one path to another.
183
+	 * Note that entire collections may be moved, so ensure that all properties
184
+	 * for children are also moved along.
185
+	 *
186
+	 * @param string $source
187
+	 * @param string $destination
188
+	 * @return void
189
+	 */
190
+	public function move($source, $destination) {
191
+
192
+		// I don't know a way to write this all in a single sql query that's
193
+		// also compatible across db engines, so we're letting PHP do all the
194
+		// updates. Much slower, but it should still be pretty fast in most
195
+		// cases.
196
+		$select = $this->pdo->prepare(sprintf('SELECT id, path FROM %s WHERE path = ? || path LIKE ?', $this->tableName));
197
+		$select->execute([$source, $source . '/%']);
198
+
199
+		$update = $this->pdo->prepare(sprintf('UPDATE %s SET path = ? WHERE id = ?', $this->tableName));
200
+		while ($row = $select->fetch(\PDO::FETCH_ASSOC)) {
201
+
202
+			// Sanity check. SQL may select too many records, such as records
203
+			// with different cases.
204
+			if ($row['path'] !== $source && strpos($row['path'], $source . '/') !== 0) continue;
205
+
206
+			$trailingPart = substr($row['path'], strlen($source) + 1);
207
+			$newPath = $destination;
208
+			if ($trailingPart) {
209
+				$newPath .= '/' . $trailingPart;
210
+			}
211
+			$update->execute([$newPath, $row['id']]);
212
+
213
+		}
214
+
215
+	}
216 216
 
217 217
 }
Please login to merge, or discard this patch.
libraries/SabreDAV/DAV/PropertyStorage/Plugin.php 1 patch
Indentation   +152 added lines, -152 removed lines patch added patch discarded remove patch
@@ -25,156 +25,156 @@
 block discarded – undo
25 25
  */
26 26
 class Plugin extends ServerPlugin {
27 27
 
28
-    /**
29
-     * If you only want this plugin to store properties for a limited set of
30
-     * paths, you can use a pathFilter to do this.
31
-     *
32
-     * The pathFilter should be a callable. The callable retrieves a path as
33
-     * its argument, and should return true or false wether it allows
34
-     * properties to be stored.
35
-     *
36
-     * @var callable
37
-     */
38
-    public $pathFilter;
39
-
40
-    /**
41
-     * Creates the plugin
42
-     *
43
-     * @param Backend\BackendInterface $backend
44
-     */
45
-    public function __construct(Backend\BackendInterface $backend) {
46
-
47
-        $this->backend = $backend;
48
-
49
-    }
50
-
51
-    /**
52
-     * This initializes the plugin.
53
-     *
54
-     * This function is called by Sabre\DAV\Server, after
55
-     * addPlugin is called.
56
-     *
57
-     * This method should set up the required event subscriptions.
58
-     *
59
-     * @param Server $server
60
-     * @return void
61
-     */
62
-    public function initialize(Server $server) {
63
-
64
-        $server->on('propFind',    [$this, 'propFind'], 130);
65
-        $server->on('propPatch',   [$this, 'propPatch'], 300);
66
-        $server->on('afterMove',   [$this, 'afterMove']);
67
-        $server->on('afterUnbind', [$this, 'afterUnbind']);
68
-
69
-    }
70
-
71
-    /**
72
-     * Called during PROPFIND operations.
73
-     *
74
-     * If there's any requested properties that don't have a value yet, this
75
-     * plugin will look in the property storage backend to find them.
76
-     *
77
-     * @param PropFind $propFind
78
-     * @param INode $node
79
-     * @return void
80
-     */
81
-    public function propFind(PropFind $propFind, INode $node) {
82
-
83
-        $path = $propFind->getPath();
84
-        $pathFilter = $this->pathFilter;
85
-        if ($pathFilter && !$pathFilter($path)) return;
86
-        $this->backend->propFind($propFind->getPath(), $propFind);
87
-
88
-    }
89
-
90
-    /**
91
-     * Called during PROPPATCH operations
92
-     *
93
-     * If there's any updated properties that haven't been stored, the
94
-     * propertystorage backend can handle it.
95
-     *
96
-     * @param string $path
97
-     * @param PropPatch $propPatch
98
-     * @return void
99
-     */
100
-    public function propPatch($path, PropPatch $propPatch) {
101
-
102
-        $pathFilter = $this->pathFilter;
103
-        if ($pathFilter && !$pathFilter($path)) return;
104
-        $this->backend->propPatch($path, $propPatch);
105
-
106
-    }
107
-
108
-    /**
109
-     * Called after a node is deleted.
110
-     *
111
-     * This allows the backend to clean up any properties still in the
112
-     * database.
113
-     *
114
-     * @param string $path
115
-     * @return void
116
-     */
117
-    public function afterUnbind($path) {
118
-
119
-        $pathFilter = $this->pathFilter;
120
-        if ($pathFilter && !$pathFilter($path)) return;
121
-        $this->backend->delete($path);
122
-
123
-    }
124
-
125
-    /**
126
-     * Called after a node is moved.
127
-     *
128
-     * This allows the backend to move all the associated properties.
129
-     *
130
-     * @param string $source
131
-     * @param string $destination
132
-     * @return void
133
-     */
134
-    public function afterMove($source, $destination) {
135
-
136
-        $pathFilter = $this->pathFilter;
137
-        if ($pathFilter && !$pathFilter($source)) return;
138
-        // If the destination is filtered, afterUnbind will handle cleaning up
139
-        // the properties.
140
-        if ($pathFilter && !$pathFilter($destination)) return;
141
-
142
-        $this->backend->move($source, $destination);
143
-
144
-    }
145
-
146
-    /**
147
-     * Returns a plugin name.
148
-     *
149
-     * Using this name other plugins will be able to access other plugins
150
-     * using \Sabre\DAV\Server::getPlugin
151
-     *
152
-     * @return string
153
-     */
154
-    public function getPluginName() {
155
-
156
-        return 'property-storage';
157
-
158
-    }
159
-
160
-    /**
161
-     * Returns a bunch of meta-data about the plugin.
162
-     *
163
-     * Providing this information is optional, and is mainly displayed by the
164
-     * Browser plugin.
165
-     *
166
-     * The description key in the returned array may contain html and will not
167
-     * be sanitized.
168
-     *
169
-     * @return array
170
-     */
171
-    public function getPluginInfo() {
172
-
173
-        return [
174
-            'name'        => $this->getPluginName(),
175
-            'description' => 'This plugin allows any arbitrary WebDAV property to be set on any resource.',
176
-            'link'        => 'http://sabre.io/dav/property-storage/',
177
-        ];
178
-
179
-    }
28
+	/**
29
+	 * If you only want this plugin to store properties for a limited set of
30
+	 * paths, you can use a pathFilter to do this.
31
+	 *
32
+	 * The pathFilter should be a callable. The callable retrieves a path as
33
+	 * its argument, and should return true or false wether it allows
34
+	 * properties to be stored.
35
+	 *
36
+	 * @var callable
37
+	 */
38
+	public $pathFilter;
39
+
40
+	/**
41
+	 * Creates the plugin
42
+	 *
43
+	 * @param Backend\BackendInterface $backend
44
+	 */
45
+	public function __construct(Backend\BackendInterface $backend) {
46
+
47
+		$this->backend = $backend;
48
+
49
+	}
50
+
51
+	/**
52
+	 * This initializes the plugin.
53
+	 *
54
+	 * This function is called by Sabre\DAV\Server, after
55
+	 * addPlugin is called.
56
+	 *
57
+	 * This method should set up the required event subscriptions.
58
+	 *
59
+	 * @param Server $server
60
+	 * @return void
61
+	 */
62
+	public function initialize(Server $server) {
63
+
64
+		$server->on('propFind',    [$this, 'propFind'], 130);
65
+		$server->on('propPatch',   [$this, 'propPatch'], 300);
66
+		$server->on('afterMove',   [$this, 'afterMove']);
67
+		$server->on('afterUnbind', [$this, 'afterUnbind']);
68
+
69
+	}
70
+
71
+	/**
72
+	 * Called during PROPFIND operations.
73
+	 *
74
+	 * If there's any requested properties that don't have a value yet, this
75
+	 * plugin will look in the property storage backend to find them.
76
+	 *
77
+	 * @param PropFind $propFind
78
+	 * @param INode $node
79
+	 * @return void
80
+	 */
81
+	public function propFind(PropFind $propFind, INode $node) {
82
+
83
+		$path = $propFind->getPath();
84
+		$pathFilter = $this->pathFilter;
85
+		if ($pathFilter && !$pathFilter($path)) return;
86
+		$this->backend->propFind($propFind->getPath(), $propFind);
87
+
88
+	}
89
+
90
+	/**
91
+	 * Called during PROPPATCH operations
92
+	 *
93
+	 * If there's any updated properties that haven't been stored, the
94
+	 * propertystorage backend can handle it.
95
+	 *
96
+	 * @param string $path
97
+	 * @param PropPatch $propPatch
98
+	 * @return void
99
+	 */
100
+	public function propPatch($path, PropPatch $propPatch) {
101
+
102
+		$pathFilter = $this->pathFilter;
103
+		if ($pathFilter && !$pathFilter($path)) return;
104
+		$this->backend->propPatch($path, $propPatch);
105
+
106
+	}
107
+
108
+	/**
109
+	 * Called after a node is deleted.
110
+	 *
111
+	 * This allows the backend to clean up any properties still in the
112
+	 * database.
113
+	 *
114
+	 * @param string $path
115
+	 * @return void
116
+	 */
117
+	public function afterUnbind($path) {
118
+
119
+		$pathFilter = $this->pathFilter;
120
+		if ($pathFilter && !$pathFilter($path)) return;
121
+		$this->backend->delete($path);
122
+
123
+	}
124
+
125
+	/**
126
+	 * Called after a node is moved.
127
+	 *
128
+	 * This allows the backend to move all the associated properties.
129
+	 *
130
+	 * @param string $source
131
+	 * @param string $destination
132
+	 * @return void
133
+	 */
134
+	public function afterMove($source, $destination) {
135
+
136
+		$pathFilter = $this->pathFilter;
137
+		if ($pathFilter && !$pathFilter($source)) return;
138
+		// If the destination is filtered, afterUnbind will handle cleaning up
139
+		// the properties.
140
+		if ($pathFilter && !$pathFilter($destination)) return;
141
+
142
+		$this->backend->move($source, $destination);
143
+
144
+	}
145
+
146
+	/**
147
+	 * Returns a plugin name.
148
+	 *
149
+	 * Using this name other plugins will be able to access other plugins
150
+	 * using \Sabre\DAV\Server::getPlugin
151
+	 *
152
+	 * @return string
153
+	 */
154
+	public function getPluginName() {
155
+
156
+		return 'property-storage';
157
+
158
+	}
159
+
160
+	/**
161
+	 * Returns a bunch of meta-data about the plugin.
162
+	 *
163
+	 * Providing this information is optional, and is mainly displayed by the
164
+	 * Browser plugin.
165
+	 *
166
+	 * The description key in the returned array may contain html and will not
167
+	 * be sanitized.
168
+	 *
169
+	 * @return array
170
+	 */
171
+	public function getPluginInfo() {
172
+
173
+		return [
174
+			'name'        => $this->getPluginName(),
175
+			'description' => 'This plugin allows any arbitrary WebDAV property to be set on any resource.',
176
+			'link'        => 'http://sabre.io/dav/property-storage/',
177
+		];
178
+
179
+	}
180 180
 }
Please login to merge, or discard this patch.
libraries/SabreDAV/DAV/INode.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -11,35 +11,35 @@
 block discarded – undo
11 11
  */
12 12
 interface INode {
13 13
 
14
-    /**
15
-     * Deleted the current node
16
-     *
17
-     * @return void
18
-     */
19
-    public function delete();
14
+	/**
15
+	 * Deleted the current node
16
+	 *
17
+	 * @return void
18
+	 */
19
+	public function delete();
20 20
 
21
-    /**
22
-     * Returns the name of the node.
23
-     *
24
-     * This is used to generate the url.
25
-     *
26
-     * @return string
27
-     */
28
-    public function getName();
21
+	/**
22
+	 * Returns the name of the node.
23
+	 *
24
+	 * This is used to generate the url.
25
+	 *
26
+	 * @return string
27
+	 */
28
+	public function getName();
29 29
 
30
-    /**
31
-     * Renames the node
32
-     *
33
-     * @param string $name The new name
34
-     * @return void
35
-     */
36
-    public function setName($name);
30
+	/**
31
+	 * Renames the node
32
+	 *
33
+	 * @param string $name The new name
34
+	 * @return void
35
+	 */
36
+	public function setName($name);
37 37
 
38
-    /**
39
-     * Returns the last modification time, as a unix timestamp
40
-     *
41
-     * @return int
42
-     */
43
-    public function getLastModified();
38
+	/**
39
+	 * Returns the last modification time, as a unix timestamp
40
+	 *
41
+	 * @return int
42
+	 */
43
+	public function getLastModified();
44 44
 
45 45
 }
Please login to merge, or discard this patch.
libraries/SabreDAV/DAV/Locks/Backend/File.php 1 patch
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -19,167 +19,167 @@
 block discarded – undo
19 19
  */
20 20
 class File extends AbstractBackend {
21 21
 
22
-    /**
23
-     * The storage file
24
-     *
25
-     * @var string
26
-     */
27
-    private $locksFile;
28
-
29
-    /**
30
-     * Constructor
31
-     *
32
-     * @param string $locksFile path to file
33
-     */
34
-    public function __construct($locksFile) {
35
-
36
-        $this->locksFile = $locksFile;
37
-
38
-    }
39
-
40
-    /**
41
-     * Returns a list of Sabre\DAV\Locks\LockInfo objects
42
-     *
43
-     * This method should return all the locks for a particular uri, including
44
-     * locks that might be set on a parent uri.
45
-     *
46
-     * If returnChildLocks is set to true, this method should also look for
47
-     * any locks in the subtree of the uri for locks.
48
-     *
49
-     * @param string $uri
50
-     * @param bool $returnChildLocks
51
-     * @return array
52
-     */
53
-    public function getLocks($uri, $returnChildLocks) {
54
-
55
-        $newLocks = [];
56
-
57
-        $locks = $this->getData();
58
-
59
-        foreach ($locks as $lock) {
60
-
61
-            if ($lock->uri === $uri ||
62
-                //deep locks on parents
63
-                ($lock->depth != 0 && strpos($uri, $lock->uri . '/') === 0) ||
64
-
65
-                // locks on children
66
-                ($returnChildLocks && (strpos($lock->uri, $uri . '/') === 0))) {
67
-
68
-                $newLocks[] = $lock;
69
-
70
-            }
71
-
72
-        }
73
-
74
-        // Checking if we can remove any of these locks
75
-        foreach ($newLocks as $k => $lock) {
76
-            if (time() > $lock->timeout + $lock->created) unset($newLocks[$k]);
77
-        }
78
-        return $newLocks;
79
-
80
-    }
81
-
82
-    /**
83
-     * Locks a uri
84
-     *
85
-     * @param string $uri
86
-     * @param LockInfo $lockInfo
87
-     * @return bool
88
-     */
89
-    public function lock($uri, LockInfo $lockInfo) {
90
-
91
-        // We're making the lock timeout 30 minutes
92
-        $lockInfo->timeout = 1800;
93
-        $lockInfo->created = time();
94
-        $lockInfo->uri = $uri;
95
-
96
-        $locks = $this->getData();
97
-
98
-        foreach ($locks as $k => $lock) {
99
-            if (
100
-                ($lock->token == $lockInfo->token) ||
101
-                (time() > $lock->timeout + $lock->created)
102
-            ) {
103
-                unset($locks[$k]);
104
-            }
105
-        }
106
-        $locks[] = $lockInfo;
107
-        $this->putData($locks);
108
-        return true;
109
-
110
-    }
111
-
112
-    /**
113
-     * Removes a lock from a uri
114
-     *
115
-     * @param string $uri
116
-     * @param LockInfo $lockInfo
117
-     * @return bool
118
-     */
119
-    public function unlock($uri, LockInfo $lockInfo) {
120
-
121
-        $locks = $this->getData();
122
-        foreach ($locks as $k => $lock) {
123
-
124
-            if ($lock->token == $lockInfo->token) {
125
-
126
-                unset($locks[$k]);
127
-                $this->putData($locks);
128
-                return true;
129
-
130
-            }
131
-        }
132
-        return false;
133
-
134
-    }
135
-
136
-    /**
137
-     * Loads the lockdata from the filesystem.
138
-     *
139
-     * @return array
140
-     */
141
-    protected function getData() {
142
-
143
-        if (!file_exists($this->locksFile)) return [];
144
-
145
-        // opening up the file, and creating a shared lock
146
-        $handle = fopen($this->locksFile, 'r');
147
-        flock($handle, LOCK_SH);
148
-
149
-        // Reading data until the eof
150
-        $data = stream_get_contents($handle);
22
+	/**
23
+	 * The storage file
24
+	 *
25
+	 * @var string
26
+	 */
27
+	private $locksFile;
28
+
29
+	/**
30
+	 * Constructor
31
+	 *
32
+	 * @param string $locksFile path to file
33
+	 */
34
+	public function __construct($locksFile) {
35
+
36
+		$this->locksFile = $locksFile;
37
+
38
+	}
39
+
40
+	/**
41
+	 * Returns a list of Sabre\DAV\Locks\LockInfo objects
42
+	 *
43
+	 * This method should return all the locks for a particular uri, including
44
+	 * locks that might be set on a parent uri.
45
+	 *
46
+	 * If returnChildLocks is set to true, this method should also look for
47
+	 * any locks in the subtree of the uri for locks.
48
+	 *
49
+	 * @param string $uri
50
+	 * @param bool $returnChildLocks
51
+	 * @return array
52
+	 */
53
+	public function getLocks($uri, $returnChildLocks) {
54
+
55
+		$newLocks = [];
56
+
57
+		$locks = $this->getData();
58
+
59
+		foreach ($locks as $lock) {
60
+
61
+			if ($lock->uri === $uri ||
62
+				//deep locks on parents
63
+				($lock->depth != 0 && strpos($uri, $lock->uri . '/') === 0) ||
64
+
65
+				// locks on children
66
+				($returnChildLocks && (strpos($lock->uri, $uri . '/') === 0))) {
67
+
68
+				$newLocks[] = $lock;
69
+
70
+			}
71
+
72
+		}
73
+
74
+		// Checking if we can remove any of these locks
75
+		foreach ($newLocks as $k => $lock) {
76
+			if (time() > $lock->timeout + $lock->created) unset($newLocks[$k]);
77
+		}
78
+		return $newLocks;
79
+
80
+	}
81
+
82
+	/**
83
+	 * Locks a uri
84
+	 *
85
+	 * @param string $uri
86
+	 * @param LockInfo $lockInfo
87
+	 * @return bool
88
+	 */
89
+	public function lock($uri, LockInfo $lockInfo) {
90
+
91
+		// We're making the lock timeout 30 minutes
92
+		$lockInfo->timeout = 1800;
93
+		$lockInfo->created = time();
94
+		$lockInfo->uri = $uri;
95
+
96
+		$locks = $this->getData();
97
+
98
+		foreach ($locks as $k => $lock) {
99
+			if (
100
+				($lock->token == $lockInfo->token) ||
101
+				(time() > $lock->timeout + $lock->created)
102
+			) {
103
+				unset($locks[$k]);
104
+			}
105
+		}
106
+		$locks[] = $lockInfo;
107
+		$this->putData($locks);
108
+		return true;
109
+
110
+	}
111
+
112
+	/**
113
+	 * Removes a lock from a uri
114
+	 *
115
+	 * @param string $uri
116
+	 * @param LockInfo $lockInfo
117
+	 * @return bool
118
+	 */
119
+	public function unlock($uri, LockInfo $lockInfo) {
120
+
121
+		$locks = $this->getData();
122
+		foreach ($locks as $k => $lock) {
123
+
124
+			if ($lock->token == $lockInfo->token) {
125
+
126
+				unset($locks[$k]);
127
+				$this->putData($locks);
128
+				return true;
129
+
130
+			}
131
+		}
132
+		return false;
133
+
134
+	}
135
+
136
+	/**
137
+	 * Loads the lockdata from the filesystem.
138
+	 *
139
+	 * @return array
140
+	 */
141
+	protected function getData() {
142
+
143
+		if (!file_exists($this->locksFile)) return [];
144
+
145
+		// opening up the file, and creating a shared lock
146
+		$handle = fopen($this->locksFile, 'r');
147
+		flock($handle, LOCK_SH);
148
+
149
+		// Reading data until the eof
150
+		$data = stream_get_contents($handle);
151 151
 
152
-        // We're all good
153
-        flock($handle, LOCK_UN);
154
-        fclose($handle);
152
+		// We're all good
153
+		flock($handle, LOCK_UN);
154
+		fclose($handle);
155 155
 
156
-        // Unserializing and checking if the resource file contains data for this file
157
-        $data = unserialize($data);
158
-        if (!$data) return [];
159
-        return $data;
160
-
161
-    }
162
-
163
-    /**
164
-     * Saves the lockdata
165
-     *
166
-     * @param array $newData
167
-     * @return void
168
-     */
169
-    protected function putData(array $newData) {
170
-
171
-        // opening up the file, and creating an exclusive lock
172
-        $handle = fopen($this->locksFile, 'a+');
173
-        flock($handle, LOCK_EX);
174
-
175
-        // We can only truncate and rewind once the lock is acquired.
176
-        ftruncate($handle, 0);
177
-        rewind($handle);
178
-
179
-        fwrite($handle, serialize($newData));
180
-        flock($handle, LOCK_UN);
181
-        fclose($handle);
182
-
183
-    }
156
+		// Unserializing and checking if the resource file contains data for this file
157
+		$data = unserialize($data);
158
+		if (!$data) return [];
159
+		return $data;
160
+
161
+	}
162
+
163
+	/**
164
+	 * Saves the lockdata
165
+	 *
166
+	 * @param array $newData
167
+	 * @return void
168
+	 */
169
+	protected function putData(array $newData) {
170
+
171
+		// opening up the file, and creating an exclusive lock
172
+		$handle = fopen($this->locksFile, 'a+');
173
+		flock($handle, LOCK_EX);
174
+
175
+		// We can only truncate and rewind once the lock is acquired.
176
+		ftruncate($handle, 0);
177
+		rewind($handle);
178
+
179
+		fwrite($handle, serialize($newData));
180
+		flock($handle, LOCK_UN);
181
+		fclose($handle);
182
+
183
+	}
184 184
 
185 185
 }
Please login to merge, or discard this patch.