ItemMapper::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright (c) 2015 Victor Dubiniuk <[email protected]>
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later.
6
 * See the COPYING-README file.
7
 */
8
9
namespace OCA\Files_Antivirus\Db;
10
11
use OCP\AppFramework\Db\DoesNotExistException;
12
use OCP\AppFramework\Db\Entity;
13
use OCP\AppFramework\Db\Mapper;
14
use OCP\IDBConnection;
15
16
class ItemMapper extends Mapper {
0 ignored issues
show
Deprecated Code introduced by
The class OCP\AppFramework\Db\Mapper has been deprecated with message: 14.0.0 Move over to QBMapper

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
17
	public function __construct(IDBConnection $db) {
18
		parent::__construct($db, 'files_antivirus', Item::class);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::__construct() has been deprecated with message: 14.0.0 Move over to QBMapper

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
19
	}
20
21
	/**
22
	 * Find rule by id
23
	 * @param int $fileid
24
	 * @return Rule
25
	 * @throws DoesNotExistException
26
	 */
27
	public function findByFileId($fileid) {
28
		$sql = 'SELECT * FROM ' . $this->getTableName() .' WHERE fileid = ?';
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::getTableName() has been deprecated with message: 14.0.0 Move over to QBMapper

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
29
		return $this->findEntity($sql, [$fileid]);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::findEntity() has been deprecated with message: 14.0.0 Move over to QBMapper

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
30
	}
31
32
	public function delete(Entity $entity) {
33
		if (!($entity instanceof Item)) {
34
			throw new \InvalidArgumentException();
35
		}
36
37
		$qb = $this->db->getQueryBuilder();
38
39
		$qb->delete('files_antivirus')
40
			->where(
41
				$qb->expr()->eq('fileid', $qb->createNamedParameter($entity->getFileid()))
42
			);
43
		$qb->execute();
0 ignored issues
show
Deprecated Code introduced by
The method OCP\DB\QueryBuilder\IQueryBuilder::execute() has been deprecated with message: 22.0.0 Use executeQuery or executeUpdate

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
44
45
		return $entity;
46
	}
47
48
	/**
49
	 * Creates a new entry in the db from an entity
50
	 * @param Entity $entity the entity that should be created
51
	 * @return Entity the saved entity with the set id
52
	 * @since 7.0.0
53
	 * @deprecated 14.0.0 Move over to QBMapper
54
	 */
55
	public function insert(Entity $entity) {
56
		// get updated fields to save, fields have to be set using a setter to
57
		// be saved
58
		$properties = $entity->getUpdatedFields();
59
		$values = '';
60
		$columns = '';
61
		$params = [];
62
63
		// build the fields
64
		$i = 0;
65
		foreach ($properties as $property => $updated) {
66
			$column = $entity->propertyToColumn($property);
67
			$getter = 'get' . ucfirst($property);
68
69
			$columns .= '`' . $column . '`';
70
			$values .= '?';
71
72
			// only append colon if there are more entries
73
			if ($i < count($properties) - 1) {
74
				$columns .= ',';
75
				$values .= ',';
76
			}
77
78
			$params[] = $entity->$getter();
79
			$i++;
80
		}
81
82
		$sql = 'INSERT INTO `' . $this->tableName . '`(' .
83
			$columns . ') VALUES(' . $values . ')';
84
85
		$stmt = $this->execute($sql, $params);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::execute() has been deprecated with message: 14.0.0 Move over to QBMapper

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
86
87
		$stmt->closeCursor();
0 ignored issues
show
Deprecated Code introduced by
The method OCP\DB\IPreparedStatement::closeCursor() has been deprecated with message: 21.0.0 use \OCP\DB\IResult::closeCursor on the \OCP\DB\IResult returned by \OCP\IDBConnection::prepare

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
88
89
		return $entity;
90
	}
91
}
92