/** * @param SynchronizableSequence $grouphubGroups * @param SynchronizableSequence $ldapGroups * * @return int */ private function doGrouphubGroupsSync(SynchronizableSequence $grouphubGroups, SynchronizableSequence $ldapGroups) { $index = $ldapGroups->synchronize($grouphubGroups, true); $this->logger->info(' - Going to add ' . count($ldapGroups->getAddedElements()) . ' Grouphub groups to LDAP...'); foreach ($ldapGroups->getAddedElements() as $element) { $this->logger->info(' -- Adding ' . $element->getName()); /** @var Group $element */ $this->ldap->addGroup($element, $this->syncAdmins); // Update the reference of the Group in the API $this->api->updateGroupReference($element->getId(), $element->getReference()); $this->syncGrouphubGroupUsers($element); $this->syncGrouphubGroupAdmins($element); } $this->logger->info(' - Going to update ' . count($ldapGroups->getUpdatedElements()) . ' Grouphub groups in LDAP...'); foreach ($ldapGroups->getUpdatedElements() as $element) { $this->logger->info(' -- Updating ' . $element['new']->getReference()); /** @var Group[] $element */ $this->ldap->updateGroup($element['old'], $element['new'], $this->syncAdmins); $this->syncGrouphubGroupUsers($element['new']); $this->syncGrouphubGroupAdmins($element['new']); } $this->logger->info(' - Going to remove ' . count($ldapGroups->getRemovedElements()) . ' Grouphub groups from LDAP...'); foreach ($ldapGroups->getRemovedElements() as $element) { $this->logger->info(' -- Removing ' . $element->getReference()); /** @var Group $element */ $this->ldap->removeGroup($element, $this->syncAdmins); } foreach ($ldapGroups->getEqualElementIndexes() as $index) { /** @var Group $element */ $this->syncGrouphubGroupUsers($grouphubGroups[$index]); $this->syncGrouphubGroupAdmins($grouphubGroups[$index]); } return $index; }
/** * @param array $elements * @param int $totalCount */ public function __construct(array $elements = [], $totalCount = 0) { parent::__construct($elements); $this->totalCount = $totalCount; }