Code Duplication    Length = 54-55 lines in 2 locations

apps/dav/lib/Connector/Sabre/CustomPropertiesBackend.php 1 location

@@ 250-304 (lines=55) @@
247
	 *
248
	 * @return bool
249
	 */
250
	private function updateProperties($node, $properties) {
251
		$path = $node->getPath();
252
253
		$deleteStatement = 'DELETE FROM `*PREFIX*properties`' .
254
			' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?';
255
256
		$insertStatement = 'INSERT INTO `*PREFIX*properties`' .
257
			' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)';
258
259
		$updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' .
260
			' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?';
261
262
		// TODO: use "insert or update" strategy ?
263
		$existing = $this->getProperties($node, array());
264
		$this->connection->beginTransaction();
265
		foreach ($properties as $propertyName => $propertyValue) {
266
			// If it was null, we need to delete the property
267
			if (is_null($propertyValue)) {
268
				if (array_key_exists($propertyName, $existing)) {
269
					$this->connection->executeUpdate($deleteStatement,
270
						array(
271
							$this->user,
272
							$path,
273
							$propertyName
274
						)
275
					);
276
				}
277
			} else {
278
				if (!array_key_exists($propertyName, $existing)) {
279
					$this->connection->executeUpdate($insertStatement,
280
						array(
281
							$this->user,
282
							$path,
283
							$propertyName,
284
							$propertyValue
285
						)
286
					);
287
				} else {
288
					$this->connection->executeUpdate($updateStatement,
289
						array(
290
							$propertyValue,
291
							$this->user,
292
							$path,
293
							$propertyName
294
						)
295
					);
296
				}
297
			}
298
		}
299
300
		$this->connection->commit();
301
		unset($this->cache[$path]);
302
303
		return true;
304
	}
305
306
	/**
307
	 * Bulk load properties for directory children

apps/dav/lib/DAV/CustomPropertiesBackend.php 1 location

@@ 236-289 (lines=54) @@
233
	 *
234
	 * @return bool
235
	 */
236
	private function updateProperties($path, $properties) {
237
238
		$deleteStatement = 'DELETE FROM `*PREFIX*properties`' .
239
			' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?';
240
241
		$insertStatement = 'INSERT INTO `*PREFIX*properties`' .
242
			' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)';
243
244
		$updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' .
245
			' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?';
246
247
		// TODO: use "insert or update" strategy ?
248
		$existing = $this->getProperties($path, array());
249
		$this->connection->beginTransaction();
250
		foreach ($properties as $propertyName => $propertyValue) {
251
			// If it was null, we need to delete the property
252
			if (is_null($propertyValue)) {
253
				if (array_key_exists($propertyName, $existing)) {
254
					$this->connection->executeUpdate($deleteStatement,
255
						array(
256
							$this->user,
257
							$path,
258
							$propertyName
259
						)
260
					);
261
				}
262
			} else {
263
				if (!array_key_exists($propertyName, $existing)) {
264
					$this->connection->executeUpdate($insertStatement,
265
						array(
266
							$this->user,
267
							$path,
268
							$propertyName,
269
							$propertyValue
270
						)
271
					);
272
				} else {
273
					$this->connection->executeUpdate($updateStatement,
274
						array(
275
							$propertyValue,
276
							$this->user,
277
							$path,
278
							$propertyName
279
						)
280
					);
281
				}
282
			}
283
		}
284
285
		$this->connection->commit();
286
		unset($this->cache[$path]);
287
288
		return true;
289
	}
290
291
}
292