deletedusersindex.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * @author Arthur Schiwon <blizzz@owncloud.com>
  4. * @author Morris Jobke <hey@morrisjobke.de>
  5. *
  6. * @copyright Copyright (c) 2015, ownCloud, Inc.
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OCA\user_ldap\lib\user;
  23. use OCA\user_ldap\lib\user\OfflineUser;
  24. use OCA\User_LDAP\Mapping\UserMapping;
  25. /**
  26. * Class DeletedUsersIndex
  27. * @package OCA\User_LDAP
  28. */
  29. class DeletedUsersIndex {
  30. /**
  31. * @var \OCP\IConfig $config
  32. */
  33. protected $config;
  34. /**
  35. * @var \OCP\IDBConnection $db
  36. */
  37. protected $db;
  38. /**
  39. * @var \OCA\User_LDAP\Mapping\UserMapping $mapping
  40. */
  41. protected $mapping;
  42. /**
  43. * @var array $deletedUsers
  44. */
  45. protected $deletedUsers;
  46. /**
  47. * @param OCP\IConfig $config
  48. * @param OCP\IDBConnection $db
  49. * @param OCA\User_LDAP\Mapping\UserMapping $mapping
  50. */
  51. public function __construct(\OCP\IConfig $config, \OCP\IDBConnection $db, UserMapping $mapping) {
  52. $this->config = $config;
  53. $this->db = $db;
  54. $this->mapping = $mapping;
  55. }
  56. /**
  57. * reads LDAP users marked as deleted from the database
  58. * @return OCA\user_ldap\lib\user\OfflineUser[]
  59. */
  60. private function fetchDeletedUsers() {
  61. $deletedUsers = $this->config->getUsersForUserValue(
  62. 'user_ldap', 'isDeleted', '1');
  63. $userObjects = array();
  64. foreach($deletedUsers as $user) {
  65. $userObjects[] = new OfflineUser($user, $this->config, $this->db, $this->mapping);
  66. }
  67. $this->deletedUsers = $userObjects;
  68. return $this->deletedUsers;
  69. }
  70. /**
  71. * returns all LDAP users that are marked as deleted
  72. * @return OCA\user_ldap\lib\user\OfflineUser[]
  73. */
  74. public function getUsers() {
  75. if(is_array($this->deletedUsers)) {
  76. return $this->deletedUsers;
  77. }
  78. return $this->fetchDeletedUsers();
  79. }
  80. /**
  81. * whether at least one user was detected as deleted
  82. * @return bool
  83. */
  84. public function hasUsers() {
  85. if($this->deletedUsers === false) {
  86. $this->fetchDeletedUsers();
  87. }
  88. if(is_array($this->deletedUsers) && count($this->deletedUsers) > 0) {
  89. return true;
  90. }
  91. return false;
  92. }
  93. /**
  94. * marks a user as deleted
  95. * @param string ocName
  96. */
  97. public function markUser($ocName) {
  98. $this->config->setUserValue($ocName, 'user_ldap', 'isDeleted', '1');
  99. }
  100. }