Skip to content

Commit 185ac3f

Browse files
committed
remove redis
1 parent ab79344 commit 185ac3f

24 files changed

+38
-506
lines changed

.github/workflows/phpunit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
with:
1313
php-version: "8.3"
1414
# php extensions also listed in tools/docker-dev/web/Dockerfile
15-
extensions: curl,mysql,ldap,pdo,redis
15+
extensions: curl,mysql,ldap,pdo
1616
tools: composer:v2
1717
- name: Install dependencies
1818
run: composer install --prefer-dist --no-progress

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Unity Web Portal is a PHP application built in top of MariaDB and LDAP which act
2323
1. PHP Extensions
2424
1. `php-ldap`
2525
2. `php-curl`
26-
3. `php-redis`
2726
4. `php-cli`
2827
5. `php-mysql`
2928
6. `php-pdo`

defaults/config.ini.default

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ user = "" ; smtp username, if exists
3939
pass = "" ; smtp password, if exists
4040
ssl_verify = "false" ; set to true to verify ssl certificates
4141

42-
[redis]
43-
host = "redis"
44-
port = "6379"
45-
4642
[colors]
4743
light_background = "#ffffff" ; Background color when in light mode
4844
light_foreground = "#1a1a1a" ; Text color when in light mode

resources/autoload.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
require_once __DIR__ . "/lib/UnitySite.php";
1919
require_once __DIR__ . "/lib/UnityConfig.php";
2020
require_once __DIR__ . "/lib/UnityWebhook.php";
21-
require_once __DIR__ . "/lib/UnityRedis.php";
2221

2322
// run init script
2423
require __DIR__ . "/init.php";

resources/init.php

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use UnityWebPortal\lib\UnitySQL;
1111
use UnityWebPortal\lib\UnitySSO;
1212
use UnityWebPortal\lib\UnityUser;
13-
use UnityWebPortal\lib\UnityRedis;
1413
use UnityWebPortal\lib\UnityWebhook;
1514

1615
//
@@ -27,12 +26,6 @@
2726
// Service Init
2827
//
2928

30-
// Creates REDIS service
31-
$REDIS = new UnityRedis(
32-
$CONFIG["redis"]["host"] ?? "",
33-
$CONFIG["redis"]["port"] ?? ""
34-
);
35-
3629
// Creates LDAP service
3730
$LDAP = new UnityLDAP(
3831
$CONFIG["ldap"]["uri"],
@@ -93,11 +86,11 @@
9386
// SSO is available
9487
$_SESSION["SSO"] = $SSO;
9588

96-
$OPERATOR = new UnityUser($SSO["user"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
89+
$OPERATOR = new UnityUser($SSO["user"], $LDAP, $SQL, $MAILER, $WEBHOOK);
9790
$_SESSION["is_admin"] = $OPERATOR->isAdmin();
9891

9992
if (isset($_SESSION["viewUser"]) && $_SESSION["is_admin"]) {
100-
$USER = new UnityUser($_SESSION["viewUser"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
93+
$USER = new UnityUser($_SESSION["viewUser"], $LDAP, $SQL, $MAILER, $WEBHOOK);
10194
} else {
10295
$USER = $OPERATOR;
10396
}
@@ -112,14 +105,6 @@
112105
"user_login",
113106
$OPERATOR->getUID()
114107
);
115-
116-
if (!$_SESSION["user_exists"]) {
117-
// populate cache
118-
$REDIS->setCache($SSO["user"], "org", $SSO["org"]);
119-
$REDIS->setCache($SSO["user"], "firstname", $SSO["firstname"]);
120-
$REDIS->setCache($SSO["user"], "lastname", $SSO["lastname"]);
121-
$REDIS->setCache($SSO["user"], "mail", $SSO["mail"]);
122-
}
123108
}
124109

125110
//

resources/lib/UnityGroup.php

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class UnityGroup
1818
private $SQL;
1919
private $MAILER;
2020
private $WEBHOOK;
21-
private $REDIS;
2221

2322
/**
2423
* Constructor for the object
@@ -27,14 +26,13 @@ class UnityGroup
2726
* @param LDAP $LDAP LDAP Connection
2827
* @param SQL $SQL SQL Connection
2928
*/
30-
public function __construct($pi_uid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK)
29+
public function __construct($pi_uid, $LDAP, $SQL, $MAILER, $WEBHOOK)
3130
{
3231
$this->pi_uid = $pi_uid;
3332

3433
$this->LDAP = $LDAP;
3534
$this->SQL = $SQL;
3635
$this->MAILER = $MAILER;
37-
$this->REDIS = $REDIS;
3836
$this->WEBHOOK = $WEBHOOK;
3937
}
4038

@@ -221,11 +219,6 @@ public function removeGroup($send_mail = true)
221219
if (!$ldapPiGroupEntry->delete()) {
222220
throw new Exception("Unable to delete PI ldap group");
223221
}
224-
225-
$this->REDIS->removeCacheArray("sorted_groups", "", $this->getPIUID());
226-
foreach ($users as $user) {
227-
$this->REDIS->removeCacheArray($user->getUID(), "groups", $this->getPIUID());
228-
}
229222
}
230223

231224
// send email to every user of the now deleted PI group
@@ -398,7 +391,6 @@ public function getRequests()
398391
$this->LDAP,
399392
$this->SQL,
400393
$this->MAILER,
401-
$this->REDIS,
402394
$this->WEBHOOK
403395
);
404396
array_push($out, [$user, $request["timestamp"]]);
@@ -407,43 +399,25 @@ public function getRequests()
407399
return $out;
408400
}
409401

410-
public function getGroupMembers($ignorecache = false)
402+
public function getGroupMembers()
411403
{
412-
if (!$ignorecache) {
413-
$cached_val = $this->REDIS->getCache($this->getPIUID(), "members");
414-
if (!is_null($cached_val)) {
415-
$members = $cached_val;
416-
}
417-
}
418-
419-
$updatecache = false;
420404
if (!isset($members)) {
421405
$pi_group = $this->getLDAPPiGroup();
422406
$members = $pi_group->getAttribute("memberuid");
423-
$updatecache = true;
424407
}
425408

426409
$out = array();
427-
$cache_arr = array();
428410
$owner_uid = $this->getOwner()->getUID();
429411
foreach ($members as $member) {
430412
$user_obj = new UnityUser(
431413
$member,
432414
$this->LDAP,
433415
$this->SQL,
434416
$this->MAILER,
435-
$this->REDIS,
436417
$this->WEBHOOK
437418
);
438419
array_push($out, $user_obj);
439-
array_push($cache_arr, $user_obj->getUID());
440420
}
441-
442-
if (!$ignorecache && $updatecache) {
443-
sort($cache_arr);
444-
$this->REDIS->setCache($this->getPIUID(), "members", $cache_arr);
445-
}
446-
447421
return $out;
448422
}
449423

@@ -492,10 +466,6 @@ private function init()
492466
throw new Exception("Failed to create POSIX group for " . $owner->getUID()); // this shouldn't execute
493467
}
494468
}
495-
496-
$this->REDIS->appendCacheArray("sorted_groups", "", $this->getPIUID());
497-
498-
// TODO if we ever make this project based, we need to update the cache here with the memberuid
499469
}
500470

501471
private function addUserToGroup($new_user)
@@ -507,9 +477,6 @@ private function addUserToGroup($new_user)
507477
if (!$pi_group->write()) {
508478
throw new Exception("Unable to write PI group");
509479
}
510-
511-
$this->REDIS->appendCacheArray($this->getPIUID(), "members", $new_user->getUID());
512-
$this->REDIS->appendCacheArray($new_user->getUID(), "groups", $this->getPIUID());
513480
}
514481

515482
private function removeUserFromGroup($old_user)
@@ -521,9 +488,6 @@ private function removeUserFromGroup($old_user)
521488
if (!$pi_group->write()) {
522489
throw new Exception("Unable to write PI group");
523490
}
524-
525-
$this->REDIS->removeCacheArray($this->getPIUID(), "members", $old_user->getUID());
526-
$this->REDIS->removeCacheArray($old_user->getUID(), "groups", $this->getPIUID());
527491
}
528492

529493
public function userExists($user)
@@ -552,7 +516,6 @@ public function getOwner()
552516
$this->LDAP,
553517
$this->SQL,
554518
$this->MAILER,
555-
$this->REDIS,
556519
$this->WEBHOOK
557520
);
558521
}

resources/lib/UnityLDAP.php

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -225,87 +225,44 @@ public function getUnassignedID($uid, $UnitySQL)
225225
//
226226
// Functions that return user/group objects
227227
//
228-
public function getAllUsers($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook, $ignorecache = false)
228+
public function getAllUsers($UnitySQL, $UnityMailer, $UnityWebhook)
229229
{
230230
$out = array();
231-
232-
if (!$ignorecache) {
233-
$users = $UnityRedis->getCache("sorted_users", "");
234-
if (!is_null($users)) {
235-
foreach ($users as $user) {
236-
array_push($out, new UnityUser($user, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook));
237-
}
238-
239-
return $out;
240-
}
241-
}
242-
243231
$users = $this->userOU->getChildren(true);
244-
245232
foreach ($users as $user) {
246-
$params = array($user->getAttribute("cn")[0], $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook);
233+
$params = array($user->getAttribute("cn")[0], $this, $UnitySQL, $UnityMailer, $UnityWebhook);
247234
array_push($out, new UnityUser(...$params));
248235
}
249236

250237
return $out;
251238
}
252239

253-
public function getAllPIGroups($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook, $ignorecache = false)
240+
public function getAllPIGroups($UnitySQL, $UnityMailer, $UnityWebhook)
254241
{
255242
$out = array();
256-
257-
if (!$ignorecache) {
258-
$groups = $UnityRedis->getCache("sorted_groups", "");
259-
if (!is_null($groups)) {
260-
foreach ($groups as $group) {
261-
$params = array($group, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook);
262-
array_push($out, new UnityGroup(...$params));
263-
}
264-
265-
return $out;
266-
}
267-
}
268-
269243
$pi_groups = $this->pi_groupOU->getChildren(true);
270-
271244
foreach ($pi_groups as $pi_group) {
272245
array_push($out, new UnityGroup(
273246
$pi_group->getAttribute("cn")[0],
274247
$this,
275248
$UnitySQL,
276249
$UnityMailer,
277-
$UnityRedis,
278250
$UnityWebhook
279251
));
280252
}
281-
282253
return $out;
283254
}
284255

285-
public function getAllOrgGroups($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook, $ignorecache = false)
256+
public function getAllOrgGroups($UnitySQL, $UnityMailer, $UnityWebhook)
286257
{
287258
$out = array();
288-
289-
if (!$ignorecache) {
290-
$orgs = $UnityRedis->getCache("sorted_orgs", "");
291-
if (!is_null($orgs)) {
292-
foreach ($orgs as $org) {
293-
array_push($out, new UnityOrg($org, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook));
294-
}
295-
296-
return $out;
297-
}
298-
}
299-
300259
$org_groups = $this->org_groupOU->getChildren(true);
301-
302260
foreach ($org_groups as $org_group) {
303261
array_push($out, new UnityOrg(
304262
$org_group->getAttribute("cn")[0],
305263
$this,
306264
$UnitySQL,
307265
$UnityMailer,
308-
$UnityRedis,
309266
$UnityWebhook
310267
));
311268
}

resources/lib/UnityOrg.php

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,16 @@ class UnityOrg
1111
private $MAILER;
1212
private $SQL;
1313
private $LDAP;
14-
private $REDIS;
1514
private $WEBHOOK;
1615

17-
public function __construct($orgid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK)
16+
public function __construct($orgid, $LDAP, $SQL, $MAILER, $WEBHOOK)
1817
{
1918
$this->orgid = $orgid;
2019

2120
$this->LDAP = $LDAP;
2221
$this->SQL = $SQL;
2322
$this->MAILER = $MAILER;
2423
$this->WEBHOOK = $WEBHOOK;
25-
$this->REDIS = $REDIS;
2624
}
2725

2826
public function init()
@@ -39,8 +37,6 @@ public function init()
3937
throw new Exception("Failed to create POSIX group for " . $this->orgid); // this shouldn't execute
4038
}
4139
}
42-
43-
$this->REDIS->appendCacheArray("sorted_orgs", "", $this->getOrgID());
4440
}
4541

4642
public function exists()
@@ -65,59 +61,36 @@ public function inOrg($user)
6561
return in_array($user, $members);
6662
}
6763

68-
public function getOrgMembers($ignorecache = false)
64+
public function getOrgMembers()
6965
{
70-
if (!$ignorecache) {
71-
$cached_val = $this->REDIS->getCache($this->getOrgID(), "members");
72-
if (!is_null($cached_val)) {
73-
$members = $cached_val;
74-
}
75-
}
76-
77-
$updatecache = false;
7866
if (!isset($members)) {
7967
$org_group = $this->getLDAPOrgGroup();
8068
$members = $org_group->getAttribute("memberuid");
81-
$updatecache = true;
8269
}
8370

8471
$out = array();
85-
$cache_arr = array();
8672
foreach ($members as $member) {
87-
$user_obj = new UnityUser($member, $this->LDAP, $this->SQL, $this->MAILER, $this->REDIS, $this->WEBHOOK);
73+
$user_obj = new UnityUser($member, $this->LDAP, $this->SQL, $this->MAILER, $this->WEBHOOK);
8874
array_push($out, $user_obj);
89-
array_push($cache_arr, $user_obj->getUID());
90-
}
91-
92-
if (!$ignorecache && $updatecache) {
93-
sort($cache_arr);
94-
$this->REDIS->setCache($this->getOrgID(), "members", $cache_arr);
9575
}
96-
9776
return $out;
9877
}
9978

10079
public function addUser($user)
10180
{
10281
$org_group = $this->getLDAPOrgGroup();
10382
$org_group->appendAttribute("memberuid", $user->getUID());
104-
10583
if (!$org_group->write()) {
10684
throw new Exception("Unable to write to org group");
10785
}
108-
109-
$this->REDIS->appendCacheArray($this->getOrgID(), "members", $user->getUID());
11086
}
11187

11288
public function removeUser($user)
11389
{
11490
$org_group = $this->getLDAPOrgGroup();
11591
$org_group->removeAttributeEntryByValue("memberuid", $user->getUID());
116-
11792
if (!$org_group->write()) {
11893
throw new Exception("Unable to write to org group");
11994
}
120-
121-
$this->REDIS->removeCacheArray($this->getOrgID(), "members", $user->getUID());
12295
}
12396
}

0 commit comments

Comments
 (0)