1
0

DeletedUsersIndex.php 2.7 KB

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