@@ -29,32 +29,32 @@ |
||
| 29 | 29 | |
| 30 | 30 | class LastUsedController extends Controller { |
| 31 | 31 | |
| 32 | - /** @var IConfig */ |
|
| 33 | - protected $config; |
|
| 32 | + /** @var IConfig */ |
|
| 33 | + protected $config; |
|
| 34 | 34 | |
| 35 | - /** @var IUserSession */ |
|
| 36 | - protected $userSession; |
|
| 35 | + /** @var IUserSession */ |
|
| 36 | + protected $userSession; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @param string $appName |
|
| 40 | - * @param IRequest $request |
|
| 41 | - * @param IConfig $config |
|
| 42 | - * @param IUserSession $userSession |
|
| 43 | - */ |
|
| 44 | - public function __construct($appName, IRequest $request, IConfig $config, IUserSession $userSession) { |
|
| 45 | - parent::__construct($appName, $request); |
|
| 46 | - $this->config = $config; |
|
| 47 | - $this->userSession = $userSession; |
|
| 48 | - } |
|
| 38 | + /** |
|
| 39 | + * @param string $appName |
|
| 40 | + * @param IRequest $request |
|
| 41 | + * @param IConfig $config |
|
| 42 | + * @param IUserSession $userSession |
|
| 43 | + */ |
|
| 44 | + public function __construct($appName, IRequest $request, IConfig $config, IUserSession $userSession) { |
|
| 45 | + parent::__construct($appName, $request); |
|
| 46 | + $this->config = $config; |
|
| 47 | + $this->userSession = $userSession; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @NoAdminRequired |
|
| 52 | - */ |
|
| 53 | - public function getLastUsedTagIds() { |
|
| 54 | - $lastUsed = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'systemtags', 'last_used', '[]'); |
|
| 55 | - $tagIds = json_decode($lastUsed, true); |
|
| 56 | - return new DataResponse(array_map(function ($id) { |
|
| 57 | - return (string) $id; |
|
| 58 | - }, $tagIds)); |
|
| 59 | - } |
|
| 50 | + /** |
|
| 51 | + * @NoAdminRequired |
|
| 52 | + */ |
|
| 53 | + public function getLastUsedTagIds() { |
|
| 54 | + $lastUsed = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'systemtags', 'last_used', '[]'); |
|
| 55 | + $tagIds = json_decode($lastUsed, true); |
|
| 56 | + return new DataResponse(array_map(function ($id) { |
|
| 57 | + return (string) $id; |
|
| 58 | + }, $tagIds)); |
|
| 59 | + } |
|
| 60 | 60 | } |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | public function getLastUsedTagIds() { |
| 54 | 54 | $lastUsed = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'systemtags', 'last_used', '[]'); |
| 55 | 55 | $tagIds = json_decode($lastUsed, true); |
| 56 | - return new DataResponse(array_map(function ($id) { |
|
| 56 | + return new DataResponse(array_map(function($id) { |
|
| 57 | 57 | return (string) $id; |
| 58 | 58 | }, $tagIds)); |
| 59 | 59 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | $token = $argument['token']; |
| 98 | 98 | $action = $argument['action']; |
| 99 | 99 | $data = json_decode($argument['data'], true); |
| 100 | - $try = (int)$argument['try'] + 1; |
|
| 100 | + $try = (int) $argument['try'] + 1; |
|
| 101 | 101 | |
| 102 | 102 | $result = $this->notifications->sendUpdateToRemote($remote, $remoteId, $token, $action, $data, $try); |
| 103 | 103 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | 'token' => $argument['token'], |
| 122 | 122 | 'data' => $argument['data'], |
| 123 | 123 | 'action' => $argument['action'], |
| 124 | - 'try' => (int)$argument['try'] + 1, |
|
| 124 | + 'try' => (int) $argument['try'] + 1, |
|
| 125 | 125 | 'lastRun' => time() |
| 126 | 126 | ] |
| 127 | 127 | ); |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | * @return bool |
| 135 | 135 | */ |
| 136 | 136 | protected function shouldRun(array $argument) { |
| 137 | - $lastRun = (int)$argument['lastRun']; |
|
| 137 | + $lastRun = (int) $argument['lastRun']; |
|
| 138 | 138 | return ((time() - $lastRun) > $this->interval); |
| 139 | 139 | } |
| 140 | 140 | } |
@@ -44,102 +44,102 @@ |
||
| 44 | 44 | */ |
| 45 | 45 | class RetryJob extends Job { |
| 46 | 46 | |
| 47 | - /** @var bool */ |
|
| 48 | - private $retainJob = true; |
|
| 47 | + /** @var bool */ |
|
| 48 | + private $retainJob = true; |
|
| 49 | 49 | |
| 50 | - /** @var Notifications */ |
|
| 51 | - private $notifications; |
|
| 50 | + /** @var Notifications */ |
|
| 51 | + private $notifications; |
|
| 52 | 52 | |
| 53 | - /** @var int max number of attempts to send the request */ |
|
| 54 | - private $maxTry = 20; |
|
| 53 | + /** @var int max number of attempts to send the request */ |
|
| 54 | + private $maxTry = 20; |
|
| 55 | 55 | |
| 56 | - /** @var int how much time should be between two tries (10 minutes) */ |
|
| 57 | - private $interval = 600; |
|
| 56 | + /** @var int how much time should be between two tries (10 minutes) */ |
|
| 57 | + private $interval = 600; |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * UnShare constructor. |
|
| 61 | - * |
|
| 62 | - * @param Notifications $notifications |
|
| 63 | - */ |
|
| 64 | - public function __construct(Notifications $notifications = null) { |
|
| 65 | - if ($notifications) { |
|
| 66 | - $this->notifications = $notifications; |
|
| 67 | - } else { |
|
| 68 | - $addressHandler = new AddressHandler( |
|
| 69 | - \OC::$server->getURLGenerator(), |
|
| 70 | - \OC::$server->getL10N('federatedfilesharing'), |
|
| 71 | - \OC::$server->getCloudIdManager() |
|
| 72 | - ); |
|
| 73 | - $this->notifications = new Notifications( |
|
| 74 | - $addressHandler, |
|
| 75 | - \OC::$server->getHTTPClientService(), |
|
| 76 | - \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 77 | - \OC::$server->getJobList(), |
|
| 78 | - \OC::$server->getCloudFederationProviderManager(), |
|
| 79 | - \OC::$server->getCloudFederationFactory() |
|
| 80 | - ); |
|
| 81 | - } |
|
| 82 | - } |
|
| 59 | + /** |
|
| 60 | + * UnShare constructor. |
|
| 61 | + * |
|
| 62 | + * @param Notifications $notifications |
|
| 63 | + */ |
|
| 64 | + public function __construct(Notifications $notifications = null) { |
|
| 65 | + if ($notifications) { |
|
| 66 | + $this->notifications = $notifications; |
|
| 67 | + } else { |
|
| 68 | + $addressHandler = new AddressHandler( |
|
| 69 | + \OC::$server->getURLGenerator(), |
|
| 70 | + \OC::$server->getL10N('federatedfilesharing'), |
|
| 71 | + \OC::$server->getCloudIdManager() |
|
| 72 | + ); |
|
| 73 | + $this->notifications = new Notifications( |
|
| 74 | + $addressHandler, |
|
| 75 | + \OC::$server->getHTTPClientService(), |
|
| 76 | + \OC::$server->query(\OCP\OCS\IDiscoveryService::class), |
|
| 77 | + \OC::$server->getJobList(), |
|
| 78 | + \OC::$server->getCloudFederationProviderManager(), |
|
| 79 | + \OC::$server->getCloudFederationFactory() |
|
| 80 | + ); |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * run the job, then remove it from the jobList |
|
| 86 | - * |
|
| 87 | - * @param JobList $jobList |
|
| 88 | - * @param ILogger|null $logger |
|
| 89 | - */ |
|
| 90 | - public function execute($jobList, ILogger $logger = null) { |
|
| 91 | - if ($this->shouldRun($this->argument)) { |
|
| 92 | - parent::execute($jobList, $logger); |
|
| 93 | - $jobList->remove($this, $this->argument); |
|
| 94 | - if ($this->retainJob) { |
|
| 95 | - $this->reAddJob($jobList, $this->argument); |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - } |
|
| 84 | + /** |
|
| 85 | + * run the job, then remove it from the jobList |
|
| 86 | + * |
|
| 87 | + * @param JobList $jobList |
|
| 88 | + * @param ILogger|null $logger |
|
| 89 | + */ |
|
| 90 | + public function execute($jobList, ILogger $logger = null) { |
|
| 91 | + if ($this->shouldRun($this->argument)) { |
|
| 92 | + parent::execute($jobList, $logger); |
|
| 93 | + $jobList->remove($this, $this->argument); |
|
| 94 | + if ($this->retainJob) { |
|
| 95 | + $this->reAddJob($jobList, $this->argument); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - protected function run($argument) { |
|
| 101 | - $remote = $argument['remote']; |
|
| 102 | - $remoteId = $argument['remoteId']; |
|
| 103 | - $token = $argument['token']; |
|
| 104 | - $action = $argument['action']; |
|
| 105 | - $data = json_decode($argument['data'], true); |
|
| 106 | - $try = (int)$argument['try'] + 1; |
|
| 100 | + protected function run($argument) { |
|
| 101 | + $remote = $argument['remote']; |
|
| 102 | + $remoteId = $argument['remoteId']; |
|
| 103 | + $token = $argument['token']; |
|
| 104 | + $action = $argument['action']; |
|
| 105 | + $data = json_decode($argument['data'], true); |
|
| 106 | + $try = (int)$argument['try'] + 1; |
|
| 107 | 107 | |
| 108 | - $result = $this->notifications->sendUpdateToRemote($remote, $remoteId, $token, $action, $data, $try); |
|
| 108 | + $result = $this->notifications->sendUpdateToRemote($remote, $remoteId, $token, $action, $data, $try); |
|
| 109 | 109 | |
| 110 | - if ($result === true || $try > $this->maxTry) { |
|
| 111 | - $this->retainJob = false; |
|
| 112 | - } |
|
| 113 | - } |
|
| 110 | + if ($result === true || $try > $this->maxTry) { |
|
| 111 | + $this->retainJob = false; |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * re-add background job with new arguments |
|
| 117 | - * |
|
| 118 | - * @param IJobList $jobList |
|
| 119 | - * @param array $argument |
|
| 120 | - */ |
|
| 121 | - protected function reAddJob(IJobList $jobList, array $argument) { |
|
| 122 | - $jobList->add(RetryJob::class, |
|
| 123 | - [ |
|
| 124 | - 'remote' => $argument['remote'], |
|
| 125 | - 'remoteId' => $argument['remoteId'], |
|
| 126 | - 'token' => $argument['token'], |
|
| 127 | - 'data' => $argument['data'], |
|
| 128 | - 'action' => $argument['action'], |
|
| 129 | - 'try' => (int)$argument['try'] + 1, |
|
| 130 | - 'lastRun' => time() |
|
| 131 | - ] |
|
| 132 | - ); |
|
| 133 | - } |
|
| 115 | + /** |
|
| 116 | + * re-add background job with new arguments |
|
| 117 | + * |
|
| 118 | + * @param IJobList $jobList |
|
| 119 | + * @param array $argument |
|
| 120 | + */ |
|
| 121 | + protected function reAddJob(IJobList $jobList, array $argument) { |
|
| 122 | + $jobList->add(RetryJob::class, |
|
| 123 | + [ |
|
| 124 | + 'remote' => $argument['remote'], |
|
| 125 | + 'remoteId' => $argument['remoteId'], |
|
| 126 | + 'token' => $argument['token'], |
|
| 127 | + 'data' => $argument['data'], |
|
| 128 | + 'action' => $argument['action'], |
|
| 129 | + 'try' => (int)$argument['try'] + 1, |
|
| 130 | + 'lastRun' => time() |
|
| 131 | + ] |
|
| 132 | + ); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * test if it is time for the next run |
|
| 137 | - * |
|
| 138 | - * @param array $argument |
|
| 139 | - * @return bool |
|
| 140 | - */ |
|
| 141 | - protected function shouldRun(array $argument) { |
|
| 142 | - $lastRun = (int)$argument['lastRun']; |
|
| 143 | - return ((time() - $lastRun) > $this->interval); |
|
| 144 | - } |
|
| 135 | + /** |
|
| 136 | + * test if it is time for the next run |
|
| 137 | + * |
|
| 138 | + * @param array $argument |
|
| 139 | + * @return bool |
|
| 140 | + */ |
|
| 141 | + protected function shouldRun(array $argument) { |
|
| 142 | + $lastRun = (int)$argument['lastRun']; |
|
| 143 | + return ((time() - $lastRun) > $this->interval); |
|
| 144 | + } |
|
| 145 | 145 | } |
@@ -31,30 +31,30 @@ |
||
| 31 | 31 | use OCP\Command\ICommand; |
| 32 | 32 | |
| 33 | 33 | class Expire implements ICommand { |
| 34 | - use FileAccess; |
|
| 34 | + use FileAccess; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - private $user; |
|
| 36 | + /** |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + private $user; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @param string $user |
|
| 43 | - */ |
|
| 44 | - public function __construct($user) { |
|
| 45 | - $this->user = $user; |
|
| 46 | - } |
|
| 41 | + /** |
|
| 42 | + * @param string $user |
|
| 43 | + */ |
|
| 44 | + public function __construct($user) { |
|
| 45 | + $this->user = $user; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - public function handle() { |
|
| 49 | - $userManager = \OC::$server->getUserManager(); |
|
| 50 | - if (!$userManager->userExists($this->user)) { |
|
| 51 | - // User has been deleted already |
|
| 52 | - return; |
|
| 53 | - } |
|
| 48 | + public function handle() { |
|
| 49 | + $userManager = \OC::$server->getUserManager(); |
|
| 50 | + if (!$userManager->userExists($this->user)) { |
|
| 51 | + // User has been deleted already |
|
| 52 | + return; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - \OC_Util::tearDownFS(); |
|
| 56 | - \OC_Util::setupFS($this->user); |
|
| 57 | - Trashbin::expire($this->user); |
|
| 58 | - \OC_Util::tearDownFS(); |
|
| 59 | - } |
|
| 55 | + \OC_Util::tearDownFS(); |
|
| 56 | + \OC_Util::setupFS($this->user); |
|
| 57 | + Trashbin::expire($this->user); |
|
| 58 | + \OC_Util::tearDownFS(); |
|
| 59 | + } |
|
| 60 | 60 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | } else { |
| 91 | 91 | $p = new ProgressBar($output); |
| 92 | 92 | $p->start(); |
| 93 | - $this->userManager->callForSeenUsers(function (IUser $user) use ($p) { |
|
| 93 | + $this->userManager->callForSeenUsers(function(IUser $user) use ($p) { |
|
| 94 | 94 | $p->advance(); |
| 95 | 95 | $this->expireTrashForUser($user); |
| 96 | 96 | }); |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | \OC_Util::setupFS($user); |
| 119 | 119 | |
| 120 | 120 | // Check if this user has a trashbin directory |
| 121 | - $view = new \OC\Files\View('/' . $user); |
|
| 121 | + $view = new \OC\Files\View('/'.$user); |
|
| 122 | 122 | if (!$view->is_dir('/files_trashbin/files')) { |
| 123 | 123 | return false; |
| 124 | 124 | } |
@@ -38,95 +38,95 @@ |
||
| 38 | 38 | |
| 39 | 39 | class ExpireTrash extends Command { |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var Expiration |
|
| 43 | - */ |
|
| 44 | - private $expiration; |
|
| 41 | + /** |
|
| 42 | + * @var Expiration |
|
| 43 | + */ |
|
| 44 | + private $expiration; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var IUserManager |
|
| 48 | - */ |
|
| 49 | - private $userManager; |
|
| 46 | + /** |
|
| 47 | + * @var IUserManager |
|
| 48 | + */ |
|
| 49 | + private $userManager; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param IUserManager|null $userManager |
|
| 53 | - * @param Expiration|null $expiration |
|
| 54 | - */ |
|
| 55 | - public function __construct(IUserManager $userManager = null, |
|
| 56 | - Expiration $expiration = null) { |
|
| 57 | - parent::__construct(); |
|
| 51 | + /** |
|
| 52 | + * @param IUserManager|null $userManager |
|
| 53 | + * @param Expiration|null $expiration |
|
| 54 | + */ |
|
| 55 | + public function __construct(IUserManager $userManager = null, |
|
| 56 | + Expiration $expiration = null) { |
|
| 57 | + parent::__construct(); |
|
| 58 | 58 | |
| 59 | - $this->userManager = $userManager; |
|
| 60 | - $this->expiration = $expiration; |
|
| 61 | - } |
|
| 59 | + $this->userManager = $userManager; |
|
| 60 | + $this->expiration = $expiration; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - protected function configure() { |
|
| 64 | - $this |
|
| 65 | - ->setName('trashbin:expire') |
|
| 66 | - ->setDescription('Expires the users trashbin') |
|
| 67 | - ->addArgument( |
|
| 68 | - 'user_id', |
|
| 69 | - InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
| 70 | - 'expires the trashbin of the given user(s), if no user is given the trash for all users will be expired' |
|
| 71 | - ); |
|
| 72 | - } |
|
| 63 | + protected function configure() { |
|
| 64 | + $this |
|
| 65 | + ->setName('trashbin:expire') |
|
| 66 | + ->setDescription('Expires the users trashbin') |
|
| 67 | + ->addArgument( |
|
| 68 | + 'user_id', |
|
| 69 | + InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
| 70 | + 'expires the trashbin of the given user(s), if no user is given the trash for all users will be expired' |
|
| 71 | + ); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 75 | - $maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
| 76 | - if (!$maxAge) { |
|
| 77 | - $output->writeln("No expiry configured."); |
|
| 78 | - return 1; |
|
| 79 | - } |
|
| 74 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 75 | + $maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
| 76 | + if (!$maxAge) { |
|
| 77 | + $output->writeln("No expiry configured."); |
|
| 78 | + return 1; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - $users = $input->getArgument('user_id'); |
|
| 82 | - if (!empty($users)) { |
|
| 83 | - foreach ($users as $user) { |
|
| 84 | - if ($this->userManager->userExists($user)) { |
|
| 85 | - $output->writeln("Remove deleted files of <info>$user</info>"); |
|
| 86 | - $userObject = $this->userManager->get($user); |
|
| 87 | - $this->expireTrashForUser($userObject); |
|
| 88 | - } else { |
|
| 89 | - $output->writeln("<error>Unknown user $user</error>"); |
|
| 90 | - return 1; |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - } else { |
|
| 94 | - $p = new ProgressBar($output); |
|
| 95 | - $p->start(); |
|
| 96 | - $this->userManager->callForSeenUsers(function (IUser $user) use ($p) { |
|
| 97 | - $p->advance(); |
|
| 98 | - $this->expireTrashForUser($user); |
|
| 99 | - }); |
|
| 100 | - $p->finish(); |
|
| 101 | - $output->writeln(''); |
|
| 102 | - } |
|
| 103 | - return 0; |
|
| 104 | - } |
|
| 81 | + $users = $input->getArgument('user_id'); |
|
| 82 | + if (!empty($users)) { |
|
| 83 | + foreach ($users as $user) { |
|
| 84 | + if ($this->userManager->userExists($user)) { |
|
| 85 | + $output->writeln("Remove deleted files of <info>$user</info>"); |
|
| 86 | + $userObject = $this->userManager->get($user); |
|
| 87 | + $this->expireTrashForUser($userObject); |
|
| 88 | + } else { |
|
| 89 | + $output->writeln("<error>Unknown user $user</error>"); |
|
| 90 | + return 1; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + } else { |
|
| 94 | + $p = new ProgressBar($output); |
|
| 95 | + $p->start(); |
|
| 96 | + $this->userManager->callForSeenUsers(function (IUser $user) use ($p) { |
|
| 97 | + $p->advance(); |
|
| 98 | + $this->expireTrashForUser($user); |
|
| 99 | + }); |
|
| 100 | + $p->finish(); |
|
| 101 | + $output->writeln(''); |
|
| 102 | + } |
|
| 103 | + return 0; |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - public function expireTrashForUser(IUser $user) { |
|
| 107 | - $uid = $user->getUID(); |
|
| 108 | - if (!$this->setupFS($uid)) { |
|
| 109 | - return; |
|
| 110 | - } |
|
| 111 | - $dirContent = Helper::getTrashFiles('/', $uid, 'mtime'); |
|
| 112 | - Trashbin::deleteExpiredFiles($dirContent, $uid); |
|
| 113 | - } |
|
| 106 | + public function expireTrashForUser(IUser $user) { |
|
| 107 | + $uid = $user->getUID(); |
|
| 108 | + if (!$this->setupFS($uid)) { |
|
| 109 | + return; |
|
| 110 | + } |
|
| 111 | + $dirContent = Helper::getTrashFiles('/', $uid, 'mtime'); |
|
| 112 | + Trashbin::deleteExpiredFiles($dirContent, $uid); |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Act on behalf on trash item owner |
|
| 117 | - * @param string $user |
|
| 118 | - * @return boolean |
|
| 119 | - */ |
|
| 120 | - protected function setupFS($user) { |
|
| 121 | - \OC_Util::tearDownFS(); |
|
| 122 | - \OC_Util::setupFS($user); |
|
| 115 | + /** |
|
| 116 | + * Act on behalf on trash item owner |
|
| 117 | + * @param string $user |
|
| 118 | + * @return boolean |
|
| 119 | + */ |
|
| 120 | + protected function setupFS($user) { |
|
| 121 | + \OC_Util::tearDownFS(); |
|
| 122 | + \OC_Util::setupFS($user); |
|
| 123 | 123 | |
| 124 | - // Check if this user has a trashbin directory |
|
| 125 | - $view = new \OC\Files\View('/' . $user); |
|
| 126 | - if (!$view->is_dir('/files_trashbin/files')) { |
|
| 127 | - return false; |
|
| 128 | - } |
|
| 124 | + // Check if this user has a trashbin directory |
|
| 125 | + $view = new \OC\Files\View('/' . $user); |
|
| 126 | + if (!$view->is_dir('/files_trashbin/files')) { |
|
| 127 | + return false; |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - return true; |
|
| 131 | - } |
|
| 130 | + return true; |
|
| 131 | + } |
|
| 132 | 132 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | return; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - $this->userManager->callForSeenUsers(function (IUser $user) { |
|
| 81 | + $this->userManager->callForSeenUsers(function(IUser $user) { |
|
| 82 | 82 | $uid = $user->getUID(); |
| 83 | 83 | if (!$this->setupFS($uid)) { |
| 84 | 84 | return; |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | \OC_Util::setupFS($user); |
| 101 | 101 | |
| 102 | 102 | // Check if this user has a trashbin directory |
| 103 | - $view = new \OC\Files\View('/' . $user); |
|
| 103 | + $view = new \OC\Files\View('/'.$user); |
|
| 104 | 104 | if (!$view->is_dir('/files_trashbin/files')) { |
| 105 | 105 | return false; |
| 106 | 106 | } |
@@ -36,77 +36,77 @@ |
||
| 36 | 36 | |
| 37 | 37 | class ExpireTrash extends \OC\BackgroundJob\TimedJob { |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @var Expiration |
|
| 41 | - */ |
|
| 42 | - private $expiration; |
|
| 39 | + /** |
|
| 40 | + * @var Expiration |
|
| 41 | + */ |
|
| 42 | + private $expiration; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @var IUserManager |
|
| 46 | - */ |
|
| 47 | - private $userManager; |
|
| 44 | + /** |
|
| 45 | + * @var IUserManager |
|
| 46 | + */ |
|
| 47 | + private $userManager; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @param IUserManager|null $userManager |
|
| 51 | - * @param Expiration|null $expiration |
|
| 52 | - */ |
|
| 53 | - public function __construct(IUserManager $userManager = null, |
|
| 54 | - Expiration $expiration = null) { |
|
| 55 | - // Run once per 30 minutes |
|
| 56 | - $this->setInterval(60 * 30); |
|
| 49 | + /** |
|
| 50 | + * @param IUserManager|null $userManager |
|
| 51 | + * @param Expiration|null $expiration |
|
| 52 | + */ |
|
| 53 | + public function __construct(IUserManager $userManager = null, |
|
| 54 | + Expiration $expiration = null) { |
|
| 55 | + // Run once per 30 minutes |
|
| 56 | + $this->setInterval(60 * 30); |
|
| 57 | 57 | |
| 58 | - if (is_null($expiration) || is_null($userManager)) { |
|
| 59 | - $this->fixDIForJobs(); |
|
| 60 | - } else { |
|
| 61 | - $this->userManager = $userManager; |
|
| 62 | - $this->expiration = $expiration; |
|
| 63 | - } |
|
| 64 | - } |
|
| 58 | + if (is_null($expiration) || is_null($userManager)) { |
|
| 59 | + $this->fixDIForJobs(); |
|
| 60 | + } else { |
|
| 61 | + $this->userManager = $userManager; |
|
| 62 | + $this->expiration = $expiration; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - protected function fixDIForJobs() { |
|
| 67 | - /** @var Application $application */ |
|
| 68 | - $application = \OC::$server->query(Application::class); |
|
| 69 | - $this->userManager = \OC::$server->getUserManager(); |
|
| 70 | - $this->expiration = $application->getContainer()->query('Expiration'); |
|
| 71 | - } |
|
| 66 | + protected function fixDIForJobs() { |
|
| 67 | + /** @var Application $application */ |
|
| 68 | + $application = \OC::$server->query(Application::class); |
|
| 69 | + $this->userManager = \OC::$server->getUserManager(); |
|
| 70 | + $this->expiration = $application->getContainer()->query('Expiration'); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @param $argument |
|
| 75 | - * @throws \Exception |
|
| 76 | - */ |
|
| 77 | - protected function run($argument) { |
|
| 78 | - $maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
| 79 | - if (!$maxAge) { |
|
| 80 | - return; |
|
| 81 | - } |
|
| 73 | + /** |
|
| 74 | + * @param $argument |
|
| 75 | + * @throws \Exception |
|
| 76 | + */ |
|
| 77 | + protected function run($argument) { |
|
| 78 | + $maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
| 79 | + if (!$maxAge) { |
|
| 80 | + return; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - $this->userManager->callForSeenUsers(function (IUser $user) { |
|
| 84 | - $uid = $user->getUID(); |
|
| 85 | - if (!$this->setupFS($uid)) { |
|
| 86 | - return; |
|
| 87 | - } |
|
| 88 | - $dirContent = Helper::getTrashFiles('/', $uid, 'mtime'); |
|
| 89 | - Trashbin::deleteExpiredFiles($dirContent, $uid); |
|
| 90 | - }); |
|
| 83 | + $this->userManager->callForSeenUsers(function (IUser $user) { |
|
| 84 | + $uid = $user->getUID(); |
|
| 85 | + if (!$this->setupFS($uid)) { |
|
| 86 | + return; |
|
| 87 | + } |
|
| 88 | + $dirContent = Helper::getTrashFiles('/', $uid, 'mtime'); |
|
| 89 | + Trashbin::deleteExpiredFiles($dirContent, $uid); |
|
| 90 | + }); |
|
| 91 | 91 | |
| 92 | - \OC_Util::tearDownFS(); |
|
| 93 | - } |
|
| 92 | + \OC_Util::tearDownFS(); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Act on behalf on trash item owner |
|
| 97 | - * @param string $user |
|
| 98 | - * @return boolean |
|
| 99 | - */ |
|
| 100 | - protected function setupFS($user) { |
|
| 101 | - \OC_Util::tearDownFS(); |
|
| 102 | - \OC_Util::setupFS($user); |
|
| 95 | + /** |
|
| 96 | + * Act on behalf on trash item owner |
|
| 97 | + * @param string $user |
|
| 98 | + * @return boolean |
|
| 99 | + */ |
|
| 100 | + protected function setupFS($user) { |
|
| 101 | + \OC_Util::tearDownFS(); |
|
| 102 | + \OC_Util::setupFS($user); |
|
| 103 | 103 | |
| 104 | - // Check if this user has a trashbin directory |
|
| 105 | - $view = new \OC\Files\View('/' . $user); |
|
| 106 | - if (!$view->is_dir('/files_trashbin/files')) { |
|
| 107 | - return false; |
|
| 108 | - } |
|
| 104 | + // Check if this user has a trashbin directory |
|
| 105 | + $view = new \OC\Files\View('/' . $user); |
|
| 106 | + if (!$view->is_dir('/files_trashbin/files')) { |
|
| 107 | + return false; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - return true; |
|
| 111 | - } |
|
| 110 | + return true; |
|
| 111 | + } |
|
| 112 | 112 | } |
@@ -27,91 +27,91 @@ |
||
| 27 | 27 | use OCP\Notification\IManager; |
| 28 | 28 | |
| 29 | 29 | class Listener { |
| 30 | - /** @var IManager */ |
|
| 31 | - protected $notificationManager; |
|
| 30 | + /** @var IManager */ |
|
| 31 | + protected $notificationManager; |
|
| 32 | 32 | |
| 33 | - /** @var IUserManager */ |
|
| 34 | - protected $userManager; |
|
| 33 | + /** @var IUserManager */ |
|
| 34 | + protected $userManager; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Listener constructor. |
|
| 38 | - * |
|
| 39 | - * @param IManager $notificationManager |
|
| 40 | - * @param IUserManager $userManager |
|
| 41 | - */ |
|
| 42 | - public function __construct( |
|
| 43 | - IManager $notificationManager, |
|
| 44 | - IUserManager $userManager |
|
| 45 | - ) { |
|
| 46 | - $this->notificationManager = $notificationManager; |
|
| 47 | - $this->userManager = $userManager; |
|
| 48 | - } |
|
| 36 | + /** |
|
| 37 | + * Listener constructor. |
|
| 38 | + * |
|
| 39 | + * @param IManager $notificationManager |
|
| 40 | + * @param IUserManager $userManager |
|
| 41 | + */ |
|
| 42 | + public function __construct( |
|
| 43 | + IManager $notificationManager, |
|
| 44 | + IUserManager $userManager |
|
| 45 | + ) { |
|
| 46 | + $this->notificationManager = $notificationManager; |
|
| 47 | + $this->userManager = $userManager; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @param CommentsEvent $event |
|
| 52 | - */ |
|
| 53 | - public function evaluate(CommentsEvent $event) { |
|
| 54 | - $comment = $event->getComment(); |
|
| 50 | + /** |
|
| 51 | + * @param CommentsEvent $event |
|
| 52 | + */ |
|
| 53 | + public function evaluate(CommentsEvent $event) { |
|
| 54 | + $comment = $event->getComment(); |
|
| 55 | 55 | |
| 56 | - $mentions = $this->extractMentions($comment->getMentions()); |
|
| 57 | - if (empty($mentions)) { |
|
| 58 | - // no one to notify |
|
| 59 | - return; |
|
| 60 | - } |
|
| 56 | + $mentions = $this->extractMentions($comment->getMentions()); |
|
| 57 | + if (empty($mentions)) { |
|
| 58 | + // no one to notify |
|
| 59 | + return; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - $notification = $this->instantiateNotification($comment); |
|
| 62 | + $notification = $this->instantiateNotification($comment); |
|
| 63 | 63 | |
| 64 | - foreach ($mentions as $uid) { |
|
| 65 | - if (($comment->getActorType() === 'users' && $uid === $comment->getActorId()) |
|
| 66 | - || !$this->userManager->userExists($uid) |
|
| 67 | - ) { |
|
| 68 | - // do not notify unknown users or yourself |
|
| 69 | - continue; |
|
| 70 | - } |
|
| 64 | + foreach ($mentions as $uid) { |
|
| 65 | + if (($comment->getActorType() === 'users' && $uid === $comment->getActorId()) |
|
| 66 | + || !$this->userManager->userExists($uid) |
|
| 67 | + ) { |
|
| 68 | + // do not notify unknown users or yourself |
|
| 69 | + continue; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - $notification->setUser($uid); |
|
| 73 | - if ($event->getEvent() === CommentsEvent::EVENT_DELETE |
|
| 74 | - || $event->getEvent() === CommentsEvent::EVENT_PRE_UPDATE) { |
|
| 75 | - $this->notificationManager->markProcessed($notification); |
|
| 76 | - } else { |
|
| 77 | - $this->notificationManager->notify($notification); |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - } |
|
| 72 | + $notification->setUser($uid); |
|
| 73 | + if ($event->getEvent() === CommentsEvent::EVENT_DELETE |
|
| 74 | + || $event->getEvent() === CommentsEvent::EVENT_PRE_UPDATE) { |
|
| 75 | + $this->notificationManager->markProcessed($notification); |
|
| 76 | + } else { |
|
| 77 | + $this->notificationManager->notify($notification); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * creates a notification instance and fills it with comment data |
|
| 84 | - * |
|
| 85 | - * @param IComment $comment |
|
| 86 | - * @return \OCP\Notification\INotification |
|
| 87 | - */ |
|
| 88 | - public function instantiateNotification(IComment $comment) { |
|
| 89 | - $notification = $this->notificationManager->createNotification(); |
|
| 90 | - $notification |
|
| 91 | - ->setApp('comments') |
|
| 92 | - ->setObject('comment', $comment->getId()) |
|
| 93 | - ->setSubject('mention', [ $comment->getObjectType(), $comment->getObjectId() ]) |
|
| 94 | - ->setDateTime($comment->getCreationDateTime()); |
|
| 82 | + /** |
|
| 83 | + * creates a notification instance and fills it with comment data |
|
| 84 | + * |
|
| 85 | + * @param IComment $comment |
|
| 86 | + * @return \OCP\Notification\INotification |
|
| 87 | + */ |
|
| 88 | + public function instantiateNotification(IComment $comment) { |
|
| 89 | + $notification = $this->notificationManager->createNotification(); |
|
| 90 | + $notification |
|
| 91 | + ->setApp('comments') |
|
| 92 | + ->setObject('comment', $comment->getId()) |
|
| 93 | + ->setSubject('mention', [ $comment->getObjectType(), $comment->getObjectId() ]) |
|
| 94 | + ->setDateTime($comment->getCreationDateTime()); |
|
| 95 | 95 | |
| 96 | - return $notification; |
|
| 97 | - } |
|
| 96 | + return $notification; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * flattens the mention array returned from comments to a list of user ids. |
|
| 101 | - * |
|
| 102 | - * @param array $mentions |
|
| 103 | - * @return string[] containing the mentions, e.g. ['alice', 'bob'] |
|
| 104 | - */ |
|
| 105 | - public function extractMentions(array $mentions) { |
|
| 106 | - if (empty($mentions)) { |
|
| 107 | - return []; |
|
| 108 | - } |
|
| 109 | - $uids = []; |
|
| 110 | - foreach ($mentions as $mention) { |
|
| 111 | - if ($mention['type'] === 'user') { |
|
| 112 | - $uids[] = $mention['id']; |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - return $uids; |
|
| 116 | - } |
|
| 99 | + /** |
|
| 100 | + * flattens the mention array returned from comments to a list of user ids. |
|
| 101 | + * |
|
| 102 | + * @param array $mentions |
|
| 103 | + * @return string[] containing the mentions, e.g. ['alice', 'bob'] |
|
| 104 | + */ |
|
| 105 | + public function extractMentions(array $mentions) { |
|
| 106 | + if (empty($mentions)) { |
|
| 107 | + return []; |
|
| 108 | + } |
|
| 109 | + $uids = []; |
|
| 110 | + foreach ($mentions as $mention) { |
|
| 111 | + if ($mention['type'] === 'user') { |
|
| 112 | + $uids[] = $mention['id']; |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + return $uids; |
|
| 116 | + } |
|
| 117 | 117 | } |
@@ -90,7 +90,7 @@ |
||
| 90 | 90 | $notification |
| 91 | 91 | ->setApp('comments') |
| 92 | 92 | ->setObject('comment', $comment->getId()) |
| 93 | - ->setSubject('mention', [ $comment->getObjectType(), $comment->getObjectId() ]) |
|
| 93 | + ->setSubject('mention', [$comment->getObjectType(), $comment->getObjectId()]) |
|
| 94 | 94 | ->setDateTime($comment->getCreationDateTime()); |
| 95 | 95 | |
| 96 | 96 | return $notification; |
@@ -29,31 +29,31 @@ |
||
| 29 | 29 | use OCA\User_LDAP\User_Proxy; |
| 30 | 30 | |
| 31 | 31 | abstract class UUIDFix extends QueuedJob { |
| 32 | - /** @var AbstractMapping */ |
|
| 33 | - protected $mapper; |
|
| 32 | + /** @var AbstractMapping */ |
|
| 33 | + protected $mapper; |
|
| 34 | 34 | |
| 35 | - /** @var Proxy */ |
|
| 36 | - protected $proxy; |
|
| 35 | + /** @var Proxy */ |
|
| 36 | + protected $proxy; |
|
| 37 | 37 | |
| 38 | - public function run($argument) { |
|
| 39 | - $isUser = $this->proxy instanceof User_Proxy; |
|
| 40 | - foreach ($argument['records'] as $record) { |
|
| 41 | - $access = $this->proxy->getLDAPAccess($record['name']); |
|
| 42 | - $uuid = $access->getUUID($record['dn'], $isUser); |
|
| 43 | - if ($uuid === false) { |
|
| 44 | - // record not found, no prob, continue with the next |
|
| 45 | - continue; |
|
| 46 | - } |
|
| 47 | - if ($uuid !== $record['uuid']) { |
|
| 48 | - $this->mapper->setUUIDbyDN($uuid, $record['dn']); |
|
| 49 | - } |
|
| 50 | - } |
|
| 51 | - } |
|
| 38 | + public function run($argument) { |
|
| 39 | + $isUser = $this->proxy instanceof User_Proxy; |
|
| 40 | + foreach ($argument['records'] as $record) { |
|
| 41 | + $access = $this->proxy->getLDAPAccess($record['name']); |
|
| 42 | + $uuid = $access->getUUID($record['dn'], $isUser); |
|
| 43 | + if ($uuid === false) { |
|
| 44 | + // record not found, no prob, continue with the next |
|
| 45 | + continue; |
|
| 46 | + } |
|
| 47 | + if ($uuid !== $record['uuid']) { |
|
| 48 | + $this->mapper->setUUIDbyDN($uuid, $record['dn']); |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @param Proxy $proxy |
|
| 55 | - */ |
|
| 56 | - public function overrideProxy(Proxy $proxy) { |
|
| 57 | - $this->proxy = $proxy; |
|
| 58 | - } |
|
| 53 | + /** |
|
| 54 | + * @param Proxy $proxy |
|
| 55 | + */ |
|
| 56 | + public function overrideProxy(Proxy $proxy) { |
|
| 57 | + $this->proxy = $proxy; |
|
| 58 | + } |
|
| 59 | 59 | } |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | * @return string|false |
| 198 | 198 | */ |
| 199 | 199 | public function loginName2UserName($loginName) { |
| 200 | - $id = 'LOGINNAME,' . $loginName; |
|
| 200 | + $id = 'LOGINNAME,'.$loginName; |
|
| 201 | 201 | return $this->handleRequest($id, 'loginName2UserName', [$loginName]); |
| 202 | 202 | } |
| 203 | 203 | |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | * @return string|false with the username |
| 209 | 209 | */ |
| 210 | 210 | public function dn2UserName($dn) { |
| 211 | - $id = 'DN,' . $dn; |
|
| 211 | + $id = 'DN,'.$dn; |
|
| 212 | 212 | return $this->handleRequest($id, 'dn2UserName', [$dn]); |
| 213 | 213 | } |
| 214 | 214 | |
@@ -38,360 +38,360 @@ |
||
| 38 | 38 | use OCP\Notification\IManager as INotificationManager; |
| 39 | 39 | |
| 40 | 40 | class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, IUserLDAP { |
| 41 | - private $backends = []; |
|
| 42 | - /** @var User_LDAP */ |
|
| 43 | - private $refBackend = null; |
|
| 41 | + private $backends = []; |
|
| 42 | + /** @var User_LDAP */ |
|
| 43 | + private $refBackend = null; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Constructor |
|
| 47 | - * |
|
| 48 | - * @param array $serverConfigPrefixes array containing the config Prefixes |
|
| 49 | - * @param ILDAPWrapper $ldap |
|
| 50 | - * @param IConfig $ocConfig |
|
| 51 | - * @param INotificationManager $notificationManager |
|
| 52 | - * @param IUserSession $userSession |
|
| 53 | - */ |
|
| 54 | - public function __construct( |
|
| 55 | - array $serverConfigPrefixes, |
|
| 56 | - ILDAPWrapper $ldap, |
|
| 57 | - IConfig $ocConfig, |
|
| 58 | - INotificationManager $notificationManager, |
|
| 59 | - IUserSession $userSession, |
|
| 60 | - UserPluginManager $userPluginManager |
|
| 61 | - ) { |
|
| 62 | - parent::__construct($ldap); |
|
| 63 | - foreach ($serverConfigPrefixes as $configPrefix) { |
|
| 64 | - $this->backends[$configPrefix] = |
|
| 65 | - new User_LDAP($this->getAccess($configPrefix), $ocConfig, $notificationManager, $userSession, $userPluginManager); |
|
| 45 | + /** |
|
| 46 | + * Constructor |
|
| 47 | + * |
|
| 48 | + * @param array $serverConfigPrefixes array containing the config Prefixes |
|
| 49 | + * @param ILDAPWrapper $ldap |
|
| 50 | + * @param IConfig $ocConfig |
|
| 51 | + * @param INotificationManager $notificationManager |
|
| 52 | + * @param IUserSession $userSession |
|
| 53 | + */ |
|
| 54 | + public function __construct( |
|
| 55 | + array $serverConfigPrefixes, |
|
| 56 | + ILDAPWrapper $ldap, |
|
| 57 | + IConfig $ocConfig, |
|
| 58 | + INotificationManager $notificationManager, |
|
| 59 | + IUserSession $userSession, |
|
| 60 | + UserPluginManager $userPluginManager |
|
| 61 | + ) { |
|
| 62 | + parent::__construct($ldap); |
|
| 63 | + foreach ($serverConfigPrefixes as $configPrefix) { |
|
| 64 | + $this->backends[$configPrefix] = |
|
| 65 | + new User_LDAP($this->getAccess($configPrefix), $ocConfig, $notificationManager, $userSession, $userPluginManager); |
|
| 66 | 66 | |
| 67 | - if (is_null($this->refBackend)) { |
|
| 68 | - $this->refBackend = &$this->backends[$configPrefix]; |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - } |
|
| 67 | + if (is_null($this->refBackend)) { |
|
| 68 | + $this->refBackend = &$this->backends[$configPrefix]; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Tries the backends one after the other until a positive result is returned from the specified method |
|
| 75 | - * |
|
| 76 | - * @param string $id the uid connected to the request |
|
| 77 | - * @param string $method the method of the user backend that shall be called |
|
| 78 | - * @param array $parameters an array of parameters to be passed |
|
| 79 | - * @return mixed the result of the method or false |
|
| 80 | - */ |
|
| 81 | - protected function walkBackends($id, $method, $parameters) { |
|
| 82 | - $uid = $id; |
|
| 83 | - $cacheKey = $this->getUserCacheKey($uid); |
|
| 84 | - foreach ($this->backends as $configPrefix => $backend) { |
|
| 85 | - $instance = $backend; |
|
| 86 | - if (!method_exists($instance, $method) |
|
| 87 | - && method_exists($this->getAccess($configPrefix), $method)) { |
|
| 88 | - $instance = $this->getAccess($configPrefix); |
|
| 89 | - } |
|
| 90 | - if ($result = call_user_func_array([$instance, $method], $parameters)) { |
|
| 91 | - if (!$this->isSingleBackend()) { |
|
| 92 | - $this->writeToCache($cacheKey, $configPrefix); |
|
| 93 | - } |
|
| 94 | - return $result; |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - return false; |
|
| 98 | - } |
|
| 73 | + /** |
|
| 74 | + * Tries the backends one after the other until a positive result is returned from the specified method |
|
| 75 | + * |
|
| 76 | + * @param string $id the uid connected to the request |
|
| 77 | + * @param string $method the method of the user backend that shall be called |
|
| 78 | + * @param array $parameters an array of parameters to be passed |
|
| 79 | + * @return mixed the result of the method or false |
|
| 80 | + */ |
|
| 81 | + protected function walkBackends($id, $method, $parameters) { |
|
| 82 | + $uid = $id; |
|
| 83 | + $cacheKey = $this->getUserCacheKey($uid); |
|
| 84 | + foreach ($this->backends as $configPrefix => $backend) { |
|
| 85 | + $instance = $backend; |
|
| 86 | + if (!method_exists($instance, $method) |
|
| 87 | + && method_exists($this->getAccess($configPrefix), $method)) { |
|
| 88 | + $instance = $this->getAccess($configPrefix); |
|
| 89 | + } |
|
| 90 | + if ($result = call_user_func_array([$instance, $method], $parameters)) { |
|
| 91 | + if (!$this->isSingleBackend()) { |
|
| 92 | + $this->writeToCache($cacheKey, $configPrefix); |
|
| 93 | + } |
|
| 94 | + return $result; |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + return false; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * Asks the backend connected to the server that supposely takes care of the uid from the request. |
|
| 102 | - * |
|
| 103 | - * @param string $id the uid connected to the request |
|
| 104 | - * @param string $method the method of the user backend that shall be called |
|
| 105 | - * @param array $parameters an array of parameters to be passed |
|
| 106 | - * @param mixed $passOnWhen the result matches this variable |
|
| 107 | - * @return mixed the result of the method or false |
|
| 108 | - */ |
|
| 109 | - protected function callOnLastSeenOn($id, $method, $parameters, $passOnWhen) { |
|
| 110 | - $uid = $id; |
|
| 111 | - $cacheKey = $this->getUserCacheKey($uid); |
|
| 112 | - $prefix = $this->getFromCache($cacheKey); |
|
| 113 | - //in case the uid has been found in the past, try this stored connection first |
|
| 114 | - if (!is_null($prefix)) { |
|
| 115 | - if (isset($this->backends[$prefix])) { |
|
| 116 | - $instance = $this->backends[$prefix]; |
|
| 117 | - if (!method_exists($instance, $method) |
|
| 118 | - && method_exists($this->getAccess($prefix), $method)) { |
|
| 119 | - $instance = $this->getAccess($prefix); |
|
| 120 | - } |
|
| 121 | - $result = call_user_func_array([$instance, $method], $parameters); |
|
| 122 | - if ($result === $passOnWhen) { |
|
| 123 | - //not found here, reset cache to null if user vanished |
|
| 124 | - //because sometimes methods return false with a reason |
|
| 125 | - $userExists = call_user_func_array( |
|
| 126 | - [$this->backends[$prefix], 'userExistsOnLDAP'], |
|
| 127 | - [$uid] |
|
| 128 | - ); |
|
| 129 | - if (!$userExists) { |
|
| 130 | - $this->writeToCache($cacheKey, null); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - return $result; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - return false; |
|
| 137 | - } |
|
| 100 | + /** |
|
| 101 | + * Asks the backend connected to the server that supposely takes care of the uid from the request. |
|
| 102 | + * |
|
| 103 | + * @param string $id the uid connected to the request |
|
| 104 | + * @param string $method the method of the user backend that shall be called |
|
| 105 | + * @param array $parameters an array of parameters to be passed |
|
| 106 | + * @param mixed $passOnWhen the result matches this variable |
|
| 107 | + * @return mixed the result of the method or false |
|
| 108 | + */ |
|
| 109 | + protected function callOnLastSeenOn($id, $method, $parameters, $passOnWhen) { |
|
| 110 | + $uid = $id; |
|
| 111 | + $cacheKey = $this->getUserCacheKey($uid); |
|
| 112 | + $prefix = $this->getFromCache($cacheKey); |
|
| 113 | + //in case the uid has been found in the past, try this stored connection first |
|
| 114 | + if (!is_null($prefix)) { |
|
| 115 | + if (isset($this->backends[$prefix])) { |
|
| 116 | + $instance = $this->backends[$prefix]; |
|
| 117 | + if (!method_exists($instance, $method) |
|
| 118 | + && method_exists($this->getAccess($prefix), $method)) { |
|
| 119 | + $instance = $this->getAccess($prefix); |
|
| 120 | + } |
|
| 121 | + $result = call_user_func_array([$instance, $method], $parameters); |
|
| 122 | + if ($result === $passOnWhen) { |
|
| 123 | + //not found here, reset cache to null if user vanished |
|
| 124 | + //because sometimes methods return false with a reason |
|
| 125 | + $userExists = call_user_func_array( |
|
| 126 | + [$this->backends[$prefix], 'userExistsOnLDAP'], |
|
| 127 | + [$uid] |
|
| 128 | + ); |
|
| 129 | + if (!$userExists) { |
|
| 130 | + $this->writeToCache($cacheKey, null); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + return $result; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + return false; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - protected function activeBackends(): int { |
|
| 140 | - return count($this->backends); |
|
| 141 | - } |
|
| 139 | + protected function activeBackends(): int { |
|
| 140 | + return count($this->backends); |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - /** |
|
| 144 | - * Check if backend implements actions |
|
| 145 | - * |
|
| 146 | - * @param int $actions bitwise-or'ed actions |
|
| 147 | - * @return boolean |
|
| 148 | - * |
|
| 149 | - * Returns the supported actions as int to be |
|
| 150 | - * compared with \OC\User\Backend::CREATE_USER etc. |
|
| 151 | - */ |
|
| 152 | - public function implementsActions($actions) { |
|
| 153 | - //it's the same across all our user backends obviously |
|
| 154 | - return $this->refBackend->implementsActions($actions); |
|
| 155 | - } |
|
| 143 | + /** |
|
| 144 | + * Check if backend implements actions |
|
| 145 | + * |
|
| 146 | + * @param int $actions bitwise-or'ed actions |
|
| 147 | + * @return boolean |
|
| 148 | + * |
|
| 149 | + * Returns the supported actions as int to be |
|
| 150 | + * compared with \OC\User\Backend::CREATE_USER etc. |
|
| 151 | + */ |
|
| 152 | + public function implementsActions($actions) { |
|
| 153 | + //it's the same across all our user backends obviously |
|
| 154 | + return $this->refBackend->implementsActions($actions); |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - /** |
|
| 158 | - * Backend name to be shown in user management |
|
| 159 | - * |
|
| 160 | - * @return string the name of the backend to be shown |
|
| 161 | - */ |
|
| 162 | - public function getBackendName() { |
|
| 163 | - return $this->refBackend->getBackendName(); |
|
| 164 | - } |
|
| 157 | + /** |
|
| 158 | + * Backend name to be shown in user management |
|
| 159 | + * |
|
| 160 | + * @return string the name of the backend to be shown |
|
| 161 | + */ |
|
| 162 | + public function getBackendName() { |
|
| 163 | + return $this->refBackend->getBackendName(); |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * Get a list of all users |
|
| 168 | - * |
|
| 169 | - * @param string $search |
|
| 170 | - * @param null|int $limit |
|
| 171 | - * @param null|int $offset |
|
| 172 | - * @return string[] an array of all uids |
|
| 173 | - */ |
|
| 174 | - public function getUsers($search = '', $limit = 10, $offset = 0) { |
|
| 175 | - //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
|
| 176 | - $users = []; |
|
| 177 | - foreach ($this->backends as $backend) { |
|
| 178 | - $backendUsers = $backend->getUsers($search, $limit, $offset); |
|
| 179 | - if (is_array($backendUsers)) { |
|
| 180 | - $users = array_merge($users, $backendUsers); |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - return $users; |
|
| 184 | - } |
|
| 166 | + /** |
|
| 167 | + * Get a list of all users |
|
| 168 | + * |
|
| 169 | + * @param string $search |
|
| 170 | + * @param null|int $limit |
|
| 171 | + * @param null|int $offset |
|
| 172 | + * @return string[] an array of all uids |
|
| 173 | + */ |
|
| 174 | + public function getUsers($search = '', $limit = 10, $offset = 0) { |
|
| 175 | + //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
|
| 176 | + $users = []; |
|
| 177 | + foreach ($this->backends as $backend) { |
|
| 178 | + $backendUsers = $backend->getUsers($search, $limit, $offset); |
|
| 179 | + if (is_array($backendUsers)) { |
|
| 180 | + $users = array_merge($users, $backendUsers); |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + return $users; |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - /** |
|
| 187 | - * check if a user exists |
|
| 188 | - * |
|
| 189 | - * @param string $uid the username |
|
| 190 | - * @return boolean |
|
| 191 | - */ |
|
| 192 | - public function userExists($uid) { |
|
| 193 | - $existsOnLDAP = false; |
|
| 194 | - $existsLocally = $this->handleRequest($uid, 'userExists', [$uid]); |
|
| 195 | - if ($existsLocally) { |
|
| 196 | - $existsOnLDAP = $this->userExistsOnLDAP($uid); |
|
| 197 | - } |
|
| 198 | - if ($existsLocally && !$existsOnLDAP) { |
|
| 199 | - try { |
|
| 200 | - $user = $this->getLDAPAccess($uid)->userManager->get($uid); |
|
| 201 | - if ($user instanceof User) { |
|
| 202 | - $user->markUser(); |
|
| 203 | - } |
|
| 204 | - } catch (\Exception $e) { |
|
| 205 | - // ignore |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - return $existsLocally; |
|
| 209 | - } |
|
| 186 | + /** |
|
| 187 | + * check if a user exists |
|
| 188 | + * |
|
| 189 | + * @param string $uid the username |
|
| 190 | + * @return boolean |
|
| 191 | + */ |
|
| 192 | + public function userExists($uid) { |
|
| 193 | + $existsOnLDAP = false; |
|
| 194 | + $existsLocally = $this->handleRequest($uid, 'userExists', [$uid]); |
|
| 195 | + if ($existsLocally) { |
|
| 196 | + $existsOnLDAP = $this->userExistsOnLDAP($uid); |
|
| 197 | + } |
|
| 198 | + if ($existsLocally && !$existsOnLDAP) { |
|
| 199 | + try { |
|
| 200 | + $user = $this->getLDAPAccess($uid)->userManager->get($uid); |
|
| 201 | + if ($user instanceof User) { |
|
| 202 | + $user->markUser(); |
|
| 203 | + } |
|
| 204 | + } catch (\Exception $e) { |
|
| 205 | + // ignore |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + return $existsLocally; |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - /** |
|
| 212 | - * check if a user exists on LDAP |
|
| 213 | - * |
|
| 214 | - * @param string|\OCA\User_LDAP\User\User $user either the Nextcloud user |
|
| 215 | - * name or an instance of that user |
|
| 216 | - * @return boolean |
|
| 217 | - */ |
|
| 218 | - public function userExistsOnLDAP($user) { |
|
| 219 | - $id = ($user instanceof User) ? $user->getUsername() : $user; |
|
| 220 | - return $this->handleRequest($id, 'userExistsOnLDAP', [$user]); |
|
| 221 | - } |
|
| 211 | + /** |
|
| 212 | + * check if a user exists on LDAP |
|
| 213 | + * |
|
| 214 | + * @param string|\OCA\User_LDAP\User\User $user either the Nextcloud user |
|
| 215 | + * name or an instance of that user |
|
| 216 | + * @return boolean |
|
| 217 | + */ |
|
| 218 | + public function userExistsOnLDAP($user) { |
|
| 219 | + $id = ($user instanceof User) ? $user->getUsername() : $user; |
|
| 220 | + return $this->handleRequest($id, 'userExistsOnLDAP', [$user]); |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - /** |
|
| 224 | - * Check if the password is correct |
|
| 225 | - * |
|
| 226 | - * @param string $uid The username |
|
| 227 | - * @param string $password The password |
|
| 228 | - * @return bool |
|
| 229 | - * |
|
| 230 | - * Check if the password is correct without logging in the user |
|
| 231 | - */ |
|
| 232 | - public function checkPassword($uid, $password) { |
|
| 233 | - return $this->handleRequest($uid, 'checkPassword', [$uid, $password]); |
|
| 234 | - } |
|
| 223 | + /** |
|
| 224 | + * Check if the password is correct |
|
| 225 | + * |
|
| 226 | + * @param string $uid The username |
|
| 227 | + * @param string $password The password |
|
| 228 | + * @return bool |
|
| 229 | + * |
|
| 230 | + * Check if the password is correct without logging in the user |
|
| 231 | + */ |
|
| 232 | + public function checkPassword($uid, $password) { |
|
| 233 | + return $this->handleRequest($uid, 'checkPassword', [$uid, $password]); |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | - /** |
|
| 237 | - * returns the username for the given login name, if available |
|
| 238 | - * |
|
| 239 | - * @param string $loginName |
|
| 240 | - * @return string|false |
|
| 241 | - */ |
|
| 242 | - public function loginName2UserName($loginName) { |
|
| 243 | - $id = 'LOGINNAME,' . $loginName; |
|
| 244 | - return $this->handleRequest($id, 'loginName2UserName', [$loginName]); |
|
| 245 | - } |
|
| 236 | + /** |
|
| 237 | + * returns the username for the given login name, if available |
|
| 238 | + * |
|
| 239 | + * @param string $loginName |
|
| 240 | + * @return string|false |
|
| 241 | + */ |
|
| 242 | + public function loginName2UserName($loginName) { |
|
| 243 | + $id = 'LOGINNAME,' . $loginName; |
|
| 244 | + return $this->handleRequest($id, 'loginName2UserName', [$loginName]); |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - /** |
|
| 248 | - * returns the username for the given LDAP DN, if available |
|
| 249 | - * |
|
| 250 | - * @param string $dn |
|
| 251 | - * @return string|false with the username |
|
| 252 | - */ |
|
| 253 | - public function dn2UserName($dn) { |
|
| 254 | - $id = 'DN,' . $dn; |
|
| 255 | - return $this->handleRequest($id, 'dn2UserName', [$dn]); |
|
| 256 | - } |
|
| 247 | + /** |
|
| 248 | + * returns the username for the given LDAP DN, if available |
|
| 249 | + * |
|
| 250 | + * @param string $dn |
|
| 251 | + * @return string|false with the username |
|
| 252 | + */ |
|
| 253 | + public function dn2UserName($dn) { |
|
| 254 | + $id = 'DN,' . $dn; |
|
| 255 | + return $this->handleRequest($id, 'dn2UserName', [$dn]); |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - /** |
|
| 259 | - * get the user's home directory |
|
| 260 | - * |
|
| 261 | - * @param string $uid the username |
|
| 262 | - * @return boolean |
|
| 263 | - */ |
|
| 264 | - public function getHome($uid) { |
|
| 265 | - return $this->handleRequest($uid, 'getHome', [$uid]); |
|
| 266 | - } |
|
| 258 | + /** |
|
| 259 | + * get the user's home directory |
|
| 260 | + * |
|
| 261 | + * @param string $uid the username |
|
| 262 | + * @return boolean |
|
| 263 | + */ |
|
| 264 | + public function getHome($uid) { |
|
| 265 | + return $this->handleRequest($uid, 'getHome', [$uid]); |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - /** |
|
| 269 | - * get display name of the user |
|
| 270 | - * |
|
| 271 | - * @param string $uid user ID of the user |
|
| 272 | - * @return string display name |
|
| 273 | - */ |
|
| 274 | - public function getDisplayName($uid) { |
|
| 275 | - return $this->handleRequest($uid, 'getDisplayName', [$uid]); |
|
| 276 | - } |
|
| 268 | + /** |
|
| 269 | + * get display name of the user |
|
| 270 | + * |
|
| 271 | + * @param string $uid user ID of the user |
|
| 272 | + * @return string display name |
|
| 273 | + */ |
|
| 274 | + public function getDisplayName($uid) { |
|
| 275 | + return $this->handleRequest($uid, 'getDisplayName', [$uid]); |
|
| 276 | + } |
|
| 277 | 277 | |
| 278 | - /** |
|
| 279 | - * set display name of the user |
|
| 280 | - * |
|
| 281 | - * @param string $uid user ID of the user |
|
| 282 | - * @param string $displayName new display name |
|
| 283 | - * @return string display name |
|
| 284 | - */ |
|
| 285 | - public function setDisplayName($uid, $displayName) { |
|
| 286 | - return $this->handleRequest($uid, 'setDisplayName', [$uid, $displayName]); |
|
| 287 | - } |
|
| 278 | + /** |
|
| 279 | + * set display name of the user |
|
| 280 | + * |
|
| 281 | + * @param string $uid user ID of the user |
|
| 282 | + * @param string $displayName new display name |
|
| 283 | + * @return string display name |
|
| 284 | + */ |
|
| 285 | + public function setDisplayName($uid, $displayName) { |
|
| 286 | + return $this->handleRequest($uid, 'setDisplayName', [$uid, $displayName]); |
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | - /** |
|
| 290 | - * checks whether the user is allowed to change his avatar in Nextcloud |
|
| 291 | - * |
|
| 292 | - * @param string $uid the Nextcloud user name |
|
| 293 | - * @return boolean either the user can or cannot |
|
| 294 | - */ |
|
| 295 | - public function canChangeAvatar($uid) { |
|
| 296 | - return $this->handleRequest($uid, 'canChangeAvatar', [$uid], true); |
|
| 297 | - } |
|
| 289 | + /** |
|
| 290 | + * checks whether the user is allowed to change his avatar in Nextcloud |
|
| 291 | + * |
|
| 292 | + * @param string $uid the Nextcloud user name |
|
| 293 | + * @return boolean either the user can or cannot |
|
| 294 | + */ |
|
| 295 | + public function canChangeAvatar($uid) { |
|
| 296 | + return $this->handleRequest($uid, 'canChangeAvatar', [$uid], true); |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - /** |
|
| 300 | - * Get a list of all display names and user ids. |
|
| 301 | - * |
|
| 302 | - * @param string $search |
|
| 303 | - * @param string|null $limit |
|
| 304 | - * @param string|null $offset |
|
| 305 | - * @return array an array of all displayNames (value) and the corresponding uids (key) |
|
| 306 | - */ |
|
| 307 | - public function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
| 308 | - //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
|
| 309 | - $users = []; |
|
| 310 | - foreach ($this->backends as $backend) { |
|
| 311 | - $backendUsers = $backend->getDisplayNames($search, $limit, $offset); |
|
| 312 | - if (is_array($backendUsers)) { |
|
| 313 | - $users = $users + $backendUsers; |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - return $users; |
|
| 317 | - } |
|
| 299 | + /** |
|
| 300 | + * Get a list of all display names and user ids. |
|
| 301 | + * |
|
| 302 | + * @param string $search |
|
| 303 | + * @param string|null $limit |
|
| 304 | + * @param string|null $offset |
|
| 305 | + * @return array an array of all displayNames (value) and the corresponding uids (key) |
|
| 306 | + */ |
|
| 307 | + public function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
| 308 | + //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
|
| 309 | + $users = []; |
|
| 310 | + foreach ($this->backends as $backend) { |
|
| 311 | + $backendUsers = $backend->getDisplayNames($search, $limit, $offset); |
|
| 312 | + if (is_array($backendUsers)) { |
|
| 313 | + $users = $users + $backendUsers; |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + return $users; |
|
| 317 | + } |
|
| 318 | 318 | |
| 319 | - /** |
|
| 320 | - * delete a user |
|
| 321 | - * |
|
| 322 | - * @param string $uid The username of the user to delete |
|
| 323 | - * @return bool |
|
| 324 | - * |
|
| 325 | - * Deletes a user |
|
| 326 | - */ |
|
| 327 | - public function deleteUser($uid) { |
|
| 328 | - return $this->handleRequest($uid, 'deleteUser', [$uid]); |
|
| 329 | - } |
|
| 319 | + /** |
|
| 320 | + * delete a user |
|
| 321 | + * |
|
| 322 | + * @param string $uid The username of the user to delete |
|
| 323 | + * @return bool |
|
| 324 | + * |
|
| 325 | + * Deletes a user |
|
| 326 | + */ |
|
| 327 | + public function deleteUser($uid) { |
|
| 328 | + return $this->handleRequest($uid, 'deleteUser', [$uid]); |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | - /** |
|
| 332 | - * Set password |
|
| 333 | - * |
|
| 334 | - * @param string $uid The username |
|
| 335 | - * @param string $password The new password |
|
| 336 | - * @return bool |
|
| 337 | - * |
|
| 338 | - */ |
|
| 339 | - public function setPassword($uid, $password) { |
|
| 340 | - return $this->handleRequest($uid, 'setPassword', [$uid, $password]); |
|
| 341 | - } |
|
| 331 | + /** |
|
| 332 | + * Set password |
|
| 333 | + * |
|
| 334 | + * @param string $uid The username |
|
| 335 | + * @param string $password The new password |
|
| 336 | + * @return bool |
|
| 337 | + * |
|
| 338 | + */ |
|
| 339 | + public function setPassword($uid, $password) { |
|
| 340 | + return $this->handleRequest($uid, 'setPassword', [$uid, $password]); |
|
| 341 | + } |
|
| 342 | 342 | |
| 343 | - /** |
|
| 344 | - * @return bool |
|
| 345 | - */ |
|
| 346 | - public function hasUserListings() { |
|
| 347 | - return $this->refBackend->hasUserListings(); |
|
| 348 | - } |
|
| 343 | + /** |
|
| 344 | + * @return bool |
|
| 345 | + */ |
|
| 346 | + public function hasUserListings() { |
|
| 347 | + return $this->refBackend->hasUserListings(); |
|
| 348 | + } |
|
| 349 | 349 | |
| 350 | - /** |
|
| 351 | - * Count the number of users |
|
| 352 | - * |
|
| 353 | - * @return int|bool |
|
| 354 | - */ |
|
| 355 | - public function countUsers() { |
|
| 356 | - $users = false; |
|
| 357 | - foreach ($this->backends as $backend) { |
|
| 358 | - $backendUsers = $backend->countUsers(); |
|
| 359 | - if ($backendUsers !== false) { |
|
| 360 | - $users += $backendUsers; |
|
| 361 | - } |
|
| 362 | - } |
|
| 363 | - return $users; |
|
| 364 | - } |
|
| 350 | + /** |
|
| 351 | + * Count the number of users |
|
| 352 | + * |
|
| 353 | + * @return int|bool |
|
| 354 | + */ |
|
| 355 | + public function countUsers() { |
|
| 356 | + $users = false; |
|
| 357 | + foreach ($this->backends as $backend) { |
|
| 358 | + $backendUsers = $backend->countUsers(); |
|
| 359 | + if ($backendUsers !== false) { |
|
| 360 | + $users += $backendUsers; |
|
| 361 | + } |
|
| 362 | + } |
|
| 363 | + return $users; |
|
| 364 | + } |
|
| 365 | 365 | |
| 366 | - /** |
|
| 367 | - * Return access for LDAP interaction. |
|
| 368 | - * |
|
| 369 | - * @param string $uid |
|
| 370 | - * @return Access instance of Access for LDAP interaction |
|
| 371 | - */ |
|
| 372 | - public function getLDAPAccess($uid) { |
|
| 373 | - return $this->handleRequest($uid, 'getLDAPAccess', [$uid]); |
|
| 374 | - } |
|
| 366 | + /** |
|
| 367 | + * Return access for LDAP interaction. |
|
| 368 | + * |
|
| 369 | + * @param string $uid |
|
| 370 | + * @return Access instance of Access for LDAP interaction |
|
| 371 | + */ |
|
| 372 | + public function getLDAPAccess($uid) { |
|
| 373 | + return $this->handleRequest($uid, 'getLDAPAccess', [$uid]); |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - /** |
|
| 377 | - * Return a new LDAP connection for the specified user. |
|
| 378 | - * The connection needs to be closed manually. |
|
| 379 | - * |
|
| 380 | - * @param string $uid |
|
| 381 | - * @return resource of the LDAP connection |
|
| 382 | - */ |
|
| 383 | - public function getNewLDAPConnection($uid) { |
|
| 384 | - return $this->handleRequest($uid, 'getNewLDAPConnection', [$uid]); |
|
| 385 | - } |
|
| 376 | + /** |
|
| 377 | + * Return a new LDAP connection for the specified user. |
|
| 378 | + * The connection needs to be closed manually. |
|
| 379 | + * |
|
| 380 | + * @param string $uid |
|
| 381 | + * @return resource of the LDAP connection |
|
| 382 | + */ |
|
| 383 | + public function getNewLDAPConnection($uid) { |
|
| 384 | + return $this->handleRequest($uid, 'getNewLDAPConnection', [$uid]); |
|
| 385 | + } |
|
| 386 | 386 | |
| 387 | - /** |
|
| 388 | - * Creates a new user in LDAP |
|
| 389 | - * |
|
| 390 | - * @param $username |
|
| 391 | - * @param $password |
|
| 392 | - * @return bool |
|
| 393 | - */ |
|
| 394 | - public function createUser($username, $password) { |
|
| 395 | - return $this->handleRequest($username, 'createUser', [$username, $password]); |
|
| 396 | - } |
|
| 387 | + /** |
|
| 388 | + * Creates a new user in LDAP |
|
| 389 | + * |
|
| 390 | + * @param $username |
|
| 391 | + * @param $password |
|
| 392 | + * @return bool |
|
| 393 | + */ |
|
| 394 | + public function createUser($username, $password) { |
|
| 395 | + return $this->handleRequest($username, 'createUser', [$username, $password]); |
|
| 396 | + } |
|
| 397 | 397 | } |
@@ -26,13 +26,13 @@ |
||
| 26 | 26 | namespace OCA\User_LDAP; |
| 27 | 27 | |
| 28 | 28 | abstract class BackendUtility { |
| 29 | - protected $access; |
|
| 29 | + protected $access; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * constructor, make sure the subclasses call this one! |
|
| 33 | - * @param Access $access an instance of Access for LDAP interaction |
|
| 34 | - */ |
|
| 35 | - public function __construct(Access $access) { |
|
| 36 | - $this->access = $access; |
|
| 37 | - } |
|
| 31 | + /** |
|
| 32 | + * constructor, make sure the subclasses call this one! |
|
| 33 | + * @param Access $access an instance of Access for LDAP interaction |
|
| 34 | + */ |
|
| 35 | + public function __construct(Access $access) { |
|
| 36 | + $this->access = $access; |
|
| 37 | + } |
|
| 38 | 38 | } |