Code Duplication    Length = 31-36 lines in 2 locations

src/Tasks/LDAPGroupSyncTask.php 1 location

@@ 69-99 (lines=31) @@
66
67
        $count = 0;
68
69
        foreach ($ldapGroups as $data) {
70
            $group = Group::get()->filter('GUID', $data['objectguid'])->limit(1)->first();
71
72
            if (!($group && $group->exists())) {
73
                // create the initial Group with some internal fields
74
                $group = new Group();
75
                $group->GUID = $data['objectguid'];
76
77
                $this->log(sprintf(
78
                    'Creating new Group (ID: %s, GUID: %s, sAMAccountName: %s)',
79
                    $group->ID,
80
                    $data['objectguid'],
81
                    $data['samaccountname']
82
                ));
83
            } else {
84
                $this->log(sprintf(
85
                    'Updating existing Group "%s" (ID: %s, GUID: %s, sAMAccountName: %s)',
86
                    $group->getTitle(),
87
                    $group->ID,
88
                    $data['objectguid'],
89
                    $data['samaccountname']
90
                ));
91
            }
92
93
            $this->ldapService->updateGroupFromLDAP($group, $data);
94
95
            // cleanup object from memory
96
            $group->destroy();
97
98
            $count++;
99
        }
100
101
        // remove Group records that were previously imported, but no longer exist in the directory
102
        // NOTE: DB::query() here is used for performance and so we don't run out of memory

src/Tasks/LDAPMemberSyncTask.php 1 location

@@ 69-104 (lines=36) @@
66
67
        $count = 0;
68
69
        foreach ($users as $data) {
70
            $member = Member::get()->filter('GUID', $data['objectguid'])->limit(1)->first();
71
72
            if (!($member && $member->exists())) {
73
                // create the initial Member with some internal fields
74
                $member = new Member();
75
                $member->GUID = $data['objectguid'];
76
77
                $this->log(sprintf(
78
                    'Creating new Member (GUID: %s, sAMAccountName: %s)',
79
                    $data['objectguid'],
80
                    $data['samaccountname']
81
                ));
82
            } else {
83
                $this->log(sprintf(
84
                    'Updating existing Member "%s" (ID: %s, GUID: %s, sAMAccountName: %s)',
85
                    $member->getName(),
86
                    $member->ID,
87
                    $data['objectguid'],
88
                    $data['samaccountname']
89
                ));
90
            }
91
92
            // Sync attributes from LDAP to the Member record. This will also write the Member record.
93
            // this is also responsible for putting the user into mapped groups
94
            try {
95
                $this->ldapService->updateMemberFromLDAP($member, $data);
96
            } catch (Exception $e) {
97
                $this->log($e->getMessage());
98
            }
99
100
            // cleanup object from memory
101
            $member->destroy();
102
103
            $count++;
104
        }
105
106
        // remove Member records that were previously imported, but no longer exist in the directory
107
        // NOTE: DB::query() here is used for performance and so we don't run out of memory