diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2014-12-20 17:08:26 +0100 |
---|---|---|
committer | Arthur Schiwon <blizzz@owncloud.com> | 2014-12-20 18:28:29 +0100 |
commit | 61ed363f820a3b25b68289ed2c03ff5e5edfed91 (patch) | |
tree | ace78508902f8d20bc3de4666d90af1b0445ed5b /apps/user_ldap/lib | |
parent | 3ca70d647a36144e64cbe4b90ffa97b3d9b64470 (diff) | |
download | nextcloud-server-61ed363f820a3b25b68289ed2c03ff5e5edfed91.tar.gz nextcloud-server-61ed363f820a3b25b68289ed2c03ff5e5edfed91.zip |
planned refactorings for OC 8
Diffstat (limited to 'apps/user_ldap/lib')
-rw-r--r-- | apps/user_ldap/lib/jobs/cleanup.php | 49 | ||||
-rw-r--r-- | apps/user_ldap/lib/mapping/abstractmapping.php | 21 | ||||
-rw-r--r-- | apps/user_ldap/lib/user/deletedusersindex.php | 9 |
3 files changed, 54 insertions, 25 deletions
diff --git a/apps/user_ldap/lib/jobs/cleanup.php b/apps/user_ldap/lib/jobs/cleanup.php index 56fb296609d..35252d6f6e5 100644 --- a/apps/user_ldap/lib/jobs/cleanup.php +++ b/apps/user_ldap/lib/jobs/cleanup.php @@ -11,6 +11,8 @@ namespace OCA\User_LDAP\Jobs; use \OCA\user_ldap\User_Proxy; use \OCA\user_ldap\lib\Helper; use \OCA\user_ldap\lib\LDAP; +use \OCA\User_LDAP\lib\User\DeletedUsersIndex; +use \OCA\User_LDAP\Mapping\UserMapping; /** * Class CleanUp @@ -45,6 +47,12 @@ class CleanUp extends \OC\BackgroundJob\TimedJob { */ protected $ldapHelper; + /** @var \OCA\User_LDAP\Mapping\UserMapping */ + protected $mapping; + + /** @var \OCA\User_LDAP\lib\User\DeletedUsersIndex */ + protected $dui; + /** * @var int $defaultIntervalMin default interval in minutes */ @@ -92,6 +100,19 @@ class CleanUp extends \OC\BackgroundJob\TimedJob { } else { $this->db = \OC::$server->getDatabaseConnection(); } + + if(isset($arguments['mapping'])) { + $this->mapping = $arguments['mapping']; + } else { + $this->mapping = new UserMapping($this->db); + } + + if(isset($arguments['deletedUsersIndex'])) { + $this->dui = $arguments['deletedUsersIndex']; + } else { + $this->dui = new DeletedUsersIndex( + $this->ocConfig, $this->db, $this->mapping); + } } /** @@ -104,7 +125,7 @@ class CleanUp extends \OC\BackgroundJob\TimedJob { if(!$this->isCleanUpAllowed()) { return; } - $users = $this->getMappedUsers($this->limit, $this->getOffset()); + $users = $this->mapping->getList($this->limit, $this->getOffset()); if(!is_array($users)) { //something wrong? Let's start from the beginning next time and //abort @@ -169,33 +190,11 @@ class CleanUp extends \OC\BackgroundJob\TimedJob { private function checkUser($user) { if($this->userBackend->userExistsOnLDAP($user['name'])) { //still available, all good + return; } - // TODO FIXME consolidate next line in DeletedUsersIndex - // (impractical now, because of class dependencies) - $this->ocConfig->setUserValue($user['name'], 'user_ldap', 'isDeleted', '1'); - } - - /** - * returns a batch of users from the mappings table - * @param int $limit - * @param int $offset - * @return array - */ - public function getMappedUsers($limit, $offset) { - $query = $this->db->prepare(' - SELECT - `ldap_dn` AS `dn`, - `owncloud_name` AS `name`, - `directory_uuid` AS `uuid` - FROM `*PREFIX*ldap_user_mapping`', - $limit, - $offset - ); - - $query->execute(); - return $query->fetchAll(); + $this->dui->markUser($user['name']); } /** diff --git a/apps/user_ldap/lib/mapping/abstractmapping.php b/apps/user_ldap/lib/mapping/abstractmapping.php index 2c45c6bb1c1..19f173577f5 100644 --- a/apps/user_ldap/lib/mapping/abstractmapping.php +++ b/apps/user_ldap/lib/mapping/abstractmapping.php @@ -153,6 +153,27 @@ abstract class AbstractMapping { } /** + * gets a piece of the mapping list + * @param int $offset + * @param int $limit + * @return array + */ + public function getList($offset = null, $limit = null) { + $query = $this->dbc->prepare(' + SELECT + `ldap_dn` AS `dn`, + `owncloud_name` AS `name`, + `directory_uuid` AS `uuid` + FROM `*PREFIX*ldap_user_mapping`', + $limit, + $offset + ); + + $query->execute(); + return $query->fetchAll(); + } + + /** * attempts to map the given entry * @param string $fdn fully distinguished name (from LDAP) * @param string $name diff --git a/apps/user_ldap/lib/user/deletedusersindex.php b/apps/user_ldap/lib/user/deletedusersindex.php index 62abe2e10de..67585530279 100644 --- a/apps/user_ldap/lib/user/deletedusersindex.php +++ b/apps/user_ldap/lib/user/deletedusersindex.php @@ -69,6 +69,7 @@ class DeletedUsersIndex { foreach($deletedUsers as $user) { $userObjects[] = new OfflineUser($user, $this->config, $this->db, $this->mapping); } + $this->deletedUsers = $userObjects; return $this->deletedUsers; } @@ -97,4 +98,12 @@ class DeletedUsersIndex { } return false; } + + /** + * marks a user as deleted + * @param string ocName + */ + public function markUser($ocName) { + $this->config->setUserValue($ocName, 'user_ldap', 'isDeleted', '1'); + } } |