From 619b835591e12855dbcc2b56a5513b2d00c1a80a Mon Sep 17 00:00:00 2001 From: theronakpatel Date: Mon, 9 Jun 2025 19:16:34 +0530 Subject: [PATCH 1/2] getCreateTimestamp function added for LDAP --- lib/Service/LDAPConnectionService.php | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lib/Service/LDAPConnectionService.php b/lib/Service/LDAPConnectionService.php index f7609941..d19ac304 100644 --- a/lib/Service/LDAPConnectionService.php +++ b/lib/Service/LDAPConnectionService.php @@ -122,4 +122,42 @@ class LDAPConnectionService { $this->closeLDAPConnection($conn); } + + /** + * Method getCreateTimestamp + * + * @param string $username [explicite description] + * + * @return string + */ + public function getCreateTimestamp(string $username): ?string + { + try { + $conn = $this->getLDAPConnection(); + $baseDn = implode(',', $this->getLDAPBaseUsers()); + $filter = sprintf('(username=%s)', ldap_escape($username, '', LDAP_ESCAPE_FILTER)); + $attributes = ['createTimestamp']; + + $search = ldap_search($conn, $baseDn, $filter, $attributes); + if (!$search) { + throw new Exception("LDAP search failed for user: $username"); + } + + $entries = ldap_get_entries($conn, $search); + $this->closeLDAPConnection($conn); + + if ($entries['count'] === 0 || empty($entries[0]['createtimestamp'][0])) { + return null; + } + + // Format: 20220817084557Z -> 2022-08-17 08:45:57 + $raw = $entries[0]['createtimestamp'][0]; + $date = \DateTime::createFromFormat('YmdHis\Z', $raw); + return $date ? $date->format('Y-m-d H:i:s') : null; + } catch (Exception $e) { + // Log or handle error as needed + return null; + } + } + } -- GitLab From dc477bfb3c8694c1adfa8f5e5de0f450c46e6088 Mon Sep 17 00:00:00 2001 From: theronakpatel Date: Tue, 10 Jun 2025 23:30:13 +0530 Subject: [PATCH 2/2] php cs fixer applied --- lib/Service/LDAPConnectionService.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Service/LDAPConnectionService.php b/lib/Service/LDAPConnectionService.php index d19ac304..75bead43 100644 --- a/lib/Service/LDAPConnectionService.php +++ b/lib/Service/LDAPConnectionService.php @@ -130,8 +130,7 @@ class LDAPConnectionService { * * @return string */ - public function getCreateTimestamp(string $username): ?string - { + public function getCreateTimestamp(string $username): ?string { try { $conn = $this->getLDAPConnection(); $baseDn = implode(',', $this->getLDAPBaseUsers()); -- GitLab