Code Duplication    Length = 12-16 lines in 5 locations

lib/private/Security/CredentialsManager.php 1 location

@@ 78-93 (lines=16) @@
75
	 * @param string $identifier
76
	 * @return mixed
77
	 */
78
	public function retrieve($userId, $identifier) {
79
		$qb = $this->dbConnection->getQueryBuilder();
80
		$qb->select('credentials')
81
			->from(self::DB_TABLE)
82
			->where($qb->expr()->eq('user', $qb->createNamedParameter($userId)))
83
			->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier)))
84
		;
85
		$result = $qb->execute()->fetch();
86
87
		if (!$result) {
88
			return null;
89
		}
90
		$value = $result['credentials'];
91
92
		return json_decode($this->crypto->decrypt($value), true);
93
	}
94
95
	/**
96
	 * Delete a set of credentials

lib/private/Group/Database.php 1 location

@@ 153-168 (lines=16) @@
150
	 *
151
	 * Checks whether the user is member of a group or not.
152
	 */
153
	public function inGroup( $uid, $gid ) {
154
		$this->fixDI();
155
156
		// check
157
		$qb = $this->dbConn->getQueryBuilder();
158
		$cursor = $qb->select('uid')
159
			->from('group_user')
160
			->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid)))
161
			->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid)))
162
			->execute();
163
164
		$result = $cursor->fetch();
165
		$cursor->closeCursor();
166
167
		return $result ? true : false;
168
	}
169
170
	/**
171
	 * Add a user to a group

apps/dav/lib/CalDAV/CalDavBackend.php 2 locations

@@ 210-222 (lines=13) @@
207
	 * @param bool $excludeBirthday
208
	 * @return int
209
	 */
210
	public function getCalendarsForUserCount($principalUri, $excludeBirthday = true) {
211
		$principalUri = $this->convertPrincipal($principalUri, true);
212
		$query = $this->db->getQueryBuilder();
213
		$query->select($query->createFunction('COUNT(*)'))
214
			->from('calendars')
215
			->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)));
216
217
		if ($excludeBirthday) {
218
			$query->andWhere($query->expr()->neq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI)));
219
		}
220
221
		return (int)$query->execute()->fetchColumn();
222
	}
223
224
	/**
225
	 * Returns a list of calendars for a principal.
@@ 2190-2201 (lines=12) @@
2187
	 * @param \OCA\DAV\CalDAV\Calendar $calendar
2188
	 * @return mixed
2189
	 */
2190
	public function getPublishStatus($calendar) {
2191
		$query = $this->db->getQueryBuilder();
2192
		$result = $query->select('publicuri')
2193
			->from('dav_shares')
2194
			->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId())))
2195
			->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC)))
2196
			->execute();
2197
2198
		$row = $result->fetch();
2199
		$result->closeCursor();
2200
		return $row ? reset($row) : false;
2201
	}
2202
2203
	/**
2204
	 * @param int $resourceId

lib/private/Authentication/Token/PublicKeyTokenMapper.php 1 location

@@ 173-186 (lines=14) @@
170
		$qb->execute();
171
	}
172
173
	public function hasExpiredTokens(string $uid): bool {
174
		$qb = $this->db->getQueryBuilder();
175
		$qb->select('*')
176
			->from('authtoken')
177
			->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid)))
178
			->andWhere($qb->expr()->eq('password_invalid', $qb->createNamedParameter(true), IQueryBuilder::PARAM_BOOL))
179
			->setMaxResults(1);
180
181
		$cursor = $qb->execute();
182
		$data = $cursor->fetchAll();
183
		$cursor->closeCursor();
184
185
		return count($data) === 1;
186
	}
187
}
188