Skip to content

Commit

Permalink
Merge pull request #35426 from nextcloud/cleanup/contactintegration
Browse files Browse the repository at this point in the history
Cleanup contactsinteraction
  • Loading branch information
CarlSchwan authored Nov 30, 2022
2 parents d8d15c3 + 6828a3b commit f4adfd1
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 87 deletions.
19 changes: 7 additions & 12 deletions apps/contactsinteraction/lib/AddressBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,13 @@
use Sabre\DAVACL\IACL;

class AddressBook extends ExternalAddressBook implements IACL {
public const URI = 'recent';

use ACLTrait;

/** @var RecentContactMapper */
private $mapper;

/** @var IL10N */
private $l10n;
public const URI = 'recent';

/** @var string */
private $principalUri;
private RecentContactMapper $mapper;
private IL10N $l10n;
private string $principalUri;

public function __construct(RecentContactMapper $mapper,
IL10N $l10n,
Expand Down Expand Up @@ -81,7 +76,7 @@ public function createFile($name, $data = null) {
* @inheritDoc
* @throws NotFound
*/
public function getChild($name) {
public function getChild($name): Card {
try {
return new Card(
$this->mapper->find(
Expand Down Expand Up @@ -115,7 +110,7 @@ function (RecentContact $contact) {
/**
* @inheritDoc
*/
public function childExists($name) {
public function childExists($name): bool {
try {
$this->mapper->find(
$this->getUid(),
Expand Down Expand Up @@ -160,7 +155,7 @@ public function getOwner(): string {
/**
* @inheritDoc
*/
public function getACL() {
public function getACL(): array {
return [
[
'privilege' => '{DAV:}read',
Expand Down
4 changes: 1 addition & 3 deletions apps/contactsinteraction/lib/BackgroundJob/CleanupJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
use OCP\BackgroundJob\TimedJob;

class CleanupJob extends TimedJob {

/** @var RecentContactMapper */
private $mapper;
private RecentContactMapper $mapper;

public function __construct(ITimeFactory $time,
RecentContactMapper $mapper) {
Expand Down
11 changes: 3 additions & 8 deletions apps/contactsinteraction/lib/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,9 @@
class Card implements ICard, IACL {
use ACLTrait;

/** @var RecentContact */
private $contact;

/** @var string */
private $principal;

/** @var array */
private $acls;
private RecentContact $contact;
private string $principal;
private array $acls;

public function __construct(RecentContact $contact, string $principal, array $acls) {
$this->contact = $contact;
Expand Down
4 changes: 1 addition & 3 deletions apps/contactsinteraction/lib/Db/CardSearchDao.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
use function stream_get_contents;

class CardSearchDao {

/** @var IDBConnection */
private $db;
private IDBConnection $db;

public function __construct(IDBConnection $db) {
$this->db = $db;
Expand Down
24 changes: 6 additions & 18 deletions apps/contactsinteraction/lib/Db/RecentContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,12 @@
* @method int getLastContact()
*/
class RecentContact extends Entity {

/** @var string */
protected $actorUid;

/** @var string|null */
protected $uid;

/** @var string|null */
protected $email;

/** @var string|null */
protected $federatedCloudId;

/** @var string */
protected $card;

/** @var int */
protected $lastContact;
protected string $actorUid = '';
protected ?string $uid = null;
protected ?string $email = null;
protected ?string $federatedCloudId = null;
protected string $card = '';
protected int $lastContact = -1;

public function __construct() {
$this->addType('actorUid', 'string');
Expand Down
19 changes: 3 additions & 16 deletions apps/contactsinteraction/lib/Db/RecentContactMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ public function findAll(string $uid): array {
}

/**
* @param string $uid
* @param int $id
*
* @return RecentContact
* @throws DoesNotExistException
*/
public function find(string $uid, int $id): RecentContact {
Expand All @@ -75,11 +71,6 @@ public function find(string $uid, int $id): RecentContact {
}

/**
* @param IUser $user
* @param string|null $uid
* @param string|null $email
* @param string|null $cloudId
*
* @return RecentContact[]
*/
public function findMatch(IUser $user,
Expand Down Expand Up @@ -108,11 +99,7 @@ public function findMatch(IUser $user,
return $this->findEntities($select);
}

/**
* @param string $uid
* @return int|null
*/
public function findLastUpdatedForUserId(string $uid):?int {
public function findLastUpdatedForUserId(string $uid): ?int {
$qb = $this->db->getQueryBuilder();

$select = $qb
Expand All @@ -122,7 +109,7 @@ public function findLastUpdatedForUserId(string $uid):?int {
->orderBy('last_contact', 'DESC')
->setMaxResults(1);

$cursor = $select->execute();
$cursor = $select->executeQuery();
$row = $cursor->fetch();

if ($row === false) {
Expand All @@ -139,6 +126,6 @@ public function cleanUp(int $olderThan): void {
->delete($this->getTableName())
->where($qb->expr()->lt('last_contact', $qb->createNamedParameter($olderThan)));

$delete->execute();
$delete->executeStatement();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,12 @@
use Throwable;

class ContactInteractionListener implements IEventListener {

/** @var RecentContactMapper */
private $mapper;

/** @var CardSearchDao */
private $cardSearchDao;

/** @var IUserManager */
private $userManager;

/** @var ITimeFactory */
private $timeFactory;

/** @var IL10N */
private $l10n;

/** @var LoggerInterface */
private $logger;
private RecentContactMapper $mapper;
private CardSearchDao $cardSearchDao;
private IUserManager $userManager;
private ITimeFactory $timeFactory;
private IL10N $l10n;
private LoggerInterface $logger;

public function __construct(RecentContactMapper $mapper,
CardSearchDao $cardSearchDao,
Expand Down
11 changes: 2 additions & 9 deletions apps/dav/lib/CardDAV/Integration/ExternalAddressBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,9 @@ abstract class ExternalAddressBook implements IAddressBook, DAV\IProperties {
*/
private const DELIMITER = '--';

/** @var string */
private $appId;

/** @var string */
private $uri;
private string $appId;
private string $uri;

/**
* @param string $appId
* @param string $uri
*/
public function __construct(string $appId, string $uri) {
$this->appId = $appId;
$this->uri = $uri;
Expand Down

0 comments on commit f4adfd1

Please sign in to comment.