[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [websites/identity-kde-org] protected/commands: Add code to sync a jointhegame-members group on Iden
From: Ben Cooksley <bcooksley () kde ! org>
Date: 2012-08-18 13:22:19
Message-ID: 20120818132219.31DECA6094 () git ! kde ! org
[Download RAW message or body]
Git commit aa6f4e300838dc85f9e256aff1bdc7b7b372fb62 by Ben Cooksley.
Committed on 18/08/2012 at 15:21.
Pushed by bcooksley into branch 'master'.
Add code to sync a jointhegame-members group on Identity
M +54 -1 protected/commands/GroupManagementCommand.php
http://commits.kde.org/websites/identity-kde-org/aa6f4e300838dc85f9e256aff1bdc7b7b372fb62
diff --git a/protected/commands/GroupManagementCommand.php b/protected/commands/GroupManagementCommand.php
index 7d0427d..655bde6 100644
--- a/protected/commands/GroupManagementCommand.php
+++ b/protected/commands/GroupManagementCommand.php
@@ -54,6 +54,59 @@ class GroupManagementCommand extends CConsoleCommand
// Save changes to the group
$evActiveGroup->save();
}
+
+ public function actionSyncJoinTheGameMembers( $filename )
+ {
+ // First we retrieve the jointhegame-members group
+ $filter = Net_LDAP2_Filter::create('cn', 'equals', 'jointhegame-members');
+ $joinTheGameGroup = Group::model()->findFirstByFilter( $filter );
+
+ // Decode the data
+ $data = file_get_contents($filename);
+ $data = json_decode($data);
+
+ // Start matching up who we can...
+ $foundPeople = array();
+ foreach( $data as $email => $fullName ) {
+ // Assemble the filter
+ $primaryMail = Net_LDAP2_Filter::create('mail', 'equals', $email);
+ $secondaryMail = Net_LDAP2_Filter::create('secondaryMail', 'equals', $email);
+ $filter = Net_LDAP2_Filter::combine('or', array($primaryMail, $secondaryMail));
+ // Find a person, if they exist
+ $person = User::model()->findFirstByFilter($filter);
+
+ // Validate the person
+ if( !$person instanceof User ) {
+ continue;
+ }
+ // The person is valid :) add them to our list
+ $username = $person->uid;
+ $foundPeople[$username] = $person;
+ }
+
+ // Get a list of currently listed people
+ $listedPeople = array();
+ foreach( $joinTheGameGroup->members as $person ) {
+ $username = $person->uid;
+ $listedPeople[$username] = $person;
+ }
+
+ // Remove anyone who is no longer a valid member
+ $toRemove = array_diff_key( $listedPeople, $foundPeople );
+ foreach( $toRemove as $username => $person ) {
+ // Remove them
+ $joinTheGameGroup->removeMember($person);
+ $person->save();
+ }
+
+ // Add anyone who is not listed currently
+ $toAdd = array_diff_key( $foundPeople, $listedPeople );
+ foreach( $toAdd as $username => $person ) {
+ // Add them
+ $joinTheGameGroup->addMember($person);
+ $person->save();
+ }
+ }
};
-?>
\ No newline at end of file
+?>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic