Code Duplication    Length = 32-34 lines in 2 locations

src/Tasks/LDAPGroupSyncTask.php 1 location

@@ 73-104 (lines=32) @@
70
        $updated = 0;
71
        $deleted = 0;
72
73
        foreach ($ldapGroups as $data) {
74
            $group = Group::get()->filter('GUID', $data['objectguid'])->limit(1)->first();
75
76
            if (!($group && $group->exists())) {
77
                // create the initial Group with some internal fields
78
                $group = new Group();
79
                $group->GUID = $data['objectguid'];
80
81
                $this->log(sprintf(
82
                    'Creating new Group (GUID: %s, sAMAccountName: %s)',
83
                    $data['objectguid'],
84
                    $data['samaccountname']
85
                ));
86
                $created++;
87
            } else {
88
                $this->log(sprintf(
89
                    'Updating existing Group "%s" (ID: %s, GUID: %s, sAMAccountName: %s)',
90
                    $group->getTitle(),
91
                    $group->ID,
92
                    $data['objectguid'],
93
                    $data['samaccountname']
94
                ));
95
                $updated++;
96
            }
97
98
            try {
99
                $this->ldapService->updateGroupFromLDAP($group, $data);
100
            } catch (Exception $e) {
101
                $this->log($e->getMessage());
102
                continue;
103
            }
104
        }
105
106
        // remove Group 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

src/Tasks/LDAPMemberSyncTask.php 1 location

@@ 71-104 (lines=34) @@
68
        $updated = 0;
69
        $deleted = 0;
70
71
        foreach ($users as $data) {
72
            $member = Member::get()->filter('GUID', $data['objectguid'])->limit(1)->first();
73
74
            if (!($member && $member->exists())) {
75
                // create the initial Member with some internal fields
76
                $member = new Member();
77
                $member->GUID = $data['objectguid'];
78
79
                $this->log(sprintf(
80
                    'Creating new Member (GUID: %s, sAMAccountName: %s)',
81
                    $data['objectguid'],
82
                    $data['samaccountname']
83
                ));
84
                $created++;
85
            } else {
86
                $this->log(sprintf(
87
                    'Updating existing Member "%s" (ID: %s, GUID: %s, sAMAccountName: %s)',
88
                    $member->getName(),
89
                    $member->ID,
90
                    $data['objectguid'],
91
                    $data['samaccountname']
92
                ));
93
                $updated++;
94
            }
95
96
            // Sync attributes from LDAP to the Member record. This will also write the Member record.
97
            // this is also responsible for putting the user into mapped groups
98
            try {
99
                $this->ldapService->updateMemberFromLDAP($member, $data);
100
            } catch (Exception $e) {
101
                $this->log($e->getMessage());
102
                continue;
103
            }
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