aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/lib/User/DeletedUsersIndex.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/user_ldap/lib/User/DeletedUsersIndex.php')
-rw-r--r--apps/user_ldap/lib/User/DeletedUsersIndex.php84
1 files changed, 30 insertions, 54 deletions
diff --git a/apps/user_ldap/lib/User/DeletedUsersIndex.php b/apps/user_ldap/lib/User/DeletedUsersIndex.php
index 1e057987eef..f57f71a9d47 100644
--- a/apps/user_ldap/lib/User/DeletedUsersIndex.php
+++ b/apps/user_ldap/lib/User/DeletedUsersIndex.php
@@ -1,29 +1,14 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\User_LDAP\User;
use OCA\User_LDAP\Mapping\UserMapping;
+use OCP\IConfig;
+use OCP\PreConditionNotMetException;
use OCP\Share\IManager;
/**
@@ -31,40 +16,30 @@ use OCP\Share\IManager;
* @package OCA\User_LDAP
*/
class DeletedUsersIndex {
- /**
- * @var \OCP\IConfig $config
- */
- protected $config;
-
- /**
- * @var \OCA\User_LDAP\Mapping\UserMapping $mapping
- */
- protected $mapping;
+ protected ?array $deletedUsers = null;
- /**
- * @var array $deletedUsers
- */
- protected $deletedUsers;
- /** @var IManager */
- private $shareManager;
-
- public function __construct(\OCP\IConfig $config, UserMapping $mapping, IManager $shareManager) {
- $this->config = $config;
- $this->mapping = $mapping;
- $this->shareManager = $shareManager;
+ public function __construct(
+ protected IConfig $config,
+ protected UserMapping $mapping,
+ private IManager $shareManager,
+ ) {
}
/**
* reads LDAP users marked as deleted from the database
- * @return \OCA\User_LDAP\User\OfflineUser[]
+ * @return OfflineUser[]
*/
- private function fetchDeletedUsers() {
- $deletedUsers = $this->config->getUsersForUserValue(
- 'user_ldap', 'isDeleted', '1');
+ private function fetchDeletedUsers(): array {
+ $deletedUsers = $this->config->getUsersForUserValue('user_ldap', 'isDeleted', '1');
$userObjects = [];
foreach ($deletedUsers as $user) {
- $userObjects[] = new OfflineUser($user, $this->config, $this->mapping, $this->shareManager);
+ $userObject = new OfflineUser($user, $this->config, $this->mapping, $this->shareManager);
+ if ($userObject->getLastLogin() > $userObject->getDetectedOn()) {
+ $userObject->unmark();
+ } else {
+ $userObjects[] = $userObject;
+ }
}
$this->deletedUsers = $userObjects;
@@ -73,9 +48,9 @@ class DeletedUsersIndex {
/**
* returns all LDAP users that are marked as deleted
- * @return \OCA\User_LDAP\User\OfflineUser[]
+ * @return OfflineUser[]
*/
- public function getUsers() {
+ public function getUsers(): array {
if (is_array($this->deletedUsers)) {
return $this->deletedUsers;
}
@@ -84,9 +59,8 @@ class DeletedUsersIndex {
/**
* whether at least one user was detected as deleted
- * @return bool
*/
- public function hasUsers() {
+ public function hasUsers(): bool {
if (!is_array($this->deletedUsers)) {
$this->fetchDeletedUsers();
}
@@ -96,12 +70,10 @@ class DeletedUsersIndex {
/**
* marks a user as deleted
*
- * @param string $ocName
- * @throws \OCP\PreConditionNotMetException
+ * @throws PreConditionNotMetException
*/
- public function markUser($ocName) {
- $curValue = $this->config->getUserValue($ocName, 'user_ldap', 'isDeleted', '0');
- if ($curValue === '1') {
+ public function markUser(string $ocName): void {
+ if ($this->isUserMarked($ocName)) {
// the user is already marked, do not write to DB again
return;
}
@@ -109,4 +81,8 @@ class DeletedUsersIndex {
$this->config->setUserValue($ocName, 'user_ldap', 'foundDeleted', (string)time());
$this->deletedUsers = null;
}
+
+ public function isUserMarked(string $ocName): bool {
+ return ($this->config->getUserValue($ocName, 'user_ldap', 'isDeleted', '0') === '1');
+ }
}