Completed
Pull Request — master (#4106)
by Blizzz
15:12 queued 15s
created
apps/dav/lib/Command/CreateCalendar.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -33,53 +33,53 @@
 block discarded – undo
33 33
 
34 34
 class CreateCalendar extends Command {
35 35
 
36
-	/** @var IUserManager */
37
-	protected $userManager;
36
+    /** @var IUserManager */
37
+    protected $userManager;
38 38
 
39
-	/** @var IGroupManager $groupManager */
40
-	private $groupManager;
39
+    /** @var IGroupManager $groupManager */
40
+    private $groupManager;
41 41
 
42
-	/** @var \OCP\IDBConnection */
43
-	protected $dbConnection;
42
+    /** @var \OCP\IDBConnection */
43
+    protected $dbConnection;
44 44
 
45
-	/**
46
-	 * @param IUserManager $userManager
47
-	 * @param IGroupManager $groupManager
48
-	 * @param IDBConnection $dbConnection
49
-	 */
50
-	function __construct(IUserManager $userManager, IGroupManager $groupManager, IDBConnection $dbConnection) {
51
-		parent::__construct();
52
-		$this->userManager = $userManager;
53
-		$this->groupManager = $groupManager;
54
-		$this->dbConnection = $dbConnection;
55
-	}
45
+    /**
46
+     * @param IUserManager $userManager
47
+     * @param IGroupManager $groupManager
48
+     * @param IDBConnection $dbConnection
49
+     */
50
+    function __construct(IUserManager $userManager, IGroupManager $groupManager, IDBConnection $dbConnection) {
51
+        parent::__construct();
52
+        $this->userManager = $userManager;
53
+        $this->groupManager = $groupManager;
54
+        $this->dbConnection = $dbConnection;
55
+    }
56 56
 
57
-	protected function configure() {
58
-		$this
59
-			->setName('dav:create-calendar')
60
-			->setDescription('Create a dav calendar')
61
-			->addArgument('user',
62
-				InputArgument::REQUIRED,
63
-				'User for whom the calendar will be created')
64
-			->addArgument('name',
65
-				InputArgument::REQUIRED,
66
-				'Name of the calendar');
67
-	}
57
+    protected function configure() {
58
+        $this
59
+            ->setName('dav:create-calendar')
60
+            ->setDescription('Create a dav calendar')
61
+            ->addArgument('user',
62
+                InputArgument::REQUIRED,
63
+                'User for whom the calendar will be created')
64
+            ->addArgument('name',
65
+                InputArgument::REQUIRED,
66
+                'Name of the calendar');
67
+    }
68 68
 
69
-	protected function execute(InputInterface $input, OutputInterface $output) {
70
-		$user = $input->getArgument('user');
71
-		if (!$this->userManager->userExists($user)) {
72
-			throw new \InvalidArgumentException("User <$user> in unknown.");
73
-		}
74
-		$principalBackend = new Principal(
75
-			$this->userManager,
76
-			$this->groupManager
77
-		);
78
-		$random = \OC::$server->getSecureRandom();
79
-		$dispatcher = \OC::$server->getEventDispatcher();
69
+    protected function execute(InputInterface $input, OutputInterface $output) {
70
+        $user = $input->getArgument('user');
71
+        if (!$this->userManager->userExists($user)) {
72
+            throw new \InvalidArgumentException("User <$user> in unknown.");
73
+        }
74
+        $principalBackend = new Principal(
75
+            $this->userManager,
76
+            $this->groupManager
77
+        );
78
+        $random = \OC::$server->getSecureRandom();
79
+        $dispatcher = \OC::$server->getEventDispatcher();
80 80
 
81
-		$name = $input->getArgument('name');
82
-		$caldav = new CalDavBackend($this->dbConnection, $principalBackend, $this->userManager, $random, $dispatcher);
83
-		$caldav->createCalendar("principals/users/$user", $name, []);
84
-	}
81
+        $name = $input->getArgument('name');
82
+        $caldav = new CalDavBackend($this->dbConnection, $principalBackend, $this->userManager, $random, $dispatcher);
83
+        $caldav->createCalendar("principals/users/$user", $name, []);
84
+    }
85 85
 }
Please login to merge, or discard this patch.
apps/dav/lib/Command/CreateAddressBook.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -36,43 +36,43 @@
 block discarded – undo
36 36
 
37 37
 class CreateAddressBook extends Command {
38 38
 
39
-	/** @var IUserManager */
40
-	private $userManager;
39
+    /** @var IUserManager */
40
+    private $userManager;
41 41
 
42
-	/** @var CardDavBackend */
43
-	private $cardDavBackend;
42
+    /** @var CardDavBackend */
43
+    private $cardDavBackend;
44 44
 
45
-	/**
46
-	 * @param IUserManager $userManager
47
-	 * @param CardDavBackend $cardDavBackend
48
-	 */
49
-	function __construct(IUserManager $userManager,
50
-						 CardDavBackend $cardDavBackend
51
-	) {
52
-		parent::__construct();
53
-		$this->userManager = $userManager;
54
-		$this->cardDavBackend = $cardDavBackend;
55
-	}
45
+    /**
46
+     * @param IUserManager $userManager
47
+     * @param CardDavBackend $cardDavBackend
48
+     */
49
+    function __construct(IUserManager $userManager,
50
+                            CardDavBackend $cardDavBackend
51
+    ) {
52
+        parent::__construct();
53
+        $this->userManager = $userManager;
54
+        $this->cardDavBackend = $cardDavBackend;
55
+    }
56 56
 
57
-	protected function configure() {
58
-		$this
59
-				->setName('dav:create-addressbook')
60
-				->setDescription('Create a dav addressbook')
61
-				->addArgument('user',
62
-						InputArgument::REQUIRED,
63
-						'User for whom the addressbook will be created')
64
-				->addArgument('name',
65
-						InputArgument::REQUIRED,
66
-						'Name of the addressbook');
67
-	}
57
+    protected function configure() {
58
+        $this
59
+                ->setName('dav:create-addressbook')
60
+                ->setDescription('Create a dav addressbook')
61
+                ->addArgument('user',
62
+                        InputArgument::REQUIRED,
63
+                        'User for whom the addressbook will be created')
64
+                ->addArgument('name',
65
+                        InputArgument::REQUIRED,
66
+                        'Name of the addressbook');
67
+    }
68 68
 
69
-	protected function execute(InputInterface $input, OutputInterface $output) {
70
-		$user = $input->getArgument('user');
71
-		if (!$this->userManager->userExists($user)) {
72
-			throw new \InvalidArgumentException("User <$user> in unknown.");
73
-		}
69
+    protected function execute(InputInterface $input, OutputInterface $output) {
70
+        $user = $input->getArgument('user');
71
+        if (!$this->userManager->userExists($user)) {
72
+            throw new \InvalidArgumentException("User <$user> in unknown.");
73
+        }
74 74
 
75
-		$name = $input->getArgument('name');
76
-		$this->cardDavBackend->createAddressBook("principals/users/$user", $name, []);
77
-	}
75
+        $name = $input->getArgument('name');
76
+        $this->cardDavBackend->createAddressBook("principals/users/$user", $name, []);
77
+    }
78 78
 }
Please login to merge, or discard this patch.
apps/dav/lib/Capabilities.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -26,11 +26,11 @@
 block discarded – undo
26 26
 
27 27
 class Capabilities implements ICapability {
28 28
 
29
-	public function getCapabilities() {
30
-		return [
31
-			'dav' => [
32
-				'chunking' => '1.0',
33
-			]
34
-		];
35
-	}
29
+    public function getCapabilities() {
30
+        return [
31
+            'dav' => [
32
+                'chunking' => '1.0',
33
+            ]
34
+        ];
35
+    }
36 36
 }
Please login to merge, or discard this patch.
apps/dav/lib/Files/FilesHome.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -27,33 +27,33 @@
 block discarded – undo
27 27
 
28 28
 class FilesHome extends Directory {
29 29
 
30
-	/**
31
-	 * @var array
32
-	 */
33
-	private $principalInfo;
30
+    /**
31
+     * @var array
32
+     */
33
+    private $principalInfo;
34 34
 
35
-	/**
36
-	 * FilesHome constructor.
37
-	 *
38
-	 * @param array $principalInfo
39
-	 */
40
-	public function __construct($principalInfo) {
41
-		$this->principalInfo = $principalInfo;
42
-		$view = \OC\Files\Filesystem::getView();
43
-		$rootInfo = $view->getFileInfo('');
44
-		parent::__construct($view, $rootInfo);
45
-	}
35
+    /**
36
+     * FilesHome constructor.
37
+     *
38
+     * @param array $principalInfo
39
+     */
40
+    public function __construct($principalInfo) {
41
+        $this->principalInfo = $principalInfo;
42
+        $view = \OC\Files\Filesystem::getView();
43
+        $rootInfo = $view->getFileInfo('');
44
+        parent::__construct($view, $rootInfo);
45
+    }
46 46
 
47
-	function delete() {
48
-		throw new Forbidden('Permission denied to delete home folder');
49
-	}
47
+    function delete() {
48
+        throw new Forbidden('Permission denied to delete home folder');
49
+    }
50 50
 
51
-	function getName() {
52
-		list(,$name) = URLUtil::splitPath($this->principalInfo['uri']);
53
-		return $name;
54
-	}
51
+    function getName() {
52
+        list(,$name) = URLUtil::splitPath($this->principalInfo['uri']);
53
+        return $name;
54
+    }
55 55
 
56
-	function setName($name) {
57
-		throw new Forbidden('Permission denied to rename this folder');
58
-	}
56
+    function setName($name) {
57
+        throw new Forbidden('Permission denied to rename this folder');
58
+    }
59 59
 }
Please login to merge, or discard this patch.
apps/dav/lib/Files/BrowserErrorPagePlugin.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -31,78 +31,78 @@
 block discarded – undo
31 31
 use Sabre\DAV\ServerPlugin;
32 32
 
33 33
 class BrowserErrorPagePlugin extends ServerPlugin {
34
-	/** @var Server */
35
-	private $server;
34
+    /** @var Server */
35
+    private $server;
36 36
 
37
-	/**
38
-	 * This initializes the plugin.
39
-	 *
40
-	 * This function is called by Sabre\DAV\Server, after
41
-	 * addPlugin is called.
42
-	 *
43
-	 * This method should set up the required event subscriptions.
44
-	 *
45
-	 * @param Server $server
46
-	 * @return void
47
-	 */
48
-	function initialize(Server $server) {
49
-		$this->server = $server;
50
-		$server->on('exception', array($this, 'logException'), 1000);
51
-	}
37
+    /**
38
+     * This initializes the plugin.
39
+     *
40
+     * This function is called by Sabre\DAV\Server, after
41
+     * addPlugin is called.
42
+     *
43
+     * This method should set up the required event subscriptions.
44
+     *
45
+     * @param Server $server
46
+     * @return void
47
+     */
48
+    function initialize(Server $server) {
49
+        $this->server = $server;
50
+        $server->on('exception', array($this, 'logException'), 1000);
51
+    }
52 52
 
53
-	/**
54
-	 * @param IRequest $request
55
-	 * @return bool
56
-	 */
57
-	public static function isBrowserRequest(IRequest $request) {
58
-		if ($request->getMethod() !== 'GET') {
59
-			return false;
60
-		}
61
-		return $request->isUserAgent([
62
-			Request::USER_AGENT_IE,
63
-			Request::USER_AGENT_MS_EDGE,
64
-			Request::USER_AGENT_CHROME,
65
-			Request::USER_AGENT_FIREFOX,
66
-			Request::USER_AGENT_SAFARI,
67
-		]);
68
-	}
53
+    /**
54
+     * @param IRequest $request
55
+     * @return bool
56
+     */
57
+    public static function isBrowserRequest(IRequest $request) {
58
+        if ($request->getMethod() !== 'GET') {
59
+            return false;
60
+        }
61
+        return $request->isUserAgent([
62
+            Request::USER_AGENT_IE,
63
+            Request::USER_AGENT_MS_EDGE,
64
+            Request::USER_AGENT_CHROME,
65
+            Request::USER_AGENT_FIREFOX,
66
+            Request::USER_AGENT_SAFARI,
67
+        ]);
68
+    }
69 69
 
70
-	/**
71
-	 * @param \Exception $ex
72
-	 */
73
-	public function logException(\Exception $ex) {
74
-		if ($ex instanceof Exception) {
75
-			$httpCode = $ex->getHTTPCode();
76
-			$headers = $ex->getHTTPHeaders($this->server);
77
-		} else {
78
-			$httpCode = 500;
79
-			$headers = [];
80
-		}
81
-		$this->server->httpResponse->addHeaders($headers);
82
-		$this->server->httpResponse->setStatus($httpCode);
83
-		$body = $this->generateBody();
84
-		$this->server->httpResponse->setBody($body);
85
-		$this->sendResponse();
86
-	}
70
+    /**
71
+     * @param \Exception $ex
72
+     */
73
+    public function logException(\Exception $ex) {
74
+        if ($ex instanceof Exception) {
75
+            $httpCode = $ex->getHTTPCode();
76
+            $headers = $ex->getHTTPHeaders($this->server);
77
+        } else {
78
+            $httpCode = 500;
79
+            $headers = [];
80
+        }
81
+        $this->server->httpResponse->addHeaders($headers);
82
+        $this->server->httpResponse->setStatus($httpCode);
83
+        $body = $this->generateBody();
84
+        $this->server->httpResponse->setBody($body);
85
+        $this->sendResponse();
86
+    }
87 87
 
88
-	/**
89
-	 * @codeCoverageIgnore
90
-	 * @return bool|string
91
-	 */
92
-	public function generateBody() {
93
-		$request = \OC::$server->getRequest();
94
-		$content = new OC_Template('dav', 'exception', 'guest');
95
-		$content->assign('title', $this->server->httpResponse->getStatusText());
96
-		$content->assign('remoteAddr', $request->getRemoteAddress());
97
-		$content->assign('requestID', $request->getId());
98
-		return $content->fetchPage();
99
-	}
88
+    /**
89
+     * @codeCoverageIgnore
90
+     * @return bool|string
91
+     */
92
+    public function generateBody() {
93
+        $request = \OC::$server->getRequest();
94
+        $content = new OC_Template('dav', 'exception', 'guest');
95
+        $content->assign('title', $this->server->httpResponse->getStatusText());
96
+        $content->assign('remoteAddr', $request->getRemoteAddress());
97
+        $content->assign('requestID', $request->getId());
98
+        return $content->fetchPage();
99
+    }
100 100
 
101
-	/**
102
-	 * @codeCoverageIgnore
103
-	 */
104
-	public function sendResponse() {
105
-		$this->server->sapi->sendResponse($this->server->httpResponse);
106
-		exit();
107
-	}
101
+    /**
102
+     * @codeCoverageIgnore
103
+     */
104
+    public function sendResponse() {
105
+        $this->server->sapi->sendResponse($this->server->httpResponse);
106
+        exit();
107
+    }
108 108
 }
Please login to merge, or discard this patch.
apps/dav/lib/Files/RootCollection.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -28,30 +28,30 @@
 block discarded – undo
28 28
 
29 29
 class RootCollection extends AbstractPrincipalCollection {
30 30
 
31
-	/**
32
-	 * This method returns a node for a principal.
33
-	 *
34
-	 * The passed array contains principal information, and is guaranteed to
35
-	 * at least contain a uri item. Other properties may or may not be
36
-	 * supplied by the authentication backend.
37
-	 *
38
-	 * @param array $principalInfo
39
-	 * @return INode
40
-	 */
41
-	function getChildForPrincipal(array $principalInfo) {
42
-		list(,$name) = URLUtil::splitPath($principalInfo['uri']);
43
-		$user = \OC::$server->getUserSession()->getUser();
44
-		if (is_null($user) || $name !== $user->getUID()) {
45
-			// a user is only allowed to see their own home contents, so in case another collection
46
-			// is accessed, we return a simple empty collection for now
47
-			// in the future this could be considered to be used for accessing shared files
48
-			return new SimpleCollection($name);
49
-		}
50
-		return new FilesHome($principalInfo);
51
-	}
31
+    /**
32
+     * This method returns a node for a principal.
33
+     *
34
+     * The passed array contains principal information, and is guaranteed to
35
+     * at least contain a uri item. Other properties may or may not be
36
+     * supplied by the authentication backend.
37
+     *
38
+     * @param array $principalInfo
39
+     * @return INode
40
+     */
41
+    function getChildForPrincipal(array $principalInfo) {
42
+        list(,$name) = URLUtil::splitPath($principalInfo['uri']);
43
+        $user = \OC::$server->getUserSession()->getUser();
44
+        if (is_null($user) || $name !== $user->getUID()) {
45
+            // a user is only allowed to see their own home contents, so in case another collection
46
+            // is accessed, we return a simple empty collection for now
47
+            // in the future this could be considered to be used for accessing shared files
48
+            return new SimpleCollection($name);
49
+        }
50
+        return new FilesHome($principalInfo);
51
+    }
52 52
 
53
-	function getName() {
54
-		return 'files';
55
-	}
53
+    function getName() {
54
+        return 'files';
55
+    }
56 56
 
57 57
 }
Please login to merge, or discard this patch.
apps/dav/lib/Files/CustomPropertiesBackend.php 1 patch
Indentation   +233 added lines, -233 removed lines patch added patch discarded remove patch
@@ -32,238 +32,238 @@
 block discarded – undo
32 32
 
33 33
 class CustomPropertiesBackend implements BackendInterface {
34 34
 
35
-	/**
36
-	 * Ignored properties
37
-	 *
38
-	 * @var array
39
-	 */
40
-	private $ignoredProperties = array(
41
-		'{DAV:}getcontentlength',
42
-		'{DAV:}getcontenttype',
43
-		'{DAV:}getetag',
44
-		'{DAV:}quota-used-bytes',
45
-		'{DAV:}quota-available-bytes',
46
-		'{http://owncloud.org/ns}permissions',
47
-		'{http://owncloud.org/ns}downloadURL',
48
-		'{http://owncloud.org/ns}dDC',
49
-		'{http://owncloud.org/ns}size',
50
-	);
51
-
52
-	/**
53
-	 * @var Tree
54
-	 */
55
-	private $tree;
56
-
57
-	/**
58
-	 * @var IDBConnection
59
-	 */
60
-	private $connection;
61
-
62
-	/**
63
-	 * @var string
64
-	 */
65
-	private $user;
66
-
67
-	/**
68
-	 * Properties cache
69
-	 *
70
-	 * @var array
71
-	 */
72
-	private $cache = [];
73
-
74
-	/**
75
-	 * @param Tree $tree node tree
76
-	 * @param IDBConnection $connection database connection
77
-	 * @param IUser $user owner of the tree and properties
78
-	 */
79
-	public function __construct(
80
-		Tree $tree,
81
-		IDBConnection $connection,
82
-		IUser $user) {
83
-		$this->tree = $tree;
84
-		$this->connection = $connection;
85
-		$this->user = $user->getUID();
86
-	}
87
-
88
-	/**
89
-	 * Fetches properties for a path.
90
-	 *
91
-	 * @param string $path
92
-	 * @param PropFind $propFind
93
-	 * @return void
94
-	 */
95
-	public function propFind($path, PropFind $propFind) {
96
-
97
-		$requestedProps = $propFind->get404Properties();
98
-
99
-		// these might appear
100
-		$requestedProps = array_diff(
101
-			$requestedProps,
102
-			$this->ignoredProperties
103
-		);
104
-
105
-		if (empty($requestedProps)) {
106
-			return;
107
-		}
108
-
109
-		$props = $this->getProperties($path, $requestedProps);
110
-		foreach ($props as $propName => $propValue) {
111
-			$propFind->set($propName, $propValue);
112
-		}
113
-	}
114
-
115
-	/**
116
-	 * Updates properties for a path
117
-	 *
118
-	 * @param string $path
119
-	 * @param PropPatch $propPatch
120
-	 *
121
-	 * @return void
122
-	 */
123
-	public function propPatch($path, PropPatch $propPatch) {
124
-		$propPatch->handleRemaining(function($changedProps) use ($path) {
125
-			return $this->updateProperties($path, $changedProps);
126
-		});
127
-	}
128
-
129
-	/**
130
-	 * This method is called after a node is deleted.
131
-	 *
132
-	 * @param string $path path of node for which to delete properties
133
-	 */
134
-	public function delete($path) {
135
-		$statement = $this->connection->prepare(
136
-			'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'
137
-		);
138
-		$statement->execute(array($this->user, $path));
139
-		$statement->closeCursor();
140
-
141
-		unset($this->cache[$path]);
142
-	}
143
-
144
-	/**
145
-	 * This method is called after a successful MOVE
146
-	 *
147
-	 * @param string $source
148
-	 * @param string $destination
149
-	 *
150
-	 * @return void
151
-	 */
152
-	public function move($source, $destination) {
153
-		$statement = $this->connection->prepare(
154
-			'UPDATE `*PREFIX*properties` SET `propertypath` = ?' .
155
-			' WHERE `userid` = ? AND `propertypath` = ?'
156
-		);
157
-		$statement->execute(array($destination, $this->user, $source));
158
-		$statement->closeCursor();
159
-	}
160
-
161
-	/**
162
-	 * Returns a list of properties for this nodes.;
163
-	 * @param string $path
164
-	 * @param array $requestedProperties requested properties or empty array for "all"
165
-	 * @return array
166
-	 * @note The properties list is a list of propertynames the client
167
-	 * requested, encoded as xmlnamespace#tagName, for example:
168
-	 * http://www.example.org/namespace#author If the array is empty, all
169
-	 * properties should be returned
170
-	 */
171
-	private function getProperties($path, array $requestedProperties) {
172
-		if (isset($this->cache[$path])) {
173
-			return $this->cache[$path];
174
-		}
175
-
176
-		// TODO: chunking if more than 1000 properties
177
-		$sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?';
178
-
179
-		$whereValues = array($this->user, $path);
180
-		$whereTypes = array(null, null);
181
-
182
-		if (!empty($requestedProperties)) {
183
-			// request only a subset
184
-			$sql .= ' AND `propertyname` in (?)';
185
-			$whereValues[] = $requestedProperties;
186
-			$whereTypes[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY;
187
-		}
188
-
189
-		$result = $this->connection->executeQuery(
190
-			$sql,
191
-			$whereValues,
192
-			$whereTypes
193
-		);
194
-
195
-		$props = [];
196
-		while ($row = $result->fetch()) {
197
-			$props[$row['propertyname']] = $row['propertyvalue'];
198
-		}
199
-
200
-		$result->closeCursor();
201
-
202
-		$this->cache[$path] = $props;
203
-		return $props;
204
-	}
205
-
206
-	/**
207
-	 * Update properties
208
-	 *
209
-	 * @param string $path node for which to update properties
210
-	 * @param array $properties array of properties to update
211
-	 *
212
-	 * @return bool
213
-	 */
214
-	private function updateProperties($path, $properties) {
215
-
216
-		$deleteStatement = 'DELETE FROM `*PREFIX*properties`' .
217
-			' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?';
218
-
219
-		$insertStatement = 'INSERT INTO `*PREFIX*properties`' .
220
-			' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)';
221
-
222
-		$updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' .
223
-			' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?';
224
-
225
-		// TODO: use "insert or update" strategy ?
226
-		$existing = $this->getProperties($path, array());
227
-		$this->connection->beginTransaction();
228
-		foreach ($properties as $propertyName => $propertyValue) {
229
-			// If it was null, we need to delete the property
230
-			if (is_null($propertyValue)) {
231
-				if (array_key_exists($propertyName, $existing)) {
232
-					$this->connection->executeUpdate($deleteStatement,
233
-						array(
234
-							$this->user,
235
-							$path,
236
-							$propertyName
237
-						)
238
-					);
239
-				}
240
-			} else {
241
-				if (!array_key_exists($propertyName, $existing)) {
242
-					$this->connection->executeUpdate($insertStatement,
243
-						array(
244
-							$this->user,
245
-							$path,
246
-							$propertyName,
247
-							$propertyValue
248
-						)
249
-					);
250
-				} else {
251
-					$this->connection->executeUpdate($updateStatement,
252
-						array(
253
-							$propertyValue,
254
-							$this->user,
255
-							$path,
256
-							$propertyName
257
-						)
258
-					);
259
-				}
260
-			}
261
-		}
262
-
263
-		$this->connection->commit();
264
-		unset($this->cache[$path]);
265
-
266
-		return true;
267
-	}
35
+    /**
36
+     * Ignored properties
37
+     *
38
+     * @var array
39
+     */
40
+    private $ignoredProperties = array(
41
+        '{DAV:}getcontentlength',
42
+        '{DAV:}getcontenttype',
43
+        '{DAV:}getetag',
44
+        '{DAV:}quota-used-bytes',
45
+        '{DAV:}quota-available-bytes',
46
+        '{http://owncloud.org/ns}permissions',
47
+        '{http://owncloud.org/ns}downloadURL',
48
+        '{http://owncloud.org/ns}dDC',
49
+        '{http://owncloud.org/ns}size',
50
+    );
51
+
52
+    /**
53
+     * @var Tree
54
+     */
55
+    private $tree;
56
+
57
+    /**
58
+     * @var IDBConnection
59
+     */
60
+    private $connection;
61
+
62
+    /**
63
+     * @var string
64
+     */
65
+    private $user;
66
+
67
+    /**
68
+     * Properties cache
69
+     *
70
+     * @var array
71
+     */
72
+    private $cache = [];
73
+
74
+    /**
75
+     * @param Tree $tree node tree
76
+     * @param IDBConnection $connection database connection
77
+     * @param IUser $user owner of the tree and properties
78
+     */
79
+    public function __construct(
80
+        Tree $tree,
81
+        IDBConnection $connection,
82
+        IUser $user) {
83
+        $this->tree = $tree;
84
+        $this->connection = $connection;
85
+        $this->user = $user->getUID();
86
+    }
87
+
88
+    /**
89
+     * Fetches properties for a path.
90
+     *
91
+     * @param string $path
92
+     * @param PropFind $propFind
93
+     * @return void
94
+     */
95
+    public function propFind($path, PropFind $propFind) {
96
+
97
+        $requestedProps = $propFind->get404Properties();
98
+
99
+        // these might appear
100
+        $requestedProps = array_diff(
101
+            $requestedProps,
102
+            $this->ignoredProperties
103
+        );
104
+
105
+        if (empty($requestedProps)) {
106
+            return;
107
+        }
108
+
109
+        $props = $this->getProperties($path, $requestedProps);
110
+        foreach ($props as $propName => $propValue) {
111
+            $propFind->set($propName, $propValue);
112
+        }
113
+    }
114
+
115
+    /**
116
+     * Updates properties for a path
117
+     *
118
+     * @param string $path
119
+     * @param PropPatch $propPatch
120
+     *
121
+     * @return void
122
+     */
123
+    public function propPatch($path, PropPatch $propPatch) {
124
+        $propPatch->handleRemaining(function($changedProps) use ($path) {
125
+            return $this->updateProperties($path, $changedProps);
126
+        });
127
+    }
128
+
129
+    /**
130
+     * This method is called after a node is deleted.
131
+     *
132
+     * @param string $path path of node for which to delete properties
133
+     */
134
+    public function delete($path) {
135
+        $statement = $this->connection->prepare(
136
+            'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'
137
+        );
138
+        $statement->execute(array($this->user, $path));
139
+        $statement->closeCursor();
140
+
141
+        unset($this->cache[$path]);
142
+    }
143
+
144
+    /**
145
+     * This method is called after a successful MOVE
146
+     *
147
+     * @param string $source
148
+     * @param string $destination
149
+     *
150
+     * @return void
151
+     */
152
+    public function move($source, $destination) {
153
+        $statement = $this->connection->prepare(
154
+            'UPDATE `*PREFIX*properties` SET `propertypath` = ?' .
155
+            ' WHERE `userid` = ? AND `propertypath` = ?'
156
+        );
157
+        $statement->execute(array($destination, $this->user, $source));
158
+        $statement->closeCursor();
159
+    }
160
+
161
+    /**
162
+     * Returns a list of properties for this nodes.;
163
+     * @param string $path
164
+     * @param array $requestedProperties requested properties or empty array for "all"
165
+     * @return array
166
+     * @note The properties list is a list of propertynames the client
167
+     * requested, encoded as xmlnamespace#tagName, for example:
168
+     * http://www.example.org/namespace#author If the array is empty, all
169
+     * properties should be returned
170
+     */
171
+    private function getProperties($path, array $requestedProperties) {
172
+        if (isset($this->cache[$path])) {
173
+            return $this->cache[$path];
174
+        }
175
+
176
+        // TODO: chunking if more than 1000 properties
177
+        $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?';
178
+
179
+        $whereValues = array($this->user, $path);
180
+        $whereTypes = array(null, null);
181
+
182
+        if (!empty($requestedProperties)) {
183
+            // request only a subset
184
+            $sql .= ' AND `propertyname` in (?)';
185
+            $whereValues[] = $requestedProperties;
186
+            $whereTypes[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY;
187
+        }
188
+
189
+        $result = $this->connection->executeQuery(
190
+            $sql,
191
+            $whereValues,
192
+            $whereTypes
193
+        );
194
+
195
+        $props = [];
196
+        while ($row = $result->fetch()) {
197
+            $props[$row['propertyname']] = $row['propertyvalue'];
198
+        }
199
+
200
+        $result->closeCursor();
201
+
202
+        $this->cache[$path] = $props;
203
+        return $props;
204
+    }
205
+
206
+    /**
207
+     * Update properties
208
+     *
209
+     * @param string $path node for which to update properties
210
+     * @param array $properties array of properties to update
211
+     *
212
+     * @return bool
213
+     */
214
+    private function updateProperties($path, $properties) {
215
+
216
+        $deleteStatement = 'DELETE FROM `*PREFIX*properties`' .
217
+            ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?';
218
+
219
+        $insertStatement = 'INSERT INTO `*PREFIX*properties`' .
220
+            ' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)';
221
+
222
+        $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' .
223
+            ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?';
224
+
225
+        // TODO: use "insert or update" strategy ?
226
+        $existing = $this->getProperties($path, array());
227
+        $this->connection->beginTransaction();
228
+        foreach ($properties as $propertyName => $propertyValue) {
229
+            // If it was null, we need to delete the property
230
+            if (is_null($propertyValue)) {
231
+                if (array_key_exists($propertyName, $existing)) {
232
+                    $this->connection->executeUpdate($deleteStatement,
233
+                        array(
234
+                            $this->user,
235
+                            $path,
236
+                            $propertyName
237
+                        )
238
+                    );
239
+                }
240
+            } else {
241
+                if (!array_key_exists($propertyName, $existing)) {
242
+                    $this->connection->executeUpdate($insertStatement,
243
+                        array(
244
+                            $this->user,
245
+                            $path,
246
+                            $propertyName,
247
+                            $propertyValue
248
+                        )
249
+                    );
250
+                } else {
251
+                    $this->connection->executeUpdate($updateStatement,
252
+                        array(
253
+                            $propertyValue,
254
+                            $this->user,
255
+                            $path,
256
+                            $propertyName
257
+                        )
258
+                    );
259
+                }
260
+            }
261
+        }
262
+
263
+        $this->connection->commit();
264
+        unset($this->cache[$path]);
265
+
266
+        return true;
267
+    }
268 268
 
269 269
 }
Please login to merge, or discard this patch.
apps/dav/lib/Files/Sharing/PublicLinkCheckPlugin.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -32,33 +32,33 @@
 block discarded – undo
32 32
  * Verify that the public link share is valid
33 33
  */
34 34
 class PublicLinkCheckPlugin extends ServerPlugin {
35
-	/**
36
-	 * @var FileInfo
37
-	 */
38
-	private $fileInfo;
35
+    /**
36
+     * @var FileInfo
37
+     */
38
+    private $fileInfo;
39 39
 
40
-	/**
41
-	 * @param FileInfo $fileInfo
42
-	 */
43
-	public function setFileInfo($fileInfo) {
44
-		$this->fileInfo = $fileInfo;
45
-	}
40
+    /**
41
+     * @param FileInfo $fileInfo
42
+     */
43
+    public function setFileInfo($fileInfo) {
44
+        $this->fileInfo = $fileInfo;
45
+    }
46 46
 
47
-	/**
48
-	 * This initializes the plugin.
49
-	 *
50
-	 * @param \Sabre\DAV\Server $server Sabre server
51
-	 *
52
-	 * @return void
53
-	 */
54
-	public function initialize(\Sabre\DAV\Server $server) {
55
-		$server->on('beforeMethod', [$this, 'beforeMethod']);
56
-	}
47
+    /**
48
+     * This initializes the plugin.
49
+     *
50
+     * @param \Sabre\DAV\Server $server Sabre server
51
+     *
52
+     * @return void
53
+     */
54
+    public function initialize(\Sabre\DAV\Server $server) {
55
+        $server->on('beforeMethod', [$this, 'beforeMethod']);
56
+    }
57 57
 
58
-	public function beforeMethod(RequestInterface $request, ResponseInterface $response){
59
-		// verify that the owner didn't have his share permissions revoked
60
-		if ($this->fileInfo && !$this->fileInfo->isShareable()) {
61
-			throw new NotFound();
62
-		}
63
-	}
58
+    public function beforeMethod(RequestInterface $request, ResponseInterface $response){
59
+        // verify that the owner didn't have his share permissions revoked
60
+        if ($this->fileInfo && !$this->fileInfo->isShareable()) {
61
+            throw new NotFound();
62
+        }
63
+    }
64 64
 }
Please login to merge, or discard this patch.
apps/dav/lib/Files/Sharing/FilesDropPlugin.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -33,52 +33,52 @@
 block discarded – undo
33 33
  */
34 34
 class FilesDropPlugin extends ServerPlugin {
35 35
 
36
-	/** @var View */
37
-	private $view;
36
+    /** @var View */
37
+    private $view;
38 38
 
39
-	/** @var bool */
40
-	private $enabled = false;
39
+    /** @var bool */
40
+    private $enabled = false;
41 41
 
42
-	/**
43
-	 * @param View $view
44
-	 */
45
-	public function setView($view) {
46
-		$this->view = $view;
47
-	}
42
+    /**
43
+     * @param View $view
44
+     */
45
+    public function setView($view) {
46
+        $this->view = $view;
47
+    }
48 48
 
49
-	public function enable() {
50
-		$this->enabled = true;
51
-	}
49
+    public function enable() {
50
+        $this->enabled = true;
51
+    }
52 52
 
53 53
 
54
-	/**
55
-	 * This initializes the plugin.
56
-	 *
57
-	 * @param \Sabre\DAV\Server $server Sabre server
58
-	 *
59
-	 * @return void
60
-	 * @throws MethodNotAllowed
61
-	 */
62
-	public function initialize(\Sabre\DAV\Server $server) {
63
-		$server->on('beforeMethod', [$this, 'beforeMethod'], 999);
64
-		$this->enabled = false;
65
-	}
54
+    /**
55
+     * This initializes the plugin.
56
+     *
57
+     * @param \Sabre\DAV\Server $server Sabre server
58
+     *
59
+     * @return void
60
+     * @throws MethodNotAllowed
61
+     */
62
+    public function initialize(\Sabre\DAV\Server $server) {
63
+        $server->on('beforeMethod', [$this, 'beforeMethod'], 999);
64
+        $this->enabled = false;
65
+    }
66 66
 
67
-	public function beforeMethod(RequestInterface $request, ResponseInterface $response){
67
+    public function beforeMethod(RequestInterface $request, ResponseInterface $response){
68 68
 
69
-		if (!$this->enabled) {
70
-			return;
71
-		}
69
+        if (!$this->enabled) {
70
+            return;
71
+        }
72 72
 
73
-		if ($request->getMethod() !== 'PUT') {
74
-			throw new MethodNotAllowed('Only PUT is allowed on files drop');
75
-		}
73
+        if ($request->getMethod() !== 'PUT') {
74
+            throw new MethodNotAllowed('Only PUT is allowed on files drop');
75
+        }
76 76
 
77
-		$path = explode('/', $request->getPath());
78
-		$path = array_pop($path);
77
+        $path = explode('/', $request->getPath());
78
+        $path = array_pop($path);
79 79
 
80
-		$newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view);
81
-		$url = $request->getBaseUrl() . $newName;
82
-		$request->setUrl($url);
83
-	}
80
+        $newName = \OC_Helper::buildNotExistingFileNameForView('/', $path, $this->view);
81
+        $url = $request->getBaseUrl() . $newName;
82
+        $request->setUrl($url);
83
+    }
84 84
 }
Please login to merge, or discard this patch.