Skip to content

Commit b86e444

Browse files
committed
Cache details and include migration
1 parent 9f7a03a commit b86e444

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
namespace OCA\User_LDAP\Migrations;
3+
4+
use OCP\Migration\ISimpleMigration;
5+
use OCP\Migration\IOutput;
6+
use OCP\IConfig;
7+
use OCA\User_LDAP\Helper;
8+
9+
class Version20220725070804 implements ISimpleMigration {
10+
/** @var IConfig */
11+
private $config;
12+
/** @var $helper */
13+
private $helper;
14+
15+
/**
16+
* @param IConfig $config
17+
*/
18+
public function __construct(IConfig $config, Helper $helper) {
19+
$this->config = $config;
20+
$this->helper = $helper;
21+
}
22+
/**
23+
* @param IOutput $out
24+
*/
25+
public function run(IOutput $out) {
26+
$prefixes = $this->helper->getServerConfigurationPrefixes();
27+
foreach ($prefixes as $prefix) {
28+
$groupnameValue = $this->config->getAppValue('user_ldap', "{$prefix}ldap_expert_groupname_attr", null);
29+
if ($groupnameValue === null) {
30+
$groupDisplaynameValue = $this->config->getAppValue('user_ldap', "{$prefix}ldap_group_display_name", null);
31+
if ($groupDisplaynameValue !== null) {
32+
$this->config->setAppValue('user_ldap', "{$prefix}ldap_expert_groupname_attr", $groupDisplaynameValue);
33+
}
34+
}
35+
}
36+
}
37+
}

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ More information is available in the [LDAP User and Group Backend documentation]
1414
</description>
1515
<licence>AGPL</licence>
1616
<author>Jörn Friedrich Dreyer, Tom Needham, Juan Pablo Villafañez Ramos, Dominik Schmidt and Arthur Schiwon</author>
17-
<version>0.16.0</version>
17+
<version>0.17.0</version>
1818
<types>
1919
<authentication/>
2020
</types>

lib/Group_LDAP.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,12 @@ public function groupExists($gid) {
10021002
}
10031003

10041004
public function getGroupDetails($gid) {
1005+
$cacheKey = "groupDetails-$gid";
1006+
$details = $this->access->getConnection()->getFromCache($cacheKey);
1007+
if ($details !== null) {
1008+
return $details;
1009+
}
1010+
10051011
$dn = $this->access->groupname2dn($gid);
10061012
if ($dn === false) {
10071013
// FIXME: It seems local groups also end up going through here...
@@ -1010,10 +1016,13 @@ public function getGroupDetails($gid) {
10101016

10111017
$attr = $this->access->getConnection()->ldapGroupDisplayName;
10121018
$displayname = $this->access->readAttribute($dn, $attr);
1013-
return [
1019+
1020+
$details = [
10141021
'gid' => $gid,
10151022
'displayName' => $displayname[0],
10161023
];
1024+
$this->access->getConnection()->writeToCache($cacheKey, $details);
1025+
return $details;
10171026
}
10181027

10191028
/**

0 commit comments

Comments
 (0)