Code Duplication    Length = 32-34 lines in 2 locations

code/tasks/LDAPGroupSyncTask.php 1 location

@@ 45-76 (lines=32) @@
42
        $updated = 0;
43
        $deleted = 0;
44
45
        foreach ($ldapGroups as $data) {
46
            $group = Group::get()->filter('GUID', $data['objectguid'])->limit(1)->first();
47
48
            if (!($group && $group->exists())) {
49
                // create the initial Group with some internal fields
50
                $group = new Group();
51
                $group->GUID = $data['objectguid'];
52
53
                $this->log(sprintf(
54
                    'Creating new Group (GUID: %s, sAMAccountName: %s)',
55
                    $data['objectguid'],
56
                    $data['samaccountname']
57
                ));
58
                $created++;
59
            } else {
60
                $this->log(sprintf(
61
                    'Updating existing Group "%s" (ID: %s, GUID: %s, sAMAccountName: %s)',
62
                    $group->getTitle(),
63
                    $group->ID,
64
                    $data['objectguid'],
65
                    $data['samaccountname']
66
                ));
67
                $updated++;
68
            }
69
70
            try {
71
                $this->ldapService->updateGroupFromLDAP($group, $data);
72
            } catch (Exception $e) {
73
                $this->log($e->getMessage());
74
                continue;
75
            }
76
        }
77
78
        // remove Group records that were previously imported, but no longer exist in the directory
79
        // NOTE: DB::query() here is used for performance and so we don't run out of memory

code/tasks/LDAPMemberSyncTask.php 1 location

@@ 43-76 (lines=34) @@
40
        $updated = 0;
41
        $deleted = 0;
42
43
        foreach ($users as $data) {
44
            $member = Member::get()->filter('GUID', $data['objectguid'])->limit(1)->first();
45
46
            if (!($member && $member->exists())) {
47
                // create the initial Member with some internal fields
48
                $member = new Member();
49
                $member->GUID = $data['objectguid'];
50
51
                $this->log(sprintf(
52
                    'Creating new Member (GUID: %s, sAMAccountName: %s)',
53
                    $data['objectguid'],
54
                    $data['samaccountname']
55
                ));
56
                $created++;
57
            } else {
58
                $this->log(sprintf(
59
                    'Updating existing Member "%s" (ID: %s, GUID: %s, sAMAccountName: %s)',
60
                    $member->getName(),
61
                    $member->ID,
62
                    $data['objectguid'],
63
                    $data['samaccountname']
64
                ));
65
                $updated++;
66
            }
67
68
            // Sync attributes from LDAP to the Member record. This will also write the Member record.
69
            // this is also responsible for putting the user into mapped groups
70
            try {
71
                $this->ldapService->updateMemberFromLDAP($member, $data);
72
            } catch (Exception $e) {
73
                $this->log($e->getMessage());
74
                continue;
75
            }
76
        }
77
78
        // remove Member records that were previously imported, but no longer exist in the directory
79
        // NOTE: DB::query() here is used for performance and so we don't run out of memory