Passed
Push — master ( 5a0b28...e11c5f )
by Joas
14:35 queued 12s
created
apps/dav/lib/Comments/RootCollection.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -147,7 +147,7 @@
 block discarded – undo
147 147
 		if (isset($this->entityTypeCollections[$name])) {
148 148
 			return $this->entityTypeCollections[$name];
149 149
 		}
150
-		throw new NotFound('Entity type "' . $name . '" not found."');
150
+		throw new NotFound('Entity type "'.$name.'" not found."');
151 151
 	}
152 152
 
153 153
 	/**
Please login to merge, or discard this patch.
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -37,168 +37,168 @@
 block discarded – undo
37 37
 
38 38
 class RootCollection implements ICollection {
39 39
 
40
-	/** @var EntityTypeCollection[]|null */
41
-	private $entityTypeCollections;
42
-
43
-	/** @var ICommentsManager */
44
-	protected $commentsManager;
45
-
46
-	/** @var string */
47
-	protected $name = 'comments';
48
-
49
-	protected LoggerInterface $logger;
50
-
51
-	/** @var IUserManager */
52
-	protected $userManager;
53
-
54
-	/** @var IUserSession */
55
-	protected $userSession;
56
-
57
-	/** @var EventDispatcherInterface */
58
-	protected $dispatcher;
59
-
60
-	public function __construct(
61
-		ICommentsManager $commentsManager,
62
-		IUserManager $userManager,
63
-		IUserSession $userSession,
64
-		EventDispatcherInterface $dispatcher,
65
-		LoggerInterface $logger) {
66
-		$this->commentsManager = $commentsManager;
67
-		$this->logger = $logger;
68
-		$this->userManager = $userManager;
69
-		$this->userSession = $userSession;
70
-		$this->dispatcher = $dispatcher;
71
-	}
72
-
73
-	/**
74
-	 * initializes the collection. At this point of time, we need the logged in
75
-	 * user. Since it is not the case when the instance is created, we cannot
76
-	 * have this in the constructor.
77
-	 *
78
-	 * @throws NotAuthenticated
79
-	 */
80
-	protected function initCollections() {
81
-		if ($this->entityTypeCollections !== null) {
82
-			return;
83
-		}
84
-		$user = $this->userSession->getUser();
85
-		if (is_null($user)) {
86
-			throw new NotAuthenticated();
87
-		}
88
-
89
-		$event = new CommentsEntityEvent(CommentsEntityEvent::EVENT_ENTITY);
90
-		$this->dispatcher->dispatch(CommentsEntityEvent::EVENT_ENTITY, $event);
91
-
92
-		$this->entityTypeCollections = [];
93
-		foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) {
94
-			$this->entityTypeCollections[$entity] = new EntityTypeCollection(
95
-				$entity,
96
-				$this->commentsManager,
97
-				$this->userManager,
98
-				$this->userSession,
99
-				$this->logger,
100
-				$entityExistsFunction
101
-			);
102
-		}
103
-	}
104
-
105
-	/**
106
-	 * Creates a new file in the directory
107
-	 *
108
-	 * @param string $name Name of the file
109
-	 * @param resource|string $data Initial payload
110
-	 * @return null|string
111
-	 * @throws Forbidden
112
-	 */
113
-	public function createFile($name, $data = null) {
114
-		throw new Forbidden('Cannot create comments by id');
115
-	}
116
-
117
-	/**
118
-	 * Creates a new subdirectory
119
-	 *
120
-	 * @param string $name
121
-	 * @throws Forbidden
122
-	 */
123
-	public function createDirectory($name) {
124
-		throw new Forbidden('Permission denied to create collections');
125
-	}
126
-
127
-	/**
128
-	 * Returns a specific child node, referenced by its name
129
-	 *
130
-	 * This method must throw Sabre\DAV\Exception\NotFound if the node does not
131
-	 * exist.
132
-	 *
133
-	 * @param string $name
134
-	 * @return \Sabre\DAV\INode
135
-	 * @throws NotFound
136
-	 */
137
-	public function getChild($name) {
138
-		$this->initCollections();
139
-		if (isset($this->entityTypeCollections[$name])) {
140
-			return $this->entityTypeCollections[$name];
141
-		}
142
-		throw new NotFound('Entity type "' . $name . '" not found."');
143
-	}
144
-
145
-	/**
146
-	 * Returns an array with all the child nodes
147
-	 *
148
-	 * @return \Sabre\DAV\INode[]
149
-	 */
150
-	public function getChildren() {
151
-		$this->initCollections();
152
-		return $this->entityTypeCollections;
153
-	}
154
-
155
-	/**
156
-	 * Checks if a child-node with the specified name exists
157
-	 *
158
-	 * @param string $name
159
-	 * @return bool
160
-	 */
161
-	public function childExists($name) {
162
-		$this->initCollections();
163
-		return isset($this->entityTypeCollections[$name]);
164
-	}
165
-
166
-	/**
167
-	 * Deleted the current node
168
-	 *
169
-	 * @throws Forbidden
170
-	 */
171
-	public function delete() {
172
-		throw new Forbidden('Permission denied to delete this collection');
173
-	}
174
-
175
-	/**
176
-	 * Returns the name of the node.
177
-	 *
178
-	 * This is used to generate the url.
179
-	 *
180
-	 * @return string
181
-	 */
182
-	public function getName() {
183
-		return $this->name;
184
-	}
185
-
186
-	/**
187
-	 * Renames the node
188
-	 *
189
-	 * @param string $name The new name
190
-	 * @throws Forbidden
191
-	 */
192
-	public function setName($name) {
193
-		throw new Forbidden('Permission denied to rename this collection');
194
-	}
195
-
196
-	/**
197
-	 * Returns the last modification time, as a unix timestamp
198
-	 *
199
-	 * @return int
200
-	 */
201
-	public function getLastModified() {
202
-		return null;
203
-	}
40
+    /** @var EntityTypeCollection[]|null */
41
+    private $entityTypeCollections;
42
+
43
+    /** @var ICommentsManager */
44
+    protected $commentsManager;
45
+
46
+    /** @var string */
47
+    protected $name = 'comments';
48
+
49
+    protected LoggerInterface $logger;
50
+
51
+    /** @var IUserManager */
52
+    protected $userManager;
53
+
54
+    /** @var IUserSession */
55
+    protected $userSession;
56
+
57
+    /** @var EventDispatcherInterface */
58
+    protected $dispatcher;
59
+
60
+    public function __construct(
61
+        ICommentsManager $commentsManager,
62
+        IUserManager $userManager,
63
+        IUserSession $userSession,
64
+        EventDispatcherInterface $dispatcher,
65
+        LoggerInterface $logger) {
66
+        $this->commentsManager = $commentsManager;
67
+        $this->logger = $logger;
68
+        $this->userManager = $userManager;
69
+        $this->userSession = $userSession;
70
+        $this->dispatcher = $dispatcher;
71
+    }
72
+
73
+    /**
74
+     * initializes the collection. At this point of time, we need the logged in
75
+     * user. Since it is not the case when the instance is created, we cannot
76
+     * have this in the constructor.
77
+     *
78
+     * @throws NotAuthenticated
79
+     */
80
+    protected function initCollections() {
81
+        if ($this->entityTypeCollections !== null) {
82
+            return;
83
+        }
84
+        $user = $this->userSession->getUser();
85
+        if (is_null($user)) {
86
+            throw new NotAuthenticated();
87
+        }
88
+
89
+        $event = new CommentsEntityEvent(CommentsEntityEvent::EVENT_ENTITY);
90
+        $this->dispatcher->dispatch(CommentsEntityEvent::EVENT_ENTITY, $event);
91
+
92
+        $this->entityTypeCollections = [];
93
+        foreach ($event->getEntityCollections() as $entity => $entityExistsFunction) {
94
+            $this->entityTypeCollections[$entity] = new EntityTypeCollection(
95
+                $entity,
96
+                $this->commentsManager,
97
+                $this->userManager,
98
+                $this->userSession,
99
+                $this->logger,
100
+                $entityExistsFunction
101
+            );
102
+        }
103
+    }
104
+
105
+    /**
106
+     * Creates a new file in the directory
107
+     *
108
+     * @param string $name Name of the file
109
+     * @param resource|string $data Initial payload
110
+     * @return null|string
111
+     * @throws Forbidden
112
+     */
113
+    public function createFile($name, $data = null) {
114
+        throw new Forbidden('Cannot create comments by id');
115
+    }
116
+
117
+    /**
118
+     * Creates a new subdirectory
119
+     *
120
+     * @param string $name
121
+     * @throws Forbidden
122
+     */
123
+    public function createDirectory($name) {
124
+        throw new Forbidden('Permission denied to create collections');
125
+    }
126
+
127
+    /**
128
+     * Returns a specific child node, referenced by its name
129
+     *
130
+     * This method must throw Sabre\DAV\Exception\NotFound if the node does not
131
+     * exist.
132
+     *
133
+     * @param string $name
134
+     * @return \Sabre\DAV\INode
135
+     * @throws NotFound
136
+     */
137
+    public function getChild($name) {
138
+        $this->initCollections();
139
+        if (isset($this->entityTypeCollections[$name])) {
140
+            return $this->entityTypeCollections[$name];
141
+        }
142
+        throw new NotFound('Entity type "' . $name . '" not found."');
143
+    }
144
+
145
+    /**
146
+     * Returns an array with all the child nodes
147
+     *
148
+     * @return \Sabre\DAV\INode[]
149
+     */
150
+    public function getChildren() {
151
+        $this->initCollections();
152
+        return $this->entityTypeCollections;
153
+    }
154
+
155
+    /**
156
+     * Checks if a child-node with the specified name exists
157
+     *
158
+     * @param string $name
159
+     * @return bool
160
+     */
161
+    public function childExists($name) {
162
+        $this->initCollections();
163
+        return isset($this->entityTypeCollections[$name]);
164
+    }
165
+
166
+    /**
167
+     * Deleted the current node
168
+     *
169
+     * @throws Forbidden
170
+     */
171
+    public function delete() {
172
+        throw new Forbidden('Permission denied to delete this collection');
173
+    }
174
+
175
+    /**
176
+     * Returns the name of the node.
177
+     *
178
+     * This is used to generate the url.
179
+     *
180
+     * @return string
181
+     */
182
+    public function getName() {
183
+        return $this->name;
184
+    }
185
+
186
+    /**
187
+     * Renames the node
188
+     *
189
+     * @param string $name The new name
190
+     * @throws Forbidden
191
+     */
192
+    public function setName($name) {
193
+        throw new Forbidden('Permission denied to rename this collection');
194
+    }
195
+
196
+    /**
197
+     * Returns the last modification time, as a unix timestamp
198
+     *
199
+     * @return int
200
+     */
201
+    public function getLastModified() {
202
+        return null;
203
+    }
204 204
 }
Please login to merge, or discard this patch.
apps/dav/lib/Comments/EntityCollection.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@
 block discarded – undo
68 68
 		foreach (['id', 'name'] as $property) {
69 69
 			$$property = trim($$property);
70 70
 			if (empty($$property) || !is_string($$property)) {
71
-				throw new \InvalidArgumentException('"' . $property . '" parameter must be non-empty string');
71
+				throw new \InvalidArgumentException('"'.$property.'" parameter must be non-empty string');
72 72
 			}
73 73
 		}
74 74
 		$this->id = $id;
Please login to merge, or discard this patch.
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -41,154 +41,154 @@
 block discarded – undo
41 41
  * @package OCA\DAV\Comments
42 42
  */
43 43
 class EntityCollection extends RootCollection implements IProperties {
44
-	public const PROPERTY_NAME_READ_MARKER = '{http://owncloud.org/ns}readMarker';
44
+    public const PROPERTY_NAME_READ_MARKER = '{http://owncloud.org/ns}readMarker';
45 45
 
46
-	/** @var  string */
47
-	protected $id;
46
+    /** @var  string */
47
+    protected $id;
48 48
 
49
-	protected LoggerInterface $logger;
49
+    protected LoggerInterface $logger;
50 50
 
51
-	/**
52
-	 * @param string $id
53
-	 * @param string $name
54
-	 * @param ICommentsManager $commentsManager
55
-	 * @param IUserManager $userManager
56
-	 * @param IUserSession $userSession
57
-	 * @param LoggerInterface $logger
58
-	 */
59
-	public function __construct(
60
-		$id,
61
-		$name,
62
-		ICommentsManager $commentsManager,
63
-		IUserManager $userManager,
64
-		IUserSession $userSession,
65
-		LoggerInterface $logger
66
-	) {
67
-		foreach (['id', 'name'] as $property) {
68
-			$$property = trim($$property);
69
-			if (empty($$property) || !is_string($$property)) {
70
-				throw new \InvalidArgumentException('"' . $property . '" parameter must be non-empty string');
71
-			}
72
-		}
73
-		$this->id = $id;
74
-		$this->name = $name;
75
-		$this->commentsManager = $commentsManager;
76
-		$this->logger = $logger;
77
-		$this->userManager = $userManager;
78
-		$this->userSession = $userSession;
79
-	}
51
+    /**
52
+     * @param string $id
53
+     * @param string $name
54
+     * @param ICommentsManager $commentsManager
55
+     * @param IUserManager $userManager
56
+     * @param IUserSession $userSession
57
+     * @param LoggerInterface $logger
58
+     */
59
+    public function __construct(
60
+        $id,
61
+        $name,
62
+        ICommentsManager $commentsManager,
63
+        IUserManager $userManager,
64
+        IUserSession $userSession,
65
+        LoggerInterface $logger
66
+    ) {
67
+        foreach (['id', 'name'] as $property) {
68
+            $$property = trim($$property);
69
+            if (empty($$property) || !is_string($$property)) {
70
+                throw new \InvalidArgumentException('"' . $property . '" parameter must be non-empty string');
71
+            }
72
+        }
73
+        $this->id = $id;
74
+        $this->name = $name;
75
+        $this->commentsManager = $commentsManager;
76
+        $this->logger = $logger;
77
+        $this->userManager = $userManager;
78
+        $this->userSession = $userSession;
79
+    }
80 80
 
81
-	/**
82
-	 * returns the ID of this entity
83
-	 *
84
-	 * @return string
85
-	 */
86
-	public function getId() {
87
-		return $this->id;
88
-	}
81
+    /**
82
+     * returns the ID of this entity
83
+     *
84
+     * @return string
85
+     */
86
+    public function getId() {
87
+        return $this->id;
88
+    }
89 89
 
90
-	/**
91
-	 * Returns a specific child node, referenced by its name
92
-	 *
93
-	 * This method must throw Sabre\DAV\Exception\NotFound if the node does not
94
-	 * exist.
95
-	 *
96
-	 * @param string $name
97
-	 * @return \Sabre\DAV\INode
98
-	 * @throws NotFound
99
-	 */
100
-	public function getChild($name) {
101
-		try {
102
-			$comment = $this->commentsManager->get($name);
103
-			return new CommentNode(
104
-				$this->commentsManager,
105
-				$comment,
106
-				$this->userManager,
107
-				$this->userSession,
108
-				$this->logger
109
-			);
110
-		} catch (NotFoundException $e) {
111
-			throw new NotFound();
112
-		}
113
-	}
90
+    /**
91
+     * Returns a specific child node, referenced by its name
92
+     *
93
+     * This method must throw Sabre\DAV\Exception\NotFound if the node does not
94
+     * exist.
95
+     *
96
+     * @param string $name
97
+     * @return \Sabre\DAV\INode
98
+     * @throws NotFound
99
+     */
100
+    public function getChild($name) {
101
+        try {
102
+            $comment = $this->commentsManager->get($name);
103
+            return new CommentNode(
104
+                $this->commentsManager,
105
+                $comment,
106
+                $this->userManager,
107
+                $this->userSession,
108
+                $this->logger
109
+            );
110
+        } catch (NotFoundException $e) {
111
+            throw new NotFound();
112
+        }
113
+    }
114 114
 
115
-	/**
116
-	 * Returns an array with all the child nodes
117
-	 *
118
-	 * @return \Sabre\DAV\INode[]
119
-	 */
120
-	public function getChildren() {
121
-		return $this->findChildren();
122
-	}
115
+    /**
116
+     * Returns an array with all the child nodes
117
+     *
118
+     * @return \Sabre\DAV\INode[]
119
+     */
120
+    public function getChildren() {
121
+        return $this->findChildren();
122
+    }
123 123
 
124
-	/**
125
-	 * Returns an array of comment nodes. Result can be influenced by offset,
126
-	 * limit and date time parameters.
127
-	 *
128
-	 * @param int $limit
129
-	 * @param int $offset
130
-	 * @param \DateTime|null $datetime
131
-	 * @return CommentNode[]
132
-	 */
133
-	public function findChildren($limit = 0, $offset = 0, \DateTime $datetime = null) {
134
-		$comments = $this->commentsManager->getForObject($this->name, $this->id, $limit, $offset, $datetime);
135
-		$result = [];
136
-		foreach ($comments as $comment) {
137
-			$result[] = new CommentNode(
138
-				$this->commentsManager,
139
-				$comment,
140
-				$this->userManager,
141
-				$this->userSession,
142
-				$this->logger
143
-			);
144
-		}
145
-		return $result;
146
-	}
124
+    /**
125
+     * Returns an array of comment nodes. Result can be influenced by offset,
126
+     * limit and date time parameters.
127
+     *
128
+     * @param int $limit
129
+     * @param int $offset
130
+     * @param \DateTime|null $datetime
131
+     * @return CommentNode[]
132
+     */
133
+    public function findChildren($limit = 0, $offset = 0, \DateTime $datetime = null) {
134
+        $comments = $this->commentsManager->getForObject($this->name, $this->id, $limit, $offset, $datetime);
135
+        $result = [];
136
+        foreach ($comments as $comment) {
137
+            $result[] = new CommentNode(
138
+                $this->commentsManager,
139
+                $comment,
140
+                $this->userManager,
141
+                $this->userSession,
142
+                $this->logger
143
+            );
144
+        }
145
+        return $result;
146
+    }
147 147
 
148
-	/**
149
-	 * Checks if a child-node with the specified name exists
150
-	 *
151
-	 * @param string $name
152
-	 * @return bool
153
-	 */
154
-	public function childExists($name) {
155
-		try {
156
-			$this->commentsManager->get($name);
157
-			return true;
158
-		} catch (NotFoundException $e) {
159
-			return false;
160
-		}
161
-	}
148
+    /**
149
+     * Checks if a child-node with the specified name exists
150
+     *
151
+     * @param string $name
152
+     * @return bool
153
+     */
154
+    public function childExists($name) {
155
+        try {
156
+            $this->commentsManager->get($name);
157
+            return true;
158
+        } catch (NotFoundException $e) {
159
+            return false;
160
+        }
161
+    }
162 162
 
163
-	/**
164
-	 * Sets the read marker to the specified date for the logged in user
165
-	 *
166
-	 * @param \DateTime $value
167
-	 * @return bool
168
-	 */
169
-	public function setReadMarker($value) {
170
-		$dateTime = new \DateTime($value);
171
-		$user = $this->userSession->getUser();
172
-		$this->commentsManager->setReadMark($this->name, $this->id, $dateTime, $user);
173
-		return true;
174
-	}
163
+    /**
164
+     * Sets the read marker to the specified date for the logged in user
165
+     *
166
+     * @param \DateTime $value
167
+     * @return bool
168
+     */
169
+    public function setReadMarker($value) {
170
+        $dateTime = new \DateTime($value);
171
+        $user = $this->userSession->getUser();
172
+        $this->commentsManager->setReadMark($this->name, $this->id, $dateTime, $user);
173
+        return true;
174
+    }
175 175
 
176
-	/**
177
-	 * @inheritdoc
178
-	 */
179
-	public function propPatch(PropPatch $propPatch) {
180
-		$propPatch->handle(self::PROPERTY_NAME_READ_MARKER, [$this, 'setReadMarker']);
181
-	}
176
+    /**
177
+     * @inheritdoc
178
+     */
179
+    public function propPatch(PropPatch $propPatch) {
180
+        $propPatch->handle(self::PROPERTY_NAME_READ_MARKER, [$this, 'setReadMarker']);
181
+    }
182 182
 
183
-	/**
184
-	 * @inheritdoc
185
-	 */
186
-	public function getProperties($properties) {
187
-		$marker = null;
188
-		$user = $this->userSession->getUser();
189
-		if (!is_null($user)) {
190
-			$marker = $this->commentsManager->getReadMark($this->name, $this->id, $user);
191
-		}
192
-		return [self::PROPERTY_NAME_READ_MARKER => $marker];
193
-	}
183
+    /**
184
+     * @inheritdoc
185
+     */
186
+    public function getProperties($properties) {
187
+        $marker = null;
188
+        $user = $this->userSession->getUser();
189
+        if (!is_null($user)) {
190
+            $marker = $this->commentsManager->getReadMark($this->name, $this->id, $user);
191
+        }
192
+        return [self::PROPERTY_NAME_READ_MARKER => $marker];
193
+    }
194 194
 }
Please login to merge, or discard this patch.
apps/dav/lib/Files/Sharing/FilesDropPlugin.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@
 block discarded – undo
77 77
 		$path = array_pop($path);
78 78
 
79 79
 		$newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view);
80
-		$url = $request->getBaseUrl() . $newName;
80
+		$url = $request->getBaseUrl().$newName;
81 81
 		$request->setUrl($url);
82 82
 	}
83 83
 }
Please login to merge, or discard this patch.
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -35,51 +35,51 @@
 block discarded – undo
35 35
  */
36 36
 class FilesDropPlugin extends ServerPlugin {
37 37
 
38
-	/** @var View */
39
-	private $view;
38
+    /** @var View */
39
+    private $view;
40 40
 
41
-	/** @var bool */
42
-	private $enabled = false;
41
+    /** @var bool */
42
+    private $enabled = false;
43 43
 
44
-	/**
45
-	 * @param View $view
46
-	 */
47
-	public function setView($view) {
48
-		$this->view = $view;
49
-	}
44
+    /**
45
+     * @param View $view
46
+     */
47
+    public function setView($view) {
48
+        $this->view = $view;
49
+    }
50 50
 
51
-	public function enable() {
52
-		$this->enabled = true;
53
-	}
51
+    public function enable() {
52
+        $this->enabled = true;
53
+    }
54 54
 
55 55
 
56
-	/**
57
-	 * This initializes the plugin.
58
-	 *
59
-	 * @param \Sabre\DAV\Server $server Sabre server
60
-	 *
61
-	 * @return void
62
-	 * @throws MethodNotAllowed
63
-	 */
64
-	public function initialize(\Sabre\DAV\Server $server) {
65
-		$server->on('beforeMethod:*', [$this, 'beforeMethod'], 999);
66
-		$this->enabled = false;
67
-	}
56
+    /**
57
+     * This initializes the plugin.
58
+     *
59
+     * @param \Sabre\DAV\Server $server Sabre server
60
+     *
61
+     * @return void
62
+     * @throws MethodNotAllowed
63
+     */
64
+    public function initialize(\Sabre\DAV\Server $server) {
65
+        $server->on('beforeMethod:*', [$this, 'beforeMethod'], 999);
66
+        $this->enabled = false;
67
+    }
68 68
 
69
-	public function beforeMethod(RequestInterface $request, ResponseInterface $response) {
70
-		if (!$this->enabled) {
71
-			return;
72
-		}
69
+    public function beforeMethod(RequestInterface $request, ResponseInterface $response) {
70
+        if (!$this->enabled) {
71
+            return;
72
+        }
73 73
 
74
-		if ($request->getMethod() !== 'PUT') {
75
-			throw new MethodNotAllowed('Only PUT is allowed on files drop');
76
-		}
74
+        if ($request->getMethod() !== 'PUT') {
75
+            throw new MethodNotAllowed('Only PUT is allowed on files drop');
76
+        }
77 77
 
78
-		$path = explode('/', $request->getPath());
79
-		$path = array_pop($path);
78
+        $path = explode('/', $request->getPath());
79
+        $path = array_pop($path);
80 80
 
81
-		$newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view);
82
-		$url = $request->getBaseUrl() . $newName;
83
-		$request->setUrl($url);
84
-	}
81
+        $newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view);
82
+        $url = $request->getBaseUrl() . $newName;
83
+        $request->setUrl($url);
84
+    }
85 85
 }
Please login to merge, or discard this patch.
apps/dav/lib/Command/SyncSystemAddressBook.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@
 block discarded – undo
54 54
 		$output->writeln('Syncing users ...');
55 55
 		$progress = new ProgressBar($output);
56 56
 		$progress->start();
57
-		$this->syncService->syncInstance(function () use ($progress) {
57
+		$this->syncService->syncInstance(function() use ($progress) {
58 58
 			$progress->advance();
59 59
 		});
60 60
 
Please login to merge, or discard this patch.
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -32,37 +32,37 @@
 block discarded – undo
32 32
 
33 33
 class SyncSystemAddressBook extends Command {
34 34
 
35
-	/** @var SyncService */
36
-	private $syncService;
35
+    /** @var SyncService */
36
+    private $syncService;
37 37
 
38
-	/**
39
-	 * @param SyncService $syncService
40
-	 */
41
-	public function __construct(SyncService $syncService) {
42
-		parent::__construct();
43
-		$this->syncService = $syncService;
44
-	}
38
+    /**
39
+     * @param SyncService $syncService
40
+     */
41
+    public function __construct(SyncService $syncService) {
42
+        parent::__construct();
43
+        $this->syncService = $syncService;
44
+    }
45 45
 
46
-	protected function configure() {
47
-		$this
48
-			->setName('dav:sync-system-addressbook')
49
-			->setDescription('Synchronizes users to the system addressbook');
50
-	}
46
+    protected function configure() {
47
+        $this
48
+            ->setName('dav:sync-system-addressbook')
49
+            ->setDescription('Synchronizes users to the system addressbook');
50
+    }
51 51
 
52
-	/**
53
-	 * @param InputInterface $input
54
-	 * @param OutputInterface $output
55
-	 */
56
-	protected function execute(InputInterface $input, OutputInterface $output): int {
57
-		$output->writeln('Syncing users ...');
58
-		$progress = new ProgressBar($output);
59
-		$progress->start();
60
-		$this->syncService->syncInstance(function () use ($progress) {
61
-			$progress->advance();
62
-		});
52
+    /**
53
+     * @param InputInterface $input
54
+     * @param OutputInterface $output
55
+     */
56
+    protected function execute(InputInterface $input, OutputInterface $output): int {
57
+        $output->writeln('Syncing users ...');
58
+        $progress = new ProgressBar($output);
59
+        $progress->start();
60
+        $this->syncService->syncInstance(function () use ($progress) {
61
+            $progress->advance();
62
+        });
63 63
 
64
-		$progress->finish();
65
-		$output->writeln('');
66
-		return 0;
67
-	}
64
+        $progress->finish();
65
+        $output->writeln('');
66
+        return 0;
67
+    }
68 68
 }
Please login to merge, or discard this patch.
apps/dav/lib/Avatars/AvatarHome.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@
 block discarded – undo
58 58
 	public function getChild($name) {
59 59
 		$elements = pathinfo($name);
60 60
 		$ext = isset($elements['extension']) ? $elements['extension'] : '';
61
-		$size = (int)(isset($elements['filename']) ? $elements['filename'] : '64');
61
+		$size = (int) (isset($elements['filename']) ? $elements['filename'] : '64');
62 62
 		if (!in_array($ext, ['jpeg', 'png'], true)) {
63 63
 			throw new MethodNotAllowed('File format not allowed');
64 64
 		}
Please login to merge, or discard this patch.
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -34,87 +34,87 @@
 block discarded – undo
34 34
 
35 35
 class AvatarHome implements ICollection {
36 36
 
37
-	/** @var array */
38
-	private $principalInfo;
39
-	/** @var IAvatarManager */
40
-	private $avatarManager;
37
+    /** @var array */
38
+    private $principalInfo;
39
+    /** @var IAvatarManager */
40
+    private $avatarManager;
41 41
 
42
-	/**
43
-	 * AvatarHome constructor.
44
-	 *
45
-	 * @param array $principalInfo
46
-	 * @param IAvatarManager $avatarManager
47
-	 */
48
-	public function __construct($principalInfo, IAvatarManager $avatarManager) {
49
-		$this->principalInfo = $principalInfo;
50
-		$this->avatarManager = $avatarManager;
51
-	}
42
+    /**
43
+     * AvatarHome constructor.
44
+     *
45
+     * @param array $principalInfo
46
+     * @param IAvatarManager $avatarManager
47
+     */
48
+    public function __construct($principalInfo, IAvatarManager $avatarManager) {
49
+        $this->principalInfo = $principalInfo;
50
+        $this->avatarManager = $avatarManager;
51
+    }
52 52
 
53
-	public function createFile($name, $data = null) {
54
-		throw new Forbidden('Permission denied to create a file');
55
-	}
53
+    public function createFile($name, $data = null) {
54
+        throw new Forbidden('Permission denied to create a file');
55
+    }
56 56
 
57
-	public function createDirectory($name) {
58
-		throw new Forbidden('Permission denied to create a folder');
59
-	}
57
+    public function createDirectory($name) {
58
+        throw new Forbidden('Permission denied to create a folder');
59
+    }
60 60
 
61
-	public function getChild($name) {
62
-		$elements = pathinfo($name);
63
-		$ext = isset($elements['extension']) ? $elements['extension'] : '';
64
-		$size = (int)(isset($elements['filename']) ? $elements['filename'] : '64');
65
-		if (!in_array($ext, ['jpeg', 'png'], true)) {
66
-			throw new MethodNotAllowed('File format not allowed');
67
-		}
68
-		if ($size <= 0 || $size > 1024) {
69
-			throw new MethodNotAllowed('Invalid image size');
70
-		}
71
-		$avatar = $this->avatarManager->getAvatar($this->getName());
72
-		if (!$avatar->exists()) {
73
-			throw new NotFound();
74
-		}
75
-		return new AvatarNode($size, $ext, $avatar);
76
-	}
61
+    public function getChild($name) {
62
+        $elements = pathinfo($name);
63
+        $ext = isset($elements['extension']) ? $elements['extension'] : '';
64
+        $size = (int)(isset($elements['filename']) ? $elements['filename'] : '64');
65
+        if (!in_array($ext, ['jpeg', 'png'], true)) {
66
+            throw new MethodNotAllowed('File format not allowed');
67
+        }
68
+        if ($size <= 0 || $size > 1024) {
69
+            throw new MethodNotAllowed('Invalid image size');
70
+        }
71
+        $avatar = $this->avatarManager->getAvatar($this->getName());
72
+        if (!$avatar->exists()) {
73
+            throw new NotFound();
74
+        }
75
+        return new AvatarNode($size, $ext, $avatar);
76
+    }
77 77
 
78
-	public function getChildren() {
79
-		try {
80
-			return [
81
-				$this->getChild('96.jpeg')
82
-			];
83
-		} catch (NotFound $exception) {
84
-			return [];
85
-		}
86
-	}
78
+    public function getChildren() {
79
+        try {
80
+            return [
81
+                $this->getChild('96.jpeg')
82
+            ];
83
+        } catch (NotFound $exception) {
84
+            return [];
85
+        }
86
+    }
87 87
 
88
-	public function childExists($name) {
89
-		try {
90
-			$ret = $this->getChild($name);
91
-			return $ret !== null;
92
-		} catch (NotFound $ex) {
93
-			return false;
94
-		} catch (MethodNotAllowed $ex) {
95
-			return false;
96
-		}
97
-	}
88
+    public function childExists($name) {
89
+        try {
90
+            $ret = $this->getChild($name);
91
+            return $ret !== null;
92
+        } catch (NotFound $ex) {
93
+            return false;
94
+        } catch (MethodNotAllowed $ex) {
95
+            return false;
96
+        }
97
+    }
98 98
 
99
-	public function delete() {
100
-		throw new Forbidden('Permission denied to delete this folder');
101
-	}
99
+    public function delete() {
100
+        throw new Forbidden('Permission denied to delete this folder');
101
+    }
102 102
 
103
-	public function getName() {
104
-		[,$name] = Uri\split($this->principalInfo['uri']);
105
-		return $name;
106
-	}
103
+    public function getName() {
104
+        [,$name] = Uri\split($this->principalInfo['uri']);
105
+        return $name;
106
+    }
107 107
 
108
-	public function setName($name) {
109
-		throw new Forbidden('Permission denied to rename this folder');
110
-	}
108
+    public function setName($name) {
109
+        throw new Forbidden('Permission denied to rename this folder');
110
+    }
111 111
 
112
-	/**
113
-	 * Returns the last modification time, as a unix timestamp
114
-	 *
115
-	 * @return int|null
116
-	 */
117
-	public function getLastModified() {
118
-		return null;
119
-	}
112
+    /**
113
+     * Returns the last modification time, as a unix timestamp
114
+     *
115
+     * @return int|null
116
+     */
117
+    public function getLastModified() {
118
+        return null;
119
+    }
120 120
 }
Please login to merge, or discard this patch.
apps/dav/lib/Avatars/AvatarNode.php 2 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -26,71 +26,71 @@
 block discarded – undo
26 26
 use Sabre\DAV\File;
27 27
 
28 28
 class AvatarNode extends File {
29
-	private $ext;
30
-	private $size;
31
-	private $avatar;
29
+    private $ext;
30
+    private $size;
31
+    private $avatar;
32 32
 
33
-	/**
34
-	 * AvatarNode constructor.
35
-	 *
36
-	 * @param integer $size
37
-	 * @param string $ext
38
-	 * @param IAvatar $avatar
39
-	 */
40
-	public function __construct($size, $ext, $avatar) {
41
-		$this->size = $size;
42
-		$this->ext = $ext;
43
-		$this->avatar = $avatar;
44
-	}
33
+    /**
34
+     * AvatarNode constructor.
35
+     *
36
+     * @param integer $size
37
+     * @param string $ext
38
+     * @param IAvatar $avatar
39
+     */
40
+    public function __construct($size, $ext, $avatar) {
41
+        $this->size = $size;
42
+        $this->ext = $ext;
43
+        $this->avatar = $avatar;
44
+    }
45 45
 
46
-	/**
47
-	 * Returns the name of the node.
48
-	 *
49
-	 * This is used to generate the url.
50
-	 *
51
-	 * @return string
52
-	 */
53
-	public function getName() {
54
-		return "$this->size.$this->ext";
55
-	}
46
+    /**
47
+     * Returns the name of the node.
48
+     *
49
+     * This is used to generate the url.
50
+     *
51
+     * @return string
52
+     */
53
+    public function getName() {
54
+        return "$this->size.$this->ext";
55
+    }
56 56
 
57
-	public function get() {
58
-		$image = $this->avatar->get($this->size);
59
-		$res = $image->resource();
57
+    public function get() {
58
+        $image = $this->avatar->get($this->size);
59
+        $res = $image->resource();
60 60
 
61
-		ob_start();
62
-		if ($this->ext === 'png') {
63
-			imagepng($res);
64
-		} else {
65
-			imagejpeg($res);
66
-		}
61
+        ob_start();
62
+        if ($this->ext === 'png') {
63
+            imagepng($res);
64
+        } else {
65
+            imagejpeg($res);
66
+        }
67 67
 
68
-		return ob_get_clean();
69
-	}
68
+        return ob_get_clean();
69
+    }
70 70
 
71
-	/**
72
-	 * Returns the mime-type for a file
73
-	 *
74
-	 * If null is returned, we'll assume application/octet-stream
75
-	 *
76
-	 * @return string|null
77
-	 */
78
-	public function getContentType() {
79
-		if ($this->ext === 'png') {
80
-			return 'image/png';
81
-		}
82
-		return 'image/jpeg';
83
-	}
71
+    /**
72
+     * Returns the mime-type for a file
73
+     *
74
+     * If null is returned, we'll assume application/octet-stream
75
+     *
76
+     * @return string|null
77
+     */
78
+    public function getContentType() {
79
+        if ($this->ext === 'png') {
80
+            return 'image/png';
81
+        }
82
+        return 'image/jpeg';
83
+    }
84 84
 
85
-	public function getETag() {
86
-		return $this->avatar->getFile($this->size)->getEtag();
87
-	}
85
+    public function getETag() {
86
+        return $this->avatar->getFile($this->size)->getEtag();
87
+    }
88 88
 
89
-	public function getLastModified() {
90
-		$timestamp = $this->avatar->getFile($this->size)->getMTime();
91
-		if (!empty($timestamp)) {
92
-			return (int)$timestamp;
93
-		}
94
-		return $timestamp;
95
-	}
89
+    public function getLastModified() {
90
+        $timestamp = $this->avatar->getFile($this->size)->getMTime();
91
+        if (!empty($timestamp)) {
92
+            return (int)$timestamp;
93
+        }
94
+        return $timestamp;
95
+    }
96 96
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@
 block discarded – undo
89 89
 	public function getLastModified() {
90 90
 		$timestamp = $this->avatar->getFile($this->size)->getMTime();
91 91
 		if (!empty($timestamp)) {
92
-			return (int)$timestamp;
92
+			return (int) $timestamp;
93 93
 		}
94 94
 		return $timestamp;
95 95
 	}
Please login to merge, or discard this patch.
apps/dav/lib/CardDAV/Xml/Groups.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@
 block discarded – undo
39 39
 
40 40
 	public function xmlSerialize(Writer $writer) {
41 41
 		foreach ($this->groups as $group) {
42
-			$writer->writeElement('{' . self::NS_OWNCLOUD . '}group', $group);
42
+			$writer->writeElement('{'.self::NS_OWNCLOUD.'}group', $group);
43 43
 		}
44 44
 	}
45 45
 }
Please login to merge, or discard this patch.
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -27,21 +27,21 @@
 block discarded – undo
27 27
 use Sabre\Xml\XmlSerializable;
28 28
 
29 29
 class Groups implements XmlSerializable {
30
-	public const NS_OWNCLOUD = 'http://owncloud.org/ns';
30
+    public const NS_OWNCLOUD = 'http://owncloud.org/ns';
31 31
 
32
-	/** @var string[] of TYPE:CHECKSUM */
33
-	private $groups;
32
+    /** @var string[] of TYPE:CHECKSUM */
33
+    private $groups;
34 34
 
35
-	/**
36
-	 * @param string $groups
37
-	 */
38
-	public function __construct($groups) {
39
-		$this->groups = $groups;
40
-	}
35
+    /**
36
+     * @param string $groups
37
+     */
38
+    public function __construct($groups) {
39
+        $this->groups = $groups;
40
+    }
41 41
 
42
-	public function xmlSerialize(Writer $writer) {
43
-		foreach ($this->groups as $group) {
44
-			$writer->writeElement('{' . self::NS_OWNCLOUD . '}group', $group);
45
-		}
46
-	}
42
+    public function xmlSerialize(Writer $writer) {
43
+        foreach ($this->groups as $group) {
44
+            $writer->writeElement('{' . self::NS_OWNCLOUD . '}group', $group);
45
+        }
46
+    }
47 47
 }
Please login to merge, or discard this patch.
apps/dav/lib/CardDAV/SyncService.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 			if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) {
97 97
 				// remote server revoked access to the address book, remove it
98 98
 				$this->backend->deleteAddressBook($addressBookId);
99
-				$this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']);
99
+				$this->logger->info('Authorization failed, remove address book: '.$url, ['app' => 'dav']);
100 100
 				throw $ex;
101 101
 			}
102 102
 		}
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 	 */
170 170
 	protected function getClient($url, $userName, $sharedSecret) {
171 171
 		$settings = [
172
-			'baseUri' => $url . '/',
172
+			'baseUri' => $url.'/',
173 173
 			'userName' => $userName,
174 174
 			'password' => $sharedSecret,
175 175
 		];
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
 		if (is_null($this->localSystemAddressBook)) {
307 307
 			$systemPrincipal = "principals/system/system";
308 308
 			$this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [
309
-				'{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance'
309
+				'{'.Plugin::NS_CARDDAV.'}addressbook-description' => 'System addressbook which holds all users of this instance'
310 310
 			]);
311 311
 		}
312 312
 
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 
316 316
 	public function syncInstance(\Closure $progressCallback = null) {
317 317
 		$systemAddressBook = $this->getLocalSystemAddressBook();
318
-		$this->userManager->callForAllUsers(function ($user) use ($systemAddressBook, $progressCallback) {
318
+		$this->userManager->callForAllUsers(function($user) use ($systemAddressBook, $progressCallback) {
319 319
 			$this->updateUser($user);
320 320
 			if (!is_null($progressCallback)) {
321 321
 				$progressCallback();
Please login to merge, or discard this patch.
Indentation   +292 added lines, -292 removed lines patch added patch discarded remove patch
@@ -41,296 +41,296 @@
 block discarded – undo
41 41
 
42 42
 class SyncService {
43 43
 
44
-	/** @var CardDavBackend */
45
-	private $backend;
46
-
47
-	/** @var IUserManager */
48
-	private $userManager;
49
-
50
-	private LoggerInterface $logger;
51
-
52
-	/** @var array */
53
-	private $localSystemAddressBook;
54
-
55
-	/** @var Converter */
56
-	private $converter;
57
-
58
-	/** @var string */
59
-	protected $certPath;
60
-
61
-	/**
62
-	 * SyncService constructor.
63
-	 */
64
-	public function __construct(CardDavBackend $backend,
65
-								IUserManager $userManager,
66
-								LoggerInterface $logger,
67
-								Converter $converter) {
68
-		$this->backend = $backend;
69
-		$this->userManager = $userManager;
70
-		$this->logger = $logger;
71
-		$this->converter = $converter;
72
-		$this->certPath = '';
73
-	}
74
-
75
-	/**
76
-	 * @param string $url
77
-	 * @param string $userName
78
-	 * @param string $addressBookUrl
79
-	 * @param string $sharedSecret
80
-	 * @param string $syncToken
81
-	 * @param int $targetBookId
82
-	 * @param string $targetPrincipal
83
-	 * @param array $targetProperties
84
-	 * @return string
85
-	 * @throws \Exception
86
-	 */
87
-	public function syncRemoteAddressBook($url, $userName, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetProperties) {
88
-		// 1. create addressbook
89
-		$book = $this->ensureSystemAddressBookExists($targetPrincipal, $targetBookId, $targetProperties);
90
-		$addressBookId = $book['id'];
91
-
92
-		// 2. query changes
93
-		try {
94
-			$response = $this->requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken);
95
-		} catch (ClientHttpException $ex) {
96
-			if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) {
97
-				// remote server revoked access to the address book, remove it
98
-				$this->backend->deleteAddressBook($addressBookId);
99
-				$this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']);
100
-				throw $ex;
101
-			}
102
-		}
103
-
104
-		// 3. apply changes
105
-		// TODO: use multi-get for download
106
-		foreach ($response['response'] as $resource => $status) {
107
-			$cardUri = basename($resource);
108
-			if (isset($status[200])) {
109
-				$vCard = $this->download($url, $userName, $sharedSecret, $resource);
110
-				$existingCard = $this->backend->getCard($addressBookId, $cardUri);
111
-				if ($existingCard === false) {
112
-					$this->backend->createCard($addressBookId, $cardUri, $vCard['body']);
113
-				} else {
114
-					$this->backend->updateCard($addressBookId, $cardUri, $vCard['body']);
115
-				}
116
-			} else {
117
-				$this->backend->deleteCard($addressBookId, $cardUri);
118
-			}
119
-		}
120
-
121
-		return $response['token'];
122
-	}
123
-
124
-	/**
125
-	 * @param string $principal
126
-	 * @param string $id
127
-	 * @param array $properties
128
-	 * @return array|null
129
-	 * @throws \Sabre\DAV\Exception\BadRequest
130
-	 */
131
-	public function ensureSystemAddressBookExists($principal, $id, $properties) {
132
-		$book = $this->backend->getAddressBooksByUri($principal, $id);
133
-		if (!is_null($book)) {
134
-			return $book;
135
-		}
136
-		$this->backend->createAddressBook($principal, $id, $properties);
137
-
138
-		return $this->backend->getAddressBooksByUri($principal, $id);
139
-	}
140
-
141
-	/**
142
-	 * Check if there is a valid certPath we should use
143
-	 *
144
-	 * @return string
145
-	 */
146
-	protected function getCertPath() {
147
-
148
-		// we already have a valid certPath
149
-		if ($this->certPath !== '') {
150
-			return $this->certPath;
151
-		}
152
-
153
-		$certManager = \OC::$server->getCertificateManager();
154
-		$certPath = $certManager->getAbsoluteBundlePath();
155
-		if (file_exists($certPath)) {
156
-			$this->certPath = $certPath;
157
-		}
158
-
159
-		return $this->certPath;
160
-	}
161
-
162
-	/**
163
-	 * @param string $url
164
-	 * @param string $userName
165
-	 * @param string $addressBookUrl
166
-	 * @param string $sharedSecret
167
-	 * @return Client
168
-	 */
169
-	protected function getClient($url, $userName, $sharedSecret) {
170
-		$settings = [
171
-			'baseUri' => $url . '/',
172
-			'userName' => $userName,
173
-			'password' => $sharedSecret,
174
-		];
175
-		$client = new Client($settings);
176
-		$certPath = $this->getCertPath();
177
-		$client->setThrowExceptions(true);
178
-
179
-		if ($certPath !== '' && strpos($url, 'http://') !== 0) {
180
-			$client->addCurlSetting(CURLOPT_CAINFO, $this->certPath);
181
-		}
182
-
183
-		return $client;
184
-	}
185
-
186
-	/**
187
-	 * @param string $url
188
-	 * @param string $userName
189
-	 * @param string $addressBookUrl
190
-	 * @param string $sharedSecret
191
-	 * @param string $syncToken
192
-	 * @return array
193
-	 */
194
-	protected function requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken) {
195
-		$client = $this->getClient($url, $userName, $sharedSecret);
196
-
197
-		$body = $this->buildSyncCollectionRequestBody($syncToken);
198
-
199
-		$response = $client->request('REPORT', $addressBookUrl, $body, [
200
-			'Content-Type' => 'application/xml'
201
-		]);
202
-
203
-		return $this->parseMultiStatus($response['body']);
204
-	}
205
-
206
-	/**
207
-	 * @param string $url
208
-	 * @param string $userName
209
-	 * @param string $sharedSecret
210
-	 * @param string $resourcePath
211
-	 * @return array
212
-	 */
213
-	protected function download($url, $userName, $sharedSecret, $resourcePath) {
214
-		$client = $this->getClient($url, $userName, $sharedSecret);
215
-		return $client->request('GET', $resourcePath);
216
-	}
217
-
218
-	/**
219
-	 * @param string|null $syncToken
220
-	 * @return string
221
-	 */
222
-	private function buildSyncCollectionRequestBody($syncToken) {
223
-		$dom = new \DOMDocument('1.0', 'UTF-8');
224
-		$dom->formatOutput = true;
225
-		$root = $dom->createElementNS('DAV:', 'd:sync-collection');
226
-		$sync = $dom->createElement('d:sync-token', $syncToken);
227
-		$prop = $dom->createElement('d:prop');
228
-		$cont = $dom->createElement('d:getcontenttype');
229
-		$etag = $dom->createElement('d:getetag');
230
-
231
-		$prop->appendChild($cont);
232
-		$prop->appendChild($etag);
233
-		$root->appendChild($sync);
234
-		$root->appendChild($prop);
235
-		$dom->appendChild($root);
236
-		return $dom->saveXML();
237
-	}
238
-
239
-	/**
240
-	 * @param string $body
241
-	 * @return array
242
-	 * @throws \Sabre\Xml\ParseException
243
-	 */
244
-	private function parseMultiStatus($body) {
245
-		$xml = new Service();
246
-
247
-		/** @var MultiStatus $multiStatus */
248
-		$multiStatus = $xml->expect('{DAV:}multistatus', $body);
249
-
250
-		$result = [];
251
-		foreach ($multiStatus->getResponses() as $response) {
252
-			$result[$response->getHref()] = $response->getResponseProperties();
253
-		}
254
-
255
-		return ['response' => $result, 'token' => $multiStatus->getSyncToken()];
256
-	}
257
-
258
-	/**
259
-	 * @param IUser $user
260
-	 */
261
-	public function updateUser(IUser $user) {
262
-		$systemAddressBook = $this->getLocalSystemAddressBook();
263
-		$addressBookId = $systemAddressBook['id'];
264
-		$name = $user->getBackendClassName();
265
-		$userId = $user->getUID();
266
-
267
-		$cardId = "$name:$userId.vcf";
268
-		$card = $this->backend->getCard($addressBookId, $cardId);
269
-		if ($user->isEnabled()) {
270
-			if ($card === false) {
271
-				$vCard = $this->converter->createCardFromUser($user);
272
-				if ($vCard !== null) {
273
-					$this->backend->createCard($addressBookId, $cardId, $vCard->serialize());
274
-				}
275
-			} else {
276
-				$vCard = $this->converter->createCardFromUser($user);
277
-				if (is_null($vCard)) {
278
-					$this->backend->deleteCard($addressBookId, $cardId);
279
-				} else {
280
-					$this->backend->updateCard($addressBookId, $cardId, $vCard->serialize());
281
-				}
282
-			}
283
-		} else {
284
-			$this->backend->deleteCard($addressBookId, $cardId);
285
-		}
286
-	}
287
-
288
-	/**
289
-	 * @param IUser|string $userOrCardId
290
-	 */
291
-	public function deleteUser($userOrCardId) {
292
-		$systemAddressBook = $this->getLocalSystemAddressBook();
293
-		if ($userOrCardId instanceof IUser) {
294
-			$name = $userOrCardId->getBackendClassName();
295
-			$userId = $userOrCardId->getUID();
296
-
297
-			$userOrCardId = "$name:$userId.vcf";
298
-		}
299
-		$this->backend->deleteCard($systemAddressBook['id'], $userOrCardId);
300
-	}
301
-
302
-	/**
303
-	 * @return array|null
304
-	 */
305
-	public function getLocalSystemAddressBook() {
306
-		if (is_null($this->localSystemAddressBook)) {
307
-			$systemPrincipal = "principals/system/system";
308
-			$this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [
309
-				'{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance'
310
-			]);
311
-		}
312
-
313
-		return $this->localSystemAddressBook;
314
-	}
315
-
316
-	public function syncInstance(\Closure $progressCallback = null) {
317
-		$systemAddressBook = $this->getLocalSystemAddressBook();
318
-		$this->userManager->callForAllUsers(function ($user) use ($systemAddressBook, $progressCallback) {
319
-			$this->updateUser($user);
320
-			if (!is_null($progressCallback)) {
321
-				$progressCallback();
322
-			}
323
-		});
324
-
325
-		// remove no longer existing
326
-		$allCards = $this->backend->getCards($systemAddressBook['id']);
327
-		foreach ($allCards as $card) {
328
-			$vCard = Reader::read($card['carddata']);
329
-			$uid = $vCard->UID->getValue();
330
-			// load backend and see if user exists
331
-			if (!$this->userManager->userExists($uid)) {
332
-				$this->deleteUser($card['uri']);
333
-			}
334
-		}
335
-	}
44
+    /** @var CardDavBackend */
45
+    private $backend;
46
+
47
+    /** @var IUserManager */
48
+    private $userManager;
49
+
50
+    private LoggerInterface $logger;
51
+
52
+    /** @var array */
53
+    private $localSystemAddressBook;
54
+
55
+    /** @var Converter */
56
+    private $converter;
57
+
58
+    /** @var string */
59
+    protected $certPath;
60
+
61
+    /**
62
+     * SyncService constructor.
63
+     */
64
+    public function __construct(CardDavBackend $backend,
65
+                                IUserManager $userManager,
66
+                                LoggerInterface $logger,
67
+                                Converter $converter) {
68
+        $this->backend = $backend;
69
+        $this->userManager = $userManager;
70
+        $this->logger = $logger;
71
+        $this->converter = $converter;
72
+        $this->certPath = '';
73
+    }
74
+
75
+    /**
76
+     * @param string $url
77
+     * @param string $userName
78
+     * @param string $addressBookUrl
79
+     * @param string $sharedSecret
80
+     * @param string $syncToken
81
+     * @param int $targetBookId
82
+     * @param string $targetPrincipal
83
+     * @param array $targetProperties
84
+     * @return string
85
+     * @throws \Exception
86
+     */
87
+    public function syncRemoteAddressBook($url, $userName, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetProperties) {
88
+        // 1. create addressbook
89
+        $book = $this->ensureSystemAddressBookExists($targetPrincipal, $targetBookId, $targetProperties);
90
+        $addressBookId = $book['id'];
91
+
92
+        // 2. query changes
93
+        try {
94
+            $response = $this->requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken);
95
+        } catch (ClientHttpException $ex) {
96
+            if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) {
97
+                // remote server revoked access to the address book, remove it
98
+                $this->backend->deleteAddressBook($addressBookId);
99
+                $this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']);
100
+                throw $ex;
101
+            }
102
+        }
103
+
104
+        // 3. apply changes
105
+        // TODO: use multi-get for download
106
+        foreach ($response['response'] as $resource => $status) {
107
+            $cardUri = basename($resource);
108
+            if (isset($status[200])) {
109
+                $vCard = $this->download($url, $userName, $sharedSecret, $resource);
110
+                $existingCard = $this->backend->getCard($addressBookId, $cardUri);
111
+                if ($existingCard === false) {
112
+                    $this->backend->createCard($addressBookId, $cardUri, $vCard['body']);
113
+                } else {
114
+                    $this->backend->updateCard($addressBookId, $cardUri, $vCard['body']);
115
+                }
116
+            } else {
117
+                $this->backend->deleteCard($addressBookId, $cardUri);
118
+            }
119
+        }
120
+
121
+        return $response['token'];
122
+    }
123
+
124
+    /**
125
+     * @param string $principal
126
+     * @param string $id
127
+     * @param array $properties
128
+     * @return array|null
129
+     * @throws \Sabre\DAV\Exception\BadRequest
130
+     */
131
+    public function ensureSystemAddressBookExists($principal, $id, $properties) {
132
+        $book = $this->backend->getAddressBooksByUri($principal, $id);
133
+        if (!is_null($book)) {
134
+            return $book;
135
+        }
136
+        $this->backend->createAddressBook($principal, $id, $properties);
137
+
138
+        return $this->backend->getAddressBooksByUri($principal, $id);
139
+    }
140
+
141
+    /**
142
+     * Check if there is a valid certPath we should use
143
+     *
144
+     * @return string
145
+     */
146
+    protected function getCertPath() {
147
+
148
+        // we already have a valid certPath
149
+        if ($this->certPath !== '') {
150
+            return $this->certPath;
151
+        }
152
+
153
+        $certManager = \OC::$server->getCertificateManager();
154
+        $certPath = $certManager->getAbsoluteBundlePath();
155
+        if (file_exists($certPath)) {
156
+            $this->certPath = $certPath;
157
+        }
158
+
159
+        return $this->certPath;
160
+    }
161
+
162
+    /**
163
+     * @param string $url
164
+     * @param string $userName
165
+     * @param string $addressBookUrl
166
+     * @param string $sharedSecret
167
+     * @return Client
168
+     */
169
+    protected function getClient($url, $userName, $sharedSecret) {
170
+        $settings = [
171
+            'baseUri' => $url . '/',
172
+            'userName' => $userName,
173
+            'password' => $sharedSecret,
174
+        ];
175
+        $client = new Client($settings);
176
+        $certPath = $this->getCertPath();
177
+        $client->setThrowExceptions(true);
178
+
179
+        if ($certPath !== '' && strpos($url, 'http://') !== 0) {
180
+            $client->addCurlSetting(CURLOPT_CAINFO, $this->certPath);
181
+        }
182
+
183
+        return $client;
184
+    }
185
+
186
+    /**
187
+     * @param string $url
188
+     * @param string $userName
189
+     * @param string $addressBookUrl
190
+     * @param string $sharedSecret
191
+     * @param string $syncToken
192
+     * @return array
193
+     */
194
+    protected function requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken) {
195
+        $client = $this->getClient($url, $userName, $sharedSecret);
196
+
197
+        $body = $this->buildSyncCollectionRequestBody($syncToken);
198
+
199
+        $response = $client->request('REPORT', $addressBookUrl, $body, [
200
+            'Content-Type' => 'application/xml'
201
+        ]);
202
+
203
+        return $this->parseMultiStatus($response['body']);
204
+    }
205
+
206
+    /**
207
+     * @param string $url
208
+     * @param string $userName
209
+     * @param string $sharedSecret
210
+     * @param string $resourcePath
211
+     * @return array
212
+     */
213
+    protected function download($url, $userName, $sharedSecret, $resourcePath) {
214
+        $client = $this->getClient($url, $userName, $sharedSecret);
215
+        return $client->request('GET', $resourcePath);
216
+    }
217
+
218
+    /**
219
+     * @param string|null $syncToken
220
+     * @return string
221
+     */
222
+    private function buildSyncCollectionRequestBody($syncToken) {
223
+        $dom = new \DOMDocument('1.0', 'UTF-8');
224
+        $dom->formatOutput = true;
225
+        $root = $dom->createElementNS('DAV:', 'd:sync-collection');
226
+        $sync = $dom->createElement('d:sync-token', $syncToken);
227
+        $prop = $dom->createElement('d:prop');
228
+        $cont = $dom->createElement('d:getcontenttype');
229
+        $etag = $dom->createElement('d:getetag');
230
+
231
+        $prop->appendChild($cont);
232
+        $prop->appendChild($etag);
233
+        $root->appendChild($sync);
234
+        $root->appendChild($prop);
235
+        $dom->appendChild($root);
236
+        return $dom->saveXML();
237
+    }
238
+
239
+    /**
240
+     * @param string $body
241
+     * @return array
242
+     * @throws \Sabre\Xml\ParseException
243
+     */
244
+    private function parseMultiStatus($body) {
245
+        $xml = new Service();
246
+
247
+        /** @var MultiStatus $multiStatus */
248
+        $multiStatus = $xml->expect('{DAV:}multistatus', $body);
249
+
250
+        $result = [];
251
+        foreach ($multiStatus->getResponses() as $response) {
252
+            $result[$response->getHref()] = $response->getResponseProperties();
253
+        }
254
+
255
+        return ['response' => $result, 'token' => $multiStatus->getSyncToken()];
256
+    }
257
+
258
+    /**
259
+     * @param IUser $user
260
+     */
261
+    public function updateUser(IUser $user) {
262
+        $systemAddressBook = $this->getLocalSystemAddressBook();
263
+        $addressBookId = $systemAddressBook['id'];
264
+        $name = $user->getBackendClassName();
265
+        $userId = $user->getUID();
266
+
267
+        $cardId = "$name:$userId.vcf";
268
+        $card = $this->backend->getCard($addressBookId, $cardId);
269
+        if ($user->isEnabled()) {
270
+            if ($card === false) {
271
+                $vCard = $this->converter->createCardFromUser($user);
272
+                if ($vCard !== null) {
273
+                    $this->backend->createCard($addressBookId, $cardId, $vCard->serialize());
274
+                }
275
+            } else {
276
+                $vCard = $this->converter->createCardFromUser($user);
277
+                if (is_null($vCard)) {
278
+                    $this->backend->deleteCard($addressBookId, $cardId);
279
+                } else {
280
+                    $this->backend->updateCard($addressBookId, $cardId, $vCard->serialize());
281
+                }
282
+            }
283
+        } else {
284
+            $this->backend->deleteCard($addressBookId, $cardId);
285
+        }
286
+    }
287
+
288
+    /**
289
+     * @param IUser|string $userOrCardId
290
+     */
291
+    public function deleteUser($userOrCardId) {
292
+        $systemAddressBook = $this->getLocalSystemAddressBook();
293
+        if ($userOrCardId instanceof IUser) {
294
+            $name = $userOrCardId->getBackendClassName();
295
+            $userId = $userOrCardId->getUID();
296
+
297
+            $userOrCardId = "$name:$userId.vcf";
298
+        }
299
+        $this->backend->deleteCard($systemAddressBook['id'], $userOrCardId);
300
+    }
301
+
302
+    /**
303
+     * @return array|null
304
+     */
305
+    public function getLocalSystemAddressBook() {
306
+        if (is_null($this->localSystemAddressBook)) {
307
+            $systemPrincipal = "principals/system/system";
308
+            $this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [
309
+                '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance'
310
+            ]);
311
+        }
312
+
313
+        return $this->localSystemAddressBook;
314
+    }
315
+
316
+    public function syncInstance(\Closure $progressCallback = null) {
317
+        $systemAddressBook = $this->getLocalSystemAddressBook();
318
+        $this->userManager->callForAllUsers(function ($user) use ($systemAddressBook, $progressCallback) {
319
+            $this->updateUser($user);
320
+            if (!is_null($progressCallback)) {
321
+                $progressCallback();
322
+            }
323
+        });
324
+
325
+        // remove no longer existing
326
+        $allCards = $this->backend->getCards($systemAddressBook['id']);
327
+        foreach ($allCards as $card) {
328
+            $vCard = Reader::read($card['carddata']);
329
+            $uid = $vCard->UID->getValue();
330
+            // load backend and see if user exists
331
+            if (!$this->userManager->userExists($uid)) {
332
+                $this->deleteUser($card['uri']);
333
+            }
334
+        }
335
+    }
336 336
 }
Please login to merge, or discard this patch.
apps/dav/lib/DAV/Sharing/IShareable.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -29,47 +29,47 @@
 block discarded – undo
29 29
  */
30 30
 interface IShareable extends INode {
31 31
 
32
-	/**
33
-	 * Updates the list of shares.
34
-	 *
35
-	 * The first array is a list of people that are to be added to the
36
-	 * resource.
37
-	 *
38
-	 * Every element in the add array has the following properties:
39
-	 *   * href - A url. Usually a mailto: address
40
-	 *   * commonName - Usually a first and last name, or false
41
-	 *   * summary - A description of the share, can also be false
42
-	 *   * readOnly - A boolean value
43
-	 *
44
-	 * Every element in the remove array is just the address string.
45
-	 *
46
-	 * @param array $add
47
-	 * @param array $remove
48
-	 * @return void
49
-	 */
50
-	public function updateShares(array $add, array $remove);
32
+    /**
33
+     * Updates the list of shares.
34
+     *
35
+     * The first array is a list of people that are to be added to the
36
+     * resource.
37
+     *
38
+     * Every element in the add array has the following properties:
39
+     *   * href - A url. Usually a mailto: address
40
+     *   * commonName - Usually a first and last name, or false
41
+     *   * summary - A description of the share, can also be false
42
+     *   * readOnly - A boolean value
43
+     *
44
+     * Every element in the remove array is just the address string.
45
+     *
46
+     * @param array $add
47
+     * @param array $remove
48
+     * @return void
49
+     */
50
+    public function updateShares(array $add, array $remove);
51 51
 
52
-	/**
53
-	 * Returns the list of people whom this resource is shared with.
54
-	 *
55
-	 * Every element in this array should have the following properties:
56
-	 *   * href - Often a mailto: address
57
-	 *   * commonName - Optional, for example a first + last name
58
-	 *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
59
-	 *   * readOnly - boolean
60
-	 *   * summary - Optional, a description for the share
61
-	 *
62
-	 * @return array
63
-	 */
64
-	public function getShares();
52
+    /**
53
+     * Returns the list of people whom this resource is shared with.
54
+     *
55
+     * Every element in this array should have the following properties:
56
+     *   * href - Often a mailto: address
57
+     *   * commonName - Optional, for example a first + last name
58
+     *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
59
+     *   * readOnly - boolean
60
+     *   * summary - Optional, a description for the share
61
+     *
62
+     * @return array
63
+     */
64
+    public function getShares();
65 65
 
66
-	/**
67
-	 * @return int
68
-	 */
69
-	public function getResourceId();
66
+    /**
67
+     * @return int
68
+     */
69
+    public function getResourceId();
70 70
 
71
-	/**
72
-	 * @return string
73
-	 */
74
-	public function getOwner();
71
+    /**
72
+     * @return string
73
+     */
74
+    public function getOwner();
75 75
 }
Please login to merge, or discard this patch.